Class: Exec::ServiceConfGet
- Inherits:
-
ExecutableCommand
- Object
- ExecutableCommand
- Exec::ServiceConfGet
- Defined in:
- lib/exec/service_conf_get.rb
Overview
Allows the user to get the properties of a service configuration.
Instance Attribute Summary
Attributes inherited from ExecutableCommand
#argv, #command_name, #logger, #options, #stderr, #stdin, #stdout, #values
Instance Method Summary collapse
-
#create_file(path, p) ⇒ Object
private
Create a file configuration.
-
#display_configurations(cluster_name = @values["cluster"], type_conf = @values["type"], tag_conf = @values["tag"], prefix = '') ⇒ Object
private
display the configurations of a cluster.
-
#exec ⇒ Object
private
Execution of the command.
-
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ ServiceConfGet
constructor
Default constructor.
-
#set_options ⇒ Object
private
Parse and check the parameters of the function.
-
#store_configuration(cluster_name = @values["cluster"], type_conf = @values["type"], tag_conf = @values["tag"], file_name = nil) ⇒ Object
Store the configuration in a file.
Methods inherited from ExecutableCommand
#check_parameters, #create_logger, #run
Constructor Details
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ ServiceConfGet
Default constructor.
28 29 30 31 |
# File 'lib/exec/service_conf_get.rb', line 28 def initialize(argv, stdin, stdout, stderr, command_name) super(argv, stdin, stdout, stderr, command_name) @configuration_directory = File.dirname(__FILE__) + "/../../resources/ambari-configurations" end |
Instance Method Details
#create_file(path, p) ⇒ Object (private)
Create a file configuration.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/exec/service_conf_get.rb', line 146 def create_file(path, p) if File.exists?(path) raise Common::FileError.new("File already exists in #{path}!") else f = nil begin f = File.new(path.to_s, "w") f.puts(JSON.pretty_generate(p)) rescue => e raise e return false else f.close() end end return true end |
#display_configurations(cluster_name = @values["cluster"], type_conf = @values["type"], tag_conf = @values["tag"], prefix = '') ⇒ Object (private)
display the configurations of a cluster.
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 |
# File 'lib/exec/service_conf_get.rb', line 81 def display_configurations(cluster_name = @values["cluster"], type_conf = @values["type"], tag_conf = @values["tag"], prefix = '') @logger.begin_main_step("listConfigurations") begin properties = Array.new output = Array.new cmd = Command::AmbariGetClusterConfiguration.new(cluster_name, type_conf, tag_conf) data = cmd.exec() return "No properties available on the cluster '#{cluster_name}' with type '#{type_conf}' and tag '#{tag_conf}'.\n" if data.nil? || data.empty? data.each do |name, valeur| properties << "#{name} : #{valeur}\n" end rescue => e raise e end @logger.debug("configuration list output: #{output}") @logger.end_main_step("listConfigurations") properties = properties.sort output << "" output << "Configurations available on the cluster '#{cluster_name}' :" output << "\n\n" output << "#{prefix}Type : #{type_conf}\n" output << "#{prefix}Tag : #{tag_conf}\n" output << "\n" output << "#{prefix}[PROPERTIES : VALUE]\n" properties.each{|propertie| output << "#{prefix}#{propertie}" } output << "\n" return output end |
#exec ⇒ Object (private)
Execution of the command
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 |
# File 'lib/exec/service_conf_get.rb', line 46 def exec() if !@values["cluster"].nil? && !@values["type"].nil? && !@values["tag"].nil? && @values["file"].nil? Color::print_log("NONE", "Display a configuration on the cluster '#{@values["cluster"]}'...", @stdout) output = display_configurations(@values["cluster"], @values["type"], @values["tag"], "\t - ") Color::echo_ok(@stdout) output.each{|conf| @stdout.print conf } elsif !@values["cluster"].nil? && !@values["type"].nil? && !@values["tag"].nil? && !@values["file"].nil? begin Color::print_log("NONE", "Save a configuration in file...", @stdout) if store_configuration(values["cluster"], @values["type"], @values["tag"], @values["file"]) Color::echo_ok(@stdout) else Color::echo_fail(@stdout) end rescue => e @logger.debug(e.) @logger.debug(e.backtrace.join('/n')) raise e end end end |
#set_options ⇒ Object (private)
Parse and check the parameters of the function.
36 37 38 39 40 41 42 |
# File 'lib/exec/service_conf_get.rb', line 36 def @logger.info("setting options") @options.add_option("C", "cluster", "The virtual cluster name where to get configuration.", true, true, method(:check_cluster_name)) @options.add_option("T", "type", "The type that will be get.", true, true) @options.add_option("t", "tag", "The tag that will be get.", true, true) @options.add_option("f", "file", "The the path and fileName where you save configuration.", false, true) end |
#store_configuration(cluster_name = @values["cluster"], type_conf = @values["type"], tag_conf = @values["tag"], file_name = nil) ⇒ Object
Store the configuration in a file
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/exec/service_conf_get.rb', line 126 def store_configuration(cluster_name = @values["cluster"], type_conf = @values["type"], tag_conf = @values["tag"], file_name = nil) cmd=Command::AmbariGetClusterConfiguration.new(cluster_name, type_conf, tag_conf) data = cmd.exec() begin return true if create_file(file_name, data) rescue => e raise e return false end return true end |