Skip to content

Commit

Permalink
feat(plugins): Task extends SpinnakerExtensionPoint, modify TaskResol…
Browse files Browse the repository at this point in the history
…ver to get task extension class (spinnaker#3657)
  • Loading branch information
jonsie authored May 5, 2020
1 parent 92b1c2c commit ceb6dac
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.netflix.spinnaker.orca.api.pipeline;

import com.netflix.spinnaker.kork.annotations.Beta;
import com.netflix.spinnaker.kork.plugins.api.internal.SpinnakerExtensionPoint;
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand All @@ -26,11 +27,10 @@
import java.util.Collections;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.pf4j.ExtensionPoint;

/** A discrete unit of work in a pipeline execution that does one thing and one thing only. */
@Beta
public interface Task extends ExtensionPoint {
public interface Task extends SpinnakerExtensionPoint {
/**
* Execute the business logic of the task, using the provided stage execution state.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public TaskResolver(Collection<Task> tasks, boolean allowFallback) {

public TaskResolver(Collection<Task> tasks, List<SimpleStage> stages, boolean allowFallback) {
for (Task task : tasks) {
taskByAlias.put(task.getClass().getCanonicalName(), task);
taskByAlias.put(task.getExtensionClass().getCanonicalName(), task);
for (String alias : task.aliases()) {
if (taskByAlias.containsKey(alias)) {
throw new DuplicateTaskAliasException(
String.format(
"Duplicate task alias detected (alias: %s, previous: %s, current: %s)",
alias,
taskByAlias.get(alias).getClass().getCanonicalName(),
task.getClass().getCanonicalName()));
task.getExtensionClass().getCanonicalName()));
}

taskByAlias.put(alias, task);
Expand Down Expand Up @@ -114,7 +114,7 @@ public Task getTask(@Nonnull Class<? extends Task> taskType) {
public Class<? extends Task> getTaskClass(@Nonnull String taskTypeIdentifier) {
try {
Task task = getTask(taskTypeIdentifier);
return (Class<? extends Task>) task.getClass();
return (Class<? extends Task>) task.getExtensionClass();
} catch (IllegalArgumentException e) {
if (!allowFallback) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doReturn TaskResult.SUCCEEDED

Expand All @@ -159,6 +160,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doReturn TaskResult.RUNNING doReturn TaskResult.SUCCEEDED

Expand Down Expand Up @@ -194,6 +196,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doReturn TaskResult.SUCCEEDED

Expand Down Expand Up @@ -234,6 +237,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doReturn TaskResult.SUCCEEDED

Expand Down Expand Up @@ -282,6 +286,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.execute(any())) doReturn TaskResult.ofStatus(TERMINAL)

context.runToCompletion(pipeline, runner::start, repository)
Expand Down Expand Up @@ -327,6 +332,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(argThat { refId == "2a1" })) doReturn TaskResult.ofStatus(TERMINAL)
whenever(dummyTask.execute(argThat { refId != "2a1" })) doReturn TaskResult.SUCCEEDED
Expand Down Expand Up @@ -375,6 +381,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(argThat { refId == "2a1" })) doReturn TaskResult.ofStatus(TERMINAL)
whenever(dummyTask.execute(argThat { refId != "2a1" })) doReturn TaskResult.SUCCEEDED
Expand Down Expand Up @@ -430,6 +437,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(argThat { refId == "2a1" })) doReturn TaskResult.ofStatus(TERMINAL)
whenever(dummyTask.execute(argThat { refId != "2a1" })) doReturn TaskResult.SUCCEEDED
Expand Down Expand Up @@ -475,6 +483,7 @@ abstract class QueueIntegrationTest {
repository.store(childPipeline)
repository.store(parentPipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.execute(argThat { refId == "1b" })) doReturn TaskResult.ofStatus(CANCELED)
context.runParentToCompletion(parentPipeline, childPipeline, runner::start, repository)

Expand Down Expand Up @@ -517,6 +526,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.execute(argThat { refId == "2b" })) doReturn TaskResult.ofStatus(TERMINAL)

context.runToCompletion(pipeline, runner::start, repository)
Expand Down Expand Up @@ -566,6 +576,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doReturn TaskResult.SUCCEEDED

Expand Down Expand Up @@ -603,6 +614,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doReturn TaskResult.SUCCEEDED

Expand Down Expand Up @@ -641,6 +653,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doReturn TaskResult.builder(SUCCEEDED).context(mapOf("output" to "foo")).build()

Expand Down Expand Up @@ -690,6 +703,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doReturn TaskResult.SUCCEEDED // second run succeeds

Expand Down Expand Up @@ -731,6 +745,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doAnswer {
val stage = it.arguments.first() as StageExecution
Expand Down Expand Up @@ -788,6 +803,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doAnswer {
val stage = it.arguments.first() as StageExecution
Expand Down Expand Up @@ -825,6 +841,7 @@ abstract class QueueIntegrationTest {
}
repository.store(pipeline)

whenever(dummyTask.extensionClass) doReturn dummyTask::class.java
whenever(dummyTask.getDynamicTimeout(any())) doReturn 2000L
whenever(dummyTask.execute(any())) doAnswer {
val stage = it.arguments.first() as StageExecution
Expand Down Expand Up @@ -868,6 +885,7 @@ class TestConfig {

@Bean
fun dummyTask(): DummyTask = mock {
on { extensionClass } doReturn DummyTask::class.java
on { getDynamicTimeout(any()) } doReturn Duration.ofMinutes(2).toMillis()
}

Expand Down
Loading

0 comments on commit ceb6dac

Please sign in to comment.