diff --git a/acceptance-tests/src/test-support/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java b/acceptance-tests/src/test-support/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java index e2adef3f2a..a575dcccc1 100644 --- a/acceptance-tests/src/test-support/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java +++ b/acceptance-tests/src/test-support/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java @@ -126,7 +126,7 @@ public void startNode(final PantheonNode node) { final KeyValueStorageProvider storageProvider = new KeyValueStorageProviderBuilder() - .withStorageFactory(storageService.getByName("rocksdb")) + .withStorageFactory(storageService.getByName("rocksdb").get()) .withCommonConfiguration(commonPluginConfiguration) .withMetricsSystem(metricsSystem) .build(); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 4cee9dbc50..ea182da6c5 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -95,6 +95,7 @@ import tech.pegasys.pantheon.plugin.services.PantheonEvents; import tech.pegasys.pantheon.plugin.services.PicoCLIOptions; import tech.pegasys.pantheon.plugin.services.StorageService; +import tech.pegasys.pantheon.plugin.services.exception.StorageException; import tech.pegasys.pantheon.plugin.services.metrics.MetricCategory; import tech.pegasys.pantheon.plugin.services.storage.rocksdb.RocksDBPlugin; import tech.pegasys.pantheon.services.PantheonConfigurationImpl; @@ -1263,7 +1264,11 @@ private PrivacyParameters privacyParameters() throws IOException { private KeyValueStorageProvider keyStorageProvider(final String name) { return new KeyValueStorageProviderBuilder() - .withStorageFactory(storageService.getByName(name)) + .withStorageFactory( + storageService + .getByName(name) + .orElseThrow( + () -> new StorageException("No KeyValueStorageFactory found for key: " + name))) .withCommonConfiguration(pluginCommonConfiguration) .withMetricsSystem(getMetricsSystem()) .build(); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/services/StorageServiceImpl.java b/pantheon/src/main/java/tech/pegasys/pantheon/services/StorageServiceImpl.java index d850af9523..c7ff5054ab 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/services/StorageServiceImpl.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/services/StorageServiceImpl.java @@ -14,7 +14,6 @@ import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import tech.pegasys.pantheon.plugin.services.StorageService; -import tech.pegasys.pantheon.plugin.services.exception.StorageException; import tech.pegasys.pantheon.plugin.services.storage.KeyValueStorageFactory; import tech.pegasys.pantheon.plugin.services.storage.SegmentIdentifier; @@ -43,9 +42,8 @@ public List getAllSegmentIdentifiers() { return segments; } - public KeyValueStorageFactory getByName(final String name) { - return Optional.ofNullable(factories.get(name)) - .orElseThrow( - () -> new StorageException("No KeyValueStorageFactory found for key: " + name)); + @Override + public Optional getByName(final String name) { + return Optional.ofNullable(factories.get(name)); } } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index b4ecf92f92..12dc3abe1c 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -201,7 +201,7 @@ public void initMocks() throws Exception { when(mockRunnerBuilder.staticNodes(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.build()).thenReturn(mockRunner); - when(storageService.getByName("rocksdb")).thenReturn(rocksDBStorageFactory); + when(storageService.getByName("rocksdb")).thenReturn(Optional.of(rocksDBStorageFactory)); when(mockPantheonPluginContext.getService(PicoCLIOptions.class)) .thenReturn(Optional.of(cliOptions)); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index 81b7f7630b..0af886669b 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -2473,7 +2473,8 @@ public void fullCLIOptionsShownWhenNotInDockerContainer() { @Test public void mustUseEnclaveUriAndOptions() { - when(storageService.getByName("rocksdb-privacy")).thenReturn(rocksDBSPrivacyStorageFactory); + when(storageService.getByName("rocksdb-privacy")) + .thenReturn(Optional.of(rocksDBSPrivacyStorageFactory)); final URL configFile = this.getClass().getResource("/orion_publickey.pub"); parseCommand( diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 2424f6397e..ba1f8d8cc1 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -56,7 +56,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'sRinlNFG0IbW1DXvVnpa/a4puB5WD0g2GReAGkIl6dc=' + knownHash = 'FzYuZLAwab2uzCEqdVvkpUL5lih3M4MUKT+qXgGmB7I=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/StorageService.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/StorageService.java index e5fbdf0367..9a1efde870 100644 --- a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/StorageService.java +++ b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/StorageService.java @@ -17,6 +17,7 @@ import tech.pegasys.pantheon.plugin.services.storage.SegmentIdentifier; import java.util.List; +import java.util.Optional; /** This service allows plugins to register as an available storage engine. */ @Unstable @@ -35,4 +36,13 @@ public interface StorageService { * @return full set of possible segments required from the storage service. */ List getAllSegmentIdentifiers(); + + /** + * Retrieves a registered factory corresponding to the supplied factory name + * + * @param name The name of the factory to retrieve + * @return an optional containing the instance of the registered factory, or empty if the factory + * hasn't been registered. + */ + Optional getByName(String name); }