1 23 24 package com.sun.enterprise.deployment.phasing; 25 26 import com.sun.enterprise.deployment.Application; 27 import com.sun.enterprise.deployment.util.DeploymentProperties; 28 29 import com.sun.enterprise.deployment.backend.DeploymentStatus; 30 import com.sun.enterprise.deployment.backend.DeploymentRequest; 31 import com.sun.enterprise.deployment.backend.DeployableObjectType; 32 import com.sun.enterprise.deployment.backend.DeploymentLogger; 33 import com.sun.enterprise.deployment.backend.IASDeploymentException; 34 35 import com.sun.enterprise.util.i18n.StringManager; 36 import com.sun.enterprise.resource.Resource; 37 import com.sun.enterprise.admin.common.MBeanServerFactory; 38 import com.sun.enterprise.admin.common.ObjectNames; 39 40 import javax.management.MBeanServer ; 41 import javax.management.ObjectName ; 42 import javax.management.MBeanException ; 43 44 import java.util.List ; 45 import java.util.ArrayList ; 46 import java.util.logging.Logger ; 47 48 51 public abstract class ResourcePhase extends DeploymentPhase { 52 53 protected static final String resourcesMBeanName = 54 "com.sun.appserv:type=resources,category=config"; 55 protected static final String CREATE_RESOURCE = 56 "createResource"; 57 protected static final String CREATE_RESOURCE_REF = 58 "createResourceReference"; 59 protected static final String CREATE_RESOURCE_AND_REF = 60 "createResourceAndResourceReference"; 61 protected static final String DELETE_RESOURCE = 62 "deleteResource"; 63 protected static final String DELETE_RESOURCE_REF = 64 "deleteResourceReference"; 65 protected static final String DELETE_RESOURCE_AND_REF = 66 "deleteResourceAndResourceReference"; 67 68 protected static final String DOMAIN_TARGET = 69 "domain"; 70 71 protected MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 72 73 protected void doResourceOperation(DeploymentRequest req) throws Exception { 74 String targetListString = req.getResourceTargetList(); 75 List <String > targetList = DeploymentServiceUtils.getTargetNamesFromTargetString(targetListString); 76 77 String resourceAction = req.getResourceAction(); 78 if (resourceAction == null || 79 getActualAction(resourceAction).equals( 80 DeploymentProperties.RES_NO_OP)) { 81 return; 82 } 83 84 if (targetList == null || targetList.isEmpty()) { 85 return; 86 } 87 88 List <Resource> resourceList = null; 89 90 Application app = DeploymentServiceUtils.getInstanceManager( 95 req.getType()).getRegisteredDescriptor(req.getName()); 96 97 if (app != null && app.getResourceList() != null && 100 !getForceParsing(resourceAction)) { 101 resourceList = (List <Resource>)app.getResourceList(); 102 } else { 105 resourceList = DeploymentServiceUtils.getResources( 106 req.getName(), req.getType()); 107 if (app != null) { 109 app.setResourceList(resourceList); 110 } 111 } 112 113 if (resourceList.size() == 0) { 115 return; 116 } 117 118 handleResources(resourceAction, targetList, 119 getRelevantResources(resourceList)); 120 } 121 122 123 protected void handleResources(String resourceAction, 124 List <String > targetList, List <Resource> resourceList) 125 throws Exception { 126 127 if (resourceList.size() == 0) { 129 return; 130 } 131 132 if (resourceAction.equals(DeploymentProperties.RES_DEPLOYMENT)) { 133 handleDeployment(targetList, resourceList); 134 } else if (resourceAction.equals(DeploymentProperties.RES_CREATE_REF)){ 135 handleCreateApplicationRef(targetList, resourceList); 136 } else if (resourceAction.equals(DeploymentProperties.RES_DELETE_REF)){ 137 handleDeleteApplicationRef(targetList, resourceList); 138 } else if (resourceAction.equals( 139 DeploymentProperties.RES_UNDEPLOYMENT)){ 140 handleUndeployment(targetList, resourceList); 141 } else if (resourceAction.equals( 142 DeploymentProperties.RES_REDEPLOYMENT)){ 143 handleRedeployment(targetList, resourceList); 144 } 145 } 146 147 protected void handleDeployment(List <String > targetList, 150 List <Resource> resourceList) throws Exception { 151 ObjectName mbeanName = new ObjectName (resourcesMBeanName); 152 153 if (targetList.size() == 1 && 155 targetList.get(0).equals(DOMAIN_TARGET)) { 156 String [] signature = new String []{ 157 "java.util.List", "java.lang.Boolean"}; 158 Object [] params = new Object []{resourceList, Boolean.TRUE}; 159 mbs.invoke(mbeanName, CREATE_RESOURCE, params, signature); 160 } else { 161 String [] signature = new String []{ 162 "java.util.List", "java.util.List", "java.lang.Boolean"}; 163 Object [] params = new Object []{resourceList, targetList, 164 Boolean.TRUE}; 165 mbs.invoke(mbeanName, CREATE_RESOURCE_AND_REF, params, signature); 166 } 167 } 168 169 protected void handleCreateApplicationRef(List <String > targetList, 171 List <Resource> resourceList) throws Exception { 172 ObjectName mbeanName = new ObjectName (resourcesMBeanName); 173 String [] signature = new String []{ 174 "java.util.List", "java.util.List", "java.lang.Boolean"}; 175 Object [] params = new Object []{resourceList, targetList, 176 Boolean.TRUE}; 177 mbs.invoke(mbeanName, CREATE_RESOURCE_REF, params, signature); 178 } 179 180 protected void handleUndeployment(List <String > targetList, 183 List <Resource> resourceList) throws Exception { 184 ObjectName mbeanName = new ObjectName (resourcesMBeanName); 185 186 if (targetList.size() == 1 && 188 targetList.get(0).equals(DOMAIN_TARGET)) { 189 String [] signature = new String []{"java.util.List"}; 190 Object [] params = new Object []{resourceList}; 191 mbs.invoke(mbeanName,DELETE_RESOURCE, params, signature); 192 } else { 193 String [] signature = new String []{ 194 "java.util.List", "java.util.List"}; 195 Object [] params = new Object []{resourceList, targetList}; 196 mbs.invoke(mbeanName, DELETE_RESOURCE_AND_REF, params, signature); 197 } 198 } 199 200 abstract protected void handleRedeployment(List <String > targetList, 201 List <Resource> resourceList) throws Exception ; 202 203 protected void handleDeleteApplicationRef(List <String > targetList, 205 List <Resource> resourceList) throws Exception { 206 ObjectName mbeanName = new ObjectName (resourcesMBeanName); 207 String [] signature = new String []{ 208 "java.util.List", "java.util.List"}; 209 Object [] params = new Object []{resourceList, targetList}; 210 mbs.invoke(mbeanName, DELETE_RESOURCE_REF, params, signature); 211 } 212 213 protected boolean getForceParsing(String resAction) { 214 return false; 215 } 216 217 protected String getActualAction(String resAction) { 218 return resAction; 219 } 220 221 abstract protected List <Resource> getRelevantResources( 222 List <Resource> allResources); 223 } 224 | Popular Tags |