1 23 24 29 30 package com.sun.enterprise.tools.upgrade.common; 31 32 36 import java.io.*; 37 import java.util.*; 38 import java.util.logging.*; 39 import com.sun.enterprise.tools.upgrade.logging.*; 40 import com.sun.enterprise.util.i18n.StringManager; 41 import com.sun.enterprise.tools.upgrade.cluster.*; 42 43 import org.w3c.dom.Document ; 44 import org.w3c.dom.Element ; 45 import org.w3c.dom.NodeList ; 46 import org.w3c.dom.Node ; 47 import org.w3c.dom.NamedNodeMap ; 48 49 import javax.xml.parsers.DocumentBuilder ; 50 import javax.xml.parsers.DocumentBuilderFactory ; 51 import javax.xml.parsers.FactoryConfigurationError ; 52 import javax.xml.parsers.ParserConfigurationException ; 53 54 import javax.xml.transform.Transformer ; 55 import javax.xml.transform.TransformerFactory ; 56 import javax.xml.transform.TransformerException ; 57 import javax.xml.transform.TransformerConfigurationException ; 58 59 import javax.xml.transform.dom.DOMSource ; 60 import javax.xml.transform.stream.StreamResult ; 61 import javax.xml.transform.OutputKeys ; 62 63 import com.sun.enterprise.tools.upgrade.transform.elements.BaseElement; 64 import sun.java2d.pipe.AATextRenderer; 65 66 public class UpgradeUtils { 67 private static UpgradeUtils upgradeUtils; 68 private StringManager stringManager = StringManager.getManager(LogService.UPGRADE_LOGGER); 69 private static Logger logger=LogService.getLogger(LogService.UPGRADE_LOGGER); 70 71 private static CommonInfoModel common; 72 private UpgradeUtils(CommonInfoModel common) { 73 this.common = common; 74 } 75 public static UpgradeUtils getUpgradeUtils(CommonInfoModel cim){ 76 if(upgradeUtils == null) { 78 upgradeUtils = new UpgradeUtils(cim); 79 } else { 80 common = cim; 81 } 82 return upgradeUtils; 84 } 85 public Hashtable enlist70DomainsFromSource(CommonInfoModel cmi){ 86 String source = cmi.getSourceInstallDir(); 87 Hashtable domainMapping = null; 88 if(!checkSourceInputAsDomainRoot(source,cmi)) { 89 cmi.getDomainList().clear(); 90 Appserver70DomainNamesResolver as =new Appserver70DomainNamesResolver(source); 91 domainMapping = as.getDomainNamesPathMapping(); 92 cmi.setInstallConfig70(as.getConfigDir70(source)); 93 cmi.setDomainMapping(domainMapping); 94 Enumeration ee = domainMapping.keys(); 95 while (ee.hasMoreElements()) { 96 String domain = (String )ee.nextElement(); 97 cmi.addDomainName(domain); 98 cmi.getTargetDomainNameMapping().put(domain,domain); 99 } 100 } else { File sourceDomain = new File(source); 102 String [] dirs = sourceDomain.list(); 103 108 String domain = ""; 109 domainMapping = new Hashtable(); 110 for (int i=0;i<dirs.length;i++) { 111 String domainPath=source + File.separator + dirs[i]; 112 File file = new File(domainPath); 113 if(!(dirs[i].endsWith("8x")) && !(file.isFile()) && isValid70Domain(domainPath)) { 114 domain=dirs[i]; 115 domainMapping.put(domain,new DomainInfo(domain,domainPath)); 116 cmi.addDomainName(domain); 117 if(new File(cmi.getSourceDomainRoot()).equals(new File(cmi.getTargetDomainRoot()))) 118 cmi.getTargetDomainNameMapping().put(domain,domain+"_8x"); 119 else 120 cmi.getTargetDomainNameMapping().put(domain,domain); 121 } 122 } 123 } 124 System.setProperty("com.sun.aas.configRoot", cmi.getTargetInstallDir() + File.separator + "config"); 125 return domainMapping; 126 } 127 public Hashtable enlistDomainsFromDomainsDirectory(CommonInfoModel cmi, String domainsDirStr){ 128 File domainsDir = new File(domainsDirStr); 129 String [] dirs = domainsDir.list(); 130 return enlistDomains(cmi,dirs, domainsDirStr); 131 } 132 133 public Hashtable enlistDomains(CommonInfoModel cmi, String [] dirs, String domainRoot) { 134 Hashtable domainMapping = new Hashtable(); 135 boolean domainRootSame = new File(cmi.getSourceDomainRoot()).equals(new File(cmi.getTargetDomainRoot())); 136 for (int i=0;i<dirs.length;i++) { 137 if(dirs[i].equals("backup")) 138 continue; 139 String domainPath=domainRoot + File.separator + dirs[i]; 140 if(new File(domainPath+"_8x").exists()) 141 continue; 142 File domainFile = new File(domainPath); 143 if(domainFile.isFile()) 144 continue; 145 if(domainRootSame) { 146 String latestdomain = findLatestDomainDir(cmi.getSourceDomainRoot(),dirs[i]); 148 String backupDomainVersion = ""; 149 String actualDomainVersion = "garbage"; 150 if(latestdomain != null) { 151 backupDomainVersion = (new VersionExtracter(latestdomain,cmi)).getVersion(); 152 String [] directories = new File(cmi.getSourceDomainRoot()).list(); 153 String domainName = null; 154 for(int j =0;j<directories.length;j++) { 155 if(directories[j].equals("backup") || new File(cmi.getSourceDomainRoot() + File.separator + directories[j]).isFile()) 156 continue; 157 else { 158 domainName = directories[j]; 159 break; 160 } 161 } 162 actualDomainVersion = (new VersionExtracter(cmi.getSourceDomainRoot() + File.separator + dirs[i],cmi)).getVersion(); 164 } 165 if(!actualDomainVersion.equals(cmi.getTargetVersionAndEdition()) && !actualDomainVersion.equals(backupDomainVersion)) { 166 String timestamp=""+System.currentTimeMillis(); 167 String newDomainName = ""; 168 String domainName = dirs[i]; 169 if(dirs[i].endsWith("_8x")) { 170 newDomainName = dirs[i].substring(0,dirs[i].indexOf("_8x"))+"_"+timestamp; 171 domainName = dirs[i].substring(0,dirs[i].indexOf("_8x")); 172 } else { 173 newDomainName = domainName+"_"+timestamp; 174 } 175 String backup = cmi.getTargetDomainRoot()+File.separator+"backup"; 176 File backupFile = new File(backup); 177 if(!(backupFile.isDirectory())) { 178 backupFile.delete(); 179 backupFile.mkdir(); 180 } 181 File domainDir = new File(domainPath); 182 String sourceDomainPath = backup+File.separator+newDomainName; 183 if(new File(domainPath+"_8x").exists()) { 185 new File(domainPath+"_8x").renameTo(new File(sourceDomainPath)); 186 domainDir.delete(); 187 } else 188 domainDir.renameTo(new File(sourceDomainPath)); 189 domainMapping.put(domainName,new DomainInfo(domainName,sourceDomainPath)); 190 cmi.addDomainName(domainName); 191 cmi.getTargetDomainNameMapping().put(domainName,domainName); 192 } else { 193 String latestDomain = findLatestDomainDir(cmi.getTargetDomainRoot(),dirs[i]); 194 domainMapping.put(dirs[i],new DomainInfo(dirs[i],latestDomain)); 195 cmi.addDomainName(dirs[i]); 196 cmi.getTargetDomainNameMapping().put(dirs[i],dirs[i]); 197 } 198 } else { 199 domainMapping.put(dirs[i],new DomainInfo(dirs[i],domainPath)); 200 cmi.addDomainName(dirs[i]); 201 cmi.getTargetDomainNameMapping().put(dirs[i],dirs[i]); 202 206 } 207 } 208 return domainMapping; 209 } 210 public Hashtable enlistDomainsFromUserDefinedDirectories(List srcDomainDirs){ 211 Hashtable domainMapping = null; 212 for(Iterator dIt = srcDomainDirs.iterator(); dIt.hasNext();){ 213 if(domainMapping == null) domainMapping = new Hashtable(); 214 String domainDirStr = (String )dIt.next(); 215 Hashtable dMaps = this.enlistDomainsFromDomainsDirectory(this.common, domainDirStr); 216 if(dMaps != null){ 217 for(Enumeration domainsEnum = dMaps.keys();domainsEnum.hasMoreElements();){ 218 String dName = (String )domainsEnum.nextElement(); 219 domainMapping.put(dName, dMaps.get(dName)); 220 } 221 } 222 } 223 return domainMapping; 224 } 225 public String findLatestDomainDir(String domainRoot,String domainName) { 226 File backupDir = new File(domainRoot+File.separator+"backup"); 227 String lastestDomainPath=null; 228 long latestTimestamp = 0; 229 if(backupDir.isDirectory()) { 230 String [] dirs = backupDir.list(); 231 for(int i=0;i<dirs.length;i++) { 232 String time = dirs[i].substring(dirs[i].lastIndexOf("_")+1); 233 if(domainName != null ) 234 if(!(dirs[i].startsWith(domainName))) 235 continue; 236 long timestamp = Long.parseLong(time); 237 if(timestamp > latestTimestamp) { 238 latestTimestamp = timestamp; 239 lastestDomainPath = domainRoot+File.separator+"backup"+File.separator+dirs[i]; 240 } 241 } 242 } 243 return lastestDomainPath; 244 } 245 246 public boolean checkSourceInputAsDomain(){ 247 File domainXML = new File(common.getSourceInstallDir() + File.separator + "config" + File.separator + "domain.xml"); 250 if(domainXML.isFile()) { 251 return true; 252 } 253 return false; 254 } 255 256 public boolean checkSourceInputAsDomainRoot(String source, CommonInfoModel cmi) { 257 if (source == null) { 258 return false; 259 } 260 File sourceDomain = new File(source); 261 File biDir = new File(source+File.separator+"bin"); 262 if(!biDir.isDirectory() && sourceDomain.isDirectory()) { 265 String [] dirs = sourceDomain.list(); 268 if(dirs.length == 0) { 270 cmi.setSourceDomainRootFlag(false); 271 return false; 272 } 273 274 if(new File(source + File.separator +"backup").exists()) { 275 cmi.setSourceDomainRootFlag(true); 276 return true; 277 } 278 for (int i=0;i<dirs.length;i++) { 280 File domainXML = new File(source+File.separator+dirs[i]+File.separator+"config"+File.separator+"domain.xml"); 281 if(domainXML.isFile()) { 282 cmi.setSourceDomainRootFlag(true); 283 return true; 284 } 285 } 286 287 String domain = ""; 291 boolean domain70=false; 292 for (int i=0;i<dirs.length;i++) { 293 if(!(dirs[i].endsWith("8x")) && (new File(source +File.separator+ dirs[i]).isDirectory()) && this.isValid70Domain(source + File.separator + dirs[i])) { 294 domain = dirs[i]; 295 domain70 =true; 296 break; 297 } 298 } 299 if(!domain70) 300 return false; 301 File domainDir = new File(source+File.separator+domain); 302 String [] serverDirs = domainDir.list(); 303 String serverInstanceName =""; 304 if(serverDirs[0].equals("admin-server")) 305 serverInstanceName = serverDirs[1]; 306 else 307 serverInstanceName = serverDirs[0]; 308 File serverXML = new File(source+File.separator+domain+File.separator+serverInstanceName+File.separator+"config"+File.separator+"server.xml"); 309 if(serverXML.isFile()) 310 cmi.setSourceDomainRootFlag(true); 311 else 312 cmi.setSourceDomainRootFlag(false); 313 320 321 }else { 322 cmi.setSourceDomainRootFlag(false); 323 } 324 return cmi.getSourceDomainRootFlag(); 325 } 326 public boolean isValid70Domain(String domainPath) { 327 File domainDir = new File(domainPath); 328 boolean domain70 = false; 329 String [] serverDirs = domainDir.list(); 330 String serverInstanceName =""; 331 if(serverDirs[0].equals("admin-server")) 332 serverInstanceName = serverDirs[1]; 333 else 334 serverInstanceName = serverDirs[0]; 335 File serverXML = new File(domainPath+File.separator+serverInstanceName+File.separator+"config"+File.separator+"server.xml"); 336 if(serverXML.isFile()) 337 domain70 = true; 338 else 339 domain70 = false; 340 return domain70; 341 } 342 343 public boolean isDomain(String domainPath) { 345 File domainXML = new File(domainPath+File.separator+ 346 "config"+File.separator+ 347 "domain.xml"); 348 if(domainXML.exists()) { 349 return true; 350 } else { 351 return false; 352 } 353 354 } 355 public String versionString(String versionEditionString){ 356 if(UpgradeConstants.VERSION_AS7X_PE.equals(versionEditionString) || 357 UpgradeConstants.VERSION_AS7X_SE.equals(versionEditionString) || 358 UpgradeConstants.VERSION_AS7X_EE.equals(versionEditionString)){ 359 return UpgradeConstants.VERSION_7X; 360 } 361 if(UpgradeConstants.VERSION_AS80_PE.equals(versionEditionString) || 362 UpgradeConstants.VERSION_AS80_SE.equals(versionEditionString) || 363 UpgradeConstants.VERSION_AS81_EE.equals(versionEditionString)){ 364 return UpgradeConstants.VERSION_80; 365 } 366 if(UpgradeConstants.VERSION_AS81_PE.equals(versionEditionString) || 367 UpgradeConstants.VERSION_AS81_EE.equals(versionEditionString)){ 368 return UpgradeConstants.VERSION_81; 369 } 370 if(UpgradeConstants.VERSION_AS90_PE.equals(versionEditionString) || 371 UpgradeConstants.VERSION_AS90_SE.equals(versionEditionString) || 372 UpgradeConstants.VERSION_AS90_EE.equals(versionEditionString)){ 373 return UpgradeConstants.VERSION_90; 374 } 375 return ""; 376 } 377 public String editionString(String versionEditionString){ 378 if(UpgradeConstants.VERSION_AS7X_PE.equals(versionEditionString) || 379 UpgradeConstants.VERSION_AS80_PE.equals(versionEditionString) || 380 UpgradeConstants.VERSION_AS81_PE.equals(versionEditionString) || 381 UpgradeConstants.VERSION_AS90_PE.equals(versionEditionString)){ 382 return UpgradeConstants.EDITION_PE; 383 } 384 if(UpgradeConstants.VERSION_AS7X_SE.equals(versionEditionString) || 385 UpgradeConstants.VERSION_AS80_SE.equals(versionEditionString)|| 386 UpgradeConstants.VERSION_AS90_SE.equals(versionEditionString)){ 387 return UpgradeConstants.EDITION_SE; 388 } 389 if(UpgradeConstants.VERSION_AS7X_EE.equals(versionEditionString) || 390 UpgradeConstants.VERSION_AS81_EE.equals(versionEditionString)|| 391 UpgradeConstants.VERSION_AS81_EE.equals(versionEditionString)|| 392 UpgradeConstants.VERSION_AS90_EE.equals(versionEditionString)){ 393 return UpgradeConstants.EDITION_EE; 394 } 395 return ""; 396 } 397 public boolean isValidSourcePath(String sourcePath){ 398 File biDir = new File(sourcePath+File.separator+"bin"); 399 if(sourcePath.equals("") || !biDir.isDirectory()) { 400 if(!checkSourceInputAsDomainRoot(sourcePath, common)) { 401 if(new File(sourcePath + File.separator + "config").isDirectory()){ 403 return true; 404 } 405 return false; 406 } 407 common.setSourceDomainRoot(sourcePath); 408 } 409 String as7xInstallFileName = "admingui.ear"; File runtime70Jar = new File(sourcePath+File.separator+"lib"+File.separator+as7xInstallFileName); 412 if((runtime70Jar != null) && runtime70Jar.exists()) { 413 return true; 415 } 416 String [] domainConfigDirs = new VersionExtracter(sourcePath,common).getDomainAndConfigDirs(); 418 if(domainConfigDirs == null || domainConfigDirs.length == 0){ 419 return false; 421 } 422 String domainsDir = domainConfigDirs[0]; 423 424 if(domainsDir == null) 428 return false; 429 return true; 430 } 431 public boolean isValidTargetPath(String targetPath){ 432 433 454 455 if(!new File(targetPath).isDirectory()) 456 return false; 457 458 return true; 459 } 460 public List getStandAloneInstances(Hashtable domainsMapping){ 461 List stdAloneList = new ArrayList(); 463 for(Iterator domIt=domainsMapping.values().iterator(); domIt.hasNext();){ 464 DomainInfo dInfo = (DomainInfo)domIt.next(); 465 for(Iterator instIt = dInfo.getInstanceNames().iterator(); instIt.hasNext();){ 466 String instName = (String )instIt.next(); 467 if(this.isInstanceInCluster(instName)){ 468 continue; 469 } 470 if( !instName.equals("admin-server") ) { 471 Vector instDInfo = new Vector(); 472 instDInfo.add(instName); 473 instDInfo.add(dInfo); 474 stdAloneList.add(instDInfo); 475 } 476 } 477 } 478 return stdAloneList; 479 } 480 public boolean isInstanceInCluster(String instName){ 481 List clList = ClustersInfoManager.getClusterInfoManager().getClusterInfoList(); 483 if(clList == null) return false; 484 for(Iterator clIt = clList.iterator(); clIt.hasNext(); ){ 485 ClusterInfo clInfo = (ClusterInfo)clIt.next(); 486 for(Iterator instIt = clInfo.getClusteredInstanceList().iterator(); instIt.hasNext();){ 487 if(((ClusteredInstance)instIt.next()).getInstanceName().equals(instName)){ 488 return true; 489 } 490 } 491 } 492 return false; 493 } 494 private Element getConfigElementFromDocumentElement(Element documentElement, String lookUpConfigName){ 495 NodeList configEles = documentElement.getElementsByTagName("config"); 496 Element configEle = null; 497 for(int lh =0; lh < configEles.getLength(); lh++){ 498 String configName = ((Element )configEles.item(lh)).getAttribute("name"); 499 if(configName.equals(lookUpConfigName)){ 500 configEle = (Element )configEles.item(lh); 501 break; 502 } 503 } 504 return configEle; 505 } 506 public boolean switchedIIOPPorts(String serverID, String portValue, Element documentElement){ 507 Element configEle = this.getConfigElementFromDocumentElement(documentElement, "server-config"); 508 NodeList iiopService = configEle.getElementsByTagName("iiop-service"); 509 NodeList iiopListeners = ((Element )iiopService.item(0)).getElementsByTagName("iiop-listener"); 510 Element iiopListener = null; 511 for(int ii =0; ii < iiopListeners.getLength(); ii++){ 512 if(((Element )iiopListeners.item(ii)).getAttribute("id").equals("orb-listener-1")){ 513 iiopListener = (Element )iiopListeners.item(ii); 514 break; 515 } 516 } 517 if(iiopListener != null){ 518 String serverIIOPPort = this.getIIOPListenerPortForServer(iiopListener.getAttribute("port"), "server", documentElement); 519 if(serverIIOPPort.equals("3700")){ 520 String portValueFromServer = this.getIIOPListenerPortForServer(portValue,serverID, documentElement); 521 if(portValueFromServer != null) 522 iiopListener.setAttribute("port", portValueFromServer); 523 return true; 524 }else{ 525 return false; 526 } 527 } 528 return false; 529 } 530 private String getIIOPListenerPortForServer(String portValue, String serverName, Element documentElement){ 531 try{ 532 if(portValue != null){ 533 int portIntValue = Integer.parseInt(portValue); 534 return String.valueOf(portIntValue); 535 } 536 }catch(java.lang.NumberFormatException ne){ 537 } 539 NodeList servers = documentElement.getElementsByTagName("servers"); 540 NodeList serverList = ((Element )servers.item(0)).getElementsByTagName("server"); 541 String portValueFromServer = null; 542 for(int lh =0; lh < serverList.getLength(); lh++){ 543 if(serverName.equals(((Element )serverList.item(lh)).getAttribute("name"))){ 544 Element serverElement = (Element )serverList.item(lh); 545 Element sysProp = getSystemPropertyElement("IIOP_LISTENER_PORT",serverElement); 546 if(sysProp != null){ 547 return sysProp.getAttribute("value"); 548 }else{ 549 Element configElement = this.getConfigElementFromDocumentElement(documentElement, serverElement.getAttribute("config-ref")); 550 if(configElement != null){ 551 sysProp = getSystemPropertyElement("IIOP_LISTENER_PORT",configElement); 552 if(sysProp != null) 553 return sysProp.getAttribute("value"); 554 } 555 } 556 } 557 } 558 return null; 559 } 560 private Element getSystemPropertyElement(String propertyName, Element parentForSysProp){ 561 NodeList sysProps = parentForSysProp.getElementsByTagName("system-property"); 562 for(int sh =0; sh < sysProps.getLength(); sh++){ 563 if(propertyName.equals(((Element )sysProps.item(sh)).getAttribute("name"))){ 564 return ((Element )sysProps.item(sh)); 565 } 566 } 567 return null; 568 } 569 public void updateDomainXMLWithIIOPCluster(CommonInfoModel cmnInfo, String domainXMLFile, IIOPCluster iiopCluster){ 570 String clusterName = iiopCluster.getClusterName(); 571 List servInstances = iiopCluster.getIIOPServerInstanceList(); 572 boolean domainFileChanged = false; 573 Document domainDoc = this.getDomainDocumentElement(domainXMLFile); 574 for(int servIt = 0; servIt < servInstances.size(); servIt++){ 575 List endPoints = ((IIOPServerInstance)servInstances.get(servIt)).getIIOPEndPoints(); 576 String serverName = ((IIOPServerInstance)servInstances.get(servIt)).getName(); 577 for(int endPt = 0; endPt < endPoints.size(); endPt++){ 578 IIOPEndPoint iiopEndPoint = (IIOPEndPoint)endPoints.get(endPt); 579 if(domainDoc != null){ 581 String propertyName = "IIOP_LISTENER_PORT"; 582 String propValue = iiopEndPoint.getPort(); 583 NodeList servers = domainDoc.getDocumentElement().getElementsByTagName("servers"); 584 NodeList serverList = ((Element )servers.item(0)).getElementsByTagName("server"); 585 if(propValue.equals("3700")){ 586 this.switchedIIOPPorts(serverName, null, domainDoc.getDocumentElement()); 587 } 589 BaseElement baseElement = null; 592 try{ 593 baseElement = com.sun.enterprise.tools.upgrade.transform.ElementToObjectMapper.getMapper().getElementObject(domainDoc.getDocumentElement().getTagName()); 594 }catch(Exception ef){ 595 } 596 this.addOrUpdateSystemPropertyToServer(serverName,serverList, propertyName, propValue, baseElement); 597 domainFileChanged = true; 598 } 599 break; 600 } 601 } 602 if(domainFileChanged && (domainDoc != null)){ 603 this.saveDocumentToDomainFile(domainXMLFile, domainDoc); 604 } 605 } 606 public java.util.List updateClusterList(String domainXMLFile, String domainName, java.util.List clList){ 607 Document domainDoc = this.getDomainDocumentElement(domainXMLFile); 608 if(domainDoc != null){ 609 NodeList clusters = domainDoc.getDocumentElement().getElementsByTagName("clusters"); 610 if(clusters != null){ 611 NodeList clusterList = ((Element )clusters.item(0)).getElementsByTagName("cluster"); 612 if((clusterList != null) && (clusterList.getLength() >0)){ 613 for(int lh =0; lh < clusterList.getLength(); lh++){ 614 String clName = ((Element )clusterList.item(lh)).getAttribute("name"); 615 ClusterInfo clInfo = new ClusterInfo(); 616 clInfo.setClusterName(clName); 617 clInfo.setDomainName(domainName); 618 clList.add(clInfo); 619 } 620 } 621 } 622 } 623 return clList; 624 } 625 private Document getDomainDocumentElement(String domainFileName){ 626 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 627 factory.setNamespaceAware(true); 629 Document resultDoc = null; 630 try { 631 DocumentBuilder builder = factory.newDocumentBuilder(); 632 builder.setEntityResolver((org.xml.sax.helpers.DefaultHandler )Class.forName 633 ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance()); 634 resultDoc = builder.parse( new File(domainFileName)); 635 }catch (Exception ex){ 636 logger.log(Level.WARNING, stringManager.getString("enterprise.tools.upgrade.iiop_port_domain_doc"),ex); 637 } 638 return resultDoc; 639 } 640 private void saveDocumentToDomainFile(String domainFileName, Document resultDoc){ 641 try{ 643 TransformerFactory tFactory = TransformerFactory.newInstance(); 644 Transformer transformer = tFactory.newTransformer(); 645 if (resultDoc.getDoctype() != null){ 646 String systemValue = resultDoc.getDoctype().getSystemId(); 647 transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, systemValue); 648 String pubValue = resultDoc.getDoctype().getPublicId(); 649 transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pubValue); 650 } 651 DOMSource source = new DOMSource (resultDoc); 652 StreamResult result = new StreamResult (new FileOutputStream(domainFileName)); 653 transformer.transform(source, result); 654 result.getOutputStream().close(); 655 }catch (Exception ex){ 656 logger.log(Level.WARNING, stringManager.getString("enterprise.tools.upgrade.iiop_port_domain_save_fail"),ex); 657 } 659 } 660 661 public void recover() { 662 List domainList = common.getDomainList(); 663 String sourceDir = common.getSourceDomainRoot(); 664 String targetDir = common.getTargetDomainRoot(); 665 if(domainList != null && sourceDir != null && targetDir != null) { 666 Iterator itr = domainList.iterator(); 667 while(itr.hasNext()) { 668 String dname = (String )itr.next(); 669 boolean domainRootSame = new File(sourceDir).equals(new File(targetDir)); 670 if(domainRootSame) { 671 if(new File(sourceDir + File.separator + "backup").isDirectory()) { 672 common.setCurrentDomain(dname); 673 String latestDomainPath=common.findLatestDomainDir(sourceDir); 674 if(latestDomainPath != null) { 675 new File(latestDomainPath).renameTo(new File(sourceDir + File.separator + dname)); 676 File backupdir = new File(sourceDir + File.separator + "backup"); 677 String [] dirs = backupdir.list(); 678 if(dirs.length == 0) 679 backupdir.delete(); 680 } 681 } 682 } 683 684 } } } 687 688 public boolean validateUserDetails(String adminUserName, String adminPassword, String masterPassword){ 689 try{ 690 com.sun.enterprise.admin.servermgmt.RepositoryManager rManager = new com.sun.enterprise.admin.servermgmt.RepositoryManager(); 691 String domainPath = this.common.getTargetDomainRoot(); 692 if(!new File(domainPath+File.separator+"domain1").exists() || 693 ((common.getSourceInstallDir() != null && common.getTargetInstallDir() != null) && (common.getSourceInstallDir().equalsIgnoreCase(common.getTargetInstallDir() + File.separator + "domains") || (common.getSourceInstallDir().equalsIgnoreCase(common.getTargetInstallDir()))))){ 694 return true; 704 } 705 com.sun.enterprise.admin.servermgmt.RepositoryConfig repConf = new com.sun.enterprise.admin.servermgmt.RepositoryConfig("domain1",domainPath); 706 rManager.validateAdminUserAndPassword(repConf,adminUserName,adminPassword); 707 if((masterPassword != null) && (!this.common.getTargetVersionAndEdition().equals(UpgradeConstants.VERSION_AS81_PE))) 708 rManager.validateMasterPassword(repConf,masterPassword); 709 }catch(com.sun.enterprise.admin.servermgmt.RepositoryException re){ 710 logger.log(Level.SEVERE, stringManager.getString("enterprise.tools.upgrade.generalException", re.getMessage()), re); 711 return false; 712 } 713 return true; 714 } 715 public void updateDomainXMLWithPersistenceStoreProps(java.util.Properties props){ 716 } 720 public void updateListenerPortsForClusteredInstances(Element docElement, String propertyName, String portValue, BaseElement bElement){ 721 NodeList servers = docElement.getElementsByTagName("servers"); 722 NodeList serverList = ((Element )servers.item(0)).getElementsByTagName("server"); 723 String clusterName = this.common.getCurrentCluster(); 724 for(java.util.Iterator dItr = ClustersInfoManager.getClusterInfoManager().getClusterInfoList().iterator(); dItr.hasNext();){ 725 ClusterInfo cInfo = (ClusterInfo)dItr.next(); 726 if(cInfo.getClusterName().equals(clusterName)){ 727 for(java.util.Iterator clItr = cInfo.getClusteredInstanceList().iterator(); clItr.hasNext();){ 728 ClusteredInstance clInstance = (ClusteredInstance)clItr.next(); 729 if(portValue == null){ 730 this.addOrUpdateSystemPropertyToServer(clInstance.getInstanceName(), serverList, propertyName, clInstance.getInstancePort(),bElement); 731 }else{ 732 this.addOrUpdateSystemPropertyToServer(clInstance.getInstanceName(), serverList, propertyName, portValue,bElement); 733 } 734 } 735 } 736 } 737 } 738 public void addOrUpdateSystemPropertyToServer(String serverName, NodeList serverList, String propertyName, String propertyValue, BaseElement bElement){ 739 for(int lh =0; lh < serverList.getLength(); lh++){ 740 if(serverName.equals(((Element )serverList.item(lh)).getAttribute("name"))){ 741 Element serverElement = (Element )serverList.item(lh); 742 Element sysProp = this.getSystemPropertyElement(propertyName,serverElement); 743 if(sysProp != null){ 744 sysProp.setAttribute("value", propertyValue); 745 return; 746 } 747 if(sysProp == null){ 748 if(bElement != null){ 750 sysProp = serverElement.getOwnerDocument().createElement("system-property"); 751 sysProp.setAttribute("name", propertyName); 752 sysProp.setAttribute("value", propertyValue); 753 bElement.appendElementToParent(serverElement,sysProp); 754 } 755 } 756 return; 757 } 758 } 759 } 760 761 public void copyFile(String source, String target) throws IOException { 762 copyFile(source, target, false); 763 } 764 765 public void copyFile(String source, String target, boolean append) throws IOException{ 766 FileInputStream in = new FileInputStream(new File(source)); 771 FileOutputStream out = new FileOutputStream(new File(target), append); 772 int c; 773 while ((c = in.read()) != -1) { 774 out.write(c); 775 } 776 in.close(); 777 out.close(); 778 } 779 780 public String getJvmOptionValueFromSourceConfig(String optionName) { 782 String sourceConfig = common.getSourceConfigXMLFile(); 783 Document sourceDoc = this.getDomainDocumentElement(common.getSourceConfigXMLFile()); 784 NodeList serverList = sourceDoc.getElementsByTagName("server"); 785 String serverName = common.getCurrentSourceInstance(); 786 if (serverName == null || serverName == "") { 787 serverName = "server"; 788 } 789 String configName = null; 790 String password = null; 791 for(int i=0;i<serverList.getLength();i++){ 792 Node serverNode = (Node )serverList.item(i); 793 NamedNodeMap attributes = serverNode.getAttributes(); 794 String name = (attributes.getNamedItem("name")).getNodeValue(); 795 if(serverName.equals(name)){ 796 configName = (attributes.getNamedItem("config-ref")).getNodeValue(); 797 } 798 } 799 if (configName != null) { 800 NodeList jvmOptionList = sourceDoc.getElementsByTagName("jvm-options"); 801 for(int j=0;j<jvmOptionList.getLength();j++) { 802 Node jvmNode = jvmOptionList.item(j); 803 String jvmOptions = getTextNodeData((Element )jvmNode); 804 if (jvmOptions.indexOf(optionName) != -1) { 805 password = jvmOptions.substring(jvmOptions.indexOf("=")+1, jvmOptions.length()); 806 } 807 } 808 } else { 809 logger.warning(stringManager.getString("enterprise.tools.upgrade.configNotFound", configName)); 810 } 811 return password; 812 813 } 814 815 public String getTextNodeData(Element element){ 816 NodeList children = element.getChildNodes(); 817 for(int index=0; index < children.getLength(); index++){ 818 if(children.item(index).getNodeType() == Node.TEXT_NODE){ 819 return children.item(index).getNodeValue(); 820 } 821 } 822 return ""; 823 } 824 } 825 | Popular Tags |