Sha256: 23aa652a13cdb6d6fd34af6c29098473f1339cb56ff815d893c81bc64d68f20e

Contents?: true

Size: 1.78 KB

Versions: 31

Compression:

Stored size: 1.78 KB

Contents

require 'json'

module HybridPlatformsConductor

  class Topographer

    module Plugins

      # Output in Graphviz format
      class Json < Topographer::Plugin

        # Output the nodes graph in a file
        # [API] - This method is mandatory.
        #
        # Parameters::
        # * *file_name* (String): The file name for output
        def write_graph(file_name)
          # Build the JSON
          json = {
            nodes: [],
            links: []
          }
          @topographer.nodes_graph.sort.each do |node_name, node_info|
            node_json = {
              id: node_name,
              description: "#{@topographer.title_for(node_name)} - #{@topographer.description_for(node_name)}",
              group: group_for(node_name)
            }
            node_json[:includes] = node_info[:includes] if @topographer.node_cluster?(node_name)
            json[:nodes] << node_json
            node_info[:connections].each do |connected_node_name, labels|
              json[:links] << {
                source: node_name,
                target: connected_node_name,
                value: 1,
                labels: labels.sort
              }
            end
          end
          File.write(file_name, JSON.pretty_generate(json))
        end

        private

        # Get the group of a given node
        #
        # Parameters::
        # * *node_name* (String): Node name
        # Result::
        # * String: Group
        def group_for(node_name)
          case @topographer.nodes_graph[node_name][:type]
          when :node
            if @topographer.node_physical?(node_name)
              1
            else
              2
            end
          when :cluster
            3
          when :unknown
            4
          end
        end

      end

    end

  end

end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
hybrid_platforms_conductor-33.9.5 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.9.4 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.9.2 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.9.1 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.9.0 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.8.4 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.8.3 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.8.2 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.8.1 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.8.0 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.7.4 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.7.3 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.7.2 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.7.1 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.7.0 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.6.0 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.5.1 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.5.0 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.4.0 lib/hybrid_platforms_conductor/topographer/plugins/json.rb
hybrid_platforms_conductor-33.3.0 lib/hybrid_platforms_conductor/topographer/plugins/json.rb