Skip to content

Commit

Permalink
feat(titus): UpdateJobProcesses Stage (#2934)
Browse files Browse the repository at this point in the history
* feat(titus): UpdateJobProcesses Stage

* fixup : move to jobs package

* fix linting issues
  • Loading branch information
aravindmd committed May 28, 2019
1 parent 9b61964 commit 005fc41
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 0 deletions.
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);
}
}
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();
}
}
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
}
}

0 comments on commit 005fc41

Please sign in to comment.