Java Code Examples for org.jboss.dmr.ModelNode#fromString()
The following examples show how to use
org.jboss.dmr.ModelNode#fromString() .
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: EchoDMRTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testHeaders() throws CliInitializationException, CommandLineException { ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream(); CommandContextConfiguration config = new CommandContextConfiguration.Builder().setConsoleOutput(consoleOutput).build(); CommandContext ctx = CommandContextFactory.getInstance().newCommandContext(config); try { String cmd = "/subsystem=foo:op(arg1=14, arg2=[{i1=\"val1\", i2=\"val2\"}], arg3=\"val3\"){allow-resource-service-restart=true;foo=\"1 2 3\";blocking-timeout=12}"; ctx.handle("echo-dmr " + cmd); String out = consoleOutput.toString(); out = out.substring(0, out.lastIndexOf("\n")); ModelNode mn = ModelNode.fromString(out); ModelNode headers = mn.get(Util.OPERATION_HEADERS); Assert.assertEquals("1 2 3", headers.get("foo").asString()); Assert.assertEquals("true", headers.get("allow-resource-service-restart").asString()); Assert.assertEquals("12", headers.get("blocking-timeout").asString()); } finally { ctx.terminateSession(); } }
Example 2
Source File: EchoDMRTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testCompact() throws CliInitializationException, CommandLineException { ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream(); CommandContextConfiguration config = new CommandContextConfiguration.Builder().setConsoleOutput(consoleOutput).build(); CommandContext ctx = CommandContextFactory.getInstance().newCommandContext(config); try { String cmd = "/subsystem=foo:op(arg1=14, arg2=[{i1=\"val1\", i2=\"val2\"}], arg3=\"val3\")"; ctx.handle("echo-dmr " + cmd); String out = consoleOutput.toString(); out = out.substring(0, out.lastIndexOf("\n")); consoleOutput.reset(); ctx.handle("echo-dmr --compact " + cmd); String compact = consoleOutput.toString(); compact = compact.substring(0, compact.lastIndexOf("\n")); Assert.assertTrue(out, out.contains("\n")); Assert.assertFalse(compact, compact.contains("\n")); ModelNode mn = ModelNode.fromString(out); ModelNode mnCompact = ModelNode.fromString(compact); Assert.assertEquals(mnCompact.toString(), mn, mnCompact); } finally { ctx.terminateSession(); } }
Example 3
Source File: ArgumentValueConverter.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public ModelNode fromString(CommandContext ctx, String value) throws CommandFormatException { if (value == null) { return new ModelNode(); } if(ctx.isResolveParameterValues()) { value = CLIExpressionResolver.resolveLax(value); } ModelNode toSet = null; try { toSet = ModelNode.fromString(value); } catch (Exception e) { final ArgumentValueCallbackHandler handler = new ArgumentValueCallbackHandler(); StateParser.parse(value, handler, ArgumentValueInitialState.INSTANCE); toSet = handler.getResult(); } return toSet; }
Example 4
Source File: AttributeNamePathCompletionTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testAttributeAccessType() throws Exception { // WFCORE-1908 final ModelNode propDescr = ModelNode.fromString(attrsDescr); assertTrue(propDescr.isDefined()); final AttributeNamePathCompleter completer = new AttributeNamePathCompleter(propDescr); final List<String> candidates = new ArrayList<String>(); // test write-only attribute int i = completer.complete("attr", candidates, propDescr, true); assertEquals(Arrays.asList("attr-read-write"), candidates); assertEquals(0, i); // test NOT write-only attribute candidates.clear(); i = completer.complete("attr", candidates, propDescr, false); assertEquals(Arrays.asList("attr-metric", "attr-read-only", "attr-read-write"), candidates); assertEquals(0, i); }
Example 5
Source File: RunAsRoleMapper.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private static ModelNode parseRolesString(String raw) { String trimmed = raw.trim(); if (trimmed.startsWith("[") && trimmed.endsWith("]")) { try { return ModelNode.fromString(trimmed); } catch (Exception ignored) { // fall through and try comma splitting } // Strip the [] trimmed = trimmed.substring(1, trimmed.length() - 1); } if (trimmed.contains(",")) { ModelNode result = new ModelNode().setEmptyList(); String[] split = trimmed.split(","); for (String item : split) { result.add(item.trim()); } return result; } else { return new ModelNode(trimmed); } }
Example 6
Source File: ValueTypeCompletionTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testCompositeSteps() throws Exception { final ModelNode propDescr = ModelNode.fromString(compositeSteps); assertTrue(propDescr.isDefined()); final List<String> candidates = new ArrayList<>(); int i; i = new ValueTypeCompleter(propDescr).complete(null, "", 0, candidates); assertEquals(Collections.singletonList("["), candidates); assertEquals(0, i); candidates.clear(); i = new ValueTypeCompleter(propDescr).complete(null, "[", 0, candidates); assertEquals(Arrays.asList(new String[]{"{"}), candidates); assertEquals(1, i); candidates.clear(); i = new ValueTypeCompleter(propDescr).complete(null, "[{", 0, candidates); assertTrue(candidates.isEmpty()); candidates.clear(); i = new ValueTypeCompleter(propDescr).complete(null, "[{a", 0, candidates); assertTrue(candidates.isEmpty()); }
Example 7
Source File: CliUtilsForPatching.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public static List<String> getResourceLoaderPathsForModule(String module, boolean ignoreError) throws Exception { try(CLIWrapper cli = new CLIWrapper(true)) { String command = "/core-service=module-loading:list-resource-loader-paths(module=" + module + ")"; logger.debug("CLI command: " + command); if (!cli.sendLine(command, ignoreError)) { throw new RuntimeException(cli.readOutput()); } ModelNode response = ModelNode.fromString(cli.readOutput()); List<ModelNode> pathList = response.get("result").asList(); List<String> patchesListString = new ArrayList<String>(); for (ModelNode n : pathList) { patchesListString.add(n.asString()); } return patchesListString; } }
Example 8
Source File: ValueTypeCompletionTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testJgroupsProtocolAdd() throws Exception { final ModelNode propDescr = ModelNode.fromString(jgroupsProtocolsAdd); assertTrue(propDescr.isDefined()); final List<String> candidates = new ArrayList<String>(); int i; i = new ValueTypeCompleter(propDescr).complete(null, "", 0, candidates); assertEquals(Collections.singletonList("["), candidates); assertEquals(0, i); candidates.clear(); i = new ValueTypeCompleter(propDescr).complete(null, "[", 0, candidates); assertEquals(Arrays.asList(new String[]{"{"}), candidates); assertEquals(1, i); candidates.clear(); i = new ValueTypeCompleter(propDescr).complete(null, "[{", 0, candidates); assertEquals(Arrays.asList(new String[]{"properties", "socket-binding", "type"}), candidates); assertEquals(2, i); }
Example 9
Source File: CliConfigTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testOptionResolveParameterValues() throws Exception { CliProcessWrapper cli = new CliProcessWrapper() .addJavaOption("-Duser.home=" + temporaryUserHome.getRoot().toPath().toString()) .addJavaOption("-DfooValue=bar") .addCliArgument("--controller=" + TestSuiteEnvironment.getServerAddress() + ":" + TestSuiteEnvironment.getServerPort()) .addCliArgument("--connect") .addCliArgument("--resolve-parameter-values"); try { cli.executeInteractive(); cli.clearOutput(); cli.pushLineAndWaitForResults("echo-dmr /system-property=foo:add(value=${fooValue})"); String out = cli.getOutput(); String dmr = out.substring(out.indexOf(Config.getLineSeparator()), out.lastIndexOf("}") + 1); ModelNode mn = ModelNode.fromString(dmr); assertEquals("bar", mn.get(Util.VALUE).asString()); } finally { cli.destroyProcess(); } }
Example 10
Source File: ValueTypeCompletionTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testCapabilities() throws Exception { final ModelNode propDescr = ModelNode.fromString(capabilities_prop); assertTrue(propDescr.isDefined()); final List<String> candidates = new ArrayList<>(); List<String> capabilities = new ArrayList<>(); CapabilityCompleterFactory factory = (OperationRequestAddress address, String staticPart) -> { return new TestCapabilityReferenceCompleter(capabilities); }; int i; i = new ValueTypeCompleter(propDescr, factory).complete(null, "{prop1=", 0, candidates); assertEquals(Arrays.asList(), candidates); assertEquals(-1, i); capabilities.add("coco"); capabilities.add("prefMapper001"); capabilities.add("prefMapper002"); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "{prop1=", 0, candidates); assertEquals(capabilities, candidates); assertEquals(7, i); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "{prop1=c", 0, candidates); assertEquals(Arrays.asList("coco"), candidates); assertEquals(7, i); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "{prop1=coco", 0, candidates); assertEquals(Arrays.asList(","), candidates); assertEquals(11, i); }
Example 11
Source File: Util.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static void setRequestProperty(ModelNode request, String name, String value) { if(name == null || name.trim().isEmpty()) throw new IllegalArgumentException("The argument name is not specified: '" + name + "'"); if(value == null || value.trim().isEmpty()) throw new IllegalArgumentException("The argument value is not specified: '" + value + "'"); ModelNode toSet = null; try { toSet = ModelNode.fromString(value); } catch (Exception e) { // just use the string toSet = new ModelNode().set(value); } request.get(name).set(toSet); }
Example 12
Source File: DMRConfigProviderFactory.java From keycloak with Apache License 2.0 | 5 votes |
private String loadDmrConfig(ServletContext context) { String dmrConfig = context.getInitParameter(KEYCLOAK_CONFIG_PARAM_NAME); if (dmrConfig == null) { return null; } ModelNode dmrConfigNode = ModelNode.fromString(dmrConfig); if (dmrConfigNode.asPropertyList().isEmpty()) { return null; } // note that we need to resolve expressions BEFORE we convert to JSON return dmrConfigNode.resolve().toJSONString(true); }
Example 13
Source File: CliUtilsForPatching.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static List<ModelNode> getPatchingHistory() throws Exception { try(CLIWrapper cli = new CLIWrapper(true)) { String command = "/core-service=patching:show-history"; logger.debug("CLI command: " + command); cli.sendLine(command, false); ModelNode response = ModelNode.fromString(cli.readOutput()); return response.get("result").asList(); } }
Example 14
Source File: ArgumentValueConverter.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public ModelNode fromString(CommandContext ctx, String value) throws CommandFormatException { if(value == null) { return new ModelNode(); } if(ctx.isResolveParameterValues()) { value = CLIExpressionResolver.resolveLax(value); } try { return ModelNode.fromString(value); } catch(Exception e) { return fromNonDMRString(ctx, value); } }
Example 15
Source File: ModelParserUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static ModelNode readResourceTree(CLIWrapper cli) { cli.sendLine("/:read-resource(recursive=true)"); ModelNode response = ModelNode.fromString(cli.readOutput()); assertTrue(response.toString(), SUCCESS.equals(response.get(OUTCOME).asString())); ModelNode firstResult = response.get(RESULT); assertTrue(response.toString(), firstResult.isDefined()); return firstResult; }
Example 16
Source File: StringValueOperand.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public StringValueOperand(String value) { if(value == null) { throw new IllegalArgumentException("value is null."); } ModelNode node; try { node = ModelNode.fromString(value); } catch(IllegalArgumentException e) { node = new ModelNode().set(value); } this.value = node; }
Example 17
Source File: LoggingJBossASClient.java From hawkular-agent with Apache License 2.0 | 5 votes |
/** * Sets the logger to the given level. * If the logger does not exist yet, it will be created. * * @param loggerName the logger name (this is also known as the category name) * @param level the new level of the logger (e.g. DEBUG, INFO, ERROR, etc.) * @throws Exception any error */ public void setLoggerLevel(String loggerName, String level) throws Exception { final Address addr = Address.root().add(SUBSYSTEM, LOGGING, LOGGER, loggerName); final ModelNode request; if (isLogger(loggerName)) { request = createWriteAttributeRequest("level", level, addr); } else { final String dmrTemplate = "" // + "{" // + "\"category\" => \"%s\" " // + ", \"level\" => \"%s\" " // + ", \"use-parent-handlers\" => \"true\" " // + "}"; final String dmr = String.format(dmrTemplate, loggerName, level); request = ModelNode.fromString(dmr); request.get(OPERATION).set(ADD); request.get(ADDRESS).set(addr.getAddressNode()); } final ModelNode response = execute(request); if (!isSuccess(response)) { throw new FailureException(response); } return; }
Example 18
Source File: ValueTypeCompletionTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testListCapabilities() throws Exception { final ModelNode propDescr = ModelNode.fromString(role_mapper); assertTrue(propDescr.isDefined()); final List<String> candidates = new ArrayList<>(); List<String> capabilities = new ArrayList<>(); CapabilityCompleterFactory factory = (OperationRequestAddress address, String staticPart) -> { return new TestCapabilityReferenceCompleter(capabilities); }; int i; i = new ValueTypeCompleter(propDescr, factory).complete(null, "", 0, candidates); assertEquals(Arrays.asList("["), candidates); assertEquals(i, 0); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[", 0, candidates); assertEquals(Arrays.asList("]"), candidates); assertEquals(i, 1); capabilities.add("coco"); capabilities.add("prefMapper001"); capabilities.add("prefMapper002"); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[", 0, candidates); assertEquals(capabilities, candidates); assertEquals(i, 1); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[p", 0, candidates); assertEquals(Arrays.asList("prefMapper001", "prefMapper002"), candidates); assertEquals(i, 1); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[prefMapper001", 0, candidates); assertEquals(Arrays.asList(","), candidates); assertEquals(i, 14); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[prefMapper001,", 0, candidates); assertEquals(Arrays.asList("coco", "prefMapper002"), candidates); assertEquals(i, 15); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[prefMapper001,c", 0, candidates); assertEquals(Arrays.asList("coco"), candidates); assertEquals(i, 15); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[prefMapper001,coco", 0, candidates); assertEquals(Arrays.asList(","), candidates); assertEquals(i, 19); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[prefMapper001,coco,", 0, candidates); assertEquals(Arrays.asList("prefMapper002"), candidates); assertEquals(i, 20); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[prefMapper001,coco,c", 0, candidates); assertEquals(Arrays.asList(), candidates); assertEquals(i, -1); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[prefMapper001,coco,p", 0, candidates); assertEquals(Arrays.asList("prefMapper002"), candidates); assertEquals(i, 20); candidates.clear(); i = new ValueTypeCompleter(propDescr, factory).complete(null, "[prefMapper001,coco,prefMapper002", 0, candidates); assertEquals(Arrays.asList("]"), candidates); assertEquals(i, 33); }
Example 19
Source File: DatasourceJBossASClient.java From hawkular-agent with Apache License 2.0 | 4 votes |
/** * Returns a ModelNode that can be used to create an XA datasource. Callers are free to tweek the datasource request * that is returned, if they so choose, before asking the client to execute the request. * * @param name name of the XA datasource * @param blockingTimeoutWaitMillis see datasource documentation for meaning of this setting * @param driverName see datasource documentation for meaning of this setting * @param xaDataSourceClass see datasource documentation for meaning of this setting * @param exceptionSorterClassName see datasource documentation for meaning of this setting * @param idleTimeoutMinutes see datasource documentation for meaning of this setting * @param minPoolSize see datasource documentation for meaning of this setting * @param maxPoolSize see datasource documentation for meaning of this setting * @param noRecovery optional, left unset if null * @param noTxSeparatePool optional, left unset if null * @param preparedStatementCacheSize see datasource documentation for meaning of this setting * @param recoveryPluginClassName optional, left unset if null * @param securityDomain see datasource documentation for meaning of this setting * @param staleConnectionCheckerClassName optional, left unset if null * @param transactionIsolation see datasource documentation for meaning of this setting * @param validConnectionCheckerClassName see datasource documentation for meaning of this setting * @param xaDatasourceProperties see datasource documentation for meaning of this setting * * @return the request that can be used to create the XA datasource */ public ModelNode createNewXADatasourceRequest(String name, int blockingTimeoutWaitMillis, String driverName, String xaDataSourceClass, String exceptionSorterClassName, int idleTimeoutMinutes, int minPoolSize, int maxPoolSize, Boolean noRecovery, Boolean noTxSeparatePool, int preparedStatementCacheSize, String recoveryPluginClassName, String securityDomain, String staleConnectionCheckerClassName, String transactionIsolation, String validConnectionCheckerClassName, Map<String, String> xaDatasourceProperties) { String jndiName = "java:jboss/datasources/" + name; String dmrTemplate = "" // + "{" // + "\"xa-datasource-class\" => \"%s\"" + ", \"blocking-timeout-wait-millis\" => %dL " // + ", \"driver-name\" => \"%s\" " // + ", \"exception-sorter-class-name\" => \"%s\" " // + ", \"idle-timeout-minutes\" => %dL " // + ", \"jndi-name\" => \"%s\" " // + ", \"jta\" => true " // + ", \"min-pool-size\" => %d " // + ", \"max-pool-size\" => %d " // + ", \"no-recovery\" => %b " // + ", \"no-tx-separate-pool\" => %b " // + ", \"prepared-statements-cache-size\" => %dL " // + ", \"recovery-plugin-class-name\" => \"%s\" " // + ", \"security-domain\" => \"%s\" " // + ", \"stale-connection-checker-class-name\" => \"%s\" " // + ", \"transaction-isolation\" => \"%s\" " // + ", \"use-java-context\" => true " // + ", \"valid-connection-checker-class-name\" => \"%s\" " // + "}"; String dmr = String.format(dmrTemplate, xaDataSourceClass, blockingTimeoutWaitMillis, driverName, exceptionSorterClassName, idleTimeoutMinutes, jndiName, minPoolSize, maxPoolSize, noRecovery, noTxSeparatePool, preparedStatementCacheSize, recoveryPluginClassName, securityDomain, staleConnectionCheckerClassName, transactionIsolation, validConnectionCheckerClassName); Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_DATASOURCES, XA_DATA_SOURCE, name); final ModelNode request1 = ModelNode.fromString(dmr); request1.get(OPERATION).set(ADD); request1.get(ADDRESS).set(addr.getAddressNode()); // if no xa datasource properties, no need to create a batch request, there is only one ADD request to make if (xaDatasourceProperties == null || xaDatasourceProperties.size() == 0) { return request1; } // create a batch of requests - the first is the main one, the rest create each conn property ModelNode[] batch = new ModelNode[1 + xaDatasourceProperties.size()]; batch[0] = request1; int n = 1; for (Map.Entry<String, String> entry : xaDatasourceProperties.entrySet()) { addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_DATASOURCES, XA_DATA_SOURCE, name, XA_DATASOURCE_PROPERTIES, entry.getKey()); final ModelNode requestN = new ModelNode(); requestN.get(OPERATION).set(ADD); requestN.get(ADDRESS).set(addr.getAddressNode()); setPossibleExpression(requestN, VALUE, entry.getValue()); batch[n++] = requestN; } ModelNode result = createBatchRequest(batch); // remove unset args if (null == noRecovery) { result.get("steps").get(0).remove("no-recovery"); } if (null == noTxSeparatePool) { result.get("steps").get(0).remove("no-tx-separate-pool"); } if (null == recoveryPluginClassName) { result.get("steps").get(0).remove("recovery-plugin-class-name"); } if (null == staleConnectionCheckerClassName) { result.get("steps").get(0).remove("stale-connection-checker-class-name"); } return result; }
Example 20
Source File: DatasourceJBossASClient.java From hawkular-agent with Apache License 2.0 | 4 votes |
public ModelNode createNewDatasourceRequest(String name, String connectionUrlExpression, String driverName, boolean jta, Map<String, String> connectionProperties) { String jndiName = "java:jboss/datasources/" + name; String dmrTemplate = "" // + "{" // + "\"connection-url\" => expression \"%s\" " // + ", \"driver-name\" => \"%s\" " // + ", \"jndi-name\" => \"%s\" " // + ", \"jta\" => %s " // + ", \"use-java-context\" => true " // + "}"; String dmr = String.format(dmrTemplate, connectionUrlExpression, driverName, jndiName, jta); Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_DATASOURCES, DATA_SOURCE, name); final ModelNode request1 = ModelNode.fromString(dmr); request1.get(OPERATION).set(ADD); request1.get(ADDRESS).set(addr.getAddressNode()); // if there are no conn properties, no need to create a batch request, there is only one ADD request to make if (connectionProperties == null || connectionProperties.size() == 0) { return request1; } // create a batch of requests - the first is the main one, the rest create each conn property ModelNode[] batch = new ModelNode[1 + connectionProperties.size()]; batch[0] = request1; int n = 1; for (Map.Entry<String, String> entry : connectionProperties.entrySet()) { addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_DATASOURCES, DATA_SOURCE, name, CONNECTION_PROPERTIES, entry.getKey()); final ModelNode requestN = new ModelNode(); requestN.get(OPERATION).set(ADD); requestN.get(ADDRESS).set(addr.getAddressNode()); if (entry.getValue().indexOf("${") > -1) { requestN.get(VALUE).set(new ValueExpression(entry.getValue())); } else { requestN.get(VALUE).set(entry.getValue()); } batch[n++] = requestN; } return createBatchRequest(batch); }