modules/enterprise/server/appserver/src/main/bin-resources/bin/rhq-installer.bat | 2
modules/enterprise/server/appserver/src/main/bin-resources/bin/rhq-installer.sh | 2
modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/Installer.java | 29 +-
modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/InstallerService.java | 20 +
modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/InstallerServiceImpl.java | 139 ++++++----
5 files changed, 134 insertions(+), 58 deletions(-)
New commits:
commit ebcaebf8ca7c0ade8cafe3731c72da2ea7fdce7a
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Dec 21 11:58:05 2012 -0500
allow for a user to do a dbsetup without having to do a full install. we had some people ask for this, its a rare use-case, but it can be useful. also useful for devs .. rhq-installer.sh --setupdb (or use the shorthand "-b" option)
diff --git a/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/Installer.java b/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/Installer.java
index 9f7b619..909a39e 100644
--- a/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/Installer.java
+++ b/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/Installer.java
@@ -46,7 +46,7 @@ public class Installer {
private InstallerConfiguration installerConfig;
private enum WhatToDo {
- DISPLAY_USAGE, DO_NOTHING, TEST, LIST_SERVERS, INSTALL
+ DISPLAY_USAGE, DO_NOTHING, TEST, SETUPDB, LIST_SERVERS, INSTALL
}
public static void main(String[] args) {
@@ -96,6 +96,18 @@ public class Installer {
}
continue;
}
+ case SETUPDB: {
+ try {
+ final InstallerService installerService = new InstallerServiceImpl(installerConfig);
+ final HashMap<String, String> serverProperties = installerService.getServerProperties();
+ installerService.prepareDatabase(serverProperties, null, null);
+ LOG.info("Database setup is complete.");
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ System.exit(EXIT_CODE_INSTALLATION_ERROR);
+ }
+ continue;
+ }
case INSTALL: {
try {
final InstallerService installerService = new InstallerServiceImpl(installerConfig);
@@ -131,22 +143,25 @@ public class Installer {
usage.append("\t--port=<port>, -p: talk to the app server over this management port").append("\n");
usage.append("\t--test, -t: test the validity of the server properties (install not performed)").append("\n");
usage.append("\t--listservers, -l: show list of known installed servers (install not performed)").append("\n");
+ usage.append("\t--setupdb, -b: only perform database schema creation or update").append("\n");
usage.append("\t--dbpassword, -d: encodes a DB password for rhq-server.properties (install not performed)")
.append("\n");
LOG.info(usage);
}
private WhatToDo[] processArguments(String[] args) throws Exception {
- String sopts = "-:HD:h:p:d:lt";
+ String sopts = "-:HD:h:p:d:blt";
LongOpt[] lopts = { new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'H'),
new LongOpt("host", LongOpt.REQUIRED_ARGUMENT, null, 'h'),
new LongOpt("port", LongOpt.REQUIRED_ARGUMENT, null, 'p'),
new LongOpt("dbpassword", LongOpt.REQUIRED_ARGUMENT, null, 'd'),
+ new LongOpt("setupdb", LongOpt.NO_ARGUMENT, null, 'b'),
new LongOpt("listservers", LongOpt.NO_ARGUMENT, null, 'l'),
new LongOpt("test", LongOpt.NO_ARGUMENT, null, 't') };
boolean test = false;
boolean listservers = false;
+ boolean setupdb = false;
String dbpassword = null;
Getopt getopt = new Getopt("installer", args, sopts, lopts);
@@ -217,6 +232,11 @@ public class Installer {
break;
}
+ case 'b': {
+ setupdb = true;
+ break; // don't return, in case we need to allow more args
+ }
+
case 'l': {
listservers = true;
break; // don't return, we need to allow more args to be processed, like -p or -h
@@ -236,11 +256,14 @@ public class Installer {
return new WhatToDo[] { WhatToDo.DO_NOTHING };
}
- if (test || listservers) {
+ if (test || setupdb || listservers) {
ArrayList<WhatToDo> whatToDo = new ArrayList<WhatToDo>();
if (test) {
whatToDo.add(WhatToDo.TEST);
}
+ if (setupdb) {
+ whatToDo.add(WhatToDo.SETUPDB);
+ }
if (listservers) {
whatToDo.add(WhatToDo.LIST_SERVERS);
}
diff --git a/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/InstallerService.java b/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/InstallerService.java
index d597d29..6eff4b7 100644
--- a/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/InstallerService.java
+++ b/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/InstallerService.java
@@ -101,6 +101,26 @@ public interface InstallerService {
throws AutoInstallDisabledException, AlreadyInstalledException, Exception;
/**
+ * Prepares the database. This is either going to do a full clean db setup or a db upgrade
+ * depending on the existingSchemaOption parameter unless autoinstall setting is on, in which case
+ * the autoinstall schema setting in serverProperties parameter will tell this method what to do.
+ * NOTE: if not in auto-install mode, the database password is assumed to be in clear text (i.e. unencoded).
+ * If in auto-install mode, the database password must be encoded already.
+ *
+ * @param serverProperties the server's settings to use. These will be persisted to
+ * the server's .properties file.
+ * @param serverDetails details on the server being installed.
+ * If in auto-install mode, this value is ignored and can be anything.
+ * @param existingSchemaOption if not in auto-install mode, this tells the installer what to do with any
+ * existing schema. Must be one of the names of the
+ * {@link ServerInstallUtil.ExistingSchemaOption} enum.
+ * If in auto-install mode, this value is ignored and can be anything.
+ * @throws Exception failed to successfully prepare the database
+ */
+ void prepareDatabase(HashMap<String, String> serverProperties, ServerDetails serverDetails,
+ String existingSchemaOption) throws Exception;
+
+ /**
* Returns a list of all registered servers in the database.
*
* @param connectionUrl
diff --git a/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/InstallerServiceImpl.java b/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/InstallerServiceImpl.java
index 81dcdd0..7006601 100644
--- a/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/InstallerServiceImpl.java
+++ b/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/InstallerServiceImpl.java
@@ -229,6 +229,54 @@ public class InstallerServiceImpl implements InstallerService {
"It looks like the installation has already been completed - there is nothing for the installer to do.");
}
+ prepareDatabase(serverProperties, serverDetails, existingSchemaOption);
+
+ String appServerConfigDir = getAppServerConfigDir();
+
+ // create an rhqadmin/rhqadmin management user so when discovered, the AS7 plugin can immediately
+ // connect to the RHQ Server.
+ ServerInstallUtil.createDefaultManagementUser(serverDetails, appServerConfigDir);
+
+ // perform stuff that has to get done via the JBossAS management client
+ ModelControllerClient mcc = null;
+ try {
+ mcc = getModelControllerClient();
+
+ // ensure the server info is up to date and stored in the DB
+ ServerInstallUtil.setSocketBindings(mcc, serverProperties);
+
+ // Make sure our deployment scanner is configured as we need it
+ ServerInstallUtil.configureDeploymentScanner(mcc);
+
+ // create a keystore whose cert has a CN of this server's public endpoint address
+ ServerInstallUtil.prepareWebConnectors(mcc, serverDetails, appServerConfigDir, serverProperties);
+ } finally {
+ safeClose(mcc);
+ }
+
+ // now create our deployment services and our main EAR
+ deployServices(serverProperties);
+
+ // deploy the main EAR app startup module extension
+ deployAppExtension();
+
+ // some of the changes we made require the app server container to reload before we can deploy the app
+ reloadConfiguration();
+
+ // we need to wait for the reload to finish - wait until we can connect again
+ testModelControllerClient(60);
+
+ // deploy the main EAR app subsystem - this is the thing that contains and actually deploys the EAR
+ deployAppSubsystem();
+
+ return;
+ }
+
+ @Override
+ public void prepareDatabase(HashMap<String, String> serverProperties, ServerDetails serverDetails,
+ String existingSchemaOption) throws Exception {
+
+ // since we are going to write out the properties file, we need to make sure the properties are valid
verifyDataFormats(serverProperties);
// if we are in auto-install mode, ignore the server details passed in and build our own using the given server properties
@@ -237,6 +285,9 @@ public class InstallerServiceImpl implements InstallerService {
if (autoInstallMode) {
serverDetails = getServerDetailsFromPropertiesOnly(serverProperties);
} else {
+ if (serverDetails == null) {
+ throw new Exception("Auto-installation is disabled and cannot determine server details");
+ }
if (ServerInstallUtil.isEmpty(serverDetails.getName())) {
throw new Exception("Please enter a server name");
}
@@ -339,7 +390,7 @@ public class InstallerServiceImpl implements InstallerService {
throw new Exception("Cannot connect to the database: " + testConnectionErrorMessage);
}
- // write the new properties to the rhq-server.properties file
+ // write the new properties to the rhq-server.properties file (this ensures the encoded password is written out)
saveServerProperties(serverProperties);
// Prepare the db schema.
@@ -357,20 +408,21 @@ public class InstallerServiceImpl implements InstallerService {
try {
if (ExistingSchemaOption.SKIP != existingSchemaOptionEnum) {
+ String dbSetupLogDir = getDatabaseSetupLogDir();
if (isDatabaseSchemaExist(dbUrl, dbUsername, clearTextDbPassword)) {
if (ExistingSchemaOption.OVERWRITE == existingSchemaOptionEnum) {
log("Database schema exists but installer was told to overwrite it - a new schema will be created now.");
ServerInstallUtil.createNewDatabaseSchema(serverProperties, serverDetails, clearTextDbPassword,
- getLogDir());
+ dbSetupLogDir);
} else {
log("Database schema exists - it will now be updated.");
ServerInstallUtil.upgradeExistingDatabaseSchema(serverProperties, serverDetails,
- clearTextDbPassword, getLogDir());
+ clearTextDbPassword, dbSetupLogDir);
}
} else {
log("Database schema does not yet exist - it will now be created.");
ServerInstallUtil.createNewDatabaseSchema(serverProperties, serverDetails, clearTextDbPassword,
- getLogDir());
+ dbSetupLogDir);
}
} else {
log("Ignoring database schema - installer will assume it exists and is already up-to-date.");
@@ -381,46 +433,6 @@ public class InstallerServiceImpl implements InstallerService {
// ensure the server info is up to date and stored in the DB
ServerInstallUtil.storeServerDetails(serverProperties, clearTextDbPassword, serverDetails);
-
- String appServerConfigDir = getAppServerConfigDir();
-
- // create an rhqadmin/rhqadmin management user so when discovered, the AS7 plugin can immediately
- // connect to the RHQ Server.
- ServerInstallUtil.createDefaultManagementUser(serverDetails, appServerConfigDir);
-
- // perform stuff that has to get done via the JBossAS management client
- ModelControllerClient mcc = null;
- try {
- mcc = getModelControllerClient();
-
- // ensure the server info is up to date and stored in the DB
- ServerInstallUtil.setSocketBindings(mcc, serverProperties);
-
- // Make sure our deployment scanner is configured as we need it
- ServerInstallUtil.configureDeploymentScanner(mcc);
-
- // create a keystore whose cert has a CN of this server's public endpoint address
- ServerInstallUtil.prepareWebConnectors(mcc, serverDetails, appServerConfigDir, serverProperties);
- } finally {
- safeClose(mcc);
- }
-
- // now create our deployment services and our main EAR
- deployServices(serverProperties);
-
- // deploy the main EAR app startup module extension
- deployAppExtension();
-
- // some of the changes we made require the app server container to reload before we can deploy the app
- reloadConfiguration();
-
- // we need to wait for the reload to finish - wait until we can connect again
- testModelControllerClient(60);
-
- // deploy the main EAR app subsystem - this is the thing that contains and actually deploys the EAR
- deployAppSubsystem();
-
- return;
}
@Override
@@ -655,16 +667,37 @@ public class InstallerServiceImpl implements InstallerService {
}
}
- private String getLogDir() throws Exception {
- ModelControllerClient mcc = null;
- try {
- mcc = getModelControllerClient();
- final CoreJBossASClient client = new CoreJBossASClient(mcc);
- final String dir = client.getAppServerLogDir();
- return dir;
- } finally {
- safeClose(mcc);
+ private String getDatabaseSetupLogDir() throws Exception {
+
+ File logDir;
+
+ // Our installer normally sets this sysprop - so use it for our log dir.
+ // If we don't have a log dir sysprop (don't know why we wouldn't), just create a tmp location.
+ final String installerLogDirStr = System.getProperty("rhq.server.installer.logdir");
+ if (installerLogDirStr != null) {
+ logDir = new File(installerLogDirStr);
+ logDir.mkdirs();
+ if (!logDir.isDirectory()) {
+ throw new Exception("Cannot create installer log directory: " + logDir);
+ }
+ } else {
+ final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
+ if (!tmpDir.isDirectory()) {
+ log("Missing tmp dir [" + tmpDir + "]; will use current directory to store logs");
+ logDir = new File(".");
+ } else {
+ logDir = new File(tmpDir, "rhq-installer-db");
+ logDir.mkdir();
+ if (!logDir.isDirectory()) {
+ log("Cannot create database setup log directory [" + logDir + "]; will use current directory");
+ logDir = new File(".");
+ }
+ }
}
+
+ final String logDirPath = logDir.getAbsolutePath();
+ log("Database setup log file directory: " + logDirPath);
+ return logDirPath;
}
private File getServerPropertiesFile() throws Exception {
commit 5443514da7b5a5bf85f50afde30667e079463339
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Dec 21 11:48:22 2012 -0500
dbsetup stuff uses the old i18nlog still and we need to tell it to not use log4j because otherwise it looks like the log messages aren't getting spit out (log4j isn't configured)
diff --git a/modules/enterprise/server/appserver/src/main/bin-resources/bin/rhq-installer.bat b/modules/enterprise/server/appserver/src/main/bin-resources/bin/rhq-installer.bat
index 3140467..811aa17 100644
--- a/modules/enterprise/server/appserver/src/main/bin-resources/bin/rhq-installer.bat
+++ b/modules/enterprise/server/appserver/src/main/bin-resources/bin/rhq-installer.bat
@@ -117,7 +117,7 @@ if not defined RHQ_SERVER_INSTALLER_JAVA_OPTS set RHQ_SERVER_INSTALLER_JAVA_OPTS
rem Add the JVM opts that we always want to specify, whether or not the user set RHQ_SERVER_INSTALLER_JAVA_OPTS.
if defined RHQ_SERVER_DEBUG set _RHQ_LOGLEVEL=DEBUG
if not defined RHQ_SERVER_DEBUG set _RHQ_LOGLEVEL=INFO
-set RHQ_SERVER_INSTALLER_JAVA_OPTS=%RHQ_SERVER_INSTALLER_JAVA_OPTS% -Djava.awt.headless=true -Drhq.server.properties-file=%RHQ_SERVER_HOME%\bin\rhq-server.properties -Drhq.server.installer.logdir=%RHQ_SERVER_HOME%\logs -Drhq.server.installer.loglevel=%_RHQ_LOGLEVEL%
+set RHQ_SERVER_INSTALLER_JAVA_OPTS=%RHQ_SERVER_INSTALLER_JAVA_OPTS% -Djava.awt.headless=true -Di18nlog.logger-type=commons -Drhq.server.properties-file=%RHQ_SERVER_HOME%\bin\rhq-server.properties -Drhq.server.installer.logdir=%RHQ_SERVER_HOME%\logs -Drhq.server.installer.loglevel=%_RHQ_LOGLEVEL%
rem Sample JPDA settings for remote socket debugging
rem RHQ_SERVER_INSTALLER_JAVA_OPTS=%RHQ_SERVER_INSTALLER_JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y
diff --git a/modules/enterprise/server/appserver/src/main/bin-resources/bin/rhq-installer.sh b/modules/enterprise/server/appserver/src/main/bin-resources/bin/rhq-installer.sh
index 969773f..ddcde6c 100755
--- a/modules/enterprise/server/appserver/src/main/bin-resources/bin/rhq-installer.sh
+++ b/modules/enterprise/server/appserver/src/main/bin-resources/bin/rhq-installer.sh
@@ -214,7 +214,7 @@ else
_RHQ_LOGLEVEL="INFO"
fi
-RHQ_SERVER_INSTALLER_JAVA_OPTS="${RHQ_SERVER_INSTALLER_JAVA_OPTS} -Djava.awt.headless=true -Drhq.server.properties-file=${RHQ_SERVER_HOME}/bin/rhq-server.properties -Drhq.server.installer.logdir=${RHQ_SERVER_HOME}/logs -Drhq.server.installer.loglevel=${_RHQ_LOGLEVEL}"
+RHQ_SERVER_INSTALLER_JAVA_OPTS="${RHQ_SERVER_INSTALLER_JAVA_OPTS} -Djava.awt.headless=true -Di18nlog.logger-type=commons -Drhq.server.properties-file=${RHQ_SERVER_HOME}/bin/rhq-server.properties -Drhq.server.installer.logdir=${RHQ_SERVER_HOME}/logs -Drhq.server.installer.loglevel=${_RHQ_LOGLEVEL}"
# Sample JPDA settings for remote socket debugging
#RHQ_SERVER_INSTALLER_JAVA_OPTS="${RHQ_SERVER_INSTALLER_JAVA_OPTS} -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"