Skip to content

Commit

Permalink
chnages
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushaga14 committed Sep 21, 2024
1 parent 8c16e50 commit f0aef70
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public void setTestSourceConfig(TestSourceConfig testSourceConfig) {
BasicDBList issuesIds;
List<YamlTemplate> activeAdvancedFilters;
Set<MergedUrls> mergedUrls;
List<TestingRunResultSummary> currentlyRunningTests;

public BasicDBList getIssuesIds() {
return issuesIds;
Expand Down Expand Up @@ -1988,6 +1989,16 @@ public String fetchMergedUrls() {
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<CustomDataTypeMapper> getCustomDataTypes() {
return customDataTypes;
}
Expand Down Expand Up @@ -2901,4 +2912,12 @@ public Set<MergedUrls> getMergedUrls() {
public void setMergedUrls(Set<MergedUrls> mergedUrls) {
this.mergedUrls = mergedUrls;
}

public List<TestingRunResultSummary> getCurrentlyRunningTests() {
return currentlyRunningTests;
}

public void setCurrentlyRunningTests(List<TestingRunResultSummary> currentlyRunningTests) {
this.currentlyRunningTests = currentlyRunningTests;
}
}
11 changes: 11 additions & 0 deletions apps/database-abstractor/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,17 @@
</result>
</action>

<action name="api/fetchStatusOfTests" class="com.akto.action.DbAction" method="fetchStatusOfTests">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
<result name="SUCCESS" type="json"/>
<result name="ERROR" type="json">
<param name="statusCode">422</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>

</package>

</struts>
35 changes: 35 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/ClientActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3163,4 +3163,39 @@ public Set<MergedUrls> fetchMergedUrls() {
return new HashSet<>(respList);
}

public List<TestingRunResultSummary> fetchStatusOfTests() {
Map<String, List<String>> headers = buildHeaders();
List<TestingRunResultSummary> 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;
}
}

}
2 changes: 2 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DataActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,6 @@ public abstract class DataActor {
public abstract List<YamlTemplate> fetchActiveAdvancedFilters();

public abstract Set<MergedUrls> fetchMergedUrls();

public abstract List<TestingRunResultSummary> fetchStatusOfTests();
}
4 changes: 4 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DbActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,8 @@ public Set<MergedUrls> fetchMergedUrls() {
return DbLayer.fetchMergedUrls();
}

public List<TestingRunResultSummary> fetchStatusOfTests() {
return DbLayer.fetchStatusOfTests();
}

}
12 changes: 12 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DbLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -916,4 +916,16 @@ public static List<YamlTemplate> fetchActiveFilterTemplates(){
public static Set<MergedUrls> fetchMergedUrls() {
return MergedUrlsDao.instance.getMergedUrls();
}

public static List<TestingRunResultSummary> fetchStatusOfTests() {
int timeFilter = Context.now() - 30 * 60;
List<TestingRunResultSummary> 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;
}
}

0 comments on commit f0aef70

Please sign in to comment.