-
Notifications
You must be signed in to change notification settings - Fork 65
feat: add steps support to templates #812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ class TemplatePreviewTaskBuilder implements PreviewTaskBuilder<TemplatePreviewCh | |
| private Object configuration; | ||
| private Object apply; | ||
| private Object rollback; | ||
| private Object steps; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a List. |
||
| private TargetSystemDescriptor targetSystem; | ||
| private RecoveryDescriptor recovery; | ||
|
|
||
|
|
@@ -108,6 +109,10 @@ public void setRecovery(RecoveryDescriptor recovery) { | |
| this.recovery = recovery; | ||
| } | ||
|
|
||
| public void setSteps(Object steps) { | ||
| this.steps = steps; | ||
| } | ||
|
|
||
| @Override | ||
| public TemplatePreviewChange build() { | ||
|
|
||
|
|
@@ -127,6 +132,7 @@ public TemplatePreviewChange build() { | |
| configuration, | ||
| apply, | ||
| rollback, | ||
| steps, | ||
| targetSystem, | ||
| recovery); | ||
| } | ||
|
|
@@ -153,6 +159,7 @@ TemplatePreviewTaskBuilder setFromDefinition(ChangeTemplateFileContent templateT | |
| setConfiguration(templateTaskDescriptor.getConfiguration()); | ||
| setApply(templateTaskDescriptor.getApply()); | ||
| setRollback(templateTaskDescriptor.getRollback()); | ||
| setSteps(templateTaskDescriptor.getSteps()); | ||
| setTransactional(templateTaskDescriptor.getTransactional() != null ? templateTaskDescriptor.getTransactional() : true); | ||
| setRunAlways(false); | ||
| setTargetSystem(templateTaskDescriptor.getTargetSystem()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ public class ChangeTemplateFileContent { | |
| private Object configuration; | ||
| private Object apply; | ||
| private Object rollback; | ||
| private Object steps; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a List. |
||
| private TargetSystemDescriptor targetSystem; | ||
| private RecoveryDescriptor recovery; | ||
|
|
||
|
|
@@ -120,6 +121,14 @@ public void setRollback(Object rollback) { | |
| this.rollback = rollback; | ||
| } | ||
|
|
||
| public Object getSteps() { | ||
| return steps; | ||
| } | ||
|
|
||
| public void setSteps(Object steps) { | ||
| this.steps = steps; | ||
| } | ||
|
|
||
| public TargetSystemDescriptor getTargetSystem() { | ||
| return targetSystem; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,9 +46,11 @@ protected void executeInternal(ExecutionRuntime executionRuntime, Method method | |
| Object instance = executionRuntime.getInstance(descriptor.getConstructor()); | ||
| ChangeTemplate<?,?,?> changeTemplateInstance = (ChangeTemplate<?,?,?>) instance; | ||
| changeTemplateInstance.setTransactional(descriptor.isTransactional()); | ||
| changeTemplateInstance.setChangeId(descriptor.getId()); | ||
| setExecutionData(executionRuntime, changeTemplateInstance, "Configuration"); | ||
| setExecutionData(executionRuntime, changeTemplateInstance, "ApplyPayload"); | ||
| setExecutionData(executionRuntime, changeTemplateInstance, "RollbackPayload"); | ||
| setStepsPayloadIfPresent(executionRuntime, changeTemplateInstance); | ||
| executionRuntime.executeMethodWithInjectedDependencies(instance, method); | ||
| } catch (Throwable ex) { | ||
| throw new ChangeExecutionException(ex.getMessage(), this.getId(), ex); | ||
|
|
@@ -100,6 +102,33 @@ private Method getSetterMethod(Class<?> changeTemplateClass, String methodName) | |
|
|
||
| } | ||
|
|
||
| /** | ||
| * Sets the steps payload on the template if the template supports it and steps data is present. | ||
| * This method uses reflection to call setStepsPayload if the template has such a method. | ||
| * Templates that don't support steps will simply not have this method called. | ||
| */ | ||
| private void setStepsPayloadIfPresent(ExecutionRuntime executionRuntime, | ||
| ChangeTemplate<?, ?, ?> instance) { | ||
| Object stepsData = descriptor.getSteps(); | ||
| if (stepsData == null) { | ||
| return; | ||
| } | ||
|
|
||
| Method setStepsMethod = Arrays.stream(instance.getClass().getMethods()) | ||
| .filter(m -> "setStepsPayload".equals(m.getName())) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method is not present in the |
||
| .filter(m -> m.getParameterCount() == 1) | ||
| .findFirst() | ||
| .orElse(null); | ||
|
|
||
| if (setStepsMethod != null) { | ||
| logger.debug("Setting steps payload for change[{}]", descriptor.getId()); | ||
| executionRuntime.executeMethodWithParameters(instance, setStepsMethod, stepsData); | ||
| } else { | ||
| logger.warn("Template[{}] has steps defined but doesn't support setStepsPayload method", | ||
| instance.getClass().getSimpleName()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ public class TemplateLoadedTaskBuilder implements LoadedTaskBuilder<TemplateLoad | |
| private Object configuration; | ||
| private Object apply; | ||
| private Object rollback; | ||
| private Object steps; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a List. |
||
| private TargetSystemDescriptor targetSystem; | ||
| private RecoveryDescriptor recovery; | ||
|
|
||
|
|
@@ -134,6 +135,11 @@ public TemplateLoadedTaskBuilder setRollback(Object rollback) { | |
| return this; | ||
| } | ||
|
|
||
| public TemplateLoadedTaskBuilder setSteps(Object steps) { | ||
| this.steps = steps; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public TemplateLoadedChange build() { | ||
| // boolean isTaskTransactional = true;//TODO implement this. isTaskTransactionalAccordingTemplate(templateSpec); | ||
|
|
@@ -156,6 +162,7 @@ public TemplateLoadedChange build() { | |
| configuration, | ||
| apply, | ||
| rollback, | ||
| steps, | ||
| targetSystem, | ||
| recovery); | ||
|
|
||
|
|
@@ -175,6 +182,7 @@ private TemplateLoadedTaskBuilder setPreview(TemplatePreviewChange preview) { | |
| setConfiguration(preview.getConfiguration()); | ||
| setApply(preview.getApply()); | ||
| setRollback(preview.getRollback()); | ||
| setSteps(preview.getSteps()); | ||
| setTargetSystem(preview.getTargetSystem()); | ||
| setRecovery(preview.getRecovery()); | ||
| return this; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a List.