Class: Exec::ServiceConfCreate
- Inherits:
-
ExecutableCommand
- Object
- ExecutableCommand
- Exec::ServiceConfCreate
- Defined in:
- lib/exec/service_conf_create.rb
Overview
Allows the user to create a service configuration.
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.
-
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ ServiceConfCreate
constructor
Default constructor.
-
#read_files(path) ⇒ Object
private
Reads a json configuration file and returns its content.
-
#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) ⇒ ServiceConfCreate
Default constructor.
31 32 33 34 |
# File 'lib/exec/service_conf_create.rb', line 31 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
#exec ⇒ Object (private)
Execution of the command
50 51 52 53 54 55 56 57 58 |
# File 'lib/exec/service_conf_create.rb', line 50 def exec() if !@values["cluster"].nil? && !@values["type"].nil? && !@values["tag"].nil? && !@values["fileName"].nil? Color::print_log("NONE", "Create a configuration on a cluster...", @stdout) properties=read_files(@values["fileName"]) cmd=Command::AmbariCreateClusterConfiguration.new(@values['cluster'], @values['type'], @values['tag'], properties, @values['Apply']) cmd.exec() end end |
#read_files(path) ⇒ Object (private)
Reads a json configuration file and returns its content.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/exec/service_conf_create.rb', line 63 def read_files(path) if File.exists?(path) begin f = nil f = File.open(path, "r") p=JSON.parse(f.read) return p rescue => e raise e else f.close() end end end |
#set_options ⇒ Object (private)
Parse and check the parameters of the function.
39 40 41 42 43 44 45 46 |
# File 'lib/exec/service_conf_create.rb', line 39 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", "fileName", "The path and fileName where you save configuration.", false, true) @options.add_option("a", "Apply", "Apply configuration to a cluster", false, false) end |