Esempio n. 1
0
  @Override
  protected void doHandle(CommandContext ctx) {

    ModelControllerClient client = ctx.getModelControllerClient();
    ParsedArguments args = ctx.getParsedArguments();
    boolean l = this.l.isPresent(args);
    if (!args.hasArguments() || l) {
      printList(ctx, Util.getDeployments(client), l);
      return;
    }

    final String name = this.name.getValue(ctx.getParsedArguments());

    if (name == null) {
      printList(ctx, Util.getDeployments(client), l);
      return;
    }

    DefaultOperationRequestBuilder builder;

    // undeploy
    builder = new DefaultOperationRequestBuilder();
    builder.setOperationName("undeploy");
    builder.addNode("deployment", name);

    ModelNode result;
    try {
      ModelNode request = builder.buildRequest();
      result = client.execute(request);
    } catch (Exception e) {
      ctx.printLine("Failed to undeploy: " + e.getLocalizedMessage());
      return;
    }

    // TODO undeploy may fail if the content failed to deploy but remove should still be executed
    if (!Util.isSuccess(result)) {
      ctx.printLine("Undeploy failed: " + Util.getFailureDescription(result));
      return;
    }

    // remove
    builder = new DefaultOperationRequestBuilder();
    builder.setOperationName("remove");
    builder.addNode("deployment", name);
    try {
      ModelNode request = builder.buildRequest();
      result = client.execute(request);
    } catch (Exception e) {
      ctx.printLine(
          "Failed to remove the deployment content from the repository: "
              + e.getLocalizedMessage());
      return;
    }
    if (!Util.isSuccess(result)) {
      ctx.printLine("Remove failed: " + Util.getFailureDescription(result));
      return;
    }

    ctx.printLine("Successfully undeployed " + name + ".");
  }
  /* (non-Javadoc)
   * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
   */
  @Override
  protected void doHandle(CommandContext ctx) {

    ModelNode request;
    try {
      request = buildRequest(ctx);
    } catch (OperationFormatException e) {
      ctx.printLine(e.getLocalizedMessage());
      return;
    }

    ModelControllerClient client = ctx.getModelControllerClient();
    final ModelNode result;
    try {
      result = client.execute(request);
    } catch (Exception e) {
      ctx.printLine("Failed to perform operation: " + e.getLocalizedMessage());
      return;
    }

    if (!Util.isSuccess(result)) {
      ctx.printLine(Util.getFailureDescription(result));
      return;
    }

    ctx.printLine("Sucessfully created queue.");
  }
  /* (non-Javadoc)
   * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
   */
  @Override
  protected void doHandle(CommandContext ctx) throws CommandLineException {

    final ModelNode request = buildRequest(ctx);

    final ModelControllerClient client = ctx.getModelControllerClient();
    final OperationResponse operationResponse;
    try {
      operationResponse =
          client.executeOperation(
              Operation.Factory.create(request), OperationMessageHandler.DISCARD);
    } catch (Exception e) {
      throw new CommandLineException("Failed to perform operation", e);
    }
    try {
      final ModelNode response = operationResponse.getResponseNode();
      if (!Util.isSuccess(response)) {
        throw new CommandLineException(Util.getFailureDescription(response));
      }
      handleResponse(
          ctx, operationResponse, Util.COMPOSITE.equals(request.get(Util.OPERATION).asString()));
      operationResponse.close();
    } catch (IOException ex) {
      throw new CommandLineException("Failed to perform operation", ex);
    }
  }
 @Override
 protected void handleResponse(CommandContext ctx, ModelNode opResponse, boolean composite) {
   if (!Util.isSuccess(opResponse)) {
     ctx.printLine(Util.getFailureDescription(opResponse));
     return;
   }
   final StringBuilder buf = formatResponse(ctx, opResponse, composite, null);
   if (buf != null) {
     ctx.printLine(buf.toString());
   }
 }
  /* (non-Javadoc)
   * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
   */
  @Override
  protected void doHandle(CommandContext ctx) {

    if (!ctx.hasArguments()) {
      ctx.printLine("Missing required argument 'name'.");
      return;
    }

    String name = ctx.getNamedArgument("name");
    if (name == null) {
      List<String> args = ctx.getArguments();
      if (!args.isEmpty()) {
        name = args.get(0);
      }
    }

    if (name == null) {
      ctx.printLine("Missing required argument 'name'.");
      return;
    }

    ModelControllerClient client = ctx.getModelControllerClient();

    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
    builder.addNode("subsystem", "jms");
    builder.addNode("connection-factory", name);
    builder.setOperationName("remove");

    final ModelNode result;
    try {
      ModelNode request = builder.buildRequest();
      result = client.execute(request);
    } catch (Exception e) {
      ctx.printLine("Failed to perform operation: " + e.getLocalizedMessage());
      return;
    }

    if (!Util.isSuccess(result)) {
      ctx.printLine(
          "Failed to delete connection factory '"
              + name
              + "': "
              + Util.getFailureDescription(result));
      return;
    }

    ctx.printLine("Removed connection factory " + name);
  }
