Search in sources :

Example 31 with DeploymentUnitProcessingException

use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.

the class WildFlyJobXmlResolver method forDeployment.

/**
     * Creates the {@linkplain JobXmlResolver resolver} for the deployment inheriting any visible resolvers and job XML
     * files from dependencies.
     *
     * @param deploymentUnit the deployment to process
     *
     * @return the resolve
     *
     * @throws DeploymentUnitProcessingException if an error occurs processing the deployment
     */
public static WildFlyJobXmlResolver forDeployment(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    // If this deployment unit already has a resolver, just use it
    if (deploymentUnit.hasAttachment(BatchAttachments.JOB_XML_RESOLVER)) {
        return deploymentUnit.getAttachment(BatchAttachments.JOB_XML_RESOLVER);
    }
    // Get the module for it's class loader
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ClassLoader classLoader = module.getClassLoader();
    WildFlyJobXmlResolver resolver;
    // access to the EAR/lib directory so those resources need to be processed
    if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        // Create a new WildFlyJobXmlResolver without jobs from sub-deployments as they'll be processed later
        final List<ResourceRoot> resources = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS).stream().filter(r -> !SubDeploymentMarker.isSubDeployment(r)).collect(Collectors.toList());
        resolver = create(classLoader, resources);
        deploymentUnit.putAttachment(BatchAttachments.JOB_XML_RESOLVER, resolver);
    } else {
        // Create a new resolver for this deployment
        if (deploymentUnit.hasAttachment(Attachments.RESOURCE_ROOTS)) {
            resolver = create(classLoader, deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS));
        } else {
            resolver = create(classLoader, Collections.singletonList(deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT)));
        }
        deploymentUnit.putAttachment(BatchAttachments.JOB_XML_RESOLVER, resolver);
        // Process all accessible sub-deployments
        final List<DeploymentUnit> accessibleDeployments = deploymentUnit.getAttachmentList(Attachments.ACCESSIBLE_SUB_DEPLOYMENTS);
        for (DeploymentUnit subDeployment : accessibleDeployments) {
            // Skip our self
            if (deploymentUnit.equals(subDeployment)) {
                continue;
            }
            if (subDeployment.hasAttachment(BatchAttachments.JOB_XML_RESOLVER)) {
                final WildFlyJobXmlResolver toCopy = subDeployment.getAttachment(BatchAttachments.JOB_XML_RESOLVER);
                WildFlyJobXmlResolver.merge(resolver, toCopy);
            } else {
                // We need to create a resolver for the sub-deployment and merge the two
                final WildFlyJobXmlResolver toCopy = forDeployment(subDeployment);
                subDeployment.putAttachment(BatchAttachments.JOB_XML_RESOLVER, toCopy);
                WildFlyJobXmlResolver.merge(resolver, toCopy);
            }
        }
    }
    return resolver;
}
Also used : JobXmlResolver(org.jberet.spi.JobXmlResolver) BatchLogger(org.wildfly.extension.batch.jberet._private.BatchLogger) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) DeploymentTypeMarker(org.jboss.as.ee.structure.DeploymentTypeMarker) SubDeploymentMarker(org.jboss.as.server.deployment.SubDeploymentMarker) ArrayList(java.util.ArrayList) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) VirtualFile(org.jboss.vfs.VirtualFile) XMLResolver(javax.xml.stream.XMLResolver) LinkedHashSet(java.util.LinkedHashSet) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) ServiceLoader(java.util.ServiceLoader) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) List(java.util.List) WildFlySecurityManager(org.wildfly.security.manager.WildFlySecurityManager) Module(org.jboss.modules.Module) DeploymentType(org.jboss.as.ee.structure.DeploymentType) JobParser(org.jberet.job.model.JobParser) Attachments(org.jboss.as.server.deployment.Attachments) VirtualFileFilter(org.jboss.vfs.VirtualFileFilter) Job(org.jberet.job.model.Job) AccessController(java.security.AccessController) Collections(java.util.Collections) InputStream(java.io.InputStream) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 32 with DeploymentUnitProcessingException

use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.

the class ApplicationClientParsingDeploymentProcessor method parseAppClient.

