Search in sources :

Example 1 with XaDataSource

use of org.jboss.jca.common.api.metadata.ds.XaDataSource in project wildfly by wildfly.

the class XaDataSourcePropertyAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException {
    final String configPropertyValue = XADATASOURCE_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString();
    final ModelNode address = operation.require(OP_ADDR);
    PathAddress path = PathAddress.pathAddress(address);
    final String dsName = path.getElement(path.size() - 2).getValue();
    final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue();
    ServiceName serviceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName).append("xa-datasource-properties").append(configPropertyName);
    final ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceName dataSourceConfigServiceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
    final ServiceController<?> dataSourceConfigController = registry.getService(dataSourceConfigServiceName);
    if (dataSourceConfigController == null || !((XaDataSource) dataSourceConfigController.getValue()).isEnabled()) {
        final ServiceTarget serviceTarget = context.getServiceTarget();
        final XaDataSourcePropertiesService service = new XaDataSourcePropertiesService(configPropertyName, configPropertyValue);
        ServiceController<?> controller = serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.NEVER).install();
    } else {
        context.reloadRequired();
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) XaDataSource(org.jboss.jca.common.api.metadata.ds.XaDataSource)

Example 2 with XaDataSource

use of org.jboss.jca.common.api.metadata.ds.XaDataSource in project wildfly by wildfly.

the class DsXmlDeploymentInstallProcessor method deploy.

/**
 * Process a deployment for standard ra deployment files. Will parse the xml
 * file and attach a configuration discovered during processing.
 *
 * @param phaseContext the deployment unit context
 * @throws DeploymentUnitProcessingException
 */
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    final List<DataSources> dataSourcesList = deploymentUnit.getAttachmentList(DsXmlDeploymentParsingProcessor.DATA_SOURCES_ATTACHMENT_KEY);
    final boolean legacySecurityPresent = support.hasCapability("org.wildfly.legacy-security");
    for (DataSources dataSources : dataSourcesList) {
        if (dataSources.getDrivers() != null && !dataSources.getDrivers().isEmpty()) {
            ConnectorLogger.DS_DEPLOYER_LOGGER.driversElementNotSupported(deploymentUnit.getName());
        }
        ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        if (dataSources.getDataSource() != null && !dataSources.getDataSource().isEmpty()) {
            for (int i = 0; i < dataSources.getDataSource().size(); i++) {
                DataSource ds = (DataSource) dataSources.getDataSource().get(i);
                if (ds.isEnabled() && ds.getDriver() != null) {
                    try {
                        final String jndiName = Util.cleanJndiName(ds.getJndiName(), ds.isUseJavaContext());
                        LocalDataSourceService lds = new LocalDataSourceService(jndiName, ContextNames.bindInfoFor(jndiName));
                        lds.getDataSourceConfigInjector().inject(buildDataSource(ds));
                        final String dsName = ds.getJndiName();
                        final PathAddress addr = getDataSourceAddress(dsName, deploymentUnit, false);
                        installManagementModel(ds, deploymentUnit, addr);
                        // TODO why have we been ignoring a configured legacy security domain but no legacy security present?
                        boolean useLegacySecurity = legacySecurityPresent && isLegacySecurityRequired(ds.getSecurity());
                        startDataSource(lds, jndiName, ds.getDriver(), serviceTarget, getRegistration(false, deploymentUnit), getResource(dsName, false, deploymentUnit), dsName, useLegacySecurity, ds.isJTA(), support);
                    } catch (DeploymentUnitProcessingException dupe) {
                        throw dupe;
                    } catch (Exception e) {
                        throw ConnectorLogger.ROOT_LOGGER.exceptionDeployingDatasource(e, ds.getJndiName());
                    }
                } else {
                    ConnectorLogger.DS_DEPLOYER_LOGGER.debugf("Ignoring: %s", ds.getJndiName());
                }
            }
        }
        if (dataSources.getXaDataSource() != null && !dataSources.getXaDataSource().isEmpty()) {
            for (int i = 0; i < dataSources.getXaDataSource().size(); i++) {
                XaDataSource xads = (XaDataSource) dataSources.getXaDataSource().get(i);
                if (xads.isEnabled() && xads.getDriver() != null) {
                    try {
                        String jndiName = Util.cleanJndiName(xads.getJndiName(), xads.isUseJavaContext());
                        XaDataSourceService xds = new XaDataSourceService(jndiName, ContextNames.bindInfoFor(jndiName));
                        xds.getDataSourceConfigInjector().inject(buildXaDataSource(xads));
                        final String dsName = xads.getJndiName();
                        final PathAddress addr = getDataSourceAddress(dsName, deploymentUnit, true);
                        installManagementModel(xads, deploymentUnit, addr);
                        final Credential credential = xads.getRecovery() == null ? null : xads.getRecovery().getCredential();
                        // TODO why have we been ignoring a configured legacy security domain but no legacy security present?
                        boolean useLegacySecurity = legacySecurityPresent && (isLegacySecurityRequired(xads.getSecurity()) || isLegacySecurityRequired(credential));
                        startDataSource(xds, jndiName, xads.getDriver(), serviceTarget, getRegistration(true, deploymentUnit), getResource(dsName, true, deploymentUnit), dsName, useLegacySecurity, true, support);
                    } catch (Exception e) {
                        throw ConnectorLogger.ROOT_LOGGER.exceptionDeployingDatasource(e, xads.getJndiName());
                    }
                } else {
                    ConnectorLogger.DS_DEPLOYER_LOGGER.debugf("Ignoring %s", xads.getJndiName());
                }
            }
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) Credential(org.jboss.jca.common.api.metadata.common.Credential) ServiceTarget(org.jboss.msc.service.ServiceTarget) ModifiableXaDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource) XaDataSource(org.jboss.jca.common.api.metadata.ds.XaDataSource) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ModifiableXaDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource) XaDataSource(org.jboss.jca.common.api.metadata.ds.XaDataSource) ModifiableDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableDataSource) DataSource(org.jboss.jca.common.api.metadata.ds.DataSource) LocalDataSourceService(org.jboss.as.connector.subsystems.datasources.LocalDataSourceService) XaDataSourceService(org.jboss.as.connector.subsystems.datasources.XaDataSourceService) DataSources(org.jboss.jca.common.api.metadata.ds.DataSources) PathAddress(org.jboss.as.controller.PathAddress) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 3 with XaDataSource

