Class: Weavr::Cluster

Inherits:
Resource show all
Defined in:
lib/weavr/resource/cluster.rb

Instance Method Summary collapse

Methods inherited from Resource

child_resources, #connection, extract_class_params, label, load_definitions!, predefine_class, receive, #receive!, #refresh!, #resource_action

Instance Method Details

#add_components(srvc, names) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/weavr/resource/cluster.rb', line 33

def add_components(srvc, names)
  names.each do |name|
    comp = Component.receive(component_name: name, href: File.join(href, 'services', srvc, 'components', name))
    comp.create
  end
  refresh!
end

#add_hosts(*names) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/weavr/resource/cluster.rb', line 17

def add_hosts(*names)
  names.each do |name|
    host = Host.receive(href: File.join(href, 'hosts', name))
    host.create
  end
  refresh!
end

#add_services(*names) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/weavr/resource/cluster.rb', line 25

def add_services(*names)
  names.each do |name|
    srvc = Service.receive(service_name: name, href: File.join(href, 'services'))
    srvc.create
  end
  refresh!
end

#assign_host_components(mapping) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/weavr/resource/cluster.rb', line 41

def assign_host_components mapping
  mapping.each_pair do |host, comps|
    comps.each do |comp|
      role = HostRole.receive(href: File.join(href, 'hosts', host, 'host_components', comp))
      role.create
    end
  end
end

#create(options) ⇒ Object



12
13
14
15
# File 'lib/weavr/resource/cluster.rb', line 12

def create options
  resource_action(:post, self.class.label => { version: 'HDP-2.1' }.merge(options))
  self
end

#create_config(type, version, properties) ⇒ Object



50
51
52
53
# File 'lib/weavr/resource/cluster.rb', line 50

def create_config(type, version, properties)
  resource_action(:put, self.class.label => { desired_config: { type: type, tag: version, properties: properties } })
  refresh!
end

#create_from_blueprint(cluster_blueprint_filename) ⇒ Object

POST /clusters/:name Creates a cluster. Since this installs and starts services, return result of Request.receive(res) example curl -H “X-Requested-By: ambari” -d @hdp_blueprint_cluster.json -u admin:admin \

-XPOST http://localhost:8080/api/v1/clusters/blueprint-hwx


61
62
63
64
65
66
67
68
# File 'lib/weavr/resource/cluster.rb', line 61

def create_from_blueprint cluster_blueprint_filename
  begin
    data = MultiJson.load File.open(cluster_blueprint_filename, 'r')
  rescue Exception => e
    raise e.message, Weavr::BlueprintError
  end
  create_from_blueprint_data data
end

#create_from_blueprint_data(data) ⇒ Object



70
71
72
73
# File 'lib/weavr/resource/cluster.rb', line 70

def create_from_blueprint_data data
  res = resource_action(:post, data)
  Request.receive(res || { })
end

#deleteObject



82
83
84
# File 'lib/weavr/resource/cluster.rb', line 82

def delete
  resource_action(:delete)
end

#get_blueprint(name) ⇒ Object

GET /clusters/:name?format=blueprint Export the current cluster layout as a blueprint. TODO: add GET param handling to Weavr::Connection#resource



78
79
80
# File 'lib/weavr/resource/cluster.rb', line 78

def get_blueprint name
  connection.resource(:get, "clusters/#{name}?format=blueprint")
end

#persistObject

Weird persist method for the browser



87
88
89
# File 'lib/weavr/resource/cluster.rb', line 87

def persist
  connection.resource(:post, 'persist', 'CLUSTER_CURRENT_STATUS' => { 'clusterState' => 'CLUSTER_STARTED_5' }.to_json)
end