示例#1
0
    /** {@inheritDoc} */
    @Override
    protected MenuResult<TaskEntry> invoke(ManageTasks app) throws ClientException {
      TaskEntry taskEntry = null;
      try {
        taskEntry = app.getTaskClient().getTaskEntry(taskId);
        List<LocalizableMessage> logs = taskEntry.getLogMessages();
        app.getOutputStream().println();

        // Create a table for the last log entry
        TableBuilder table = new TableBuilder();
        table.appendHeading(INFO_TASKINFO_FIELD_LOG.get());
        if (logs != null && !logs.isEmpty()) {
          for (LocalizableMessage log : logs) {
            table.startRow();
            table.appendCell(log);
          }
        } else {
          table.startRow();
          table.appendCell(INFO_TASKINFO_NONE.get());
        }
        StringWriter sw = new StringWriter();
        TextTablePrinter tablePrinter = new TextTablePrinter(sw);
        tablePrinter.setTotalWidth(80);
        tablePrinter.setIndentWidth(INDENT);
        tablePrinter.setColumnWidth(0, 0);
        table.print(tablePrinter);
        app.getOutputStream().println(LocalizableMessage.raw(sw.getBuffer().toString()));
        app.getOutputStream().println();
      } catch (Exception e) {
        app.println(ERR_TASKINFO_ACCESSING_LOGS.get(taskId, e.getMessage()));
      }
      return MenuResult.success(taskEntry);
    }
示例#2
0
 /** {@inheritDoc} */
 @Override
 public MenuResult<TaskEntry> invoke(ManageTasks app) throws ClientException {
   try {
     TaskEntry entry = app.getTaskClient().getTaskEntry(taskId);
     if (entry.isCancelable()) {
       app.getTaskClient().cancelTask(taskId);
       app.println(INFO_TASKINFO_CMD_CANCEL_SUCCESS.get(taskId));
       return MenuResult.success(entry);
     } else {
       app.println(ERR_TASKINFO_TASK_NOT_CANCELABLE_TASK.get(taskId));
       return MenuResult.again();
     }
   } catch (Exception e) {
     app.println(ERR_TASKINFO_CANCELING_TASK.get(taskId, e.getMessage()));
     return MenuResult.again();
   }
 }
示例#3
0
    /** {@inheritDoc} */
    @Override
    public MenuResult<Void> invoke(ManageTasks app) throws ClientException {
      MenuResult<TaskEntry> res = new PrintTaskInfo(taskId).invoke(app);
      TaskEntry taskEntry = res.getValue();
      if (taskEntry != null) {
        while (true) {
          try {
            taskEntry = app.getTaskClient().getTaskEntry(taskId);

            // Show the menu
            MenuBuilder<TaskEntry> menuBuilder = new MenuBuilder<>(app);
            menuBuilder.addBackOption(true);
            menuBuilder.addCharOption(
                INFO_TASKINFO_CMD_REFRESH_CHAR.get(),
                INFO_TASKINFO_CMD_REFRESH.get(),
                new PrintTaskInfo(taskId));
            List<LocalizableMessage> logs = taskEntry.getLogMessages();
            if (logs != null && !logs.isEmpty()) {
              menuBuilder.addCharOption(
                  INFO_TASKINFO_CMD_VIEW_LOGS_CHAR.get(),
                  INFO_TASKINFO_CMD_VIEW_LOGS.get(),
                  new ViewTaskLogs(taskId));
            }
            if (taskEntry.isCancelable() && !taskEntry.isDone()) {
              menuBuilder.addCharOption(
                  INFO_TASKINFO_CMD_CANCEL_CHAR.get(),
                  INFO_TASKINFO_CMD_CANCEL.get(),
                  new CancelTask(taskId));
            }
            menuBuilder.addQuitOption();
            Menu<TaskEntry> menu = menuBuilder.toMenu();
            MenuResult<TaskEntry> result = menu.run();
            if (result.isCancel()) {
              break;
            } else if (result.isQuit()) {
              System.exit(0);
            }
          } catch (Exception e) {
            app.println(LocalizableMessage.raw(StaticUtils.getExceptionMessage(e)));
          }
        }
      } else {
        app.println(ERR_TASKINFO_UNKNOWN_TASK_ENTRY.get(taskId));
      }
      return MenuResult.success();
    }
