@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { operationDeprecated(context, operation); PathAddress address = translateProxyPath(context); String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString(); PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type)); PathAddress metricPathAddress = address.append(metricPath); ModelNode metricOperation = Util.createAddOperation(metricPathAddress); OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.ADD); for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) { String name = attribute.getName(); if (operation.hasDefined(name)) { metricOperation.get(name).set(operation.get(name)); } } context.addStep(metricOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true); } };
static void executeDirectOperation(OperationContext context, ModelNode operation, boolean checkPrivate) throws OperationFailedException { final String operationName = operation.require(OP).asString(); final ImmutableManagementResourceRegistration registration = context.getResourceRegistration(); PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR)); final OperationEntry stepEntry = context.getRootResourceRegistration().getOperationEntry(pathAddress, operationName); if (stepEntry != null) { boolean illegalPrivateStep = checkPrivate && stepEntry.getType() == OperationEntry.EntryType.PRIVATE && operation.hasDefined(OPERATION_HEADERS, CALLER_TYPE) && USER.equals(operation.get(OPERATION_HEADERS, CALLER_TYPE).asString()); if (illegalPrivateStep) { context.getFailureDescription().set(ControllerLogger.ROOT_LOGGER.noHandlerForOperation(operationName, pathAddress)); } else { context.addModelStep(stepEntry.getOperationDefinition(), stepEntry.getOperationHandler(), false); } } else { if (! context.isBooting()) { if (registration == null) { context.getFailureDescription().set(ControllerLogger.ROOT_LOGGER.noSuchResourceType(pathAddress)); } else { context.getFailureDescription().set(ControllerLogger.ROOT_LOGGER.noHandlerForOperation(operationName, pathAddress)); } } } }
final String opName = operation.require(OP).asString(); PathAddress opAddr = PathAddress.pathAddress(operation.get(OP_ADDR)); final DescriptionProvider descriptionProvider = registry.getModelDescription(PathAddress.EMPTY_ADDRESS); final Locale locale = GlobalOperationHandlers.getLocale(context, operation); context.addStep(assemblyHandler, OperationContext.Stage.MODEL, true); for (final Map.Entry<String, OperationEntry> entry : registry.getOperationDescriptions(PathAddress.EMPTY_ADDRESS, inherited).entrySet()) { if (entry.getValue().getType() == OperationEntry.EntryType.PUBLIC) { if (context.getProcessType() != ProcessType.DOMAIN_SERVER || entry.getValue().getFlags().contains(OperationEntry.Flag.RUNTIME_ONLY)) { final DescriptionProvider provider = entry.getValue().getDescriptionProvider(); operations.put(entry.getKey(), provider.getModelDescription(locale)); for (final Map.Entry<String, NotificationEntry> entry : registry.getNotificationDescriptions(PathAddress.EMPTY_ADDRESS, inherited).entrySet()) { final DescriptionProvider provider = entry.getValue().getDescriptionProvider(); notifications.put(entry.getKey(), provider.getModelDescription(locale)); context.getProcessType() == ProcessType.DOMAIN_SERVER && storage == AttributeAccess.Storage.CONFIGURATION ? AttributeAccess.AccessType.READ_ONLY.toString() : accessType.toString(); attrNode.get(ACCESS_TYPE).set(displayedAccessType); for (final PathElement element : registry.getChildAddresses(PathAddress.EMPTY_ADDRESS)) { PathAddress relativeAddr = PathAddress.pathAddress(element); ImmutableManagementResourceRegistration childReg = registry.getSubModel(relativeAddr);
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); if (registry == null) { throw new OperationFailedException(ControllerMessages.MESSAGES.noSuchResourceType(PathAddress.pathAddress(operation.get(OP_ADDR)))); final Map<String, OperationEntry> operations = registry.getOperationDescriptions(PathAddress.EMPTY_ADDRESS, true); final boolean accessControl = ACCESS_CONTROL.resolveModelAttribute(context, operation).asBoolean(); final ModelNode result = new ModelNode(); if (operations.size() > 0) { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); for (final Map.Entry<String, OperationEntry> entry : operations.entrySet()) { if (entry.getValue().getType() == OperationEntry.EntryType.PUBLIC) { if (context.getProcessType() != ProcessType.DOMAIN_SERVER || entry.getValue().getFlags().contains(OperationEntry.Flag.RUNTIME_ONLY)) { ModelNode operationToCheck = Util.createOperation(entry.getKey(), address); operationToCheck.get(OPERATION_HEADERS).set(operation.get(OPERATION_HEADERS)); AuthorizationResult authorizationResult = context.authorizeOperation(operationToCheck); add = authorizationResult.getDecision() == Decision.PERMIT;
private Object invoke(final OperationEntry entry, final String operationName, PathAddress address, Object[] params) throws InstanceNotFoundException, MBeanException, ReflectionException { if (!standalone && !entry.getFlags().contains(OperationEntry.Flag.READ_ONLY)) { throw MESSAGES.noOperationCalled(operationName); final ModelNode description = entry.getDescriptionProvider().getModelDescription(null); ModelNode op = new ModelNode(); op.get(OP).set(operationName); op.get(OP_ADDR).set(address.toModelNode()); if (params.length > 0) { ModelNode requestProperties = description.require(REQUEST_PROPERTIES);
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { String operationName = NAME.resolveModelAttribute(context, operation).asString(); final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); OperationEntry operationEntry = registry.getOperationEntry(PathAddress.EMPTY_ADDRESS, operationName); if (operationEntry == null || (context.getProcessType() == ProcessType.DOMAIN_SERVER && !operationEntry.getFlags().contains(OperationEntry.Flag.RUNTIME_ONLY))) { throw new OperationFailedException(new ModelNode().set(MESSAGES.operationNotRegistered(operationName, PathAddress.pathAddress(operation.require(OP_ADDR))))); } else { final ModelNode result = operationEntry.getDescriptionProvider().getModelDescription(GlobalOperationHandlers.getLocale(context, operation)); Set<OperationEntry.Flag> flags = operationEntry.getFlags(); boolean readOnly = flags.contains(OperationEntry.Flag.READ_ONLY); result.get(READ_ONLY).set(readOnly); if (!readOnly) { if (flags.contains(OperationEntry.Flag.RESTART_ALL_SERVICES)) { result.get(RESTART_REQUIRED).set("all-services"); } else if (flags.contains(OperationEntry.Flag.RESTART_RESOURCE_SERVICES)) { result.get(RESTART_REQUIRED).set("resource-services"); } else if (flags.contains(OperationEntry.Flag.RESTART_JVM)) { result.get(RESTART_REQUIRED).set("jvm"); } } context.getResult().set(result); } context.stepCompleted(); } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (MGMT_OP_LOGGER.isTraceEnabled()) { MGMT_OP_LOGGER.tracef("Executing %s %s", operation.get(OP), operation.get(OP_ADDR)); } final PathAddress address = context.getCurrentAddress(); final String operationName = operation.require(OP).asString(); final OperationEntry stepOperation = resolveOperationHandler(address, operationName); if (stepOperation != null) { if (!context.isBooting() && stepOperation.getType() == OperationEntry.EntryType.PRIVATE && operation.hasDefined(OPERATION_HEADERS, CALLER_TYPE) && USER.equals(operation.get(OPERATION_HEADERS, CALLER_TYPE).asString())) { // End user trying to invoke a private op. Respond as if there is no such operation context.getFailureDescription().set(ControllerLogger.ROOT_LOGGER.noHandlerForOperation(operationName, address)); } else { context.addModelStep(stepOperation.getOperationDefinition(), stepOperation.getOperationHandler(), false); } } else { ImmutableManagementResourceRegistration child = managementModel.get().getRootResourceRegistration().getSubModel(address); if (child == null) { context.getFailureDescription().set(ControllerLogger.ROOT_LOGGER.noSuchResourceType(address)); } else { context.getFailureDescription().set(ControllerLogger.ROOT_LOGGER.noHandlerForOperation(operationName, address)); } } context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER); } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { operationDeprecated(context, operation); PathAddress address = translateProxyPath(context); String type = operation.require(CustomLoadMetricResourceDefinition.Attribute.CLASS.getName()).asString(); PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type)); PathAddress metricPathAddress = address.append(metricPath); ModelNode metricOperation = Util.createRemoveOperation(metricPathAddress); OperationEntry removeOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.REMOVE); context.addStep(metricOperation, removeOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true); } };
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { Resource res = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS,false); Set<String> hosts = res.getChildrenNames(HOST); String hostName = hosts.iterator().next(); PathAddress address = PathAddress.pathAddress(PathElement.pathElement(HOST)); //Hacky part we are getting the handler from a real host and calling the operation on /host=* OperationEntry entry = context.getRootResourceRegistration().getOperationEntry(PathAddress.pathAddress(PathElement.pathElement(HOST, hostName)), OPERATION_NAME); ModelNode reportOperation = Util.getEmptyOperation(OPERATION_NAME, address.toModelNode()); if (operation.hasDefined(CREATE_REPORT_DEFINITION.getName())) { reportOperation.get(CREATE_REPORT_DEFINITION.getName()).set(operation.get(CREATE_REPORT_DEFINITION.getName())); if (operation.hasDefined(FILE_FORMAT_DEFINITION.getName())) { reportOperation.get(FILE_FORMAT_DEFINITION.getName()).set(operation.get(FILE_FORMAT_DEFINITION.getName())); } } if (entry != null) { OperationStepHandler osh = entry.getOperationHandler(); context.addStep(reportOperation, osh, OperationContext.Stage.MODEL); } } };
return; final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String name = operation.get(OP).asString(); OperationEntry entry = root.getOperationEntry(address, name); if (entry == null) { throwOrWarnAboutDescriptorProblem(ControllerLogger.ROOT_LOGGER.noOperationEntry(name, address)); if (entry.getType() == EntryType.PRIVATE || entry.getFlags().contains(OperationEntry.Flag.HIDDEN)) { return; if (entry.getOperationHandler() == null) { throwOrWarnAboutDescriptorProblem(ControllerLogger.ROOT_LOGGER.noOperationHandler(name, address));
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); final Map<String, OperationEntry> operations = registry.getOperationDescriptions(PathAddress.EMPTY_ADDRESS, true); final ModelNode result = new ModelNode(); if (operations.size() > 0) { for (final Map.Entry<String, OperationEntry> entry : operations.entrySet()) { if (entry.getValue().getType() == OperationEntry.EntryType.PUBLIC) { if (context.getProcessType() != ProcessType.DOMAIN_SERVER || entry.getValue().getFlags().contains(OperationEntry.Flag.RUNTIME_ONLY)) { result.add(entry.getKey()); } } } } else { result.setEmptyList(); } context.getResult().set(result); context.stepCompleted(); } }
private static OpData getOpData(OperationContext context, ModelNode subOperation, ModelNode response, PathAddress stepAddress, OperationHandlerResolver handlerResolver, boolean rejectPrivateOperations) throws OperationFailedException { ImmutableManagementResourceRegistration registry = context.getRootResourceRegistration(); String stepOpName = subOperation.require(OP).asString(); OperationEntry operationEntry = registry.getOperationEntry(stepAddress, stepOpName); if (operationEntry == null) { ImmutableManagementResourceRegistration child = registry.getSubModel(stepAddress); if (child == null) { throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noSuchResourceType(stepAddress)); } else { throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noHandlerForOperation(stepOpName, stepAddress)); } } else if (operationEntry.getType() == OperationEntry.EntryType.PRIVATE) { if (rejectPrivateOperations || (subOperation.hasDefined(OPERATION_HEADERS, CALLER_TYPE) && USER.equals(subOperation.get(OPERATION_HEADERS, CALLER_TYPE).asString()))) { // Not allowed; respond as if there is no such operation throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noHandlerForOperation(stepOpName, stepAddress)); } } OperationStepHandler osh = handlerResolver.getOperationStepHandler(stepOpName, stepAddress, subOperation, operationEntry); return new OpData(subOperation, operationEntry.getOperationDefinition(), osh, response); }
private void addHostReport(OperationContext context, PathAddress address, String host, final Map<String, GlobalOperationHandlers.AvailableResponse> responseMap) { ModelNode reportOperation = Util.getEmptyOperation(SUB_OPERATION_NAME, address.toModelNode()); final ModelNode response = new ModelNode(); GlobalOperationHandlers.AvailableResponse availableResponse = new GlobalOperationHandlers.AvailableResponse(response); responseMap.put(host, availableResponse); OperationEntry entry = context.getRootResourceRegistration().getOperationEntry(address, SUB_OPERATION_NAME); if (entry != null) { OperationStepHandler osh = entry.getOperationHandler(); GlobalOperationHandlers.AvailableResponseWrapper wrapper = new GlobalOperationHandlers.AvailableResponseWrapper(osh, availableResponse); context.addStep(response, reportOperation, wrapper, OperationContext.Stage.RUNTIME); ControllerLogger.ROOT_LOGGER.debugf("We are asking the host %s its report", host); } }
public final void execute(final OperationContext context, final ModelNode operation) { if (context.isBooting()) { execute(TARGET); } else { // WFCORE-1781 We should not be called post-boot as the DUP chain can only be modified in boot // Check and see if the OperationDefinition for this op declares reload/restart required and if so // trigger that; otherwise fail. ImmutableManagementResourceRegistration mrr = context.getResourceRegistration(); OperationEntry oe = mrr.getOperationEntry(PathAddress.EMPTY_ADDRESS, operation.get(ModelDescriptionConstants.OP).asString()); Set<OperationEntry.Flag> flags = oe == null ? Collections.emptySet() : oe.getOperationDefinition().getFlags(); if (flags.contains(OperationEntry.Flag.RESTART_JVM)) { context.restartRequired(); context.completeStep((ctx, op) -> ctx.revertRestartRequired()); } else if (flags.contains(OperationEntry.Flag.RESTART_ALL_SERVICES)) { context.reloadRequired(); context.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER); } else { // Coding error we cannot recover from throw new IllegalStateException(); } } }
private void addOpenjdkExtension(final OperationContext context, final Map<PathAddress, ModelNode> migrateOperations) { final PathAddress extensionAddress = PathAddress.EMPTY_ADDRESS.append(OPENJDK_EXTENSION_ELEMENT); OperationEntry addEntry = context.getRootResourceRegistration().getOperationEntry(extensionAddress, ADD); final ModelNode addOperation = Util.createAddOperation(extensionAddress); if (describe) { migrateOperations.put(extensionAddress, addOperation); } else { context.addStep(context.getResult().get(extensionAddress.toString()), addOperation, addEntry.getOperationHandler(), MODEL); } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ModelNode patchingInfo = new ModelNode(); PathAddress patchingAddress = PathAddress.pathAddress(PathElement.pathElement(CORE_SERVICE, "patching")); OperationEntry opEntry = context.getRootResourceRegistration().getOperationEntry(patchingAddress, "show-history"); if(opEntry != null) { context.addStep(patchingInfo, Util.createOperation("show-history", patchingAddress), opEntry.getOperationHandler(), OperationContext.Stage.RUNTIME); } final Path installationDir = environment.getHomeDir().toPath(); context.addStep(new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode result = context.getResult(); result.get(SUMMARY_DEFINITION.getName()).set(createProductNode(context, new InstallationConfiguration( environment, environment.getProductConfig(), patchingInfo, installationDir))); } }, OperationContext.Stage.RUNTIME); } }
private void addStandaloneReport(OperationContext context, final Map<String, GlobalOperationHandlers.AvailableResponse> responseMap) { ModelNode reportOperation = Util.getEmptyOperation(SUB_OPERATION_NAME, PathAddress.EMPTY_ADDRESS.toModelNode()); final ModelNode response = new ModelNode(); GlobalOperationHandlers.AvailableResponse availableResponse = new GlobalOperationHandlers.AvailableResponse(response); OperationEntry entry = context.getResourceRegistration().getOperationEntry(PathAddress.EMPTY_ADDRESS, SUB_OPERATION_NAME); OperationStepHandler osh = entry.getOperationHandler(); GlobalOperationHandlers.AvailableResponseWrapper wrapper = new GlobalOperationHandlers.AvailableResponseWrapper(osh, availableResponse); context.addStep(response, reportOperation, wrapper, OperationContext.Stage.RUNTIME); responseMap.put("", availableResponse); ControllerLogger.ROOT_LOGGER.debug("We are asking the standalone server its report"); }
static boolean isVisible(OperationEntry operationEntry, OperationContext context) { Set<OperationEntry.Flag> flags = operationEntry.getFlags(); return operationEntry.getType() == OperationEntry.EntryType.PUBLIC && !flags.contains(OperationEntry.Flag.HIDDEN) && (context.getProcessType() != ProcessType.DOMAIN_SERVER || flags.contains(OperationEntry.Flag.RUNTIME_ONLY) || flags.contains(OperationEntry.Flag.READ_ONLY)); } }
@Override OperationEntry getOperationEntry(final ListIterator<PathElement> iterator, final String operationName, OperationEntry inherited) { OperationEntry targetOp = target.getOperationEntry(iterator, operationName, inherited); if (targetOp == null) { return null; } return new OperationEntry(handler, targetOp.getDescriptionProvider(), targetOp.isInherited(), targetOp.getType(), targetOp.getFlags()); }
DescribedOp(OperationEntry operationEntry, Locale locale) { this.description = operationEntry.getDescriptionProvider().getModelDescription(locale); this.flags = operationEntry.getFlags(); }