Class: Seiso::ImportMaster::Importers::NodeImporter

Inherits:
BaseImporter
  • Object
show all
Defined in:
lib/seiso/import_master/importers/node_importer.rb

Overview

Imports a node document into Seiso.

Each node doc corresponds to a service instance. This importer compares the nodes in Seiso with the nodes in the node doc, and removes anything from Seiso that isn’t in the node doc. Then it imports the nodes from the node doc into Seiso.

Author

Willie Wheeler ([email protected])

Copyright

Copyright © 2014-2015 Expedia, Inc.

License

Apache 2.0

Instance Method Summary collapse

Methods inherited from BaseImporter

#detach_children

Constructor Details

#initialize(mapper, uri_factory_v1, rest_connector_v1) ⇒ NodeImporter

Returns a new instance of NodeImporter.



18
19
20
21
22
# File 'lib/seiso/import_master/importers/node_importer.rb', line 18

def initialize(mapper, uri_factory_v1, rest_connector_v1)
  @mapper = mapper
  @uri_factory_v1 = uri_factory_v1
  @rest_connector_v1 = rest_connector_v1
end

Instance Method Details

#import(doc) ⇒ Object

Imports the node document.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/seiso/import_master/importers/node_importer.rb', line 25

def import(doc)
  si_key = doc['serviceInstance']
  nodes = doc['items']
  puts "Importing node document for service instance #{si_key}"

  delete_stale_nodes_from_seiso

  # Node masters contain the service instance at the top-level, so enrich the nodes themselves
  # with the service instance.
  nodes.each do |n|
    n['serviceInstance'] = si_key
  end

  nips = detach_children(nodes, 'node', 'name', 'ipAddresses')

  seiso_nodes = nodes.map { |n| @mapper.seiso_node n }
  nodes_uri = @uri_factory_v1.nodes_uri true
  @rest_connector_v1.post(nodes_uri, seiso_nodes)

  import_nips nips
end