Exemplo n.º 1
0
 public void parseCommandLine(String buffer) throws CommandFormatException {
   try {
     parsedCmd.parse(prefix, buffer);
   } catch (CommandFormatException e) {
     if (!parsedCmd.endsOnAddressOperationNameSeparator() || !parsedCmd.endsOnSeparator()) {
       throw e;
     }
   }
 }
 protected Operation parseExpression(String condition) throws CommandFormatException {
   LINE.parse(ADDRESS, "if " + condition + " of /a=b:c", CTX);
   return CONDITION.resolveOperation(LINE);
 }
  @Test
  public void testRolloutIdWithValue() throws Exception {

    parse(":do{ rollout id = myplan}");

    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());
    assertTrue(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;
    assertEquals("myplan", rollout.getPlanRef());
    assertEquals(18, rollout.getLastChunkIndex());
  }
Exemplo n.º 4
0
 protected void parse(String input) throws OperationFormatException {
   callback.reset();
   parser.parse(input, callback);
 }
  @Test
  public void testSingleHeader() throws Exception {

    parse("/profile=default/subsystem=threads/thread-factory=mytf:do{ name = value }");

    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 ParsedOperationRequestHeader header = headers.iterator().next();

    assertEquals("name", header.getName());
    final ModelNode node = new ModelNode();
    node.get("name").set("value");

    final ModelNode headersNode = new ModelNode();
    header.addTo(ctx, headersNode);
    assertEquals(node, headersNode);
  }
  @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);
  }
  @Test
  public void testTwoConcurrentGroupNames() throws Exception {

    parse("/profile=default/subsystem=threads/thread-factory=mytf:do{ rollout groupA ^ groupB");

    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());
    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 ModelNode node = new ModelNode();
    final ModelNode inSeries = node.get(Util.ROLLOUT_PLAN).get(Util.IN_SERIES);

    final ModelNode concurrent = new ModelNode();
    final ModelNode cg = concurrent.get(Util.CONCURRENT_GROUPS);
    cg.get("groupA");
    cg.get("groupB");

    inSeries.add().set(concurrent);

    final ModelNode headersNode = new ModelNode();
    header.addTo(ctx, headersNode);
    assertEquals(node, headersNode);
  }
  @Test
  public void testMix() 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");

    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());
    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 ModelNode node = new ModelNode();
    final ModelNode inSeries = node.get(Util.ROLLOUT_PLAN).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");

    group = cg.get("groupE");

    inSeries.add().set(concurrent);

    final ModelNode headersNode = new ModelNode();
    header.addTo(ctx, headersNode);
    assertEquals(node, headersNode);
  }
  @Test
  public void testEndsOnGroupConcurrent() 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(32, rollout.getLastSeparatorIndex());
  }
Exemplo n.º 10
0
  @Test
  public void testEmptyHeaders() throws Exception {

    parse("/profile=default/subsystem=threads/thread-factory=mytf:do{}");

    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());
    assertFalse(handler.hasHeaders());
  }
Exemplo n.º 11
0
  @Test
  public void testRolloutSingleGroupWithProps() throws Exception {

    // parse("/profile=default/subsystem=threads/thread-factory=mytf:do{ rollout
    // in-series=groupA(rolling-to-servers=true,max-failure-percentage=20)");
    parse(
        "/profile=default/subsystem=threads/thread-factory=mytf:do{ rollout groupA(rolling-to-servers=true,max-failure-percentage=20)");

    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());
    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 ModelNode node = new ModelNode();
    final ModelNode inSeries = node.get(Util.ROLLOUT_PLAN).get(Util.IN_SERIES);
    final ModelNode groupA = new ModelNode();
    final ModelNode groupProps = groupA.get("groupA");
    groupProps.get("rolling-to-servers").set("true");
    groupProps.get("max-failure-percentage").set("20");
    inSeries.add().get(Util.SERVER_GROUP).set(groupA);

    final ModelNode headersNode = new ModelNode();
    header.addTo(ctx, headersNode);
    assertEquals(node, headersNode);
  }
Exemplo n.º 12
0
  @Test
  public void testEndsOnGroupPropertySeparator() 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);
    ParsedRolloutPlanHeader rollout = (ParsedRolloutPlanHeader) header;
    final SingleRolloutPlanGroup group = rollout.getLastGroup();
    assertNotNull(group);

    assertEquals("groupA", group.getGroupName());
    assertFalse(group.endsOnPropertyListStart());
    assertFalse(group.endsOnPropertyListEnd());
    assertTrue(group.hasProperties());
    assertFalse(group.endsOnPropertyValueSeparator());
    assertNull(group.getLastPropertyName());
    assertNull(group.getLastPropertyValue());

    assertTrue(group.endsOnPropertySeparator());
    assertEquals(29, group.getLastSeparatorIndex());
  }
Exemplo n.º 13
0
 protected void parse(String opReq) throws CommandFormatException {
   handler.reset();
   parser.parse(opReq, handler);
 }
Exemplo n.º 14
0
  @Test
  public void testOnlyHeaderListStart() throws Exception {

    parse("{");

    assertFalse(handler.hasAddress());
    assertFalse(handler.hasOperationName());
    assertFalse(handler.hasProperties());
    assertFalse(handler.endsOnAddressOperationNameSeparator());
    assertFalse(handler.endsOnPropertyListStart());
    assertFalse(handler.endsOnPropertySeparator());
    assertFalse(handler.endsOnPropertyValueSeparator());
    assertFalse(handler.endsOnNodeSeparator());
    assertFalse(handler.endsOnNodeTypeNameSeparator());
    assertTrue(handler.endsOnSeparator());
    assertTrue(handler.endsOnHeaderListStart());
    assertFalse(handler.isRequestComplete());
    assertFalse(handler.hasHeaders());
  }
Exemplo n.º 15
0
  @Test
  public void testRollout() throws Exception {

    parse(":do{rollout");

    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(0, headers.size());
    assertEquals("rollout", handler.getLastHeaderName());
  }