001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.config;
017:
018: import java.io.Closeable;
019: import java.io.File;
020: import java.io.FileInputStream;
021: import java.io.IOException;
022: import java.io.InputStream;
023: import java.io.PrintWriter;
024: import java.io.Serializable;
025: import java.io.StringWriter;
026: import java.net.URI;
027: import java.net.URISyntaxException;
028: import java.util.ArrayList;
029: import java.util.Collection;
030: import java.util.Collections;
031: import java.util.HashSet;
032: import java.util.List;
033: import java.util.Locale;
034: import java.util.Properties;
035: import java.util.Set;
036: import java.util.TreeSet;
037: import java.util.Arrays;
038: import javax.enterprise.deploy.model.DeployableObject;
039: import javax.enterprise.deploy.shared.ActionType;
040: import javax.enterprise.deploy.shared.CommandType;
041: import javax.enterprise.deploy.shared.DConfigBeanVersionType;
042: import javax.enterprise.deploy.shared.ModuleType;
043: import javax.enterprise.deploy.shared.StateType;
044: import javax.enterprise.deploy.spi.DeploymentConfiguration;
045: import javax.enterprise.deploy.spi.DeploymentManager;
046: import javax.enterprise.deploy.spi.Target;
047: import javax.enterprise.deploy.spi.TargetModuleID;
048: import javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException;
049: import javax.enterprise.deploy.spi.exceptions.InvalidModuleException;
050: import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
051: import javax.enterprise.deploy.spi.exceptions.TargetException;
052: import javax.enterprise.deploy.spi.status.ClientConfiguration;
053: import javax.enterprise.deploy.spi.status.DeploymentStatus;
054: import javax.enterprise.deploy.spi.status.ProgressEvent;
055: import javax.enterprise.deploy.spi.status.ProgressListener;
056: import javax.enterprise.deploy.spi.status.ProgressObject;
057: import javax.naming.InitialContext;
058:
059: import org.apache.openejb.NoSuchApplicationException;
060: import org.apache.openejb.OpenEJBException;
061: import org.apache.openejb.UndeployException;
062: import org.apache.openejb.assembler.classic.AppInfo;
063: import org.apache.openejb.assembler.classic.ClientInfo;
064: import org.apache.openejb.assembler.classic.EjbJarInfo;
065: import org.apache.openejb.assembler.classic.InfoObject;
066: import org.apache.openejb.assembler.classic.ConnectorInfo;
067: import org.apache.openejb.assembler.classic.WebAppInfo;
068: import org.apache.openejb.assembler.Deployer;
069:
070: public class VmDeploymentManager implements DeploymentManager {
071: private static final Target DEFAULT_TARGET = new TargetImpl(
072: "DefaultTarget", "OpenEJB Default Target");
073: private static final DConfigBeanVersionType DCONFIG_BEAN_VERSION = DConfigBeanVersionType.V1_4;
074: private static final Locale LOCALE = Locale.getDefault();
075:
076: private boolean connected = true;
077: private Deployer deployer;
078: private final String openejbUri;
079: private boolean deployerLocal;
080:
081: public VmDeploymentManager() {
082: String openejbHome = System.getProperty("openejb.home",
083: "target/openejb-3.0.0-SNAPSHOT");
084: File openejbHomeDir = new File(openejbHome);
085: if (!openejbHomeDir.exists()) {
086: throw new IllegalArgumentException(
087: "OpenEJB home dir does not exist: "
088: + openejbHomeDir);
089: }
090: if (!openejbHomeDir.isDirectory()) {
091: throw new IllegalArgumentException(
092: "OpenEJB home dir is not a directory: "
093: + openejbHomeDir);
094: }
095:
096: String openejbUri = System.getProperty("openejb.server.uri");
097: if (openejbUri == null) {
098: try {
099: openejbUri = new URI("ejb", null, "localhost", 4201,
100: null, null, null).toString();
101: } catch (URISyntaxException e) {
102: throw new RuntimeException(e);
103: }
104: }
105: this .openejbUri = openejbUri;
106:
107: }
108:
109: private Deployer getDeployer() {
110: if (deployer == null) {
111: try {
112: Properties p = new Properties();
113: p
114: .put("java.naming.factory.initial",
115: "org.apache.openejb.client.RemoteInitialContextFactory");
116: p.put("java.naming.provider.url", openejbUri);
117:
118: InitialContext ctx = new InitialContext(p);
119: deployer = (Deployer) ctx
120: .lookup("openejb/DeployerBusinessRemote");
121: } catch (Exception e) {
122: throw new RuntimeException(e);
123: }
124: }
125: return deployer;
126: }
127:
128: private boolean isDeployerLocal() {
129: if (deployer == null) {
130: deployerLocal = new File(getDeployer().getUniqueFile())
131: .exists();
132: }
133: return deployerLocal;
134: }
135:
136: public void release() {
137: connected = false;
138: }
139:
140: public Target[] getTargets() {
141: if (!connected)
142: throw new IllegalStateException(
143: "Deployment manager is disconnected");
144:
145: return new Target[] { DEFAULT_TARGET };
146: }
147:
148: public TargetModuleID[] getAvailableModules(ModuleType moduleType,
149: Target[] targetList) throws TargetException {
150: if (!connected)
151: throw new IllegalStateException(
152: "Deployment manager is disconnected");
153:
154: if (!containsDefaultTarget(targetList)) {
155: return null;
156: }
157:
158: Set<TargetModuleID> targetModuleIds = toTargetModuleIds(
159: getDeployer().getDeployedApps(), moduleType);
160: return targetModuleIds
161: .toArray(new TargetModuleID[targetModuleIds.size()]);
162: }
163:
164: private static Set<TargetModuleID> toTargetModuleIds(
165: Collection<AppInfo> deployedApps,
166: ModuleType allowedModuleType) {
167: Set<TargetModuleID> targetModuleIds = new HashSet<TargetModuleID>(
168: deployedApps.size());
169: for (AppInfo deployedApp : deployedApps) {
170: TargetModuleID moduleId = toTargetModuleId(deployedApp,
171: allowedModuleType);
172: // moduleID will be null if the module was filtered
173: if (moduleId != null) {
174: targetModuleIds.add(moduleId);
175: }
176: }
177: return targetModuleIds;
178: }
179:
180: private static TargetModuleID toTargetModuleId(AppInfo appInfo,
181: ModuleType allowedModuleType) {
182: List<InfoObject> infos = new ArrayList<InfoObject>();
183: infos.addAll(appInfo.clients);
184: infos.addAll(appInfo.ejbJars);
185: infos.addAll(appInfo.webApps);
186: infos.addAll(appInfo.connectors);
187:
188: // if the module id is the same as the appInfo, then it is a standalone module
189: if (infos.size() == 1) {
190: InfoObject infoObject = infos.get(0);
191: if (infoObject instanceof ClientInfo) {
192: ClientInfo clientInfo = (ClientInfo) infoObject;
193: if (appInfo.jarPath.equals(clientInfo.codebase)) {
194: // are client modules allowed
195: if (allowedModuleType != null
196: && !allowedModuleType
197: .equals(ModuleType.CAR)) {
198: return null;
199: }
200: if (clientInfo.moduleId == appInfo.jarPath) {
201: return new TargetModuleIDImpl(DEFAULT_TARGET,
202: clientInfo.moduleId);
203: }
204: }
205: }
206: if (infoObject instanceof EjbJarInfo) {
207: EjbJarInfo ejbJarInfo = (EjbJarInfo) infoObject;
208: if (appInfo.jarPath.equals(ejbJarInfo.jarPath)) {
209: // are ejb modules allowed
210: if (allowedModuleType != null
211: && !allowedModuleType
212: .equals(ModuleType.EJB)) {
213: return null;
214: }
215: if (ejbJarInfo.moduleId == appInfo.jarPath) {
216: return new TargetModuleIDImpl(DEFAULT_TARGET,
217: ejbJarInfo.moduleId);
218: }
219: }
220: }
221: if (infoObject instanceof ConnectorInfo) {
222: ConnectorInfo connectorInfo = (ConnectorInfo) infoObject;
223: if (appInfo.jarPath.equals(connectorInfo.codebase)) {
224: // are connector modules allowed
225: if (allowedModuleType != null
226: && !allowedModuleType
227: .equals(ModuleType.RAR)) {
228: return null;
229: }
230: if (connectorInfo.moduleId == appInfo.jarPath) {
231: return new TargetModuleIDImpl(DEFAULT_TARGET,
232: connectorInfo.moduleId);
233: }
234: }
235: }
236: if (infoObject instanceof WebAppInfo) {
237: WebAppInfo webAppInfo = (WebAppInfo) infoObject;
238: if (appInfo.jarPath.equals(webAppInfo.codebase)) {
239: // are web app modules allowed
240: if (allowedModuleType != null
241: && !allowedModuleType
242: .equals(ModuleType.WAR)) {
243: return null;
244: }
245: if (webAppInfo.moduleId == appInfo.jarPath) {
246: return new TargetModuleIDImpl(DEFAULT_TARGET,
247: webAppInfo.moduleId); //todo web module
248: }
249: }
250: }
251: }
252:
253: // regular ear
254:
255: // are ear modules allowed
256: if (allowedModuleType != null
257: && !allowedModuleType.equals(ModuleType.EAR)) {
258: return null;
259: }
260:
261: TargetModuleIDImpl earModuleId = new TargetModuleIDImpl(
262: DEFAULT_TARGET, appInfo.jarPath);
263: for (ClientInfo clientInfo : appInfo.clients) {
264: TargetModuleIDImpl clientModuleId = new TargetModuleIDImpl(
265: DEFAULT_TARGET, clientInfo.moduleId);
266: clientModuleId.setParentTargetModuleID(earModuleId);
267: }
268: for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
269: TargetModuleIDImpl ejbJarModuleId = new TargetModuleIDImpl(
270: DEFAULT_TARGET, ejbJarInfo.moduleId);
271: ejbJarModuleId.setParentTargetModuleID(earModuleId);
272: }
273: for (ConnectorInfo connectorInfo : appInfo.connectors) {
274: TargetModuleIDImpl clientModuleId = new TargetModuleIDImpl(
275: DEFAULT_TARGET, connectorInfo.moduleId);
276: clientModuleId.setParentTargetModuleID(earModuleId);
277: }
278: for (WebAppInfo webAppInfo : appInfo.webApps) {
279: TargetModuleIDImpl clientModuleId = new TargetModuleIDImpl(
280: DEFAULT_TARGET, webAppInfo.moduleId,
281: webAppInfo.contextRoot);
282: clientModuleId.setParentTargetModuleID(earModuleId);
283: }
284:
285: return earModuleId;
286: }
287:
288: public TargetModuleID[] getNonRunningModules(ModuleType moduleType,
289: Target[] targetList) throws TargetException {
290: if (!connected)
291: throw new IllegalStateException(
292: "Deployment manager is disconnected");
293:
294: if (!containsDefaultTarget(targetList)) {
295: return null;
296: }
297:
298: return new TargetModuleIDImpl[0];
299: }
300:
301: public TargetModuleID[] getRunningModules(ModuleType moduleType,
302: Target[] targetList) throws TargetException {
303: if (!connected)
304: throw new IllegalStateException(
305: "Deployment manager is disconnected");
306:
307: if (!containsDefaultTarget(targetList)) {
308: return null;
309: }
310:
311: Set<TargetModuleID> targetModuleIds = toTargetModuleIds(
312: getDeployer().getDeployedApps(), moduleType);
313: return targetModuleIds
314: .toArray(new TargetModuleID[targetModuleIds.size()]);
315: }
316:
317: public ProgressObject distribute(Target[] targetList,
318: File moduleFile, File planFile) {
319: if (!connected)
320: throw new IllegalStateException(
321: "Deployment manager is disconnected");
322:
323: if (!isDeployerLocal()) {
324: // todo when we input stream is a valid remote type we can implement this
325: throw new UnsupportedOperationException(
326: "Deployment from a remote computer is not currently supproted");
327: }
328:
329: // load properties
330: Properties properties = new Properties();
331: if (planFile != null) {
332: InputStream in = null;
333: try {
334: in = new FileInputStream(planFile);
335: properties.load(in);
336: } catch (IOException ignored) {
337: } finally {
338: close(in);
339: }
340:
341: }
342:
343: ProgressObject progressObject = deploy(targetList, properties);
344: return progressObject;
345: }
346:
347: public ProgressObject distribute(Target[] targetList,
348: InputStream moduleStream, InputStream planStream) {
349: if (!connected)
350: throw new IllegalStateException(
351: "Deployment manager is disconnected");
352:
353: // consume module stream
354: if (isDeployerLocal()) {
355: close(moduleStream);
356: } else {
357: // todo when we input stream is a valid remote type we can implement this
358: throw new UnsupportedOperationException(
359: "Deployment from a remote computer is not currently supproted");
360: }
361:
362: // load properties
363: Properties properties = new Properties();
364: if (planStream != null) {
365: try {
366: properties.load(planStream);
367: } catch (IOException ignored) {
368: } finally {
369: close(planStream);
370: }
371:
372: }
373: ProgressObject progressObject = deploy(targetList, properties);
374: return progressObject;
375: }
376:
377: private ProgressObject deploy(Target[] targetList,
378: Properties properties) {
379: if (targetList == null)
380: return new ProgressObjectImpl(CommandType.DISTRIBUTE,
381: new NullPointerException("targetList is null"));
382:
383: if (!containsDefaultTarget(targetList)) {
384: return new ProgressObjectImpl(CommandType.DISTRIBUTE,
385: Collections.<TargetModuleID> emptySet());
386: }
387:
388: try {
389: AppInfo appInfo = getDeployer().deploy(properties);
390: TargetModuleID targetModuleId = toTargetModuleId(appInfo,
391: null);
392:
393: return new ProgressObjectImpl(CommandType.DISTRIBUTE,
394: Collections.singleton(targetModuleId));
395: } catch (OpenEJBException e) {
396: return new ProgressObjectImpl(CommandType.DISTRIBUTE, e);
397: }
398: }
399:
400: private boolean containsDefaultTarget(Target[] targetList) {
401: for (Target target : targetList) {
402: if (DEFAULT_TARGET.equals(target))
403: return true;
404: }
405: return false;
406: }
407:
408: public ProgressObject start(TargetModuleID[] moduleIdList) {
409: if (!connected)
410: throw new IllegalStateException(
411: "Deployment manager is disconnected");
412:
413: Set<TargetModuleID> deployedModules = toTargetModuleIds(
414: getDeployer().getDeployedApps(), null);
415: Set<TargetModuleID> targetModuleIds = new HashSet<TargetModuleID>(
416: Arrays.asList(moduleIdList));
417: targetModuleIds.retainAll(deployedModules);
418:
419: return new ProgressObjectImpl(CommandType.START,
420: targetModuleIds);
421: }
422:
423: public ProgressObject stop(TargetModuleID[] moduleIdList) {
424: if (!connected)
425: throw new IllegalStateException(
426: "Deployment manager is disconnected");
427:
428: return new ProgressObjectImpl(CommandType.START, Collections
429: .<TargetModuleID> emptySet());
430: }
431:
432: public ProgressObject undeploy(TargetModuleID[] moduleIdList) {
433: if (!connected)
434: throw new IllegalStateException(
435: "Deployment manager is disconnected");
436:
437: UndeployException undeployException = null;
438: Set<TargetModuleID> results = new TreeSet<TargetModuleID>();
439: for (TargetModuleID targetModuleId : moduleIdList) {
440: try {
441: getDeployer().undeploy(targetModuleId.getModuleID());
442: results.add(targetModuleId);
443: } catch (UndeployException e) {
444: if (undeployException == null) {
445: undeployException = e;
446: }
447: } catch (NoSuchApplicationException e) {
448: // app was not deployed... this should be ignored by jsr88
449: }
450: }
451:
452: if (undeployException == null) {
453: return new ProgressObjectImpl(CommandType.UNDEPLOY, results);
454: } else {
455: return new ProgressObjectImpl(CommandType.UNDEPLOY,
456: undeployException);
457: }
458: }
459:
460: public boolean isRedeploySupported() {
461: return false;
462: }
463:
464: public ProgressObject redeploy(TargetModuleID[] moduleIDList,
465: File moduleArchive, File deploymentPlan) {
466: throw new UnsupportedOperationException(
467: "redeploy is not supported");
468: }
469:
470: public ProgressObject redeploy(TargetModuleID[] moduleIDList,
471: InputStream moduleArchive, InputStream deploymentPlan) {
472: throw new UnsupportedOperationException(
473: "redeploy is not supported");
474: }
475:
476: public Locale[] getSupportedLocales() {
477: return new Locale[] { getDefaultLocale() };
478: }
479:
480: public Locale getCurrentLocale() {
481: return getDefaultLocale();
482: }
483:
484: public Locale getDefaultLocale() {
485: return LOCALE;
486: }
487:
488: public boolean isLocaleSupported(Locale locale) {
489: return getDefaultLocale().equals(locale);
490: }
491:
492: public void setLocale(Locale locale) {
493: if (!isLocaleSupported(locale)) {
494: throw new UnsupportedOperationException(
495: "Unsupported locale");
496: }
497: }
498:
499: public DConfigBeanVersionType getDConfigBeanVersion() {
500: return DCONFIG_BEAN_VERSION;
501: }
502:
503: public boolean isDConfigBeanVersionSupported(
504: DConfigBeanVersionType version) {
505: return DCONFIG_BEAN_VERSION.equals(version);
506: }
507:
508: public void setDConfigBeanVersion(DConfigBeanVersionType version)
509: throws DConfigBeanVersionUnsupportedException {
510: if (!isDConfigBeanVersionSupported(version)) {
511: throw new DConfigBeanVersionUnsupportedException(
512: "Version not supported " + version);
513: }
514: }
515:
516: public DeploymentConfiguration createConfiguration(
517: DeployableObject deployableObject)
518: throws InvalidModuleException {
519: throw new InvalidModuleException("Not supported: "
520: + deployableObject.getType());
521: }
522:
523: public String toString() {
524: if (connected) {
525: return "OpenEJBDeploymentManager - connected";
526: } else {
527: return "OpenEJBDeploymentManager - disconnected";
528: }
529: }
530:
531: public static class TargetImpl implements Target, Comparable,
532: Serializable {
533: private static final long serialVersionUID = -7257857314911948377L;
534: private final String name;
535: private final String description;
536:
537: public TargetImpl(String name) {
538: this (name, null);
539: }
540:
541: public TargetImpl(String name, String description) {
542: if (name == null)
543: throw new NullPointerException("name is null");
544: this .name = name;
545: this .description = description;
546: }
547:
548: public String getName() {
549: return name;
550: }
551:
552: public String getDescription() {
553: return description;
554: }
555:
556: public String toString() {
557: return name;
558: }
559:
560: public boolean equals(Object o) {
561: if (this == o)
562: return true;
563: if (!(o instanceof TargetImpl))
564: return false;
565:
566: TargetImpl target = (TargetImpl) o;
567: return name.equals(target.name);
568: }
569:
570: public int hashCode() {
571: return name.hashCode();
572: }
573:
574: public int compareTo(Object o) {
575: TargetImpl target = (TargetImpl) o;
576: return name.compareTo(target.name);
577: }
578: }
579:
580: public static class TargetModuleIDImpl implements TargetModuleID,
581: Comparable, Serializable {
582: private static final long serialVersionUID = 2471961579457311472L;
583:
584: private final Target target;
585: private final String moduleId;
586: private final String webUrl;
587: private TargetModuleID parentTargetModuleId;
588: private Set<TargetModuleID> children = new TreeSet<TargetModuleID>();
589:
590: public TargetModuleIDImpl(Target target, String moduleId) {
591: this (target, moduleId, null);
592: }
593:
594: public TargetModuleIDImpl(Target target, String moduleId,
595: String webUrl) {
596: if (target == null)
597: throw new NullPointerException("target is null");
598: if (moduleId == null)
599: throw new NullPointerException("moduleId is null");
600: this .target = target;
601: this .moduleId = moduleId;
602: if (webUrl != null && !webUrl.startsWith("http:"))
603: webUrl = "http://localhost:8080/" + webUrl;
604: this .webUrl = webUrl;
605: }
606:
607: public Target getTarget() {
608: return target;
609: }
610:
611: public String getModuleID() {
612: return moduleId;
613: }
614:
615: public TargetModuleID getParentTargetModuleID() {
616: return parentTargetModuleId;
617: }
618:
619: public void setParentTargetModuleID(
620: TargetModuleIDImpl parentTargetModuleId) {
621: this .parentTargetModuleId = parentTargetModuleId;
622: parentTargetModuleId.children.add(this );
623: }
624:
625: public TargetModuleID[] getChildTargetModuleID() {
626: return children
627: .toArray(new TargetModuleID[children.size()]);
628: }
629:
630: public String getWebURL() {
631: return webUrl;
632: }
633:
634: public String toString() {
635: return target + "/" + moduleId
636: + (webUrl == null ? " " : webUrl);
637: }
638:
639: public boolean equals(Object o) {
640: if (this == o)
641: return true;
642: if (!(o instanceof TargetModuleIDImpl))
643: return false;
644:
645: TargetModuleIDImpl targetModuleID = (TargetModuleIDImpl) o;
646: return target.equals(targetModuleID.target)
647: && moduleId.equals(targetModuleID.moduleId);
648: }
649:
650: public int hashCode() {
651: int result;
652: result = target.hashCode();
653: result = 29 * result + moduleId.hashCode();
654: return result;
655: }
656:
657: public int compareTo(Object o) {
658: TargetModuleIDImpl targetModuleID = (TargetModuleIDImpl) o;
659:
660: // compare target name
661: int val = target.getName().compareTo(
662: targetModuleID.target.getName());
663: if (val != 0)
664: return val;
665:
666: // compare moduleId
667: return moduleId.compareTo(targetModuleID.moduleId);
668: }
669: }
670:
671: public class ProgressObjectImpl implements ProgressObject {
672: private final Set<TargetModuleID> targetModuleIds;
673: private final ProgressEvent event;
674: private final DeploymentStatus deploymentStatus;
675:
676: public ProgressObjectImpl(CommandType command,
677: Set<TargetModuleID> targetModuleIds) {
678: this .targetModuleIds = targetModuleIds;
679: deploymentStatus = new DeploymentStatusImpl(command);
680: event = new ProgressEvent(this , null, deploymentStatus);
681: }
682:
683: public ProgressObjectImpl(CommandType command,
684: Exception exception) {
685: this .targetModuleIds = null;
686: deploymentStatus = new DeploymentStatusImpl(command,
687: exception);
688: event = new ProgressEvent(this , null, deploymentStatus);
689: }
690:
691: public synchronized TargetModuleID[] getResultTargetModuleIDs() {
692: if (targetModuleIds == null)
693: return new TargetModuleID[0];
694: return targetModuleIds
695: .toArray(new TargetModuleID[targetModuleIds.size()]);
696: }
697:
698: public synchronized DeploymentStatus getDeploymentStatus() {
699: return deploymentStatus;
700: }
701:
702: public ClientConfiguration getClientConfiguration(
703: TargetModuleID id) {
704: return null;
705: }
706:
707: public boolean isCancelSupported() {
708: return false;
709: }
710:
711: public void cancel() throws OperationUnsupportedException {
712: throw new OperationUnsupportedException(
713: "cancel is not supported");
714: }
715:
716: public boolean isStopSupported() {
717: return false;
718: }
719:
720: public void stop() throws OperationUnsupportedException {
721: throw new OperationUnsupportedException(
722: "stop is not supported");
723: }
724:
725: public void addProgressListener(ProgressListener pol) {
726: pol.handleProgressEvent(event);
727: }
728:
729: public void removeProgressListener(ProgressListener pol) {
730: }
731:
732: }
733:
734: public static class DeploymentStatusImpl implements
735: DeploymentStatus {
736: private final CommandType command;
737: private final StateType state;
738: private final String message;
739:
740: public DeploymentStatusImpl(CommandType command) {
741: this .command = command;
742: this .state = StateType.COMPLETED;
743: this .message = null;
744: }
745:
746: public DeploymentStatusImpl(CommandType command,
747: Exception exception) {
748: this .command = command;
749: this .state = StateType.FAILED;
750:
751: StringWriter writer = new StringWriter();
752: exception.printStackTrace(new PrintWriter(writer, true));
753: this .message = writer.toString();
754: }
755:
756: public CommandType getCommand() {
757: return command;
758: }
759:
760: public ActionType getAction() {
761: return ActionType.EXECUTE;
762: }
763:
764: public String getMessage() {
765: return message;
766: }
767:
768: public StateType getState() {
769: return state;
770: }
771:
772: public boolean isRunning() {
773: return StateType.RUNNING.equals(state);
774: }
775:
776: public boolean isCompleted() {
777: return StateType.COMPLETED.equals(state);
778: }
779:
780: public boolean isFailed() {
781: return StateType.FAILED.equals(state);
782: }
783:
784: public String toString() {
785: StringBuffer buf = new StringBuffer();
786: buf.append("DeploymentStatus[").append(command).append(',');
787: buf.append(state);
788: if (message != null) {
789: buf.append(',').append(message);
790: }
791: buf.append(']');
792: return buf.toString();
793: }
794: }
795:
796: private static void close(Closeable thing) {
797: if (thing != null) {
798: try {
799: thing.close();
800: } catch (Exception ignored) {
801: }
802: }
803: }
804: }
|