0001: /**
0002: * $Id: DesktopDynamic.java,v 1.35 2007/01/26 03:48:19 portalbld Exp $
0003: * Copyright 2004 Sun Microsystems, Inc. All
0004: * rights reserved. Use of this product is subject
0005: * to license terms. Federal Acquisitions:
0006: * Commercial Software -- Government Users
0007: * Subject to Standard License Terms and
0008: * Conditions.
0009: *
0010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0011: * are trademarks or registered trademarks of Sun Microsystems,
0012: * Inc. in the United States and other countries.
0013: */package com.sun.portal.desktop.admin.mbeans;
0014:
0015: import java.lang.reflect.Constructor;
0016:
0017: import java.util.ArrayList;
0018: import java.util.List;
0019: import java.util.Iterator;
0020: import java.util.Random;
0021: import java.util.LinkedList;
0022: import java.util.TreeSet;
0023: import java.util.Set;
0024: import java.util.Map;
0025: import java.util.HashMap;
0026: import java.util.logging.Level;
0027: import java.util.logging.Logger;
0028:
0029: import java.io.File;
0030: import java.io.FileInputStream;
0031: import java.io.FileOutputStream;
0032: import java.io.FileNotFoundException;
0033: import java.io.IOException;
0034: import java.net.InetAddress;
0035: import java.net.UnknownHostException;
0036:
0037: import javax.management.MBeanServer;
0038: import javax.management.MBeanException;
0039: import javax.management.MBeanServerConnection;
0040: import javax.management.ObjectName;
0041: import javax.management.DynamicMBean;
0042: import javax.management.Attribute;
0043: import javax.management.AttributeList;
0044: import javax.management.remote.JMXConnector;
0045: import javax.management.MBeanInfo;
0046: import javax.management.MBeanConstructorInfo;
0047: import javax.management.MBeanOperationInfo;
0048: import javax.management.MBeanAttributeInfo;
0049: import javax.management.MBeanParameterInfo;
0050: import javax.management.MBeanNotificationInfo;
0051: import javax.management.MalformedObjectNameException;
0052: import javax.management.AttributeNotFoundException;
0053: import javax.management.InvalidAttributeValueException;
0054: import javax.management.RuntimeOperationsException;
0055: import javax.management.ReflectionException;
0056:
0057: import com.sun.portal.log.common.PortalLogger;
0058:
0059: import com.sun.portal.admin.common.InstanceAttributes;
0060: import com.sun.portal.admin.common.BackupVersion;
0061: import com.sun.portal.admin.common.PSMBeanException;
0062: import com.sun.portal.admin.common.PSConfigConstants;
0063: import com.sun.portal.admin.common.PortalAttributes;
0064: import com.sun.portal.admin.common.util.AdminUtil;
0065: import com.sun.portal.admin.common.util.AdminClientUtil;
0066: import com.sun.portal.admin.common.util.UploadDownloadException;
0067: import com.sun.portal.admin.common.context.PSConfigContext;
0068: import com.sun.portal.admin.common.context.PortalDomainContext;
0069: import com.sun.portal.admin.common.context.PortalDomainContextException;
0070:
0071: import com.sun.portal.admin.server.PASModule;
0072: import com.sun.portal.admin.server.AdminServerUtil;
0073: import com.sun.portal.admin.server.mbeans.PSResource;
0074:
0075: import com.sun.portal.desktop.deployment.ParFile;
0076: import com.sun.portal.desktop.deployment.ParManifest;
0077: import com.sun.portal.desktop.deployment.ParFileException;
0078:
0079: import com.sun.portal.desktop.admin.mbeans.tasks.DesktopData;
0080: import com.sun.portal.desktop.admin.mbeans.tasks.DesktopDataException;
0081:
0082: import com.sun.portal.util.Platform;
0083:
0084: public class DesktopDynamic extends PSResource implements DynamicMBean {
0085:
0086: //The buffer size for transfering par file binaries
0087: public static final int BUFFER_SIZE = 4096;
0088:
0089: //private member variables
0090: private String dClassName = this .getClass().getName();
0091: private MBeanInfo dMBeanInfo = null;
0092: private static Logger logger = PortalLogger
0093: .getLogger(DesktopDynamic.class);
0094: private String domainId;
0095: private String portalId;
0096: private PSConfigContext pcc;
0097: public static final String FS = Platform.fs;
0098:
0099: public void init(PSConfigContext cc, PortalDomainContext pdc,
0100: List path) {
0101: super .init(cc, pdc, path);
0102: buildMBeanInfo();
0103: domainId = pdc.getID();
0104: portalId = (String) path.get(1);
0105: pcc = cc;
0106: }
0107:
0108: public Object getAttribute(String attribute) {
0109: return null;
0110: }
0111:
0112: public void setAttribute(Attribute attribute) {
0113: }
0114:
0115: public AttributeList getAttributes(String[] attributes) {
0116: return null;
0117: }
0118:
0119: public AttributeList setAttributes(AttributeList attributes) {
0120: return null;
0121: }
0122:
0123: public MBeanInfo getMBeanInfo() {
0124: return dMBeanInfo;
0125: }
0126:
0127: public Object invoke(String operationName, Object params[],
0128: String signature[]) throws MBeanException,
0129: ReflectionException {
0130: // Check operationName is not null to avoid NullPointerException later on
0131: if (operationName == null) {
0132: throw new RuntimeOperationsException(
0133: new IllegalArgumentException(
0134: "Operation name cannot be null"),
0135: "Cannot invoke a null operation in " + dClassName);
0136: }
0137:
0138: try {
0139:
0140: // Check for a recognized operation name and call the
0141: // corresponding operation
0142: if (operationName.equals("getArchiveFileVersion")) {
0143: return (String) (getArchiveFileVersion((String) params[0]));
0144: } else if (operationName.equals("deleteTempFile")) {
0145: deleteTempFile((String) params[0]);
0146: } else if (operationName.equals("importDesktop")) {
0147: importDesktop((Boolean) params[0], (Boolean) params[1],
0148: (Boolean) params[2], (Boolean) params[3],
0149: (Boolean) params[4], (String) params[5],
0150: (Boolean) params[6], (String) params[7],
0151: (String) params[8], (Boolean) params[9]);
0152: } else if (operationName.equals("importProvider")) {
0153: importProvider((String) params[0], (Boolean) params[1],
0154: (Boolean) params[2], (List) params[3],
0155: (String) params[4]);
0156: } else if (operationName.equals("lImportProvider")) {
0157: lImportProvider((String) params[0],
0158: (Boolean) params[1], (Boolean) params[2],
0159: (String) params[3], (List) params[4],
0160: (String) params[5], (Boolean) params[6]);
0161: } else if (operationName.equals("exportDesktop")) {
0162: exportDesktop((String) params[0], (Boolean) params[1],
0163: (Boolean) params[2], (Boolean) params[3],
0164: (String) params[4]);
0165: } else if (operationName.equals("exportProvider")) {
0166: exportProvider((String) params[0], (Boolean) params[1],
0167: (String) params[2], (Boolean) params[3],
0168: (byte[][]) params[4]);
0169: } else if (operationName.equals("lImportDesktop")) {
0170: lImportDesktop((Boolean) params[0],
0171: (Boolean) params[1], (Boolean) params[2],
0172: (Boolean) params[3], (Boolean) params[4],
0173: (String) params[5], (String) params[6],
0174: (Boolean) params[7], (String) params[8],
0175: (String) params[9], (Boolean) params[10]);
0176: } else if (operationName.equals("listPar")) {
0177: return listPar((String) params[0], (Boolean) params[1],
0178: (Boolean) params[2], (Boolean) params[3],
0179: (Boolean) params[4], (Boolean) params[5]);
0180: } else {
0181: // unrecognized operation name:
0182: throw new ReflectionException(
0183: new NoSuchMethodException(operationName),
0184: "Cannot find the operation " + operationName
0185: + " in " + dClassName);
0186: }
0187: } catch (PSMBeanException pe) {
0188: throw new MBeanException(pe, pe.getMessage());
0189: }
0190:
0191: return null;
0192: }
0193:
0194: /*
0195: * -----------------------------------------------------
0196: * OTHER PUBLIC METHODS
0197: * -----------------------------------------------------
0198: */
0199:
0200: /**
0201: * Reads portal id from the archive file.
0202: */
0203: public String getArchiveFileVersion(String parFileName)
0204: throws PSMBeanException {
0205:
0206: String version = null;
0207:
0208: try {
0209: ParFile par = ParFile.makeParFile(parFileName);
0210: ParManifest pMan = par.getParManifest();
0211: version = pMan.getBackupVersion();
0212: /* this part is commented out and the client need to check
0213: for null.
0214: */
0215: /* if (version == null) {
0216: throw new
0217: PSMBeanException("error.bad.archive.file.version",
0218: "DesktopDynamic.getArchiveFileVersion(),
0219: par file version is not compatiable.");
0220: }*/
0221:
0222: if (logger.isLoggable(Level.INFO)) {
0223: Object tokens[] = { version };
0224: logger.log(Level.INFO, "PSDT_CSPDAMB0001", tokens);
0225: }
0226: } catch (ParFileException pe) {
0227: logger.log(Level.SEVERE, "PSDT_CSPDAMB0002", pe);
0228: throw new PSMBeanException("error.archive.file.version", pe
0229: .getMessage());
0230: } catch (Exception e) {
0231: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", e);
0232: throw new PSMBeanException("error.archive.file.version", e
0233: .getMessage());
0234: }
0235:
0236: return version;
0237: }
0238:
0239: /**
0240: * Delete Temporary File.
0241: */
0242: public void deleteTempFile(String tempFileName) {
0243: logger.log(Level.INFO, "PSDT_CSPDAMB0011", tempFileName);
0244: File f = new File(tempFileName);
0245: if (f.exists()) {
0246: f.delete();
0247: }
0248: }
0249:
0250: /**
0251: * Export the provider/channel data.
0252: * <p>
0253: * The provider/channel data that will be backed in this method includes:
0254: * <UL>
0255: * <LI>Display profiles fragment for this provider/channel at the specified dn.
0256: * <LI>Desktop web-src data
0257: * <LI>Static files,templates for this provider/channel
0258: * </UL>
0259: *
0260: * @param parFileName The par file name.
0261: * @param verbose If true then some par specific debugging
0262: * messages will be generated, also debug level will be set to
0263: * "FINEST".
0264: * @param dn dn from where provider data needs to be backed up.
0265: * @param global if global data needs to be backed up.
0266: * @param exportfile 2-d array of export files streams .
0267: * @exception PSMBeanException If the export operation fails.
0268: */
0269: // add option for modify -- only if time permits.
0270: public void exportProvider(String parFileName, Boolean verbose,
0271: String dn, Boolean global, byte[][] exportfile)
0272: throws PSMBeanException {
0273: try {
0274: //Check if the local host is one of the host that is running
0275: //this portal, if not, reconnect to a remote host, and call
0276: //export operation on that
0277:
0278: String host = getRemoteHost();
0279: if (host != null) {
0280: JMXConnector connector = AdminServerUtil
0281: .getJMXConnector(host);
0282: MBeanServerConnection mbsc = connector
0283: .getMBeanServerConnection();
0284: String tempName = Integer.toString(new Random()
0285: .nextInt());
0286: String tempFileName = pcc.getPSDataDir() + FS + "tmp"
0287: + FS + tempName;
0288:
0289: //Call exportProvider on remote host
0290: Object[] params = { tempFileName, verbose, dn, global,
0291: exportfile };
0292: String[] signature = { "java.lang.String",
0293: "java.lang.Boolean", "java.lang.String",
0294: "java.lang.Boolean", "[[B" };
0295:
0296: LinkedList pPath = new LinkedList();
0297: pPath.addFirst(domainId);
0298: pPath.addFirst(portalId);
0299: pPath.addFirst(AdminUtil.DESKTOP_DYNAMIC_MBEAN);
0300:
0301: ObjectName objName = AdminUtil
0302: .getResourceMBeanObjectName(
0303: AdminUtil.DESKTOP_DYNAMIC_MBEAN_TYPE,
0304: pPath);
0305:
0306: mbsc.invoke(objName, "exportProvider", params,
0307: signature);
0308: downloadFile(mbsc, tempFileName, parFileName);
0309: connector.close();
0310: } else {
0311: // The local host does have this portal running,
0312: // do the export.
0313: DesktopData dd = new DesktopData(AdminServerUtil
0314: .getSSOToken(), cc, pdc.getID(), (String) path
0315: .get(1), verbose.booleanValue(), logger, null);
0316:
0317: dd.exportProvider(parFileName, dn, global
0318: .booleanValue(), exportfile);
0319: }
0320: } catch (MalformedObjectNameException me) {
0321: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", me);
0322: throw new PSMBeanException("error.execute.export", me
0323: .getMessage());
0324: } catch (DesktopDataException ce) {
0325: String message = (ce.getCause()) == null ? ce.getMessage()
0326: : ce.getCause().getMessage();
0327: throw new PSMBeanException("error.execute.export", message);
0328: } catch (PSMBeanException me) {
0329: throw me;
0330: } catch (Exception e) {
0331: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", e);
0332: throw new PSMBeanException("error.execute.export", e
0333: .getMessage());
0334: }
0335: }
0336:
0337: /**
0338: * Export the desktop data.
0339: * <p>
0340: * The desktop data that will be backed in this method includes:
0341: * <UL>
0342: * <LI>Display profiles on global, org, and role levels.
0343: * <LI>Desktop service attributes: default channel name, edit
0344: * channel name, desktop type, and desktop canView value.
0345: * <LI>SSO adapter service attributes: sso adapter templates, and
0346: * sso adapter configurations.
0347: * <LI>Desktop template data: any files under subdirectory of <Port
0348: * runtime data root>/portals/<portal ID>/desktop
0349: * <LI>Desktop configuration file
0350: * <LI>Desktop web-src directory
0351: * <LI>Portlet war file
0352: * </UL>
0353: *
0354: * @param parFileName The par file name.
0355: * @param verbose If true then some par specific debugging
0356: * messages will be generated, also debug level will be set to
0357: * "FINEST".
0358: * @param fsOnly If true then only the file system data will be
0359: * backed up, otherwise all desktop data will be backed up.
0360: * @exception PSMBeanException If the export operation fails.
0361: */
0362: public void exportDesktop(String parFileName, Boolean verbose,
0363: Boolean fsOnly, Boolean dpOnly, String searchLevel)
0364: throws PSMBeanException {
0365: logger.log(Level.SEVERE, "PSDT_CSPDAMB0001", parFileName);
0366:
0367: try {
0368: //Check if the local host is one of the host that is running
0369: //this portal, if not, reconnect to a remote host, and call
0370: //export operation on that
0371:
0372: String host = getRemoteHost();
0373: if (host != null) {
0374: if (logger.isLoggable(Level.INFO)) {
0375: Object token[] = { host };
0376: logger.log(Level.INFO, "PSDT_CSPDAMB0010", token);
0377: }
0378: JMXConnector connector = AdminServerUtil
0379: .getJMXConnector(host);
0380: MBeanServerConnection mbsc = connector
0381: .getMBeanServerConnection();
0382: String tempName = Integer.toString(new Random()
0383: .nextInt());
0384: String tempFileName = pcc.getPSDataDir() + FS + "tmp"
0385: + FS + tempName;
0386:
0387: //Call exportDesktop on remote host
0388: Object[] params = { tempFileName, verbose, fsOnly,
0389: dpOnly, searchLevel };
0390: String[] signature = { "java.lang.String",
0391: "java.lang.Boolean", "java.lang.Boolean",
0392: "java.lang.Boolean", "java.lang.String" };
0393:
0394: LinkedList pPath = new LinkedList();
0395: pPath.addFirst(domainId);
0396: pPath.addFirst(portalId);
0397: pPath.addFirst(AdminUtil.DESKTOP_DYNAMIC_MBEAN);
0398:
0399: ObjectName objName = AdminUtil
0400: .getResourceMBeanObjectName(
0401: AdminUtil.DESKTOP_DYNAMIC_MBEAN_TYPE,
0402: pPath);
0403:
0404: mbsc
0405: .invoke(objName, "exportDesktop", params,
0406: signature);
0407: downloadFile(mbsc, tempFileName, parFileName);
0408:
0409: // Delete the temp file on remote host
0410: params = new Object[] { tempFileName };
0411: signature = new String[] { "java.lang.String" };
0412: mbsc.invoke(objName, "deleteTempFile", params,
0413: signature);
0414:
0415: connector.close();
0416: } else {
0417: if (logger.isLoggable(Level.INFO)) {
0418: logger.log(Level.INFO, "PSDT_CSPDAMB0009");
0419: }
0420: // get portal uri from PortalMBean
0421: LinkedList pPath = new LinkedList();
0422: pPath.addFirst(domainId);
0423: pPath.addFirst(portalId);
0424: String portalUri = pdc.getAttributeValue(
0425: AdminUtil.PORTAL_MBEAN_TYPE, pPath,
0426: PortalAttributes.PORTAL_URI);
0427:
0428: // The local host does have this portal running,
0429: // do the export.
0430: DesktopData dd = new DesktopData(AdminServerUtil
0431: .getSSOToken(), cc, pdc.getID(), (String) path
0432: .get(1), verbose.booleanValue(), logger,
0433: portalUri);
0434:
0435: dd.exportDesktop(parFileName, null, fsOnly
0436: .booleanValue(), dpOnly.booleanValue(),
0437: searchLevel);
0438: }
0439:
0440: } catch (MalformedObjectNameException me) {
0441: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", me);
0442: throw new PSMBeanException("error.execute.export", me
0443: .getMessage());
0444: } catch (DesktopDataException ce) {
0445: String message = (ce.getCause()) == null ? ce.getMessage()
0446: : ce.getCause().getMessage();
0447: throw new PSMBeanException("error.execute.export", message);
0448: } catch (PSMBeanException me) {
0449: throw me;
0450: } catch (Exception e) {
0451: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", e);
0452: throw new PSMBeanException("error.execute.export", e
0453: .getMessage());
0454: }
0455: }
0456:
0457: /**
0458: * Import the provider data to the Portal Server systems.
0459: * <p>
0460: * This method is called from the client side which passes in a par file
0461: * In the case when the Portal Server Instances are installed in
0462: * different hosts, provider data will be restored back to all of the
0463: * involved hosts. This method handles the import operation for the local host,
0464: * and then delegate the call to other host by calling the internal
0465: * <code>lImportProvider()</code>.
0466: * @param parFileName The full path of the par file.
0467: * @param verbose If true then some par specific debugging
0468: * messages will be generated, also debug level will be set to
0469: * "FINEST".
0470: * @param overwrite If true then overwrite the entry .default is false.
0471: * @param operations The operations used for importing provider data.
0472: * @param dpnode The destination dn where provider is imported
0473: *
0474: * @exception PSMBeanException If the import operation fails.
0475: */
0476: public void importProvider(String parFileName, Boolean verbose,
0477: Boolean overwrite, List operations, String dpnode)
0478: throws PSMBeanException {
0479: //The import operation needs to be done in each host that has
0480: //a portal instance
0481: Set hosts = getHosts();
0482: Iterator it = hosts.iterator();
0483: //setup path and signature for lImportProvider()
0484: String domainId = pdc.getID();
0485: String portalId = (String) path.get(1);
0486:
0487: LinkedList pPath = new LinkedList();
0488: pPath.addFirst(domainId);
0489: pPath.addFirst(portalId);
0490: pPath.addFirst(AdminUtil.DESKTOP_DYNAMIC_MBEAN);
0491:
0492: String[] signature = { "java.lang.String", "java.lang.Boolean",
0493: "java.lang.Boolean", "java.lang.String",
0494: "java.util.List", "java.lang.String",
0495: "java.lang.Boolean" };
0496: ObjectName objName = null;
0497:
0498: try {
0499: objName = AdminUtil.getResourceMBeanObjectName(
0500: AdminUtil.DESKTOP_DYNAMIC_MBEAN_TYPE, pPath);
0501: } catch (MalformedObjectNameException me) {
0502: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", me);
0503: throw new PSMBeanException("error.execute.import", me
0504: .getMessage());
0505: }
0506: Boolean extractDP = new Boolean(true);
0507:
0508: while (it.hasNext()) {
0509: String hostName = (String) it.next();
0510: try {
0511: if (AdminServerUtil.isLocal(hostName)) {
0512: lImportProvider(parFileName, verbose, overwrite,
0513: portalId, operations, dpnode, extractDP);
0514: extractDP = new Boolean(false);
0515:
0516: } else {
0517: JMXConnector connector = AdminServerUtil
0518: .getJMXConnector(hostName);
0519: MBeanServerConnection mbsc = connector
0520: .getMBeanServerConnection();
0521:
0522: //upload parFile to the remote host
0523: String[] dest = uploadFile(mbsc, parFileName);
0524: String destFileName = dest[1];
0525:
0526: //Call lImportProvider on remote host
0527: Object[] params = { destFileName, verbose,
0528: overwrite, portalId, operations, dpnode,
0529: extractDP };
0530:
0531: mbsc.invoke(objName, "lImportProvider", params,
0532: signature);
0533: extractDP = new Boolean(false);
0534: //clean up temp files
0535: try {
0536: AdminClientUtil.uploadDownloadCleanUp(mbsc,
0537: domainId, dest[0]);
0538: } catch (UploadDownloadException upe) {
0539: if (connector != null) {
0540: connector.close();
0541: }
0542:
0543: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003",
0544: upe);
0545: throw new PSMBeanException(
0546: "error.execute.import", upe
0547: .getMessage());
0548: }
0549: connector.close();
0550:
0551: }
0552: } catch (Exception e) {
0553: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", e);
0554: throw new PSMBeanException("error.execute.import", e
0555: .getMessage());
0556: }
0557: }
0558: }
0559:
0560: /**
0561: * Import the desktop data to the Portal Server systems.
0562: * <p>
0563: * This method is called from the client side which passes in an
0564: * <code>byte[]</code>, the cient has to call this multiple times
0565: * until all data has been transferred from the client side.
0566: *
0567: * When the portalId is specified, the archive file will be
0568: * imported to a specified portal. If the portalId
0569: * is null, then the import will be operated on the portal where the
0570: * archive file is exported from, and the portalId is read from the
0571: * archive file.
0572: *
0573: * In the case when the Portal Server Instances are installed in
0574: * different hosts, the display profiles, the service attributes
0575: * are going to be restored, and the desktop file system data will
0576: * be restored back to all of the involved hosts. This method
0577: * handles the import operation for the local host, and then
0578: * delegate the call to other host by calling the internal
0579: * <code>lImportDesktop()</code>.
0580: *
0581: * @param byteArray The buffer contains par file data.
0582: * @param rStr A random number for the temp file name.
0583: * @param endOfStream Indicating if this buffer the last to be passed.
0584: * @param verbose If true then some par specific debugging
0585: * messages will be generated, also debug level will be set to
0586: * "FINEST".
0587: * @param fsOnly If true then only the desktop file system data
0588: * will be imported. If fasle the display profile and the service
0589: * attributes will also be imported.
0590: * This parameter is used because in one portal site that
0591: * involving multiple hosts, the data stored in a centralized
0592: * backend storage will only need to be performed once, but the
0593: * file system data needs to be performed in individual host.
0594: * @param parFileName The full path of the par file.
0595: * @param portalId The portal on which the import operation
0596: * should be operated on.
0597: * @param cont If there's miss-match of the schema, e.g., some
0598: * organizations/roles is missing from the target system, continue
0599: * the operation on existing orgs/roles or stop the operation.
0600: * @param searchLevel The search level is used to set the scope
0601: * when accessing to the display profile and service attribute data.
0602: * @param dpnode The base dn for importing display profiles.
0603: * when accessing to the display profile and service attribute data.
0604: * @exception PSMBeanException If the import operation fails.
0605: */
0606: public void importDesktop(Boolean verbose, Boolean fsOnly,
0607: Boolean dpOnly, Boolean overwrite, Boolean redeploy,
0608: String parFileName, Boolean cont, String searchLevel,
0609: String dpnode, Boolean skipValidation)
0610: throws PSMBeanException {
0611:
0612: //setup path and signature for lImportDesktop()
0613:
0614: LinkedList pPath = new LinkedList();
0615: pPath.addFirst(domainId);
0616: pPath.addFirst(portalId);
0617: pPath.addFirst(AdminUtil.DESKTOP_DYNAMIC_MBEAN);
0618:
0619: ObjectName objName = null;
0620: JMXConnector connector = null;
0621:
0622: try {
0623: objName = AdminUtil.getResourceMBeanObjectName(
0624: AdminUtil.DESKTOP_DYNAMIC_MBEAN_TYPE, pPath);
0625: } catch (MalformedObjectNameException me) {
0626: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", me);
0627: throw new PSMBeanException("error.execute.import", me
0628: .getMessage());
0629: }
0630:
0631: try {
0632: //The import operation needs to be done in each host that has
0633: //a portal instance
0634: Set hosts = getHosts();
0635: Iterator it = hosts.iterator();
0636: boolean fsOnlyFlag = fsOnly.booleanValue();
0637: boolean dpOnlyFlag = dpOnly.booleanValue();
0638: String[] signature = { "java.lang.Boolean",
0639: "java.lang.Boolean", "java.lang.Boolean",
0640: "java.lang.Boolean", "java.lang.Boolean",
0641: "java.lang.String", "java.lang.String",
0642: "java.lang.Boolean", "java.lang.String",
0643: "java.lang.String", "java.lang.Boolean" };
0644: Object[] params = { verbose, null, null, overwrite,
0645: redeploy, null, portalId, cont, searchLevel,
0646: dpnode, skipValidation };
0647:
0648: while (it.hasNext()) {
0649: String hostName = (String) it.next();
0650: logger.log(Level.INFO, "importDesktop, next host: "
0651: + hostName);
0652: if (AdminServerUtil.isLocal(hostName)) {
0653: if (logger.isLoggable(Level.INFO)) {
0654: logger.log(Level.INFO, "PSDT_CSPDAMB0009");
0655: }
0656:
0657: lImportDesktop(verbose, new Boolean(fsOnlyFlag),
0658: new Boolean(dpOnlyFlag), overwrite,
0659: redeploy, parFileName, portalId, cont,
0660: searchLevel, dpnode, skipValidation);
0661:
0662: //after the import operation has done for
0663: //for the first host, set fsOnly flag is false.
0664: if (dpOnlyFlag) {
0665: break;
0666: } else if (fsOnlyFlag) {
0667: continue;
0668: } else {
0669: fsOnlyFlag = true;
0670: }
0671: } else {
0672: if (logger.isLoggable(Level.INFO)) {
0673: Object token[] = { hostName };
0674: logger.log(Level.INFO, "PSDT_CSPDAMB0010",
0675: token);
0676: }
0677:
0678: try {
0679:
0680: connector = AdminServerUtil
0681: .getJMXConnector(hostName);
0682: MBeanServerConnection mbsc = connector
0683: .getMBeanServerConnection();
0684:
0685: //upload parFile to the remote host
0686: String[] dest = uploadFile(mbsc, parFileName);
0687: String destFileName = dest[1];
0688: //Call lImportDesktop on remote host
0689: params[1] = new Boolean(fsOnlyFlag);
0690: params[2] = new Boolean(dpOnlyFlag);
0691: params[5] = destFileName;
0692:
0693: mbsc.invoke(objName, "lImportDesktop", params,
0694: signature);
0695: //clean up temp files
0696: try {
0697: AdminClientUtil.uploadDownloadCleanUp(mbsc,
0698: domainId, dest[0]);
0699: } catch (UploadDownloadException upe) {
0700: if (connector != null) {
0701: connector.close();
0702: }
0703:
0704: logger.log(Level.SEVERE,
0705: "PSDT_CSPDAMB0003", upe);
0706: throw new PSMBeanException(
0707: "error.execute.import", upe
0708: .getMessage());
0709: }
0710:
0711: connector.close();
0712:
0713: //after the import operation has done for
0714: //for the first host, set fsOnly flag is false.
0715: if (dpOnlyFlag) {
0716: break;
0717: } else if (fsOnlyFlag) {
0718: continue;
0719: } else {
0720: fsOnlyFlag = true;
0721: }
0722: } catch (Exception e) {
0723: if (connector != null) {
0724: connector.close();
0725: }
0726:
0727: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", e);
0728: throw new PSMBeanException(
0729: "error.execute.import", e.getMessage());
0730: }
0731: }
0732: }
0733: } catch (Exception e) {
0734: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", e);
0735: throw new PSMBeanException("error.execute.import", e
0736: .getMessage());
0737: }
0738:
0739: }
0740:
0741: /**
0742: * Import the provider data to the Portal Server systems to the specified dn.
0743: * <p>
0744: * This method is called from the server side where the par file
0745: * can be retrieved locally.
0746: * @param parFileName The full path of the par file.
0747: * @param verbose If true then some par specific debugging
0748: * messages will be generated, also debug level will be set to
0749: * "FINEST".
0750: * @param portalId The portal on which the import operation
0751: * should be operated on.
0752: * @param overwrite If true then overwrite the entry .default is false.
0753: * @param operations used for importing provider.
0754: * @param dpnode destination dn where provider is imported
0755: * @param extractDP flag to decide if dp related data is to be imported
0756: * @exception PSMBeanException If the import operation fails.
0757: */
0758: public void lImportProvider(String parFileName, Boolean verbose,
0759: Boolean overwrite, String portalId, List operations,
0760: String dpnode, Boolean extractDP) throws PSMBeanException {
0761:
0762: try {
0763: DesktopData dd = new DesktopData(AdminServerUtil
0764: .getSSOToken(), cc, pdc.getID(), portalId, verbose
0765: .booleanValue(), logger, null);
0766:
0767: dd.importProvider(parFileName, operations, overwrite
0768: .booleanValue(), dpnode, extractDP.booleanValue());
0769:
0770: } catch (DesktopDataException de) {
0771: String message = (de.getCause()) == null ? de.getMessage()
0772: : de.getCause().getMessage();
0773: throw new PSMBeanException("error.execute.import", message);
0774: } catch (Exception e) {
0775: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", e);
0776: throw new PSMBeanException("error.execute.import", e
0777: .getMessage());
0778: }
0779: }
0780:
0781: /**
0782: * Import the desktop data to the Portal Server systems.
0783: * <p>
0784: * This method is called from the server side where the par file
0785: * can be retrieved locally. This is used from the PortalDomain
0786: * MBean where create-portal is executed.
0787: *
0788: * The difference between this method and the importDesktop()
0789: * method is:
0790: *
0791: * First, the portalId is the newly created portal, the
0792: * portalId read from the archive file is ignored.
0793: *
0794: * Secondly, there will be one Portal Server Instance created
0795: * along with the new Portal, so the data will be imported into
0796: * the newly created Portal Server Instance, and the file system
0797: * data will not be propagated to other hosts.
0798: *
0799: * @param verbose If true then some par specific debugging
0800: * messages will be generated, also debug level will be set to
0801: * "FINEST".
0802: * @param fsOnly If true then only the desktop file system data
0803: * will be imported. If fasle the display profile and the service
0804: * attributes will also be imported.
0805: * This parameter is used because in one portal site that
0806: * involving multiple hosts, the data stored in a centralized
0807: * backend storage will only need to be performed once, but the
0808: * file system data needs to be performed in individual host.
0809: * @param portalId The portal on which the import operation
0810: * should be operated on.
0811: * @param parFileName The full path of the par file.
0812: * @param cont If there's miss-match of the schema, e.g., some
0813: * organizations/roles is missing from the target system, continue
0814: * the operation on existing orgs/roles or stop the operation.
0815: * @param searchLevel The search level is used to set the scope
0816: * when accessing to the display profile and service attribute data.
0817: * @exception PSMBeanException If the import operation fails.
0818: */
0819: public void lImportDesktop(Boolean verbose, Boolean fsOnly,
0820: Boolean dpOnly, Boolean overwrite, Boolean redeploy,
0821: String parFileName, String portalId, Boolean cont,
0822: String searchLevel, String dpnode, Boolean skipValidation)
0823: throws PSMBeanException {
0824:
0825: try {
0826: DesktopData dd = new DesktopData(AdminServerUtil
0827: .getSSOToken(), cc, pdc.getID(), portalId, verbose
0828: .booleanValue(), logger, null);
0829:
0830: dd.importDesktop(parFileName, fsOnly.booleanValue(), dpOnly
0831: .booleanValue(), cont.booleanValue(), searchLevel,
0832: overwrite.booleanValue(), dpnode, skipValidation
0833: .booleanValue());
0834:
0835: //create a portal web app on local system
0836: if (redeploy.booleanValue() == true) {
0837: createPortalWebApp();
0838: }
0839: } catch (DesktopDataException de) {
0840: String message = (de.getCause()) == null ? de.getMessage()
0841: : de.getCause().getMessage();
0842: throw new PSMBeanException("error.execute.import", message);
0843: } catch (PSMBeanException pe) {
0844: throw pe;
0845: } catch (Exception e) {
0846: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", e);
0847: throw new PSMBeanException("error.execute.import", e
0848: .getMessage());
0849: }
0850: }
0851:
0852: /**
0853: * Describes the archive file.
0854: */
0855: public String listPar(String parFileName, Boolean verbose,
0856: Boolean dpOnly, Boolean pbfilesOnly, Boolean warOnly,
0857: Boolean staticOnly) throws PSMBeanException {
0858:
0859: String parDescription = null;
0860: Map types = new HashMap();
0861: try {
0862: ParFile pf = ParFile.makeParFile(parFileName);
0863: ParManifest pMan = pf.getParManifest();
0864: if (!dpOnly.booleanValue() && !pbfilesOnly.booleanValue()
0865: && !warOnly.booleanValue()
0866: && !staticOnly.booleanValue()) {
0867: parDescription = pMan.describeAll(pf);
0868: } else {
0869: //create map to set what needs to be described
0870: types.put(new Integer(ParManifest.DPFILE), dpOnly);
0871: types.put(new Integer(ParManifest.PBFILE), pbfilesOnly);
0872: types.put(new Integer(ParManifest.WARFILE), warOnly);
0873: types
0874: .put(new Integer(ParManifest.STATFILE),
0875: staticOnly);
0876:
0877: parDescription = pMan.describeAll(pf, types);
0878: }
0879:
0880: } catch (ParFileException e) {
0881: logger.log(Level.SEVERE, "PSDT_CSPDAMB0002", e);
0882: throw new PSMBeanException("error.list.par",
0883: "DesktopDynamic.listPar");
0884: }
0885: return parDescription;
0886: }
0887:
0888: /**
0889: * Get all hosts that has portal instances for this portal.
0890: */
0891: private Set getHosts() throws PSMBeanException {
0892: Set hosts = new TreeSet();
0893: LinkedList pPath = new LinkedList();
0894: pPath.addFirst(pdc.getID());
0895: pPath.addFirst(path.get(1));
0896:
0897: try {
0898: // gets all instance names
0899: Set instances = pdc.getResourceIDs(
0900: AdminServerUtil.PORTAL_SERVER_INSTANCE_MBEAN_TYPE,
0901: pPath);
0902: Iterator it = instances.iterator();
0903: MBeanServer mbs = PASModule.getMBeanServer();
0904:
0905: while (it.hasNext()) {
0906: String instance = (String) it.next();
0907:
0908: // gets instance object name
0909: ObjectName iObjectName = AdminUtil
0910: .getInstanceMBeanObjectName(pdc.getID(),
0911: (String) path.get(1), instance);
0912: String host = (String) mbs.getAttribute(iObjectName,
0913: "Host");
0914: if (!hosts.contains(host)) {
0915: hosts.add(host);
0916: }
0917: }
0918: } catch (Exception e) {
0919: logger.log(Level.SEVERE, "PSDT_CSPDAMB0004", e);
0920: throw new PSMBeanException(
0921: "error.importexport.get.instances", e.getMessage());
0922: }
0923: return hosts;
0924: }
0925:
0926: private String[] uploadFile(MBeanServerConnection mbsc,
0927: String parFileName) throws PSMBeanException {
0928:
0929: String[] dest = new String[2];
0930: try {
0931: dest = AdminClientUtil.uploadFile(mbsc, pdc.getID(),
0932: new File(parFileName), 0);
0933: } catch (UploadDownloadException upde) {
0934: Object[] tokens = { parFileName };
0935: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", upde);
0936: throw new PSMBeanException("error.importexport.upload",
0937: upde.getMessage(), tokens);
0938: }
0939: return dest;
0940: }
0941:
0942: private void downloadFile(MBeanServerConnection mbsc,
0943: String tempFileName, String parFileName)
0944: throws PSMBeanException {
0945: String destFileName = parFileName;
0946: try {
0947: AdminClientUtil.downloadFile(mbsc, pdc.getID(),
0948: tempFileName, 0, destFileName);
0949: } catch (UploadDownloadException upde) {
0950: Object[] tokens = { parFileName };
0951: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", upde);
0952: throw new PSMBeanException("error.importexport.download",
0953: upde.getMessage(), tokens);
0954: }
0955: }
0956:
0957: private String getRemoteHost() throws PSMBeanException {
0958: String host = null;
0959: boolean isLocal = false;
0960: String oneHost = null;
0961: try {
0962:
0963: Set hosts = getHosts();
0964: String localhost = InetAddress.getLocalHost()
0965: .getCanonicalHostName();
0966: Iterator it = hosts.iterator();
0967: oneHost = null;
0968: while (it.hasNext()) {
0969: oneHost = (String) it.next();
0970: logger.log(Level.INFO, "portal: " + portalId
0971: + ", host: " + oneHost);
0972: if (AdminServerUtil.isLocal(oneHost)) {
0973: logger.log(Level.INFO, "Is local true");
0974: isLocal = true;
0975: break;
0976: }
0977: }
0978: if (isLocal) {
0979: logger.log(Level.INFO, "remote host: " + host);
0980: return host;
0981: }
0982: if (oneHost != null) {
0983: host = oneHost;
0984: }
0985: logger.log(Level.SEVERE,
0986: "DesktopDynamic.getRemoteHost(), localhost: "
0987: + localhost);
0988: } catch (UnknownHostException uhe) {
0989: Object tokens[] = { oneHost };
0990: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", uhe);
0991: throw new PSMBeanException(
0992: "error.importexport.unknownhost", uhe.getMessage(),
0993: tokens);
0994: }
0995:
0996: return host;
0997: }
0998:
0999: private void createPortalWebApp() throws PSMBeanException {
1000: String[] signature = {};
1001: Object[] params = {};
1002: try {
1003: ObjectName on = AdminUtil.getPortalMBeanObjectName(
1004: domainId, portalId);
1005: MBeanServer mbs = PASModule.getMBeanServer();
1006: mbs.invoke(on, "createPortalWebApp", params, signature);
1007: } catch (Exception e) {
1008: logger.log(Level.SEVERE, "PSDT_CSPDAMB0003", e);
1009: throw new PSMBeanException(
1010: "error.importexport.createPortalWeb", e
1011: .getMessage());
1012: }
1013: }
1014:
1015: /*
1016: * Build the MBeanInfo for the DesktopDynamic MBean.
1017: */
1018: private void buildMBeanInfo() {
1019: String description = "Desktop Dynamic mbean implementation.";
1020: Constructor[] constructors = this .getClass().getConstructors();
1021: MBeanConstructorInfo[] constructorInfo = new MBeanConstructorInfo[1];
1022: constructorInfo[0] = new MBeanConstructorInfo(
1023: "DesktopDynamic(): Constructs a DesktopDynamic object",
1024: constructors[0]);
1025:
1026: MBeanOperationInfo[] operations = new MBeanOperationInfo[9];
1027:
1028: //getArchiveFileVersion
1029: MBeanParameterInfo[] bParams = new MBeanParameterInfo[1];
1030: bParams[0] = new MBeanParameterInfo("parFileName",
1031: "java.lang.String", "parFileName");
1032: //deleteTempFile
1033: MBeanParameterInfo[] dParams = new MBeanParameterInfo[1];
1034: dParams[0] = new MBeanParameterInfo("tempFileName",
1035: "java.lang.String", "tempFileName");
1036: //exportDesktop
1037: MBeanParameterInfo[] eParams = new MBeanParameterInfo[5];
1038: eParams[0] = new MBeanParameterInfo("parFileName",
1039: "java.lang.String", "parFileName");
1040: eParams[1] = new MBeanParameterInfo("verbose",
1041: "java.lang.Boolean", "verbose");
1042: eParams[2] = new MBeanParameterInfo("fsOnly",
1043: "java.lang.Boolean", "files-only");
1044: eParams[3] = new MBeanParameterInfo("dpOnly",
1045: "java.lang.Boolean", "dp-only");
1046: eParams[4] = new MBeanParameterInfo("searchLevel",
1047: "java.lang.String", "scope");
1048: //exportProvider
1049: MBeanParameterInfo[] pParams = new MBeanParameterInfo[5];
1050: pParams[0] = new MBeanParameterInfo("parFileName",
1051: "java.lang.String", "parFileName");
1052: pParams[1] = new MBeanParameterInfo("verbose",
1053: "java.lang.Boolean", "verbose");
1054: pParams[2] = new MBeanParameterInfo("dn", "java.lang.String",
1055: "dn");
1056: pParams[3] = new MBeanParameterInfo("global",
1057: "java.lang.Boolean", "global");
1058: pParams[4] = new MBeanParameterInfo("exportfile", "[[B",
1059: "exportfile");
1060: //importProvider
1061: MBeanParameterInfo[] ipParams = new MBeanParameterInfo[5];
1062: ipParams[0] = new MBeanParameterInfo("parFileName",
1063: "java.lang.String", "parFileName");
1064: ipParams[1] = new MBeanParameterInfo("verbose",
1065: "java.lang.Boolean", "verbose");
1066: ipParams[2] = new MBeanParameterInfo("overwrite",
1067: "java.lang.Boolean", "overwrite");
1068: ipParams[3] = new MBeanParameterInfo("operations",
1069: "java.util.List", "operations");
1070: ipParams[4] = new MBeanParameterInfo("dpnode",
1071: "java.lang.String", "dpnode");
1072: //lImportProvider
1073: MBeanParameterInfo[] lipParams = new MBeanParameterInfo[7];
1074: lipParams[0] = new MBeanParameterInfo("parFileName",
1075: "java.lang.String", "parFileName");
1076: lipParams[1] = new MBeanParameterInfo("verbose",
1077: "java.lang.Boolean", "verbose");
1078: lipParams[2] = new MBeanParameterInfo("overwrite",
1079: "java.lang.Boolean", "overwrite");
1080: lipParams[3] = new MBeanParameterInfo("portalId",
1081: "java.lang.String", "portalId");
1082: lipParams[4] = new MBeanParameterInfo("operations",
1083: "java.util.List", "operations");
1084: lipParams[5] = new MBeanParameterInfo("dpnode",
1085: "java.lang.String", "dpnode");
1086: lipParams[6] = new MBeanParameterInfo("extractDP",
1087: "java.lang.Boolean", "extractDP");
1088: //importDesktop
1089: MBeanParameterInfo[] iParams = new MBeanParameterInfo[10];
1090: iParams[0] = new MBeanParameterInfo("verbose",
1091: "java.lang.Boolean", "verbose");
1092: iParams[1] = new MBeanParameterInfo("fsOnly",
1093: "java.lang.Boolean", "files-only");
1094: iParams[2] = new MBeanParameterInfo("dpOnly",
1095: "java.lang.Boolean", "dp-only");
1096: iParams[3] = new MBeanParameterInfo("overwrite",
1097: "java.lang.Boolean", "overwrite");
1098: iParams[4] = new MBeanParameterInfo("redeploy",
1099: "java.lang.Boolean", "redeploy");
1100: iParams[5] = new MBeanParameterInfo("parFileName",
1101: "java.lang.String", "parFileName");
1102: iParams[6] = new MBeanParameterInfo("cont",
1103: "java.lang.Boolean", "continue");
1104: iParams[7] = new MBeanParameterInfo("searchLevel",
1105: "java.lang.String", "scope");
1106: iParams[8] = new MBeanParameterInfo("dpnode",
1107: "java.lang.String", "dpnode");
1108: iParams[9] = new MBeanParameterInfo("skipValidation",
1109: "java.lang.Boolean", "skip-node-validation");
1110: //lImportDesktop
1111: MBeanParameterInfo[] lParams = new MBeanParameterInfo[11];
1112: lParams[0] = new MBeanParameterInfo("verbose",
1113: "java.lang.Boolean", "verbose");
1114: lParams[1] = new MBeanParameterInfo("fsOnly",
1115: "java.lang.Boolean", "files-only");
1116: lParams[2] = new MBeanParameterInfo("dpOnly",
1117: "java.lang.Boolean", "dp-only");
1118: lParams[3] = new MBeanParameterInfo("overwrite",
1119: "java.lang.Boolean", "overwrite");
1120: lParams[4] = new MBeanParameterInfo("redeploy",
1121: "java.lang.Boolean", "redeploy");
1122: lParams[5] = new MBeanParameterInfo("parFileName",
1123: "java.lang.String", "parFileName");
1124: lParams[6] = new MBeanParameterInfo("portalId",
1125: "java.lang.String", "portal");
1126: lParams[7] = new MBeanParameterInfo("cont",
1127: "java.lang.Boolean", "continue");
1128: lParams[8] = new MBeanParameterInfo("searchLevel",
1129: "java.lang.String", "scope");
1130: lParams[9] = new MBeanParameterInfo("dpnode",
1131: "java.lang.String", "dpnode");
1132: lParams[10] = new MBeanParameterInfo("skipValidation",
1133: "java.lang.Boolean", "skip-node-validation");
1134: //listPar
1135: MBeanParameterInfo[] tParams = new MBeanParameterInfo[6];
1136: tParams[0] = new MBeanParameterInfo("parFileName",
1137: "java.lang.String", "parFileName");
1138: tParams[1] = new MBeanParameterInfo("verbose",
1139: "java.lang.Boolean", "verbose");
1140: tParams[2] = new MBeanParameterInfo("dpOnly",
1141: "java.lang.Boolean", "dpOnly");
1142: tParams[3] = new MBeanParameterInfo("pbfilesOnly",
1143: "java.lang.Boolean", "pbfilesOnly");
1144: tParams[4] = new MBeanParameterInfo("warOnly",
1145: "java.lang.Boolean", "warOnly");
1146: tParams[5] = new MBeanParameterInfo("staticOnly",
1147: "java.lang.Boolean", "staticOnly");
1148:
1149: //define operations in MBeanOperationInfo
1150: operations[0] = new MBeanOperationInfo("getArchiveFileVersion",
1151: "getArchiveFileVersion(): get the backup file version",
1152: bParams, "java.lang.String", MBeanOperationInfo.ACTION);
1153: operations[1] = new MBeanOperationInfo("deleteTempFile",
1154: "deleteTempFile(): delete temporary file", dParams,
1155: "void", MBeanOperationInfo.ACTION);
1156: operations[2] = new MBeanOperationInfo("exportDesktop",
1157: "exportDesktop(): export desktop data", eParams,
1158: "void", MBeanOperationInfo.ACTION);
1159:
1160: operations[3] = new MBeanOperationInfo("importDesktop",
1161: "importDesktop(): import desktop data", iParams,
1162: "void", MBeanOperationInfo.ACTION);
1163:
1164: operations[4] = new MBeanOperationInfo("lImportDesktop",
1165: "lImportDesktop(): import desktop data", lParams,
1166: "void", MBeanOperationInfo.ACTION);
1167:
1168: operations[5] = new MBeanOperationInfo("listPar",
1169: "listPar(): describes par file", tParams,
1170: "java.lang.String", MBeanOperationInfo.ACTION);
1171: operations[6] = new MBeanOperationInfo("exportProvider",
1172: "exportProvider(): export provider data", pParams,
1173: "void", MBeanOperationInfo.ACTION);
1174: operations[7] = new MBeanOperationInfo("importProvider",
1175: "importProvider(): import provider data", ipParams,
1176: "void", MBeanOperationInfo.ACTION);
1177: operations[8] = new MBeanOperationInfo("lImportProvider",
1178: "lImportProvider(): import provider data", lipParams,
1179: "void", MBeanOperationInfo.ACTION);
1180:
1181: //define MBeanInfo
1182: dMBeanInfo = new MBeanInfo(dClassName, description,
1183: new MBeanAttributeInfo[0], constructorInfo, operations,
1184: new MBeanNotificationInfo[0]);
1185: }
1186:
1187: }
|