usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [3/8] git commit: USERGRID-195
Date Fri, 25 Jul 2014 16:58:49 GMT
USERGRID-195


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/b4cee12c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/b4cee12c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/b4cee12c

Branch: refs/heads/two-dot-o
Commit: b4cee12c0c57377b3897ce6712a694ab80bb08f5
Parents: 54f045f
Author: Salih Kardan <skardan@apache.org>
Authored: Wed Jul 23 11:11:26 2014 +0300
Committer: Salih Kardan <skardan@apache.org>
Committed: Wed Jul 23 11:11:26 2014 +0300

----------------------------------------------------------------------
 chop/example/src/main/resources/runner.sh       |  45 ++++++++
 chop/example/src/main/resources/stack.json      |   1 +
 .../usergrid/chop/stack/BasicInstanceSpec.java  |  12 +++
 .../usergrid/chop/stack/InstanceSpec.java       |   8 ++
 chop/webapp/chop-webapp                         | 104 +++++++++++++++++++
 chop/webapp/pom.xml                             |  26 +++--
 .../webapp/coordinator/CoordinatorUtils.java    |  59 ++++++++++-
 7 files changed, 244 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b4cee12c/chop/example/src/main/resources/runner.sh
----------------------------------------------------------------------
diff --git a/chop/example/src/main/resources/runner.sh b/chop/example/src/main/resources/runner.sh
new file mode 100644
index 0000000..1d13cbf
--- /dev/null
+++ b/chop/example/src/main/resources/runner.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. 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. For additional information regarding
+# copyright in this work, please see the NOTICE file in the top level
+# directory of this distribution.
+#
+
+# NOTE: To install oracle jdk, we need to accept licence aggrement, therefore we could not
download
+#       tar ball from oracle's website. We need to put tar ball elsewhere for example S3
like Dave
+#       just did here : https://github.com/apache/incubator-usergrid/blob/two-dot-o/stack/awscluster/src/main/dist/init_instance/install_oraclejdk.sh
+
+# Get JDK
+# wget http://download.oracle.com/otn-pub/java/jdk/7u65-b17/jdk-7u65-linux-x64.tar.gz
+
+# Install it as they do here:
+# http://askubuntu.com/questions/56104/how-can-i-install-sun-oracles-proprietary-java-6-7-jre-or-jdk
+# tar -xf jdk-7u65-linux-x64.tar.gz
+# mkdir -p /usr/lib/jvm
+# mv ./jdk1.7.0_65 /usr/lib/jvm/jdk1.7.0
+#
+# update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 2000
+# update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac"
2000
+# update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws"
2000
+#
+# chmod a+x /usr/bin/java
+# chmod a+x /usr/bin/javac
+# chmod a+x /usr/bin/javaws
+# chown -R root:root /usr/lib/jvm/jdk1.7.0
+#
+# sudo rm /usr/lib/jvm/default-java
+# sudo ln -s /usr/lib/jvm/jdk1.7.0 /usr/lib/jvm/default-java
+sudo apt-get update >> /dev/null
+sudo apt-get --yes --force-yes install openjdk-7-jdk >> /dev/null
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b4cee12c/chop/example/src/main/resources/stack.json
----------------------------------------------------------------------
diff --git a/chop/example/src/main/resources/stack.json b/chop/example/src/main/resources/stack.json
index efeb563..7f28963 100644
--- a/chop/example/src/main/resources/stack.json
+++ b/chop/example/src/main/resources/stack.json
@@ -8,6 +8,7 @@
       "type" : "m1.large",
       "keyName" : "TestKeyPair",
       "setupScripts" : [ "file://./test_script.sh" ],
+      "runnerScripts" : [ "file://./runner.sh" ],
       "scriptEnvironment" : {
           "TEST_PARAM" : "Test Param Value"
       }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b4cee12c/chop/stack/src/main/java/org/apache/usergrid/chop/stack/BasicInstanceSpec.java
