Class: Receiver::AmbariReceiver

Inherits:
BasicReceiver show all
Defined in:
lib/receiver/ambari_receiver.rb

Overview

TODO:

Catch the HTTPError and throw a new one with just the error message.

TODO:

Reformat the returned arrays to remove the http notion.

TODO:

Refactor names and private methods below

Class listing all the available methods to interact with Ambari.

Author:

  • tnoguer

Constant Summary collapse

@@hadoop_services_description =
{
    "HDFS" => {
        "MASTER" => %w{NAMENODE SECONDARY_NAMENODE},
        "SLAVE" => %w{DATANODE}},
    "MAPREDUCE" => {
        "MASTER" => %w{JOBTRACKER},
        "SLAVE" => %w{TASKTRACKER}},
    "HIVE" => {
        "MASTER" => %w{HIVE_SERVER},
        "SLAVE" => []},
    "HBASE" => {
        "MASTER" => %w{HBASE_MASTER},
        "SLAVE" => %w{HBASE_REGIONSERVER}},
    "ZOOKEEPER" => {
        "MASTER" => %w{ZOOKEEPER_SERVER},
        "SLAVE" => []},
    "OOZIE" => {
        "MASTER" => %w{OOZIE_SERVER},
        "SLAVE" => []},
    "NAGIOS" => {
        "MASTER" => %w{NAGIOS_SERVER},
        "SLAVE" => []},
    "GANGLIA" => {
        "MASTER" => %w{GANGLIA_SERVER},
        "SLAVE" => []}
}
@@available_actions =
{'START' => {'required_state' => %w{INSTALLED STARTED START_FAILED},
                                       'target_state' => 'STARTED'},
                           'STOP' => {'required_state' => %w{STARTED INSTALLED STOP_FAILED},
                                      'target_state' => 'INSTALLED'},
                           'INSTALL' => {'required_state' => %w{INIT MAINTENANCE INSTALLED INSTALL_FAILED},
 'target_state' => 'INSTALLED'},
                           'DETACH' => {'required_state' => %w{INSTALLED MAINTENANCE},
'target_state' => 'MAINTENANCE'},
                           'DELETE' => {'required_state' => %w{MAINTENANCE},
'target_state' => nil}}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger = nil) ⇒ AmbariReceiver

Default constructor.

Author:

  • tnoguer



136
137
138
139
140
# File 'lib/receiver/ambari_receiver.rb', line 136

def initialize(logger = nil)
  super(logger)
  @rest_connector = Receiver::AmbariRestAPIConnector.new(logger)
  @logger.info("Command::AmbariReceiver   initialize the parameters...")
end

Class Method Details

.get_components_by_service_name(service_name) ⇒ Array<String>

TODO:

throw an exception of type UnknownHadoopService

Get the component list of service_name. It includes master and slave nodes.

Parameters:

  • service_name (String)

    The hadoop service name.

Returns:

  • (Array<String>)

    The list of components.



65
66
67
68
69
70
71
72
73
74
# File 'lib/receiver/ambari_receiver.rb', line 65

def self.get_components_by_service_name(service_name)
  return nil if !valid_service?(service_name) # @todo throw exception

  components = []

  components.concat(@@hadoop_services_description[service_name]["MASTER"])
  components.concat(@@hadoop_services_description[service_name]["SLAVE"])

  return components
end

.get_service_by_component_name(component_name) ⇒ String

TODO:

throw an exception of type UnknownHadoopComponent

Get the component list of service_name. It includes master and slave nodes.

Parameters:

  • component_name (String)

    The hadoop component name.

Returns:

  • (String)

    The related service name.



82
83
84
85
86
87
88
89
90
# File 'lib/receiver/ambari_receiver.rb', line 82

def self.get_service_by_component_name(component_name)
  return nil if !valid_component?(component_name) # @todo throw exception

  @@hadoop_services_description.each do |service_name|
    return service_name if get_components_by_service_name(service_name).include?(component_name)
  end

  return nil
end

.valid_component?(component_name) ⇒ Boolean

Check if component_name is a Hadoop service.

Parameters:

  • component_name (String)

    The Hadoop component name.

Returns:

  • (Boolean)

    true if component_name is a known hadoop component.



104
105
106
107
108
109
# File 'lib/receiver/ambari_receiver.rb', line 104

