Ejemplo n.º 1
0
  /**
   * Creates {@code ExecutionContext} which defines the context for executing the finalizing step of
   * the job. If the step exists, it must be part of a job, therefore the {@code Job} entity is
   * being set as part of the context.
   *
   * @param stepId The unique identifier of the step. Must not be {@code null}.
   * @return The context for monitoring the finalizing step of the job, or {@code null} if no such
   *     step.
   */
  public static ExecutionContext createFinalizingContext(Guid stepId) {
    ExecutionContext context = null;
    try {
      Step step = JobRepositoryFactory.getJobRepository().getStep(stepId);
      if (step != null && step.getParentStepId() != null) {
        context = new ExecutionContext();
        Step executionStep =
            JobRepositoryFactory.getJobRepository().getStep(step.getParentStepId());

        // indicates if a step is monitored at Job level or as an inner step
        Guid parentStepId = executionStep.getParentStepId();
        if (parentStepId == null) {
          context.setExecutionMethod(ExecutionMethod.AsJob);
          context.setJob(JobRepositoryFactory.getJobRepository().getJobWithSteps(step.getJobId()));
        } else {
          context.setExecutionMethod(ExecutionMethod.AsStep);
          Step parentStep = JobRepositoryFactory.getJobRepository().getStep(parentStepId);
          parentStep.setSteps(
              DbFacade.getInstance().getStepDao().getStepsByParentStepId(parentStep.getId()));
          context.setStep(parentStep);
        }
        context.setMonitored(true);
      }
    } catch (Exception e) {
      log.error(e);
    }
    return context;
  }
Ejemplo n.º 2
0
 /**
  * Updates the step with the id in the external system in which the describe task runs.
  *
  * @param step The step which represents the external task
  * @param externalId The id of the task in the external system
  * @param systemType The type of the system
  */
 public static void updateStepExternalId(
     Step step, Guid externalId, ExternalSystemType systemType) {
   if (step != null) {
     step.getExternalSystem().setId(externalId);
     step.getExternalSystem().setType(systemType);
     try {
       JobRepositoryFactory.getJobRepository().updateStep(step);
     } catch (Exception e) {
       log.errorFormat(
           "Failed to save step {0}, {1} for system-type {2} with id {3}",
           step.getId(), step.getStepType().name(), systemType.name(), externalId, e);
     }
   }
 }
Ejemplo n.º 3
0
  /**
   * Gets a list of {@link Step} entities ordered by:
   * <li>parent step id, preceded by nulls
   * <li>step number
   *
   * @param steps
   * @return a collection of the steps.
   */
  private List<Step> buildStepsTree(List<Step> steps) {
    List<Step> jobDirectSteps = new ArrayList<Step>();

    // a map of parent step id and a list of child-steps
    Map<NGuid, List<Step>> parentStepMap = new HashMap<NGuid, List<Step>>();

    for (Step step : steps) {
      if (step.getParentStepId() == null) {
        jobDirectSteps.add(step);
      } else {
        MultiValueMapUtils.addToMap(step.getParentStepId(), step, parentStepMap);
      }
    }

    for (Step step : steps) {
      step.setSteps(parentStepMap.get(step.getId()));
    }
    return jobDirectSteps;
  }
Ejemplo n.º 4
0
  private static Step addSubStep(Step parentStep, StepEnum stepName, String description) {
    Step step = null;

    if (parentStep != null) {
      if (description == null) {
        description = ExecutionMessageDirector.getInstance().getStepMessage(stepName);
      }
      step = parentStep.addStep(stepName, description);

      try {
        JobRepositoryFactory.getJobRepository().saveStep(step);
      } catch (Exception e) {
        log.errorFormat(
            "Failed to save new step {0} for step {1}, {2}.",
            stepName.name(), parentStep.getId(), parentStep.getStepType().name(), e);
        parentStep.getSteps().remove(step);
        step = null;
      }
    }
    return step;
  }
Ejemplo n.º 5
0
  /**
   * Adds a {@link Step} entity by the provided context as a child step of a given parent step. A
   * {@link Step} will not be created if {@code ExecutionContext.isMonitored()} returns false.
   *
   * @param context The context of the execution which defines visibility and execution method.
   * @param parentStep The parent step which the new step will be added as its child.
   * @param newStepName The name of the step.
   * @param description A presentation name for the step. If not provided, the presentation name is
   *     resolved by the {@code stepName}.
   * @param isExternal Indicates if the step is invoked by a plug-in
   * @return
   */
  public static Step addSubStep(
      ExecutionContext context,
      Step parentStep,
      StepEnum newStepName,
      String description,
      boolean isExternal) {
    Step step = null;

    if (context == null || parentStep == null) {
      return null;
    }

    try {
      if (context.isMonitored()) {
        if (description == null) {
          description = ExecutionMessageDirector.getInstance().getStepMessage(newStepName);
        }

        if (context.getExecutionMethod() == ExecutionMethod.AsJob) {
          if (DbFacade.getInstance().getStepDao().exists(parentStep.getId())) {
            if (parentStep.getJobId().equals(context.getJob().getId())) {
              step = parentStep.addStep(newStepName, description);
            }
          }
        } else if (context.getExecutionMethod() == ExecutionMethod.AsStep) {
          step = parentStep.addStep(newStepName, description);
        }
      }
      if (step != null) {
        step.setExternal(isExternal);
        JobRepositoryFactory.getJobRepository().saveStep(step);
      }
    } catch (Exception e) {
      log.error(e);
    }
    return step;
  }