modules/common/cassandra-bundle/pom.xml | 3 modules/common/cassandra-bundle/src/main/cassandra/cli/dbsetup.script | 40 ++++++++ modules/common/cassandra-bundle/src/main/java/org/rhq/cassandra/bundle/EmbeddedDeployer.java | 47 ++++++++++ 3 files changed, 90 insertions(+)
New commits: commit aa4ea8740b3b274c2c6ad9741a93a4ab90c12893 Author: John Sanda jsanda@redhat.com Date: Tue Oct 2 22:48:50 2012 -0400
Install schema after starting first node
After starting the first node we wait until we can establish a connection to it in order to verify that it is running. If we cannot connect after 10 attempts, an exception is thrown. Once a connection is established, we execute cassandra-cli on dbsetup.script.
There is still a lot more work to do here like better error handling, logging, etc.
diff --git a/modules/common/cassandra-bundle/pom.xml b/modules/common/cassandra-bundle/pom.xml index 5a69c3d..50896a2 100644 --- a/modules/common/cassandra-bundle/pom.xml +++ b/modules/common/cassandra-bundle/pom.xml @@ -55,6 +55,9 @@ <directory>src/main/resources</directory> <filtering>true</filtering> </resource> + <resource> + <directory>src/main/cassandra/cli</directory> + </resource> </resources>
<filters> diff --git a/modules/common/cassandra-bundle/src/main/cassandra/cli/dbsetup.script b/modules/common/cassandra-bundle/src/main/cassandra/cli/dbsetup.script new file mode 100644 index 0000000..73bc2a7 --- /dev/null +++ b/modules/common/cassandra-bundle/src/main/cassandra/cli/dbsetup.script @@ -0,0 +1,40 @@ +create keyspace rhq + with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and + strategy_options = {replication_factor:1}; + +use rhq; + +create column family raw_metrics + with comparator = DateType and + default_validation_class = DoubleType and + key_validation_class = Int32Type; + +create column family one_hour_metric_data + with comparator = 'CompositeType(DateType, Int32Type)' and + default_validation_class = DoubleType and + key_validation_class = Int32Type; + +create column family six_hour_metric_data + with comparator = 'CompositeType(DateType, Int32Type)' and + default_validation_class = DoubleType and + key_validation_class = Int32Type; + +create column family twenty_four_hour_metric_data + with comparator = 'CompositeType(DateType, Int32Type)' and + default_validation_class = DoubleType and + key_validation_class = Int32Type; + +create column family metrics_work_queue + with comparator = 'CompositeType(DateType, Int32Type)' and + default_validation_class = Int32Type and + key_validation_class = UTF8Type; + +create column family resource_traits + with comparator = 'CompositeType(DateType, Int32Type, Int32Type, UTF8Type, UTF8Type)' and + default_validation_class = UTF8Type and + key_validation_class = Int32Type; + +create column family traits + with comparator = DateType and + default_validation_class = UTF8Type and + key_validation_class = Int32Type; diff --git a/modules/common/cassandra-bundle/src/main/java/org/rhq/cassandra/bundle/EmbeddedDeployer.java b/modules/common/cassandra-bundle/src/main/java/org/rhq/cassandra/bundle/EmbeddedDeployer.java index 981eded..375e5e7 100644 --- a/modules/common/cassandra-bundle/src/main/java/org/rhq/cassandra/bundle/EmbeddedDeployer.java +++ b/modules/common/cassandra-bundle/src/main/java/org/rhq/cassandra/bundle/EmbeddedDeployer.java @@ -38,6 +38,9 @@ import java.util.HashSet; import java.util.Properties; import java.util.Set;
+import org.apache.thrift.transport.TSocket; +import org.apache.thrift.transport.TTransportException; + import org.rhq.bundle.ant.AntLauncher; import org.rhq.cassandra.CassandraException; import org.rhq.core.pluginapi.util.ProcessExecutionUtility; @@ -114,6 +117,10 @@ public class EmbeddedDeployer {
doLocalDeploy(props, bundleDir); startNode(nodeBasedir); + if (i == 0) { + waitForNodeToStart(10, address); + updateSchema(nodeBasedir, address, 9160); + } } FileUtil.writeFile(new ByteArrayInputStream(new byte[] {0}), installedMarker); } catch (IOException e) { @@ -158,6 +165,46 @@ public class EmbeddedDeployer { ProcessExecutionResults results = systemInfo.executeProcess(startScriptExe); }
+ private void waitForNodeToStart(int maxRetries, String host) throws CassandraException { + int port = 9160; + int timeout = 50; + for (int i = 0; i < maxRetries; ++i) { + TSocket socket = new TSocket(host, port, timeout); + try { + socket.open(); + return; + } catch (TTransportException e) { + } + } + throw new CassandraException("Could not connect to " + host + " after " + maxRetries); + } + + private void updateSchema(File basedir, String host, int port) throws CassandraException { + File binDir = new File(basedir, "bin"); + File cliScript; + SystemInfo systemInfo = SystemInfoFactory.createSystemInfo(); + + if (systemInfo.getOperatingSystemType() == OperatingSystemType.WINDOWS) { + cliScript = new File(binDir, "cassandra-cli.bat"); + } else { + cliScript = new File(binDir, "cassandra-cli"); + } + + File dbsetupFile = null; + try { + dbsetupFile = File.createTempFile("dbsetup.script", null); + InputStream inputStream = getClass().getResourceAsStream("/dbsetup.script"); + FileOutputStream outputStream = new FileOutputStream(dbsetupFile); + StreamUtil.copy(inputStream, outputStream); + } catch (IOException e) { + throw new CassandraException("Failed to load schema update script", e); + } + ProcessExecution cliExe = ProcessExecutionUtility.createProcessExecution(cliScript); + cliExe.setArguments(asList("-f", dbsetupFile.getAbsolutePath(), "-h", host, "-p", Integer.toString(port))); + + ProcessExecutionResults results = systemInfo.executeProcess(cliExe); + } + private File unpackBundleZipFile() throws IOException { InputStream bundleInputStream = getClass().getResourceAsStream("/cassandra-bundle.zip"); File bundleZipFile = File.createTempFile("cassandra-bundle.zip", null);
rhq-commits@lists.fedorahosted.org