Eli Mesika has uploaded a new change for review. Change subject: [WIP] core: enable to inject a job in Execution.. ......................................................................
[WIP] core: enable to inject a job in Execution.. core: enable to inject a job in ExecutionHandler Change-Id: I2e2fb56663ca730b3fb98ad53e653d3584857540 Signed-off-by: Eli Mesika <emes...@redhat.com> Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=872719 --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/job/ExecutionHandler.java 1 file changed, 39 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/24/15224/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/job/ExecutionHandler.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/job/ExecutionHandler.java index 794fba3..e00a7c8 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/job/ExecutionHandler.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/job/ExecutionHandler.java @@ -192,8 +192,7 @@ // A monitored job is created for monitored external flows if (isMonitored || context.isJobRequired()) { - Job job = createJob(actionType, command); - JobRepositoryFactory.getJobRepository().saveJob(job); + Job job = getJob(command, actionType); context.setExecutionMethod(ExecutionMethod.AsJob); context.setJob(job); command.setExecutionContext(context); @@ -206,6 +205,20 @@ ExceptionUtils.getMessage(e), e); } + } + + private static Job getJob(CommandBase<?> command, VdcActionType actionType) { + VdcActionParametersBase params = command.getParameters(); + Job job; + // if Job is external, we had already created the Job by AddExternalJobCommand, so just get it from DB + if (params.getJobId() != null) { + job = DbFacade.getInstance().getJobDao().get((Guid)params.getJobId()); + } + else { + job = createJob(actionType, command); + JobRepositoryFactory.getJobRepository().saveJob(job); + } + return job; } /** @@ -275,6 +288,7 @@ if (context.getExecutionMethod() == ExecutionMethod.AsJob && job != null) { step = job.addStep(stepName, description); try { + step.setExternal(isExternal); JobRepositoryFactory.getJobRepository().saveStep(step); } catch (Exception e) { log.errorFormat("Failed to save new step {0} for job {1}, {2}.", stepName.name(), @@ -284,7 +298,7 @@ } } else { Step contextStep = context.getStep(); - + step.setExternal(isExternal); if (context.getExecutionMethod() == ExecutionMethod.AsStep && contextStep != null) { step = addSubStep(contextStep, stepName, description); } @@ -293,7 +307,6 @@ log.error(e); } } - step.setExternal(isExternal); return step; } @@ -363,6 +376,27 @@ * @return The created instance of the step or {@code null}. */ public static Step addSubStep(ExecutionContext context, Step parentStep, StepEnum newStepName, String description) { + return addSubStep(context, parentStep, newStepName, description, false); + } + + /** + * 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) { @@ -386,12 +420,12 @@ } } if (step != null) { + step.setExternal(isExternal); JobRepositoryFactory.getJobRepository().saveStep(step); } } catch (Exception e) { log.error(e); } - return step; } -- To view, visit http://gerrit.ovirt.org/15224 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2e2fb56663ca730b3fb98ad53e653d3584857540 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Eli Mesika <emes...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches