Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appengine): adds platform application caching agent (#1538)
- Loading branch information
1 parent
d3ecca8
commit 21def0e
Showing
4 changed files
with
136 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ovy/com/netflix/spinnaker/clouddriver/appengine/model/AppenginePlatformApplication.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2017 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.clouddriver.appengine.model | ||
|
||
import com.google.api.services.appengine.v1.model.Application | ||
import groovy.transform.TupleConstructor | ||
|
||
class AppenginePlatformApplication { | ||
List<AppengineDispatchRule> dispatchRules | ||
String authDomain | ||
String codeBucket | ||
String defaultBucket | ||
String defaultCookieExpiration | ||
String defaultHostname | ||
String id | ||
String locationId | ||
|
||
AppenginePlatformApplication(Application application) { | ||
this.dispatchRules = application.getDispatchRules()?.collect { rule -> | ||
new AppengineDispatchRule(rule.getDomain(), rule.getPath(), rule.getService()) | ||
} ?: [] | ||
this.authDomain = application.getAuthDomain() | ||
this.codeBucket = application.getCodeBucket() | ||
this.defaultBucket = application.getDefaultBucket() | ||
this.defaultCookieExpiration = application.getDefaultCookieExpiration() | ||
this.defaultHostname = application.getDefaultHostname() | ||
this.id = application.getId() | ||
this.locationId = application.getLocationId() | ||
} | ||
|
||
@TupleConstructor | ||
static class AppengineDispatchRule { | ||
String domain | ||
String path | ||
String service | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...aker/clouddriver/appengine/provider/agent/AppenginePlatformApplicationCachingAgent.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2017 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.clouddriver.appengine.provider.agent | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.google.api.services.appengine.v1.model.Application | ||
import com.netflix.spinnaker.cats.agent.AgentDataType | ||
import com.netflix.spinnaker.cats.agent.CacheResult | ||
import com.netflix.spinnaker.cats.agent.DefaultCacheResult | ||
import com.netflix.spinnaker.cats.provider.ProviderCache | ||
import com.netflix.spinnaker.clouddriver.appengine.cache.Keys | ||
import com.netflix.spinnaker.clouddriver.appengine.model.AppenginePlatformApplication | ||
import com.netflix.spinnaker.clouddriver.appengine.security.AppengineNamedAccountCredentials | ||
import com.netflix.spinnaker.clouddriver.kubernetes.provider.view.MutableCacheData | ||
import groovy.util.logging.Slf4j | ||
|
||
import static com.netflix.spinnaker.cats.agent.AgentDataType.Authority.AUTHORITATIVE | ||
|
||
@Slf4j | ||
class AppenginePlatformApplicationCachingAgent extends AbstractAppengineCachingAgent { | ||
String agentType = "${accountName}/${AppenginePlatformApplicationCachingAgent.simpleName}" | ||
|
||
static final Set<AgentDataType> types = Collections.unmodifiableSet([ | ||
AUTHORITATIVE.forType(Keys.Namespace.PLATFORM_APPLICATIONS.ns)] as Set | ||
) | ||
|
||
AppenginePlatformApplicationCachingAgent(String accountName, | ||
AppengineNamedAccountCredentials credentials, | ||
ObjectMapper objectMapper) { | ||
super(accountName, objectMapper, credentials) | ||
} | ||
|
||
@Override | ||
String getSimpleName() { | ||
AppenginePlatformApplicationCachingAgent.simpleName | ||
} | ||
|
||
@Override | ||
Collection<AgentDataType> getProvidedDataTypes() { | ||
types | ||
} | ||
|
||
@Override | ||
CacheResult loadData(ProviderCache providerCache) { | ||
def platformApplicationName = credentials.project | ||
Application platformApplication = credentials.appengine.apps().get(platformApplicationName).execute() | ||
Map<String, MutableCacheData> cachedPlatformApplications = MutableCacheData.mutableCacheMap() | ||
def apiApplicationKey = Keys.getPlatformApplicationKey(platformApplicationName) | ||
|
||
cachedPlatformApplications[apiApplicationKey].with { | ||
attributes.name = platformApplicationName | ||
attributes.platformApplication = new AppenginePlatformApplication(platformApplication) | ||
} | ||
|
||
log.info("Caching ${cachedPlatformApplications.size()} platform applications in ${agentType}") | ||
return new DefaultCacheResult([(Keys.Namespace.PLATFORM_APPLICATIONS.ns): cachedPlatformApplications.values()], [:]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters