-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(titus): UpdateJobProcesses Stage (#2934)
* feat(titus): UpdateJobProcesses Stage * fixup : move to jobs package * fix linting issues
- Loading branch information
Showing
3 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...n/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/job/UpdateJobProcessesStage.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,37 @@ | ||
/* | ||
* Copyright 2019 Netflix, 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.clouddriver.pipeline.job; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.tasks.MonitorKatoTask; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.job.UpdateJobProcessesTask; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.servergroup.ServerGroupCacheForceRefreshTask; | ||
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder; | ||
import com.netflix.spinnaker.orca.pipeline.TaskNode; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import javax.validation.constraints.NotNull; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class UpdateJobProcessesStage implements StageDefinitionBuilder { | ||
@Override | ||
public void taskGraph(@NotNull Stage stage, @NotNull TaskNode.Builder builder) { | ||
builder | ||
.withTask("updateJobProcesses", UpdateJobProcessesTask.class) | ||
.withTask("monitorUpdateJobProcesses", MonitorKatoTask.class) | ||
.withTask("forceCacheRefresh", ServerGroupCacheForceRefreshTask.class); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
.../main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/job/UpdateJobProcessesTask.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,66 @@ | ||
/* | ||
* Copyright 2019 Netflix, 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.clouddriver.tasks.job; | ||
|
||
import com.netflix.spinnaker.orca.ExecutionStatus; | ||
import com.netflix.spinnaker.orca.TaskResult; | ||
import com.netflix.spinnaker.orca.clouddriver.KatoService; | ||
import com.netflix.spinnaker.orca.clouddriver.model.TaskId; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.AbstractCloudProviderAwareTask; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import java.util.*; | ||
import javax.annotation.Nonnull; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class UpdateJobProcessesTask extends AbstractCloudProviderAwareTask { | ||
|
||
private final KatoService katoService; | ||
|
||
@Autowired | ||
public UpdateJobProcessesTask(KatoService katoService) { | ||
this.katoService = katoService; | ||
} | ||
|
||
@Override | ||
public TaskResult execute(@Nonnull Stage stage) { | ||
|
||
Map request = stage.mapTo(Map.class); | ||
List<Map<String, Map>> operations = new ArrayList<>(); | ||
|
||
Map<String, Object> operation = new HashMap<>(); | ||
operation.put("credentials", request.get("credentials")); | ||
operation.put("region", request.get("region")); | ||
operation.put("jobId", request.get("jobId")); | ||
operation.put("serviceJobProcesses", request.get("serviceJobProcesses")); | ||
operations.add(Collections.singletonMap("updateJobProcesses", operation)); | ||
|
||
TaskId taskId = | ||
katoService | ||
.requestOperations(request.get("cloudProvider").toString(), operations) | ||
.toBlocking() | ||
.first(); | ||
|
||
Map<String, Object> outputs = new HashMap<>(); | ||
outputs.put("notification.type", "updateJobProcesses"); | ||
outputs.put("kato.last.task.id", taskId); | ||
outputs.put("titus.region", request.get("region")); | ||
outputs.put("titus.account.name", request.get("credentials")); | ||
|
||
return TaskResult.builder(ExecutionStatus.SUCCEEDED).context(outputs).build(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...om/netflix/spinnaker/orca/clouddriver/tasks/servergroup/UpdateJobProcessesTaskSpec.groovy
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,64 @@ | ||
/* | ||
* Copyright 2019 Netflix, 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.clouddriver.tasks.servergroup | ||
|
||
import com.netflix.spinnaker.orca.ExecutionStatus | ||
import com.netflix.spinnaker.orca.clouddriver.KatoService | ||
import com.netflix.spinnaker.orca.clouddriver.model.TaskId | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.job.UpdateJobProcessesTask | ||
import com.netflix.spinnaker.orca.pipeline.model.Execution | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage | ||
import spock.lang.Specification | ||
|
||
class UpdateJobProcessesTaskSpec extends Specification { | ||
|
||
def "Should update job processes budget"() { | ||
|
||
given: | ||
def context = [ | ||
cloudProvider : "titus", | ||
credentials : "titustestvpc", | ||
region : "us-east-1", | ||
jobId : "60455788-d3a6-4090-a753-59332091b29f", | ||
serviceJobProcesses : [ | ||
disableIncreaseDesired : true, | ||
disableDecreaseDesired : true | ||
] | ||
] | ||
|
||
def stage = new Stage(Execution.newPipeline("orca"), "updateJobProcesses", context) | ||
and: | ||
List<Map> operations = [] | ||
def katoService = Mock(KatoService) { | ||
1 * requestOperations("titus", _) >> { | ||
operations = it[1] | ||
rx.Observable.from(new TaskId(UUID.randomUUID().toString())) | ||
} | ||
} | ||
def task = new UpdateJobProcessesTask(katoService) | ||
|
||
when: | ||
def result = task.execute(stage) | ||
|
||
then: | ||
operations.size() == 1 | ||
operations[0].updateJobProcesses.jobId == context.jobId | ||
operations[0].updateJobProcesses.region == context.region | ||
operations[0].updateJobProcesses.credentials == context.credentials | ||
operations[0].updateJobProcesses.serviceJobProcesses != null | ||
result.status == ExecutionStatus.SUCCEEDED | ||
} | ||
} |