Java Code Examples for org.jboss.dmr.ModelNode#asProperty()
The following examples show how to use
org.jboss.dmr.ModelNode#asProperty() .
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: CommonXml.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
protected void writeSchemaLocation(final XMLExtendedStreamWriter writer, final ModelNode modelNode) throws XMLStreamException { if (!modelNode.hasDefined(SCHEMA_LOCATIONS)) { return; } final StringBuilder b = new StringBuilder(); final Iterator<ModelNode> iterator = modelNode.get(SCHEMA_LOCATIONS).asList().iterator(); while (iterator.hasNext()) { final ModelNode location = iterator.next(); final Property property = location.asProperty(); b.append(property.getName()).append(' ').append(property.getValue().asString()); if (iterator.hasNext()) { b.append(' '); } } if (b.length() > 0) { writer.writeAttribute(Namespace.XML_SCHEMA_INSTANCE.getUriString(), Attribute.SCHEMA_LOCATION.getLocalName(), b.toString()); } }
Example 2
Source File: NewExtension.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException { ModelNode properties = operation.remove("properties"); ModelNode composite = Util.createEmptyOperation("composite", PathAddress.EMPTY_ADDRESS); ModelNode steps = composite.get("steps"); steps.add(operation); for (ModelNode property : properties.asList()) { Property prop = property.asProperty(); ModelNode addProp = Util.createAddOperation(address.append("property", prop.getName())); addProp.get("value").set(prop.getValue()); steps.add(addProp); } return new TransformedOperation(composite, TransformedOperation.ORIGINAL_RESULT); }
Example 3
Source File: AbstractDiscoveryOptionRemoveHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
protected void updateOptionsAttribute(OperationContext context, ModelNode operation, String type) { final PathAddress operationAddress = PathAddress.pathAddress(operation.get(OP_ADDR)); final PathAddress discoveryOptionsAddress = operationAddress.subAddress(0, operationAddress.size() - 1); final ModelNode discoveryOptions = Resource.Tools.readModel(context.readResourceFromRoot(discoveryOptionsAddress)); // Get the current list of discovery options and remove the given discovery option // from the list to maintain the order final ModelNode currentList = discoveryOptions.get(ModelDescriptionConstants.OPTIONS); final String name = operationAddress.getLastElement().getValue(); final ModelNode newList = new ModelNode().setEmptyList(); for (ModelNode e : currentList.asList()) { final Property prop = e.asProperty(); final String discoveryOptionType = prop.getName(); final String discoveryOptionName = prop.getValue().get(ModelDescriptionConstants.NAME).asString(); if (!(discoveryOptionType.equals(type) && discoveryOptionName.equals(name))) { newList.add(e); } } final ModelNode writeOp = Util.getWriteAttributeOperation(discoveryOptionsAddress, ModelDescriptionConstants.OPTIONS, newList); final OperationStepHandler writeHandler = context.getRootResourceRegistration().getSubModel(discoveryOptionsAddress).getOperationHandler(PathAddress.EMPTY_ADDRESS, WRITE_ATTRIBUTE_OPERATION); context.addStep(writeOp, writeHandler, OperationContext.Stage.MODEL); }
Example 4
Source File: ModelTestUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static ModelNode trimUndefinedChildren(ModelNode model) { ModelNode copy = model.clone(); for (String key : new HashSet<String>(copy.keys())) { if (!copy.hasDefined(key)) { copy.remove(key); } else if (copy.get(key).getType() == ModelType.OBJECT) { for (ModelNode mn : model.get(key).asList()) { boolean undefined = true; Property p = mn.asProperty(); if (p.getValue().getType() != ModelType.OBJECT) { continue; } for (String subKey : new HashSet<String>(p.getValue().keys())) { if (copy.get(key, p.getName()).hasDefined(subKey)) { undefined = false; break; } else { copy.get(key, p.getName()).remove(subKey); } } if (undefined) { copy.get(key).remove(p.getName()); if (!copy.hasDefined(key)) { copy.remove(key); } else if (copy.get(key).getType() == ModelType.OBJECT) { //this is stupid workaround if (copy.get(key).keys().size() == 0) { copy.remove(key); } } } } } } return copy; }
Example 5
Source File: DMRDriver.java From hawkular-agent with Apache License 2.0 | 5 votes |
private static Object toObject(ModelNode value) throws ProtocolException { switch (value.getType()) { case BIG_DECIMAL: return value.asBigDecimal(); case BIG_INTEGER: return value.asBigInteger(); case BOOLEAN: return value.asBoolean(); case BYTES: return value.asBytes(); case DOUBLE: return value.asDouble(); case INT: return value.asInt(); case LONG: return value.asLong(); case OBJECT: return value.asObject(); case PROPERTY: return value.asProperty(); case STRING: return value.asString(); case UNDEFINED: return null; case LIST: return toObjectList(value.asList()); default: throw new ProtocolException("cannot handle an attribute of type [" + value.getType() + "]"); } }
Example 6
Source File: NewExtension.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException { ModelNode properties = resource.getModel().remove("properties"); ResourceTransformationContext childCtx = context.addTransformedResourceFromRoot(address, resource); for (ModelNode property : properties.asList()) { Property prop = property.asProperty(); Resource child = Resource.Factory.create(); child.getModel().get("value").set(prop.getValue()); childCtx.addTransformedResource(PathAddress.pathAddress("property", prop.getName()), child); } }
Example 7
Source File: BatchRunHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static String formatBatchError(CommandContext ctx, ModelNode responseNode) { if (responseNode == null) { return null; } ModelNode mn = responseNode.get(Util.RESULT); String msg = null; try { if (mn.isDefined()) { int index = 0; Batch batch = ctx.getBatchManager().getActiveBatch(); StringBuilder b = new StringBuilder(); ModelNode fd = responseNode.get(Util.FAILURE_DESCRIPTION); if (fd.isDefined()) { Property p = fd.asProperty(); b.append(Config.getLineSeparator()). append(p.getName()).append(Config.getLineSeparator()); boolean foundError = false; for (Property prop : mn.asPropertyList()) { ModelNode val = prop.getValue(); if (val.hasDefined(Util.FAILURE_DESCRIPTION)) { b.append("Step: step-").append(index + 1). append(Config.getLineSeparator()); b.append("Operation: ").append(batch.getCommands(). get(index).getCommand()).append(Config.getLineSeparator()); b.append("Failure: ").append(val.get(Util.FAILURE_DESCRIPTION).asString()). append(Config.getLineSeparator()); foundError = true; } index += 1; } if (foundError) { msg = b.toString(); } } } } catch (Exception ex) { // XXX OK, will fallback to null msg. } return msg; }
Example 8
Source File: ModelNodeFormatter.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override void formatDefined(StringBuilder buf, int newLineOffset, ModelNode value) { final Property prop = value.asProperty(); buf.append(prop.getName()); final ModelNode propValue = prop.getValue(); final ModelNodeFormatterBase formatter = Factory.forType(propValue.getType()); if(formatter == LIST) { buf.append('\n'); formatter.format(buf, newLineOffset + OFFSET, propValue); } else { buf.append('='); formatter.format(buf, newLineOffset, propValue); } }
Example 9
Source File: AttributeMarshallers.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void marshallSingleElement(AttributeDefinition attribute, ModelNode property, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { ObjectMapAttributeDefinition map = ((ObjectMapAttributeDefinition) attribute); AttributeDefinition[] valueTypes = map.getValueType().getValueTypes(); writer.writeEmptyElement(elementName); Property p = property.asProperty(); writer.writeAttribute(keyAttributeName, p.getName()); for (AttributeDefinition valueType : valueTypes) { valueType.getMarshaller().marshall(valueType, p.getValue(), false, writer); } }
Example 10
Source File: ManagedServerOperationsFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void addKerberosServerIdentity(ModelNode serverIdentity, ModelNode realmAddress, List<ModelNode> updates) { ModelNode kerberos = serverIdentity.require(KERBEROS); ModelNode addKerberos = new ModelNode(); ModelNode kerberosAddr = realmAddress.clone().add(SERVER_IDENTITY, KERBEROS); addAddNameAndAddress(addKerberos, kerberosAddr); updates.add(addKerberos); if (kerberos.hasDefined(KEYTAB)) { ModelNode keytab = kerberos.require(KEYTAB); ModelNode addKeytab = new ModelNode(); Property keytabProp = keytab.asProperty(); convertAttributesToParams(keytabProp.getValue(), addKeytab); addAddNameAndAddress(addKeytab, kerberosAddr.clone().add(KEYTAB, keytabProp.getName())); updates.add(addKeytab); } }
Example 11
Source File: StaticDiscoveryWriteAttributeHandler.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 { super.finishModelStage(context, operation, attributeName, newValue, oldValue, model); final PathAddress operationAddress = context.getCurrentAddress(); final PathAddress discoveryOptionsAddress = operationAddress.getParent(); final ModelNode discoveryOptions = context.readResourceFromRoot(discoveryOptionsAddress, false).getModel(); // Get the current list of discovery options and set new value for attribute final ModelNode currentListClone = discoveryOptions.get(ModelDescriptionConstants.OPTIONS).clone(); final String name = context.getCurrentAddressValue(); for (ModelNode element : currentListClone.asList()) { final Property prop = element.asProperty(); final String discoveryOptionType = prop.getName(); final String discoveryOptionName = prop.getValue().get(ModelDescriptionConstants.NAME).asString(); if ( discoveryOptionName.equals(name) && discoveryOptionType.equals(ModelDescriptionConstants.STATIC_DISCOVERY)) { final ModelNode node = element.get(ModelDescriptionConstants.STATIC_DISCOVERY); node.get(attributeName).set(newValue); break; } } final ModelNode writeOp = Util.getWriteAttributeOperation(discoveryOptionsAddress, ModelDescriptionConstants.OPTIONS, currentListClone); final OperationStepHandler writeHandler = context.getRootResourceRegistration().getSubModel(discoveryOptionsAddress).getOperationHandler(PathAddress.EMPTY_ADDRESS, WRITE_ATTRIBUTE_OPERATION); context.addStep(writeOp, writeHandler, OperationContext.Stage.MODEL, true); }
Example 12
Source File: TypeConverters.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Object fromModelNode(ModelNode node) { Property prop = node.asProperty(); Map<String, Object> items = new HashMap<String, Object>(); items.put("name", prop.getName()); items.put("value", getConverter().fromModelNode(prop.getValue())); try { return new CompositeDataSupport(getOpenType(), items); } catch (OpenDataException e) { throw new IllegalStateException(e); } }
Example 13
Source File: DeploymentOverlayScenario.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private String getServerProperty(DomainClient slaveClient, String propName) throws Exception { PathAddress addr = SLAVE_ADDR.append(SERVER, "server-affected") .append(CORE_SERVICE, PLATFORM_MBEAN).append(TYPE, "runtime"); ModelNode op = Util.getReadAttributeOperation(addr, SYSTEM_PROPERTIES); ModelNode props = DomainTestUtils.executeForResult(op, slaveClient); for (ModelNode prop : props.asList()) { Property property = prop.asProperty(); if (property.getName().equals(propName)) { return property.getValue().asString(); } } return null; }
Example 14
Source File: ModelParserUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void compare(ModelNode node1, ModelNode node2) { Assert.assertEquals(node1.getType(), node2.getType()); if (node1.getType() == ModelType.OBJECT) { final Set<String> keys1 = node1.keys(); final Set<String> keys2 = node2.keys(); Assert.assertEquals(node1 + "\n" + node2, keys1.size(), keys2.size()); for (String key : keys1) { final ModelNode child1 = node1.get(key); Assert.assertTrue("Missing: " + key + "\n" + node1 + "\n" + node2, node2.has(key)); final ModelNode child2 = node2.get(key); if (child1.isDefined()) { Assert.assertTrue(child1.toString(), child2.isDefined()); compare(child1, child2); } else { Assert.assertFalse(child2.asString(), child2.isDefined()); } } } else if (node1.getType() == ModelType.LIST) { List<ModelNode> list1 = node1.asList(); List<ModelNode> list2 = node2.asList(); Assert.assertEquals(list1 + "\n" + list2, list1.size(), list2.size()); for (int i = 0; i < list1.size(); i++) { compare(list1.get(i), list2.get(i)); } } else if (node1.getType() == ModelType.PROPERTY) { Property prop1 = node1.asProperty(); Property prop2 = node2.asProperty(); Assert.assertEquals(prop1 + "\n" + prop2, prop1.getName(), prop2.getName()); compare(prop1.getValue(), prop2.getValue()); } else { Assert.assertEquals("\n\"" + node1.asString() + "\"\n\"" + node2.asString() + "\"\n-----", node1.asString().trim(), node2.asString().trim()); } }
Example 15
Source File: CLIOpResult.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
protected Object toObject(ModelNode node) { final ModelType type = node.getType(); if(type.equals(ModelType.LIST)) { return toList(node); } else if(type.equals(ModelType.OBJECT)) { return toMap(node); } else if(type.equals(ModelType.PROPERTY)) { final Property prop = node.asProperty(); return Collections.singletonMap(prop.getName(), toObject(prop.getValue())); } else { return node.asString(); } }
Example 16
Source File: JmxManagementInterface.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static Object object(ModelNode node) { switch (node.getType()) { case BIG_DECIMAL: return node.asBigDecimal(); case BIG_INTEGER: return node.asBigInteger(); case BOOLEAN: return node.asBoolean(); case BYTES: return node.asBytes(); case DOUBLE: return node.asDouble(); case EXPRESSION: return node.asExpression(); case INT: return node.asInt(); case LIST: return node.asList(); case LONG: return node.asLong(); case PROPERTY: return node.asProperty(); case STRING: return node.asString(); case UNDEFINED: return null; default: throw new UnsupportedOperationException("Can't convert '" + node.getType() + "' to object"); } }
Example 17
Source File: TlsParser.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void marshallSingleElement(AttributeDefinition attribute, ModelNode mapping, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement(SNI_MAPPING); Property mappingProperty = mapping.asProperty(); writer.writeAttribute(HOST, mappingProperty.getName()); writer.writeAttribute(SSL_CONTEXT, mappingProperty.getValue().asString()); }
Example 18
Source File: OperationValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void checkType(final ModelType modelType, final ModelNode value) { ModelNode resolved; try { resolved = expressionResolver.resolveExpressions(value); } catch (OperationFailedException e) { // Dealing with an unresolvable expression is beyond what this class can do. // So fall through and see what happens. Basically if modelType is EXPRESSION or STRING // it will pass, otherwise an IAE will be thrown resolved = value; } switch (modelType) { case BIG_DECIMAL: resolved.asBigDecimal(); break; case BIG_INTEGER: resolved.asBigInteger(); break; case BOOLEAN: resolved.asBoolean(); break; case BYTES: resolved.asBytes(); break; case DOUBLE: resolved.asDouble(); break; case EXPRESSION: value.asString(); break; case INT: resolved.asInt(); break; case LIST: value.asList(); break; case LONG: resolved.asLong(); break; case OBJECT: value.asObject(); break; case PROPERTY: value.asProperty(); break; case STRING: value.asString(); break; case TYPE: resolved.asType(); break; } }
Example 19
Source File: ModelTestUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private static void compare(ModelNode node1, ModelNode node2, boolean ignoreUndefined, boolean ignoreType, Stack<String> stack) { if (! ignoreType) { Assert.assertEquals(getCompareStackAsString(stack) + " types", node1.getType(), node2.getType()); } if (node1.getType() == ModelType.OBJECT) { ModelNode model1 = ignoreUndefined ? trimUndefinedChildren(node1) : node1; ModelNode model2 = ignoreUndefined ? trimUndefinedChildren(node2) : node2; final Set<String> keys1 = new TreeSet<String>(model1.keys()); final Set<String> keys2 = new TreeSet<String>(model2.keys()); // compare string representations of the keys to help see the difference if (!keys1.toString().equals(keys2.toString())){ //Just to make debugging easier System.out.print(""); } Assert.assertEquals(getCompareStackAsString(stack) + ": " + node1 + "\n" + node2, keys1.toString(), keys2.toString()); Assert.assertTrue(keys1.containsAll(keys2)); for (String key : keys1) { final ModelNode child1 = model1.get(key); Assert.assertTrue("Missing: " + key + "\n" + node1 + "\n" + node2, model2.has(key)); final ModelNode child2 = model2.get(key); if (child1.isDefined()) { if (!ignoreUndefined) { Assert.assertTrue(getCompareStackAsString(stack) + " key=" + key + "\n with child1 \n" + child1.toString() + "\n has child2 not defined\n node2 is:\n" + node2.toString(), child2.isDefined()); } stack.push(key + "/"); compare(child1, child2, ignoreUndefined, ignoreType, stack); stack.pop(); } else if (!ignoreUndefined) { Assert.assertFalse(getCompareStackAsString(stack) + " key=" + key + "\n with child1 undefined has child2 \n" + child2.asString(), child2.isDefined()); } } } else if (node1.getType() == ModelType.LIST) { List<ModelNode> list1 = node1.asList(); List<ModelNode> list2 = node2.asList(); Assert.assertEquals(list1 + "\n" + list2, list1.size(), list2.size()); for (int i = 0; i < list1.size(); i++) { stack.push(i + "/"); compare(list1.get(i), list2.get(i), ignoreUndefined, ignoreType, stack); stack.pop(); } } else if (node1.getType() == ModelType.PROPERTY) { Property prop1 = node1.asProperty(); Property prop2 = node2.asProperty(); Assert.assertEquals(prop1 + "\n" + prop2, prop1.getName(), prop2.getName()); stack.push(prop1.getName() + "/"); compare(prop1.getValue(), prop2.getValue(), ignoreUndefined, ignoreType, stack); stack.pop(); } else { Assert.assertEquals(getCompareStackAsString(stack) + "\n\"" + node1.asString() + "\"\n\"" + node2.asString() + "\"\n-----", node1.asString().trim(), node2.asString().trim()); } }
Example 20
Source File: UpdateDatasourceCommand.java From hawkular-agent with Apache License 2.0 | 4 votes |
private void syncProps(ModelControllerClient client, ModelNode parentAddress, String propType, Map<String, String> newProps, CompositeOperationBuilder<?> batch, boolean isXaDatasource) { List<ModelNode> availableProps = OperationBuilder.readChildrenResources().address(parentAddress) .childType(propType).execute(client).assertSuccess().getNodeList(); if (newProps == null) { newProps = Collections.emptyMap(); } Set<String> updatedPropNames = new HashSet<>(); /* We must remove the keys and then re-create them, see https://issues.jboss.org/browse/AS7-6302 */ for (ModelNode avialNode : availableProps) { Property prop = avialNode.asProperty(); String availPropName = prop.getName(); String availPropValue = prop.getValue().get(ModelDescriptionConstants.VALUE).asString(); String newVal = newProps.get(availPropName); if (newVal == null) { /* no new val -> remove */ // if (isXaDatasource) { // /* broken for XA */ // throw new IllegalStateException("Cannot remove [" + propType + "=" + availPropName + "]"); // } else { batch.remove() // .address().segments(parentAddress).segment(propType, availPropName).parentBuilder() // .parentBuilder(); // } } else if (!newVal.equals(availPropValue)) { log.tracef("Modification of [%s=%s]: ![%s].equals([%s])", propType, availPropName, newVal, availPropValue); /* a modification: remove old and add the new value */ // if (isXaDatasource) { // /* broken for XA */ // throw new IllegalStateException("Cannot modify [" + propType + "=" + availPropName + "]"); // } else { batch.remove() // .address().segments(parentAddress).segment(propType, availPropName).parentBuilder() // .parentBuilder(); batch.add() // .address().segments(parentAddress).segment(propType, availPropName).parentBuilder() // .valueAttribute(newVal).parentBuilder(); // } updatedPropNames.add(availPropName); } else { /* no change */ log.tracef("No change for [%s=%s]: [%s].equals([%s])", propType, availPropName, newVal, availPropValue); updatedPropNames.add(availPropName); } } for (Entry<String, String> newProp : newProps.entrySet()) { String newPropName = newProp.getKey(); if (!updatedPropNames.contains(newPropName)) { /* add key not available yet */ batch.add() // .address().segments(parentAddress).segment(propType, newPropName).parentBuilder() // .valueAttribute(newProp.getValue()).parentBuilder(); } } }