use of org.jboss.jca.common.api.metadata.ds.XaDataSource in project wildfly by wildfly.

the class DsXmlDeploymentInstallProcessor method undeploy.

@Override
public void undeploy(final DeploymentUnit deploymentUnit) {
    final List<DataSources> dataSourcesList = deploymentUnit.getAttachmentList(DsXmlDeploymentParsingProcessor.DATA_SOURCES_ATTACHMENT_KEY);
    for (final DataSources dataSources : dataSourcesList) {
        if (dataSources.getDataSource() != null) {
            for (int i = 0; i < dataSources.getDataSource().size(); i++) {
                DataSource ds = dataSources.getDataSource().get(i);
                undeployDataSource(ds, deploymentUnit);
            }
        }
        if (dataSources.getXaDataSource() != null) {
            for (int i = 0; i < dataSources.getXaDataSource().size(); i++) {
                XaDataSource xads = dataSources.getXaDataSource().get(i);
                undeployXaDataSource(xads, deploymentUnit);
            }
        }
    }
    deploymentUnit.removeAttachment(DsXmlDeploymentParsingProcessor.DATA_SOURCES_ATTACHMENT_KEY);
}
Also used : DataSources(org.jboss.jca.common.api.metadata.ds.DataSources) ModifiableXaDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource) XaDataSource(org.jboss.jca.common.api.metadata.ds.XaDataSource) ModifiableXaDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource) XaDataSource(org.jboss.jca.common.api.metadata.ds.XaDataSource) ModifiableDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableDataSource) DataSource(org.jboss.jca.common.api.metadata.ds.DataSource)

Aggregations

XaDataSource (org.jboss.jca.common.api.metadata.ds.XaDataSource)3 ModifiableDataSource (org.jboss.as.connector.subsystems.datasources.ModifiableDataSource)2 ModifiableXaDataSource (org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource)2 PathAddress (org.jboss.as.controller.PathAddress)2 DataSource (org.jboss.jca.common.api.metadata.ds.DataSource)2 DataSources (org.jboss.jca.common.api.metadata.ds.DataSources)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 LocalDataSourceService (org.jboss.as.connector.subsystems.datasources.LocalDataSourceService)1 XaDataSourceService (org.jboss.as.connector.subsystems.datasources.XaDataSourceService)1 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 ModelNode (org.jboss.dmr.ModelNode)1 Credential (org.jboss.jca.common.api.metadata.common.Credential)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1