Search in sources :

Example 31 with Node

use of org.jboss.as.cli.operation.OperationRequestAddress.Node in project wildfly-core by wildfly.

the class OperationParsingTestCase method testNoOperation.

@Test
public void testNoOperation() throws Exception {
    DefaultCallbackHandler handler = new DefaultCallbackHandler();
    try {
        parse("./subsystem=logging:", handler);
    } catch (OperationFormatException e) {
    }
    assertTrue(handler.hasAddress());
    assertFalse(handler.hasOperationName());
    assertFalse(handler.hasProperties());
    assertTrue(handler.endsOnAddressOperationNameSeparator());
    assertFalse(handler.endsOnPropertyListStart());
    assertFalse(handler.endsOnPropertySeparator());
    assertFalse(handler.endsOnPropertyValueSeparator());
    assertFalse(handler.endsOnNodeSeparator());
    assertFalse(handler.endsOnNodeTypeNameSeparator());
    assertFalse(handler.isRequestComplete());
    OperationRequestAddress address = handler.getAddress();
    Iterator<Node> i = address.iterator();
    assertTrue(i.hasNext());
    Node node = i.next();
    assertEquals("subsystem", node.getType());
    assertEquals("logging", node.getName());
    assertFalse(i.hasNext());
}
Also used : OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) Node(org.jboss.as.cli.operation.OperationRequestAddress.Node) ModelNode(org.jboss.dmr.ModelNode) DefaultCallbackHandler(org.jboss.as.cli.operation.impl.DefaultCallbackHandler) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress) Test(org.junit.Test)

Example 32 with Node

use of org.jboss.as.cli.operation.OperationRequestAddress.Node in project wildfly-core by wildfly.

the class OperationParsingTestCase method testOperationEscapedQuotesInArgumentValues.

@Test
public void testOperationEscapedQuotesInArgumentValues() throws Exception {
    DefaultCallbackHandler handler = new DefaultCallbackHandler();
    parse("/subsystem=logging/console-handler=CONSOLE:write-attribute(name=filter-spec, value=\"substituteAll(\\\"JBAS\\\",\\\"DUMMY\\\")\")", handler);
    assertTrue(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("write-attribute", handler.getOperationName());
    OperationRequestAddress address = handler.getAddress();
    Iterator<Node> i = address.iterator();
    assertTrue(i.hasNext());
    Node node = i.next();
    assertEquals("subsystem", node.getType());
    assertEquals("logging", node.getName());
    assertTrue(i.hasNext());
    node = i.next();
    assertEquals("console-handler", node.getType());
    assertEquals("CONSOLE", node.getName());
    assertFalse(i.hasNext());
    Set<String> args = handler.getPropertyNames();
    assertEquals(2, args.size());
    assertTrue(args.contains("name"));
    assertEquals("filter-spec", handler.getPropertyValue("name"));
    assertTrue(args.contains("value"));
    assertEquals("\"substituteAll(\\\"JBAS\\\",\\\"DUMMY\\\")\"", handler.getPropertyValue("value"));
}
Also used : Node(org.jboss.as.cli.operation.OperationRequestAddress.Node) ModelNode(org.jboss.dmr.ModelNode) DefaultCallbackHandler(org.jboss.as.cli.operation.impl.DefaultCallbackHandler) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress) Test(org.junit.Test)

Example 33 with Node

use of org.jboss.as.cli.operation.OperationRequestAddress.Node in project wildfly-core by wildfly.

the class OperationParsingTestCase method testOpenQuote.

@Test
public void testOpenQuote() throws Exception {
    DefaultCallbackHandler handler = new DefaultCallbackHandler(false);
    try {
        handler.parse(null, "./subsystem=logging:add(a=\"", null);
    } catch (OperationFormatException e) {
    }
    assertTrue(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());
    OperationRequestAddress address = handler.getAddress();
    Iterator<Node> i = address.iterator();
    assertTrue(i.hasNext());
    Node node = i.next();
    assertEquals("subsystem", node.getType());
    assertEquals("logging", node.getName());
    assertFalse(i.hasNext());
    assertEquals("add", handler.getOperationName());
    assertEquals("a", handler.getLastParsedPropertyName());
    assertEquals("\"", handler.getLastParsedPropertyValue());
}
Also used : OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) Node(org.jboss.as.cli.operation.OperationRequestAddress.Node) ModelNode(org.jboss.dmr.ModelNode) DefaultCallbackHandler(org.jboss.as.cli.operation.impl.DefaultCallbackHandler) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress) Test(org.junit.Test)

Example 34 with Node

use of org.jboss.as.cli.operation.OperationRequestAddress.Node in project wildfly-core by wildfly.

the class BaseOperationCommand method isAvailable.

