[jbosstools-commits] JBoss Tools SVN: r30586 - in workspace/adietish: org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/internal/deployment and 1 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Fri Apr 15 11:32:27 EDT 2011
Author: adietish
Date: 2011-04-15 11:32:27 -0400 (Fri, 15 Apr 2011)
New Revision: 30586
Modified:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/TypedDeployerIntegrationTest.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/internal/deployment/TypedDeployer.java
Log:
replaced future with DeploymentResult
Modified: workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath 2011-04-15 10:01:21 UTC (rev 30585)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath 2011-04-15 15:32:27 UTC (rev 30586)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="jboss-threads-2.0.0.CR8.jar" sourcepath="/home/adietish/jboss-workspaces/jboss-tools/jbosstools-src/jboss-threads-2.0.0.CR8-sources.jar"/>
- <classpathentry exported="true" kind="lib" path="jboss-as-controller-client-7.0.0.Beta3-SNAPSHOT.jar" sourcepath="/home/rob/.m2/repository/org/jboss/as/jboss-as-controller-client/7.0.0.Beta3-SNAPSHOT/jboss-as-controller-client-7.0.0.Beta3-SNAPSHOT-sources.jar"/>
+ <classpathentry exported="true" kind="lib" path="jboss-as-controller-client-7.0.0.Beta3-SNAPSHOT.jar" sourcepath="/jboss-as-controller-client"/>
<classpathentry exported="true" kind="lib" path="jboss-as-protocol-7.0.0.Beta3-SNAPSHOT.jar" sourcepath="/jboss-as-protocol"/>
<classpathentry exported="true" kind="lib" path="jboss-dmr-1.0.0.Beta5.jar" sourcepath="/home/adietish/jboss-workspaces/jboss-tools/jbosstools-src/jboss-dmr-1.0.0.Beta5-sources.jar"/>
<classpathentry exported="true" kind="lib" path="jboss-logging-3.0.0.Beta3.jar"/>
Modified: workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/internal/deployment/TypedDeployer.java
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/internal/deployment/TypedDeployer.java 2011-04-15 10:01:21 UTC (rev 30585)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/internal/deployment/TypedDeployer.java 2011-04-15 15:32:27 UTC (rev 30586)
@@ -22,14 +22,21 @@
package org.jboss.ide.eclipse.as7.internal.deployment;
import java.io.File;
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.text.MessageFormat;
import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.jboss.as.controller.client.ModelControllerClient;
-import org.jboss.as.controller.client.helpers.standalone.DeploymentPlan;
-import org.jboss.as.controller.client.helpers.standalone.InitialDeploymentPlanBuilder;
+import org.jboss.as.controller.client.helpers.standalone.DeploymentAction;
+import org.jboss.as.controller.client.helpers.standalone.DeploymentPlanBuilder;
+import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentActionResult;
import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentManager;
+import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentPlanResult;
import org.jboss.as.protocol.StreamUtils;
/**
@@ -38,83 +45,68 @@
*/
public class TypedDeployer {
- public static void undeploySync(String name, String host, int port, IProgressMonitor monitor) throws DeployerException {
- Future f = undeploy(name, host, port);
- syncWait(f, monitor);
- }
-
- public static void syncDeploy(String name, File file, String host, int port, IProgressMonitor monitor) throws DeployerException {
- Future f = deploy(name, file, host, port);
- syncWait(f, monitor);
+ private ModelControllerClient client;
+ private ServerDeploymentManager manager;
+
+ public TypedDeployer(String host, int port) throws UnknownHostException {
+ this.client = ModelControllerClient.Factory.create(host, port);
+ this.manager = ServerDeploymentManager.Factory.create(client);
}
-
- private static void syncWait(Future f, IProgressMonitor monitor) {
- while(!f.isDone()) {
- if( monitor.isCanceled()) {
- f.cancel(true);
- return;
- }
- try {
- Thread.sleep(150);
- } catch(InterruptedException ie) {
- }
- }
+
+ public void undeploySync(String name, IProgressMonitor monitor) throws DeployerException {
+ DeploymentResult result = undeploy(name);
+ result.getStatus();
}
-
- public static Future undeploy(String name, String host, int port) throws DeployerException {
- ModelControllerClient client = null;
+
+ public void syncDeploy(String name, File file, IProgressMonitor monitor) throws DeployerException {
+ DeploymentResult result = deploy(name, file);
+ result.getStatus();
+ }
+
+ public DeploymentResult undeploy(String name) throws DeployerException {
try {
- client = ModelControllerClient.Factory.create(host, port);
- ServerDeploymentManager manager = ServerDeploymentManager.Factory.create(client);
- InitialDeploymentPlanBuilder builder = manager.newDeploymentPlan();
-
- DeploymentPlan plan = builder.undeploy(name).andRemoveUndeployed().build();
- return manager.execute(plan);
+ DeploymentPlanBuilder builder = manager.newDeploymentPlan();
+ builder = builder.undeploy(name).andRemoveUndeployed();
+ return new DeploymentResult(builder.getLastAction(), manager.execute(builder.build()));
} catch (Exception e) {
throw new DeployerException(e);
- } finally {
- StreamUtils.safeClose(client);
}
}
- public static Future deploy(File file, String host, int port) throws DeployerException {
- return deploy(file.getName(), file, host, port);
+ public DeploymentResult deploy(File file) throws DeployerException {
+ return deploy(file.getName(), file);
}
- public static Future deploy(String name, File file, String host, int port) throws DeployerException {
- return internalDeploy(name, file, host, port, false);
+ public DeploymentResult deploy(String name, File file) throws DeployerException {
+ try {
+ return execute(manager.newDeploymentPlan().add(name, file).andDeploy());
+ } catch (IOException e) {
+ throw new DeployerException(e);
+ }
}
- public static Future replace(File file, String host, int port) throws DeployerException {
- return replace(file.getName(), file, host, port);
+ public DeploymentResult replace(File file) throws DeployerException {
+ return replace(file.getName(), file);
}
- public static Future replace(String name, File file, String host, int port) throws DeployerException {
- return internalDeploy(name, file, host, port, true);
+ public DeploymentResult replace(String name, File file) throws DeployerException {
+ try {
+ return execute(manager.newDeploymentPlan().replace(name, file));
+ } catch (IOException e) {
+ throw new DeployerException(e);
+ }
}
- public static Future internalDeploy(String name, File file, String host, int port, boolean replace) throws DeployerException {
- ModelControllerClient client = null;
+ private DeploymentResult execute(DeploymentPlanBuilder builder) throws DeployerException {
try {
- client = ModelControllerClient.Factory.create(host, port);
- ServerDeploymentManager manager = ServerDeploymentManager.Factory.create(client);
- InitialDeploymentPlanBuilder builder = manager.newDeploymentPlan();
-
- DeploymentPlan plan = null;
- if( replace )
- plan = builder.replace(name, file).build();
- else
- plan = builder.add(name, file).deploy(name).build();
-
- return manager.execute(plan);
+ DeploymentAction action = builder.getLastAction();
+ Future<ServerDeploymentPlanResult> planResult = manager.execute(builder.build());
+ return new DeploymentResult(action, planResult);
} catch (Exception e) {
throw new DeployerException(e);
- } finally {
- StreamUtils.safeClose(client);
}
}
-
-
+
//
// public static boolean isDeployed(String name, String host, int port)
// throws CancellationException, IOException {
@@ -141,8 +133,67 @@
// }
// }
- private TypedDeployer() {
- // inhibit instantiation
+ public void dispose() {
+ StreamUtils.safeClose(client);
}
+ public static class DeploymentResult {
+
+ private Future<ServerDeploymentPlanResult> planResult;
+ private DeploymentAction action;
+
+ public DeploymentResult(DeploymentAction action, Future<ServerDeploymentPlanResult> planResult) {
+ Assert.isNotNull(action);
+ this.action = action;
+ Assert.isNotNull(planResult);
+ this.planResult = planResult;
+ }
+
+ public IStatus getStatus() throws DeployerException {
+ try {
+ ServerDeploymentActionResult actionResult = planResult.get().getDeploymentActionResult(action.getId());
+ return createStatus(action.getDeploymentUnitUniqueName(), action.getType().name(), actionResult);
+ } catch (Exception e) {
+ throw new DeployerException(e);
+ }
+ }
+
+ private IStatus createStatus(String deploymentName, String actionName, ServerDeploymentActionResult actionResult) {
+ if (actionResult == null) {
+ return null;
+ }
+
+ IStatus status = null;
+ switch (actionResult.getResult()) {
+ case NOT_EXECUTED:
+ status = createStatus(IStatus.ERROR, "The operation {0} was not executed on unit {1}",
+ actionName, deploymentName);
+ break;
+ case EXECUTED:
+ status = Status.OK_STATUS;
+ break;
+ case FAILED:
+ status = createStatus(IStatus.ERROR, "The operation {0} failed for unit {1}",
+ actionName, deploymentName);
+ break;
+ case ROLLED_BACK:
+ status = createStatus(IStatus.ERROR, "The operation {0} for unit {1} was rolled back",
+ actionName, deploymentName);
+ break;
+ case CONFIGURATION_MODIFIED_REQUIRES_RESTART:
+ status = createStatus(
+ IStatus.WARNING,
+ "The operation {0} was not executed on unit {1}. The server configuration was changed though and the server needs to be restarted",
+ actionName, deploymentName);
+ break;
+ }
+ return status;
+ }
+
+ private IStatus createStatus(int severity, String messagePattern, Object... messageArguments) {
+ return new Status(severity, Activator.getContext().getBundle().getSymbolicName(), MessageFormat.format(
+ messagePattern, messageArguments));
+ }
+ }
+
}
Modified: workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/TypedDeployerIntegrationTest.java
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/TypedDeployerIntegrationTest.java 2011-04-15 10:01:21 UTC (rev 30585)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/TypedDeployerIntegrationTest.java 2011-04-15 15:32:27 UTC (rev 30586)
@@ -24,9 +24,14 @@
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.net.UnknownHostException;
+import java.util.concurrent.ExecutionException;
import org.jboss.ide.eclipse.as7.internal.deployment.DeployerException;
import org.jboss.ide.eclipse.as7.internal.deployment.TypedDeployer;
+import org.jboss.ide.eclipse.as7.internal.deployment.TypedDeployer.DeploymentResult;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
/**
@@ -35,12 +40,24 @@
*/
public class TypedDeployerIntegrationTest {
+ private TypedDeployer deployer;
+
+ @Before
+ public void setUp() throws UnknownHostException {
+ this.deployer = new TypedDeployer(DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
+ }
+
+ @After
+ public void tearDown() {
+ deployer.dispose();
+ }
+
@Test
public void canDeploy() throws Exception {
File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
try {
- TypedDeployer.deploy(warFile, DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
-
+ waitUntilFinished(deployer.deploy(warFile));
+
String response = DeployerTestUtils.getWebappResponse(
"minimalistic", DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
assertTrue(response.indexOf("minimalistic") >= 0);
@@ -54,26 +71,26 @@
public void cannotDeployWarTwice() throws Exception {
File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
try {
- TypedDeployer.deploy(warFile, DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
- TypedDeployer.deploy(warFile, DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
+ waitUntilFinished(deployer.deploy(warFile));
+ waitUntilFinished(deployer.deploy(warFile));
} finally {
quietlyUndeploy(warFile);
}
}
@Test(expected = DeployerException.class)
- public void cannotUndeployNondeployed() throws DeployerException {
- TypedDeployer.undeploy("inexistant", DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
+ public void cannotUndeployNondeployed() throws DeployerException, InterruptedException, ExecutionException {
+ waitUntilFinished(deployer.undeploy("inexistant"));
}
@Test
- public void canReplaceyWar() throws Exception {
+ public void canReplaceWar() throws Exception {
File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
File warFile2 = DeployerTestUtils.getWarFile(DeployerTestUtils.GWT_HELLOWORLD_WAR);
String name = warFile.getName();
try {
- TypedDeployer.deploy(name, warFile, DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
- TypedDeployer.replace(name, warFile2, DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
+ waitUntilFinished(deployer.deploy(name, warFile));
+ waitUntilFinished(deployer.replace(name, warFile2));
String response = DeployerTestUtils.getWebappResponse(
"minimalistic", DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
assertTrue(response.indexOf("GWT") >= 0);
@@ -126,12 +143,17 @@
// return writer.toString();
// }
//
+
private void quietlyUndeploy(File file) {
try {
- TypedDeployer.undeploy(file.getName(), DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
+ waitUntilFinished(deployer.undeploy(file.getName()));
} catch (Exception e) {
e.printStackTrace();
// ignore
}
}
+
+ private void waitUntilFinished(DeploymentResult result) throws DeployerException {
+ result.getStatus(); // wait for operation to finish
+ }
}
More information about the jbosstools-commits
mailing list