modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/InternodeAuthConfUpdateException.java
| 22 ++
modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java
| 104 +++-------
modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeComponentITest.java
| 4
3 files changed, 64 insertions(+), 66 deletions(-)
New commits:
commit 96745558fb5c803bda91f5ac1180b17db8a76364
Author: John Sanda <jsanda(a)redhat.com>
Date: Sat Jul 27 14:08:18 2013 -0400
updating exception handling and logging in prepareForBootstrap
diff --git
a/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/InternodeAuthConfUpdateException.java
b/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/InternodeAuthConfUpdateException.java
new file mode 100644
index 0000000..d1e6e56
--- /dev/null
+++
b/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/InternodeAuthConfUpdateException.java
@@ -0,0 +1,22 @@
+package org.rhq.plugins.storage;
+
+/**
+ * @author John Sanda
+ */
+public class InternodeAuthConfUpdateException extends Exception {
+
+ public InternodeAuthConfUpdateException() {
+ }
+
+ public InternodeAuthConfUpdateException(String message) {
+ super(message);
+ }
+
+ public InternodeAuthConfUpdateException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InternodeAuthConfUpdateException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git
a/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java
b/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java
index eb0b9fd..2cb9501 100644
---
a/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java
+++
b/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java
@@ -29,12 +29,10 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
-import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -95,6 +93,14 @@ public class StorageNodeComponent extends CassandraNodeComponent
implements Oper
return new File(pluginConfig.getSimpleValue("baseDir"));
}
+ private File getConfDir() {
+ return new File(getBasedir(), "conf");
+ }
+
+ private File getInternodeAuthConfFile() {
+ return new File(getConfDir(), "rhq-storage-auth.conf");
+ }
+
@Override
public OperationResult invokeOperation(String name, Configuration parameters) throws
Exception {
if (name.equals("addNodeMaintenance")) {
@@ -242,56 +248,24 @@ public class StorageNodeComponent extends CassandraNodeComponent
implements Oper
ipAddresses.add(propertySimple.getStringValue());
}
- if (updateAuthFile(result, ipAddresses)) return result;
-
- EmsBean authBean =
getEmsConnection().getBean("org.rhq.cassandra.auth:type=RhqInternodeAuthenticator");
- EmsOperation emsOperation =
authBean.getOperation("reloadConfiguration");
- emsOperation.invoke();
-
- result.setSimpleResult("Successfully updated the set of known
nodes.");
-
- return result;
- }
-
- private boolean updateAuthFile(OperationResult result, Set<String> ipAddresses)
{
- log.info("Updating known nodes to " + ipAddresses);
+ try {
+ updateInternodeAuthConfFile(ipAddresses);
- File confDir = new File(getBasedir(), "conf");
- File authFile = new File(confDir, "rhq-storage-auth.conf");
- File authBackupFile = new File(confDir, "." + authFile.getName() +
".bak");
+ EmsBean authBean =
getEmsConnection().getBean("org.rhq.cassandra.auth:type=RhqInternodeAuthenticator");
+ EmsOperation emsOperation =
authBean.getOperation("reloadConfiguration");
+ emsOperation.invoke();
- if (authBackupFile.exists()) {
- if (log.isDebugEnabled()) {
- log.debug(authBackupFile + " already exists. Deleting it now in
preparation of creating new backup " +
- "for " + authFile.getName());
- }
- if (!authBackupFile.delete()) {
- String msg = "Failed to delete backup file " + authBackupFile +
". The operation will abort " +
- "since " + authFile + " cannot reliably be backed up
before making changes. Please delete " +
- authBackupFile + " manually and reschedule the operation once
the file has been removed.";
- log.error(msg);
- result.setErrorMessage(msg);
-
- return true;
- }
- }
+ result.setSimpleResult("Successfully updated the set of known
nodes.");
- try {
- StreamUtil.copy(new StringReader(StringUtil.collectionToString(ipAddresses,
"\n")),
- new FileWriter(authFile), true);
- } catch (IOException e) {
- log.error("An error occurred while updating " + authFile, e);
- try {
- log.info("Restoring back up file " + authBackupFile);
- FileUtil.copyFile(authBackupFile, authFile);
- authBackupFile.delete();
- } catch (IOException e1) {
- log.error("Failed to revert backup of " + authFile, e1);
- }
- result.setErrorMessage("There was an unexpected error while updating
" + authFile);
- return true;
+ return result;
+ } catch (InternodeAuthConfUpdateException e) {
+ File authFile = getInternodeAuthConfFile();
+ log.error("Failed to update set of trusted nodes in " + authFile +
" due to the following error(s): " +
+ ThrowableUtil.getAllMessages(e)) ;
+ result.setErrorMessage("Failed to update set of trusted nodes in "
+ authFile + " due to the following " +
+ "error(s): " + ThrowableUtil.getAllMessages(e));
+ return result;
}
- return false;
}
private OperationResult prepareForBootstrap(Configuration params) {
@@ -326,7 +300,6 @@ public class StorageNodeComponent extends CassandraNodeComponent
implements Oper
}
purgeDir(new File(configEditor.getSavedCachesDirectory()));
-
log.info("Updating cluster settings");
String address = pluginConfig.getSimpleValue("host");
@@ -344,10 +317,9 @@ public class StorageNodeComponent extends CassandraNodeComponent
implements Oper
configEditor.setStoragePort(gossipPort);
configEditor.save();
+ log.info("Cluster configuration settings have been applied to " +
yamlFile);
- if (updateAuthFile(result, new HashSet<String>(addresses))) {
- return result;
- }
+ updateInternodeAuthConfFile(new HashSet<String>(addresses));
log.info(this + " is ready to be bootstrap. Restarting storage
node...");
OperationResult startResult = startNode();
@@ -376,6 +348,11 @@ public class StorageNodeComponent extends CassandraNodeComponent
implements Oper
}
}
return result;
+ } catch (InternodeAuthConfUpdateException e) {
+ File authFile = getInternodeAuthConfFile();
+ result.setErrorMessage("Failed to update " + authFile + " due
to the following error(s): " +
+ ThrowableUtil.getAllMessages(e));
+ return result;
}
}
@@ -384,23 +361,18 @@ public class StorageNodeComponent extends CassandraNodeComponent
implements Oper
FileUtil.purge(dir, true);
}
- private File getCommitLogDir(Map yamlConfig) {
- return new File((String) yamlConfig.get("commitlog_directory"));
- }
+ private void updateInternodeAuthConfFile(Set<String> ipAddresses) throws
InternodeAuthConfUpdateException {
+ File authFile = getInternodeAuthConfFile();
- private List<File> getDataDirs(Map yamlConfig) {
- List<File> dirs = new ArrayList<File>();
- List<String> dirNames = (List<String>)
yamlConfig.get("data_file_directories");
+ log.info("Updating " + authFile);
- for (String dirName : dirNames) {
- dirs.add(new File(dirName));
+ try {
+ StreamUtil.copy(new StringReader(StringUtil.collectionToString(ipAddresses,
"\n")),
+ new FileWriter(authFile), true);
+ } catch (Exception e) {
+ log.error("An error occurred while trying to update " + authFile,
e);
+ throw new InternodeAuthConfUpdateException("An error occurred while
trying to update " + authFile, e);
}
-
- return dirs;
- }
-
- private File getSavedCachesDir(Map yamlConfig) {
- return new File((String) yamlConfig.get("saved_caches_directory"));
}
private OperationResult nodeAdded(Configuration params) {
diff --git
a/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeComponentITest.java
b/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeComponentITest.java
index d10e428..ef92510 100644
---
a/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeComponentITest.java
+++
b/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeComponentITest.java
@@ -259,6 +259,10 @@ public class StorageNodeComponentITest {
params, timeout);
log.info("Waiting for node to boostrap...");
+ // When a node goes through bootstrap, StorageService sleeps for RING_DELAY ms
+ // while it determines the ranges of the token ring it will own. RING_DELAY
defaults
+ // to 30 seconds by default.
+ // TODO Override the default RING_DELAY to speed up tests
Thread.sleep(33000);
assertEquals(result.getResultCode(), OperationServicesResultCode.SUCCESS,
"The operation failed: " +