Search in sources :

Example 81 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class TransactionSubsystemAdd method performBoottime.

@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    checkIfNodeIdentifierIsDefault(context, model);
    boolean jts = model.hasDefined(JTS) && model.get(JTS).asBoolean();
    final Resource subsystemResource = context.readResourceFromRoot(PathAddress.pathAddress(TransactionExtension.SUBSYSTEM_PATH));
    final List<ServiceName> deps = new LinkedList<>();
    for (Resource.ResourceEntry re : subsystemResource.getChildren(CM_RESOURCE)) {
        deps.add(TxnServices.JBOSS_TXN_CMR.append(re.getName()));
    }
    //recovery environment
    performRecoveryEnvBoottime(context, model, jts, deps);
    //core environment
    performCoreEnvironmentBootTime(context, model);
    //coordinator environment
    performCoordinatorEnvBoottime(context, model, jts);
    //object store
    performObjectStoreBoottime(context, model);
    //always propagate the transaction context
    //TODO: need a better way to do this, but this value gets cached in a static
    //so we need to make sure we set it before anything tries to read it
    jtsPropertyManager.getJTSEnvironmentBean().setAlwaysPropagateContext(true);
    context.addStep(new AbstractDeploymentChainStep() {

        protected void execute(final DeploymentProcessorTarget processorTarget) {
            processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_TRANSACTION_ROLLBACK_ACTION, new TransactionLeakRollbackProcessor());
            processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_TRANSACTIONS_EE_CONCURRENCY, new EEConcurrencyContextHandleFactoryProcessor());
            processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_TRANSACTION_BINDINGS, new TransactionJndiBindingProcessor());
            processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_TRANSACTIONS, new TransactionDependenciesProcessor());
            processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_TRANSACTIONS, new CompensationsDependenciesDeploymentProcessor());
        }
    }, OperationContext.Stage.RUNTIME);
    //bind the TransactionManger and the TSR into JNDI
    final BinderService tmBinderService = new BinderService("TransactionManager");
    final ServiceBuilder<ManagedReferenceFactory> tmBuilder = context.getServiceTarget().addService(ContextNames.JBOSS_CONTEXT_SERVICE_NAME.append("TransactionManager"), tmBinderService);
    tmBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, tmBinderService.getNamingStoreInjector());
    tmBuilder.addDependency(TransactionManagerService.SERVICE_NAME, javax.transaction.TransactionManager.class, new Injector<javax.transaction.TransactionManager>() {

        @Override
        public void inject(final javax.transaction.TransactionManager value) throws InjectionException {
            tmBinderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value)));
        }

        @Override
        public void uninject() {
            tmBinderService.getManagedObjectInjector().uninject();
        }
    });
    tmBuilder.install();
    final BinderService tmLegacyBinderService = new BinderService("TransactionManager");
    final ServiceBuilder<ManagedReferenceFactory> tmLegacyBuilder = context.getServiceTarget().addService(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append("TransactionManager"), tmLegacyBinderService);
    tmLegacyBuilder.addDependency(ContextNames.JAVA_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, tmLegacyBinderService.getNamingStoreInjector());
    tmLegacyBuilder.addDependency(TransactionManagerService.SERVICE_NAME, javax.transaction.TransactionManager.class, new Injector<javax.transaction.TransactionManager>() {

        @Override
        public void inject(final javax.transaction.TransactionManager value) throws InjectionException {
            tmLegacyBinderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value)));
        }

        @Override
        public void uninject() {
            tmLegacyBinderService.getManagedObjectInjector().uninject();
        }
    });
    tmLegacyBuilder.install();
    final BinderService tsrBinderService = new BinderService("TransactionSynchronizationRegistry");
    final ServiceBuilder<ManagedReferenceFactory> tsrBuilder = context.getServiceTarget().addService(ContextNames.JBOSS_CONTEXT_SERVICE_NAME.append("TransactionSynchronizationRegistry"), tsrBinderService);
    tsrBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, tsrBinderService.getNamingStoreInjector());
    tsrBuilder.addDependency(TransactionSynchronizationRegistryService.SERVICE_NAME, TransactionSynchronizationRegistry.class, new Injector<TransactionSynchronizationRegistry>() {

        @Override
        public void inject(final TransactionSynchronizationRegistry value) throws InjectionException {
            tsrBinderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value)));
        }

        @Override
        public void uninject() {
            tsrBinderService.getManagedObjectInjector().uninject();
        }
    });
    tsrBuilder.install();
    // Install the UserTransactionAccessControlService
    final UserTransactionAccessControlService lookupControlService = new UserTransactionAccessControlService();
    context.getServiceTarget().addService(UserTransactionAccessControlService.SERVICE_NAME, lookupControlService).install();
    // Bind the UserTransaction into JNDI
    final UserTransactionBindingService userTransactionBindingService = new UserTransactionBindingService("UserTransaction");
    final ServiceBuilder<ManagedReferenceFactory> utBuilder = context.getServiceTarget().addService(ContextNames.JBOSS_CONTEXT_SERVICE_NAME.append("UserTransaction"), userTransactionBindingService);
    utBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, userTransactionBindingService.getNamingStoreInjector()).addDependency(UserTransactionAccessControlService.SERVICE_NAME, UserTransactionAccessControlService.class, userTransactionBindingService.getUserTransactionAccessControlServiceInjector()).addDependency(UserTransactionService.SERVICE_NAME, UserTransaction.class, new ManagedReferenceInjector<UserTransaction>(userTransactionBindingService.getManagedObjectInjector()));
    utBuilder.install();
    // install the EE Concurrency transaction setup provider's service
    final TransactionSetupProviderService transactionSetupProviderService = new TransactionSetupProviderService();
    context.getServiceTarget().addService(ConcurrentServiceNames.TRANSACTION_SETUP_PROVIDER_SERVICE_NAME, transactionSetupProviderService).addDependency(TransactionManagerService.SERVICE_NAME, TransactionManager.class, transactionSetupProviderService.getTransactionManagerInjectedValue()).install();
}
Also used : TransactionLeakRollbackProcessor(org.jboss.as.txn.deployment.TransactionLeakRollbackProcessor) EEConcurrencyContextHandleFactoryProcessor(org.jboss.as.txn.ee.concurrency.EEConcurrencyContextHandleFactoryProcessor) TransactionDependenciesProcessor(org.jboss.as.txn.deployment.TransactionDependenciesProcessor) BinderService(org.jboss.as.naming.service.BinderService) InjectionException(org.jboss.msc.inject.InjectionException) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) UserTransaction(javax.transaction.UserTransaction) Resource(org.jboss.as.controller.registry.Resource) UserTransactionBindingService(org.jboss.as.txn.service.UserTransactionBindingService) LinkedList(java.util.LinkedList) TransactionSetupProviderService(org.jboss.as.txn.ee.concurrency.TransactionSetupProviderService) DeploymentProcessorTarget(org.jboss.as.server.DeploymentProcessorTarget) ServiceName(org.jboss.msc.service.ServiceName) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) AbstractDeploymentChainStep(org.jboss.as.server.AbstractDeploymentChainStep) UserTransactionAccessControlService(org.jboss.as.txn.service.UserTransactionAccessControlService) TransactionManager(javax.transaction.TransactionManager) TransactionJndiBindingProcessor(org.jboss.as.txn.deployment.TransactionJndiBindingProcessor)

