Methods Summary |
---|
public void | addOrUpdateSystemPropertyToServer(java.lang.String serverName, org.w3c.dom.NodeList serverList, java.lang.String propertyName, java.lang.String propertyValue, com.sun.enterprise.tools.upgrade.transform.elements.BaseElement bElement)
for(int lh =0; lh < serverList.getLength(); lh++){
if(serverName.equals(((Element)serverList.item(lh)).
getAttribute("name"))){
Element serverElement = (Element)serverList.item(lh);
Element sysProp =
this.getSystemPropertyElement(propertyName,serverElement);
if(sysProp != null){
sysProp.setAttribute("value", propertyValue);
return;
}
if(sysProp == null){
// bElement could be passed as null in case if this property need not be added.
if(bElement != null){
sysProp =
serverElement.getOwnerDocument().
createElement("system-property");
sysProp.setAttribute("name", propertyName);
sysProp.setAttribute("value", propertyValue);
bElement.appendElementToParent(serverElement,sysProp);
}
}
return;
}
}
|
public java.util.ArrayList | buildAppDeploymentParameters(java.lang.String moduleName)
ArrayList appDeploymentParameters = null;
String appEnabledStatus = null;
String appVirtualServers = null;
String sourceConfig = common.getSourceConfigXMLFile();
Document sourceDoc =
this.getDomainDocumentElement(common.getSourceConfigXMLFile());
NodeList appRefList =
sourceDoc.getDocumentElement().getElementsByTagName("application-ref");
for(int i=0; i<appRefList.getLength(); i++) {
Element element = ((Element)appRefList.item(i));
if(null == element) {
} else {
if(element.getAttribute("ref").equals(moduleName)) {
appEnabledStatus = element.getAttribute("enabled");
appVirtualServers = element.getAttribute("virtual-servers");
}
}
}
if(appEnabledStatus != null || appVirtualServers != null) {
appDeploymentParameters = new ArrayList();
}
if(appEnabledStatus != null) {
appDeploymentParameters.add("--enabled=" + appEnabledStatus);
}
if(appVirtualServers != null && !(appVirtualServers.equals(""))) {
appDeploymentParameters.add("--virtualservers");
appDeploymentParameters.add(appVirtualServers);
}
return appDeploymentParameters;
|
public java.lang.String | buildAppDeploymentTarget(java.lang.String moduleName)Builds the web module target.
Returns a string that is the target server for this web module.
It is taken from the source domain.xml file.
Used only for > 8.1/8.2EE domain.xmls
String appTarget = null;
String actualModName = moduleName;
String sourceConfig = common.getSourceConfigXMLFile();
Document sourceDoc =
this.getDomainDocumentElement(common.getSourceConfigXMLFile());
Element sourceDocumentElement = sourceDoc.getDocumentElement();
//Check for the occurence of the instance name in the clusters
NodeList clusters = sourceDocumentElement.getElementsByTagName("clusters");
if(clusters != null) {
Element clustersEle = (Element)clusters.item(0);
if(clustersEle != null) {
NodeList clusterList = clustersEle.getElementsByTagName("cluster");
if(clusterList != null) {
for(int k=0; k<clusterList.getLength(); k++) {
Element cluster = (Element)clusterList.item(k);
String clusterName = cluster.getAttribute("name");
NodeList clusterAppRefs = cluster.getElementsByTagName("application-ref");
for(int j = 0; j<clusterAppRefs.getLength(); j++) {
Element clusterAppRef = (Element) clusterAppRefs.item(j);
String appRef = clusterAppRef.getAttribute("ref");
if(actualModName.equals(appRef)) {
//The target is a cluster name
appTarget = clusterName;
break;
}
}
}
}
}
}
if(appTarget != null) {
return appTarget;
}
NodeList servers = sourceDocumentElement.getElementsByTagName("servers");
if(servers != null) {
Element serversEle = (Element) servers.item(0);
if(serversEle != null) {
NodeList serverList = serversEle.getElementsByTagName("server");
if(serverList != null) {
for(int lh =0; lh < serverList.getLength(); lh++){
Element server = (Element)serverList.item(lh);
String instanceName = server.getAttribute("name");
String configRef = server.getAttribute("config-ref");
//Get application refs for only stand alone servers
if((instanceName + "-config").equals(configRef)) {
NodeList applicationRefList = server.getElementsByTagName("application-ref");
for(int i = 0; i<applicationRefList.getLength(); i++) {
Element applicationRef = (Element) applicationRefList.item(i);
String ref = applicationRef.getAttribute("ref");
if(actualModName.equals(ref)) {
//The target can be a stand alone instance name or the DAS itself.
if(!("server".equals(instanceName))) {
appTarget = instanceName;
break;
}
}
}
}
}
}
}
}
return appTarget;
|
public java.lang.String | buildWebModuleContextRoot(java.lang.String moduleName)
String webModuleContextRoot = null;
String actualModName = moduleName;
if(common.getSourceVersion().equals(UpgradeConstants.VERSION_7X)) {
if(moduleName.lastIndexOf("_1") != -1) {
actualModName = moduleName.substring(0,moduleName.lastIndexOf("_1"));
} else {
actualModName = moduleName;
}
}
String sourceConfig = common.getSourceConfigXMLFile();
Document sourceDoc =
this.getDomainDocumentElement(common.getSourceConfigXMLFile());
NodeList webModuleList =
sourceDoc.getDocumentElement().getElementsByTagName("web-module");
for(int i=0; i<webModuleList.getLength(); i++) {
Element element = ((Element)webModuleList.item(i));
if(null == element) {
} else {
if(element.getAttribute("name").equals(actualModName)) {
webModuleContextRoot = element.getAttribute("context-root");
}
}
}
return webModuleContextRoot;
|
public boolean | checkSourceInputAsDomain()Method to find if the source input is a domain directory.
File domainXML = new File(common.getSourceInstallDir() +
File.separator +
"config" +
File.separator +
"domain.xml");
if(domainXML.isFile()) {
return true;
}
return false;
|
public boolean | checkSourceInputAsDomainRoot(java.lang.String source)Checks if the passed source directory is a domains root directory.
//If source is null, return false
if (source == null) {
return false;
}
File sourceDomain = new File(source);
File biDir = new File(source + File.separator +
UpgradeConstants.AS_BIN_DIRECTORY);
//check for 7.x
if(!biDir.isDirectory() && sourceDomain.isDirectory()) {
//Now check wheather it is a domainRoot
//by checking the existence of domain/server1/config/server.xml file
String [] dirs = sourceDomain.list();
if(dirs.length == 0) {
common.setSourceDomainRootFlag(false);
return false;
}
if(new File(source + File.separator +"backup").exists()) {
common.setSourceDomainRootFlag(true);
return true;
}
// Checking If it contains 8.0 domain
for (int i=0;i<dirs.length;i++) {
File domainXML = new File(source+
File.separator+dirs[i]+
File.separator+"config"+
File.separator+"domain.xml");
if(domainXML.isFile()) {
common.setSourceDomainRootFlag(true);
return true;
}
}
// Checking If it contains 7.0 domain
//if(cmi.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){
// Get any 7.0 domain
String domain = "";
boolean domain70=false;
for (int i=0;i<dirs.length;i++) {
if(!(dirs[i].endsWith("8x")) &&
(new File(source +File.separator+ dirs[i]).isDirectory())&& this.isValid70Domain(source +File.separator+ dirs[i])) {
domain = dirs[i];
domain70 =true;
break;
}
}
if(!domain70)
return false;
File domainDir = new File(source+File.separator+domain);
String [] serverDirs = domainDir.list();
String serverInstanceName ="";
if(serverDirs[0].equals("admin-server"))
serverInstanceName = serverDirs[1];
else
serverInstanceName = serverDirs[0];
File serverXML = new File(source+File.separator+domain+
File.separator+serverInstanceName+
File.separator+"config"+
File.separator+"server.xml");
if(serverXML.isFile())
common.setSourceDomainRootFlag(true);
else
common.setSourceDomainRootFlag(false);
/*}else {
File domainXML = new File(source+File.separator+dirs[0]+File.separator+"config"+File.separator+"domain.xml");
if(domainXML.isFile())
cmi.setSourceDomainRootFlag(true);
else
cmi.setSourceDomainRootFlag(false);
} */
}else {
common.setSourceDomainRootFlag(false);
}
return common.getSourceDomainRootFlag();
|
public static void | copyDirectory(java.io.File sourceDir, java.io.File targetDir)Copies the entire tree to a new location except the symbolic links
Invokes the FileUtils.java to do the same
//FileUtils.copyTree(sourceDir, targetDir, false);
// FileUtils.copyTree doesn't copy empty directories
File [] srcFiles = sourceDir.listFiles();
if (srcFiles != null) {
for(int i=0; i< srcFiles.length; i++) {
File dest = new File(targetDir, srcFiles[i].getName());
if( srcFiles[i].isDirectory() && FileUtils.safeIsRealDirectory(srcFiles[i])) {
if (!dest.exists()) {
dest.mkdirs();
}
copyDirectory(srcFiles[i], dest);
} else {
if (!dest.exists()) {
dest.createNewFile();
}
copyFile(srcFiles[i].getAbsolutePath(), new File(targetDir, srcFiles[i].getName()).getAbsolutePath());
}
}
}
|
public static void | copyFile(java.lang.String source, java.lang.String target)
FileUtils.copy(source, target);
|
public static boolean | deleteDirectory(java.io.File dir)
if(dir.isDirectory()) {
String[] subDirs = dir.list();
for(int i=0; i<subDirs.length; i++) {
boolean success = deleteDirectory(new File(dir, subDirs[i]));
if(!success) {
return false;
}
}
}
//Delete the empty directory
return dir.delete();
|
public static boolean | deleteFile(java.lang.String targetMasterPasswordFile)
File masterPasswordFile = new File(targetMasterPasswordFile);
return masterPasswordFile.delete();
|
public java.lang.String | editionString(java.lang.String versionEditionString)
if(UpgradeConstants.VERSION_AS7X_PE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS80_PE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS81_PE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS82_PE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS90_PE.equals(versionEditionString)) {
return UpgradeConstants.EDITION_PE;
}
if(UpgradeConstants.VERSION_AS7X_SE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS80_SE.equals(versionEditionString)||
UpgradeConstants.VERSION_AS81_SE.equals(versionEditionString)||
UpgradeConstants.VERSION_AS82_SE.equals(versionEditionString)||
UpgradeConstants.VERSION_AS90_SE.equals(versionEditionString)){
return UpgradeConstants.EDITION_SE;
}
if(UpgradeConstants.VERSION_AS7X_EE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS81_EE.equals(versionEditionString)||
UpgradeConstants.VERSION_AS81_EE.equals(versionEditionString)||
UpgradeConstants.VERSION_AS90_EE.equals(versionEditionString)||
UpgradeConstants.VERSION_AS82_EE.equals(versionEditionString)){
return UpgradeConstants.EDITION_EE;
}
return null;
|
public java.util.Hashtable | enlistDomains(java.lang.String domainName, java.lang.String domainRoot)Method to create backup directory if In-Place upgrade is done.
Also to build the domain mapping of the source.
Hashtable domainMapping = new Hashtable();
String domainPath = domainRoot + File.separator + domainName;
String sourceDomainRoot = common.getSourceDomainRoot();
String targetDomainRoot = common.getTargetDomainRoot();
boolean domainRootSame =
new File(sourceDomainRoot).equals(new File(targetDomainRoot));
String profile = getProfileInfoFromSourceInput();
//Inplace Upgrade if domain root is same for source and target.
if(domainRootSame) {
String latestdomain = findLatestDomainDir(sourceDomainRoot,domainName);
String backupDomainVersion = "";
String actualDomainVersion = "garbage";
//Backup directory already exists, get version information
if(latestdomain != null) {
backupDomainVersion =
(new VersionExtracter(latestdomain,common)).getVersion();
String[] directories =
new File(common.getSourceDomainRoot()).list();
String tempDomainName = null;
for(int j =0;j<directories.length;j++) {
if(directories[j].equals("backup") ||
new File(common.getSourceDomainRoot() +
File.separator +
directories[j]).isFile())
continue;
else {
tempDomainName = directories[j];
break;
}
}
actualDomainVersion = (new VersionExtracter(common.getSourceDomainRoot() +
File.separator +
domainName,common)).getVersion();
}
//Create backup of the source domain
//Do only version-version checks since editions will remain same
if(!actualDomainVersion.equals(common.getTargetVersion()) &&
!actualDomainVersion.equals(backupDomainVersion)) {
common.setIsInPlace(true);
String timestamp=""+System.currentTimeMillis();
String newDomainName = domainName+"_"+timestamp;
String backup = common.getTargetDomainRoot() + File.separator +
UpgradeConstants.BACKUP_DIR;
File backupFile = new File(backup);
//delete any existing backup directory and create a new one
try {
deleteDirectory(backupFile);
if(!backupFile.mkdir()) {
throw new SecurityException();
}
} catch(SecurityException se) {
logger.log(Level.SEVERE,
stringManager.getString("upgrade.common.make_directory_failed",
backupFile.getAbsolutePath()));
System.exit(1);
}
//Move the existing domain to backup directory
File domainDir = new File(domainPath);
String sourceDomainPath = backup + File.separator + newDomainName;
//Copy and delete instead of rename because of Windows issue.
try{
copyDirectory(domainDir, new File(sourceDomainPath));
if(!deleteDirectory(domainDir)) {
throw new SecurityException();
}
}catch (Exception e) {
if(e instanceof IOException) {
logger.log(Level.SEVERE,
stringManager.getString("upgrade.common.copy_directory_failed",
domainDir.getAbsolutePath(), sourceDomainPath));
deleteDirectory(backupFile);
System.exit(1);
}
if(e instanceof SecurityException) {
logger.log(Level.WARNING,
stringManager.getString("upgrade.common.delete_backedup_domain_directory_failed",
domainDir.getAbsolutePath()));
System.exit(1);
}
}
//Add to domain mapping, the backed up source
domainMapping.put(domainName,
new DomainInfo(domainName,sourceDomainPath,profile));
common.addDomainName(domainName);
common.setSourceInstallDir(sourceDomainPath);
common.getTargetDomainNameMapping().put(domainName,domainName);
} else {
String latestDomain =
findLatestDomainDir(common.getTargetDomainRoot(),domainName);
domainMapping.put(domainName,
new DomainInfo(domainName,latestDomain,profile));
common.addDomainName(domainName);
common.setSourceInstallDir(latestDomain);
common.getTargetDomainNameMapping().put(domainName,domainName);
}
}
//Side by Side Upgrade when domains root are different
else {
domainMapping.put(domainName,
new DomainInfo(domainName,domainPath,profile));
common.addDomainName(domainName);
common.getTargetDomainNameMapping().put(domainName,domainName);
}
return domainMapping;
|
public java.lang.String | findLatestDomainDir(java.lang.String domainRoot, java.lang.String domainName)
String backupDirPath = domainRoot + File.separator +
UpgradeConstants.BACKUP_DIR;
File backupDir = new File(backupDirPath);
String latestDomainPath = null;
long latestTimestamp = 0;
//If backup directory already exists return the directory name else null
if(backupDir.isDirectory()) {
String [] dirs = backupDir.list();
for(int i=0;i<dirs.length;i++) {
String time = dirs[i].substring(dirs[i].lastIndexOf("_")+1);
if(domainName != null )
if(!(dirs[i].startsWith(domainName)))
continue;
long timestamp = Long.parseLong(time);
if(timestamp > latestTimestamp) {
latestTimestamp = timestamp;
latestDomainPath = backupDirPath + File.separator+dirs[i];
}
}
}
return latestDomainPath;
|
private org.w3c.dom.Element | getConfigElementFromDocumentElement(org.w3c.dom.Element documentElement, java.lang.String lookUpConfigName)
NodeList configEles = documentElement.getElementsByTagName("config");
Element configEle = null;
for(int lh =0; lh < configEles.getLength(); lh++){
String configName = ((Element)configEles.item(lh)).getAttribute("name");
if(configName.equals(lookUpConfigName)){
configEle = (Element)configEles.item(lh);
break;
}
}
return configEle;
|
public org.w3c.dom.Document | getDomainDocumentElement(java.lang.String domainFileName)
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document resultDoc = null;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(
(org.xml.sax.helpers.DefaultHandler)Class.forName
("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance());
resultDoc = builder.parse( new File(domainFileName));
}catch (Exception ex){
logger.log(Level.WARNING,
stringManager.getString(
"upgrade.common.iiop_port_domain_doc"),ex);
}
return resultDoc;
|
private java.lang.String | getIIOPListenerPortForServer(java.lang.String portValue, java.lang.String serverName, org.w3c.dom.Element documentElement)
try{
if(portValue != null){
int portIntValue = Integer.parseInt(portValue);
return String.valueOf(portIntValue);
}
}catch(java.lang.NumberFormatException ne){
// This shows the the portValue is not a string but ${IIOP_LISTENER_PORT}
}
NodeList servers = documentElement.getElementsByTagName("servers");
NodeList serverList =
((Element)servers.item(0)).getElementsByTagName("server");
String portValueFromServer = null;
for(int lh =0; lh < serverList.getLength(); lh++){
if(serverName.equals(((Element)serverList.item(lh)).getAttribute("name"))){
Element serverElement = (Element)serverList.item(lh);
Element sysProp =
getSystemPropertyElement("IIOP_LISTENER_PORT",serverElement);
if(sysProp != null){
return sysProp.getAttribute("value");
}else{
Element configElement =
this.getConfigElementFromDocumentElement(documentElement,
serverElement.getAttribute("config-ref"));
if(configElement != null){
sysProp = getSystemPropertyElement("IIOP_LISTENER_PORT",configElement);
if(sysProp != null)
return sysProp.getAttribute("value");
}
}
}
}
return null;
|
public java.lang.String | getJvmOptionValueFromSourceConfig(java.lang.String optionName)
String sourceConfig = common.getSourceConfigXMLFile();
Document sourceDoc =
this.getDomainDocumentElement(common.getSourceConfigXMLFile());
NodeList serverList = sourceDoc.getElementsByTagName("server");
String serverName = common.getCurrentSourceInstance();
if (serverName == null || serverName == "") {
serverName = "server";
}
String configName = null;
String password = null;
for(int i=0;i<serverList.getLength();i++){
Node serverNode = (Node)serverList.item(i);
NamedNodeMap attributes = serverNode.getAttributes();
String name = (attributes.getNamedItem("name")).getNodeValue();
if(serverName.equals(name)){
configName =
(attributes.getNamedItem("config-ref")).getNodeValue();
}
}
if (configName != null) {
NodeList jvmOptionList =
sourceDoc.getElementsByTagName("jvm-options");
for(int j=0;j<jvmOptionList.getLength();j++) {
Node jvmNode = jvmOptionList.item(j);
String jvmOptions = getTextNodeData((Element)jvmNode);
if (jvmOptions.indexOf(optionName) != -1) {
password = jvmOptions.substring(jvmOptions.indexOf("=")+1, jvmOptions.length());
}
}
} else {
logger.warning(stringManager.
getString("upgrade.common.config_not_found",
configName));
}
return password;
|
public java.lang.String | getProfileInfoFromSourceInput()
String sourceEdition = common.getSourceEdition();
if(UpgradeConstants.EDITION_PE.equals(sourceEdition)) {
return UpgradeConstants.DEVELOPER_PROFILE;
} else if(UpgradeConstants.EDITION_EE.equals(sourceEdition)) {
return UpgradeConstants.ENTERPRISE_PROFILE;
} else {
//Source is SE
return UpgradeConstants.DEVELOPER_PROFILE;
}
|
public java.lang.String | getSourceApplicationRootDir()
String applicationRootDir = "applications";
String applicationRoot = common.getSourceApplicationRoot();
if(applicationRoot != null) {
applicationRoot =
applicationRoot.replaceAll("/", "\\" + File.separator);
String[] aryApplRoot = applicationRoot.split("\\" + File.separator);
int indexApplRoot = (aryApplRoot.length) - 1;
applicationRootDir = aryApplRoot[indexApplRoot];
}
return applicationRootDir;
|
public java.util.List | getStandAloneInstances(java.util.Hashtable domainsMapping)
// This method is called while upgradeing 7.x EE upgrading.
//This compares with servers listed in clusters with domains mapping.
List stdAloneList = new ArrayList();
for(Iterator domIt=domainsMapping.values().iterator(); domIt.hasNext();){
DomainInfo dInfo = (DomainInfo)domIt.next();
for(Iterator instIt =
dInfo.getInstanceNames().iterator(); instIt.hasNext();){
String instName = (String)instIt.next();
if(this.isInstanceInCluster(instName)){
continue;
}
if( !instName.equals("admin-server") ) {
Vector instDInfo = new Vector();
instDInfo.add(instName);
instDInfo.add(dInfo);
stdAloneList.add(instDInfo);
}
}
}
return stdAloneList;
|
public java.util.List | getStandAloneInstancesFromDomainXml()Parses the domain.xml for the server elements
Returns the list of stand alone instances.
Hashtable domainsMapping = common.getDomainMapping();
List stdAloneList = new ArrayList();
for(Iterator domIt = domainsMapping.values().iterator(); domIt.hasNext();) {
DomainInfo dInfo = (DomainInfo) domIt.next();
String domainName = dInfo.getDomainName();
String sourceDomainPath = ((DomainInfo) common.getDomainMapping().get(domainName)).getDomainPath();
String domainXmlFile = sourceDomainPath + File.separator +
"config" + File.separator + "domain.xml";
Document adminServerDoc = getDomainDocumentElement(domainXmlFile);
try {
NodeList servers = adminServerDoc.getDocumentElement().
getElementsByTagName("servers");
NodeList serverList = ((Element)servers.item(0)).
getElementsByTagName("server");
for(int lh =0; lh < serverList.getLength(); lh++){
Element server = (Element)serverList.item(lh);
String instanceName = server.getAttribute("name");
String configRef = server.getAttribute("config-ref");
if((instanceName + "-config").equals(configRef)) {
Vector instDInfo = new Vector();
instDInfo.add(instanceName);
instDInfo.add(dInfo);
stdAloneList.add(instDInfo);
}
}
}catch (Exception ex){
logger.log(Level.WARNING, stringManager.getString("upgrade.common.server_instances_from_XML"),ex);
}
}
return stdAloneList;
|
private org.w3c.dom.Element | getSystemPropertyElement(java.lang.String propertyName, org.w3c.dom.Element parentForSysProp)
NodeList sysProps =
parentForSysProp.getElementsByTagName("system-property");
for(int sh =0; sh < sysProps.getLength(); sh++){
if(propertyName.equals(((Element)sysProps.item(sh)).getAttribute("name"))){
return ((Element)sysProps.item(sh));
}
}
return null;
|
public java.lang.String | getTextNodeData(org.w3c.dom.Element element)
NodeList children = element.getChildNodes();
for(int index=0; index < children.getLength(); index++){
if(children.item(index).getNodeType() == Node.TEXT_NODE){
return children.item(index).getNodeValue();
}
}
return "";
|
public static com.sun.enterprise.tools.upgrade.common.UpgradeUtils | getUpgradeUtils(CommonInfoModel cim)UpgradeUtils constructor
if(upgradeUtils == null) {
upgradeUtils = new UpgradeUtils(cim);
} else {
common = cim;
}
return upgradeUtils;
|
public boolean | isInstanceInCluster(java.lang.String instName)
// This method is a utility method to check for the instnce clustered or not.
List clList = ClustersInfoManager.getClusterInfoManager().getClusterInfoList();
if(clList == null) return false;
for(Iterator clIt = clList.iterator(); clIt.hasNext(); ){
ClusterInfo clInfo = (ClusterInfo)clIt.next();
for(Iterator instIt = clInfo.getClusteredInstanceList().iterator(); instIt.hasNext();){
if(((ClusteredInstance)instIt.next()).getInstanceName().equals(instName)){
return true;
}
}
}
return false;
|
public boolean | isValid70Domain(java.lang.String domainPath)
File domainDir = new File(domainPath);
boolean domain70 = false;
String [] serverDirs = domainDir.list();
String serverInstanceName ="";
if(serverDirs[0].equals("admin-server"))
serverInstanceName = serverDirs[1];
else
serverInstanceName = serverDirs[0];
File serverXML = new File(domainPath+File.separator+
serverInstanceName+File.separator+
"config"+File.separator+"server.xml");
if(serverXML.isFile())
domain70 = true;
else
domain70 = false;
return domain70;
|
public boolean | isValidSourcePath(java.lang.String sourcePath)
// If the directory does not exist throw an error instantly
if(!(new File(sourcePath)).exists()) return false;
File domainXML=null;
// First check if it is regular 7.x install directory.
String as7xInstallFileName = "admingui.ear"; //only exists in 7.x installations
File runtime70Jar = new File(sourcePath+
File.separator+
"lib"+
File.separator+
as7xInstallFileName);
if((runtime70Jar != null) && runtime70Jar.exists()) {
// Its a valid 7.x directory.
return true;
}
// Check if the source path is a domain directory that has config file
domainXML = new File(sourcePath + File.separator + "config" +
File.separator + "domain.xml");
if(domainXML.exists() &&
domainXML.isFile() ){
return true;
}
// if none of the above match then its an invalid directory
return false;
|
public boolean | isValidTargetPath(java.lang.String targetPath)Method to check if the target input is a domains root.
All other inputs are rejected.
// check if this path exists
File targetPathDir = new File(targetPath);
if( !targetPathDir.exists() ) {
return false;
}
// check if this is an existing domain
File domainXML = new File(targetPath + File.separator +
"config" + File.separator +"domain.xml");
if( domainXML.isFile() && domainXML.exists()) {
return false;
}
// else its valid
return true;
|
public void | recover()
List domainList = common.getDomainList();
String sourceDir = common.getSourceDomainRoot();
String targetDir = common.getTargetDomainRoot();
if(domainList != null && sourceDir != null && targetDir != null) {
Iterator itr = domainList.iterator();
while(itr.hasNext()) {
String dname = (String)itr.next();
boolean domainRootSame = new File(sourceDir).equals(new File(targetDir));
if(domainRootSame) {
if(new File(sourceDir + File.separator + "backup").isDirectory()) {
common.setCurrentDomain(dname);
String latestDomainPath = common.findLatestDomainDir(sourceDir);
if(latestDomainPath != null) {
//Copy and delete instead of rename because of Windows issue.
try{
copyDirectory(new File(latestDomainPath),
new File(sourceDir + File.separator + dname));
File backupdir = new File(sourceDir + File.separator + "backup");
if(!deleteDirectory(backupdir)) {
logger.log(Level.WARNING,
stringManager.getString("upgrade.common.delete_directory_failed",
backupdir.getAbsolutePath()));
}
}catch (IOException e) {
logger.log(Level.SEVERE,
stringManager.getString("upgrade.common.copy_directory_failed",
latestDomainPath, sourceDir));
}
}
}
}
}//while loop
}//not null check of domainList
|
private void | saveDocumentToDomainFile(java.lang.String domainFileName, org.w3c.dom.Document resultDoc)
// Use a Transformer for output
try{
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
if (resultDoc.getDoctype() != null){
String systemValue = resultDoc.getDoctype().getSystemId();
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
systemValue);
String pubValue = resultDoc.getDoctype().getPublicId();
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
pubValue);
}
DOMSource source = new DOMSource(resultDoc);
StreamResult result =
new StreamResult(new FileOutputStream(domainFileName));
transformer.transform(source, result);
result.getOutputStream().close();
}catch (Exception ex){
logger.log(Level.WARNING,
stringManager.getString(
"upgrade.common.iiop_port_domain_save_fail"),ex);
}
|
public boolean | switchedIIOPPorts(java.lang.String serverID, java.lang.String portValue, org.w3c.dom.Element documentElement)
Element configEle =
this.getConfigElementFromDocumentElement(documentElement,
"server-config");
NodeList iiopService = configEle.getElementsByTagName("iiop-service");
NodeList iiopListeners =
((Element)iiopService.item(0)).getElementsByTagName("iiop-listener");
Element iiopListener = null;
for(int ii =0; ii < iiopListeners.getLength(); ii++){
if(((Element)iiopListeners.item(ii)).
getAttribute("id").equals("orb-listener-1")){
iiopListener = (Element)iiopListeners.item(ii);
break;
}
}
if(iiopListener != null){
String serverIIOPPort =
this.getIIOPListenerPortForServer(
iiopListener.getAttribute("port"),
"server", documentElement);
if(serverIIOPPort.equals("3700")){
String portValueFromServer =
this.getIIOPListenerPortForServer(portValue,serverID,
documentElement);
if(portValueFromServer != null)
iiopListener.setAttribute("port", portValueFromServer);
return true;
}else{
return false;
}
}
return false;
|
public void | updateClusterList(java.lang.String domainXMLFile, java.lang.String domainName, java.util.List clusterInfoList)Builds the ClusterInfo object and loads the clusters in a list.
The domain.xml is parsed for all clusters.
Values are loaded in ClusterInfo object and clusterInfoList is updated.
//Get the domain.xml document
Document domainDoc = this.getDomainDocumentElement(domainXMLFile);
if(domainDoc != null){
//Get the clusters nodelist
NodeList clusters = domainDoc.getDocumentElement().
getElementsByTagName("clusters");
if(clusters != null){
//Get the cluster elements under clusters element
NodeList clusterList = ((Element)clusters.item(0)).
getElementsByTagName("cluster");
if((clusterList != null) && (clusterList.getLength() >0)){
//Iterate through the cluster elements to get details
for(int lh =0; lh < clusterList.getLength(); lh++){
//Get cluster name
String clName = ((Element)clusterList.item(lh)).
getAttribute("name");
ClusterInfo clInfo = new ClusterInfo();
clInfo.setClusterName(clName);
//Set domain name for this cluster
clInfo.setDomainName(domainName);
//Update the instance list for this cluster
clInfo.updateClusteredInstanceList(domainXMLFile,
domainName, clName, this);
clusterInfoList.add(clInfo);
}
}
}
}
|
public void | updateClusteredInstanceList(java.lang.String domainXMLFile, java.lang.String domainName, java.lang.String clusterName, java.util.List clusteredInstanceList)Builds the ClusteredInstance object for the particular cluster.
The source domain.xml is parsed for cluster and its associated instances.
Values are loaded in the ClusteredInstance object.
DomainInfo dInfo = (DomainInfo)common.getDomainMapping().get(domainName);
String domainPath = dInfo.getDomainPath();
//Get admin username
String userName = common.getAdminUserName();
DomainsProcessor dProcessor = new DomainsProcessor(common);
//Get admin port
String adminPort = dProcessor.getSourceAdminPort(domainPath);
//Get domain.xml document
Document domainDoc = this.getDomainDocumentElement(domainXMLFile);
if(domainDoc != null){
//Get the servers nodelist
NodeList servers = domainDoc.getDocumentElement().
getElementsByTagName("servers");
if(servers != null){
//Get all the server elements under servers element
NodeList serverList = ((Element)servers.item(0)).
getElementsByTagName("server");
if((serverList != null) && (serverList.getLength() >0)){
//Iterate through the server elements to get the attributes
for(int lh =0; lh < serverList.getLength(); lh++){
Element server = (Element) serverList.item(lh);
//Get config-ref attribute
String configRefName = server.getAttribute("config-ref");
//Check if the server instance belongs to a cluster
if((clusterName+"-config").equals(configRefName)) {
//Get server instance name
String instanceName = server.getAttribute("name");
//Get node-agent name
String nodeAgentName = server.getAttribute("node-agent-ref");
//Build clInstance
ClusteredInstance clInstance = new ClusteredInstance(instanceName);
clInstance.setHost(nodeAgentName);
clInstance.setDomain(domainName);
clInstance.setUser(userName);
clInstance.setPort(adminPort);
clusteredInstanceList.add(clInstance);
}
}
}
}
}
|
public void | updateDomainXMLWithIIOPCluster(CommonInfoModel cmnInfo, java.lang.String domainXMLFile, IIOPCluster iiopCluster)
String clusterName = iiopCluster.getClusterName();
List servInstances = iiopCluster.getIIOPServerInstanceList();
boolean domainFileChanged = false;
Document domainDoc = this.getDomainDocumentElement(domainXMLFile);
for(int servIt = 0; servIt < servInstances.size(); servIt++){
List endPoints =
((IIOPServerInstance)servInstances.get(servIt)).getIIOPEndPoints();
String serverName =
((IIOPServerInstance)servInstances.get(servIt)).getName();
for(int endPt = 0; endPt < endPoints.size(); endPt++){
IIOPEndPoint iiopEndPoint = (IIOPEndPoint)endPoints.get(endPt);
// just use only one endpoint and transfer the port no.
if(domainDoc != null){
String propertyName = "IIOP_LISTENER_PORT";
String propValue = iiopEndPoint.getPort();
NodeList servers =
domainDoc.getDocumentElement().
getElementsByTagName("servers");
NodeList serverList =
((Element)servers.item(0)).
getElementsByTagName("server");
if(propValue.equals("3700")){
this.switchedIIOPPorts(serverName,
null, domainDoc.getDocumentElement());
}
// Passing baseElement as null. "IIOP_LISTENER_PORT" should definitely exist. Ssome times the create-instance does not add it.
// This base element is only a structural reference to invoke appendChild method.
BaseElement baseElement = null;
try{
baseElement =
com.sun.enterprise.tools.upgrade.transform.ElementToObjectMapper.getMapper().getElementObject(domainDoc.getDocumentElement().getTagName());
}catch(Exception ef){
}
this.addOrUpdateSystemPropertyToServer(serverName,
serverList, propertyName, propValue, baseElement);
domainFileChanged = true;
}
break;
}
}
if(domainFileChanged && (domainDoc != null)){
this.saveDocumentToDomainFile(domainXMLFile, domainDoc);
}
|
public void | updateDomainXMLWithPersistenceStoreProps(java.util.Properties props)
// TODO
// Read each property and add it to appropriate place in domain.xml
// Yet to hear back from Larry white.
|
public void | updateListenerPortsForClusteredInstances(org.w3c.dom.Element docElement, java.lang.String propertyName, java.lang.String portValue, com.sun.enterprise.tools.upgrade.transform.elements.BaseElement bElement)
NodeList servers = docElement.getElementsByTagName("servers");
NodeList serverList =
((Element)servers.item(0)).getElementsByTagName("server");
String clusterName = this.common.getCurrentCluster();
for(java.util.Iterator dItr =
ClustersInfoManager.getClusterInfoManager().getClusterInfoList().iterator(); dItr.hasNext();){
ClusterInfo cInfo = (ClusterInfo)dItr.next();
if(cInfo.getClusterName().equals(clusterName)){
for(java.util.Iterator clItr =
cInfo.getClusteredInstanceList().iterator();
clItr.hasNext();){
ClusteredInstance clInstance = (ClusteredInstance)clItr.next();
if(portValue == null){
this.addOrUpdateSystemPropertyToServer(
clInstance.getInstanceName(),
serverList, propertyName,
clInstance.getInstancePort(),bElement);
}else{
this.addOrUpdateSystemPropertyToServer(
clInstance.getInstanceName(),
serverList, propertyName, portValue,bElement);
}
}
}
}
|
public boolean | validateUserDetails(java.lang.String adminUserName, java.lang.String adminPassword, java.lang.String masterPassword)Method to validate the admin credentials and
master password (if any provided)
try{
//RepositoryManager.validateAdminUserAndPassword method cannot validate credentials for 8.0 because of
//changes in domain.xml and the file in which the credentials were stored has changed from keyfile
// to adminkeyfile. Hence return true in this case without validating passwords.
if(UpgradeConstants.VERSION_AS80_PE.equals(common.getSourceVersionAndEdition()))
return true;
com.sun.enterprise.admin.servermgmt.RepositoryManager rManager =
new com.sun.enterprise.admin.servermgmt.RepositoryManager();
String domainName = "domain1";
String newDomainName = null;
String newDomainPath = null;
List domainList = common.getDomainList();
Iterator itr = domainList.iterator();
Hashtable domainMapping = common.getDomainMapping();
String domainPath = null;
String sourceInstallDir = common.getSourceInstallDir();
String targetInstallDir = common.getTargetInstallDir();
while(itr.hasNext()) {
domainName = (String)itr.next();
}
if(domainMapping != null) {
domainPath = ((DomainInfo) domainMapping.get(domainName)).getDomainPath();
}
//Added for SBS upgrade invoked from installer, where this method
//is called before source directory is input
if(sourceInstallDir == null) {
return true;
}
if(domainPath != null) {
newDomainName = domainPath.substring(domainPath.lastIndexOf(File.separator)+1);
newDomainPath = domainPath.substring(0, domainPath.lastIndexOf(File.separator));
}
com.sun.enterprise.admin.servermgmt.RepositoryConfig repConf =
new com.sun.enterprise.admin.servermgmt.RepositoryConfig(
newDomainName, newDomainPath);
rManager.validateAdminUserAndPassword(repConf,
adminUserName,adminPassword);
if(masterPassword != null)
rManager.validateMasterPassword(repConf,masterPassword);
}catch(com.sun.enterprise.admin.servermgmt.RepositoryException re){
logger.log(Level.SEVERE,
stringManager.getString("enterprise.tools.upgrade.generalException",
re.getMessage()), re);
return false;
}
return true;
|
public java.lang.String | versionString(java.lang.String versionEditionString)
if(UpgradeConstants.VERSION_AS7X_PE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS7X_SE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS7X_EE.equals(versionEditionString)){
return UpgradeConstants.VERSION_7X;
}
if(UpgradeConstants.VERSION_AS80_PE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS80_SE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS80_EE.equals(versionEditionString)){
return UpgradeConstants.VERSION_80;
}
if(UpgradeConstants.VERSION_AS81_PE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS81_EE.equals(versionEditionString)){
return UpgradeConstants.VERSION_81;
}
if(UpgradeConstants.VERSION_AS90_PE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS90_SE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS90_EE.equals(versionEditionString)){
return UpgradeConstants.VERSION_90;
}
if(UpgradeConstants.VERSION_91.equals(versionEditionString)) {
return UpgradeConstants.VERSION_91;
}
if(UpgradeConstants.VERSION_AS82_PE.equals(versionEditionString)||
UpgradeConstants.VERSION_AS82_SE.equals(versionEditionString) ||
UpgradeConstants.VERSION_AS82_EE.equals(versionEditionString)){
return UpgradeConstants.VERSION_82;
}
return null;
|