Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[1092707] If re-install is attempted using a different storage node h…
Browse files Browse the repository at this point in the history
…ost name, install fails

Allow a re-install/re-upgrade to replaceme existing storage node definitions
as long as the storage nodes have not actually been used.  Basically, if
none of the storage nodes are yet linked to a resource, they are eligible
for replacement.

(cherry picked from commit a074c18)
Signed-off-by: Jay Shaughnessy <jshaughn@redhat.com>
  • Loading branch information
jshaughn committed Oct 17, 2014
1 parent 13e260a commit 23eb998
Showing 1 changed file with 16 additions and 2 deletions.
Expand Up @@ -221,7 +221,7 @@ public static void configureLogging(ModelControllerClient mcc, HashMap<String, S
sb.append(",");
sb.append("match(\"ARJUNA016009\")"); //BZ 1144998, waiting for fix of https://issues.jboss.org/browse/WFLY-2828
sb.append(",");
sb.append("match(\"JBAS014807\")"); //BZ 1144998, missing web subsystem is expected at times
sb.append("match(\"JBAS014807\")"); //BZ 1144998, missing web subsystem is expected at times
sb.append(",");
sb.append("match(\"admin/user/UserAdminPortal\")"); //BZ 994267
sb.append("))");
Expand Down Expand Up @@ -1072,6 +1072,7 @@ public static void persistStorageNodesIfNecessary(HashMap<String, String> server
Statement queryStatement = null;
ResultSet resultSet = null;
PreparedStatement insertStorageNode = null;
PreparedStatement deleteStorageNodes = null;

try {
String dbUrl = serverProperties.get(ServerProperties.PROP_DATABASE_CONNECTION_URL);
Expand All @@ -1083,14 +1084,26 @@ public static void persistStorageNodesIfNecessary(HashMap<String, String> server
throw new IllegalArgumentException("Unknown database type, can't continue: " + db);
}

// IF there are no current storage nodes then we can persist the specified storage nodes.
// IF there are current storage nodes but none are linked to resources, we replace them with
// the currently specified addresses. This allows an install or upgrade to be run again if the
// initial address(es) were incorrect.

queryStatement = connection.createStatement();
resultSet = queryStatement.executeQuery("SELECT count(id) FROM rhq_storage_node");
resultSet = queryStatement
.executeQuery("SELECT count(*) FROM rhq_storage_node sn WHERE NOT sn.resource_id IS NULL");
resultSet.next();

if (resultSet.getInt(1) == 0) {
connection.setAutoCommit(false);

try {
deleteStorageNodes = connection.prepareStatement("DELETE FROM rhq_storage_node");
int numRemoved = deleteStorageNodes.executeUpdate();
if (numRemoved > 0) {
LOG.info("Removed [" + numRemoved + "] storage nodes. They will be redefined now...");
}

LOG.info("Persisting to database new storage nodes for values specified in server configuration property [rhq.storage.nodes]");

insertStorageNode = connection
Expand Down Expand Up @@ -1127,6 +1140,7 @@ public static void persistStorageNodesIfNecessary(HashMap<String, String> server
if (db != null) {
db.closeResultSet(resultSet);
db.closeStatement(queryStatement);
db.closeStatement(deleteStorageNodes);
db.closeStatement(insertStorageNode);
db.closeConnection(connection);
}
Expand Down

0 comments on commit 23eb998

Please sign in to comment.