Repository: phoenix
Updated Branches:
  refs/heads/4.0 7578ee92b -> 968e431b3


PHOENIX-1552 Add a self-contained sandbox

Add a sandbox that can be started via the phoenix_sandbox.py
script.


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/968e431b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/968e431b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/968e431b

Branch: refs/heads/4.0
Commit: 968e431b3e750d515ff29a4d3b9dc8fa8db82bc7
Parents: 7578ee9
Author: Gabriel Reid <gabri...@ngdata.com>
Authored: Tue Dec 23 15:44:46 2014 +0100
Committer: Gabriel Reid <gabri...@ngdata.com>
Committed: Mon Jan 12 10:25:04 2015 +0100

----------------------------------------------------------------------
 bin/phoenix_sandbox.py                          | 59 +++++++++++++++++
 bin/sandbox-log4j.properties                    | 45 +++++++++++++
 phoenix-core/pom.xml                            | 15 +++++
 .../src/it/java/org/apache/phoenix/Sandbox.java | 67 ++++++++++++++++++++
 4 files changed, 186 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/968e431b/bin/phoenix_sandbox.py
----------------------------------------------------------------------
diff --git a/bin/phoenix_sandbox.py b/bin/phoenix_sandbox.py
new file mode 100755
index 0000000..c4fb841
--- /dev/null
+++ b/bin/phoenix_sandbox.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+############################################################################
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+############################################################################
+
+import os
+import subprocess
+import sys
+import phoenix_utils
+
+phoenix_utils.setPath()
+
+base_dir = os.path.join(phoenix_utils.current_dir, '..')
+phoenix_target_dir = os.path.join(base_dir, 'phoenix-core', 'target')
+
+cp_file_path = os.path.join(phoenix_target_dir, 'cached_classpath.txt')
+
+
+if not os.path.exists(cp_file_path):
+    sys.err.write("cached_classpath.txt is not present under "
+                + "phoenix-core/target, please rebuild the project first")
+    sys.exit(1)
+
+logging_config = os.path.join(base_dir, 'bin', 'sandbox-log4j.properties')
+
+cp_components = [phoenix_target_dir + "/*"]
+with open(cp_file_path, 'rb') as cp_file:
+    cp_components.append(cp_file.read())
+
+java_cmd = ("java -Dlog4j.configuration=file:%s " +
+                "-cp %s org.apache.phoenix.Sandbox") % (
+                            logging_config, ":".join(cp_components))
+
+proc = subprocess.Popen(java_cmd, shell=True)
+try:
+    proc.wait()
+except KeyboardInterrupt:
+    print "Shutting down sandbox..."
+    proc.terminate()
+
+proc.wait()
+
+print "Sandbox is stopped"

http://git-wip-us.apache.org/repos/asf/phoenix/blob/968e431b/bin/sandbox-log4j.properties
----------------------------------------------------------------------
diff --git a/bin/sandbox-log4j.properties b/bin/sandbox-log4j.properties
new file mode 100644
index 0000000..a30f129
--- /dev/null
+++ b/bin/sandbox-log4j.properties
@@ -0,0 +1,45 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+# Define some default values that can be overridden by system properties
+sandbox.root.logger=INFO,console
+
+# Define the root logger to the system property "plsql.root.logger".
+log4j.rootLogger=${sandbox.root.logger}
+
+# Logging Threshold
+log4j.threshold=WARN
+
+#
+# console
+# Add "console" to rootlogger above if you want to use this
+#
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.target=System.err
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p 
%c{2}: %m%n
+
+# Custom Logging levels
+log4j.logger.org.apache.zookeeper=ERROR
+log4j.logger.org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper=ERROR
+log4j.logger.org.apache.hadoop.hbase.zookeeper.ZKUtil=ERROR
+log4j.logger.org.apache.hadoop.hbase.HBaseConfiguration=ERROR
+log4j.logger.org.apache.hadoop.hbase.ZNodeClearer=ERROR

http://git-wip-us.apache.org/repos/asf/phoenix/blob/968e431b/phoenix-core/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-core/pom.xml b/phoenix-core/pom.xml
index 45ee0b8..5f06e87 100644
--- a/phoenix-core/pom.xml
+++ b/phoenix-core/pom.xml
@@ -201,6 +201,21 @@
         <artifactId>maven-dependency-plugin</artifactId>
         <version>${maven-dependency-plugin.version}</version>
       </plugin>
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <!-- generates the file that will be used by the sandbox script in 
the dev env -->
+            <id>create-phoenix-generated-classpath</id>
+            <goals>
+              <goal>build-classpath</goal>
+            </goals>
+            <configuration>
+              
<outputFile>${project.build.directory}/cached_classpath.txt</outputFile>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/968e431b/phoenix-core/src/it/java/org/apache/phoenix/Sandbox.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/Sandbox.java 
b/phoenix-core/src/it/java/org/apache/phoenix/Sandbox.java
new file mode 100644
index 0000000..b7bc107
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/Sandbox.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Starts up a self-contained HBase cluster with Phoenix installed to allow 
simple local
+ * testing of Phoenix.
+ */
+public class Sandbox {
+
+    private static final Logger LOG = LoggerFactory.getLogger(Sandbox.class);
+
+    public static void main(String[] args) throws Exception {
+        System.out.println("Starting Phoenix sandbox");
+        Configuration conf = HBaseConfiguration.create();
+        BaseTest.setUpConfigForMiniCluster(conf, new 
ReadOnlyProps(ImmutableMap.<String, String>of()));
+
+        final HBaseTestingUtility testUtil = new HBaseTestingUtility(conf);
+        testUtil.startMiniCluster();
+
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            @Override
+            public void run() {
+                try {
+                    if (testUtil != null) {
+                        testUtil.shutdownMiniCluster();
+                    }
+                } catch (Exception e) {
+                    LOG.error("Exception caught when shutting down mini 
cluster", e);
+                }
+            }
+        });
+
+        int clientPort = testUtil.getZkCluster().getClientPort();
+        System.out.println("\n\n\tPhoenix Sandbox is started\n\n");
+        System.out.printf("\tYou can now connect with url 
'jdbc:phoenix:localhost:%d'\n" +
+                        "\tor connect via sqlline with 'bin/sqlline.py 
localhost:%d'\n\n",
+                clientPort, clientPort);
+
+        Thread.sleep(Long.MAX_VALUE);
+    }
+
+}

Reply via email to