Class: Exec::ServiceConfCreate

Inherits:
ExecutableCommand show all
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

Methods inherited from ExecutableCommand

#check_parameters, #create_logger, #run

Constructor Details

#initialize(argv, stdin, stdout, stderr, command_name) ⇒ ServiceConfCreate

Default constructor.

Parameters:

  • argv

    The arguments of the command.

  • stdin (IO)

    The input stream of the command.

  • stdout (IO)

    The output stream of the command.

  • stderr (IO)

    The error stream of the command.

  • command_name (String)

    The name of the executed command.

Author:

  • aboudot



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

#execObject (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.

Parameters:

  • path

    The path to the file.

Returns:

  • The content of the file.



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_optionsObject (private)

Parse and check the parameters of the function.

Author:

  • aboudot



39
40
41
42
43
44
45
46
# File 'lib/exec/service_conf_create.rb', line 39

def set_options
  @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