diff --git a/front50-core/src/main/groovy/com/netflix/spinnaker/front50/model/StorageService.java b/front50-core/src/main/groovy/com/netflix/spinnaker/front50/model/StorageService.java index 4ae372c61..249d33a04 100644 --- a/front50-core/src/main/groovy/com/netflix/spinnaker/front50/model/StorageService.java +++ b/front50-core/src/main/groovy/com/netflix/spinnaker/front50/model/StorageService.java @@ -28,6 +28,10 @@ public interface StorageService { /** Returns true if the storage service supports versioning. */ boolean supportsVersioning(); + default boolean supportsEventing(ObjectType objectType) { + return true; + } + T loadObject(ObjectType objectType, String objectKey) throws NotFoundException; diff --git a/front50-s3/src/main/java/com/netflix/spinnaker/front50/config/S3Config.java b/front50-s3/src/main/java/com/netflix/spinnaker/front50/config/S3Config.java index ec6d956d8..ca7160b90 100644 --- a/front50-s3/src/main/java/com/netflix/spinnaker/front50/config/S3Config.java +++ b/front50-s3/src/main/java/com/netflix/spinnaker/front50/config/S3Config.java @@ -18,6 +18,7 @@ import com.netflix.spinnaker.front50.model.EventingS3ObjectKeyLoader; import com.netflix.spinnaker.front50.model.ObjectKeyLoader; import com.netflix.spinnaker.front50.model.S3StorageService; +import com.netflix.spinnaker.front50.model.StorageService; import com.netflix.spinnaker.front50.model.TemporarySQSQueue; import com.netflix.spinnaker.kork.aws.bastion.BastionConfig; import java.net.InetAddress; @@ -123,7 +124,7 @@ public TemporarySQSQueue temporaryQueueSupport( public ObjectKeyLoader eventingS3ObjectKeyLoader( ObjectMapper objectMapper, S3Properties s3Properties, - S3StorageService s3StorageService, + StorageService storageService, TemporarySQSQueue temporaryQueueSupport, Registry registry) { return new EventingS3ObjectKeyLoader( @@ -131,7 +132,7 @@ public ObjectKeyLoader eventingS3ObjectKeyLoader( objectMapper, s3Properties, temporaryQueueSupport, - s3StorageService, + storageService, registry, true); } diff --git a/front50-s3/src/main/java/com/netflix/spinnaker/front50/model/EventingS3ObjectKeyLoader.java b/front50-s3/src/main/java/com/netflix/spinnaker/front50/model/EventingS3ObjectKeyLoader.java index ccfa4ec3a..8c367a098 100644 --- a/front50-s3/src/main/java/com/netflix/spinnaker/front50/model/EventingS3ObjectKeyLoader.java +++ b/front50-s3/src/main/java/com/netflix/spinnaker/front50/model/EventingS3ObjectKeyLoader.java @@ -65,7 +65,7 @@ public class EventingS3ObjectKeyLoader implements ObjectKeyLoader, Runnable { private final ObjectMapper objectMapper; private final TemporarySQSQueue temporarySQSQueue; - private final S3StorageService s3StorageService; + private final StorageService storageService; private final Registry registry; private final Cache objectKeysByLastModifiedCache; @@ -80,12 +80,12 @@ public EventingS3ObjectKeyLoader( ObjectMapper objectMapper, S3Properties s3Properties, TemporarySQSQueue temporarySQSQueue, - S3StorageService s3StorageService, + StorageService storageService, Registry registry, boolean scheduleImmediately) { this.objectMapper = objectMapper; this.temporarySQSQueue = temporarySQSQueue; - this.s3StorageService = s3StorageService; + this.storageService = storageService; this.registry = registry; this.objectKeysByLastModifiedCache = @@ -106,7 +106,7 @@ public EventingS3ObjectKeyLoader( @Override public Map load(ObjectType objectType) throws Exception { log.debug("Loading object keys for {}", value("type", objectType)); - return s3StorageService.listObjectKeys(objectType); + return storageService.listObjectKeys(objectType); } @Override @@ -118,7 +118,7 @@ public ListenableFuture> reload( log.debug( "Refreshing object keys for {} (asynchronous)", value("type", objectType)); - return s3StorageService.listObjectKeys(objectType); + return storageService.listObjectKeys(objectType); }); executor.execute(task); return task; @@ -142,6 +142,10 @@ public void shutdown() { @Override public Map listObjectKeys(ObjectType objectType) { + if (!storageService.supportsEventing(objectType)) { + return storageService.listObjectKeys(objectType); + } + try { Map objectKeys = objectKeysByObjectTypeCache.get(objectType); objectKeysByLastModifiedCache.asMap().entrySet().stream() @@ -173,7 +177,7 @@ public Map listObjectKeys(ObjectType objectType) { return objectKeys; } catch (ExecutionException e) { log.error("Unable to fetch keys from cache", e); - return s3StorageService.listObjectKeys(objectType); + return storageService.listObjectKeys(objectType); } } diff --git a/front50-s3/src/test/groovy/com/netflix/spinnaker/front50/model/EventingS3ObjectKeyLoaderSpec.groovy b/front50-s3/src/test/groovy/com/netflix/spinnaker/front50/model/EventingS3ObjectKeyLoaderSpec.groovy index cd134f7ef..f87e93ba2 100644 --- a/front50-s3/src/test/groovy/com/netflix/spinnaker/front50/model/EventingS3ObjectKeyLoaderSpec.groovy +++ b/front50-s3/src/test/groovy/com/netflix/spinnaker/front50/model/EventingS3ObjectKeyLoaderSpec.groovy @@ -75,6 +75,7 @@ class EventingS3ObjectKeyLoaderSpec extends Specification { def objectKeys = objectKeyLoader.listObjectKeys(ObjectType.APPLICATION) then: + 1 * s3StorageService.supportsEventing(_) >> { return true } 1 * s3StorageService.listObjectKeys(ObjectType.APPLICATION) >> { return [ "key1": 100L,