[jboss-cvs] JBossAS SVN: r101394 - in projects/jboss-deployers/trunk: deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 24 09:01:55 EST 2010
Author: adrian at jboss.org
Date: 2010-02-24 09:01:55 -0500 (Wed, 24 Feb 2010)
New Revision: 101394
Modified:
projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/client/spi/DeployerClientChangeExt.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/main/MainDeployerImpl.java
projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/main/test/ChangeExtTestCase.java
projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/DeployersChangeExt.java
Log:
[JBDEPLOY-226] - Add a notion of a bouncing a deployment
Modified: projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/client/spi/DeployerClientChangeExt.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/client/spi/DeployerClientChangeExt.java 2010-02-24 13:57:56 UTC (rev 101393)
+++ projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/client/spi/DeployerClientChangeExt.java 2010-02-24 14:01:55 UTC (rev 101394)
@@ -41,4 +41,17 @@
* @throws DeploymentException for any error
*/
void change(DeploymentStage stage, boolean checkComplete, String... deploymentNames) throws DeploymentException;
+
+ /**
+ * Change the state of a number of deployments to the given stage,
+ * then return them to their original stage and optionally check the changes are complete.<p>
+ *
+ * NOTE: This only moves things backwards.
+ *
+ * @param stage the stage
+ * @param checkComplete whether to check the deployments are complete
+ * @param deploymentNames the deployment names
+ * @throws DeploymentException for any error
+ */
+ void bounce(DeploymentStage stage, boolean checkComplete, String... deploymentNames) throws DeploymentException;
}
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2010-02-24 13:57:56 UTC (rev 101393)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2010-02-24 14:01:55 UTC (rev 101394)
@@ -28,10 +28,12 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -756,21 +758,13 @@
throw new DeploymentException("Deployment " + context.getName() + " has no deployment controller context");
checkShutdown();
-
+
context.setRequiredStage(stage);
ControllerState state = ControllerState.getInstance(stageName);
- try
- {
- controller.change(deploymentControllerContext, state);
- }
- catch (Throwable t)
- {
- context.setState(DeploymentState.ERROR);
- context.setProblem(t);
- }
+ change(deploymentControllerContext, state, false);
Throwable problem = context.getProblem();
if (problem != null)
- throw DeploymentException.rethrowAsDeploymentException("Error changing to stage " + stage + " for " + context.getName(), problem);
+ throw DeploymentException.rethrowAsDeploymentException("Error changing to stage " + state + " for " + context.getName(), problem);
}
public void change(DeploymentStage stage, boolean checkComplete, DeploymentContext... contexts) throws DeploymentException
@@ -849,24 +843,9 @@
{
ControllerState current = deploymentControllerContext.getState();
if (ControllerState.ERROR.equals(current) == false && states.isAfterState(current, state))
- {
- DeploymentContext context = deploymentControllerContext.getDeploymentContext();
- try
- {
- controller.change(deploymentControllerContext, state);
- }
- catch (Throwable t)
- {
- log.warn("Error during change for " + context, t);
- context.setState(DeploymentState.ERROR);
- context.setProblem(t);
- }
- }
- else
- {
- if (trace)
- log.trace("Not moving " + deploymentControllerContext + " to state " + state + " it is at " + current);
- }
+ change(deploymentControllerContext, state);
+ else if (trace)
+ log.trace("Not moving " + deploymentControllerContext + " to state " + state + " it is at " + current);
}
if (requiredState.equals(state))
break;
@@ -883,26 +862,122 @@
ControllerState current = deploymentControllerContext.getState();
if (ControllerState.ERROR.equals(current) == false && states.isBeforeState(current, state))
{
- DeploymentContext context = deploymentControllerContext.getDeploymentContext();
- try
+ change(deploymentControllerContext, state, true);
+ }
+ else if (trace)
+ log.trace("Not moving " + deploymentControllerContext + " to state " + state + " it is at " + current);
+ }
+ if (requiredState.equals(state))
+ break;
+ }
+ }
+
+ // Now do any completeness check
+ if (checkComplete)
+ checkComplete(contexts);
+ }
+
+ public void bounce(DeploymentStage stage, boolean checkComplete, DeploymentContext... contexts) throws DeploymentException
+ {
+ if (contexts == null)
+ throw new DeploymentException("Null contexts");
+ if (stage == null)
+ throw new DeploymentException("Null stage");
+
+ String stageName = stage.getName();
+ if (stages.containsKey(stage.getName()) == false)
+ throw new DeploymentException("Unknown deployment stage: " + stage);
+ ControllerState bounceState = ControllerState.getInstance(stageName);
+
+ if (contexts.length == 0)
+ return;
+
+ Map<DeploymentControllerContext, ControllerState> toBounce = null;
+
+ boolean trace = log.isTraceEnabled();
+
+ // Work out what we are going to do
+ ControllerStateModel states = controller.getStates();
+ for (DeploymentContext context : contexts)
+ {
+ if (context == null)
+ throw new DeploymentException("Null context in " + Arrays.asList(contexts));
+ DeploymentControllerContext deploymentControllerContext = context.getTransientAttachments().getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
+ if (deploymentControllerContext == null)
+ throw new DeploymentException("Deployment " + context.getName() + " has no deployment controller context");
+ ControllerState current = deploymentControllerContext.getState();
+ if (ControllerState.ERROR.equals(current))
+ {
+ // Ignore contexts in error
+ if (trace)
+ log.trace("Not moving " + deploymentControllerContext + " to state " + bounceState + " it is currently in **ERROR**.");
+ }
+ else
+ {
+ // This is beyond the required state
+ if (states.isAfterState(current, bounceState))
+ {
+ if (toBounce == null)
+ toBounce = new LinkedHashMap<DeploymentControllerContext, ControllerState>();
+ ControllerState requiredState = ControllerState.getInstance(context.getRequiredStage().getName());
+ toBounce.put(deploymentControllerContext, requiredState);
+ context.setRequiredStage(stage);
+ }
+ // Ignore before the required state
+ else if (states.isBeforeState(current, bounceState))
+ {
+ if (trace)
+ log.trace("Not moving " + deploymentControllerContext + " to state " + bounceState + " it has not reached that state.");
+ }
+ // It is already in the required state
+ else
+ {
+ if (trace)
+ log.trace("Not moving " + deploymentControllerContext + " to state " + bounceState + " it is already there.");
+ }
+ }
+ }
+
+ checkShutdown();
+
+ // First move the contexts back to the bounce state
+ if (toBounce != null)
+ {
+ ListIterator<ControllerState> iter = states.listIteraror();
+ while (iter.hasPrevious())
+ {
+ ControllerState state = iter.previous();
+
+ for (DeploymentControllerContext deploymentControllerContext : toBounce.keySet())
+ {
+ ControllerState current = deploymentControllerContext.getState();
+ if (ControllerState.ERROR.equals(current) == false && states.isAfterState(current, state))
+ change(deploymentControllerContext, state);
+ else if (trace)
+ log.trace("Not moving " + deploymentControllerContext + " to state " + state + " it is at " + current);
+ }
+ if (bounceState.equals(state))
+ break;
+ }
+ // Now move the contexts back to their original state
+ for (ControllerState state : states)
+ {
+ if (states.isAfterState(state, bounceState))
+ {
+ for (Entry<DeploymentControllerContext, ControllerState> entry : toBounce.entrySet())
+ {
+ DeploymentControllerContext deploymentControllerContext = entry.getKey();
+ ControllerState requiredState = entry.getValue();
+ ControllerState current = deploymentControllerContext.getState();
+ if (ControllerState.ERROR.equals(current) == false && states.isBeforeState(current, requiredState) && states.isBeforeState(current, state))
{
- controller.change(deploymentControllerContext, state);
+ change(deploymentControllerContext, state, true);
}
- catch (Throwable t)
- {
- log.warn("Error during change for " + context, t);
- context.setState(DeploymentState.ERROR);
- context.setProblem(t);
- }
- }
- else
- {
- if (trace)
+ else if (trace)
log.trace("Not moving " + deploymentControllerContext + " to state " + state + " it is at " + current);
}
+
}
- if (requiredState.equals(state))
- break;
}
}
@@ -948,23 +1023,10 @@
ControllerState current = deploymentControllerContext.getState();
if (ControllerState.ERROR.equals(current) == false && states.isAfterState(current, state))
{
- DeploymentContext context = deploymentControllerContext.getDeploymentContext();
- try
- {
- controller.change(deploymentControllerContext, state);
- }
- catch (Throwable t)
- {
- log.warn("Error during undeploy", t);
- context.setState(DeploymentState.ERROR);
- context.setProblem(t);
- }
+ change(deploymentControllerContext, state);
}
- else
- {
- if (trace)
- log.trace("Not moving " + deploymentControllerContext + " to state " + state + " it is at " + current);
- }
+ else if (trace)
+ log.trace("Not moving " + deploymentControllerContext + " to state " + state + " it is at " + current);
}
}
@@ -1036,15 +1098,7 @@
if (ControllerState.ERROR.equals(current) == false && states.isBeforeState(current, state) && current.getStateString().equals(context.getRequiredStage().getName()) == false)
{
checkShutdown();
- try
- {
- controller.change(deploymentControllerContext, state);
- }
- catch (Throwable t)
- {
- context.setState(DeploymentState.ERROR);
- context.setProblem(t);
- }
+ change(deploymentControllerContext, state, false);
}
else
{
@@ -1929,6 +1983,40 @@
}
/**
+ * Change the state of a deployment
+ *
+ * @param deploymentControllerContext the controller context
+ * @param state the state to change to
+ */
+ private void change(DeploymentControllerContext deploymentControllerContext, ControllerState state)
+ {
+ change(deploymentControllerContext, state, true);
+ }
+
+ /**
+ * Change the state of a deployment
+ *
+ * @param deploymentControllerContext the controller context
+ * @param state the state to change to
+ * @param warn true when warn of error rather than throwing an exception
+ */
+ private void change(DeploymentControllerContext deploymentControllerContext, ControllerState state, boolean warn)
+ {
+ DeploymentContext context = deploymentControllerContext.getDeploymentContext();
+ try
+ {
+ controller.change(deploymentControllerContext, state);
+ }
+ catch (Throwable t)
+ {
+ context.setState(DeploymentState.ERROR);
+ context.setProblem(t);
+ if (warn)
+ log.warn("Error changing to stage " + state + " for " + context.getName(), t);
+ }
+ }
+
+ /**
* Cleanup the deployment context
*
* @param context the context
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/main/MainDeployerImpl.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/main/MainDeployerImpl.java 2010-02-24 13:57:56 UTC (rev 101393)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/main/MainDeployerImpl.java 2010-02-24 14:01:55 UTC (rev 101394)
@@ -800,6 +800,70 @@
}
}
+ public void bounce(DeploymentStage stage, boolean checkComplete, String... deploymentNames) throws DeploymentException
+ {
+ if (deployers == null)
+ throw new IllegalStateException("No deployers");
+
+ if (deploymentNames == null)
+ throw new IllegalArgumentException("Null deploymentNames");
+ if (deploymentNames.length == 0)
+ return;
+
+ lockRead();
+ try
+ {
+ DeploymentContext[] contexts = new DeploymentContext[deploymentNames.length];
+ for (int i = 0; i < contexts.length; ++i)
+ {
+ String deploymentName = deploymentNames[i];
+ DeploymentContext context = getTopLevelDeploymentContext(deploymentName);
+ if (context == null)
+ throw new DeploymentException("Top level deployment " + deploymentName + " not found");
+ contexts[i] = context;
+ }
+
+ // If we have the extension
+ if (deployers instanceof DeployersChangeExt)
+ {
+ try
+ {
+ ((DeployersChangeExt) deployers).bounce(stage, checkComplete, contexts);
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Error bouncing contexts " + Arrays.asList(deploymentNames) + " to stage " + stage, t);
+ }
+ }
+ else
+ {
+ // Do it the hard way
+ DeploymentStage[] originalStages = new DeploymentStage[contexts.length];
+ for (int i = 0; i < contexts.length; ++i)
+ {
+ DeploymentContext context = contexts[i];
+ originalStages[i] = context.getRequiredStage();
+ deployers.change(context, stage);
+ }
+ for (int i = 0; i < contexts.length; ++i)
+ {
+ DeploymentContext context = contexts[i];
+ deployers.change(context, originalStages[i]);
+ }
+ if (checkComplete)
+ deployers.checkComplete(contexts);
+ }
+ }
+ finally
+ {
+ unlockRead();
+ }
+ }
+
public void prepareShutdown()
{
if (deployers != null)
Modified: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/main/test/ChangeExtTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/main/test/ChangeExtTestCase.java 2010-02-24 13:57:56 UTC (rev 101393)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/main/test/ChangeExtTestCase.java 2010-02-24 14:01:55 UTC (rev 101394)
@@ -85,7 +85,7 @@
assertUndeployed(expected);
}
- public void testSimple() throws Throwable
+ public void testSimpleChange() throws Throwable
{
DeployerClient main = getMainDeployer();
DeployerClientChangeExt change = getChangeExt(main);
@@ -119,7 +119,7 @@
assertUndeployed(NOTHING);
}
- public void testNoMove() throws Throwable
+ public void testNoMoveChange() throws Throwable
{
DeployerClient main = getMainDeployer();
DeployerClientChangeExt change = getChangeExt(main);
@@ -147,7 +147,7 @@
assertUndeployed(NOTHING);
}
- public void testError() throws Throwable
+ public void testErrorChange() throws Throwable
{
DeployerClient main = getMainDeployer();
DeployerClientChangeExt change = getChangeExt(main);
@@ -179,7 +179,7 @@
assertUndeployed(NOTHING, deployer5);
}
- public void testCheckComplete() throws Throwable
+ public void testCheckCompleteChange() throws Throwable
{
DeployerClient main = getMainDeployer();
DeployerClientChangeExt change = getChangeExt(main);
@@ -209,7 +209,7 @@
}
}
- public void testMultiple() throws Throwable
+ public void testMultipleChange() throws Throwable
{
DeployerClient main = getMainDeployer();
DeployerClientChangeExt change = getChangeExt(main);
@@ -269,6 +269,178 @@
assertUndeployed(B, deployer5);
}
+ public void testSimpleBounce() throws Throwable
+ {
+ DeployerClient main = getMainDeployer();
+ DeployerClientChangeExt change = getChangeExt(main);
+
+ Deployment single = createSimpleDeployment("single");
+ main.deploy(single);
+ List<String> expected = new ArrayList<String>();
+ expected.add(single.getName());
+ assertDeployed(expected);
+ assertUndeployed(NOTHING);
+
+ DeploymentUnit unit = assertDeploymentUnit(main, single.getName());
+ assertEquals(main, unit.getMainDeployer());
+
+ clear();
+ change.bounce(deployer1.getStage(), true, single.getName());
+ assertDeployed(NOTHING, deployer1);
+ assertDeployed(expected, deployer2);
+ assertDeployed(expected, deployer3);
+ assertDeployed(expected, deployer4);
+ assertDeployed(expected, deployer5);
+ assertUndeployed(NOTHING, deployer1);
+ assertUndeployed(expected, deployer2);
+ assertUndeployed(expected, deployer3);
+ assertUndeployed(expected, deployer4);
+ assertUndeployed(expected, deployer5);
+ }
+
+ public void testNoMoveBounce() throws Throwable
+ {
+ DeployerClient main = getMainDeployer();
+ DeployerClientChangeExt change = getChangeExt(main);
+
+ Deployment single = createSimpleDeployment("single");
+ main.deploy(single);
+ List<String> expected = new ArrayList<String>();
+ expected.add(single.getName());
+ assertDeployed(expected);
+ assertUndeployed(NOTHING);
+
+ DeploymentUnit unit = assertDeploymentUnit(main, single.getName());
+ assertEquals(main, unit.getMainDeployer());
+
+ change.change(deployer3.getStage(), true, single.getName());
+
+ clear();
+ change.bounce(deployer3.getStage(), true, single.getName());
+ assertDeployed(NOTHING);
+ assertUndeployed(NOTHING);
+ }
+
+ public void testNoMovePreviousStateBounce() throws Throwable
+ {
+ DeployerClient main = getMainDeployer();
+ DeployerClientChangeExt change = getChangeExt(main);
+
+ Deployment single = createSimpleDeployment("single");
+ main.deploy(single);
+ List<String> expected = new ArrayList<String>();
+ expected.add(single.getName());
+ assertDeployed(expected);
+ assertUndeployed(NOTHING);
+
+ DeploymentUnit unit = assertDeploymentUnit(main, single.getName());
+ assertEquals(main, unit.getMainDeployer());
+
+ change.change(deployer1.getStage(), true, single.getName());
+
+ clear();
+ change.bounce(deployer3.getStage(), true, single.getName());
+ assertDeployed(NOTHING);
+ assertUndeployed(NOTHING);
+ }
+
+ public void testErrorBounce() throws Throwable
+ {
+ DeployerClient main = getMainDeployer();
+ DeployerClientChangeExt change = getChangeExt(main);
+
+ Deployment single = createSimpleDeployment("single");
+ main.deploy(single);
+ List<String> expected = new ArrayList<String>();
+ expected.add(single.getName());
+ assertDeployed(expected);
+ assertUndeployed(NOTHING);
+
+ DeploymentUnit unit = assertDeploymentUnit(main, single.getName());
+ assertEquals(main, unit.getMainDeployer());
+
+ makeFail(single, deployer2);
+
+ clear();
+ change.bounce(deployer1.getStage(), false, single.getName());
+ assertDeployed(NOTHING, deployer1);
+ assertDeployed(expected, deployer2);
+ assertDeployed(NOTHING, deployer3);
+ assertDeployed(NOTHING, deployer4);
+ assertDeployed(NOTHING, deployer5);
+ assertUndeployed(expected);
+ }
+
+ public void testCheckCompleteBounce() throws Throwable
+ {
+ DeployerClient main = getMainDeployer();
+ DeployerClientChangeExt change = getChangeExt(main);
+
+ Deployment single = createSimpleDeployment("single");
+ main.deploy(single);
+ List<String> expected = new ArrayList<String>();
+ expected.add(single.getName());
+ assertDeployed(expected);
+ assertUndeployed(NOTHING);
+
+ DeploymentUnit unit = assertDeploymentUnit(main, single.getName());
+ assertEquals(main, unit.getMainDeployer());
+
+ makeFail(single, deployer2);
+
+ clear();
+ try
+ {
+ change.bounce(deployer1.getStage(), true, single.getName());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IncompleteDeploymentException.class, t);
+ }
+ }
+
+ public void testMultipleBounce() throws Throwable
+ {
+ DeployerClient main = getMainDeployer();
+ DeployerClientChangeExt change = getChangeExt(main);
+
+ Deployment a = createSimpleDeployment("A");
+ main.deploy(a);
+ Deployment b = createSimpleDeployment("B");
+ main.deploy(b);
+ Deployment c = createSimpleDeployment("C");
+ main.deploy(c);
+ List<String> all = new ArrayList<String>();
+ all.add(a.getName());
+ all.add(b.getName());
+ all.add(c.getName());
+ List<String> BC = new ArrayList<String>();
+ BC.add(b.getName());
+ BC.add(c.getName());
+ List<String> C = new ArrayList<String>();
+ C.add(c.getName());
+ assertDeployed(all);
+ assertUndeployed(NOTHING);
+
+ change.change(deployer1.getStage(), true, a.getName());
+ change.change(deployer3.getStage(), true, b.getName());
+ change.change(deployer4.getStage(), true, c.getName());
+
+ clear();
+ change.bounce(deployer2.getStage(), true, a.getName(), b.getName(), c.getName());
+ assertDeployed(NOTHING, deployer1);
+ assertDeployed(NOTHING, deployer2);
+ assertDeployed(BC, deployer3);
+ assertDeployed(C, deployer4);
+ assertUndeployed(NOTHING, deployer5);
+ assertUndeployed(NOTHING, deployer1);
+ assertUndeployed(NOTHING, deployer2);
+ assertUndeployed(BC, deployer3);
+ assertUndeployed(C, deployer4);
+ assertUndeployed(NOTHING, deployer5);
+ }
+
protected DeployerClient getMainDeployer()
{
return createMainDeployer(deployer1, deployer2, deployer3, deployer4, deployer5);
Modified: projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/DeployersChangeExt.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/DeployersChangeExt.java 2010-02-24 13:57:56 UTC (rev 101393)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/DeployersChangeExt.java 2010-02-24 14:01:55 UTC (rev 101394)
@@ -42,4 +42,17 @@
* @throws DeploymentException for any error
*/
void change(DeploymentStage stage, boolean checkComplete, DeploymentContext... contexts) throws DeploymentException;
+
+ /**
+ * Change the state of a number of deployments to the given stage,
+ * then return them to their original stage and optionally check the changes are complete.<p>
+ *
+ * NOTE: This only moves things backwards.
+ *
+ * @param stage the stage
+ * @param checkComplete whether to check the deployments are complete
+ * @param contexts the deployment contexts
+ * @throws DeploymentException for any error
+ */
+ void bounce(DeploymentStage stage, boolean checkComplete, DeploymentContext... contexts) throws DeploymentException;
}
More information about the jboss-cvs-commits
mailing list