Search in sources :

Example 51 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class IronJacamarResourceCreator method addResourceAdapter.

private void addResourceAdapter(final Resource parent, String name, Activation ironJacamarMetadata) {
    final Resource ijResourceAdapter = new IronJacamarResource.IronJacamarRuntimeResource();
    final ModelNode model = ijResourceAdapter.getModel();
    model.get(Constants.ARCHIVE.getName()).set(name);
    setAttribute(model, Constants.BOOTSTRAP_CONTEXT, ironJacamarMetadata.getBootstrapContext());
    if (ironJacamarMetadata.getTransactionSupport() != null)
        model.get(Constants.TRANSACTION_SUPPORT.getName()).set(ironJacamarMetadata.getTransactionSupport().name());
    if (ironJacamarMetadata.getWorkManager() != null && ironJacamarMetadata.getWorkManager().getSecurity() != null) {
        org.jboss.jca.common.api.metadata.resourceadapter.WorkManagerSecurity security = ironJacamarMetadata.getWorkManager().getSecurity();
        model.get(Constants.WM_SECURITY.getName()).set(true);
        if (security.getDefaultGroups() != null) {
            for (String group : security.getDefaultGroups()) {
                model.get(Constants.WM_SECURITY_DEFAULT_GROUPS.getName()).add(group);
            }
        }
        if (security.getDefaultPrincipal() != null)
            model.get(Constants.WM_SECURITY_DEFAULT_PRINCIPAL.getName()).set(security.getDefaultPrincipal());
        model.get(Constants.WM_SECURITY_MAPPING_REQUIRED.getName()).set(security.isMappingRequired());
        if (security instanceof WorkManagerSecurity && ((WorkManagerSecurity) security).isElytronEnabled()) {
            model.get(Constants.WM_ELYTRON_SECURITY_DOMAIN.getName()).set(security.getDomain());
        } else {
            model.get(Constants.WM_SECURITY_DOMAIN.getName()).set(security.getDomain());
        }
        if (security.getGroupMappings() != null) {
            for (Map.Entry<String, String> entry : security.getGroupMappings().entrySet()) {
                final Resource mapping = new IronJacamarResource.IronJacamarRuntimeResource();
                final ModelNode subModel = mapping.getModel();
                subModel.get(Constants.WM_SECURITY_MAPPING_FROM.getName()).set(entry.getKey());
                subModel.get(Constants.WM_SECURITY_MAPPING_TO.getName()).set(entry.getKey());
                final PathElement element = PathElement.pathElement(Constants.WM_SECURITY_MAPPING_GROUPS.getName(), WM_SECURITY_MAPPING_GROUP.getName());
                ijResourceAdapter.registerChild(element, mapping);
            }
        }
        if (security.getUserMappings() != null) {
            for (Map.Entry<String, String> entry : security.getUserMappings().entrySet()) {
                final Resource mapping = new IronJacamarResource.IronJacamarRuntimeResource();
                final ModelNode subModel = mapping.getModel();
                subModel.get(Constants.WM_SECURITY_MAPPING_FROM.getName()).set(entry.getKey());
                subModel.get(Constants.WM_SECURITY_MAPPING_TO.getName()).set(entry.getKey());
                final PathElement element = PathElement.pathElement(Constants.WM_SECURITY_MAPPING_USERS.getName(), WM_SECURITY_MAPPING_USER.getName());
                ijResourceAdapter.registerChild(element, mapping);
            }
        }
    }
    if (ironJacamarMetadata.getBeanValidationGroups() != null) {
        for (String bv : ironJacamarMetadata.getBeanValidationGroups()) {
            model.get(Constants.BEANVALIDATION_GROUPS.getName()).add(new ModelNode().set(bv));
        }
    }
    if (ironJacamarMetadata.getConfigProperties() != null) {
        for (Map.Entry<String, String> config : ironJacamarMetadata.getConfigProperties().entrySet()) {
            addConfigProperties(ijResourceAdapter, config.getKey(), config.getValue());
        }
    }
    if (ironJacamarMetadata.getConnectionDefinitions() != null) {
        for (ConnectionDefinition connDef : ironJacamarMetadata.getConnectionDefinitions()) {
            addConnectionDefinition(ijResourceAdapter, connDef);
        }
    }
    if (ironJacamarMetadata.getAdminObjects() != null) {
        for (AdminObject adminObject : ironJacamarMetadata.getAdminObjects()) {
            addAdminObject(ijResourceAdapter, adminObject);
        }
    }
    final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource();
    ijResourceAdapter.registerChild(PathElement.pathElement(Constants.STATISTICS_NAME, "local"), statsResource);
    final PathElement element = PathElement.pathElement(Constants.RESOURCEADAPTER_NAME, name);
    parent.registerChild(element, ijResourceAdapter);
}
Also used : ConnectionDefinition(org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition) Resource(org.jboss.as.controller.registry.Resource) WorkManagerSecurity(org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity) PathElement(org.jboss.as.controller.PathElement) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) AdminObject(org.jboss.jca.common.api.metadata.resourceadapter.AdminObject)

Example 52 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class IronJacamarResourceCreator method addConfigProperties.

private void addConfigProperties(final Resource parent, String name, String value) {
    final Resource config = new IronJacamarResource.IronJacamarRuntimeResource();
    final ModelNode model = config.getModel();
    model.get(Constants.CONFIG_PROPERTY_VALUE.getName()).set(value);
    final PathElement element = PathElement.pathElement(Constants.CONFIG_PROPERTIES.getName(), name);
    parent.registerChild(element, config);
}
Also used : PathElement(org.jboss.as.controller.PathElement) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 53 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class IronJacamarResourceCreator method addAdminObject.

