Search in sources :

Example 1 with AdminObjectStatisticsService

use of org.jboss.as.connector.services.resourceadapters.statistics.AdminObjectStatisticsService in project wildfly by wildfly.

the class AdminObjectAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    PathAddress path = PathAddress.pathAddress(address);
    final String raName = context.getCurrentAddress().getParent().getLastElement().getValue();
    final String archiveOrModuleName;
    ModelNode raModel = context.readResourceFromRoot(path.subAddress(0, path.size() - 1)).getModel();
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean();
    if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (raModel.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString();
    } else {
        archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString();
    }
    final String poolName = PathAddress.pathAddress(address).getLastElement().getValue();
    final ModifiableAdminObject adminObjectValue;
    try {
        adminObjectValue = RaOperationUtil.buildAdminObjects(context, operation, poolName);
    } catch (ValidateException e) {
        throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("AdminObject", operation, e.getLocalizedMessage())));
    }
    ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName, poolName);
    ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName);
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final AdminObjectService service = new AdminObjectService(adminObjectValue);
    serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector()).install();
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName));
    Activation raxml = (Activation) RaxmlController.getValue();
    ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, raName);
    String bootStrapCtxName = DEFAULT_NAME;
    if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
        bootStrapCtxName = raxml.getBootstrapContext();
    }
    AdminObjectStatisticsService adminObjectStatisticsService = new AdminObjectStatisticsService(context.getResourceRegistrationForUpdate(), poolName, statsEnabled);
    ServiceBuilder statsServiceBuilder = serviceTarget.addService(serviceName.append(ConnectorServices.STATISTICS_SUFFIX), adminObjectStatisticsService);
    statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), adminObjectStatisticsService.getBootstrapContextInjector()).addDependency(deploymentServiceName, adminObjectStatisticsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peAO = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
    final Resource aoResource = new IronJacamarResource.IronJacamarRuntimeResource();
    resource.registerChild(peAO, aoResource);
}
Also used : ValidateException(org.jboss.jca.common.api.validator.ValidateException) AdminObjectStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.AdminObjectStatisticsService) ServiceTarget(org.jboss.msc.service.ServiceTarget) 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) PathAddress(org.jboss.as.controller.PathAddress) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

AdminObjectStatisticsService (org.jboss.as.connector.services.resourceadapters.statistics.AdminObjectStatisticsService)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 PathAddress (org.jboss.as.controller.PathAddress)1 PathElement (org.jboss.as.controller.PathElement)1 Resource (org.jboss.as.controller.registry.Resource)1 ModelNode (org.jboss.dmr.ModelNode)1 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)1 ValidateException (org.jboss.jca.common.api.validator.ValidateException)1 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1