----------------------------------------------------------------------
diff --git a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/BasicInstanceSpec.java
b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/BasicInstanceSpec.java
index d388cd6..452e8ff 100644
--- a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/BasicInstanceSpec.java
+++ b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/BasicInstanceSpec.java
@@ -34,6 +34,7 @@ public class BasicInstanceSpec implements InstanceSpec
     private String type;
     private String keyName;
     private List<URL> setupScripts = new ArrayList<URL>();
+    private List<URL> runnerScripts = new ArrayList<URL>();
     private Properties scriptEnvironment = new Properties();
 
 
@@ -79,6 +80,11 @@ public class BasicInstanceSpec implements InstanceSpec
         return setupScripts;
     }
 
+    @Override
+    public List<URL> getRunnerScripts() {
+        return runnerScripts;
+    }
+
 
     public BasicInstanceSpec setSetupScripts( final List<URL> setupScripts ) {
         this.setupScripts = setupScripts;
@@ -86,6 +92,12 @@ public class BasicInstanceSpec implements InstanceSpec
     }
 
 
+    public BasicInstanceSpec setRunnerScripts( final List<URL> runnerScripts ) {
+        this.runnerScripts = runnerScripts;
+        return this;
+    }
+
+
     public BasicInstanceSpec addSetupScript( URL setupScript ) {
         this.setupScripts.add( setupScript );
         return this;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b4cee12c/chop/stack/src/main/java/org/apache/usergrid/chop/stack/InstanceSpec.java
----------------------------------------------------------------------
diff --git a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/InstanceSpec.java b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/InstanceSpec.java
index 5e14f0b..6891118 100644
--- a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/InstanceSpec.java
+++ b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/InstanceSpec.java
@@ -66,6 +66,14 @@ public interface InstanceSpec {
     List<URL> getSetupScripts();
 
     /**
+     * A list of scripts executed on newly created runner instances of this instance specification.
+     *
+     * @return the runner scripts
+     */
+    @JsonProperty
+    List<URL> getRunnerScripts();
+
+    /**
      * The environment properties to inject into the shell before executing setup scripts.
      */
     @JsonProperty

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b4cee12c/chop/webapp/chop-webapp
----------------------------------------------------------------------
diff --git a/chop/webapp/chop-webapp b/chop/webapp/chop-webapp
new file mode 100644
index 0000000..80b2976
--- /dev/null
+++ b/chop/webapp/chop-webapp
@@ -0,0 +1,104 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. 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. For additional information regarding
+# copyright in this work, please see the NOTICE file in the top level
+# directory of this distribution.
+#
+
+
+# Starts and stops chop web application.
+
+NAME=chop-webapp
+PIDFILE=/var/run/$NAME/$NAME.pid
+DESC="Chop Webapp"
+CMD_PATT="chop-webapp"
+LOGFILE=/var/log/chop-webapp.log
+. /lib/lsb/init-functions
+
+if [ `id -u` -ne 0 ]; then
+        echo "You need root privileges to run this script"
+        exit 1
+fi
+
+if [ "x$CHOP_HOME" = "x" ]; then
+    CHOP_HOME=/opt/chop
+fi
+
+is_running()
+{
+    if [ -f $PIDFILE ]; then
+        pid=`cat $PIDFILE`
+        grep -Eq "$CMD_PATT" "/proc/$pid/cmdline" 2>/dev/null && return 0
+        return 1
+    fi
+    return 3
+}
+
+case "$1" in
+start)
+        is_running
+        stat=$?
+        case "$stat" in
+                0) echo $DESC "is already running..." ;;
+                1) echo "Could not access pidfile for $DESC" ;;
+                *)
+                echo "Starting "$DESC" ... "
+                [ -e `dirname "$PIDFILE"` ] || \
+                        install -d -m755 `dirname $PIDFILE`
+                DAEMON="/usr/bin/java"
+                ARGS=" -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
$CHOP_HOME/webapp/chop-webapp-2.0.0-SNAPSHOT-shaded.jar -e -d /var/lib/elasticsearch"
+		start-stop-daemon --start --quiet --make-pidfile --pidfile "$PIDFILE" --background  --exec
/bin/bash -- -c "exec ${DAEMON} ${ARGS} > ${LOGFILE} 2>&1"
+	;;
+        esac
+;;
+
+stop)
+        is_running
+        stat=$?
+        case "$stat" in
+        0)
+                echo "Stopping" $DESC
+                echo "PID: " $PIDFILE
+                start-stop-daemon -K -p "$PIDFILE" -R TERM/30/KILL/5 >/dev/null
+                rm -f "$PIDFILE";;
+        1) echo "Could not access pidfile for $DESC" ;;
+        *) echo $DESC" is not running..." ;;
+        esac
+;;
+
+restart)
+        $0 stop
+        $0 start
+;;
+
+status)
+        is_running
+        stat=$?
+        case "$stat" in
+                0) log_success_msg "$DESC is running" ;;
+                1) log_failure_msg "could not access pidfile for $DESC" ;;
+                *) log_success_msg "$DESC is not running" ;;
+        esac
+        exit "$stat"
+;;
+kill)
+        start-stop-daemon -K -p "$PIDFILE" -R TERM/30/KILL/5 >/dev/null
+        rm -f "$PIDFILE"
+        echo $DESC "is killed..."
+;;
+*)
+        echo "Usage: $0 {start|stop|restart|status|kill}"
+        exit 1
+esac

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b4cee12c/chop/webapp/pom.xml
----------------------------------------------------------------------
diff --git a/chop/webapp/pom.xml b/chop/webapp/pom.xml
index f50a82e..d770361 100644
--- a/chop/webapp/pom.xml
+++ b/chop/webapp/pom.xml
@@ -23,6 +23,7 @@
       <wagon.plugin.version>1.0-beta-5</wagon.plugin.version>
       <webapp-shaded-jar>${project.artifactId}-${project.version}-shaded.${project.packaging}</webapp-shaded-jar>
       <wagon.webapp.copy.file>${project.build.directory}/${webapp-shaded-jar}</wagon.webapp.copy.file>
