[jbosstools-commits] JBoss Tools SVN: r30418 - workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Apr 7 13:42:06 EDT 2011


Author: adietish
Date: 2011-04-07 13:42:06 -0400 (Thu, 07 Apr 2011)
New Revision: 30418

Added:
   workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/DeploymentBuilderException.java
Modified:
   workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/DeploymentBuilder.java
Log:
[JBIDE-8690] now returning status to show deployment success

Modified: workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/DeploymentBuilder.java
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/DeploymentBuilder.java	2011-04-07 15:09:52 UTC (rev 30417)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/DeploymentBuilder.java	2011-04-07 17:42:06 UTC (rev 30418)
@@ -14,14 +14,20 @@
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
+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.DeploymentPlan;
 import org.jboss.as.controller.client.helpers.standalone.DeploymentPlanBuilder;
+import org.jboss.as.controller.client.helpers.standalone.InitialDeploymentPlanBuilder;
+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;
@@ -31,46 +37,151 @@
  */
 public class DeploymentBuilder {
 
-    public static final long DEFAULT_TIMEOUT = 15 * 1000;
+	public static final long DEFAULT_TIMEOUT = 15 * 1000;
 
-    private ModelControllerClient client;
-    private ServerDeploymentManager manager;
-    private final List<File> warFiles = new ArrayList<File>();
-    private long timeout = DEFAULT_TIMEOUT;
+	private ModelControllerClient client;
+	private ServerDeploymentManager manager;
+	private final List<Deployable> deployables = new ArrayList<Deployable>();
+	private long timeout = DEFAULT_TIMEOUT;
+	private InitialDeploymentPlanBuilder builder;
 
-    public DeploymentBuilder(String host, int port) throws UnknownHostException {
-        this.client = ModelControllerClient.Factory.create(InetAddress.getByName(host), port);
-        this.manager = ServerDeploymentManager.Factory.create(client);
-    }
+	public DeploymentBuilder(String host, int port) throws UnknownHostException {
+		this.client = ModelControllerClient.Factory.create(InetAddress.getByName(host), port);
+		this.manager = ServerDeploymentManager.Factory.create(client);
+		this.builder = manager.newDeploymentPlan();
+	}
 
-    public DeploymentBuilder add(File file) {
-        warFiles.add(file);
-        return this;
-    }
+	public DeploymentBuilder add(String name, File file) {
+		deployables.add(new Deployable(name, file, timeout));
+		return this;
+	}
 
-    public void deploy() {
-        try {
-            try {
-                DeploymentPlanBuilder builder = manager.newDeploymentPlan();
-                addWarFiles(builder);
-                DeploymentPlan plan = builder.build();
-                Future<ServerDeploymentPlanResult> planResult = manager.execute(plan);
-                planResult.get(timeout, TimeUnit.MILLISECONDS);
-            } finally {
-                cleanup();
-            }
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
+	public DeploymentBuilder add(File file) {
+		return add(file.getName(), file);
+	}
 
-    private void addWarFiles(DeploymentPlanBuilder builder) throws IOException {
-        for (File warFile : warFiles) {
-            builder.add(warFile.getName(), warFile).andDeploy();
-        }
-    }
+	public DeploymentBuilder setTimeout(long timeout) {
+		this.timeout = timeout;
+		return this;
+	}
 
-    private void cleanup() {
-        StreamUtils.safeClose(client);
-    }
+	public List<Deployable> deploy() throws DeploymentBuilderException {
+		if (deployables.isEmpty()) {
+			throw new DeploymentBuilderException("no files to deploy.");
+		}
+
+		try {
+			try {
+				addWarFiles(builder, deployables);
+				DeploymentPlan plan = builder.build();
+				Future<ServerDeploymentPlanResult> planResult = manager.execute(plan);
+				setResult(planResult, deployables);
+				return deployables;
+			} finally {
+				cleanup();
+			}
+		} catch (Exception e) {
+			throw new DeploymentBuilderException(e);
+		}
+	}
+
+	private void setResult(Future<ServerDeploymentPlanResult> planResult, List<Deployable> deployables) {
+		for (Deployable deployable : deployables) {
+			deployable.setResultFuture(planResult);
+		}
+	}
+
+	private void addWarFiles(DeploymentPlanBuilder builder, List<Deployable> deployables) throws IOException {
+		for (int i = 0; i < deployables.size(); i++) {
+			Deployable deployable = deployables.get(i);
+			DeploymentPlanBuilder addBuilder = builder.add(deployable.getName(), deployable.getFile()).andDeploy();
+			deployable.setDeploymentAction(addBuilder.getLastAction());
+		}
+	}
+
+	private void cleanup() {
+		StreamUtils.safeClose(client);
+	}
+
+	public class Deployable {
+
+		private String name;
+		private File file;
+		private Future<ServerDeploymentPlanResult> resultFuture;
+		private long timeout;
+		private DeploymentAction action;
+
+		private Deployable(String name, File file, long timeout) {
+			this.name = name;
+			this.file = file;
+			this.timeout = timeout;
+		}
+
+		private void setDeploymentAction(DeploymentAction action) {
+			this.action = action;
+		}
+
+		private void setResultFuture(Future<ServerDeploymentPlanResult> resultFuture) {
+			this.resultFuture = resultFuture;
+		}
+
+		public File getFile() {
+			return file;
+		}
+
+		public String getName() {
+			return name;
+		}
+
+		public IStatus getStatus() throws DeploymentBuilderException {
+			if (resultFuture == null
+					|| action == null) {
+				return null;
+			}
+			try {
+				ServerDeploymentPlanResult result = resultFuture.get(timeout, TimeUnit.MILLISECONDS);
+				ServerDeploymentActionResult actionResult = result.getDeploymentActionResult(action.getId());
+				return createStatus(action, actionResult);
+			} catch (Exception e) {
+				throw new DeploymentBuilderException(e);
+			}
+		}
+
+		private IStatus createStatus(DeploymentAction action, ServerDeploymentActionResult actionResult) {
+			IStatus status = null;
+			switch (actionResult.getResult()) {
+			case NOT_EXECUTED:
+				status = createStatus(IStatus.ERROR, "The operation {0} was not executed on unit {1}", action
+						.getType().name(), getName());
+				break;
+			case EXECUTED:
+				status = Status.OK_STATUS;
+				break;
+			case FAILED:
+				status = createStatus(IStatus.ERROR, "The operation {0} failed for unit {1}", action.getType()
+						.name(), getName());
+				break;
+			case ROLLED_BACK:
+				status = createStatus(IStatus.ERROR, "The operation {0} for unit {1} was rolled back", action
+						.getType().name(), getName());
+				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",
+						action.getType().name(), getName());
+				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 static class Deployment {
+
+	}
 }

Added: workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/DeploymentBuilderException.java
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/DeploymentBuilderException.java	                        (rev 0)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/DeploymentBuilderException.java	2011-04-07 17:42:06 UTC (rev 30418)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.ide.eclipse.as7.deployment;
+
+/**
+ * @author André Dietisheim
+ */
+public class DeploymentBuilderException extends Exception {
+
+	private static final long serialVersionUID = 1L;
+
+	public DeploymentBuilderException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+	public DeploymentBuilderException(Throwable cause) {
+		super(cause);
+	}
+
+	public DeploymentBuilderException(String message) {
+		super(message);
+	}
+
+}


Property changes on: workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/DeploymentBuilderException.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list