Search in sources :

Example 1 with ManagementRepository

use of org.jboss.jca.core.api.management.ManagementRepository in project wildfly by wildfly.

the class EnlistmentTraceAttributeWriteHandler method applyUpdateToRuntime.

@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String parameterName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<List<DataSource>> handbackHolder) throws OperationFailedException {
    final String jndiName = context.readResource(PathAddress.EMPTY_ADDRESS).getModel().get(Constants.JNDI_NAME.getName()).asString();
    final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
    Boolean boolValue = Constants.ENLISTMENT_TRACE.resolveValue(context, newValue).asBoolean();
    try {
        final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
        if (repository.getDataSources() != null) {
            repository.getDataSources().stream().filter(ds -> jndiName.equalsIgnoreCase(ds.getJndiName())).forEach(ds -> ds.setEnlistmentTrace(boolValue));
            handbackHolder.setHandback(repository.getDataSources().stream().filter(ds -> jndiName.equalsIgnoreCase(ds.getJndiName())).collect(Collectors.toList()));
        }
    } catch (Exception e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToSetAttribute(e.getLocalizedMessage()));
    }
    return false;
}
Also used : AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) OperationContext(org.jboss.as.controller.OperationContext) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) PathAddress(org.jboss.as.controller.PathAddress) ConnectorLogger(org.jboss.as.connector.logging.ConnectorLogger) ConnectorServices(org.jboss.as.connector.util.ConnectorServices) ModelNode(org.jboss.dmr.ModelNode) Collectors(java.util.stream.Collectors) DataSource(org.jboss.jca.core.api.management.DataSource) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 2 with ManagementRepository

use of org.jboss.jca.core.api.management.ManagementRepository in project wildfly by wildfly.

the class PoolOperations method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String jndiName;
    ModelNode model;
    if (!address.getElement(0).getKey().equals(ModelDescriptionConstants.DEPLOYMENT) && (model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel()).isDefined()) {
        jndiName = Util.getJndiName(context, model);
    } else {
        jndiName = address.getLastElement().getValue();
    }
    final Object[] parameters = getParameters(context, operation);
    if (context.isNormalServer()) {
        context.addStep(new OperationStepHandler() {

            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                final ServiceController<?> managementRepoService = context.getServiceRegistry(disallowMonitor).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
                if (managementRepoService != null) {
                    ModelNode operationResult = null;
                    try {
                        final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
                        final List<Pool> pools = matcher.match(jndiName, repository);
                        if (pools.isEmpty()) {
                            throw ConnectorLogger.ROOT_LOGGER.failedToMatchPool(jndiName);
                        }
                        for (Pool pool : pools) {
                            operationResult = invokeCommandOn(pool, parameters);
                        }
                    } catch (Exception e) {
                        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToInvokeOperation(e.getLocalizedMessage()));
                    }
                    if (operationResult != null) {
                        context.getResult().set(operationResult);
                    }
                }
                context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
        }, OperationContext.Stage.RUNTIME);
    }
    context.stepCompleted();
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ArrayList(java.util.ArrayList) List(java.util.List) Pool(org.jboss.jca.core.api.connectionmanager.pool.Pool) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with ManagementRepository

use of org.jboss.jca.core.api.management.ManagementRepository in project wildfly by wildfly.

the class EnlistmentTraceAttributeWriteHandler method applyUpdateToRuntime.

@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String parameterName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<List<ConnectionManager>> handbackHolder) throws OperationFailedException {
    final String jndiName = context.readResource(PathAddress.EMPTY_ADDRESS).getModel().get(Constants.JNDINAME.getName()).asString();
    final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
    Boolean boolValue = Constants.ENLISTMENT_TRACE.resolveValue(context, newValue).asBoolean();
    try {
        final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
        if (repository.getConnectors() != null) {
            List<ConnectionManager> handback = new LinkedList<>();
            repository.getConnectors().stream().forEach(connector -> connector.getConnectionManagers().stream().filter(cm -> jndiName.equalsIgnoreCase(cm.getUniqueId())).forEach(cm -> {
                cm.setEnlistmentTrace(boolValue);
                handback.add(cm);
            }));
            handbackHolder.setHandback(handback);
        }
    } catch (Exception e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToSetAttribute(e.getLocalizedMessage()));
    }
    return false;
}
Also used : AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) OperationContext(org.jboss.as.controller.OperationContext) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) PathAddress(org.jboss.as.controller.PathAddress) ConnectionManager(org.jboss.jca.core.api.management.ConnectionManager) ConnectorLogger(org.jboss.as.connector.logging.ConnectorLogger) ConnectorServices(org.jboss.as.connector.util.ConnectorServices) ModelNode(org.jboss.dmr.ModelNode) LinkedList(java.util.LinkedList) ConnectionManager(org.jboss.jca.core.api.management.ConnectionManager) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) LinkedList(java.util.LinkedList) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

List (java.util.List)3 OperationContext (org.jboss.as.controller.OperationContext)3 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 PathAddress (org.jboss.as.controller.PathAddress)3 ModelNode (org.jboss.dmr.ModelNode)3 ManagementRepository (org.jboss.jca.core.api.management.ManagementRepository)3 ServiceController (org.jboss.msc.service.ServiceController)3 ConnectorLogger (org.jboss.as.connector.logging.ConnectorLogger)2 ConnectorServices (org.jboss.as.connector.util.ConnectorServices)2 AbstractWriteAttributeHandler (org.jboss.as.controller.AbstractWriteAttributeHandler)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Collectors (java.util.stream.Collectors)1 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)1 Pool (org.jboss.jca.core.api.connectionmanager.pool.Pool)1 ConnectionManager (org.jboss.jca.core.api.management.ConnectionManager)1 DataSource (org.jboss.jca.core.api.management.DataSource)1