usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [04/50] [abbrv] git commit: Change state of setupstack via signals to prevent it from entering disallowed states
Date Mon, 07 Jul 2014 18:16:21 GMT
Change state of setupstack via signals to prevent it from entering disallowed states


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

Branch: refs/heads/two-dot-o
Commit: 96c4ef95a8a05fb81e05f93e978c750656b0d919
Parents: 1b0a5e3
Author: Furkan Bicak <bicak.cs@safehaus.org>
Authored: Fri Jun 27 16:32:26 2014 +0300
Committer: Furkan Bicak <bicak.cs@safehaus.org>
Committed: Fri Jun 27 16:32:26 2014 +0300

----------------------------------------------------------------------
 .../apache/usergrid/chop/plugin/DeployMojo.java |   3 +
 .../usergrid/chop/stack/CoordinatedStack.java   |  19 +++-
 .../usergrid/chop/stack/IStackController.java   |  45 --------
 .../usergrid/chop/stack/SetupStackSignal.java   |   6 +-
 .../usergrid/chop/stack/SetupStackState.java    |  34 +++---
 .../usergrid/chop/stack/StackController.java    | 111 -------------------
 .../webapp/coordinator/SetupStackThread.java    |  16 +--
 .../webapp/coordinator/StackCoordinator.java    |  58 +++++++++-
 .../chop/webapp/coordinator/StackDestroyer.java |   3 +-
 .../webapp/coordinator/rest/ResetResource.java  |   5 +
 .../webapp/coordinator/rest/StartResource.java  |   5 +-
 .../webapp/coordinator/rest/StopResource.java   |   5 +
 .../coordinator/rest/TestableResource.java      |  56 ++++++++++
 .../webapp/coordinator/rest/UploadResource.java |  55 +++------
 14 files changed, 189 insertions(+), 232 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/plugin/src/main/java/org/apache/usergrid/chop/plugin/DeployMojo.java
