Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2011, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.as.connector.subsystems.resourceadapters;
 
 
 import java.io.File;
 import java.net.URL;
 import java.util.List;
 import java.util.Map;
 
 import static org.jboss.as.connector.logging.ConnectorMessages.MESSAGES;
 import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION;
 import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS;
 import static org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS;
 import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS;
 import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES;
 import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS;
 import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES;
 import static org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES;
 import static org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE;
import static org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE;
import static org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE;
import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY;
import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL;
import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN;
import static org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY_WAIT_MILLIS;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.APPLICATION;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BEANVALIDATION_GROUPS;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BOOTSTRAP_CONTEXT;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CLASS_NAME;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENABLED;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.INTERLEAVING;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.JNDINAME;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NOTXSEPARATEPOOL;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NO_RECOVERY;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.PAD_XID;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERLUGIN_CLASSNAME;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERLUGIN_PROPERTIES;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_PASSWORD;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_SECURITY_DOMAIN;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_USERNAME;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SAME_RM_OVERRIDE;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN_AND_APPLICATION;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SHARABLE;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRANSACTION_SUPPORT;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.USE_CCM;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.USE_JAVA_CONTEXT;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_GROUPS;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_PRINCIPAL;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DOMAIN;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_FROM;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_GROUPS;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_REQUIRED;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_TO;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_USERS;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WRAP_XA_RESOURCE;
import static org.jboss.as.connector.subsystems.resourceadapters.Constants.XA_RESOURCE_TIMEOUT;
public class RaOperationUtil {
    public static final ServiceName RAR_MODULE = ServiceName.of("rarinsidemodule");
    public static ModifiableResourceAdapter buildResourceAdaptersObject(final String idfinal OperationContext contextModelNode operationString archiveOrModulethrows OperationFailedException {
        Map<StringStringconfigProperties = new HashMap<StringString>(0);
        List<CommonConnDefconnectionDefinitions = new ArrayList<CommonConnDef>(0);
        List<CommonAdminObjectadminObjects = new ArrayList<CommonAdminObject>(0);
        TransactionSupportEnum transactionSupport = operation.hasDefined(.getName()) ? TransactionSupportEnum
                .valueOf(operation.get(.getName()).asString()) : null;
        String bootstrapContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextoperation);
        List<StringbeanValidationGroups = .unwrap(contextoperation);
        boolean wmSecurity = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextoperation);
        WorkManager workManager = null;
        if (wmSecurity) {
            final boolean mappingRequired = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextoperation);
            final String domain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextoperation);
            final String defaultPrincipal = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextoperation);
            final List<StringdefaultGroups = .unwrap(contextoperation);
            final Map<StringStringgroups = ModelNodeUtil.extractMap(operation);
            final Map<StringStringusers = ModelNodeUtil.extractMap(operation);
            workManager = new WorkManagerImpl(new WorkManagerSecurityImpl(mappingRequireddomaindefaultPrincipaldefaultGroupsusersgroups));
        }
        ModifiableResourceAdapter ra;
        ra = new ModifiableResourceAdapter(idarchiveOrModuletransactionSupportconnectionDefinitions,
                adminObjectsconfigPropertiesbeanValidationGroupsbootstrapContextworkManager);
        return ra;
    }
    public static ModifiableConnDef buildConnectionDefinitionObject(final OperationContext contextfinal ModelNode connDefModelfinal String poolName,
                                                                    final boolean isXathrows OperationFailedExceptionValidateException {
        Map<StringStringconfigProperties = new HashMap<StringString>(0);
        String className = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextconnDefModel);
        String jndiName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextconnDefModel);
        boolean enabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        boolean useJavaContext = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        boolean useCcm = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        boolean sharable = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        boolean enlistment = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        int maxPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(contextconnDefModel);
        int minPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(contextconnDefModel);
        Integer initialPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(contextconnDefModel);
        boolean prefill = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        boolean useStrictMin = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        String flushStrategyString = .resolveModelAttribute(contextconnDefModel).asString();
        final FlushStrategy flushStrategy = FlushStrategy.forName(flushStrategyString);
        Boolean isSameRM  = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        boolean interlivng = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        boolean padXid = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        boolean wrapXaResource = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        boolean noTxSeparatePool = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        Integer allocationRetry = ModelNodeUtil.getIntIfSetOrGetDefault(contextconnDefModel);
        Long allocationRetryWaitMillis = ModelNodeUtil.getLongIfSetOrGetDefault(contextconnDefModel);
        Long blockingTimeoutMillis = ModelNodeUtil.getLongIfSetOrGetDefault(contextconnDefModel);
        Long idleTimeoutMinutes = ModelNodeUtil.getLongIfSetOrGetDefault(contextconnDefModel);
        Integer xaResourceTimeout = ModelNodeUtil.getIntIfSetOrGetDefault(contextconnDefModel);
        CommonTimeOut timeOut = new CommonTimeOutImpl(blockingTimeoutMillisidleTimeoutMinutesallocationRetry,
                allocationRetryWaitMillisxaResourceTimeout);
        Extension incrementer = ModelNodeUtil.extractExtension(contextconnDefModel);
        Extension decrementer = ModelNodeUtil.extractExtension(contextconnDefModel);
        final Capacity capacity = new Capacity(incrementerdecrementer);
        CommonPool pool;
        if (isXa) {
            pool = new ConnDefXaPoolImpl(minPoolSizeinitialPoolSizemaxPoolSizeprefilluseStrictMinflushStrategycapacityisSameRMinterlivngpadXidwrapXaResourcenoTxSeparatePool);
        } else {
            pool = new ConnDefPoolImpl(minPoolSizeinitialPoolSizemaxPoolSizeprefilluseStrictMinflushStrategycapacity);
        }
        String securityDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextconnDefModel);
        String securityDomainAndApplication = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextconnDefModel);
        boolean application = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        CommonSecurity security = null;
        if (securityDomain != null || securityDomainAndApplication != null || application) {
            security = new CommonSecurityImpl(securityDomainsecurityDomainAndApplicationapplication);
        }
        Long backgroundValidationMillis = ModelNodeUtil.getLongIfSetOrGetDefault(contextconnDefModel);
        boolean backgroundValidation = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        boolean useFastFail = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        CommonValidation validation = new CommonValidationImpl(backgroundValidationbackgroundValidationMillisuseFastFail);
        final String recoveryUsername = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextconnDefModel);
        final String recoveryPassword =  ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextconnDefModel);
        final String recoverySecurityDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextconnDefModel);
        Boolean noRecovery = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextconnDefModel);
        Recovery recovery = null;
        if ((recoveryUsername != null && recoveryPassword != null) || recoverySecurityDomain != null || noRecovery != null) {
            Credential credential = null;
            if ((recoveryUsername != null && recoveryPassword != null) || recoverySecurityDomain != null)
               credential = new CredentialImpl(recoveryUsernamerecoveryPasswordrecoverySecurityDomain);
            Extension recoverPlugin = ModelNodeUtil.extractExtension(contextconnDefModel);
            if (noRecovery == null)
                noRecovery = .;
            recovery = new Recovery(credentialrecoverPluginnoRecovery);
        }
        ModifiableConnDef connectionDefinition = new ModifiableConnDef(configPropertiesclassNamejndiNamepoolName,
                enableduseJavaContextuseCcmpooltimeOutvalidationsecurityrecoverysharableenlistment);
        return connectionDefinition;
    }
    public static ModifiableAdminObject buildAdminObjects(final OperationContext contextModelNode operationfinal String poolNamethrows OperationFailedExceptionValidateException {
        Map<StringStringconfigProperties = new HashMap<StringString>(0);
        String className = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextoperation);
        String jndiName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(contextoperation);
        boolean enabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextoperation);
        boolean useJavaContext = ModelNodeUtil.getBooleanIfSetOrGetDefault(contextoperation);
        ModifiableAdminObject adminObject = new ModifiableAdminObject(configPropertiesclassNamejndiNamepoolName,
                enableduseJavaContext);
        return adminObject;
    }
    public static ServiceName restartIfPresent(OperationContext contextfinal String raNamefinal String idServiceVerificationHandler svhthrows OperationFailedException {
        final ServiceName raDeploymentServiceName = ConnectorServices.getDeploymentServiceName(raNameid);
            final ServiceRegistry registry = context.getServiceRegistry(true);
            ServiceController raServiceController = registry.getService(raDeploymentServiceName);
            if (raServiceController != null) {
                final org.jboss.msc.service.ServiceController.Mode originalMode = raServiceController.getMode();
                if (svh != null) {
                    raServiceController.addListener(svh);
                }
                raServiceController.addListener(new AbstractServiceListener() {
                    @Override
                    public void transition(ServiceController controllerServiceController.Transition transition) {
                        switch (transition) {
                            case :
                                try {
                                    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(.id));
                                    ResourceAdapter raxml = (ResourceAdapterRaxmlController.getValue();
                                    ((ResourceAdapterXmlDeploymentServicecontroller.getService()).setRaxml(raxml);
                                    controller.compareAndSetMode(..originalMode);
                                } finally {
                                    controller.removeListener(this);
                                }
                        }
                    }
                    @Override
                    public void listenerAdded(ServiceController controller) {
                        controller.setMode(..);
                    }
                });
                return raDeploymentServiceName;
            } else {
                return null;
            }
    }
    public static boolean removeIfActive(OperationContext contextString raNameString id ) throws OperationFailedException {
        boolean wasActive = false;
        final ServiceName raDeploymentServiceName;
        if (raName == null) {
            raDeploymentServiceName = ConnectorServices.getDeploymentServiceName(id);
        } else {
            raDeploymentServiceName = ConnectorServices.getDeploymentServiceName(raNameid);
        }
        if(context.getServiceRegistry(true).getService(raDeploymentServiceName) != null){
            context.removeService(raDeploymentServiceName);
            wasActive = true;
        }
        return wasActive;
    }
    public static void activate(OperationContext contextString raNamefinal ServiceVerificationHandler serviceVerificationHandlerthrows OperationFailedException {
        ServiceRegistry registry = context.getServiceRegistry(true);
        final ServiceController<?> inactiveRaController = registry.getService(..append(raName));
        if (inactiveRaController == null) {
            throw .RARNotYetDeployed(raName);
        }
        final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(.raName));
        ResourceAdapter raxml = (ResourceAdapterRaxmlController.getValue();
        RaServicesFactory.createDeploymentService(inactive.getRegistration(), inactive.getConnectorXmlDescriptor(), inactive.getModule(), inactive.getServiceTarget(), raNameinactive.getDeploymentUnitServiceName(), inactive.getDeployment(), raxmlinactive.getResource(), serviceVerificationHandler);
    }
    public static ServiceName installRaServices(OperationContext contextServiceVerificationHandler verificationHandlerString nameModifiableResourceAdapter resourceAdapterfinal List<ServiceController<?>> newControllers) {
        final ServiceTarget serviceTarget = context.getServiceTarget();
        final ServiceController<?> resourceAdaptersService = context.getServiceRegistry(false).getService(
                .);
        if (resourceAdaptersService == null) {
            newControllers.add(serviceTarget.addService(.,
                    new ResourceAdaptersService()).setInitialMode(..).addListener(verificationHandler).install());
        }
        ServiceName raServiceName = ServiceName.of(.name);
        final ServiceController<?> service = context.getServiceRegistry(true).getService(raServiceName);
        if (service == null) {
            ResourceAdapterService raService = new ResourceAdapterService(resourceAdaptername);
            newControllers.add(serviceTarget.addService(raServiceNameraService).setInitialMode(..)
                    .addListener(verificationHandler).install());
        }
        return raServiceName;
    }
    public static void installRaServicesAndDeployFromModule(OperationContext contextServiceVerificationHandler verificationHandlerString nameModifiableResourceAdapter resourceAdapterString fullModuleNamefinal List<ServiceController<?>> newControllersthrows OperationFailedException{
        ServiceName raServiceName =  installRaServices(contextverificationHandlernameresourceAdapternewControllers);
        final boolean resolveProperties = true;
        final ServiceTarget serviceTarget = context.getServiceTarget();
        final String moduleName;
        //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(moduleNameslot);
            module = Module.getCallerModuleLoader().loadModule(moduleId);
        } catch (ModuleLoadException e) {
            throw new OperationFailedException(.failedToLoadModuleRA(moduleName), e);
        }
        URL path = module.getExportedResource("META-INF/ra.xml");
        Closeable closable = null;
            try {
                VirtualFile child;
                if (path.getPath().contains("!")) {
                    throw new OperationFailedException(.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(childmountHandle);
                final VirtualFile deploymentRoot = resourceRoot.getRoot();
                if (deploymentRoot == null || !deploymentRoot.exists())
                    return;
                ConnectorXmlDescriptor connectorXmlDescriptor = RaDeploymentParsingProcessor.process(resolvePropertiesdeploymentRootnullname);
                IronJacamarXmlDescriptor ironJacamarXmlDescriptor = IronJacamarDeploymentParsingProcessor.process(deploymentRootresolveProperties);
                RaNativeProcessor.process(deploymentRoot);
                Map<ResourceRootIndexannotationIndexes = new HashMap<ResourceRootIndex>();
                ResourceRootIndexer.indexResourceRoot(resourceRoot);
                Index index = resourceRoot.getAttachment(.);
                if (index != null) {
                    annotationIndexes.put(resourceRootindex);
                }
                if (ironJacamarXmlDescriptor != null) {
                    ..forceIJToNull();
                    ironJacamarXmlDescriptor = null;
                }
                final ServiceName deployerServiceName = ..append(connectorXmlDescriptor.getDeploymentName());
                final ServiceController<?> deployerService = context.getServiceRegistry(true).getService(deployerServiceName);
                if (deployerService == null) {
                    ServiceBuilder builder = ParsedRaDeploymentProcessor.process(connectorXmlDescriptorironJacamarXmlDescriptormodule.getClassLoader(), serviceTargetannotationIndexes.append(name), verificationHandler);
                    newControllers.add(builder.addDependency(raServiceName).setInitialMode(..).install());
                }
                String rarName = resourceAdapter.getArchive();
                if (fullModuleName.equals(rarName)) {
                    ServiceName serviceName = ..append(name);
                    InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptormodulenamename.append(name), nullserviceTargetnull);
                    newControllers.add(serviceTarget
                            .addService(serviceNameservice)
                            .setInitialMode(..).addListener(verificationHandler).install());
                }
            } catch (Exception e) {
                throw new OperationFailedException(.failedToLoadModuleRA(moduleName), e);
            } finally {
                if (closable != null) {
                    try {
                        closable.close();
                    } catch (IOException e) {
                    }
                }
            }
    }
New to GrepCode? Check out our FAQ X