use of io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension in project stackgres by ongres.
the class ExtensionManagerTest method getInstalledExtension.
private StackGresClusterInstalledExtension getInstalledExtension() {
StackGresClusterInstalledExtension installedExtension = new StackGresClusterInstalledExtension();
installedExtension.setName("timescaledb");
installedExtension.setPublisher("com.ongres");
installedExtension.setRepository(REPOSITORY.toASCIIString());
installedExtension.setVersion("1.7.1");
installedExtension.setPostgresVersion(POSTGRES_MAJOR_VERSION);
installedExtension.setBuild(BUILD_MAJOR_VERSION);
return installedExtension;
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension in project stackgres by ongres.
the class ExtensionManagerTest method testCheckExtensionWillOverwrite.
@Test
void testCheckExtensionWillOverwrite() throws Exception {
StackGresCluster cluster = getCluster();
when(webClientFactory.create(anyBoolean())).thenReturn(webClient);
when(webClient.getJson(any(), any())).thenReturn(getExtensions());
final String extensionPackageName = ExtensionUtil.getExtensionPackageName(getInstalledExtension());
when(fileSystemHandler.newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.TGZ_SUFFIX)))).then(invocation -> getClass().getResourceAsStream("/test.tgz"));
when(fileSystemHandler.exists(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql/12/lib").resolve("test.so")))).thenReturn(true);
StackGresClusterInstalledExtension extension = getInstalledExtension();
Assertions.assertTrue(extensionManager.getExtensionInstaller(context(cluster), extension).doesInstallOverwriteAnySharedLibrary());
verify(webClientFactory, times(1)).create(anyBoolean());
verify(webClient, times(1)).getJson(any(), any());
verify(webClient, times(1)).getJson(eq(ExtensionUtil.getIndexUri(REPOSITORY)), eq(StackGresExtensions.class));
verify(webClient, times(0)).getInputStream(eq(ExtensionUtil.getExtensionPackageUri(REPOSITORY, extension, getExtensionMetadata())));
verify(fileSystemHandler, times(0)).newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.SHA256_SUFFIX)));
verify(fileSystemHandler, times(1)).newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.TGZ_SUFFIX)));
verify(fileSystemHandler, times(0)).createOrReplaceFile(any());
verify(fileSystemHandler, times(0)).createDirectories(any());
verify(fileSystemHandler, times(0)).createOrReplaceSymbolicLink(any(), any());
verify(fileSystemHandler, times(0)).copyOrReplace(any(), any());
verify(fileSystemHandler, times(0)).setPosixFilePermissions(any(), any());
verify(fileSystemHandler, times(0)).deleteIfExists(any());
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension in project stackgres by ongres.
the class ExtensionEventEmitterImplTest method setUp.
@BeforeEach
void setUp() {
extension = new StackGresClusterInstalledExtension();
extension.setBuild(StringUtils.getRandomString());
extension.setName(StringUtils.getRandomString());
extension.setVersion(StringUtils.getRandomString());
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension in project stackgres by ongres.
the class ExtensionUtilTest method testExtensionsMetadataMap.
@Test
public void testExtensionsMetadataMap() {
StackGresClusterInstalledExtension installedExtension0 = new StackGresClusterInstalledExtension();
installedExtension0.setName(extensions.get(0).getName());
installedExtension0.setPublisher(extensionsMetadata.getPublishers().get(0).getId());
installedExtension0.setRepository(repository.toASCIIString());
installedExtension0.setVersion(extensions.get(0).getVersion());
installedExtension0.setPostgresVersion(firstPgMajorVersion);
installedExtension0.setBuild(build);
StackGresClusterInstalledExtension installedExtension1 = new StackGresClusterInstalledExtension();
installedExtension1.setName(extensions.get(1).getName());
installedExtension1.setPublisher(extensionsMetadata.getPublishers().get(0).getId());
installedExtension1.setRepository(repository.toASCIIString());
installedExtension1.setVersion(extensionsMetadata.getExtensions().stream().filter(e -> e.getName().equals(extensions.get(1).getName())).findAny().get().getVersions().get(0).getVersion());
installedExtension1.setPostgresVersion(firstPgMajorVersion);
installedExtension1.setBuild(build);
StackGresClusterInstalledExtension installedExtension2 = new StackGresClusterInstalledExtension();
installedExtension2.setName(extensions.get(2).getName());
installedExtension2.setPublisher(extensionsMetadata.getPublishers().get(0).getId());
installedExtension2.setRepository(repository.toASCIIString());
installedExtension2.setVersion(extensions.get(2).getVersion());
installedExtension2.setPostgresVersion(firstPgMajorVersion);
installedExtension2.setBuild(build);
StackGresClusterInstalledExtension installedExtension3 = new StackGresClusterInstalledExtension();
installedExtension3.setName(extensions.get(3).getName());
installedExtension3.setPublisher(extensionsMetadata.getPublishers().get(0).getId());
installedExtension3.setRepository(repository.toASCIIString());
installedExtension3.setVersion(extensionsMetadata.getExtensions().stream().filter(e -> e.getName().equals(extensions.get(3).getName())).findAny().get().getVersions().get(0).getVersion());
installedExtension3.setPostgresVersion(pgVersion);
installedExtension3.setBuild(build);
Map<StackGresExtensionIndex, StackGresExtensionMetadata> extensionMetadataMap = ExtensionUtil.toExtensionsMetadataIndex(repository, extensionsMetadata);
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension0)));
Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension0)).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension1)));
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension1)).getExtension().getRepository());
Assertions.assertNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension2)));
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension3)));
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension3)).getExtension().getRepository());
installedExtension0.setPostgresVersion(secondPgMajorVersion);
installedExtension1.setPostgresVersion(secondPgMajorVersion);
installedExtension2.setPostgresVersion(secondPgMajorVersion);
installedExtension3.setPostgresVersion(secondPgVersion);
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension0)));
Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension0)).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension1)));
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension1)).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension2)));
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension2)).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension3)));
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndex(installedExtension3)).getExtension().getRepository());
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension 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();
}
Aggregations