def self.valid_component?(component_name)
  @@hadoop_services_description.each_key do |service|
    return true if get_component_by_service_name(service).include?(component_name)
  end
  return false
end

.valid_service?(service_name) ⇒ Boolean

Check if service_name is a Hadoop service.

Parameters:

  • service_name (String)

    The Hadoop service name.

Returns:

  • (Boolean)

    true if service_name is a known hadoop service.



96
97
98
# File 'lib/receiver/ambari_receiver.rb', line 96

def self.valid_service?(service_name)
  return true if @@hadoop_services_description.has_key?(service_name)
end

.valid_service_component?(service_name, component_name) ⇒ Boolean

TODO:

throw an exception of type UnknownHadoopService if the service_name doesn’t exists.

TODO:

throw and exception of type UnknownHadoopComponent if the component_name doesn’t exists.

Check if a component is part of a service

Parameters:

  • service_name (String)

    The Hadoop service name.

  • component_name (String)

    The Hadoop component name.

Returns:

  • (Boolean)

    true if component_name is a component of service service_name.



118
119
120
121
122
123
124
125
126
127
# File 'lib/receiver/ambari_receiver.rb', line 118

def self.valid_service_component?(service_name, component_name)
  return nil if !valid_service?(service_name) # @todo throw an exception
  return nil if !valid_component?(component_name) # @todo throw an exception

  @@hadoop_services_description[service_name].each_value do |component|
    return true if component == component_name
  end

  return false
end

Instance Method Details

#add_host(cluster_name, host_name) ⇒ Object

Adds an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host to add.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



486
487
488
# File 'lib/receiver/ambari_receiver.rb', line 486

def add_host(cluster_name, host_name)
  @rest_connector.add_host(cluster_name, host_name)
end

#add_host_component(cluster_name, host_name, component_name) ⇒ Object

Adds a component to an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

  • component_name

    The name of the component to add.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common:AlreadyExistsEntity)

    If the request is invalid.

Author:

  • tnoguer



382
383
384
385
386
387
388
# File 'lib/receiver/ambari_receiver.rb', line 382

def add_host_component(cluster_name, host_name, component_name)
  begin
    @rest_connector.add_host_component(cluster_name, host_name, component_name)
  rescue ClientError => e
    raise Common::AlreadyExistsEntity.new("host component", component_name, e.to_s) if e.code == 409
  end
end

#add_service_component(cluster_name, service_name, component_name) ⇒ Object

Adds a component to a service.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service.

  • component_name

    The name of the component to add.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



620
621
622
# File 'lib/receiver/ambari_receiver.rb', line 620

def add_service_component(cluster_name, service_name, component_name)
  @rest_connector.add_service_component(cluster_name, service_name, component_name)
end

#apply_configuration(cluster_name, configuration_type, configuration_tag) ⇒ Object

Apply a configuration into a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

  • configuration_type

    The type of the configuration to add.

  • configuration_tag

    The tag of the configuration to add.

Returns:

  • The http response.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (HTTPError)

    If the request is invalid.

  • (UnknownEntity)

    If the configuration does not exist.

Author:

  • tnoguer



180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/receiver/ambari_receiver.rb', line 180

def apply_configuration(cluster_name, configuration_type, configuration_tag)

  confs = get_cluster_configurations_list(cluster_name)
  exist = false
  confs.each do |conf|
    if (configuration_type == conf["type"] && configuration_tag == conf["tag"])
      exist = true
    end
  end
  raise Common::UnknownEntity.new("Ambari configuration", "Type: #{configuration_type} Tag: #{configuration_tag}") unless exist

  response = @rest_connector.apply_configuration(cluster_name, configuration_type, configuration_tag)
end

#create_apply_configuration(cluster_name, configuration_type, configuration_tag, configuration_properties) ⇒ Object

Create and apply a configuration into a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

  • configuration_type

    The type of the configuration to add.

  • configuration_tag

    The tag of the configuration to add.

  • configuration_properties

    The hash of properties for the configuration. (ex: 1” => “value”, “Property 2” => “value”)

Returns:

  • The http response.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (HTTPError)

    If the request is invalid.

Author:

  • tnoguer



166
167
168
# File 'lib/receiver/ambari_receiver.rb', line 166