@Override
public boolean isAvailable(CommandContext ctx) {
    if (!super.isAvailable(ctx)) {
        return false;
    }
    if (requiredAddress == null) {
        return ctx.getConfig().isAccessControl() ? accessRequirement.isSatisfied(ctx) : true;
    }
    if (dependsOnProfile && ctx.isDomainMode()) {
        // not checking address in all the profiles
        return ctx.getConfig().isAccessControl() ? accessRequirement.isSatisfied(ctx) : true;
    }
    if (available != null) {
        return available.booleanValue();
    }
    final ModelControllerClient client = ctx.getModelControllerClient();
    if (client == null) {
        return false;
    }
    // which happens on reconnect/disconnect
    if (requiredType == null) {
        available = isAddressValid(ctx);
    } else {
        final ModelNode request = new ModelNode();
        final ModelNode address = request.get(Util.ADDRESS);
        for (OperationRequestAddress.Node node : requiredAddress) {
            address.add(node.getType(), node.getName());
        }
        request.get(Util.OPERATION).set(Util.READ_CHILDREN_TYPES);
        ModelNode result;
        try {
            result = ctx.getModelControllerClient().execute(request);
        } catch (IOException e) {
            return false;
        }
        available = Util.listContains(result, requiredType);
    }
    if (ctx.getConfig().isAccessControl()) {
        available = available && accessRequirement.isSatisfied(ctx);
    }
    return available;
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) Node(org.jboss.as.cli.operation.OperationRequestAddress.Node) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress)

Example 35 with Node

use of org.jboss.as.cli.operation.OperationRequestAddress.Node in project wildfly-core by wildfly.

the class LsHandler method getDynamicOptions.

private Map<String, CommandArgument> getDynamicOptions(CommandContext ctx) throws CommandFormatException {
    if (ctx.getModelControllerClient() == null) {
        return Collections.emptyMap();
    }
    final OperationRequestAddress address = getOperationRequestAddress(ctx);
    if (address.endsOnType()) {
        return Collections.emptyMap();
    }
    final ModelNode req = new ModelNode();
    if (address.isEmpty()) {
        req.get(Util.ADDRESS).setEmptyList();
    } else {
        final ModelNode addrNode = req.get(Util.ADDRESS);
        for (OperationRequestAddress.Node node : address) {
            addrNode.add(node.getType(), node.getName());
        }
    }
    req.get(Util.OPERATION).set(Util.READ_RESOURCE_DESCRIPTION);
    Map<String, CommandArgument> options = Collections.emptyMap();
    try {
        final ModelNode response = ctx.getModelControllerClient().execute(req);
        if (Util.isSuccess(response)) {
            if (response.hasDefined(Util.RESULT)) {
                final ModelNode result = response.get(Util.RESULT);
                if (result.hasDefined(Util.ATTRIBUTES)) {
                    options = new TreeMap<>();
                    ModelNode attributes = result.get(Util.ATTRIBUTES);
                    for (String key : attributes.keys()) {
                        ModelNode attribute = attributes.get(key);
                        for (String k : attribute.keys()) {
                            ArgumentWithoutValue wv = new ArgumentWithoutValue(new CommandHandlerWithArguments() {

                                @Override
                                public boolean isAvailable(CommandContext ctx) {
                                    return LsHandler.this.isAvailable(ctx);
                                }

                                @Override
                                public boolean isBatchMode(CommandContext ctx) {
                                    return LsHandler.this.isBatchMode(ctx);
                                }

                                @Override
                                public void handle(CommandContext ctx) throws CommandLineException {
                                    LsHandler.this.handle(ctx);
                                }

                                @Override
                                public void addArgument(CommandArgument arg) {
                                // Noop.
                                }
                            }, "--" + k);
                            wv.addRequiredPreceding(l);
                            options.put("--" + k, wv);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return options;
}
Also used : Node(org.jboss.as.cli.operation.OperationRequestAddress.Node) CommandContext(org.jboss.as.cli.CommandContext) CommandArgument(org.jboss.as.cli.CommandArgument) CommandLineException(org.jboss.as.cli.CommandLineException) OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) IOException(java.io.IOException) CommandLineException(org.jboss.as.cli.CommandLineException) CommandFormatException(org.jboss.as.cli.CommandFormatException) ModelNode(org.jboss.dmr.ModelNode) ArgumentWithoutValue(org.jboss.as.cli.impl.ArgumentWithoutValue) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress)

Aggregations

Node (org.jboss.as.cli.operation.OperationRequestAddress.Node)36 OperationRequestAddress (org.jboss.as.cli.operation.OperationRequestAddress)35 DefaultOperationRequestAddress (org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress)32 DefaultCallbackHandler (org.jboss.as.cli.operation.impl.DefaultCallbackHandler)29 Test (org.junit.Test)28 ModelNode (org.jboss.dmr.ModelNode)14 OperationFormatException (org.jboss.as.cli.operation.OperationFormatException)4 IOException (java.io.IOException)3 TerminalString (org.aesh.readline.terminal.formatting.TerminalString)1 CommandArgument (org.jboss.as.cli.CommandArgument)1 CommandContext (org.jboss.as.cli.CommandContext)1 CommandFormatException (org.jboss.as.cli.CommandFormatException)1 CommandLineException (org.jboss.as.cli.CommandLineException)1 ArgumentWithoutValue (org.jboss.as.cli.impl.ArgumentWithoutValue)1 ParsedOperationRequestHeader (org.jboss.as.cli.operation.ParsedOperationRequestHeader)1 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)1