diff --git a/core/src/main/java/io/aiven/klaw/helpers/HandleDbRequests.java b/core/src/main/java/io/aiven/klaw/helpers/HandleDbRequests.java index 9049b5b0a9..032776a0f4 100644 --- a/core/src/main/java/io/aiven/klaw/helpers/HandleDbRequests.java +++ b/core/src/main/java/io/aiven/klaw/helpers/HandleDbRequests.java @@ -327,6 +327,8 @@ List getAllSchemaRequests( List getAllClusters(KafkaClustersType typeOfCluster, int tenantId); + boolean existsClusters(KafkaClustersType typeOfCluster, int tenantId); + KwClusters getClusterDetails(int id, int tenantId); // Analytics - charts - dashboard diff --git a/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/HandleDbRequestsJdbc.java b/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/HandleDbRequestsJdbc.java index 09e838200c..b409681ffb 100644 --- a/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/HandleDbRequestsJdbc.java +++ b/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/HandleDbRequestsJdbc.java @@ -754,6 +754,11 @@ public List getAllClusters(KafkaClustersType typeOfCluster, int tena return jdbcSelectHelper.getAllClusters(typeOfCluster, tenantId); } + @Override + public boolean existsClusters(KafkaClustersType typeOfCluster, int tenantId) { + return jdbcSelectHelper.existsClusters(typeOfCluster, tenantId); + } + @Override public KwClusters getClusterDetails(int id, int tenantId) { return jdbcSelectHelper.getClusterDetails(id, tenantId); diff --git a/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java b/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java index 18577865d2..5e58563e78 100644 --- a/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java +++ b/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java @@ -1376,6 +1376,10 @@ public List getAllClusters(KafkaClustersType typeOfCluster, int tena } } + public boolean existsClusters(KafkaClustersType typeOfCluster, int tenantId) { + return kwClusterRepo.existsByClusterTypeAndTenantId(typeOfCluster.value, tenantId); + } + public KwClusters getClusterDetails(int id, int tenantId) { KwClusterID kwClusterID = new KwClusterID(); kwClusterID.setClusterId(id); diff --git a/core/src/main/java/io/aiven/klaw/repository/KwClusterRepo.java b/core/src/main/java/io/aiven/klaw/repository/KwClusterRepo.java index 13814bb851..3cd3558f45 100644 --- a/core/src/main/java/io/aiven/klaw/repository/KwClusterRepo.java +++ b/core/src/main/java/io/aiven/klaw/repository/KwClusterRepo.java @@ -10,6 +10,8 @@ public interface KwClusterRepo extends CrudRepository { List findAllByClusterTypeAndTenantId(String type, int tenantId); + boolean existsByClusterTypeAndTenantId(String type, int tenantId); + @Query( value = "select max(clusterid) from kwclusters where tenantid = :tenantId", nativeQuery = true) diff --git a/core/src/main/java/io/aiven/klaw/service/DefaultDataService.java b/core/src/main/java/io/aiven/klaw/service/DefaultDataService.java index 72cbc6d77e..db6115c0eb 100644 --- a/core/src/main/java/io/aiven/klaw/service/DefaultDataService.java +++ b/core/src/main/java/io/aiven/klaw/service/DefaultDataService.java @@ -487,9 +487,7 @@ public void handleQuickStartData( HandleDbRequestsJdbc handleDbRequests, String encryptorSecretKey, String infraTeam) { if (quickStartEnabled) { // verify if quick start data already exists tbd - List kwClusters = - handleDbRequests.getAllClusters(KafkaClustersType.KAFKA, KwConstants.DEFAULT_TENANT_ID); - if (!kwClusters.isEmpty()) { + if (handleDbRequests.existsClusters(KafkaClustersType.KAFKA, KwConstants.DEFAULT_TENANT_ID)) { return; } @@ -536,7 +534,7 @@ public void handleQuickStartData( handleDbRequests.addNewCluster(kwClusterSchemaRegistry); // Add kafka environment - kwClusters = + var kwClusters = handleDbRequests.getAllClusters(KafkaClustersType.KAFKA, KwConstants.DEFAULT_TENANT_ID); Env envKafka = new Env(); envKafka.setClusterId(kwClusters.get(0).getClusterId());