+      <wagon.target.dir>${project.basedir}</wagon.target.dir>
       <wagon.temp.directory>/tmp</wagon.temp.directory>
       <chop.home.directory>/opt/chop</chop.home.directory>
       <chop.webapp.directory>${chop.home.directory}/webapp</chop.webapp.directory>
@@ -71,21 +72,26 @@
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>wagon-maven-plugin</artifactId>
         <version>${wagon.plugin.version}</version>
-        <configuration>
-          <serverId>ec2-coordinator-instance</serverId>
-          <fromFile>${wagon.webapp.copy.file}</fromFile>
-          <url>scp://${chop.coordinator.url}${wagon.temp.directory}</url>
-          <commands>
-            <command>sudo mv ${wagon.temp.directory}/${webapp-shaded-jar} ${chop.webapp.directory}</command>
-            <command>sudo service chop-webapp restart</command>
-          </commands>
-        </configuration>
+          <configuration>
+            <serverId>ec2-coordinator-instance</serverId>
+            <fromDir>${wagon.target.dir}</fromDir>
+            <includes>target/${webapp-shaded-jar},jssecacerts,chop-webapp</includes>
+            <url>scp://${chop.coordinator.url}${wagon.temp.directory}</url>
+            <commands>
+              <command>if [ ! -f /etc/init.d/chop-webapp ]; then sudo cp ${wagon.temp.directory}/chop-webapp
/etc/init.d/; fi</command>
+              <command>sudo chmod +x /etc/init.d/chop-webapp</command>
+              <command>if [ ! -f ${chop.webapp.java.home}/lib/security/jssecacerts
]; then sudo cp ${wagon.temp.directory}/jssecacerts ${chop.webapp.java.home}/jre/lib/security/;
fi</command>
+              <command>if [ ! -d ${chop.webapp.directory} ]; then sudo mkdir -p ${chop.webapp.directory};
fi</command>
+              <command>sudo cp ${wagon.temp.directory}/target/${webapp-shaded-jar}
${chop.webapp.directory}</command>
+              <command>sudo service chop-webapp restart</command>
+            </commands>
+          </configuration>
         <executions>
           <execution>
             <id>upload-webapp-jar</id>
             <phase>deploy</phase>
             <goals>
