<commit_before>class ContainerTopologyService < TopologyService

  def initialize(provider_id)
    @provider_id = provider_id
    @providers = retrieve_providers(@provider_id, ManageIQ::Providers::ContainerManager)
  end

  def build_topology
    topology = {}
    topo_items = {}
    links = []

    @providers.each do |provider|
      topo_items[entity_id(provider)] =  build_entity_data(provider)
      provider.container_nodes.each { |n|
        topo_items[entity_id(n)] = build_entity_data(n)
        links << build_link(entity_id(provider), entity_id(n))
        n.container_groups.each do |cg|
          topo_items[entity_id(cg)] = build_entity_data(cg)
          links << build_link(entity_id(n), entity_id(cg))
          cg.containers.each do |c|
            topo_items[entity_id(c)] = build_entity_data(c)
            links << build_link(entity_id(cg), entity_id(c))
          end
          if cg.container_replicator
            cr = cg.container_replicator
            topo_items[entity_id(cr)] = build_entity_data(cr)
            links << build_link(entity_id(cr), entity_id(cg))
          end
        end

        if n.lives_on
          topo_items[entity_id(n.lives_on)] = build_entity_data(n.lives_on)
          links << build_link(entity_id(n), entity_id(n.lives_on))
          if n.lives_on.kind_of?(Vm) # add link to Host
            host = n.lives_on.host
            if host
              topo_items[entity_id(host)] = build_entity_data(host)
              links << build_link(entity_id(n.lives_on), entity_id(host))
            end
          end
        end
      }

      provider.container_services.each { |s|
        topo_items[entity_id(s)] = build_entity_data(s)
        s.container_groups.each { |cg| links << build_link(entity_id(s), entity_id(cg)) } if s.container_groups.size > 0
        if s.container_routes.size > 0
          s.container_routes.each { |r|
            topo_items[entity_id(r)] = build_entity_data(r)
            links << build_link(entity_id(s), entity_id(r))
          }
        end
      }
    end

    topology[:items] = topo_items
    topology[:relations] = links
    topology[:kinds] = build_kinds
    topology
  end

  def entity_display_type(entity)
    if entity.kind_of?(ManageIQ::Providers::ContainerManager)
      entity.type.split('::')[2]
    elsif entity.kind_of?(ManageIQ::Providers::ContainerManager::ContainerGroup)
      "Pod"
    else
      name = entity.class.name.demodulize
      if name.start_with? "Container"<commit_msg>Remove deprecation warning about top level constant<commit_after>class ContainerTopologyService < TopologyService

  def initialize(provider_id)
    @provider_id = provider_id
    @providers = retrieve_providers(@provider_id, ManageIQ::Providers::ContainerManager)
  end

  def build_topology
    topology = {}
    topo_items = {}
    links = []

    @providers.each do |provider|
      topo_items[entity_id(provider)] =  build_entity_data(provider)
      provider.container_nodes.each { |n|
        topo_items[entity_id(n)] = build_entity_data(n)
        links << build_link(entity_id(provider), entity_id(n))
        n.container_groups.each do |cg|
          topo_items[entity_id(cg)] = build_entity_data(cg)
          links << build_link(entity_id(n), entity_id(cg))
          cg.containers.each do |c|
            topo_items[entity_id(c)] = build_entity_data(c)
            links << build_link(entity_id(cg), entity_id(c))
          end
          if cg.container_replicator
            cr = cg.container_replicator
            topo_items[entity_id(cr)] = build_entity_data(cr)
            links << build_link(entity_id(cr), entity_id(cg))
          end
        end

        if n.lives_on
          topo_items[entity_id(n.lives_on)] = build_entity_data(n.lives_on)
          links << build_link(entity_id(n), entity_id(n.lives_on))
          if n.lives_on.kind_of?(Vm) # add link to Host
            host = n.lives_on.host
            if host
              topo_items[entity_id(host)] = build_entity_data(host)
              links << build_link(entity_id(n.lives_on), entity_id(host))
            end
          end
        end
      }

      provider.container_services.each { |s|
        topo_items[entity_id(s)] = build_entity_data(s)
        s.container_groups.each { |cg| links << build_link(entity_id(s), entity_id(cg)) } if s.container_groups.size > 0
        if s.container_routes.size > 0
          s.container_routes.each { |r|
            topo_items[entity_id(r)] = build_entity_data(r)
            links << build_link(entity_id(s), entity_id(r))
          }
        end
      }
    end

    topology[:items] = topo_items
    topology[:relations] = links
    topology[:kinds] = build_kinds
    topology
  end

  def entity_display_type(entity)
    if entity.kind_of?(ManageIQ::Providers::ContainerManager)
      entity.type.split('::')[2]
    elsif entity.kind_of?(ContainerGroup)
      "Pod"
    else
      name = entity.class.name.demodulize
      if name.start_with? "Container"
{'fraction_non_alphanumeric': 0.10823812387251955, 'fraction_numerical': 0.0012026458208057728, 'mean_word_length': 2.6449963476990503, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5702775', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1651, 'n_words': 259}