/** * Extract the JNDI name from the resource. Collecting for resource valitation. * * @param resource * @return jndi name if present, null otherwise */ private String extractJNDIName(org.glassfish.resources.api.Resource resource) { HashMap attrs = resource.getAttributes(); return (String) attrs.get(JNDI_NAME); }
private boolean hasRAName(org.glassfish.resources.api.Resource resource) { return resource.getType().equals(ADMIN_OBJECT_RESOURCE) || resource.getType().equals(CONNECTOR_CONNECTION_POOL) || resource.getType().equals(RESOURCE_ADAPTER_CONFIG) || resource.getType().equals(CONNECTOR_WORK_SECURITY_MAP); }
/** * Extract the RA name for a connector resource. Collecting for resource validation. * * @param resource * @return resource adapter name */ private String extractRAName(org.glassfish.resources.api.Resource resource) { if (resource.getType().equals(ADMIN_OBJECT_RESOURCE)) return (String)resource.getAttributes().get(RES_ADAPTER); else return (String)resource.getAttributes().get(RES_ADAPTER_NAME); }
new ArrayList<Resource>(); for (org.glassfish.resources.api.Resource resource : resourcesToRegister) { final HashMap attrList = resource.getAttributes(); final Properties props = resource.getProperties(); String desc = resource.getDescription(); if (desc != null) { attrList.put("description", desc);
/** * preserve the resources such that they can be undeployed during deployment failure. * @param resources resources * @param appName application-name * @param moduleName module-name */ private static void preserveResources(Resources resources, String appName, String moduleName) { Map<String, Resources> allResources = ResourcesRegistry.getResources(appName); if(allResources != null){ allResources.put(moduleName, resources); }else{ allResources = new HashMap<String, Resources>(); allResources.put(moduleName, resources); ResourcesRegistry.putResources(appName, allResources); } }
private void cleanupPreservedResources(String appName, Properties properties) { if(properties != null){ String preserve = properties.getProperty(DeploymentProperties.PRESERVE_APP_SCOPED_RESOURCES); if(preserve != null && Boolean.valueOf(preserve)){ ResourcesRegistry.remove(appName); preservedApps.remove(appName); } } }
for (Property property : properties) { ResourceProperty rp = new ResourcePropertyImpl(property.getName(), property.getValue()); jr.addProperty(rp);
public void deployResources(String applicationName, boolean postDeployPhase) throws Exception { Map<String, Resources> allResources = ResourcesRegistry.getResources(applicationName); if(allResources != null){ for(Map.Entry<String, Resources> entry : allResources.entrySet()){ String moduleName = entry.getKey(); Resources resources = entry.getValue(); if(applicationName.equals(moduleName)){ deployResources(applicationName, null, resources.getResources(), postDeployPhase); }else{ deployResources(applicationName, moduleName, resources.getResources(), postDeployPhase); } } } } public void deployResources(String applicationName, String moduleName,
/** * Un-installs the external jndi resource. * * @param resource external jndi resource */ public void uninstallExternalJndiResource(JavaEEResource resource, ResourceInfo resourceInfo) { // removes the jndi context from the factory cache //String bindName = resource.getResourceInfo().getName(); JndiProxyObjectFactory.removeInitialContext(resource.getResourceInfo()); // removes the resource from jndi naming try { namingService.unpublishObject(resourceInfo, resourceInfo.getName()); /* TODO V3 handle jms later //START OF IASRI 4660565 if (((ExternalJndiResource)resource).isJMSConnectionFactory()) { nm.unpublishObject(IASJmsUtil.getXAConnectionFactoryName(resourceName)); } //END OF IASRI 4660565 */ } catch (javax.naming.NamingException e) { if (_logger.isLoggable(Level.FINE)) { _logger.log(Level.FINE, "Error while unpublishing resource: " + resourceInfo, e); } } }
private void preserveResources(Application app) { String appName = app.getName(); Map<String, Resources> allResources = new HashMap<String, Resources>(); Resources appScopedResources = app.getResources(); if(appScopedResources != null){ allResources.put(appName, appScopedResources); } List<Module> modules = app.getModule(); if(modules != null){ for(Module module : modules){ Resources moduleScopedResources = module.getResources(); if(moduleScopedResources != null){ allResources.put(module.getName(), moduleScopedResources); } } } //store the resource-configuration ResourcesRegistry.putResources(appName, allResources); }
private static org.glassfish.resources.api.Resource getPoolResource( String poolName, Collection<org.glassfish.resources.api.Resource> resources){ org.glassfish.resources.api.Resource result = null; for(org.glassfish.resources.api.Resource resource : resources){ if(resource.getType().equals(CONNECTOR_CONNECTION_POOL)){ String cpName = (String)resource.getAttributes().get(CONNECTION_POOL_NAME); if(poolName.equals(cpName)){ result = resource; break; } } } return result; }
if (deploymentPhase == OpsParams.Origin.deploy || deploymentPhase == OpsParams.Origin.deploy_instance || deploymentPhase == OpsParams.Origin.create_application_ref) { Map<String, Resources> allResources = ResourcesRegistry.remove(appName); if(allResources != null){ for(Map.Entry<String, Resources> entry : allResources.entrySet()){
private static boolean isEmbeddedRar(org.glassfish.resources.api.Resource resource, String attributeName) { boolean result = false; String raName = (String)resource.getAttributes().get(attributeName); if(raName != null && raName.contains(ResourceConstants.EMBEDDEDRAR_NAME_DELIMITER)){ result = true; } return result; }
private static boolean isConnectorResource(org.glassfish.resources.api.Resource resource){ if(resource.getType().equals(ADMIN_OBJECT_RESOURCE) || resource.getType().equals(CONNECTOR_CONNECTION_POOL) || resource.getType().equals(CONNECTOR_RESOURCE) || resource.getType().equals(RESOURCE_ADAPTER_CONFIG) || resource.getType().equals(CONNECTOR_WORK_SECURITY_MAP)){ return true; }else{ return false; } }
for (Property property : properties) { ResourceProperty rp = new ResourcePropertyImpl(property.getName(), property.getValue()); jr.addProperty(rp);
private static boolean isEmbeddedResource(org.glassfish.resources.api.Resource resource, Collection<org.glassfish.resources.api.Resource> resources){ boolean result = false; if(isConnectorResource(resource)){ String attributeName = null; if(resource.getType().equals(ADMIN_OBJECT_RESOURCE)){ attributeName = RES_ADAPTER; } else if(resource.getType().equals(CONNECTOR_CONNECTION_POOL)){ attributeName = RES_ADAPTER_NAME; } else if(resource.getType().equals(CONNECTOR_RESOURCE)){ String poolName = (String)resource.getAttributes().get(POOL_NAME); if(poolName != null){ org.glassfish.resources.api.Resource poolResource = getPoolResource(poolName, resources); //point to poolResource resource = poolResource; attributeName = RES_ADAPTER_NAME; } }/* else if(resource.getType().equals(org.glassfish.resources.api.Resource.RESOURCE_ADAPTER_CONFIG)){ attributeName = ResourceConstants.RES_ADAPTER_NAME; } */else if(resource.getType().equals(CONNECTOR_WORK_SECURITY_MAP)){ attributeName = RES_ADAPTER_NAME; } if(attributeName != null && resource != null){ result = isEmbeddedRar(resource, attributeName); } } return result; }
Map<String, Resources> allResources = ResourcesRegistry.remove(appName); Application oldApp = preservedApps.remove(appName); if (allResources != null && oldApp != null) {
private static void logAttributes(Resource res) { StringBuffer message = new StringBuffer(); Set<Map.Entry> entries = res.getAttributes().entrySet(); Iterator<Map.Entry> entriesIter = entries.iterator(); while(entriesIter.hasNext()){ Map.Entry entry = entriesIter.next(); message.append(entry.getKey()); message.append("="); message.append(entry.getValue()); message.append(" "); } if (_logger.isLoggable(Level.FINE)) { _logger.fine(localStrings.getString("resource.attributes", message.toString())); } } }
private static String getIdToCompare(final Resource res) { final HashMap attrs = res.getAttributes(); final String type = res.getType(); String id; if (org.glassfish.resources.api.Resource.JDBC_CONNECTION_POOL.equals(type) || Resource.CONNECTOR_CONNECTION_POOL.equals(type)){ id = getNamedAttributeValue(attrs, CONNECTION_POOL_NAME); // this should come from refactored stuff TBD } else if (org.glassfish.resources.api.Resource.CONNECTOR_SECURITY_MAP.equals(type)) { id = getNamedAttributeValue(attrs, SECURITY_MAP_NAME); // this should come from refactored stuff TBD } else if (org.glassfish.resources.api.Resource.RESOURCE_ADAPTER_CONFIG.equals(type)) { id = getNamedAttributeValue(attrs, RESOURCE_ADAPTER_CONFIG_NAME); // this should come from refactored stuff TBD } else if(org.glassfish.resources.api.Resource.CONNECTOR_WORK_SECURITY_MAP.equals(type)){ id = getNamedAttributeValue(attrs, WORK_SECURITY_MAP_NAME); } else { //it is OK to assume that this Resource will one of the *RESOURCEs? id = getNamedAttributeValue(attrs, JNDI_NAME); // this should come from refactored stuff TBD } return ( id ); }
/** * Event listener to listen to </code>application undeploy validation</code> and * if <i>preserveResources</i> flag is set, cache the <resources> * config for persisting it in domain.xml */ public void event(Event event) { if (event.is(Deployment.DEPLOYMENT_BEFORE_CLASSLOADER_CREATION)) { DeploymentContext dc = (DeploymentContext) event.hook(); final DeployCommandParameters deployParams = dc.getCommandParameters(DeployCommandParameters.class); processResources(dc, deployParams); }else if(event.is(Deployment.UNDEPLOYMENT_VALIDATION)){ DeploymentContext dc = (DeploymentContext) event.hook(); final UndeployCommandParameters undeployCommandParameters = dc.getCommandParameters(UndeployCommandParameters.class); preserveResources(dc, undeployCommandParameters); }else if(Deployment.UNDEPLOYMENT_FAILURE.equals(event.type())){ DeploymentContext dc = (DeploymentContext) event.hook(); cleanupPreservedResources(dc, event); }else if(Deployment.DEPLOYMENT_FAILURE.equals(event.type())){ DeploymentContext dc = (DeploymentContext) event.hook(); String appName = getAppNameFromDeployCmdParams(dc); cleanupResources(appName, dc.getCommandParameters(DeployCommandParameters.class).origin); //TODO ASR call this only when the flag is on ? --properties preserveAppScopedResources=true cleanupPreservedResources(dc, event); }else if(Deployment.DEPLOYMENT_SUCCESS.equals(event.type())){ ApplicationInfo applicationInfo = (ApplicationInfo) event.hook(); String appName = applicationInfo.getName(); ResourcesRegistry.remove(appName); } }