void removeRuntimeServices(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { // get container and cache addresses final PathAddress cacheAddress = getCacheAddressFromOperation(operation); final PathAddress containerAddress = getCacheContainerAddressFromOperation(operation); // get container and cache names final String cacheName = cacheAddress.getLastElement().getValue(); final String containerName = containerAddress.getLastElement().getValue(); // remove all services started by CacheAdd, in reverse order // remove the binder service ModelNode resolvedValue = null; final String jndiNameString = (resolvedValue = CommonAttributes.JNDI_NAME.resolveModelAttribute(context, model)) .isDefined() ? resolvedValue.asString() : null; final String jndiName = InfinispanJndiName.createCacheJndiNameOrDefault(jndiNameString, containerName, cacheName); ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName); context.removeService(bindInfo.getBinderServiceName()); // remove the CacheService instance context.removeService(CacheService.getServiceName(containerName, cacheName)); // remove the cache configuration service context.removeService(CacheConfigurationService.getServiceName(containerName, cacheName)); log.debugf("cache %s removed for container %s", cacheName, containerName); }
/** * Transfer elements common to both operations and models * * @param fromModel * @param toModel */ void populate(ModelNode fromModel, ModelNode toModel) throws OperationFailedException { CommonAttributes.START.validateAndSet(fromModel, toModel); CommonAttributes.BATCHING.validateAndSet(fromModel, toModel); CommonAttributes.INDEXING.validateAndSet(fromModel, toModel); CommonAttributes.JNDI_NAME.validateAndSet(fromModel, toModel); CommonAttributes.CACHE_MODULE.validateAndSet(fromModel, toModel); CommonAttributes.INDEXING_PROPERTIES.validateAndSet(fromModel, toModel); }
Collection<ServiceController<?>> installRuntimeServices( OperationContext context, ModelNode operation, ModelNode containerModel, ModelNode cacheModel, ServiceVerificationHandler verificationHandler) throws OperationFailedException { // get all required addresses, names and service names PathAddress cacheAddress = getCacheAddressFromOperation(operation); PathAddress containerAddress = getCacheContainerAddressFromOperation(operation); String cacheName = cacheAddress.getLastElement().getValue(); String containerName = containerAddress.getLastElement().getValue(); // get model attributes ModelNode resolvedValue = null; final String jndiName = ((resolvedValue = CommonAttributes.JNDI_NAME.resolveModelAttribute(context, cacheModel)) .isDefined()) ? resolvedValue.asString() : null; final ServiceController.Mode initialMode = StartMode.valueOf( CommonAttributes.START.resolveModelAttribute(context, cacheModel).asString()) .getMode(); final ModuleIdentifier moduleId = (resolvedValue = CommonAttributes.CACHE_MODULE.resolveModelAttribute(context, cacheModel)) .isDefined() ? ModuleIdentifier.fromString(resolvedValue.asString()) : null; // create a list for dependencies which may need to be added during processing List<Dependency<?>> dependencies = new LinkedList<Dependency<?>>(); // Infinispan Configuration to hold the operation data ConfigurationBuilder builder = new ConfigurationBuilder().read(getDefaultConfiguration(this.mode)); // process cache configuration ModelNode describing overrides to defaults processModelNode(context, containerName, cacheModel, builder, dependencies); // get container Model to pick up the value of the default cache of the container // AS7-3488 make default-cache no required attribute String defaultCache = CommonAttributes.DEFAULT_CACHE.resolveModelAttribute(context, containerModel).asString(); ServiceTarget target = context.getServiceTarget(); Configuration config = builder.build(); Collection<ServiceController<?>> controllers = new ArrayList<ServiceController<?>>(3); // install the cache configuration service (configures a cache) controllers.add( this.installCacheConfigurationService( target, containerName, cacheName, defaultCache, moduleId, builder, config, dependencies, verificationHandler)); log.debugf( "Cache configuration service for %s installed for container %s", cacheName, containerName); // now install the corresponding cache service (starts a configured cache) controllers.add( this.installCacheService( target, containerName, cacheName, defaultCache, initialMode, config, verificationHandler)); // install a name service entry for the cache controllers.add( this.installJndiService(target, containerName, cacheName, jndiName, verificationHandler)); log.debugf("Cache service for cache %s installed for container %s", cacheName, containerName); return controllers; }
private void parseContainer( XMLExtendedStreamReader reader, ModelNode subsystemAddress, List<ModelNode> operations) throws XMLStreamException { ModelNode container = Util.getEmptyOperation(ModelDescriptionConstants.ADD, null); String name = null; for (int i = 0; i < reader.getAttributeCount(); i++) { ParseUtils.requireNoNamespaceAttribute(reader, i); String value = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: { name = value; break; } case DEFAULT_CACHE: { CommonAttributes.DEFAULT_CACHE.parseAndSetParameter(value, container, reader); break; } case JNDI_NAME: { CommonAttributes.JNDI_NAME.parseAndSetParameter(value, container, reader); break; } case LISTENER_EXECUTOR: { CommonAttributes.LISTENER_EXECUTOR.parseAndSetParameter(value, container, reader); break; } case EVICTION_EXECUTOR: { CommonAttributes.EVICTION_EXECUTOR.parseAndSetParameter(value, container, reader); break; } case REPLICATION_QUEUE_EXECUTOR: { CommonAttributes.REPLICATION_QUEUE_EXECUTOR.parseAndSetParameter( value, container, reader); break; } default: { throw ParseUtils.unexpectedAttribute(reader, i); } } } if ((name == null) || !container.hasDefined(ModelKeys.DEFAULT_CACHE)) { throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.NAME, Attribute.DEFAULT_CACHE)); } // Backwards compatible default module CommonAttributes.CACHE_CONTAINER_MODULE.parseAndSetParameter( "org.jboss.as.jpa.hibernate:4", container, reader); ModelNode containerAddress = subsystemAddress.clone(); containerAddress.add(ModelKeys.CACHE_CONTAINER, name); containerAddress.protect(); container.get(ModelDescriptionConstants.OP_ADDR).set(containerAddress); // operation to add the container operations.add(container); while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) { Element element = Element.forName(reader.getLocalName()); switch (element) { case ALIAS: { container.get(ModelKeys.ALIASES).add(reader.getElementText()); break; } case TRANSPORT: { parseTransport(reader, containerAddress, operations); break; } case LOCAL_CACHE: { parseLocalCache(reader, containerAddress, operations); break; } case INVALIDATION_CACHE: { parseInvalidationCache(reader, containerAddress, operations); break; } case REPLICATED_CACHE: { parseReplicatedCache(reader, containerAddress, operations); break; } case DISTRIBUTED_CACHE: { parseDistributedCache(reader, containerAddress, operations); break; } default: { throw ParseUtils.unexpectedElement(reader); } } } }