def create_apply_configuration(cluster_name, configuration_type, configuration_tag, configuration_properties)
  @rest_connector.create_apply_configuration(cluster_name, configuration_type, configuration_tag, configuration_properties)
end

#create_configuration(cluster_name, configuration_type, configuration_tag, configuration_properties) ⇒ Object

Create a configuration into a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

  • configuration_type

    The type of the configuration to add.

  • configuration_tag

    The tag of the configuration to add.

  • configuration_properties

    The hash of properties for the configuration. (ex: 1” => “value”, “Property 2” => “value”)

Returns:

  • The http response.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (HTTPError)

    If the request is invalid.

Author:

  • tnoguer



152
153
154
# File 'lib/receiver/ambari_receiver.rb', line 152

def create_configuration(cluster_name, configuration_type, configuration_tag, configuration_properties)
  @rest_connector.create_configuration(cluster_name, configuration_type, configuration_tag, configuration_properties)
end

#define_cluster(cluster_name, cluster_version) ⇒ Object

Defines a new cluster.

Parameters:

  • cluster_name

    The name of the cluster to be defined.

  • cluster_version

    The version of the cluster to be created.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common:HTTPError)

    If the request is invalid.

Author:

  • tnoguer



201
202
203
# File 'lib/receiver/ambari_receiver.rb', line 201

def define_cluster(cluster_name, cluster_version)
  @rest_connector.define_cluster(cluster_name, cluster_version)
end

#define_service(cluster_name, service_name) ⇒ Object

Defines a new service.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service to define.

Raises:

Author:

  • tnoguer



632
633
634
635
636
637
638
# File 'lib/receiver/ambari_receiver.rb', line 632

def define_service(cluster_name, service_name)
  begin
    @rest_connector.define_service(cluster_name, service_name)
  rescue ServerError => e
    raise Common::AlreadyExistsEntity.new("service", service_name, e.to_s) if e.code == 409
  end
end

#delete_cluster(cluster_name) ⇒ Object

Deletes a new cluster.

Parameters:

  • cluster_name

    The name of the cluster to be deleted.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common:HTTPError)

    If the request is invalid.

Author:

  • tnoguer



211
212
213
# File 'lib/receiver/ambari_receiver.rb', line 211

def delete_cluster(cluster_name)
  @rest_connector.delete_cluster(cluster_name)
end

#delete_host(cluster_name, host_name) ⇒ Object

Deletes an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host to delete.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



411
412
413
# File 'lib/receiver/ambari_receiver.rb', line 411

def delete_host(cluster_name, host_name)
  @rest_connector.delete_host(cluster_name, host_name)
end

#delete_host_component(cluster_name, host_name, component_name) ⇒ Object

Deletes a component from an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

  • component_name

    The name of the component to delete.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

  • (Common::InvalideActionSequence)

    If the action can’t be performed on the host component.

Author:

  • tnoguer



399
400
401
402
# File 'lib/receiver/ambari_receiver.rb', line 399

def delete_host_component(cluster_name, host_name, component_name)
  valid_action_host_component('DELETE', cluster_name, host_name, component_name)
  @rest_connector.delete_host_component(cluster_name, host_name, component_name)
end

#delete_service(cluster_name, service_name) ⇒ Object

Deletes a service.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service to delete.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



647
648
649
# File 'lib/receiver/ambari_receiver.rb', line 647

def delete_service(cluster_name, service_name)
  @rest_connector.delete_service(cluster_name, service_name)
end

#detach_host_component(cluster_name, host_name, component_name) ⇒ Int

Detachs a component of an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

  • component_name

    The name of the component to detach.

Returns:

  • (Int)

    The ID of the processing request if there is one, Nil otherwise.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

  • (Common::InvalideActionSequence)

    If the action can’t be performed on the host component.

Author:

  • tnoguer



473
474
475
476
477
# File 'lib/receiver/ambari_receiver.rb', line 473

def detach_host_component(cluster_name, host_name, component_name)
  valid_action_host_component('DETACH', cluster_name, host_name, component_name)
  response = @rest_connector.detach_host_component(cluster_name, host_name, component_name)
  return get_request_id_from_response(response)
end

#execute_method_on_components(method, cluster_name, service_name = nil, host_name = nil, component_type = nil) ⇒ Array (private)

Execute a method passed in parameter for every host component of a cluster