private void addAdminObject(final Resource parent, AdminObject adminObject) {
    final Resource adminObjectResource = new IronJacamarResource.IronJacamarRuntimeResource();
    final ModelNode model = adminObjectResource.getModel();
    setAttribute(model, CLASS_NAME, adminObject.getClassName());
    setAttribute(model, JNDINAME, adminObject.getJndiName());
    setAttribute(model, USE_JAVA_CONTEXT, adminObject.isUseJavaContext());
    setAttribute(model, ENABLED, adminObject.isEnabled());
    if (adminObject.getConfigProperties() != null) {
        for (Map.Entry<String, String> config : adminObject.getConfigProperties().entrySet()) {
            addConfigProperties(adminObjectResource, config.getKey(), config.getValue());
        }
    }
    final PathElement element = PathElement.pathElement(Constants.ADMIN_OBJECTS_NAME, adminObject.getJndiName());
    parent.registerChild(element, adminObjectResource);
}
Also used : PathElement(org.jboss.as.controller.PathElement) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Example 54 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class RaActivate method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    final String idName = PathAddress.pathAddress(address).getLastElement().getValue();
    ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
    final String archiveOrModuleName;
    if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (model.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
    } else {
        archiveOrModuleName = model.get(MODULE.getName()).asString();
    }
    if (context.isNormalServer()) {
        context.addStep(new OperationStepHandler() {

            public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException {
                ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, idName);
                if (restartedServiceName == null) {
                    RaOperationUtil.activate(context, idName, archiveOrModuleName);
                }
                context.completeStep(new OperationContext.RollbackHandler() {

                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                        try {
                            RaOperationUtil.removeIfActive(context, archiveOrModuleName, idName);
                        } catch (OperationFailedException e) {
                        }
                    }
                });
            }
        }, OperationContext.Stage.RUNTIME);
    }
    context.stepCompleted();
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ServiceName(org.jboss.msc.service.ServiceName) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

Example 55 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class RaAdd method performRuntime.

@Override
public void performRuntime(final OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode model = resource.getModel();
    // domains/application attributes should only be defined when Elytron enabled is undefined or false (default value)
    if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(SECURITY_DOMAIN.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(APPLICATION.getName(), ELYTRON_ENABLED.getName());
    } else {
        if (model.hasDefined(AUTHENTICATION_CONTEXT.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
    }
    // do the same for recovery security attributes
    if (RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    } else {
        if (model.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    }
    // Compensating is remove
    final String name = context.getCurrentAddressValue();
    final String archiveOrModuleName;
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (model.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
    } else {
        archiveOrModuleName = model.get(MODULE.getName()).asString();
    }
    ModifiableResourceAdapter resourceAdapter = RaOperationUtil.buildResourceAdaptersObject(name, context, operation, archiveOrModuleName);
    List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>();
    if (model.get(ARCHIVE.getName()).isDefined()) {
        RaOperationUtil.installRaServices(context, name, resourceAdapter, newControllers);
    } else {
        RaOperationUtil.installRaServicesAndDeployFromModule(context, name, resourceAdapter, archiveOrModuleName, newControllers);
        if (context.isBooting()) {
            context.addStep(new OperationStepHandler() {

                public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException {
                    //Next lines activate configuration on module deployed rar
                    //in case there is 2 different resource-adapter config using same module deployed rar
                    // a Deployment sercivice could be already present and need a restart to consider also this
                    //newly added configuration
                    ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, name);
                    if (restartedServiceName == null) {
                        RaOperationUtil.activate(context, name, archiveOrModuleName);
                    }
                    context.completeStep(new OperationContext.RollbackHandler() {

                        @Override
                        public void handleRollback(OperationContext context, ModelNode operation) {
                            try {
                                RaOperationUtil.removeIfActive(context, archiveOrModuleName, name);
                            } catch (OperationFailedException e) {
                            }
                        }
                    });
                }
            }, OperationContext.Stage.RUNTIME);
        }
    }
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, name));
    Activation raxml = (Activation) RaxmlController.getValue();
    ServiceName serviceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, name);
    String bootStrapCtxName = DEFAULT_NAME;
    if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
        bootStrapCtxName = raxml.getBootstrapContext();
    }
    ResourceAdapterStatisticsService raStatsService = new ResourceAdapterStatisticsService(context.getResourceRegistrationForUpdate(), name, statsEnabled);
    ServiceBuilder statsServiceBuilder = context.getServiceTarget().addService(ServiceName.of(ConnectorServices.RA_SERVICE, name).append(ConnectorServices.STATISTICS_SUFFIX), raStatsService);
    statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), raStatsService.getBootstrapContextInjector()).addDependency(serviceName, raStatsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
    final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource();
    resource.registerChild(peStats, statsResource);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ResourceAdapterStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.ResourceAdapterStatisticsService) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ModelNode (org.jboss.dmr.ModelNode)1634 PathAddress (org.jboss.as.controller.PathAddress)351 Test (org.junit.Test)344 KernelServices (org.jboss.as.subsystem.test.KernelServices)102 Property (org.jboss.dmr.Property)92 OperationFailedException (org.jboss.as.controller.OperationFailedException)89 OperationContext (org.jboss.as.controller.OperationContext)68 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)68 ArrayList (java.util.ArrayList)58 Resource (org.jboss.as.controller.registry.Resource)54 PathElement (org.jboss.as.controller.PathElement)53 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)52 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)50 IOException (java.io.IOException)49 ServiceName (org.jboss.msc.service.ServiceName)49 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)47 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)44 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)42 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)42 Map (java.util.Map)38