}
}
private InstallerInfo install(CommandLine cmdLine) throws StorageInstallerException {
DeploymentOptionsFactory factory = new DeploymentOptionsFactory();
DeploymentOptions deploymentOptions = factory.newDeploymentOptions();
InstallerInfo installerInfo = new InstallerInfo();
if (cmdLine.hasOption("dir")) {
installerInfo.basedir = new File(cmdLine.getOptionValue("dir"));
deploymentOptions.setBasedir(installerInfo.basedir.getAbsolutePath());
} else {
installerInfo.basedir = new File(serverBasedir, "rhq-storage");
deploymentOptions.setBasedir(installerInfo.basedir.getAbsolutePath());
}
try {
if (cmdLine.hasOption("n")) {
installerInfo.hostname = cmdLine.getOptionValue("n");
// Make sure it is a reachable address
InetAddress.getByName(installerInfo.hostname);
} else {
installerInfo.hostname = InetAddress.getLocalHost().getHostName();
}
if (InetAddress.getByName(installerInfo.hostname).isLoopbackAddress()) {
log.warn("This Storage Node is bound to the loopback address " + installerInfo.hostname + " . "
+ "It will not be able to communicate with Storage Nodes on other machines,"
+ " and it can only receive client requests from this machine.");
}
deploymentOptions.setListenAddress(installerInfo.hostname);
deploymentOptions.setRpcAddress(installerInfo.hostname);
String seeds = cmdLine.getOptionValue(StorageProperty.SEEDS.property(), installerInfo.hostname);
deploymentOptions.setSeeds(seeds);
String commitlogDir = cmdLine
.getOptionValue(StorageProperty.COMMITLOG.property(), getDefaultCommitLogDir());
String dataDir = cmdLine.getOptionValue(StorageProperty.DATA.property(), getDefaultDataDir());
String savedCachesDir = cmdLine.getOptionValue(StorageProperty.SAVED_CACHES.property(),
getDefaultSavedCachesDir());
File commitLogDirFile = new File(commitlogDir);
File dataDirFile = new File(dataDir);
File savedCachesDirFile = new File(savedCachesDir);
boolean verifyDataDirsEmpty = Boolean.valueOf(cmdLine.getOptionValue(
StorageProperty.VERIFY_DATA_DIRS_EMPTY.property(), "true"));
if (verifyDataDirsEmpty) {
// validate the three data directories are empty - if they are not, we are probably stepping on
// another storage node
if (!isDirectoryEmpty(commitLogDirFile)) {
log.error("Commitlog directory is not empty. It should not exist for a new Storage Node ["
+ commitLogDirFile.getAbsolutePath() + "]");
throw new StorageInstallerException("Installation cannot proceed. The commit log directory "
+ commitLogDirFile + " is not empty", STATUS_DATA_DIR_NOT_EMPTY);
}
if (!isDirectoryEmpty(dataDirFile)) {
log.error("Data directory is not empty. It should not exist for a new Storage Node ["
+ dataDirFile.getAbsolutePath() + "]");
throw new StorageInstallerException("Installation cannot proceed. The data directory "
+ dataDirFile + " is not empty", STATUS_DATA_DIR_NOT_EMPTY);
}
if (!isDirectoryEmpty(savedCachesDirFile)) {
log.error("Saved caches directory is not empty. It should not exist for a new Storage Node ["
+ savedCachesDirFile.getAbsolutePath() + "]");
throw new StorageInstallerException("Installation cannot proceed. The saved caches directory "
+ savedCachesDirFile + " is not empty", STATUS_DATA_DIR_NOT_EMPTY);
}
}
verifyPortStatus(cmdLine, installerInfo);
deploymentOptions.setCommitLogDir(commitlogDir);
// TODO add support for specifying multiple dirs
deploymentOptions.setDataDir(dataDirFile.getPath());
deploymentOptions.setSavedCachesDir(savedCachesDir);
deploymentOptions.setLogFileName(installerInfo.logFile);
deploymentOptions.setLoggingLevel("INFO");
deploymentOptions.setRpcPort(RPC_PORT);
deploymentOptions.setCqlPort(installerInfo.cqlPort);
deploymentOptions.setGossipPort(installerInfo.gossipPort);
deploymentOptions.setJmxPort(installerInfo.jmxPort);
deploymentOptions
.setHeapSize(cmdLine.getOptionValue(StorageProperty.HEAP_SIZE.property(), defaultHeapSize));
deploymentOptions.setHeapNewSize(cmdLine.getOptionValue(StorageProperty.HEAP_NEW_SIZE.property(),
defaultHeapNewSize));
if (cmdLine.hasOption(StorageProperty.STACK_SIZE.property())) {
deploymentOptions.setStackSize(cmdLine.getOptionValue(StorageProperty.STACK_SIZE.property()));
}
// The out of box default for native_transport_max_threads is 128. We default
// to 64 for dev/test environments so we need to update it here.
deploymentOptions.setNativeTransportMaxThreads(128);
deploymentOptions.load();
List<String> errors = new ArrayList<String>();
checkPerms(options.getOption(StorageProperty.SAVED_CACHES.property()), savedCachesDir, errors);
checkPerms(options.getOption(StorageProperty.COMMITLOG.property()), commitlogDir, errors);
checkPerms(options.getOption(StorageProperty.DATA.property()), dataDir, errors);