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

fix(google): Add partner metadata on instanceTemplate properties #6334

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ public GoogleComputeOperationRequest<Compute.InstanceTemplates.Insert> insert(
return requestFactory.wrapOperationRequest(request, "insert");
}

public PaginatedComputeRequest<Compute.InstanceTemplates.List, InstanceTemplate> list() {
public PaginatedComputeRequest<Compute.InstanceTemplates.List, InstanceTemplate> list(
String view) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this api used anywhere else? I see the one spot below in the abstract caching agent that passes a fixed value of "FULL", but no place else this list call is updated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IF it's only ever called in that ONE operation - why not just add that as a fixed value here?

return new PaginatedComputeRequestImpl<>(
pageToken ->
requestFactory.wrapRequest(
computeApi.list(credentials.getProject()).setPageToken(pageToken), "list"),
computeApi.list(credentials.getProject()).setPageToken(pageToken).setView(view),
"list"),
InstanceTemplateList::getNextPageToken,
InstanceTemplateList::getItems);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,10 @@ Collection<Instance> retrieveAllInstancesInRegion() throws IOException {

private Collection<InstanceTemplate> retrieveInstanceTemplates() throws IOException {
InstanceTemplates instanceTemplatesApi = computeApiFactory.createInstanceTemplates(credentials);
return instanceTemplatesApi.list().execute();
return instanceTemplatesApi
.list("FULL") // See view options:
// https://cloud.google.com/sdk/gcloud/reference/beta/compute/instance-templates/list
.execute();
}

Collection<String> getZonesForRegion() {
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,96 @@ 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("BASIC");

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("BASIC");

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("BASIC");

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

@Test
public void list_withFullView_success() throws IOException {

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

InstanceTemplates instanceTemplates = createInstanceTemplates(transport);

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

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

assertThat(response).hasSize(2);
assertThat(response.get(0).getName()).isEqualTo("template1");
assertThat(response.get(0).getDescription()).isEqualTo("Detailed description for template1");
assertThat(response.get(1).getName()).isEqualTo("template2");
assertThat(response.get(1).getDescription()).isEqualTo("Detailed description for template2");
}

private static InstanceTemplates createInstanceTemplates(HttpTransport transport) {
return createInstanceTemplates(transport, new NoopRegistry());
}
Expand Down
Loading