Java Code Examples for org.jboss.as.controller.OperationContext#readResource()
The following examples show how to use
org.jboss.as.controller.OperationContext#readResource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericSubsystemDescribeHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { final ModelNode address; final PathAddress pa = context.getCurrentAddress(); AuthorizationResult authResult = context.authorize(operation, DESCRIBE_EFFECTS); if (authResult.getDecision() != AuthorizationResult.Decision.PERMIT) { throw ControllerLogger.ROOT_LOGGER.unauthorized(operation.require(OP).asString(), pa, authResult.getExplanation()); } if (pa.size() > 0) { address = new ModelNode().add(pa.getLastElement().getKey(), pa.getLastElement().getValue()); } else { address = new ModelNode().setEmptyList(); } final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); final ModelNode result = context.getResult(); describe(context.getAttachment(OrderedChildTypesAttachment.KEY), resource, address, result, context.getResourceRegistration()); }
Example 2
Source File: ReadAttributeHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
static void resolveAttribute(OperationContext context, AttributeDefinition attribute, String attributeSyntax, boolean defaults, boolean enhancedSyntax) throws OperationFailedException { final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS, false); final ModelNode subModel = resource.getModel(); if (enhancedSyntax) { context.getResult().set(EnhancedSyntaxSupport.resolveEnhancedSyntax(attributeSyntax, subModel, attribute)); } else if (subModel.hasDefined(attribute.getName())) { final ModelNode result = subModel.get(attribute.getName()); context.getResult().set(result); } else if (defaults && attribute.getDefaultValue() != null) { // No defined value in the model. See if we should reply with a default from the metadata, // reply with undefined, or fail because it's a non-existent attribute name context.getResult().set(attribute.getDefaultValue()); } else { // model had no defined value, but we treat its existence in the model or the metadata // as proof that it's a legit attribute name context.getResult(); // this initializes the "result" to ModelType.UNDEFINED } }
Example 3
Source File: DetailedOperationsTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { for (Action.ActionEffect actionEffect : actionEffects) { if (actionEffect == Action.ActionEffect.READ_CONFIG) { context.readResource(EMPTY_ADDRESS); // causes read-config auth } if (actionEffect == Action.ActionEffect.WRITE_CONFIG) { context.getResourceRegistrationForUpdate(); // causes read-config+write-config auth } if (actionEffect == Action.ActionEffect.READ_RUNTIME) { context.addStep((ctx, op) -> { ctx.getServiceRegistry(false); // causes read-runtime auth }, OperationContext.Stage.RUNTIME); } if (actionEffect == Action.ActionEffect.WRITE_RUNTIME) { context.addStep((ctx, op) -> { ctx.getServiceRegistry(true); // causes read-runtime+write-runtime auth }, OperationContext.Stage.RUNTIME); } } context.getResult().set(new Random().nextInt()); }
Example 4
Source File: ManagedDeploymentReadContentHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.getProcessType() == ProcessType.SELF_CONTAINED) { throw DomainControllerLogger.ROOT_LOGGER.cannotReadContentFromSelfContainedServer(); } final Resource deploymentResource = context.readResource(PathAddress.EMPTY_ADDRESS); ModelNode contentItemNode = getContentItem(deploymentResource); // Validate this op is available if (!isManaged(contentItemNode)) { throw DomainControllerLogger.ROOT_LOGGER.cannotReadContentFromUnmanagedDeployment(); } final byte[] deploymentHash = CONTENT_HASH.resolveModelAttribute(context, contentItemNode).asBytes(); final ModelNode contentPath = CONTENT_PATH.resolveModelAttribute(context, operation); final String path = contentPath.isDefined() ? contentPath.asString() : ""; try { TypedInputStream inputStream = contentRepository.readContent(deploymentHash, path); String uuid = context.attachResultStream(inputStream.getContentType(), inputStream); context.getResult().get(UUID).set(uuid); } catch (ExplodedContentException ex) { throw new OperationFailedException(ex.getMessage()); } }
Example 5
Source File: LogFileResourceDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private static void validateFile(final OperationContext context, final String logDir, final String fileName) throws OperationFailedException { // Ensure the resource exists context.readResource(PathAddress.EMPTY_ADDRESS); final Path dir = Paths.get(logDir); final AtomicBoolean found = new AtomicBoolean(); try { // Walk the log directory and only allow files within the log directory to be read Files.walkFileTree(dir, Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { final Path relativeFile = dir.relativize(file); if (fileName.equals(relativeFile.toString())) { found.set(true); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw LoggingLogger.ROOT_LOGGER.failedToReadLogFile(e, fileName); } if (!found.get()) { throw LoggingLogger.ROOT_LOGGER.readNotAllowed(fileName); } }
Example 6
Source File: WorkerThreadPoolVsEndpointHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); ModelNode model = resource.getModel(); boolean hasLegacy = false; if (forDomain) { for (final AttributeDefinition attribute : RemotingSubsystemRootResource.LEGACY_ATTRIBUTES) { if (model.hasDefined(attribute.getName())) { hasLegacy = true; break; } } } if (!hasLegacy && !resource.hasChild(RemotingEndpointResource.ENDPOINT_PATH)) { // User didn't configure either worker-thread-pool or endpoint. Add a default endpoint resource so // users can read the default config attribute values context.addResource(PathAddress.pathAddress(RemotingEndpointResource.ENDPOINT_PATH), Resource.Factory.create()); } }
Example 7
Source File: ScopedRoleRequiredHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); Set<String> hostScopedRoles = resource.getChildrenNames(HOST_SCOPED_ROLE); Set<String> serverGroupScopedRoles = resource.getChildrenNames(SERVER_GROUP_SCOPED_ROLE); if (hostScopedRoles.contains(roleName) == false && serverGroupScopedRoles.contains(roleName) == false) { throw DomainManagementLogger.ROOT_LOGGER.invalidRoleNameDomain(roleName); } }
Example 8
Source File: DeploymentUploadUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Add contents to the deployment and attach a "transformed" slave operation to the operation context. * * @param context the operation context * @param operation the original operation * @param contentRepository the content repository * @return the hash of the uploaded deployment content * @throws IOException * @throws OperationFailedException */ public static byte[] addContentToExplodedAndTransformOperation(OperationContext context, ModelNode operation, ContentRepository contentRepository) throws OperationFailedException, ExplodedContentException { final Resource deploymentResource = context.readResource(PathAddress.EMPTY_ADDRESS); ModelNode contentItem = getContentItem(deploymentResource); byte[] oldHash = CONTENT_HASH.resolveModelAttribute(context, contentItem).asBytes(); List<ModelNode> contents = CONTENT_PARAM_ALL_EXPLODED.resolveModelAttribute(context, operation).asList(); final List<ExplodedContent> addedFiles = new ArrayList<>(contents.size()); final ModelNode slave = operation.clone(); ModelNode slaveAddedfiles = slave.get(UPDATED_PATHS.getName()).setEmptyList(); for(ModelNode content : contents) { InputStream in; if(hasValidContentAdditionParameterDefined(content)) { in = getInputStream(context, content); } else { in = null; } String path = TARGET_PATH.resolveModelAttribute(context, content).asString(); addedFiles.add(new ExplodedContent(path, in)); slaveAddedfiles.add(path); } final boolean overwrite = OVERWRITE.resolveModelAttribute(context, operation).asBoolean(true); final byte[] hash = contentRepository.addContentToExploded(oldHash, addedFiles, overwrite); // Clear the contents and update with the hash ModelNode addedContent = new ModelNode().setEmptyObject(); addedContent.get(HASH).set(hash); addedContent.get(TARGET_PATH.getName()).set("."); slave.get(CONTENT).setEmptyList().add(addedContent); // Add the domain op transformer List<DomainOperationTransmuter> transformers = context.getAttachment(OperationAttachments.SLAVE_SERVER_OPERATION_TRANSMUTERS); if (transformers == null) { context.attach(OperationAttachments.SLAVE_SERVER_OPERATION_TRANSMUTERS, transformers = new ArrayList<>()); } transformers.add(new CompositeOperationAwareTransmuter(slave)); return hash; }
Example 9
Source File: ManagedDeploymentBrowseContentHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.getProcessType() == ProcessType.SELF_CONTAINED) { throw DomainControllerLogger.ROOT_LOGGER.cannotReadContentFromSelfContainedServer(); } final Resource deploymentResource = context.readResource(PathAddress.EMPTY_ADDRESS); ModelNode contentItemNode = getContentItem(deploymentResource); // Validate this op is available if (!isManaged(contentItemNode)) { throw DomainControllerLogger.ROOT_LOGGER.cannotReadContentFromUnmanagedDeployment(); } final byte[] deploymentHash = CONTENT_HASH.resolveModelAttribute(context, contentItemNode).asBytes(); final ModelNode pathNode = DEPLOYMENT_CONTENT_PATH.resolveModelAttribute(context, operation); final String path; if(pathNode.isDefined()) { path = pathNode.asString(); } else { path = ""; } int depth = DEPTH.resolveModelAttribute(context, operation).asInt(); boolean explodable = ARCHIVE.resolveModelAttribute(context, operation).asBoolean(); try { for (ContentRepositoryElement content : contentRepository.listContent(deploymentHash, path, ContentFilter.Factory.createContentFilter(depth, explodable))) { ModelNode contentNode = new ModelNode(); contentNode.get(PATH).set(content.getPath()); contentNode.get(DIRECTORY).set(content.isFolder()); if(!content.isFolder()) { contentNode.get(FILE_SIZE).set(content.getSize()); } context.getResult().add(contentNode); } } catch (ExplodedContentException ex) { throw new OperationFailedException(ex.getMessage()); } }
Example 10
Source File: ManagedDeploymentBrowseContentHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.getProcessType() == ProcessType.SELF_CONTAINED) { throw ServerLogger.ROOT_LOGGER.cannotReadContentFromSelfContainedServer(); } final Resource deploymentResource = context.readResource(PathAddress.EMPTY_ADDRESS); ModelNode contentItemNode = getContentItem(deploymentResource); // Validate this op is available if (!isManaged(contentItemNode)) { throw ServerLogger.ROOT_LOGGER.cannotReadContentFromUnmanagedDeployment(); } final byte[] deploymentHash = CONTENT_HASH.resolveModelAttribute(context, contentItemNode).asBytes(); final ModelNode pathNode = DEPLOYMENT_CONTENT_PATH.resolveModelAttribute(context, operation); final String path; if(pathNode.isDefined()) { path = pathNode.asString(); } else { path = ""; } int depth = DEPTH.resolveModelAttribute(context, operation).asInt(); boolean explodable = ARCHIVE.resolveModelAttribute(context, operation).asBoolean(); try { for (ContentRepositoryElement content : contentRepository.listContent(deploymentHash, path, ContentFilter.Factory.createContentFilter(depth, explodable))) { ModelNode contentNode = new ModelNode(); contentNode.get(PATH).set(content.getPath()); contentNode.get(DIRECTORY).set(content.isFolder()); if(!content.isFolder()) { contentNode.get(FILE_SIZE).set(content.getSize()); } context.getResult().add(contentNode); } } catch (ExplodedContentException ex) { throw createFailureException(ex.toString()); } }
Example 11
Source File: SensitivityResourceDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final String attribute = operation.require(NAME).asString(); final SensitivityClassificationResource resource = (SensitivityClassificationResource)context.readResource(PathAddress.EMPTY_ADDRESS); final AbstractSensitivity classification = resource.classification; Boolean result; if (attribute.equals(DEFAULT_REQUIRES_ADDRESSABLE.getName()) && includeAddressable) { result = classification.isDefaultRequiresAccessPermission(); } else if (attribute.equals(DEFAULT_REQUIRES_READ.getName())) { result = classification.isDefaultRequiresReadPermission(); } else if (attribute.equals(DEFAULT_REQUIRES_WRITE.getName())) { result = classification.isDefaultRequiresWritePermission(); } else if (attribute.equals(CONFIGURED_REQUIRES_ADDRESSABLE.getName()) && includeAddressable) { result = classification.getConfiguredRequiresAccessPermission(); } else if (attribute.equals(CONFIGURED_REQUIRES_READ.getName())) { result = classification.getConfiguredRequiresReadPermission(); } else if (attribute.equals(CONFIGURED_REQUIRES_WRITE.getName())) { result = classification.getConfiguredRequiresWritePermission(); } else { throw DomainManagementLogger.ROOT_LOGGER.invalidSensitiveClassificationAttribute(attribute); } context.getResult(); if (result != null) { context.getResult().set(result); } }
Example 12
Source File: ResolvePathHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { // Get the resource final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); final ModelNode model = resource.getModel(); // Validate the operation final ModelNode relativeToOnly = RELATIVE_TO_ONLY.validateOperation(operation); final boolean resolveRelativeToOnly = relativeToOnly.asBoolean(false); // Resolve the model values final ModelNode file = (parentAttribute != null ? parentAttribute.resolveModelAttribute(context, model) : model); final ModelNode relativeTo = relativeToAttribute.resolveModelAttribute(context, file); final ModelNode path = pathAttribute.resolveModelAttribute(context, file); // Resolve paths final String result; if (checkAbsolutePath && path.isDefined() && AbsolutePathService.isAbsoluteUnixOrWindowsPath(path.asString())) { result = pathManager.resolveRelativePathEntry(path.asString(), null); } else if (relativeTo.isDefined()) { // If resolving the full path and a path is defined if (!resolveRelativeToOnly && path.isDefined()) { result = pathManager.resolveRelativePathEntry(path.asString(), relativeTo.asString()); } else { result = pathManager.getPathEntry(relativeTo.asString()).resolvePath(); } } else if (path.isDefined()) { result = pathManager.resolveRelativePathEntry(path.asString(), null); } else { throw ControllerLogger.ROOT_LOGGER.noPathToResolve(relativeToAttribute.getName(), pathAttribute.getName(), model); } context.getResult().set(new ModelNode(result)); context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); }
Example 13
Source File: AuthorizationValidatingHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); Set<String> children = resource.getChildrenNames(ModelDescriptionConstants.AUTHORIZATION); if (children.size() > 1) { String realmName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue(); Set<String> invalid = new HashSet<String>(children); throw DomainManagementLogger.ROOT_LOGGER.multipleAuthorizationConfigurationsDefined(realmName, invalid); } }
Example 14
Source File: GlobalOperationHandlers.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected boolean authorize(OperationContext context, PathAddress base, ModelNode operation) { try { context.readResource(base, false); } catch(UnknowRoleException ex) { context.getFailureDescription().set(ex.getMessage()); return false; } //An exception will happen if not allowed return true; }
Example 15
Source File: AuthenticationValidatingHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { String realmName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue(); if(!hasResource(context)) {//realm has been deleted, who cares :) return; } final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); Set<String> children = resource.getChildrenNames(ModelDescriptionConstants.AUTHENTICATION); if (children.contains(KERBEROS)) { Resource kerberosIdentity = resource.getChild(PathElement.pathElement(SERVER_IDENTITY, KERBEROS)); if (kerberosIdentity == null || kerberosIdentity.getChildrenNames(KEYTAB).size() < 1) { throw DomainManagementLogger.ROOT_LOGGER.kerberosWithoutKeytab(realmName); } } /* * Truststore, Local, and Kerberos can be defined in addition to the username/password mechanism so exclude these from the * validation check. */ children.remove(ModelDescriptionConstants.TRUSTSTORE); children.remove(ModelDescriptionConstants.LOCAL); children.remove(KERBEROS); if (children.size() > 1) { Set<String> invalid = new HashSet<String>(children); invalid.remove(ModelDescriptionConstants.TRUSTSTORE); throw DomainManagementLogger.ROOT_LOGGER.multipleAuthenticationMechanismsDefined(realmName, invalid); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); }
Example 16
Source File: JmxFacadeRbacEnabledTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (readOnly) { context.readResource(PathAddress.EMPTY_ADDRESS); } else { context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); } }
Example 17
Source File: ReadChildrenResourcesHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = context.getCurrentAddress(); final String childType = CHILD_TYPE.resolveModelAttribute(context, operation).asString(); // Build up the op we're going to repeatedly execute final ModelNode readOp = new ModelNode(); readOp.get(OP).set(READ_RESOURCE_OPERATION); INCLUDE_RUNTIME.validateAndSet(operation, readOp); RECURSIVE.validateAndSet(operation, readOp); RECURSIVE_DEPTH.validateAndSet(operation, readOp); PROXIES.validateAndSet(operation, readOp); INCLUDE_DEFAULTS.validateAndSet(operation, readOp); final Map<PathElement, ModelNode> resources = new HashMap<PathElement, ModelNode>(); final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS, false); final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); Map<String, Set<String>> childAddresses = GlobalOperationHandlers.getChildAddresses(context, address, registry, resource, childType); Set<String> childNames = childAddresses.get(childType); if (childNames == null) { throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.unknownChildType(childType)); } // Track any excluded items FilteredData filteredData = new FilteredData(address); // We're going to add a bunch of steps that should immediately follow this one. We are going to add them // in reverse order of how they should execute, building up a stack. // Last to execute is the handler that assembles the overall response from the pieces created by all the other steps final ReadChildrenResourcesAssemblyHandler assemblyHandler = new ReadChildrenResourcesAssemblyHandler(resources, filteredData, address, childType); context.addStep(assemblyHandler, OperationContext.Stage.MODEL, true); for (final String key : childNames) { final PathElement childPath = PathElement.pathElement(childType, key); final PathAddress childAddress = PathAddress.EMPTY_ADDRESS.append(PathElement.pathElement(childType, key)); final ModelNode readResOp = readOp.clone(); readResOp.get(OP_ADDR).set(PathAddress.pathAddress(address, childPath).toModelNode()); // See if there was an override registered for the standard :read-resource handling (unlikely!!!) OperationStepHandler overrideHandler = context.getResourceRegistration().getOperationHandler(childAddress, READ_RESOURCE_OPERATION); if (overrideHandler == null) { throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noOperationHandler()); } else if (overrideHandler.getClass() == ReadResourceHandler.class) { // not an override overrideHandler = null; } OperationStepHandler rrHandler = new ReadResourceHandler(filteredData, overrideHandler, false); final ModelNode rrRsp = new ModelNode(); resources.put(childPath, rrRsp); context.addStep(rrRsp, readResOp, rrHandler, OperationContext.Stage.MODEL, true); } }
Example 18
Source File: ValidateAddressOperationHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode addr = VALUE_PARAM.validateOperation(operation); final PathAddress pathAddr = PathAddress.pathAddress(addr); Resource model = context.readResource(PathAddress.EMPTY_ADDRESS); final Iterator<PathElement> iterator = pathAddr.iterator(); PathAddress current = PathAddress.EMPTY_ADDRESS; out: while(iterator.hasNext()) { final PathElement next = iterator.next(); current = current.append(next); // Check if the registration is a proxy and dispatch directly final ImmutableManagementResourceRegistration registration = context.getResourceRegistration().getSubModel(current); if(registration != null && registration.isRemote()) { // If the target is a registered proxy return immediately if(! iterator.hasNext()) { break out; } // Create the proxy op final PathAddress newAddress = pathAddr.subAddress(current.size()); final ModelNode newOperation = operation.clone(); newOperation.get(OP_ADDR).set(current.toModelNode()); newOperation.get(VALUE).set(newAddress.toModelNode()); // On the DC the host=master is not a proxy but the validate-address is registered at the root // Otherwise delegate to the proxy handler final OperationStepHandler proxyHandler = registration.getOperationHandler(PathAddress.EMPTY_ADDRESS, OPERATION_NAME); if(proxyHandler != null) { context.addStep(newOperation, proxyHandler, OperationContext.Stage.MODEL, true); return; } } else if (model.hasChild(next)) { model = model.getChild(next); } else { // Invalid context.getResult().get(VALID).set(false); context.getResult().get(PROBLEM).set(ControllerLogger.ROOT_LOGGER.childResourceNotFound(next)); return; } } if (authorize(context, current, operation).getDecision() == Decision.DENY) { context.getResult().get(VALID).set(false); context.getResult().get(PROBLEM).set(ControllerLogger.ROOT_LOGGER.managementResourceNotFoundMessage(current)); } else { context.getResult().get(VALID).set(true); } }
Example 19
Source File: AccessConstraintAppliesToResourceDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { AccessConstraintAppliesToResource resource = (AccessConstraintAppliesToResource) context.readResource(PathAddress.EMPTY_ADDRESS); setResult(context, resource.constraintUtilization); }
Example 20
Source File: DeploymentReplaceHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { for (AttributeDefinition def : DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.values()) { def.validateOperation(operation); } String name = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(NAME).resolveModelAttribute(context, operation).asString(); String toReplace = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(TO_REPLACE).resolveModelAttribute(context, operation).asString(); if (name.equals(toReplace)) { throw ServerLogger.ROOT_LOGGER.cannotReplaceDeployment(OPERATION_NAME, NAME, TO_REPLACE, DeploymentRedeployHandler.OPERATION_NAME, DeploymentFullReplaceHandler.OPERATION_NAME); } final PathElement deployPath = PathElement.pathElement(DEPLOYMENT, name); final PathElement replacePath = PathElement.pathElement(DEPLOYMENT, toReplace); final Resource root = context.readResource(PathAddress.EMPTY_ADDRESS, false); if (! root.hasChild(replacePath)) { throw ServerLogger.ROOT_LOGGER.noSuchDeployment(toReplace); } final ModelNode replaceNode = context.readResourceForUpdate(PathAddress.pathAddress(replacePath)).getModel(); final String replacedName = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, replaceNode).asString(); ModelNode deployNode; String runtimeName; if (!root.hasChild(deployPath)) { if (!operation.hasDefined(CONTENT)) { throw ServerLogger.ROOT_LOGGER.noSuchDeployment(name); } // else -- the HostController handles a server group replace-deployment like an add, so we do too final ModelNode content = operation.require(CONTENT); // TODO: JBAS-9020: for the moment overlays are not supported, so there is a single content item final ModelNode contentItemNode = content.require(0); if (contentItemNode.hasDefined(HASH)) { byte[] hash = contentItemNode.require(HASH).asBytes(); addFromHash(ModelContentReference.fromDeploymentName(name, hash)); } else { } runtimeName = operation.hasDefined(RUNTIME_NAME) ? DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, operation).asString() : replacedName; // Create the resource final Resource deployResource = context.createResource(PathAddress.pathAddress(deployPath)); deployNode = deployResource.getModel(); deployNode.get(RUNTIME_NAME).set(runtimeName); //TODO Assumes this can only be set by client deployNode.get(ModelDescriptionConstants.PERSISTENT).set(true); deployNode.get(CONTENT).set(content); } else { deployNode = context.readResourceForUpdate(PathAddress.pathAddress(deployPath)).getModel(); if (ENABLED.resolveModelAttribute(context, deployNode).asBoolean()) { throw ServerLogger.ROOT_LOGGER.deploymentAlreadyStarted(toReplace); } runtimeName = operation.hasDefined(RUNTIME_NAME) ? DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, operation).asString() : deployNode.require(RUNTIME_NAME).asString(); deployNode.get(RUNTIME_NAME).set(runtimeName); } deployNode.get(ENABLED.getName()).set(true); replaceNode.get(ENABLED.getName()).set(false); final DeploymentHandlerUtil.ContentItem[] contents = getContents(deployNode.require(CONTENT)); DeploymentHandlerUtil.replace(context, replaceNode, runtimeName, name, replacedName, vaultReader, contents); }