-              <goal>upload-single</goal>
+              <goal>upload</goal>
               <goal>sshexec</goal>
             </goals>
           </execution>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b4cee12c/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/CoordinatorUtils.java
----------------------------------------------------------------------
diff --git a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/CoordinatorUtils.java
b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/CoordinatorUtils.java
index 87f8c5b..a52abb5 100644
--- a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/CoordinatorUtils.java
+++ b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/CoordinatorUtils.java
@@ -31,6 +31,7 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.concurrent.ExecutionException;
 
+import org.apache.usergrid.chop.stack.Cluster;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -124,7 +125,7 @@ public class CoordinatorUtils {
         InputStream stream = null;
         URLClassLoader classLoader = null;
         try {
-             // Access the jar file resources after adding it to a new ClassLoader
+            // Access the jar file resources after adding it to a new ClassLoader
             classLoader = new URLClassLoader( new URL[] { runnerJar.toURL() },
                     Thread.currentThread().getContextClassLoader() );
 
@@ -352,6 +353,62 @@ public class CoordinatorUtils {
         String destFile = sb.toString();
         commands.add( new SCPCommand( runnerJar.getAbsolutePath(), destFile ) );
 
+        sb = new StringBuilder();
+
+        /** Get runner scripts out of the jar file and prepare ssh & scp commands */
+        for ( Cluster cluster : stack.getClusters() ){
+
+            // Prepare setup environment variables
+            for( Object obj: cluster.getInstanceSpec().getScriptEnvironment().keySet() )
{
+
+                String envVar = obj.toString();
+                String value = cluster.getInstanceSpec().getScriptEnvironment().getProperty(
envVar );
+                sb.append( "export " )
+                        .append( envVar )
+                        .append( "=\"" )
+                        .append( value )
+                        .append( "\";" );
+            }
+
+            String exportVars = sb.toString();
+
+            // Prepare SSH and SCP commands
+            for( URL scriptFile : cluster.getInstanceSpec().getRunnerScripts() ) {
+                /** First save file beside runner.jar */
+                File file = new File( scriptFile.getPath() );
+                File fileToSave = new File( runnerJar.getParentFile(), file.getName() );
+                writeToFile( getResourceAsStreamFromRunnerJar( runnerJar, file.getName()
), fileToSave.getPath() );
+
+                /** SCP the script to instance **/
+                sb = new StringBuilder();
+                sb.append( "/home/" )
+                        .append( Utils.DEFAULT_USER )
+                        .append( "/" )
+                        .append( fileToSave.getName() );
+
+                String destinationFile = sb.toString();
+                commands.add( new SCPCommand( fileToSave.getAbsolutePath(), destinationFile
) );
+
+                /** calling chmod first just in case **/
+                sb = new StringBuilder();
+                sb.append( "chmod 0755 " )
+                        .append( "/home/" )
+                        .append( Utils.DEFAULT_USER )
+                        .append( "/" )
+                        .append( fileToSave.getName() )
+                        .append( ";" );
+
+                /** Run the script command */
+                sb.append( exportVars )
+                        .append( "sudo -E " )
+                        .append( destinationFile );
+
+
+                commands.add( new SSHCommand( sb.toString() ) );
+            }
+        }
+
+
         /**
          * Start the runner.jar on instance.
          * This assumes an appropriate java is existing at /usr/bin/java on given instances,


Mime
View raw message