Author: adietish
Date: 2011-04-21 11:28:12 -0400 (Thu, 21 Apr 2011)
New Revision: 30703
Modified:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/TypedDeployerIntegrationTest.java
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/.classpath
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossDeploymentManager.java
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManagementUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/TypedDeployer.java
Log:
[JBIDE-8769] implementing state checking
Modified:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/TypedDeployerIntegrationTest.java
===================================================================
---
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/TypedDeployerIntegrationTest.java 2011-04-21
15:01:38 UTC (rev 30702)
+++
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/TypedDeployerIntegrationTest.java 2011-04-21
15:28:12 UTC (rev 30703)
@@ -21,6 +21,8 @@
*/
package org.jboss.ide.eclipse.as.management.as7.tests;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -32,9 +34,11 @@
import org.jboss.ide.eclipse.as.management.as7.deployment.DeployerException;
import org.jboss.ide.eclipse.as.management.as7.deployment.TypedDeployer;
-import
org.jboss.ide.eclipse.as.management.as7.deployment.TypedDeployer.DeploymentResult;
+import
org.jboss.ide.eclipse.as.management.as7.deployment.TypedDeployer.DeploymentPlanResult;
+import org.jboss.ide.eclipse.as.management.as7.deployment.TypedDeployer.DeploymentState;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -49,21 +53,22 @@
public void setUp() throws UnknownHostException {
this.deployer = new TypedDeployer(DeployerTestUtils.HOST,
DeployerTestUtils.MGMT_PORT);
}
-
+
@After
public void tearDown() {
deployer.dispose();
}
-
+
+ @Ignore
@Test
public void canDeploy() throws Exception {
File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
try {
waitUntilFinished(deployer.deploy(warFile));
-
+
String response = DeployerTestUtils.getWebappResponse(
"minimalistic", DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
- assertTrue(response != null
+ assertTrue(response != null
&& response.indexOf("minimalistic") >= 0);
} finally {
@@ -71,15 +76,16 @@
}
}
+ @Ignore
@Test
public void deployedWarIsResponding() throws Exception {
File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
try {
waitUntilFinished(deployer.deploy(warFile));
-
+
String response = DeployerTestUtils.getWebappResponse(
"minimalistic", DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
- assertTrue(response != null
+ assertTrue(response != null
&& response.indexOf("minimalistic") >= 0);
} finally {
@@ -87,6 +93,7 @@
}
}
+ @Ignore
@Test(expected = DeployerException.class)
public void cannotDeployWarTwice() throws Exception {
File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
@@ -98,11 +105,13 @@
}
}
+ @Ignore
@Test(expected = DeployerException.class)
public void cannotUndeployNondeployed() throws DeployerException, InterruptedException,
ExecutionException {
waitUntilFinished(deployer.undeploy("inexistant"));
}
+ @Ignore
@Test
public void canReplaceWar() throws Exception {
File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
@@ -113,26 +122,53 @@
waitUntilFinished(deployer.replace(name, warFile2));
String response = DeployerTestUtils.getWebappResponse(
"minimalistic", DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
- assertTrue(response != null
+ assertTrue(response != null
&& response.indexOf("GWT") >= 0);
} finally {
quietlyUndeploy(name);
}
}
-
+
@Test
- public void canQueryDeploymentState() throws URISyntaxException, IOException,
DeployerException {
+ public void getEnabledStateIfDeploymentIsDeployed() throws URISyntaxException,
IOException, DeployerException {
String deploymentName = "testDeployment";
File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
try {
waitUntilFinished(deployer.deploy(deploymentName, warFile));
- String state = deployer.getDeploymentState(deploymentName);
+ DeploymentState state = deployer.getDeploymentState(deploymentName);
assertNotNull(state);
+ assertThat(state, equalTo(DeploymentState.ENABLEDSTATE));
} finally {
quietlyUndeploy(deploymentName);
}
}
-
+
+ @Test
+ public void getDisabledStateIfDeploymentIsOnlyAdded() throws URISyntaxException,
IOException, DeployerException {
+ String deploymentName = "testDeployment";
+ File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
+ try {
+ waitUntilFinished(deployer.deploy(deploymentName, warFile));
+ DeploymentState state = deployer.getDeploymentState(deploymentName);
+ assertNotNull(state);
+ assertThat(state, equalTo(DeploymentState.ENABLEDSTATE));
+ } finally {
+ quietlyUndeploy(deploymentName);
+ }
+ }
+
+ @Test(expected=DeployerException.class)
+ public void getErrorIfDeploymentIsNotDeployed() throws URISyntaxException, IOException,
DeployerException {
+ String deploymentName = "testDeployment";
+ try {
+ DeploymentState state = deployer.getDeploymentState(deploymentName);
+ assertNotNull(state);
+ assertThat(state, equalTo(DeploymentState.ENABLEDSTATE));
+ } finally {
+ quietlyUndeploy(deploymentName);
+ }
+ }
+
private void quietlyUndeploy(String name) {
try {
waitUntilFinished(deployer.undeploy(name));
@@ -141,12 +177,12 @@
// ignore
}
}
-
+
private void quietlyUndeploy(File file) {
quietlyUndeploy(file.getName());
}
-
- private void waitUntilFinished(DeploymentResult result) throws DeployerException {
+
+ private void waitUntilFinished(DeploymentPlanResult result) throws DeployerException {
result.getStatus(); // wait for operation to finish
}
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/.classpath
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/.classpath 2011-04-21
15:01:38 UTC (rev 30702)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/.classpath 2011-04-21
15:28:12 UTC (rev 30703)
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry exported="true" kind="lib"
path="jboss-as-controller-client-7.0.0.Beta3-SNAPSHOT.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"/>
- <classpathentry exported="true" kind="lib"
path="jboss-dmr-1.0.0.Beta5.jar"/>
+ <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"/>
<classpathentry exported="true" kind="lib"
path="jboss-marshalling-1.3.0.CR8.jar"/>
- <classpathentry exported="true" kind="lib"
path="jboss-threads-2.0.0.CR8.jar"/>
+ <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 kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossDeploymentManager.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossDeploymentManager.java 2011-04-21
15:01:38 UTC (rev 30702)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossDeploymentManager.java 2011-04-21
15:28:12 UTC (rev 30703)
@@ -4,29 +4,29 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.jboss.ide.eclipse.as.core.server.internal.v7.IJBoss7DeploymentManager;
-import
org.jboss.ide.eclipse.as.management.as7.deployment.TypedDeployer.DeploymentResult;
+import
org.jboss.ide.eclipse.as.management.as7.deployment.TypedDeployer.DeploymentPlanResult;
public class JBossDeploymentManager implements IJBoss7DeploymentManager {
- public DeploymentResult deployAsync(String host, int port, String deploymentName,
+ public DeploymentPlanResult deployAsync(String host, int port, String deploymentName,
File file, IProgressMonitor monitor) throws Exception {
TypedDeployer deployer = new TypedDeployer(host, port);
return deployer.deploy(deploymentName, file);
}
- public DeploymentResult deploySync(String host, int port, String deploymentName,
+ public DeploymentPlanResult deploySync(String host, int port, String deploymentName,
File file, IProgressMonitor monitor) throws Exception {
TypedDeployer deployer = new TypedDeployer(host, port);
return deployer.deploySync(deploymentName, file, monitor);
}
- public DeploymentResult undeployAsync(String host, int port, String deploymentName,
+ public DeploymentPlanResult undeployAsync(String host, int port, String deploymentName,
boolean removeFile, IProgressMonitor monitor) throws Exception {
TypedDeployer deployer = new TypedDeployer(host, port);
return deployer.undeploy(deploymentName);
}
- public DeploymentResult syncUndeploy(String host, int port, String deploymentName,
+ public DeploymentPlanResult syncUndeploy(String host, int port, String deploymentName,
boolean removeFile, IProgressMonitor monitor) throws Exception {
TypedDeployer deployer = new TypedDeployer(host, port);
return deployer.undeploySync(deploymentName, monitor);
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManagementUtil.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManagementUtil.java 2011-04-21
15:01:38 UTC (rev 30702)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManagementUtil.java 2011-04-21
15:28:12 UTC (rev 30703)
@@ -37,6 +37,7 @@
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.Operation;
import org.jboss.dmr.ModelNode;
+import org.jboss.dmr.ModelType;
import org.jboss.dmr.Property;
import org.jboss.ide.eclipse.as.management.as7.internal.DefaultOperationRequestBuilder;
import org.jboss.ide.eclipse.as.management.as7.internal.OperationFormatException;
@@ -131,6 +132,22 @@
return Collections.emptyList();
}
+ public static Boolean getBooleanProperty(String propertyName, ModelNode node) {
+ if (node == null) {
+ return null;
+ }
+ ModelNode valueNode = node.get(propertyName);
+ if (valueNode == null) {
+ return null;
+ }
+ String value = valueNode.toString();
+ if (value == null
+ || valueNode.getType() != ModelType.BOOLEAN) {
+ return null;
+ }
+ return Boolean.valueOf(value);
+ }
+
public static ModelNode execute(Operation operation, ModelControllerClient client)
throws DeployerException {
try {
ModelNode result = client.execute(operation);
@@ -142,7 +159,7 @@
throw new DeployerException(result.get(FAILURE_DESCRIPTION).toString());
}
else {
- throw new DeployerException("Operation outcome is " +
result.get(OUTCOME).asString());
+ throw new DeployerException("Operation outcome is " +
result.get(OUTCOME).asString());
}
} catch (IOException e) {
throw new DeployerException(e);
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/TypedDeployer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/TypedDeployer.java 2011-04-21
15:01:38 UTC (rev 30702)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/TypedDeployer.java 2011-04-21
15:28:12 UTC (rev 30703)
@@ -22,9 +22,12 @@
package org.jboss.ide.eclipse.as.management.as7.deployment;
import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.ADDRESS;
-import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.NAME;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.DEPLOYMENT;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.ENABLED;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.OP;
-import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.READ_RESOURCE_OPERATION;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.RESULT;
import java.io.File;
import java.io.IOException;
@@ -37,7 +40,6 @@
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.OperationBuilder;
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;
@@ -61,33 +63,33 @@
this.manager = ServerDeploymentManager.Factory.create(client);
}
- public DeploymentResult undeploySync(String name, IProgressMonitor monitor) throws
DeployerException {
- DeploymentResult result = undeploy(name);
+ public DeploymentPlanResult undeploySync(String name, IProgressMonitor monitor) throws
DeployerException {
+ DeploymentPlanResult result = undeploy(name);
result.getStatus();
return result;
}
- public DeploymentResult deploySync(String name, File file, IProgressMonitor monitor)
throws DeployerException {
- DeploymentResult result = deploy(name, file);
+ public DeploymentPlanResult deploySync(String name, File file, IProgressMonitor monitor)
throws DeployerException {
+ DeploymentPlanResult result = deploy(name, file);
result.getStatus();
return result;
}
- public DeploymentResult undeploy(String name) throws DeployerException {
+ public DeploymentPlanResult undeploy(String name) throws DeployerException {
try {
DeploymentPlanBuilder builder = manager.newDeploymentPlan();
builder = builder.undeploy(name).andRemoveUndeployed();
- return new DeploymentResult(builder.getLastAction(),
manager.execute(builder.build()));
+ return new DeploymentPlanResult(builder.getLastAction(),
manager.execute(builder.build()));
} catch (Exception e) {
throw new DeployerException(e);
}
}
- public DeploymentResult deploy(File file) throws DeployerException {
+ public DeploymentPlanResult deploy(File file) throws DeployerException {
return deploy(file.getName(), file);
}
- public DeploymentResult deploy(String name, File file) throws DeployerException {
+ public DeploymentPlanResult deploy(String name, File file) throws DeployerException {
try {
return execute(manager.newDeploymentPlan().add(name, file).andDeploy());
} catch (IOException e) {
@@ -95,11 +97,11 @@
}
}
- public DeploymentResult replace(File file) throws DeployerException {
+ public DeploymentPlanResult replace(File file) throws DeployerException {
return replace(file.getName(), file);
}
- public DeploymentResult replace(String name, File file) throws DeployerException {
+ public DeploymentPlanResult replace(String name, File file) throws DeployerException {
try {
return execute(manager.newDeploymentPlan().replace(name, file));
} catch (IOException e) {
@@ -107,36 +109,48 @@
}
}
- private DeploymentResult execute(DeploymentPlanBuilder builder) throws DeployerException
{
+ public DeploymentState getDeploymentState(String name) throws DeployerException {
+ ModelNode request = new ModelNode();
+ request.get(OP).set(READ_RESOURCE_OPERATION);
+ request.get(ADDRESS).add(DEPLOYMENT, name);
+
+ ModelNode result = execute(request);
+ return DeploymentState.getForResultNode(result);
+ }
+
+ public void dispose() {
+ StreamUtils.safeClose(client);
+ }
+
+ private ModelNode execute(ModelNode node) throws DeployerException {
try {
+ ModelNode response = client.execute(node);
+ if (!JBossManagementUtil.isSuccess(response)) {
+ throw new DeployerException(
+ MessageFormat.format("Could not execute {0} for {1}. Failure was {2}.",
node.get(OP), node.get(ADDRESS), response.get(FAILURE_DESCRIPTION)));
+ }
+ return response.get(RESULT);
+ } catch (Exception e) {
+ throw new DeployerException(e);
+ }
+ }
+
+ private DeploymentPlanResult execute(DeploymentPlanBuilder builder) throws
DeployerException {
+ try {
DeploymentAction action = builder.getLastAction();
Future<ServerDeploymentPlanResult> planResult =
manager.execute(builder.build());
- return new DeploymentResult(action, planResult);
+ return new DeploymentPlanResult(action, planResult);
} catch (Exception e) {
throw new DeployerException(e);
}
}
- public String getServerName() throws DeployerException {
- ModelNode request = new ModelNode();
- request.get(OP).set(READ_ATTRIBUTE_OPERATION);
- request.get(ADDRESS).set(ADDRESS);
- request.get(NAME).set(NAME);
+ public static class DeploymentPlanResult {
- ModelNode response =
JBossManagementUtil.execute(OperationBuilder.Factory.create(request).build(), client);
- return response.asString();
- }
-
- public void dispose() {
- StreamUtils.safeClose(client);
- }
-
- public static class DeploymentResult {
-
private Future<ServerDeploymentPlanResult> planResult;
private DeploymentAction action;
- public DeploymentResult(DeploymentAction action,
Future<ServerDeploymentPlanResult> planResult) {
+ public DeploymentPlanResult(DeploymentAction action,
Future<ServerDeploymentPlanResult> planResult) {
Assert.isNotNull(action);
this.action = action;
Assert.isNotNull(planResult);
@@ -190,4 +204,34 @@
}
}
+ public enum DeploymentState {
+ ENABLEDSTATE {
+ protected boolean matches(boolean enabled) {
+ return enabled == true;
+ }
+ },
+ STOPPEDSTATE {
+ protected boolean matches(boolean enabled) {
+ return enabled == false;
+ }
+ };
+
+ public static DeploymentState getForResultNode(ModelNode resultNode) {
+ Boolean enabled = JBossManagementUtil.getBooleanProperty(ENABLED, resultNode);
+ if (enabled == null) {
+ return null;
+ }
+
+ DeploymentState matchingState = null;
+ for(DeploymentState state : values()) {
+ if (state.matches(enabled)) {
+ matchingState = state;
+ }
+ }
+ return matchingState;
+ }
+
+ protected abstract boolean matches(boolean enabled);
+
+ }
}