Skip to content
Merged
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 @@ -535,6 +535,8 @@ private Object fromStep(String fieldName) {
stepInstanceAttributes.getType(), stepInstanceAttributes.getSubType());
case Constants.STEP_ERROR_RETRIES_PARAM:
return stepInstanceAttributes.getStepRetry().getErrorRetries();
case Constants.STEP_STATUS_PARAM:
return stepInstanceAttributes.getStatus().name();
default:
throw new MaestroValidationException(
"Invalid field name [%s] for getFromStep call", fieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class StepInstanceAttributes {
private final String stepInstanceUuid;
private final StepInstance.StepRetry stepRetry;
private final SignalDependencies signalDependencies;
private final StepInstance.Status status;

static StepInstanceAttributes from(StepRuntimeSummary summary) {
return StepInstanceAttributes.builder()
Expand All @@ -46,6 +47,7 @@ static StepInstanceAttributes from(StepRuntimeSummary summary) {
.stepInstanceUuid(summary.getStepInstanceUuid())
.stepRetry(summary.getStepRetry())
.signalDependencies(summary.getSignalDependencies())
.status(summary.getRuntimeState().getStatus())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.netflix.maestro.models.initiator.SignalInitiator;
import com.netflix.maestro.models.initiator.SubworkflowInitiator;
import com.netflix.maestro.models.instance.StepInstance;
import com.netflix.maestro.models.instance.StepRuntimeState;
import com.netflix.maestro.models.parameter.LongParameter;
import com.netflix.maestro.models.parameter.MapParameter;
import com.netflix.maestro.models.parameter.ParamType;
Expand Down Expand Up @@ -397,6 +398,29 @@ public void testGetFromCurrentStep() {
assertEquals(
StepType.NOTEBOOK.toString(), paramExtension.getFromStep(Constants.STEP_TYPE_INFO_PARAM));
assertEquals(0L, paramExtension.getFromStep(Constants.STEP_ERROR_RETRIES_PARAM));
assertEquals(
StepInstance.Status.NOT_CREATED.name(),
paramExtension.getFromStep(Constants.STEP_STATUS_PARAM));
}

@Test
public void testGetStatusFromCurrentStep() {
StepRuntimeState runtimeState = new StepRuntimeState();
runtimeState.setStatus(StepInstance.Status.COMPLETED_WITH_ERROR);
StepRuntimeSummary summary =
StepRuntimeSummary.builder()
.stepId("step-123")
.type(StepType.NOTEBOOK)
.stepRetry(StepInstance.StepRetry.from(null))
.runtimeState(runtimeState)
.build();
when(instanceWrapper.isWorkflowParam()).thenReturn(false);
when(instanceWrapper.getStepInstanceAttributes())
.thenReturn(StepInstanceAttributes.from(summary));

assertEquals(
StepInstance.Status.COMPLETED_WITH_ERROR.name(),
paramExtension.getFromStep(Constants.STEP_STATUS_PARAM));
}

@Test
Expand Down
12 changes: 12 additions & 0 deletions netflix-sel/docs/lang-guide/class-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ return params.getFromStep('step1', 'MAESTRO_STEP_STATUS'); // returns the sta
return params.getFromStep('step1', 'MAESTRO_STEP_END_TIME'); // returns the end time of upstream step1.
```

* `Object getFromStep(String)`

Returns a field of the current step instead of an upstream one. Useful in a step transition condition,
which is evaluated in the context of the step it is attached to, to branch on how that step ended.
```sel
return params.getFromStep('MAESTRO_STEP_STATUS'); // returns the status of the current step.

return params.getFromStep('MAESTRO_STEP_STATUS') == 'COMPLETED_WITH_ERROR'; // branch taken only when the current step failed.

return params.getFromStep('step_id'); // also supports step_id, step_instance_id, step_instance_uuid, step_attempt_id, step_type_info and MAESTRO_STEP_ERROR_RETRIES.
```

* `Object getFromSignal(String, String)`
```sel
return params.getFromSignal('signal1', 'param1'); // returns parameter param1's value from signal1. Use it to get param from the signal triggers.
Expand Down
Loading