Skip to content

Commit

Permalink
feat(titus): Add updateJobProcesses operation (#3699)
Browse files Browse the repository at this point in the history
* feat(titus): Add updateJobProcesses operation

* fix test based on PR feedback

* fixup comments
  • Loading branch information
aravindmd authored May 28, 2019
1 parent 37b56f1 commit b2e8638
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public final class AtomicOperations {
public static final String STOP_SERVER_GROUP = "stopServerGroup";
public static final String SET_STATEFUL_DISK = "setStatefulDisk";
public static final String UPSERT_DISRUPTION_BUDGET = "upsertDisruptionBudget";
public static final String UPDATE_JOB_PROCESSES = "updateJobProcesses";

// Instance operations
public static final String REBOOT_INSTANCES = "rebootInstances";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.netflix.spinnaker.clouddriver.titus.client.model.HealthStatus;
import com.netflix.spinnaker.clouddriver.titus.client.model.Job;
import com.netflix.spinnaker.clouddriver.titus.client.model.Task;
import com.netflix.spinnaker.clouddriver.titus.deploy.description.ServiceJobProcessesRequest;
import com.netflix.spinnaker.kork.core.RetrySupport;
import com.netflix.titus.grpc.protogen.*;
import io.grpc.Status;
Expand Down Expand Up @@ -217,6 +218,25 @@ public void updateDisruptionBudget(JobDisruptionBudgetUpdateRequest request) {
.build());
}

@Override
public void updateScalingProcesses(ServiceJobProcessesRequest serviceJobProcessesRequest) {
TitusClientAuthenticationUtil.attachCaller(grpcBlockingStub)
.updateJobProcesses(
JobProcessesUpdate.newBuilder()
.setServiceJobProcesses(
ServiceJobSpec.ServiceJobProcesses.newBuilder()
.setDisableDecreaseDesired(
serviceJobProcessesRequest
.getServiceJobProcesses()
.isDisableDecreaseDesired())
.setDisableIncreaseDesired(
serviceJobProcessesRequest
.getServiceJobProcesses()
.isDisableIncreaseDesired()))
.setJobId(serviceJobProcessesRequest.getJobId())
.build());
}

@Override
public void resizeJob(ResizeJobRequest resizeJobRequest) {
TitusClientAuthenticationUtil.attachCaller(grpcBlockingStub)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.netflix.spinnaker.clouddriver.titus.client;

import com.netflix.spinnaker.clouddriver.titus.client.model.*;
import com.netflix.spinnaker.clouddriver.titus.deploy.description.ServiceJobProcessesRequest;
import com.netflix.titus.grpc.protogen.JobChangeNotification;
import com.netflix.titus.grpc.protogen.ObserveJobsQuery;
import java.util.Iterator;
Expand Down Expand Up @@ -66,6 +67,9 @@ public interface TitusClient {
public void updateDisruptionBudget(
JobDisruptionBudgetUpdateRequest jobDisruptionBudgetUpdateRequest);

/** @param serviceJobProcessesRequest */
public void updateScalingProcesses(ServiceJobProcessesRequest serviceJobProcessesRequest);

/** @param resizeJobRequest */
public void resizeJob(ResizeJobRequest resizeJobRequest);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.clouddriver.titus.deploy.converters;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation;
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperations;
import com.netflix.spinnaker.clouddriver.security.AbstractAtomicOperationsCredentialsSupport;
import com.netflix.spinnaker.clouddriver.titus.TitusClientProvider;
import com.netflix.spinnaker.clouddriver.titus.TitusOperation;
import com.netflix.spinnaker.clouddriver.titus.deploy.description.ServiceJobProcessesRequest;
import com.netflix.spinnaker.clouddriver.titus.deploy.ops.UpdateTitusJobProcessesAtomicOperation;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@TitusOperation(AtomicOperations.UPDATE_JOB_PROCESSES)
@Component
public class UpdateTitusJobProcessesAtomicOperationConverter
extends AbstractAtomicOperationsCredentialsSupport {

private final TitusClientProvider titusClientProvider;
private final ObjectMapper objectMapper;

@Autowired
UpdateTitusJobProcessesAtomicOperationConverter(
TitusClientProvider titusClientProvider, ObjectMapper objectMapper) {
this.titusClientProvider = titusClientProvider;
this.objectMapper = objectMapper;
}

@Override
public AtomicOperation convertOperation(Map input) {
return new UpdateTitusJobProcessesAtomicOperation(
titusClientProvider, convertDescription(input));
}

@Override
public ServiceJobProcessesRequest convertDescription(Map input) {
ServiceJobProcessesRequest converted =
objectMapper.convertValue(input, ServiceJobProcessesRequest.class);
converted.setCredentials(getCredentialsObject(input.get("credentials").toString()));
return converted;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.clouddriver.titus.deploy.description;

import com.netflix.spinnaker.clouddriver.titus.client.model.ServiceJobProcesses;
import lombok.Data;

@Data
public class ServiceJobProcessesRequest extends AbstractTitusCredentialsDescription {

ServiceJobProcesses serviceJobProcesses;
String region;
String jobId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.clouddriver.titus.deploy.ops;

import com.netflix.spinnaker.clouddriver.data.task.Task;
import com.netflix.spinnaker.clouddriver.data.task.TaskRepository;
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation;
import com.netflix.spinnaker.clouddriver.titus.TitusClientProvider;
import com.netflix.spinnaker.clouddriver.titus.client.TitusClient;
import com.netflix.spinnaker.clouddriver.titus.deploy.description.ServiceJobProcessesRequest;
import java.util.List;

public class UpdateTitusJobProcessesAtomicOperation implements AtomicOperation<Void> {

private static final String PHASE = "UPDATE_TITUS_JOB_PROCESSES";
private final TitusClientProvider titusClientProvider;
private final ServiceJobProcessesRequest description;

public UpdateTitusJobProcessesAtomicOperation(
TitusClientProvider titusClientProvider, ServiceJobProcessesRequest description) {
this.titusClientProvider = titusClientProvider;
this.description = description;
}

@Override
public Void operate(List priorOutputs) {

TitusClient titusClient =
titusClientProvider.getTitusClient(description.getCredentials(), description.getRegion());
getTask()
.updateStatus(
PHASE, "Updating Titus serviceJobProcesses : " + description.getJobId() + "...");

titusClient.updateScalingProcesses(description);
return null;
}

private static Task getTask() {
return TaskRepository.threadLocalTask.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.clouddriver.titus.deploy.ops

import com.netflix.spinnaker.clouddriver.data.task.Task
import com.netflix.spinnaker.clouddriver.data.task.TaskRepository
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation
import com.netflix.spinnaker.clouddriver.titus.TitusClientProvider
import com.netflix.spinnaker.clouddriver.titus.client.TitusClient
import com.netflix.spinnaker.clouddriver.titus.client.model.ServiceJobProcesses
import com.netflix.spinnaker.clouddriver.titus.credentials.NetflixTitusCredentials
import com.netflix.spinnaker.clouddriver.titus.deploy.description.ServiceJobProcessesRequest
import spock.lang.Specification
import spock.lang.Subject

class UpdateJobProcessesAtomicOperationSpec extends Specification {

TitusClient titusClient = Mock(TitusClient)
TitusClientProvider titusClientProvider = Stub()
NetflixTitusCredentials testCredentials = Stub()
ServiceJobProcesses serviceJobProcesses = new ServiceJobProcesses(
disableIncreaseDesired : false,
disableDecreaseDesired : true
)

ServiceJobProcessesRequest request = new ServiceJobProcessesRequest(
jobId: "abc123", region: "us-east-1", credentials: testCredentials, serviceJobProcesses: serviceJobProcesses
)

@Subject
AtomicOperation atomicOperation = new UpdateTitusJobProcessesAtomicOperation(titusClientProvider, request)

def setup() {
Task task = Mock(Task)
TaskRepository.threadLocalTask.set(task)
titusClientProvider.getTitusClient(_, _) >> titusClient
}

void 'UpdateJobProcessesOperation should update Titus job successfully'() {

when:
atomicOperation.operate([])

then:
1 * titusClient.updateScalingProcesses(request)
request.serviceJobProcesses.disableIncreaseDesired == false
request.serviceJobProcesses.disableDecreaseDesired == true

}
}

0 comments on commit b2e8638

Please sign in to comment.