forked from spinnaker/orca
-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat(plugins): filled in scaffolding #11
Open
bpowell
wants to merge
20
commits into
master
Choose a base branch
from
plugins-filled
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
cd4a3c2
feat(plugins): start of API for new stages
5320954
feat(plugins): scaffolding setup for plugins
0581af4
fix(plugins): removed ulid dep
442e404
chore(plugins): added copyright
c0f6c4c
feat(plugins): filled in scaffolding
895a5c8
fix(plugins): changed StageInputs to be generic
7d62393
fix(plugins): make use of generic StageInput
f9ab27a
Merge branch 'plugins-scaffolding' into plugins-filled
bc56a28
fix(plugins): should properly get the generic from StageInput
fde6cb6
fix(plugins): properly gets generic class for StageInput
c858bd4
fix(plugins): made Stage take in generic for StageInput
a3aa65e
Merge branch 'plugins-scaffolding' into plugins-filled
9c3c8f0
fix(plugins): using Arrays.asList instead of constructing by hand
2aa3953
fix(plugins): refactored variable name
7fc46c2
feat(plugins): actually able to use stage outputs
00f5f88
chore(plugins): updated tests for Api Stages
8dd69f7
chore(plugins): added test for ApiTask
d525300
fix(plugins): chnaged header and made code more groovy
c752ffa
fix(plugins): made tests work when no plugins are in the codebase
34ead88
chore(plugins): refacgtored to simple
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2019 Armory, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
apply from: "$rootDir/gradle/kotlin.gradle" | ||
apply from: "$rootDir/gradle/spock.gradle" | ||
|
||
test { | ||
useJUnitPlatform { | ||
includeEngines "junit-vintage", "junit-jupiter" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation("com.google.guava:guava") | ||
} |
26 changes: 26 additions & 0 deletions
26
orca-api/src/main/java/com/netflix/spinnaker/orca/api/Stage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2019 Armory, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.api; | ||
|
||
import com.google.common.annotations.Beta; | ||
|
||
@Beta | ||
public interface Stage<T> { | ||
<T> StageOutput execute(StageInput<T> stageInput); | ||
|
||
String getName(); | ||
} |
36 changes: 36 additions & 0 deletions
36
orca-api/src/main/java/com/netflix/spinnaker/orca/api/StageInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2019 Armory, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.api; | ||
|
||
import com.google.common.annotations.Beta; | ||
|
||
@Beta | ||
public class StageInput<T> { | ||
private T value; | ||
|
||
public StageInput(T value) { | ||
this.value = value; | ||
} | ||
|
||
public void setValue(T value) { | ||
this.value = value; | ||
} | ||
|
||
public T getValue() { | ||
return this.value; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
orca-api/src/main/java/com/netflix/spinnaker/orca/api/StageOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2019 Armory, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.api; | ||
|
||
import com.google.common.annotations.Beta; | ||
import java.util.Map; | ||
|
||
@Beta | ||
public class StageOutput { | ||
private StageStatus status; | ||
|
||
public void setStatus(StageStatus status) { | ||
this.status = status; | ||
} | ||
|
||
public StageStatus getStatus() { | ||
return this.status; | ||
} | ||
|
||
private Map outputs; | ||
|
||
public void setOutputs(Map outputs) { | ||
this.outputs = outputs; | ||
} | ||
|
||
public Map getOutputs() { | ||
return this.outputs; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
orca-api/src/main/java/com/netflix/spinnaker/orca/api/StageStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2019 Armory, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.api; | ||
|
||
import com.google.common.annotations.Beta; | ||
|
||
@Beta | ||
public enum StageStatus { | ||
TERMINAL, | ||
RUNNING, | ||
COMPLETED, | ||
NOT_STARTED | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/ApiStageDefinitionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2019 Armory, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.pipeline; | ||
|
||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import javax.annotation.Nonnull; | ||
|
||
public class ApiStageDefinitionBuilder implements StageDefinitionBuilder { | ||
private com.netflix.spinnaker.orca.api.Stage apiStage; | ||
|
||
public ApiStageDefinitionBuilder(com.netflix.spinnaker.orca.api.Stage apiStage) { | ||
this.apiStage = apiStage; | ||
} | ||
|
||
public void taskGraph(@Nonnull Stage stage, @Nonnull TaskNode.Builder builder) { | ||
ApiTask task = new ApiTask(apiStage); | ||
builder.withTask(apiStage.getName(), task.getClass()); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/ApiTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2019 Armory, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.pipeline; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.netflix.spinnaker.orca.ExecutionStatus; | ||
import com.netflix.spinnaker.orca.Task; | ||
import com.netflix.spinnaker.orca.TaskResult; | ||
import com.netflix.spinnaker.orca.api.StageInput; | ||
import com.netflix.spinnaker.orca.api.StageOutput; | ||
import com.netflix.spinnaker.orca.jackson.OrcaObjectMapper; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Type; | ||
import java.lang.reflect.TypeVariable; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.annotation.Nonnull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.GenericTypeResolver; | ||
import org.springframework.core.ResolvableType; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
public class ApiTask implements Task { | ||
private com.netflix.spinnaker.orca.api.Stage apiStage; | ||
|
||
ApiTask(com.netflix.spinnaker.orca.api.Stage apiStage) { | ||
this.apiStage = apiStage; | ||
} | ||
|
||
@Nonnull | ||
public TaskResult execute(@Nonnull Stage stage) { | ||
ObjectMapper objectMapper = OrcaObjectMapper.newInstance(); | ||
|
||
ExecutionStatus status; | ||
StageOutput outputs = new StageOutput(); | ||
|
||
try { | ||
List<Class<?>> cArg = Arrays.asList(StageInput.class); | ||
Method method = apiStage.getClass().getMethod("execute", cArg.toArray(new Class[0])); | ||
Type inputType = ResolvableType.forMethodParameter(method, 0).getGeneric().getType(); | ||
Map<TypeVariable, Type> typeVariableMap = | ||
GenericTypeResolver.getTypeVariableMap(apiStage.getClass()); | ||
|
||
StageInput stageInput = | ||
new StageInput( | ||
objectMapper.convertValue( | ||
stage.getContext(), GenericTypeResolver.resolveType(inputType, typeVariableMap))); | ||
outputs = apiStage.execute(stageInput); | ||
switch (outputs.getStatus()) { | ||
case TERMINAL: | ||
status = ExecutionStatus.TERMINAL; | ||
break; | ||
case RUNNING: | ||
status = ExecutionStatus.RUNNING; | ||
break; | ||
case COMPLETED: | ||
status = ExecutionStatus.SUCCEEDED; | ||
break; | ||
case NOT_STARTED: | ||
status = ExecutionStatus.NOT_STARTED; | ||
break; | ||
default: | ||
status = ExecutionStatus.FAILED_CONTINUE; | ||
break; | ||
} | ||
} catch (Exception e) { | ||
log.error("Cannot execute stage " + apiStage.getName()); | ||
log.error(e.getMessage()); | ||
status = ExecutionStatus.TERMINAL; | ||
} | ||
|
||
return TaskResult.builder(status) | ||
.context(outputs.getOutputs()) | ||
.outputs(outputs.getOutputs()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not a fan of duplicated class name. It hurts readability and increases complexity by having to determine which type of Stage object you're working with.