@Override public <T> T getTransientAppMetaData(String metaDataKey, Class<T> metadataType) { return context.getTransientAppMetaData(metaDataKey, metadataType); }
@Override public String getJTADataSourceOverride() { return deploymentContext.getTransientAppMetaData(DatabaseConstants.JTA_DATASOURCE_JNDI_NAME_OVERRIDE, String.class); } }
public void setDeploymentContext(final DeploymentContext dc) { this.dc = dc; /* * Save the previous targets (if any), because the deploy command * processing will clear the transient app metadata which is * where the previous targets are stored. The previous targets are used * during redeployment if the target is "domain" which means "to all * targets where the app is already deployed." */ previousTargets = dc.getTransientAppMetaData("previousTargets", List.class); }
public BeansXml getBeansXml() { BeansXml result = null; WeldBootstrap wb = context.getTransientAppMetaData(WeldDeployer.WELD_BOOTSTRAP, WeldBootstrap.class); if (beansXmlURLs.size() == 1) { result = wb.parse(beansXmlURLs.get(0)); } else { // This method attempts to performs a merge, but loses some // information (e.g., version, bean-discovery-mode) result = wb.parse(beansXmlURLs); } return result; }
@Override protected Types getTypes() { if (wmInfo.getDeploymentContext()!=null) { return wmInfo.getDeploymentContext().getTransientAppMetaData(Types.class.getName(), Types.class); } else { return null; } }
protected BeansXml parseBeansXML(ReadableArchive archive, String beansXMLPath) throws IOException { WeldBootstrap wb = context.getTransientAppMetaData(WeldDeployer.WELD_BOOTSTRAP, WeldBootstrap.class); return wb.parse(getBeansXMLFileURL(archive, beansXMLPath)); }
/** * Retreives the client artifacts store from the provided deployment * context, creating one and storing it back into the DC if none is * there yet. * * @param dc the deployment context to hold the ClientArtifactsManager object * @return the ClientArtifactsManager object from the deployment context (created * and stored in the DC if needed) */ public static ClientArtifactsManager get(final DeploymentContext dc) { synchronized (dc) { ClientArtifactsManager result = dc.getTransientAppMetaData( CLIENT_ARTIFACTS_KEY, ClientArtifactsManager.class); if (result == null) { result = new ClientArtifactsManager(); dc.addTransientAppMetaData(CLIENT_ARTIFACTS_KEY, result); } return result; } }
@Override public Iterable<Metadata<Extension>> getExtensions() { if ( extensions != null ) { return extensions; } List<BeanDeploymentArchive> bdas = getBeanDeploymentArchives(); ArrayList<Metadata<Extension>> extnList = new ArrayList<Metadata<Extension>>(); for ( BeanDeploymentArchive bda : bdas ) { if ( ! ( bda instanceof RootBeanDeploymentArchive ) ) { ClassLoader moduleClassLoader = ( ( BeanDeploymentArchiveImpl ) bda ).getModuleClassLoaderForBDA(); extensions = context.getTransientAppMetaData( WeldDeployer.WELD_BOOTSTRAP, WeldBootstrap.class).loadExtensions( moduleClassLoader ); if ( extensions != null ) { for ( Metadata<Extension> bdaExtn : extensions ) { extnList.add(bdaExtn); } } } } return extnList; }
private boolean isDASTarget(DeploymentContext context, DeployCommandParameters params) { if (DeploymentUtils.isDASTarget(params.target)) { return true; } else if (DeploymentUtils.isDomainTarget(params.target)) { List<String> targets = context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class); if (targets == null) { targets = domain.getAllReferencedTargetsForApplication( params.name); } if (targets.size() == 1 && DeploymentUtils.isDASTarget(targets.get(0))) { return true; } } return false; } }
/** * Returns a collection of sniffers that recognized some parts of the * passed archive as components their container handle. * * If no sniffer recognize the passed archive, an empty collection is * returned. * * @param context the deployment context * @return possibly empty collection of sniffers that handle the passed * archive. */ public Collection<Sniffer> getSniffers(DeploymentContext context) { ReadableArchive archive = context.getSource(); ArchiveHandler handler = context.getArchiveHandler(); List<URI> uris = handler.getClassPathURIs(archive); Types types = context.getTransientAppMetaData(Types.class.getName(), Types.class); return getSniffers(context, uris, types); }
@SuppressWarnings("unchecked") public void decorate(T webComponent, WebModule wm) { if (wm.getWebBundleDescriptor().hasExtensionProperty(WeldDeployer.WELD_EXTENSION)) { DeploymentContext deploymentContext = wm.getWebModuleConfig().getDeploymentContext(); WeldBootstrap weldBootstrap = deploymentContext.getTransientAppMetaData( WeldDeployer.WELD_BOOTSTRAP, org.jboss.weld.bootstrap.WeldBootstrap.class); DeploymentImpl deploymentImpl = deploymentContext.getTransientAppMetaData( WeldDeployer.WELD_DEPLOYMENT, DeploymentImpl.class); Collection<BeanDeploymentArchive> deployments = deploymentImpl.getBeanDeploymentArchives(); BeanDeploymentArchive beanDeploymentArchive = deployments.iterator().next(); BeanManager beanManager = weldBootstrap.getManager(beanDeploymentArchive); // PENDING : Not available in this Web Beans Release CreationalContext<T> ccontext = beanManager.createCreationalContext(null); @SuppressWarnings("rawtypes") Class<T> clazz = (Class<T>) webComponent.getClass(); AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(clazz); InjectionTarget<T> injectionTarget = beanManager.createInjectionTarget(annotatedType); injectionTarget.inject(webComponent, ccontext); } } }
private boolean loadOnCurrentInstance(DeploymentContext context) { final DeployCommandParameters commandParams = context.getCommandParameters(DeployCommandParameters.class); final Properties appProps = context.getAppProps(); if (commandParams.enabled) { // if the current instance match with the target if (domain.isCurrentInstanceMatchingTarget(commandParams.target, commandParams.name(), server.getName(), context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class))) { return true; } if (server.isDas()) { String objectType = appProps.getProperty(ServerTags.OBJECT_TYPE); if (objectType != null) { // if it's a system application needs to be loaded on DAS if (objectType.equals(DeploymentProperties.SYSTEM_ADMIN) || objectType.equals(DeploymentProperties.SYSTEM_ALL)) { return true; } } } } return false; }
public boolean start(ApplicationContext startupContext) throws Exception { started = true; if (! initializeInOrder) { Boolean alreadyMarked = dc.getTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.class); if (! alreadyMarked.booleanValue()) { List<EjbApplication> ejbAppList = dc.getTransientAppMetaData(CONTAINER_LIST_KEY, List.class); for (EjbApplication app : ejbAppList) { app.markAllContainersAsStarted(); } dc.addTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.TRUE); } } try { DeployCommandParameters params = ((DeploymentContext)startupContext). getCommandParameters(DeployCommandParameters.class); for (Container container : containers) { container.startApplication(params.origin.isDeploy()); } singletonLCM.doStartup(this); } catch(Exception e) { abortInitializationAfterException(); throw e; } return true; }
private boolean loadOnCurrentInstance(DeploymentContext context) { final DeployCommandParameters commandParams = context.getCommandParameters(DeployCommandParameters.class); final Properties appProps = context.getAppProps(); if (commandParams.enabled) { // if the current instance match with the target if (domain.isCurrentInstanceMatchingTarget(commandParams.target, commandParams.name(), server.getName(), context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class))) { return true; } if (server.isDas()) { String objectType = appProps.getProperty(ServerTags.OBJECT_TYPE); if (objectType != null) { // if it's a system application needs to be loaded on DAS if (objectType.equals(DeploymentProperties.SYSTEM_ADMIN) || objectType.equals(DeploymentProperties.SYSTEM_ALL)) { return true; } } } } return false; }
public boolean start(ApplicationContext startupContext) throws Exception { started = true; if (! initializeInOrder) { Boolean alreadyMarked = dc.getTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.class); if (! alreadyMarked.booleanValue()) { List<EjbApplication> ejbAppList = dc.getTransientAppMetaData(CONTAINER_LIST_KEY, List.class); for (EjbApplication app : ejbAppList) { app.markAllContainersAsStarted(); } dc.addTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.TRUE); } } try { DeployCommandParameters params = ((DeploymentContext)startupContext). getCommandParameters(DeployCommandParameters.class); for (Container container : containers) { container.startApplication(params.origin.isDeploy()); } singletonLCM.doStartup(this); } catch(Exception e) { abortInitializationAfterException(); throw e; } return true; }
/** * Returns the Artifacts object from the deployment context with the * sepcified key prefix, creating a new one and storing it in the DC if * no matching Artifacts object already exists. * @param dc the deployment context * @param keyPrefix key prefix by which to look up or store the artifacts * @return */ public static Artifacts get( final DeploymentContext dc, final String keyPrefix) { final String key = transientAppMetadataKey(keyPrefix); synchronized (dc) { Artifacts result = dc.getTransientAppMetaData( transientAppMetadataKey(keyPrefix), Artifacts.class); if (result == null) { result = new Artifacts(keyPrefix); dc.addTransientAppMetaData(key, result); } return result; } }
/** * retain old resource configuration for the new archive being deployed. * @param dc DeploymentContext * @param allResources all resources (app scoped, module scoped) of old application * @throws Exception when unable to retain old resource configuration. */ public static void retainResourceConfig(DeploymentContext dc, Map<String, Resources> allResources) throws Exception { String appName = getAppNameFromDeployCmdParams(dc); Application application = dc.getTransientAppMetaData(Application.APPLICATION, Application.class); Resources appScopedResources = allResources.get(appName); if(appScopedResources != null){ application.setResources(appScopedResources); } if(DeploymentUtils.isEAR(dc.getSource())){ List<Module> modules = application.getModule(); if(modules != null){ for(Module module : modules){ Resources moduleScopedResources = allResources.get(module.getName()); if(moduleScopedResources != null){ module.setResources(moduleScopedResources); } } } } }
/** * retain old resource configuration for the new archive being deployed. * @param dc DeploymentContext * @param allResources all resources (app scoped, module scoped) of old application * @throws Exception when unable to retain old resource configuration. */ public void retainResourceConfig(DeploymentContext dc, Map<String, Resources> allResources) throws Exception { String appName = getAppNameFromDeployCmdParams(dc); Application application = dc.getTransientAppMetaData(ServerTags.APPLICATION, Application.class); Resources appScopedResources = allResources.get(appName); if(appScopedResources != null){ application.setResources(appScopedResources); } if(DeploymentUtils.isArchiveOfType(dc.getSource(), DOLUtils.earType(), locator)){ List<Module> modules = application.getModule(); if(modules != null){ for(Module module : modules){ Resources moduleScopedResources = allResources.get(module.getName()); if(moduleScopedResources != null){ module.setResources(moduleScopedResources); } } } } }
private void addModuleConfig(DeploymentContext dc, Application application) { DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class); if (!params.origin.isDeploy()) { return; } try { com.sun.enterprise.config.serverbeans.Application app_w = dc.getTransientAppMetaData(com.sun.enterprise.config.serverbeans.ServerTags.APPLICATION, com.sun.enterprise.config.serverbeans.Application.class); if (app_w != null) { if (application.isVirtual()) { Module modConfig = app_w.createChild(Module.class); app_w.getModule().add(modConfig); modConfig.setName(application.getRegistrationName()); } else { for (ModuleDescriptor moduleDesc : application.getModules()) { Module modConfig = app_w.createChild(Module.class); app_w.getModule().add(modConfig); modConfig.setName(moduleDesc.getArchiveUri()); } } } } catch (Exception e) { Logger.getAnonymousLogger().log(Level.WARNING, "failed to add the module config", e); } }
private static void createModuleScopedResources(Application app, Module module, List<org.glassfish.resource.common.Resource> resources, DeploymentContext dc, boolean embedded) throws ResourceException { try { if (resources != null) { Resources msc = dc.getTransientAppMetaData(module.getName()+"-resources", Resources.class); if (msc == null) { msc = module.createChild(Resources.class); module.setResources(msc); dc.addTransientAppMetaData(module.getName()+"-resources", msc); ApplicationInfo appInfo = appRegistry.get(app.getName()); if(appInfo != null){ appInfo.addTransientAppMetaData(module.getName()+"-resources", msc); } } createConfig(msc, resources, embedded); preserveResources(msc, app.getName(), module.getName()); } } catch (Exception e) { Object params[] = new Object[]{module.getName(),app.getName(), e}; _logger.log(Level.SEVERE, "gf.resources.module.scope.deployment.failure", params); throw new ResourceException(e); } }