Skip to content

Commit

Permalink
Merge pull request #196 from agrare/dont_start_evmserverd_if_messagin…
Browse files Browse the repository at this point in the history
…g_not_configured

Don't start evmserverd if messaging is not configured
  • Loading branch information
Fryguy committed Oct 18, 2022
2 parents 5f9346d + 1327aca commit eff5253
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 20 deletions.
10 changes: 8 additions & 2 deletions bin/appliance_console
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@ module ApplianceConsole
version = File.read(VERSION_FILE).chomp if File.exist?(VERSION_FILE)
dbhost = ManageIQ::ApplianceConsole::DatabaseConfiguration.database_host
database = ManageIQ::ApplianceConsole::DatabaseConfiguration.database_name
evm_running = ManageIQ::ApplianceConsole::EvmServer.running?
messaging = ManageIQ::ApplianceConsole::MessageConfiguration.configured?
messaging_broker = ManageIQ::ApplianceConsole::MessageServerConfiguration.configured?
evm_status = if ManageIQ::ApplianceConsole::EvmServer.running?
"running"
elsif ManageIQ::ApplianceConsole::EvmServer.runnable?
"not running"
else
"not configured"
end

summary_attributes = [
summary_entry("Hostname", host),
Expand All @@ -119,7 +125,7 @@ module ApplianceConsole
summary_entry("MAC Address", mac),
summary_entry("Timezone", timezone),
summary_entry("Local Database Server", PostgresAdmin.local_server_status),
summary_entry("#{I18n.t("product.name")} Server", evm_running ? "running" : "not running"),
summary_entry("#{I18n.t("product.name")} Server", evm_status),
summary_entry("#{I18n.t("product.name")} Database", dbhost || "not configured"),
summary_entry("Database/Region", database ? "#{database} / #{region.to_i}" : "not configured"),
summary_entry("Messaging", messaging ? "configured" : "not configured"),
Expand Down
3 changes: 2 additions & 1 deletion lib/manageiq/appliance_console/database_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module ApplianceConsole
class DatabaseConfiguration
include ManageIQ::ApplianceConsole::ManageiqUserMixin

attr_accessor :adapter, :host, :username, :database, :port, :region
attr_accessor :adapter, :host, :username, :database, :port, :region, :run_as_evm_server
attr_reader :password

class ModelWithNoBackingTable < ActiveRecord::Base
Expand All @@ -38,6 +38,7 @@ def initialize(hash = {})
@adapter ||= "postgresql"
# introduced by Logging
self.interactive = true unless hash.key?(:interactive)
self.run_as_evm_server = true unless hash.key?(:run_as_evm_server)
end

def run_interactive
Expand Down
27 changes: 24 additions & 3 deletions lib/manageiq/appliance_console/evm_server.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
module ManageIQ
module ApplianceConsole
class EvmServer
class NotRunnableError < RuntimeError; end

class << self
def running?
service.running?
end

def start!(enable: false)
raise NotRunnableError, "Cannot start #{I18n.t("product.name")}: #{not_runnable_reason}" unless runnable?

service.start(enable)
end

def start(enable: false)
start!(:enable => enable)
rescue AwesomeSpawn::CommandResultError => e
say e.result.output
say e.result.error
say ""
say(e.result.output)
say(e.result.error)
say("")
false
rescue NotRunnableError => e
say(e.to_s)
say("")
false
end

def stop
Expand All @@ -34,6 +43,18 @@ def disable
service.disable
end

def runnable?
DatabaseConfiguration.database_yml_configured? && MessageConfiguration.configured?
end

def not_runnable_reason
if !DatabaseConfiguration.database_yml_configured?
"A Database connection has not been configured."
elsif !MessageConfiguration.configured?
"Messaging has not been configured."
end
end

private

def service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module ManageIQ
module ApplianceConsole
class InternalDatabaseConfiguration < DatabaseConfiguration
attr_accessor :disk, :run_as_evm_server
attr_accessor :disk

DEDICATED_DB_SHARED_BUFFERS = "'1GB'".freeze
SHARED_DB_SHARED_BUFFERS = "'128MB'".freeze
Expand All @@ -24,10 +24,9 @@ def initialize(hash = {})
end

def set_defaults
self.host = 'localhost'
self.username = "root"
self.database = "vmdb_production"
self.run_as_evm_server = true
self.host = 'localhost'
self.username = "root"
self.database = "vmdb_production"
end

def activate
Expand Down
7 changes: 0 additions & 7 deletions lib/manageiq/appliance_console/message_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,7 @@ def host_reachable?(host, what)
true
end

def configure_messaging_type(value)
say(__method__.to_s.tr("_", " ").titleize)

ManageIQ::ApplianceConsole::Utilities.rake_run!("evm:settings:set", ["/prototype/messaging_type=#{value}"])
end

def unconfigure
configure_messaging_type("miq_queue") # Settings.prototype.messaging_type = 'miq_queue'
remove_installed_files
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def configure
configure_messaging_yaml # Set up the local message client in case EVM is actually running on this, Message Server
create_client_properties # Create the client.properties configuration fle
fetch_truststore_from_server # Fetch the Java Keystore from the Kafka Server
configure_messaging_type("kafka") # Settings.prototype.messaging_type = 'kafka'
rescue AwesomeSpawn::CommandResultError => e
say(e.result.output)
say(e.result.error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def configure
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
configure_messaging_type("kafka") # Settings.prototype.messaging_type = 'kafka'
restart_services
rescue AwesomeSpawn::CommandResultError => e
say(e.result.output)
Expand Down

0 comments on commit eff5253

Please sign in to comment.