Skip to content

Commit

Permalink
Nb of Running execution is displayed on homepage.. Added Websocket.
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigo17 committed Jun 16, 2024
1 parent 805527a commit fa57429
Show file tree
Hide file tree
Showing 17 changed files with 812 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ExecutionPrivateController {
TestCaseExecutionService executionService;

@Autowired
ExecutionUUID executionUUIDObject;
private ExecutionUUID executionUUIDObject;

@GetMapping("/getLastByCriteria")
public String getLastByCriteria(
Expand Down Expand Up @@ -110,9 +110,7 @@ public String getRunning(
try {

// ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
LOG.debug("TOTO");
LOG.debug(executionUUIDObject.getExecutionUUIDList());
jsonResponse.put("simultaneous_execution", executionUUIDObject.size());
JSONArray executionArray = new JSONArray();
for (Object ex : executionUUIDObject.getExecutionUUIDList().values()) {
TestCaseExecution execution = (TestCaseExecution) ex;
Expand All @@ -129,7 +127,13 @@ public String getRunning(
object.put("start", new Timestamp(execution.getStart()));
executionArray.put(object);
}
jsonResponse.put("simultaneous_execution_list", executionArray);
jsonResponse.put("runningExecutionsList", executionArray);

JSONObject queueStatus = new JSONObject();
queueStatus.put("queueSize", executionUUIDObject.getQueueSize());
queueStatus.put("globalLimit", executionUUIDObject.getGlobalLimit());
queueStatus.put("running", executionUUIDObject.getRunning());
jsonResponse.put("queueStats", queueStatus);

return jsonResponse.toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public class TestCaseExecution {
private Integer nbExecutions; // Has the nb of execution that was necessary to execute the testcase.
// Global parameters.
private Integer cerberus_action_wait_default;
// Websocket management parameters
private boolean cerberus_featureflipping_activatewebsocketpush;
private long cerberus_featureflipping_websocketpushperiod;
private long lastWebsocketPush;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,34 @@
public class ExecutionUUID {

private HashMap<String, TestCaseExecution> executionHashMap;
private int running;
private int queueSize;
private int globalLimit;

public int getRunning() {
return running;
}

public int getQueueSize() {
return queueSize;
}

public int getGlobalLimit() {
return globalLimit;
}

public void setQueueCounters(int globalLimit, int running, int queueSize) {
this.globalLimit = globalLimit;
this.running = running;
this.queueSize = queueSize;
}

@PostConstruct
public void init() {
executionHashMap = new HashMap<>();
running = 0;
queueSize = 0;
globalLimit = 0;
}

public HashMap<String, TestCaseExecution> getExecutionUUIDList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import org.cerberus.core.exception.CerberusException;
import org.cerberus.core.util.ParameterParserUtil;
import org.cerberus.core.util.StringUtil;
import org.cerberus.core.websocket.QueueStatus;
import org.cerberus.core.websocket.QueueStatusEndPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -87,7 +89,7 @@ public class ExecutionStartService implements IExecutionStartService {
@Autowired
private IInvariantService invariantService;
@Autowired
ExecutionUUID executionUUIDObject;
private ExecutionUUID executionUUIDObject;
@Autowired
private ITagService tagService;
@Autowired
Expand Down Expand Up @@ -564,6 +566,12 @@ public TestCaseExecution startExecution(TestCaseExecution execution) throws Cerb
if (runID != 0) {
execution.setId(runID);
executionUUIDObject.setExecutionUUID(execution.getExecutionUUID(), execution);
QueueStatus queueS = QueueStatus.builder()
.executionHashMap(executionUUIDObject.getExecutionUUIDList())
.globalLimit(executionUUIDObject.getGlobalLimit())
.running(executionUUIDObject.getRunning())
.queueSize(executionUUIDObject.getQueueSize()).build();
QueueStatusEndPoint.getInstance().send(queueS, true);
// Update Queue Execution here if QueueID =! 0.
if (execution.getQueueID() != 0) {
inQueueService.updateToExecuting(execution.getQueueID(), "", runID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public class ExecutionQueueThreadPool {
private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(ExecutionQueueThreadPool.class);

private ExecutorService executor;
private Integer totalNumberOfThread;
private Integer size;
private Integer inExecution;
Map<String, List<Future<?>>> map = new HashMap<>();
// private Integer totalNumberOfThread;
// private Integer size;
// private Integer inExecution;
// Map<String, List<Future<?>>> map = new HashMap<>();

@PostConstruct
public void init() {
executor = Executors.newCachedThreadPool();
totalNumberOfThread = 0;
inExecution = 0;
// totalNumberOfThread = 0;
// inExecution = 0;
LOG.debug("Starting Execution Queueing !! (ExecutionQueueThreadPool).");
}

Expand All @@ -61,22 +61,22 @@ public void setExecutor(ExecutorService executor) {
}

//Changer le nombre de tache simultanée...
public void setNumberOfPool(Integer numberOfPool) {
totalNumberOfThread = numberOfPool;
}

public Integer getSize() {
return size;
}

public Integer getNumberOfThread() {
return totalNumberOfThread;
}

public void setSize(Integer size) {
this.size = size;
}

// public void setNumberOfPool(Integer numberOfPool) {
// totalNumberOfThread = numberOfPool;
// }

// public Integer getSize() {
// return size;
// }
//
// public Integer getNumberOfThread() {
// return totalNumberOfThread;
// }

// public void setSize(Integer size) {
// this.size = size;
// }
//
public void reset() {
this.stop();
init();
Expand All @@ -88,20 +88,20 @@ public void stop() {
}
}

public Integer getInExecution() {
return inExecution;
}

public void setInExecution(Integer inExecution) {
this.inExecution = inExecution;
}

public void incrementInExecution() {
this.inExecution++;
}

public void decrementInExecution() {
this.inExecution--;
}
// public Integer getInExecution() {
// return inExecution;
// }
//
// public void setInExecution(Integer inExecution) {
// this.inExecution = inExecution;
// }
//
// public void incrementInExecution() {
// this.inExecution++;
// }
//
// public void decrementInExecution() {
// this.inExecution--;
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.cerberus.core.crud.service.ITagService;
import org.cerberus.core.crud.service.ITestCaseExecutionQueueDepService;
import org.cerberus.core.crud.service.ITestCaseExecutionQueueService;
import org.cerberus.core.engine.entity.ExecutionUUID;
import org.cerberus.core.engine.queuemanagement.IExecutionThreadPoolService;
import org.cerberus.core.exception.CerberusException;
import org.cerberus.core.service.authentification.impl.APIKeyService;
Expand All @@ -51,6 +52,8 @@
import org.cerberus.core.util.ParameterParserUtil;
import org.cerberus.core.util.StringUtil;
import org.cerberus.core.util.answer.AnswerList;
import org.cerberus.core.websocket.QueueStatus;
import org.cerberus.core.websocket.QueueStatusEndPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -82,6 +85,8 @@ public class ExecutionThreadPoolService implements IExecutionThreadPoolService {
@Autowired
private IMyVersionService myVersionService;
@Autowired
private ExecutionUUID executionUUIDObject;
@Autowired
ExecutionQueueThreadPool threadQueuePool;
@Autowired
private ITestCaseExecutionQueueService queueService;
Expand Down Expand Up @@ -662,6 +667,16 @@ public void executeNextInQueue(boolean forceExecution) throws CerberusException
}
LOG.debug("Stats : GlobalContrain=" + poolSizeGeneral + " - nbRunning=" + const01_current + " - NbQueued=" + executionsInQueue.size());

if (nbqueuedexe == 0) { // Websocket of queue status is sent only if no new execution was submitted. In case a new execution is submitted, the websocket is refreshed only when execution has been created on database.
executionUUIDObject.setQueueCounters(poolSizeGeneral, const01_current, executionsInQueue.size());
QueueStatus queueS = QueueStatus.builder()
.executionHashMap(executionUUIDObject.getExecutionUUIDList())
.globalLimit(poolSizeGeneral)
.running(const01_current)
.queueSize(executionsInQueue.size()).build();
QueueStatusEndPoint.getInstance().send(queueS, true);
}

queueStatService.create(factoryQueueStat.create(0, poolSizeGeneral, const01_current, executionsInQueue.size(), "", null, null, null));

} while (nbqueuedexe > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
Infos infos = new Infos();

try {
jsonResponse.put("simultaneous_execution", euuid.size());
JSONArray executionArray = new JSONArray();
for (Object ex : euuid.getExecutionUUIDList().values()) {
TestCaseExecution execution = (TestCaseExecution) ex;
Expand All @@ -116,14 +115,15 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
object.put("start", new Timestamp(execution.getStart()));
executionArray.put(object);
}
jsonResponse.put("simultaneous_execution_list", executionArray);
jsonResponse.put("runningExecutionsList", executionArray);

jsonResponse.put("simultaneous_session", sc.getTotalActiveSession());
jsonResponse.put("active_users", sc.getActiveUsers());

JSONObject object = new JSONObject();
JSONObject schedulerObject = new JSONObject();
if (scInit != null) {
object.put("schedulerInstanceVersion", scInit.getInstanceSchedulerVersion());
object.put("schedulerReloadIsRunning", scInit.isIsRunning());
schedulerObject.put("schedulerInstanceVersion", scInit.getInstanceSchedulerVersion());
schedulerObject.put("schedulerReloadIsRunning", scInit.isIsRunning());
// We get here the list of triggers of Quartz scheduler.
List<JSONObject> triggerList = new ArrayList<>();
for (Trigger triggerSet : scInit.getMyTriggersSet()) {
Expand All @@ -138,12 +138,18 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
}
Collections.sort(triggerList, new SortTriggers());
JSONArray object1 = new JSONArray(triggerList);
object.put("schedulerTriggers", object1);
schedulerObject.put("schedulerTriggers", object1);
Date now = new Date();
object.put("serverDate", new SimpleDateFormat(DATE_FORMAT).format(now));
object.put("serverTimeZone", TimeZone.getDefault().getDisplayName());
schedulerObject.put("serverDate", new SimpleDateFormat(DATE_FORMAT).format(now));
schedulerObject.put("serverTimeZone", TimeZone.getDefault().getDisplayName());
}
jsonResponse.put("scheduler", object);
jsonResponse.put("scheduler", schedulerObject);

JSONObject queueObject = new JSONObject();
queueObject.put("globalLimit", euuid.getGlobalLimit());
queueObject.put("running", euuid.getRunning());
queueObject.put("queueSize", euuid.getQueueSize());
jsonResponse.put("queueStats", queueObject);

cerberusDatabaseInformation = appContext.getBean(ICerberusInformationDAO.class);

Expand Down
Loading

0 comments on commit fa57429

Please sign in to comment.