InplaceDomainUpgradeHandlerpublic final class InplaceDomainUpgradeHandler extends Object A class that determines behavior of invoking the In-place upgrade for a given
domain. It revolves around the com.sun.appserv.server.util.Version class and
information returned from there. It matches the information that is returned
by the current version and the expected System ID for the domain.xml.
Whenever a mismatch occurs, an in-place upgrade results.
It is also assumed that in-place upgrade will not be invoked for
the update releases because the DTD version won't change across them. Thus, a
domain created with version 9.1 should work without in-place upgrade using
application server binary version 9.1_01, 9.1_02 etc. The most important thing
to note is that the Version information denotes the binary version
of the application server installation and DTD's System ID denotes
the application server binaries that initially created the domain. |
Fields Summary |
---|
private final String | versionKeyThe key representing current version of the software binaries | private final File | domainXmlFileThe File representing domain.xml | private final File | domainConfigFolderThe File representing domain's config folder | private final File | requiredUpgradedToFileThe File whose status determines if upgrade is needed | private final com.sun.enterprise.admin.servermgmt.DomainConfig | dc | private static final com.sun.enterprise.util.i18n.StringManager | lsm | private String | mSystemId | private static final String | FILE_PREFIX | private static final Map | VERSION_DTD_SYS_ID_MAP | private static final String | ONEO | private static final String | ONE1 | private static final String | ONE2 | private static final String | ONE3 |
Constructors Summary |
---|
public InplaceDomainUpgradeHandler(com.sun.enterprise.admin.servermgmt.DomainConfig dc)
VERSION_DTD_SYS_ID_MAP.put("80", "http://www.sun.com/software/appserver/dtds/" + ONEO);
VERSION_DTD_SYS_ID_MAP.put("81", "http://www.sun.com/software/appserver/dtds/" + ONE1);
VERSION_DTD_SYS_ID_MAP.put("82", "http://www.sun.com/software/appserver/dtds/" + ONE1);
VERSION_DTD_SYS_ID_MAP.put("90", "http://www.sun.com/software/appserver/dtds/" + ONE2);
VERSION_DTD_SYS_ID_MAP.put("91", "http://www.sun.com/software/appserver/dtds/" + ONE3);
if (dc == null)
throw new IllegalArgumentException ("null arguments");
this.dc = dc;
this.domainXmlFile = new PEFileLayout(dc).getDomainConfigFile();
if (! domainXmlFile.exists() || ! domainXmlFile.canRead()) {
final String msg = lsm.getString("InplaceUpgradeDomainNotReadable", dc.getDomainName(), dc.getDomainRoot());
throw new IllegalArgumentException(msg);
}
this.domainConfigFolder = domainXmlFile.getParentFile();
this.versionKey = Version.getMajorVersion() + Version.getMinorVersion();
this.requiredUpgradedToFile = new File(domainConfigFolder, FILE_PREFIX + versionKey);
/* The way the build is set up, the following holds:
* Release Major Version Minor Version versionKey
* 8.0 PE/EE 8 0 80
* 8.0 UR1 PE/EE 8 0_01 8001
* 8.1 PE/EE 8 1 81
* 8.1 UR2 PE/EE 8 1_02 8102
* 8.2 PE/EE 8 2 82
* 9.0 PE 9 0 90
* 9.1 9 1 91
*/
|
Methods Summary |
---|
private java.lang.String | getSystemIdFromDtd()
//Use Streaming XML parser, returns null in case of parsing error
BufferedInputStream bis = null;
try {
bis = new BufferedInputStream(new FileInputStream(domainXmlFile));
final XMLReader xr = XMLReaderFactory.createXMLReader();
final InputSource is = new InputSource(bis);
xr.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(final String pid, final String sid)
throws SAXException, IOException {
if (sid != null) {
mSystemId = sid.trim();
final String dtdName = sid.substring(sid.lastIndexOf("/"));
final File dtdFile = new File(new PEFileLayout(dc).getDtdsDir(), dtdName);
if (dtdFile.exists()) {
return new InputSource(new BufferedInputStream(new FileInputStream(dtdFile)));
} //else default resolution
} //else default resolution
return ( null );
}
});
xr.parse(is);
return ( mSystemId );
} catch (final Exception ioe) {
throw new RuntimeException(ioe);
} finally {
try {
if (bis != null)
bis.close();
} catch(Exception ee) {
//squelching ee on purpose
}
}
| private java.lang.String | getSystemIdFromMap()
String id = "";
//this is where the assumption holds -- for update release, the upgrade is not needed
for (final String key : VERSION_DTD_SYS_ID_MAP.keySet()) {
if (key.startsWith(versionKey)) {
id = VERSION_DTD_SYS_ID_MAP.get(key);
}
}
// if there is no such key, return an empty string -- this mostly means something's wrong
return ( id );
| boolean | needsUpgrade()
boolean needed = false;
if (!this.requiredUpgradedToFile.exists()) {
final String fromDtd = getSystemIdFromDtd();
final String fromMap = getSystemIdFromMap();
if (!fromMap.equals(fromDtd)) {
needed = true;
final String msg = lsm.getString("InplaceUpgradeNeeded",
dc.getDomainName(), fromDtd, fromMap);
CLILogger.getInstance().printMessage(msg);
}
else { //the system ids do match and no upgrade is necessary
final String msg = lsm.getString("InplaceUpgradeNotNeededDtdsMatch",
fromDtd);
CLILogger.getInstance().printDebugMessage(msg);
}
} else { //upgrade is already taken care of, for this release
final String msg = lsm.getString("InplaceUpgradeAlreadyDone",
requiredUpgradedToFile.getName());
CLILogger.getInstance().printDebugMessage(msg);
}
return ( needed );
| void | touchUpgradedToFile()
this.requiredUpgradedToFile.createNewFile();
|
|