Search in sources :

Example 1 with DataSource

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

the class ConnectionPropertyAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException {
    final String configPropertyValue = CONNECTION_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString();
    final ModelNode address = operation.require(OP_ADDR);
    PathAddress path = PathAddress.pathAddress(address);
    final String jndiName = path.getElement(path.size() - 2).getValue();
    final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue();
    ServiceName serviceName = DataSourceConfigService.SERVICE_NAME_BASE.append(jndiName).append("connection-properties").append(configPropertyName);
    final ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceName dataSourceConfigServiceName = DataSourceConfigService.SERVICE_NAME_BASE.append(jndiName);
    final ServiceController<?> dataSourceConfigController = registry.getService(dataSourceConfigServiceName);
    if (dataSourceConfigController == null || !((DataSource) dataSourceConfigController.getValue()).isEnabled()) {
        final ServiceTarget serviceTarget = context.getServiceTarget();
        final ConnectionPropertiesService service = new ConnectionPropertiesService(configPropertyName, configPropertyValue);
        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) DataSource(org.jboss.jca.common.api.metadata.ds.DataSource)

Example 2 with DataSource

use of org.jboss.jca.common.api.metadata.ds.DataSource 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 org.jboss.as.server.deployment.DeploymentUnitProcessingException
     *
     */
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final List<DataSources> dataSourcesList = deploymentUnit.getAttachmentList(DsXmlDeploymentParsingProcessor.DATA_SOURCES_ATTACHMENT_KEY);
    final boolean legacySecurityPresent = phaseContext.getDeploymentUnit().hasAttachment(SecurityAttachments.SECURITY_ENABLED);
    for (DataSources dataSources : dataSourcesList) {
        if (dataSources.getDrivers() != null && dataSources.getDrivers().size() > 0) {
            ConnectorLogger.DS_DEPLOYER_LOGGER.driversElementNotSupported(deploymentUnit.getName());
        }
        ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        if (dataSources.getDataSource() != null && dataSources.getDataSource().size() > 0) {
            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());
                    } 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().size() > 0) {
            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);
                        // TODO why have we been ignoring a configured legacy security domain but no legacy security present?
                        boolean useLegacySecurity = legacySecurityPresent && isLegacySecurityRequired(xads.getSecurity());
                        startDataSource(xds, jndiName, xads.getDriver(), serviceTarget, getRegistration(true, deploymentUnit), getResource(dsName, true, deploymentUnit), dsName, useLegacySecurity, true);
                    } catch (Exception e) {
                        throw ConnectorLogger.ROOT_LOGGER.exceptionDeployingDatasource(e, xads.getJndiName());
                    }
                } else {
                    ConnectorLogger.DS_DEPLOYER_LOGGER.debugf("Ignoring %s", xads.getJndiName());
                }
            }
        }
    }
}
Also used : 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) 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 DataSource

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

the class DsXmlDeploymentInstallProcessor method undeploy.

public void undeploy(final DeploymentUnit context) {
    final List<DataSources> dataSourcesList = context.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 = (DataSource) dataSources.getDataSource().get(i);
                undeployDataSource(ds, context);
            }
        }
        if (dataSources.getXaDataSource() != null) {
            for (int i = 0; i < dataSources.getXaDataSource().size(); i++) {
                XaDataSource xads = (XaDataSource) dataSources.getXaDataSource().get(i);
                undeployXaDataSource(xads, context);
            }
        }
    }
}
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)

Example 4 with DataSource

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

the class DsXmlDeploymentParsingProcessor 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();
    boolean resolveProperties = Util.shouldResolveJBoss(deploymentUnit);
    final PropertyResolver propertyResolver = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_RESOLVER);
    final PropertyReplacer propertyReplacer = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_REPLACER);
    final Set<VirtualFile> files = dataSources(deploymentUnit);
    boolean loggedDeprication = false;
    for (VirtualFile f : files) {
        InputStream xmlStream = null;
        try {
            xmlStream = new FileInputStream(f.getPhysicalFile());
            DsXmlParser parser = new DsXmlParser(propertyResolver, propertyReplacer);
            parser.setSystemPropertiesResolved(resolveProperties);
            DataSources dataSources = parser.parse(xmlStream);
            if (dataSources != null) {
                if (!loggedDeprication) {
                    loggedDeprication = true;
                    ConnectorLogger.ROOT_LOGGER.deprecated();
                }
                for (DataSource ds : dataSources.getDataSource()) {
                    if (ds.getDriver() == null) {
                        throw ConnectorLogger.ROOT_LOGGER.FailedDeployDriverNotSpecified(ds.getJndiName());
                    }
                }
                deploymentUnit.addToAttachmentList(DATA_SOURCES_ATTACHMENT_KEY, dataSources);
            }
        } catch (Exception e) {
            throw new DeploymentUnitProcessingException(e.getMessage(), e);
        } finally {
            VFSUtils.safeClose(xmlStream);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PropertyResolver(org.jboss.metadata.property.PropertyResolver) FileInputStream(java.io.FileInputStream) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) DataSource(org.jboss.jca.common.api.metadata.ds.DataSource) DataSources(org.jboss.jca.common.api.metadata.ds.DataSources) DsXmlParser(org.jboss.as.connector.deployers.ds.DsXmlParser) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

DataSource (org.jboss.jca.common.api.metadata.ds.DataSource)4 DataSources (org.jboss.jca.common.api.metadata.ds.DataSources)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 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 XaDataSource (org.jboss.jca.common.api.metadata.ds.XaDataSource)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 DsXmlParser (org.jboss.as.connector.deployers.ds.DsXmlParser)1 LocalDataSourceService (org.jboss.as.connector.subsystems.datasources.LocalDataSourceService)1 XaDataSourceService (org.jboss.as.connector.subsystems.datasources.XaDataSourceService)1 ModelNode (org.jboss.dmr.ModelNode)1 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)1 PropertyResolver (org.jboss.metadata.property.PropertyResolver)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1 VirtualFile (org.jboss.vfs.VirtualFile)1