001: /**
002: * Copyright 2004 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.fabric.config;
013:
014: import java.util.logging.Level;
015: import java.util.logging.Logger;
016:
017: import com.sun.portal.fabric.tasks.ConfigurationException;
018: import com.sun.portal.log.common.PortalLogManager;
019: import com.sun.portal.log.common.PortalLogger;
020: import com.sun.portal.fabric.util.ExecuteUtil;
021: import com.sun.portal.util.Platform;
022:
023: /* This class has code to reset cacao java-flags parameter.
024: Cacao flags are reset only if unconfigure all option is selected in
025: input xml file. */
026: public class ResetCacaoParams {
027:
028: private static final String FS = Platform.fs;
029: private static String logConfigFileOption = "com.sun.portal.log.config.file";
030: private static String ubtVMOption = " -Djava.awt.headless=true ";
031: private static String logProperties = "PSAdminLogConfig.properties";
032: private ExecuteUtil execUtil = null;
033: private String cacaoAdmCmd = null;
034: private static final String CACAO_ADMIN = "cacaoadm";
035: private static final String JAVA_FLAGS = "java-flags";
036: public static final String STATUS = "status";
037: public static final String CACAO_UPTIME = "ptime";
038: private static final String GET_PARAM = "get-param";
039: private static final String SET_PARAM = "set-param";
040: private static final String START = "start";
041: private static final String STOP = "stop";
042: private static Logger logger = null;
043:
044: public ResetCacaoParams() {
045: //Initialise Portal Log Manager
046: new PortalLogManager().init("debug.com.sun.portal.fabric");
047: logger = PortalLogger.getLogger(ResetCacaoParams.class);
048: }
049:
050: public static void main(String[] args) {
051:
052: // Initialize error code to success
053: int exitCode = 1;
054:
055: if (args == null || args.length < 1) {
056: System.err
057: .println("ResetCacaoParams Failed : Missing arguments. Please provide cacao install location.");
058: // Exit current VM with error
059: System.exit(exitCode);
060: }
061:
062: ResetCacaoParams resetCacao = new ResetCacaoParams();
063: System.err.println("Resetting Cacao java-flags... ");
064: resetCacao.cacaoAdmCmd = args[0] + FS + "bin" + FS
065: + CACAO_ADMIN;
066: resetCacao.execUtil = new ExecuteUtil();
067: resetCacao.resetCacaoJavaFlags();
068: System.err.println("Done ");
069: }
070:
071: /** This method checks the value of cacao java-flags param and
072: * clears the java flags which are portal specific.
073: */
074: public void resetCacaoJavaFlags() {
075: try {
076: String javaFlags = execCacaoCommand(GET_PARAM, JAVA_FLAGS,
077: true);
078: String logFileStr = " -D" + logConfigFileOption + "="
079: + "/etc/opt/SUNWportal" + FS + logProperties;
080: javaFlags = javaFlags.replaceFirst(logFileStr, "");
081:
082: javaFlags = javaFlags.replaceFirst(ubtVMOption.trim(), "");
083:
084: String status = execCacaoCommand(STATUS, null, true);
085: if (status.indexOf(CACAO_UPTIME) > 0) {
086: execCacaoCommand(STOP, null, false);
087: }
088: execCacaoCommand(SET_PARAM, javaFlags, false);
089: status = execCacaoCommand(STATUS, null, true);
090: if (status.indexOf(CACAO_UPTIME) == -1) {
091: execCacaoCommand(START, null, false);
092: }
093: } catch (Exception e) {
094: logger.log(Level.SEVERE, "PSFB_CSPFT0204", e);
095: }
096: }
097:
098: /** This method executes cacaoadm commands by calling ExecuteUtil methods.
099: */
100: public String execCacaoCommand(final String sCommandName,
101: final String sParam, final boolean bOutput) {
102:
103: String[] args = (sParam != null) ? new String[] { sCommandName,
104: sParam } : new String[] { sCommandName };
105: execUtil.storeOutput(bOutput);
106: execUtil.exec(cacaoAdmCmd, args);
107: return (bOutput ? execUtil.getOutput() : null);
108: }
109: }
|