From 9aaa58bb64d3473a877cddbb9d71584a87d7bbd1 Mon Sep 17 00:00:00 2001 From: Avneesh Hota Date: Wed, 6 Dec 2023 16:24:52 +0530 Subject: [PATCH] moved create indices to daoinit --- .../src/main/java/com/akto/runtime/Main.java | 7 +----- .../java/com/akto/action/AccountAction.java | 3 ++- .../akto/listener/InitializerListener.java | 13 ++-------- libs/dao/src/main/java/com/akto/DaoInit.java | 25 +++++++++++++++++++ 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/apps/api-runtime/src/main/java/com/akto/runtime/Main.java b/apps/api-runtime/src/main/java/com/akto/runtime/Main.java index 4eb1a026f4..bed9e34a14 100644 --- a/apps/api-runtime/src/main/java/com/akto/runtime/Main.java +++ b/apps/api-runtime/src/main/java/com/akto/runtime/Main.java @@ -101,11 +101,6 @@ public static boolean tryForCollectionName(String message) { } - public static void createIndices() { - SingleTypeInfoDao.instance.createIndicesIfAbsent(); - SensitiveSampleDataDao.instance.createIndicesIfAbsent(); - SampleDataDao.instance.createIndicesIfAbsent(); - } public static void insertRuntimeFilters() { RuntimeFilterDao.instance.initialiseFilters(); @@ -350,7 +345,7 @@ public static void initializeRuntime(){ public static void initializeRuntimeHelper() { SingleTypeInfoDao.instance.getMCollection().updateMany(Filters.exists("apiCollectionId", false), Updates.set("apiCollectionId", 0)); - createIndices(); + DaoInit.createIndices(); insertRuntimeFilters(); try { AccountSettingsDao.instance.updateVersion(AccountSettings.API_RUNTIME_VERSION); diff --git a/apps/dashboard/src/main/java/com/akto/action/AccountAction.java b/apps/dashboard/src/main/java/com/akto/action/AccountAction.java index aee4aa9e1c..e7b256b3ad 100644 --- a/apps/dashboard/src/main/java/com/akto/action/AccountAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/AccountAction.java @@ -1,5 +1,6 @@ package com.akto.action; +import com.akto.DaoInit; import com.akto.dao.*; import com.akto.dao.context.Context; import com.akto.dto.*; @@ -256,7 +257,7 @@ public void run() { BackwardCompatibilityDao.instance.insertOne(backwardCompatibility); } InitializerListener.setBackwardCompatibilities(backwardCompatibility); - Main.createIndices(); + DaoInit.createIndices(); Main.insertRuntimeFilters(); RuntimeListener.initialiseDemoCollections(); RuntimeListener.addSampleData(); diff --git a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java index bea5e0757e..db73c5433d 100644 --- a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java +++ b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java @@ -32,6 +32,7 @@ import com.akto.dto.pii.PIIType; import com.akto.dto.test_editor.TestConfig; import com.akto.dto.test_editor.YamlTemplate; +import com.akto.dto.testing.TestingRun; import com.akto.dto.traffic.SampleData; import com.akto.dto.type.SingleTypeInfo; import com.akto.github.GithubFile; @@ -1253,17 +1254,7 @@ public static void setBackwardCompatibilities(BackwardCompatibility backwardComp } public void runInitializerFunctions() { - SingleTypeInfoDao.instance.createIndicesIfAbsent(); - TrafficMetricsDao.instance.createIndicesIfAbsent(); - TestRolesDao.instance.createIndicesIfAbsent(); - - ApiInfoDao.instance.createIndicesIfAbsent(); - RuntimeLogsDao.instance.createIndicesIfAbsent(); - LogsDao.instance.createIndicesIfAbsent(); - DashboardLogsDao.instance.createIndicesIfAbsent(); - LoadersDao.instance.createIndicesIfAbsent(); - TestingRunResultDao.instance.createIndicesIfAbsent(); - TestingRunResultSummariesDao.instance.createIndicesIfAbsent(); + DaoInit.createIndices(); fillCollectionIdArray(); BackwardCompatibility backwardCompatibility = BackwardCompatibilityDao.instance.findOne(new BasicDBObject()); diff --git a/libs/dao/src/main/java/com/akto/DaoInit.java b/libs/dao/src/main/java/com/akto/DaoInit.java index af389aae3f..617a9a4a78 100644 --- a/libs/dao/src/main/java/com/akto/DaoInit.java +++ b/libs/dao/src/main/java/com/akto/DaoInit.java @@ -1,5 +1,13 @@ package com.akto; +import com.akto.dao.*; +import com.akto.dao.loaders.LoadersDao; +import com.akto.dao.testing.TestRolesDao; +import com.akto.dao.testing.TestingRunDao; +import com.akto.dao.testing.TestingRunResultDao; +import com.akto.dao.testing.TestingRunResultSummariesDao; +import com.akto.dao.testing_run_findings.TestingRunIssuesDao; +import com.akto.dao.traffic_metrics.TrafficMetricsDao; import com.akto.dto.*; import com.akto.dto.data_types.*; import com.akto.dto.demo.VulnerableRequestForTemplate; @@ -250,4 +258,21 @@ public static void init(ConnectionString connectionString) { clients[0] = MongoClients.create(clientSettings); } + + public static void createIndices() { + SingleTypeInfoDao.instance.createIndicesIfAbsent(); + TrafficMetricsDao.instance.createIndicesIfAbsent(); + TestRolesDao.instance.createIndicesIfAbsent(); + + ApiInfoDao.instance.createIndicesIfAbsent(); + RuntimeLogsDao.instance.createIndicesIfAbsent(); + LogsDao.instance.createIndicesIfAbsent(); + DashboardLogsDao.instance.createIndicesIfAbsent(); + LoadersDao.instance.createIndicesIfAbsent(); + TestingRunResultDao.instance.createIndicesIfAbsent(); + TestingRunResultSummariesDao.instance.createIndicesIfAbsent(); + TestingRunDao.instance.createIndicesIfAbsent(); + TestingRunIssuesDao.instance.createIndicesIfAbsent(); + } + }