[rhq] Branch 'rhq-on-as7' - modules/enterprise
mazz
mazz at fedoraproject.org
Sat Aug 4 05:53:30 UTC 2012
modules/enterprise/gui/installer/pom.xml | 7
modules/enterprise/gui/installer/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java | 51 +++-
modules/enterprise/gui/installer/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java | 125 ++++++++++
3 files changed, 179 insertions(+), 4 deletions(-)
New commits:
commit 08a5d79de93d68f67e6dd70714054142bfe447ff
Author: John Mazzitelli <mazz at redhat.com>
Date: Sat Aug 4 01:53:26 2012 -0400
gwt installer now does dbsetup/dbupgrade and sets up the HA server info in the db
diff --git a/modules/enterprise/gui/installer/pom.xml b/modules/enterprise/gui/installer/pom.xml
index b784cb6..131e893 100644
--- a/modules/enterprise/gui/installer/pom.xml
+++ b/modules/enterprise/gui/installer/pom.xml
@@ -66,6 +66,13 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <!-- need this solely for SecurityUtils -->
+ <groupId>org.rhq</groupId>
+ <artifactId>rhq-enterprise-comm</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
<!-- dbutils has transitive dep on ant-launcher but with test scope - installer needs it for real -->
<dependency>
<groupId>ant</groupId>
diff --git a/modules/enterprise/gui/installer/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java b/modules/enterprise/gui/installer/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
index 4b16898..fcc8a51 100644
--- a/modules/enterprise/gui/installer/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
+++ b/modules/enterprise/gui/installer/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
@@ -86,9 +86,21 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
}
// if we are in auto-install mode, ignore the server details passed in and build our own using the given server properties
+ // if not in auto-install mode, make sure user gave us the server details that we will need
boolean autoInstallMode = ServerInstallUtil.isAutoinstallEnabled(serverProperties);
if (autoInstallMode) {
serverDetails = getServerDetailsFromPropertiesOnly(serverProperties);
+ } else {
+ if (ServerInstallUtil.isEmpty(serverDetails.getName())) {
+ throw new Exception("Please enter a server name");
+ }
+ if (ServerInstallUtil.isEmpty(serverDetails.getEndpointAddress())) {
+ try {
+ serverDetails.setEndpointAddress(InetAddress.getLocalHost().getCanonicalHostName());
+ } catch (Exception e) {
+ throw new Exception("Could not assign a server public address automatically - please specify one.");
+ }
+ }
}
// its possible the JDBC URL was changed, clear the factory cache in case the DB version is different now
@@ -165,11 +177,15 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
// test the connection to make sure everything is OK - note that if we are in auto-install mode,
// the password will have been obfuscated, so we need to de-obfucate it in order to use it.
+ // make sure the server properties map itself has an obfuscated password
String dbUrl = serverProperties.get(ServerProperties.PROP_DATABASE_CONNECTION_URL);
String dbUsername = serverProperties.get(ServerProperties.PROP_DATABASE_USERNAME);
String dbPassword = serverProperties.get(ServerProperties.PROP_DATABASE_PASSWORD);
if (autoInstallMode) {
dbPassword = ServerInstallUtil.deobfuscatePassword(dbPassword);
+ } else {
+ serverProperties.put(ServerProperties.PROP_DATABASE_PASSWORD,
+ ServerInstallUtil.obfuscatePassword(dbPassword));
}
String testConnectionErrorMessage = testConnection(dbUrl, dbUsername, dbPassword);
if (testConnectionErrorMessage != null) {
@@ -210,9 +226,14 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
}
}
- // TODO: CONTINUE WITH CONFIGURATION BEAN LINE 777
- if (true)
- throw new IllegalArgumentException("testing");
+ // ensure the server info is up to date and stored in the DB
+ ServerInstallUtil.storeServerDetails(serverProperties, dbPassword, serverDetails);
+
+ // create a keystore whose cert has a CN of this server's public endpoint address
+ ServerInstallUtil.createKeystore(serverDetails, getAppServerConfigDir());
+
+ // now create our deployment services and our main EAR
+ // TODO: finish this
return;
}
@@ -230,7 +251,22 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
public ServerDetails getServerDetails(String connectionUrl, String username, String password, String serverName)
throws Exception {
try {
- return ServerInstallUtil.getServerDetails(connectionUrl, username, password, serverName);
+ ServerDetails sd = ServerInstallUtil.getServerDetails(connectionUrl, username, password, serverName);
+ if (ServerInstallUtil.isEmpty(sd.getName())) {
+ try {
+ sd.setEndpointAddress(InetAddress.getLocalHost().getCanonicalHostName());
+ } catch (Exception ignore) {
+ // oh well.. we'll have to expect the user to set the name they want to use
+ }
+ }
+ if (ServerInstallUtil.isEmpty(sd.getEndpointAddress())) {
+ try {
+ sd.setEndpointAddress(InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception ignore) {
+ // oh well.. we'll have to expect the user to set the address they want to use
+ }
+ }
+ return sd;
} catch (Exception e) {
log("Could not get server details for [" + serverName + "]", e);
return null;
@@ -328,6 +364,13 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
return dir;
}
+ private String getAppServerConfigDir() throws Exception {
+ JBossASClient client = new JBossASClient(getClient());
+ String[] address = { "core-service", "server-environment" };
+ String dir = client.getStringAttribute(true, "config-dir", Address.root().add(address));
+ return dir;
+ }
+
private String getLogDir() throws Exception {
File asHomeDir = new File(getAppServerHomeDir());
File logDir = new File(asHomeDir, "../logs"); // this is RHQ's log dir, not JBossAS's log dir
diff --git a/modules/enterprise/gui/installer/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java b/modules/enterprise/gui/installer/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java
index 8952ef7..15ed1a7 100644
--- a/modules/enterprise/gui/installer/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java
+++ b/modules/enterprise/gui/installer/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java
@@ -45,9 +45,12 @@ import org.apache.tools.ant.helper.ProjectHelper2;
import org.rhq.core.db.DatabaseType;
import org.rhq.core.db.DatabaseTypeFactory;
import org.rhq.core.db.DbUtil;
+import org.rhq.core.db.OracleDatabaseType;
+import org.rhq.core.db.PostgresqlDatabaseType;
import org.rhq.core.db.setup.DBSetup;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.core.util.stream.StreamUtil;
+import org.rhq.enterprise.communications.util.SecurityUtil;
import org.rhq.enterprise.gui.installer.client.shared.ServerDetails;
import org.rhq.enterprise.gui.installer.client.shared.ServerProperties;
@@ -351,6 +354,86 @@ public class ServerInstallUtil {
}
/**
+ * Stores the server details (such as the public endpoint) in the database. If the server definition already
+ * exists, it will be updated; otherwise, a new server will be added to the HA cloud.
+ *
+ * @param serverProperties the server properties
+ * @param password clear text password to connect to the database
+ * @param serverDetails the details of the server to put into the database
+ * @throws Exception
+ */
+ public static void storeServerDetails(HashMap<String, String> serverProperties, String password,
+ ServerDetails serverDetails) throws Exception {
+
+ DatabaseType db = null;
+ Connection conn = null;
+
+ try {
+ String dbUrl = serverProperties.get(ServerProperties.PROP_DATABASE_CONNECTION_URL);
+ String userName = serverProperties.get(ServerProperties.PROP_DATABASE_USERNAME);
+ conn = getDatabaseConnection(dbUrl, userName, password);
+ db = DatabaseTypeFactory.getDatabaseType(conn);
+
+ updateOrInsertServer(db, conn, serverDetails);
+
+ } catch (SQLException e) {
+ LOG.info("Unable to store server entry in the database: " + ThrowableUtil.getAllMessages(e));
+ } finally {
+ if (null != db) {
+ db.closeConnection(conn);
+ }
+ }
+ }
+
+ private static void updateOrInsertServer(DatabaseType db, Connection conn, ServerDetails serverDetails) {
+ PreparedStatement stm = null;
+ ResultSet rs = null;
+
+ if (null == serverDetails || isEmpty(serverDetails.getName())) {
+ return;
+ }
+
+ try {
+ stm = conn.prepareStatement("UPDATE rhq_server SET address=?, port=?, secure_port=? WHERE name=?");
+ stm.setString(1, serverDetails.getEndpointAddress());
+ stm.setInt(2, serverDetails.getEndpointPort());
+ stm.setInt(3, serverDetails.getEndpointSecurePort());
+ stm.setString(4, serverDetails.getName());
+ if (0 == stm.executeUpdate()) {
+ stm.close();
+
+ // set all new servers to operation_mode=INSTALLED
+ int i = 1;
+ if (db instanceof PostgresqlDatabaseType || db instanceof OracleDatabaseType) {
+ stm = conn.prepareStatement("INSERT INTO rhq_server " //
+ + " ( id, name, address, port, secure_port, ctime, mtime, operation_mode, compute_power ) " //
+ + "VALUES ( ?, ?, ?, ?, ?, ?, ?, 'INSTALLED', 1 )");
+ stm.setInt(i++, db.getNextSequenceValue(conn, "rhq_server", "id"));
+ } else {
+ throw new IllegalArgumentException("Unknown database type, can't continue: " + db);
+ }
+
+ stm.setString(i++, serverDetails.getName());
+ stm.setString(i++, serverDetails.getEndpointAddress());
+ stm.setInt(i++, serverDetails.getEndpointPort());
+ stm.setInt(i++, serverDetails.getEndpointSecurePort());
+ long now = System.currentTimeMillis();
+ stm.setLong(i++, now);
+ stm.setLong(i++, now);
+ stm.executeUpdate();
+ }
+
+ } catch (SQLException e) {
+ LOG.info("Unable to put the server details in the database: " + ThrowableUtil.getAllMessages(e));
+ } finally {
+ if (null != db) {
+ db.closeResultSet(rs);
+ db.closeStatement(stm);
+ }
+ }
+ }
+
+ /**
* This will create the database schema in the database. <code>props</code> define the connection to the database -
*
* <p>Note that if the {@link #isDatabaseSchemaExist(Properties) schema already exists}, it will be purged of all
@@ -566,4 +649,46 @@ public class ServerInstallUtil {
}
}
}
+
+ /**
+ * Creates a keystore whose cert has a CN of this server's public endpoint address.
+ *
+ * @param serverDetails details of the server being installed
+ * @param configDirStr location of a configuration directory where the keystore is to be stored
+ */
+ public static void createKeystore(ServerDetails serverDetails, String configDirStr) {
+ File confDir = new File(configDirStr);
+ File keystore = new File(confDir, "rhq.keystore");
+ File keystoreBackup = new File(confDir, "rhq.keystore.backup");
+
+ // if there is one out-of-box, we want to remove it and create one with our proper CN
+ if (keystore.exists()) {
+ keystoreBackup.delete();
+ if (!keystore.renameTo(keystoreBackup)) {
+ LOG.warn("Cannot backup existing keystore - cannot generate a new cert with a proper domain name. ["
+ + keystore + "] will be the keystore used by this server");
+ return;
+ }
+ }
+
+ try {
+ String keystorePath = keystore.getAbsolutePath();
+ String keyAlias = "RHQ";
+ String domainName = "CN=" + serverDetails.getEndpointAddress() + ", OU=RHQ, O=rhq-project.org, C=US";
+ String keystorePassword = "RHQManagement";
+ String keyPassword = keystorePassword;
+ String keyAlgorithm = "rsa";
+ int validity = 7300;
+ SecurityUtil.createKeyStore(keystorePath, keyAlias, domainName, keystorePassword, keyPassword,
+ keyAlgorithm, validity);
+ LOG.info("New keystore created [" + keystorePath + "] with cert domain name of [" + domainName + "]");
+ } catch (Exception e) {
+ LOG.warn("Could not generate a new cert with a proper domain name, will use the original keystore");
+ keystore.delete();
+ if (!keystoreBackup.renameTo(keystore)) {
+ LOG.warn("Failed to restore the original keystore from backup - please rename [" + keystoreBackup
+ + "] to [" + keystore + "]");
+ }
+ }
+ }
}
More information about the rhq-commits
mailing list