001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)Engine1Deployer.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.ui.cli.test.engine1.rt;
030:
031: import com.sun.jbi.management.ComponentMessageHolder;
032: import java.util.HashMap;
033: import java.util.Map;
034: import java.util.logging.Level;
035: import javax.jbi.component.ServiceUnitManager;
036: import javax.jbi.management.DeploymentException;
037:
038: /**
039: * fix it
040: * @author Sun Microsystems, Inc.
041: */
042: public class Engine1Deployer implements ServiceUnitManager {
043: /**
044: * fix it
045: */
046: private Engine1Runtime mContext;
047: /**
048: * fix it
049: */
050: private Map mDeployMap;
051:
052: /**
053: * Creates a new instance of Binding1Deployer
054: * @param ctx fix it
055: */
056: public Engine1Deployer(Engine1Runtime ctx) {
057: this .mDeployMap = new HashMap();
058:
059: this .mContext = ctx;
060:
061: }
062:
063: /**
064: * fix it
065: * @param asaId fix it
066: * @param asaJarPath fix it
067: * @throws DeploymentException fix it
068: * @return fix it
069: */
070: public String deploy(String asaId, String asaJarPath)
071: throws DeploymentException {
072: // this.mContext.getLogger().log(Level.INFO, "");
073: System.out.println("cli_ENGINE1: Deploying " + asaId);
074:
075: String asaInfo = (String) this .mDeployMap.get(asaId);
076: if (asaInfo != null) {
077: // throw already exists
078: String exMsg = createExceptionMessage(
079: this .mContext.getId(), "deploy", "FAILED",
080: "cli_E1_0001", asaId, "ASA " + asaId
081: + " Already Exists", null);
082: throw new DeploymentException(exMsg);
083: } else {
084: this .mDeployMap.put(asaId, asaJarPath);
085: // return "Deployed " + asaId;
086: try {
087: ComponentMessageHolder compMsgHolder = new ComponentMessageHolder(
088: "STATUS_MSG");
089: compMsgHolder.setComponentName(this .mContext.getId());
090: compMsgHolder.setTaskName("deploy");
091: compMsgHolder.setTaskResult("SUCCESS");
092:
093: return this .mContext.getMgmtMsgBuilder()
094: .buildComponentMessage(compMsgHolder);
095:
096: /*
097: return this.mContext.getMgmtMsgBuilder().buildComponentTaskStatusMessage(
098: this.mContext.getId(),
099: "deploy","SUCCESS", null
100: );
101: */
102: } catch (Exception ex) {
103: ex.printStackTrace();
104: return null;
105: }
106:
107: }
108: }
109:
110: /**
111: * fix it
112: * @param asaId fix it
113: * @return fix it
114: */
115: public String getDeploymentInfo(String asaId) {
116: // Should throw exception if asaId not exists
117: return (String) this .mDeployMap.get(asaId);
118: }
119:
120: /**
121: * fix it
122: * @return fix it
123: */
124: public String[] getDeployments() {
125: return (String[]) this .mDeployMap.keySet().toArray(
126: new String[0]);
127: }
128:
129: /**
130: * fix it
131: * @param asaId fix it
132: * @return fix it
133: */
134: public boolean isDeployed(String asaId) {
135: return (this .mDeployMap.get(asaId) != null);
136: }
137:
138: /**
139: * fix it
140: * @param asaId fix it
141: * @throws DeploymentException fix it
142: * @return fix it
143: */
144: public String undeploy(String asaId, String asaJarPath)
145: throws DeploymentException {
146: String asaInfo = (String) this .mDeployMap.remove(asaId);
147: if (asaInfo == null) {
148: // throw exception
149: String exMsg = createExceptionMessage(
150: this .mContext.getId(), "undeploy", "FAILED",
151: "cli_E1_0002", asaId, "ASA with " + asaId
152: + " Not Found", null);
153: throw new DeploymentException(exMsg);
154: } else {
155: // return "Undeployed " + asaId;
156: try {
157: ComponentMessageHolder compMsgHolder = new ComponentMessageHolder(
158: "STATUS_MSG");
159: compMsgHolder.setComponentName(this .mContext.getId());
160: compMsgHolder.setTaskName("undeploy");
161: compMsgHolder.setTaskResult("SUCCESS");
162:
163: return this .mContext.getMgmtMsgBuilder()
164: .buildComponentMessage(compMsgHolder);
165:
166: /*
167: return this.mContext.getMgmtMsgBuilder().buildComponentTaskStatusMessage(
168: this.mContext.getId(),
169: "undeploy","SUCCESS", null
170: );
171: */
172: } catch (Exception ex) {
173: ex.printStackTrace();
174: return null;
175: }
176:
177: }
178: }
179:
180: /**
181: * helper method to create XML exception string.
182: *
183: * @param compid Component id.
184: * @param oper operation like deploy or undeploy
185: * @param status success r failure
186: * @param loctoken some failure string token like SEQ_300001
187: * @param locparam parameters for error message.
188: * @param locmessage error message.
189: * @param stckTrElem stack trace of exception.
190: *
191: * @return XML string.
192: */
193: private String createExceptionMessage(String compid, String oper,
194: String status, String loctoken, String locparam,
195: String locmessage, Throwable exObj) {
196:
197: String[] locParams = new String[1];
198: locParams[0] = locparam;
199:
200: ComponentMessageHolder msgMap = new ComponentMessageHolder(
201: "EXCEPTION_MSG");
202:
203: msgMap.setComponentName(compid);
204: msgMap.setTaskName(oper);
205: msgMap.setTaskResult(status);
206: msgMap.setLocToken(1, loctoken);
207: msgMap.setLocParam(1, locParams);
208: msgMap.setLocMessage(1, locmessage);
209: msgMap.setExceptionObject(exObj);
210:
211: /*
212: msgMap.put("COMPONENTID", compid);
213: msgMap.put("TASKIDENTIFIER", oper);
214: msgMap.put("TASKRSLTSTATUS", status);
215: msgMap.put("COMPONENTEXLOCTOKEN", loctoken);
216: msgMap.put("COMPONENTEXLOCPARAM", locparam);
217: msgMap.put("COMPONENTEXLOCMESSAGE", locmessage);
218: msgMap.put("COMPONENTEXSTACKTRACE", sb.toString());
219: */
220:
221: String retMsg = null;
222:
223: try {
224: retMsg = this .mContext.getMgmtMsgBuilder()
225: .buildComponentMessage(msgMap);
226: } catch (Exception e) {
227: this .mContext.getLogger().log(Level.INFO,
228: "Failed to create Mgmt Msg", e);
229: }
230:
231: return retMsg;
232: }
233:
234: /**
235: * Initialize the deployment. This is the first phase of a two-phase
236: * start, where the component must prepare to receive service requests
237: * related to the deployment (if any).
238: * @param serviceUnitName the name of the Service Unit being initialized.
239: * @param serviceUnitRootPath the full path to the Service Unit artifact
240: * root directory.
241: * @throws javax.jbi.management.DeploymentException if the Service Unit is
242: * not deployed, or is in an incorrect state.
243: */
244: public void init(String serviceUnitName, String serviceUnitRootPath)
245: throws javax.jbi.management.DeploymentException {
246: }
247:
248: /**
249: * Shut down the deployment. This causes the deployment to return to the
250: * state it was in after <code>deploy()</code> and before <code>init()</code>.
251: * @param serviceUnitName the name of the Service Unit being shut down.
252: * @throws javax.jbi.management.DeploymentException if the Service Unit
253: * is not deployed, or is in an incorrect state.
254: */
255: public void shutDown(String serviceUnitName)
256: throws javax.jbi.management.DeploymentException {
257: }
258:
259: /**
260: * Start the deployment. This is the second phase of a two-phase start,
261: * where the component can now initiate service requests related to the
262: * deployment.
263: * @param serviceUnitName the name of the Service Unit being started.
264: * @throws javax.jbi.management.DeploymentException if the Service Unit
265: * is not deployed, or is in an incorrect state.
266: */
267: public void start(String serviceUnitName)
268: throws javax.jbi.management.DeploymentException {
269: }
270:
271: /**
272: * Stop the deployment. This causes the component to cease generating
273: * service requests related to the deployment. This returns the deployment
274: * to a state equivalent to after <code>init()</code> was called.
275: * @param serviceUnitName the name of the Service Unit being stopped.
276: * @throws javax.jbi.management.DeploymentException if the Service Unit
277: * is not deployed, or is in an incorrect state.
278: */
279: public void stop(String serviceUnitName)
280: throws javax.jbi.management.DeploymentException {
281: }
282:
283: }
|