@Override public AttributeValueTranslator getReadTranslator() { return (context, value) -> { String poolName = value.asString(); PathAddress address = context.getCurrentAddress(); PathAddress rootAddress = address.subAddress(0, address.size() - 4); PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources")); Resource subsystem = context.readResourceFromRoot(subsystemAddress); for (String type : Arrays.asList("data-source", "xa-data-source")) { Resource resource = subsystem.getChild(PathElement.pathElement(type, poolName)); if (resource != null) { return resource.getModel().get("jndi-name"); } } throw InfinispanLogger.ROOT_LOGGER.dataSourceNotFound(poolName); }; }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException { final String configPropertyValue = CONFIG_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString(); final ModelNode address = operation.require(OP_ADDR); PathAddress path = PathAddress.pathAddress(address); final String archiveName = path.getElement(path.size() -3).getValue(); final String aoName = path.getElement(path.size() -2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName, aoName, configPropertyName); ServiceName aoServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName, aoName); final ServiceTarget serviceTarget = context.getServiceTarget(); final AOConfigPropertiesService service = new AOConfigPropertiesService(configPropertyName, configPropertyValue); serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(aoServiceName, ModifiableAdminObject.class, service.getAOInjector() ) .install(); } }
@Override public PathAddress convertToTargetAddress(PathAddress address, AliasContext aliasContext) { PathAddress target = this.getTargetAddress(); List<PathElement> result = new ArrayList<>(address.size()); for (int i = 0; i < address.size(); ++i) { PathElement element = address.getElement(i); if (i < target.size()) { PathElement targetElement = target.getElement(i); result.add(targetElement.isWildcard() ? PathElement.pathElement(targetElement.getKey(), element.getValue()) : targetElement); } else { result.add(element); } } return PathAddress.pathAddress(result); } }
XMLElement(PathElement path) { this.name = path.isWildcard() ? path.getKey() : path.getValue(); }
@Override public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) { PathElement pe = aliasAddress.getLastElement(); return aliasAddress.getParent().append(PathElement.pathElement(targetPe.getKey(), pe.getValue())); } };
@Override public PathAddress convertToTargetAddress(PathAddress address, AliasContext aliasContext) { PathElement element = address.getLastElement(); element = PathElement.pathElement(Constants.ACL_MODULE, element.getValue()); return address.subAddress(0, address.size() -1).append(element); } });
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { Resource existing = context.readResource(PathAddress.EMPTY_ADDRESS); OperationStepHandler addHandler = context.getResourceRegistration().getSubModel(PathAddress.EMPTY_ADDRESS.append(newKeyName)).getOperationHandler(PathAddress.EMPTY_ADDRESS, "add"); ModelNode value = operation.get(VALUE); if (value.isDefined()) { List<ModelNode> modules = new ArrayList<ModelNode>(value.asList()); Collections.reverse(modules); //need to reverse it to make sure they are added in proper order for (ModelNode module : modules) { ModelNode addModuleOp = module.clone(); String code = addModuleOp.get(Constants.CODE).asString(); PathElement relativePath = PathElement.pathElement(newKeyName, code); PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)).append(relativePath); addModuleOp.get(OP_ADDR).set(address.toModelNode()); addModuleOp.get(OP).set(ADD); context.addStep(new ModelNode(), addModuleOp, addHandler, OperationContext.Stage.MODEL, true); } } //remove on the end to make sure it is executed first for (Resource.ResourceEntry entry : existing.getChildren(newKeyName)) { PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)).append(entry.getPathElement()); ModelNode removeModuleOp = Util.createRemoveOperation(address); context.addStep(new ModelNode(), removeModuleOp, new SecurityDomainReloadRemoveHandler(), OperationContext.Stage.MODEL, true); } } }
protected void performRuntime(final OperationContext context, ModelNode operation, final ModelNode model) throws OperationFailedException { final ModelNode pathNode = FileDataStoreResourceDefinition.PATH.resolveModelAttribute(context, model); final String path = pathNode.isDefined() ? pathNode.asString() : null; final ModelNode relativeToNode = FileDataStoreResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, model); final String relativeTo = relativeToNode.isDefined() ? relativeToNode.asString() : null; final FileTimerPersistence fileTimerPersistence = new FileTimerPersistence(true, path, relativeTo); final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final ServiceName serviceName = TimerPersistence.SERVICE_NAME.append(address.getLastElement().getValue()); final ServiceBuilder sb = context.getServiceTarget().addService(serviceName, fileTimerPersistence); sb.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ModuleLoader.class, fileTimerPersistence.getModuleLoader()); sb.addDependency(PathManagerService.SERVICE_NAME, PathManager.class, fileTimerPersistence.getPathManager()); sb.requires(context.getCapabilityServiceName("org.wildfly.transactions.global-default-local-provider", null)); sb.addDependency(context.getCapabilityServiceName("org.wildfly.transactions.transaction-synchronization-registry", null), TransactionSynchronizationRegistry.class, fileTimerPersistence.getTransactionSynchronizationRegistry()); sb.install(); }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { boolean rcPresent = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false).hasChild(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, RequestControllerExtension.SUBSYSTEM_NAME)); final String name = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue(); final String jndiName = ManagedExecutorServiceResourceDefinition.JNDI_NAME_AD.resolveModelAttribute(context, model).asString(); final long hungTaskThreshold = ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.resolveModelAttribute(context, model).asLong(); final boolean longRunningTasks = ManagedScheduledExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.resolveModelAttribute(context, model).asBoolean(); final ServiceBuilder<ManagedScheduledExecutorServiceAdapter> serviceBuilder = context.getServiceTarget().addService(ConcurrentServiceNames.getManagedScheduledExecutorServiceServiceName(name), service);
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 { if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException {
/** * {@inheritDoc} */ @Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String jndiName = address.getLastElement().getValue(); final String tableName = CMResourceResourceDefinition.CM_TABLE_NAME.resolveModelAttribute(context, model).asString(); final int batchSize = CMResourceResourceDefinition.CM_TABLE_BATCH_SIZE.resolveModelAttribute(context, model).asInt(); final boolean immediateCleanup = CMResourceResourceDefinition.CM_TABLE_IMMEDIATE_CLEANUP.resolveModelAttribute(context, model).asBoolean(); ROOT_LOGGER.debugf("adding commit-markable-resource: jndi-name=%s, table-name=%s, batch-size=%d, immediate-cleanup=%b", jndiName, tableName, batchSize, immediateCleanup); CMResourceService service = new CMResourceService(jndiName, tableName, immediateCleanup, batchSize); context.getServiceTarget().addService(TxnServices.JBOSS_TXN_CMR.append(jndiName), service) .addDependency(TxnServices.JBOSS_TXN_JTA_ENVIRONMENT, JTAEnvironmentBean.class, service.getJTAEnvironmentBeanInjector()) .setInitialMode(ServiceController.Mode.ACTIVE) .install(); if (!context.isBooting()) { context.reloadRequired(); } } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final String name = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue(); final String jndiName = ManagedExecutorServiceResourceDefinition.JNDI_NAME_AD.resolveModelAttribute(context, model).asString(); final int priority = ManagedThreadFactoryResourceDefinition.PRIORITY_AD.resolveModelAttribute(context, model).asInt(); final ManagedThreadFactoryService service = new ManagedThreadFactoryService(name, jndiName, priority); final ServiceBuilder<ManagedThreadFactoryImpl> serviceBuilder = context.getServiceTarget().addService(ConcurrentServiceNames.getManagedThreadFactoryServiceName(name), service); String contextService = null; if(model.hasDefined(ManagedThreadFactoryResourceDefinition.CONTEXT_SERVICE)) { contextService = ManagedThreadFactoryResourceDefinition.CONTEXT_SERVICE_AD.resolveModelAttribute(context, model).asString(); } if (contextService != null) { serviceBuilder.addDependency(ConcurrentServiceNames.getContextServiceServiceName(contextService), ContextServiceImpl.class, service.getContextServiceInjector()); } serviceBuilder.install(); } }
@Override public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) { PathAddress target = this.getTargetAddress(); List<PathElement> result = new ArrayList<>(aliasAddress.size()); for (int i = 0; i < aliasAddress.size(); ++i) { PathElement element = aliasAddress.getElement(i); if (i == target.size() - 1) { final ModelNode operation = aliasContext.getOperation(); final String stackName; if (ModelDescriptionConstants.ADD.equals(Operations.getName(operation)) && operation.hasDefined("type")) { stackName = operation.get("type").asString(); } else { Resource root = null; stackName = "*"; } else { Set<String> names = root.getChildrenNames("transport"); if (names.size() > 1) { throw new AssertionError("There should be at most one child"); result.add(PathElement.pathElement("transport", stackName)); } else if (i < target.size()) { PathElement targetElement = target.getElement(i); result.add(targetElement.isWildcard() ? PathElement.pathElement(targetElement.getKey(), element.getValue()) : targetElement); } else { result.add(element);
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode strictMaxPoolModel) throws OperationFailedException { final String poolName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue(); final int maxPoolSize = StrictMaxPoolResourceDefinition.MAX_POOL_SIZE.resolveModelAttribute(context, strictMaxPoolModel).asInt(); final Derive derive = StrictMaxPoolResourceDefinition.parseDeriveSize(context, strictMaxPoolModel); final long timeout = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT.resolveModelAttribute(context, strictMaxPoolModel).asLong(); final String unit = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT_UNIT.resolveModelAttribute(context, strictMaxPoolModel).asString(); // create and install the service final StrictMaxPoolConfigService poolConfigService = new StrictMaxPoolConfigService(poolName, maxPoolSize, derive, timeout, TimeUnit.valueOf(unit)); final ServiceName serviceName = StrictMaxPoolConfigService.EJB_POOL_CONFIG_BASE_SERVICE_NAME.append(poolName); ServiceBuilder<StrictMaxPoolConfig> svcBuilder = context.getServiceTarget().addService(serviceName, poolConfigService); if (context.hasOptionalCapability(IO_MAX_THREADS_RUNTIME_CAPABILITY_NAME, null, null)) { ServiceName name = context.getCapabilityServiceName(IO_MAX_THREADS_RUNTIME_CAPABILITY_NAME, Integer.class); svcBuilder.addDependency(name, Integer.class, poolConfigService.getMaxThreadsInjector()); } svcBuilder.install(); }
@Override public void convert(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) { if (value.isDefined()) { PathAddress rootAddress = address.subAddress(0, address.size() - 4); PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources")); Resource subsystem = context.readResourceFromRoot(subsystemAddress); String poolName = value.asString(); for (String type : Arrays.asList("data-source", "xa-data-source")) { if (subsystem.hasChildren(type)) { for (Resource.ResourceEntry entry : subsystem.getChildren(type)) { if (entry.getName().equals(poolName)) { value.set(entry.getModel().get("jndi-name")); return; } } } } } } };
@Override protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { ModelNode model = resource.getModel(); final String name = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue(); final String jndiName = ContextServiceResourceDefinition.JNDI_NAME_AD.resolveModelAttribute(context, model).asString(); final boolean useTransactionSetupProvider = ContextServiceResourceDefinition.USE_TRANSACTION_SETUP_PROVIDER_AD.resolveModelAttribute(context, model).asBoolean(); // install the service which manages the default context service final ContextServiceService contextServiceService = new ContextServiceService(name, jndiName, new DefaultContextSetupProviderImpl()); final ServiceBuilder<ContextServiceImpl> serviceBuilder = context.getServiceTarget().addService(ConcurrentServiceNames.getContextServiceServiceName(name), contextServiceService); if (useTransactionSetupProvider) { // add it to deps of context service's service, for injection of its value serviceBuilder.addDependency(ConcurrentServiceNames.TRANSACTION_SETUP_PROVIDER_SERVICE_NAME,TransactionSetupProvider.class,contextServiceService.getTransactionSetupProvider()); } serviceBuilder.install(); } }
@Override public AttributeValueTranslator getWriteTranslator() { return (context, value) -> { String jndiName = value.asString(); PathAddress address = context.getCurrentAddress(); PathAddress rootAddress = address.subAddress(0, address.size() - 4); PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources")); Resource subsystem = context.readResourceFromRoot(subsystemAddress); for (String type : Arrays.asList("data-source", "xa-data-source")) { if (subsystem.hasChildren(type)) { for (Resource.ResourceEntry entry : subsystem.getChildren(type)) { ModelNode model = entry.getModel(); if (model.get("jndi-name").asString().equals(jndiName)) { return new ModelNode(entry.getName()); } } } } throw InfinispanLogger.ROOT_LOGGER.dataSourceJndiNameNotFound(jndiName); }; } };
@Override public TransformedOperation transformOperation(final TransformationContext context, final PathAddress address, final ModelNode operation) throws OperationFailedException { Resource original = context.readResourceFromRoot(address); String defaultDataStore = original.getModel().get(TimerServiceResourceDefinition.DEFAULT_DATA_STORE.getName()).asString(); boolean hasFileDataStore = original.hasChild(PathElement.pathElement(EJB3SubsystemModel.FILE_DATA_STORE_PATH.getKey(), defaultDataStore)); if (original.getChildren(EJB3SubsystemModel.FILE_DATA_STORE).size() > 1 || !hasFileDataStore) { return new TransformedOperation(operation, new OperationRejectionPolicy() { @Override public boolean rejectOperation(ModelNode preparedResult) { return true; } @Override public String getFailureDescription() { return context.getLogger().getRejectedResourceWarning(address, operation); } }, OperationResultTransformer.ORIGINAL_RESULT); } operation.get(TimerServiceResourceDefinition.THREAD_POOL_NAME.getName()).set(original.getModel().get(TimerServiceResourceDefinition.THREAD_POOL_NAME.getName())); return new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT); }
protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { final ModelNode address = operation.require(OP_ADDR); final String driverName = PathAddress.pathAddress(address).getLastElement().getValue(); for (AttributeDefinition attribute : Constants.JDBC_DRIVER_ATTRIBUTES) { // https://issues.jboss.org/browse/WFLY-9324 skip validation on driver-name if (!attribute.getName().equals(DRIVER_NAME_NAME)) { attribute.validateAndSet(operation, model); } } model.get(DRIVER_NAME.getName()).set(driverName);//this shouldn't be here anymore }
protected void installServices(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final String groupName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement() .getValue(); final boolean active = MdbDeliveryGroupResourceDefinition.ACTIVE.resolveModelAttribute(context, model).asBoolean(); context.getServiceTarget().addService(getDeliveryGroupServiceName(groupName), Service.NULL) .setInitialMode(active? ServiceController.Mode.ACTIVE: ServiceController.Mode.NEVER).install(); } }