Search in sources :

Example 11 with ParsedOperationRequestHeader

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

the class RolloutPlanParsingTestCase method testEndsOnGroupComma.

@Test
public void testEndsOnGroupComma() throws Exception {
    parse(":do{ rollout groupA( prop = v ),");
    assertFalse(handler.hasAddress());
    assertTrue(handler.hasOperationName());
    assertFalse(handler.hasProperties());
    assertFalse(handler.endsOnAddressOperationNameSeparator());
    assertFalse(handler.endsOnPropertyListStart());
    assertFalse(handler.endsOnPropertySeparator());
    assertFalse(handler.endsOnPropertyValueSeparator());
    assertFalse(handler.endsOnNodeSeparator());
    assertFalse(handler.endsOnNodeTypeNameSeparator());
    assertFalse(handler.endsOnSeparator());
    assertFalse(handler.endsOnHeaderListStart());
    assertFalse(handler.isRequestComplete());
    assertTrue(handler.hasHeaders());
    final Collection<ParsedOperationRequestHeader> headers = handler.getHeaders();
    assertEquals(1, headers.size());
    final ParsedOperationRequestHeader header = headers.iterator().next();
    assertTrue(header instanceof ParsedRolloutPlanHeader);
    final ParsedRolloutPlanHeader rollout = (ParsedRolloutPlanHeader) header;
    assertTrue(rollout.endsOnGroupSeparator());
    assertEquals(31, rollout.getLastSeparatorIndex());
}
Also used : ParsedOperationRequestHeader(org.jboss.as.cli.operation.ParsedOperationRequestHeader) ParsedRolloutPlanHeader(org.jboss.as.cli.operation.impl.ParsedRolloutPlanHeader) Test(org.junit.Test)

Example 12 with ParsedOperationRequestHeader

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

the class RolloutPlanParsingTestCase method testMixAgainstWholeRequest.

@Test
public void testMixAgainstWholeRequest() throws Exception {
    parse("/profile=default/subsystem=threads/thread-factory=mytf:do{ rollout " + "groupA(rolling-to-servers=true,max-failure-percentage=20) ^ groupB, groupC," + "groupD(rolling-to-servers=true,max-failed-servers=1) ^ groupE rollback-across-groups}");
    assertTrue(handler.hasAddress());
    assertTrue(handler.hasOperationName());
    assertFalse(handler.hasProperties());
    assertFalse(handler.endsOnAddressOperationNameSeparator());
    assertFalse(handler.endsOnPropertyListStart());
    assertFalse(handler.endsOnPropertySeparator());
    assertFalse(handler.endsOnPropertyValueSeparator());
    assertFalse(handler.endsOnNodeSeparator());
    assertFalse(handler.endsOnNodeTypeNameSeparator());
    assertFalse(handler.endsOnSeparator());
    assertFalse(handler.endsOnHeaderListStart());
    assertTrue(handler.isRequestComplete());
    assertTrue(handler.hasHeaders());
    final Collection<ParsedOperationRequestHeader> headers = handler.getHeaders();
    assertEquals(1, headers.size());
    final ModelNode op = handler.toOperationRequest(ctx);
    assertTrue(op.hasDefined(Util.OPERATION_HEADERS));
    final ModelNode headersNode = op.get(Util.OPERATION_HEADERS);
    final ModelNode expectedHeaders = new ModelNode();
    final ModelNode rolloutPlan = expectedHeaders.get(Util.ROLLOUT_PLAN);
    final ModelNode inSeries = rolloutPlan.get(Util.IN_SERIES);
    ModelNode concurrent = new ModelNode();
    ModelNode cg = concurrent.get(Util.CONCURRENT_GROUPS);
    ModelNode group = cg.get("groupA");
    group.get("rolling-to-servers").set("true");
    group.get("max-failure-percentage").set("20");
    group = cg.get("groupB");
    inSeries.add().set(concurrent);
    ModelNode sg = new ModelNode();
    group = sg.get(Util.SERVER_GROUP);
    group.get("groupC");
    inSeries.add().set(sg);
    concurrent = new ModelNode();
    cg = concurrent.get(Util.CONCURRENT_GROUPS);
    group = cg.get("groupD");
    group.get("rolling-to-servers").set("true");
    group.get("max-failed-servers").set("1");
    cg.get("groupE");
    inSeries.add().set(concurrent);
    rolloutPlan.get("rollback-across-groups").set("true");
    assertEquals(expectedHeaders, headersNode);
}
Also used : ParsedOperationRequestHeader(org.jboss.as.cli.operation.ParsedOperationRequestHeader) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 13 with ParsedOperationRequestHeader

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

the class HeadersArgumentValueConverter method fromNonDMRString.

@Override
protected ModelNode fromNonDMRString(CommandContext ctx, String value) throws CommandFormatException {
    callback.reset();
    ParserUtil.parse(value, callback, initialState);
    final Collection<ParsedOperationRequestHeader> headers = callback.getHeaders();
    if (headers.isEmpty()) {
        throw new CommandFormatException("'" + value + "' doesn't follow format {[rollout server_group_list [rollback-across-groups];] (<header_name>=<header_value>;)*}");
    }
    final ModelNode node = new ModelNode();
    for (ParsedOperationRequestHeader header : headers) {
        header.addTo(ctx, node);
    }
    return node;
}
Also used : ParsedOperationRequestHeader(org.jboss.as.cli.operation.ParsedOperationRequestHeader) CommandFormatException(org.jboss.as.cli.CommandFormatException) ModelNode(org.jboss.dmr.ModelNode)