示例#4
0
    /** {@inheritDoc} */
    @Override
    public MenuResult<Void> invoke(ManageTasks app) throws ClientException {
      if (taskIds != null && !taskIds.isEmpty()) {
        if (cancelableIndices != null && !cancelableIndices.isEmpty()) {

          // Prompt for the task number
          Integer index = null;
          String line =
              app.readLineOfInput(
                  INFO_TASKINFO_CMD_CANCEL_NUMBER_PROMPT.get(cancelableIndices.get(0)));
          if (line.length() == 0) {
            line = String.valueOf(cancelableIndices.get(0));
          }
          try {
            int i = Integer.parseInt(line);
            if (!cancelableIndices.contains(i)) {
              app.println(ERR_TASKINFO_NOT_CANCELABLE_TASK_INDEX.get(i));
            } else {
              index = i - 1;
            }
          } catch (NumberFormatException nfe) {
            // ignore;
          }
          if (index != null) {
            String taskId = taskIds.get(index);
            try {
              CancelTask ct = new CancelTask(taskId);
              MenuResult<TaskEntry> result = ct.invoke(app);
              if (result.isSuccess()) {
                return MenuResult.success();
              } else {
                return MenuResult.again();
              }
            } catch (Exception e) {
              app.println(ERR_TASKINFO_CANCELING_TASK.get(taskId, e.getMessage()));
              return MenuResult.again();
            }
          } else {
            app.println(ERR_TASKINFO_INVALID_MENU_KEY.get(line));
            return MenuResult.again();
          }
        } else {
          app.println(INFO_TASKINFO_NO_CANCELABLE_TASKS.get());
          return MenuResult.cancel();
        }
      } else {
        app.println(INFO_TASKINFO_NO_TASKS.get());
        return MenuResult.cancel();
      }
    }
  /** {@inheritDoc} */
  public void runTask() {
    state = State.RUNNING;
    lastException = null;
    try {
      final int totalNumber = tasks.size();
      int numberCanceled = 0;

      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              getProgressDialog().getProgressBar().setIndeterminate(true);
            }
          });
      for (final TaskEntry task : tasks) {
        final ArrayList<String> arguments = getCommandLineArguments(task);

        final boolean isFirst = numberCanceled == 0;
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                if (isFirst) {
                  getProgressDialog().appendProgressHtml("<br><br>");
                }
                ArrayList<String> args = new ArrayList<String>();
                args.addAll(getObfuscatedCommandLineArguments(arguments));
                printEquivalentCommandLine(
                    getCommandLinePath("manage-tasks"),
                    args,
                    INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_CANCEL_TASK.get(task.getId()));
              }
            });

        String[] args = new String[arguments.size()];

        arguments.toArray(args);

        returnCode =
            ManageTasks.mainTaskInfo(args, System.in, outPrintStream, errorPrintStream, false);
        if (returnCode != 0) {
          break;
        } else {
          numberCanceled++;
          final int fNumberCanceled = numberCanceled;
          SwingUtilities.invokeLater(
              new Runnable() {
                public void run() {
                  if (fNumberCanceled == 1) {
                    getProgressDialog().getProgressBar().setIndeterminate(false);
                  }
                  getProgressDialog()
                      .getProgressBar()
                      .setValue((fNumberCanceled * 100) / totalNumber);
                }
              });
        }
      }
      if (returnCode != 0) {
        state = State.FINISHED_WITH_ERROR;
      } else {
        state = State.FINISHED_SUCCESSFULLY;
      }
    } catch (Throwable t) {
      lastException = t;
      state = State.FINISHED_WITH_ERROR;
    }
  }
