Search in sources :

Example 1 with StackGresClusterRestoreFromBackup

use of io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup in project stackgres by ongres.

the class ClusterRequiredResourcesGeneratorTest method givenAClusterInvalidRestoreData_getRequiredResourcesShouldNotScanForBackups.

@Test
void givenAClusterInvalidRestoreData_getRequiredResourcesShouldNotScanForBackups() {
    cluster.getSpec().getInitData().getRestore().setFromBackup(new StackGresClusterRestoreFromBackup());
    cluster.getSpec().getInitData().getRestore().getFromBackup().setUid(UUID.randomUUID().toString());
    final ObjectMeta metadata = cluster.getMetadata();
    final String clusterName = metadata.getName();
    final String clusterNamespace = metadata.getNamespace();
    final StackGresClusterSpec clusterSpec = cluster.getSpec();
    final StackGresClusterConfiguration clusterConfiguration = clusterSpec.getConfiguration();
    final String backupConfigName = clusterConfiguration.getBackupConfig();
    mockBackupConfig(clusterNamespace, backupConfigName);
    final String postgresConfigName = clusterConfiguration.getPostgresConfig();
    mockPgConfig(clusterNamespace, postgresConfigName);
    final String connectionPoolingConfig = clusterConfiguration.getConnectionPoolingConfig();
    mockPoolingConfig(clusterNamespace, connectionPoolingConfig);
    final String resourceProfile = clusterSpec.getResourceProfile();
    when(profileConfigFinder.findByNameAndNamespace(resourceProfile, clusterNamespace)).thenReturn(Optional.of(instanceProfile));
    when(backupScanner.getResources()).thenReturn(backups);
    assertException("SGCluster " + clusterNamespace + "/" + clusterName + " have an invalid restore backup Uid");
    verify(backupConfigFinder).findByNameAndNamespace(backupConfigName, clusterNamespace);
    verify(postgresConfigFinder).findByNameAndNamespace(postgresConfigName, clusterNamespace);
    verify(poolingConfigFinder).findByNameAndNamespace(connectionPoolingConfig, clusterNamespace);
    verify(profileConfigFinder).findByNameAndNamespace(resourceProfile, clusterNamespace);
    verify(backupScanner, atLeastOnce()).getResources();
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterRestoreFromBackup(io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 2 with StackGresClusterRestoreFromBackup

use of io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup in project stackgres by ongres.

the class ClusterTransformer method getResourceRestoreFromBackup.

private ClusterRestoreFromBackup getResourceRestoreFromBackup(StackGresClusterRestoreFromBackup source) {
    if (source == null) {
        return null;
    }
    ClusterRestoreFromBackup transformation = new ClusterRestoreFromBackup();
    transformation.setUid(source.getUid());
    transformation.setPointInTimeRecovery(getResourceRestorePitr(source.getPointInTimeRecovery()));
    return transformation;
}
Also used : ClusterRestoreFromBackup(io.stackgres.apiweb.dto.cluster.ClusterRestoreFromBackup) StackGresClusterRestoreFromBackup(io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup)

Example 3 with StackGresClusterRestoreFromBackup

use of io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup in project stackgres by ongres.

the class DefaultRestoreMutatorTest method clusteRestorerWithNoDownloadDiskConcurrency_shouldSetDefaultValue.

@Test
void clusteRestorerWithNoDownloadDiskConcurrency_shouldSetDefaultValue() throws JsonPatchException {
    StackGresClusterRestore restore = new StackGresClusterRestore();
    restore.setDownloadDiskConcurrency(null);
    restore.setFromBackup(new StackGresClusterRestoreFromBackup());
    restore.getFromBackup().setUid(UUID.randomUUID().toString());
    review.getRequest().getObject().getSpec().getInitData().setRestore(restore);
    List<JsonPatchOperation> operations = mutator.mutate(review);
    JsonNode crJson = JSON_MAPPER.valueToTree(review.getRequest().getObject());
    JsonPatch jp = new JsonPatch(operations);
    JsonNode newConfig = jp.apply(crJson);
    Integer defaultDownloadDisConcurrency = Integer.parseInt(defaultRestoreValues.getProperty("downloadDiskConcurrency"));
    int actualDownloadDiskConcurrency = newConfig.get("spec").get("initialData").get("restore").get("downloadDiskConcurrency").asInt();
    assertEquals(defaultDownloadDisConcurrency, actualDownloadDiskConcurrency);
}
Also used : StackGresClusterRestore(io.stackgres.common.crd.sgcluster.StackGresClusterRestore) StackGresClusterRestoreFromBackup(io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonPatch(com.github.fge.jsonpatch.JsonPatch) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) Test(org.junit.jupiter.api.Test)

Example 4 with StackGresClusterRestoreFromBackup

use of io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup in project stackgres by ongres.

the class ClusterTransformer method getCustomResourceRestoreFromBackup.

private StackGresClusterRestoreFromBackup getCustomResourceRestoreFromBackup(ClusterRestoreFromBackup source) {
    if (source == null) {
        return null;
    }
    StackGresClusterRestoreFromBackup transformation = new StackGresClusterRestoreFromBackup();
    transformation.setUid(source.getUid());
    transformation.setPointInTimeRecovery(getCustomResourceRestorePitr(source.getPointInTimeRecovery()));
    return transformation;
}
Also used : StackGresClusterRestoreFromBackup(io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup)

Aggregations

StackGresClusterRestoreFromBackup (io.stackgres.common.crd.sgcluster.StackGresClusterRestoreFromBackup)4 Test (org.junit.jupiter.api.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonPatch (com.github.fge.jsonpatch.JsonPatch)1 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 ClusterRestoreFromBackup (io.stackgres.apiweb.dto.cluster.ClusterRestoreFromBackup)1 StackGresClusterConfiguration (io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration)1 StackGresClusterRestore (io.stackgres.common.crd.sgcluster.StackGresClusterRestore)1 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)1