Ejemplo n.º 1
0
 /**
  * User-initiated commands use this method.
  *
  * @param command The CLI command
  * @return A Response object containing the command line, DMR request, and DMR response
  * @throws CommandFormatException
  * @throws IOException
  */
 public synchronized Response doCommandFullResponse(String command)
     throws CommandFormatException, IOException {
   ModelNode request = cmdCtx.buildRequest(command);
   boolean replacedBytes = replaceFilePathsWithBytes(request);
   OperationResponse response = execute(request, isSlowCommand(command) || replacedBytes);
   return new Response(command, request, response);
 }
  @Test
  @InSequence(2)
  public void testModClusterRemove() throws Exception {
    final CommandContext ctx = CLITestUtil.getCommandContext();
    final ModelControllerClient controllerClient = managementClient.getControllerClient();

    try {
      ctx.connectController();

      // Test subsystem remove
      ModelNode request = ctx.buildRequest("/subsystem=modcluster:remove");
      ModelNode response = controllerClient.execute(request);
      String outcome = response.get("outcome").asString();
      Assert.assertEquals(
          "Removing mod_cluster subsystem failed! " + request.toJSONString(false),
          "success",
          outcome);

      // Cleanup socket binding
      request =
          ctx.buildRequest(
              "/socket-binding-group=standard-sockets/socket-binding=mod_cluster:remove");
      response = controllerClient.execute(request);
      outcome = response.get("outcome").asString();
      Assert.assertEquals(
          "Removing socket binding failed! " + request.toJSONString(false), "success", outcome);

      // Cleanup and remove the extension
      request = ctx.buildRequest("/extension=org.wildfly.extension.mod_cluster:remove");
      response = controllerClient.execute(request);
      outcome = response.get("outcome").asString();
      Assert.assertEquals(
          "Removing mod_cluster extension failed! " + request.toJSONString(false),
          "success",
          outcome);
    } finally {
      ctx.terminateSession();
    }
  }
  @Test
  @InSequence(1)
  public void testModClusterAdd() throws Exception {
    final CommandContext ctx = CLITestUtil.getCommandContext();
    final ModelControllerClient controllerClient = managementClient.getControllerClient();

    try {
      ctx.connectController();

      // Add the mod_cluster extension first (not in this profile by default)
      ModelNode request = ctx.buildRequest("/extension=org.wildfly.extension.mod_cluster:add");
      ModelNode response = controllerClient.execute(request);
      String outcome = response.get("outcome").asString();
      Assert.assertEquals(
          "Adding mod_cluster extension failed! " + request.toJSONString(false),
          "success",
          outcome);

      // Now lets execute subsystem add operation but we need to specify a connector
      ctx.getBatchManager().activateNewBatch();
      Batch b = ctx.getBatchManager().getActiveBatch();
      b.add(
          ctx.toBatchedCommand(
              "/socket-binding-group=standard-sockets/socket-binding=mod_cluster:add(multicast-port=23364, multicast-address=224.0.1.105)"));
      b.add(ctx.toBatchedCommand("/subsystem=modcluster:add"));
      b.add(
          ctx.toBatchedCommand(
              "/subsystem=modcluster/mod-cluster-config=configuration:add(connector=http,advertise-socket=mod_cluster)"));
      request = b.toRequest();
      b.clear();
      ctx.getBatchManager().discardActiveBatch();

      response = controllerClient.execute(request);
      outcome = response.get("outcome").asString();
      Assert.assertEquals(
          "Adding mod_cluster subsystem failed! " + request.toJSONString(false),
          "success",
          outcome);
    } finally {
      ctx.terminateSession();
    }
  }
Ejemplo n.º 4
0
  /* (non-Javadoc)
   * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
   */
  @Override
  protected void doHandle(CommandContext ctx) throws CommandLineException {

    String argsStr = ctx.getArgumentsString();
    if (argsStr == null) {
      throw new CommandFormatException("The command is missing arguments.");
    }

    final BatchManager batchManager = ctx.getBatchManager();
    if (batchManager.isBatchActive()) {
      throw new CommandFormatException("if is not allowed while in batch mode.");
    }

    final ParsedCommandLine args = ctx.getParsedCommandLine();
    final String conditionStr = this.condition.getValue(args, true);
    int i = argsStr.indexOf(conditionStr);
    if (i < 0) {
      throw new CommandFormatException(
          "Failed to locate '" + conditionStr + "' in '" + argsStr + "'");
    }
    i = argsStr.indexOf("of", i + conditionStr.length());
    if (i < 0) {
      throw new CommandFormatException("Failed to locate 'of' in '" + argsStr + "'");
    }

    final String line = argsStr.substring(i + 2);
    try {
      IfElseBlock.create(ctx).setCondition(conditionStr, ctx.buildRequest(line));
    } catch (CommandLineException e) {
      IfElseBlock.remove(ctx);
      throw e;
    }

    if (!batchManager.activateNewBatch()) {
      IfElseBlock.remove(ctx);
      // that's more like illegal state
      throw new CommandFormatException("Failed to activate batch mode for if.");
    }
  }
Ejemplo n.º 5
0
 /**
  * Submit a command to the server.
  *
  * @param command The CLI command
  * @return The DMR response as a ModelNode
  * @throws CommandFormatException
  * @throws IOException
  */
 public synchronized ModelNode doCommand(String command)
     throws CommandFormatException, IOException {
   ModelNode request = cmdCtx.buildRequest(command);
   return execute(request, isSlowCommand(command)).getResponseNode();
 }