Example 82 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class LogStoreParticipantOperationHandler method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    MBeanServer mbs = TransactionExtension.getMBeanServer(context);
    final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    try {
        // Get the internal object name
        final ObjectName on = LogStoreResource.getObjectName(resource);
        //  Invoke the MBean operation
        mbs.invoke(on, operationName, null, null);
    } catch (Exception e) {
        throw new OperationFailedException("JMX error: " + e.getMessage());
    }
    // refresh the attributes of this participant (the status attribute should have changed to PREPARED
    refreshParticipant(context);
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 83 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class LogStoreProbeHandler method addTransactions.

private void addTransactions(final Resource parent, Set<ObjectInstance> transactions, MBeanServer mbs) throws IntrospectionException, InstanceNotFoundException, IOException, ReflectionException, MalformedObjectNameException {
    for (ObjectInstance oi : transactions) {
        String transactionId = oi.getObjectName().getCanonicalName();
        if (!transactionId.contains("puid") && transactionId.contains("itype")) {
            final Resource transaction = new LogStoreResource.LogStoreRuntimeResource(oi.getObjectName());
            final ModelNode model = transaction.getModel();
            Map<String, String> tAttributes = getMBeanValues(mbs, oi.getObjectName(), LogStoreConstants.TXN_JMX_NAMES);
            String txnId = tAttributes.get("Id");
            addAttributes(model, LogStoreConstants.MODEL_TO_JMX_TXN_NAMES, tAttributes);
            // model.get(LogStoreConstants.JMX_ON_ATTRIBUTE).set(transactionId);
            String participantQuery = transactionId + ",puid=*";
            Set<ObjectInstance> participants = mbs.queryMBeans(new ObjectName(participantQuery), null);
            addParticipants(transaction, participants, mbs);
            final PathElement element = PathElement.pathElement(LogStoreConstants.TRANSACTIONS, txnId);
            parent.registerChild(element, transaction);
        }
    }
}
Also used : PathElement(org.jboss.as.controller.PathElement) ObjectInstance(javax.management.ObjectInstance) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode) ObjectName(javax.management.ObjectName)

