Author: adietish
Date: 2011-04-21 16:14:54 -0400 (Thu, 21 Apr 2011)
New Revision: 30722
Added:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/JBossManagementIntegrationTest.java
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/JBossManagementTestUtils.java
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManager.java
Removed:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DeployerTestUtils.java
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/src/org/jboss/ide/eclipse/as/management/as7/deployment/TypedDeployer.java
Modified:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DetypedDeployerIntegrationTest.java
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/.classpath
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/META-INF/MANIFEST.MF
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DetypedDeployer.java
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossDeploymentManager.java
Log:
[JBIDE-8769] implementing state checking
Deleted:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DeployerTestUtils.java
===================================================================
---
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DeployerTestUtils.java 2011-04-21
20:07:15 UTC (rev 30721)
+++
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DeployerTestUtils.java 2011-04-21
20:14:54 UTC (rev 30722)
@@ -1,97 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ide.eclipse.as.management.as7.tests;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.net.HttpURLConnection;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.text.MessageFormat;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
-import org.osgi.framework.Bundle;
-
-/**
- * @author André Dietisheim
- */
-public class DeployerTestUtils {
-
- public static final String GWT_HELLOWORLD_WAR = "gwt-helloworld.war";
- public static final String MINIMALISTIC_WAR = "minimalistic.war";
-
- public static final String HOST = "localhost";
- public static final int MGMT_PORT = 9999;
- public static final int WEB_PORT = 8080;
-
- private static final String WAR_FOLDER = "/wars/";
- private static final String BUNDLE_ID =
"org.jboss.ide.eclipse.as.management.as7.tests";
-
- private static final int WEBAPP_RESPONSE_TIMEOUT = 10 * 1024;
- private static final long WAIT_DEPLOYED_TIMEOUT = 10 * 1024;
-
- public static File getWarFile(String name) throws URISyntaxException, IOException {
- Bundle bundle = Platform.getBundle(BUNDLE_ID);
- URL entryUrl = bundle.getEntry(WAR_FOLDER + name);
- return new File(FileLocator.resolve(entryUrl).toURI());
- }
-
- public static String getWebappResponse(String name, String host, int port) throws
IOException {
- long until = System.currentTimeMillis() + WAIT_DEPLOYED_TIMEOUT;
- while (System.currentTimeMillis() < until) {
- try {
- return getServerResponse(new URL(
- MessageFormat.format(
- "http://{0}:{1}/{2}", host, String.valueOf(port), name)));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
-
- }
- return null;
- }
-
- public static String getServerResponse(URL url) throws IOException {
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setUseCaches(false);
- connection.setDoInput(true);
- connection.setAllowUserInteraction(false);
- connection.setConnectTimeout(WEBAPP_RESPONSE_TIMEOUT);
- connection.setInstanceFollowRedirects(true);
- connection.setDoOutput(false);
- BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
- return toString(in);
- }
-
- public static String toString(InputStream in) throws IOException {
- StringWriter writer = new StringWriter();
- for (int data = -1; ((data = in.read()) != -1);) {
- writer.write(data);
- }
- return writer.toString();
- }
-}
Modified:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DetypedDeployerIntegrationTest.java
===================================================================
---
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DetypedDeployerIntegrationTest.java 2011-04-21
20:07:15 UTC (rev 30721)
+++
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DetypedDeployerIntegrationTest.java 2011-04-21
20:14:54 UTC (rev 30722)
@@ -40,11 +40,11 @@
@Test
public void canDeploy() throws Exception {
- File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
+ File warFile =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.MINIMALISTIC_WAR);
try {
- DetypedDeployer.deploy(warFile, DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
+ DetypedDeployer.deploy(warFile, JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
- String response = DeployerTestUtils.getWebappResponse("minimalistic",
DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
+ String response = JBossManagementTestUtils.waitForRespose("minimalistic",
JBossManagementTestUtils.HOST, JBossManagementTestUtils.WEB_PORT);
assertTrue(response.indexOf("minimalistic") >= 0);
} finally {
@@ -54,10 +54,10 @@
@Test(expected = DeployerException.class)
public void cannotDeployWarTwice() throws Exception {
- File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
+ File warFile =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.MINIMALISTIC_WAR);
try {
- DetypedDeployer.deploy(warFile, DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
- DetypedDeployer.deploy(warFile, DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
+ DetypedDeployer.deploy(warFile, JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
+ DetypedDeployer.deploy(warFile, JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
} finally {
quietlyUndeploy(warFile);
}
@@ -65,14 +65,14 @@
@Test
public void canReplaceWar() throws Exception {
- File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
- File warFile2 = DeployerTestUtils.getWarFile(DeployerTestUtils.GWT_HELLOWORLD_WAR);
+ File warFile =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.MINIMALISTIC_WAR);
+ File warFile2 =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.GWT_HELLOWORLD_WAR);
String name = warFile.getName();
try {
- DetypedDeployer.deploy(name, warFile, DeployerTestUtils.HOST,
DeployerTestUtils.MGMT_PORT);
- DetypedDeployer.replace(name, warFile2, DeployerTestUtils.HOST,
DeployerTestUtils.MGMT_PORT);
- String response = DeployerTestUtils.getWebappResponse(
- "minimalistic", DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
+ DetypedDeployer.deploy(name, warFile, JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
+ DetypedDeployer.replace(name, warFile2, JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
+ String response = JBossManagementTestUtils.waitForRespose(
+ "minimalistic", JBossManagementTestUtils.HOST,
JBossManagementTestUtils.WEB_PORT);
assertTrue(response.indexOf("GWT") >= 0);
} finally {
quietlyUndeploy(warFile);
@@ -81,19 +81,19 @@
@Test(expected = DeployerException.class)
public void cannotUndeployNondeployed() throws DeployerException {
- DetypedDeployer.undeploy("inexistant", DeployerTestUtils.HOST,
DeployerTestUtils.MGMT_PORT);
+ DetypedDeployer.undeploy("inexistant", JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
}
@Test
public void canQueryDeploymentdeployedState() throws Exception {
- File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
- File warFile2 = DeployerTestUtils.getWarFile(DeployerTestUtils.GWT_HELLOWORLD_WAR);
+ File warFile =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.MINIMALISTIC_WAR);
+ File warFile2 =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.GWT_HELLOWORLD_WAR);
try {
- DetypedDeployer.deploy(warFile, DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
- DetypedDeployer.deploy(warFile2, DeployerTestUtils.HOST,
DeployerTestUtils.MGMT_PORT);
- List<String> deployments =
DetypedDeployer.getDeployments(DeployerTestUtils.HOST, DeployerTestUtils.MGMT_PORT);
+ DetypedDeployer.deploy(warFile, JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
+ DetypedDeployer.deploy(warFile2, JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
+ List<String> deployments =
DetypedDeployer.getDeployments(JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
assertThat(deployments.size(), is(2));
- assertThat(deployments, hasItems(DeployerTestUtils.MINIMALISTIC_WAR,
DeployerTestUtils.GWT_HELLOWORLD_WAR));
+ assertThat(deployments, hasItems(JBossManagementTestUtils.MINIMALISTIC_WAR,
JBossManagementTestUtils.GWT_HELLOWORLD_WAR));
} finally {
quietlyUndeploy(warFile);
quietlyUndeploy(warFile2);
@@ -102,7 +102,7 @@
private void quietlyUndeploy(File file) {
try {
- DetypedDeployer.undeploy(file.getName(), DeployerTestUtils.HOST,
DeployerTestUtils.MGMT_PORT);
+ DetypedDeployer.undeploy(file.getName(), JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
} catch (Exception e) {
e.printStackTrace();
// ignore
Copied:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/JBossManagementIntegrationTest.java
(from rev 30703,
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/JBossManagementIntegrationTest.java
(rev 0)
+++
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/JBossManagementIntegrationTest.java 2011-04-21
20:14:54 UTC (rev 30722)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+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;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.UnknownHostException;
+import java.util.concurrent.ExecutionException;
+
+import org.jboss.ide.eclipse.as.management.as7.deployment.DeployerException;
+import org.jboss.ide.eclipse.as.management.as7.deployment.JBossManager;
+import org.jboss.ide.eclipse.as.management.as7.deployment.JBossManager.DeploymentState;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ *
+ * @author André Dietisheim
+ */
+public class JBossManagementIntegrationTest {
+
+ private JBossManager manager;
+
+ @Before
+ public void setUp() throws UnknownHostException {
+ this.manager = new JBossManager(JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
+ }
+
+ @After
+ public void tearDown() {
+ manager.dispose();
+ }
+
+ @Ignore
+ @Test
+ public void canDeploy() throws Exception {
+ File warFile =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.MINIMALISTIC_WAR);
+ try {
+ JBossManagementTestUtils.waitUntilFinished(manager.deploy(warFile));
+
+ String response = JBossManagementTestUtils.waitForRespose(
+ "minimalistic", JBossManagementTestUtils.HOST,
JBossManagementTestUtils.WEB_PORT);
+ assertTrue(response != null
+ && response.indexOf("minimalistic") >= 0);
+ } finally {
+ JBossManagementTestUtils.quietlyUndeploy(warFile, manager);
+ }
+ }
+
+ @Ignore
+ @Test
+ public void deployedWarIsResponding() throws Exception {
+ File warFile =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.MINIMALISTIC_WAR);
+ try {
+ JBossManagementTestUtils.waitUntilFinished(manager.deploy(warFile));
+
+ String response = JBossManagementTestUtils.waitForRespose(
+ "minimalistic", JBossManagementTestUtils.HOST,
JBossManagementTestUtils.WEB_PORT);
+ assertTrue(response != null
+ && response.indexOf("minimalistic") >= 0);
+
+ } finally {
+ JBossManagementTestUtils.quietlyUndeploy(warFile, manager);
+ }
+ }
+
+ @Ignore
+ @Test(expected = DeployerException.class)
+ public void cannotDeployWarTwice() throws Exception {
+ File warFile =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.MINIMALISTIC_WAR);
+ try {
+ JBossManagementTestUtils.waitUntilFinished(manager.deploy(warFile));
+ JBossManagementTestUtils.waitUntilFinished(manager.deploy(warFile));
+ } finally {
+ JBossManagementTestUtils.quietlyUndeploy(warFile, manager);
+ }
+ }
+
+ @Ignore
+ @Test(expected = DeployerException.class)
+ public void cannotUndeployNondeployed() throws DeployerException, InterruptedException,
ExecutionException {
+ JBossManagementTestUtils.waitUntilFinished(manager.undeploy("inexistant"));
+ }
+
+ @Ignore
+ @Test
+ public void canReplaceWar() throws Exception {
+ File warFile =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.MINIMALISTIC_WAR);
+ File warFile2 =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.GWT_HELLOWORLD_WAR);
+ String name = warFile.getName();
+ try {
+ JBossManagementTestUtils.waitUntilFinished(manager.deploy(name, warFile));
+ JBossManagementTestUtils.waitUntilFinished(manager.replace(name, warFile2));
+ String response = JBossManagementTestUtils.waitForRespose(
+ "minimalistic", JBossManagementTestUtils.HOST,
JBossManagementTestUtils.WEB_PORT);
+ assertTrue(response != null
+ && response.indexOf("GWT") >= 0);
+ } finally {
+ JBossManagementTestUtils.quietlyUndeploy(name, manager);
+ }
+ }
+
+ @Test
+ public void getEnabledStateIfDeploymentIsDeployed() throws URISyntaxException,
IOException, DeployerException {
+ String deploymentName = "testDeployment";
+ File warFile =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.MINIMALISTIC_WAR);
+ try {
+ JBossManagementTestUtils.waitUntilFinished(manager.deploy(deploymentName, warFile));
+ DeploymentState state = manager.getDeploymentState(deploymentName);
+ assertNotNull(state);
+ assertThat(state, equalTo(DeploymentState.ENABLEDSTATE));
+ } finally {
+ JBossManagementTestUtils.quietlyUndeploy(deploymentName, manager);
+ }
+ }
+
+ @Test
+ public void getDisabledStateIfDeploymentIsOnlyAdded() throws URISyntaxException,
IOException, DeployerException {
+ String deploymentName = "testDeployment";
+ File warFile =
JBossManagementTestUtils.getWarFile(JBossManagementTestUtils.MINIMALISTIC_WAR);
+ try {
+ JBossManagementTestUtils.waitUntilFinished(manager.add(deploymentName, warFile));
+ DeploymentState state = manager.getDeploymentState(deploymentName);
+ assertNotNull(state);
+ assertThat(state, equalTo(DeploymentState.DISABLEDSTATE));
+ } finally {
+ JBossManagementTestUtils.quietlyRemove(deploymentName, manager);
+ }
+ }
+
+ @Test(expected = DeployerException.class)
+ public void getErrorIfDeploymentIsNotDeployed() throws URISyntaxException, IOException,
DeployerException {
+ String deploymentName = "testDeployment";
+ try {
+ manager.getDeploymentState(deploymentName);
+ } finally {
+ JBossManagementTestUtils.quietlyUndeploy(deploymentName, manager);
+ }
+ }
+}
Property changes on:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/JBossManagementIntegrationTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Copied:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/JBossManagementTestUtils.java
(from rev 30699,
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DeployerTestUtils.java)
===================================================================
---
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/JBossManagementTestUtils.java
(rev 0)
+++
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/JBossManagementTestUtils.java 2011-04-21
20:14:54 UTC (rev 30722)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.tests;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.HttpURLConnection;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.ide.eclipse.as.management.as7.deployment.DeployerException;
+import org.jboss.ide.eclipse.as.management.as7.deployment.JBossManager;
+import
org.jboss.ide.eclipse.as.management.as7.deployment.JBossManager.DeploymentPlanResult;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author André Dietisheim
+ */
+public class JBossManagementTestUtils {
+
+ public static final String GWT_HELLOWORLD_WAR = "gwt-helloworld.war";
+ public static final String MINIMALISTIC_WAR = "minimalistic.war";
+
+ public static final String HOST = "localhost";
+ public static final int MGMT_PORT = 9999;
+ public static final int WEB_PORT = 8080;
+
+ private static final String WAR_FOLDER = "/wars/";
+ private static final String BUNDLE_ID =
"org.jboss.ide.eclipse.as.management.as7.tests";
+
+ private static final int RESPONSE_TIMEOUT = 10 * 1024;
+ private static final long WAIT_TIMEOUT = 10 * 1024;
+
+ public static File getWarFile(String name) throws URISyntaxException, IOException {
+ Bundle bundle = Platform.getBundle(BUNDLE_ID);
+ URL entryUrl = bundle.getEntry(WAR_FOLDER + name);
+ return new File(FileLocator.resolve(entryUrl).toURI());
+ }
+
+ public static String waitForRespose(String name, String host, int port) throws
IOException {
+ waitForResponseCode(200, name, host, port);
+ return getResponse(name, host, port);
+ }
+
+ public static void quietlyUndeploy(File file, JBossManager manager) {
+ quietlyUndeploy(file.getName(), manager);
+ }
+
+ public static void quietlyUndeploy(String name, JBossManager manager) {
+ try {
+ // DetypedDeployer.undeploy(name, JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
+ waitUntilFinished(manager.undeploy(name));
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ public static void quietlyRemove(String name, JBossManager manager) {
+ try {
+ //DetypedDeployer.remove(name, JBossManagementTestUtils.HOST,
JBossManagementTestUtils.MGMT_PORT);
+ waitUntilFinished(manager.remove(name));
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ public static void waitUntilFinished(DeploymentPlanResult result) throws
DeployerException {
+ result.getStatus(); // wait for operation to finish
+ }
+
+
+ public static String getResponse(String name, String host, int port) throws IOException
{
+ URL url = new URL("http://" + host + ":" + port + "/" +
name);
+ HttpURLConnection connection = connect(url);
+ return toString(new BufferedInputStream(connection.getInputStream()));
+ }
+
+ public static HttpURLConnection waitForResponseCode(int code, String name, String host,
int port)
+ throws IOException {
+ URL url = new URL("http://" + host + ":" + port + "/" +
name);
+ long until = System.currentTimeMillis() + WAIT_TIMEOUT;
+ while (System.currentTimeMillis() < until) {
+ HttpURLConnection connection = connect(url);
+ try {
+ if (connection.getResponseCode() == code) {
+ return connection;
+ }
+ } catch (FileNotFoundException e) {
+ if (code == 404) {
+ return connection;
+ }
+ throw e;
+ }
+ }
+ throw new RuntimeException("wait on url " + url + " for response code
" + code + " timed out.");
+ }
+
+ private static HttpURLConnection connect(URL url) throws IOException {
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setUseCaches(false);
+ connection.setDoInput(true);
+ connection.setAllowUserInteraction(false);
+ connection.setConnectTimeout(RESPONSE_TIMEOUT);
+ connection.setInstanceFollowRedirects(true);
+ connection.setDoOutput(false);
+ return connection;
+ }
+
+ public static String toString(InputStream in) throws IOException {
+ StringWriter writer = new StringWriter();
+ for (int data = -1; ((data = in.read()) != -1);) {
+ writer.write(data);
+ }
+ return writer.toString();
+ }
+}
Property changes on:
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/JBossManagementTestUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
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
20:07:15 UTC (rev 30721)
+++
trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/TypedDeployerIntegrationTest.java 2011-04-21
20:14:54 UTC (rev 30722)
@@ -1,188 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-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;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.UnknownHostException;
-import java.util.concurrent.ExecutionException;
-
-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.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;
-
-/**
- *
- * @author André Dietisheim
- */
-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();
- }
-
- @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
- && response.indexOf("minimalistic") >= 0);
-
- } finally {
- quietlyUndeploy(warFile);
- }
- }
-
- @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
- && response.indexOf("minimalistic") >= 0);
-
- } finally {
- quietlyUndeploy(warFile);
- }
- }
-
- @Ignore
- @Test(expected = DeployerException.class)
- public void cannotDeployWarTwice() throws Exception {
- File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
- try {
- waitUntilFinished(deployer.deploy(warFile));
- waitUntilFinished(deployer.deploy(warFile));
- } finally {
- quietlyUndeploy(warFile);
- }
- }
-
- @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);
- File warFile2 = DeployerTestUtils.getWarFile(DeployerTestUtils.GWT_HELLOWORLD_WAR);
- String name = warFile.getName();
- try {
- waitUntilFinished(deployer.deploy(name, warFile));
- waitUntilFinished(deployer.replace(name, warFile2));
- String response = DeployerTestUtils.getWebappResponse(
- "minimalistic", DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
- assertTrue(response != null
- && response.indexOf("GWT") >= 0);
- } finally {
- quietlyUndeploy(name);
- }
- }
-
- @Test
- public void getEnabledStateIfDeploymentIsDeployed() 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
- 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));
- } catch (Exception e) {
- e.printStackTrace();
- // ignore
- }
- }
-
- private void quietlyUndeploy(File file) {
- quietlyUndeploy(file.getName());
- }
-
- 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
20:07:15 UTC (rev 30721)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/.classpath 2011-04-21
20:14:54 UTC (rev 30722)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry exported="true" kind="lib"
path="jboss-as-controller-client-7.0.0.Beta3.jar"/>
+ <classpathentry exported="true" kind="lib"
path="jboss-as-controller-client-7.0.0.Beta3.jar"
sourcepath="/jboss-as-controller-client"/>
<classpathentry exported="true" kind="lib"
path="jboss-as-protocol-7.0.0.Beta3.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"/>
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/META-INF/MANIFEST.MF
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/META-INF/MANIFEST.MF 2011-04-21
20:07:15 UTC (rev 30721)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/META-INF/MANIFEST.MF 2011-04-21
20:14:54 UTC (rev 30722)
@@ -9,8 +9,8 @@
org.jboss.ide.eclipse.as.core
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ClassPath: jboss-as-controller-client-7.0.0.Beta3-SNAPSHOT.jar,
- jboss-as-protocol-7.0.0.Beta3-SNAPSHOT.jar,
+Bundle-ClassPath: jboss-as-controller-client-7.0.0.Beta3.jar,
+ jboss-as-protocol-7.0.0.Beta3.jar,
jboss-dmr-1.0.0.Beta5.jar,
jboss-logging-3.0.0.Beta3.jar,
jboss-marshalling-1.3.0.CR8.jar,
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DetypedDeployer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DetypedDeployer.java 2011-04-21
20:07:15 UTC (rev 30721)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DetypedDeployer.java 2011-04-21
20:14:54 UTC (rev 30722)
@@ -21,6 +21,15 @@
*/
package org.jboss.ide.eclipse.as.management.as7.deployment;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.ADD;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.ADDRESS;
+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.INPUT_STREAM_INDEX;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.OP;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.REMOVE;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.UNDEPLOY;
+
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -46,16 +55,30 @@
client = ModelControllerClient.Factory.create(host, port);
// undeploy
ModelNode request = new ModelNode();
- request.get("operation").set("undeploy");
- request.get("address").add("deployment", name);
+ request.get(OP).set(UNDEPLOY);
+ request.get(ADDRESS).add(DEPLOYMENT, name);
ModelNode result = client.execute(request);
throwOnFailure(result);
+ remove(name, host, port);
+
+ } catch (Exception e) {
+ throw new DeployerException(e);
+ } finally {
+ StreamUtils.safeClose(client);
+ }
+ }
+
+ public static void remove(String name, String host, int port) throws DeployerException
{
+ ModelControllerClient client = null;
+ try {
+ client = ModelControllerClient.Factory.create(host, port);
+
// remove
- request = new ModelNode();
- request.get("operation").set("remove");
- request.get("address").add("deployment", name);
- result = client.execute(request);
+ ModelNode request = new ModelNode();
+ request.get(OP).set(REMOVE);
+ request.get(ADDRESS).add(DEPLOYMENT, name);
+ ModelNode result = client.execute(request);
} catch (Exception e) {
throw new DeployerException(e);
} finally {
@@ -73,14 +96,14 @@
client = ModelControllerClient.Factory.create(host, port);
ModelNode request = new ModelNode();
- request.get("operation").set("add");
- request.get("address").add("deployment", name);
- request.get("enabled").set(true);
+ request.get(OP).set(ADD);
+ request.get(ADDRESS).add(DEPLOYMENT, name);
+ request.get(ENABLED).set(true);
OperationBuilder builder = OperationBuilder.Factory.create(request);
builder.addInputStream(new BufferedInputStream(new FileInputStream(file)));
Operation operation = builder.build();
- request.get("input-stream-index").set(0);
+ request.get(INPUT_STREAM_INDEX).set(0);
ModelNode result = client.execute(operation);
System.out.println(result);
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
20:07:15 UTC (rev 30721)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossDeploymentManager.java 2011-04-21
20:14:54 UTC (rev 30722)
@@ -4,31 +4,31 @@
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.DeploymentPlanResult;
+import
org.jboss.ide.eclipse.as.management.as7.deployment.JBossManager.DeploymentPlanResult;
public class JBossDeploymentManager implements IJBoss7DeploymentManager {
public DeploymentPlanResult deployAsync(String host, int port, String deploymentName,
File file, IProgressMonitor monitor) throws Exception {
- TypedDeployer deployer = new TypedDeployer(host, port);
+ JBossManager deployer = new JBossManager(host, port);
return deployer.deploy(deploymentName, file);
}
public DeploymentPlanResult deploySync(String host, int port, String deploymentName,
File file, IProgressMonitor monitor) throws Exception {
- TypedDeployer deployer = new TypedDeployer(host, port);
+ JBossManager deployer = new JBossManager(host, port);
return deployer.deploySync(deploymentName, file, monitor);
}
public DeploymentPlanResult undeployAsync(String host, int port, String deploymentName,
boolean removeFile, IProgressMonitor monitor) throws Exception {
- TypedDeployer deployer = new TypedDeployer(host, port);
+ JBossManager deployer = new JBossManager(host, port);
return deployer.undeploy(deploymentName);
}
public DeploymentPlanResult syncUndeploy(String host, int port, String deploymentName,
boolean removeFile, IProgressMonitor monitor) throws Exception {
- TypedDeployer deployer = new TypedDeployer(host, port);
+ JBossManager deployer = new JBossManager(host, port);
return deployer.undeploySync(deploymentName, monitor);
}
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManager.java
(from rev 30703,
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/JBossManager.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManager.java 2011-04-21
20:14:54 UTC (rev 30722)
@@ -0,0 +1,253 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+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.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_RESOURCE_OPERATION;
+import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.RESULT;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.text.MessageFormat;
+import java.util.concurrent.Future;
+
+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.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;
+import org.jboss.dmr.ModelNode;
+import org.jboss.ide.eclipse.as.management.as7.Activator;
+
+/**
+ * @author André Dietisheim
+ */
+public class JBossManager {
+
+ private ModelControllerClient client;
+ private ServerDeploymentManager manager;
+
+ public JBossManager(String host, int port) throws UnknownHostException {
+ this.client = ModelControllerClient.Factory.create(host, port);
+ this.manager = ServerDeploymentManager.Factory.create(client);
+ }
+
+ public DeploymentPlanResult undeploySync(String name, IProgressMonitor monitor) throws
DeployerException {
+ DeploymentPlanResult result = undeploy(name);
+ result.getStatus();
+ return result;
+ }
+
+ public DeploymentPlanResult deploySync(String name, File file, IProgressMonitor monitor)
throws DeployerException {
+ DeploymentPlanResult result = deploy(name, file);
+ result.getStatus();
+ return result;
+ }
+
+ public DeploymentPlanResult undeploy(String name) throws DeployerException {
+ try {
+ DeploymentPlanBuilder builder = manager.newDeploymentPlan();
+ builder = builder.undeploy(name).andRemoveUndeployed();
+ return new DeploymentPlanResult(builder.getLastAction(),
manager.execute(builder.build()));
+ } catch (Exception e) {
+ throw new DeployerException(e);
+ }
+ }
+
+ public DeploymentPlanResult remove(String name) throws DeployerException {
+ try {
+ DeploymentPlanBuilder builder = manager.newDeploymentPlan();
+ builder = builder.remove(name);
+ return new DeploymentPlanResult(builder.getLastAction(),
manager.execute(builder.build()));
+ } catch (Exception e) {
+ throw new DeployerException(e);
+ }
+ }
+
+ public DeploymentPlanResult deploy(File file) throws DeployerException {
+ return deploy(file.getName(), file);
+ }
+
+ public DeploymentPlanResult add(String name, File file) throws DeployerException {
+ try {
+ return execute(manager.newDeploymentPlan().add(name, file));
+ } catch (IOException e) {
+ throw new DeployerException(e);
+ }
+ }
+
+ public DeploymentPlanResult deploy(String name, File file) throws DeployerException {
+ try {
+ return execute(manager.newDeploymentPlan().add(name, file).andDeploy());
+ } catch (IOException e) {
+ throw new DeployerException(e);
+ }
+ }
+
+ public DeploymentPlanResult replace(File file) throws DeployerException {
+ return replace(file.getName(), file);
+ }
+
+ public DeploymentPlanResult replace(String name, File file) throws DeployerException {
+ try {
+ return execute(manager.newDeploymentPlan().replace(name, file));
+ } catch (IOException e) {
+ throw new DeployerException(e);
+ }
+ }
+
+ 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 DeploymentPlanResult(action, planResult);
+ } catch (Exception e) {
+ throw new DeployerException(e);
+ }
+ }
+
+ public static class DeploymentPlanResult {
+
+ private Future<ServerDeploymentPlanResult> planResult;
+ private DeploymentAction action;
+
+ public DeploymentPlanResult(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));
+ }
+ }
+
+ public enum DeploymentState {
+ ENABLEDSTATE {
+ protected boolean matches(boolean enabled) {
+ return enabled == true;
+ }
+ },
+ DISABLEDSTATE {
+ 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);
+
+ }
+}
Deleted:
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
20:07:15 UTC (rev 30721)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/TypedDeployer.java 2011-04-21
20:14:54 UTC (rev 30722)
@@ -1,237 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-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.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_RESOURCE_OPERATION;
-import static
org.jboss.ide.eclipse.as.management.as7.deployment.ModelDescriptionConstants.RESULT;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.UnknownHostException;
-import java.text.MessageFormat;
-import java.util.concurrent.Future;
-
-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.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;
-import org.jboss.dmr.ModelNode;
-import org.jboss.ide.eclipse.as.management.as7.Activator;
-
-/**
- *
- * @author André Dietisheim
- */
-public class TypedDeployer {
-
- 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);
- }
-
- public DeploymentPlanResult undeploySync(String name, IProgressMonitor monitor) throws
DeployerException {
- DeploymentPlanResult result = undeploy(name);
- result.getStatus();
- return result;
- }
-
- public DeploymentPlanResult deploySync(String name, File file, IProgressMonitor monitor)
throws DeployerException {
- DeploymentPlanResult result = deploy(name, file);
- result.getStatus();
- return result;
- }
-
- public DeploymentPlanResult undeploy(String name) throws DeployerException {
- try {
- DeploymentPlanBuilder builder = manager.newDeploymentPlan();
- builder = builder.undeploy(name).andRemoveUndeployed();
- return new DeploymentPlanResult(builder.getLastAction(),
manager.execute(builder.build()));
- } catch (Exception e) {
- throw new DeployerException(e);
- }
- }
-
- public DeploymentPlanResult deploy(File file) throws DeployerException {
- return deploy(file.getName(), file);
- }
-
- public DeploymentPlanResult deploy(String name, File file) throws DeployerException {
- try {
- return execute(manager.newDeploymentPlan().add(name, file).andDeploy());
- } catch (IOException e) {
- throw new DeployerException(e);
- }
- }
-
- public DeploymentPlanResult replace(File file) throws DeployerException {
- return replace(file.getName(), file);
- }
-
- public DeploymentPlanResult replace(String name, File file) throws DeployerException {
- try {
- return execute(manager.newDeploymentPlan().replace(name, file));
- } catch (IOException e) {
- throw new DeployerException(e);
- }
- }
-
- 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 DeploymentPlanResult(action, planResult);
- } catch (Exception e) {
- throw new DeployerException(e);
- }
- }
-
- public static class DeploymentPlanResult {
-
- private Future<ServerDeploymentPlanResult> planResult;
- private DeploymentAction action;
-
- public DeploymentPlanResult(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));
- }
- }
-
- 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);
-
- }
-}