Parameters:

  • method

    The method to be executed. Must be either install_host_component, start_host_component or stop_host_component

  • cluster_name

    The name of the cluster.

  • service_name (defaults to: nil)

    The name of the service, used to filter to this service.. Can be nil.

  • host_name (defaults to: nil)

    The name of the host, used to filter to this host. Can be nil.

  • component_type (defaults to: nil)

    The type of component, used to filter to this component. Can be nil

Returns:

  • (Array)

    The returns of the calls of the method.

Author:

  • tnoguer



775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
# File 'lib/receiver/ambari_receiver.rb', line 775

def execute_method_on_components(method, cluster_name, service_name = nil, host_name = nil, component_type = nil)
  request_ids = []
  data = show_cluster(cluster_name, true, true)
  data['services'].each do |service|
    if service_name == nil || service_name == service['ServiceInfo']['service_name']
      service['components'].each do |component|
        if component_type == nil || component_type == component['ServiceComponentInfo']['component_name']
          component['host_components'].each do |host_component|
            if host_name == nil || host_name == host_component['HostRoles']['host_name']
              begin
                request_ids << method.call(cluster_name, host_component['HostRoles']['host_name'], component['ServiceComponentInfo']['component_name'])
              rescue Common::InvalidActionSequence
                # @todo Do a feedback to the interface that the install of the component was ignored.
              end
            end
          end
        end
      end
    end
  end
  return request_ids
end

#get_cluster_configuration(cluster_name, type, tag) ⇒ Object

Returns the list of configuration of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

  • type

    The type of configuration.

  • tag

    The tag ot configuration.

Returns:

  • The hash of properties of the configuration. (ex: name”=>value,“Property name2”=>value, …}.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (HTTPError)

    If the request is invalid.

  • (UnknownEntity)

    If the configuration does not exist.

Author:

  • tnoguer



277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/receiver/ambari_receiver.rb', line 277

def get_cluster_configuration(cluster_name, type, tag)
  if cluster_name == nil || type == nil || tag == nil
    raise(ArgumentError, 'Arguments can\'t be nil!')
  end

  response = @rest_connector.get_cluster_configuration(cluster_name, type, tag)
  conf = JSON.parse(response.body)
  conf = conf["items"][0]
  if conf.nil?
    raise Common::UnknownEntity.new("Ambari configuration", "Type: #{type} Tag: #{tag}")
  end
  return conf["properties"]
end

#get_cluster_configurations_list(cluster_name) ⇒ Object

Returns the list of configuration of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

Returns:

  • The list of configuration. (ex: [{“active”=>true,“type”=>value,“tag”=>value, …]})

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (HTTPError)

    If the request is invalid.

Author:

  • tnoguer



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/receiver/ambari_receiver.rb', line 246

def get_cluster_configurations_list(cluster_name)
  if cluster_name == nil
    raise(ArgumentError, 'Arguments can\'t be nil!')
  end

  response = @rest_connector.show_cluster(cluster_name)
  confs = JSON.parse(response.body)
  active_confs = confs["Clusters"]["desired_configs"]
  confs = confs["configurations"].sort { |x, y| x["href"] <=> y["href"] }
  confs.each do |conf|
    conf.delete("href")
    conf.delete("Config")
    if (!conf["type"].nil? && active_confs[conf["type"]]["tag"] == conf["tag"])
      conf["active"] = true
    else
      conf["active"] = false
    end
  end
  return confs
end

#get_host_list(cluster_name) ⇒ Array

Gets the list of hosts.

Parameters:

  • cluster_name

    The name of the cluster.

Returns:

  • (Array)

    The list of hosts.

Raises:



495
496
497
498
499
500
501
502
503
# File 'lib/receiver/ambari_receiver.rb', line 495

def get_host_list(cluster_name)
  response = @rest_connector.show_cluster(cluster_name)
  data = JSON.parse(response.body)
  hosts = []
  data["hosts"].each do |host|
    hosts << host["Hosts"]["host_name"]
  end
  return hosts
end

#get_request_id_from_response(response) ⇒ Object (private)

Get the id of the ambari request from the http response when the response code is 202.

Parameters:

  • response (HTTPReseponse)

    The http response.

Returns:

  • The id of the request in case there is one, nil otherwise.