Example 84 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class LogStoreProbeHandler method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (!context.isNormalServer()) {
        context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
        return;
    }
    final MBeanServer mbs = TransactionExtension.getMBeanServer(context);
    if (mbs != null) {
        // Get the log-store resource
        final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
        assert resource instanceof LogStoreResource;
        final LogStoreResource logStore = (LogStoreResource) resource;
        // Get the expose-all-logs parameter value
        final ModelNode subModel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
        final boolean exposeAllLogs = LogStoreConstants.EXPOSE_ALL_LOGS.resolveModelAttribute(context, subModel).asBoolean();
        final Resource storeModel = probeTransactions(mbs, exposeAllLogs);
        // Replace the current model with an updated one
        context.acquireControllerLock();
        // WFLY-3020 -- don't drop the root model
        storeModel.writeModel(logStore.getModel());
        logStore.update(storeModel);
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode) MBeanServer(javax.management.MBeanServer)

Example 85 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class CacheResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) {
    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        builder.discardChildResource(NoStoreResourceDefinition.PATH);
    } else {
        NoStoreResourceDefinition.buildTransformation(version, builder);
    }
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        // Set batching=true if transaction mode=BATCH
        ResourceTransformer batchingTransformer = new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                PathAddress transactionAddress = address.append(TransactionResourceDefinition.PATH);
                try {
                    ModelNode transaction = context.readResourceFromRoot(transactionAddress).getModel();
                    if (transaction.hasDefined(TransactionResourceDefinition.Attribute.MODE.getName())) {
                        ModelNode mode = transaction.get(TransactionResourceDefinition.Attribute.MODE.getName());
                        if ((mode.getType() == ModelType.STRING) && (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH)) {
                            resource.getModel().get(DeprecatedAttribute.BATCHING.getName()).set(true);
                        }
                    }
                } catch (NoSuchElementException e) {
                // Ignore, nothing to convert
                }
                context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource).processChildren(resource);
            }
        };
        builder.setCustomResourceTransformer(batchingTransformer);
    }
    if (InfinispanModel.VERSION_1_5_0.requiresTransformation(version)) {
        builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, false, new ModelNode(true)), Attribute.STATISTICS_ENABLED.getDefinition()).addRejectCheck(RejectAttributeChecker.UNDEFINED, Attribute.STATISTICS_ENABLED.getDefinition()).addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, Attribute.STATISTICS_ENABLED.getDefinition()).addRejectCheck(new RejectAttributeChecker.SimpleRejectAttributeChecker(new ModelNode(false)), Attribute.STATISTICS_ENABLED.getDefinition());
    }
    LockingResourceDefinition.buildTransformation(version, builder);
    EvictionResourceDefinition.buildTransformation(version, builder);
    ExpirationResourceDefinition.buildTransformation(version, builder);
    TransactionResourceDefinition.buildTransformation(version, builder);
    FileStoreResourceDefinition.buildTransformation(version, builder);
    BinaryKeyedJDBCStoreResourceDefinition.buildTransformation(version, builder);
    MixedKeyedJDBCStoreResourceDefinition.buildTransformation(version, builder);
    StringKeyedJDBCStoreResourceDefinition.buildTransformation(version, builder);
    RemoteStoreResourceDefinition.buildTransformation(version, builder);
    CustomStoreResourceDefinition.buildTransformation(version, builder);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) ModelNode(org.jboss.dmr.ModelNode) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) RejectAttributeChecker(org.jboss.as.controller.transform.description.RejectAttributeChecker) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Resource (org.jboss.as.controller.registry.Resource)93 PathAddress (org.jboss.as.controller.PathAddress)52 ModelNode (org.jboss.dmr.ModelNode)52 PathElement (org.jboss.as.controller.PathElement)25 OperationFailedException (org.jboss.as.controller.OperationFailedException)24 OperationContext (org.jboss.as.controller.OperationContext)15 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)12 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)11 Map (java.util.Map)10 ServiceName (org.jboss.msc.service.ServiceName)10 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)9 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)6 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)6 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)6 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)6 ObjectName (javax.management.ObjectName)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5 ArrayList (java.util.ArrayList)4