public boolean terminateLoopTask(
     FlowAction action,
     InternalTask initiator,
     ChangedTasksInfo changesInfo,
     SchedulerStateUpdate frontend) {
   // find the target of the loop
   InternalTask target = null;
   if (action.getTarget().equals(initiator.getName())) {
     target = initiator;
   } else {
     target = internalJob.findTaskUp(action.getTarget(), initiator);
   }
   boolean replicateForNextLoopIteration =
       internalJob.replicateForNextLoopIteration(initiator, target, changesInfo, frontend, action);
   if (replicateForNextLoopIteration && action.getCronExpr() != null) {
     for (TaskId tid : changesInfo.getNewTasks()) {
       InternalTask newTask = internalJob.getIHMTasks().get(tid);
       try {
         Date startAt = (new Predictor(action.getCronExpr())).nextMatchingDate();
         newTask.addGenericInformation(
             InternalJob.GENERIC_INFO_START_AT_KEY, ISO8601DateUtil.parse(startAt));
         newTask.setScheduledTime(startAt.getTime());
       } catch (InvalidPatternException e) {
         // this will not happen as the cron expression is
         // already being validated in FlowScript class.
         LOGGER.debug(e.getMessage());
       }
     }
   }
   return replicateForNextLoopIteration;
 }
Esempio n. 2
0
  InternalTask toInternalTask(InternalJob internalJob) throws InvalidScriptException {
    TaskId taskId = createTaskId(internalJob);

    InternalTask internalTask;

    if (taskType.equals(SCRIPT_TASK)) {
      internalTask = new InternalScriptTask();
    } else if (taskType.equals(FORKED_SCRIPT_TASK)) {
      internalTask = new InternalForkedScriptTask();
    } else {
      throw new IllegalStateException("Unexpected stored task type: " + taskType);
    }

    internalTask.setId(taskId);
    internalTask.setDescription(getDescription());
    internalTask.setStatus(getTaskStatus());
    internalTask.setJobInfo(internalJob.getJobInfo());
    internalTask.setName(getTaskName());
    internalTask.setExecutionDuration(getExecutionDuration());
    internalTask.setFinishedTime(getFinishedTime());
    internalTask.setStartTime(getStartTime());
    internalTask.setExecutionHostName(getExecutionHostName());
    internalTask.setCancelJobOnError(isCancelJobOnError());
    internalTask.setPreciousLogs(isPreciousLogs());
    internalTask.setPreciousResult(isPreciousResult());
    internalTask.setRunAsMe(isRunAsMe());
    internalTask.setWallTime(getWallTime());
    internalTask.setMaxNumberOfExecution(getMaxNumberOfExecution());
    internalTask.setRestartTaskOnError(getRestartMode());
    internalTask.setFlowBlock(getFlowBlock());
    internalTask.setIterationIndex(getIteration());
    internalTask.setReplicationIndex(getReplication());
    internalTask.setMatchingBlock(getMatchingBlock());

    ForkEnvironment forkEnv = new ForkEnvironment();
    forkEnv.setJavaHome(javaHome);

    List<String> additionalClasspath = getAdditionalClasspath();
    if (additionalClasspath != null) {
      for (String classpath : additionalClasspath) {
        forkEnv.addAdditionalClasspath(classpath);
      }
    }

    List<String> jvmArguments = getJvmArguments();
    if (jvmArguments != null) {
      for (String jvmArg : jvmArguments) {
        forkEnv.addJVMArgument(jvmArg);
      }
    }

    List<EnvironmentModifierData> envModifiers = getEnvModifiers();

    if (envModifiers != null) {
      for (EnvironmentModifierData envModifier : envModifiers) {
        forkEnv.addSystemEnvironmentVariable(envModifier.getName(), envModifier.getValue());
      }
    }

    if (envScript != null) {
      forkEnv.setEnvScript(envScript.createSimpleScript());
    }

    internalTask.setForkEnvironment(forkEnv);

    return internalTask;
  }
Esempio n. 3
0
 TaskId createTaskId(InternalJob internalJob) {
   return TaskIdImpl.createTaskId(internalJob.getId(), getTaskName(), getId().getTaskId());
 }