1 23 24 29 30 package com.sun.enterprise.tools.upgrade.common; 31 32 import java.util.*; 33 import java.io.*; 34 import java.util.logging.*; 35 import java.net.InetAddress ; 36 import java.net.UnknownHostException ; 37 38 import com.sun.enterprise.util.ASenvPropertyReader; 39 import com.sun.enterprise.util.SystemPropertyConstants; 40 41 import com.sun.enterprise.tools.upgrade.logging.*; 42 import com.sun.enterprise.cli.framework.*; 43 import com.sun.enterprise.util.i18n.StringManager; 44 45 import javax.xml.parsers.DocumentBuilder ; 46 import javax.xml.parsers.DocumentBuilderFactory ; 47 import javax.xml.parsers.FactoryConfigurationError ; 48 import javax.xml.parsers.ParserConfigurationException ; 49 50 import javax.xml.transform.Transformer ; 51 import javax.xml.transform.TransformerFactory ; 52 import javax.xml.transform.TransformerException ; 53 import javax.xml.transform.TransformerConfigurationException ; 54 55 import javax.xml.transform.dom.DOMSource ; 56 import javax.xml.transform.stream.StreamResult ; 57 import javax.xml.transform.OutputKeys ; 58 59 import org.xml.sax.SAXException ; 60 import org.xml.sax.SAXParseException ; 61 import org.w3c.dom.Document ; 62 import org.w3c.dom.DOMException ; 63 import org.w3c.dom.Element ; 64 import org.w3c.dom.Node ; 65 import org.w3c.dom.NodeList ; 66 67 import com.sun.enterprise.tools.upgrade.cluster.*; 68 69 74 75 76 public class DomainsProcessor { 77 private static CommonInfoModel commonInfo; 78 private java.util.Vector httpSSLPorts; 79 private java.util.Vector iiopSSLPorts; 80 private java.util.Vector iiopMutualAuthPorts; 81 private java.util.Vector sourceXMLCorePorts; 82 private java.util.Vector adminJMXPorts; 84 86 private static int adminPortToStartWith = 4858; 87 88 private static Logger logger = LogService.getLogger(LogService.UPGRADE_LOGGER); 89 private static StringManager stringManager = StringManager.getManager(LogService.UPGRADE_LOGGER); 90 91 92 public DomainsProcessor(CommonInfoModel ci) { 93 this.commonInfo = ci; 94 httpSSLPorts = new java.util.Vector (); 95 iiopSSLPorts = new java.util.Vector (); 96 iiopMutualAuthPorts = new java.util.Vector (); 97 sourceXMLCorePorts = new java.util.Vector (); 98 adminJMXPorts = new java.util.Vector (); 100 102 File domainDir = new File(ci.getTargetDomainRoot() + File.separator + "domain1"); 105 if(!domainDir.exists()){ 106 } 108 else { 110 String targetDomainFile = ci.getTargetDomainRoot() + File.separator + "domain1"+File.separator+ 112 "config"+File.separator+"domain.xml" ; 113 if(domainDir.isDirectory() && 114 !(ci.isValid70Domain(ci.getTargetDomainRoot() + File.separator + "domain1")) && 115 (new File(targetDomainFile)).exists()) { 116 String htSSP = getPortFromXML(targetDomainFile, "http-listener", "http-listener-2"); 117 if(htSSP != null) httpSSLPorts.add(htSSP); 118 String iiSSP = getPortFromXML(targetDomainFile, "iiop-listener", "SSL"); 119 if(iiSSP != null) iiopSSLPorts.add(iiSSP); 120 String iiMAP = getPortFromXML(targetDomainFile, "iiop-listener", "SSL_MUTUALAUTH"); 121 if(iiMAP != null) iiopMutualAuthPorts.add(iiMAP); 122 String adminJMX = getJMXPortFromXML(targetDomainFile, "jmx-connector", "system"); 124 if(adminJMX != null) adminJMXPorts.add(adminJMX); 125 } 127 } 129 File samplesDir = new File(ci.getTargetDomainRoot() + File.separator + "samples"); 131 if(samplesDir.isDirectory() && !(ci.isValid70Domain(ci.getTargetDomainRoot() + File.separator + "samples")) ) { 132 String sampleDomainFile = ci.getTargetDomainRoot() + File.separator + "samples"+File.separator+"config"+File.separator+"domain.xml" ; 134 if(new File(sampleDomainFile).exists()){ 135 String shtSSP = getPortFromXML(sampleDomainFile, "http-listener", "http-listener-2"); 136 if(shtSSP != null) httpSSLPorts.add(shtSSP); 137 String siiSSP = getPortFromXML(sampleDomainFile, "iiop-listener", "SSL"); 138 if(siiSSP != null) iiopSSLPorts.add(siiSSP); 139 String siiMAP = getPortFromXML(sampleDomainFile, "iiop-listener", "SSL_MUTUALAUTH"); 140 if(siiMAP != null) iiopMutualAuthPorts.add(siiMAP); 141 String sadminJMX = getJMXPortFromXML(sampleDomainFile, "jmx-connector", "system"); 143 if(sadminJMX != null) adminJMXPorts.add(sadminJMX); 144 } 146 147 } 148 149 } 153 private DomainsProcessor(CommonInfoModel ci, boolean nothing) { 154 155 } 156 157 public void processTargetDomains() throws HarnessException{ 158 List domainNames = commonInfo.getDomainList(); 159 String target = commonInfo.getTargetInstallDir(); 160 161 ASenvPropertyReader reader = new ASenvPropertyReader(System.getProperty(SystemPropertyConstants.CONFIG_ROOT_PROPERTY)); 163 reader.setSystemProperties(); 164 for(int i=0; i<domainNames.size();i++) { 167 String sourceDomainName = (String )domainNames.get(i); 168 String targetDomainName=sourceDomainName; 169 if(!new File(commonInfo.getTargetDomainRoot()).isDirectory()) { 170 logger.log(Level.INFO,stringManager.getString("enterprise.tools.upgrade.not_valid_target_install")); 171 return; 172 } 173 File targetDomainUpgrade = new File(commonInfo.getTargetDomainRoot()+File.separator+targetDomainName); 174 if( !commonInfo.isDomain(targetDomainUpgrade.getAbsolutePath()) ){ 178 179 185 String [] createDomainCommand = this.getCreateDomainCommand(sourceDomainName,targetDomainName); 186 boolean canContinue = executeCommand(createDomainCommand); 187 UpdateProgressManager.getProgressManager().setContinueUpgrade(canContinue); 188 if(!canContinue) { 189 throw new HarnessException(stringManager.getString("enterprise.tools.upgrade.domain_creation_error", targetDomainName)); 190 } 191 UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent((i*30)/domainNames.size()); 192 } 193 if(commonInfo.isDomain(targetDomainUpgrade.getAbsolutePath())) 194 this.setAdminPortAndSecurity(sourceDomainName,targetDomainName); 195 } 196 } 198 199 private String [] getCreateDomainCommand(String domainName, String domainName80) { 200 213 String target = commonInfo.getTargetInstallDir(); 214 String adminPort = getSourceAdminPort(((DomainInfo)this.commonInfo.getDomainMapping().get(domainName)).getDomainPath()); 215 String httpPort = "8080"; 217 String jmsPort = "7676"; 218 String iiopPort = "3700"; 219 220 String httpSSLPort = getAFreePort(1044,10); 222 String iiopSSLPort = getAFreePort(1090,10); 223 String iiopSSLMutualAuth = getAFreePort(1091,10); 224 String adminJMXPort = getAFreePort(8687,10); 226 adminJMXPorts.add(adminJMXPort); 228 231 httpSSLPorts.add(httpSSLPort); 232 iiopSSLPorts.add(iiopSSLPort); 233 iiopMutualAuthPorts.add(iiopSSLMutualAuth); 234 String propertiesString = "http.ssl.port="+httpSSLPort+":orb.ssl.port="+iiopSSLPort+":orb.mutualauth.port="+iiopSSLMutualAuth+ 235 ":jms.port="+jmsPort+":orb.listener.port="+iiopPort; 236 237 if(commonInfo.checkUpgradefrom8xpeto90pe()) { 241 propertiesString = propertiesString+":domain.jmxPort="+adminJMXPort; 242 } 243 String [] createDomainCommand = {"create-domain", 245 "--domaindir", 246 "\"" + commonInfo.getTargetDomainRoot() +"\"", 247 "--adminport", 248 adminPort, 249 "--adminuser", 250 commonInfo.getAdminUserName(), 251 "--passwordfile ", 252 "\"" + commonInfo.getPasswordFile() +"\"", 253 "--domainproperties", 254 propertiesString, 255 domainName80 256 }; 257 return createDomainCommand; 258 259 } 260 261 public static String getSourceAdminPort() { 262 return getSourceAdminPort(commonInfo.getSourceDomainPath()); 263 } 264 265 public static String getSourceAdminPort(String domainPath) { 267 if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)) { 269 String adminServerXmlFile = domainPath+File.separator+"admin-server"+File.separator+"config"+File.separator+"server.xml"; 270 String port = getPortFromXML(adminServerXmlFile,"http-listener", "http-listener-1"); 271 if(port != null) 272 return port; 273 }else{ 274 String domainXmlFile = domainPath+File.separator+"config"+File.separator+"domain.xml"; 276 if(new File(domainXmlFile).exists()){ 277 String port = getPortFromXML(domainXmlFile,"http-listener", "admin-listener"); 278 if(port != null) 279 return port; 280 } 281 } 282 adminPortToStartWith =+10; 284 return String.valueOf(adminPortToStartWith); 285 } 286 public static String getSourceAdminSecurity(String domainPath) { 287 if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)) { 289 String adminServerXmlFile = domainPath+File.separator+"admin-server"+File.separator+"config"+File.separator+"server.xml"; 290 String securityEnabled = getSecurityEnabledFromXML(adminServerXmlFile,"http-listener", "http-listener-1"); 291 if(securityEnabled != null) 292 return securityEnabled; 293 }else{ 294 String domainXmlFile = domainPath+File.separator+"config"+File.separator+"domain.xml"; 296 if(new File(domainXmlFile).exists()){ 297 String securityEnabled = getSecurityEnabledFromXML(domainXmlFile,"http-listener", "admin-listener"); 298 if(securityEnabled != null) 299 return securityEnabled; 300 } 301 } 302 return "true"; } 304 305 public static String getSourceAdminSecurity() { 306 String domainPath = commonInfo.getSourceDomainPath(); 307 return getSourceAdminSecurity(domainPath); 308 } 309 private void setAdminPortAndSecurity(String sourceDomainName, String targetDomainName){ 310 String domainPath = ((DomainInfo)this.commonInfo.getDomainMapping().get(sourceDomainName)).getDomainPath(); 311 String adminPort = getSourceAdminPort(domainPath); 312 String securityEnabled = getSourceAdminSecurity(domainPath); 313 314 String domainFileName = commonInfo.getTargetDomainRoot()+File.separator+targetDomainName+File.separator+"config"+File.separator+"domain.xml"; 315 316 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 317 factory.setNamespaceAware(true); 319 try { 320 DocumentBuilder builder = factory.newDocumentBuilder(); 321 builder.setEntityResolver((org.xml.sax.helpers.DefaultHandler )Class.forName 322 ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance()); 323 Document resultDoc = builder.parse( new File(domainFileName)); 324 NodeList taggedElements = resultDoc.getDocumentElement().getElementsByTagName("http-listener"); 325 for(int lh =0; lh < taggedElements.getLength(); lh++){ 326 Element element = (Element )taggedElements.item(lh); 327 if((element.getAttribute("id")).equals("admin-listener")){ 329 element.setAttribute("port",adminPort); 330 element.setAttribute("security-enabled", securityEnabled); 331 break; 332 } 333 } 334 335 TransformerFactory tFactory = TransformerFactory.newInstance(); 337 Transformer transformer = tFactory.newTransformer(); 338 if (resultDoc.getDoctype() != null){ 339 String systemValue = resultDoc.getDoctype().getSystemId(); 340 transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, systemValue); 341 String pubValue = resultDoc.getDoctype().getPublicId(); 342 transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pubValue); 343 } 344 345 DOMSource source = new DOMSource (resultDoc); 346 StreamResult result = new StreamResult (new FileOutputStream(domainFileName)); 347 transformer.transform(source, result); 348 result.getOutputStream().close(); 349 350 }catch (Exception ex){ 351 logger.log(Level.WARNING, stringManager.getString("domainProcessor.portFromXML"),ex); 352 } 354 355 } 356 private static String getPortFromXML(String fileName, String tagName, String id) { 357 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 358 factory.setNamespaceAware(true); 360 try { 361 DocumentBuilder builder = factory.newDocumentBuilder(); 362 builder.setEntityResolver((org.xml.sax.helpers.DefaultHandler )Class.forName 363 ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance()); 364 Document adminServerDoc = builder.parse( new File(fileName)); 365 NodeList taggedElements = adminServerDoc.getDocumentElement().getElementsByTagName(tagName); 366 for(int lh =0; lh < taggedElements.getLength(); lh++){ 367 Element element = (Element )taggedElements.item(lh); 368 if((element.getAttribute("id")).equals(id)){ 370 return element.getAttribute("port"); 371 } 372 } 373 }catch (Exception ex){ 374 logger.log(Level.WARNING, stringManager.getString("domainProcessor.portFromXML"),ex); 375 } 377 return null; 378 } 379 380 private static String getSecurityEnabledFromXML(String fileName, String tagName, String id) { 381 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 382 factory.setNamespaceAware(true); 384 try { 385 DocumentBuilder builder = factory.newDocumentBuilder(); 386 builder.setEntityResolver((org.xml.sax.helpers.DefaultHandler )Class.forName 387 ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance()); 388 Document adminServerDoc = builder.parse( new File(fileName)); 389 NodeList taggedElements = adminServerDoc.getDocumentElement().getElementsByTagName(tagName); 390 for(int lh =0; lh < taggedElements.getLength(); lh++){ 391 Element element = (Element )taggedElements.item(lh); 392 if((element.getAttribute("id")).equals(id)){ 394 return element.getAttribute("security-enabled"); 395 } 396 } 397 }catch (Exception ex){ 398 logger.log(Level.WARNING, stringManager.getString("domainProcessor.adminSecureFromXML"),ex); 399 } 401 return null; 402 } 403 404 private String getTargetNodeAgentName(String domainName, CommonInfoModel commonInfoMod){ 405 String configFileName = commonInfoMod.getTargetDomainRoot()+File.separator+domainName+File.separator+"config"+File.separator+"domain.xml"; 406 return getNodeAgentNameFromXML(configFileName); 407 } 408 409 private String getNodeAgentNameFromXML(String fileName) { 410 if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X) || ! new File(fileName).exists()) { 411 return null; 412 } 413 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 414 factory.setNamespaceAware(true); 416 try { 417 DocumentBuilder builder = factory.newDocumentBuilder(); 418 builder.setEntityResolver((org.xml.sax.helpers.DefaultHandler )Class.forName 419 ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance()); 420 Document adminServerDoc = builder.parse( new File(fileName)); 421 NodeList taggedElements = adminServerDoc.getDocumentElement().getElementsByTagName("node-agent"); 422 Element element = (Element )taggedElements.item(0); 423 return element.getAttribute("name"); 424 }catch (Exception ex){ 425 logger.log(Level.WARNING, stringManager.getString("domainProcessor.nodeAgentFromXML"),ex); 426 } 428 return null; 429 } 430 private boolean isNodeAgentExists(String agentName, String fileName){ 431 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 432 factory.setNamespaceAware(true); 434 try { 435 DocumentBuilder builder = factory.newDocumentBuilder(); 436 builder.setEntityResolver((org.xml.sax.helpers.DefaultHandler )Class.forName 437 ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance()); 438 Document adminServerDoc = builder.parse( new File(fileName)); 439 NodeList taggedElements = adminServerDoc.getDocumentElement().getElementsByTagName("node-agent"); 440 for(int lh =0; lh < taggedElements.getLength(); lh++){ 441 Element itElement = ((Element )taggedElements.item(lh)); 442 String attrName = itElement.getAttribute("name"); 443 if(attrName.equals(agentName)) 444 return true; 445 if(agentName.indexOf(".") != -1){ 447 if(agentName.substring(0,agentName.indexOf(".")).equals(attrName)){ 448 return true; 449 } 450 } 451 } 452 }catch (Exception ex){ 453 logger.log(Level.WARNING, stringManager.getString("domainProcessor.nodeAgentFromXML"),ex); 454 } 456 return false; 457 } 458 459 public static String getTargetDomainPort(String domainName, CommonInfoModel commonInfoMod){ 460 String configFileName = commonInfoMod.getTargetDomainRoot()+File.separator+domainName+File.separator+"config"+File.separator+"domain.xml"; 461 return getPortFromXML(configFileName, "http-listener", "admin-listener"); 462 } 463 464 public static String getTargetDomainSecurity(String domainName, CommonInfoModel commonInfoMod){ 465 String configFileName = commonInfoMod.getTargetDomainRoot()+File.separator+domainName+File.separator+"config"+File.separator+"domain.xml"; 466 return getSecurityEnabledFromXML(configFileName, "http-listener", "admin-listener"); 467 } 468 469 private String getAFreePort(int initPortNumber, int increment){ 470 int portNumber = initPortNumber; 472 for(int i=0; i<20; i++){ 473 if(isPortNumberUsable(portNumber)) 474 return Integer.toString(portNumber); 475 portNumber +=increment; 476 } 477 return Integer.toString(portNumber); 479 } 480 private boolean isPortNumberUsable(int portNumber){ 481 String portString = Integer.toString(portNumber); 483 for(int i=0; i<httpSSLPorts.size(); i++){ 484 if(((String )httpSSLPorts.get(i)).equals(portString)) 485 return false; 486 } 487 for(int i=0; i<iiopSSLPorts.size(); i++){ 488 if(((String )iiopSSLPorts.get(i)).equals(portString)) 489 return false; 490 } 491 for(int i=0; i<iiopMutualAuthPorts.size(); i++){ 492 if(((String )iiopMutualAuthPorts.get(i)).equals(portString)) 493 return false; 494 } 495 for(int i=0; i<sourceXMLCorePorts.size(); i++){ 496 if(((String )sourceXMLCorePorts.get(i)).equals(portString)) 497 return false; 498 } 499 for(int i=0; i<adminJMXPorts.size(); i++){ 501 if(((String )adminJMXPorts.get(i)).equals(portString)) 502 return false; 503 } 504 return com.sun.enterprise.util.net.NetUtils.isPortFree(portNumber); 507 } 508 private java.util.List getInstanceNamesWithoutAdminServerAndServer1(java.util.List instanceList){ 509 java.util.List newList = new java.util.ArrayList (); 510 for(java.util.Iterator it = instanceList.iterator(); it.hasNext();){ 511 String serverName = (String )it.next(); 512 if(serverName.equals("admin-server")) continue; 514 newList.add(serverName); 515 } 516 return newList; 517 } 518 public void processDomainInstances() throws HarnessException { 519 java.util.Hashtable domainMapping = commonInfo.getDomainMapping(); 521 522 if(commonInfo.getTargetEdition().equals(UpgradeConstants.EDITION_PE)){ 525 return; 526 } 527 for(java.util.Enumeration domains = domainMapping.keys();domains.hasMoreElements();){ 528 DomainInfo dInfo = (DomainInfo)domainMapping.get((String )domains.nextElement()); 529 boolean domainStarted = false; 534 if(this.getInstanceNamesWithoutAdminServerAndServer1(dInfo.getInstanceNames()).size() > 0){ 536 String adminPort = this.getTargetDomainPort(dInfo.getDomainName(),this.commonInfo); 538 String adminSecurity = this.getTargetDomainSecurity(dInfo.getDomainName(),this.commonInfo); 539 String agentName = getTargetNodeAgentName(dInfo.getDomainName(),this.commonInfo); 540 if ( agentName == null ) { 542 String hostName; 543 try { 544 hostName = (java.net.InetAddress.getLocalHost()).getHostName(); 545 agentName = hostName + "_" + dInfo.getDomainName(); 546 } catch (java.net.UnknownHostException uhe) { 547 hostName = "localhost"; 548 agentName = dInfo.getDomainName() + "-agent"; 549 } 550 createNodeAgent(agentName, hostName, adminPort, commonInfo.getAdminUserName(), commonInfo.getAdminPassword(),dInfo.getDomainName()); 551 } 552 for(java.util.Iterator instanceNames = dInfo.getInstanceNames().iterator(); instanceNames.hasNext();){ 553 String serverName = (String )instanceNames.next(); 554 if(!serverName.equals("admin-server") && 555 !commonInfo.getTargetEdition().equals(UpgradeConstants.EDITION_PE)) { if(!domainStarted){ 557 if(!this.startDomain(dInfo.getDomainName())){ 558 throw new HarnessException(stringManager.getString("domainProcessor.domainStartFailed",dInfo.getDomainName())); 559 } 560 domainStarted = true; 561 } 562 boolean status = this.createServerInstance(serverName, agentName, null, commonInfo.getAdminUserName(), commonInfo.getAdminPassword(), adminPort, adminSecurity); 563 if(!instanceNames.hasNext()){ 564 if(domainStarted) 565 this.stopDomain(dInfo.getDomainName()); 566 } 567 } 568 } 569 } 570 } 571 } 572 573 public boolean createNodeAgent(String agentName, String dasHost,String dasPort, String dasuser, String daspwd, String domainName){ 574 String adminSecurity = DomainsProcessor.getTargetDomainSecurity(domainName, commonInfo); 575 String [] command = {"create-node-agent", "--host",dasHost,"--port", dasPort, "--secure="+adminSecurity, "--user", dasuser, "--passwordfile ", "\"" + commonInfo.getPasswordFile() +"\"", 576 agentName }; 577 return this.executeCommand(command); 578 } 579 580 public boolean createConfig(String configName){ 581 return false; 583 } 584 585 public boolean createServerInstance(String serverName, String agentName, String configName, String userid, String pwd, String adminPort, String adminSecurity){ 586 if(configName != null){ 589 String [] command = {"create-instance","--nodeagent",agentName,"--port",adminPort, "--secure="+adminSecurity, "--config", configName, 590 "--user", userid, "--passwordfile ", "\"" + commonInfo.getPasswordFile() +"\"", serverName }; 591 return this.executeCommand(command); 592 }else{ 593 String [] command = {"create-instance","--nodeagent",agentName, 596 "--user", userid, "--passwordfile ", "\"" + commonInfo.getPasswordFile() +"\"", "--port",adminPort,"--secure="+adminSecurity ,serverName }; 597 return this.executeCommand(command); 598 } 599 } 600 601 private boolean startDomain(String domainName) { 602 return startDomain(domainName, this.commonInfo); 603 } 604 605 public boolean startDomain(String domainName, CommonInfoModel commonInfo){ 606 return Commands.startDomain(domainName, commonInfo); 607 } 608 609 public boolean stopDomain(String domainName){ 610 return Commands.stopDomain(domainName, commonInfo); 611 } 612 613 private boolean executeCommand(String [] commandStrings){ 614 try { 615 return Commands.executeCommand(commandStrings); 616 } catch (com.sun.enterprise.cli.framework.CommandException ce) { 617 Throwable t = ce.getCause(); 619 CommonInfoModel.getDefaultLogger().log(Level.SEVERE, stringManager.getString("enterprise.tools.upgrade.generalException", ce.getMessage()),ce); 620 if (t != null) { 621 CommonInfoModel.getDefaultLogger().severe(stringManager.getString("enterprise.tools.upgrade.generalException", t.getMessage())); 622 } 623 } 624 return false; 625 } 626 public boolean processClusters() throws HarnessException { 627 java.util.List clInfoList = ClustersInfoManager.getClusterInfoManager().getClusterInfoList(); 628 if((clInfoList == null) || (clInfoList.isEmpty())) 629 return false; 630 int clusterNo = 0; 632 for(Iterator it = clInfoList.iterator(); it.hasNext(); ){ 633 ClusterInfo clInfo = (ClusterInfo)it.next(); 634 String clusterName = clInfo.getClusterName(); 635 if(clusterName == null) 636 clusterName = "cluster_"+Integer.toString(clusterNo++); 637 clInfo.setClusterName(clusterName); 638 this.createCluster(clusterName,clInfo.getDomainName()); 640 if(!this.commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){ 641 continue; 642 } 643 List clInstances = clInfo.getClusteredInstanceList(); 644 ClusteredInstance masterInstance = clInfo.getMasterInstance(); 645 boolean domainStarted = false; 646 String startedDomainName = null; 647 String configName = configName = clusterName+"_config"; 648 if(masterInstance == null){ 649 String adminPort = null; 651 String adminSecurity = null; 652 for(Iterator clInstIt = clInstances.iterator(); clInstIt.hasNext();){ 653 ClusteredInstance clusteredInstance = (ClusteredInstance)clInstIt.next(); 654 if(!domainStarted){ 655 startedDomainName = clusteredInstance.getDomain(); 656 if(!this.startDomain(startedDomainName)){ 657 domainStarted = false; 659 throw new HarnessException(stringManager.getString("domainProcessor.domainStartFailed",startedDomainName)); 660 } 661 adminPort = this.getTargetDomainPort(startedDomainName,this.commonInfo); 662 adminSecurity = this.getTargetDomainSecurity(startedDomainName,this.commonInfo); 663 domainStarted = true; 664 } 665 this.createClusteredInstance(clusteredInstance,clusterName,startedDomainName,configName,adminPort, adminSecurity); 666 if(!clInstIt.hasNext()){ 667 if(domainStarted) 668 this.stopDomain(startedDomainName); 669 } 670 } 671 }else{ 672 if(this.startDomain(masterInstance.getDomain())){ 673 domainStarted = true; 674 String adminPort = this.getTargetDomainPort(masterInstance.getDomain(),this.commonInfo); 675 String adminSecurity = this.getTargetDomainSecurity(masterInstance.getDomain(),this.commonInfo); 676 this.createClusteredInstance(masterInstance,clusterName,masterInstance.getDomain(),configName,adminPort, adminSecurity); 677 for(Iterator clInstIt = clInstances.iterator(); clInstIt.hasNext();){ 678 ClusteredInstance clInst = (ClusteredInstance)clInstIt.next(); 679 if(!clInst.isMaster()) 680 this.createClusteredInstance(clInst,clusterName,masterInstance.getDomain(),configName,adminPort, adminSecurity); 681 if(!clInstIt.hasNext()){ 682 if(domainStarted) 683 this.stopDomain(masterInstance.getDomain()); 684 } 685 } 686 }else{ 687 throw new HarnessException(stringManager.getString("domainProcessor.domainStartFailed",masterInstance.getDomain())); 688 } 689 } 690 } 691 this.commonInfo.setCurrentCluster(null); 693 this.processStandAloneInstances(); 694 return true; 695 } 696 private boolean createClusteredInstance(ClusteredInstance clInstance, String clusterName, String domainName, String configName, String adminPort, String adminSecurity){ 697 String nodeAgentName = clInstance.getHost(); 698 String dasHostName = null; 699 try { 700 dasHostName = (java.net.InetAddress.getLocalHost()).getHostName(); 701 } catch (java.net.UnknownHostException uhe) { 702 dasHostName = domainName; 703 } 704 if(nodeAgentName.equals("localhost")){ 705 nodeAgentName = dasHostName + "_" + domainName; 706 } else { 707 nodeAgentName = nodeAgentName + "_" + domainName; 708 } 709 String configFileName = commonInfo.getTargetDomainRoot()+File.separator+domainName+File.separator+"config"+File.separator+"domain.xml"; 710 if(!this.isNodeAgentExists(nodeAgentName,configFileName)){ 711 createNodeAgent(nodeAgentName, dasHostName, clInstance.getPort(), commonInfo.getAdminUserName(), commonInfo.getAdminPassword(),domainName); 712 } 713 String user = commonInfo.getAdminUserName(); 717 String password = commonInfo.getAdminPassword(); 718 String [] command = {"create-instance","--user", user, "--passwordfile ", "\"" + commonInfo.getPasswordFile() +"\"","--nodeagent",nodeAgentName,"--port",adminPort, "--secure="+adminSecurity,"--cluster",clusterName,clInstance.getInstanceName()}; 719 return this.executeCommand(command); 720 } 721 private boolean createCluster(String clusterName, String domainName){ 722 String adminSecurity = null; 723 String adminPort = null; 724 if(domainName != null){ 725 this.startDomain(domainName); 726 adminPort = this.getTargetDomainPort(domainName, this.commonInfo); 727 adminSecurity = this.getTargetDomainSecurity(domainName, this.commonInfo); 728 }else{ 729 } 731 String [] command = {"create-cluster","--port",adminPort, "--secure="+adminSecurity,"--user",commonInfo.getAdminUserName(),"--passwordfile ", "\"" + commonInfo.getPasswordFile() +"\"",clusterName}; 732 boolean returnStatus = this.executeCommand(command); 733 this.stopDomain(domainName); 734 return returnStatus; 735 } 736 public void processStandAloneInstances() throws HarnessException { 737 if(!this.commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){ 738 return; 740 } 741 List stdAloneInsts = UpgradeUtils.getUpgradeUtils(this.commonInfo).getStandAloneInstances(this.commonInfo.getDomainMapping()); 742 for(Iterator it = stdAloneInsts.iterator(); it.hasNext();){ 743 Vector instDInfo = (Vector)it.next(); 744 String serverName = (String )instDInfo.elementAt(0); 745 DomainInfo dInfo = (DomainInfo)instDInfo.elementAt(1); 746 String adminPort = this.getTargetDomainPort(dInfo.getDomainName(),this.commonInfo); 747 String adminSecurity = this.getTargetDomainSecurity(dInfo.getDomainName(),this.commonInfo); 748 String agentName = getTargetNodeAgentName(dInfo.getDomainName(),this.commonInfo); 749 if(!this.startDomain(dInfo.getDomainName())){ 750 throw new HarnessException(stringManager.getString("domainProcessor.domainStartFailed",dInfo.getDomainName())); 751 } 752 if ( agentName == null ) { 753 String hostName; 754 try { 755 hostName = (java.net.InetAddress.getLocalHost()).getHostName(); 756 agentName = hostName + "_" + dInfo.getDomainName(); 757 } catch (java.net.UnknownHostException uhe) { 758 hostName = "localhost"; 759 agentName = dInfo.getDomainName() + "-agent"; 760 } 761 createNodeAgent(agentName, hostName, adminPort, commonInfo.getAdminUserName(), commonInfo.getAdminPassword(),dInfo.getDomainName()); 762 } 763 if(!serverName.equals("admin-server")) { boolean status = this.createServerInstance(serverName, agentName, null, commonInfo.getAdminUserName(), commonInfo.getAdminPassword(),adminPort, adminSecurity); 765 } 766 this.stopDomain(dInfo.getDomainName()); 767 } 768 } 769 770 private static String getJMXPortFromXML(String fileName, String tagName, String name) { 772 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 773 factory.setNamespaceAware(true); 774 try { 775 DocumentBuilder builder = factory.newDocumentBuilder(); 776 builder.setEntityResolver((org.xml.sax.helpers.DefaultHandler )Class.forName 777 ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance()); 778 Document adminServerDoc = builder.parse( new File(fileName)); 779 NodeList taggedElements = adminServerDoc.getDocumentElement().getElementsByTagName(tagName); 780 for(int lh =0; lh < taggedElements.getLength(); lh++){ 781 Element element = (Element )taggedElements.item(lh); 782 if((element.getAttribute("name")).equals(name)){ 784 return element.getAttribute("port"); 785 } 786 } 787 }catch (Exception ex){ 788 logger.log(Level.WARNING, stringManager.getString("domainProcessor.portFromXML"),ex); 789 } 791 return null; 792 } 793 795 } 796 | Popular Tags |