Пример #1
0
  private int executeStage(Configuration configuration, Cluster cluster, int stageId) {
    Stage stage =
        masterConfig
            .getScenario()
            .getStage(
                stageId,
                state,
                getCurrentExtras(masterConfig, configuration, cluster),
                state.getReport());
    InitHelper.init(stage);
    StageResult result;
    try {
      if (stage instanceof MasterStage) {
        result = executeMasterStage((MasterStage) stage);
      } else if (stage instanceof DistStage) {
        result = executeDistStage(stageId, (DistStage) stage);
      } else {
        log.error("Stage '" + stage.getName() + "' is neither master nor distributed");
        return -1;
      }
    } finally {
      InitHelper.destroy(stage);
    }

    if (result == StageResult.SUCCESS) {
      return stageId + 1;
    } else if (result == StageResult.FAIL || result == StageResult.EXIT) {
      returnCode = masterConfig.getConfigurations().indexOf(configuration) + 1;
      if (result == StageResult.EXIT) {
        exitFlag = true;
      }
      return -1;
    } else if (result == StageResult.BREAK || result == StageResult.CONTINUE) {
      Stack<String> repeatNames = (Stack<String>) state.get(RepeatStage.REPEAT_NAMES);
      String nextLabel;
      if (repeatNames == null || repeatNames.isEmpty()) {
        log.warn("BREAK or CONTINUE used out of any repeat.");
        return -1;
      } else if (result == StageResult.BREAK) {
        nextLabel = Utils.concat(".", "repeat", repeatNames.peek(), "end");
      } else if (result == StageResult.CONTINUE) {
        nextLabel = Utils.concat(".", "repeat", repeatNames.peek(), "begin");
      } else throw new IllegalStateException();
      int nextStageId = masterConfig.getScenario().getLabel(nextLabel);
      if (nextStageId < 0) {
        log.error("No label '" + nextLabel + "' defined");
      }
      return nextStageId;
    } else {
      throw new IllegalStateException("Result does not match to any type.");
    }
  }