Java Code Examples for org.jboss.dmr.ModelNode#protect()
The following examples show how to use
org.jboss.dmr.ModelNode#protect() .
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: LegacyTypeConverterUnitTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testPropertyTypeExpressionConverter() throws OperationFailedException { ModelNode description = createDescription(ModelType.PROPERTY); TypeConverter converter = getConverter(description); ModelNode node = new ModelNode(); node.set("name", "${this.should.not.exist.!!!!!:value}"); node.protect(); ModelNode expected = ExpressionResolver.TEST_RESOLVER.resolveExpressions(node.clone()); Assert.assertEquals(SimpleType.STRING, converter.getOpenType()); String dmr = assertCast(String.class, converter.fromModelNode(node)); Assert.assertEquals(expected, ModelNode.fromString(dmr)); Assert.assertEquals(dmr, assertCast(String.class, converter.fromModelNode(expected))); assertToArray(converter, dmr); }
Example 2
Source File: BasicOperationsUnitTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testSocketBindingsWildcards() throws IOException { final ModelNode address = new ModelNode(); address.add("socket-binding-group", "*"); address.add("socket-binding", "*"); address.protect(); final ModelNode operation = new ModelNode(); operation.get(OP).set(READ_RESOURCE_OPERATION); operation.get(OP_ADDR).set(address); final ModelNode result = managementClient.getControllerClient().execute(operation); assertTrue(result.hasDefined(RESULT)); assertEquals(SUCCESS, result.get(OUTCOME).asString()); final Collection<ModelNode> steps = getSteps(result.get(RESULT)); assertFalse(steps.isEmpty()); for(final ModelNode step : steps) { assertTrue(step.hasDefined(OP_ADDR)); assertTrue(step.hasDefined(RESULT)); assertEquals(SUCCESS, step.get(OUTCOME).asString()); } }
Example 3
Source File: LegacyTypeConverterUnitTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testUndefinedTypeConverter() { TypeConverter converter = getConverter(new ModelNode()); Assert.assertEquals(SimpleType.STRING, converter.getOpenType()); ModelNode node = new ModelNode(); // BES 2013/01/10 This uses BigInteger; I'm not sure why. But use a value > Long.MAX_VALUE // so the json parser won't convert it down to a long or int resulting in a different value // See AS7-4913 // Likely BigInteger was used *because of* the problem discussed in AS7-4913 node.get("abc").set(new BigInteger(String.valueOf(Long.MAX_VALUE) + "0")); node.get("def").set(false); node.protect(); String json = assertCast(String.class, converter.fromModelNode(node)); Assert.assertEquals(node, ModelNode.fromJSONString(json)); Assert.assertEquals(json, assertCast(String.class, converter.fromModelNode(node))); assertToArray(converter, json); }
Example 4
Source File: FailedOperationTransformationConfig.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public ModelNode correctOperation(ModelNode operation) { ModelNode op = operation.clone(); for (String attr : attributes) { ModelNode value = op.get(attr); ModelNode checkOp = op.clone(); checkOp.protect(); if (checkValue(checkOp, attr, value, false)) { AttributesPathAddressConfig<?> complexChildConfig = complexAttributes.get(attr); if (complexChildConfig == null) { ModelNode resolved = correctValue(op.get(attr), false); op.get(attr).set(resolved); } else { op.get(attr).set(complexChildConfig.correctOperation(operation.get(attr))); } return op; } } return operation; }
Example 5
Source File: DeploymentScannerParser_1_1.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * {@inheritDoc} */ @Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException { // no attributes requireNoAttributes(reader); final ModelNode address = new ModelNode(); address.add(ModelDescriptionConstants.SUBSYSTEM, DeploymentScannerExtension.SUBSYSTEM_NAME); address.protect(); final ModelNode subsystem = new ModelNode(); subsystem.get(OP).set(ADD); subsystem.get(OP_ADDR).set(address); list.add(subsystem); // elements while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { switch (Namespace.forUri(reader.getNamespaceURI())) { case DEPLOYMENT_SCANNER_1_0: case DEPLOYMENT_SCANNER_1_1: { final String element = reader.getLocalName(); switch (element) { case DEPLOYMENT_SCANNER: { //noinspection unchecked parseScanner(reader, address, list); break; } default: throw unexpectedElement(reader); } break; } default: throw unexpectedElement(reader); } } }
Example 6
Source File: LegacyTypeConverterUnitTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testPropertyValueTypeConverter() { ModelNode description = createDescription(ModelType.PROPERTY, ModelType.INT); TypeConverter converter = getConverter(description); ModelNode node = new ModelNode(); node.set("name", 1); node.protect(); Assert.assertEquals(SimpleType.STRING, converter.getOpenType()); String dmr = assertCast(String.class, converter.fromModelNode(node)); Assert.assertEquals(node, ModelNode.fromString(dmr)); Assert.assertEquals(dmr, assertCast(String.class, converter.fromModelNode(node))); assertToArray(converter, dmr); }
Example 7
Source File: LegacyTypeConverterUnitTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testPropertyTypeConverter() { ModelNode description = createDescription(ModelType.PROPERTY); TypeConverter converter = getConverter(description); ModelNode node = new ModelNode(); node.set("name", "value"); node.protect(); Assert.assertEquals(SimpleType.STRING, converter.getOpenType()); String dmr = assertCast(String.class, converter.fromModelNode(node)); Assert.assertEquals(node, ModelNode.fromString(dmr)); Assert.assertEquals(dmr, assertCast(String.class, converter.fromModelNode(node))); assertToArray(converter, dmr); }
Example 8
Source File: DeploymentScannerParser_2_0.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * {@inheritDoc} */ @Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException { // no attributes requireNoAttributes(reader); final ModelNode address = new ModelNode(); address.add(ModelDescriptionConstants.SUBSYSTEM, DeploymentScannerExtension.SUBSYSTEM_NAME); address.protect(); final ModelNode subsystem = new ModelNode(); subsystem.get(OP).set(ADD); subsystem.get(OP_ADDR).set(address); list.add(subsystem); // elements while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { switch (Namespace.forUri(reader.getNamespaceURI())) { case DEPLOYMENT_SCANNER_1_0: case DEPLOYMENT_SCANNER_1_1: case DEPLOYMENT_SCANNER_2_0: { final String element = reader.getLocalName(); switch (element) { case DEPLOYMENT_SCANNER: { //noinspection unchecked parseScanner(reader, address, list); break; } default: throw unexpectedElement(reader); } break; } default: throw unexpectedElement(reader); } } }
Example 9
Source File: ExpressionTypeConverterUnitTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testUndefinedTypeExpressionConverter() throws Exception { ModelNode description = new ModelNode(); description.get(EXPRESSIONS_ALLOWED).set(true); TypeConverter converter = getConverter(description); ModelNode node = new ModelNode(); node.get("abc").set(new ValueExpression("${this.should.not.exist.!!!!!:10}")); node.get("def").set(new ValueExpression("${this.should.not.exist.!!!!!:false}")); node.protect(); String json = assertCast(String.class, converter.fromModelNode(node)); Assert.assertEquals(node, ModelNode.fromJSONString(json)); assertToArray(converter, json, null); }
Example 10
Source File: FailedOperationTransformationConfig.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public ModelNode correctWriteAttributeOperation(ModelNode operation) { ModelNode op = operation.clone(); ModelNode checkOp = op.clone(); checkOp.protect(); String name = operation.get(NAME).asString(); if (attributes.contains(name) && checkValue(checkOp, name, op.get(VALUE), true)) { op.get(VALUE).set(correctValue(op.get(VALUE), true)); return op; } return operation; }
Example 11
Source File: ManagementAccessTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testCompositeDomainWriteAccess() throws IOException { ModelNode masterRequest = getEmptyOperation(COMPOSITE, null); ModelNode steps = masterRequest.get(STEPS); steps.add(SchemaLocationAddHandler.getAddSchemaLocationOperation(ROOT_ADDRESS, "uri", "location")); // Now try a resource below root final ModelNode addServerGroupRequest = Util.getEmptyOperation(ADD, TEST_SERVER_GROUP_ADDRESS); addServerGroupRequest.get(PROFILE).set("default"); addServerGroupRequest.get(SOCKET_BINDING_GROUP).set("standard-sockets"); steps.add(addServerGroupRequest); masterRequest.protect(); ModelNode response = masterClient.execute(masterRequest); System.out.println(response); validateResponse(response); response = masterClient.execute(getReadAttributeOperation(ROOT_ADDRESS, SCHEMA_LOCATIONS)); ModelNode returnVal = validateResponse(response); Assert.assertTrue(hasTestSchemaLocation(returnVal)); response = masterClient.execute(getReadAttributeOperation(TEST_SERVER_GROUP_ADDRESS, PROFILE)); returnVal = validateResponse(response); Assert.assertEquals("default", returnVal.asString()); // Slave can't write response = slaveClient.execute(masterRequest); validateFailedResponse(response); }
Example 12
Source File: DmrNodePath.java From hawkular-agent with Apache License 2.0 | 5 votes |
public ModelNode asModelNode() { ModelNode result = new ModelNode(); for (DmrNodePathSegment segment : segments) { result.add(segment.getType(), segment.getName()); } result.protect(); return result; }
Example 13
Source File: ManagementAccessTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testCompositeHostReadAccess() throws IOException { ModelNode masterRequest = getEmptyOperation(COMPOSITE, null); ModelNode steps = masterRequest.get(STEPS); steps.add(getReadAttributeOperation(MASTER_ROOT_ADDRESS, NAME)); steps.add(getReadAttributeOperation(MASTER_INTERFACE_ADDRESS, INET_ADDRESS)); masterRequest.protect(); ModelNode response = masterClient.execute(masterRequest); System.out.println(response); ModelNode returnVal = validateResponse(response); ModelNode name = validateResponse(returnVal.get("step-1")); Assert.assertEquals("master", name.asString()); ModelNode inetAddress = validateResponse(returnVal.get("step-2")); Assert.assertEquals(ModelType.EXPRESSION, inetAddress.getType()); ModelNode slaveRequest = getEmptyOperation(COMPOSITE, null); steps = slaveRequest.get(STEPS); steps.add(getReadAttributeOperation(SLAVE_ROOT_ADDRESS, NAME)); steps.add(getReadAttributeOperation(SLAVE_INTERFACE_ADDRESS, INET_ADDRESS)); masterRequest.protect(); response = slaveClient.execute(slaveRequest); System.out.println(response); ModelNode slaveReturnVal = validateResponse(response); name = validateResponse(slaveReturnVal.get("step-1")); Assert.assertEquals("slave", name.asString()); inetAddress = validateResponse(slaveReturnVal.get("step-2")); Assert.assertEquals(ModelType.EXPRESSION, inetAddress.getType()); // Check we get the same thing via the master response = masterClient.execute(slaveRequest); returnVal = validateResponse(response); Assert.assertEquals(returnVal, slaveReturnVal); // Can't access the master via the slave response = slaveClient.execute(masterRequest); validateFailedResponse(response); }
Example 14
Source File: DeploymentResult.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates an unsuccessful result with the failure description. * * @param failureMessage the failure description */ DeploymentResult(final CharSequence failureMessage) { successful = false; this.failureMessage = failureMessage.toString(); result = new ModelNode(); result.protect(); }
Example 15
Source File: BpmPlatformParser1_1.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations) throws XMLStreamException { // Require no attributes ParseUtils.requireNoAttributes(reader); final ModelNode subsystemAddress = new ModelNode(); subsystemAddress.add(SUBSYSTEM, ModelConstants.SUBSYSTEM_NAME); subsystemAddress.protect(); final ModelNode subsystemAdd = new ModelNode(); subsystemAdd.get(OP).set(ADD); subsystemAdd.get(OP_ADDR).set(subsystemAddress); operations.add(subsystemAdd); while(reader.hasNext() && !reader.isEndElement()) { switch (reader.getLocalName()) { case SUBSYSTEM: { try { final BpmPlatformParser1_1 parser = new BpmPlatformParser1_1(); parser.parse(reader, operations, subsystemAddress); } catch (Exception e) { throw new XMLStreamException(e); } } } } }
Example 16
Source File: DeploymentScannerParser_1_0.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** {@inheritDoc} */ @Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException { // no attributes requireNoAttributes(reader); final ModelNode address = new ModelNode(); address.add(ModelDescriptionConstants.SUBSYSTEM, DeploymentScannerExtension.SUBSYSTEM_NAME); address.protect(); final ModelNode subsystem = new ModelNode(); subsystem.get(OP).set(ADD); subsystem.get(OP_ADDR).set(address); list.add(subsystem); // elements while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { switch (Namespace.forUri(reader.getNamespaceURI())) { case DEPLOYMENT_SCANNER_1_0: { final String element = reader.getLocalName(); switch (element) { case CommonAttributes.DEPLOYMENT_SCANNER: { //noinspection unchecked parseScanner(reader, address, list); break; } default: throw unexpectedElement(reader); } break; } default: throw unexpectedElement(reader); } } }
Example 17
Source File: BasicOperationsUnitTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testSocketBindingDescriptions() throws IOException { final ModelNode address = new ModelNode(); address.add("socket-binding-group", "*"); address.add("socket-binding", "*"); address.protect(); final ModelNode operation = new ModelNode(); operation.get(OP).set(READ_RESOURCE_DESCRIPTION_OPERATION); operation.get(OP_ADDR).set(address); final ModelNode result = managementClient.getControllerClient().execute(operation); assertTrue(result.hasDefined(RESULT)); assertEquals(SUCCESS, result.get(OUTCOME).asString()); final Collection<ModelNode> steps = result.get(RESULT).asList(); assertFalse(steps.isEmpty()); assertEquals("should only contain a single type", 1, steps.size()); for(final ModelNode step : steps) { assertTrue(step.hasDefined(OP_ADDR)); assertTrue(step.hasDefined(RESULT)); assertEquals(SUCCESS, step.get(OUTCOME).asString()); final ModelNode stepResult = step.get(RESULT); assertTrue(stepResult.hasDefined(DESCRIPTION)); assertTrue(stepResult.hasDefined(ATTRIBUTES)); assertTrue(stepResult.get(ModelDescriptionConstants.ATTRIBUTES).hasDefined(ModelDescriptionConstants.NAME)); assertTrue(stepResult.get(ModelDescriptionConstants.ATTRIBUTES).hasDefined(ModelDescriptionConstants.INTERFACE)); assertTrue(stepResult.get(ModelDescriptionConstants.ATTRIBUTES).hasDefined(ModelDescriptionConstants.PORT)); } }
Example 18
Source File: BpmPlatformParser.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException { // Require no attributes ParseUtils.requireNoAttributes(reader); //Add the main subsystem 'add' operation final ModelNode subsystemAddress = new ModelNode(); subsystemAddress.add(SUBSYSTEM, ModelConstants.SUBSYSTEM_NAME); subsystemAddress.protect(); final ModelNode subsystemAdd = new ModelNode(); subsystemAdd.get(OP).set(ADD); subsystemAdd.get(OP_ADDR).set(subsystemAddress); list.add(subsystemAdd); while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); switch (element) { case PROCESS_ENGINES: { parseProcessEngines(reader, list, subsystemAddress); break; } case JOB_EXECUTOR: { parseJobExecutor(reader, list, subsystemAddress); break; } default: { throw unexpectedElement(reader); } } } }
Example 19
Source File: DeploymentResult.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 4 votes |
private DeploymentResult() { successful = true; failureMessage = null; result = new ModelNode(); result.protect(); }
Example 20
Source File: ThreadsParser.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public String parseThreadFactory(final XMLExtendedStreamReader reader, final String expectedNs, Namespace threadsNamespace, final ModelNode parentAddress, final List<ModelNode> list, final String childType, final String providedName) throws XMLStreamException { final ModelNode op = new ModelNode(); list.add(op); op.get(OP).set(ADD); String name = null; int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: { name = value; break; } case GROUP_NAME: { PoolAttributeDefinitions.GROUP_NAME.parseAndSetParameter(value, op, reader); break; } case THREAD_NAME_PATTERN: { PoolAttributeDefinitions.THREAD_NAME_PATTERN.parseAndSetParameter(value, op, reader); break; } case PRIORITY: { PoolAttributeDefinitions.PRIORITY.parseAndSetParameter(value, op, reader); break; } default: throw unexpectedAttribute(reader, i); } } if (providedName != null) { name = providedName; } else if (name == null) { throw missingRequired(reader, Collections.singleton(Attribute.NAME)); } final ModelNode address = parentAddress.clone(); address.add(childType, name); address.protect(); op.get(OP_ADDR).set(address); while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { Element element = nextElement(reader, expectedNs); switch (element) { case PROPERTIES: { parseProperties(reader, threadsNamespace); break; } default: { throw unexpectedElement(reader); } } } return name; }