Author:

  • tnoguer



803
804
805
806
807
808
809
# File 'lib/receiver/ambari_receiver.rb', line 803

def get_request_id_from_response(response)
  request_id = nil
  if response.code == '202'
    request_id = JSON.parse(response.body)['Requests']['id']
  end
  return request_id
end

#install_cluster(cluster_name) ⇒ Array

Installs every host components of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



347
348
349
# File 'lib/receiver/ambari_receiver.rb', line 347

def install_cluster(cluster_name)
  return execute_method_on_components(method(:install_host_component), cluster_name)
end

#install_component(cluster_name, component_name) ⇒ Array

Installs a type of components of a service.

Parameters:

  • cluster_name

    The name of the cluster.

  • component_name

    The name of the components to install.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



695
696
697
# File 'lib/receiver/ambari_receiver.rb', line 695

def install_component(cluster_name, component_name)
  return execute_method_on_components(method(:install_host_component), cluster_name, nil, nil, component_name)
end

#install_host(cluster_name, host_name) ⇒ Array

Installs every components of an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



545
546
547
# File 'lib/receiver/ambari_receiver.rb', line 545

def install_host(cluster_name, host_name)
  return execute_method_on_components(method(:install_host_component), cluster_name, nil, host_name)
end

#install_host_component(cluster_name, host_name, component_name) ⇒ Int

Installs a component of an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

  • component_name

    The name of the component to install.

Returns:

  • (Int)

    The ID of the processing request if there is one, Nil otherwise.

Raises:

Author:

  • tnoguer



425
426
427
428
429
# File 'lib/receiver/ambari_receiver.rb', line 425

def install_host_component(cluster_name, host_name, component_name)
  valid_action_host_component('INSTALL', cluster_name, host_name, component_name)
  response = @rest_connector.install_host_component(cluster_name, host_name, component_name)
  return get_request_id_from_response(response)
end

#install_host_components(cluster_name, service_name, host_name) ⇒ Array

Installs every components of a specific service for an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service.

  • host_name

    The name of the host.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



582
583
584
# File 'lib/receiver/ambari_receiver.rb', line 582

def install_host_components(cluster_name, service_name, host_name)
  return execute_method_on_components(method(:install_host_component), cluster_name, service_name, host_name)
end

#install_service(cluster_name, service_name) ⇒ Array

Installs a service.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service to install.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



659
660
661
# File 'lib/receiver/ambari_receiver.rb', line 659

def install_service(cluster_name, service_name)
  return execute_method_on_components(method(:install_host_component), cluster_name, service_name)
end

#list_clustersObject

Shows the list of clusters.

Returns:

  • The result of the request.

Raises:

  • (Common:HTTPError)

    If the request is invalid.

Author:

  • tnoguerr



335
336
337
338
# File 'lib/receiver/ambari_receiver.rb', line 335

def list_clusters
  response = @rest_connector.list_clusters()
  return JSON.parse(response.body)
end

#show_cluster(cluster_name, show_host, show_components) ⇒ Object

Shows the information of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

  • show_host

    True to show the detail of the hosts. False otherwise.

  • show_components

    True to show the detail of the components. False otherwise.

Returns:

  • The result of the request.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common:HTTPError)

    If the request is invalid.

Author:

  • tnoguer



325
326
327
328
# File 'lib/receiver/ambari_receiver.rb', line 325

def show_cluster(cluster_name, show_host, show_components)
  response = @rest_connector.show_cluster(cluster_name, show_host, show_components)
  return JSON.parse(response.body)
end

#show_cluster_hosts(cluster_name) ⇒ Object

Shows the hosts of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

Returns:

  • The result of the request.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common:HTTPError)

    If the request is invalid.

Author:

  • tnoguer



222
223
224
225
# File 'lib/receiver/ambari_receiver.rb', line 222

def show_cluster_hosts(cluster_name)
  response = @rest_connector.show_cluster_hosts(cluster_name)
  return JSON.parse(response.body)
end

#show_cluster_services(cluster_name) ⇒ Object

Shows the services of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

Returns:

  • The result of the request.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common:HTTPError)

    If the request is invalid.

Author:

  • tnoguer



234
235
236
237
# File 'lib/receiver/ambari_receiver.rb', line 234

