0001: /**
0002: * Copyright 2004 Sun Microsystems, Inc. All
0003: * rights reserved. Use of this product is subject
0004: * to license terms. Federal Acquisitions:
0005: * Commercial Software -- Government Users
0006: * Subject to Standard License Terms and
0007: * Conditions.
0008: *
0009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0010: * are trademarks or registered trademarks of Sun Microsystems,
0011: * Inc. in the United States and other countries.
0012: */package com.sun.portal.fabric.mbeans;
0013:
0014: import java.io.File;
0015: import java.io.UnsupportedEncodingException;
0016: import java.io.BufferedReader;
0017: import java.io.FileReader;
0018: import java.io.FilenameFilter;
0019: import java.io.InputStream;
0020: import java.io.FileInputStream;
0021: import java.io.IOException;
0022: import java.util.*;
0023: import java.util.logging.Level;
0024: import java.util.logging.Logger;
0025: import java.util.logging.LogRecord;
0026: import java.net.URL;
0027:
0028: import javax.management.remote.JMXConnector;
0029: import javax.management.MBeanServerConnection;
0030: import javax.management.MBeanServer;
0031: import javax.management.ObjectName;
0032: import javax.management.MBeanException;
0033: import javax.management.JMException;
0034:
0035: import sun.misc.BASE64Encoder;
0036: import com.iplanet.sso.SSOToken;
0037:
0038: import com.sun.portal.admin.common.AttrOptionConstants;
0039: import com.sun.portal.admin.common.PSConfigConstants;
0040: import com.sun.portal.admin.common.PSMBeanException;
0041: import com.sun.portal.admin.common.InstanceAttributes;
0042: import com.sun.portal.admin.common.PortalAttributes;
0043: import com.sun.portal.admin.common.context.PSConfigContext;
0044: import com.sun.portal.admin.common.context.PortalDomainContext;
0045: import com.sun.portal.admin.common.util.AdminUtil;
0046: import com.sun.portal.admin.common.util.AdminClientUtil;
0047: import com.sun.portal.admin.server.AdminServerUtil;
0048: import com.sun.portal.admin.server.PASModule;
0049: import com.sun.portal.admin.server.mbeans.PSResource;
0050: import com.sun.portal.fabric.tasks.WebContainerFactory;
0051: import com.sun.portal.fabric.tasks.WebContainer;
0052: import com.sun.portal.fabric.common.AttributeHandler;
0053: import com.sun.portal.fabric.common.AttributeHandlerFactory;
0054: import com.sun.portal.fabric.tasks.ConfigurationException;
0055: import com.sun.portal.fabric.tasks.Domain;
0056: import com.sun.portal.fabric.tasks.EnableServices;
0057: import com.sun.portal.fabric.tasks.Portal;
0058: import com.sun.portal.fabric.tasks.SearchSetup;
0059: import com.sun.portal.fabric.tasks.PortalVersion;
0060: import com.sun.portal.fabric.tasks.CreateSearchServerThread;
0061: import com.sun.portal.fabric.util.FileUtil;
0062: import com.sun.portal.util.Platform;
0063: import com.sun.portal.log.common.PortalLogger;
0064:
0065: public class PortalDomain extends PSResource implements
0066: PortalDomainMBean {
0067: private static class PortletWarFilenameFilter implements
0068: FilenameFilter {
0069: public boolean accept(File dir, String name) {
0070: if (!name.endsWith("war")) {
0071: return false;
0072: }
0073: return true;
0074: }
0075: }
0076:
0077: private static final FilenameFilter PORTLET_WAR_FILENAME_FILTER = new PortletWarFilenameFilter();
0078:
0079: private static final String FS = Platform.fs;
0080: private static Logger logger = PortalLogger
0081: .getLogger(PortalDomain.class);
0082: private CreateSearchServerThread csst = null;
0083:
0084: public void init(PSConfigContext cc, PortalDomainContext pdc,
0085: List path) {
0086: super .init(cc, pdc, path);
0087:
0088: try {
0089: if (!isResourceAvailable(
0090: PortalLogConfigHostBridgeMBean.TYPE,
0091: "portalLogConfigHostBridge")) {
0092: pdc.createResource(PortalLogConfigHostBridgeMBean.TYPE,
0093: path, "portalLogConfigHostBridge",
0094: Collections.EMPTY_MAP);
0095: PASModule.reloadMBeans(pdc,
0096: PortalLogConfigHostBridgeMBean.TYPE, path);
0097: }
0098: } catch (Exception pme) {
0099: logger.log(Level.SEVERE, "PSFB_CSPFM1064", pme);
0100: }
0101:
0102: try {
0103: if (!isResourceAvailable(PortalLogConfiguratorMBean.TYPE,
0104: "portalLogConfigurator")) {
0105: pdc.createResource(PortalLogConfiguratorMBean.TYPE,
0106: path, "portalLogConfigurator",
0107: Collections.EMPTY_MAP);
0108: PASModule.reloadMBeans(pdc,
0109: PortalLogConfiguratorMBean.TYPE, path);
0110: }
0111: } catch (Exception pme) {
0112: logger.log(Level.SEVERE, "PSFB_CSPFM1065", pme);
0113: }
0114:
0115: try {
0116: if (!isResourceAvailable(PortalDomainMBean.TYPE
0117: + ".Rewriter", "rewriter")) {
0118: pdc.createResource(
0119: PortalDomainMBean.TYPE + ".Rewriter", path,
0120: "rewriter", Collections.EMPTY_MAP);
0121: PASModule.reloadMBeans(pdc, PortalDomainMBean.TYPE
0122: + ".Rewriter", path);
0123: }
0124: } catch (Exception pme) {
0125: logger.log(Level.SEVERE, "PSFB_CSPFM1066", pme);
0126: }
0127:
0128: if (AdminUtil.isSRAInstalled(cc)) {
0129:
0130: try {
0131: if (!isResourceAvailable(PortalDomainMBean.TYPE
0132: + ".SRA", "sra")) {
0133: pdc.createResource(PortalDomainMBean.TYPE + ".SRA",
0134: path, "sra", Collections.EMPTY_MAP);
0135: PASModule.reloadMBeans(pdc, PortalDomainMBean.TYPE
0136: + ".SRA", path);
0137: }
0138: } catch (Exception pme) {
0139: logger.log(Level.SEVERE, "PSFB_CSPFM1067", pme);
0140: }
0141: try {
0142: if (!isResourceAvailable(PortalDomainMBean.TYPE
0143: + ".SRAMonitoring", "sramonitoring")) {
0144: pdc.createResource(PortalDomainMBean.TYPE
0145: + ".SRAMonitoring", path, "sramonitoring",
0146: Collections.EMPTY_MAP);
0147: PASModule.reloadMBeans(pdc, PortalDomainMBean.TYPE
0148: + ".SRAMonitoring", path);
0149: }
0150: } catch (Exception pme) {
0151: logger.log(Level.SEVERE, "PSFB_CSPFM1068", pme);
0152: }
0153: }
0154:
0155: if (!AdminUtil.isOnlySRAInstalled(cc)) {
0156: try {
0157: if (!isResourceAvailable(SchedulerMBean.TYPE,
0158: "scheduler")) {
0159: pdc.createResource(SchedulerMBean.TYPE, path,
0160: "scheduler", Collections.EMPTY_MAP);
0161: PASModule.reloadMBeans(pdc, SchedulerMBean.TYPE,
0162: path);
0163: }
0164: } catch (Exception pme) {
0165: logger.log(Level.SEVERE, "PSFB_CSPFM1063", pme);
0166: }
0167:
0168: try {
0169: if (!isResourceAvailable(AMObjectSearchMBean.TYPE,
0170: "amobjsearch")) {
0171: pdc.createResource(AMObjectSearchMBean.TYPE, path,
0172: "amobjsearch", Collections.EMPTY_MAP);
0173: PASModule.reloadMBeans(pdc,
0174: AMObjectSearchMBean.TYPE, path);
0175: }
0176: } catch (Exception pme) {
0177: logger.log(Level.SEVERE, "PSFB_CSPFM1062", pme);
0178: }
0179:
0180: try {
0181: if (!isResourceAvailable(PortalDomainMBean.TYPE
0182: + ".UploadDownloadFileManager",
0183: "UploadDownloadFileManager")) {
0184: pdc.createResource(PortalDomainMBean.TYPE
0185: + ".UploadDownloadFileManager", path,
0186: "UploadDownloadFileManager",
0187: Collections.EMPTY_MAP);
0188: PASModule.reloadMBeans(pdc, PortalDomainMBean.TYPE
0189: + ".UploadDownloadFileManager", path);
0190: }
0191:
0192: } catch (Exception pme) {
0193: logger.log(Level.SEVERE, "PSFB_CSPFM1069", pme);
0194: }
0195:
0196: try {
0197: if (!isResourceAvailable(PortalDomainMBean.TYPE
0198: + ".SSOAdapter", "ssoadapter")) {
0199: pdc.createResource(PortalDomainMBean.TYPE
0200: + ".SSOAdapter", path, "ssoadapter",
0201: Collections.EMPTY_MAP);
0202: PASModule.reloadMBeans(pdc, PortalDomainMBean.TYPE
0203: + ".SSOAdapter", path);
0204: }
0205: } catch (Exception pme) {
0206: logger.log(Level.SEVERE, "PSFB_CSPFM1070", pme);
0207: }
0208: }
0209: }
0210:
0211: public void setDomainRepositoryPassword(String password)
0212: throws PSMBeanException {
0213:
0214: File domainConfigFile = new File(cc.getPSConfigDir() + fs
0215: + PSConfigConstants.DOMAINS + fs + getID() + fs
0216: + PSConfigConstants.DOMAIN_CONFIG_FILE);
0217:
0218: String pattern = PSConfigConstants.DOMAIN_DATA_CREDENTIALS
0219: + "=";
0220:
0221: if (password == null) {
0222: password = "";
0223: } else {
0224: try {
0225: byte[] passwordBytes = password.getBytes("8859_1");
0226: password = (new BASE64Encoder())
0227: .encodeBuffer(passwordBytes);
0228: } catch (UnsupportedEncodingException e) {
0229: logger.log(Level.SEVERE, "PSFB_CSPFM1071", e);
0230: }
0231: }
0232:
0233: String text = pattern + password;
0234:
0235: if (!FileUtil
0236: .replaceLineInFile(domainConfigFile, pattern, text)) {
0237: String message = "Can't set domain repository password.";
0238: logger.log(Level.SEVERE, "PSFB_CSPFM1071");
0239: throw new PSMBeanException("admin.error.setPassword",
0240: message);
0241: }
0242:
0243: logger.log(Level.INFO, "PSFB_CSPFM1072", password);
0244: }
0245:
0246: public List getPortals() throws PSMBeanException {
0247: // Return the list of portals in the domain by getting the data from PDC
0248: try {
0249: return new ArrayList(pdc.getResourceIDs(PortalMBean.TYPE,
0250: path));
0251: } catch (Exception e) {
0252: if (logger.isLoggable(Level.SEVERE)) {
0253: LogRecord rec = new LogRecord(Level.SEVERE,
0254: "PSFB_CSPFM1073");
0255: rec.setLoggerName(logger.getName());
0256: rec.setParameters(new Object[] { m_sPsID });
0257: rec.setThrown(e);
0258: logger.log(rec);
0259: }
0260: throw new PSMBeanException("admin.error.getPortals", e
0261: .getMessage(), e, new Object[] { m_sPsID });
0262: }
0263: }
0264:
0265: /**
0266: * Get file prefix.
0267: * The file's prefix is the file name, minus the path, minus the extension.
0268: */
0269: private static String getFilePrefix(File f) {
0270: String s = f.getName();
0271: int i = s.lastIndexOf(".");
0272: if (i == -1) {
0273: return s;
0274: }
0275:
0276: s = s.substring(0, i);
0277: return s;
0278: }
0279:
0280: /**
0281: * Get a portlet's user info file based on the portlet WAR file.
0282: * If a WAR file is of the form name.war, the user info file
0283: * us of the form name.user.properties.
0284: */
0285: private static File getUserInfoFile(File portletWarFile) {
0286: String s = getFilePrefix(portletWarFile);
0287: File userInfoFile = new File(portletWarFile.getParent(), s
0288: + ".user.properties");
0289: return userInfoFile;
0290: }
0291:
0292: /**
0293: * Get a portlet's roles file based on the portlet WAR file.
0294: * If a WAR file is of the form name.war, the roles file
0295: * us of the form name.roles.properties.
0296: */
0297: private static File getRolesFile(File portletWarFile) {
0298: String s = getFilePrefix(portletWarFile);
0299: File rolesFile = new File(portletWarFile.getParent(), s
0300: + ".roles.properties");
0301: return rolesFile;
0302: }
0303:
0304: /**
0305: * Register (deploy w/ nodeploy option) all portlets under the
0306: * .../portlet/core directory.
0307: */
0308: private void registerCorePortlets(MBeanServer mbs, String portalID)
0309: throws PSMBeanException {
0310: File corePortletsDir = new File(cc.getPSBaseDir() + fs
0311: + "portlet" + fs + "core");
0312: if (!corePortletsDir.exists()) {
0313: return;
0314: }
0315: File[] corePortletWars = corePortletsDir
0316: .listFiles(PORTLET_WAR_FILENAME_FILTER);
0317:
0318: // arguments for mbean call
0319: // these are the same regardless of the portlet
0320: // so are defined outside of the loop
0321: String[] sign = { "java.lang.String", "java.lang.Boolean",
0322: "java.lang.String", "java.util.Properties",
0323: "java.util.Properties", "java.lang.Boolean",
0324: "java.util.List", "java.lang.Boolean",
0325: "java.lang.Boolean" };
0326: //Note: as the instance does not exist yet, use the --nodeploy option
0327: List instanceList = Collections.singletonList("DummyInstance");
0328: boolean nodeploy = true;
0329: String dn = null;
0330: boolean global = true;
0331: boolean verbose = true;
0332:
0333: for (int i = 0; i < corePortletWars.length; i++) {
0334: File portletWarFile = corePortletWars[i];
0335:
0336: LinkedList path = new LinkedList();
0337: path.addFirst(getID());
0338: path.addFirst(portalID);
0339: path.addFirst(AdminUtil.PORTLET_ADMIN_MBEAN);
0340:
0341: try {
0342: ObjectName objName = AdminUtil
0343: .getResourceMBeanObjectName(
0344: AdminUtil.PORTLET_ADMIN_MBEAN_TYPE,
0345: path);
0346: Properties userinfoProperties = new Properties();
0347: // if the user info file exists, use it
0348: File userInfoFile = getUserInfoFile(portletWarFile);
0349: if (userInfoFile.exists()) {
0350: InputStream is = new FileInputStream(userInfoFile);
0351: userinfoProperties.load(is);
0352: is.close();
0353: }
0354: Properties rolesProperties = new Properties();
0355: // if the roles file exists, use it
0356: File rolesFile = getRolesFile(portletWarFile);
0357: if (rolesFile.exists()) {
0358: InputStream is = new FileInputStream(rolesFile);
0359: rolesProperties.load(is);
0360: is.close();
0361: }
0362:
0363: Object[] parm = { dn, Boolean.valueOf(global),
0364: portletWarFile.toString(), rolesProperties,
0365: userinfoProperties, Boolean.valueOf(verbose),
0366: instanceList, Boolean.valueOf(false),
0367: Boolean.valueOf(nodeploy) };
0368:
0369: mbs.invoke(objName, "deployAll", parm, sign);
0370: } catch (JMException e) {
0371: if (logger.isLoggable(Level.SEVERE)) {
0372: LogRecord rec = new LogRecord(Level.SEVERE,
0373: "PSFB_CSPFM1128");
0374: rec.setLoggerName(logger.getName());
0375: rec.setParameters(new Object[] {
0376: portletWarFile.toString(), portalID });
0377: rec.setThrown(e);
0378: logger.log(rec);
0379: }
0380: } catch (IOException e) {
0381: if (logger.isLoggable(Level.SEVERE)) {
0382: LogRecord rec = new LogRecord(Level.SEVERE,
0383: "PSFB_CSPFM1128");
0384: rec.setLoggerName(logger.getName());
0385: rec.setParameters(new Object[] {
0386: portletWarFile.toString(), portalID });
0387: rec.setThrown(e);
0388: logger.log(rec);
0389: }
0390: }
0391: }
0392: }
0393:
0394: public void createPortal(String portalID, String host, String uri)
0395: throws PSMBeanException {
0396:
0397: try {
0398: // Check if the host in the param is the local host
0399: if (host != null && !AdminUtil.isLocal(host)) {
0400: // If not connect to the remote host and invoke the create
0401: // portal operation
0402: ObjectName domainObj = AdminUtil
0403: .getPortalDomainMBeanObjectName(getDomainID());
0404: Object[] params = { portalID, host, uri };
0405: String[] signature = { "java.lang.String",
0406: "java.lang.String", "java.lang.String" };
0407: invokeRemoteOperation(host, domainObj, "createPortal",
0408: params, signature);
0409: return;
0410: }
0411: } catch (Exception e) {
0412: if (logger.isLoggable(Level.SEVERE)) {
0413: LogRecord rec = new LogRecord(Level.SEVERE,
0414: "PSFB_CSPFM1025");
0415: rec.setLoggerName(logger.getName());
0416: rec.setParameters(new Object[] { portalID });
0417: rec.setThrown(e);
0418: logger.log(rec);
0419: }
0420: throw new PSMBeanException("admin.error.create.portal",
0421: getStackTrace(e), new Object[] { portalID });
0422: }
0423:
0424: if (AdminUtil.isOnlySRAInstalled(cc)) {
0425: throw new PSMBeanException(
0426: "error.psadmin.non.sra.validateion.failed");
0427: }
0428:
0429: // Get the SSO Token form PAS
0430: SSOToken ssoToken = AdminServerUtil.getSSOToken();
0431:
0432: // Get the amadmin Password. - TODO do not use passwords
0433: // Modify task classes to remove requirment of passoword strings
0434: String amAdminPassword = AdminServerUtil.getPassword();
0435:
0436: // Create an instance of the EnableServices task object that will
0437: // enable the service template creation
0438: EnableServices es = new EnableServices(cc, amAdminPassword);
0439:
0440: // Create an instance of the Portal task object to do the configuration
0441: // tasks
0442: Portal newPortal = new Portal(cc);
0443:
0444: // Get the list of all PortalIDs in the current domain
0445: List allPortals = getPortals();
0446: try {
0447:
0448: if (allPortals.size() > 0) {
0449: // If the portalID already exists in the domain repository quit.
0450: // Portal-id is case retentive, so users may use it in a
0451: // case insensitive manner.
0452: Iterator iter = allPortals.iterator();
0453: while (iter.hasNext()) {
0454: String id = (String) iter.next();
0455: if (id.equalsIgnoreCase(portalID)) {
0456: logger.log(Level.SEVERE, "PSFB_CSPFM1074");
0457: throw new PSMBeanException(
0458: "admin.error.duplicate.portal",
0459: "Portal " + portalID
0460: + " already exists",
0461: new Object[] { portalID });
0462: }
0463: }
0464: } else {
0465: // This is the first portal that is being created. So the domain
0466: // services and related configuration needs to be done
0467: Domain pDomain = new Domain(cc);
0468: pDomain.configureMandatoryServices(ssoToken);
0469:
0470: // Use the Enable services task class to create service template
0471: // at the default org for the portal domain services
0472: es.domainServices(cc.getDefaultOrganization());
0473:
0474: // Load RewriterRuleSets for Portal
0475: logger.log(Level.INFO, "PSFB_CSPFC0201");
0476: loadPortalRewriterRulesSet();
0477: logger.log(Level.INFO, "PSFB_CSPFC0202");
0478: }
0479:
0480: logger.log(Level.INFO, "PSFB_CSPFM1075", portalID);
0481: newPortal.configurePortal(portalID, ssoToken, cc
0482: .getDirectoryServerHost(), cc
0483: .getDirectoryServerPort(), cc
0484: .getUserDataStoreManager(), cc
0485: .getUserDataStoreManagerCredentials(), cc
0486: .isDomainDataSecure());
0487:
0488: logger.log(Level.INFO, "PSFB_CSPFM1076", portalID);
0489: es.portalServices(portalID, cc.getDefaultOrganization(), cc
0490: .getUserNamingAttribute());
0491: } catch (ConfigurationException ce) {
0492: if (logger.isLoggable(Level.SEVERE)) {
0493: LogRecord rec = new LogRecord(Level.SEVERE,
0494: "PSFB_CSPFM1077");
0495: rec.setLoggerName(logger.getName());
0496: rec.setParameters(new Object[] { portalID });
0497: rec.setThrown(ce);
0498: logger.log(rec);
0499: }
0500:
0501: throw new PSMBeanException("admin.error.configure.portal",
0502: getStackTrace(ce), new Object[] { portalID });
0503: }
0504:
0505: logger.log(Level.INFO, "PSFB_CSPFM1078", portalID);
0506: // Store the new portal data in the portal domain context
0507: List portalPath = AdminUtil.getChildPath(path, portalID);
0508: Map attributes = new HashMap();
0509: attributes.put(PortalAttributes.NAME, portalID);
0510: attributes.put(PortalAttributes.DESCRIPTION, portalID);
0511: attributes.put(PortalAttributes.PORTAL_URI, uri);
0512:
0513: try {
0514: // Register the newly created Portal as a domain resource
0515: logger.log(Level.INFO, "PSFB_CSPFM1079");
0516: pdc.createResource(PortalMBean.TYPE, path, portalID,
0517: attributes);
0518:
0519: // Register the import/export MBean for this Portal.
0520: logger.log(Level.INFO, "PSFB_CSPFM1080");
0521: pdc.createResource(AdminUtil.DESKTOP_DYNAMIC_MBEAN_TYPE,
0522: portalPath, AdminUtil.DESKTOP_DYNAMIC_MBEAN,
0523: Collections.EMPTY_MAP);
0524:
0525: // Register the DPAdminWrapperMBean for this Portal.
0526: logger.log(Level.INFO, "PSFB_CSPFM1081");
0527: pdc.createResource(AdminUtil.DPADMINWRAPPER_MBEAN_TYPE,
0528: portalPath, AdminUtil.DPADMINWRAPPER_MBEAN,
0529: Collections.EMPTY_MAP);
0530:
0531: // Register the DisplayProfileMBean for this Portal.
0532: logger.log(Level.INFO, "PSFB_CSPFM1082");
0533: pdc.createResource(AdminUtil.DISPLAYPROFILE_MBEAN_TYPE,
0534: portalPath, AdminUtil.DISPLAYPROFILE_MBEAN,
0535: Collections.EMPTY_MAP);
0536:
0537: // There is one Subscription service per Portal
0538: pdc.createResource(AdminUtil.PROFILER_MBEAN_TYPE,
0539: portalPath, AdminUtil.PROFILER_MBEAN,
0540: Collections.EMPTY_MAP);
0541:
0542: // There is one Community Manager service per Portal.
0543: Map m = new HashMap();
0544: m.put("PortalID", portalID);
0545: m.put("CommunityManagerWSURL", "");
0546: m.put("UserCommunityManagerWSURL", "");
0547: pdc.createResource(AdminUtil.COMMUNITYMANAGER_MBEAN_TYPE,
0548: portalPath, AdminUtil.COMMUNITYMANAGER_MBEAN, m);
0549:
0550: // Register the PortletAdminMBean for this Portal.
0551: logger.log(Level.INFO, "PSFB_CSPFM1083");
0552: pdc.createResource(AdminUtil.PORTLET_ADMIN_MBEAN_TYPE,
0553: portalPath, AdminUtil.PORTLET_ADMIN_MBEAN,
0554: Collections.EMPTY_MAP);
0555:
0556: // There is one Producer Manager per portal.
0557: pdc.createResource(PortalMBean.TYPE + ".ProducerManager",
0558: portalPath, "ProducerManager",
0559: Collections.EMPTY_MAP);
0560:
0561: // There is a default Producer.
0562: pdc.createResource(PortalMBean.TYPE
0563: + ".ProducerManager.Producer", AdminUtil
0564: .getChildPath(portalPath, "ProducerManager"),
0565: "default", Collections.EMPTY_MAP);
0566:
0567: // There is one Consumer per portal.
0568: pdc.createResource(PortalMBean.TYPE + ".Consumer",
0569: portalPath, "Consumer", Collections.EMPTY_MAP);
0570:
0571: // There is one RegistryConsumer per portal
0572: pdc
0573: .createResource(PortalMBean.TYPE
0574: + ".RegistrySearch", portalPath,
0575: "RegistrySearch", Collections.EMPTY_MAP);
0576:
0577: // There is one RegistryPublish per portal
0578: pdc.createResource(PortalMBean.TYPE + ".RegistryPublish",
0579: portalPath, "RegistryPublish",
0580: Collections.EMPTY_MAP);
0581: // UBT MBeans per portal
0582: logger.log(Level.INFO, "PSFB_CSPFM1084");
0583: pdc.createResource(PortalMBean.TYPE
0584: + ".UBTReportAggregator", portalPath,
0585: "UBTReportAggregator", Collections.EMPTY_MAP);
0586: logger.log(Level.INFO, "PSFB_CSPFM1085");
0587: pdc.createResource(PortalMBean.TYPE + ".UBTReport",
0588: portalPath, "UBTReport", Collections.EMPTY_MAP);
0589: logger.log(Level.INFO, "PSFB_CSPFM1086");
0590: pdc.createResource(PortalMBean.TYPE
0591: + ".UBTSettingsHostBridge", portalPath,
0592: "UBTSettingsHostBridge", Collections.EMPTY_MAP);
0593: logger.log(Level.INFO, "PSFB_CSPFM1087");
0594: pdc.createResource(PortalMBean.TYPE + ".UBTSettings",
0595: portalPath, "UBTSettings", Collections.EMPTY_MAP);
0596:
0597: // The PAS reload operation will ensure that MBean objects will be
0598: // instantiated for newly registered resouces.
0599: logger.log(Level.INFO, "PSFB_CSPFM1088");
0600: PASModule.reloadMBeans(pdc, PortalMBean.TYPE, path);
0601:
0602: // Get the MBean server object on the local host
0603: MBeanServer mbs = PASModule.getMBeanServer();
0604:
0605: // Construct the ObjectName for the newly created import/export
0606: // MBean using the AdminUtil
0607: ObjectName mBeanName = AdminUtil
0608: .getResourceMBeanObjectName(
0609: AdminUtil.DESKTOP_DYNAMIC_MBEAN_TYPE,
0610: AdminUtil.getChildPath(portalPath,
0611: AdminUtil.DESKTOP_DYNAMIC_MBEAN));
0612:
0613: String parLoc = newPortal.createDesktopPar();
0614:
0615: // Prepare the signature for the import desktop method invocation
0616: String[] signature = { "java.lang.Boolean",
0617: "java.lang.Boolean", "java.lang.Boolean",
0618: "java.lang.Boolean", "java.lang.Boolean",
0619: "java.lang.String", "java.lang.String",
0620: "java.lang.Boolean", "java.lang.String",
0621: "java.lang.String" };
0622:
0623: // Prepare the params for the import desktop method invocation
0624: Object[] params = { Boolean.FALSE, Boolean.FALSE,
0625: Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, parLoc,
0626: portalID, Boolean.TRUE, "2", "", Boolean.FALSE };
0627:
0628: // Invoke the importdesktop method on the
0629: logger.log(Level.INFO, "PSFB_CSPFM1089");
0630: mbs.invoke(mBeanName, "lImportDesktop", params, signature);
0631:
0632: // Delete the imported par file from the portal tmp dir
0633: File parFile = new File(parLoc);
0634: if (parFile.exists()) {
0635: parFile.delete();
0636: }
0637:
0638: // Following steps create the Portal WAR file in the portal's
0639: // war directory in the portal data dir
0640: ObjectName portalMBeanName = AdminUtil
0641: .getResourceMBeanObjectName(PortalMBean.TYPE,
0642: portalPath);
0643: String[] signtrarr = {};
0644: String[] paramarr = {};
0645: // Invoke the importdesktop method on the
0646: logger.log(Level.INFO, "PSFB_CSPFM1090");
0647: mbs.invoke(portalMBeanName, "createPortalWebApp", paramarr,
0648: signtrarr);
0649:
0650: registerCorePortlets(mbs, portalID);
0651:
0652: // Token substitution of search server url for community portlet
0653: ObjectName pattern = AdminClientUtil
0654: .getSearchServerPattern(AdminClientUtil.DEFAULT_DOMAIN);
0655: Set objects = mbs.queryNames(pattern, new ObjectName(""));
0656: Iterator i = objects.iterator();
0657:
0658: if (i.hasNext()) {
0659: ObjectName on = (ObjectName) i.next();
0660: Object[] params1 = {};
0661: String[] signatures1 = {};
0662: Properties p = (Properties) mbs.invoke(on,
0663: "retrieveVitals", params1, signatures1);
0664: URL searchURL = new URL(p.getProperty("url"));
0665: String surl = searchURL.toString();
0666: if ((surl != null) && (surl != "")) {
0667: surl += "/search";
0668: }
0669: String propFileLoc = cc.getPSDataDir() + fs + "portals"
0670: + fs + portalID + fs + "config" + fs
0671: + "communitymgmnt.properties";
0672: File propFile = new File(propFileLoc);
0673: if (propFile.exists()) {
0674: if (FileUtil.replaceTokenInFile(propFile,
0675: "%SEARCH_SERVER_URL%", surl)) {
0676: logger.log(Level.INFO, "PSFB_CSPFM1091");
0677: } else {
0678: logger.log(Level.INFO, "PSFB_CSPFM1092");
0679: }
0680: } else {
0681: logger.log(Level.INFO, "PSFB_CSPFM1093");
0682: }
0683: } else {
0684: logger.log(Level.INFO, "PSFB_CSPFM1094");
0685: }
0686:
0687: } catch (Exception e) {
0688: if (logger.isLoggable(Level.SEVERE)) {
0689: LogRecord rec = new LogRecord(Level.SEVERE,
0690: "PSFB_CSPFM1025");
0691: rec.setLoggerName(logger.getName());
0692: rec.setParameters(new Object[] { portalID });
0693: rec.setThrown(e);
0694: logger.log(rec);
0695: }
0696: throw new PSMBeanException("admin.error.create.portal",
0697: getStackTrace(e), new Object[] { portalID });
0698: }
0699: }
0700:
0701: public void deletePortal(String portalID) throws PSMBeanException {
0702:
0703: // Get the list of all PortalIDs in the current domain
0704: List allPortals = getPortals();
0705: // If the portalID does not exist in the domain repository quit
0706: if (!allPortals.contains(portalID)) {
0707: logger.log(Level.SEVERE, "PSFB_CSPFM1095", portalID);
0708: throw new PSMBeanException("admin.error.delete.portal",
0709: "Portal " + portalID + " does not exists",
0710: new Object[] { portalID });
0711: } else {
0712: // Get the list of all instances for this portal and delete each
0713: // of the instances
0714: try {
0715: ObjectName pObjName = AdminClientUtil
0716: .getPortalMBeanObjectName(
0717: AdminClientUtil.DEFAULT_DOMAIN,
0718: portalID);
0719: ObjectName instancePat = AdminClientUtil
0720: .getPortalServerInstancesPattern(
0721: AdminClientUtil.DEFAULT_DOMAIN,
0722: portalID);
0723: // Get the MBean server object on the local host
0724: MBeanServer mbs = PASModule.getMBeanServer();
0725: Set instanceObjs = mbs.queryNames(instancePat,
0726: new ObjectName(""));
0727: for (Iterator j = instanceObjs.iterator(); j.hasNext();) {
0728: ObjectName iObj = (ObjectName) j.next();
0729: String instanceId = null;
0730: try {
0731: instanceId = (String) mbs.getAttribute(iObj,
0732: "ID");
0733: Object[] params = { instanceId };
0734: String[] signatures = { "java.lang.String" };
0735: mbs.invoke(pObjName, "deleteInstance", params,
0736: signatures);
0737: } catch (Exception e) {
0738: if (logger.isLoggable(Level.SEVERE)) {
0739: LogRecord rec = new LogRecord(Level.SEVERE,
0740: "PSFB_CSPFM1051");
0741: rec.setLoggerName(logger.getName());
0742: rec
0743: .setParameters(new Object[] { instanceId });
0744: rec.setThrown(e);
0745: logger.log(rec);
0746: }
0747: }
0748: }
0749: } catch (Exception e) {
0750: if (logger.isLoggable(Level.SEVERE)) {
0751: LogRecord rec = new LogRecord(Level.SEVERE,
0752: "PSFB_CSPFM1096");
0753: rec.setLoggerName(logger.getName());
0754: rec.setParameters(new Object[] { portalID });
0755: rec.setThrown(e);
0756: logger.log(rec);
0757: }
0758: }
0759: }
0760:
0761: Portal newPortal = new Portal(cc);
0762:
0763: String amAdminPassword = AdminServerUtil.getPassword();
0764: EnableServices es = new EnableServices(cc, amAdminPassword);
0765:
0766: try {
0767: // Get the SSO Token form PAS
0768: SSOToken ssoToken = AdminServerUtil.getSSOToken();
0769:
0770: logger.log(Level.INFO, "PSFB_CSPFM1097", portalID);
0771: es.unconfigPortalRequests(portalID, cc
0772: .getDefaultOrganization(), cc
0773: .getUserNamingAttribute());
0774: newPortal.unconfigurePortal(portalID, ssoToken);
0775:
0776: // Remove the portal from the portal domain context
0777: pdc.removeResource(PortalMBean.TYPE, AdminUtil
0778: .getChildPath(path, portalID));
0779:
0780: // Remove the one Subscription service per Portal
0781: pdc.removeResource(AdminUtil.PROFILER_MBEAN_TYPE, AdminUtil
0782: .getChildPath(path, portalID));
0783:
0784: // Remove the one Community Manager service per Portal
0785: pdc.removeResource(AdminUtil.COMMUNITYMANAGER_MBEAN_TYPE,
0786: AdminUtil.getChildPath(path, portalID));
0787:
0788: // Reload the mbeans to ensure that the removal is propogated to
0789: // all hosts
0790: PASModule.reloadMBeans(pdc, PortalMBean.TYPE, path);
0791: } catch (ConfigurationException ce) {
0792: logger.log(Level.SEVERE, "PSFB_CSPFM1098", ce);
0793: throw new PSMBeanException(
0794: "admin.error.unconfigure.portal",
0795: getStackTrace(ce), new Object[] { ce.getMessage() });
0796: } catch (Exception e) {
0797: if (logger.isLoggable(Level.SEVERE)) {
0798: LogRecord rec = new LogRecord(Level.SEVERE,
0799: "PSFB_CSPFM1099");
0800: rec.setLoggerName(logger.getName());
0801: rec.setParameters(new Object[] { portalID });
0802: rec.setThrown(e);
0803: logger.log(rec);
0804: }
0805: throw new PSMBeanException("admin.error.delete.portal",
0806: getStackTrace(e), new Object[] { portalID });
0807: }
0808: }
0809:
0810: public void createSearchServer(String searchServerID,
0811: Properties webContainerProperties) throws PSMBeanException {
0812: try {
0813: String host = (String) webContainerProperties.get("Host");
0814: if (!AdminUtil.isLocal(host)) {
0815: JMXConnector jmxc = AdminServerUtil
0816: .getJMXConnector(host);
0817: MBeanServerConnection msc = jmxc
0818: .getMBeanServerConnection();
0819:
0820: LinkedList path = new LinkedList();
0821: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
0822: ObjectName on = AdminClientUtil
0823: .getResourceMBeanObjectName(
0824: AdminClientUtil.PORTAL_DOMAIN_MBEAN_TYPE,
0825: path);
0826:
0827: Object[] params = { searchServerID,
0828: webContainerProperties };
0829: String[] signatures = { "java.lang.String",
0830: "java.util.Properties" };
0831: msc
0832: .invoke(on, "createSearchServer", params,
0833: signatures);
0834: } else {
0835: if (AdminUtil.isOnlySRAInstalled(cc)) {
0836: throw new PSMBeanException(
0837: "error.psadmin.non.sra.validateion.failed");
0838: }
0839:
0840: SearchSetup ss = new SearchSetup();
0841: ss.configuration(cc, searchServerID,
0842: webContainerProperties);
0843: ss.deployment(cc, searchServerID, searchServerID,
0844: webContainerProperties);
0845: Map m = new HashMap();
0846: m.put("Type", getProperty(webContainerProperties,
0847: "WebContainerType"));
0848: m.put("Protocol", getProperty(webContainerProperties,
0849: "Scheme"));
0850: m.put("Host", getProperty(webContainerProperties,
0851: "Host"));
0852: m.put("Port", getProperty(webContainerProperties,
0853: "Port"));
0854: m.put("Domain", getProperty(webContainerProperties,
0855: "WebContainerDomainName"));
0856: m.put("Instance", getProperty(webContainerProperties,
0857: "WebContainerInstanceName"));
0858: m.put("Cell", getProperty(webContainerProperties,
0859: "WebContainerDeployCell"));
0860: m.put("Node", getProperty(webContainerProperties,
0861: "WebContainerDeployNode"));
0862: m.put("ManagedServer", getProperty(
0863: webContainerProperties,
0864: "WebContainerManagedServer"));
0865: m.put("AdministrationProtocol", getProperty(
0866: webContainerProperties,
0867: "WebContainerAdminScheme"));
0868: m.put("AdministrationHost",
0869: getProperty(webContainerProperties,
0870: "WebContainerAdminHost"));
0871: m.put("AdministrationPort",
0872: getProperty(webContainerProperties,
0873: "WebContainerAdminPort"));
0874: m
0875: .put("Administrator", getProperty(
0876: webContainerProperties,
0877: "WebContainerAdminUid"));
0878: m.put("AdministrationPassword", getProperty(
0879: webContainerProperties,
0880: "WebContainerAdminPassword"));
0881: m.put("MasterPassword", getProperty(
0882: webContainerProperties,
0883: "WebContainerMasterPassword"));
0884: m.put("JDKDirectory", getProperty(
0885: webContainerProperties, "WebContainerJDKDir"));
0886: m.put("InstallDirectory", getProperty(
0887: webContainerProperties,
0888: "WebContainerInstallDir"));
0889: m.put("InstanceDirectory", getProperty(
0890: webContainerProperties,
0891: "WebContainerInstanceDir"));
0892: m.put("DocumentRootDirectory", getProperty(
0893: webContainerProperties, "WebContainerDocRoot"));
0894: pdc.createResource(AdminUtil.SEARCHSERVER_MBEAN_TYPE,
0895: path, searchServerID, m);
0896: List childPath = AdminUtil.getChildPath(path,
0897: searchServerID);
0898: pdc.createResource(
0899: AdminUtil.SEARCH_DATABASE_MBEAN_TYPE,
0900: childPath, "database", m);
0901: pdc.createResource(AdminUtil.SEARCH_ROBOT_MBEAN_TYPE,
0902: childPath, "robot", m);
0903: pdc.createResource(
0904: AdminUtil.SEARCH_SITEPROBE_MBEAN_TYPE,
0905: childPath, "siteprobe", m);
0906: pdc.createResource(
0907: AdminUtil.SEARCH_AUTOCLASSIFY_MBEAN_TYPE,
0908: childPath, "autoclassify", m);
0909: pdc.createResource(
0910: AdminUtil.SEARCH_CATEGORY_MBEAN_TYPE,
0911: childPath, "category", m);
0912: PASModule.reloadMBeans(pdc,
0913: AdminUtil.SEARCHSERVER_MBEAN_TYPE, path);
0914: }
0915: } catch (Exception e) {
0916: if (logger.isLoggable(Level.SEVERE)) {
0917: LogRecord lr = new LogRecord(Level.SEVERE,
0918: "PSFB_CSPFM1100");
0919: lr.setLoggerName(logger.getName());
0920: lr.setParameters(new Object[] { searchServerID });
0921: lr.setThrown(e);
0922: logger.log(lr);
0923: }
0924: throw new PSMBeanException("admin.error.create.search", e
0925: .getMessage(), e, new Object[] { searchServerID });
0926: }
0927: }
0928:
0929: public void createSearchServerBackground(String searchServerID,
0930: Properties webContainerProperties) throws PSMBeanException {
0931: try {
0932: String host = (String) webContainerProperties.get("Host");
0933: if (!AdminUtil.isLocal(host)) {
0934: JMXConnector jmxc = AdminServerUtil
0935: .getJMXConnector(host);
0936: MBeanServerConnection msc = jmxc
0937: .getMBeanServerConnection();
0938:
0939: LinkedList path = new LinkedList();
0940: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
0941: ObjectName on = AdminClientUtil
0942: .getResourceMBeanObjectName(
0943: AdminClientUtil.PORTAL_DOMAIN_MBEAN_TYPE,
0944: path);
0945:
0946: Object[] params = { searchServerID,
0947: webContainerProperties };
0948: String[] signatures = { "java.lang.String",
0949: "java.util.Properties" };
0950: msc.invoke(on, "createSearchServerBackground", params,
0951: signatures);
0952: } else {
0953: if (AdminUtil.isOnlySRAInstalled(cc)) {
0954: throw new PSMBeanException(
0955: "error.psadmin.non.sra.validateion.failed");
0956: }
0957:
0958: csst = new CreateSearchServerThread(cc, pdc, path,
0959: searchServerID, webContainerProperties);
0960: csst.start();
0961: }
0962: } catch (Exception e) {
0963: if (logger.isLoggable(Level.SEVERE)) {
0964: LogRecord lr = new LogRecord(Level.SEVERE,
0965: "PSFB_CSPFM1100");
0966: lr.setLoggerName(logger.getName());
0967: lr.setParameters(new Object[] { searchServerID });
0968: lr.setThrown(e);
0969: logger.log(lr);
0970: }
0971: throw new PSMBeanException("admin.error.create.search", e
0972: .getMessage(), e, new Object[] { searchServerID });
0973: }
0974: }
0975:
0976: public Integer retrieveCreateSearchServerStatus()
0977: throws PSMBeanException {
0978: if (csst == null) {
0979: return new Integer(0);
0980: }
0981: if (!csst.isAlive()) {
0982: csst = null;
0983: return new Integer(0);
0984: }
0985: if (csst.status == 0) {
0986: csst = null;
0987: return new Integer(0);
0988: }
0989: return new Integer(csst.status);
0990: }
0991:
0992: public void deleteSearchServer(String searchServerID)
0993: throws PSMBeanException {
0994: boolean isCorrectHost = false;
0995: String correctHost = "";
0996: try {
0997: LinkedList path1 = new LinkedList();
0998: path1.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
0999: path1.addFirst(searchServerID);
1000: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
1001: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path1);
1002: correctHost = (String) PASModule.getMBeanServer()
1003: .getAttribute(on, "Host");
1004: isCorrectHost = AdminUtil.isLocal(correctHost);
1005: } catch (Exception e) {
1006: if (logger.isLoggable(Level.SEVERE)) {
1007: LogRecord lr = new LogRecord(Level.SEVERE,
1008: "PSFB_CSPFM1100");
1009: lr.setLoggerName(logger.getName());
1010: lr.setParameters(new Object[] { searchServerID });
1011: lr.setThrown(e);
1012: logger.log(lr);
1013: }
1014: throw new PSMBeanException("admin.error.delete.search", e
1015: .getMessage(), e, new Object[] { searchServerID });
1016: }
1017: if (!isCorrectHost) {
1018: try {
1019: LinkedList path1 = new LinkedList();
1020: path1.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
1021: ObjectName on = AdminClientUtil
1022: .getResourceMBeanObjectName(
1023: AdminClientUtil.PORTAL_DOMAIN_MBEAN_TYPE,
1024: path1);
1025:
1026: Object[] params = { searchServerID };
1027: String[] signatures = { "java.lang.String" };
1028:
1029: invokeRemoteOperation(correctHost, on,
1030: "deleteSearchServer", params, signatures);
1031: } catch (Exception e) {
1032: if (logger.isLoggable(Level.SEVERE)) {
1033: LogRecord lr = new LogRecord(Level.SEVERE,
1034: "PSFB_CSPFM1100");
1035: lr.setLoggerName(logger.getName());
1036: lr.setParameters(new Object[] { searchServerID });
1037: lr.setThrown(e);
1038: logger.log(lr);
1039: }
1040: throw new PSMBeanException("admin.error.delete.search",
1041: e.getMessage(), e,
1042: new Object[] { searchServerID });
1043: }
1044: } else {
1045: if (AdminUtil.isOnlySRAInstalled(cc)) {
1046: throw new PSMBeanException(
1047: "error.psadmin.non.sra.validateion.failed");
1048: }
1049:
1050: Properties p = new Properties();
1051: try {
1052: List childPath = AdminUtil.getChildPath(path,
1053: searchServerID);
1054: p.setProperty("WebContainerType", pdc
1055: .getAttributeValue(
1056: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1057: childPath, "Type"));
1058: p.setProperty("Scheme", pdc.getAttributeValue(
1059: AdminUtil.SEARCHSERVER_MBEAN_TYPE, childPath,
1060: "Protocol"));
1061: p.setProperty("Host", pdc.getAttributeValue(
1062: AdminUtil.SEARCHSERVER_MBEAN_TYPE, childPath,
1063: "Host"));
1064: p.setProperty("Port", pdc.getAttributeValue(
1065: AdminUtil.SEARCHSERVER_MBEAN_TYPE, childPath,
1066: "Port"));
1067: p.setProperty("WebContainerDomainName", pdc
1068: .getAttributeValue(
1069: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1070: childPath, "Domain"));
1071: p.setProperty("WebContainerInstanceName", pdc
1072: .getAttributeValue(
1073: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1074: childPath, "Instance"));
1075: p.setProperty("WebContainerDeployCell", pdc
1076: .getAttributeValue(
1077: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1078: childPath, "Cell"));
1079: p.setProperty("WebContainerDeployNode", pdc
1080: .getAttributeValue(
1081: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1082: childPath, "Node"));
1083: p.setProperty("WebContainerManagedServer", pdc
1084: .getAttributeValue(
1085: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1086: childPath, "ManagedServer"));
1087: p.setProperty("WebContainerAdminScheme", pdc
1088: .getAttributeValue(
1089: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1090: childPath, "AdministrationProtocol"));
1091: p.setProperty("WebContainerAdminHost", pdc
1092: .getAttributeValue(
1093: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1094: childPath, "AdministrationHost"));
1095: p.setProperty("WebContainerAdminPort", pdc
1096: .getAttributeValue(
1097: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1098: childPath, "AdministrationPort"));
1099: p.setProperty("WebContainerAdminUid", pdc
1100: .getAttributeValue(
1101: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1102: childPath, "Administrator"));
1103: p.setProperty("WebContainerAdminPassword", pdc
1104: .getAttributeValue(
1105: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1106: childPath, "AdministrationPassword"));
1107: p.setProperty("WebContainerMasterPassword", pdc
1108: .getAttributeValue(
1109: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1110: childPath, "MasterPassword"));
1111: p.setProperty("WebContainerJDKDir", pdc
1112: .getAttributeValue(
1113: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1114: childPath, "JDKDirectory"));
1115: p.setProperty("WebContainerInstallDir", pdc
1116: .getAttributeValue(
1117: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1118: childPath, "InstallDirectory"));
1119: p.setProperty("WebContainerInstanceDir", pdc
1120: .getAttributeValue(
1121: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1122: childPath, "InstanceDirectory"));
1123: p.setProperty("WebContainerDocRoot", pdc
1124: .getAttributeValue(
1125: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1126: childPath, "DocumentRootDirectory"));
1127: } catch (Exception e) {
1128: if (logger.isLoggable(Level.SEVERE)) {
1129: LogRecord lr = new LogRecord(Level.SEVERE,
1130: "PSFB_CSPFM1100");
1131: lr.setLoggerName(logger.getName());
1132: lr.setParameters(new Object[] { searchServerID });
1133: lr.setThrown(e);
1134: logger.log(lr);
1135: }
1136: throw new PSMBeanException("admin.error.delete.search",
1137: e.getMessage(), e,
1138: new Object[] { searchServerID });
1139: }
1140:
1141: try {
1142: SearchSetup ss = new SearchSetup();
1143: ss.delete(cc, searchServerID, searchServerID, p);
1144: } catch (Exception e) {
1145: if (logger.isLoggable(Level.SEVERE)) {
1146: LogRecord lr = new LogRecord(Level.SEVERE,
1147: "PSFB_CSPFM1100");
1148: lr.setLoggerName(logger.getName());
1149: lr.setParameters(new Object[] { searchServerID });
1150: lr.setThrown(e);
1151: logger.log(lr);
1152: }
1153: throw new PSMBeanException("admin.error.delete.search",
1154: e.getMessage(), e,
1155: new Object[] { searchServerID });
1156: }
1157:
1158: try {
1159: List childPath = AdminUtil.getChildPath(path,
1160: searchServerID);
1161: pdc.removeResource(AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1162: childPath);
1163: PASModule.reloadMBeans(pdc,
1164: AdminUtil.SEARCHSERVER_MBEAN_TYPE, path);
1165: } catch (Exception e) {
1166: if (logger.isLoggable(Level.SEVERE)) {
1167: LogRecord lr = new LogRecord(Level.SEVERE,
1168: "PSFB_CSPFM1100");
1169: lr.setLoggerName(logger.getName());
1170: lr.setParameters(new Object[] { searchServerID });
1171: lr.setThrown(e);
1172: logger.log(lr);
1173: }
1174: throw new PSMBeanException("admin.error.delete.search",
1175: e.getMessage(), e,
1176: new Object[] { searchServerID });
1177: }
1178: }
1179: }
1180:
1181: public void redeploySearchServerWarfile(String searchServerID)
1182: throws PSMBeanException {
1183: if (AdminUtil.isOnlySRAInstalled(cc)) {
1184: throw new PSMBeanException(
1185: "error.psadmin.non.sra.validateion.failed");
1186: }
1187:
1188: Properties p = new Properties();
1189: try {
1190: List childPath = AdminUtil.getChildPath(path,
1191: searchServerID);
1192: p.setProperty("WebContainerType", pdc.getAttributeValue(
1193: AdminUtil.SEARCHSERVER_MBEAN_TYPE, childPath,
1194: "Type"));
1195: p.setProperty("Scheme", pdc.getAttributeValue(
1196: AdminUtil.SEARCHSERVER_MBEAN_TYPE, childPath,
1197: "Protocol"));
1198: p.setProperty("Host", pdc.getAttributeValue(
1199: AdminUtil.SEARCHSERVER_MBEAN_TYPE, childPath,
1200: "Host"));
1201: p.setProperty("Port", pdc.getAttributeValue(
1202: AdminUtil.SEARCHSERVER_MBEAN_TYPE, childPath,
1203: "Port"));
1204: p.setProperty("WebContainerDomainName", pdc
1205: .getAttributeValue(
1206: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1207: childPath, "Domain"));
1208: p.setProperty("WebContainerInstanceName", pdc
1209: .getAttributeValue(
1210: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1211: childPath, "Instance"));
1212: p.setProperty("WebContainerDeployCell", pdc
1213: .getAttributeValue(
1214: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1215: childPath, "Cell"));
1216: p.setProperty("WebContainerDeployNode", pdc
1217: .getAttributeValue(
1218: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1219: childPath, "Node"));
1220: p.setProperty("WebContainerManagedServer", pdc
1221: .getAttributeValue(
1222: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1223: childPath, "ManagedServer"));
1224: p.setProperty("WebContainerAdminScheme", pdc
1225: .getAttributeValue(
1226: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1227: childPath, "AdministrationProtocol"));
1228: p.setProperty("WebContainerAdminHost", pdc
1229: .getAttributeValue(
1230: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1231: childPath, "AdministrationHost"));
1232: p.setProperty("WebContainerAdminPort", pdc
1233: .getAttributeValue(
1234: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1235: childPath, "AdministrationPort"));
1236: p.setProperty("WebContainerAdminUid", pdc
1237: .getAttributeValue(
1238: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1239: childPath, "Administrator"));
1240: p.setProperty("WebContainerAdminPassword", pdc
1241: .getAttributeValue(
1242: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1243: childPath, "AdministrationPassword"));
1244: p.setProperty("WebContainerMasterPassword", pdc
1245: .getAttributeValue(
1246: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1247: childPath, "MasterPassword"));
1248: p.setProperty("WebContainerJDKDir", pdc.getAttributeValue(
1249: AdminUtil.SEARCHSERVER_MBEAN_TYPE, childPath,
1250: "JDKDirectory"));
1251: p.setProperty("WebContainerInstallDir", pdc
1252: .getAttributeValue(
1253: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1254: childPath, "InstallDirectory"));
1255: p.setProperty("WebContainerInstanceDir", pdc
1256: .getAttributeValue(
1257: AdminUtil.SEARCHSERVER_MBEAN_TYPE,
1258: childPath, "InstanceDirectory"));
1259: p.setProperty("WebContainerDocRoot", pdc.getAttributeValue(
1260: AdminUtil.SEARCHSERVER_MBEAN_TYPE, childPath,
1261: "DocumentRootDirectory"));
1262: } catch (Exception e) {
1263: logger.log(Level.SEVERE,
1264: "Error deleting " + searchServerID, e);
1265: throw new PSMBeanException("admin.error.delete.search", e
1266: .getMessage(), e, new Object[] { searchServerID });
1267: }
1268:
1269: try {
1270: SearchSetup ss = new SearchSetup();
1271: ss.redeployment(cc, searchServerID, searchServerID, p);
1272: } catch (Exception e) {
1273: if (logger.isLoggable(Level.SEVERE)) {
1274: LogRecord lr = new LogRecord(Level.SEVERE,
1275: "PSFB_CSPFM1100");
1276: lr.setLoggerName(logger.getName());
1277: lr.setParameters(new Object[] { searchServerID });
1278: lr.setThrown(e);
1279: logger.log(lr);
1280: }
1281: throw new PSMBeanException("admin.error.redeploy.search", e
1282: .getMessage(), e, new Object[] { searchServerID });
1283: }
1284: }
1285:
1286: public String getPortalVersion(Boolean display, String jarpath,
1287: Boolean patch, Boolean patchVerbose)
1288: throws PSMBeanException {
1289: PortalVersion pv = new PortalVersion(getPSConfigContext());
1290: StringBuffer sb = new StringBuffer(256);
1291: if (display.booleanValue() == true) {
1292: sb.append(pv.getVersion());
1293: sb.append("\n");
1294: }
1295:
1296: if (jarpath != null) {
1297: sb.append(pv.getVersionFromJar(jarpath));
1298: sb.append("\n");
1299: }
1300:
1301: if (patch.booleanValue() == true) {
1302: sb.append(pv.getPatchInfo());
1303: sb.append("\n");
1304: }
1305:
1306: if (patchVerbose.booleanValue() == true) {
1307: sb.append(pv.getPatchVerbose());
1308: sb.append("\n");
1309: }
1310: return sb.toString();
1311: }
1312:
1313: public List getAttribute(Map optionsMap) throws PSMBeanException {
1314: List values = null;
1315: String compName = (String) optionsMap
1316: .get(AttrOptionConstants.OPT_COMPONENT);
1317: logger.log(Level.FINEST, "PSFB_CSPFM1057", compName);
1318:
1319: AttributeHandler handler = AttributeHandlerFactory
1320: .getComponentAttrHandler(compName,
1321: getPSConfigContext(), getDomainID(), null);
1322: handler.validate(null, optionsMap);
1323: values = handler.getAttribute(optionsMap);
1324: return values;
1325: }
1326:
1327: public Map getAttributes(Map optionsMap) throws PSMBeanException {
1328: Map nameValues = null;
1329: String compName = (String) optionsMap
1330: .get(AttrOptionConstants.OPT_COMPONENT);
1331: logger.log(Level.FINEST, "PSFB_CSPFM1058", compName);
1332: AttributeHandler handler = AttributeHandlerFactory
1333: .getComponentAttrHandler(compName,
1334: getPSConfigContext(), getDomainID(), null);
1335: handler.validate(null, optionsMap);
1336: nameValues = handler.getAttributes(optionsMap);
1337: return nameValues;
1338: }
1339:
1340: public void setAttribute(List values, Map optionsMap)
1341: throws PSMBeanException {
1342: String compName = (String) optionsMap
1343: .get(AttrOptionConstants.OPT_COMPONENT);
1344: logger.log(Level.FINEST, "PSFB_CSPFM1059", compName);
1345: AttributeHandler handler = AttributeHandlerFactory
1346: .getComponentAttrHandler(compName,
1347: getPSConfigContext(), getDomainID(), null);
1348: handler.validate(values, optionsMap);
1349: handler.setAttribute(values, optionsMap);
1350: }
1351:
1352: public void setAttributes(Map nameValues, Map optionsMap)
1353: throws PSMBeanException {
1354: String compName = (String) optionsMap
1355: .get(AttrOptionConstants.OPT_COMPONENT);
1356: logger.log(Level.FINEST, "PSFB_CSPFM1060", compName);
1357: AttributeHandler handler = AttributeHandlerFactory
1358: .getComponentAttrHandler(compName,
1359: getPSConfigContext(), getDomainID(), null);
1360: handler.validate(null, optionsMap);
1361: handler.setAttributes(nameValues, optionsMap);
1362: }
1363:
1364: public Map listAttributes(Map optionsMap) throws PSMBeanException {
1365: Map values = null;
1366: String compName = (String) optionsMap
1367: .get(AttrOptionConstants.OPT_COMPONENT);
1368: logger.log(Level.FINEST, "PSFB_CSPFM1061", compName);
1369: AttributeHandler handler = AttributeHandlerFactory
1370: .getComponentAttrHandler(compName,
1371: getPSConfigContext(), getDomainID(), null);
1372: handler.validate(null, optionsMap);
1373: values = handler.listAttributes(optionsMap);
1374: return values;
1375: }
1376:
1377: public void validateWebContainer(Map attributes)
1378: throws PSMBeanException {
1379:
1380: String iHost = (String) attributes.get(InstanceAttributes.HOST);
1381: String iPort = (String) attributes.get(InstanceAttributes.PORT);
1382: logger.log(Level.FINEST, "PSFB_CSPFM1034", iHost);
1383:
1384: try {
1385: // Check if the host in the param is the local host
1386: if (iHost != null && !AdminUtil.isLocal(iHost)) {
1387: // If not connect to the remote host and invoke the create
1388: // portal operation
1389: ObjectName domainObj = AdminUtil
1390: .getPortalDomainMBeanObjectName(getDomainID());
1391: Object[] params = { attributes };
1392: String[] signature = { "java.util.Map" };
1393: invokeRemoteOperation(iHost, domainObj,
1394: "validateWebContainer", params, signature);
1395: return;
1396: }
1397: } catch (Exception e) {
1398: logger.log(Level.SEVERE, "PSFB_CSPFM1101", e);
1399: throw new PSMBeanException("admin.error.validate.instance",
1400: getStackTrace(e), new Object[] { e.getCause()
1401: .getMessage() });
1402: }
1403:
1404: try {
1405: // Get the MBean server object on the local host
1406: MBeanServer mbs = PASModule.getMBeanServer();
1407: ObjectName portalPat = AdminUtil
1408: .getPortalsPattern(AdminClientUtil.DEFAULT_DOMAIN);
1409: Set portalObjs = mbs.queryNames(portalPat, new ObjectName(
1410: ""));
1411: for (Iterator i = portalObjs.iterator(); i.hasNext();) {
1412: ObjectName o = (ObjectName) i.next();
1413: String pId = (String) mbs.getAttribute(o, "ID");
1414: ObjectName instancePat = AdminClientUtil
1415: .getPortalServerInstancesPattern(
1416: AdminClientUtil.DEFAULT_DOMAIN, pId);
1417: Set instanceObjs = mbs.queryNames(instancePat,
1418: new ObjectName(""));
1419: for (Iterator j = instanceObjs.iterator(); j.hasNext();) {
1420: ObjectName iObj = (ObjectName) j.next();
1421: String host = (String) mbs.getAttribute(iObj,
1422: InstanceAttributes.HOST);
1423: String port = (String) mbs.getAttribute(iObj,
1424: InstanceAttributes.PORT);
1425: // For any instance if the host & port are the same as the
1426: // instance thats being created. Throw exception
1427: if (host.equalsIgnoreCase(iHost)
1428: && port.equals(iPort)) {
1429: String msg = "Another Portal Instance Configured on:"
1430: + host + ":" + port;
1431: throw new IllegalArgumentException(msg);
1432: }
1433: }
1434: }
1435:
1436: WebContainer wc = WebContainerFactory.getWebContainer(
1437: attributes, true);
1438: } catch (IllegalArgumentException iae) {
1439: logger.log(Level.SEVERE, "PSFB_CSPFM1102", iae);
1440: Throwable tr = iae.getCause();
1441: if (tr != null) {
1442: throw new PSMBeanException(
1443: "admin.error.validate.instance",
1444: getStackTrace(iae), new Object[] { tr
1445: .getMessage() });
1446: } else {
1447: throw new PSMBeanException(
1448: "admin.error.validate.instance", iae
1449: .getMessage(), new Object[] { iae
1450: .getMessage() });
1451: }
1452: } catch (Exception e) {
1453: logger.log(Level.SEVERE, "PSFB_CSPFM1103", e);
1454: throw new PSMBeanException("admin.error.validate.instance",
1455: getStackTrace(e), new Object[] { e.getCause()
1456: .getMessage() });
1457: }
1458: }
1459:
1460: private String getProperty(Properties p, String key) {
1461: if (p.containsKey(key)) {
1462: return p.getProperty(key);
1463: } else {
1464: return "";
1465: }
1466: }
1467:
1468: protected void loadPortalRewriterRulesSet() throws PSMBeanException {
1469:
1470: String ruleDir = getPSConfigContext().getPSBaseDir() + FS
1471: + "export" + FS + "rewriter_rule";
1472:
1473: String[] ruleXMLPaths = { ruleDir + FS + "GenericRuleSet.xml",
1474: ruleDir + FS + "DefaultRuleSet.xml" };
1475:
1476: // Get the MBean server object on the local host
1477: MBeanServer mbs = PASModule.getMBeanServer();
1478:
1479: for (int i = 0; i < ruleXMLPaths.length; i++) {
1480: loadRewriterRuleSets(mbs, ruleXMLPaths[i]);
1481: }
1482: }
1483:
1484: private void loadRewriterRuleSets(MBeanServerConnection mbs,
1485: String ruleSetXMLPath) throws PSMBeanException {
1486:
1487: ObjectName objName;
1488: String lResult = "";
1489: LinkedList path = new LinkedList();
1490:
1491: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
1492: path.addFirst("rewriter");
1493:
1494: try {
1495: if ((new File(ruleSetXMLPath)).exists()) {
1496: BufferedReader buffReader = new BufferedReader(
1497: new FileReader(ruleSetXMLPath));
1498: StringBuffer sb = new StringBuffer();
1499: char data[] = new char[2048];
1500:
1501: for (int count = 0; (count = buffReader.read(data)) != -1;)
1502: sb.append(data, 0, count);
1503:
1504: buffReader.close();
1505: lResult = sb.toString();
1506: } else {
1507: //String token[] = {lResult};
1508: throw new PSMBeanException(
1509: "admin.error.loadRewriterRuleSets",
1510: ruleSetXMLPath + " file doesn't Exists");
1511: }
1512:
1513: Object[] params = { lResult };
1514: String[] signature = { "java.lang.String" };
1515: objName = AdminClientUtil.getResourceMBeanObjectName(
1516: "PortalDomain.Rewriter", path);
1517: logger.log(Level.INFO, "PSFB_CSPFM1125", ruleSetXMLPath);
1518:
1519: mbs.invoke(objName, "storeRule", params, signature);
1520: logger.log(Level.INFO, "PSFB_CSPFM1126", ruleSetXMLPath);
1521:
1522: } catch (Exception e) {
1523: //If the exception is that ruleset already exists,
1524: //do not rethrow. In case of upgraded portals, multi portal scenarios
1525: //the rulesets may already exist
1526: boolean rulesetExistsException = false;
1527: if (e instanceof MBeanException) {
1528: MBeanException me = (MBeanException) e;
1529: if (me.getTargetException() instanceof PSMBeanException) {
1530: PSMBeanException pme = (PSMBeanException) me
1531: .getTargetException();
1532: if (pme.getErrorKey() == "psadmin.error.rewriter.alreadyexists") {
1533: rulesetExistsException = true;
1534: }
1535: }
1536: }
1537: if (!rulesetExistsException) {
1538: if (logger.isLoggable(Level.SEVERE)) {
1539: LogRecord rec = new LogRecord(Level.SEVERE,
1540: "PSFB_CSPFM1124");
1541: rec.setLoggerName(logger.getName());
1542: rec.setParameters(new String[] { ruleSetXMLPath });
1543: rec.setThrown(e);
1544: logger.log(rec);
1545: }
1546: throw new PSMBeanException(
1547: "admin.error.loadRewriterRuleSets", e
1548: .getMessage(), e,
1549: new Object[] { m_sPsID });
1550: }
1551: }
1552: }
1553: }
|