Search in sources :

Example 1 with InactiveResourceAdapterDeploymentService

use of org.jboss.as.connector.services.resourceadapters.deployment.InactiveResourceAdapterDeploymentService in project wildfly by wildfly.

the class RaOperationUtil method installRaServicesAndDeployFromModule.

public static void installRaServicesAndDeployFromModule(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, String fullModuleName, final List<ServiceController<?>> newControllers) throws OperationFailedException {
    ServiceName raServiceName = installRaServices(context, name, resourceAdapter, newControllers);
    final boolean resolveProperties = true;
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final String moduleName;
    final CapabilityServiceSupport support = context.getCapabilityServiceSupport();
    // load module
    String slot = "main";
    if (fullModuleName.contains(":")) {
        slot = fullModuleName.substring(fullModuleName.indexOf(":") + 1);
        moduleName = fullModuleName.substring(0, fullModuleName.indexOf(":"));
    } else {
        moduleName = fullModuleName;
    }
    Module module;
    try {
        ModuleIdentifier moduleId = ModuleIdentifier.create(moduleName, slot);
        module = Module.getCallerModuleLoader().loadModule(moduleId);
    } catch (ModuleNotFoundException e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.raModuleNotFound(moduleName, e.getMessage()), e);
    } catch (ModuleLoadException e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
    }
    URL path = module.getExportedResource("META-INF/ra.xml");
    Closeable closable = null;
    try {
        VirtualFile child;
        if (path.getPath().contains("!")) {
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.compressedRarNotSupportedInModuleRA(moduleName));
        } else {
            child = VFS.getChild(path.getPath().split("META-INF")[0]);
            closable = VFS.mountReal(new File(path.getPath().split("META-INF")[0]), child);
        }
        // final Closeable closable = VFS.mountZip((InputStream) new JarInputStream(new FileInputStream(path.getPath().split("!")[0].split(":")[1])), path.getPath().split("!")[0].split(":")[1], child, TempFileProviderService.provider());
        final MountHandle mountHandle = new MountHandle(closable);
        final ResourceRoot resourceRoot = new ResourceRoot(child, mountHandle);
        final VirtualFile deploymentRoot = resourceRoot.getRoot();
        if (deploymentRoot == null || !deploymentRoot.exists())
            return;
        ConnectorXmlDescriptor connectorXmlDescriptor = RaDeploymentParsingProcessor.process(resolveProperties, deploymentRoot, null, name);
        IronJacamarXmlDescriptor ironJacamarXmlDescriptor = IronJacamarDeploymentParsingProcessor.process(deploymentRoot, resolveProperties);
        RaNativeProcessor.process(deploymentRoot);
        Map<ResourceRoot, Index> annotationIndexes = new HashMap<ResourceRoot, Index>();
        ResourceRootIndexer.indexResourceRoot(resourceRoot);
        Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
        if (index != null) {
            annotationIndexes.put(resourceRoot, index);
        }
        if (ironJacamarXmlDescriptor != null) {
            ConnectorLogger.SUBSYSTEM_RA_LOGGER.forceIJToNull();
            ironJacamarXmlDescriptor = null;
        }
        final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
        final ServiceController<?> deployerService = context.getServiceRegistry(true).getService(deployerServiceName);
        if (deployerService == null) {
            ServiceBuilder builder = ParsedRaDeploymentProcessor.process(connectorXmlDescriptor, ironJacamarXmlDescriptor, module.getClassLoader(), serviceTarget, annotationIndexes, RAR_MODULE.append(name), null, null, support);
            builder.requires(raServiceName);
            newControllers.add(builder.setInitialMode(ServiceController.Mode.ACTIVE).install());
        }
        String rarName = resourceAdapter.getArchive();
        if (fullModuleName.equals(rarName)) {
            ServiceName serviceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(name);
            InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptor, module, name, name, RAR_MODULE.append(name), null, serviceTarget, null);
            newControllers.add(serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).install());
        }
    } catch (Exception e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
    } finally {
        if (closable != null) {
            try {
                closable.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) VirtualFile(org.jboss.vfs.VirtualFile) HashMap(java.util.HashMap) Closeable(java.io.Closeable) ConnectorXmlDescriptor(org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor) Index(org.jboss.jandex.Index) URL(java.net.URL) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) InactiveResourceAdapterDeploymentService(org.jboss.as.connector.services.resourceadapters.deployment.InactiveResourceAdapterDeploymentService) ModuleNotFoundException(org.jboss.modules.ModuleNotFoundException) MountHandle(org.jboss.as.server.deployment.module.MountHandle) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) IOException(java.io.IOException) ModuleNotFoundException(org.jboss.modules.ModuleNotFoundException) IOException(java.io.IOException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModuleLoadException(org.jboss.modules.ModuleLoadException) ValidateException(org.jboss.jca.common.api.validator.ValidateException) ServiceName(org.jboss.msc.service.ServiceName) IronJacamarXmlDescriptor(org.jboss.as.connector.metadata.xmldescriptors.IronJacamarXmlDescriptor) Module(org.jboss.modules.Module) File(java.io.File) VirtualFile(org.jboss.vfs.VirtualFile)

Example 2 with InactiveResourceAdapterDeploymentService

use of org.jboss.as.connector.services.resourceadapters.deployment.InactiveResourceAdapterDeploymentService 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 = deploymentUnit.getAttachment(DeploymentModelUtils.DEPLOYMENT_RESOURCE);
    final ConnectorXmlDescriptor connectorXmlDescriptor = deploymentUnit.getAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY);
    final CapabilityServiceSupport support = deploymentUnit.getAttachment(CAPABILITY_SERVICE_SUPPORT);
    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);
    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(), support);
                }
            }
        }
        // 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) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ServiceName(org.jboss.msc.service.ServiceName) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

ConnectorXmlDescriptor (org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor)2 InactiveResourceAdapterDeploymentService (org.jboss.as.connector.services.resourceadapters.deployment.InactiveResourceAdapterDeploymentService)2 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)2 Module (org.jboss.modules.Module)2 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)2 ServiceName (org.jboss.msc.service.ServiceName)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 Closeable (java.io.Closeable)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 IronJacamarXmlDescriptor (org.jboss.as.connector.metadata.xmldescriptors.IronJacamarXmlDescriptor)1 ResourceAdaptersService (org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersService)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)1 Resource (org.jboss.as.controller.registry.Resource)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 MountHandle (org.jboss.as.server.deployment.module.MountHandle)1