private ApplicationClientMetaData parseAppClient(DeploymentUnit deploymentUnit, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR);
    // Locate the descriptor
    final VirtualFile descriptor;
    if (alternateDescriptor != null) {
        descriptor = alternateDescriptor;
    } else {
        descriptor = deploymentRoot.getRoot().getChild(APP_XML);
    }
    if (descriptor.exists()) {
        InputStream is = null;
        try {
            is = descriptor.openStream();
            ApplicationClientMetaData data = new ApplicationClientMetaDataParser().parse(getXMLStreamReader(is), propertyReplacer);
            return data;
        } catch (XMLStreamException e) {
            throw AppClientLogger.ROOT_LOGGER.failedToParseXml(e, descriptor, e.getLocation().getLineNumber(), e.getLocation().getColumnNumber());
        } catch (IOException e) {
            throw new DeploymentUnitProcessingException("Failed to parse " + descriptor, e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            // Ignore
            }
        }
    } else {
        return null;
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) ApplicationClientMetaData(org.jboss.metadata.appclient.spec.ApplicationClientMetaData) IOException(java.io.IOException) ApplicationClientMetaDataParser(org.jboss.metadata.appclient.parser.spec.ApplicationClientMetaDataParser)

Example 33 with DeploymentUnitProcessingException

use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.

the class RaXmlDeploymentProcessor method deploy.

/**
     * Process a deployment for a Connector. Will install a {@Code
     * JBossService} for this ResourceAdapter.
     *
     * @param phaseContext the deployment unit context
     * @throws DeploymentUnitProcessingException
     */
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ManagementResourceRegistration baseRegistration = deploymentUnit.getAttachment(DeploymentModelUtils.MUTABLE_REGISTRATION_ATTACHMENT);
    final ManagementResourceRegistration registration;
    final Resource deploymentResource = phaseContext.getDeploymentUnit().getAttachment(DeploymentModelUtils.DEPLOYMENT_RESOURCE);
    final ConnectorXmlDescriptor connectorXmlDescriptor = deploymentUnit.getAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY);
    if (connectorXmlDescriptor == null) {
        // Skip non ra deployments
        return;
    }
    if (deploymentUnit.getParent() != null) {
        registration = baseRegistration.getSubModel(PathAddress.pathAddress(PathElement.pathElement("subdeployment")));
    } else {
        registration = baseRegistration;
    }
    ResourceAdaptersService.ModifiableResourceAdaptors raxmls = null;
    final ServiceController<?> raService = phaseContext.getServiceRegistry().getService(ConnectorServices.RESOURCEADAPTERS_SERVICE);
    if (raService != null)
        raxmls = ((ResourceAdaptersService.ModifiableResourceAdaptors) raService.getValue());
    ROOT_LOGGER.tracef("processing Raxml");
    Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null)
        throw ConnectorLogger.ROOT_LOGGER.failedToGetModuleAttachment(deploymentUnit);
    try {
        final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        String deploymentUnitPrefix = "";
        if (deploymentUnit.getParent() != null) {
            deploymentUnitPrefix = deploymentUnit.getParent().getName() + "#";
        }
        final String deploymentUnitName = deploymentUnitPrefix + deploymentUnit.getName();
        if (raxmls != null) {
            for (Activation raxml : raxmls.getActivations()) {
                String rarName = raxml.getArchive();
                if (deploymentUnitName.equals(rarName)) {
                    RaServicesFactory.createDeploymentService(registration, connectorXmlDescriptor, module, serviceTarget, deploymentUnitName, deploymentUnit.getServiceName(), deploymentUnitName, raxml, deploymentResource, phaseContext.getServiceRegistry());
                }
            }
        }
        //create service pointing to rar for other future activations
        ServiceName serviceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(deploymentUnitName);
        InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptor, module, deploymentUnitName, deploymentUnitName, deploymentUnit.getServiceName(), registration, serviceTarget, deploymentResource);
        ServiceBuilder builder = serviceTarget.addService(serviceName, service);
        builder.setInitialMode(Mode.ACTIVE).install();
    } catch (Throwable t) {
        throw new DeploymentUnitProcessingException(t);
    }
}
Also used : InactiveResourceAdapterDeploymentService(org.jboss.as.connector.services.resourceadapters.deployment.InactiveResourceAdapterDeploymentService) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ServiceTarget(org.jboss.msc.service.ServiceTarget) Resource(org.jboss.as.controller.registry.Resource) ConnectorXmlDescriptor(org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) ResourceAdaptersService(org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersService) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ServiceName(org.jboss.msc.service.ServiceName) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 34 with DeploymentUnitProcessingException

use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.

the class DataSourceDefinitionInjectionSource method getResourceValue.

