001: package com.sun.portal.fabric.upgrade;
002:
003: import com.sun.portal.fabric.util.ExecuteUtil;
004: import com.sun.portal.fabric.util.FileUtil;
005: import com.sun.portal.fabric.tasks.WebContainer;
006: import com.sun.portal.log.common.PortalLogger;
007: import java.util.*;
008: import java.util.logging.*;
009: import java.io.*;
010: import java.net.*;
011:
012: /*
013: * This class is used to rollback an upgraded portal server to its previous version.
014: * This class determines the version of portal server to be rolled back, loads required properties
015: * and calls ant target 'rollback'.
016: * This class was created to fix CR 6373066.
017: */
018: public class PSRollBack {
019: static String fs = File.separator;
020: public static String RESOURCE_DIR = null;
021: private static String PS_BASEDIR = null;
022: private static String IDSAME_ADMIN_PASSWORD = null;
023: private static ExecuteUtil execUtil = null;
024: private static Logger logger = null;
025: private static FileHandler fh = null;
026: private static final String LOGFILE = fs + "var" + fs + "sadm" + fs
027: + "install" + fs + "logs" + fs
028: + "Sun_Java_System_Portal_Server_upgrade.log";
029: private boolean linuxOS = false;
030: private boolean sunOS = false;
031: Properties psRollbackProps;
032: private String PS_CONFIG_DIR;
033: private String PS_VAR_DIR;
034: private String PS_PRODUCT_DIR;
035: private String PS_ETC_DIR;
036: private String PS_70_PRODUCT_DIR = null;
037: private String PS_PRODUCT_DIR_OLD = null;
038: private String PS_70_DATA_DIR = null;
039: private String PS_70_CONFIG_DIR = null;
040: private String PS_DATA_DIR_OLD = null;
041: private String PS_CONFIG_DIR_OLD = null;
042: private File upgradeAntFile;
043: private File upgradePropFile;
044: private String upgradeAntFilePathStr;
045: private String upgradePropFilePathStr;
046: private String rollbackVersion;
047:
048: static {
049: try {
050: logger = PortalLogger.getLogger("PSUpgrade.class");
051: //TODO: Make it OS independent log location.
052: //File psupgradeTmpDir= new File(UpgradeConstants.SOLARIS_TMP_DIR);
053: //psupgradeTmpDir.mkdirs();
054:
055: fh = new FileHandler(LOGFILE, true);
056: fh.setFormatter(new SimpleFormatter());
057:
058: Handler[] logHandlers = logger.getHandlers();
059: for (int i = 0; i < logHandlers.length; i++) {
060: logHandlers[i].close();
061: logger.removeHandler(logHandlers[i]);
062: }
063:
064: logger.setUseParentHandlers(false);
065: logger.addHandler(fh);
066:
067: UpgradeUtils.setLogger(logger);
068: execUtil = new ExecuteUtil();
069: UpgradeUtils.setExecUtil(execUtil);
070: } catch (IOException e) {
071: System.out.println(e);
072: }
073: }
074:
075: /* Main method.
076: */
077: public static void main(String[] args) {
078: PSRollBack ps;
079: String dsRestored = null;
080:
081: dsRestored = UpgradeUtils
082: .readInput("Is the Directory server restore operation succesfully completed? (y/n)");
083: if ((dsRestored != null) && (dsRestored.equalsIgnoreCase("y"))) {
084: ps = new PSRollBack();
085: try {
086: ps.init();
087: ps.rollback();
088: } catch (UpgradeException e) {
089: System.out
090: .println("Error encountered while performing rollback operations.");
091: System.exit(1);
092: }
093: } else {
094: System.out
095: .println("Cannot start rollback operations until directory server is manually restored\n. Please retry after restoring directory server.");
096: System.exit(0);
097: }
098: }
099:
100: /*
101: * This method identifies all the required properties and loads them.
102: */
103: public void init() throws UpgradeException {
104: String sunPortalDir = null;
105: String OSStr = System.getProperty("os.name");
106:
107: linuxOS = (OSStr.indexOf("Linux") != -1) ? true : false;
108: sunOS = (OSStr.indexOf("SunOS") != -1) ? true : false;
109:
110: if (sunOS) {
111: sunPortalDir = "SUNWportal";
112: psRollbackProps = new Properties();
113: try {
114: psRollbackProps.load(new FileInputStream(
115: UpgradeConstants.PS_PKG_INFO_FILE));
116: } catch (Exception e) {
117: psRollbackProps = null;
118: logger.log(Level.SEVERE, "PSFB_CSPFUP0016", e);
119: throw new UpgradeException(
120: "Unable to load Existing Installation properties",
121: e);
122: }
123:
124: PS_ETC_DIR = psRollbackProps.getProperty("ETC_DIR", "/etc");
125: PS_VAR_DIR = psRollbackProps.getProperty("VAR_DIR", "/var");
126: PS_BASEDIR = psRollbackProps.getProperty("BASEDIR");
127: PS_PRODUCT_DIR = psRollbackProps.getProperty("PRODUCT_DIR");
128: PS_PRODUCT_DIR_OLD = PS_BASEDIR + fs + PS_PRODUCT_DIR;
129: PS_70_PRODUCT_DIR = PS_BASEDIR + fs + sunPortalDir;
130: PS_70_DATA_DIR = PS_VAR_DIR + fs + "opt" + fs
131: + sunPortalDir;
132: PS_70_CONFIG_DIR = PS_ETC_DIR + fs + "opt" + fs
133: + sunPortalDir;
134: PS_CONFIG_DIR_OLD = PS_ETC_DIR + fs + "opt" + fs + "SUNWps";
135: PS_DATA_DIR_OLD = PS_VAR_DIR + fs + "opt" + fs + "SUNWps";
136:
137: psRollbackProps.setProperty("PS_PRODUCT_DIR",
138: PS_PRODUCT_DIR);
139: psRollbackProps.setProperty("PS_PRODUCT_DIR_OLD",
140: PS_PRODUCT_DIR_OLD);
141: psRollbackProps.setProperty("PS_70_PRODUCT_DIR",
142: PS_70_PRODUCT_DIR);
143: psRollbackProps.setProperty("PS_70_DATA_DIR",
144: PS_70_DATA_DIR);
145: psRollbackProps.setProperty("PS_70_CONFIG_DIR",
146: PS_70_CONFIG_DIR);
147: psRollbackProps.setProperty("PS_CONFIG_DIR_OLD",
148: PS_CONFIG_DIR_OLD);
149: psRollbackProps.setProperty("PS_DATA_DIR_OLD",
150: PS_DATA_DIR_OLD);
151:
152: rollbackVersion = getPSRollbackVersion(PS_PRODUCT_DIR_OLD
153: + ".bak");
154: RESOURCE_DIR = UpgradeUtils.getResourceDir(rollbackVersion);
155: }
156: }
157:
158: /*
159: * This method calls 'rollback' ant target.
160: */
161: public void rollback() {
162: while (IDSAME_ADMIN_PASSWORD == null
163: || IDSAME_ADMIN_PASSWORD.equals("")) {
164: IDSAME_ADMIN_PASSWORD = UpgradeUtils
165: .readPassword("Please enter the Access Manager Admin password : ");
166: psRollbackProps.setProperty(
167: UpgradeConstants.IDSAME_ADMIN_PASSWORD_STR,
168: IDSAME_ADMIN_PASSWORD);
169: }
170:
171: String deployType = getDeployType(psRollbackProps
172: .getProperty("PS_CONFIG_DIR_OLD")
173: + ".bak");
174: String adminPwd = "";
175: if (deployType.equals("SUNONE") || deployType.equals("SUNONE8")
176: || deployType.equals("WEBLOGIC")) {
177: adminPwd = UpgradeUtils
178: .readPassword("What is the Application Server administration password?");
179: }
180: psRollbackProps.setProperty("APP_SVR_ADMIN_PWD", adminPwd);
181:
182: try {
183: prepareUpgradePropertiesFile();
184: prepareUpgradeAntFile();
185: System.out.println("Starting rollback operations......\n");
186: Vector antTargets = new Vector();
187: Vector files = new Vector();
188: //Add the Ant rollback target.
189: antTargets.add(UpgradeConstants.ROLLBACK);
190: //Add IDSAME_ADMIN_PASSWORD env variable.
191: Vector envp = new Vector();
192: envp
193: .addElement("IDSAME_ADMIN_PASSWORD="
194: + psRollbackProps
195: .getProperty(UpgradeConstants.IDSAME_ADMIN_PASSWORD_STR));
196: UpgradeUtils.execAnt(upgradeAntFilePathStr, antTargets,
197: LOGFILE, upgradePropFilePathStr, envp);
198: System.out.println("Rollback operation successful..");
199: System.out
200: .println("Please restart the server before using portal server.");
201: } catch (UpgradeException e) {
202: e.printStackTrace();
203: System.out.println("Failed to perform rollback operations");
204: System.exit(1);
205: }
206: }
207:
208: private void prepareUpgradeAntFile() throws UpgradeException {
209: try {
210: upgradeAntFile = FileUtil.extractFileFromJar(RESOURCE_DIR
211: + fs + UpgradeConstants.RESOURCE_JAR,
212: "upgrade.xml", false);
213: upgradeAntFilePathStr = upgradeAntFile.getAbsolutePath();
214: } catch (IOException e) {
215: if (logger.isLoggable(Level.SEVERE)) {
216: LogRecord rec = new LogRecord(Level.SEVERE,
217: "PSFB_CSPFUP0039");
218: rec.setLoggerName(logger.getName());
219: rec
220: .setParameters(new Object[] { UpgradeConstants.RESOURCE_JAR });
221: rec.setThrown(e);
222: logger.log(rec);
223: }
224: throw new UpgradeException("Could not fetch ant file from "
225: + UpgradeConstants.RESOURCE_JAR, e);
226: }
227: }
228:
229: private void prepareUpgradePropertiesFile() throws UpgradeException {
230: logger.log(Level.INFO, "PSFB_CSPFUP0037");
231: try {
232: upgradePropFile = FileUtil.extractFileFromJar(RESOURCE_DIR
233: + fs + UpgradeConstants.RESOURCE_JAR,
234: UpgradeConstants.PS_UPGRADE_PROPERTIES_FILE, false);
235: upgradePropFilePathStr = upgradePropFile.getAbsolutePath();
236: psRollbackProps.store(new FileOutputStream(upgradePropFile,
237: true), null);
238: } catch (IOException e) {
239: if (logger.isLoggable(Level.SEVERE)) {
240: LogRecord rec = new LogRecord(Level.SEVERE,
241: "PSFB_CSPFUP0038");
242: rec.setLoggerName(logger.getName());
243: rec
244: .setParameters(new Object[] { UpgradeConstants.RESOURCE_JAR });
245: rec.setThrown(e);
246: logger.log(rec);
247: }
248: throw new UpgradeException(
249: "Could not fetch or store properties file from "
250: + UpgradeConstants.RESOURCE_JAR, e);
251: }
252: }
253:
254: private String getPSRollbackVersion(String psProdDir) {
255: String version = null;
256: String propFile = "PSversion.properties";
257: String versionProperty = "productversion";
258: Properties versionProp = new Properties();
259: try {
260: versionProp.load(new FileInputStream(new File(psProdDir
261: + fs + "lib" + File.separator + propFile)));
262: version = versionProp.getProperty(versionProperty);
263: logger.log(Level.INFO, "PSFB_CSPFUP0117", version);
264: } catch (Exception e) {
265: e.printStackTrace();
266: logger.log(Level.SEVERE, "PSFB_CSPFUP0118", e);
267: }
268: return version;
269: }
270:
271: private String getDeployType(String psConfigDir) {
272: String deployType = null;
273: Properties confProp = new Properties();
274: try {
275: confProp.load(new FileInputStream(new File(psConfigDir + fs
276: + UpgradeConstants.PS_CONFIG_PROPPERTIES_FILE)));
277: deployType = confProp.getProperty("DEPLOY_TYPE");
278: logger.log(Level.INFO, "PSFB_CSPFUP0053", deployType);
279: } catch (Exception e) {
280: e.printStackTrace();
281: logger.log(Level.SEVERE, "PSFB_CSPFUP0055", e);
282: }
283: return deployType;
284: }
285: }
|