diff --git a/apps/database-abstractor/src/main/java/com/akto/action/DbAction.java b/apps/database-abstractor/src/main/java/com/akto/action/DbAction.java index 824f39e157..1bd4cbc323 100644 --- a/apps/database-abstractor/src/main/java/com/akto/action/DbAction.java +++ b/apps/database-abstractor/src/main/java/com/akto/action/DbAction.java @@ -163,6 +163,7 @@ public void setTestSourceConfig(TestSourceConfig testSourceConfig) { String logicalGroupName; BasicDBList issuesIds; List activeAdvancedFilters; + List currentlyRunningTests; public BasicDBList getIssuesIds() { return issuesIds; @@ -1977,6 +1978,16 @@ public String fetchActiveAdvancedFilters(){ return Action.SUCCESS.toUpperCase(); } + public String fetchStatusOfTests(){ + try { + this.currentlyRunningTests = DbLayer.fetchStatusOfTests(); + } catch (Exception e) { + loggerMaker.errorAndAddToDb(e, "Error in fetchStatusOfTests " + e.toString()); + return Action.ERROR.toUpperCase(); + } + return Action.SUCCESS.toUpperCase(); + } + public List getCustomDataTypes() { return customDataTypes; } @@ -2883,4 +2894,12 @@ public void setActiveAdvancedFilters(List activeAdvancedFilters) { this.activeAdvancedFilters = activeAdvancedFilters; } + public List getCurrentlyRunningTests() { + return currentlyRunningTests; + } + + public void setCurrentlyRunningTests(List currentlyRunningTests) { + this.currentlyRunningTests = currentlyRunningTests; + } + } diff --git a/apps/database-abstractor/src/main/resources/struts.xml b/apps/database-abstractor/src/main/resources/struts.xml index 38f82e1c29..777a50f75f 100644 --- a/apps/database-abstractor/src/main/resources/struts.xml +++ b/apps/database-abstractor/src/main/resources/struts.xml @@ -1211,6 +1211,17 @@ + + + + + + 422 + false + ^actionErrors.* + + + diff --git a/libs/utils/src/main/java/com/akto/data_actor/ClientActor.java b/libs/utils/src/main/java/com/akto/data_actor/ClientActor.java index d1b6cd1df3..217996e431 100644 --- a/libs/utils/src/main/java/com/akto/data_actor/ClientActor.java +++ b/libs/utils/src/main/java/com/akto/data_actor/ClientActor.java @@ -8,6 +8,7 @@ import com.akto.bulk_update_util.ApiInfoBulkUpdate; import com.akto.dao.SetupDao; import com.akto.dao.context.Context; +import com.akto.dao.testing.TestingRunResultSummariesDao; import com.akto.database_abstractor_authenticator.JwtAuthenticator; import com.akto.dto.*; import com.akto.dto.ApiInfo.ApiInfoKey; @@ -3128,4 +3129,38 @@ public List fetchActiveAdvancedFilters(){ return respList; } + public List fetchStatusOfTests() { + Map> headers = buildHeaders(); + List result = new ArrayList<>(); + OriginalHttpRequest request = new OriginalHttpRequest(url + "/fetchStatusOfTests", "", "GET", null, headers, ""); + try { + OriginalHttpResponse response = ApiExecutor.sendRequest(request, true, null, false, null); + String responsePayload = response.getBody(); + if (response.getStatusCode() != 200 || responsePayload == null) { + loggerMaker.errorAndAddToDb("non 2xx response in fetchStatusOfTests", LoggerMaker.LogDb.RUNTIME); + return null; + } + BasicDBObject payloadObj; + try { + payloadObj = BasicDBObject.parse(responsePayload); + BasicDBList tests = (BasicDBList) payloadObj.get("currentlyRunningTests"); + for (Object test: tests) { + BasicDBObject obj = (BasicDBObject) test; + obj.remove("id"); + obj.remove("testingRunId"); + TestingRunResultSummary res = objectMapper.readValue(obj.toJson(), TestingRunResultSummary.class); + res.setId(new ObjectId(obj.getString("hexId"))); + res.setTestingRunId(new ObjectId(obj.getString("testingRunHexId"))); + result.add(res); + } + } catch(Exception e) { + loggerMaker.errorAndAddToDb("error extracting response in fetchStatusOfTests" + e, LoggerMaker.LogDb.RUNTIME); + } + + return result; + } catch (Exception e) { + loggerMaker.errorAndAddToDb("error in fetchStatusOfTests" + e, LoggerMaker.LogDb.RUNTIME); + return null; + } + } } diff --git a/libs/utils/src/main/java/com/akto/data_actor/DataActor.java b/libs/utils/src/main/java/com/akto/data_actor/DataActor.java index 5b9c7499d7..07062048e3 100644 --- a/libs/utils/src/main/java/com/akto/data_actor/DataActor.java +++ b/libs/utils/src/main/java/com/akto/data_actor/DataActor.java @@ -237,4 +237,6 @@ public abstract class DataActor { public abstract void insertProtectionLog(Log log); public abstract List fetchActiveAdvancedFilters(); + + public abstract List fetchStatusOfTests(); } diff --git a/libs/utils/src/main/java/com/akto/data_actor/DbActor.java b/libs/utils/src/main/java/com/akto/data_actor/DbActor.java index 43e119f338..0ccc3737b5 100644 --- a/libs/utils/src/main/java/com/akto/data_actor/DbActor.java +++ b/libs/utils/src/main/java/com/akto/data_actor/DbActor.java @@ -495,4 +495,8 @@ public List fetchActiveAdvancedFilters(){ return DbLayer.fetchActiveFilterTemplates(); } + public List fetchStatusOfTests() { + return DbLayer.fetchStatusOfTests(); + } + } diff --git a/libs/utils/src/main/java/com/akto/data_actor/DbLayer.java b/libs/utils/src/main/java/com/akto/data_actor/DbLayer.java index ffadce61bc..5194a5d448 100644 --- a/libs/utils/src/main/java/com/akto/data_actor/DbLayer.java +++ b/libs/utils/src/main/java/com/akto/data_actor/DbLayer.java @@ -910,4 +910,16 @@ public static List fetchActiveFilterTemplates(){ Filters.ne(YamlTemplate.INACTIVE, false) ); } + + public static List fetchStatusOfTests() { + int timeFilter = Context.now() - 30 * 60; + List currentRunningTests = TestingRunResultSummariesDao.instance.findAll( + Filters.gte(TestingRunResultSummary.START_TIMESTAMP, timeFilter), + Projections.include("_id", TestingRunResultSummary.STATE, TestingRunResultSummary.TESTING_RUN_ID) + ); + for (TestingRunResultSummary summary: currentRunningTests) { + summary.setTestingRunHexId(summary.getTestingRunId().toHexString()); + } + return currentRunningTests; + } }