Java Code Examples for org.jboss.dmr.ModelNode#keys()
The following examples show how to use
org.jboss.dmr.ModelNode#keys() .
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: AbstractJvmModelTest.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
protected KernelServices doEmptyJvmAdd() throws Exception { List<ModelNode> bootOps = new ArrayList<ModelNode>(); bootOps.add(createOperation(ADD)); KernelServices kernelServices = createKernelServicesBuilder(type) .setBootOperations(bootOps) .setModelInitializer(getModelInitializer(), null) .build(); Assert.assertTrue(kernelServices.isSuccessfulBoot()); ModelNode resource = getJvmResource(kernelServices); Assert.assertTrue(resource.keys().size() > 0); for (String key : resource.keys()) { Assert.assertFalse(resource.hasDefined(key)); } return kernelServices; }
Example 2
Source File: ManagedServerOperationsFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void addManagementConnections(List<ModelNode> updates) { if (hostModel.get(CORE_SERVICE, MANAGEMENT, LDAP_CONNECTION).isDefined()) { ModelNode baseAddress = new ModelNode(); baseAddress.add(CORE_SERVICE, MANAGEMENT); ModelNode connections = hostModel.get(CORE_SERVICE, MANAGEMENT, LDAP_CONNECTION); for (String connectionName : connections.keys()) { ModelNode addConnection = new ModelNode(); // First take the properties to pass over. addConnection.set(connections.get(connectionName)); // Now convert it to an operation by adding a name and address. ModelNode identityAddress = baseAddress.clone().add(LDAP_CONNECTION, connectionName); addAddNameAndAddress(addConnection, identityAddress); updates.add(addConnection); } } }
Example 3
Source File: ElytronUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public static String findKeyStoreRealm(CommandContext ctx, String trustStore) throws IOException, OperationFormatException { DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(); String name = null; builder.setOperationName(Util.READ_CHILDREN_RESOURCES); builder.addNode(Util.SUBSYSTEM, Util.ELYTRON); builder.addProperty(Util.CHILD_TYPE, Util.KEY_STORE_REALM); ModelNode response = ctx.getModelControllerClient().execute(builder.buildRequest()); if (Util.isSuccess(response)) { if (response.hasDefined(Util.RESULT)) { ModelNode mn = response.get(Util.RESULT); for (String key : mn.keys()) { ModelNode ksr = mn.get(key); if (ksr.hasDefined(Util.KEY_STORE)) { String ks = ksr.get(Util.KEY_STORE).asString(); if (ks.equals(trustStore)) { name = key; break; } } } } } return name; }
Example 4
Source File: SimpleMapAttributeDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void handleCapabilityRequirements(OperationContext context, Resource resource, ModelNode attributeValue, boolean remove) { CapabilityReferenceRecorder refRecorder = getReferenceRecorder(); if (refRecorder != null && attributeValue.isDefined()) { Set<String> KeyList = attributeValue.keys(); String[] attributeValues = new String[KeyList.size()]; int position = 0; for (String key : KeyList) { ModelNode current = attributeValue.get(key); if (current.isDefined() == false || current.getType().equals(ModelType.EXPRESSION)) { return; } attributeValues[position++] = current.asString(); } if (remove) { refRecorder.removeCapabilityRequirements(context, resource, getName(), attributeValues); } else { refRecorder.addCapabilityRequirements(context, resource, getName(), attributeValues); } } }
Example 5
Source File: ReadConfigAsFeaturesTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
protected boolean compareObjects(ModelNode model1, ModelNode model2) { Assert.assertEquals(getProgrammingErrorMessage("OBJECT"), model1.getType(), model2.getType()); Assert.assertEquals(getProgrammingErrorMessage("OBJECT"), OBJECT, model1.getType()); if (!model1.keys().equals(model2.keys())) { return false; } for (String key : model1.keys()) { switch (model1.get(key).getType()) { case OBJECT: if (!compareObjects(model1.get(key), model2.get(key))) return false; break; case LIST: if (!compareLists(model1.get(key), model2.get(key))) return false; break; default: if (!model1.get(key).equals(model2.get(key))) return false; } } return true; }
Example 6
Source File: ObjectMapAttributeDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public ModelNode correct(ModelNode newValue, ModelNode currentValue) { ModelNode result = newValue; if (newValue.isDefined()) { for (String key : newValue.keys()) { ModelNode toCorrect = newValue.get(key); ModelNode corrected = valueCorrector.correct(toCorrect, currentValue.has(key) ? currentValue.get(key) : new ModelNode()); if (!corrected.equals(toCorrect)) { toCorrect.set(corrected); } } } if (listCorrector != null) { result = listCorrector.correct(result, currentValue); } return result; }
Example 7
Source File: CLIOpResult.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
protected Map<String, Object> toMap(ModelNode node) { final Set<String> keys = node.keys(); Map<String,Object> map = new HashMap<String,Object>(keys.size()); for(String key : keys) { map.put(key, toObject(node.get(key))); } return map; }
Example 8
Source File: OperationValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private Map<String, ModelNode> getActualRequestProperties(final ModelNode operation) { final Map<String, ModelNode> requestProperties = new HashMap<String, ModelNode>(); for (String key : operation.keys()) { if (key.equals(OP) || key.equals(OP_ADDR) || key.equals(OPERATION_HEADERS)) { continue; } requestProperties.put(key, operation.get(key)); } return requestProperties; }
Example 9
Source File: ElytronUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static ModelNode addKeyManager(CommandContext ctx, KeyStore keyStore, String name, String alias, String algorithm) throws Exception { DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(); builder.setOperationName(Util.ADD); builder.addNode(Util.SUBSYSTEM, Util.ELYTRON); builder.addNode(Util.KEY_MANAGER, name); ModelNode mn = buildKeyManagerResource(keyStore, alias, algorithm); for (String k : mn.keys()) { builder.getModelNode().get(k).set(mn.get(k)); } builder.getModelNode().get(Util.CREDENTIAL_REFERENCE).set(buildCredentialReferences(keyStore.getPassword())); return builder.buildRequest(); }
Example 10
Source File: ElytronUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static ModelNode addSecurityDomain(CommandContext ctx, Realm realm, String newSecurityDomain) throws OperationFormatException { DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(); builder.setOperationName(Util.ADD); builder.addNode(Util.SUBSYSTEM, Util.ELYTRON); builder.addNode(Util.SECURITY_DOMAIN, newSecurityDomain); ModelNode mn = buildSecurityDomainResource(realm); for (String k : mn.keys()) { builder.getModelNode().get(k).set(mn.get(k)); } return builder.buildRequest(); }
Example 11
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 12
Source File: StandaloneXml_14.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void writeServerDeployments(final XMLExtendedStreamWriter writer, final ModelNode modelNode) throws XMLStreamException { boolean deploymentWritten = false; for (String deploymentName : modelNode.keys()) { final ModelNode deployment = modelNode.get(deploymentName); if (!deployment.isDefined()) { continue; } if (!deploymentWritten) { writer.writeStartElement(Element.DEPLOYMENTS.getLocalName()); deploymentWritten = true; } writer.writeStartElement(Element.DEPLOYMENT.getLocalName()); WriteUtils.writeAttribute(writer, Attribute.NAME, deploymentName); DeploymentAttributes.RUNTIME_NAME.marshallAsAttribute(deployment, writer); DeploymentAttributes.ENABLED.marshallAsAttribute(deployment, writer); final List<ModelNode> contentItems = deployment.require(CONTENT).asList(); for (ModelNode contentItem : contentItems) { writeContentItem(writer, contentItem); } writer.writeEndElement(); } if (deploymentWritten) { writer.writeEndElement(); } }
Example 13
Source File: ManagementXml_5.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void writePlugIn_Authorization(XMLExtendedStreamWriter writer, ModelNode plugIn) throws XMLStreamException { writer.writeStartElement(Element.PLUG_IN.getLocalName()); AbstractPlugInAuthResourceDefinition.NAME.marshallAsAttribute(plugIn, writer); if (plugIn.hasDefined(PROPERTY)) { writer.writeStartElement(PROPERTIES); ModelNode properties = plugIn.get(PROPERTY); for (String current : properties.keys()) { writer.writeEmptyElement(PROPERTY); writer.writeAttribute(Attribute.NAME.getLocalName(), current); PropertyResourceDefinition.VALUE.marshallAsAttribute(properties.get(current), writer); } writer.writeEndElement(); } writer.writeEndElement(); }
Example 14
Source File: OperationParsingTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testDMREqualsAsParamEquals() throws Exception { DefaultCallbackHandler handler = new DefaultCallbackHandler(); parse(":add(keystore=>{password=1234test,url=/Users/xxx/clientcert.jks})", handler); assertFalse(handler.hasAddress()); assertTrue(handler.hasOperationName()); assertTrue(handler.hasProperties()); assertFalse(handler.endsOnAddressOperationNameSeparator()); assertFalse(handler.endsOnPropertyListStart()); assertFalse(handler.endsOnPropertySeparator()); assertFalse(handler.endsOnPropertyValueSeparator()); assertFalse(handler.endsOnNodeSeparator()); assertFalse(handler.endsOnNodeTypeNameSeparator()); assertFalse(handler.isRequestComplete()); assertEquals("add", handler.getOperationName()); Set<String> args = handler.getPropertyNames(); assertEquals(1, args.size()); assertTrue(args.contains("keystore")); assertEquals(">{password=1234test,url=/Users/xxx/clientcert.jks}", handler.getPropertyValue("keystore")); final ModelNode request = handler.toOperationRequest(new MockCommandContext()); final ModelNode keystoreDmr = request.get("keystore"); assertTrue(keystoreDmr.isDefined()); assertEquals(ModelType.OBJECT, keystoreDmr.getType()); final Set<String> props = keystoreDmr.keys(); assertEquals(2, props.size()); // this name is not alphanumeric but it's still a value of the CLI operation parameter // and the CLI at the moment does not attempt to validate values assertTrue(props.contains(">{password")); assertTrue(props.contains("url")); assertEquals("1234test", keystoreDmr.get(">{password").asString()); assertEquals("/Users/xxx/clientcert.jks}", keystoreDmr.get("url").asString()); }
Example 15
Source File: AbstractJvmModelTest.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
protected void checkEmptyJvm(ModelNode empty) { Assert.assertTrue(empty.isDefined()); Assert.assertTrue(empty.isDefined()); Assert.assertTrue(empty.keys().size() > 1); for (String key : empty.keys()) { Assert.assertFalse(empty.get(key).isDefined()); } }
Example 16
Source File: ModelTestModelDescriptionValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void validateAttributes(ModelNode attributes) { for (String key : attributes.keys()) { ModelNode attribute = attributes.get(key); AttributeValidationElement attributeValidationElement = new AttributeValidationElement(key); validateAttributeOrParameter(attributeValidationElement, attribute); } }
Example 17
Source File: RealmMapperDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { ServiceTarget serviceTarget = context.getServiceTarget(); RuntimeCapability<Void> runtimeCapability = REALM_MAPPER_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue()); ServiceName realmMapperName = runtimeCapability.getCapabilityServiceName(RealmMapper.class); final String pattern = PATTERN_CAPTURE_GROUP.resolveModelAttribute(context, model).asString(); ModelNode realmMapList = REALM_REALM_MAP.resolveModelAttribute(context, model); Set<String> names = realmMapList.keys(); final Map<String, String> realmRealmMap = new HashMap<String, String>(names.size()); for (String s : names) { realmRealmMap.put(s, realmMapList.require(s).asString()); } String delegateRealmMapper = DELEGATE_REALM_MAPPER.resolveModelAttribute(context, model).asStringOrNull(); final InjectedValue<RealmMapper> delegateRealmMapperInjector = new InjectedValue<RealmMapper>(); TrivialService<RealmMapper> realmMapperService = new TrivialService<RealmMapper>(() -> { RealmMapper delegate = delegateRealmMapperInjector.getOptionalValue(); Pattern compiledPattern = Pattern.compile(pattern); if (delegate == null) { return new MappedRegexRealmMapper(compiledPattern, realmRealmMap); } else { return new MappedRegexRealmMapper(compiledPattern, delegate, realmRealmMap); } }); ServiceBuilder<RealmMapper> realmMapperBuilder = serviceTarget.addService(realmMapperName, realmMapperService); if (delegateRealmMapper != null) { String delegateCapabilityName = RuntimeCapability.buildDynamicCapabilityName(REALM_MAPPER_CAPABILITY, delegateRealmMapper); ServiceName delegateServiceName = context.getCapabilityServiceName(delegateCapabilityName, RealmMapper.class); realmMapperBuilder.addDependency(delegateServiceName, RealmMapper.class, delegateRealmMapperInjector); } commonDependencies(realmMapperBuilder) .setInitialMode(Mode.LAZY) .install(); }
Example 18
Source File: DomainXml_14.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
void writeContent(final XMLExtendedStreamWriter writer, final ModelMarshallingContext context) throws XMLStreamException { ModelNode modelNode = context.getModelNode(); writer.writeStartDocument(); writer.writeStartElement(Element.DOMAIN.getLocalName()); writer.writeDefaultNamespace(CURRENT.getUriString()); writeNamespaces(writer, modelNode); writeSchemaLocation(writer, modelNode); DomainRootDefinition.NAME.marshallAsAttribute(modelNode, false, writer); if (modelNode.hasDefined(DOMAIN_ORGANIZATION)) { DomainRootDefinition.ORGANIZATION_IDENTIFIER.marshallAsAttribute(modelNode, writer); } if (modelNode.hasDefined(EXTENSION)) { extensionXml.writeExtensions(writer, modelNode.get(EXTENSION)); } if (modelNode.hasDefined(SYSTEM_PROPERTY)) { writeProperties(writer, modelNode.get(SYSTEM_PROPERTY), Element.SYSTEM_PROPERTIES, false); } if (modelNode.hasDefined(PATH)) { writePaths(writer, modelNode.get(PATH), true); } if (modelNode.hasDefined(CORE_SERVICE) && modelNode.get(CORE_SERVICE).hasDefined(MANAGEMENT)) { // We use CURRENT here as we only support writing the most recent. ManagementXml managementXml = ManagementXml.newInstance(CURRENT, this, true); managementXml.writeManagement(writer, modelNode.get(CORE_SERVICE, MANAGEMENT), true); } if (modelNode.hasDefined(PROFILE)) { writer.writeStartElement(Element.PROFILES.getLocalName()); ModelNode profiles = modelNode.get(PROFILE); for (final String profile : profiles.keys()) { writeProfile(writer, profile, profiles.get(profile), context); } writer.writeEndElement(); } if (modelNode.hasDefined(INTERFACE)) { writeInterfaces(writer, modelNode.get(INTERFACE)); } if (modelNode.hasDefined(SOCKET_BINDING_GROUP)) { writer.writeStartElement(Element.SOCKET_BINDING_GROUPS.getLocalName()); ModelNode sbgs = modelNode.get(SOCKET_BINDING_GROUP); for (final String sbg : sbgs.keys()) { writeSocketBindingGroup(writer, sbgs.get(sbg), sbg); } writer.writeEndElement(); } if (modelNode.hasDefined(DEPLOYMENT)) { writeDomainDeployments(writer, modelNode.get(DEPLOYMENT)); } if (modelNode.hasDefined(DEPLOYMENT_OVERLAY)) { writeDeploymentOverlays(writer, modelNode.get(DEPLOYMENT_OVERLAY)); } if (modelNode.hasDefined(SERVER_GROUP)) { writer.writeStartElement(Element.SERVER_GROUPS.getLocalName()); ModelNode sgs = modelNode.get(SERVER_GROUP); for (final String sg : sgs.keys()) { writeServerGroup(writer, sg, sgs.get(sg)); } writer.writeEndElement(); } if (modelNode.hasDefined(HOST_EXCLUDE)) { writeHostExcludes(writer, modelNode.get(HOST_EXCLUDE)); } if (modelNode.hasDefined(MANAGEMENT_CLIENT_CONTENT)) { writeManagementClientContent(writer, modelNode.get(MANAGEMENT_CLIENT_CONTENT)); } writer.writeEndElement(); writer.writeEndDocument(); }
Example 19
Source File: DeploymentOverlaysXml.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
void writeDeploymentOverlays(final XMLExtendedStreamWriter writer, final ModelNode modelNode) throws XMLStreamException { Set<String> names = modelNode.keys(); if (names.size() > 0) { writer.writeStartElement(Element.DEPLOYMENT_OVERLAYS.getLocalName()); for (String uniqueName : names) { final ModelNode contentItem = modelNode.get(uniqueName); writer.writeStartElement(Element.DEPLOYMENT_OVERLAY.getLocalName()); writeAttribute(writer, Attribute.NAME, uniqueName); if (contentItem.hasDefined(CONTENT)) { final ModelNode overridesNode = contentItem.get(CONTENT); final Set<String> overrides = overridesNode.keys(); for (final String override : overrides) { final ModelNode overrideNode = overridesNode.get(override); final String content = HashUtil.bytesToHexString(overrideNode.require(CONTENT).asBytes()); writer.writeStartElement(Element.CONTENT.getLocalName()); writeAttribute(writer, Attribute.PATH, override); writeAttribute(writer, Attribute.CONTENT, content); writer.writeEndElement(); } } if (contentItem.hasDefined(DEPLOYMENT)) { final ModelNode deployments = contentItem.get(DEPLOYMENT); Set<String> deploymentNames = deployments.keys(); if (deploymentNames.size() > 0) { for (String deploymentName : deploymentNames) { final ModelNode depNode = deployments.get(deploymentName); writer.writeStartElement(Element.DEPLOYMENT.getLocalName()); writeAttribute(writer, Attribute.NAME, deploymentName); writer.writeEndElement(); } } } writer.writeEndElement(); } writer.writeEndElement(); writeNewLine(writer); } }
Example 20
Source File: HostXml_14.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void writeServers(final XMLExtendedStreamWriter writer, final ModelNode modelNode) throws XMLStreamException { for (String serverName : modelNode.keys()) { final ModelNode server = modelNode.get(serverName); writer.writeStartElement(Element.SERVER.getLocalName()); WriteUtils.writeAttribute(writer, Attribute.NAME, serverName); ServerConfigResourceDefinition.GROUP.marshallAsAttribute(server, writer); ServerConfigResourceDefinition.AUTO_START.marshallAsAttribute(server, writer); ServerConfigResourceDefinition.UPDATE_AUTO_START_WITH_SERVER_STATUS.marshallAsAttribute(server, writer); if (server.hasDefined(PATH)) { writePaths(writer, server.get(PATH), false); } if (server.hasDefined(SYSTEM_PROPERTY)) { writeProperties(writer, server.get(SYSTEM_PROPERTY), Element.SYSTEM_PROPERTIES, false); } if (server.hasDefined(INTERFACE)) { writeInterfaces(writer, server.get(INTERFACE)); } if (server.hasDefined(JVM)) { for (final Property jvm : server.get(JVM).asPropertyList()) { JvmXml.writeJVMElement(writer, jvm.getName(), jvm.getValue()); break; // TODO just write the first !? } } if (server.hasDefined(SOCKET_BINDING_GROUP) || server.hasDefined(SOCKET_BINDING_PORT_OFFSET) || server.hasDefined(SOCKET_BINDING_DEFAULT_INTERFACE)) { writer.writeStartElement(Element.SOCKET_BINDINGS.getLocalName()); ServerConfigResourceDefinition.SOCKET_BINDING_GROUP.marshallAsAttribute(server, writer); ServerConfigResourceDefinition.SOCKET_BINDING_PORT_OFFSET.marshallAsAttribute(server, writer); ServerConfigResourceDefinition.SOCKET_BINDING_DEFAULT_INTERFACE.marshallAsAttribute(server, writer); writer.writeEndElement(); } if (server.hasDefined(SSL, LOOPBACK)) { ModelNode ssl = server.get(SSL, LOOPBACK); writer.writeStartElement(Element.SSL.getLocalName()); SslLoopbackResourceDefinition.SSL_PROTOCOCOL.marshallAsAttribute(ssl, writer); SslLoopbackResourceDefinition.TRUST_MANAGER_ALGORITHM.marshallAsAttribute(ssl, writer); SslLoopbackResourceDefinition.TRUSTSTORE_TYPE.marshallAsAttribute(ssl, writer); SslLoopbackResourceDefinition.TRUSTSTORE_PATH.marshallAsAttribute(ssl, writer); SslLoopbackResourceDefinition.TRUSTSTORE_PASSWORD.marshallAsAttribute(ssl, writer); writer.writeEndElement(); } writer.writeEndElement(); } }