@Override
 public void done(String message, Exception e) {
   if (emitOutput) {
     System.out.println(
         '\n'
             + "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");
     System.out.println("  RunBook : " + runbook.getRunBookPath() + "  |  " + " State : COMPLETE");
     System.out.println("  Error Reason :");
     e.printStackTrace();
     System.out.println(
         "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-"
             + '\n');
   }
   try {
     execStatus.setEndTime(System.currentTimeMillis());
     // TODO: handle exception later.
     execStatus.setComplete(true);
     execStatus.setFinerStatus(message);
     execStatus.setState(ExecState.FAILED);
     store.update(execStatus);
     store.done();
   } finally {
     barrier.release(blockingKey);
   }
 }
 @Override
 public StepExecutionStatus pausedItem(DtRunbookItem runbookItem) {
   StepExecutionStatus itemStatus = new StepExecutionStatus(runbookItem.getItemId());
   itemStatus.setStartTime(System.currentTimeMillis());
   itemStatus.setState(ExecState.PAUSED);
   execStatus.addItemStatus(runbookItem.getItemId(), itemStatus);
   store.update(execStatus);
   return itemStatus;
 }
 @Override
 public StepExecutionStatus resumedItem(DtRunbookItem runbookItem) {
   StepExecutionStatus itemStatus =
       (StepExecutionStatus) execStatus.getItemStatus(runbookItem.getItemId());
   itemStatus.setComplete(false);
   itemStatus.setState(ExecState.RESUMED);
   store.update(itemStatus);
   return itemStatus;
 }
 public RunBookApiCallback(
     DtRunbook runbook,
     RunBookOutput runBookOutput,
     String executionId,
     OutputStore store,
     TransformedRunBook transformedRunbook,
     ConditionalBarrier<String> barrier,
     String blockingKey,
     boolean emitOutput) {
   this.runbook = runbook;
   this.runBookOutput = runBookOutput;
   this.executionId = executionId;
   this.store = store;
   this.barrier = barrier;
   this.blockingKey = blockingKey;
   this.emitOutput = emitOutput;
   execStatus = new RunBookApiExecStatus();
   execStatus.setExecutionId(executionId);
   // execStatus.setNodesMap(nodesMap);
   execStatus.setTransformedRunbook(transformedRunbook);
 }
 @Override
 public void done(String message) {
   if (emitOutput) {
     System.out.println(
         '\n'
             + "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");
     System.out.println("  RunBook : " + runbook.getRunBookPath() + "  |  " + " COMPLETE");
     System.out.println(
         "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-"
             + '\n');
   }
   try {
     execStatus.setEndTime(System.currentTimeMillis());
     execStatus.setComplete(true);
     execStatus.setState(didLatestStepFail() ? ExecState.FAILED : ExecState.SUCCESSFUL);
     execStatus.setFinerStatus(message);
     store.update(execStatus);
     store.done();
   } finally {
     barrier.release(blockingKey);
   }
 }
 @Override
 public void started() {
   if (emitOutput) {
     System.out.println(
         '\n'
             + "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");
     System.out.println("  RunBook : " + runbook.getRunBookPath() + "  |  " + " STARTED");
     System.out.println(
         "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-"
             + '\n');
   }
   execStatus.setStartTime(System.currentTimeMillis());
   store.create(execStatus);
 }
 private void appendToOutputMap(NodeOutputChunk nodeOutputChunk) {
   Map<String, Map<String, String>> outputMap = execStatus.getOutputMap();
   if (!outputMap.containsKey(nodeOutputChunk.getRunbookItemId())) {
     outputMap.put(nodeOutputChunk.getRunbookItemId(), new ConcurrentHashMap<>());
   }
   if (!outputMap
       .get(nodeOutputChunk.getRunbookItemId())
       .containsKey(nodeOutputChunk.getDisplayId())) {
     outputMap.get(nodeOutputChunk.getRunbookItemId()).put(nodeOutputChunk.getDisplayId(), "");
   }
   String currentOutput =
       outputMap.get(nodeOutputChunk.getRunbookItemId()).get(nodeOutputChunk.getDisplayId());
   outputMap
       .get(nodeOutputChunk.getRunbookItemId())
       .put(nodeOutputChunk.getDisplayId(), currentOutput + nodeOutputChunk.getOutputChunk());
 }
  @Override
  public StepExecutionStatus completedItem(DtRunbookItem runbookItem) {
    StepExecutionStatus itemStatus =
        (StepExecutionStatus) execStatus.getItemStatus(runbookItem.getItemId());
    itemStatus.setComplete(true);
    itemStatus.setEndTime(System.currentTimeMillis());
    System.out.println(
        '\n'
            + "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
    System.out.println("  Step : " + runbookItem.getId() + "  |  " + " COMPLETE");
    System.out.println(
        "-----------------------------------------------------------------------------------"
            + '\n');

    store.update(execStatus);
    return itemStatus;
  }
  @Override
  public StepExecutionStatus executingItem(DtRunbookItem runbookItem) {
    if (emitOutput) {
      System.out.println(
          '\n'
              + "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
      System.out.println("  Step : " + runbookItem.getId() + "  |  " + " STARTED");
      System.out.println(
          "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
              + '\n');
    }

    StepExecutionStatus itemStatus = new StepExecutionStatus(runbookItem.getItemId());
    itemStatus.setStartTime(System.currentTimeMillis());
    execStatus.addItemStatus(runbookItem.getItemId(), itemStatus);
    store.create(itemStatus);
    return itemStatus;
  }
Ejemplo n.º 10
0
  @Override
  public void itemExecOnNodeDone(String itemId, String nodeId, int statusCode, String message) {
    synchronized (this) {
      if (statusCode != 0) {
        latestStepFailed = true;
      } else {
        if (!latestStepFailed) {
          latestStepFailed = false;
        }
      }

      if (emitOutput) {
        System.out.println(
            '\n'
                + ". - . - . - . - . - . - . - . - . - . - . - . - . - . - . - . - . - . - . - . - . -");
        System.out.println(
            "  Node : "
                + nodeId
                + "  |  "
                + " "
                + (latestStepFailed ? "FAILED" : "SUCCESSFUL")
                + (latestStepFailed ? "  |  REASON : " + message : ""));
        System.out.println(
            ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ."
                + '\n');

        Map<String, Map<String, String>> runBookOutputMap = runBookOutput.getOutputMap();
        Map<String, String> stepOutputMap = runBookOutputMap.get(itemId);
        String nodeOutput = stepOutputMap.get(nodeId);
        System.out.println(nodeOutput);
      }

      StepExecutionStatus itemStatus = (StepExecutionStatus) execStatus.getItemStatus(itemId);
      itemStatus.addNodeStatus(nodeId, statusCode, message);
      if (message != null) {
        NodeOutputChunk outputChunk = new NodeOutputChunk(nodeId, message, itemId);
        output(outputChunk);
      }
    }
  }