Skip to content

Commit

Permalink
Merge branch 'spinnaker:master' into fix-CleanupAlarmsAgentException
Browse files Browse the repository at this point in the history
  • Loading branch information
christosarvanitis authored Jan 22, 2025
2 parents 7d77512 + fcc5394 commit 4cf1da0
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package com.netflix.spinnaker.clouddriver.google.model

public enum GoogleDiskType {
PD_STANDARD("pd-standard", true),
PD_EXTREME("pd-extreme", true),
PD_BALANCED("pd-balanced", true),
PD_SSD("pd-ssd", true),
LOCAL_SSD("local-ssd", false),
HYPERDISK_BALANCED("hyperdisk-balanced", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class InstanceTemplates {
private final Compute.InstanceTemplates computeApi;
private final GoogleNamedAccountCredentials credentials;
private final GlobalGoogleComputeRequestFactory requestFactory;
private static final String defaultView =
"FULL"; // https://cloud.google.com/sdk/gcloud/reference/beta/compute/instance-templates/list

InstanceTemplates(
GoogleNamedAccountCredentials credentials,
Expand Down Expand Up @@ -65,7 +67,11 @@ public PaginatedComputeRequest<Compute.InstanceTemplates.List, InstanceTemplate>
return new PaginatedComputeRequestImpl<>(
pageToken ->
requestFactory.wrapRequest(
computeApi.list(credentials.getProject()).setPageToken(pageToken), "list"),
computeApi
.list(credentials.getProject())
.setPageToken(pageToken)
.setView(defaultView),
"list"),
InstanceTemplateList::getNextPageToken,
InstanceTemplateList::getItems);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
import com.google.api.services.compute.Compute;
import com.google.api.services.compute.model.InstanceTemplate;
import com.google.common.collect.ImmutableList;
import com.netflix.spectator.api.BasicTag;
import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.NoopRegistry;
Expand Down Expand Up @@ -190,6 +191,69 @@ public void get_errorMetrics() {
assertThat(timer.totalTime()).isEqualTo(CLOCK_STEP_TIME_NS);
}

@Test
public void list_success() throws IOException {

MockHttpTransport transport =
new MockHttpTransport.Builder()
.setLowLevelHttpResponse(
new MockLowLevelHttpResponse()
.setStatusCode(200)
.addHeader("Content-Type", "application/json")
.setContent(
"{\"items\": [{\"name\": \"template1\"}, {\"name\": \"template2\"}], \"nextPageToken\": \"\"}"))
.build();

InstanceTemplates instanceTemplates = createInstanceTemplates(transport);

PaginatedComputeRequest<Compute.InstanceTemplates.List, InstanceTemplate> request =
instanceTemplates.list();

ImmutableList<InstanceTemplate> response = request.execute();
assertThat(response).hasSize(2);
assertThat(response.get(0).getName()).isEqualTo("template1");
assertThat(response.get(1).getName()).isEqualTo("template2");
}

@Test
public void list_noResults() throws IOException {

MockHttpTransport transport =
new MockHttpTransport.Builder()
.setLowLevelHttpResponse(
new MockLowLevelHttpResponse()
.setStatusCode(200)
.setContent("{\"items\": [], \"nextPageToken\": \"\"}"))
.build();

InstanceTemplates instanceTemplates = createInstanceTemplates(transport);

PaginatedComputeRequest<Compute.InstanceTemplates.List, InstanceTemplate> request =
instanceTemplates.list();

ImmutableList<InstanceTemplate> response = request.execute();
assertThat(response).isEmpty();
}

@Test
public void list_errorResponse() {

MockHttpTransport transport =
new MockHttpTransport.Builder()
.setLowLevelHttpResponse(
new MockLowLevelHttpResponse()
.setStatusCode(500)
.setContent("{\"error\": \"Internal Server Error\"}"))
.build();

InstanceTemplates instanceTemplates = createInstanceTemplates(transport);

PaginatedComputeRequest<Compute.InstanceTemplates.List, InstanceTemplate> request =
instanceTemplates.list();

assertThatIOException().isThrownBy(() -> request.execute());
}

private static InstanceTemplates createInstanceTemplates(HttpTransport transport) {
return createInstanceTemplates(transport, new NoopRegistry());
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
korkVersion=7.247.0
korkVersion=7.248.0
fiatVersion=1.53.0
org.gradle.parallel=true
spinnakerGradleVersion=8.32.1
Expand Down

0 comments on commit 4cf1da0

Please sign in to comment.