Java Code Examples for org.jboss.dmr.ModelNode#asString()
The following examples show how to use
org.jboss.dmr.ModelNode#asString() .
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: ModuleLoadingManagementTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void moduleRootAttributeTest(boolean forServer) throws Exception { DomainClient domainClient = domainMasterLifecycleUtil.getDomainClient(); ModelNode op = Util.createEmptyOperation("read-attribute", forServer ? SERVER_PA : HOST_PA); op.get(NAME).set("module-roots"); ModelNode response = domainClient.execute(op); List<ModelNode> result = validateResponse(response).asList(); boolean hasModules = false; boolean hasBase = false; for (ModelNode node : result) { String root = node.asString(); if (root.endsWith(MODULES_DIR)) { Assert.assertFalse(hasModules); hasModules = true; } if (root.endsWith(LAYERS_BASE)) { Assert.assertFalse(hasBase); hasBase = true; } } Assert.assertTrue(hasModules); Assert.assertTrue(hasBase); }
Example 2
Source File: Util.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public static String getFailureDescription(ModelNode operationResponse) { if(operationResponse == null) { return null; } ModelNode descr = operationResponse.get(Util.FAILURE_DESCRIPTION); if(descr == null) { return null; } if(descr.hasDefined(Util.DOMAIN_FAILURE_DESCRIPTION)) { descr = descr.get(Util.DOMAIN_FAILURE_DESCRIPTION); } if(descr.hasDefined(Util.ROLLED_BACK)) { final StringBuilder buf = new StringBuilder(); buf.append(descr.asString()); if(descr.get(Util.ROLLED_BACK).asBoolean()) { buf.append("(The operation was rolled back)"); } else if(descr.hasDefined(Util.ROLLBACK_FAILURE_DESCRIPTION)){ buf.append(descr.get(Util.ROLLBACK_FAILURE_DESCRIPTION).toString()); } else { buf.append("(The operation also failed to rollback, failure description is not available.)"); } } else { return descr.asString(); } return descr.asString(); }
Example 3
Source File: NamespaceRemoveHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel(); ModelNode param = NAMESPACE.resolveModelAttribute(context, operation); ModelNode namespaces = model.get(NAMESPACES); Property toRemove = null; ModelNode newList = new ModelNode().setEmptyList(); String prefix = param.asString(); if (namespaces.isDefined()) { for (Property namespace : namespaces.asPropertyList()) { if (prefix.equals(namespace.getName())) { toRemove = namespace; } else { newList.add(namespace.getName(), namespace.getValue()); } } } if (toRemove != null) { namespaces.set(newList); } else { throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.namespaceNotFound(prefix)); } }
Example 4
Source File: AbstractIncludeExcludeFilter.java From revapi with Apache License 2.0 | 6 votes |
private void readMatches(ModelNode array, boolean regexes, List<String> fullMatches, List<Pattern> patterns) { if (!array.isDefined()) { return; } for (ModelNode ann : array.asList()) { String name = ann.asString(); if (regexes) { patterns.add(Pattern.compile(name)); } else { fullMatches.add(name); } } if (!regexes) { Collections.sort(fullMatches); } }
Example 5
Source File: StringListAttributeDefinition.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()) { List<ModelNode> valueList = attributeValue.asList(); String[] attributeValues = new String[valueList.size()]; int position = 0; for (ModelNode current : valueList) { 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 6
Source File: PropertyObjectTypeAttributeDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public String resolvePropertyValue(final OperationContext context, final ModelNode model) throws OperationFailedException { String result = null; final ModelNode value = resolveModelAttribute(context, model); if (value.isDefined()) { if (resolver == null) { result = value.asString(); } else { result = resolver.resolveValue(context, value); } } return result; }
Example 7
Source File: LevelResolver.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public String resolveValue(final OperationContext context, final ModelNode value) throws OperationFailedException { try { Level.parse(value.asString()); return value.asString(); } catch (IllegalArgumentException e) { throw createOperationFailure(LoggingLogger.ROOT_LOGGER.invalidLogLevel(value.asString())); } }
Example 8
Source File: MissingVaultExpressionTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static String getFailureDescriptionId(ModelNode response) { assertEquals(response.toString(), "failed", response.get("outcome").asString()); ModelNode failDesc = response.get("failure-description"); assertTrue(response.toString(), failDesc.isDefined()); assertEquals(response.toString(), ModelType.STRING, failDesc.getType()); String str = failDesc.asString(); int idx = str.indexOf(':'); assertTrue(str, idx > 0); return str.substring(0, idx); }
Example 9
Source File: CaseParameterCorrector.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public ModelNode correct(final ModelNode newValue, final ModelNode currentValue) { if (newValue.getType() == ModelType.UNDEFINED) { return newValue; } if (newValue.getType() != ModelType.STRING || currentValue.getType() != ModelType.STRING) { return newValue; } final String stringValue = newValue.asString(); final String uCase = stringValue.toLowerCase(Locale.ENGLISH); if (!stringValue.equals(uCase)) { newValue.set(uCase); } return newValue; }
Example 10
Source File: SubnetValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); if (value.isDefined() && value.getType() != ModelType.EXPRESSION) { String subnet = value.asString(); try { calculate(subnet); } catch (IllegalArgumentException e) { throw ControllerLogger.ROOT_LOGGER.invalidSubnetFormat(subnet, parameterName); } } }
Example 11
Source File: RegexAttributeDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); String pattern = value.asString(); try { Pattern.compile(pattern); } catch (IllegalArgumentException e) { throw ROOT_LOGGER.invalidRegularExpression(pattern, e); } }
Example 12
Source File: LdapConnectionAddHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String name = address.getLastElement().getValue(); final ServiceTarget serviceTarget = context.getServiceTarget(); final ServiceName ldapConMgrName = LdapConnectionManagerService.ServiceUtil.createServiceName(name); final ServiceBuilder<?> sb = serviceTarget.addService(ldapConMgrName); final Consumer<LdapConnectionManager> lcmConsumer = sb.provides(ldapConMgrName); final ModelNode securityRealm = SECURITY_REALM.resolveModelAttribute(context, model); Supplier<SSLContext> fullSSLContextSupplier = null; Supplier<SSLContext> trustSSLContextSupplier = null; if (securityRealm.isDefined()) { String realmName = securityRealm.asString(); fullSSLContextSupplier = SSLContextService.ServiceUtil.requires(sb, SecurityRealm.ServiceUtil.createServiceName(realmName), false); trustSSLContextSupplier = SSLContextService.ServiceUtil.requires(sb, SecurityRealm.ServiceUtil.createServiceName(realmName), true); } ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier = null; if (LdapConnectionResourceDefinition.SEARCH_CREDENTIAL_REFERENCE.resolveModelAttribute(context, model).isDefined()) { credentialSourceSupplier = CredentialReference.getCredentialSourceSupplier(context, LdapConnectionResourceDefinition.SEARCH_CREDENTIAL_REFERENCE, model, sb); } final LdapConnectionManagerService connectionManagerService = new LdapConnectionManagerService( lcmConsumer, fullSSLContextSupplier, trustSSLContextSupplier, credentialSourceSupplier, name, connectionManagerRegistry); updateRuntime(context, model, connectionManagerService); sb.setInstance(connectionManagerService); sb.install(); }
Example 13
Source File: AuthorizedAddressTest.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test of authorizeAddress method, of class AuthorizedAddress. */ @Test public void testAccessParialUnauthorizedAddress() { ModelNode address = PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT,"test.war"), PathElement.pathElement(SUBSYSTEM, "Undertow")).toModelNode(); ModelNode authorizedAddress = PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT,"test.war")).toModelNode(); OperationContext context = new AuthorizationOperationContext(authorizedAddress.asString()); ModelNode operation = new ModelNode(); operation.get(OP).set(READ_RESOURCE_OPERATION); operation.get(OP_ADDR).set(address); AuthorizedAddress expResult = new AuthorizedAddress(PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT,"test.war"), PathElement.pathElement(SUBSYSTEM,"<hidden>")).toModelNode(), true); AuthorizedAddress result = AuthorizedAddress.authorizeAddress(context, operation); assertEquals(expResult, result); }
Example 14
Source File: RuntimeExpressionResolver.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void resolvePluggableExpression(ModelNode node) throws OperationFailedException { String expression = node.asString(); if (expression.length() > 3) { String vaultedData = expression.substring(2, expression.length() -1); if (vaultReader == null) { // No VaultReader was configured or could be loaded given the modules on the classpath // This is common in WildFly Core itself as the org.picketbox module is not present // to allow loading the standard RuntimeVaultReader impl // Just check for a picektbox vault pattern and if present reject // We don't want to let vault expressions pass as other resolvers will treat the ":' // as a system property name vs default value delimiter if (VaultReader.STANDARD_VAULT_PATTERN.matcher(vaultedData).matches()) { log.tracef("Cannot resolve %s -- it is in the default vault format but no vault reader is available", vaultedData); throw ControllerLogger.ROOT_LOGGER.cannotResolveExpression(expression); } log.tracef("Not resolving %s -- no vault reader available and not in default vault format", vaultedData); } else if (vaultReader.isVaultFormat(vaultedData)) { try { String retrieved = vaultReader.retrieveFromVault(vaultedData); log.tracef("Retrieved %s from vault for %s", retrieved, vaultedData); node.set(retrieved); } catch (VaultReader.NoSuchItemException nsie) { throw ControllerLogger.ROOT_LOGGER.cannotResolveExpression(expression); } } else { log.tracef("Not resolving %s -- not in vault format", vaultedData); } } }
Example 15
Source File: InetAddressValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * {@inheritDoc} */ @Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); if (value.isDefined() && value.getType() != ModelType.EXPRESSION) { String str = value.asString(); if (Inet.parseInetAddress(str) == null) { throw new OperationFailedException("Address is invalid: \"" + str + "\""); } } }
Example 16
Source File: DifferenceMatchRecipe.java From revapi with Apache License 2.0 | 5 votes |
private static String getElement(ModelNode elementRoot) { if (!elementRoot.isDefined()) { return null; } return elementRoot.getType() == ModelType.STRING ? elementRoot.asString() : null; }
Example 17
Source File: PathAddHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static String getPathValue(OperationContext context, SimpleAttributeDefinition def, ModelNode model) throws OperationFailedException { final ModelNode resolved = def.resolveModelAttribute(context, model); return resolved.isDefined() ? resolved.asString() : null; }
Example 18
Source File: TypeConverters.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
Object fromModelNode(final ModelNode node) { return node.asString(); }
Example 19
Source File: CliBootOperationsTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
String getRunningMode() throws Exception { ModelNode op = Util.getReadAttributeOperation(PathAddress.EMPTY_ADDRESS, RUNNING_MODE); ModelNode result = container.getClient().executeForResult(op); return result.asString(); }
Example 20
Source File: Client.java From openshift-ping with Apache License 2.0 | 4 votes |
public final List<Pod> getPods(String namespace, String labels) throws Exception { ModelNode root = getNode("pods", namespace, labels); List<Pod> pods = new ArrayList<Pod>(); List<ModelNode> itemNodes = root.get("items").asList(); for (ModelNode itemNode : itemNodes) { //ModelNode metadataNode = itemNode.get("metadata"); //String podName = metadataNode.get("name").asString(); // eap-app-1-43wra //String podNamespace = metadataNode.get("namespace").asString(); // dward ModelNode specNode = itemNode.get("spec"); //String serviceAccount = specNode.get("serviceAccount").asString(); // default //String host = specNode.get("host").asString(); // ce-openshift-rhel-minion-1.lab.eng.brq.redhat.com ModelNode statusNode = itemNode.get("status"); ModelNode phaseNode = statusNode.get("phase"); if (!phaseNode.isDefined() || !"Running".equals(phaseNode.asString())) { continue; } /* We don't want to filter on the following as that could result in MERGEs instead of JOINs. ModelNode conditionsNode = statusNode.get("conditions"); if (!conditionsNode.isDefined()) { continue; } boolean ready = false; List<ModelNode> conditions = conditionsNode.asList(); for (ModelNode condition : conditions) { ModelNode conditionTypeNode = condition.get("type"); ModelNode conditionStatusNode = condition.get("status"); if (conditionTypeNode.isDefined() && "Ready".equals(conditionTypeNode.asString()) && conditionStatusNode.isDefined() && "True".equals(conditionStatusNode.asString())) { ready = true; break; } } if (!ready) { continue; } */ //String hostIP = statusNode.get("hostIP").asString(); // 10.34.75.250 ModelNode podIPNode = statusNode.get("podIP"); if (!podIPNode.isDefined()) { continue; } String podIP = podIPNode.asString(); // 10.1.0.169 Pod pod = new Pod(podIP); ModelNode containersNode = specNode.get("containers"); if (!containersNode.isDefined()) { continue; } List<ModelNode> containerNodes = containersNode.asList(); for (ModelNode containerNode : containerNodes) { ModelNode portsNode = containerNode.get("ports"); if (!portsNode.isDefined()) { continue; } //String containerName = containerNode.get("name").asString(); // eap-app Container container = new Container(); List<ModelNode> portNodes = portsNode.asList(); for (ModelNode portNode : portNodes) { ModelNode portNameNode = portNode.get("name"); if (!portNameNode.isDefined()) { continue; } String portName = portNameNode.asString(); // ping ModelNode containerPortNode = portNode.get("containerPort"); if (!containerPortNode.isDefined()) { continue; } int containerPort = containerPortNode.asInt(); // 8888 Port port = new Port(portName, containerPort); container.addPort(port); } pod.addContainer(container); } pods.add(pod); } if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, String.format("getPods(%s, %s) = %s", namespace, labels, pods)); } return pods; }