modules/common/cassandra-installer/src/main/java/org/rhq/storage/installer/StorageInstaller.java
| 28 +++-
modules/common/cassandra-installer/src/main/java/org/rhq/storage/installer/StorageInstallerException.java
| 57 ++++++++++
modules/common/cassandra-installer/src/main/resources/logging.properties
| 4
3 files changed, 79 insertions(+), 10 deletions(-)
New commits:
commit 54472730a50ef27f374b4a4decdf4bdfbc183684
Author: John Sanda <jsanda(a)redhat.com>
Date: Wed Mar 27 17:46:17 2013 -0400
update error handling for directory checks
The installer now aborts if it detects that the storage node will not be able
to write to any of the external directories to which it needs write access.
diff --git
a/modules/common/cassandra-installer/src/main/java/org/rhq/storage/installer/StorageInstaller.java
b/modules/common/cassandra-installer/src/main/java/org/rhq/storage/installer/StorageInstaller.java
index db0a69d..91b19e8 100644
---
a/modules/common/cassandra-installer/src/main/java/org/rhq/storage/installer/StorageInstaller.java
+++
b/modules/common/cassandra-installer/src/main/java/org/rhq/storage/installer/StorageInstaller.java
@@ -110,7 +110,7 @@ public class StorageInstaller {
logDir = new File(rhqBaseDir, "logs");
Option hostname = new Option("n", "hostname", true, "The
hostname or IP address on which the node will listen for " +
- "requests. If not specified, defaults to the value returned by
InetAddress.getLocalHost().getHostName().");
+ "requests. If not specified, defaults to the hostname for
localhost.");
hostname.setArgName("HOSTNAME");
Option seeds = new Option("s", "seeds", true, "A
comma-delimited list of hostnames or IP addresses that " +
@@ -215,9 +215,15 @@ public class StorageInstaller {
deploymentOptions.setSslStoragePort(getPort(cmdLine,
"ssl-storage-port", sslStoragePort));
deploymentOptions.load();
- checkPerms(options.getOption("saved-caches"), savedCachesDir);
- checkPerms(options.getOption("commitlog"), commitLogDir);
- checkPerms(options.getOption("data"), dataDir);
+ List<String> errors = new ArrayList<String>();
+ checkPerms(options.getOption("saved-caches"), savedCachesDir,
errors);
+ checkPerms(options.getOption("commitlog"), commitLogDir, errors);
+ checkPerms(options.getOption("data"), dataDir, errors);
+
+ if (!errors.isEmpty()) {
+ throw new StorageInstallerException("Problems have been detected
with one or more of the directories " +
+ "to which the storage node will need to store data.",
errors);
+ }
UnmanagedDeployer deployer = new UnmanagedDeployer();
deployer.unpackBundle();
@@ -259,17 +265,17 @@ public class StorageInstaller {
return Integer.parseInt(cmdLine.getOptionValue(option,
Integer.toString(defaultValue)));
}
- private void checkPerms(Option option, String path) {
+ private void checkPerms(Option option, String path, List<String> errors) {
File dir = new File(path);
if (dir.exists()) {
if (dir.isFile()) {
- log.warn(path + " is not a directory. Use the --" +
option.getLongOpt() + " to change this value.");
+ errors.add(path + " is not a directory. Use the --" +
option.getLongOpt() + " to change this value.");
}
} else {
File parent = findParentDir(new File(path));
if (!parent.canWrite()) {
- log.warn("The user running this installer does not appear to have
write permissions to " + parent +
+ errors.add("The user running this installer does not appear to have
write permissions to " + parent +
". Either make sure that the user running the storage node has
write permissions or use the --" +
option.getLongOpt() + " to change this value.");
}
@@ -387,7 +393,13 @@ public class StorageInstaller {
CommandLineParser parser = new PosixParser();
CommandLine cmdLine = parser.parse(installer.getOptions(), args);
installer.run(cmdLine);
- return;
+ } catch (StorageInstallerException e) {
+ installer.log.warn(e.getMessage());
+ for (String error : e.getErrors()) {
+ installer.log.error(error);
+ }
+ installer.log.error("The installer is exiting due to previous
errors.");
+ System.exit(1);
} catch (ParseException e) {
installer.printUsage();
}
diff --git
a/modules/common/cassandra-installer/src/main/java/org/rhq/storage/installer/StorageInstallerException.java
b/modules/common/cassandra-installer/src/main/java/org/rhq/storage/installer/StorageInstallerException.java
new file mode 100644
index 0000000..2ed5af2
--- /dev/null
+++
b/modules/common/cassandra-installer/src/main/java/org/rhq/storage/installer/StorageInstallerException.java
@@ -0,0 +1,57 @@
+/*
+ *
+ * * RHQ Management Platform
+ * * Copyright (C) 2005-2012 Red Hat, Inc.
+ * * All rights reserved.
+ * *
+ * * This program is free software; you can redistribute it and/or modify
+ * * it under the terms of the GNU General Public License, version 2, as
+ * * published by the Free Software Foundation, and/or the GNU Lesser
+ * * General Public License, version 2.1, also as published by the Free
+ * * Software Foundation.
+ * *
+ * * This program is distributed in the hope that it will be useful,
+ * * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * * GNU General Public License and the GNU Lesser General Public License
+ * * for more details.
+ * *
+ * * You should have received a copy of the GNU General Public License
+ * * and the GNU Lesser General Public License along with this program;
+ * * if not, write to the Free Software Foundation, Inc.,
+ * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+package org.rhq.storage.installer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author John Sanda
+ */
+public class StorageInstallerException extends Exception {
+
+ private List<String> errors = new ArrayList<String>();
+
+ public StorageInstallerException() {
+ }
+
+ public StorageInstallerException(String message) {
+ super(message);
+ }
+
+ public StorageInstallerException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public StorageInstallerException(String msg, List<String> errors) {
+ super(msg);
+ this.errors = errors;
+ }
+
+ public List<String> getErrors() {
+ return errors;
+ }
+}
diff --git a/modules/common/cassandra-installer/src/main/resources/logging.properties
b/modules/common/cassandra-installer/src/main/resources/logging.properties
index 92288e1..15a0e92 100644
--- a/modules/common/cassandra-installer/src/main/resources/logging.properties
+++ b/modules/common/cassandra-installer/src/main/resources/logging.properties
@@ -1,5 +1,5 @@
# Additional logger names to configure (root logger is always configured)
-loggers=org.rhq, org.rhq.cassandra.installer.CassandraInstaller
+loggers=org.rhq, org.rhq.storage.installer.StorageInstaller
# Root logger level
logger.level=${rhq.storage.installer.loglevel:INFO}
@@ -7,7 +7,7 @@ logger.level=${rhq.storage.installer.loglevel:INFO}
logger.handlers=FILE,CONSOLE
logger.org.rhq.level=WARN
-logger.org.rhq.cassandra.installer.CassandraInstaller.level=INFO
+logger.org.rhq.storage.installer.StorageInstaller.level=INFO
# Console handler configuration
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler