Java Code Examples for org.jboss.dmr.ModelNode#toString()
The following examples show how to use
org.jboss.dmr.ModelNode#toString() .
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: AbstractITest.java From hawkular-agent with Apache License 2.0 | 6 votes |
protected void assertNodeRegex(ModelControllerClient mcc, ModelNode address, Class<?> caller, String expectedNodeFileName, boolean saveActual) { try { ModelNode actual = OperationBuilder .readResource() .address(address) .includeRuntime() .includeDefaults() .recursive() .execute(mcc) .assertSuccess() .getResultNode(); String expected = readNode(caller, expectedNodeFileName); Pattern pattern = Pattern.compile(expected); String actualString = actual.toString(); if (saveActual) { writeNode(caller, actual, expectedNodeFileName + ".actual.txt"); } Assert.assertTrue(pattern.matcher(actualString).matches()); } catch (Exception e) { throw new RuntimeException(e); } }
Example 2
Source File: DomainModelControllerService.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public ModelNode getProfileOperations(String profileName) { ModelNode operation = new ModelNode(); operation.get(OP).set(DESCRIBE); operation.get(OP_ADDR).set(PathAddress.pathAddress(PathElement.pathElement(PROFILE, profileName)).toModelNode()); operation.get(SERVER_LAUNCH).set(true); ModelNode rsp = getValue().execute(operation, null, null, null); if (!rsp.hasDefined(OUTCOME) || !SUCCESS.equals(rsp.get(OUTCOME).asString())) { ModelNode msgNode = rsp.get(FAILURE_DESCRIPTION); String msg = msgNode.isDefined() ? msgNode.toString() : HostControllerLogger.ROOT_LOGGER.failedProfileOperationsRetrieval(); throw new RuntimeException(msg); } return rsp.require(RESULT); }
Example 3
Source File: HcExtensionAndSubsystemManagementTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private static void validateInvokePublicStep(ModelNode response, int step, boolean expectRollback) { String msg = response.toString(); assertTrue(msg, response.has("result")); ModelNode result = response.get("result"); assertTrue(msg, result.isDefined()); String stepKey = "step-"+step; assertEquals(msg, expectRollback ? "failed" : "success", result.get(stepKey, "outcome").asString()); assertTrue(msg, result.has(stepKey, "result")); assertEquals(msg, TestHostCapableExtension.MODULE_NAME, result.get(stepKey, "result").asString()); if (expectRollback) { assertTrue(msg, result.has(stepKey, "rolled-back")); assertTrue(msg, result.get(stepKey, "rolled-back").asBoolean()); } else { assertFalse(msg, result.has(stepKey, "rolled-back")); } }
Example 4
Source File: ExtensionSubsystemCompositeTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private static void validateInvokePublicStep(ModelNode response, int step, boolean expectRollback) { String msg = response.toString(); assertTrue(msg, response.has("result")); ModelNode result = response.get("result"); assertTrue(msg, result.isDefined()); String stepKey = "step-"+step; assertEquals(msg, expectRollback ? "failed" : "success", result.get(stepKey, "outcome").asString()); assertTrue(msg, result.has(stepKey, "result")); assertTrue(msg, result.get(stepKey, "result").asBoolean()); if (expectRollback) { assertTrue(msg, result.has(stepKey, "rolled-back")); assertTrue(msg, result.get(stepKey, "rolled-back").asBoolean()); } else { assertFalse(msg, result.has(stepKey, "rolled-back")); } }
Example 5
Source File: DmrUtils.java From hawkular-agent with Apache License 2.0 | 6 votes |
public static String toJavaStringLiteral(ModelNode node) { String in = node.toString(); StringBuilder result = new StringBuilder(in.length() + in.length()/16); StringTokenizer st = new StringTokenizer(in, "\n\r"); boolean first = true; while (st.hasMoreTokens()) { String line = st.nextToken(); /* no newline character at the end of the last line */ String newLine = st.hasMoreTokens() ? "\\n" : ""; line = "\"" + line.replace("\"", "\\\"") + newLine + "\" //"; if (first) { first = false; } else { line = "+ " + line; } result.append(line); } return result.toString(); }
Example 6
Source File: AbstractITest.java From hawkular-agent with Apache License 2.0 | 6 votes |
protected void assertNodeEquals(ModelControllerClient mcc, ModelNode address, Class<?> caller, String expectedNodeFileName, boolean saveActual) { try { ModelNode actual = OperationBuilder .readResource() .address(address) .includeRuntime() .includeDefaults() .recursive() .execute(mcc) .assertSuccess() .getResultNode(); String expected = readNode(caller, expectedNodeFileName); String actualString = actual.toString(); if (saveActual) { writeNode(caller, actual, expectedNodeFileName + ".actual.txt"); } Assert.assertEquals(actualString, expected); } catch (Exception e) { throw new RuntimeException(e); } }
Example 7
Source File: RolloutPlanBuilder.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public String buildAsString() { ModelNode plan = build(); String planString = plan.toString(); planString = planString.replace("\n", " "); return planString; }
Example 8
Source File: ModelTestKernelServicesImpl.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public ModelNode executeForResult(ModelNode operation, InputStream...inputStreams) throws OperationFailedException { ModelNode rsp = executeOperation(operation, inputStreams); if (FAILED.equals(rsp.get(OUTCOME).asString())) { ModelNode fd = rsp.get(FAILURE_DESCRIPTION); throw new OperationFailedException(fd.toString(), fd); } return rsp.get(RESULT); }
Example 9
Source File: RealmAddHandler.java From keycloak with Apache License 2.0 | 5 votes |
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { // TODO: localize exception. get id number if (!operation.get(OP).asString().equals(ADD)) { throw new OperationFailedException("Unexpected operation for add realm. operation=" + operation.toString()); } for (AttributeDefinition attrib : RealmDefinition.ALL_ATTRIBUTES) { attrib.validateAndSet(operation, model); } }
Example 10
Source File: KeycloakAdapterConfigService.java From keycloak with Apache License 2.0 | 5 votes |
public void updateCredential(ModelNode operation, String attrName, ModelNode resolvedValue) { ModelNode credentials = credentialsFromOp(operation); if (!credentials.isDefined()) { throw new RuntimeException("Can not update credential. No credential defined for deployment in op " + operation.toString()); } String credentialName = credentialNameFromOp(operation); credentials.get(credentialName).set(resolvedValue); }
Example 11
Source File: DeploymentHandlerUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static String getFormattedFailureDescription(OperationContext context) { ModelNode failureDescNode = context.getFailureDescription(); String failureDesc = failureDescNode.toString(); // // Strip the wrapping {} from ModelType.OBJECT types // if (failureDescNode.getType() == ModelType.OBJECT && failureDesc.length() > 2 // && failureDesc.charAt(0) == '{' && failureDesc.charAt(failureDesc.length() - 1) == '}') { // failureDesc = failureDesc.substring(1, failureDesc.length() - 1); // } if (failureDesc.contains("\n") && failureDesc.charAt(0) != '\n') { failureDesc = "\n" + failureDesc; } return failureDesc; }
Example 12
Source File: AbstractCoreModelTest.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private ModelNode fixSensitivityConstraint(ModelNode modelNode) { if (modelNode.hasDefined("core-service","management","access","authorization","constraint","sensitivity-classification","type")) { ModelNode typeNode = modelNode.get("core-service","management","access","authorization","constraint","sensitivity-classification","type"); for (String type : typeNode.keys()) { if (typeNode.hasDefined(type, "classification")) { ModelNode classificationNode = typeNode.get(type, "classification"); if ("core".equals(type)) { if (!classificationNode.hasDefined("credential") || !classificationNode.hasDefined("domain-controller")) { throw new IllegalArgumentException(classificationNode.toString()); } } for (String classification : classificationNode.keys()) { ModelNode target = classificationNode.get(classification); if (target.has("default-requires-addressable")) { target.remove("default-requires-addressable"); } if (target.has("default-requires-read")) { target.remove("default-requires-read"); } if (target.has("default-requires-write")) { target.remove("default-requires-write"); } } if ("core".equals(type)) { if (!classificationNode.hasDefined("credential") || !classificationNode.hasDefined("domain-controller")) { throw new IllegalArgumentException(classificationNode.toString()); } } } } } else throw new IllegalArgumentException(modelNode.toString()); return modelNode; }
Example 13
Source File: AbstractControllerTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public ModelNode executeForResult(ModelNode operation) throws OperationFailedException { ModelNode rsp = getController().execute(operation, null, null, null); if (FAILED.equals(rsp.get(OUTCOME).asString())) { ModelNode fd = rsp.get(FAILURE_DESCRIPTION); throw new OperationFailedException(fd.toString(), fd); } return rsp.get(RESULT); }
Example 14
Source File: AbstractControllerTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public ModelNode executeForResult(ModelNode operation) throws OperationFailedException { ModelNode rsp = getController().execute(operation, null, null, null); if (FAILED.equals(rsp.get(OUTCOME).asString())) { ModelNode fd = rsp.get(FAILURE_DESCRIPTION); throw new OperationFailedException(fd.toString(), fd); } return rsp.get(RESULT); }
Example 15
Source File: ProviderResourceAddHandler.java From keycloak with Apache License 2.0 | 5 votes |
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { // TODO: localize exception. get id number if (!operation.get(OP).asString().equals(ADD)) { throw new OperationFailedException("Unexpected operation for add SPI. operation=" + operation.toString()); } ProviderResourceDefinition.ENABLED.validateAndSet(operation, model); ProviderResourceDefinition.PROPERTIES.validateAndSet(operation, model); KeycloakAdapterConfigService.INSTANCE.updateConfig(operation, model); }
Example 16
Source File: ThreadsSubsystemParsingTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Override to get the actual result from the response. * * @param operation the operation to execute * @return the response's "result" child node * @throws OperationFailedException if the response outcome is "failed" */ public ModelNode executeForResult(ModelNode operation) throws OperationFailedException { createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT); ModelNode rsp = services.executeForResult(operation); if (FAILED.equals(rsp.get(OUTCOME).asString())) { ModelNode fd = rsp.get(FAILURE_DESCRIPTION); throw new OperationFailedException(fd.toString(), fd); } model = services.readWholeModel(); return rsp.get(RESULT); }
Example 17
Source File: AbstractControllerTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public ModelNode executeCheckNoFailure(ModelNode operation) throws OperationFailedException { ModelNode rsp = getController().execute(operation, null, null, null); if (FAILED.equals(rsp.get(OUTCOME).asString())) { ModelNode fd = rsp.get(FAILURE_DESCRIPTION); throw new OperationFailedException(fd.toString(), fd); } return rsp; }
Example 18
Source File: KeycloakAdapterConfigService.java From keycloak with Apache License 2.0 | 5 votes |
public void removeCredential(ModelNode operation) { ModelNode credentials = credentialsFromOp(operation); if (!credentials.isDefined()) { throw new RuntimeException("Can not remove credential. No credential defined for deployment in op " + operation.toString()); } String credentialName = credentialNameFromOp(operation); credentials.remove(credentialName); }
Example 19
Source File: DMRDriver.java From hawkular-agent with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public Map<DMRNodeLocation, ModelNode> fetchNodes(DMRNodeLocation query) throws ProtocolException { ReadResourceOperationBuilder<?> opBuilder = OperationBuilder .readResource()// .address(query.getPathAddress()) // .includeRuntime(); // time the execute separately - we want to time ONLY the execute call OperationResult<?> opResult; try (Context timerContext = diagnostics.getRequestTimer().time()) { opResult = opBuilder.execute(client); } catch (Exception e) { diagnostics.getErrorRate().mark(1); throw new ProtocolException("Error fetching nodes for query [" + query + "]", e); } Optional<ModelNode> resultNode = opResult.getOptionalResultNode(); if (resultNode.isPresent()) { ModelNode n = resultNode.get(); if (n.getType() == ModelType.OBJECT) { return Collections.singletonMap(query, n); } else if (n.getType() == ModelType.LIST) { Map<DMRNodeLocation, ModelNode> result = new HashMap<>(); List<ModelNode> list = n.asList(); for (ModelNode item : list) { ModelNode pathAddress = item.get(JBossASClient.ADDRESS); pathAddress = makePathAddressFullyQualified_WFLY6628(query.getPathAddress(), pathAddress); result.put(DMRNodeLocation.of(pathAddress, true, true), JBossASClient.getResults(item)); } return Collections.unmodifiableMap(result); } else { throw new IllegalStateException("Invalid type - please report this bug: " + n.getType() + " [[" + n.toString() + "]]"); } } else { return Collections.emptyMap(); } }
Example 20
Source File: CompositeOperationTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private static void validateRRDResponse(ModelNode response, int stepCount) { String responseString = response.toString(); assertEquals(responseString, SUCCESS, response.get(OUTCOME).asString()); assertTrue(responseString, response.hasDefined(RESULT)); ModelNode result = response.get(RESULT); assertEquals(responseString, ModelType.OBJECT, result.getType()); List<Property> list = result.asPropertyList(); assertEquals(responseString, stepCount, list.size()); for (Property prop : list) { ModelNode stepResp = prop.getValue(); assertEquals(responseString, SUCCESS, stepResp.get(OUTCOME).asString()); assertTrue(responseString, stepResp.hasDefined(RESULT, ATTRIBUTES)); ModelNode stepResult = stepResp.get(RESULT); Set<String> keys = stepResult.get(ATTRIBUTES).keys(); assertTrue(responseString, keys.contains("launch-type")); assertTrue(responseString, keys.contains("server-state")); assertTrue(responseString, keys.contains("runtime-configuration-state")); assertTrue(responseString, stepResult.hasDefined(ACCESS_CONTROL, "default", ATTRIBUTES)); Set<String> accessKeys = stepResult.get(ACCESS_CONTROL, "default", ATTRIBUTES).keys(); assertTrue(responseString, accessKeys.contains("launch-type")); assertTrue(responseString, accessKeys.contains("server-state")); assertTrue(responseString, accessKeys.contains("runtime-configuration-state")); assertTrue(responseString, stepResult.hasDefined(ACCESS_CONTROL, EXCEPTIONS)); assertEquals(responseString, 0, stepResult.get(ACCESS_CONTROL, EXCEPTIONS).asInt()); switch (prop.getName()) { case "step-1": case "step-2": assertEquals(responseString, 3, keys.size()); assertEquals(responseString, 3, accessKeys.size()); break; case "step-3": case "step-4": assertTrue(responseString, keys.size() > 2); assertEquals(responseString, keys.size(), accessKeys.size()); break; default: fail(responseString); } } }