@Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.siteName = SITE.resolveModelAttribute(context, model).asString(); PathAddress address = context.getCurrentAddress(); Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); Set<Resource.ResourceEntry> entries = resource.getChildren(RemoteSiteResourceDefinition.WILDCARD_PATH.getKey()); this.sites = new ArrayList<>(entries.size()); for (Resource.ResourceEntry entry : entries) { this.sites.add(new ServiceSupplierDependency<>(new RemoteSiteServiceNameProvider(address, entry.getPathElement()))); } return super.configure(context, model); }
@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"); oldAttribute.validateOperation(operation); List<ModelNode> modules = new ArrayList<ModelNode>(operation.get(oldAttribute.getName()).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); } } }
@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); } } }
@Override public void processChildren(final Resource resource) throws OperationFailedException { final Set<String> types = resource.getChildTypes(); for (final String type : types) { for (final Resource.ResourceEntry child : resource.getChildren(type)) { processChild(child.getPathElement(), child); } } }
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 transformModulesToAttributes(final PathAddress address, final String newName, final String oldName, final TransformationContext context, final ModelNode model) { ModelNode modules = model.get(oldName).setEmptyList(); for (Resource.ResourceEntry entry : context.readResourceFromRoot(address).getChildren(newName)) { Resource moduleResource = context.readResourceFromRoot(address.append(entry.getPathElement())); modules.add(moduleResource.getModel()); } } }
private void addAllAddresses(ImmutableManagementResourceRegistration mrr, PathAddress current, Resource resource, Set<PathAddress> addresses) { addresses.add(current); for (String name : getNonIgnoredChildTypes(mrr)) { for (ResourceEntry entry : resource.getChildren(name)) { if (!entry.isProxy() && !entry.isRuntime()) { addAllAddresses(mrr.getSubModel(PathAddress.pathAddress(entry.getPathElement())), current.append(entry.getPathElement()), entry, addresses); } } } }
@Override public PathElement getPathElement() { return delegate.getPathElement(); } }
@Override public void processChildren(final Resource resource) throws OperationFailedException { final Set<String> types = resource.getChildTypes(); for (final String type : types) { for (final Resource.ResourceEntry child : resource.getChildren(type)) { processChild(child.getPathElement(), child); } } }
@Override public PathElement getPathElement() { return delegate.getPathElement(); } }
private List<PathElement> getChildren(Resource resource) { final List<PathElement> pes = new ArrayList<PathElement>(); for (String childType : resource.getChildTypes()) { for (Resource.ResourceEntry entry : resource.getChildren(childType)) { pes.add(entry.getPathElement()); } } return pes; }
static void cleanup(final Resource resource) { synchronized (resource) { for(final Resource.ResourceEntry entry : resource.getChildren(SUBSYSTEM)) { resource.removeChild(entry.getPathElement()); } for(final Resource.ResourceEntry entry : resource.getChildren(SUB_DEPLOYMENT)) { resource.removeChild(entry.getPathElement()); } } }
private void addAllAddresses(ImmutableManagementResourceRegistration mrr, PathAddress current, Resource resource, Set<PathAddress> addresses) { addresses.add(current); for (String name : getNonIgnoredChildTypes(mrr)) { for (ResourceEntry entry : resource.getChildren(name)) { if (!entry.isProxy() && !entry.isRuntime()) { addAllAddresses(mrr.getSubModel(PathAddress.pathAddress(entry.getPathElement())), current.append(entry.getPathElement()), entry, addresses); } } } }
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()); } } } }
@Override public PathElement getPathElement() { return delegate.getPathElement(); } }
static void cleanup(final Resource resource) { synchronized (resource) { for(final Resource.ResourceEntry entry : resource.getChildren(SUBSYSTEM)) { resource.removeChild(entry.getPathElement()); } for(final Resource.ResourceEntry entry : resource.getChildren(SUB_DEPLOYMENT)) { resource.removeChild(entry.getPathElement()); } } }
@Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.statisticsEnabled = StackResourceDefinition.Attribute.STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean(); Resource resource = context.readResourceFromRoot(this.address, false); Iterator<Resource.ResourceEntry> transports = resource.getChildren(TransportResourceDefinition.WILDCARD_PATH.getKey()).iterator(); if (!transports.hasNext()) { throw JGroupsLogger.ROOT_LOGGER.transportNotDefined(this.getName()); } this.transport = new ServiceSupplierDependency<>(new SingletonProtocolServiceNameProvider(this.address, transports.next().getPathElement())); Set<Resource.ResourceEntry> entries = resource.getChildren(ProtocolResourceDefinition.WILDCARD_PATH.getKey()); this.protocols = new ArrayList<>(entries.size()); for (Resource.ResourceEntry entry : entries) { this.protocols.add(new ServiceSupplierDependency<>(new ProtocolServiceNameProvider(this.address, entry.getPathElement()))); } this.relay = resource.hasChild(RelayResourceDefinition.PATH) ? new ServiceSupplierDependency<>(new SingletonProtocolServiceNameProvider(this.address, RelayResourceDefinition.PATH)) : null; this.socketBindingManager = new ServiceSupplierDependency<>(CommonRequirement.SOCKET_BINDING_MANAGER.getServiceName(context)); return this; }
@Override protected void describe(OrderedChildTypesAttachment orderedChildTypesAttachment, Resource resource, ModelNode addressModel, ModelNode result, ImmutableManagementResourceRegistration registration) { if (resource == null || registration.isRemote() || registration.isRuntimeOnly() || resource.isProxy() || resource.isRuntime() || registration.isAlias()) return; result.add(createAddOperation(orderedChildTypesAttachment, addressModel, resource, registration.getChildAddresses(PathAddress.EMPTY_ADDRESS))); PathAddress address = PathAddress.pathAddress(addressModel); for (String type : resource.getChildTypes()) { for (Resource.ResourceEntry entry : resource.getChildren(type)) { PathElement path = entry.getPathElement(); ImmutableManagementResourceRegistration childRegistration = Optional.ofNullable(registration.getSubModel(PathAddress.pathAddress(path))).orElse(registration.getSubModel(PathAddress.pathAddress(PathElement.pathElement(path.getKey())))); PathAddress childAddress = address.append(path); this.describe(orderedChildTypesAttachment, entry, childAddress.toModelNode(), result, childRegistration); } } }
@Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { Resource resource = context.getCurrentAddress().equals(this.address) ? context.readResourceFromRoot(this.address, false) : PlaceholderResource.INSTANCE; Set<Resource.ResourceEntry> entries = resource.getChildren(ProtocolResourceDefinition.WILDCARD_PATH.getKey()); this.protocols = new ArrayList<>(entries.size()); for (Resource.ResourceEntry entry : entries) { this.protocols.add(new ServiceSupplierDependency<>(new ProtocolServiceNameProvider(this.address, entry.getPathElement()))); } String channelName = this.address.getParent().getLastElement().getValue(); this.parentChannel = new ServiceSupplierDependency<>(JGroupsRequirement.CHANNEL.getServiceName(context, channelName)); this.parentFactory = new ServiceSupplierDependency<>(JGroupsRequirement.CHANNEL_SOURCE.getServiceName(context, channelName)); return this; } }
private static boolean removeInCurrentStep(Resource resource) { for (String childType : resource.getChildTypes()) { for (Resource.ResourceEntry entry : resource.getChildren(childType)) { if (!entry.isRuntime() && resource.hasChild(entry.getPathElement())) { return false; } } } return true; }