Search in sources :

Example 1 with StackGresDistributedLogsStatusDatabase

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase in project stackgres by ongres.

the class DistributedLogsClusterReconciliatorTest method testReconciliationWithRetentionUpdated_isPerformedWithoutUpdatingRetention.

@Test
void testReconciliationWithRetentionUpdated_isPerformedWithoutUpdatingRetention() throws Exception {
    when(propertyContext.getString(same(DistributedLogsControllerProperty.DISTRIBUTEDLOGS_CONTROLLER_POD_NAME))).thenReturn("stackgres-0");
    StackGresDistributedLogsContext distributedLogsContext = getDistributedLogsContext();
    StackGresDistributedLogsStatusDatabase databaseStatus = new StackGresDistributedLogsStatusDatabase();
    databaseStatus.setName("stackgres_stackgres");
    databaseStatus.setRetention("1 minute");
    distributedLogsContext.getDistributedLogs().getStatus().setDatabases(Seq.of(databaseStatus).toList());
    Assertions.assertFalse(reconciliator.reconcile(null, distributedLogsContext).result().get());
    verify(databaseReconciliator, times(1)).existsDatabase(any(), any());
    verify(databaseReconciliator, times(1)).createDatabase(any(), any());
    verify(databaseReconciliator, times(0)).updateRetention(any(), any(), any(), any());
    verify(databaseReconciliator, times(2)).reconcileRetention(any(), any(), any(), any());
}
Also used : StackGresDistributedLogsContext(io.stackgres.distributedlogs.common.StackGresDistributedLogsContext) ImmutableStackGresDistributedLogsContext(io.stackgres.distributedlogs.common.ImmutableStackGresDistributedLogsContext) StackGresDistributedLogsStatusDatabase(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase) Test(org.junit.jupiter.api.Test)

Example 2 with StackGresDistributedLogsStatusDatabase

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase in project stackgres by ongres.

the class DistributedLogsClusterReconciliatorTest method testReconciliationWithEmptyDatabaseStatus_isPerformed.

@Test
void testReconciliationWithEmptyDatabaseStatus_isPerformed() throws Exception {
    when(propertyContext.getString(same(DistributedLogsControllerProperty.DISTRIBUTEDLOGS_CONTROLLER_POD_NAME))).thenReturn("stackgres-0");
    StackGresDistributedLogsContext distributedLogsContext = getDistributedLogsContext();
    StackGresDistributedLogsStatusDatabase databaseStatus = new StackGresDistributedLogsStatusDatabase();
    databaseStatus.setName("stackgres_stackgres");
    distributedLogsContext.getDistributedLogs().getStatus().setDatabases(Seq.of(databaseStatus).toList());
    Assertions.assertTrue(reconciliator.reconcile(null, distributedLogsContext).result().get());
    verify(databaseReconciliator, times(1)).existsDatabase(any(), any());
    verify(databaseReconciliator, times(1)).createDatabase(any(), any());
    verify(databaseReconciliator, times(2)).updateRetention(any(), any(), any(), any());
    verify(databaseReconciliator, times(2)).reconcileRetention(any(), any(), any(), any());
}
Also used : StackGresDistributedLogsContext(io.stackgres.distributedlogs.common.StackGresDistributedLogsContext) ImmutableStackGresDistributedLogsContext(io.stackgres.distributedlogs.common.ImmutableStackGresDistributedLogsContext) StackGresDistributedLogsStatusDatabase(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase) Test(org.junit.jupiter.api.Test)

Example 3 with StackGresDistributedLogsStatusDatabase

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase in project stackgres by ongres.

the class DistributedLogsClusterReconciliator method updateStatus.

private boolean updateStatus(StackGresDistributedLogs distributedLogs, String database, String retention) {
    Optional<StackGresDistributedLogsStatusDatabase> foundDistributedLogsDatabase = distributedLogs.getStatus().getDatabases().stream().filter(databaseStatus -> databaseStatus.getName().equals(database)).findAny();
    final StackGresDistributedLogsStatusDatabase distributedLogsDatabase = foundDistributedLogsDatabase.orElseGet(() -> new StackGresDistributedLogsStatusDatabase());
    if (!foundDistributedLogsDatabase.isPresent()) {
        distributedLogs.getStatus().getDatabases().add(distributedLogsDatabase);
    }
    if (Objects.isNull(distributedLogsDatabase.getName()) || !Objects.equals(retention, distributedLogsDatabase.getRetention())) {
        distributedLogsDatabase.setName(database);
        distributedLogsDatabase.setRetention(retention);
        return true;
    }
    return false;
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Seq(org.jooq.lambda.Seq) StackgresClusterContainers(io.stackgres.common.StackgresClusterContainers) Tables(io.stackgres.common.distributedlogs.Tables) DistributedLogsControllerEventReason(io.stackgres.distributedlogs.common.DistributedLogsControllerEventReason) Inject(javax.inject.Inject) StackGresDistributedLogsContext(io.stackgres.distributedlogs.common.StackGresDistributedLogsContext) Tuple2(org.jooq.lambda.tuple.Tuple2) ImmutableList(com.google.common.collect.ImmutableList) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) MessageFormatter(org.slf4j.helpers.MessageFormatter) PodStatus(io.fabric8.kubernetes.api.model.PodStatus) Logger(org.slf4j.Logger) StackGresDistributedLogsStatusCluster(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusCluster) ReconciliationResult(io.stackgres.operatorframework.reconciliation.ReconciliationResult) Pod(io.fabric8.kubernetes.api.model.Pod) FluentdUtil(io.stackgres.common.FluentdUtil) DistributedLogsControllerProperty(io.stackgres.common.DistributedLogsControllerProperty) Objects(java.util.Objects) Consumer(java.util.function.Consumer) CdiUtil(io.stackgres.common.CdiUtil) Stream(java.util.stream.Stream) DistributedLogsControllerPropertyContext(io.stackgres.distributedlogs.configuration.DistributedLogsControllerPropertyContext) Dependent(javax.enterprise.context.Dependent) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) StackGresDistributedLogsStatusDatabase(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase) ApplicationScoped(javax.enterprise.context.ApplicationScoped) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StackGresDistributedLogsStatusDatabase(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase)

Aggregations

StackGresDistributedLogsStatusDatabase (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase)3 StackGresDistributedLogsContext (io.stackgres.distributedlogs.common.StackGresDistributedLogsContext)3 ImmutableStackGresDistributedLogsContext (io.stackgres.distributedlogs.common.ImmutableStackGresDistributedLogsContext)2 Test (org.junit.jupiter.api.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 PodStatus (io.fabric8.kubernetes.api.model.PodStatus)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 CdiUtil (io.stackgres.common.CdiUtil)1 DistributedLogsControllerProperty (io.stackgres.common.DistributedLogsControllerProperty)1 FluentdUtil (io.stackgres.common.FluentdUtil)1 StackgresClusterContainers (io.stackgres.common.StackgresClusterContainers)1 StackGresDistributedLogs (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs)1 StackGresDistributedLogsStatusCluster (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusCluster)1 Tables (io.stackgres.common.distributedlogs.Tables)1 DistributedLogsControllerEventReason (io.stackgres.distributedlogs.common.DistributedLogsControllerEventReason)1 DistributedLogsControllerPropertyContext (io.stackgres.distributedlogs.configuration.DistributedLogsControllerPropertyContext)1 ReconciliationResult (io.stackgres.operatorframework.reconciliation.ReconciliationResult)1 Objects (java.util.Objects)1