----------------------------------------------------------------------
diff --git a/chop/plugin/src/main/java/org/apache/usergrid/chop/plugin/DeployMojo.java b/chop/plugin/src/main/java/org/apache/usergrid/chop/plugin/DeployMojo.java
index 99bbf39..0ec6227 100644
--- a/chop/plugin/src/main/java/org/apache/usergrid/chop/plugin/DeployMojo.java
+++ b/chop/plugin/src/main/java/org/apache/usergrid/chop/plugin/DeployMojo.java
@@ -118,9 +118,11 @@ public class DeployMojo extends MainMojo {
                 .queryParam( RestParams.MODULE_VERSION,
                         props.getProperty( Project.PROJECT_VERSION_KEY ) )
                 .queryParam( RestParams.USERNAME, username )
+                .queryParam( RestParams.VCS_REPO_URL, props.getProperty( Project.GIT_URL_KEY
) )
                 .queryParam( RestParams.TEST_PACKAGE,
                         props.getProperty( Project.TEST_PACKAGE_BASE ) )
                 .queryParam( RestParams.MD5, props.getProperty( Project.MD5_KEY ) )
+                .queryParam( RestParams.RUNNER_COUNT, runnerCount.toString() )
                 .type( MediaType.APPLICATION_JSON )
                 .accept( MediaType.APPLICATION_JSON )
                 .post( ClientResponse.class );
@@ -144,6 +146,7 @@ public class DeployMojo extends MainMojo {
             multipart.field( RestParams.USERNAME, username );
             multipart.field( RestParams.VCS_REPO_URL, props.getProperty( Project.GIT_URL_KEY
) );
             multipart.field( RestParams.TEST_PACKAGE, props.getProperty( Project.TEST_PACKAGE_BASE
) );
+            multipart.field( RestParams.RUNNER_COUNT, runnerCount.toString() );
             multipart.field( RestParams.MD5, props.getProperty( Project.MD5_KEY ) );
 
             FileInputStream in = new FileInputStream( source );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/stack/src/main/java/org/apache/usergrid/chop/stack/CoordinatedStack.java
----------------------------------------------------------------------
diff --git a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/CoordinatedStack.java
b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/CoordinatedStack.java
index 9bdf3ea..82beb03 100644
--- a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/CoordinatedStack.java
+++ b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/CoordinatedStack.java
@@ -26,6 +26,9 @@ import java.util.List;
 import java.util.Set;
 import java.util.UUID;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.commons.lang.builder.HashCodeBuilder;
 
 import org.apache.usergrid.chop.api.Commit;
@@ -39,6 +42,8 @@ import org.apache.usergrid.chop.api.Runner;
  */
 public class CoordinatedStack implements ICoordinatedStack {
 
+    private static final Logger LOG = LoggerFactory.getLogger( CoordinatedStack.class );
+
     private final Stack delegate;
     private final List<CoordinatedCluster> clusters;
     private final Commit commit;
@@ -160,7 +165,19 @@ public class CoordinatedStack implements ICoordinatedStack {
     }
 
 
-    public void setSetupState( SetupStackState setupState ) {
+    public void setSetupState( SetupStackSignal signal ) {
+        if ( setupState.accepts( signal ) ) {
+            LOG.info( setupState.getMessage( signal ) );
+            setupState = setupState.next( signal );
+            LOG.debug( "New state is: {}", setupState );
+        }
+        else {
+            LOG.error( setupState.getMessage( signal ) );
+        }
+    }
+
+
+    private void setSetupState( SetupStackState setupState ) {
         this.setupState = setupState;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/stack/src/main/java/org/apache/usergrid/chop/stack/IStackController.java
----------------------------------------------------------------------
diff --git a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/IStackController.java
b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/IStackController.java
deleted file mode 100644
index 556f733..0000000
--- a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/IStackController.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.apache.usergrid.chop.stack;
-
-
-public interface IStackController {
-    /**
-     * Resets this IStackController if it has been prematurely stopped.
-     */
-    void reset();
-
-
-    /**
-     * Gets the State of this IStackController.
-     *
-     * @return the current state
-     */
-    SetupStackState getState();
-
-
-    /**
-     * Starts this IStackController which begins running the suite of chops.
-     */
-    void start();
-
-    /**
-     * Prematurely stops this IStackController. The IController will naturally stop
-     * itself after running all chops to fall back into the State.READY state.
-     */
-    void stop();
-
-
-    void setup();
-
-
-    void deploy();
-
-
-    void destroy();
-
-
-    /**
-     * Takes a signal parameter to determine whether to start, stop, reset etc.
-     */
-    void send( SetupStackSignal signal );
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/stack/src/main/java/org/apache/usergrid/chop/stack/SetupStackSignal.java
----------------------------------------------------------------------
diff --git a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/SetupStackSignal.java
b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/SetupStackSignal.java
index 8885d5c..96caa4b 100644
--- a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/SetupStackSignal.java
+++ b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/SetupStackSignal.java
@@ -22,7 +22,7 @@ package org.apache.usergrid.chop.stack;
 
 public enum SetupStackSignal {
 
-    START( 0 ), STOP( 1 ), RESET( 2 ), DESTROY( 3 ), DEPLOY( 4 ), SETUP( 5 );
+    START( 0 ), STOP( 1 ), RESET( 2 ), DESTROY( 3 ), DEPLOY( 4 ), SETUP( 5 ), FAIL ( 6 ),
COMPLETE ( 7 );
 
     private final int signalID;
 
@@ -51,6 +51,10 @@ public enum SetupStackSignal {
                 return DEPLOY;
             case 5:
                 return SETUP;
+            case 6:
+                return FAIL;
+            case 7:
+                return COMPLETE;
         }
 
         throw new RuntimeException( "Should never get here!" );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/stack/src/main/java/org/apache/usergrid/chop/stack/SetupStackState.java
----------------------------------------------------------------------
diff --git a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/SetupStackState.java
b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/SetupStackState.java
index 4bd3b84..809c12c 100644
--- a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/SetupStackState.java
+++ b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/SetupStackState.java
@@ -37,13 +37,13 @@ import com.google.common.base.Preconditions;
  * Represents the setup state of a stack
  */
 public enum SetupStackState {
-    // After tests finishes, it will automatically switch to SetUp state
+    // Running ==> (Complete signal) ==> SetUp
+    // Running ==> (Destroy signal) ==> NotSetUp
     // Running ==> (Stop signal) ==> Stopped
-    Running( 7, new SetupStackSignal[] { SetupStackSignal.STOP }, new Integer[] { 6 },
+    Running( 7, new SetupStackSignal[] { SetupStackSignal.STOP, SetupStackSignal.DESTROY,
SetupStackSignal.COMPLETE }, new Integer[] { 6, 3, 0 },
             "Running tests on stack.",
-            "%s signal rejected. When Running only a STOP signal(s) which cause to transition
into " +
-                    "Stopped state(s) respectively" +
-                    " or it will automatically transition into SetUp state when tests are
finished" ),
+            "%s signal rejected. When Running only a STOP, DESTROY and COMPLETE signal(s)
which cause to transition into " +
+                    "Stopped, NotSetUp and SetUp state(s) respectively" ),
 
     // Stopped ==> (reset signal) ==> SetUp
     Stopped( 6, new SetupStackSignal[] { SetupStackSignal.RESET }, new Integer[] { 0 },
@@ -51,17 +51,17 @@ public enum SetupStackState {
             "%s signal rejected. When Stopped only a RESET signal(s) which cause to transition
into " +
                     "SetUp state(s) respectively" ),
 
-    // JarNotFound ==> (deploy signal) ==> JarAlreadyDeployed
-    JarNotFound( 5, new SetupStackSignal[] { SetupStackSignal.DEPLOY }, new Integer[] { 3
},
+    // JarNotFound ==> (deploy signal) ==> NotSetUp
+    JarNotFound( 5, new SetupStackSignal[] { SetupStackSignal.DEPLOY, SetupStackSignal.SETUP
}, new Integer[] { 3, 1 },
             "No runner jars found with given parameters, deploy first.",
-            "%s signal rejected. When JarNotFound only a DEPLOY signal(s) which cause to
transition into " +
-                    "JarAlreadyDeployed state(s) respectively" ),
+            "%s signal rejected. When JarNotFound only a DEPLOY and SETUP signal(s) which
cause to transition into " +
+                    "NotSetUp and SettingUp state(s) respectively" ),
 
-    // After destroy finishes, it will automatically switch to NotSetUp state
-    Destroying( 4, new SetupStackSignal[] { }, new Integer[] { },
+    // Destroying ==> (Complete signal) ==> NotSetUp
+    Destroying( 4, new SetupStackSignal[] { SetupStackSignal.COMPLETE }, new Integer[] {
3 },
             "Currently being destroyed. Wait until it is finished to set up again.",
-            "%s signal rejected. When Destroying no Signal can be sent. It transitions into
" +
-                    "NotSetUp state automatically when it finishes." ),
+            "%s signal rejected. When Destroying only a COMPLETE signal(s) can be sent which
cause to " +
+                    "transition into NotSetUp state(s) respectively" ),
 
     // NotSetUp ==> (setup signal) ==> NotSetUp
     // NotSetUp ==> (setup signal) ==> SettingUp
@@ -77,11 +77,11 @@ public enum SetupStackState {
             "%s signal rejected. When SetupFailed only a SETUP and DEPLOY signal(s) which
cause to transition into " +
                     "SettingUp and NotSetUp state(s) respectively" ),
 
-    // After setting up the stack finishes, it will automatically switch to SetUp state
-    SettingUp( 1, new SetupStackSignal[] { }, new Integer[] { },
+    // SettingUp ==> (Complete signal) ==> SetUp
+    SettingUp( 1, new SetupStackSignal[] { SetupStackSignal.COMPLETE, SetupStackSignal.FAIL
}, new Integer[] { 0, 2 },
             "Setting up the stack right now.",
-            "%s signal rejected. When SettingUp no Signal can be sent. It transitions into
" +
-                    "SetUp state automatically when it finishes." ),
+            "%s signal rejected. When SettingUp only a COMPLETE signal(s) can be sent which
cause to " +
+                    "transition into SetUp state(s) respectively" ),
 
     // SetUp ==> (start signal) ==> Running
     // SetUp ==> (destroy signal) ==> NotSetUp

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/stack/src/main/java/org/apache/usergrid/chop/stack/StackController.java
----------------------------------------------------------------------
diff --git a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/StackController.java
b/chop/stack/src/main/java/org/apache/usergrid/chop/stack/StackController.java
deleted file mode 100644
index c8d1fca..0000000
--- a/chop/stack/src/main/java/org/apache/usergrid/chop/stack/StackController.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
-*  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.usergrid.chop.stack;
-
-
-import org.apache.usergrid.chop.api.State;
-
-import com.google.common.base.Preconditions;
-
-
-public class StackController implements IStackController{
-    private final Object lock = new Object();
-    private SetupStackState state = initializeState();
-
-
-    private SetupStackState initializeState() {
-        // TODO find the real state!!!
-        return SetupStackState.JarNotFound;
-    }
-
-
-    public void send( final SetupStackSignal signal ) {
-        Preconditions.checkState( state.accepts( signal ), state.getMessage( signal ) );
-
-        switch ( signal ) {
-            case STOP: stop(); break;
-            case START: start(); break;
-            case RESET: reset(); break;
-            case DESTROY: destroy(); break;
-            case DEPLOY: deploy(); break;
-            case SETUP: setup(); break;
-            default:
-                throw new IllegalStateException( "Just accepting start, stop, reset, destroy,
deploy or setup." );
-        }
-    }
-
-    public void reset() {
-        synchronized ( lock ) {
-            Preconditions.checkState( state.accepts( SetupStackSignal.RESET ),
-                    "Cannot reset the controller in state: " + state );
-            state = state.next( SetupStackSignal.RESET );
-        }
-    }
-
-
-    @Override
-    public SetupStackState getState() {
-        return state;
-    }
-
-
-    @Override
-    public void start() {
-        synchronized ( lock ) {
-            Preconditions.checkState( state.accepts( SetupStackSignal.START ), "Cannot start
the controller in state: " + state );
-            state = state.next( SetupStackSignal.START );
-            //            new Thread( this ).start();
-            lock.notifyAll();
-        }
-    }
-
-
-    @Override
-    public void stop() {
-        synchronized ( lock ) {
-            Preconditions.checkState( state.accepts( SetupStackSignal.STOP ), "Cannot stop
a controller in state: " + state );
-            state = state.next( SetupStackSignal.STOP );
-            lock.notifyAll();
-        }
-    }
-
-
-    @Override
-    public void setup() {
-
-    }
-
-
-    @Override
-    public void deploy() {
-        synchronized ( lock ) {
-            Preconditions.checkState( state.accepts( SetupStackSignal.DEPLOY ), "Cannot deploy
jar while controller in state: " + state );
-            state = state.next( SetupStackSignal.DEPLOY );
-            lock.notifyAll();
-        }
-
-    }
-
-
-    @Override
-    public void destroy() {
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/SetupStackThread.java
----------------------------------------------------------------------
diff --git a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/SetupStackThread.java
b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/SetupStackThread.java
index 4a065b6..5a506cf 100644
--- a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/SetupStackThread.java
+++ b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/SetupStackThread.java
@@ -37,7 +37,7 @@ import org.apache.usergrid.chop.stack.BasicInstanceSpec;
 import org.apache.usergrid.chop.stack.CoordinatedStack;
 import org.apache.usergrid.chop.stack.ICoordinatedCluster;
 import org.apache.usergrid.chop.stack.Instance;
-import org.apache.usergrid.chop.stack.SetupStackState;
+import org.apache.usergrid.chop.stack.SetupStackSignal;
 import org.apache.usergrid.chop.webapp.ChopUiFig;
 import org.apache.usergrid.chop.webapp.dao.ProviderParamsDao;
 import org.apache.usergrid.chop.webapp.service.InjectorFactory;
@@ -108,7 +108,7 @@ public class SetupStackThread implements Callable<CoordinatedStack>
{
                         " for cluster " + cluster.getName();
                 LOG.warn( errorMessage + ", aborting and terminating launched instances..."
);
                 instanceManager.terminateInstances( launchedInstances );
-                stack.setSetupState( SetupStackState.SetupFailed );
+                stack.setSetupState( SetupStackSignal.FAIL );
                 stack.notifyAll();
                 return null;
             }
@@ -116,7 +116,7 @@ public class SetupStackThread implements Callable<CoordinatedStack>
{
                 errorMessage = "Key file " + keyFile + " for cluster " + cluster.getName()
+ " not found";
                 LOG.warn( errorMessage + ", aborting and terminating launched instances..."
);
                 instanceManager.terminateInstances( launchedInstances );
-                stack.setSetupState( SetupStackState.SetupFailed );
+                stack.setSetupState( SetupStackSignal.FAIL );
                 stack.notifyAll();
                 return null;
             }
@@ -140,7 +140,7 @@ public class SetupStackThread implements Callable<CoordinatedStack>
{
             if ( ! success ) {
                 errorMessage = "SSH commands have failed, will not continue";
                 instanceManager.terminateInstances( launchedInstances );
-                stack.setSetupState( SetupStackState.SetupFailed );
+                stack.setSetupState( SetupStackSignal.FAIL );
                 stack.notifyAll();
                 return null;
             }
@@ -154,7 +154,7 @@ public class SetupStackThread implements Callable<CoordinatedStack>
{
             errorMessage = "No key found with name " + providerParams.getKeyName() + " for
runners";
             LOG.warn( errorMessage + ", aborting and terminating launched instances..." );
             instanceManager.terminateInstances( launchedInstances );
-            stack.setSetupState( SetupStackState.SetupFailed );
+            stack.setSetupState( SetupStackSignal.FAIL );
             stack.notifyAll();
             return null;
         }
@@ -162,7 +162,7 @@ public class SetupStackThread implements Callable<CoordinatedStack>
{
             errorMessage = "Key file " + keyFile + " for runners not found";
             LOG.warn( errorMessage + ", aborting and terminating launched instances..." );
             instanceManager.terminateInstances( launchedInstances );
-            stack.setSetupState( SetupStackState.SetupFailed );
+            stack.setSetupState( SetupStackSignal.FAIL );
             stack.notifyAll();
             return null;
         }
@@ -190,12 +190,12 @@ public class SetupStackThread implements Callable<CoordinatedStack>
{
         if ( ! success ) {
             errorMessage = "SSH commands have failed, will not continue";
             instanceManager.terminateInstances( launchedInstances );
-            stack.setSetupState( SetupStackState.SetupFailed );
+            stack.setSetupState( SetupStackSignal.FAIL );
             stack.notifyAll();
             return null;
         }
 
-        stack.setSetupState( SetupStackState.SetUp );
+        stack.setSetupState( SetupStackSignal.COMPLETE );
         LOG.info( "Stack {} is set up and ready...", stack.getName() );
 
         stack.notifyAll();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/StackCoordinator.java
----------------------------------------------------------------------
diff --git a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/StackCoordinator.java
b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/StackCoordinator.java
index 3f7e325..5b88cce 100644
--- a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/StackCoordinator.java
+++ b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/StackCoordinator.java
@@ -28,6 +28,7 @@ import java.util.concurrent.Executors;
 import org.apache.usergrid.chop.api.Commit;
 import org.apache.usergrid.chop.api.Module;
 import org.apache.usergrid.chop.stack.CoordinatedStack;
+import org.apache.usergrid.chop.stack.SetupStackSignal;
 import org.apache.usergrid.chop.stack.SetupStackState;
 import org.apache.usergrid.chop.stack.Stack;
 import org.apache.usergrid.chop.stack.User;
@@ -87,8 +88,8 @@ public class StackCoordinator {
      * @param runnerCount
      * @return
      */
-    public CoordinatedStack setupStack( String commitId, String artifactId, String groupId,
String version,
-                                        String user, int runnerCount ) {
+    public CoordinatedStack setupStack( String commitId, String artifactId, String groupId,
String version, String user,
+                                        int runnerCount ) {
 
         User chopUser = userDao.get( user );
         File runnerJar = CoordinatorUtils.getRunnerJar( chopUiFig.getContextPath(), user,
groupId, artifactId, version,
@@ -133,7 +134,7 @@ public class StackCoordinator {
 
         LOG.info( "Starting setup stack thread of {}...", stack.getName() );
         synchronized ( coordinatedStack ) {
-            coordinatedStack.setSetupState( SetupStackState.SettingUp );
+            coordinatedStack.setSetupState( SetupStackSignal.SETUP );
             registeredStacks.put( coordinatedStack.hashCode(), coordinatedStack );
 
             SetupStackThread setupThread = new SetupStackThread( coordinatedStack );
@@ -179,11 +180,12 @@ public class StackCoordinator {
 
             // TODO should we also check run state of stack?
             LOG.info( "Starting to destroy stack instances of {}...", stack.getName() );
-            coordinatedStack.setSetupState( SetupStackState.Destroying );
+            coordinatedStack.setSetupState( SetupStackSignal.DESTROY );
             StackDestroyer destroyer = new StackDestroyer( coordinatedStack );
             destroyer.destroy();
             registeredStacks.remove( coordinatedStack.hashCode() );
             setupStackThreads.remove( coordinatedStack );
+            coordinatedStack.setSetupState( SetupStackSignal.COMPLETE );
             coordinatedStack.notifyAll();
         }
     }
@@ -239,7 +241,7 @@ public class StackCoordinator {
      * @return  matching coordinated stack, or null
      */
     public CoordinatedStack findCoordinatedStack( String commitId, String artifactId, String
groupId, String version,
-                                                     String user ) {
+                                                  String user ) {
 
         User chopUser = userDao.get( user );
         if( chopUser == null ) {
@@ -292,7 +294,7 @@ public class StackCoordinator {
      * @return Setup state of given parameters' stack
      */
     public SetupStackState stackStatus( String commitId, String artifactId, String groupId,
String version,
-                                              String user ) {
+                                        String user ) {
 
         CoordinatedStack stack = findCoordinatedStack( commitId, artifactId, groupId, version,
user );
 
@@ -332,4 +334,48 @@ public class StackCoordinator {
             stack.notifyAll();
         }
     }
+
+
+    public CoordinatedStack registerStack( final String commitId, final String artifactId,
final String groupId,
+                                           final String version, final String user, final
int runnerCount ) {
+
+        User chopUser = userDao.get( user );
+        File runnerJar = CoordinatorUtils.getRunnerJar( chopUiFig.getContextPath(), user,
groupId, artifactId, version,
+                commitId );
+
+        Stack stack = CoordinatorUtils.getStackFromRunnerJar( runnerJar );
+        Module module = moduleDao.get( BasicModule.createId( groupId, artifactId, version
) );
+        Commit commit = null;
+        for( Commit c: commitDao.getByModule( module.getId() ) ) {
+            if( commitId.equals( c.getId() ) ) {
+                commit = c;
+                break;
+            }
+        }
+
+        return registerStack( stack, chopUser, commit, module, runnerCount );
+    }
+
+
+    public CoordinatedStack registerStack( final Stack stack, final User user, final Commit
commit, final Module
+            module, final int runnerCount ) {
+        CoordinatedStack coordinatedStack = getCoordinatedStack( stack, user, commit, module
);
+        if ( coordinatedStack != null ) {
+            LOG.info( "Stack {} is already registered", stack.getName() );
+            if ( coordinatedStack.getSetupState() == SetupStackState.SetUp ) {
+                return coordinatedStack;
+            }
+        }
+        else {
+            coordinatedStack = new CoordinatedStack( stack, user, commit, module, runnerCount
);
+        }
+
+        LOG.info( "Registering stack...", stack.getName() );
+        synchronized ( coordinatedStack ) {
+            coordinatedStack.setSetupState( SetupStackSignal.DEPLOY );
+            registeredStacks.put( coordinatedStack.hashCode(), coordinatedStack );
+        }
+
+        return coordinatedStack;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/StackDestroyer.java
----------------------------------------------------------------------
diff --git a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/StackDestroyer.java
b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/StackDestroyer.java
index dfac136..1a1d1e4 100644
--- a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/StackDestroyer.java
+++ b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/StackDestroyer.java
@@ -31,7 +31,7 @@ import org.apache.usergrid.chop.spi.InstanceManager;
 import org.apache.usergrid.chop.stack.CoordinatedStack;
 import org.apache.usergrid.chop.stack.ICoordinatedCluster;
 import org.apache.usergrid.chop.stack.Instance;
-import org.apache.usergrid.chop.stack.SetupStackState;
+import org.apache.usergrid.chop.stack.SetupStackSignal;
 import org.apache.usergrid.chop.webapp.dao.ProviderParamsDao;
 import org.apache.usergrid.chop.webapp.service.InjectorFactory;
 
@@ -82,7 +82,6 @@ public class StackDestroyer {
         }
         LOG.info( "Destroying all {} cluster and runner instances of {} stack...", instances.size(),
stack.getName() );
         instanceManager.terminateInstances( instances );
-        stack.setSetupState( SetupStackState.NotSetUp );
         LOG.info( "Destroyed {} stack.", stack.getName() );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/ResetResource.java
----------------------------------------------------------------------
diff --git a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/ResetResource.java
b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/ResetResource.java
index 6567e10..8ef5eb6 100644
--- a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/ResetResource.java
+++ b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/ResetResource.java
@@ -29,6 +29,8 @@ import com.google.inject.Singleton;
 import org.apache.usergrid.chop.api.RestParams;
 import org.apache.usergrid.chop.api.Runner;
 import org.apache.usergrid.chop.api.State;
+import org.apache.usergrid.chop.stack.CoordinatedStack;
+import org.apache.usergrid.chop.stack.SetupStackSignal;
 import org.apache.usergrid.chop.stack.SetupStackState;
 import org.apache.usergrid.chop.webapp.coordinator.RunnerCoordinator;
 import org.apache.usergrid.chop.webapp.coordinator.StackCoordinator;
@@ -195,6 +197,9 @@ public class ResetResource extends TestableResource implements RestParams
{
                            .build();
         }
 
+        CoordinatedStack stack = stackCoordinator.findCoordinatedStack( commitId, artifactId,
groupId, version, user );
+        stack.setSetupState( SetupStackSignal.RESET );
+
         return Response.status( Response.Status.CREATED )
                        .entity( "All stopped runners have been reset." )
                        .type( MediaType.APPLICATION_JSON )

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StartResource.java
----------------------------------------------------------------------
diff --git a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StartResource.java
b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StartResource.java
index ff1d140..55dc11c 100644
--- a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StartResource.java
+++ b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StartResource.java
@@ -30,6 +30,7 @@ import org.apache.usergrid.chop.api.RestParams;
 import org.apache.usergrid.chop.api.Runner;
 import org.apache.usergrid.chop.api.State;
 import org.apache.usergrid.chop.stack.CoordinatedStack;
+import org.apache.usergrid.chop.stack.SetupStackSignal;
 import org.apache.usergrid.chop.stack.SetupStackState;
 import org.apache.usergrid.chop.webapp.coordinator.RunnerCoordinator;
 import org.apache.usergrid.chop.webapp.coordinator.StackCoordinator;
@@ -108,7 +109,7 @@ public class StartResource extends TestableResource implements RestParams
{
 
         if( ! status.equals( SetupStackState.SetUp ) ) {
             return Response.status( Response.Status.OK )
-                           .entity( SetupStackState.NotSetUp.getStackStateMessage() )
+                           .entity( status.getStackStateMessage() )
                            .type( MediaType.APPLICATION_JSON )
                            .build();
         }
@@ -193,6 +194,8 @@ public class StartResource extends TestableResource implements RestParams
{
                            .build();
         }
 
+        stack.setSetupState( SetupStackSignal.START );
+
         return Response.status( Response.Status.CREATED )
                        .entity( "Started chop tests" )
                        .type( MediaType.APPLICATION_JSON )

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StopResource.java
----------------------------------------------------------------------
diff --git a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StopResource.java
b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StopResource.java
index af2294e..74d91aa 100644
--- a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StopResource.java
+++ b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StopResource.java
@@ -29,6 +29,8 @@ import com.google.inject.Singleton;
 import org.apache.usergrid.chop.api.RestParams;
 import org.apache.usergrid.chop.api.Runner;
 import org.apache.usergrid.chop.api.State;
+import org.apache.usergrid.chop.stack.CoordinatedStack;
+import org.apache.usergrid.chop.stack.SetupStackSignal;
 import org.apache.usergrid.chop.stack.SetupStackState;
 import org.apache.usergrid.chop.webapp.coordinator.RunnerCoordinator;
 import org.apache.usergrid.chop.webapp.coordinator.StackCoordinator;
@@ -182,6 +184,9 @@ public class StopResource extends TestableResource implements RestParams
{
                            .build();
         }
 
+        CoordinatedStack stack = stackCoordinator.findCoordinatedStack( commitId, artifactId,
groupId, version, user );
+        stack.setSetupState( SetupStackSignal.STOP );
+
         return Response.status( Response.Status.CREATED )
                        .entity( "All running runners have been stopped." )
                        .type( MediaType.APPLICATION_JSON )

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/TestableResource.java
----------------------------------------------------------------------
diff --git a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/TestableResource.java
b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/TestableResource.java
index f8a8412..ccac1c3 100644
--- a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/TestableResource.java
+++ b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/TestableResource.java
@@ -19,8 +19,26 @@
 package org.apache.usergrid.chop.webapp.coordinator.rest;
 
 
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
 import org.safehaus.jettyjam.utils.TestMode;
 
+import org.apache.usergrid.chop.api.Commit;
+import org.apache.usergrid.chop.api.Module;
+import org.apache.usergrid.chop.stack.CoordinatedStack;
+import org.apache.usergrid.chop.stack.Stack;
+import org.apache.usergrid.chop.stack.User;
+import org.apache.usergrid.chop.webapp.coordinator.CoordinatorUtils;
+import org.apache.usergrid.chop.webapp.coordinator.StackCoordinator;
+import org.apache.usergrid.chop.webapp.dao.CommitDao;
+import org.apache.usergrid.chop.webapp.dao.ModuleDao;
+import org.apache.usergrid.chop.webapp.dao.UserDao;
+import org.apache.usergrid.chop.webapp.dao.model.BasicCommit;
+import org.apache.usergrid.chop.webapp.dao.model.BasicModule;
+
 
 /**
  * A base class for all signal resources.
@@ -47,4 +65,42 @@ public abstract class TestableResource {
         return testMode != null &&
                 (testMode.equals(TestMode.INTEG.toString()) || testMode.equals(TestMode.UNIT.toString()));
     }
+
+    public CoordinatedStack getCoordinatedStack( CommitDao commitDao, ModuleDao moduleDao,
UserDao userDao,
+                                                  StackCoordinator stackCoordinator, String
artifactId,
+                                                  String commitId, String md5, String username,
+                                                  String groupId, String version, String
vcsRepoUrl,
+                                                  String testPackage, File runnerJar )
+            throws IOException {
+        Commit commit = null;
+        Module module = null;
+
+        List<Commit> commits = commitDao.getByModule( artifactId );
+        for ( Commit returnedCommit : commits ) {
+            Module commitModule = moduleDao.get( returnedCommit.getModuleId() );
+            if ( commitModule.getArtifactId().equals( artifactId ) &&
+                    commitModule.getGroupId().equals( groupId ) &&
+                    commitModule.getVersion().equals( version ) )
+            {
+                commit = returnedCommit;
+                module = commitModule;
+            }
+        }
+
+        if ( module == null ) {
+            module = new BasicModule( groupId, artifactId, version, vcsRepoUrl, testPackage
);
+            moduleDao.save( module );
+        }
+
+        if ( commit == null ) {
+            commit = new BasicCommit( commitId, module.getId(), md5, new Date(), runnerJar.getAbsolutePath()
);
+            commitDao.save( commit );
+        }
+
+        // Send DEPLOY signal to coordinatedStack
+        Stack stack = CoordinatorUtils.getStackFromRunnerJar( runnerJar );
+        User chopUser = userDao.get( username );
+        CoordinatedStack coordinatedStack =  stackCoordinator.getCoordinatedStack( stack,
chopUser, commit, module );
+        return coordinatedStack;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96c4ef95/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/UploadResource.java
----------------------------------------------------------------------
diff --git a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/UploadResource.java
b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/UploadResource.java
index be16e66..6caaa22 100644
--- a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/UploadResource.java
+++ b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/UploadResource.java
@@ -27,8 +27,6 @@ import java.io.InputStreamReader;
 import java.net.JarURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.Date;
-import java.util.List;
 import java.util.Properties;
 
 import javax.annotation.Nullable;
@@ -41,23 +39,20 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import org.apache.usergrid.chop.stack.SetupStackState;
-import org.apache.usergrid.chop.webapp.coordinator.StackCoordinator;
 import org.safehaus.jettyjam.utils.TestMode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.usergrid.chop.api.Commit;
 import org.apache.usergrid.chop.api.Constants;
-import org.apache.usergrid.chop.api.Module;
 import org.apache.usergrid.chop.api.Project;
 import org.apache.usergrid.chop.api.RestParams;
+import org.apache.usergrid.chop.stack.SetupStackState;
 import org.apache.usergrid.chop.webapp.ChopUiFig;
 import org.apache.usergrid.chop.webapp.coordinator.CoordinatorUtils;
+import org.apache.usergrid.chop.webapp.coordinator.StackCoordinator;
 import org.apache.usergrid.chop.webapp.dao.CommitDao;
 import org.apache.usergrid.chop.webapp.dao.ModuleDao;
-import org.apache.usergrid.chop.webapp.dao.model.BasicCommit;
-import org.apache.usergrid.chop.webapp.dao.model.BasicModule;
+import org.apache.usergrid.chop.webapp.dao.UserDao;
 
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
@@ -87,7 +82,6 @@ public class UploadResource extends TestableResource implements RestParams,
Cons
     @Inject
     private StackCoordinator stackCoordinator;
 
-
     public UploadResource() {
         super( ENDPOINT );
     }
@@ -127,10 +121,12 @@ public class UploadResource extends TestableResource implements RestParams,
Cons
             @QueryParam( RestParams.MODULE_GROUPID ) String groupId,
             @QueryParam( RestParams.MODULE_VERSION ) String version,
             @QueryParam( RestParams.USERNAME ) String username,
+            @QueryParam( VCS_REPO_URL ) String vcsRepoUrl,
             @QueryParam( TEST_PACKAGE ) String testPackage,
             @QueryParam( MD5 ) String md5,
+            @QueryParam( RestParams.RUNNER_COUNT ) int runnerCount,
             @Nullable @QueryParam( TestMode.TEST_MODE_PROPERTY ) String testMode
-    ) {
+                                ) throws IOException {
 
         if( inTestMode( testMode ) ) {
             LOG.info( "Calling /upload/status in test mode ..." );
@@ -175,10 +171,11 @@ public class UploadResource extends TestableResource implements RestParams,
Cons
             @FormDataParam( VCS_REPO_URL ) String vcsRepoUrl,
             @FormDataParam( TEST_PACKAGE ) String testPackage,
             @FormDataParam( MD5 ) String md5,
+            @FormDataParam( RestParams.RUNNER_COUNT ) int runnerCount,
             @FormDataParam( CONTENT ) InputStream runnerJarStream,
             @Nullable @QueryParam( TestMode.TEST_MODE_PROPERTY ) String testMode
 
-    ) throws Exception {
+                                ) throws Exception {
 
         if( inTestMode( testMode ) ) {
             LOG.info( "Calling /upload/runner in test mode ..." );
@@ -193,14 +190,15 @@ public class UploadResource extends TestableResource implements RestParams,
Cons
         LOG.debug( "extracted {} = {}", RestParams.MODULE_VERSION, version );
         LOG.debug( "extracted {} = {}", RestParams.USERNAME, username );
         LOG.debug( "extracted {} = {}", RestParams.VCS_REPO_URL, vcsRepoUrl );
-        LOG.debug( "extracted {} = {}", RestParams.TEST_PACKAGE, testPackage );
+        LOG.debug( "extracted {} = {}", RestParams.TEST_PACKAGE, runnerCount );
+        LOG.debug( "extracted {} = {}", RestParams.RUNNER_COUNT, testPackage );
         LOG.debug( "extracted {} = {}", RestParams.MD5, md5 );
 
         if( inTestMode( testMode ) ) {
             return Response.status( Response.Status.CREATED )
-                    .entity( SUCCESSFUL_TEST_MESSAGE )
-                    .type( MediaType.TEXT_PLAIN )
-                    .build();
+                           .entity( SUCCESSFUL_TEST_MESSAGE )
+                           .type( MediaType.TEXT_PLAIN )
+                           .build();
         }
 
         File runnerJar = CoordinatorUtils.getRunnerJar( chopUiFig.getContextPath(), username,
groupId, artifactId,
@@ -232,31 +230,7 @@ public class UploadResource extends TestableResource implements RestParams,
Cons
         // - this is bad news because we will get commits of other users :(
         // - we also need to qualify the commit with username, groupId,
         //   and the version of module as well
-
-        Commit commit = null;
-        Module module = null;
-
-        List<Commit> commits = commitDao.getByModule( artifactId );
-        for ( Commit returnedCommit : commits ) {
-            Module commitModule = moduleDao.get( returnedCommit.getModuleId() );
-            if ( commitModule.getArtifactId().equals( artifactId ) &&
-                    commitModule.getGroupId().equals( groupId ) &&
-                    commitModule.getVersion().equals( version ) )
-            {
-                commit = returnedCommit;
-                module = commitModule;
-            }
-        }
-
-        if ( module == null ) {
-            module = new BasicModule( groupId, artifactId, version, vcsRepoUrl, testPackage
);
-            moduleDao.save( module );
-        }
-
-        if ( commit == null ) {
-            commit = new BasicCommit( commitId, module.getId(), md5, new Date(), runnerJar.getAbsolutePath()
);
-            commitDao.save( commit );
-        }
+        stackCoordinator.registerStack( commitId, artifactId, groupId, version, username,
runnerCount );
 
         return Response.status( Response.Status.CREATED ).entity( runnerJar.getAbsolutePath()
).build();
     }
@@ -292,4 +266,5 @@ public class UploadResource extends TestableResource implements RestParams,
Cons
 
         return coordinatorJarMd5;
     }
+
 }


Mime
View raw message