def show_cluster_services(cluster_name)
  response = @rest_connector.show_cluster_services(cluster_name)
  return JSON.parse(response.body)
end

#show_host(cluster_name, host_name) ⇒ Object

Shows information of an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

Returns:

  • The result of the request

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



513
514
515
516
# File 'lib/receiver/ambari_receiver.rb', line 513

def show_host(cluster_name, host_name)
  response = @rest_connector.show_host(cluster_name, host_name)
  return JSON.parse(response.body)
end

#show_host_component(cluster_name, host_name, component_name) ⇒ Hash

Shows information of an host component.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

  • component_name

    The name of component.

Returns:

  • (Hash)

    The information of the host component.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



527
528
529
530
531
532
533
534
535
# File 'lib/receiver/ambari_receiver.rb', line 527

def show_host_component(cluster_name, host_name, component_name)
  response = @rest_connector.show_host(cluster_name, host_name)
  data = JSON.parse(response.body)
  data["host_components"].each do |component|
    if component["HostRoles"]["component_name"] == component_name
      return component["HostRoles"]
    end
  end
end

#show_request(cluster_name, request_id) ⇒ Object

Shows the requests of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

  • request_id

    The id of the request.

Returns:

  • The result of the request.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common:HTTPError)

    If the request is invalid.

Author:

  • tnoguer



311
312
313
314
# File 'lib/receiver/ambari_receiver.rb', line 311

def show_request(cluster_name, request_id)
  response = @rest_connector.show_request(cluster_name, request_id)
  return JSON.parse(response.body)
end

#show_requests(cluster_name) ⇒ Object

Shows the requests of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

Returns:

  • The result of the request.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common:HTTPError)

    If the request is invalid.

Author:

  • tnoguer



298
299
300
301
# File 'lib/receiver/ambari_receiver.rb', line 298

def show_requests(cluster_name)
  response = @rest_connector.show_requests(cluster_name)
  return JSON.parse(response.body)
end

#show_service(cluster_name, service_name) ⇒ Object

Shows the list of service of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service.

Returns:

  • The result of the request.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



745
746
747
748
# File 'lib/receiver/ambari_receiver.rb', line 745

def show_service(cluster_name, service_name)
  response = @rest_connector.show_service(cluster_name, service_name)
  return JSON.parse(response.body)
end

#show_service_components(cluster_name, service_name, component_name) ⇒ Object

Shows information of a type of components of a service.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service.

  • component_name

    The name of the components.

Returns:

  • The result of the request.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



732
733
734
735
# File 'lib/receiver/ambari_receiver.rb', line 732

def show_service_components(cluster_name, service_name, component_name)
  response = @rest_connector.show_service_components(cluster_name, service_name, component_name)
  return JSON.parse(response.body)
end

#start_cluster(cluster_name) ⇒ Array

Starts every host components of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



358
359
360
# File 'lib/receiver/ambari_receiver.rb', line 358

def start_cluster(cluster_name)
  return execute_method_on_components(method(:start_host_component), cluster_name)
end

#start_component(cluster_name, component_name) ⇒ Array

Starts a type of component.

Parameters:

  • cluster_name

    The name of the cluster.

  • component_name

    The name of the components to start.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



707
708
709
# File 'lib/receiver/ambari_receiver.rb', line 707

def start_component(cluster_name, component_name)
  return execute_method_on_components(method(:start_host_component), cluster_name, nil, nil, component_name)
end

#start_host(cluster_name, host_name) ⇒ Array

Starts every components of an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



557
558
559
# File 'lib/receiver/ambari_receiver.rb', line 557

def start_host(cluster_name, host_name)
  return execute_method_on_components(method(:start_host_component), cluster_name, nil, host_name)
end

#start_host_component(cluster_name, host_name, component_name) ⇒ Int

Starts a component of an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

  • component_name

    The name of the component to start.

Returns:

  • (Int)

    The ID of the processing request if there is one, Nil otherwise.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

  • (Common::InvalideActionSequence)

    If the action can’t be performed on the host component.

Author:

  • tnoguer



441
442
443
444
445
# File 'lib/receiver/ambari_receiver.rb', line 441

def start_host_component(cluster_name, host_name, component_name)
  valid_action_host_component('START', cluster_name, host_name, component_name)
  response = @rest_connector.start_host_component(cluster_name, host_name, component_name)
  return get_request_id_from_response(response)
