Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asdf #2

Merged
merged 8 commits into from
Jun 6, 2019
60 changes: 59 additions & 1 deletion clouddriver-artifacts/clouddriver-artifacts.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,63 @@ test {
useJUnitPlatform()
}

class DownloadTask extends DefaultTask {
@Input
String sourceUrl

@OutputFile
File target

@TaskAction
void download() {
ant.get(src: sourceUrl, dest: target)
}
}

final File sdkDownloadLocation = project.file('build/sdkdownload')
final File sdkLocation = project.file('build/oci-java-sdk')

// Oracle BMCS SDK isn't published to any maven repo (yet!), so we manually download, unpack and add to compile/runtime deps
// https://github.com/oracle/oci-java-sdk/issues/25
task fetchSdk(type: DownloadTask) {
sourceUrl = 'https://github.com/oracle/oci-java-sdk/releases/download/v1.3.2/oci-java-sdk.zip'
target = sdkDownloadLocation
}

task unpackSdk(type: Sync) {
dependsOn('fetchSdk')
from zipTree(tasks.fetchSdk.target)
into sdkLocation
include "**/*.jar"
exclude "**/*-sources.jar"
exclude "**/*-javadoc.jar"
exclude "apidocs/**"
exclude "examples/**"

// Scary but works. I think clouddriver deps in general need cleaning at some point
// Even without the oracle bmc sdk 3rd party deps there's still multiple javax.inject and commons-X JARs
exclude "**/*jackson*.jar"
exclude "**/*jersey*.jar"
exclude "**/hk2*.jar"
exclude "**/*guava*.jar"
exclude "**/commons*.jar"
exclude "**/aopalliance*.jar"
exclude "**/javassist*.jar"
exclude "**/slf*.jar"
exclude "**/osgi*.jar"
exclude "**/validation*.jar"
exclude "**/jsr305*.jar"
exclude "**/json-smart*.jar"
exclude "**/oci-java-sdk-full-shaded-*.jar"
}

task cleanSdk(type: Delete) {
delete sdkLocation, sdkDownloadLocation
}

tasks.clean.dependsOn('cleanSdk')
tasks.compileJava.dependsOn('unpackSdk')

