Class: ManageIQ::ApplianceConsole::MessageServerConfiguration

Inherits:
MessageConfiguration show all
Defined in:
lib/manageiq/appliance_console/message_configuration_server.rb

Constant Summary collapse

PERSISTENT_DIRECTORY =
Pathname.new("/var/lib/kafka/persistent_data").freeze
PERSISTENT_NAME =
"kafka_messages".freeze

Constants inherited from MessageConfiguration

ManageIQ::ApplianceConsole::MessageConfiguration::BASE_DIR, ManageIQ::ApplianceConsole::MessageConfiguration::CONFIG_DIR, ManageIQ::ApplianceConsole::MessageConfiguration::LOGS_DIR, ManageIQ::ApplianceConsole::MessageConfiguration::MIQ_CONFIG_DIR, ManageIQ::ApplianceConsole::MessageConfiguration::SAMPLE_CONFIG_DIR

Instance Attribute Summary collapse

Attributes inherited from MessageConfiguration

#ca_cert_path, #client_properties_path, #config_dir_path, #keystore_dir_path, #keystore_path, #message_keystore_password, #message_keystore_username, #message_server_host, #message_server_port, #messaging_yaml_path, #messaging_yaml_sample_path, #miq_config_dir_path, #sample_config_dir_path, #truststore_path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MessageConfiguration

#already_configured?, #ask_questions, available?, #configure_messaging_yaml, #create_client_properties, #file_contains?, #file_found?, #files_found?, #host_reachable?, #remove_installed_files, #secure?, #secure_client_properties_content, #unsecure_client_properties_content, #valid_environment?

Methods included from ManageiqUserMixin

#manageiq_gid, #manageiq_uid

Constructor Details

#initialize(options = {}) ⇒ MessageServerConfiguration

Returns a new instance of MessageServerConfiguration.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 17

def initialize(options = {})
  super(options)

  @message_server_host           = options[:message_server_use_ipaddr] == true ? my_ipaddr : options[:message_server_host] || my_hostname
  @message_persistent_disk       = LinuxAdmin::Disk.new(:path => options[:message_persistent_disk]) unless options[:message_persistent_disk].nil?

  @jaas_config_path              = config_dir_path.join("kafka_server_jaas.conf")
  @server_properties_path        = config_dir_path.join("server.properties")
  @server_properties_sample_path = sample_config_dir_path.join("server.properties")

  @ca_cert_srl_path              = keystore_dir_path.join("ca-cert.srl")
  @ca_key_path                   = keystore_dir_path.join("ca-key")
  @cert_file_path                = keystore_dir_path.join("cert-file")
  @cert_signed_path              = keystore_dir_path.join("cert-signed")

  @keystore_files  = [ca_cert_path, ca_cert_srl_path, ca_key_path, cert_file_path, cert_signed_path, truststore_path, keystore_path]
  @installed_files = [jaas_config_path, client_properties_path, server_properties_path, messaging_yaml_path, LOGS_DIR] + keystore_files
end

Instance Attribute Details

#ca_cert_srl_pathObject (readonly)

Returns the value of attribute ca_cert_srl_path.



9
10
11
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 9

def ca_cert_srl_path
  @ca_cert_srl_path
end

#ca_key_pathObject (readonly)

Returns the value of attribute ca_key_path.



9
10
11
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 9

def ca_key_path
  @ca_key_path
end

#cert_file_pathObject (readonly)

Returns the value of attribute cert_file_path.



9
10
11
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 9

def cert_file_path
  @cert_file_path
end

#cert_signed_pathObject (readonly)

Returns the value of attribute cert_signed_path.



9
10
11
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 9

def cert_signed_path
  @cert_signed_path
end

#installed_filesObject (readonly)

Returns the value of attribute installed_files.



9
10
11
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 9

def installed_files
  @installed_files
end

#jaas_config_pathObject (readonly)

Returns the value of attribute jaas_config_path.



