Ejemplo n.º 1
0
  @Override
  protected void printHelp(CommandContext ctx) {

    ParsedCommandLine args = ctx.getParsedCommandLine();
    try {
      if (helpProperties.isPresent(args)) {
        try {
          printProperties(ctx, getNodeProperties(ctx));
        } catch (Exception e) {
          ctx.error("Failed to obtain the list or properties: " + e.getLocalizedMessage());
          return;
        }
        return;
      }
    } catch (CommandFormatException e) {
      ctx.error(e.getLocalizedMessage());
      return;
    }

    try {
      if (helpCommands.isPresent(args)) {
        printCommands(ctx);
        return;
      }
    } catch (CommandFormatException e) {
      ctx.error(e.getLocalizedMessage());
      return;
    }

    final String operationName = operation.getValue(args);
    if (operationName == null) {
      printNodeDescription(ctx);
      return;
    }

    try {
      ModelNode result = getOperationDescription(ctx, operationName);
      if (!result.hasDefined(Util.DESCRIPTION)) {
        ctx.error("Operation description is not available.");
        return;
      }

      final StringBuilder buf = new StringBuilder();
      buf.append("\nDESCRIPTION:\n\n");
      buf.append(result.get(Util.DESCRIPTION).asString());
      ctx.printLine(buf.toString());

      if (result.hasDefined(Util.REQUEST_PROPERTIES)) {
        printProperties(ctx, result.get(Util.REQUEST_PROPERTIES).asPropertyList());
      } else {
        printProperties(ctx, Collections.<Property>emptyList());
      }
    } catch (Exception e) {
    }
  }
Ejemplo n.º 2
0
 protected StringBuilder formatResponse(
     CommandContext ctx, ModelNode opResponse, boolean composite, StringBuilder buf) {
   if (!opResponse.hasDefined(Util.RESULT)) {
     return null;
   }
   final ModelNode result = opResponse.get(Util.RESULT);
   if (composite) {
     final Set<String> keys;
     try {
       keys = result.keys();
     } catch (Exception e) {
       ctx.error("Failed to get step results from a composite operation response " + opResponse);
       e.printStackTrace();
       return null;
     }
     for (String key : keys) {
       final ModelNode stepResponse = result.get(key);
       buf =
           formatResponse(
               ctx, stepResponse, false, buf); // TODO nested composite ops aren't expected for now
     }
   } else {
     final ModelNodeFormatter formatter = ModelNodeFormatter.Factory.forType(result.getType());
     if (buf == null) {
       buf = new StringBuilder();
     }
     formatter.format(buf, 0, result);
   }
   return buf;
 }
Ejemplo n.º 3
0
 @Override
 protected void handleResponse(CommandContext ctx, ModelNode opResponse, boolean composite) {
   // System.out.println(opResponse);
   if (!Util.isSuccess(opResponse)) {
     ctx.error(Util.getFailureDescription(opResponse));
     return;
   }
   final StringBuilder buf = formatResponse(ctx, opResponse, composite, null);
   if (buf != null) {
     ctx.printLine(buf.toString());
   }
 }
Ejemplo n.º 4
0
 protected ModelNode initRequest(CommandContext ctx) {
   ModelNode request = new ModelNode();
   ModelNode address = request.get(Util.ADDRESS);
   if (isDependsOnProfile() && ctx.isDomainMode()) {
     final String profileName = profile.getValue(ctx.getParsedCommandLine());
     if (profileName == null) {
       ctx.error("--profile argument is required to get the node description.");
       return null;
     }
     address.add(Util.PROFILE, profileName);
   }
   for (OperationRequestAddress.Node node : getRequiredAddress()) {
     address.add(node.getType(), node.getName());
   }
   address.add(getRequiredType(), "?");
   return request;
 }
Ejemplo n.º 5
0
 protected void printCommands(CommandContext ctx) {
   ModelNode request = initRequest(ctx);
   if (request == null) {
     return;
   }
   request.get(Util.OPERATION).set(Util.READ_OPERATION_NAMES);
   try {
     ModelNode result = ctx.getModelControllerClient().execute(request);
     if (!result.hasDefined(Util.RESULT)) {
       ctx.error("Operation names aren't available.");
       return;
     }
     final List<String> list = Util.getList(result);
     list.removeAll(this.excludeOps);
     list.add(
         "To read the description of a specific command execute '"
             + this.commandName
             + " command_name --help'.");
     for (String name : list) {
       ctx.printLine(name);
     }
   } catch (Exception e) {
   }
 }
