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: * @(#)DeploymentServiceMBeanImpl.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.esb.management.impl.deployment;
030:
031: import java.io.File;
032: import java.io.IOException;
033: import java.io.Serializable;
034: import java.util.Map;
035: import java.util.concurrent.ConcurrentHashMap;
036:
037: import javax.management.ObjectName;
038:
039: import com.sun.esb.management.api.deployment.DeploymentService;
040: import com.sun.esb.management.base.services.AbstractServiceMBeansImpl;
041: import com.sun.esb.management.common.ManagementRemoteException;
042: import com.sun.jbi.EnvironmentContext;
043: import com.sun.jbi.ui.common.JBIAdminCommands;
044: import com.sun.jbi.ui.common.JBIArchive;
045: import com.sun.jbi.ui.common.JBIRemoteException;
046: import com.sun.jbi.ui.common.ServiceAssemblyDD;
047:
048: /**
049: * Defines operations for common deployment/undeployment services.
050: *
051: * @author graj
052: *
053: */
054: public class DeploymentServiceMBeanImpl extends
055: AbstractServiceMBeansImpl implements DeploymentService,
056: Serializable {
057:
058: static final long serialVersionUID = -1L;
059:
060: /**
061: * Constructor - Constructs a new instance of DeploymentServiceMBeanImpl
062: *
063: * @param anEnvContext
064: */
065: public DeploymentServiceMBeanImpl(EnvironmentContext anEnvContext) {
066: super (anEnvContext);
067: }
068:
069: /**
070: * deploys service assembly
071: *
072: * @return result as a management message xml text
073: * @param zipFilePath
074: * fie path
075: * @param targetName
076: * @throws ManagementRemoteException
077: * on error
078: *
079: * @see com.sun.esb.management.api.deployment.DeploymentService#deployServiceAssembly(java.lang.String, java.lang.String)
080: */
081: public String deployServiceAssembly(String zipFilePath,
082: String targetName) throws ManagementRemoteException {
083: /*
084: * ==================================================================
085: * According to IN=100359 at
086: * http://inf.central.sun.com/inf/integrationReport.jsp?id=100359
087: *
088: * NOTE: Facade MBean operations for the InstallationService: When the
089: * Installer is loaded for a component, it is added to the domain. When
090: * the Installer is unloaded the component is removed from the domain if
091: * it is not installed on any instances. For the domain targetName, the
092: * ComponentLifeCycle MBean is not available.
093: *
094: * NOTE: Facade MBean operations for the DeploymentService: On deploy, a
095: * Service Assembly is added to the domain and on undeploy it is removed
096: * from the domain.
097: * ==================================================================
098: */
099:
100: logDebug("deploying Service Assembly Zip file " + zipFilePath);
101: String result = null;
102: Object resultObject = null;
103: String assemblyName = this .validateServiceAssembly(zipFilePath);
104:
105: File file = new File(zipFilePath);
106: String fileURLString = null;
107:
108: fileURLString = file.getAbsolutePath();
109:
110: ObjectName deploymentServiceObjectName = this
111: .getDeploymentServiceMBeanObjectName(targetName);
112:
113: this .checkForValidTarget(deploymentServiceObjectName,
114: targetName);
115:
116: logDebug("Calling deploy on DeploymentServiceMBean = "
117: + deploymentServiceObjectName);
118:
119: resultObject = this .invokeMBeanOperation(
120: deploymentServiceObjectName, "deploy", fileURLString);
121:
122: if (resultObject != null) {
123: result = resultObject.toString();
124: if ((assemblyName == null)
125: || (result.contains("FAILED") == true)
126: || (result.contains("WARNING") == true)) {
127: result = resultObject.toString();
128: } else {
129: result = assemblyName;
130: }
131: } else {
132: Exception exception = this .createManagementException(
133: "ui.mbean.deploy.error", null, null);
134: throw new ManagementRemoteException(exception);
135:
136: }
137:
138: return result;
139: }
140:
141: /**
142: * Retrieve the Service Assembly Name
143: *
144: * @param zipFilePath
145: * @return the name of the Service Assembly or null
146: */
147: String validateServiceAssembly(String zipFilePath) {
148: JBIArchive archive = null;
149: ServiceAssemblyDD descriptor = null;
150: String name = null;
151:
152: try {
153: archive = new JBIArchive(zipFilePath);
154: if (archive.isServiceAssemblyArchive() == true) {
155: descriptor = (ServiceAssemblyDD) archive
156: .getJbiDescriptor();
157: name = descriptor.getName();
158: }
159: } catch (IOException ioException) {
160: } catch (Exception exception) {
161: }
162:
163: return name;
164: }
165:
166: /**
167: * deploys service assembly
168: *
169: * @param assemblyName
170: * service assembly name
171: * @param targetName
172: * name of the target for this operation
173: * @return Map of targetName and management message xml text strings.
174: * @throws ManagementRemoteException
175: * on error
176: *
177: * @see com.sun.esb.management.api.deployment.DeploymentService#deployServiceAssemblyFromDomain(java.lang.String, java.lang.String)
178: */
179: public String deployServiceAssemblyFromDomain(String assemblyName,
180: String targetName) throws ManagementRemoteException {
181: if (true == targetName
182: .equals(JBIAdminCommands.DOMAIN_TARGET_KEY)) {
183: return assemblyName;
184: }
185: String result = null;
186: Object resultObject = null;
187:
188: ObjectName deploymentServiceObjectName = this
189: .getDeploymentServiceMBeanObjectName(targetName);
190: if (deploymentServiceObjectName != null) {
191: this .checkForValidTarget(deploymentServiceObjectName,
192: targetName);
193:
194: logDebug("Invoking deployServiceAssemblyFromRepository which "
195: + "internally invokes deploy on DeploymentServiceMBean = "
196: + deploymentServiceObjectName);
197:
198: resultObject = this .invokeMBeanOperation(
199: deploymentServiceObjectName,
200: "deployFromRepository", assemblyName);
201: }
202:
203: if (resultObject != null) {
204: result = resultObject.toString();
205: if ((assemblyName == null)
206: || (result.contains("FAILED") == true)
207: || (result.contains("WARNING") == true)) {
208: result = resultObject.toString();
209: } else {
210: result = assemblyName;
211: }
212: } else {
213: Exception exception = this .createManagementException(
214: "ui.mbean.deploy.error", null, null);
215: throw new ManagementRemoteException(exception);
216:
217: }
218:
219: return result;
220: }
221:
222: /**
223: * undeploys service assembly
224: *
225: * @param serviceAssemblyName
226: * name of the service assembly
227: * @param forceDelete
228: * forces deletion of the assembly if true, false if not
229: * @param retainInDomain
230: * true to not delete it from the domain target, false to also
231: * delete it from the domain target.
232: * @param targetName
233: * name of the target for this operation
234: * @return result as a management message xml text string.
235: * @throws ManagementRemoteException
236: * on error
237: *
238: * @see com.sun.esb.management.api.deployment.DeploymentService#undeployServiceAssembly(java.lang.String, boolean, boolean, java.lang.String)
239: */
240: public String undeployServiceAssembly(String serviceAssemblyName,
241: boolean forceDelete, boolean retainInDomain,
242: String targetName) throws ManagementRemoteException {
243: return this .undeployServiceAssemblyInternal(
244: serviceAssemblyName, forceDelete, retainInDomain,
245: targetName);
246: }
247:
248: /**
249: * Undeploys service assembly
250: *
251: * @param serviceAssemblyName
252: * name of the service assembly
253: * @param forceDelete
254: * forces deletion of the assembly if true, false if not
255: * @param targetName
256: * name of the target for this operation
257: * @return Map of targetName and result as a management message xml text
258: * strings.
259: * @throws ManagementRemoteException
260: * on error
261: *
262: * @see com.sun.esb.management.api.deployment.DeploymentService#undeployServiceAssembly(java.lang.String, boolean, java.lang.String)
263: */
264: public String undeployServiceAssembly(String serviceAssemblyName,
265: boolean forceDelete, String targetName)
266: throws ManagementRemoteException {
267: if (false == forceDelete) {
268: return this .undeployServiceAssembly(serviceAssemblyName,
269: targetName);
270: }
271: boolean retainInDomian = false;
272: return this .undeployServiceAssembly(serviceAssemblyName,
273: forceDelete, retainInDomian, targetName);
274: }
275:
276: /**
277: * Undeploys service assembly
278: *
279: * @param serviceAssemblyName
280: * name of the service assembly
281: * @param targetName
282: * @return result as a management message xml text
283: * @throws ManagementRemoteException
284: * on error
285: *
286: * @see com.sun.esb.management.api.deployment.DeploymentService#undeployServiceAssembly(java.lang.String, java.lang.String)
287: */
288: public String undeployServiceAssembly(String serviceAssemblyName,
289: String targetName) throws ManagementRemoteException {
290: return this .undeployServiceAssemblyInternal(
291: serviceAssemblyName, targetName);
292: }
293:
294: /**
295: * undeploys service assembly
296: *
297: * @param serviceAssemblyName
298: * name of the service assembly
299: * @param force
300: * @param retainInDomain
301: * @param targetName
302: * @throws JBIRemoteException
303: * on error
304: * @return result as a management message xml text
305: *
306: * @see com.sun.jbi.ui.common.JBIAdminCommands#undeployServiceAssembly(java.lang.String,
307: * java.lang.String)
308: */
309: String undeployServiceAssemblyInternal(String serviceAssemblyName,
310: boolean force, boolean retainInDomain, String targetName)
311: throws ManagementRemoteException {
312:
313: logDebug("Undeploying Service Assembly " + serviceAssemblyName);
314:
315: ObjectName deploymentServiceObjectName = this
316: .getDeploymentServiceMBeanObjectName(targetName);
317: // ////////////////////////////////////////
318: // Start Check to make sure target is valid
319: // ////////////////////////////////////////
320: this .checkForValidTarget(deploymentServiceObjectName,
321: targetName);
322: // ////////////////////////////////////////
323: // End Check to make sure target is valid
324: // ////////////////////////////////////////
325:
326: logDebug("Calling undeploy on DeploymentServiceMBean = "
327: + deploymentServiceObjectName);
328:
329: Object[] params = new Object[3];
330: params[0] = serviceAssemblyName;
331: params[1] = Boolean.valueOf(force);
332: params[2] = Boolean.valueOf(retainInDomain);
333:
334: String[] signature = new String[3];
335: signature[0] = "java.lang.String";
336: signature[1] = "boolean";
337: signature[2] = "boolean";
338:
339: Object resultObject = this .invokeMBeanOperation(
340: deploymentServiceObjectName, "undeploy", params,
341: signature);
342:
343: String result = null;
344: if (resultObject != null) {
345: result = resultObject.toString();
346: if ((serviceAssemblyName == null)
347: || (result.contains("FAILED") == true)
348: || (result.contains("WARNING") == true)) {
349: result = resultObject.toString();
350: } else {
351: result = serviceAssemblyName;
352: }
353: return result;
354: } else {
355: Exception exception = this .createManagementException(
356: "ui.mbean.undeploy.error", null, null);
357: throw new ManagementRemoteException(exception);
358: }
359: }
360:
361: /**
362: * undeploys service assembly
363: *
364: * @param serviceAssemblyName
365: * name of the service assembly
366: * @param targetName
367: * @throws JBIRemoteException
368: * on error
369: * @return result as a management message xml text
370: *
371: * @see com.sun.jbi.ui.common.JBIAdminCommands#undeployServiceAssembly(java.lang.String,
372: * java.lang.String)
373: */
374: String undeployServiceAssemblyInternal(String serviceAssemblyName,
375: String targetName) throws ManagementRemoteException {
376:
377: logDebug("Undeploying Service Assembly " + serviceAssemblyName);
378:
379: ObjectName deploymentServiceObjectName = this
380: .getDeploymentServiceMBeanObjectName(targetName);
381: // ////////////////////////////////////////
382: // Start Check to make sure target is valid
383: // ////////////////////////////////////////
384: this .checkForValidTarget(deploymentServiceObjectName,
385: targetName);
386: // ////////////////////////////////////////
387: // End Check to make sure target is valid
388: // ////////////////////////////////////////
389:
390: logDebug("Calling undeploy on DeploymentServiceMBean = "
391: + deploymentServiceObjectName);
392:
393: Object resultObject = this .invokeMBeanOperation(
394: deploymentServiceObjectName, "undeploy",
395: serviceAssemblyName);
396:
397: String result = null;
398: if (resultObject != null) {
399: result = resultObject.toString();
400: if ((serviceAssemblyName == null)
401: || (result.contains("FAILED") == true)
402: || (result.contains("WARNING") == true)) {
403: result = resultObject.toString();
404: } else {
405: result = serviceAssemblyName;
406: }
407: return result;
408: } else {
409: Exception exception = this .createManagementException(
410: "ui.mbean.undeploy.error", null, null);
411: throw new ManagementRemoteException(exception);
412: }
413: }
414:
415: /////////////////////////////////////////////
416: // Start of Cumulative Operation Definitions
417: /////////////////////////////////////////////
418: /**
419: * deploys service assembly
420: *
421: * @param zipFilePath
422: * fie path
423: * @param targetNames
424: * @return result as a management message xml text [targetName,xmlString]
425: * map
426: * @throws ManagementRemoteException
427: * on error
428: */
429: public Map<String, String> deployServiceAssembly(
430: String zipFilePath, String[] targetNames)
431: throws ManagementRemoteException {
432: String xmlString = null;
433: ConcurrentHashMap<String, String> result = new ConcurrentHashMap<String, String>();
434: for (int index = 0; index < targetNames.length; index++) {
435: try {
436: xmlString = this .deployServiceAssembly(zipFilePath,
437: targetNames[index]);
438: if (xmlString != null) {
439: result.putIfAbsent(targetNames[index], xmlString);
440: }
441: } catch (ManagementRemoteException exception) {
442: xmlString = this .getStackTrace(exception);
443: result.putIfAbsent(targetNames[index], xmlString);
444: }
445: }
446: return (Map<String, String>) result;
447: }
448:
449: /**
450: * undeploys service assembly
451: *
452: * @param serviceAssemblyName
453: * name of the service assembly
454: * @param targetNames
455: * @return result as a management message xml text as [targetName, string]
456: * map
457: * @throws ManagementRemoteException
458: * on error
459: *
460: */
461: public Map<String, String> undeployServiceAssembly(
462: String serviceAssemblyName, String[] targetNames)
463: throws ManagementRemoteException {
464:
465: String xmlString = null;
466: ConcurrentHashMap<String, String> result = new ConcurrentHashMap<String, String>();
467: for (int index = 0; index < targetNames.length; index++) {
468: try {
469: xmlString = this .undeployServiceAssembly(
470: serviceAssemblyName, targetNames[index]);
471: if (xmlString != null) {
472: result.putIfAbsent(targetNames[index], xmlString);
473: }
474: } catch (ManagementRemoteException exception) {
475: xmlString = this .getStackTrace(exception);
476: result.putIfAbsent(targetNames[index], xmlString);
477: }
478:
479: }
480: return (Map<String, String>) result;
481:
482: }
483:
484: /**
485: * deploys service assembly
486: *
487: * @param assemblyName
488: * name of the service assembly
489: * @param targetName
490: * name of the target for this operation
491: * @return Map of targetName and management message xml text strings.
492: * @throws ManagementRemoteException
493: * on error
494: */
495: public Map<String /* targetName */, String /* targetResult */> deployServiceAssemblyFromDomain(
496: String assemblyName, String[] targetNames)
497: throws ManagementRemoteException {
498: String xmlString = null;
499: ConcurrentHashMap<String, String> result = new ConcurrentHashMap<String, String>();
500: for (int index = 0; index < targetNames.length; index++) {
501: try {
502: xmlString = this .deployServiceAssemblyFromDomain(
503: assemblyName, targetNames[index]);
504: if (xmlString != null) {
505: result.putIfAbsent(targetNames[index], xmlString);
506: }
507: } catch (ManagementRemoteException exception) {
508: xmlString = this .getStackTrace(exception);
509: result.putIfAbsent(targetNames[index], xmlString);
510: }
511:
512: }
513: return (Map<String, String>) result;
514:
515: }
516:
517: /**
518: * undeploys service assembly
519: *
520: * @param serviceAssemblyName
521: * name of the service assembly
522: * @param forceDelete
523: * true to delete, false to not
524: * @param targetName
525: * name of the target for this operation
526: * @return Map of targetName and result as a management message xml text
527: * strings.
528: * @throws ManagementRemoteException
529: * on error
530: */
531: public Map<String /* targetName */, String /* targetResult */> undeployServiceAssembly(
532: String serviceAssemblyName, boolean forceDelete,
533: String[] targetNames) throws ManagementRemoteException {
534: String xmlString = null;
535: ConcurrentHashMap<String, String> result = new ConcurrentHashMap<String, String>();
536: for (int index = 0; index < targetNames.length; index++) {
537: try {
538: xmlString = this .undeployServiceAssembly(
539: serviceAssemblyName, forceDelete,
540: targetNames[index]);
541: if (xmlString != null) {
542: result.putIfAbsent(targetNames[index], xmlString);
543: }
544: } catch (ManagementRemoteException exception) {
545: xmlString = this .getStackTrace(exception);
546: result.putIfAbsent(targetNames[index], xmlString);
547: }
548:
549: }
550: return (Map<String, String>) result;
551:
552: }
553:
554: /**
555: * undeploys service assembly
556: *
557: * @param serviceAssemblyName
558: * name of the service assembly
559: * @param forceDelete
560: * forces deletion of the assembly if true, false if not
561: * @param retainInDomain
562: * true to not delete it from the domain target, false to also
563: * delete it from the domain target.
564: * @param targetNames
565: * array of targets for this operation
566: * @return Map of targetName and result as a management message xml text
567: * strings.
568: * @throws ManagementRemoteException
569: * on error
570: */
571: public Map<String /* targetName */, String /* targetResult */> undeployServiceAssembly(
572: String serviceAssemblyName, boolean forceDelete,
573: boolean retainInDomain, String[] targetNames)
574: throws ManagementRemoteException {
575: String xmlString = null;
576: ConcurrentHashMap<String, String> result = new ConcurrentHashMap<String, String>();
577: for (int index = 0; index < targetNames.length; index++) {
578: try {
579: xmlString = this .undeployServiceAssembly(
580: serviceAssemblyName, forceDelete,
581: retainInDomain, targetNames[index]);
582: if (xmlString != null) {
583: result.putIfAbsent(targetNames[index], xmlString);
584: }
585: } catch (ManagementRemoteException exception) {
586: xmlString = this .getStackTrace(exception);
587: result.putIfAbsent(targetNames[index], xmlString);
588: }
589:
590: }
591: return (Map<String, String>) result;
592:
593: }
594:
595: /////////////////////////////////////////////
596: // End of Cumulative Operation Definitions
597: /////////////////////////////////////////////
598:
599: }
|