示例#6
0
    /** {@inheritDoc} */
    @Override
    public MenuResult<TaskEntry> invoke(ManageTasks app) throws ClientException {
      LocalizableMessage m;
      TaskEntry taskEntry;
      try {
        taskEntry = app.getTaskClient().getTaskEntry(taskId);

        TableBuilder table = new TableBuilder();
        table.appendHeading(INFO_TASKINFO_DETAILS.get());

        table.startRow();
        table.appendCell(INFO_TASKINFO_FIELD_ID.get());
        table.appendCell(taskEntry.getId());

        table.startRow();
        table.appendCell(INFO_TASKINFO_FIELD_TYPE.get());
        table.appendCell(taskEntry.getType());

        table.startRow();
        table.appendCell(INFO_TASKINFO_FIELD_STATUS.get());
        table.appendCell(taskEntry.getState());

        table.startRow();
        table.appendCell(INFO_TASKINFO_FIELD_SCHEDULED_START.get());

        if (TaskState.isRecurring(taskEntry.getTaskState())) {
          m = taskEntry.getScheduleTab();
          table.appendCell(m);
        } else {
          m = taskEntry.getScheduledStartTime();
          if (m == null || m.equals(LocalizableMessage.EMPTY)) {
            table.appendCell(INFO_TASKINFO_IMMEDIATE_EXECUTION.get());
          } else {
            table.appendCell(m);
          }

          table.startRow();
          table.appendCell(INFO_TASKINFO_FIELD_ACTUAL_START.get());
          table.appendCell(taskEntry.getActualStartTime());

          table.startRow();
          table.appendCell(INFO_TASKINFO_FIELD_COMPLETION_TIME.get());
          table.appendCell(taskEntry.getCompletionTime());
        }

        writeMultiValueCells(
            table, INFO_TASKINFO_FIELD_DEPENDENCY.get(), taskEntry.getDependencyIds());

        table.startRow();
        table.appendCell(INFO_TASKINFO_FIELD_FAILED_DEPENDENCY_ACTION.get());
        m = taskEntry.getFailedDependencyAction();
        table.appendCell(m != null ? m : INFO_TASKINFO_NONE.get());

        writeMultiValueCells(
            table,
            INFO_TASKINFO_FIELD_NOTIFY_ON_COMPLETION.get(),
            taskEntry.getCompletionNotificationEmailAddresses(),
            INFO_TASKINFO_NONE_SPECIFIED.get());

        writeMultiValueCells(
            table,
            INFO_TASKINFO_FIELD_NOTIFY_ON_ERROR.get(),
            taskEntry.getErrorNotificationEmailAddresses(),
            INFO_TASKINFO_NONE_SPECIFIED.get());

        StringWriter sw = new StringWriter();
        TextTablePrinter tablePrinter = new TextTablePrinter(sw);
        tablePrinter.setTotalWidth(80);
        tablePrinter.setIndentWidth(INDENT);
        tablePrinter.setColumnWidth(1, 0);
        table.print(tablePrinter);
        app.getOutputStream().println();
        app.getOutputStream().println(LocalizableMessage.raw(sw.getBuffer().toString()));

        // Create a table for the task options
        table = new TableBuilder();
        table.appendHeading(INFO_TASKINFO_OPTIONS.get(taskEntry.getType()));
        Map<LocalizableMessage, List<String>> taskSpecificAttrs =
            taskEntry.getTaskSpecificAttributeValuePairs();
        for (LocalizableMessage attrName : taskSpecificAttrs.keySet()) {
          table.startRow();
          table.appendCell(attrName);
          List<String> values = taskSpecificAttrs.get(attrName);
          if (!values.isEmpty()) {
            table.appendCell(values.get(0));
          }
          if (values.size() > 1) {
            for (int i = 1; i < values.size(); i++) {
              table.startRow();
              table.appendCell();
              table.appendCell(values.get(i));
            }
          }
        }
        sw = new StringWriter();
        tablePrinter = new TextTablePrinter(sw);
        tablePrinter.setTotalWidth(80);
        tablePrinter.setIndentWidth(INDENT);
        tablePrinter.setColumnWidth(1, 0);
        table.print(tablePrinter);
        app.getOutputStream().println(LocalizableMessage.raw(sw.getBuffer().toString()));

        // Print the last log message if any
        List<LocalizableMessage> logs = taskEntry.getLogMessages();
        if (logs != null && !logs.isEmpty()) {
          // Create a table for the last log entry
          table = new TableBuilder();
          table.appendHeading(INFO_TASKINFO_FIELD_LAST_LOG.get());
          table.startRow();
          table.appendCell(logs.get(logs.size() - 1));

          sw = new StringWriter();
          tablePrinter = new TextTablePrinter(sw);
          tablePrinter.setTotalWidth(80);
          tablePrinter.setIndentWidth(INDENT);
          tablePrinter.setColumnWidth(0, 0);
          table.print(tablePrinter);
          app.getOutputStream().println(LocalizableMessage.raw(sw.getBuffer().toString()));
        }

        app.getOutputStream().println();
      } catch (Exception e) {
        app.println(ERR_TASKINFO_RETRIEVING_TASK_ENTRY.get(taskId, e.getMessage()));
        return MenuResult.again();
      }
      return MenuResult.success(taskEntry);
    }
示例#7
0
 /**
  * Processes the command-line arguments and invokes the export process.
  *
  * @param args The command-line arguments provided to this
  * @param in Input stream from which to solicit user input.
  * @param out The output stream to use for standard output, or {@code null} if standard output is
  *     not needed.
  * @param err The output stream to use for standard error, or {@code null} if standard error is
  *     not needed.
  * @param initializeServer Indicates whether to initialize the server.
  * @return int return code
  */
 public static int mainTaskInfo(
     String[] args, InputStream in, OutputStream out, OutputStream err, boolean initializeServer) {
   ManageTasks tool = new ManageTasks(in, out, err);
   return tool.process(args, initializeServer);
 }