1 23 24 32 33 package com.sun.enterprise.admin.mbeans; 34 35 import com.sun.enterprise.admin.mbeans.custom.CustomMBeanException; 36 import java.io.File ; 37 import java.net.InetAddress ; 38 import java.net.UnknownHostException ; 39 import java.util.ArrayList ; 40 import java.util.Properties ; 41 import java.util.StringTokenizer ; 42 import java.util.logging.Level ; 43 import java.util.logging.Logger ; 44 import java.util.Map ; 45 import java.util.HashMap ; 46 import java.util.Set ; 47 import java.util.HashSet ; 48 import java.util.Enumeration ; 49 import javax.management.MBeanException ; 50 import javax.management.MBeanServer ; 51 import javax.management.ObjectName ; 52 import javax.management.Attribute ; 53 import javax.management.AttributeList ; 54 import javax.management.MBeanInfo ; 55 56 import com.sun.enterprise.instance.InstanceEnvironment; 57 import com.sun.enterprise.admin.config.BaseConfigMBean; 59 import com.sun.enterprise.config.ConfigBean; 60 import com.sun.enterprise.config.ConfigContext; 61 import com.sun.enterprise.config.ConfigBeansFactory; 62 import com.sun.enterprise.config.ConfigException; 63 import com.sun.enterprise.config.serverbeans.Server; 64 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 65 import com.sun.enterprise.config.serverbeans.HttpService; 66 import com.sun.enterprise.config.serverbeans.VirtualServer; 67 import com.sun.enterprise.config.serverbeans.Applications; 68 import com.sun.enterprise.config.serverbeans.J2eeApplication; 69 import com.sun.enterprise.config.serverbeans.WebModule; 70 import com.sun.enterprise.config.serverbeans.EjbModule; 71 import com.sun.enterprise.config.serverbeans.ConnectorModule; 72 import com.sun.enterprise.config.serverbeans.Config; 73 import com.sun.enterprise.config.serverbeans.ServerTags; 74 import com.sun.enterprise.config.serverbeans.PropertyResolver; 75 import com.sun.enterprise.config.serverbeans.LifecycleModule; 76 import com.sun.enterprise.config.serverbeans.ElementProperty; 77 import com.sun.enterprise.admin.common.exception.DeploymentException; 78 import com.sun.enterprise.admin.common.exception.ServerInstanceException; 79 import com.sun.enterprise.admin.common.constant.AdminConstants; 80 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 81 import com.sun.enterprise.admin.event.BaseDeployEvent; 82 import com.sun.enterprise.admin.server.core.AdminService; 83 import com.sun.enterprise.admin.util.HostAndPort; 84 import com.sun.enterprise.admin.common.MBeanServerFactory; 85 import com.sun.enterprise.deployment.phasing.DeploymentService; 87 import com.sun.enterprise.deployment.phasing.DeploymentServiceUtils; 88 import com.sun.enterprise.deployment.phasing.DeploymentTarget; 89 import com.sun.enterprise.deployment.phasing.DeploymentTargetFactory; 90 import com.sun.enterprise.deployment.backend.DeployableObjectType; 92 import com.sun.enterprise.deployment.backend.IASDeploymentException; 93 import com.sun.enterprise.deployment.backend.DeploymentRequest; 94 import com.sun.enterprise.deployment.backend.DeploymentCommand; 95 import com.sun.enterprise.deployment.backend.DeploymentStatus; 96 import com.sun.enterprise.deployment.util.DeploymentProperties; 97 import com.sun.enterprise.util.i18n.StringManager; 98 import com.sun.enterprise.deployment.Application; 100 import com.sun.enterprise.deployment.BundleDescriptor; 101 import com.sun.enterprise.deployment.EjbBundleDescriptor; 102 import com.sun.enterprise.deployment.WebBundleDescriptor; 103 import com.sun.enterprise.deployment.WebComponentDescriptor; 104 import com.sun.enterprise.deployment.ConnectorDescriptor; 105 import com.sun.enterprise.deployment.InboundResourceAdapter; 106 import com.sun.enterprise.deployment.OutboundResourceAdapter; 107 import com.sun.enterprise.deployment.EjbDescriptor; 108 import com.sun.enterprise.deployment.io.DescriptorList; 109 import com.sun.enterprise.deployment.backend.DeploymentUtils; 110 import com.sun.enterprise.instance.InstanceFactory; 111 import com.sun.enterprise.instance.AppsManager; 112 import com.sun.enterprise.instance.EjbModulesManager; 113 import com.sun.enterprise.instance.WebModulesManager; 114 import com.sun.enterprise.instance.ConnectorModulesManager; 115 import com.sun.enterprise.instance.AppclientModulesManager; 116 import java.util.Iterator ; 117 import com.sun.enterprise.Switch; 118 import com.sun.enterprise.ManagementObjectManager; 119 import javax.enterprise.deploy.shared.ModuleType ; 120 import com.sun.enterprise.deployment.util.XModuleType; 121 import com.sun.enterprise.connectors.ConnectorConstants; 122 123 import com.sun.enterprise.config.serverbeans.ApplicationRef; 124 import com.sun.enterprise.util.StringUtils; 125 import java.util.List ; 126 import java.util.ListIterator ; 127 128 import com.sun.enterprise.server.Constants; 129 import com.sun.enterprise.admin.mbeanapi.IApplicationsConfigMBean; 130 import com.sun.enterprise.admin.mbeans.custom.BasicCustomMBeanConfigQueries; 131 import com.sun.enterprise.admin.mbeans.custom.BasicCustomMBeanOperations; 132 import com.sun.enterprise.admin.mbeans.custom.CustomMBeanConfigQueries; 133 import com.sun.enterprise.admin.mbeans.custom.CustomMBeanOperationsMBean; 134 135 import com.sun.enterprise.admin.target.TargetType; 136 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 137 import com.sun.enterprise.config.serverbeans.ClusterHelper; 138 import com.sun.enterprise.config.serverbeans.ServerHelper; 139 140 import com.sun.enterprise.util.io.FileUtils; 141 142 151 public class ApplicationsConfigMBean extends BaseConfigMBean 152 implements IApplicationsConfigMBean, CustomMBeanOperationsMBean, CustomMBeanConfigQueries 153 { 154 155 156 public static final String DEFAULT_TARGET = "domain"; 157 158 159 public static final Logger sLogger = Logger.getLogger(AdminConstants.kLoggerName); 160 161 163 164 protected DeploymentService deployService = null; 165 166 167 protected String mInstanceName = null; 168 169 170 protected ConfigContext m_configContext = null; 171 protected CustomMBeanOperationsMBean cmo = null; 172 protected CustomMBeanConfigQueries cmcq = null; 173 174 protected static final Object [] emptyParams = new Object []{}; 175 protected static final String [] emptySignature = new String []{}; 176 177 178 protected static StringManager localStrings = 179 StringManager.getManager( ApplicationsConfigMBean.class ); 180 181 182 protected static final String TYPE_APPLICATION = "application"; 183 protected static final String TYPE_EJB = "ejb"; 184 protected static final String TYPE_WEB = "web"; 185 protected static final String TYPE_CONNECTOR = "connector"; 186 protected static final String TYPE_APPCLIENT = "appclient"; 187 188 protected static final String JSR88_TYPE_APPLICATION = "ear"; 189 protected static final String JSR88_TYPE_EJB = "ejb"; 190 protected static final String JSR88_TYPE_WEB = "war"; 191 protected static final String JSR88_TYPE_CONNECTOR = "rar"; 192 protected static final String JSR88_TYPE_APPCLIENT = "car"; 193 194 protected static final String DOMAIN_TARGET = "domain"; 195 196 protected static final DeployableObjectType[] deployableObjectTypes = 197 new DeployableObjectType[] { 198 DeployableObjectType.APP, 199 DeployableObjectType.EJB, 200 DeployableObjectType.WEB, 201 DeployableObjectType.CONN, 202 DeployableObjectType.CAR, 203 DeployableObjectType.LCM, 204 DeployableObjectType.CMB 205 }; 206 207 209 private static final TargetType[] VALID_LIST_TYPES = new TargetType[] { 210 TargetType.CLUSTER, TargetType.SERVER, TargetType.DAS, TargetType.DOMAIN}; 211 212 213 218 public ApplicationsConfigMBean(String instanceName, ConfigContext configContext) throws MBeanConfigException { 219 super(); 220 mInstanceName = instanceName; 221 m_configContext = configContext; 222 deployService = DeploymentService.getDeploymentService(configContext); 223 initCustomMBeanHandlers(); 224 } 225 226 public ApplicationsConfigMBean() throws MBeanConfigException { 227 super(); 228 initCustomMBeanHandlers(); 229 } 230 231 protected void initCustomMBeanHandlers() { 232 cmo = new BasicCustomMBeanOperations(); 233 cmcq = new BasicCustomMBeanConfigQueries(); 234 } 235 236 private DeploymentTarget getAndValidateDeploymentTarget(String targetName, 237 String appName, boolean isRegistered) throws IASDeploymentException 238 { 239 return getAndValidateDeploymentTarget(targetName, appName, isRegistered, false); 240 } 241 242 private DeploymentTarget getAndValidateDeploymentTarget(String targetName, 243 String appName, boolean isRegistered, boolean isDeleting) throws IASDeploymentException 244 { 245 try { 246 final DeploymentTarget target = getTargetFactory().getTarget( 247 getConfigContext(), getDomainName(), targetName); 248 249 if (isRegistered) { 250 if (targetName == null) { 251 targetName = target.getTarget().getName(); 253 } 254 if (target.getTarget().getType() == TargetType.DOMAIN && isDeleting) { 255 if (ApplicationHelper.isApplicationReferenced(getConfigContext(), appName)) { 258 throw new IASDeploymentException(localStrings.getString("applicationIsReferenced", 259 appName, ApplicationHelper.getApplicationReferenceesAsString( 260 getConfigContext(), appName))); 261 } 262 } 263 else if (target.getTarget().getType() == TargetType.SERVER || 264 target.getTarget().getType() == TargetType.DAS) { 265 if (!ServerHelper.serverReferencesApplication(getConfigContext(), 269 targetName, appName) && isDeleting) { 270 throw new IASDeploymentException(localStrings.getString("serverApplicationRefDoesNotExist", 271 targetName, appName)); 272 } else if (!ApplicationHelper.isApplicationReferencedByServerOnly(getConfigContext(), 273 appName, targetName)) { 274 throw new IASDeploymentException(localStrings.getString("applicationHasMultipleRefs", 275 targetName, appName, ApplicationHelper.getApplicationReferenceesAsString( 276 getConfigContext(), appName))); 277 } 278 } else if (target.getTarget().getType() == TargetType.CLUSTER) { 279 if (!ClusterHelper.clusterReferencesApplication(getConfigContext(), 283 targetName, appName) && isDeleting) { 284 throw new IASDeploymentException(localStrings.getString("clusterApplicationRefDoesNotExist", 285 targetName, appName)); 286 } else if (!ApplicationHelper.isApplicationReferencedByClusterOnly(getConfigContext(), 287 appName, targetName)) { 288 throw new IASDeploymentException(localStrings.getString("applicationHasMultipleRefs", 289 targetName, appName, ApplicationHelper.getApplicationReferenceesAsString( 290 getConfigContext(), appName))); 291 } 292 } 293 } 294 return target; 295 } catch (IASDeploymentException ex) { 296 throw (ex); 297 } catch (Exception ex) { 298 throw new IASDeploymentException(ex); 299 } 300 } 301 302 316 public DeploymentStatus deploy(Properties props, String [] targets) 317 throws DeploymentException{ 318 DeploymentStatus status = null; 319 props.setProperty(DeploymentProperties.TARGET, targets[0]); 320 status = deploy(props); 321 for(int i = 1; i < targets.length; i++) { 322 try { 323 associateApplication(props, targets[i]); 324 } catch(MBeanConfigException m) { 325 DeploymentException e = new DeploymentException(m.getMessage()); 326 e.initCause(m); 327 throw e; 328 } 329 } 330 return status; 331 } 332 333 348 public void associateApplication(Properties props, String targetName) 349 throws MBeanConfigException { 350 try { 351 final DeploymentTarget target = getTargetFactory().getTarget( 352 getConfigContext(), getDomainName(), targetName); 353 boolean enabled = new Boolean (props.getProperty( 354 DeploymentProperties.ENABLE)).booleanValue(); 355 target.addAppReference( 356 props.getProperty(DeploymentProperties.NAME), 357 enabled, 358 props.getProperty(DeploymentProperties.VIRTUAL_SERVERS)); 359 } catch(Exception e) { 360 MBeanConfigException m = new MBeanConfigException(e.getMessage()); 361 m.initCause(e); 362 throw m; 363 } 364 } 365 366 380 public DeploymentStatus undeploy(Properties props, String [] targets) 381 throws DeploymentException{ 382 DeploymentStatus status = null; 383 props.setProperty(DeploymentProperties.TARGET, targets[0]); 384 for(int i = 1; i < targets.length; i++) { 385 try { 386 disassociateApplication(props, targets[i]); 387 } catch (MBeanConfigException m) { 388 DeploymentException e = new DeploymentException(m.getMessage()); 389 e.initCause(m); 390 throw e; 391 } 392 } 393 status = undeploy(props); 394 return status; 395 } 396 397 409 public void disassociateApplication(Properties props, String targetName) 410 throws MBeanConfigException { 411 try { 412 final DeploymentTarget target = getTargetFactory().getTarget( 413 getConfigContext(), getDomainName(), targetName); 414 target.removeAppReference( 415 props.getProperty(DeploymentProperties.NAME)); 416 } catch(Exception e) { 417 MBeanConfigException m = new MBeanConfigException(e.getMessage()); 418 m.initCause(e); 419 throw m; 420 } 421 } 422 423 432 public Integer getModuleType(String standAloneModuleName) 433 throws ServerInstanceException { 434 435 sLogger.log(Level.FINE, "getModuleType - begin" + 436 " standAloneModuleName = " + standAloneModuleName); 437 438 J2EEModule j2eeModule = new J2EEModule(standAloneModuleName); 440 441 ModuleType moduleType = j2eeModule.getModuleType(); 443 if (moduleType == null) { 444 return null; 445 } 446 447 return (new Integer (moduleType.getValue())); 448 } 449 450 451 455 public com.sun.enterprise.deployment.backend.DeploymentStatus deploy(Properties props) 456 throws DeploymentException 457 { 458 DeploymentProperties dProps = new DeploymentProperties(props); 459 String archiveName = dProps.getArchiveName(); 460 String name = dProps.getName(archiveName); 461 DeployableObjectType type = getTypeFromFile(name, archiveName); 462 if(archiveName == null) 463 throw new IllegalArgumentException ("archiveName not specified"); 464 465 sLogger.log(Level.FINE, "mbean.begin_deploy", archiveName); 466 467 java.io.File deployFile = new java.io.File (archiveName); 468 int actionCode = BaseDeployEvent.APPLICATION_DEPLOYED; 469 try { 470 InstanceEnvironment env = new InstanceEnvironment(getInstanceName()); 471 DeploymentRequest req = new DeploymentRequest( 472 env, 473 type, 474 DeploymentCommand.DEPLOY); 475 476 477 480 boolean isRegistered = false ; ObjectName componentON = 482 getRegisteredComponentObjectName(name, type); 483 484 if(componentON != null) 485 isRegistered = true; 486 487 if(isRegistered) 488 validate(componentON, REDEPLOY_ACTION); 489 490 if(type.isAPP()) 491 { 492 actionCode = BaseDeployEvent.APPLICATION_DEPLOYED; 493 } 494 else 495 { 496 actionCode = BaseDeployEvent.MODULE_DEPLOYED; 497 } 498 499 req.setFileSource(deployFile); 500 req.setName(name); 501 req.setForced(dProps.getForce()); 502 req.setCascade(true); 504 if(type.isWEB()) { 505 req.setDefaultContextRoot(dProps.getDefaultContextRoot( 506 archiveName)); 507 req.setContextRoot(dProps.getContextRoot()); 508 } 509 req.setVerifying(dProps.getVerify()); 510 req.setPrecompileJSP(dProps.getPrecompileJSP()); 511 req.setGenerateRMIStubs(dProps.getGenerateRMIStubs()); 512 req.setAvailabilityEnabled(dProps.getAvailabilityEnabled()); 513 req.setStartOnDeploy(dProps.getEnable()); 514 req.setDescription(dProps.getDescription()); 515 req.setActionCode(actionCode); 516 DeploymentServiceUtils.setResourceOptionsInRequest(req, dProps); 517 final DeploymentTarget target = getAndValidateDeploymentTarget(dProps.getTarget(), 518 name, isRegistered); 519 req.setTarget(target); 520 521 Properties optionalAttributes = new Properties (); 522 String virtualServers = dProps.getVirtualServers(); 524 if(virtualServers!=null) 525 optionalAttributes.put(ServerTags.VIRTUAL_SERVERS, dProps.getVirtualServers()); 526 req.setOptionalAttributes(optionalAttributes); 527 if(props == null) 528 props = new Properties (); 529 else 530 props = dProps.prune(); 531 req.addOptionalArguments(props); 532 533 setHostAndPort(req); 534 return getDeploymentService().deploy(req); 535 } 536 catch(Exception e) { 537 if (actionCode == BaseDeployEvent.APPLICATION_DEPLOYED) { 538 sLogger.log(Level.WARNING, "mbean.deploy_failed", e); 539 } 540 else { 541 sLogger.log(Level.WARNING, "mbean.redeploy_failed", e); 542 } 543 DeploymentStatus ds = new DeploymentStatus(); 544 ds.setStageException(e); 545 ds.setStageStatus(DeploymentStatus.FAILURE); 546 ds.setStageStatusMessage(e.getMessage()); 547 ds.setStageDescription("Deployment"); 548 return ds; 549 } 550 finally { 551 deleteFile(archiveName); 552 } 553 } 554 556 557 567 public com.sun.enterprise.deployment.backend.DeploymentStatus undeploy(Properties props) 568 throws DeploymentException { 569 String name = props.getProperty(DeploymentProperties.NAME); 570 if(name == null) 571 throw new DeploymentException("name not specified in undeploy"); 572 573 sLogger.log(Level.FINE, "mbean.begin_undeploy", name); 574 try { 575 576 DeployableObjectType objectType = getRegisteredType(name); 577 578 ObjectName componentON = 579 getRegisteredComponentObjectName(name,objectType); 580 validate(componentON, UNDEPLOY_ACTION); 581 582 if (objectType.isWEB()) { 584 checkWebModuleReferences(name); 585 } 586 DeploymentRequest req = new DeploymentRequest( 588 new InstanceEnvironment(getInstanceName()), 589 objectType, DeploymentCommand.UNDEPLOY); 590 DeploymentProperties dProps = new DeploymentProperties(props); 591 req.setName(name); 592 req.setCascade(dProps.getCascade()); 593 req.setReload(dProps.getReload()); 594 req.setForced(false); 595 DeploymentServiceUtils.setResourceOptionsInRequest(req, dProps); 596 597 if(props == null) 598 props = new Properties (); 599 else 600 props = dProps.prune(); 601 602 req.addOptionalArguments(props); 603 604 if(objectType.isAPP()) 605 req.setActionCode(BaseDeployEvent.APPLICATION_UNDEPLOYED); 606 else 607 req.setActionCode(BaseDeployEvent.MODULE_UNDEPLOYED); 608 609 final DeploymentTarget target = getAndValidateDeploymentTarget(dProps.getTarget(), 610 name, true, true); 611 req.setTarget(target); 612 613 return getDeploymentService().undeploy(req); 614 } 615 catch(Exception e) { 616 sLogger.log(Level.WARNING, "mbean.undeploy_failed", e); 617 DeploymentStatus ds = new DeploymentStatus(); 618 ds.setStageException(e); 619 ds.setStageStatus(DeploymentStatus.FAILURE); 620 ds.setStageStatusMessage(e.getMessage()); 621 ds.setStageDescription("Undeployment"); 622 return ds; 623 } 624 } 625 626 public DeploymentStatus createApplicationReference(String targetName, 627 boolean enabled, String virtualServers, String referenceName) { 628 try { 629 sLogger.log(Level.FINE, "mbean.create_app_reference", 630 referenceName); 631 return DeploymentService.getDeploymentService().associate(targetName, enabled, virtualServers, referenceName); 632 } catch (Exception e) { 633 sLogger.log(Level.WARNING, "mbean.create_app_reference_failed", 634 e); 635 DeploymentStatus ds = new DeploymentStatus(); 636 ds.setStageException(e); 637 ds.setStageStatus(DeploymentStatus.FAILURE); 638 ds.setStageStatusMessage(e.getMessage()); 639 ds.setStageDescription("Association"); 640 return ds; 641 } 642 } 643 644 public DeploymentStatus deleteApplicationReference(String targetName, 645 String referenceName) { 646 try { 647 sLogger.log(Level.FINE, "mbean.delete_app_reference", 648 referenceName); 649 return DeploymentService.getDeploymentService( 650 ).disassociate(targetName, referenceName); 651 } catch (Exception e) { 652 sLogger.log(Level.WARNING, "mbean.delete_app_reference_failed", 653 e); 654 DeploymentStatus ds = new DeploymentStatus(); 655 ds.setStageException(e); 656 ds.setStageStatus(DeploymentStatus.FAILURE); 657 ds.setStageStatusMessage(e.getMessage()); 658 ds.setStageDescription("Disassociation"); 659 return ds; 660 } 661 } 662 663 public DeploymentStatus createApplicationReference(String targetName, 664 String referenceName, Map options) { 665 try { 666 sLogger.log(Level.FINE, "mbean.create_app_reference", 667 referenceName); 668 return DeploymentService.getDeploymentService().associate(targetName, 669 referenceName, options); 670 } catch (Exception e) { 671 sLogger.log(Level.WARNING, "mbean.create_app_reference_failed", 672 e); 673 DeploymentStatus ds = new DeploymentStatus(); 674 ds.setStageException(e); 675 ds.setStageStatus(DeploymentStatus.FAILURE); 676 ds.setStageStatusMessage(e.getMessage()); 677 ds.setStageDescription("Association"); 678 return ds; 679 } 680 } 681 682 public Map createApplicationReferenceAndReturnStatusAsMap( 683 String targetName, String referenceName, Map options) { 684 DeploymentStatus oldStatus = createApplicationReference(targetName, 685 referenceName, options); 686 return oldStatus.asMap(); 687 } 688 689 public DeploymentStatus deleteApplicationReference(String targetName, 690 String referenceName, Map options) { 691 try { 692 sLogger.log(Level.FINE, "mbean.delete_app_reference", 693 referenceName); 694 return DeploymentService.getDeploymentService( 695 ).disassociate(targetName, referenceName, options); 696 } catch (Exception e) { 697 sLogger.log(Level.WARNING, "mbean.delete_app_reference_failed", 698 e); 699 DeploymentStatus ds = new DeploymentStatus(); 700 ds.setStageException(e); 701 ds.setStageStatus(DeploymentStatus.FAILURE); 702 ds.setStageStatusMessage(e.getMessage()); 703 ds.setStageDescription("Disassociation"); 704 return ds; 705 } 706 } 707 708 public Map deleteApplicationReferenceAndReturnStatusAsMap( 709 String targetName, String referenceName, Map options) { 710 DeploymentStatus oldStatus = deleteApplicationReference(targetName, 711 referenceName, options); 712 return oldStatus.asMap(); 713 } 714 715 public DeploymentStatus start(String moduleID, String targetName, 716 Map options) { 717 try { 718 sLogger.log(Level.FINE, "mbean.start", moduleID); 719 return DeploymentService.getDeploymentService().start(moduleID, 720 targetName, options); 721 } catch (Exception e) { 722 sLogger.log(Level.WARNING, "mbean.start_failed", e); 723 DeploymentStatus ds = new DeploymentStatus(); 724 ds.setStageException(e); 725 ds.setStageStatus(DeploymentStatus.FAILURE); 726 ds.setStageStatusMessage(e.getMessage()); 727 ds.setStageDescription("Start"); 728 return ds; 729 } 730 } 731 732 public Map startAndReturnStatusAsMap( 733 String moduleID, String targetName, Map options) { 734 DeploymentStatus oldStatus = start(moduleID, targetName, options); 735 return oldStatus.asMap(); 736 } 737 738 public DeploymentStatus stop(String moduleID, String targetName, 739 Map options) { 740 try { 741 sLogger.log(Level.FINE, "mbean.stop", moduleID); 742 return DeploymentService.getDeploymentService().stop(moduleID, 743 targetName, options); 744 } catch (Exception e) { 745 sLogger.log(Level.WARNING, "mbean.stop_failed", e); 746 DeploymentStatus ds = new DeploymentStatus(); 747 ds.setStageException(e); 748 ds.setStageStatus(DeploymentStatus.FAILURE); 749 ds.setStageStatusMessage(e.getMessage()); 750 ds.setStageDescription("Stop"); 751 return ds; 752 } 753 } 754 755 public Map stopAndReturnStatusAsMap( 756 String moduleID, String targetName, Map options) { 757 DeploymentStatus oldStatus = stop(moduleID, targetName, options); 758 return oldStatus.asMap(); 759 } 760 761 781 public boolean deployJ2EEApplication(Properties props) 782 throws DeploymentException { 783 784 DeploymentProperties dProps = new DeploymentProperties(props); 785 String archiveName = dProps.getArchiveName(); 786 if(archiveName == null) 787 throw new IllegalArgumentException ("archiveName not specified"); 788 sLogger.log(Level.FINE, "mbean.begin_deploy", archiveName); 789 java.io.File deployFile = new java.io.File (archiveName); 790 int actionCode = BaseDeployEvent.APPLICATION_DEPLOYED; 791 try { 792 793 794 InstanceEnvironment env = new InstanceEnvironment(getInstanceName()); 795 DeploymentRequest req = new DeploymentRequest( 796 env, 797 DeployableObjectType.APP, 798 DeploymentCommand.DEPLOY); 799 800 801 String appName = dProps.getName(archiveName); 802 805 boolean isAppExists = isRegistered(appName, DeployableObjectType.APP); 806 actionCode = (isAppExists && dProps.getForce()) ? 807 BaseDeployEvent.APPLICATION_REDEPLOYED : BaseDeployEvent.APPLICATION_DEPLOYED; 808 req.setFileSource(deployFile); 809 req.setName(appName); 810 req.setForced(dProps.getForce()); 811 req.setVerifying(dProps.getVerify()); 812 req.setPrecompileJSP(dProps.getPrecompileJSP()); 813 req.setStartOnDeploy(dProps.getEnable()); 814 req.setActionCode(actionCode); 815 final DeploymentTarget target = getAndValidateDeploymentTarget(dProps.getTarget(), 816 appName, isAppExists); 817 req.setTarget(target); 818 819 Properties optionalAttributes = new Properties (); 820 String virtualServers = dProps.getVirtualServers(); 822 if(virtualServers!=null) 823 optionalAttributes.put(ServerTags.VIRTUAL_SERVERS, dProps.getVirtualServers()); 824 req.setOptionalAttributes(optionalAttributes); 825 if(props == null) 826 props = new Properties (); 827 else 828 props = dProps.prune(); 829 req.addOptionalArguments(props); 830 831 setHostAndPort(req); 832 833 getDeploymentService().deploy(req); 834 } 835 catch(Exception e) { 836 if (actionCode == BaseDeployEvent.APPLICATION_DEPLOYED) { 837 sLogger.log(Level.WARNING, "mbean.deploy_failed", e); 838 } 839 else { 840 sLogger.log(Level.WARNING, "mbean.redeploy_failed", e); 841 } 842 DeploymentException newE = new DeploymentException(e.getMessage()); 843 newE.initCause(e); 844 throw newE; 845 } 846 finally { 847 deleteFile(archiveName); 848 } 849 return true; 850 } 851 852 853 872 public boolean deployEJBJarModule(Properties props) 873 throws DeploymentException { 874 875 DeploymentProperties dProps = new DeploymentProperties(props); 876 String filePath = dProps.getArchiveName(); 877 if (filePath == null) { 878 throw new IllegalArgumentException (); 879 } 880 boolean loadStatus = true; 881 sLogger.log(Level.FINE, "deploymentservice.begin_deploy", filePath); 882 java.io.File deployFile = new java.io.File (filePath); 883 int actionCode = BaseDeployEvent.MODULE_DEPLOYED; 884 try { 885 886 887 InstanceEnvironment env = new InstanceEnvironment(getInstanceName()); 888 DeploymentRequest req = new DeploymentRequest( 890 env, 891 DeployableObjectType.EJB, 892 DeploymentCommand.DEPLOY); 893 894 String moduleName = dProps.getName(filePath); 895 boolean isModuleExists = isRegistered(moduleName, 896 DeployableObjectType.EJB); 897 actionCode = (isModuleExists && dProps.getForce()) ? 898 BaseDeployEvent.MODULE_REDEPLOYED : BaseDeployEvent.MODULE_DEPLOYED; 899 req.setFileSource(deployFile); 900 req.setName(moduleName); 901 req.setForced(dProps.getForce()); 903 req.setVerifying(dProps.getVerify()); 904 req.setStartOnDeploy(dProps.getEnable()); 905 req.setActionCode(actionCode); 906 final DeploymentTarget target = getAndValidateDeploymentTarget(dProps.getTarget(), 907 moduleName, isModuleExists); 908 req.setTarget(target); 909 if(props == null) 910 props = new Properties (); 911 else 912 props = dProps.prune(); 913 req.addOptionalArguments(props); 914 916 getDeploymentService().deploy(req); 917 } 918 catch(Exception e) { 919 if (actionCode == BaseDeployEvent.MODULE_DEPLOYED) { 920 sLogger.log(Level.WARNING, "mbean.deploy_failed", e); 921 } 922 else { 923 sLogger.log(Level.WARNING, "mbean.redeploy_failed", e); 924 } 925 throw new DeploymentException(e.getMessage()); 926 } 927 finally { 928 deleteFile(filePath); 929 } 930 return loadStatus; 931 } 932 933 955 public boolean deployWarModule(Properties props) 956 throws DeploymentException { 957 958 DeploymentProperties dProps = new DeploymentProperties(props); 959 String filePath = dProps.getArchiveName(); 960 if (filePath == null) { 961 throw new IllegalArgumentException (); 962 } 963 964 boolean loadStatus = true; 965 sLogger.log(Level.FINE, "mbean.begin_deploy", filePath); 966 java.io.File deployFile = new java.io.File (filePath); 967 int actionCode = BaseDeployEvent.MODULE_DEPLOYED; 968 try { 969 970 InstanceEnvironment env = new InstanceEnvironment(getInstanceName()); 971 972 DeploymentRequest req = new DeploymentRequest( 974 env, 975 DeployableObjectType.WEB, 976 DeploymentCommand.DEPLOY); 977 978 String webAppName = dProps.getName(filePath); 979 boolean isModuleExists = isRegistered(webAppName, 980 DeployableObjectType.WEB); 981 actionCode = (isModuleExists && dProps.getForce()) ? 982 BaseDeployEvent.MODULE_REDEPLOYED : BaseDeployEvent.MODULE_DEPLOYED; 983 984 req.setFileSource(deployFile); 985 req.setName(webAppName); 986 req.setContextRoot(dProps.getContextRoot()); 987 req.setForced(dProps.getForce()); 988 req.setVerifying(dProps.getVerify()); 989 req.setPrecompileJSP(dProps.getPrecompileJSP()); 990 req.setStartOnDeploy(dProps.getEnable()); 991 req.setActionCode(actionCode); 992 final DeploymentTarget target = getAndValidateDeploymentTarget(dProps.getTarget(), 993 webAppName, isModuleExists); 994 req.setTarget(target); 995 setHostAndPort(req); 998 Properties optionalAttributes = new Properties (); 999 String virtualServers = dProps.getVirtualServers(); 1001 if(virtualServers!=null) 1002 optionalAttributes.put(ServerTags.VIRTUAL_SERVERS, virtualServers); 1003 req.setOptionalAttributes(optionalAttributes); 1004 1005 getDeploymentService().deploy(req); 1006 } 1007 catch(Exception e) { 1008 if (actionCode == BaseDeployEvent.MODULE_DEPLOYED) { 1009 sLogger.log(Level.WARNING, "mbean.deploy_failed", e); 1010 } 1011 else { 1012 sLogger.log(Level.WARNING, "mbean.redeploy_failed", e); 1013 } 1014 throw new DeploymentException(e.getMessage()); 1015 } 1016 finally { 1017 deleteFile(filePath); 1018 } 1019 return loadStatus; 1020 } 1021 1022 1040 public boolean deployConnectorModule(Properties props) 1041 throws DeploymentException { 1042 1043 DeploymentProperties dProps = new DeploymentProperties(props); 1044 String filePath = dProps.getArchiveName(); 1045 if (filePath == null) { 1046 throw new IllegalArgumentException (); 1047 } 1048 1049 boolean loadStatus = true; 1050 sLogger.log(Level.FINE, "mbean.begin_deploy", filePath); 1051 java.io.File deployFile = new java.io.File (filePath); 1052 int actionCode = BaseDeployEvent.MODULE_DEPLOYED; 1053 try { 1054 1055 InstanceEnvironment env = new InstanceEnvironment(getInstanceName()); 1056 1057 DeploymentRequest req = new DeploymentRequest( 1058 env, 1059 DeployableObjectType.CONN, 1060 DeploymentCommand.DEPLOY); 1061 1062 String moduleName = dProps.getName(filePath); 1063 boolean isModuleExists = isRegistered(moduleName, 1064 DeployableObjectType.CONN); 1065 actionCode = (isModuleExists && dProps.getForce()) ? 1066 BaseDeployEvent.MODULE_REDEPLOYED : BaseDeployEvent.MODULE_DEPLOYED; 1067 1068 req.setFileSource(deployFile); 1069 req.setName(moduleName); 1070 req.setForced(dProps.getForce()); 1071 req.setVerifying(dProps.getVerify()); 1072 req.setActionCode(actionCode); 1073 final DeploymentTarget target = getAndValidateDeploymentTarget(dProps.getTarget(), 1074 moduleName, isModuleExists); 1075 req.setTarget(target); 1076 req.setStartOnDeploy(dProps.getEnable()); 1077 1079 setDeployDirOwner(req, env); 1080 getDeploymentService().deploy(req); 1081 } 1082 catch(Exception e) { 1083 if (actionCode == BaseDeployEvent.MODULE_DEPLOYED) { 1084 sLogger.log(Level.WARNING, "mbean.deploy_failed", e); 1085 } 1086 else { 1087 sLogger.log(Level.WARNING, "mbean.redeploy_failed", e); 1088 } 1089 throw new DeploymentException(e.getMessage()); 1090 } 1091 finally { 1092 deleteFile(filePath); 1093 } 1094 return loadStatus; 1095 } 1096 1097 1104 1105 public String [] getTargets() throws MBeanConfigException{ 1106 try{ 1107 1108 ArrayList targetList = new ArrayList (); 1109 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 1110 1122 1125 try{ 1126 ObjectName serversON = new ObjectName (getDomainName()+":type=servers,category=config"); 1127 ObjectName [] serverONArr = (ObjectName [])mbs.invoke(serversON, "getServer", emptyParams, emptySignature); 1128 for(int i = 0; i<serverONArr.length; i++){ 1129 targetList.add(mbs.getAttribute(serverONArr[i], "name")); 1130 } 1131 }catch(Exception e) 1132 { 1133 targetList.add("server"); 1134 } 1135 1136 return (String [])targetList.toArray(new String []{}); 1137 1138 }catch(Throwable t) { 1139 throw new MBeanConfigException(t.getMessage()); 1140 } 1141 } 1142 1143 1149 public String [] getAvailableModules(String moduleType) throws MBeanConfigException { 1150 String target = DEFAULT_TARGET; 1151 return getAvailableModules(moduleType, new String []{target}); 1152 } 1153 1154 1160 public String [] getAvailableModules(String moduleType, String [] targetList) 1161 throws MBeanConfigException { 1162 return getAvailableModules(moduleType, targetList, false); 1163 } 1164 1165 1172 public String [] getAvailableUserModules(String moduleType, 1173 String [] targetList) 1174 throws MBeanConfigException { 1175 return getAvailableModules(moduleType, targetList, true); 1176 } 1177 1178 1187 private String [] getAvailableModules(String moduleType, String [] targetList, 1188 boolean excludeSystemApps) 1189 throws MBeanConfigException { 1190 try{ 1191 DeployableObjectType type = getDeployableObjectType(moduleType); 1192 ArrayList listOfModules = new ArrayList (); 1193 for(int i = 0 ; i< targetList.length;i++) 1194 { 1195 listOfModules.addAll(getModules(targetList[i], type, null, excludeSystemApps)); 1196 } 1197 return (String [])listOfModules.toArray(new String [listOfModules.size()]); 1198 }catch(Exception e){ 1199 throw new MBeanConfigException(e.getMessage()); 1200 } 1201 } 1202 1203 1210 public String [] getRunningModules(String moduleType, String [] targetList) 1211 throws MBeanConfigException { 1212 return getRunningModules(moduleType, targetList, false); 1213 } 1214 1215 1222 public String [] getRunningUserModules(String moduleType, String [] targetList) 1223 throws MBeanConfigException { 1224 return getRunningModules(moduleType, targetList, true); 1225 } 1226 1227 1236 private String [] getRunningModules(String moduleType, String [] targetList, 1237 boolean excludeSystemApps) 1238 throws MBeanConfigException { 1239 try{ 1240 DeployableObjectType type = getDeployableObjectType(moduleType); 1241 ArrayList listOfModules= new ArrayList (); 1242 for(int i = 0 ; i< targetList.length;i++) 1243 { 1244 listOfModules.addAll(getModules(targetList[i], type, 1245 new Boolean (true), excludeSystemApps)); 1246 } 1247 return (String [])listOfModules.toArray(new String [listOfModules.size()]); 1248 }catch(Exception e){ 1249 throw new MBeanConfigException(e.getMessage()); 1250 } 1251 } 1252 1253 1260 1261 public String [] getNonRunningModules(String moduleType, String [] targetList) 1262 throws MBeanConfigException { 1263 return getNonRunningModules(moduleType, targetList, false); 1264 } 1265 1266 1273 public String [] getNonRunningUserModules(String moduleType, String [] targetList) 1274 throws MBeanConfigException { 1275 return getNonRunningModules(moduleType, targetList, false); 1276 } 1277 1278 1287 private String [] getNonRunningModules(String moduleType, 1288 String [] targetList, boolean excludeSystemApps) 1289 throws MBeanConfigException { 1290 try{ 1291 DeployableObjectType type = getDeployableObjectType(moduleType); 1292 ArrayList listOfModules= new ArrayList (); 1293 for(int i = 0 ; i< targetList.length;i++) 1294 { 1295 listOfModules.addAll(getModules(targetList[i], type, new Boolean (false), excludeSystemApps)); 1296 } 1297 return (String [])listOfModules.toArray(new String [listOfModules.size()]); 1298 }catch(Exception e){ 1299 throw new MBeanConfigException(e.getMessage()); 1300 } 1301 } 1302 1303 1310 public String [] getDeployedJ2EEApplications() throws ServerInstanceException { 1311 String [] apps = new String [0]; 1312 try { 1313 sLogger.log(Level.FINE, "mbean.list_components"); 1314 Applications appsConfigBean = 1315 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 1316 getConfigContext(), ServerXPathHelper.XPATH_APPLICATIONS); 1317 J2eeApplication[] j2eeApps = appsConfigBean.getJ2eeApplication(); 1318 if (j2eeApps != null) { 1319 apps = new String [j2eeApps.length]; 1320 for(int i=0; i<j2eeApps.length; i++) { 1321 apps[i] = j2eeApps[i].getName(); 1322 } 1323 } 1324 } 1325 catch (Exception e) { 1326 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1327 throw new ServerInstanceException(e.getLocalizedMessage()); 1328 } 1329 return ( apps ); 1330 } 1331 1332 1339 public String [] getDeployedEJBModules() throws ServerInstanceException { 1340 String [] ejbModules = new String [0]; 1341 try { 1342 sLogger.log(Level.FINE, "mbean.list_components"); 1343 Applications appsConfigBean = 1344 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 1345 getConfigContext(), ServerXPathHelper.XPATH_APPLICATIONS); 1346 EjbModule[] modules = appsConfigBean.getEjbModule(); 1347 if (modules != null) { 1348 ejbModules = new String [modules.length]; 1349 for(int i=0; i<modules.length; i++) { 1350 ejbModules[i] = modules[i].getName(); 1351 } 1352 } 1353 } 1354 catch (Exception e) { 1355 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1356 throw new ServerInstanceException(e.getLocalizedMessage()); 1357 } 1358 return ejbModules; 1359 } 1360 1361 1368 public String [] getDeployedWebModules() throws ServerInstanceException { 1369 String [] webModules = new String [0]; 1370 try { 1371 sLogger.log(Level.FINE, "mbean.list_components"); 1372 Applications appsConfigBean = 1373 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 1374 getConfigContext(), ServerXPathHelper.XPATH_APPLICATIONS); 1375 WebModule[] modules = appsConfigBean.getWebModule(); 1376 if (modules != null) { 1377 webModules = new String [modules.length]; 1378 for(int i=0; i<modules.length; i++) { 1379 webModules[i] = modules[i].getName(); 1380 } 1381 } 1382 } 1383 catch (Exception e) { 1384 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1385 throw new ServerInstanceException(e.getLocalizedMessage()); 1386 } 1387 return webModules; 1388 } 1389 1390 1396 public String [] getDeployedConnectors() throws ServerInstanceException { 1397 String [] connectors = new String [0]; 1398 try { 1399 sLogger.log(Level.FINE, "mbean.list_components"); 1400 Applications appsConfigBean = 1401 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 1402 getConfigContext(), ServerXPathHelper.XPATH_APPLICATIONS); 1403 ConnectorModule[] connectorConfigBeans = 1404 appsConfigBean.getConnectorModule(); 1405 if (connectorConfigBeans != null) { 1406 connectors = new String [connectorConfigBeans.length]; 1407 for(int i = 0; i < connectors.length; i++) { 1408 connectors[i] = connectorConfigBeans[i].getName(); 1409 } 1410 } 1411 } 1412 catch (Exception e) { 1413 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1414 throw new ServerInstanceException(e.getLocalizedMessage()); 1415 } 1416 return connectors; 1417 } 1418 1419 1420 1426 public ObjectName [] getAllDeployedComponents() throws ServerInstanceException { 1427 1428 int totalCount=0; 1429 ObjectName [] allComponents = null; 1430 1431 try { 1432 sLogger.log(Level.FINE, "mbean.list_components"); 1433 ObjectName [] components= null; 1434 for(int count = 0; count < deployableObjectTypes.length; count++) { 1435 components = getAllRegisteredComponentsOfType(deployableObjectTypes[count]); 1436 if(components != null && components.length > 0) { 1437 totalCount=totalCount+components.length; 1438 } 1439 } 1440 allComponents = new ObjectName [totalCount]; 1441 1442 if(totalCount > 0) { 1443 totalCount=0; 1444 for(int count = 0; count < deployableObjectTypes.length; count++) { 1445 components = getAllRegisteredComponentsOfType(deployableObjectTypes[count]); 1446 if(components != null && components.length > 0) { 1447 1448 for(int count1=0; count1<components.length; count1++,totalCount++) { 1449 allComponents[totalCount] = components[count1]; 1451 1452 } 1453 } 1454 } 1455 } 1456 1457 } 1458 catch (Exception e) { 1459 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1460 throw new ServerInstanceException(e.getLocalizedMessage()); 1461 } 1462 return (allComponents); 1463 } 1464 1465 1466 1473 public ObjectName [] getAllDeployedJ2EEApplications() throws ServerInstanceException { 1474 return getAllRegisteredComponentsOfType(deployableObjectTypes[0]); 1475 } 1476 1477 1484 public ObjectName [] getAllDeployedEJBModules() throws ServerInstanceException { 1485 return getAllRegisteredComponentsOfType(deployableObjectTypes[1]); 1486 } 1487 1488 1495 public ObjectName [] getAllDeployedWebModules() throws ServerInstanceException { 1496 return getAllRegisteredComponentsOfType(deployableObjectTypes[2]); 1497 } 1498 1499 1505 public ObjectName [] getAllDeployedConnectors() throws ServerInstanceException { 1506 1507 return getAllRegisteredComponentsOfType(deployableObjectTypes[3]); 1508 } 1509 1510 1522 public String [] getEmbeddedConnectorNames(String appName, 1523 String targetName) throws ServerInstanceException 1524 { 1525 final List names = new ArrayList (); 1526 try { 1527 final com.sun.enterprise.admin.target.Target target = 1528 getListTarget(targetName); 1529 final String [] apps = filterAppsByTargetAndAppName(target, appName); 1530 for (int i = 0; i < apps.length; i++) { 1531 final Application ad = getDescrForApplication(apps[i]); 1532 final String app_name = ad.getRegistrationName(); 1533 final Set bds = ad.getRarDescriptors(); 1534 for(Iterator it = bds.iterator(); it.hasNext(); ) { 1535 final ConnectorDescriptor cd = (ConnectorDescriptor)it.next(); 1536 final String rarJndiName = app_name + 1537 ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER + 1538 FileUtils.makeFriendlyFilenameNoExtension(cd.getDeployName()); 1539 names.add(rarJndiName); 1540 } 1541 } 1542 } catch (ConfigException e) { 1543 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1544 throw new ServerInstanceException(e.getLocalizedMessage()); 1545 } 1546 return (String [])names.toArray(new String [0]); 1547 } 1548 1549 String [] filterAppsByTargetAndAppName( 1550 com.sun.enterprise.admin.target.Target target, String appName) 1551 throws ConfigException 1552 { 1553 1558 ObjectName [] appObjectNames = getAllRegisteredComponentsOfType( 1559 deployableObjectTypes[0]); 1560 if (target.getType() != 1561 com.sun.enterprise.admin.target.TargetType.DOMAIN) { 1562 final ApplicationRef[] appRefs = target.getApplicationRefs(); 1563 appObjectNames = ObjectNameAppRefComparator.intersect( 1564 appObjectNames, appRefs); 1565 } 1566 final Set s = new HashSet (); 1568 if (null != appObjectNames) { 1569 for (int i = 0; i < appObjectNames.length; i++) { 1570 s.add(appObjectNames[i].getKeyProperty(NAME)); 1571 } 1572 } 1573 if (null != appName) { 1575 if (s.contains(appName)) { 1576 return new String [] {appName}; 1577 } else { 1578 throw new ConfigException(localStrings.getString( 1579 "admin.mbeans.acmb.appRefDoesnotExistForTheTarget", 1580 appName, target.getName())); 1581 } 1582 } 1583 return (String [])s.toArray(new String [0]); 1584 } 1585 1586 1588 1595 public ObjectName [] getAllDeployedComponents(String targetName) 1596 throws ServerInstanceException 1597 { 1598 ObjectName [] oa = new ObjectName [0]; 1599 try 1600 { 1601 final com.sun.enterprise.admin.target.Target target = 1602 getListTarget(targetName); 1603 final ObjectName [] allComponents = getAllDeployedComponents(); 1604 if (target.getType() == TargetType.DOMAIN) 1605 { 1606 return allComponents; 1607 } 1608 final ApplicationRef[] appRefs = target.getApplicationRefs(); 1609 oa = ObjectNameAppRefComparator.intersect(allComponents, appRefs); 1610 } 1611 catch (Exception e) { 1612 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1613 throw new ServerInstanceException(e.getLocalizedMessage()); 1614 } 1615 return oa; 1616 } 1617 1618 protected com.sun.enterprise.admin.target.Target 1619 getListTarget(String targetName) throws ConfigException 1620 { 1621 return com.sun.enterprise.admin.target.TargetBuilder.INSTANCE.createTarget( 1622 VALID_LIST_TYPES, targetName, getConfigContext()); 1623 } 1624 1625 1630 public ObjectName [] getAllUserDeployedComponents() throws ServerInstanceException { 1631 1632 ObjectName [] allComponents = new ObjectName [0]; 1633 1634 ObjectName [] sysNuserComponents = getAllDeployedComponents(); 1635 1636 try { 1637 ArrayList arrList = new ArrayList (); 1638 1639 for (int i=0; i<sysNuserComponents.length; i++) { 1640 String type = sysNuserComponents[i].getKeyProperty("type"); 1641 if (type.equals("appclient-module")) { 1644 arrList.add(sysNuserComponents[i]); 1645 continue; 1646 } 1647 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 1650 String objectType = (String )mbs.getAttribute(sysNuserComponents[i], OBJECT_TYPE); 1651 if ((objectType != null) && 1652 (objectType.startsWith(Constants.SYSTEM_PREFIX))) { 1653 continue; 1654 } 1655 arrList.add(sysNuserComponents[i]); 1657 } 1658 if (!arrList.isEmpty()) { 1659 allComponents = (ObjectName [])arrList.toArray(new ObjectName [arrList.size()]); 1660 } 1661 1662 } catch (Exception e) { 1663 sLogger.log(Level.WARNING, "ApplicationsConfigMBean.getAllUserDeployedComponents", e); 1664 throw new ServerInstanceException(e.getLocalizedMessage()); 1665 } 1666 return (allComponents); 1667 } 1668 1669 1676 public ObjectName [] getAllUserDeployedComponents(String targetName) 1677 throws ServerInstanceException 1678 { 1679 ObjectName [] oa = new ObjectName [0]; 1680 try 1681 { 1682 final com.sun.enterprise.admin.target.Target target = 1683 getListTarget(targetName); 1684 final ObjectName [] allComponents = getAllUserDeployedComponents(); 1685 if (target.getType() == TargetType.DOMAIN) 1686 { 1687 return allComponents; 1688 } 1689 final ApplicationRef[] appRefs = target.getApplicationRefs(); 1690 oa = ObjectNameAppRefComparator.intersect(allComponents, appRefs); 1691 } 1692 catch (Exception e) { 1693 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1694 throw new ServerInstanceException(e.getLocalizedMessage()); 1695 } 1696 return oa; 1697 } 1698 1699 1707 public ObjectName [] getAllDeployedJ2EEApplications(String target) throws ServerInstanceException { 1708 return getAllRegisteredComponentsOfType(deployableObjectTypes[0]); 1710 } 1711 1712 1720 public ObjectName [] getAllDeployedEJBModules(String target) throws ServerInstanceException { 1721 return getAllRegisteredComponentsOfType(deployableObjectTypes[1]); 1723 } 1724 1725 1733 public ObjectName [] getAllDeployedWebModules(String target) throws ServerInstanceException { 1734 return getAllRegisteredComponentsOfType(deployableObjectTypes[2]); 1736 } 1737 1738 1745 public ObjectName [] getAllDeployedConnectors(String target) throws ServerInstanceException { 1746 return getAllRegisteredComponentsOfType(deployableObjectTypes[3]); 1748 } 1749 1750 1757 public ObjectName [] getAllDeployedAppclientModules(String target) 1758 throws ServerInstanceException 1759 { 1760 return getAllRegisteredComponentsOfType(DeployableObjectType.CAR); 1762 } 1763 1764 1772 public void enable(String appName, String type, String target) 1773 throws MBeanConfigException { 1774 1775 try{ 1776 ObjectName componentON = null; 1777 if(type != null) { 1778 DeployableObjectType objectType = getDeployableObjectType(type); 1779 componentON = getRegisteredComponentObjectName(appName, objectType); 1780 } else { 1781 componentON = getRegisteredComponentObjectName(appName); 1782 } 1783 1784 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 1785 1786 Attribute attr = new Attribute ("enabled","true"); 1790 if(componentON != null) { 1791 mbs.setAttribute(componentON, attr); 1792 } 1793 1794 if (!target.equals(DOMAIN_TARGET)) { 1797 setAppEnableInRefs(appName, target, true); 1798 } 1799 1800 }catch(Throwable te){ 1801 sLogger.log(Level.SEVERE, "enable", te); 1802 sLogger.log(Level.FINE,"enable exception"); 1803 throw new MBeanConfigException(te.getMessage()); 1804 } 1805 } 1806 1807 1815 public void disable(String appName, String type, String target) 1816 throws MBeanConfigException { 1817 try{ 1818 ObjectName componentON = null; 1819 1820 if(type != null) { 1821 DeployableObjectType objectType = getDeployableObjectType(type); 1822 componentON = getRegisteredComponentObjectName(appName, objectType); 1823 } 1824 else { 1825 componentON = getRegisteredComponentObjectName(appName); 1826 } 1827 1828 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 1829 1830 Attribute attr = new Attribute ("enabled","false"); 1831 if (target.equals(DOMAIN_TARGET)) { 1834 if(componentON != null ) { 1835 mbs.setAttribute(componentON, attr); 1836 } 1837 } else { 1838 setAppEnableInRefs(appName, target, false); 1842 } 1843 1844 } catch(Throwable te){ 1845 sLogger.log(Level.FINE,"disable exception"); 1846 throw new MBeanConfigException(te.getMessage()); 1847 } 1848 } 1849 1850 1851 1856 private void setAppEnableInRefs(String appName, String target, boolean enable) 1857 throws Exception { 1858 Attribute attr = new Attribute ("enabled", "" + enable); 1859 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 1860 ObjectName apprefON = getRegisteredAppRefObjectName(appName, target); 1861 1862 if (apprefON != null) { 1863 mbs.setAttribute(apprefON,attr); 1864 } 1865 1866 if (isCluster(target)) { 1867 ObjectName [] ons = getAllRefObjectNames(appName, target); 1868 if (ons != null) { 1869 for (int i = 0; i < ons.length; i ++ ) { 1870 mbs.setAttribute(ons[i],attr); 1871 } 1872 } 1873 } 1874 1875 } 1876 1877 1881 private ObjectName [] getAllRefObjectNames(String appName, String cluster) 1882 throws Exception { 1883 Server [] servers = ServerHelper.getServersInCluster(getConfigContext(), cluster); 1884 if(servers == null) return null; 1885 ObjectName [] ons = new ObjectName [servers.length]; 1886 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 1887 ObjectName serverON = null; 1888 for (int j = 0; j < servers.length; j ++ ) { 1889 serverON = super.getServerObjectName(servers[j].getName()); 1890 ObjectName [] apprefONArr = (ObjectName [])mbs.invoke(serverON, 1891 "getApplicationRef", emptyParams, emptySignature); 1892 for(int i =0; i< apprefONArr.length;i++) 1893 { 1894 String ref = (String )mbs.getAttribute(apprefONArr[i], "ref"); 1895 if(appName.equals(ref)) 1896 ons[j] = apprefONArr[i]; 1897 } 1898 } 1899 return ons; 1900 } 1901 1902 private boolean isCluster(String targetName) 1903 throws Exception { 1904 final com.sun.enterprise.admin.target.Target target = 1905 com.sun.enterprise.admin.target.TargetBuilder.INSTANCE.createTarget( 1906 VALID_LIST_TYPES, targetName, getConfigContext()); 1907 if (target.getType() == TargetType.CLUSTER) { 1908 return true; 1909 } 1910 return false; 1911 } 1912 1913 1923 public boolean getStatus(String name, String target) 1924 throws MBeanConfigException 1925 { 1926 try{ 1927 boolean appEnabled = true; 1928 boolean appRefEnabled = true; 1929 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 1930 ObjectName componentON = null; 1931 1932 try{ 1933 componentON = getRegisteredComponentObjectName(name); 1934 }catch(Exception e){ 1935 if(componentON == null) 1936 throw new MBeanConfigException(e.getMessage()); 1937 } 1938 String appEnabledStr = (String )mbs.getAttribute(componentON, 1939 ServerTags.ENABLED); 1940 1941 if("false".equalsIgnoreCase(appEnabledStr)) 1942 appEnabled = false; 1943 1944 if(!isDefaultTarget(target)) 1945 { 1946 ObjectName apprefON = 1947 getRegisteredAppRefObjectName(name, target); 1948 String appRefEnabledStr = 1949 (String )mbs.getAttribute(apprefON, ServerTags.ENABLED); 1950 if("false".equalsIgnoreCase(appRefEnabledStr)) 1951 appRefEnabled = false; 1952 1953 } 1954 1955 if(appEnabled && appRefEnabled) 1956 { 1957 return true; 1958 } 1959 1960 return false; 1961 1962 }catch(Exception e){ 1963 sLogger.log(Level.WARNING,"Exception in getStatus:"+e.getMessage()); 1964 throw new MBeanConfigException(e.getMessage()); 1965 } 1966 } 1967 1968 1969 1973 public boolean isRedeploySupported() 1974 throws MBeanConfigException { 1975 return true; 1976 } 1977 1978 1980 1986 public String [] getAvailableVersions(String appName, String type) throws MBeanConfigException { 1987 throw new MBeanConfigException("Notyet supported"); 1988 } 1989 1990 1997 public String getDefaultVersion(String appName, String type) throws MBeanConfigException { 1998 return ""; 1999 } 2000 2001 2007 public String getLastModified(String appName, String type) throws MBeanConfigException { 2008 return ""; 2009 } 2010 2011 2015 public boolean isRepositoryCleanerEnabled() throws MBeanConfigException { 2016 return true; 2017 } 2018 2019 2023 public int getRepositoryCleanerPollingInterval() throws MBeanConfigException { 2024 return 2; 2025 } 2026 2027 2031 public void setRepositoryCleanerPollingInterval(int interval) 2032 throws MBeanConfigException { 2033 } 2034 2035 2039 public int getMaxApplicationVersions() throws MBeanConfigException { 2040 return 10; 2041 } 2042 2043 2048 public void setMaxApplicationVersions(int maxVersions) 2049 throws MBeanConfigException { 2050 } 2051 2052 2054 2058 public boolean isAutoDeployEnabled() throws MBeanConfigException { 2059 return true; 2060 } 2061 2062 2065 public void setAutoDeployEnabled() throws MBeanConfigException { 2066 } 2067 2068 2072 public boolean isAutoDeployJspPreCompilationEnabled() 2073 throws MBeanConfigException { 2074 return true; 2075 } 2076 2077 2080 public void setAutoDeployJspPreCompilationEnabled() 2081 throws MBeanConfigException { 2082 } 2083 2084 2088 2090 public ObjectName [] getLifecycleModule(String targetName) throws Exception 2091 { 2092 final com.sun.enterprise.admin.target.Target target = 2093 com.sun.enterprise.admin.target.TargetBuilder.INSTANCE.createTarget( 2094 VALID_LIST_TYPES, targetName, getConfigContext()); 2095 final ObjectName [] registeredModules = 2096 (ObjectName [])invoke("getLifecycleModule", null, null); 2097 if (target.getType() == TargetType.DOMAIN) 2098 { 2099 return registeredModules; 2100 } 2101 final ApplicationRef[] refs = target.getApplicationRefs(); 2102 final ArrayList al = new ArrayList (); 2103 for (int i = 0; i < registeredModules.length; i++) 2104 { 2105 final String name = registeredModules[i].getKeyProperty( 2106 ServerTags.NAME); 2107 for (int j = 0; j < refs.length; j++) 2108 { 2109 if (refs[j].getRef().equals(name)) 2110 { 2111 al.add(registeredModules[i]); 2112 continue; 2113 } 2114 } 2115 } 2116 final ObjectName [] refModules = new ObjectName [al.size()]; 2117 for (int i = 0; i < refModules.length; i++) 2118 { 2119 refModules[i] = (ObjectName )al.get(i); 2120 } 2121 return refModules; 2122 } 2123 2124 2126 public ObjectName getLifecycleModuleByName(String key, String targetName) 2127 throws Exception 2128 { 2129 final com.sun.enterprise.admin.target.Target target = 2130 com.sun.enterprise.admin.target.TargetBuilder.INSTANCE.createTarget( 2131 VALID_LIST_TYPES, targetName, getConfigContext()); 2132 final ObjectName on = (ObjectName )invoke("getLifecycleModuleByName", 2133 new Object []{key}, new String []{"java.lang.String"}); 2134 if (!(target.getType() == TargetType.DOMAIN)) 2135 { 2136 final ApplicationRef[] refs = target.getApplicationRefs(); 2137 boolean isReffed = false; 2138 for (int i = 0; i < refs.length; i++) 2139 { 2140 if (refs[i].getRef().equals(key)) 2141 { 2142 isReffed = true; 2143 break; 2144 } 2145 } 2146 if (!isReffed) 2147 { 2148 throw new ConfigException(localStrings.getString( 2149 "applicationRefDoesnotExist", targetName, key)); 2150 } 2151 } 2152 return on; 2153 } 2154 2155 static Map getAttributeValues(AttributeList attributeList, String [] names) 2156 { 2157 int len = names.length; 2158 final Map values = new HashMap (len); 2159 final Iterator it = attributeList.iterator(); 2160 while (it.hasNext()) 2161 { 2162 final Attribute a = (Attribute )it.next(); 2163 final String name = a.getName(); 2164 for (int i = 0; i < len; i++) 2165 { 2166 if (name.equals(names[i])) 2167 { 2168 values.put(name, a.getValue()); 2169 } 2170 } 2171 } 2172 return values; 2173 } 2174 2175 static final String NAME = ServerTags.NAME; 2176 static final String ENABLED = ServerTags.ENABLED; 2177 2178 public Boolean isLifecycleModuleRegistered(String name) 2179 { 2180 Boolean isRegistered = Boolean.FALSE; 2181 try 2182 { 2183 final ObjectName on = (ObjectName )invoke("getLifecycleModuleByName", 2184 new Object []{name}, new String []{"java.lang.String"}); 2185 if(on != null) { 2186 isRegistered = Boolean.TRUE; 2187 } 2188 } 2189 catch (Exception e) 2190 { 2191 } 2193 return isRegistered; 2194 } 2195 2196 2206 public ObjectName createLifecycleModule(AttributeList attribute_list, 2207 String targetName) 2208 throws Exception 2209 { 2210 return createLifecycleModule(attribute_list, null, targetName); 2211 2212 } 2213 2214 2224 public ObjectName createLifecycleModule(AttributeList attribute_list, 2225 Properties props, 2226 String targetName) 2227 throws Exception 2228 { 2229 final Map values = getAttributeValues(attribute_list, 2230 new String []{NAME, ENABLED}); 2231 final String name = (String )values.get(NAME); 2232 2233 ConfigContext ctx = getConfigContext(); 2234 ConfigBean app = ApplicationHelper.findApplication(ctx, name); 2235 if ( (app!=null) && !(app instanceof LifecycleModule) ) { 2236 2237 throw new ConfigException(localStrings.getString( 2238 "admin.mbeans.acmb.duplicateLCMName", name)); 2239 } 2240 2241 Boolean isRegistered = isLifecycleModuleRegistered(name); 2242 final DeploymentTarget target = getAndValidateDeploymentTarget( 2243 targetName, name, isRegistered.booleanValue(), false); 2244 2250 final ObjectName on = (ObjectName )invoke("createLifecycleModule", 2251 new Object []{attribute_list}, 2252 new String []{"javax.management.AttributeList"}); 2253 2254 2255 if (props!=null && props.size()>0) { 2257 ArrayList arr = new ArrayList (); 2259 for (Enumeration e = props.propertyNames(); e.hasMoreElements() ;) { 2260 String propName = (String )e.nextElement(); 2261 String propValue = (String )props.getProperty(propName); 2262 if (propValue != null) { 2263 ElementProperty ep = new ElementProperty(); 2264 ep.setName(propName); 2265 ep.setValue(propValue); 2266 arr.add(ep); 2267 } 2268 } 2269 if(arr.size()>0) 2270 { 2271 LifecycleModule lcm = (LifecycleModule)ApplicationHelper.findApplication(ctx, name); 2272 lcm.setElementProperty((ElementProperty[])arr.toArray(new ElementProperty[arr.size()])); 2273 } 2274 } 2275 2276 final String isEnabled = (String )values.get(ENABLED); 2277 boolean enabled = new Boolean (isEnabled).booleanValue(); 2278 target.addAppReference(name, enabled, null); 2279 return on; 2280 } 2281 2282 2289 public DeploymentStatus createLifecycleModuleReference(String referenceName, String targetName, Map options) { 2290 DeploymentStatus ds = new DeploymentStatus(); 2291 ds.setStageDescription("CreateLifecycleModuleReference"); 2292 try { 2293 final DeploymentTarget target = getAndValidateDeploymentTarget( 2294 targetName, referenceName, false, false); 2295 boolean enabled = (new DeploymentProperties(options)).getEnable(); 2296 target.addAppReference(referenceName, enabled, null); 2297 ds.setStageStatus(DeploymentStatus.SUCCESS); 2298 } catch(Exception e) { 2299 ds.setStageException(e); 2300 ds.setStageStatus(DeploymentStatus.FAILURE); 2301 ds.setStageStatusMessage(e.getMessage()); 2302 } 2303 return ds; 2304 } 2305 2306 2314 public DeploymentStatus removeLifecycleModuleReference(String referenceName, String targetName) { 2315 DeploymentStatus ds = new DeploymentStatus(); 2316 ds.setStageDescription("RemoveLifecycleModuleReference"); 2317 try { 2318 final DeploymentTarget target = getAndValidateDeploymentTarget( 2319 targetName, referenceName, false, false); 2320 target.removeAppReference(referenceName); 2321 ds.setStageStatus(DeploymentStatus.SUCCESS); 2322 } catch(Exception e) { 2323 ds.setStageException(e); 2324 ds.setStageStatus(DeploymentStatus.FAILURE); 2325 ds.setStageStatusMessage(e.getMessage()); 2326 } 2327 return ds; 2328 } 2329 2330 2338 public void removeLifecycleModuleByName(String name, String targetName) 2339 throws Exception 2340 { 2341 Boolean isRegistered = isLifecycleModuleRegistered(name); 2342 final DeploymentTarget target = getAndValidateDeploymentTarget( 2343 targetName, name, isRegistered.booleanValue(), true); 2344 target.removeAppReference(name); 2345 invoke("removeLifecycleModuleByName", new Object []{name}, 2346 new String []{"java.lang.String"}); 2347 } 2348 2349 2353 2356 private DeploymentService getDeploymentService() throws DeploymentException { 2357 if(deployService == null) { 2358 deployService = DeploymentService.getDeploymentService( 2359 getConfigContext()); 2360 } 2361 return deployService; 2362 } 2363 2364 2367 private String getInstanceName() throws DeploymentException 2368 { 2369 2370 if(mInstanceName == null) 2371 { 2372 try{ 2373 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 2374 ObjectName serversON = new ObjectName (getDomainName()+":type=servers,category=config"); 2375 ObjectName [] serverONArr = (ObjectName [])mbs.invoke(serversON, "getServer", new Object []{}, new String []{}); 2376 mInstanceName = (String )mbs.getAttribute(serverONArr[0], "name"); 2377 }catch(Exception e){ 2378 sLogger.log(Level.WARNING,"Could not obtain instanceName"); 2379 throw new DeploymentException("Could not obtain instanceName"); 2380 } 2381 } 2382 return mInstanceName; 2383 } 2384 2385 2392 private boolean isRegistered(String name, DeployableObjectType type) { 2393 try { 2394 if(getRegisteredComponentObjectName(name,type) != null) 2395 return true; 2396 else 2397 return false; 2398 } 2399 catch (Exception e) { 2400 sLogger.log(Level.WARNING, "appexists failed", e); } 2402 return true; 2403 } 2404 2405 2411 private DeployableObjectType getRegisteredType(String name) throws DeploymentException 2412 { 2413 try{ 2414 for(int i = 0; i< deployableObjectTypes.length; i++) 2415 { 2416 if(isRegistered(name, deployableObjectTypes[i])) 2417 return deployableObjectTypes[i]; 2418 } 2419 }catch(Exception e){ 2420 throw new DeploymentException(e.getMessage()); 2421 } 2422 throw new DeploymentException("Component not registered"); 2423 } 2424 2425 2431 private DeployableObjectType getTypeFromFile(String moduleID, String filePath) throws DeploymentException{ 2432 return DeploymentServiceUtils.getTypeFromFile(moduleID, filePath); 2433 } 2434 2435 2442 private void checkWebModuleReferences(String webModuleName) 2443 throws ConfigException { 2444 ArrayList virtualServerIds = new ArrayList (); 2445 2446 Config config = (Config) ConfigBeansFactory.getConfigBeanByXPath(getConfigContext(),ServerXPathHelper.XPATH_CONFIG); 2448 HttpService httpService = config.getHttpService(); 2449 VirtualServer[] virtualServers = httpService.getVirtualServer(); 2450 for (int j = 0; j < virtualServers.length; j++) { 2451 VirtualServer aServer = virtualServers[j]; 2452 String defWebModule = aServer.getDefaultWebModule(); 2453 if ((defWebModule != null) && 2454 (defWebModule.equals(webModuleName))) { 2455 virtualServerIds.add(aServer.getId()); 2456 } 2457 } 2458 2459 if (!virtualServerIds.isEmpty()) { 2460 throw new ConfigException(localStrings.getString( 2461 "admin.mbeans.acmb.def_web_module_refs_exist", 2462 virtualServerIds.toString(), webModuleName)); 2463 } 2464 } 2465 2466 2467 2472 private void deleteFile(String filePath) { 2473 2474 try{ 2475 File f = new File (filePath); 2476 if (f.exists()) { 2477 File parentDir = f.getParentFile(); 2478 File tmpDir = new File (AdminService.getAdminService(). 2479 getTempDirPath(), getInstanceName()); 2480 2481 if (tmpDir != null && tmpDir.equals(parentDir)) { 2482 boolean couldDelete = f.delete(); 2483 if (couldDelete) { 2484 sLogger.log(Level.FINE, "mbean.delete_temp_file_ok", filePath); 2485 } 2486 else { 2487 sLogger.log(Level.INFO, "mbean.delete_temp_file_failed", filePath); 2488 } 2489 } 2490 } 2491 }catch(Exception e){ 2492 sLogger.log(Level.WARNING,"could not deletefile"+filePath); 2493 } 2494 } 2495 2496 2497 2498 2499 2505 private DeployableObjectType getDeployableObjectType(String moduleType) throws DeploymentException { 2506 if(moduleType.equals(TYPE_APPLICATION) || moduleType.equals(JSR88_TYPE_APPLICATION)) { 2507 return DeployableObjectType.APP; 2508 } 2509 else if(moduleType.equals(TYPE_EJB) || moduleType.equals(JSR88_TYPE_EJB)) { 2510 return DeployableObjectType.EJB; 2511 } 2512 else if(moduleType.equals(TYPE_WEB) || moduleType.equals(JSR88_TYPE_WEB)) { 2513 return DeployableObjectType.WEB; 2514 } 2515 else if(moduleType.equals(TYPE_CONNECTOR) || moduleType.equals(JSR88_TYPE_CONNECTOR)) { 2516 return DeployableObjectType.CONN; 2517 } 2518 else if(moduleType.equals(TYPE_APPCLIENT) || moduleType.equals(JSR88_TYPE_APPCLIENT)) { 2519 return DeployableObjectType.CAR; 2520 } 2521 else if(moduleType.equals(XModuleType.LCM.toString())) { 2522 return DeployableObjectType.LCM; 2523 } 2524 else if(moduleType.equals(XModuleType.CMB.toString())) { 2525 return DeployableObjectType.CMB; 2526 } 2527 else { 2528 throw new DeploymentException("Unknown deployable object type"); 2529 } 2530 } 2531 2532 2537 private void chownDir(File dir, String user) { 2538 if (dir == null || user == null || user.trim().equals("")) { 2539 return; 2540 } 2541 String err = null; 2542 2543 2550 } 2551 2552 2555 2556 public HostAndPort getHostAndPort() throws ServerInstanceException { 2557 return getHostAndPort(false); 2558 } 2559 2560 2564 public HostAndPort getHostAndPort(boolean securityEnabled) throws ServerInstanceException { 2565 HostAndPort hAndp = null; 2566 try { 2567 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 2568 ObjectName objectName = new ObjectName (getDomainName()+":type=configs,category=config"); 2569 String operationName1 = "getConfig"; 2570 ObjectName [] configs = (ObjectName [])mbs.invoke(objectName,operationName1, emptyParams,emptySignature); 2571 String configName = (String )mbs.getAttribute(configs[0], "name"); 2572 ObjectName httpService = new ObjectName (getDomainName()+":type=http-service,config="+configName+",category=config"); 2573 String operationName2 = "getHttpListener"; 2574 ObjectName [] httpListener = (ObjectName [])mbs.invoke(httpService, operationName2,emptyParams,emptySignature); 2575 2576 String serverName = null; 2577 int port = 0; 2578 for (int i = 0; i < httpListener.length; i++) { 2579 AttributeList attrs = mbs.getAttributes(httpListener[i], 2580 httpListenerAttrNames); 2581 Boolean bb = Boolean.valueOf((String )getNamedAttributeValue( 2582 attrs, LISTENER_ENABLED)); 2583 boolean enabled = ((bb == null) ? false : bb.booleanValue()); 2584 if (!enabled) { 2585 continue; 2587 } 2588 String vs = (String )getNamedAttributeValue(attrs, DEF_VS); 2589 if (ADMIN_VS.equals(vs)) { 2590 continue; 2592 } 2593 bb = Boolean.valueOf((String )getNamedAttributeValue( 2594 attrs, SEC_ENABLED)); 2595 boolean sec_on = ((bb == null) ? false : bb.booleanValue()); 2596 if (securityEnabled == sec_on) { 2597 serverName = (String )getNamedAttributeValue(attrs, 2598 SERVER_NAME); 2599 if (serverName == null || serverName.trim().equals("")) { 2600 serverName = getDefaultHostName(); 2601 } 2602 String portStr = (String )getNamedAttributeValue(attrs, 2603 PORT); 2604 String redirPort = (String )getNamedAttributeValue(attrs, 2605 REDIRECT_PORT); 2606 if (redirPort != null && !redirPort.trim().equals("")) { 2607 portStr = redirPort; 2608 } 2609 String resolvedPort = 2610 new PropertyResolver(getConfigContext(), 2611 getInstanceName()).resolve(portStr); 2612 port = Integer.parseInt(resolvedPort); 2613 break; 2614 } 2615 } 2616 hAndp = new HostAndPort(serverName, port); 2617 } 2618 catch (Exception e) { 2619 throw new ServerInstanceException(e.getLocalizedMessage()); 2620 } 2621 return hAndp; 2622 } 2623 2624 2631 public HostAndPort getHostAndPort(String standAloneModuleId, boolean securityEnabled) 2632 throws ServerInstanceException { 2633 2634 HostAndPort hAndp = null; 2635 boolean setHP = false; 2636 2637 try { 2638 2639 2641 String appRefXPath = ServerXPathHelper.getServerIdXpath(getInstanceName()) 2642 + ServerXPathHelper.XPATH_SEPARATOR 2643 + ServerTags.APPLICATION_REF + "[@" 2644 + ServerTags.REF + "='" + standAloneModuleId + "']"; 2645 2646 ApplicationRef appRef = (ApplicationRef) ConfigBeansFactory.getConfigBeanByXPath( 2647 getConfigContext(), appRefXPath); 2648 2649 if (appRef.getVirtualServers()!=null) { 2651 return getHostAndPort(securityEnabled); 2652 } 2653 2654 2656 String appRefvs = null; 2657 List vsList = StringUtils.parseStringList(appRef.getVirtualServers(), " ,"); 2658 if (vsList==null) { 2659 return getHostAndPort(securityEnabled); 2660 } 2661 ListIterator vsListIter = vsList.listIterator(); 2662 2663 2665 while(vsListIter.hasNext()) { 2666 String virtualServer = (String ) vsListIter.next(); 2667 HostAndPort hp = getVirtualServerHostAndPort(virtualServer, securityEnabled); 2668 if (hp!=null) { 2669 return hp; 2670 } 2671 } 2672 } catch (Exception e) { 2673 throw new ServerInstanceException(e.getLocalizedMessage()); 2674 } 2675 2676 return null; 2677 } 2678 2679 2682 public HostAndPort getVirtualServerHostAndPort(String vs, boolean securityEnabled) 2683 throws ServerInstanceException 2684 { 2685 String serverName = null; 2686 int port = 0; 2687 2688 try { 2689 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 2690 2691 ObjectName objectName = new ObjectName ( 2692 getDomainName()+":type=configs,category=config"); 2693 String operationName1 = "getConfig"; 2694 ObjectName [] configs = ( 2695 ObjectName [])mbs.invoke(objectName,operationName1, 2696 emptyParams,emptySignature); 2697 String configName = (String )mbs.getAttribute(configs[0], "name"); 2698 ObjectName httpService = new ObjectName ( 2699 getDomainName()+":type=http-service,config="+configName+",category=config"); 2700 2701 2703 String operationName2 = "getHttpListener"; 2704 ObjectName [] httpListener = (ObjectName [])mbs.invoke(httpService, 2705 operationName2,emptyParams,emptySignature); 2706 2707 2709 operationName2 = "getVirtualServer"; 2710 ObjectName [] virtualServer = (ObjectName [])mbs.invoke(httpService, 2711 operationName2,emptyParams,emptySignature); 2712 2713 2715 for (int i = 0; i < virtualServer.length; i++) { 2716 2717 AttributeList vsAttrs = mbs.getAttributes(virtualServer[i], vsAttrNames); 2718 2719 2725 String id = (String )getNamedAttributeValue(vsAttrs, ID); 2726 if (! id.equals(vs)) { 2727 continue; 2728 } 2729 2730 2732 2738 String httpListeners = (String ) getNamedAttributeValue(vsAttrs, "http-listeners"); 2739 String vsHttpListener = null; 2740 List httpListenerList = StringUtils.parseStringList(httpListeners, " ,"); 2741 ListIterator hlListIter = httpListenerList.listIterator(); 2742 2743 while(hlListIter.hasNext()) { 2744 2745 vsHttpListener = (String ) hlListIter.next(); 2746 2747 for (int j = 0; j < httpListener.length; j++) { 2748 2749 AttributeList attrs = mbs.getAttributes(httpListener[j], 2750 httpListenerAttrNames); 2751 2752 String listenerId = (String )getNamedAttributeValue(attrs, ID); 2754 if (! listenerId.equals(vsHttpListener)) { 2755 continue; 2756 } 2757 2758 Boolean bb = Boolean.valueOf((String )getNamedAttributeValue( 2759 attrs, LISTENER_ENABLED)); 2760 boolean enabled = ((bb == null) ? false : bb.booleanValue()); 2761 if (!enabled) { 2762 continue; 2764 } 2765 bb = Boolean.valueOf((String )getNamedAttributeValue( attrs, SEC_ENABLED)); 2766 boolean sec_on = ((bb == null) ? false : bb.booleanValue()); 2767 if (securityEnabled == sec_on) { 2768 serverName = (String )getNamedAttributeValue(attrs, SERVER_NAME); 2769 if (serverName == null || serverName.trim().equals("")) { 2770 serverName = getDefaultHostName(); 2771 } 2772 String portStr = (String )getNamedAttributeValue(attrs, PORT); 2773 String redirPort = (String )getNamedAttributeValue(attrs, REDIRECT_PORT); 2774 if (redirPort != null && !redirPort.trim().equals("")) { 2775 portStr = redirPort; 2776 } 2777 final String resolvedPort = 2778 new PropertyResolver(getConfigContext(), 2779 getInstanceName()).resolve(portStr); 2780 port = Integer.parseInt(resolvedPort); 2781 return new HostAndPort(serverName, port); 2782 } 2783 } 2784 } 2785 } 2786 } catch (Exception e) { 2787 throw new ServerInstanceException(e.getLocalizedMessage()); 2788 } 2789 return null; 2790 } 2791 2792 2796 private void setDeployDirOwner(DeploymentRequest request, 2797 InstanceEnvironment env) { 2798 2814 } 2815 2816 2817 private ObjectName [] getAllRegisteredComponentsOfType(DeployableObjectType type) { 2818 String operationName = null; 2819 ObjectName [] ONArr = null; 2820 try{ 2821 if(type.isAPP()) 2822 operationName = "getJ2eeApplication"; 2823 else if(type.isEJB()) 2824 operationName = "getEjbModule"; 2825 else if(type.isWEB()) 2826 operationName = "getWebModule"; 2827 else if(type.isCONN()) 2828 operationName = "getConnectorModule"; 2829 else if(type.isCAR()) 2830 operationName = "getAppclientModule"; 2831 2832 ONArr = (ObjectName [])invoke(operationName,emptyParams,emptySignature); 2833 }catch(Exception e){ 2834 sLogger.log(Level.FINE, e.getMessage()); 2835 ONArr = new ObjectName []{}; 2836 } 2837 return ONArr; 2838 } 2839 2840 private ArrayList getModules(String target, DeployableObjectType type, Boolean state, boolean excludeSystemApps) throws Exception 2841 { 2842 ArrayList list = new ArrayList (); 2843 String operationName = "getApplicationRef"; 2844 try{ 2845 ObjectName [] appONArr = getAllRegisteredComponentsOfType(type); 2846 ObjectName serverON = new ObjectName (getDomainName()+":type=server,name=" 2847 +target+",category=config"); 2848 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 2849 ObjectName [] apprefONArr = (ObjectName [])mbs.invoke(serverON, operationName, 2850 emptyParams, emptySignature); 2851 for(int i =0 ; i< apprefONArr.length ; i++) { 2852 String refName = (String )mbs.getAttribute(apprefONArr[i], "ref"); 2853 2854 String refenabled = (String )mbs.getAttribute(apprefONArr[i], "enabled"); 2855 for(int j =0 ; j < appONArr.length ; j++) { 2857 String name = (String )mbs.getAttribute(appONArr[j], "name"); 2858 if(name.equals(refName)) { 2859 2863 String objectType = (type.equals(DeployableObjectType.CAR) 2864 ? Constants.USER 2865 : (String )mbs.getAttribute(appONArr[j], OBJECT_TYPE)); 2866 if (excludeSystemApps 2867 && (objectType != null) 2868 && (objectType.startsWith(Constants.SYSTEM_PREFIX))) { 2869 break; 2870 } 2871 if(state == null) { 2872 list.add(refName); 2873 }else { 2874 2879 String enabled = (type.equals(DeployableObjectType.CAR) 2880 ? "true" 2881 : (String )mbs.getAttribute(appONArr[j], "enabled")); 2882 if(state.equals(Boolean.TRUE)) { 2883 if(enabled.equalsIgnoreCase("true") && refenabled.equalsIgnoreCase("true")) 2884 list.add(refName); 2885 } 2886 else if(state.equals(Boolean.FALSE)) { 2887 if(enabled.equalsIgnoreCase("false") || refenabled.equalsIgnoreCase("false")) 2888 list.add(refName); 2889 } 2890 } 2891 } 2892 2893 } 2894 2895 } 2896 }catch(Exception e) { 2897 sLogger.log(Level.FINE, e.getMessage()); 2898 throw e; 2899 } 2900 return list; 2901 } 2902 2903 private ObjectName constructComponentObjectName(String name, DeployableObjectType type){ 2904 ObjectName ON = null; 2905 try{ 2906 if(type.isAPP()) 2907 ON = new ObjectName (getDomainName()+":type=j2ee-application,name="+name+",category=config"); 2908 else if(type.isEJB()) 2909 ON = new ObjectName (getDomainName()+":type=ejb-module,name="+name+",category=config"); 2910 else if(type.isAPP()) 2911 ON = new ObjectName (getDomainName()+":type=web-module,name="+name+",category=config"); 2912 else if(type.isAPP()) 2913 ON = new ObjectName (getDomainName()+":type=connector-module,name="+name+",category=config"); 2914 else if(type.isAPP()) 2915 ON = new ObjectName (getDomainName()+":type=appclient-module,name="+name+",category=config"); 2916 }catch(Exception e){ 2917 } 2918 return ON; 2919 } 2920 2921 2924 private ObjectName getRegisteredComponentObjectName(String name, DeployableObjectType type) { 2925 ObjectName ret = null; 2926 try { 2927 String operationName = null; 2928 if(type.equals(DeployableObjectType.APP)) { 2929 operationName = "getJ2eeApplicationByName"; 2930 } 2931 else if(type.equals(DeployableObjectType.EJB)) { 2932 operationName = "getEjbModuleByName"; 2933 } 2934 else if(type.equals(DeployableObjectType.WEB)) { 2935 operationName = "getWebModuleByName"; 2936 } 2937 else if(type.equals(DeployableObjectType.CONN)) { 2938 operationName = "getConnectorModuleByName"; 2939 } 2940 else if(type.equals(DeployableObjectType.CAR)) { 2941 operationName = "getAppclientModuleByName"; 2942 } 2943 else if(type.equals(DeployableObjectType.LCM)) { 2944 operationName = "getLifecycleModuleByName"; 2945 } 2946 else if(type.equals(DeployableObjectType.CMB)) { 2947 operationName = "getMbeanByName"; 2948 } 2949 Object [] params = new Object []{name}; 2950 String [] signature = new String []{"java.lang.String"}; 2951 ret = (ObjectName )invoke(operationName, params, signature); 2952 2953 }catch (Exception e) { 2954 } 2956 return ret; 2957 } 2958 2959 private ObjectName getRegisteredComponentObjectName(String name) 2960 throws DeploymentException { 2961 ObjectName ret = null; 2962 2963 for(int i=0 ; i < deployableObjectTypes.length ; i++) 2964 { 2965 ret = getRegisteredComponentObjectName(name,deployableObjectTypes[i]); 2966 if(ret != null) 2967 return ret; 2968 } 2969 throw new DeploymentException("Component not registered"); 2970 } 2971 2972 private ObjectName getRegisteredAppRefObjectName(String name, String targetName) 2973 throws DeploymentException 2974 { 2975 try{ 2976 final com.sun.enterprise.admin.target.Target target = 2977 com.sun.enterprise.admin.target.TargetBuilder.INSTANCE. 2978 createTarget(VALID_LIST_TYPES, targetName, getConfigContext()); 2979 assert target != null; 2980 2981 ObjectName targetON = null; 2982 if (target.getType() == 2983 com.sun.enterprise.admin.target.TargetType.CLUSTER) { 2984 targetON = super.getClusterObjectName(targetName); 2985 } else if (target.getType() == 2986 com.sun.enterprise.admin.target.TargetType.DOMAIN) { 2987 return null; 2989 } else { 2990 targetON = super.getServerObjectName(targetName); 2991 } 2992 assert targetON != null; 2993 2994 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 2995 ObjectName [] apprefONArr = (ObjectName [])mbs.invoke(targetON, 2996 "getApplicationRef", emptyParams, emptySignature); 2997 for(int i =0; i< apprefONArr.length;i++) 2998 { 2999 String ref = (String )mbs.getAttribute(apprefONArr[i], "ref"); 3000 if(name.equals(ref)) 3001 return apprefONArr[i]; 3002 } 3003 }catch(Exception e){ 3004 throw new DeploymentException(e.getMessage()); 3005 } 3006 throw new DeploymentException("Component not registered"); 3007 } 3008 3009 3010 3013 3021 public String [] getModuleComponents(String standAloneModuleName) 3022 throws ServerInstanceException { 3023 3024 String [] modComponents = new String [0]; 3025 3026 if ((standAloneModuleName == null) || (standAloneModuleName.length() < 1)) { 3027 throw new ServerInstanceException( 3028 localStrings.getString("admin.mbeans.ssmb.invalid_app_or_module_name", "")); 3029 } 3030 3031 try { 3032 sLogger.log(Level.FINE, 3033 "ApplicationsConfigMBean.getModuleComponents for " + standAloneModuleName); 3034 3035 3038 String j2eeType = getJ2eeType(standAloneModuleName); 3039 3040 if (j2eeType == null) { 3041 throw new ServerInstanceException( 3042 localStrings.getString("admin.mbeans.ssmb.invalid_app_or_module_name", 3043 standAloneModuleName)); 3044 } 3045 3046 3049 if (j2eeType.equals("EJBModule")) { 3050 BundleDescriptor bd = getDescrForStandAloneEjbModule(standAloneModuleName); 3051 modComponents = getValidatedObjectNames( 3052 getEjbModuleComponents((EjbBundleDescriptor)bd)); 3053 return modComponents; 3054 } else if (j2eeType.equals("WebModule")) { 3055 BundleDescriptor bd = getDescrForStandAloneWebModule(standAloneModuleName); 3056 modComponents = getValidatedObjectNames( 3057 getWebModuleComponents((WebBundleDescriptor)bd)); 3058 return modComponents; 3059 } else if (j2eeType.equals("ResourceAdapterModule")) { 3060 BundleDescriptor bd = getDescrForStandAloneRarModule(standAloneModuleName); 3061 modComponents = getValidatedObjectNames( 3062 getRarModuleComponents((ConnectorDescriptor)bd)); 3063 return modComponents; 3064 } else if (j2eeType.equals("AppClientModule")) { 3065 BundleDescriptor bd = getDescrForStandAloneCarModule(standAloneModuleName); 3066 modComponents = getValidatedObjectNames(getCarModuleComponents(bd)); 3067 return modComponents; 3068 } else if (j2eeType.equals("J2EEApplication")) { 3069 Application ad = getDescrForApplication(standAloneModuleName); 3070 modComponents = getValidatedObjectNames(getApplicationComponents(ad)); 3071 return modComponents; 3072 } else { 3073 throw new ServerInstanceException( 3074 localStrings.getString("admin.mbeans.ssmb.invalid_app_or_module_name", 3075 standAloneModuleName)); 3076 } 3077 3078 } catch (Exception e) { 3079 sLogger.log(Level.WARNING, "ApplicationsConfigMBean.getModuleComponents failed", e); 3080 throw new ServerInstanceException(e.getLocalizedMessage()); 3081 } 3082 3083 } 3084 3085 3086 3094 public String [] getModuleComponents(String appName, String modName) 3095 throws ServerInstanceException { 3096 3097 String [] modComponents = new String [0]; 3098 3099 if ((modName == null) || (modName.length() < 1)) { 3100 throw new ServerInstanceException("invalid ModuleName"); 3101 } 3102 3103 try { 3104 sLogger.log(Level.FINE, 3105 "ApplicationsConfigMBean.getModuleComponents for application = " + 3106 appName + " and module = " + modName); 3107 3108 3110 AppsManager am = InstanceFactory.createAppsManager(getInstanceName()); 3111 Application appD = null; 3112 try { 3113 appD = (Application) DeploymentUtils.getDescriptor(appName, am); 3114 } catch (java.lang.NullPointerException npe) { 3115 throw new ServerInstanceException( 3116 localStrings.getString("admin.mbeans.ssmb.invalid_appname", appName)); 3117 } 3118 3119 3122 BundleDescriptor bd = null; 3123 ModuleType modType = null; 3124 java.util.Set bds = appD.getBundleDescriptors(); 3125 for(Iterator it=bds.iterator(); it.hasNext(); ) { 3126 bd = (BundleDescriptor)it.next(); 3127 if ((bd.getModuleDescriptor().getArchiveUri()).equals(modName) || 3128 bd.getModuleID().equals(modName) || 3129 bd.getName().equals(modName)) { 3130 modType = bd.getModuleType(); 3131 break; 3132 } 3133 } 3134 3135 3137 if (modType == ModuleType.EJB) { 3138 modComponents = getValidatedObjectNames( 3139 getEjbModuleComponents((EjbBundleDescriptor)bd)); 3140 return modComponents; 3141 } else if (modType == ModuleType.WAR) { 3142 modComponents = getValidatedObjectNames( 3143 getWebModuleComponents((WebBundleDescriptor)bd)); 3144 return modComponents; 3145 } else if (modType == ModuleType.RAR) { 3146 modComponents = getValidatedObjectNames( 3147 getRarModuleComponents((ConnectorDescriptor)bd)); 3148 return modComponents; 3149 } else if (modType == ModuleType.CAR) { 3150 modComponents = getValidatedObjectNames( 3151 getCarModuleComponents(bd)); 3152 return modComponents; 3153 } else { 3154 throw new ServerInstanceException("invalid module or application name"); 3155 } 3156 3157 } catch (Exception e) { 3158 sLogger.log(Level.WARNING, "ApplicationsConfigMBean.getModuleComponents failed", e); 3159 throw new ServerInstanceException(e.getLocalizedMessage()); 3160 } 3161 3162 } 3163 3164 3169 String getJ2eeType(String dName) 3170 throws ServerInstanceException { 3171 3172 3174 String j2eeType = null; 3175 3176 try { 3177 3178 Applications appsConfigBean = 3180 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 3181 getConfigContext(), ServerXPathHelper.XPATH_APPLICATIONS); 3182 3183 J2eeApplication[] j2eeApps = appsConfigBean.getJ2eeApplication(); 3185 if (j2eeApps != null) { 3186 for(int i=0; i<j2eeApps.length; i++) { 3187 if ((j2eeApps[i].getName()).equals(dName)) { 3188 return "J2EEApplication"; 3189 } 3190 } 3191 } 3192 3193 EjbModule[] eModules = appsConfigBean.getEjbModule(); 3195 if (eModules != null) { 3196 for(int i=0; i<eModules.length; i++) { 3197 if ((eModules[i].getName()).equals(dName)) { 3198 return "EJBModule"; 3199 } 3200 } 3201 } 3202 3203 WebModule[] wModules = appsConfigBean.getWebModule(); 3205 if (wModules != null) { 3206 for(int i=0; i<wModules.length; i++) { 3207 if ((wModules[i].getName()).equals(dName)) { 3208 return "WebModule"; 3209 } 3210 } 3211 } 3212 3213 ConnectorModule[] connectorConfigBeans = appsConfigBean.getConnectorModule(); 3215 if (connectorConfigBeans != null) { 3216 for(int i = 0; i < connectorConfigBeans.length; i++) { 3217 if ((connectorConfigBeans[i].getName()).equals(dName)) { 3218 return "ResourceAdapterModule"; 3219 } 3220 } 3221 } 3222 3223 } catch (Exception e) { 3224 throw new ServerInstanceException(e.getLocalizedMessage()); 3225 } 3226 return j2eeType; 3227 } 3228 3229 3234 BundleDescriptor getDescrForStandAloneEjbModule (String ejbModuleName) 3235 throws ServerInstanceException { 3236 try { 3237 EjbModulesManager ejbModMgr = 3238 InstanceFactory.createEjbModuleManager(getInstanceName()); 3239 return (BundleDescriptor) 3240 DeploymentUtils.getDescriptor(ejbModuleName, ejbModMgr); 3241 } catch (Exception e) { 3242 throw new ServerInstanceException(e.getLocalizedMessage()); 3243 } 3244 3245 } 3246 3247 String [] getEjbModuleComponents(EjbBundleDescriptor bd) 3248 throws ServerInstanceException { 3249 3250 String [] sArr = null; 3251 3252 try { 3253 java.util.Set ejbs = bd.getEjbs(); 3254 ManagementObjectManager mom = Switch.getSwitch().getManagementObjectManager(); 3255 String moduleName = mom.getModuleName(bd); 3256 String applicationName = mom.getApplicationName(bd); 3257 EjbDescriptor ed = null; 3258 sArr = new String [ejbs.size()]; 3259 int i=0; 3260 String j2eeType = null; 3261 3262 for(Iterator it=ejbs.iterator(); it.hasNext(); ) { 3263 ed = (EjbDescriptor) it.next(); 3264 j2eeType = mom.getJ2eeTypeForEjb(ed); 3265 sArr[i] = ("j2eeType=" + j2eeType + "," + 3266 "name=" + ed.getName() + "," + 3267 "EJBModule=" + moduleName + "," + 3268 "J2EEApplication=" + applicationName); 3269 i++; 3270 } 3271 3272 } catch (Exception e) { 3273 throw new ServerInstanceException(e.getLocalizedMessage()); 3274 } 3275 3276 return sArr; 3277 } 3278 3279 3284 BundleDescriptor getDescrForStandAloneWebModule (String moduleName) 3285 throws ServerInstanceException { 3286 try { 3287 WebModulesManager webModMgr = 3288 InstanceFactory.createWebModuleManager(getInstanceName()); 3289 return (BundleDescriptor) 3290 DeploymentUtils.getDescriptor(moduleName, webModMgr); 3291 } catch (Exception e) { 3292 throw new ServerInstanceException(e.getLocalizedMessage()); 3293 } 3294 } 3295 3296 String [] getWebModuleComponents(WebBundleDescriptor bd) 3297 throws ServerInstanceException { 3298 3299 String [] sArr = null; 3300 3301 try { 3302 java.util.Set webDescriptors = bd.getWebDescriptors(); 3303 ManagementObjectManager mom = Switch.getSwitch().getManagementObjectManager(); 3304 String moduleName = mom.getModuleName(bd); 3305 String applicationName = mom.getApplicationName(bd); 3306 WebComponentDescriptor wd = null; 3307 sArr = new String [webDescriptors.size()]; 3308 int i=0; 3309 String j2eeType = null; 3310 String servletName = null; 3311 String cName = null; 3312 String dName = null; 3313 String sName = null; 3314 3315 for(Iterator it=webDescriptors.iterator(); it.hasNext(); ) { 3316 wd = (WebComponentDescriptor) it.next(); 3317 3318 dName = wd.getDisplayName(); 3319 sName = wd.getName(); 3320 cName = wd.getCanonicalName(); 3321 3322 if ((dName != null) && (dName.length() > 0)) { 3323 servletName = dName; 3324 } else if ((sName != null) && (sName.length() > 0)) { 3325 servletName = sName; 3326 } else if ((cName != null) && (cName.length() > 0)) { 3327 servletName = cName; 3328 } else { 3329 servletName = ""; 3330 } 3331 3332 j2eeType = "Servlet"; 3333 sArr[i] = ("j2eeType=" + j2eeType + "," + 3334 "name=" + servletName + "," + 3335 "WebModule=" + moduleName + "," + 3336 "J2EEApplication=" + applicationName); 3337 i++; 3338 } 3339 3340 } catch (Exception e) { 3341 throw new ServerInstanceException(e.getLocalizedMessage()); 3342 } 3343 3344 return sArr; 3345 } 3346 3347 3348 BundleDescriptor getDescrForStandAloneCarModule (String moduleName) 3349 throws ServerInstanceException { 3350 try { 3351 AppclientModulesManager appClModMgr = 3352 InstanceFactory.createAppclientModulesManager(getInstanceName()); 3353 return (BundleDescriptor) 3354 DeploymentUtils.getDescriptor(moduleName, appClModMgr); 3355 } catch (Exception e) { 3356 throw new ServerInstanceException(e.getLocalizedMessage()); 3357 } 3358 } 3359 3360 3361 String [] getCarModuleComponents(BundleDescriptor bd) 3362 throws ServerInstanceException { 3363 3364 String [] sArr = new String [1]; 3365 3366 try { 3367 ManagementObjectManager mom = Switch.getSwitch().getManagementObjectManager(); 3368 String moduleName = bd.getModuleID(); 3369 String applicationName = mom.getApplicationName(bd); 3370 sArr[0] = ("j2eeType=AppClientModule," + 3371 "name=" + moduleName + "," + 3372 "J2EEApplication=" + applicationName); 3373 } catch (Exception e) { 3374 throw new ServerInstanceException(e.getLocalizedMessage()); 3375 } 3376 3377 return sArr; 3378 } 3379 3380 3381 3386 BundleDescriptor getDescrForStandAloneRarModule (String moduleName) 3387 throws ServerInstanceException { 3388 try { 3389 ConnectorModulesManager connModMgr = 3390 InstanceFactory.createConnectorModulesManager(getInstanceName()); 3391 return (BundleDescriptor) 3392 DeploymentUtils.getDescriptor(moduleName, connModMgr); 3393 } catch (Exception e) { 3394 throw new ServerInstanceException(e.getLocalizedMessage()); 3395 } 3396 } 3397 3398 String [] getRarModuleComponents(ConnectorDescriptor bd) 3399 throws ServerInstanceException { 3400 3401 String [] sArr = null; 3402 3403 try { 3404 ManagementObjectManager mom = Switch.getSwitch().getManagementObjectManager(); 3405 String moduleName = mom.getModuleName(bd); 3406 String applicationName = mom.getApplicationName(bd); 3407 String j2eeType = null; 3408 int i = 0; 3409 3410 InboundResourceAdapter ibRA = bd.getInboundResourceAdapter(); 3412 OutboundResourceAdapter obRA = bd.getOutboundResourceAdapter(); 3413 int kount = 0; 3414 if (ibRA != null) { kount = kount + 1; } 3415 if (obRA != null) { kount = kount + 1; } 3416 if (kount > 0) {sArr = new String [kount];} 3417 3418 3420 if (ibRA != null) { 3421 j2eeType = "ResourceAdapter"; 3422 sArr[i] = ("j2eeType=" + j2eeType + "," + 3423 "name=" + ibRA.getName() + "," + 3424 "ResourceAdapterModule=" + moduleName + "," + 3425 "J2EEApplication=" + applicationName); 3426 i++; 3427 } 3428 3429 3431 if (obRA != null) { 3432 j2eeType = "ResourceAdapter"; 3433 sArr[i] = ("j2eeType=" + j2eeType + "," + 3434 "name=" + obRA.getName() + "," + 3435 "ResourceAdapterModule=" + moduleName + "," + 3436 "J2EEApplication=" + applicationName); 3437 i++; 3438 } 3439 3440 } catch (Exception e) { 3441 throw new ServerInstanceException(e.getLocalizedMessage()); 3442 } 3443 3444 return sArr; 3445 } 3446 3447 3448 3453 Application getDescrForApplication (String appName) 3454 throws ServerInstanceException { 3455 try { 3456 AppsManager appsMgr = 3457 InstanceFactory.createAppsManager(getInstanceName()); 3458 return (Application) 3459 DeploymentUtils.getDescriptor(appName, appsMgr); 3460 } catch (Exception e) { 3461 throw new ServerInstanceException(e.getLocalizedMessage()); 3462 } 3463 } 3464 3465 3473 public String [] getAllSystemConnectors() throws ServerInstanceException { 3474 return ConnectorConstants.systemRarNames; 3475 } 3476 3477 String [] getApplicationComponents(Application ad) 3478 throws ServerInstanceException { 3479 3480 String [] sArr = null; 3481 3482 try { 3483 ManagementObjectManager mom = Switch.getSwitch().getManagementObjectManager(); 3484 String applicationName = ad.getRegistrationName(); 3485 String j2eeType = null; 3486 3487 java.util.Set bds = null; 3488 BundleDescriptor bd = null; 3489 3490 int i = 0; 3492 sArr = new String [ ad.getApplicationClientDescriptors().size() + 3493 ad.getEjbBundleDescriptors().size() + 3494 ad.getRarDescriptors().size() + 3495 ad.getWebBundleDescriptors().size() ]; 3496 3497 bds = ad.getApplicationClientDescriptors(); 3499 for(Iterator it=bds.iterator(); it.hasNext(); ) { 3500 bd = (BundleDescriptor) it.next(); 3501 sArr[i] = ("j2eeType=AppClientModule" + "," + 3502 "name=" + bd.getModuleDescriptor().getArchiveUri() + "," + 3503 "J2EEApplication=" + applicationName); 3504 i++; 3505 } 3506 3507 bds = ad.getEjbBundleDescriptors(); 3509 for(Iterator it=bds.iterator(); it.hasNext(); ) { 3510 bd = (BundleDescriptor) it.next(); 3511 sArr[i] = ("j2eeType=EJBModule" + "," + 3512 "name=" + bd.getModuleDescriptor().getArchiveUri() + "," + 3513 "J2EEApplication=" + applicationName); 3514 i++; 3515 } 3516 3517 bds = ad.getRarDescriptors(); 3519 for(Iterator it=bds.iterator(); it.hasNext(); ) { 3520 bd = (BundleDescriptor) it.next(); 3521 sArr[i] = ("j2eeType=ResourceAdapterModule" + "," + 3522 "name=" + bd.getModuleDescriptor().getArchiveUri() + "," + 3523 "J2EEApplication=" + applicationName); 3524 i++; 3525 } 3526 3527 bds = ad.getWebBundleDescriptors(); 3529 for(Iterator it=bds.iterator(); it.hasNext(); ) { 3530 bd = (BundleDescriptor) it.next(); 3531 sArr[i] = ("j2eeType=WebModule" + "," + 3532 "name=" + bd.getModuleDescriptor().getArchiveUri() + "," + 3533 "J2EEApplication=" + applicationName); 3534 i++; 3535 } 3536 3537 3538 } catch (Exception e) { 3539 throw new ServerInstanceException(e.getLocalizedMessage()); 3540 } 3541 3542 return sArr; 3543 } 3544 3545 3547 private String [] getValidatedObjectNames(String [] strArr) 3548 throws ServerInstanceException { 3549 3550 3553 String [] sArr = new String [strArr.length]; 3554 3555 try { 3556 for (int i=0; i<strArr.length; i++) { 3557 sArr[i] = ("com.sun.appserv" + ":" + 3558 strArr[i] + "," + 3559 "J2EEServer=" + getInstanceName()); 3560 } 3561 } catch (Exception e) { 3562 throw new ServerInstanceException(e.getLocalizedMessage()); 3563 } 3564 3565 return sArr; 3566 3567 } 3568 3569 3576 private boolean isDefaultTarget(String target) 3577 { 3578 if(target == null 3579 || target.length() == 0 3580 || target.equalsIgnoreCase(DEFAULT_TARGET)) 3581 { 3582 return true; 3583 } 3584 else 3585 { 3586 return false; 3587 } 3588 } 3589 3590 3595 private void setHostAndPort(DeploymentRequest req) 3596 throws ServerInstanceException { 3597 3598 String virtualServers = (String ) req.getOptionalAttributes().get(ServerTags.VIRTUAL_SERVERS); 3599 if (virtualServers==null) { 3600 HostAndPort hap = getHostAndPort(false); 3601 if(hap != null) { 3602 req.setHttpHostName(getHostName(hap)); 3603 req.setHttpPort(getPort(hap, false)); 3604 } 3605 hap = getHostAndPort(true); 3606 if(hap != null) { 3607 req.setHttpsHostName(getHostName(hap)); 3608 req.setHttpsPort(getPort(hap, true)); 3609 } 3610 } else { 3611 StringTokenizer st = new StringTokenizer (virtualServers,","); 3612 if (st.hasMoreTokens()) { 3613 String aVirtualServer = st.nextToken(); 3614 HostAndPort hap = getVirtualServerHostAndPort(aVirtualServer, false); 3615 if(hap != null) { 3616 req.setHttpHostName(getHostName(hap)); 3617 req.setHttpPort(getPort(hap, false)); 3618 } 3619 hap = getVirtualServerHostAndPort(aVirtualServer, true); 3620 if(hap != null) { 3621 req.setHttpsHostName(getHostName(hap)); 3622 req.setHttpsPort(getPort(hap, true)); 3623 } 3624 } 3625 } 3626 } 3627 3628 public String getHostName(HostAndPort hap) { 3629 String hostName = hap.getHost(); 3630 if (hostName == null || hostName.trim().equals("")) { 3631 hostName = getDefaultHostName(); 3632 } 3633 return hostName; 3634 } 3635 3636 private String getDefaultHostName() { 3637 String defaultHostName = "localhost"; 3638 try { 3639 InetAddress host = InetAddress.getLocalHost(); 3640 defaultHostName = host.getCanonicalHostName(); 3641 } catch(UnknownHostException uhe) { 3642 sLogger.log(Level.FINEST, "mbean.get_local_host_error", uhe); 3643 sLogger.log(Level.INFO, "mbean.use_default_host"); 3644 } 3645 return defaultHostName; 3646 } 3647 3648 private int getPort(HostAndPort hap, boolean securityEnabled) { 3649 int port = hap.getPort(); 3650 if (port == 0) { 3651 port = getDefaultPort(securityEnabled); 3652 } 3653 return port; 3654 } 3655 3656 private int getDefaultPort(boolean securityEnabled) { 3657 int port = 0; 3658 if (securityEnabled) { 3659 port = 8181; 3660 } else { 3661 port = 8080; 3662 } 3663 sLogger.log(Level.INFO, "mbean.use_default_port", String.valueOf(port)); 3664 return port; 3665 } 3666 3667 3678 private Object getNamedAttributeValue(AttributeList attrs, 3679 String attrName) { 3680 if (attrs == null || attrName == null) { 3681 return null; 3682 } 3683 Object value = null; 3684 Iterator iter = attrs.iterator(); 3685 while (iter.hasNext()) { 3686 Attribute attr = (Attribute )iter.next(); 3687 if (attrName.equals(attr.getName())) { 3688 value = attr.getValue(); 3689 break; 3690 } 3691 } 3692 return value; 3693 } 3694 3695 3703 private void validate(ObjectName componentON, String action) 3704 throws MBeanConfigException { 3705 3706 if(componentON == null) 3707 return; 3708 3709 3715 String componentType = componentON.getKeyProperty(ServerTags.TYPE); 3716 if ((componentType != null) && (componentType.length() > 0)) { 3717 if (componentType.equals(ServerTags.APPCLIENT_MODULE)) { 3718 return; 3719 } 3720 } 3721 3722 boolean allowSystemAppModification = 3723 (Boolean.valueOf(System.getProperty( 3724 Constants.ALLOW_SYSAPP_DEPLOYMENT, "false")).booleanValue()); 3725 3726 if(allowSystemAppModification) 3727 return; 3728 3729 String objectType = null; 3730 try{ 3731 3732 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 3733 objectType = (String )mbs.getAttribute(componentON, OBJECT_TYPE); 3734 3735 }catch(Exception e){ 3736 String msg = localStrings.getString( 3737 "admin.mbeans.acmb.exception_object_type"); 3738 sLogger.log(Level.FINE, msg); 3739 throw new MBeanConfigException(e.getMessage()); 3740 } 3741 3742 if(objectType!= null && objectType.startsWith(Constants.SYSTEM_PREFIX)) 3743 { 3744 String msg = localStrings.getString( 3745 "admin.mbeans.acmb.component_is_system",new Object []{action}); 3746 throw new MBeanConfigException(msg); 3747 } 3748 3749 } 3750 3751 public void associate(String appName, String target) 3752 throws MBeanException, MBeanConfigException { 3753 } 3754 3755 public void disassociate(String appName, String target) 3756 throws MBeanException, MBeanConfigException { 3757 } 3758 3759 private DeploymentTargetFactory getTargetFactory() { 3760 return DeploymentTargetFactory.getDeploymentTargetFactory(); 3761 } 3762 3763 3765 protected static final String ADMIN_VS = "__asadmin"; 3766 3767 protected static final String PORT = "port"; 3769 protected static final String DEF_VS = "default-virtual-server"; 3770 protected static final String SERVER_NAME = "server-name"; 3771 protected static final String REDIRECT_PORT = "redirect-port"; 3772 protected static final String SEC_ENABLED = "security-enabled"; 3773 protected static final String LISTENER_ENABLED = "enabled"; 3774 protected static final String OBJECT_TYPE = "object-type"; 3775 3776 protected static final String HOSTS = "hosts"; 3778 protected static final String HTTP_LISTENERS = "http_listeners"; 3779 protected static final String DEFAULT_WEB_MODULE = "default_web_module"; 3780 protected static final String STATE = "state"; 3781 protected static final String ID = "id"; 3782 3783 protected static final String DEPLOY_ACTION = "deploy"; 3785 protected static final String REDEPLOY_ACTION = "redeploy"; 3786 protected static final String UNDEPLOY_ACTION = "undeploy"; 3787 protected static final String ENABLE_ACTION = "enable"; 3788 protected static final String DISABLE_ACTION = "disable"; 3789 3790 3791 protected static String [] httpListenerAttrNames = {LISTENER_ENABLED, 3792 DEF_VS, SERVER_NAME, REDIRECT_PORT, PORT, SEC_ENABLED, ID }; 3793 3794 protected static String [] vsAttrNames = {HOSTS, HTTP_LISTENERS, 3795 DEFAULT_WEB_MODULE, STATE, ID}; 3796 3797 3799 private static final class ObjectNameAppRefComparator 3800 { 3801 private ObjectNameAppRefComparator() 3802 { 3803 } 3804 3805 private static int compare(ObjectName on, ApplicationRef ref) 3806 { 3807 String k1 = on.getKeyProperty(NAME); 3808 String k2 = ref.getRef(); 3809 return k1.compareTo(k2); 3810 } 3811 3812 public static ObjectName [] intersect(final ObjectName [] oa, 3813 final ApplicationRef[] ra) 3814 { 3815 if ((null == oa) || (0 == oa.length) || 3816 (null == ra) || (0 == ra.length)) 3817 { 3818 return new ObjectName [0]; 3819 } 3820 final ArrayList al = new ArrayList (); 3821 for (int i = 0; i < ra.length; i++) 3822 { 3823 for (int j = 0; j < oa.length; j++) 3824 { 3825 if (0 == compare(oa[j], ra[i])) 3826 { 3827 al.add(oa[j]); 3828 break; 3829 } 3830 } 3831 } 3832 return (ObjectName [])al.toArray(new ObjectName [al.size()]); 3833 } 3834 } 3835 3836 3837 3849 3850 public String [] getDeploymentDescriptorLocations ( 3851 String standAloneModuleName, String subComponentName) 3852 throws ServerInstanceException { 3853 3854 sLogger.log(Level.FINE, "getDeploymentDescriptorLocations - begin" + 3855 " standAloneModuleName = " + standAloneModuleName + 3856 " subComponentName = " + subComponentName); 3857 3858 J2EEModule j2eeModule = null; 3860 3861 if (subComponentName != null) { 3863 j2eeModule = new J2EEModule(standAloneModuleName, subComponentName); 3864 } else { 3865 j2eeModule = new J2EEModule(standAloneModuleName); 3866 } 3867 3868 ModuleType moduleType = j2eeModule.getModuleType(); 3870 if (moduleType == null) { 3871 throw new ServerInstanceException( 3872 localStrings.getString("admin.mbeans.acmb.invalidModuleType")); 3873 } 3874 sLogger.log(Level.FINE, "getDeploymentDescriptorLocations - moduleType" + moduleType); 3875 3876 String ddLocation = j2eeModule.getDeploymentDescriptorsLocation(); 3878 if (ddLocation == null) { 3879 throw new ServerInstanceException( 3880 localStrings.getString("admin.mbeans.acmb.invalidDeplDescrLoc")); 3881 } 3882 sLogger.log(Level.FINE, "getDeploymentDescriptorLocations - ddLocation" + ddLocation); 3883 3884 String [] ddList = DescriptorList.getDescriptorsList(moduleType); 3886 if ((ddList == null) || (ddList.length < 1)) { 3887 return null; 3888 } 3889 ArrayList arrL = new ArrayList (); 3890 String fileLocation = null; 3891 for (int i=0; i<ddList.length; i++) { 3892 fileLocation = ddLocation + File.separator + ddList[i]; 3894 try { 3895 File file = new File (fileLocation); 3896 if (file.exists()) { 3897 arrL.add(fileLocation); 3898 } 3899 } catch (Exception e) { 3900 sLogger.log(Level.WARNING, 3901 "getDeploymentDescriptorLocations - descriptor does not exist for " + 3902 fileLocation); 3903 } 3905 } 3906 3907 if (arrL.size() > 0) { 3909 String [] strArr = new String [arrL.size()]; 3910 for (int j=0; j<arrL.size(); j++) { 3911 strArr[j] = (String ) arrL.get(j); 3912 sLogger.log(Level.FINE, 3913 "getDeploymentDescriptorLocations: " + 3914 "next dd location = " + strArr[j]); 3915 } 3916 return strArr; 3917 } 3918 return null; 3919 } 3920 3921 3922 3927 public String getDeploymentDescriptor( 3928 String deploymentDescriptorLocation) 3929 throws ServerInstanceException { 3930 3931 sLogger.log(Level.FINE, "getDeploymentDescriptor - begin" + 3932 " deploymentDescriptorLocation = " + deploymentDescriptorLocation); 3933 3934 if (deploymentDescriptorLocation == null) return null; 3935 3936 J2EEModule j2eeModule = new J2EEModule(); 3937 3938 String str = j2eeModule.getStringForDDxml(deploymentDescriptorLocation); 3939 3940 if (str != null) { 3941 sLogger.log(Level.FINE, "getDeploymentDescriptor: for " + 3942 deploymentDescriptorLocation + " = " + 3943 str); 3944 } 3945 3946 return str; 3947 } 3948 3949 public String createMBean(String target, String className) throws CustomMBeanException { 3950 return ( cmo.createMBean(target, className) ); 3951 } 3952 3953 public String createMBean(String target, Map <String , String > params) throws CustomMBeanException { 3954 Map <String ,String > paramsCopy = new HashMap <String ,String >(params); 3955 return ( cmo.createMBean(target, paramsCopy) ); 3956 } 3957 3958 public String createMBean(String target, Map <String , String > params, Map <String , String > attributes) throws CustomMBeanException { 3959 Map <String ,String > paramsCopy = new HashMap <String ,String >(params); 3960 return ( cmo.createMBean(target, paramsCopy, attributes) ); 3961 } 3962 3963 public void createMBeanRef(String target, String ref) throws CustomMBeanException { 3964 cmo.createMBeanRef(target, ref); 3965 } 3966 3967 public String deleteMBean(String target, String name) throws CustomMBeanException { 3968 return ( cmo.deleteMBean(target, name) ); 3969 } 3970 3971 public void deleteMBeanRef(String target, String ref) throws CustomMBeanException { 3972 cmo.deleteMBeanRef(target, ref); 3973 } 3974 3975 public boolean existsMBean(String target, String name) throws CustomMBeanException { 3976 return ( cmcq.existsMBean(target, name) ); 3977 } 3978 3979 public boolean isMBeanEnabled(String target, String name) throws CustomMBeanException { 3980 return ( cmcq.isMBeanEnabled(target, name) ); 3981 } 3982 3983 public List <ObjectName > listMBeanConfigObjectNames(String target) throws CustomMBeanException { 3984 return ( cmcq.listMBeanConfigObjectNames(target) ); 3985 } 3986 3987 public List <ObjectName > listMBeanConfigObjectNames(String target, int type, boolean state) throws CustomMBeanException { 3988 return (cmcq.listMBeanConfigObjectNames(target, type, state) ); 3989 } 3990 3991 public List <String > listMBeanNames(String target) throws CustomMBeanException { 3992 return ( cmcq.listMBeanNames(target) ); 3993 } 3994 3995 4009 public MBeanInfo getMBeanInfo(String classname) throws CustomMBeanException { 4010 return ( cmo.getMBeanInfo(classname) ); 4011 } 4012} 4013 | Popular Tags |