refactor(cf): removed unused code, fix spelling and etc
MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/cache/Keys.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/cache/Keys.java
@@ -75,7 +75,7 @@ public class Keys implements KeyParser {
}
public static String getApplicationKey(String app) {
- return ID + ":" + Namespace.APPLICATIONS + ":" + app;
+ return ID + ":" + Namespace.APPLICATIONS + ":" + app.toLowerCase();
}
public static String getAllLoadBalancers() {
@@ -132,11 +132,27 @@ public class Keys implements KeyParser {
}
public static String getClusterKey(String account, String app, String name) {
- return ID + ":" + Namespace.CLUSTERS + ":" + account + ":" + app + ":" + name;
+ return ID
+ + ":"
+ + Namespace.CLUSTERS
+ + ":"
+ + account
+ + ":"
+ + app.toLowerCase()
+ + ":"
+ + name.toLowerCase();
}
public static String getServerGroupKey(String account, String name, String region) {
- return ID + ":" + Namespace.SERVER_GROUPS + ":" + account + ":" + name + ":" + region;
+ return ID
+ + ":"
+ + Namespace.SERVER_GROUPS
+ + ":"
+ + account
+ + ":"
+ + name.toLowerCase()
+ + ":"
+ + region;
}
public static String getInstanceKey(String account, String instanceName) {

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/Applications.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/Applications.java
@@ -102,7 +102,9 @@ public class Applications {
// Evict Records from `cache` that are no longer in the foundation
List<String> availableAppIds =
newCloudFoundryAppList.stream().map(Application::getGuid).collect(toList());
- serverGroupCache.asMap().keySet().stream()
+ serverGroupCache
+ .asMap()
+ .keySet()
.forEach(
key -> {
if (!availableAppIds.contains(key)) {
@@ -168,7 +170,7 @@ public class Applications {
@Nullable
public CloudFoundryServerGroup findServerGroupByNameAndSpaceId(String name, String spaceId) {
return Optional.ofNullable(findServerGroupId(name, spaceId))
- .map(serverGroupId -> Optional.ofNullable(findById(serverGroupId)).orElse(null))
+ .flatMap(serverGroupId -> Optional.ofNullable(findById(serverGroupId)))
.orElse(null);
}
@@ -214,7 +216,7 @@ public class Applications {
try {
CloudFoundryPackage cfPackage =
safelyCall(() -> api.findPackagesByAppId(appId))
- .map(
+ .flatMap(
packages ->
packages.getResources().stream()
.findFirst()
@@ -233,8 +235,7 @@ public class Applications {
pkg.getData().getChecksum() == null
? null
: pkg.getData().getChecksum().getValue())
- .build())
- .orElse(null))
+ .build()))
.orElse(null);
droplet =
@@ -304,13 +305,17 @@ public class Applications {
String serverGroupAppManagerUri = appsManagerUri;
if (StringUtils.isNotEmpty(appsManagerUri)) {
serverGroupAppManagerUri =
+ Optional.ofNullable(space)
+ .map(
+ s ->
appsManagerUri
+ "/organizations/"
- + space.getOrganization().getId()
+ + s.getOrganization().getId()
+ "/spaces/"
- + space.getId()
+ + s.getId()
+ "/applications/"
- + appId;
+ + appId)
+ .orElse("");
}
String serverGroupMetricsUri = metricsUri;
@@ -504,7 +509,7 @@ public class Applications {
throws CloudFoundryApiException {
final Process.HealthCheck healthCheck =
healthCheckType != null ? new Process.HealthCheck().setType(healthCheckType) : null;
- if (healthCheckEndpoint != null && !healthCheckEndpoint.isEmpty()) {
+ if (healthCheckEndpoint != null && !healthCheckEndpoint.isEmpty() && healthCheck != null) {
healthCheck.setData(new Process.HealthCheckData().setEndpoint(healthCheckEndpoint));
}
safelyCall(() -> api.updateProcess(guid, new UpdateProcess(command, healthCheck)));
@@ -539,9 +544,9 @@ public class Applications {
}
}
- public String uploadPackageBits(String packageGuid, File file) throws CloudFoundryApiException {
+ public void uploadPackageBits(String packageGuid, File file) throws CloudFoundryApiException {
TypedFile uploadFile = new TypedFile("multipart/form-data", file);
- return safelyCall(() -> api.uploadPackageBits(packageGuid, uploadFile))
+ safelyCall(() -> api.uploadPackageBits(packageGuid, uploadFile))
.map(Package::getGuid)
.orElseThrow(
() ->

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/CloudFoundryApiException.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/CloudFoundryApiException.java
@@ -36,18 +36,16 @@ public class CloudFoundryApiException extends RuntimeException {
super(
Optional.ofNullable(errorCause)
.map(e -> getMessage(e.getErrors().toArray(new String[0])))
- .orElse(
- "status: "
- + retrofitError.getResponse().getStatus()
- + ". url: "
- + retrofitError.getResponse().getUrl()
- + ". raw response body: "
- + retrofitError.getResponse().getBody()));
+ .orElse(getRetrofitErrorMessage(retrofitError)));
if (errorCause != null) {
this.errorCode = errorCause.getCode();
}
}
+ public CloudFoundryApiException(RetrofitError retrofitError) {
+ super(getRetrofitErrorMessage(retrofitError));
+ }
+
public CloudFoundryApiException(Throwable t, String... errors) {
super(getMessage(t, errors), t);
}
@@ -66,4 +64,13 @@ public class CloudFoundryApiException extends RuntimeException {
allErrors[errors.length] = t.getMessage();
return getMessage(allErrors);
}
+
+ private static String getRetrofitErrorMessage(RetrofitError retrofitError) {
+ return "status: "
+ + retrofitError.getResponse().getStatus()
+ + ". url: "
+ + retrofitError.getResponse().getUrl()
+ + ". raw response body: "
+ + retrofitError.getResponse().getBody();
+ }
}

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/CloudFoundryClientUtils.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/CloudFoundryClientUtils.java
@@ -50,7 +50,7 @@ final class CloudFoundryClientUtils {
ErrorDescription errorDescription =
(ErrorDescription) retrofitError.getBodyAs(ErrorDescription.class);
if (errorDescription == null) {
- throw new CloudFoundryApiException(retrofitError.getCause());
+ throw new CloudFoundryApiException(retrofitError);
}
throw new CloudFoundryApiException(errorDescription, retrofitError);
}

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/HttpCloudFoundryClient.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/HttpCloudFoundryClient.java
@@ -74,6 +74,7 @@ public class HttpCloudFoundryClient implements CloudFoundryClient {
private final String user;
private final String password;
private final OkHttpClient okHttpClient;
+ private Logger logger = LoggerFactory.getLogger(HttpCloudFoundryClient.class);
private AuthenticationService uaaService;
private AtomicLong tokenExpirationNs = new AtomicLong(System.nanoTime());
@@ -91,8 +92,6 @@ public class HttpCloudFoundryClient implements CloudFoundryClient {
private Tasks tasks;
private Logs logs;
- Logger logger = LoggerFactory.getLogger(HttpCloudFoundryClient.class);
-
private final RequestInterceptor oauthInterceptor =
new RequestInterceptor() {
@Override
@@ -164,7 +163,7 @@ public class HttpCloudFoundryClient implements CloudFoundryClient {
});
} catch (SocketTimeoutException e) {
throw new RetryableApiException(
- "Timeout " + callName + " " + chain.request().httpUrl() + ", attempting retrying", e);
+ "Timeout " + callName + " " + chain.request().httpUrl() + ", attempting retry", e);
} catch (Exception e) {
final Response response = lastResponse.get();
if (response == null) {

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/DeployCloudFoundryServerGroupAtomicOperation.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/DeployCloudFoundryServerGroupAtomicOperation.java
@@ -111,7 +111,7 @@ public class DeployCloudFoundryServerGroupAtomicOperation
return deploymentResult();
}
- final Integer desiredInstanceCount = description.getApplicationAttributes().getInstances();
+ final int desiredInstanceCount = description.getApplicationAttributes().getInstances();
if (description.isStartApplication() && desiredInstanceCount > 0) {
client.getApplications().startApplication(serverGroup.getId());
ProcessStats.State state =
@@ -285,7 +285,6 @@ public class DeployCloudFoundryServerGroupAtomicOperation
private static ExternalReference resolveBuildInfo(
DeployCloudFoundryServerGroupDescription description) {
Map<String, Object> buildInfo = null;
- if (buildInfo == null) {
final Artifact applicationArtifact = description.getApplicationArtifact();
if (applicationArtifact != null) {
final Map<String, Object> metadata = applicationArtifact.getMetadata();
@@ -293,7 +292,6 @@ public class DeployCloudFoundryServerGroupAtomicOperation
buildInfo = (Map<String, Object>) applicationArtifact.getMetadata().get("build");
}
}
- }
if (buildInfo == null) {
final Map<String, Object> trigger = description.getTrigger();
if (trigger != null) {

refactor(cf): removed unused code, fix spelling and etc (#4159)