Skip to content

Commit

Permalink
feat(s3): Support for disabling s3 eventing on a per-ObjectType basis (
Browse files Browse the repository at this point in the history
  • Loading branch information
ajordens committed May 30, 2019
1 parent e2a43fb commit 799d103
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 extends Timestamped> T loadObject(ObjectType objectType, String objectKey)
throws NotFoundException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,15 +124,15 @@ public TemporarySQSQueue temporaryQueueSupport(
public ObjectKeyLoader eventingS3ObjectKeyLoader(
ObjectMapper objectMapper,
S3Properties s3Properties,
S3StorageService s3StorageService,
StorageService storageService,
TemporarySQSQueue temporaryQueueSupport,
Registry registry) {
return new EventingS3ObjectKeyLoader(
Executors.newFixedThreadPool(1),
objectMapper,
s3Properties,
temporaryQueueSupport,
s3StorageService,
storageService,
registry,
true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyWithObjectType, Long> objectKeysByLastModifiedCache;
Expand All @@ -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 =
Expand All @@ -106,7 +106,7 @@ public EventingS3ObjectKeyLoader(
@Override
public Map<String, Long> load(ObjectType objectType) throws Exception {
log.debug("Loading object keys for {}", value("type", objectType));
return s3StorageService.listObjectKeys(objectType);
return storageService.listObjectKeys(objectType);
}

@Override
Expand All @@ -118,7 +118,7 @@ public ListenableFuture<Map<String, Long>> reload(
log.debug(
"Refreshing object keys for {} (asynchronous)",
value("type", objectType));
return s3StorageService.listObjectKeys(objectType);
return storageService.listObjectKeys(objectType);
});
executor.execute(task);
return task;
Expand All @@ -142,6 +142,10 @@ public void shutdown() {

@Override
public Map<String, Long> listObjectKeys(ObjectType objectType) {
if (!storageService.supportsEventing(objectType)) {
return storageService.listObjectKeys(objectType);
}

try {
Map<String, Long> objectKeys = objectKeysByObjectTypeCache.get(objectType);
objectKeysByLastModifiedCache.asMap().entrySet().stream()
Expand Down Expand Up @@ -173,7 +177,7 @@ public Map<String, Long> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 799d103

Please sign in to comment.