Ejemplo n.º 6
0
  protected void printNodeDescription(CommandContext ctx) {

    final StringBuilder buf = new StringBuilder();

    buf.append("\nSYNOPSIS\n\n");
    buf.append(commandName).append(" --help [--properties | --commands] |\n");
    for (int i = 0; i <= commandName.length(); ++i) {
      buf.append(' ');
    }
    buf.append(name.getFullName())
        .append("=<value> --<property>=<value> (--<property>=<value>)* |\n");
    for (int i = 0; i <= commandName.length(); ++i) {
      buf.append(' ');
    }
    buf.append("<command> ").append(name.getFullName()).append("=<value> (--<parameter>=<value>)*");

    buf.append("\n\nDESCRIPTION\n\n");
    buf.append("The command is used to manage resources of type " + this.nodeType + ".");

    buf.append("\n\nRESOURCE DESCRIPTION\n\n");

    if (isDependsOnProfile()
        && ctx.isDomainMode()
        && profile.getValue(ctx.getParsedCommandLine()) == null) {
      buf.append("(Execute '");
      buf.append(commandName)
          .append(" --profile=<profile_name> --help' to include the resource description here.)");
    } else {
      ModelNode request = initRequest(ctx);
      if (request == null) {
        return;
      }
      request.get(Util.OPERATION).set(Util.READ_RESOURCE_DESCRIPTION);
      ModelNode result = null;
      try {
        result = ctx.getModelControllerClient().execute(request);
        if (!result.hasDefined(Util.RESULT)) {
          ctx.error("Node description is not available.");
          return;
        }
        result = result.get(Util.RESULT);
        if (!result.hasDefined(Util.DESCRIPTION)) {
          ctx.error("Node description is not available.");
          return;
        }
      } catch (Exception e) {
      }

      if (result != null) {
        buf.append(result.get(Util.DESCRIPTION).asString());
      } else {
        buf.append(
            "N/A. Please, open a jira issue at https://issues.jboss.org/browse/AS7 to get this fixed. Thanks!");
      }
    }

    buf.append("\n\nARGUMENTS\n");

    buf.append("\n--help                - prints this content.");
    buf.append(
        "\n--help --properties   - prints the list of the resource properties including their access-type");
    buf.append("\n                        (read/write/metric), value type, and the description.");
    buf.append(
        "\n--help --commands     - prints the list of the commands available for the resource.");
    buf.append(
        "\n                        To get the complete description of a specific command (including its parameters,");
    buf.append("\n                        their types and descriptions), execute ")
        .append(commandName)
        .append(" <command> --help.");

    buf.append("\n\n").append(name.getFullName()).append("   - ");
    if (idProperty == null) {
      buf.append("is the name of the resource that completes the path ")
          .append(nodeType)
          .append(" and \n");
    } else {
      buf.append("corresponds to a property of the resourse which \n");
    }
    for (int i = 0; i < name.getFullName().length() + 5; ++i) {
      buf.append(' ');
    }
    buf.append("is used to identify the resourse against which the command should be executed.");

    buf.append("\n\n<property>   - property name of the resourse whose value should be updated.");
    buf.append(
        "\n               For a complete list of available property names, their types and descriptions,");
    buf.append("\n               execute ").append(commandName).append(" --help --properties.");

    buf.append(
        "\n\n<command>    - command name provided by the resourse. For a complete list of available commands,");
    buf.append("\n               execute ").append(commandName).append(" --help --commands.");

    buf.append("\n\n<parameter>  - parameter name of the <command> provided by the resourse.");
    buf.append(
        "\n               For a complete list of available parameter names of a specific <command>,");
    buf.append("\n               their types and descriptions, execute ")
        .append(commandName)
        .append(" <command> --help.");

    ctx.printLine(buf.toString());
  }