Class: Receiver::AmbariRestAPIConnector
- Inherits:
-
RestApiConnector
- Object
- Connector
- RestApiConnector
- Receiver::AmbariRestAPIConnector
- Defined in:
- lib/receiver/ambari_rest_api_connector.rb
Overview
Class linking to the Ambari Rest API.
Instance Attribute Summary
Attributes inherited from RestApiConnector
#auth_type, #dest_ip, #dest_port, #timeout
Instance Method Summary collapse
-
#add_host(cluster_name, host_name) ⇒ Object
Adds an host.
-
#add_host_component(cluster_name, host_name, component_name) ⇒ Object
Adds a component to an host.
-
#add_service_component(cluster_name, service_name, component_name) ⇒ Object
Adds a component to a service.
-
#apply_configuration(cluster_name, configuration_type, configuration_tag) ⇒ Object
Apply a configuration into a cluster.
-
#create_apply_configuration(cluster_name, configuration_type, configuration_tag, properties) ⇒ Object
Create and apply a configuration into a cluster.
-
#create_configuration(cluster_name, configuration_type, configuration_tag, properties) ⇒ Object
Create a configuration into a cluster.
-
#define_cluster(cluster_name, cluster_version) ⇒ Object
Defines a new cluster.
-
#define_service(cluster_name, service_name) ⇒ Object
Defines a new service.
-
#delete_cluster(cluster_name) ⇒ Object
Deletes a new cluster.
-
#delete_host(cluster_name, host_name) ⇒ Object
Deletes an host.
-
#delete_host_component(cluster_name, host_name, component_name) ⇒ Object
Deletes a component from an host.
-
#delete_service(cluster_name, service_name) ⇒ Object
Deletes a service.
-
#detach_host_component(cluster_name, host_name, component_name) ⇒ Object
Detachs a component of an host.
-
#get_cluster_configuration(cluster_name, type, tag) ⇒ Object
Launches a GET request on a specifique configuration.
-
#initialize(logger = nil) ⇒ AmbariRestAPIConnector
constructor
Default constructor.
-
#install_host_component(cluster_name, host_name, component_name) ⇒ Object
Installs a component of an host.
-
#install_service(cluster_name, service_name) ⇒ Object
Installs a service.
-
#install_service_components(cluster_name, service_name, component_name) ⇒ Object
Installs a type of components of a service.
-
#list_clusters ⇒ Object
Shows the list of clusters.
-
#set_status_host_component(cluster_name, host_name, component_name, status) ⇒ Object
private
Set the status of a component of an host.
-
#set_status_service(cluster_name, service_name, status) ⇒ Object
private
Set the status of a service.
-
#set_status_service_components(cluster_name, service_name, component_name, status) ⇒ Object
private
Set the status of a type of components of a service.
-
#show_cluster(cluster_name, show_host = false, show_components = false) ⇒ Object
Shows the information of a cluster.
-
#show_cluster_services(cluster_name) ⇒ Object
Shows the services of a cluster.
-
#show_host(cluster_name, host_name) ⇒ Object
Shows information of an host.
-
#show_request(cluster_name, request_id) ⇒ Object
Shows the information of a request.
-
#show_requests(cluster_name) ⇒ Object
Shows the requests of a cluster.
-
#show_service(cluster_name, service_name) ⇒ Object
Shows the list of service of a cluster.
-
#show_service_components(cluster_name, service_name, component_name) ⇒ Object
Shows information of a type of components of a service.
-
#start_host_component(cluster_name, host_name, component_name) ⇒ Object
Starts a component of an host.
-
#start_service(cluster_name, service_name) ⇒ Object
Starts a service.
-
#start_service_components(cluster_name, service_name, component_name) ⇒ Object
Starts a type of components of a service.
-
#stop_host_component(cluster_name, host_name, component_name) ⇒ Object
Stops a component of an host.
-
#stop_service(cluster_name, service_name) ⇒ Object
Stops a service.
-
#stop_service_components(cluster_name, service_name, component_name) ⇒ Object
Stops a type of components of a service.
Methods inherited from RestApiConnector
#get_message_html, #launch_request, #launch_request_mock
Constructor Details
#initialize(logger = nil) ⇒ AmbariRestAPIConnector
Change the conf file path to a relative path
Default constructor.
17 18 19 20 21 22 23 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 17 def initialize(logger = nil) file = File.new(File.dirname(__FILE__) + "/../../resources/cloudbox-server.conf", "r") json = file.read() conf = JSON.parse(json) super(conf["ambari_server_ip"], conf["ambari_server_port"], "BASIC", conf["ambari_user"], conf["ambari_password"], 10000, logger) @logger.info("Receiver::AmbariRestAPIConnector initialize the parameters...") end |
Instance Method Details
#add_host(cluster_name, host_name) ⇒ Object
Adds an host.
356 357 358 359 360 361 362 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 356 def add_host(cluster_name, host_name) if host_name == nil || cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("POST", "/api/v1/clusters/#{cluster_name}/hosts/#{host_name}") end |
#add_host_component(cluster_name, host_name, component_name) ⇒ Object
Adds a component to an host.
236 237 238 239 240 241 242 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 236 def add_host_component(cluster_name, host_name, component_name) if cluster_name == nil || host_name == nil || component_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("POST", "/api/v1/clusters/#{cluster_name}/hosts/#{host_name}/host_components/#{component_name}") end |
#add_service_component(cluster_name, service_name, component_name) ⇒ Object
Adds a component to a service.
412 413 414 415 416 417 418 419 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 412 def add_service_component(cluster_name, service_name, component_name) if service_name == nil || component_name == nil || cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("POST", "/api/v1/clusters/#{cluster_name}/services/#{service_name}/components/#{component_name}") end |
#apply_configuration(cluster_name, configuration_type, configuration_tag) ⇒ Object
Apply a configuration into a cluster.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 85 def apply_configuration(cluster_name, configuration_type, configuration_tag) if cluster_name == nil || configuration_type == nil || configuration_tag == nil raise(ArgumentError, 'Arguments can\'t be nil!') end body = {"Clusters" => { "desired_config" => { "type" => configuration_type, "tag" => configuration_tag } }} return launch_request("PUT", "/api/v1/clusters/#{cluster_name}", body.to_json) end |
#create_apply_configuration(cluster_name, configuration_type, configuration_tag, properties) ⇒ Object
Create and apply a configuration into a cluster.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 61 def create_apply_configuration(cluster_name, configuration_type, configuration_tag, properties) if cluster_name == nil || configuration_type == nil || configuration_tag == nil || properties == nil raise(ArgumentError, 'Arguments can\'t be nil!') end body = {"Clusters" => { "desired_config" => { "type" => configuration_type.to_s, "tag" => configuration_tag.to_s, "properties" => {} } }} body['Clusters']['desired_config']['properties'].update(properties) return launch_request("PUT", "/api/v1/clusters/#{cluster_name}", body.to_json) end |
#create_configuration(cluster_name, configuration_type, configuration_tag, properties) ⇒ Object
Create a configuration into a cluster.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 35 def create_configuration(cluster_name, configuration_type, configuration_tag, properties) if cluster_name == nil || configuration_type == nil || configuration_tag == nil || properties == nil raise(ArgumentError, 'Arguments can\'t be nil!') end body = {"type" => configuration_type, "tag" => configuration_tag, "Config" => { "cluster_name" => cluster_name }, "properties" => {} } body["properties"].update(properties) return launch_request("POST", "/api/v1/clusters/#{cluster_name}/configurations", body.to_json) end |
#define_cluster(cluster_name, cluster_version) ⇒ Object
Defines a new cluster.
108 109 110 111 112 113 114 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 108 def define_cluster(cluster_name, cluster_version) if cluster_name == nil || cluster_version == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("POST", "/api/v1/clusters/#{cluster_name}", "{\"Clusters\": {\"version\" : \"#{cluster_version}\"}}") end |
#define_service(cluster_name, service_name) ⇒ Object
Defines a new service.
429 430 431 432 433 434 435 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 429 def define_service(cluster_name, service_name) if service_name == nil || cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("POST", "/api/v1/clusters/#{cluster_name}/services/#{service_name}") end |
#delete_cluster(cluster_name) ⇒ Object
Deletes a new cluster.
123 124 125 126 127 128 129 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 123 def delete_cluster(cluster_name) if cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("DELETE", "/api/v1/clusters/#{cluster_name}") end |
#delete_host(cluster_name, host_name) ⇒ Object
Deletes an host.
269 270 271 272 273 274 275 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 269 def delete_host(cluster_name, host_name) if host_name == nil || cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("DELETE", "/api/v1/clusters/#{cluster_name}/hosts/#{host_name}") end |
#delete_host_component(cluster_name, host_name, component_name) ⇒ Object
Deletes a component from an host.
253 254 255 256 257 258 259 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 253 def delete_host_component(cluster_name, host_name, component_name) if host_name == nil || component_name == nil || cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("DELETE", "/api/v1/clusters/#{cluster_name}/hosts/#{host_name}/host_components/#{component_name}") end |
#delete_service(cluster_name, service_name) ⇒ Object
Deletes a service.
445 446 447 448 449 450 451 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 445 def delete_service(cluster_name, service_name) if service_name == nil || cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("DELETE", "/api/v1/clusters/#{cluster_name}/services/#{service_name}") end |
#detach_host_component(cluster_name, host_name, component_name) ⇒ Object
Detachs a component of an host.
325 326 327 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 325 def detach_host_component(cluster_name, host_name, component_name) return set_status_host_component(cluster_name, host_name, component_name, "MAINTENANCE") end |
#get_cluster_configuration(cluster_name, type, tag) ⇒ Object
Launches a GET request on a specifique configuration.
155 156 157 158 159 160 161 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 155 def get_cluster_configuration(cluster_name, type, tag) if cluster_name == nil || type == nil || tag == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("GET", "/api/v1/clusters/#{cluster_name}/configurations?type=#{type}&tag=#{tag}") end |
#install_host_component(cluster_name, host_name, component_name) ⇒ Object
Installs a component of an host.
286 287 288 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 286 def install_host_component(cluster_name, host_name, component_name) return set_status_host_component(cluster_name, host_name, component_name, "INSTALLED") end |
#install_service(cluster_name, service_name) ⇒ Object
Installs a service.
461 462 463 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 461 def install_service(cluster_name, service_name) return set_status_service(cluster_name, service_name, "INSTALLED") end |
#install_service_components(cluster_name, service_name, component_name) ⇒ Object
Installs a type of components of a service.
516 517 518 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 516 def install_service_components(cluster_name, service_name, component_name) return set_status_service_components(cluster_name, service_name, component_name, "INSTALLED") end |
#list_clusters ⇒ Object
Shows the list of clusters.
223 224 225 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 223 def list_clusters return launch_request("GET", "/api/v1/clusters") end |
#set_status_host_component(cluster_name, host_name, component_name, status) ⇒ Object (private)
Set the status of a component of an host.
339 340 341 342 343 344 345 346 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 339 def set_status_host_component(cluster_name, host_name, component_name, status) if host_name == nil || component_name == nil || cluster_name == nil || status == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("PUT", "/api/v1/clusters/#{cluster_name}/hosts/#{host_name}/host_components/#{component_name}", "{ \"HostRoles\" : { \"state\" : \"#{status}\"}}") end |
#set_status_service(cluster_name, service_name, status) ⇒ Object (private)
Set the status of a service.
498 499 500 501 502 503 504 505 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 498 def set_status_service(cluster_name, service_name, status) if service_name == nil || cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("PUT", "/api/v1/clusters/#{cluster_name}/services/#{service_name}", "{\"ServiceInfo\": {\"state\" : \"#{status}\"}}") end |
#set_status_service_components(cluster_name, service_name, component_name, status) ⇒ Object (private)
Set the status of a type of components of a service.
556 557 558 559 560 561 562 563 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 556 def set_status_service_components(cluster_name, service_name, component_name, status) if service_name == nil || cluster_name == nil || component_name == nil || status == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("PUT", "/api/v1/clusters/#{cluster_name}/services/#{service_name}/components/#{component_name}", "{\"ServiceComponentInfo\": {\"state\" : \"#{status}\"}}") end |
#show_cluster(cluster_name, show_host = false, show_components = false) ⇒ Object
Shows the information of a cluster.
204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 204 def show_cluster(cluster_name, show_host=false, show_components=false) if cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end show_host = false unless show_host show_components = false unless show_components fields = "?fields=*" fields += ",services/*" if show_components fields += ",services/components/*" if show_host return launch_request("GET", "/api/v1/clusters/#{cluster_name}#{fields}") end |
#show_cluster_services(cluster_name) ⇒ Object
Shows the services of a cluster.
138 139 140 141 142 143 144 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 138 def show_cluster_services(cluster_name) if cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("GET", "/api/v1/clusters/#{cluster_name}/services") end |
#show_host(cluster_name, host_name) ⇒ Object
Shows information of an host.
395 396 397 398 399 400 401 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 395 def show_host(cluster_name, host_name) if host_name == nil || cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("GET", "/api/v1/clusters/#{cluster_name}/hosts/#{host_name}?fields=*,host_components/*") end |
#show_request(cluster_name, request_id) ⇒ Object
Shows the information of a request.
186 187 188 189 190 191 192 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 186 def show_request(cluster_name, request_id) if cluster_name == nil || request_id == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("GET", "/api/v1/clusters/#{cluster_name}/requests/#{request_id}?fields=tasks/*") end |
#show_requests(cluster_name) ⇒ Object
Shows the requests of a cluster.
170 171 172 173 174 175 176 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 170 def show_requests(cluster_name) if cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("GET", "/api/v1/clusters/#{cluster_name}/requests") end |
#show_service(cluster_name, service_name) ⇒ Object
Shows the list of service of a cluster.
590 591 592 593 594 595 596 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 590 def show_service(cluster_name, service_name) if service_name == nil || cluster_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("GET", "/api/v1/clusters/#{cluster_name}/services/#{service_name}?fields=*,components/ServiceComponentInfo,components/host_components/*") end |
#show_service_components(cluster_name, service_name, component_name) ⇒ Object
Shows information of a type of components of a service.
574 575 576 577 578 579 580 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 574 def show_service_components(cluster_name, service_name, component_name) if service_name == nil || cluster_name == nil ||component_name == nil raise(ArgumentError, 'Arguments can\'t be nil!') end return launch_request("GET", "/api/v1/clusters/#{cluster_name}/services/#{service_name}/components/#{component_name}?fields=host_components/*") end |
#start_host_component(cluster_name, host_name, component_name) ⇒ Object
Starts a component of an host.
299 300 301 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 299 def start_host_component(cluster_name, host_name, component_name) return set_status_host_component(cluster_name, host_name, component_name, "STARTED") end |
#start_service(cluster_name, service_name) ⇒ Object
Starts a service.
473 474 475 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 473 def start_service(cluster_name, service_name) return set_status_service(cluster_name, service_name, "STARTED") end |
#start_service_components(cluster_name, service_name, component_name) ⇒ Object
Starts a type of components of a service.
529 530 531 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 529 def start_service_components(cluster_name, service_name, component_name) return set_status_service_components(cluster_name, service_name, component_name, "STARTED") end |
#stop_host_component(cluster_name, host_name, component_name) ⇒ Object
Stops a component of an host.
312 313 314 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 312 def stop_host_component(cluster_name, host_name, component_name) return set_status_host_component(cluster_name, host_name, component_name, "INSTALLED") end |
#stop_service(cluster_name, service_name) ⇒ Object
Stops a service.
485 486 487 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 485 def stop_service(cluster_name, service_name) return set_status_service(cluster_name, service_name, "INSTALLED") end |
#stop_service_components(cluster_name, service_name, component_name) ⇒ Object
Stops a type of components of a service.
542 543 544 |
# File 'lib/receiver/ambari_rest_api_connector.rb', line 542 def stop_service_components(cluster_name, service_name, component_name) return set_status_service_components(cluster_name, service_name, component_name, "INSTALLED") end |