end

#start_host_components(cluster_name, service_name, host_name) ⇒ Array

Starts every components of a specific service for an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service.

  • host_name

    The name of the host.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



595
596
597
# File 'lib/receiver/ambari_receiver.rb', line 595

def start_host_components(cluster_name, service_name, host_name)
  return execute_method_on_components(method(:start_host_component), cluster_name, service_name, host_name)
end

#start_service(cluster_name, service_name) ⇒ Array

Starts a service.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service to start.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



671
672
673
# File 'lib/receiver/ambari_receiver.rb', line 671

def start_service(cluster_name, service_name)
  return execute_method_on_components(method(:start_host_component), cluster_name, service_name)
end

#stop_cluster(cluster_name) ⇒ Array

Stops every host components of a cluster.

Parameters:

  • cluster_name

    The name of the cluster.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



369
370
371
# File 'lib/receiver/ambari_receiver.rb', line 369

def stop_cluster(cluster_name)
  return execute_method_on_components(method(:stop_host_component), cluster_name)
end

#stop_component(cluster_name, component_name) ⇒ Array

Stops a type of component.

Parameters:

  • cluster_name

    The name of the cluster.

  • component_name

    The name of the components to stops.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



719
720
721
# File 'lib/receiver/ambari_receiver.rb', line 719

def stop_component(cluster_name, component_name)
  return execute_method_on_components(method(:stop_host_component), cluster_name, nil, nil, component_name)
end

#stop_host(cluster_name, host_name) ⇒ Array

Stops every components of an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



569
570
571
# File 'lib/receiver/ambari_receiver.rb', line 569

def stop_host(cluster_name, host_name)
  return execute_method_on_components(method(:stop_host_component), cluster_name, nil, host_name)
end

#stop_host_component(cluster_name, host_name, component_name) ⇒ Int

Stops a component of an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

  • component_name

    The name of the component to stop.

Returns:

  • (Int)

    The ID of the processing request if there is one, Nil otherwise.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

  • (Common::InvalideActionSequence)

    If the action can’t be performed on the host component.

Author:

  • tnoguer



457
458
459
460
461
# File 'lib/receiver/ambari_receiver.rb', line 457

def stop_host_component(cluster_name, host_name, component_name)
  valid_action_host_component('STOP', cluster_name, host_name, component_name)
  response = @rest_connector.stop_host_component(cluster_name, host_name, component_name)
  return get_request_id_from_response(response)
end

#stop_host_components(cluster_name, service_name, host_name) ⇒ Array

Stops every components of a specific service for an host.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service.

  • host_name

    The name of the host.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



608
609
610
# File 'lib/receiver/ambari_receiver.rb', line 608

def stop_host_components(cluster_name, service_name, host_name)
  return execute_method_on_components(method(:stop_host_component), cluster_name, service_name, host_name)
end

#stop_service(cluster_name, service_name) ⇒ Array

Stops a service.

Parameters:

  • cluster_name

    The name of the cluster.

  • service_name

    The name of the service to stop.

Returns:

  • (Array)

    The IDs of the processing requests. Empty if there is no requests.

Raises:

  • (ArgumentError)

    If any argument is nil.

  • (Common::HTTPError)

    If the request is invalid.

Author:

  • tnoguer



683
684
685
# File 'lib/receiver/ambari_receiver.rb', line 683

def stop_service(cluster_name, service_name)
  return execute_method_on_components(method(:stop_host_component), cluster_name, service_name)
end

#valid_action_host_component(action, cluster_name, host_name, component_name) ⇒ Object (private)

Checks if the action is valid on the host component.

Parameters:

  • action

    The action to perform.

  • cluster_name

    The name of the cluster.

  • host_name

    The name of the host.

  • component_name

    The name of the component

Raises:

Author:

  • tnoguer



758
759
760
761
762
763
764
# File 'lib/receiver/ambari_receiver.rb', line 758

def valid_action_host_component(action, cluster_name, host_name, component_name)
  response = show_host_component(cluster_name, host_name, component_name)
  current_state = response["state"]
  unless @@available_actions[action]['required_state'].include?(current_state)
    raise Common::InvalidActionSequence.new(action, current_state, @@available_actions, "#{component_name}/#{host_name}", "host component")
  end
end