9
10
11
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 9

def jaas_config_path
  @jaas_config_path
end

#keystore_filesObject (readonly)

Returns the value of attribute keystore_files.



9
10
11
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 9

def keystore_files
  @keystore_files
end

#message_persistent_diskObject (readonly)

Returns the value of attribute message_persistent_disk.



9
10
11
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 9

def message_persistent_disk
  @message_persistent_disk
end

#server_properties_pathObject (readonly)

Returns the value of attribute server_properties_path.



9
10
11
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 9

def server_properties_path
  @server_properties_path
end

#server_properties_sample_pathObject (readonly)

Returns the value of attribute server_properties_sample_path.



9
10
11
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 9

def server_properties_sample_path
  @server_properties_sample_path
end

Class Method Details

.configured?Boolean

Returns:

  • (Boolean)


109
110
111
112
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 109

def self.configured?
  LinuxAdmin::Service.new("kafka").running? ||
    LinuxAdmin::Service.new("zookeeper").running?
end

Instance Method Details

#ask_for_parametersObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 68

def ask_for_parameters
  say("\nMessage Server Parameters:\n\n")

  @message_server_host       = ask_for_string("Message Server Hostname or IP address", message_server_host)

  # SSL Validation for Kafka does not work for hostnames containing "localhost"
  # Therefore we replace with the equivalent IP "127.0.0.1" if a /localhost*/ hostname was entered
  @message_server_host       = "127.0.0.1" if @message_server_host.include?("localhost")

  @message_keystore_username = ask_for_string("Message Keystore Username", message_keystore_username)
  @message_keystore_password = ask_for_password("Message Keystore Password")
  @message_persistent_disk   = ask_for_persistent_disk
end

#ask_for_persistent_diskObject



82
83
84
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 82

def ask_for_persistent_disk
  choose_disk if use_new_disk
end

#choose_diskObject



90
91
92
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 90

def choose_disk
  ask_for_disk("Persistent disk")
end

#configureObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 36

def configure
  begin
    configure_persistent_disk         # Configure the persistent message store on a different disk
    create_jaas_config                # Create the message server jaas config file
    create_client_properties          # Create the client.properties config
    create_logs_directory             # Create the logs directory:
    configure_firewall                # Open the firewall for message port 9093
    configure_keystore                # Populate the Java Keystore
    create_server_properties          # Update the /opt/message/config/server.properties
    configure_messaging_yaml          # Set up the local message client in case EVM is actually running on this, Message Server
    restart_services
  rescue AwesomeSpawn::CommandResultError => e
    say(e.result.output)
    say(e.result.error)
    say("")
    say("Failed to Configure the Message Server- #{e}")
    return false
  rescue => e
    say("Failed to Configure the Message Server- #{e}")
    return false
  end
  true
end

#restart_servicesObject



60
61
62
63
64
65
66
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 60

def restart_services
  say("Starting zookeeper and configure it to start on reboots ...")
  LinuxAdmin::Service.new("zookeeper").start.enable

  say("Starting kafka and configure it to start on reboots ...")
  LinuxAdmin::Service.new("kafka").start.enable
end

#show_parametersObject



94
95
96
97
98
99
100
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 94

def show_parameters
  say("\nMessage Server Configuration:\n")
  say("Message Server Details:\n")
  say("    Message Server Hostname: #{message_server_host}\n")
  say("  Message Keystore Username: #{message_keystore_username}\n")
  say("    Persistent message disk: #{message_persistent_disk.path}\n") if message_persistent_disk
end

#unconfigureObject



102
103
104
105
106
107
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 102

def unconfigure
  super

  unconfigure_firewall
  deactivate_services
end

#use_new_diskObject



86
87
88
# File 'lib/manageiq/appliance_console/message_configuration_server.rb', line 86

def use_new_disk
  agree("Configure a new persistent disk volume? (Y/N): ")
end