Class: Exec::ServiceAdd
- Inherits:
-
ExecutableCommand
- Object
- ExecutableCommand
- Exec::ServiceAdd
- Defined in:
- lib/exec/service_add.rb
Overview
Allows user to add a new service to the ambari cluster
Instance Attribute Summary
Attributes inherited from ExecutableCommand
#argv, #command_name, #logger, #options, #stderr, #stdin, #stdout, #values
Instance Method Summary collapse
-
#configure_service(cluster_name, service_name, conf_dir) ⇒ Object
private
Adds the default configurations for the service.
-
#create_common_default_conf(cluster_name, conf_type, dir) ⇒ Object
private
Creates and applies a default configuration into the cluster.
-
#exec ⇒ Object
private
Execution of the command.
-
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ ServiceAdd
constructor
Default constructor.
-
#set_options ⇒ Object
private
Parse and check the parameters of the function.
Methods inherited from ExecutableCommand
#check_parameters, #create_logger, #run
Constructor Details
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ ServiceAdd
Default constructor.
39 40 41 42 43 |
# File 'lib/exec/service_add.rb', line 39 def initialize(argv, stdin, stdout, stderr, command_name) super(argv, stdin, stdout, stderr, command_name) @configuration_directory = File.dirname(__FILE__) + "/../../resources/ambari-configurations" @jdk_home = '/usr/jdk64/jdk1.6.0_31' end |
Instance Method Details
#configure_service(cluster_name, service_name, conf_dir) ⇒ Object (private)
Adds the default configurations for the service.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/exec/service_add.rb', line 158 def configure_service(cluster_name, service_name, conf_dir) @logger.begin_main_step("configureServices") @logger.debug("Getting configuration list") confs = Command::.new(cluster_name).exec() @logger.debug("confs:\n" + confs.to_s) core_site = false global = false confs.each do |conf| if conf["type"] == "core-site" core_site = true elsif conf["type"] == "global" global = true end end @logger.debug("check if global already exists") if !global create_common_default_conf(cluster_name, "global", conf_dir) end @logger.debug("check if default core-site already exists") if !core_site create_common_default_conf(cluster_name, "core-site", conf_dir) end conf_name = Common::ServicesDescription.get_config_name_service(@values["service"]) unless conf_name.nil? service_configs_path = conf_dir + "/" + service_name raise(StandardError, "Default configuration directory doesn't exists for service #{service_name}: #{service_configs_path.to_s}") if !File.directory?(service_configs_path) @logger.debug("adding needed configuration #{conf_name}") create_common_default_conf(cluster_name, conf_name, service_configs_path) end end |
#create_common_default_conf(cluster_name, conf_type, dir) ⇒ Object (private)
Creates and applies a default configuration into the cluster.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/exec/service_add.rb', line 202 def create_common_default_conf(cluster_name, conf_type, dir) @logger.debug("default #{conf_type} doesn't already exists!") file_path = dir + "/default_#{conf_type}" raise(StandardError, "Default #{conf_type} configuration doesn't exists: #{file_path}") if !File.file?(file_path) file = File.open(file_path, "r") if conf_type == "hbase-site" zk_server=[] zk = Command::.new("ZOOKEEPER", @values["cluster"], "ZOOKEEPER_SERVER").exec zk["host_components"].each do |component| zk_server.push(component["HostRoles"]["host_name"]) end zk_host = zk_server.join(",") data = file.read.gsub("__MASTERNODE__", @values["master"].to_s).gsub("__HOST_ZOOKEEPER__", zk_host.to_s) else data = file.read.gsub("__MASTERNODE__", @values["master"].to_s).gsub("__JDK_HOME__", @jdk_home.to_s) end properties = JSON.parse(data) Command::.new(cluster_name, conf_type, "default", properties, true).exec() @logger.debug("default #{conf_type} created") end |
#exec ⇒ Object (private)
Execution of the command.
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/exec/service_add.rb', line 58 def exec begin Color::print_log("NONE", "Checking dependencies...", @stdout) services = [] Command::.new(@values["cluster"]).exec["items"].each do |service| services.push(service["ServiceInfo"]["service_name"]) end Common::ServicesDescription.get_deps(@values["service"]).each do |deps_name| raise MissingDependency.new("Service(s) #{Common::ServicesDescription.get_deps(@values["service"]).join(", ")} has to be defined in cluster before add #{@values["service"]} service.") unless services.include?(deps_name) end Color::echo_ok(@stdout) if @values["service"] == "HBASE" data = Command::.new("HDFS", @values["cluster"], "NAMENODE").exec data["host_components"].each do |component| if component["HostRoles"]["state"] == "STARTED" raise Common::AddServiceHbaseError.new("The service HDFS must be Stopped for add service HBASE and restart after add service ") end end end Color::print_log("NONE", "Adding service on cluster...", @stdout) Command::.new(@values["cluster"], @values["service"]).exec() Color::echo_ok(@stdout) rescue CloudboxError => e Color::echo_fail(@stdout) raise e end begin if @values["service"] == "ZOOKEEPER" or @values["service"]=="HBASE" Common::ServicesDescription.get_master_nodes(@values["service"]).each do |component_name| Color::print_log("NONE", "Adding ZOOKEEPER_HOST component #{component_name} on master node...") list_host=[] list_host= (@values["master"]).delete(' ').split(",") list_host.each do |host| Command::.new(@values["cluster"], component_name,host ).exec end end else Common::ServicesDescription.get_master_nodes(@values["service"]).each do |component_name| begin Color::print_log("NONE", "Adding master component #{component_name} on master node...") Command::.new(@values["cluster"], component_name, @values["master"]).exec() Color::echo_ok(@stdout) rescue AlreadyExistsEntity => e Color::echo_warn(@stdout) @stdout.puts(e) end end end Common::ServicesDescription.get_slave_nodes_on_master(@values["service"]).each do |component_name| begin Color::print_log("NONE", "Adding slave component #{component_name} on master node...") Command::.new(@values["cluster"], component_name, @values["master"]).exec() Color::echo_ok(@stdout) rescue AlreadyExistsEntity => e Color::echo_warn(@stdout) @stdout.puts(e) end end Common::ServicesDescription.get_slave_nodes(@values["service"]).each do |component_name| begin Color::print_log("NONE", "Adding slave component #{component_name} on other nodes...") Command::.new(@values["cluster"]).exec().each do |host_name| unless host_name == @values["master"] Command::.new(@values["cluster"], component_name, host_name).exec() end end Color::echo_ok(@stdout) rescue AlreadyExistsEntity => e Color::echo_warn(@stdout) @stdout.puts(e) end end Color::print_log("NONE", "Setting up default configurations...") configure_service(@values["cluster"], @values["service"], @configuration_directory) Color::echo_ok(@stdout) rescue => e Color::echo_fail(@stdout) @stdout.puts "Deleting service..." Command::.new(@values["cluster"], @values["service"]).exec() raise e end end |
#set_options ⇒ Object (private)
Parse and check the parameters of the function.
48 49 50 51 52 53 |
# File 'lib/exec/service_add.rb', line 48 def @logger.info("setting options") .add_option("C", "cluster", "The virtual cluster name where to list services.", true, true, method(:check_cluster_name)) .add_option("s", "service", "The service that will be add.", true, true, method(:check_hadoop_service_name)) .add_option("m", "master", "The master node of the service.", true, true) end |