use of io.stackgres.common.extension.StackGresExtensionMetadata in project stackgres by ongres.
the class AbstractExtensionsMutator method getExtension.
protected Optional<StackGresClusterInstalledExtension> getExtension(StackGresCluster cluster, String extensionName, String extensionVersion) {
StackGresClusterExtension extension = new StackGresClusterExtension();
extension.setName(extensionName);
extension.setVersion(extensionVersion);
try {
StackGresExtensionMetadata extensionMetadata = getExtensionMetadataManager().getExtensionCandidateSameMajorBuild(cluster, extension);
return Optional.of(ExtensionUtil.getInstalledExtension(extension, extensionMetadata));
} catch (Exception ex) {
LOGGER.warn("Unable to retrieve candidate with same major build for extension", ex);
return Optional.empty();
}
}
use of io.stackgres.common.extension.StackGresExtensionMetadata in project stackgres by ongres.
the class ExtensionsMutatorTest method clusterWithExtensionInstalledAddExtensionWithExtraMounts_shouldReplaceToInstallExtensions.
@Test
void clusterWithExtensionInstalledAddExtensionWithExtraMounts_shouldReplaceToInstallExtensions() throws Exception {
final StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
final StackGresClusterExtension extension = getExtension();
extension.setVersion(installedExtension.getVersion());
review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(extension));
review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
installedTestExtension.setName("test");
review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedTestExtension);
final StackGresExtensionMetadata extensionMetadata = getExtensionMetadata();
extensionMetadata.getVersion().setExtraMounts(ImmutableList.of("test"));
when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(extension))).thenReturn(extensionMetadata);
final List<JsonPatchOperation> operations = mutator.mutate(review);
assertEquals(1, operations.size());
assertEquals(1, operations.stream().filter(o -> o instanceof ReplaceOperation).count());
}
use of io.stackgres.common.extension.StackGresExtensionMetadata in project stackgres by ongres.
the class ExtensionsMutatorTest method clusterWithMissingExtension_shouldNotDoAnything.
@Test
void clusterWithMissingExtension_shouldNotDoAnything() throws Exception {
final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
installedTestExtension.setName("test");
final StackGresClusterExtension testExtension = getExtension();
testExtension.setName("test");
testExtension.setVersion(installedTestExtension.getVersion());
review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(testExtension));
review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
final StackGresExtensionMetadata extensionTestMetadata = getExtensionMetadata();
extensionTestMetadata.getExtension().setName("test");
when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(testExtension))).thenThrow(IllegalArgumentException.class);
final List<JsonPatchOperation> operations = mutator.mutate(review);
assertEquals(0, operations.size());
}
use of io.stackgres.common.extension.StackGresExtensionMetadata in project stackgres by ongres.
the class ExtensionsMutatorTest method clusterWithExtensionInstalledAddADifferntExtension_shouldAddToInstallPostgresExtensions.
@Test
void clusterWithExtensionInstalledAddADifferntExtension_shouldAddToInstallPostgresExtensions() throws Exception {
final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
installedTestExtension.setName("test");
final StackGresClusterExtension testExtension = getExtension();
testExtension.setName("test");
testExtension.setVersion(installedTestExtension.getVersion());
final StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
final StackGresClusterExtension extension = getExtension();
extension.setVersion(installedExtension.getVersion());
review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(extension, testExtension));
review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedTestExtension);
final StackGresExtensionMetadata extensionTestMetadata = getExtensionMetadata();
extensionTestMetadata.getExtension().setName("test");
when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(testExtension))).thenReturn(extensionTestMetadata);
final StackGresExtensionMetadata extensionMetadata = getExtensionMetadata();
when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(extension))).thenReturn(extensionMetadata);
final List<JsonPatchOperation> operations = mutator.mutate(review);
assertEquals(1, operations.size());
}
use of io.stackgres.common.extension.StackGresExtensionMetadata in project stackgres by ongres.
the class ExtensionsMutatorTest method clusterWithAnAlreadyInstalledMissingExtension_shouldReplaceToInstall.
@Test
void clusterWithAnAlreadyInstalledMissingExtension_shouldReplaceToInstall() throws Exception {
final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
installedTestExtension.setName("test");
final StackGresClusterExtension testExtension = getExtension();
testExtension.setName("test");
testExtension.setVersion(installedTestExtension.getVersion());
review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(testExtension));
review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedTestExtension);
final StackGresExtensionMetadata extensionTestMetadata = getExtensionMetadata();
extensionTestMetadata.getExtension().setName("test");
when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(testExtension))).thenThrow(IllegalArgumentException.class);
final List<JsonPatchOperation> operations = mutator.mutate(review);
assertEquals(1, operations.size());
assertEquals(1, operations.stream().filter(o -> o instanceof ReplaceOperation).count());
}
Aggregations