use of io.stackgres.common.crd.sgcluster.StackGresClusterExtension in project stackgres by ongres.
the class ExtensionManagerTest method getClusterExtension.
private StackGresClusterExtension getClusterExtension() {
StackGresClusterExtension extension = new StackGresClusterExtension();
extension.setName("timescaledb");
return extension;
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterExtension 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.crd.sgcluster.StackGresClusterExtension in project stackgres by ongres.
the class AbstractExtensionsMutator method mutateExtensions.
private ImmutableList<JsonPatchOperation> mutateExtensions(T customResource) {
final ImmutableList.Builder<JsonPatchOperation> operations = ImmutableList.builder();
final StackGresCluster cluster = getCluster(customResource);
List<StackGresClusterExtension> extensions = getExtensions(customResource);
List<StackGresClusterInstalledExtension> missingDefaultExtensions = Seq.seq(getDefaultExtensions(getCluster(customResource))).filter(defaultExtension -> extensions.stream().noneMatch(extension -> extension.getName().equals(defaultExtension.getName()))).collect(ImmutableList.toImmutableList());
final List<StackGresClusterInstalledExtension> toInstallExtensions = Seq.seq(extensions).map(extension -> getToInstallExtension(cluster, extension)).filter(Optional::isPresent).map(Optional::get).append(missingDefaultExtensions).collect(ImmutableList.toImmutableList());
final ArrayNode toInstallExtensionsNode = getObjectMapper().valueToTree(toInstallExtensions);
if (getToInstallExtensions(customResource).orElse(null) == null) {
operations.add(new AddOperation(TO_INSTALL_EXTENSIONS_POINTER, toInstallExtensionsNode));
} else if (getToInstallExtensions(customResource).map(previousToInstallExtensions -> toInstallExtensionsHasChanged(toInstallExtensions, previousToInstallExtensions)).orElse(true)) {
operations.add(new ReplaceOperation(TO_INSTALL_EXTENSIONS_POINTER, toInstallExtensionsNode));
}
Seq.seq(extensions).zipWithIndex().forEach(extension -> toInstallExtensions.stream().filter(toInstallExtension -> toInstallExtension.getName().equals(extension.v1.getName())).findFirst().ifPresent(installedExtension -> onExtensionToInstall(operations, extension.v1, extension.v2.intValue(), installedExtension)));
return operations.build();
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterExtension 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.crd.sgcluster.StackGresClusterExtension 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());
}
Aggregations