@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 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, ModelNode model) throws OperationFailedException { // Cache the TransactionManager service name for use by our runtime services ConnectorServices.registerCapabilityServiceName(LOCAL_TRANSACTION_PROVIDER_CAPABILITY, context.getCapabilityServiceName(LOCAL_TRANSACTION_PROVIDER_CAPABILITY, null)); final Resource subsystemResource = context.readResourceFromRoot(PathAddress.pathAddress(ResourceAdaptersExtension.SUBSYSTEM_PATH)); ResourceAdaptersSubsystemService service = new ResourceAdaptersSubsystemService(); CopyOnWriteArrayListMultiMap<String, ServiceName> value = service.getValue(); for (Resource.ResourceEntry re : subsystemResource.getChildren(RESOURCEADAPTER_NAME)) { value.putIfAbsent(re.getModel().get(ARCHIVE.getName()).asString(), ConnectorServices.RA_SERVICE.append(re.getName())); } final ServiceBuilder<?> builder = context.getServiceTarget().addService(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE, service); builder.setInitialMode(ServiceController.Mode.ACTIVE).install(); } }
protected void validateType(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress pathAddress = context.getCurrentAddress(); String elementName = context.getCurrentAddressValue(); ModelNode typeNode = context.readResource(EMPTY_ADDRESS, false).getModel(); String type = getType(context, typeNode); PathAddress parentAddress = pathAddress.getParent(); Set<Resource.ResourceEntry> children = context.readResourceFromRoot(parentAddress, true).getChildren(this.element.getName()); for (Resource.ResourceEntry child : children) { String existingResourceName = child.getName(); String existingType = getType(context, child.getModel()); if (!elementName.equals(existingResourceName) && (type.equals(existingType))) { throw ROOT_LOGGER.typeAlreadyDefined(type); } } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ModelNode ignoreSummary = new ModelNode(); final ModelNode cacheNames = operation.get(ModelKeys.CACHE_NAMES); Resource endpointResource = context.readResource(PathAddress.EMPTY_ADDRESS); List<ResourceEntry> endpoints = endpointResource.getChildTypes().stream() .flatMap(type -> endpointResource.getChildren(type).stream()).collect(Collectors.toList()); cacheNames.asList().stream().map(ModelNode::asString).forEach(cacheName -> { boolean ignoredAllEndpoints = endpoints.stream() .map(endpoint -> endpoint.getModel().get(ModelKeys.IGNORED_CACHES)) .allMatch(ignoredList -> contains(ignoredList, cacheName)); ignoreSummary.get(cacheName).set(ignoredAllEndpoints); }); context.getResult().set(ignoreSummary); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); final ModelNode cacheNames = operation.get(ModelKeys.CACHE_NAMES); Resource endpointResource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); Stream<Resource.ResourceEntry> connectorResources = endpointResource.getChildTypes().stream().flatMap(type -> endpointResource.getChildren(type).stream()); connectorResources.forEach(resourceEntry -> { ModelNode list = resourceEntry.getModel().get(ModelKeys.IGNORED_CACHES); ModelNode result = modelNodeOp.apply(list, cacheNames); PathElement pathElement = resourceEntry.getPathElement(); ModelNode op = Operations.createWriteAttributeOperation(PathAddress.pathAddress(address, pathElement), ModelKeys.IGNORED_CACHES, result); context.addStep(op, new CacheIgnoreReadWriteHandler(CommonConnectorResource.IGNORED_CACHES), OperationContext.Stage.MODEL); }); }
public static void addServerGroupsToModel(Resource hostModel, ModelNode model) { ModelNode initialServerGroups = new ModelNode(); initialServerGroups.setEmptyObject(); for (ResourceEntry entry : hostModel.getChildren(SERVER_CONFIG)) { ModelNode serverNode = new ModelNode(); serverNode.get(GROUP).set(entry.getModel().get(GROUP)); if (entry.getModel().hasDefined(SOCKET_BINDING_GROUP)) { serverNode.get(SOCKET_BINDING_GROUP).set(entry.getModel().get(SOCKET_BINDING_GROUP).asString()); } initialServerGroups.get(entry.getName()).set(serverNode); } model.get(ModelDescriptionConstants.INITIAL_SERVER_GROUPS).set(initialServerGroups); }
void processResource(ResourceEntry resourceEntry) throws OperationFailedException{ ModelNode model = resourceEntry.getModel(); final Set<String> includes; if (model.hasDefined(INCLUDES)) { includes = new HashSet<>(); for (ModelNode include : model.get(INCLUDES).asList()) { includes.add(include.asString()); } } else { includes = Collections.emptySet(); } resourceIncludes.put(resourceEntry.getName(), includes); }
private static Set<String> getIncludes(Resource.ResourceEntry resource) { Set<String> result; ModelNode model = resource.getModel(); if (model.hasDefined(INCLUDES)) { result = new HashSet<>(); for (ModelNode node : model.get(INCLUDES).asList()) { result.add(node.asString()); } } else { result = Collections.emptySet(); } return result; }
void processResource(ResourceEntry resourceEntry) throws OperationFailedException{ ModelNode model = resourceEntry.getModel(); final Set<String> includes; if (model.hasDefined(INCLUDES)) { includes = new HashSet<>(); for (ModelNode include : model.get(INCLUDES).asList()) { includes.add(include.asString()); } } else { includes = Collections.emptySet(); } resourceIncludes.put(resourceEntry.getName(), includes); }
/** * For use on a slave HC to get all the server groups used by the host * * @param hostResource the host resource * @return the server configs on this host */ public Set<ServerConfigInfo> getServerConfigsOnSlave(Resource hostResource){ Set<ServerConfigInfo> groups = new HashSet<>(); for (ResourceEntry entry : hostResource.getChildren(SERVER_CONFIG)) { groups.add(new ServerConfigInfoImpl(entry.getModel())); } return groups; }
public static void addServerGroupsToModel(Resource hostModel, ModelNode model) { ModelNode initialServerGroups = new ModelNode(); initialServerGroups.setEmptyObject(); for (ResourceEntry entry : hostModel.getChildren(SERVER_CONFIG)) { ModelNode serverNode = new ModelNode(); serverNode.get(GROUP).set(entry.getModel().get(GROUP)); if (entry.getModel().hasDefined(SOCKET_BINDING_GROUP)) { serverNode.get(SOCKET_BINDING_GROUP).set(entry.getModel().get(SOCKET_BINDING_GROUP).asString()); } initialServerGroups.get(entry.getName()).set(serverNode); } model.get(ModelDescriptionConstants.INITIAL_SERVER_GROUPS).set(initialServerGroups); }
/** * For use on a slave HC to get all the server groups used by the host * * @param hostResource the host resource * @return the server configs on this host */ public Set<ServerConfigInfo> getServerConfigsOnSlave(Resource hostResource){ Set<ServerConfigInfo> groups = new HashSet<>(); for (ResourceEntry entry : hostResource.getChildren(SERVER_CONFIG)) { groups.add(new ServerConfigInfoImpl(entry.getModel())); } return groups; }
private static Set<String> getIncludes(Resource.ResourceEntry resource) { Set<String> result; ModelNode model = resource.getModel(); if (model.hasDefined(INCLUDES)) { result = new HashSet<>(); for (ModelNode node : model.get(INCLUDES).asList()) { result.add(node.asString()); } } else { result = Collections.emptySet(); } return result; }
private boolean lookForHandlerForHc(OperationContext context, String name) { final Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS); for (ResourceEntry entry : root.getChildren(ModelDescriptionConstants.HOST)) { if (entry.getModel().isDefined()) { return lookForHandler(PathAddress.pathAddress(ModelDescriptionConstants.HOST, entry.getName()), root, name); } } return false; }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final Resource subsystemResource = context.readResourceFromRoot(PathAddress.pathAddress(ResourceAdaptersExtension.SUBSYSTEM_PATH)); ResourceAdaptersSubsystemService service = new ResourceAdaptersSubsystemService(); CopyOnWriteArrayListMultiMap<String, ServiceName> value = service.getValue(); for (Resource.ResourceEntry re : subsystemResource.getChildren(RESOURCEADAPTER_NAME)) { value.putIfAbsent(re.getModel().get(ARCHIVE.getName()).asString(), ConnectorServices.RA_SERVICE.append(re.getName())); } final ServiceBuilder<?> builder = context.getServiceTarget().addService(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE, service); builder.setInitialMode(ServiceController.Mode.ACTIVE).install(); } }
private void checkFormatterNotReferenced(String name, Resource auditLog, String...handlerTypes) throws OperationFailedException { for (String handlerType : handlerTypes) { for (ResourceEntry entry : auditLog.getChildren(handlerType)) { ModelNode auditLogModel = entry.getModel(); if (auditLogModel.get(FORMATTER).asString().equals(name)) { throw DomainManagementLogger.ROOT_LOGGER.cannotRemoveReferencedFormatter(entry.getPathElement()); } } } }
private void checkFormatterNotReferenced(String name, Resource auditLog, String...handlerTypes) throws OperationFailedException { for (String handlerType : handlerTypes) { for (ResourceEntry entry : auditLog.getChildren(handlerType)) { ModelNode auditLogModel = entry.getModel(); if (auditLogModel.get(FORMATTER).asString().equals(name)) { throw DomainManagementLogger.ROOT_LOGGER.cannotRemoveReferencedFormatter(entry.getPathElement()); } } } }
private boolean lookForHandlerForHc(OperationContext context, String name) { final Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS); for (ResourceEntry entry : root.getChildren(ModelDescriptionConstants.HOST)) { if (entry.getModel().isDefined()) { return lookForHandler(PathAddress.pathAddress(ModelDescriptionConstants.HOST, entry.getName()), root, name); } } return false; }
@Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.connectionTimeout = Attribute.CONNECTION_TIMEOUT.resolveModelAttribute(context, model).asInt(); this.defaultRemoteCluster = Attribute.DEFAULT_REMOTE_CLUSTER.resolveModelAttribute(context, model).asString(); this.keySizeEstimate = Attribute.KEY_SIZE_ESTIMATE.resolveModelAttribute(context, model).asInt(); this.maxRetries = Attribute.MAX_RETRIES.resolveModelAttribute(context, model).asInt(); this.protocolVersion = Attribute.PROTOCOL_VERSION.resolveModelAttribute(context, model).asString(); this.socketTimeout = Attribute.SOCKET_TIMEOUT.resolveModelAttribute(context, model).asInt(); this.tcpNoDelay = Attribute.TCP_NO_DELAY.resolveModelAttribute(context, model).asBoolean(); this.tcpKeepAlive = Attribute.TCP_KEEP_ALIVE.resolveModelAttribute(context, model).asBoolean(); this.valueSizeEstimate = Attribute.VALUE_SIZE_ESTIMATE.resolveModelAttribute(context, model).asInt(); this.clusters.clear(); Resource container = context.readResource(PathAddress.EMPTY_ADDRESS); for (Resource.ResourceEntry entry : container.getChildren(RemoteClusterResourceDefinition.WILDCARD_PATH.getKey())) { String clusterName = entry.getName(); ModelNode cluster = entry.getModel(); List<String> bindings = StringListAttributeDefinition.unwrapValue(context, RemoteClusterResourceDefinition.Attribute.SOCKET_BINDINGS.resolveModelAttribute(context, cluster)); List<SupplierDependency<OutboundSocketBinding>> bindingDependencies = new ArrayList<>(bindings.size()); for (String binding : bindings) { bindingDependencies.add(new ServiceSupplierDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, binding))); } this.clusters.put(clusterName, bindingDependencies); } return this; }