Ejemplo 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 + ".");
  }
Ejemplo n.º 2
0
  /* (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);
    }
  }
  /* (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.CandidatesProvider#getNodeTypes(org.jboss.as.cli.Prefix)
   */
  @Override
  public List<String> getNodeTypes(OperationRequestAddress prefix) {

    ModelControllerClient client = ctx.getModelControllerClient();
    if (client == null) {
      return Collections.emptyList();
    }

    if (prefix.endsOnType()) {
      throw new IllegalArgumentException("The prefix isn't expected to end on a type.");
    }

    ModelNode request;
    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(prefix);
    try {
      builder.operationName("read-children-types");
      request = builder.buildRequest();
    } catch (OperationFormatException e1) {
      throw new IllegalStateException("Failed to build operation", e1);
    }

    List<String> result;
    try {
      ModelNode outcome = client.execute(request);
      if (!Util.isSuccess(outcome)) {
        // TODO logging... exception?
        result = Collections.emptyList();
      } else {
        result = Util.getList(outcome);
      }
    } catch (Exception e) {
      result = Collections.emptyList();
    }
    return result;
  }
Ejemplo n.º 5
0
 @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());
   }
 }
Ejemplo n.º 6
0
  /* (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);
  }
Ejemplo n.º 7
0
  public ModelNode execute(ModelNode operation, boolean awaitClose) throws IOException {
    final ModelNode response = super.execute(operation);
    if (!Util.isSuccess(response)) {
      return response;
    }

    if (awaitClose) {
      synchronized (this) {
        try {
          if (strategy == null) {
            throw new IOException("Connection has been closed.");
          }
          strategy.getChannel().getConnection().awaitClosed();
        } catch (InterruptedException e) {
        }
      }
    }
    return response;
  }
Ejemplo n.º 8
0
  public ModelNode execute(ModelNode operation, boolean awaitClose) throws IOException {
    final ModelNode response = super.execute(operation);
    if (!Util.isSuccess(response)) {
      return response;
    }

    if (awaitClose) {
      synchronized (lock) {
        if (strategy != null) {
          try {
            lock.wait(5000);
          } catch (InterruptedException e) {
          }
          StreamUtils.safeClose(strategy);
          strategy = null;
        }
      }
    }

    return response;
  }
  @Override
  public List<String> getPropertyNames(String operationName, OperationRequestAddress address) {

    ModelControllerClient client = ctx.getModelControllerClient();
    if (client == null) {
      return Collections.emptyList();
    }

    if (address.endsOnType()) {
      throw new IllegalArgumentException("The prefix isn't expected to end on a type.");
    }

    ModelNode request;
    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(address);
    try {
      builder.operationName("read-operation-description");
      builder.property("name", operationName, -1);
      request = builder.buildRequest();
    } catch (OperationFormatException e1) {
      throw new IllegalStateException("Failed to build operation", e1);
    }

    List<String> result;
    try {
      ModelNode outcome = client.execute(request);
      if (!Util.isSuccess(outcome)) {
        result = Collections.emptyList();
      } else {
        outcome.get("request-properties");
        result = Util.getRequestPropertyNames(outcome);
      }
    } catch (Exception e) {
      result = Collections.emptyList();
    }
    return result;
  }
Ejemplo n.º 10
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.");
    }
  }