public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final String poolName = uniqueName(context, jndiName);
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
    final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    try {
        final Class<?> clazz = module.getClassLoader().loadClass(className);
        clearUnknownProperties(reflectionIndex, clazz, properties);
        populateProperties(reflectionIndex, clazz, properties);
        DsSecurityImpl dsSecurity = new DsSecurityImpl(user, password, null, false, null, null);
        if (XADataSource.class.isAssignableFrom(clazz) && transactional) {
            final DsXaPoolImpl xaPool = new DsXaPoolImpl(minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize), initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize), maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize), Defaults.PREFILL, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY, Defaults.IS_SAME_RM_OVERRIDE, Defaults.INTERLEAVING, Defaults.PAD_XID, Defaults.WRAP_XA_RESOURCE, Defaults.NO_TX_SEPARATE_POOL, Boolean.FALSE, null, Defaults.FAIR, null);
            final ModifiableXaDataSource dataSource = new ModifiableXaDataSource(transactionIsolation(), null, dsSecurity, null, null, null, null, null, null, poolName, true, jndiName, false, false, Defaults.CONNECTABLE, Defaults.TRACKING, Defaults.MCP, Defaults.ENLISTMENT_TRACE, properties, className, null, null, xaPool, null);
            final XaDataSourceService xds = new XaDataSourceService(bindInfo.getBinderServiceName().getCanonicalName(), bindInfo, module.getClassLoader());
            xds.getDataSourceConfigInjector().inject(dataSource);
            startDataSource(xds, bindInfo, eeModuleDescription, context, phaseContext.getServiceTarget(), serviceBuilder, injector);
        } else {
            final DsPoolImpl commonPool = new DsPoolImpl(minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize), initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize), maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize), Defaults.PREFILL, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY, Boolean.FALSE, null, Defaults.FAIR, null);
            final ModifiableDataSource dataSource = new ModifiableDataSource(url, null, className, null, transactionIsolation(), properties, null, dsSecurity, null, null, null, null, null, false, poolName, true, jndiName, Defaults.SPY, Defaults.USE_CCM, transactional, Defaults.CONNECTABLE, Defaults.TRACKING, Defaults.MCP, Defaults.ENLISTMENT_TRACE, commonPool);
            final LocalDataSourceService ds = new LocalDataSourceService(bindInfo.getBinderServiceName().getCanonicalName(), bindInfo, module.getClassLoader());
            ds.getDataSourceConfigInjector().inject(dataSource);
            startDataSource(ds, bindInfo, eeModuleDescription, context, phaseContext.getServiceTarget(), serviceBuilder, injector);
        }
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XADataSource(javax.sql.XADataSource) ModifiableXaDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XaDataSourceService(org.jboss.as.connector.subsystems.datasources.XaDataSourceService) LocalDataSourceService(org.jboss.as.connector.subsystems.datasources.LocalDataSourceService) ModifiableDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableDataSource) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DsSecurityImpl(org.jboss.as.connector.metadata.ds.DsSecurityImpl) DsPoolImpl(org.jboss.jca.common.metadata.ds.DsPoolImpl) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) DsXaPoolImpl(org.jboss.jca.common.metadata.ds.DsXaPoolImpl) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 35 with DeploymentUnitProcessingException

use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.

the class PersistenceUnitParseProcessor method parse.

private void parse(final VirtualFile persistence_xml, final List<PersistenceUnitMetadataHolder> listPUHolders, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    ROOT_LOGGER.tracef("parse checking if %s exists, result = %b", persistence_xml.toString(), persistence_xml.exists());
    if (persistence_xml.exists() && persistence_xml.isFile()) {
        InputStream is = null;
        try {
            is = persistence_xml.openStream();
            final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            inputFactory.setXMLResolver(NoopXMLResolver.create());
            XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
            PersistenceUnitMetadataHolder puHolder = PersistenceUnitXmlParser.parse(xmlReader, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
            postParseSteps(persistence_xml, puHolder, deploymentUnit);
            listPUHolders.add(puHolder);
        } catch (Exception e) {
            throw new DeploymentUnitProcessingException(JpaLogger.ROOT_LOGGER.failedToParse(persistence_xml), e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            // Ignore
            }
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) InputStream(java.io.InputStream) IOException(java.io.IOException) XMLInputFactory(javax.xml.stream.XMLInputFactory) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)95 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)45 Module (org.jboss.modules.Module)28 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)26 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)26 VirtualFile (org.jboss.vfs.VirtualFile)22 InputStream (java.io.InputStream)20 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)18 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)18 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)18 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)17 ViewDescription (org.jboss.as.ee.component.ViewDescription)16 Method (java.lang.reflect.Method)15 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)15 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)15 ServiceName (org.jboss.msc.service.ServiceName)15 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)14 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)12 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)12