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

Commit

Permalink
Bug 1213812 - After upgrade from JBoss ON 3.2 to 3.3, some rhq column…
Browse files Browse the repository at this point in the history
… families are unavailable and compaction operations fail
  • Loading branch information
rubenvp8510 committed Jun 3, 2016
1 parent c7014c2 commit a404238
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
Expand Up @@ -711,6 +711,8 @@ public void updateStorageSchema(HashMap<String, String> serverProperties) throws
ExistingSchemaOption.KEEP);
ServerInstallUtil.persistStorageNodesIfNecessary(serverProperties, clearTextDbPassword,
parseNodeInformation(serverProperties, storageNodeAddresses));

ServerInstallUtil.removeObsoleteStorageColumnFamilies(serverProperties, clearTextDbPassword);
}

private Set<String> prepareStorageSchema(HashMap<String, String> serverProperties, String clearTextDbPassword,
Expand Down
Expand Up @@ -75,6 +75,7 @@
import org.rhq.core.db.upgrade.ServerVersionColumnUpgrader;
import org.rhq.core.domain.cloud.StorageNode;
import org.rhq.core.domain.cloud.StorageNode.OperationMode;
import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.util.PropertiesFileUpdate;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.core.util.file.FileUtil;
Expand Down Expand Up @@ -1053,6 +1054,93 @@ public static void persistAdminPasswordIfNecessary(HashMap<String, String> serve
}
}

/**
* Mark as uninventoried the obsolete column families for RHQ storage node resources.
*
* @param serverProperties the server properties
* @param dbpassword clear text password to connect to the database
* @throws Exception
*/
public static void removeObsoleteStorageColumnFamilies(HashMap<String, String> serverProperties, String password)
throws Exception {

DatabaseType db = null;
Connection connection = null;
Statement queryTypeStatement = null;
ResultSet resultSet = null;

PreparedStatement uninventoriedStatement = null;
String[] columnKeys = { "one_hour_metrics", "six_hour_metrics", "twenty_four_hour_metrics", "metrics_index" };

try {

LOG.info("Uninventory obsolete column families... ");

String dbUrl = serverProperties.get(ServerProperties.PROP_DATABASE_CONNECTION_URL);
String userName = serverProperties.get(ServerProperties.PROP_DATABASE_USERNAME);
connection = getDatabaseConnection(dbUrl, userName, password);
db = DatabaseTypeFactory.getDatabaseType(connection);

if (!(db instanceof PostgresqlDatabaseType || db instanceof OracleDatabaseType)) {
throw new IllegalArgumentException("Unknown database type, can't continue: " + db);
}

queryTypeStatement = connection.createStatement();

// Get resource type id for ColumnFamily and RHQStorage plugin so we can make sure that
// we are going to uninventory only those resource types.

resultSet = queryTypeStatement
.executeQuery("SELECT id FROM rhq_resource_type WHERE name='ColumnFamily' AND plugin='RHQStorage'");

if (!resultSet.next()) {
return;
}

int resource_type_id = resultSet.getInt(1);

if (resource_type_id != 0) {

connection.setAutoCommit(false);

// Mark obsolete column family resources as uninventoried
try {

uninventoriedStatement = connection.prepareStatement(
"UPDATE rhq_resource SET inventory_status= ?, agent_id= ?, parent_resource_id = ?, resource_key = ? "
+ " WHERE resource_type_id = ? AND resource_key= ?");

String uninventoryStatus = InventoryStatus.UNINVENTORIED.name();

uninventoriedStatement.setString(1, uninventoryStatus);
uninventoriedStatement.setNull(2, java.sql.Types.INTEGER);
uninventoriedStatement.setNull(3, java.sql.Types.INTEGER);
uninventoriedStatement.setString(4, "deleted");
uninventoriedStatement.setInt(5, resource_type_id);

for (String key : columnKeys) {
uninventoriedStatement.setString(6, key);
uninventoriedStatement.executeUpdate();
}

connection.commit();

} catch (SQLException e) {
connection.rollback();
LOG.error("Failed uninventoried obsolete column families. Transaction will be rolled back.", e);
throw e;
}
}
} finally {
if (db != null) {
db.closeResultSet(resultSet);
db.closeStatement(queryTypeStatement);
db.closeStatement(uninventoriedStatement);
db.closeConnection(connection);
}
}
}

/**
* Delete all of the current storage nodes defined in the database, unless they are already managed (meaning,
* at least one is linked to a resource). This can be useful for re-installs where the original install
Expand Down

0 comments on commit a404238

Please sign in to comment.