Class: Exec::ServiceStop
- Inherits:
-
ExecutableCommand
- Object
- ExecutableCommand
- Exec::ServiceStop
- Defined in:
- lib/exec/service_stop.rb
Overview
Allows the user to stop host components.
Instance Attribute Summary
Attributes inherited from ExecutableCommand
#argv, #command_name, #logger, #options, #stderr, #stdin, #stdout, #values
Instance Method Summary collapse
-
#exec ⇒ Object
private
Execution of the command.
-
#set_options ⇒ Object
private
Parse and check the parameters of the function.
Methods inherited from ExecutableCommand
#check_parameters, #create_logger, #initialize, #run
Constructor Details
This class inherits a constructor from Exec::ExecutableCommand
Instance Method Details
#exec ⇒ Object (private)
Execution of the command
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/exec/service_stop.rb', line 40 def exec begin Color::print_log("NONE", "Checking dependencies...", @stdout) Common::ServicesDescription.get_master_components_depends_on(@values["service"]).each do |dep_master_component| dep_service_name = Common::ServicesDescription.get_service_name_by_comp_name(dep_master_component) data = Command::AmbariServiceComponentInfo.new(dep_service_name, @values["cluster"], dep_master_component).exec stopped = true data["host_components"].each do |host_component| stopped = false if host_component["HostRoles"]["status"] != "STOPPED" end raise MissingDependency.new("Master component #{dep_master_component} has to be stopped before stop #{@values["service"]} service.") unless stopped end Color::echo_ok(@stdout) rescue CloudboxError => e Color::echo_fail(@stdout) raise e end msg = "Unknown combination of attributes... (should never happend)" cmd = nil if (!@values["host"].nil? && !@values["component"].nil?) || (!@values["service"].nil? && !@values["host"].nil? && !@values["component"].nil?) # 3 # one component on one host msg = "Stop components #{@values["component"]} on host #{@values["host"]} (@cluster #{@values["cluster"]})." cmd = Command::AmbariStopHostComponent.new(@values["cluster"], @values["component"], @values["host"]) elsif !@values["component"].nil? || (!@values["service"].nil? && !@values["component"].nil?) # 1 # one component on all hosts msg = "Stop all components (@cluster #{@values["cluster"]})." cmd = Command::AmbariStopComponent.new(@values["cluster"], @values["component"]) elsif !@values["service"].nil? && !@values["host"].nil? # 5 # all component on one host for one service # @todo it is the same case than number 3 msg = "Stop components #{@values["component"]} of service #{@values["service"]} on host #{@values["host"]} (@cluster #{@values["cluster"]})." cmd = Command::AmbariStopHostComponents.new(@values["cluster"], @values["service"], @values["host"]) elsif !@values["host"].nil? # 2 # all component on one host msg = "Stop all components on host #{@values["host"]} (@cluster #{@values["cluster"]})." cmd = Command::AmbariStopHost.new(@values["cluster"], @values["host"]) elsif !@values["service"].nil? # 4 # all component on all hosts for one service msg = "Stop all components #{@values["component"]} of service #{@values["service"]} on all hosts (@cluster #{@values["cluster"]})." cmd = Command::AmbariStopServiceComponents.new(@values["cluster"], @values["service"]) elsif @values["service"].nil? && @values["host"].nil? && @values["component"].nil? # 6 # all component on all host for all service msg = "Stop all components of all services on all hosts (@cluster #{@values["cluster"]})." cmd = Command::AmbariStopCluster.new(@values["cluster"]) else raise StandardError(msg) end Color::print_log("NONE", msg, @stdout) cmd.exec() Color::echo_ok(@stdout) end |
#set_options ⇒ Object (private)
Parse and check the parameters of the function.
28 29 30 31 32 33 34 35 |
# File 'lib/exec/service_stop.rb', line 28 def @logger.info("setting options") @options.add_option("C", "cluster", "The virtual cluster name.", true, true, method(:check_cluster_name)) @options.add_option("s", "service", "Limit request to this service.", false, true, method(:check_hadoop_service_name)) @options.add_option("H", "host", "Limit request to this host.", false, true, method(:check_ambari_host_name)) @options.add_option("c", "component", "Limit request to this component type.", false, true, method(:check_hadoop_component_name)) @options.add_option("f", "follow", "Follow completion of the request.", false) end |