Example 14 with ParsedOperationRequestHeader

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

the class Util method toOperationRequest.

private static ModelNode toOperationRequest(CommandContext ctx, ParsedCommandLine parsedLine, Attachments attachments, boolean description) throws CommandFormatException {
    if (parsedLine.getFormat() != OperationFormat.INSTANCE) {
        throw new OperationFormatException("The line does not follow the operation request format");
    }
    ModelNode request = new ModelNode();
    ModelNode addressNode = request.get(Util.ADDRESS);
    if (parsedLine.getAddress().isEmpty()) {
        addressNode.setEmptyList();
    } else {
        Iterator<Node> iterator = parsedLine.getAddress().iterator();
        while (iterator.hasNext()) {
            OperationRequestAddress.Node node = iterator.next();
            if (node.getName() != null) {
                addressNode.add(node.getType(), node.getName());
            } else if (iterator.hasNext()) {
                throw new OperationFormatException("The node name is not specified for type '" + node.getType() + "'");
            }
        }
    }
    final String operationName = parsedLine.getOperationName();
    if (operationName == null || operationName.isEmpty()) {
        throw new OperationFormatException("The operation name is missing or the format of the operation request is wrong.");
    }
    request.get(Util.OPERATION).set(operationName);
    ModelNode outcome = null;
    if (description) {
        outcome = (ModelNode) ctx.get(Scope.REQUEST, DESCRIPTION_RESPONSE);
        if (outcome == null) {
            outcome = retrieveDescription(ctx, request, false);
            if (outcome != null) {
                ctx.set(Scope.REQUEST, DESCRIPTION_RESPONSE, outcome);
            }
        }
        if (outcome != null) {
            if (!outcome.has(Util.RESULT)) {
                throw new CommandFormatException("Failed to perform " + Util.READ_OPERATION_DESCRIPTION + " to validate the request: result is not available.");
            } else {
                outcome = outcome.get(Util.RESULT).get(Util.REQUEST_PROPERTIES);
            }
        }
    }
    for (String propName : parsedLine.getPropertyNames()) {
        String value = parsedLine.getPropertyValue(propName);
        if (propName == null || propName.trim().isEmpty())
            throw new OperationFormatException("The argument name is not specified: '" + propName + "'");
        if (value == null || value.trim().isEmpty()) {
            throw new OperationFormatException("The argument value is not specified for " + propName + ": '" + value + "'");
        }
        final ModelNode toSet = ArgumentValueConverter.DEFAULT.fromString(ctx, value);
        if (outcome != null && outcome.hasDefined(propName)) {
            try {
                ModelNode p = outcome.get(propName);
                if (p.hasDefined("type")) {
                    applyReplacements(ctx, propName, toSet, p, p.get("type").asType(), attachments);
                }
            } catch (Throwable ex) {
                // System.err.println("FAULTY " + propName + " " + outcome.get(propName));
                throw ex;
            }
        }
        request.get(propName).set(toSet);
    }
    if (parsedLine.getLastHeaderName() != null) {
        throw new OperationFormatException("Header '" + parsedLine.getLastHeaderName() + "' is not complete.");
    }
    final Collection<ParsedOperationRequestHeader> headers = parsedLine.getHeaders();
    if (headers != null && !headers.isEmpty()) {
        final ModelNode headersNode = request.get(Util.OPERATION_HEADERS);
        for (ParsedOperationRequestHeader header : headers) {
            header.addTo(ctx, headersNode);
        }
    }
    return request;
}
Also used : OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) Node(org.jboss.as.cli.operation.OperationRequestAddress.Node) ParsedOperationRequestHeader(org.jboss.as.cli.operation.ParsedOperationRequestHeader) Node(org.jboss.as.cli.operation.OperationRequestAddress.Node) ModelNode(org.jboss.dmr.ModelNode) TerminalString(org.aesh.readline.terminal.formatting.TerminalString) ModelNode(org.jboss.dmr.ModelNode) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress)

Example 15 with ParsedOperationRequestHeader

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

the class DeployCompletionTestCase method assertHasRolloutHeaderWithRef.

private static void assertHasRolloutHeaderWithRef(Collection<ParsedOperationRequestHeader> headers, String planRef) {
    assertEquals("Should have one parsed header", 1, headers.size());
    ParsedOperationRequestHeader rolloutHeader = headers.iterator().next();
    assertEquals("The parsed header should be a rollout header", "rollout", rolloutHeader.getName());
    assertEquals("The rollout header has wrong planRef", planRef, ((ParsedRolloutPlanHeader) rolloutHeader).getPlanRef());
}
Also used : ParsedOperationRequestHeader(org.jboss.as.cli.operation.ParsedOperationRequestHeader)

Aggregations

ParsedOperationRequestHeader (org.jboss.as.cli.operation.ParsedOperationRequestHeader)27 Test (org.junit.Test)22 ParsedRolloutPlanHeader (org.jboss.as.cli.operation.impl.ParsedRolloutPlanHeader)19 ModelNode (org.jboss.dmr.ModelNode)13 SingleRolloutPlanGroup (org.jboss.as.cli.operation.impl.SingleRolloutPlanGroup)7 CommandFormatException (org.jboss.as.cli.CommandFormatException)2 TerminalString (org.aesh.readline.terminal.formatting.TerminalString)1 OperationFormatException (org.jboss.as.cli.operation.OperationFormatException)1 OperationRequestAddress (org.jboss.as.cli.operation.OperationRequestAddress)1 Node (org.jboss.as.cli.operation.OperationRequestAddress.Node)1