Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Fixed NullpointerException
Browse files Browse the repository at this point in the history
  • Loading branch information
falu2010-netflix committed Feb 8, 2019
1 parent 5a4aa57 commit e3eb561
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Optional<WorkflowDef> lookupLatestWorkflowDefinition(String workflowName) {
}

public Workflow populateWorkflowWithDefinitions(Workflow workflow) {

Preconditions.checkNotNull(workflow, "workflow cannot be null");
WorkflowDef workflowDefinition = Optional.ofNullable(workflow.getWorkflowDefinition())
.orElseGet(() -> {
WorkflowDef wd = lookupForWorkflowDefinition(workflow.getWorkflowName(), workflow.getWorkflowVersion());
Expand All @@ -115,6 +115,7 @@ public Workflow populateWorkflowWithDefinitions(Workflow workflow) {
}

public WorkflowDef populateTaskDefinitions(WorkflowDef workflowDefinition) {
Preconditions.checkNotNull(workflowDefinition, "workflowDefinition cannot be null");
workflowDefinition.collectTasks().forEach(
this::populateWorkflowTaskWithDefinition
);
Expand All @@ -123,6 +124,7 @@ public WorkflowDef populateTaskDefinitions(WorkflowDef workflowDefinition) {
}

private WorkflowTask populateWorkflowTaskWithDefinition(WorkflowTask workflowTask) {
Preconditions.checkNotNull(workflowTask, "WorkflowTask cannot be null");
if (shouldPopulateDefinition(workflowTask)) {
workflowTask.setTaskDefinition(metadataDAO.getTaskDef(workflowTask.getName()));
} else if (workflowTask.getType().equals(TaskType.SUB_WORKFLOW.name())) {
Expand All @@ -132,6 +134,7 @@ private WorkflowTask populateWorkflowTaskWithDefinition(WorkflowTask workflowTas
}

private void populateVersionForSubWorkflow(WorkflowTask workflowTask) {
Preconditions.checkNotNull(workflowTask, "WorkflowTask cannot be null");
SubWorkflowParams subworkflowParams = workflowTask.getSubWorkflowParam();
if (subworkflowParams.getVersion() == null) {
String subWorkflowName = subworkflowParams.getName();
Expand All @@ -150,6 +153,7 @@ private void populateVersionForSubWorkflow(WorkflowTask workflowTask) {
}

private void checkNotEmptyDefinitions(WorkflowDef workflowDefinition) {
Preconditions.checkNotNull(workflowDefinition, "WorkflowDefinition cannot be null");

// Obtain the names of the tasks with missing definitions
Set<String> missingTaskDefinitionNames = workflowDefinition.collectTasks().stream()
Expand All @@ -165,11 +169,14 @@ private void checkNotEmptyDefinitions(WorkflowDef workflowDefinition) {
}

public Task populateTaskWithDefinition(Task task) {
Preconditions.checkNotNull(task, "Task cannot be null");
populateWorkflowTaskWithDefinition(task.getWorkflowTask());
return task;
}

public static boolean shouldPopulateDefinition(WorkflowTask workflowTask) {
Preconditions.checkNotNull(workflowTask, "WorkflowTask cannot be null");
Preconditions.checkNotNull(workflowTask.getType(), "WorkflowTask type cannot be null");
return workflowTask.getType().equals(TaskType.SIMPLE.name()) &&
workflowTask.getTaskDefinition() == null;
}
Expand Down

0 comments on commit e3eb561

Please sign in to comment.