-
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.
implement autoscaling crud for titus
- Loading branch information
1 parent
dd2b91e
commit 8ae2092
Showing
15 changed files
with
697 additions
and
13 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
90 changes: 90 additions & 0 deletions
90
...vy/com/netflix/spinnaker/clouddriver/titus/client/RegionScopedTitusAutoscalingClient.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,90 @@ | ||
/* | ||
* Copyright 2017 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.client; | ||
|
||
import com.google.protobuf.Empty; | ||
import com.netflix.eureka2.grpc.nameresolver.Eureka2NameResolverFactory; | ||
import com.netflix.spectator.api.Registry; | ||
import com.netflix.spinnaker.clouddriver.titus.v3client.ClientAuthenticationUtils; | ||
import com.netflix.spinnaker.clouddriver.titus.v3client.GrpcMetricsInterceptor; | ||
import com.netflix.spinnaker.clouddriver.titus.v3client.GrpcRetryInterceptor; | ||
import com.netflix.titus.grpc.protogen.*; | ||
import io.grpc.ManagedChannel; | ||
import io.grpc.netty.NegotiationType; | ||
import io.grpc.netty.NettyChannelBuilder; | ||
import io.grpc.util.RoundRobinLoadBalancerFactory; | ||
|
||
import java.util.List; | ||
|
||
public class RegionScopedTitusAutoscalingClient implements TitusAutoscalingClient { | ||
|
||
/** | ||
* Default connect timeout in milliseconds | ||
*/ | ||
private static final long DEFAULT_CONNECT_TIMEOUT = 5000; | ||
|
||
private final AutoScalingServiceGrpc.AutoScalingServiceBlockingStub autoScalingServiceBlockingStub; | ||
|
||
public RegionScopedTitusAutoscalingClient(TitusRegion titusRegion, | ||
Registry registry, | ||
String environment, | ||
String eurekaName) { | ||
|
||
ManagedChannel eurekaChannel = NettyChannelBuilder | ||
.forTarget("eurekaproxy." + titusRegion.getName() + ".discovery" + environment + ".netflix.net:8980") | ||
.loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance()) | ||
.usePlaintext(true) | ||
.userAgent("spinnaker") | ||
.build(); | ||
|
||
ManagedChannel channel = NettyChannelBuilder | ||
.forTarget("eureka:///" + eurekaName + "?eureka.status=up") | ||
.sslContext(ClientAuthenticationUtils.newSslContext("titusapi")) | ||
.negotiationType(NegotiationType.TLS) | ||
.nameResolverFactory(new Eureka2NameResolverFactory(eurekaChannel)) // This enables the client to resolve the Eureka URI above into a set of addressable service endpoints. | ||
.loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance()) | ||
.intercept(new GrpcMetricsInterceptor(registry, titusRegion)) | ||
.intercept(new GrpcRetryInterceptor(DEFAULT_CONNECT_TIMEOUT)) | ||
.build(); | ||
|
||
this.autoScalingServiceBlockingStub = AutoScalingServiceGrpc.newBlockingStub(channel); | ||
} | ||
|
||
@Override | ||
public List<ScalingPolicyResult> getAllScalingPolicies() { | ||
return autoScalingServiceBlockingStub.getAllScalingPolicies(Empty.newBuilder().build()).getItemsList(); | ||
} | ||
|
||
@Override | ||
public List<ScalingPolicyResult> getJobScalingPolicies(String jobId) { | ||
JobId request = JobId.newBuilder().setId(jobId).build(); | ||
return autoScalingServiceBlockingStub | ||
.getJobScalingPolicies(request).getItemsList(); | ||
} | ||
|
||
@Override | ||
public ScalingPolicyID upsertScalingPolicy(PutPolicyRequest policy) { | ||
return autoScalingServiceBlockingStub | ||
.setAutoScalingPolicy(policy); | ||
} | ||
|
||
@Override | ||
public void deleteScalingPolicy(DeletePolicyRequest request) { | ||
autoScalingServiceBlockingStub.deleteAutoScalingPolicy(request); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/groovy/com/netflix/spinnaker/clouddriver/titus/client/TitusAutoscalingClient.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,35 @@ | ||
/* | ||
* Copyright 2017 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.client; | ||
|
||
import com.netflix.titus.grpc.protogen.DeletePolicyRequest; | ||
import com.netflix.titus.grpc.protogen.PutPolicyRequest; | ||
import com.netflix.titus.grpc.protogen.ScalingPolicyID; | ||
import com.netflix.titus.grpc.protogen.ScalingPolicyResult; | ||
|
||
import java.util.List; | ||
|
||
public interface TitusAutoscalingClient { | ||
|
||
List<ScalingPolicyResult> getAllScalingPolicies(); | ||
|
||
List<ScalingPolicyResult> getJobScalingPolicies(String jobId); | ||
|
||
ScalingPolicyID upsertScalingPolicy(PutPolicyRequest policy); | ||
|
||
void deleteScalingPolicy(DeletePolicyRequest request); | ||
} |
42 changes: 42 additions & 0 deletions
42
...ouddriver/titus/deploy/converters/DeleteTitusScalingPolicyAtomicOperationConverter.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,42 @@ | ||
/* | ||
* Copyright 2017 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.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.TitusOperation | ||
import com.netflix.spinnaker.clouddriver.titus.deploy.description.DeleteTitusScalingPolicyDescription | ||
import com.netflix.spinnaker.clouddriver.titus.deploy.ops.DeleteTitusScalingPolicyAtomicOperation | ||
import org.springframework.stereotype.Component | ||
|
||
@Component('titusDeleteScalingPolicyDescription') | ||
@TitusOperation(AtomicOperations.DELETE_SCALING_POLICY) | ||
class DeleteTitusScalingPolicyAtomicOperationConverter extends AbstractAtomicOperationsCredentialsSupport { | ||
|
||
@Override | ||
AtomicOperation convertOperation(Map input) { | ||
new DeleteTitusScalingPolicyAtomicOperation(convertDescription(input)) | ||
} | ||
|
||
@Override | ||
DeleteTitusScalingPolicyDescription convertDescription(Map input) { | ||
DeleteTitusScalingPolicyDescription converted = getObjectMapper().convertValue(input, DeleteTitusScalingPolicyDescription); | ||
converted.credentials = getCredentialsObject(input.credentials as String) | ||
converted | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ouddriver/titus/deploy/converters/UpsertTitusScalingPolicyAtomicOperationConverter.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,51 @@ | ||
/* | ||
* Copyright 2017 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.DeserializationFeature | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.netflix.spinnaker.clouddriver.aws.deploy.converters.UpsertScalingPolicyDescriptionAtomicOperationConverter | ||
import com.netflix.spinnaker.clouddriver.aws.deploy.ops.UpsertScalingPolicyAtomicOperation | ||
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperations | ||
import com.netflix.spinnaker.clouddriver.security.AbstractAtomicOperationsCredentialsSupport | ||
import com.netflix.spinnaker.clouddriver.titus.TitusOperation | ||
import com.netflix.spinnaker.clouddriver.titus.deploy.description.UpsertTitusScalingPolicyDescription | ||
import com.netflix.spinnaker.clouddriver.titus.deploy.ops.UpsertTitusScalingPolicyAtomicOperation | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.stereotype.Component | ||
|
||
@Component('titusUpsertScalingPolicyDescription') | ||
@TitusOperation(AtomicOperations.UPSERT_SCALING_POLICY) | ||
class UpsertTitusScalingPolicyAtomicOperationConverter extends AbstractAtomicOperationsCredentialsSupport { | ||
|
||
@Autowired | ||
ObjectMapper objectMapper | ||
|
||
@Override | ||
UpsertTitusScalingPolicyAtomicOperation convertOperation(Map input) { | ||
new UpsertTitusScalingPolicyAtomicOperation(convertDescription(input)) | ||
} | ||
|
||
@Override | ||
UpsertTitusScalingPolicyDescription convertDescription(Map input) { | ||
UpsertTitusScalingPolicyDescription converted = objectMapper.copy() | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
.convertValue(input, UpsertTitusScalingPolicyDescription) | ||
converted.credentials = getCredentialsObject(input.credentials as String) | ||
converted | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...spinnaker/clouddriver/titus/deploy/description/DeleteTitusScalingPolicyDescription.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,23 @@ | ||
/* | ||
* Copyright 2017 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 | ||
|
||
class DeleteTitusScalingPolicyDescription extends AbstractTitusCredentialsDescription { | ||
|
||
String region | ||
String scalingPolicyID | ||
} |
Oops, something went wrong.