Java Code Examples for org.jboss.dmr.ModelNode#asBoolean()
The following examples show how to use
org.jboss.dmr.ModelNode#asBoolean() .
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: OperationCancellationTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void cancel(DomainClient client, String host, String server, String opName, OperationContext.ExecutionStatus targetStatus, long executionStart, boolean serverOpOnly) throws Exception { PathAddress address = PathAddress.pathAddress(PathElement.pathElement(HOST, host)); if (server != null) { address = address.append(PathElement.pathElement(SERVER, server)); } address = address.append(MGMT_CONTROLLER); final String opToCancel = findActiveOperation(client, address, opName, targetStatus, executionStart, serverOpOnly); address = address.append(PathElement.pathElement(ACTIVE_OPERATION, opToCancel)); ModelNode result = executeForResult(Util.createEmptyOperation("cancel", address), client); boolean retVal = result.asBoolean(); assertTrue(result.asString(), retVal); }
Example 2
Source File: ControlledCommandActivator.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
protected boolean isAddressValid(CommandContext ctx, OperationRequestAddress requiredAddress) { final ModelNode request = new ModelNode(); final ModelNode address = request.get(Util.ADDRESS); address.setEmptyList(); request.get(Util.OPERATION).set(Util.VALIDATE_ADDRESS); final ModelNode addressValue = request.get(Util.VALUE); for (OperationRequestAddress.Node node : requiredAddress) { addressValue.add(node.getType(), node.getName()); } final ModelNode response; try { response = ctx.getModelControllerClient().execute(request); } catch (IOException e) { return false; } final ModelNode result = response.get(Util.RESULT); if (!result.isDefined()) { return false; } final ModelNode valid = result.get(Util.VALID); if (!valid.isDefined()) { return false; } return valid.asBoolean(); }
Example 3
Source File: ReadResourceDescriptionVsActualOperationTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private boolean canExecuteOperation(ModelControllerClient client, String opName, String path) throws IOException { ModelNode operation = createOpNode(path, READ_RESOURCE_DESCRIPTION_OPERATION); operation.get(OPERATIONS).set(true); operation.get(ACCESS_CONTROL).set("trim-descriptions"); ModelNode result = RbacUtil.executeOperation(client, operation, Outcome.SUCCESS); System.out.println(); System.out.println(result); System.out.println(); ModelNode clone = result.clone(); ModelNode allowExecute = clone.get(RESULT, ACCESS_CONTROL, DEFAULT, OPERATIONS, opName, EXECUTE); assertTrue(result.toString(), allowExecute.isDefined()); if (!allowExecute.asBoolean()) { return false; } for (Property prop : clone.get(RESULT, ACCESS_CONTROL, DEFAULT, ATTRIBUTES).asPropertyList()) { ModelNode write = prop.getValue().get(WRITE); assertTrue(prop.toString(), write.isDefined()); if (!prop.getValue().get(WRITE).asBoolean()) { return false; } } return true; }
Example 4
Source File: SecurityRealmAddHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private Supplier<CallbackHandlerService> addLocalService(OperationContext context, ModelNode local, String realmName, ServiceTarget serviceTarget, ServiceBuilder<?> realmBuilder) throws OperationFailedException { ServiceName localServiceName = LocalCallbackHandlerService.ServiceUtil.createServiceName(realmName); ModelNode node = LocalAuthenticationResourceDefinition.DEFAULT_USER.resolveModelAttribute(context, local); String defaultUser = node.isDefined() ? node.asString() : null; node = LocalAuthenticationResourceDefinition.ALLOWED_USERS.resolveModelAttribute(context, local); String allowedUsers = node.isDefined() ? node.asString() : null; node = LocalAuthenticationResourceDefinition.SKIP_GROUP_LOADING.resolveModelAttribute(context, local); boolean skipGroupLoading = node.asBoolean(); final ServiceBuilder<?> builder = serviceTarget.addService(localServiceName); final Consumer<CallbackHandlerService> chsConsumer = builder.provides(localServiceName); builder.setInstance(new LocalCallbackHandlerService(chsConsumer, defaultUser, allowedUsers, skipGroupLoading)); builder.setInitialMode(ON_DEMAND); builder.install(); return CallbackHandlerService.ServiceUtil.requires(realmBuilder, localServiceName); }
Example 5
Source File: ElytronSubsystemTransformers.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected boolean rejectAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { if (attributeValue.isDefined()) { boolean synced = context.readResourceFromRoot(address).getModel().get(SYNCHRONIZED).asBoolean(); return synced != attributeValue.asBoolean(); } return false; }
Example 6
Source File: ResourceAccessControlUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public boolean isWritableAttribute(String attribute) { ModelNode node = accessControl.get(ATTRIBUTES, attribute, WRITE); if (!node.isDefined()) { //Should not happen but return false just in case return false; } return node.asBoolean(); }
Example 7
Source File: ResourceAccessControlUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public boolean isReadableAttribute(String attribute) { ModelNode node = accessControl.get(ATTRIBUTES, attribute, READ); if (!node.isDefined()) { //Should not happen but return false just in case return false; } return node.asBoolean(); }
Example 8
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 9
Source File: GlobalOperationHandlers.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static boolean getRecursive(OperationContext context, ModelNode op) throws OperationFailedException { // -1 means UNDEFINED ModelNode recursiveNode = RECURSIVE.resolveModelAttribute(context, op); final int recursiveValue = recursiveNode.isDefined() ? (recursiveNode.asBoolean() ? 1 : 0) : -1; final int recursiveDepthValue = RECURSIVE_DEPTH.resolveModelAttribute(context, op).asInt(-1); // WFCORE-76: We are recursing in this round IFF: // Recursive is explicitly specified as TRUE and recursiveDepth is UNDEFINED // Recursive is either TRUE or UNDEFINED and recursiveDepth is >0 return recursiveValue > 0 && recursiveDepthValue == -1 || // recursiveValue != 0 && recursiveDepthValue > 0; }
Example 10
Source File: ReadAttributeGroupTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private boolean canExecuteOperation(ModelControllerClient client, String opName, String path) throws IOException { ModelNode operation = createOpNode(path, READ_RESOURCE_DESCRIPTION_OPERATION); operation.get(OPERATIONS).set(true); operation.get(ACCESS_CONTROL).set("trim-descriptions"); ModelNode result = RbacUtil.executeOperation(client, operation, Outcome.SUCCESS); ModelNode clone = result.clone(); ModelNode allowExecute = clone.get(RESULT, ACCESS_CONTROL, DEFAULT, OPERATIONS, opName, EXECUTE); assertTrue(result.toString(), allowExecute.isDefined()); return allowExecute.asBoolean(); }
Example 11
Source File: DatasourceJBossASClient.java From hawkular-agent with Apache License 2.0 | 5 votes |
private boolean isDatasourceEnabled(boolean isXA, String name) throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_DATASOURCES); addr.add((isXA) ? XA_DATA_SOURCE : DATA_SOURCE, name); ModelNode results = readResource(addr); boolean enabledFlag = false; if (results.hasDefined("enabled")) { ModelNode enabled = results.get("enabled"); enabledFlag = enabled.asBoolean(false); } return enabledFlag; }
Example 12
Source File: ResourceAccessControlUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public boolean isExecutableOperation(String operation) { ModelNode node = accessControl.get(OPERATIONS, operation, EXECUTE); if (!node.isDefined()) { //Should not happen but return false just in case return false; } return node.asBoolean(); }
Example 13
Source File: Util.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static boolean isValidPath(ModelControllerClient client, String... node) throws CommandLineException { if(node == null) { return false; } if(node.length % 2 != 0) { return false; } final ModelNode op = new ModelNode(); op.get(ADDRESS).setEmptyList(); op.get(OPERATION).set(VALIDATE_ADDRESS); final ModelNode addressValue = op.get(VALUE); for(int i = 0; i < node.length; i += 2) { addressValue.add(node[i], node[i+1]); } final ModelNode response; try { response = client.execute(op); } catch (IOException e) { throw new CommandLineException("Failed to execute " + VALIDATE_ADDRESS, e); } final ModelNode result = response.get(Util.RESULT); if(!result.isDefined()) { return false; } final ModelNode valid = result.get(Util.VALID); if(!valid.isDefined()) { return false; } return valid.asBoolean(); }
Example 14
Source File: AccessAuthorizationUseIdentityRolesWriteAttributeHander.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void finishModelStage(OperationContext context, ModelNode operation, String attributeName, ModelNode newValue, ModelNode oldValue, Resource model) throws OperationFailedException { boolean useIdentityRoles = newValue.asBoolean(); if (useIdentityRoles == false) { /* * As we are no longer using identity roles we may need another role mapping strategy. */ RbacSanityCheckOperation.addOperation(context); } }
Example 15
Source File: NonPublicClassPartOfAPI.java From revapi with Apache License 2.0 | 5 votes |
@Override public void initialize(@Nonnull AnalysisContext analysisContext) { super.initialize(analysisContext); ModelNode reportUnchanged = analysisContext.getConfiguration().get("reportUnchanged"); if (reportUnchanged.isDefined()) { this.reportUnchanged = reportUnchanged.asBoolean(); } else { this.reportUnchanged = true; } }
Example 16
Source File: UpdateScannerWriteAttributeHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void updateScanner(String attributeName, DeploymentScanner scanner, ModelNode resolvedNewValue) { AttributeDefinition ad = getAttributeDefinition(attributeName); if (ad == AUTO_DEPLOY_EXPLODED) { scanner.setAutoDeployExplodedContent(resolvedNewValue.asBoolean()); } else if (ad == AUTO_DEPLOY_XML) { scanner.setAutoDeployXMLContent(resolvedNewValue.asBoolean()); } else if (ad == AUTO_DEPLOY_ZIPPED) { scanner.setAutoDeployZippedContent(resolvedNewValue.asBoolean()); } else if (ad == DEPLOYMENT_TIMEOUT) { scanner.setDeploymentTimeout(resolvedNewValue.asLong()); } else if (ad == RUNTIME_FAILURE_CAUSES_ROLLBACK) { scanner.setRuntimeFailureCausesRollback(resolvedNewValue.asBoolean()); } else if (ad == SCAN_INTERVAL) { scanner.setScanInterval(resolvedNewValue.asInt()); } else if (ad == SCAN_ENABLED) { boolean enable = resolvedNewValue.asBoolean(); if (enable) { scanner.startScanner(); } else { scanner.stopScanner(); } } else { // Someone forgot something throw new IllegalStateException(); } }
Example 17
Source File: ElytronSubsystemTransformers.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override protected boolean isValueDiscardable(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { boolean synced = context.readResourceFromRoot(address).getModel().get(SYNCHRONIZED).asBoolean(); return synced == attributeValue.asBoolean(); }
Example 18
Source File: QueryOperationHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private static boolean matchesFilter(final ModelNode resource, final ModelNode filter, final Operator operator) throws OperationFailedException { boolean isMatching = false; List<Property> filterProperties = filter.asPropertyList(); List<Boolean> matches = new ArrayList<>(filterProperties.size()); for (Property property : filterProperties) { final String filterName = property.getName(); final ModelNode filterValue = property.getValue(); boolean isEqual = false; if(!filterValue.isDefined() || filterValue.asString().equals(UNDEFINED)) { // query for undefined attributes isEqual = !resource.get(filterName).isDefined(); } else { final ModelType targetValueType = resource.get(filterName).getType(); try { // query for attribute values (throws exception when types don't match) switch (targetValueType) { case BOOLEAN: isEqual = filterValue.asBoolean() == resource.get(filterName).asBoolean(); break; case LONG: isEqual = filterValue.asLong() == resource.get(filterName).asLong(); break; case INT: isEqual = filterValue.asInt() == resource.get(filterName).asInt(); break; case DOUBLE: isEqual = filterValue.asDouble() == resource.get(filterName).asDouble(); break; default: isEqual = filterValue.equals(resource.get(filterName)); } } catch (IllegalArgumentException e) { throw ControllerLogger.MGMT_OP_LOGGER.selectFailedCouldNotConvertAttributeToType(filterName, targetValueType); } } if(isEqual) { matches.add(resource.get(filterName).equals(filterValue)); } } if (Operator.AND.equals(operator)) { // all matches must be true isMatching = matches.size() == filterProperties.size(); } else if(Operator.OR.equals(operator)){ // at least one match must be true for (Boolean match : matches) { if (match) { isMatching = true; break; } } } else { // This is just to catch programming errors where a new case isn't added above throw new IllegalArgumentException( ControllerLogger.MGMT_OP_LOGGER.invalidValue( operator.toString(), OPERATOR, Arrays.asList(Operator.values()) ) ); } return isMatching; }
Example 19
Source File: AccessAuthorizationUseIdentityRolesWriteAttributeHander.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static void updateAuthorizer(final ModelNode value, final WritableAuthorizerConfiguration writableConfiguration) { ModelNode resolvedValue = value.isDefined() ? value : AccessAuthorizationResourceDefinition.USE_IDENTITY_ROLES.getDefaultValue(); boolean useIdentityRoles = resolvedValue.asBoolean(); writableConfiguration.setUseIdentityRoles(useIdentityRoles); }
Example 20
Source File: AbstractIncludeExcludeFilter.java From revapi with Apache License 2.0 | 3 votes |
@Override public void initialize(@Nonnull AnalysisContext analysisContext) { ModelNode root = analysisContext.getConfiguration(); if (!root.isDefined()) { doNothing = true; return; } ModelNode regex = root.get("regex"); boolean regexes = regex.isDefined() && regex.asBoolean(); List<String> fullMatches = new ArrayList<>(); List<Pattern> patterns = new ArrayList<>(); readMatches(root.get("exclude"), regexes, fullMatches, patterns); validateConfiguration(true, fullMatches, patterns, regexes); this.excludeTest = composeTest(fullMatches, patterns); fullMatches = new ArrayList<>(); patterns = new ArrayList<>(); readMatches(root.get("include"), regexes, fullMatches, patterns); validateConfiguration(false, fullMatches, patterns, regexes); this.includeTest = composeTest(fullMatches, patterns); doNothing = includeTest == null && excludeTest == null; }