Esempio n. 6
0
  @Override
  protected void doHandle(CommandContext ctx) {

    ModelControllerClient client = ctx.getModelControllerClient();

    if (!ctx.hasArguments()) {
      printList(ctx, Util.getDeployments(client));
      return;
    }

    String filePath = null;
    String name = null;
    String runtimeName = null;

    for (String arg : ctx.getArguments()) {
      if (filePath == null) {
        filePath = arg;
      } else if (name == null) {
        name = arg;
      } else {
        runtimeName = arg;
      }
    }

    if (filePath == null) {
      printList(ctx, Util.getDeployments(client));
      return;
    }

    File f = new File(filePath);
    if (!f.exists()) {
      ctx.printLine("The path doesn't exist: " + f.getAbsolutePath());
      return;
    }

    if (name == null) {
      name = f.getName();
    }

    if (Util.isDeployed(name, client)) {
      if (ctx.hasSwitch("f")) {
        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();

        ModelNode result;

        // replace
        builder = new DefaultOperationRequestBuilder();
        builder.setOperationName("full-replace-deployment");
        builder.addProperty("name", name);
        if (runtimeName != null) {
          builder.addProperty("runtime-name", runtimeName);
        }

        FileInputStream is = null;
        try {
          is = new FileInputStream(f);
          ModelNode request = builder.buildRequest();
          OperationBuilder op = OperationBuilder.Factory.create(request);
          op.addInputStream(is);
          request.get("input-stream-index").set(0);
          result = client.execute(op.build());
        } catch (Exception e) {
          ctx.printLine("Failed to replace the deployment: " + e.getLocalizedMessage());
          return;
        } finally {
          StreamUtils.safeClose(is);
        }
        if (!Util.isSuccess(result)) {
          ctx.printLine(Util.getFailureDescription(result));
          return;
        }

        ctx.printLine("'" + name + "' re-deployed successfully.");
      } else {
        ctx.printLine("'" + name + "' is already deployed (use -f to force re-deploy).");
      }

      return;
    } else {

      DefaultOperationRequestBuilder builder;

      ModelNode result;

      // add
      builder = new DefaultOperationRequestBuilder();
      builder.setOperationName("add");
      builder.addNode("deployment", name);
      if (runtimeName != null) {
        builder.addProperty("runtime-name", runtimeName);
      }

      FileInputStream is = null;
      try {
        is = new FileInputStream(f);
        ModelNode request = builder.buildRequest();
        OperationBuilder op = OperationBuilder.Factory.create(request);
        op.addInputStream(is);
        request.get("input-stream-index").set(0);
        result = client.execute(op.build());
      } catch (Exception e) {
        ctx.printLine(
            "Failed to add the deployment content to the repository: " + e.getLocalizedMessage());
        return;
      } finally {
        StreamUtils.safeClose(is);
      }
      if (!Util.isSuccess(result)) {
        ctx.printLine(Util.getFailureDescription(result));
        return;
      }

      // deploy
      builder = new DefaultOperationRequestBuilder();
      builder.setOperationName("deploy");
      builder.addNode("deployment", name);
      try {
        ModelNode request = builder.buildRequest();
        result = client.execute(request);
      } catch (Exception e) {
        ctx.printLine("Failed to deploy: " + e.getLocalizedMessage());
        return;
      }
      if (!Util.isSuccess(result)) {
        ctx.printLine(Util.getFailureDescription(result));
        return;
      }
      ctx.printLine("'" + name + "' deployed successfully.");
    }
  }