Skip to content

Commit

Permalink
Add payload caching for OSS repo.
Browse files Browse the repository at this point in the history
Update manifest models.
  • Loading branch information
sjrd218 committed Apr 30, 2019
1 parent 6331b11 commit a487f00
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ class ManifestEntry {

final ManifestEntry that = (ManifestEntry) o

if (id != that.id) {
if (getId() != that.getId()) {
return false
}

return true
}

int hashCode() {
return (id != null ? id.hashCode() : 0)
return (getId() != null ? getId().hashCode() : 0)
}

String getInstallId() { return id }
boolean getInstallable() { return true }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class RundeckManifestEntry extends ManifestEntry {
Map record = [:]

String getId() {
return record.object_id ?: record.post_id
return record.post_id
}

String getInstallId() {
return record.object_id
}

String getName() {
Expand All @@ -46,11 +50,11 @@ class RundeckManifestEntry extends ManifestEntry {
String getSourceLink() {
return record.source_link
}
//
// String getArtifactType() {
// return artifactType
// }
//

String getArtifactType() {
return record.artifact_type
}

String getSupport() {
return record.taxonomies?.plugin_support_type?.join(" ")
}
Expand All @@ -71,6 +75,8 @@ class RundeckManifestEntry extends ManifestEntry {
return record.binary_link
}

boolean getInstallable() { return record.object_id }

// Long getLastRelease() {
// return
// }
Expand Down
2 changes: 1 addition & 1 deletion repository-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

group = 'com.rundeck.repository'
archivesBaseName = 'repository'
version = "0.9.0"
version = "0.9.1"

// In this section you declare where to find the dependencies of your project
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package com.rundeck.repository.client.manifest
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder
import com.rundeck.repository.ResponseMessage
import com.rundeck.repository.client.util.ArtifactUtils
import com.rundeck.repository.manifest.ManifestEntry
Expand All @@ -32,16 +34,24 @@ import okhttp3.Response
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import java.util.concurrent.TimeUnit


class RundeckOfficialManifestService implements ManifestService {
private static Logger LOG = LoggerFactory.getLogger(HttpManifestSource)
private static ObjectMapper mapper = new ObjectMapper()
private static final String ARTIFACT_LIST = "artifact-list"
private static final Logger LOG = LoggerFactory.getLogger(HttpManifestSource)
private static final ObjectMapper mapper = new ObjectMapper()
private OkHttpClient client = new OkHttpClient();
private final String serviceEndpoint
private Cache<String,Collection<ManifestEntry>> cache

RundeckOfficialManifestService(String serviceEndpoint) {
RundeckOfficialManifestService(String serviceEndpoint, long cacheListTime, TimeUnit cacheUnit) {
this.serviceEndpoint = serviceEndpoint
if(LOG.traceEnabled) LOG.trace("service endpoint: ${serviceEndpoint}")
cache =CacheBuilder.newBuilder()
.maximumSize(1)
.expireAfterWrite(cacheListTime, cacheUnit)
.build()
}

@Override
Expand Down Expand Up @@ -75,6 +85,9 @@ class RundeckOfficialManifestService implements ManifestService {

@Override
Collection<ManifestEntry> listArtifacts(final Integer offset, final Integer max) {
Collection<ManifestEntry> artifactList = cache.getIfPresent(ARTIFACT_LIST)
if(artifactList != null) return artifactList
artifactList = []
Response response
try {
Request rq = new Request.Builder()
Expand All @@ -84,12 +97,13 @@ class RundeckOfficialManifestService implements ManifestService {
response = client.newCall(rq).execute()
if(response.isSuccessful()) {
def map = mapper.readValue(response.body().byteStream(),HashMap)
Collection<ManifestEntry> artifactList = []

map.hits.each { hit ->
RundeckManifestEntry entry = new RundeckManifestEntry()
entry.record = hit
artifactList.add(entry)
}
cache.put(ARTIFACT_LIST,artifactList)
return artifactList
} else {
LOG.error("listArtifacts http error: ${response.body().string()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import okhttp3.Response
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import java.util.concurrent.TimeUnit


class RundeckHttpRepository implements ArtifactRepository {
private static final String REPO_ENDPOINT = "https://api.rundeck.com/repo/v1/oss"
Expand All @@ -49,7 +51,7 @@ class RundeckHttpRepository implements ArtifactRepository {
RundeckHttpRepository(RepositoryDefinition repoDef) {
this.rundeckRepositoryEndpoint = repoDef.configProperties.staging == true ? REPO_STAGING_ENDPOINT : REPO_ENDPOINT
this.repositoryDefinition = repoDef
this.manifestService = new RundeckOfficialManifestService(this.rundeckRepositoryEndpoint)
this.manifestService = new RundeckOfficialManifestService(this.rundeckRepositoryEndpoint, 24, TimeUnit.HOURS)
}

@Override
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider
import spock.lang.Specification

import java.security.Security
import java.util.concurrent.TimeUnit


class RundeckHttpRepositoryTest extends Specification {
Expand All @@ -49,7 +50,7 @@ class RundeckHttpRepositoryTest extends Specification {
repoDef.repositoryName = "OSS"
RundeckHttpRepository repo = new RundeckHttpRepository(repoDef)
repo.rundeckRepositoryEndpoint = endpoint
repo.manifestService = new RundeckOfficialManifestService(endpoint)
repo.manifestService = new RundeckOfficialManifestService(endpoint, 1, TimeUnit.HOURS)
def pubKey = repo.getRundeckPublicKey()
RecordedRequest r = httpServer.takeRequest()
def pubKeyFromCache = repo.getRundeckPublicKey()
Expand Down

0 comments on commit a487f00

Please sign in to comment.