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: * @(#)Engine2Deployer.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.engine2.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 Engine2Deployer implements ServiceUnitManager {
043: /**
044: * fix it
045: */
046: private Engine2Runtime 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 Engine2Deployer(Engine2Runtime 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_ENGINE2: 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: * Initialize the deployment. This is the first phase of a two-phase
182: * start, where the component must prepare to receive service requests
183: * related to the deployment (if any).
184: * @param serviceUnitName the name of the Service Unit being initialized.
185: * @param serviceUnitRootPath the full path to the Service Unit artifact
186: * root directory.
187: * @throws javax.jbi.management.DeploymentException if the Service Unit is
188: * not deployed, or is in an incorrect state.
189: */
190: public void init(String serviceUnitName, String serviceUnitRootPath)
191: throws javax.jbi.management.DeploymentException {
192: }
193:
194: /**
195: * Shut down the deployment. This causes the deployment to return to the
196: * state it was in after <code>deploy()</code> and before <code>init()</code>.
197: * @param serviceUnitName the name of the Service Unit being shut down.
198: * @throws javax.jbi.management.DeploymentException if the Service Unit
199: * is not deployed, or is in an incorrect state.
200: */
201: public void shutDown(String serviceUnitName)
202: throws javax.jbi.management.DeploymentException {
203: }
204:
205: /**
206: * Start the deployment. This is the second phase of a two-phase start,
207: * where the component can now initiate service requests related to the
208: * deployment.
209: * @param serviceUnitName the name of the Service Unit being started.
210: * @throws javax.jbi.management.DeploymentException if the Service Unit
211: * is not deployed, or is in an incorrect state.
212: */
213: public void start(String serviceUnitName)
214: throws javax.jbi.management.DeploymentException {
215: }
216:
217: /**
218: * Stop the deployment. This causes the component to cease generating
219: * service requests related to the deployment. This returns the deployment
220: * to a state equivalent to after <code>init()</code> was called.
221: * @param serviceUnitName the name of the Service Unit being stopped.
222: * @throws javax.jbi.management.DeploymentException if the Service Unit
223: * is not deployed, or is in an incorrect state.
224: */
225: public void stop(String serviceUnitName)
226: throws javax.jbi.management.DeploymentException {
227: }
228:
229: /**
230: * helper method to create XML exception string.
231: *
232: * @param compid Component id.
233: * @param oper operation like deploy or undeploy
234: * @param status success r failure
235: * @param loctoken some failure string token like SEQ_300001
236: * @param locparam parameters for error message.
237: * @param locmessage error message.
238: * @param stckTrElem stack trace of exception.
239: *
240: * @return XML string.
241: */
242: private String createExceptionMessage(String compid, String oper,
243: String status, String loctoken, String locparam,
244: String locmessage, Throwable exObj) {
245:
246: String[] locParams = new String[1];
247: locParams[0] = locparam;
248:
249: ComponentMessageHolder msgMap = new ComponentMessageHolder(
250: "EXCEPTION_MSG");
251:
252: msgMap.setComponentName(compid);
253: msgMap.setTaskName(oper);
254: msgMap.setTaskResult(status);
255: msgMap.setLocToken(1, loctoken);
256: msgMap.setLocParam(1, locParams);
257: msgMap.setLocMessage(1, locmessage);
258: msgMap.setExceptionObject(exObj);
259:
260: /*
261: msgMap.put("COMPONENTID", compid);
262: msgMap.put("TASKIDENTIFIER", oper);
263: msgMap.put("TASKRSLTSTATUS", status);
264: msgMap.put("COMPONENTEXLOCTOKEN", loctoken);
265: msgMap.put("COMPONENTEXLOCPARAM", locparam);
266: msgMap.put("COMPONENTEXLOCMESSAGE", locmessage);
267: msgMap.put("COMPONENTEXSTACKTRACE", sb.toString());
268: */
269:
270: String retMsg = null;
271:
272: try {
273: retMsg = this .mContext.getMgmtMsgBuilder()
274: .buildComponentMessage(msgMap);
275: } catch (Exception e) {
276: this .mContext.getLogger().log(Level.INFO,
277: "Failed to create Mgmt Msg", e);
278: }
279:
280: return retMsg;
281: }
282:
283: }
|