use of io.stackgres.common.extension.ExtensionManager.ExtensionInstaller in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithExtension_installIsPerformed.
@Test
void testReconciliationWithExtension_installIsPerformed() throws Exception {
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
});
when(extensionManager.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionInstalled()).thenReturn(false);
when(extensionInstaller.isExtensionPendingOverwrite()).thenReturn(false);
doNothing().when(eventEmitter).emitExtensionDeployed(installedExtension);
Assertions.assertTrue(reconciliator.reconcile(null, context).result().get());
Assertions.assertTrue(Optional.of(context.getCluster()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getPodStatuses).stream().flatMap(List::stream).anyMatch(podStatus -> podStatus.getName().equals("test-0")));
Assertions.assertFalse(context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getPendingRestart).orElse(false));
Assertions.assertIterableEquals(ImmutableList.of(installedExtension), context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getInstalledPostgresExtensions).stream().flatMap(List::stream).collect(ImmutableList.toImmutableList()));
verify(extensionInstaller, times(1)).isExtensionInstalled();
verify(extensionInstaller, times(0)).isLinksCreated();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(1)).downloadAndExtract();
verify(extensionInstaller, times(1)).verify();
verify(extensionInstaller, times(1)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(1)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
verify(eventEmitter).emitExtensionDeployed(installedExtension);
}
use of io.stackgres.common.extension.ExtensionManager.ExtensionInstaller in project stackgres by ongres.
the class ExtensionManagerTest method testSetExtensionAsPending.
@Test
void testSetExtensionAsPending() throws Exception {
StackGresCluster cluster = getCluster();
StackGresClusterInstalledExtension extension = getInstalledExtension();
when(webClientFactory.create(anyBoolean())).thenReturn(webClient);
when(webClient.getJson(any(), any())).thenReturn(getExtensions());
final String extensionPackageName = ExtensionUtil.getExtensionPackageName(getInstalledExtension());
ExtensionInstaller extensionInstaller = extensionManager.getExtensionInstaller(context(cluster), extension);
extensionInstaller.setExtensionAsPending();
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(any());
verify(fileSystemHandler, times(0)).newInputStream(any());
verify(fileSystemHandler, times(1)).createOrReplaceFile(any());
verify(fileSystemHandler, times(1)).createOrReplaceFile(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.PENDING_SUFFIX)));
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.extension.ExtensionManager.ExtensionInstaller in project stackgres by ongres.
the class ExtensionReconciliationTest method testInitReconciliationWithExtensionPending_installIsPerformed.
@Test
void testInitReconciliationWithExtensionPending_installIsPerformed() throws Exception {
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
cluster.setStatus(new StackGresClusterStatus());
cluster.getStatus().setPodStatuses(new ArrayList<>());
StackGresClusterPodStatus podStatus = new StackGresClusterPodStatus();
podStatus.setName("test-0");
podStatus.setPendingRestart(true);
podStatus.setInstalledPostgresExtensions(new ArrayList<>());
podStatus.getInstalledPostgresExtensions().add(installedExtension);
cluster.getStatus().getPodStatuses().add(podStatus);
});
when(extensionManager.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionInstalled()).thenReturn(false);
doNothing().when(eventEmitter).emitExtensionDeployed(installedExtension);
Assertions.assertTrue(initReconciliator.reconcile(null, context).result().get());
Assertions.assertTrue(Optional.of(context.getCluster()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getPodStatuses).stream().flatMap(List::stream).anyMatch(podStatus -> podStatus.getName().equals("test-0")));
Assertions.assertFalse(context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getPendingRestart).orElse(false));
Assertions.assertIterableEquals(ImmutableList.of(installedExtension), context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getInstalledPostgresExtensions).stream().flatMap(List::stream).collect(ImmutableList.toImmutableList()));
verify(extensionInstaller, times(1)).isExtensionInstalled();
verify(extensionInstaller, times(0)).isLinksCreated();
verify(extensionInstaller, times(0)).isExtensionPendingOverwrite();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(1)).downloadAndExtract();
verify(extensionInstaller, times(1)).verify();
verify(extensionInstaller, times(1)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(0)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
verify(eventEmitter).emitExtensionDeployed(installedExtension);
}
use of io.stackgres.common.extension.ExtensionManager.ExtensionInstaller in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithExtensionPending_installIsSkipped.
@Test
void testReconciliationWithExtensionPending_installIsSkipped() throws Exception {
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
cluster.setStatus(new StackGresClusterStatus());
cluster.getStatus().setPodStatuses(new ArrayList<>());
StackGresClusterPodStatus podStatus = new StackGresClusterPodStatus();
podStatus.setName("test-0");
podStatus.setPendingRestart(true);
podStatus.setInstalledPostgresExtensions(new ArrayList<>());
podStatus.getInstalledPostgresExtensions().add(installedExtension);
cluster.getStatus().getPodStatuses().add(podStatus);
});
when(extensionManager.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionInstalled()).thenReturn(false);
when(extensionInstaller.isLinksCreated()).thenReturn(true);
when(extensionInstaller.isExtensionPendingOverwrite()).thenReturn(true);
Assertions.assertFalse(reconciliator.reconcile(null, context).result().get());
Assertions.assertTrue(Optional.of(context.getCluster()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getPodStatuses).stream().flatMap(List::stream).anyMatch(podStatus -> podStatus.getName().equals("test-0")));
Assertions.assertTrue(context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getPendingRestart).orElse(false));
Assertions.assertIterableEquals(ImmutableList.of(installedExtension), context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getInstalledPostgresExtensions).stream().flatMap(List::stream).collect(ImmutableList.toImmutableList()));
verify(extensionInstaller, times(1)).isExtensionInstalled();
verify(extensionInstaller, times(1)).isLinksCreated();
verify(extensionInstaller, times(1)).isExtensionPendingOverwrite();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(0)).downloadAndExtract();
verify(extensionInstaller, times(0)).verify();
verify(extensionInstaller, times(0)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(0)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
}
use of io.stackgres.common.extension.ExtensionManager.ExtensionInstaller in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithInstalledExtensions_uninstallIsSkippedButStatusUpdated.
@Test
void testReconciliationWithInstalledExtensions_uninstallIsSkippedButStatusUpdated() throws Exception {
final StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.setStatus(new StackGresClusterStatus());
cluster.getStatus().setPodStatuses(new ArrayList<>());
StackGresClusterPodStatus podStatus = new StackGresClusterPodStatus();
podStatus.setName("test-0");
podStatus.setInstalledPostgresExtensions(new ArrayList<>());
podStatus.getInstalledPostgresExtensions().add(installedExtension);
cluster.getStatus().getPodStatuses().add(podStatus);
});
Assertions.assertTrue(reconciliator.reconcile(null, context).result().get());
Assertions.assertTrue(Optional.of(context.getCluster()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getPodStatuses).stream().flatMap(List::stream).anyMatch(podStatus -> podStatus.getName().equals("test-0")));
Assertions.assertTrue(context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getPendingRestart).orElse(true));
Assertions.assertIterableEquals(ImmutableList.of(installedExtension), context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getInstalledPostgresExtensions).stream().flatMap(List::stream).collect(ImmutableList.toImmutableList()));
verify(extensionInstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(0)).isLinksCreated();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(0)).downloadAndExtract();
verify(extensionInstaller, times(0)).verify();
verify(extensionInstaller, times(0)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(0)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
}
Aggregations