Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TemplatePreviewChange extends AbstractPreviewTask {
private Object configuration;
private Object apply;
private Object rollback;
private Object steps;
Copy link
Member

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.


public TemplatePreviewChange() {}

Expand All @@ -44,6 +45,7 @@ public TemplatePreviewChange(String fileName,
Object configuration,
Object apply,
Object rollback,
Object steps,
TargetSystemDescriptor targetSystem,
RecoveryDescriptor recovery) {
super(id, order, author, templateName, runAlways, transactional, system, targetSystem, recovery, false);
Expand All @@ -52,6 +54,7 @@ public TemplatePreviewChange(String fileName,
this.configuration = configuration;
this.apply = apply;
this.rollback = rollback;
this.steps = steps;
}

public String getFileName() {
Expand Down Expand Up @@ -98,12 +101,21 @@ public void setRollback(Object rollback) {
this.rollback = rollback;
}

public Object getSteps() {
return steps;
}

public void setSteps(Object steps) {
this.steps = steps;
}

@Override
public String toString() {
return "TemplatePreviewChange{" + "profiles=" + profiles +
", configuration=" + configuration +
", apply=" + apply +
", rollback=" + rollback +
", steps=" + steps +
", id='" + id + '\'' +
", order='" + order + '\'' +
", author='" + author + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class TemplatePreviewTaskBuilder implements PreviewTaskBuilder<TemplatePreviewCh
private Object configuration;
private Object apply;
private Object rollback;
private Object steps;
Copy link
Member

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.

private TargetSystemDescriptor targetSystem;
private RecoveryDescriptor recovery;

Expand Down Expand Up @@ -108,6 +109,10 @@ public void setRecovery(RecoveryDescriptor recovery) {
this.recovery = recovery;
}

public void setSteps(Object steps) {
this.steps = steps;
}

@Override
public TemplatePreviewChange build() {

Expand All @@ -127,6 +132,7 @@ public TemplatePreviewChange build() {
configuration,
apply,
rollback,
steps,
targetSystem,
recovery);
}
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ChangeTemplateFileContent {
private Object configuration;
private Object apply;
private Object rollback;
private Object steps;
Copy link
Member

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.

private TargetSystemDescriptor targetSystem;
private RecoveryDescriptor recovery;

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is not present in the ChangeTemplate interface

.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());
}
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class TemplateLoadedChange extends AbstractLoadedChange {
private final Object configuration;
private final Object apply;
private final Object rollback;
private final Object steps;

TemplateLoadedChange(String changeFileName,
String id,
Expand All @@ -49,6 +50,7 @@ public class TemplateLoadedChange extends AbstractLoadedChange {
Object configuration,
Object apply,
Object rollback,
Object steps,
TargetSystemDescriptor targetSystem,
RecoveryDescriptor recovery) {
super(changeFileName, id, order, author, templateClass, constructor, runAlways, transactional, systemTask, targetSystem, recovery, false);
Expand All @@ -57,6 +59,7 @@ public class TemplateLoadedChange extends AbstractLoadedChange {
this.configuration = configuration;
this.apply = apply;
this.rollback = rollback;
this.steps = steps;
}

public Object getConfiguration() {
Expand All @@ -71,6 +74,10 @@ public Object getRollback() {
return rollback;
}

public Object getSteps() {
return steps;
}

public List<String> getProfiles() {
return profiles;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class TemplateLoadedTaskBuilder implements LoadedTaskBuilder<TemplateLoad
private Object configuration;
private Object apply;
private Object rollback;
private Object steps;
Copy link
Member

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.

private TargetSystemDescriptor targetSystem;
private RecoveryDescriptor recovery;

Expand Down Expand Up @@ -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);
Expand All @@ -156,6 +162,7 @@ public TemplateLoadedChange build() {
configuration,
apply,
rollback,
steps,
targetSystem,
recovery);

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public AbstractPreviewTask toPreview() {
configuration,
apply,
rollback,
null, // steps - null for backward compatibility
TargetSystemDescriptor.fromId(targetSystem),
RecoveryDescriptor.getDefault()
);
Expand Down
Loading