Skip to content

Commit

Permalink
fix(provider/gce): Paginate instance template list in svg caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtk54 committed Oct 24, 2017
1 parent 84ebd77 commit ded22ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ class GoogleRegionalServerGroupCachingAgent extends AbstractGoogleCachingAgent i
BatchRequest instanceGroupsRequest = buildBatchRequest()
BatchRequest autoscalerRequest = buildBatchRequest()

List<InstanceTemplate> instanceTemplates = timeExecute(
compute.instanceTemplates().list(project),
"compute.instanceTemplates.list",
TAG_SCOPE, SCOPE_GLOBAL)
.getItems()
List<InstanceTemplate> instanceTemplates = GoogleZonalServerGroupCachingAgent.fetchInstanceTemplates(compute, project)

InstanceGroupManagerCallbacks instanceGroupManagerCallbacks = new InstanceGroupManagerCallbacks(
providerCache: providerCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.google.api.client.googleapis.batch.BatchRequest
import com.google.api.client.googleapis.batch.json.JsonBatchCallback
import com.google.api.client.googleapis.json.GoogleJsonError
import com.google.api.client.http.HttpHeaders
import com.google.api.services.compute.Compute
import com.google.api.services.compute.model.*
import com.netflix.frigga.Names
import com.netflix.frigga.ami.AppVersion
Expand All @@ -42,6 +43,7 @@ import com.netflix.spinnaker.clouddriver.google.model.GoogleServerGroup
import com.netflix.spinnaker.clouddriver.google.model.callbacks.Utils
import com.netflix.spinnaker.clouddriver.google.model.loadbalancing.GoogleHttpLoadBalancingPolicy
import com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials
import com.netflix.spinnaker.clouddriver.googlecommon.GoogleExecutor
import groovy.transform.Canonical
import groovy.util.logging.Slf4j

Expand Down Expand Up @@ -135,11 +137,7 @@ class GoogleZonalServerGroupCachingAgent extends AbstractGoogleCachingAgent impl
BatchRequest instanceGroupsRequest = buildBatchRequest()
BatchRequest autoscalerRequest = buildBatchRequest()

List<InstanceTemplate> instanceTemplates = timeExecute(
compute.instanceTemplates().list(project),
"compute.instanceTemplates.list",
TAG_SCOPE, SCOPE_GLOBAL)
.getItems()
List<InstanceTemplate> instanceTemplates = fetchInstanceTemplates(compute, project)

zones?.each { String zone ->
InstanceGroupManagerCallbacks instanceGroupManagerCallbacks = new InstanceGroupManagerCallbacks(
Expand All @@ -165,6 +163,25 @@ class GoogleZonalServerGroupCachingAgent extends AbstractGoogleCachingAgent impl
serverGroups
}

static List<InstanceTemplate> fetchInstanceTemplates(Compute compute, String project) {
Boolean executedAtLeastOnce = false
String nextPageToken = null
List<InstanceTemplate> instanceTemplates = []
while (!executedAtLeastOnce || nextPageToken) {
InstanceTemplateList instanceTemplateList = GoogleExecutor.timeExecute(
GoogleExecutor.getRegistry(),
compute.instanceTemplates().list(project).setPageToken(nextPageToken),
"google.api",
"compute.instanceTemplates.list",
GoogleExecutor.TAG_SCOPE, GoogleExecutor.SCOPE_GLOBAL)

executedAtLeastOnce = true
nextPageToken = instanceTemplateList.getNextPageToken()
instanceTemplates.addAll(instanceTemplateList.getItems())
}
return instanceTemplates
}

@Override
boolean handles(OnDemandAgent.OnDemandType type, String cloudProvider) {
type == OnDemandAgent.OnDemandType.ServerGroup && cloudProvider == GoogleCloudProvider.ID
Expand Down

0 comments on commit ded22ee

Please sign in to comment.