dependencies {
implementation project(":clouddriver-core")

Expand All @@ -16,7 +73,6 @@ dependencies {
implementation "com.netflix.frigga:frigga"
implementation "com.netflix.spinnaker.kork:kork-artifacts"
implementation "com.netflix.spinnaker.kork:kork-exceptions"
implementation "com.oracle.oci.sdk:oci-java-sdk-core:1.5.2"
implementation "com.squareup.okhttp:okhttp"
implementation "com.sun.jersey:jersey-client:1.9.1"
implementation "org.apache.commons:commons-compress:1.14"
Expand All @@ -28,6 +84,8 @@ dependencies {
implementation "org.springframework.boot:spring-boot-actuator"
implementation "org.springframework.boot:spring-boot-starter-web"

implementation fileTree(sdkLocation)

testImplementation "com.github.tomakehurst:wiremock:latest.release"
testImplementation "org.assertj:assertj-core"
testImplementation "org.junit-pioneer:junit-pioneer:0.3.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@

package com.netflix.spinnaker.clouddriver.cloudfoundry.security;

import static java.util.Collections.emptyList;
import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toList;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.HttpCloudFoundryClient;
import com.netflix.spinnaker.clouddriver.security.AccountCredentials;
Expand All @@ -27,7 +32,7 @@

@Slf4j
@Getter
@JsonIgnoreProperties({"credentials", "client"})
@JsonIgnoreProperties({"credentials", "client", "password"})
public class CloudFoundryCredentials implements AccountCredentials<CloudFoundryClient> {

private final String name;
Expand Down Expand Up @@ -80,6 +85,17 @@ public CloudFoundryClient getClient() {
return getCredentials();
}

public Collection<Map<String, String>> getRegions() {
try {
return getCredentials().getSpaces().all().stream()
.map(space -> singletonMap("name", space.getRegion()))
.collect(toList());
} catch (CloudFoundryApiException e) {
log.warn("Unable to determine regions for Cloud Foundry account " + name, e);
return emptyList();
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private List<String> getDeletedAccountNames(
CloudFoundryConfigurationProperties cloudFoundryConfigurationProperties) {
List<String> existingNames =
accountCredentialsRepository.getAll().stream()
.filter(c -> CloudFoundryProvider.PROVIDER_ID.equals(c.getCloudProvider()))
.map(AccountCredentials::getName)
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,45 @@ void setUp() {
provider, configurationProperties, repository, catsModule, registry);
}

private class StaticOtherProviderCredentials implements AccountCredentials<Void> {
@Override
public String getName() {
return "unchanged-other-provider";
}

@Override
public String getEnvironment() {
return null;
}

@Override
public String getAccountType() {
return null;
}

@Override
public Void getCredentials() {
return null;
}

@Override
public String getCloudProvider() {
return "other";
}

@Override
public List<String> getRequiredGroupMembership() {
return null;
}
}

@Test
void synchronize() {
repository.save("to-be-changed", createCredentials("to-be-changed"));
repository.save("unchanged2", createCredentials("unchanged2"));
repository.save("unchanged3", createCredentials("unchanged3"));
repository.save("to-be-deleted", createCredentials("to-be-deleted"));
repository.save("unchanged-other-provider", new StaticOtherProviderCredentials());

loadProviderFromRepository();

Expand All @@ -91,7 +124,8 @@ void synchronize() {

assertThat(repository.getAll())
.extracting(AccountCredentials::getName)
.containsExactlyInAnyOrder("unchanged2", "unchanged3", "added", "to-be-changed");
.containsExactlyInAnyOrder(
"unchanged2", "unchanged3", "added", "to-be-changed", "unchanged-other-provider");

assertThat(ProviderUtils.getScheduledAccounts(provider))
.containsExactlyInAnyOrder("unchanged2", "unchanged3", "added", "to-be-changed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ private <T> JobResult<T> executeStreaming(JobRequest jobRequest, ReaderConsumer<
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
executor.execute(jobRequest.getCommandLine(), jobRequest.getEnvironment(), resultHandler);

T result =
consumer.consume(new BufferedReader(new InputStreamReader(new PipedInputStream(stdOut))));
T result;
try {
result =
consumer.consume(new BufferedReader(new InputStreamReader(new PipedInputStream(stdOut))));
} catch (IOException e) {
return JobResult.<T>builder().result(JobResult.Result.FAILURE).error(e.toString()).build();
}

try {
resultHandler.waitFor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ private Service createService(
String ecsServiceRole,
String newServerGroupName,
Service sourceService) {
Collection<LoadBalancer> loadBalancers =
retrieveLoadBalancers(EcsServerGroupNameResolver.getEcsContainerName(newServerGroupName));

String taskDefinitionArn = taskDefinition.getTaskDefinitionArn();

Integer desiredCount = description.getCapacity().getDesired();
if (sourceService != null
Expand All @@ -278,6 +278,38 @@ private Service createService(
desiredCount = sourceService.getDesiredCount();
}

CreateServiceRequest request =
makeServiceRequest(taskDefinitionArn, ecsServiceRole, newServerGroupName, desiredCount);

updateTaskStatus(
String.format(
"Creating %s of %s with %s for %s.",
desiredCount,
newServerGroupName,
taskDefinitionArn,
description.getCredentialAccount()));

Service service = ecs.createService(request).getService();

updateTaskStatus(
String.format(
"Done creating %s of %s with %s for %s.",
desiredCount,
newServerGroupName,
taskDefinitionArn,
description.getCredentialAccount()));

return service;
}

protected CreateServiceRequest makeServiceRequest(
String taskDefinitionArn,
String ecsServiceRole,
String newServerGroupName,
Integer desiredCount) {
Collection<LoadBalancer> loadBalancers =
retrieveLoadBalancers(EcsServerGroupNameResolver.getEcsContainerName(newServerGroupName));

Collection<ServiceRegistry> serviceRegistries = new LinkedList<>();
if (description.getServiceDiscoveryAssociations() != null) {
for (CreateServerGroupDescription.ServiceDiscoveryAssociation config :
Expand All @@ -300,8 +332,6 @@ private Service createService(
}
}

String taskDefinitionArn = taskDefinition.getTaskDefinitionArn();

DeploymentConfiguration deploymentConfiguration =
new DeploymentConfiguration().withMinimumHealthyPercent(100).withMaximumPercent(200);

Expand All @@ -325,7 +355,11 @@ private Service createService(
request.withTags(taskDefTags).withEnableECSManagedTags(true).withPropagateTags("SERVICE");
}

if (!AWSVPC_NETWORK_MODE.equals(description.getNetworkMode())) {
// Load balancer management role:
// N/A for non-load-balanced services
// Services using awsvpc mode must not specify a role in order to use the
// ECS service-linked role
if (!AWSVPC_NETWORK_MODE.equals(description.getNetworkMode()) && !loadBalancers.isEmpty()) {
request.withRole(ecsServiceRole);
}

Expand Down Expand Up @@ -367,25 +401,7 @@ private Service createService(
request.withHealthCheckGracePeriodSeconds(description.getHealthCheckGracePeriodSeconds());
}

updateTaskStatus(
String.format(
"Creating %s of %s with %s for %s.",
desiredCount,
newServerGroupName,
taskDefinitionArn,
description.getCredentialAccount()));

Service service = ecs.createService(request).getService();

updateTaskStatus(
String.format(
"Done creating %s of %s with %s for %s.",
desiredCount,
newServerGroupName,
taskDefinitionArn,
description.getCredentialAccount()));

return service;
return request;
}

private String registerAutoScalingGroup(
Expand Down
Loading