-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(titus): Add updateJobProcesses operation (#3699)
* feat(titus): Add updateJobProcesses operation * fix test based on PR feedback * fixup comments
- Loading branch information
Showing
7 changed files
with
230 additions
and
0 deletions.
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
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
59 changes: 59 additions & 0 deletions
59
.../clouddriver/titus/deploy/converters/UpdateTitusJobProcessesAtomicOperationConverter.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,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; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...om/netflix/spinnaker/clouddriver/titus/deploy/description/ServiceJobProcessesRequest.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,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; | ||
} |
55 changes: 55 additions & 0 deletions
55
...etflix/spinnaker/clouddriver/titus/deploy/ops/UpdateTitusJobProcessesAtomicOperation.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,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(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...tflix/spinnaker/clouddriver/titus/deploy/ops/UpdateJobProcessesAtomicOperationSpec.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,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 | ||
|
||
} | ||
} |