Skip to content

Commit

Permalink
Merge branch 'main' into issue900
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Anderson authored Oct 5, 2023
2 parents a4c2955 + 7e13033 commit 372b50d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 10 additions & 5 deletions core/src/main/java/io/aiven/klaw/service/EnvControllerService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package io.aiven.klaw.service;

import static io.aiven.klaw.helpers.KwConstants.DATE_TIME_DDMMMYYYY_HHMMSS_FORMATTER;

import io.aiven.klaw.config.ManageDatabase;
import io.aiven.klaw.dao.Env;
import io.aiven.klaw.dao.KwClusters;
import io.aiven.klaw.error.KlawException;
import io.aiven.klaw.model.enums.ClusterStatus;
import io.aiven.klaw.model.enums.KafkaClustersType;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -23,7 +27,7 @@ public class EnvControllerService {
@Autowired ManageDatabase manageDatabase;

// every 1 hour
@Scheduled(fixedRateString = "PT1H", initialDelay = 60000)
@Scheduled(fixedRateString = "PT1H", initialDelay = 60)
public void loadTenantActiveStatus() {
try {
for (Integer tenantId : manageDatabase.getTenantMap().keySet()) {
Expand All @@ -40,7 +44,7 @@ public void loadTenantActiveStatus() {
}
}

@Scheduled(fixedRateString = "PT1H", initialDelay = 60000)
@Scheduled(fixedRateString = "PT1H", initialDelay = 9000)
public void loadEnvsWithStatus() {
updateEnvsStatus();
}
Expand All @@ -56,7 +60,6 @@ public void updateEnvsStatus() {
for (Env env : envList) {
updateEnvStatusPerEnv(tenantId, env);
}
manageDatabase.loadEnvMapForOneTenant(tenantId);
}

for (Integer tenantId : tenants) {
Expand All @@ -65,7 +68,6 @@ public void updateEnvsStatus() {
for (Env env : envList) {
updateEnvStatusPerEnv(tenantId, env);
}
manageDatabase.loadEnvMapForOneTenant(tenantId);
}

for (Integer tenantId : tenants) {
Expand All @@ -74,7 +76,6 @@ public void updateEnvsStatus() {
for (Env env : envList) {
updateEnvStatusPerEnv(tenantId, env);
}
manageDatabase.loadEnvMapForOneTenant(tenantId);
}
} catch (Exception e) {
log.error("Error in loading cluster status ", e);
Expand All @@ -83,6 +84,7 @@ public void updateEnvsStatus() {

private void updateEnvStatusPerEnv(Integer tenantId, Env env) throws KlawException {
ClusterStatus status;
LocalDateTime statusTime = LocalDateTime.now(ZoneOffset.UTC);
KwClusters kwClusters =
manageDatabase
.getClusters(KafkaClustersType.of(env.getType()), tenantId)
Expand All @@ -98,6 +100,9 @@ private void updateEnvStatusPerEnv(Integer tenantId, Env env) throws KlawExcepti

env.setEnvStatus(status);
kwClusters.setClusterStatus(status);
env.setEnvStatusTime(statusTime);
env.setEnvStatusTimeString(DATE_TIME_DDMMMYYYY_HHMMSS_FORMATTER.format(statusTime));
manageDatabase.addEnvToCache(tenantId, env, true);
manageDatabase.getHandleDbRequests().addNewCluster(kwClusters);
manageDatabase.getHandleDbRequests().addNewEnv(env);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ void loadEnvsWithStatus() {
envControllerService.loadEnvsWithStatus();

Mockito.verify(handleDbRequestsJdbc, Mockito.times(3)).addNewEnv(env);
Mockito.verify(manageDatabase, Mockito.times(3))
.loadEnvMapForOneTenant(TestConstants.TENANT_ID);
Assertions.assertEquals(env.getEnvStatus(), ClusterStatus.ONLINE);
}
}

0 comments on commit 372b50d

Please sign in to comment.