1 23 24 32 33 package com.sun.enterprise.deployment.phasing; 34 35 import javax.management.MBeanServer ; 36 import javax.management.ObjectName ; 37 import javax.management.MBeanException ; 38 39 import com.sun.enterprise.deployment.backend.IASDeploymentException; 40 import com.sun.enterprise.deployment.backend.DeploymentRequest; 41 import com.sun.enterprise.deployment.backend.DeploymentEvent; 42 import com.sun.enterprise.deployment.backend.DeploymentEventType; 43 import com.sun.enterprise.deployment.backend.DeploymentEventInfo; 44 import com.sun.enterprise.deployment.backend.DeploymentLogger; 45 import com.sun.enterprise.deployment.backend.DeploymentStatus; 46 import com.sun.enterprise.deployment.backend.DeployableObjectType; 47 import com.sun.enterprise.deployment.util.DeploymentProperties; 48 import com.sun.enterprise.deployment.Application; 49 import com.sun.enterprise.util.i18n.StringManager; 50 import com.sun.enterprise.admin.event.BaseDeployEvent; 51 import com.sun.enterprise.admin.common.MBeanServerFactory; 52 import com.sun.enterprise.admin.common.ObjectNames; 53 import com.sun.enterprise.admin.server.core.AdminNotificationHelper; 54 import com.sun.enterprise.admin.server.core.AdminService; 55 import com.sun.enterprise.admin.AdminContext; 56 import com.sun.enterprise.server.Constants; 57 58 import java.util.logging.Level ; 59 import java.util.logging.Logger ; 60 61 66 public class ResourceAdapterStopPhase extends DeploymentPhase { 67 68 69 public static final Logger sLogger = DeploymentLogger.get(); 70 71 72 private static StringManager localStrings = 73 StringManager.getManager( ResourceAdapterStopPhase.class ); 74 75 79 public ResourceAdapterStopPhase(DeploymentContext deploymentCtx) 80 { 81 this.deploymentCtx = deploymentCtx; 82 this.name = RA_STOP; 83 } 84 85 88 public void prePhase(DeploymentPhaseContext phaseCtx) 89 { 90 DeploymentStatus status = phaseCtx.getDeploymentStatus(); 91 DeploymentRequest req = phaseCtx.getDeploymentRequest(); 92 String resourceAction = req.getResourceAction(); 93 94 if(!req.getCascade() && resourceAction.equals( 95 DeploymentProperties.RES_UNDEPLOYMENT)) { 96 try { 97 if(checkConnectorDependentResources( 98 req.getName(), status)) { 99 status.setStageStatus(DeploymentStatus.FAILURE); 100 String dependentResource = status.getStageStatusMessage(); 101 status.setStageStatusMessage(localStrings.getString( 102 "enterprise.deployment.phasing.stop.dependentresexist", new Object [] {dependentResource, req.getName()})); 103 } 104 } catch(Throwable t){ 105 status.setStageStatus(DeploymentStatus.FAILURE); 106 status.setStageException(t); 107 status.setStageStatusMessage(t.getMessage()); 108 } 109 } 110 } 111 112 117 public void runPhase(DeploymentPhaseContext phaseCtx) 118 { 119 String type = null; 120 121 DeploymentRequest req = phaseCtx.getDeploymentRequest(); 122 123 DeploymentTarget target = (DeploymentTarget)req.getTarget(); 124 DeploymentStatus status = phaseCtx.getDeploymentStatus(); 125 126 boolean containsRar = false; 127 128 if(!req.isApplication()) 129 { 130 type = DeploymentServiceUtils.getModuleTypeString(req.getType()); 131 if (req.isConnectorModule()) { 132 containsRar = true; 133 } 134 } else { 135 Application app = DeploymentServiceUtils.getInstanceManager( 136 DeployableObjectType.APP).getRegisteredDescriptor(req.getName()); 137 138 if ( (app != null) && (app.getRarComponentCount() != 0) ) { 139 containsRar = true; 140 } 141 } 142 143 if (!containsRar) { 144 status.setStageStatus(DeploymentStatus.SUCCESS); 145 return; 146 } 147 148 try { 149 if (req.getCascade() && !req.isForced()){ 150 deleteConnectorDependentResources(req.getName(), 151 target.getName()); 152 deploymentCtx.getConfigContext().flush(); 153 AdminContext adminContext = 154 AdminService.getAdminService().getAdminContext(); 155 new AdminNotificationHelper(adminContext).sendNotification(); 156 } 157 } catch(Throwable t){ 158 status.setStageStatus(DeploymentStatus.FAILURE); 159 status.setStageException(t); 160 status.setStageStatusMessage(t.getMessage()); 161 return; 162 } 163 164 prePhaseNotify(getPrePhaseEvent(req)); 165 166 boolean success; 167 try { 168 success = target.sendStopEvent(req.getActionCode(), req.getName(), type, req.getCascade(), req.isForced(), Constants.UNLOAD_RAR); 169 } catch(DeploymentTargetException dte) { 170 status.setStageStatus(DeploymentStatus.FAILURE); 171 if (dte.getCause()!=null) { 172 status.setStageException(dte.getCause()); 173 status.setStageStatusMessage(dte.getMessage()); 174 } 175 return; 176 } 177 if (success) { 178 status.setStageStatus(DeploymentStatus.SUCCESS); 179 } else { 180 status.setStageStatus(DeploymentStatus.FAILURE); 181 status.setStageStatusMessage("Application failed to stop"); 182 } 183 184 postPhaseNotify(getPostPhaseEvent(req)); 185 186 } 189 190 195 protected DeploymentEvent getPrePhaseEvent(DeploymentRequest req) 196 { 197 return new DeploymentEvent(DeploymentEventType.PRE_RA_STOP, new DeploymentEventInfo(req)); 198 } 199 200 205 protected DeploymentEvent getPostPhaseEvent(DeploymentRequest req) 206 { 207 return new DeploymentEvent(DeploymentEventType.POST_RA_STOP,new DeploymentEventInfo(req) ); 208 } 209 210 private boolean checkConnectorDependentResources( 211 String id, DeploymentStatus status) throws Exception { 212 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 213 ObjectName mbeanName = 214 new ObjectName ("com.sun.appserv:type=resources,category=config"); 215 216 Object [] params = new Object [] {}; 217 String [] signature = new String [] {}; 218 219 ObjectName [] adminObjs = 221 (ObjectName []) mbs.invoke(mbeanName, LIST_ADMIN_OBJECTS, 222 params, signature); 223 for(int i = 0 ; i< adminObjs.length;i++) { 224 String raName = 225 (String )mbs.getAttribute(adminObjs[i],"res_adapter"); 226 if(id.equals(raName)) { 227 String adminObjName = 228 (String )mbs.getAttribute(adminObjs[i], "jndi_name"); 229 status.setStageStatusMessage("admin object [" + adminObjName 230 + "]"); 231 return true; 232 } 233 } 234 235 ObjectName [] poolNames = (ObjectName [])mbs.invoke(mbeanName, 237 LIST_CONNECTOR_CONNECTION_POOLS, params, signature); 238 for (int i = 0 ; i< poolNames.length;i++) { 239 String raName = (String )mbs.getAttribute(poolNames[i], 240 "resource_adapter_name"); 241 if(id.equals(raName)) { 242 String poolName = (String )mbs.getAttribute(poolNames[i], 243 "name"); 244 status.setStageStatusMessage("connector connection pool [" + 245 poolName + "]"); 246 return true; 247 } 248 } 249 250 ObjectName [] resAdapterConfigs = (ObjectName [])mbs.invoke(mbeanName, 252 LIST_RESOURCE_ADAPTER_CONFIGS, params, signature); 253 for (int i = 0 ; i< resAdapterConfigs.length;i++) { 254 String raName = (String )mbs.getAttribute(resAdapterConfigs[i], 255 "resource_adapter_name"); 256 if(id.equals(raName)) { 257 status.setStageStatusMessage("resource adapter config"); 258 return true; 259 } 260 } 261 262 return false; 263 } 264 265 private void deleteConnectorDependentResources( 266 String id, String targetName) throws Exception { 267 try{ 268 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 269 ObjectName mbeanName = 270 new ObjectName ("com.sun.appserv:type=resources,category=config"); 271 272 Object [] params = new Object [] {}; 273 String [] signature = new String [] {}; 274 275 ObjectName [] adminObjs = 277 (ObjectName []) mbs.invoke(mbeanName, LIST_ADMIN_OBJECTS, 278 params, signature); 279 String [] adminObjSignature = new String []{ 280 "java.lang.String", "java.lang.String"}; 281 for(int i = 0 ; i< adminObjs.length;i++) { 282 String raName = 283 (String )mbs.getAttribute(adminObjs[i],"res_adapter"); 284 if(id.equals(raName)) { 285 String adminObjName = 286 (String )mbs.getAttribute(adminObjs[i],"jndi_name"); 287 Object [] deleteAdminParams = 288 new Object []{adminObjName, (String )targetName}; 289 mbs.invoke(mbeanName, 290 DELETE_ADMIN_OBJECT, deleteAdminParams, 291 adminObjSignature); 292 } 293 } 294 296 ObjectName [] poolNames = (ObjectName [])mbs.invoke(mbeanName, 298 LIST_CONNECTOR_CONNECTION_POOLS, params, signature); 299 String [] deletePoolSignature = new String [] {"java.lang.String", 300 "java.lang.Boolean", "java.lang.String"}; 301 for(int i = 0 ; i < poolNames.length ; i++) { 302 String raName = (String )mbs.getAttribute(poolNames[i], 303 "resource_adapter_name"); 304 if(id.equals(raName)) { 305 String poolName = (String )mbs.getAttribute(poolNames[i], 306 "name"); 307 Object [] deletePoolParams = new Object [] {poolName, 308 Boolean.TRUE, (String )targetName}; 309 mbs.invoke(mbeanName, DELETE_CONNECTOR_CONNECTION_POOL, 310 deletePoolParams, deletePoolSignature); 311 } 312 } 313 315 ObjectName [] resAdapterConfigs = (ObjectName [])mbs.invoke( 317 mbeanName, LIST_RESOURCE_ADAPTER_CONFIGS, params, signature); 318 String [] adapterConfigSignature = new String []{ 319 "java.lang.String", "java.lang.String"}; 320 Object [] adapterConfigParams = new Object []{id, (String )targetName}; 321 for(int i = 0 ; i < resAdapterConfigs.length ; i++) { 322 String raName = (String )mbs.getAttribute(resAdapterConfigs[i], 323 "resource_adapter_name"); 324 if(id.equals(raName)) { 325 mbs.invoke(mbeanName, DELETE_RESOURCE_ADAPTER_CONFIG, 326 adapterConfigParams, adapterConfigSignature); 327 } 328 } 329 331 }catch(Exception e){ 332 throw new DeploymentPhaseException(getName(), "Exception occured while deleting dependent connector resources", e); 334 } 335 } 336 337 private static final String LIST_ADMIN_OBJECTS = 338 "getAdminObjectResource"; 339 private static final String DELETE_ADMIN_OBJECT = 340 "deleteAdminObjectResource"; 341 private static final String LIST_CONNECTOR_CONNECTION_POOLS = 342 "getConnectorConnectionPool"; 343 private static final String DELETE_CONNECTOR_CONNECTION_POOL = 344 "deleteConnectorConnectionPool"; 345 private static final String LIST_RESOURCE_ADAPTER_CONFIGS = 346 "getResourceAdapterConfig"; 347 private static final String DELETE_RESOURCE_ADAPTER_CONFIG = 348 "deleteResourceAdapterConfig"; 349 350 } 351 | Popular Tags |