Skip to content

Commit

Permalink
UI - Initiators, Deployments, Processes, Logs (#167)
Browse files Browse the repository at this point in the history
* Move css to separate file, implement hide LINE:

* Add statefulness for filters

* Start adding copy buttons

* Handle hide log lines toggle

* Add rest of copy buttons

* Fix js thinking strs were images

* Add delay to click

* Move status filtering to datatables, add css file

* Update how data is loaded (use dt.rows.add())

* Add ability to suspend/resume proc defs

* Fix infinite rapid update on deployments page

* Fix null in procInstId & proc start columns

* Add ability to cancel running process

* Fix logs erroring

* Fix error w/ output vars on process page, inits

* Update proc page to display type except for str

* Sped-up initiators enable-all

* Enable all reflect status of all initiators

* Fix interaction w/ procdef-level stats

* Add param to detect if we can used cached qstr

* Add delay to open all in new tab

* Remove autocomplete for process instances (slow)
  • Loading branch information
wcgunter authored Aug 2, 2023
1 parent 8b5978c commit edf5658
Show file tree
Hide file tree
Showing 15 changed files with 1,287 additions and 600 deletions.
1 change: 0 additions & 1 deletion cws-service/src/main/java/jpl/cws/controller/MvcCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ protected ModelAndView buildLogsModel(String message) {
//
model.addObject("procDefs", cwsExecutionService.listProcessDefinitions());
model.addObject("workerIds", cwsConsoleService.getAllWorkerIds());
model.addObject("procInstIds", cwsConsoleService.getProcInstIds());

log.trace("MODEL for Logs page: "+model.getModel());
}
Expand Down
85 changes: 83 additions & 2 deletions cws-service/src/main/java/jpl/cws/controller/RestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,23 @@ public RestService() {}
// Success!
return buildModel("login", "updated initiator enabled to " + enabled);
}

@RequestMapping(value = "/initiators/all/enabled", method = POST)
public @ResponseBody ModelAndView setAllInitiatorsEnabled(
@RequestParam("enabled") boolean enabled) {

try {
if (enabled) {
cwsInitiatorsService.enableAndStartAllInitiators();
} else {
cwsInitiatorsService.disableAndStopAllInitiators();
}
} catch (Exception e) {
log.error("A problem occured when setting enabled status to " + enabled, e);
return buildModel("initiators", e.getMessage());
}
return buildModel("login", "updated initiator enabled to " + enabled);
}


/**
Expand All @@ -252,6 +269,32 @@ public RestService() {}
}
return "error";
}

/**
* Gets all process initiators enabled flag.
*
*/
@RequestMapping(value = "initiators/all/enabled", method = GET)
public @ResponseBody Map<String, String> areAllInitiatorsEnabled () {
try {
log.trace("REST::areAllInitiatorsEnabled");
List<CwsProcessInitiator> initiators = cwsConsoleService.getAllProcessInitiators();
Map<String, String> statusMap = new HashMap<>();
for (int i = 0; i < initiators.size(); i++) {
String status = "";
if (initiators.get(i).isEnabled()) {
status = "true";
} else {
status = "false";
}
statusMap.put(initiators.get(i).getInitiatorId(), status);
}
return statusMap;
} catch (Exception e) {
log.error("areAllInitiatorsEnabled exception", e);
}
return null;
}


/**
Expand Down Expand Up @@ -1436,8 +1479,45 @@ public GsonUTCDateAdapter() {

return "success";
}



/**
* Suspends a process definition given its procDefId
*
*/
@RequestMapping(value = "/deployments/suspend/{procDefId}", method = POST)
public @ResponseBody String suspendProcDefId(
@PathVariable String procDefId) {
log.info("*** REST CALL *** suspendProcDefId (procDefId=" + procDefId + ")");
String result = cwsConsoleService.suspendProcDefId(procDefId);
return result;
}

/**
* Activates a suspended process definition given its procDefId
*
*/
@RequestMapping(value = "/deployments/activate/{procDefId}", method = POST)
public @ResponseBody String activateProcDefId(
@PathVariable String procDefId ) {
log.info ("*** REST CALL *** activateProcDefId (procDefId" + procDefId + ")");
String result = cwsConsoleService.activateProcDefId(procDefId);
return result;
}

/**
* Method that deletes a running process instance.
*
* Accepts an array of procInstIds and expects all of them to be running.
*/
@RequestMapping(value = "/processes/delete", method = POST)
public @ResponseBody String deleteRunningProcInsts(
final HttpSession session,
@RequestBody List<String> procInstIds) {
log.debug("*** REST CALL *** deleteRunningProcInsts");
String result = cwsConsoleService.deleteRunningProcInst(procInstIds);
return result;
}

/**
*
*
Expand Down Expand Up @@ -1635,4 +1715,5 @@ public Message createMessage(Session session) throws JMSException {
}
return restCallResult.getResponse();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,78 @@ public synchronized void disableAndStopInitiator(String initiatorId) throws Exce
disableAndStopInitiator(cwsConsoleService.getProcessInitiatorById(initiatorId));
}

public synchronized void disableAndStopAllInitiators() throws Exception {
disableAndStopAllInitiators(cwsConsoleService.getAllProcessInitiators());
}

// Synchronized to prevent race conditions in refreshing the spring context
public synchronized void enableAndStartInitiator(String initiatorId) throws Exception {
enableAndStartInitiator(cwsConsoleService.getProcessInitiatorById(initiatorId));
}

public synchronized void enableAndStartAllInitiators() throws Exception {
enableAndStartAllInitiators(cwsConsoleService.getAllProcessInitiators());
}


public CwsProcessInitiator getInitiator(String initiatorId) {
return cwsConsoleService.getProcessInitiatorById(initiatorId);
}

private void disableAndStopAllInitiators(List<CwsProcessInitiator> initiators) throws Exception {
log.debug("disableAndStopAllInitiators");
if (initiators == null) {
throw new IllegalArgumentException("Null initiator list!");
}

//Check if any initiators are currently enabled
for (CwsProcessInitiator initiator : initiators) {
if (initiator == null) {
throw new IllegalArgumentException("null initiator!");
}

// Is the initiator currently enabled?
//
boolean isEnabled = initiator.isEnabled();
log.trace("before updating initiator, enabled = " + isEnabled);

if (isEnabled) {
// Disable the initiator
//
initiator.setEnabled(false);
}

// Stop initiator, if necessary
//
if (initiator.isAlive()) {
log.trace("Interrupting (stopping) initiator: " + initiator + " ...");

// Interrupt the initiator...
//
initiator.interrupt();

// Wait for initiator to die...
//
int maxWaits = 0;
while (initiator.isAlive() && maxWaits++ < 10) {
log.warn("initiator still alive... (poll #" + maxWaits + ")");
try { Thread.sleep(200); } catch (InterruptedException e) { }
}
if (initiator.isAlive()) {
log.error("initiator " + initiator + " (procDefKey=" +initiator.getProcDefKey()+") still alive after interruption!");
}
else {
log.trace("initator is NOT alive.");
}
}
else {
log.trace("initiator was already dead. No need to interrupt it.");
}

initiator.cleanUp();
log.trace("Done with disableAndStopInitiator of " + initiator);
}
}

/**
*
Expand Down Expand Up @@ -677,6 +740,52 @@ private void disableAndStopInitiator(CwsProcessInitiator initiator) throws Excep
initiator.cleanUp();
log.trace("Done with disableAndStopInitiator of " + initiator);
}

/**
*
*
*/
private void enableAndStartAllInitiators(List<CwsProcessInitiator> initiators) throws Exception {
log.debug("enableAndStartAllInitiators");
if (initiators == null) {
throw new IllegalArgumentException("Null initiator list!");
}

//Check if any initiators are currently enabled
for (CwsProcessInitiator initiator : initiators) {
if (initiator == null) {
throw new IllegalArgumentException("null initiator!");
}

// If this initiator is not being enabled for the first time, then
// we must re-initialize it..
//
if (initiator.getState() != Thread.State.NEW) {
disableAndStopInitiator(initiator);
cwsConsoleService.replaceInitiatorBean(initiator.getInitiatorId(), initiator);
initiator = cwsConsoleService.getProcessInitiatorById(initiator.getInitiatorId());
}

// Enable the initiator
//
initiator.setEnabled(true);

// Start up initiator if necessary
//
try {
if (initiator.isAlive()) {
log.error("initiator should not already be alive!");
}
else {
log.debug("Starting initiator: " + initiator + " ...");
initiator.start();
}
}
catch (Exception e) {
log.error("problem while starting up a new initiator", e);
}
}
}


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public CwsProcessInstance(
String startedByWorker,
Timestamp procStartTime,
Timestamp procEndTime,
Map<String, String> inputVariables) {
Map<String, String> inputVariables,
Map<String, String> outputVariables) {
super();
this.uuid = uuid;
this.procDefKey = procDefKey;
Expand All @@ -55,6 +56,7 @@ public CwsProcessInstance(
this.procStartTime = procStartTime;
this.procEndTime = procEndTime;
this.inputVariables = inputVariables;
this.outputVariables = outputVariables;
}

public String getUuid() {
Expand Down Expand Up @@ -161,5 +163,13 @@ public Map<String, String> getInputVariables() {
return inputVariables;
}

public void setOutputVariables(Map<String, String> input) {
this.outputVariables = input;
}

public Map<String, String> getOutputVariables() {
return outputVariables;
}


}
56 changes: 55 additions & 1 deletion cws-service/src/main/java/jpl/cws/service/CwsConsoleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,16 @@ public CwsProcessInitiator getProcessInitiatorById(String initiatorId) {
return initiator;
}

public List<CwsProcessInitiator> getAllProcessInitiators() {
Map<String, CwsProcessInitiator> initiatorMap;
initiatorMap = SpringApplicationContext.getBeansOfType(CwsProcessInitiator.class);
ArrayList<CwsProcessInitiator> initiators= new ArrayList<CwsProcessInitiator>();
for (Map.Entry<String, CwsProcessInitiator> initiator : initiatorMap.entrySet()) {
initiators.add(initiator.getValue());
}
return initiators;
}

public void replaceInitiatorBean(String springBeanKey, CwsProcessInitiator newInitiator) {
log.debug("replaceInitiatorBean initiator: " + springBeanKey + " ...");
springApplicationContext.replaceBean(springBeanKey, null, newInitiator.getPropertyValues(),
Expand Down Expand Up @@ -1134,10 +1144,13 @@ public List<CwsProcessInstance> getFilteredProcessInstancesCamunda(String superP
Timestamp procStartTime = (Timestamp) row.get("proc_start_time");
Timestamp procEndTime = (Timestamp) row.get("proc_end_time");
Map<String, String> inputVars;
Map<String, String> outputVars;
if (procInstIdObj != null) {
inputVars = getInputVariablesForProcess(procInstIdObj.toString());
outputVars = getOutputVariablesForProcess(procInstIdObj.toString());
} else {
inputVars = new HashMap<String, String>();
outputVars = new HashMap<String, String>();
}
CwsProcessInstance instance = new CwsProcessInstance(uuidObj == null ? null : uuidObj.toString(),
procDefKeyObj == null ? null : procDefKeyObj.toString(),
Expand All @@ -1149,7 +1162,7 @@ public List<CwsProcessInstance> getFilteredProcessInstancesCamunda(String superP
updatedTimestampObj == null ? null : updatedTimestampObj,
claimedByWorker == null ? null : claimedByWorker, startedByWorker == null ? null : startedByWorker,
procStartTime == null ? null : procStartTime, procEndTime == null ? null : procEndTime,
inputVars);
inputVars, outputVars);
instances.add(instance);
}

Expand Down Expand Up @@ -1218,4 +1231,45 @@ public Message createMessage(Session session) throws JMSException {
throw e;
}
}

/**
* Suspend a procDefKey given a procDefId
*/
public String suspendProcDefId(String procDefId) {
try {
repositoryService.updateProcessDefinitionSuspensionState().byProcessDefinitionId(procDefId).suspend();
return "Success";
} catch (Exception e) {
log.error("*** ERROR *** Could not suspend procDefId: " + e);
return "Error";
}
}

/**
* Activate a suspended procDefKey given a procDefId
*/
public String activateProcDefId(String procDefId) {
try {
repositoryService.updateProcessDefinitionSuspensionState().byProcessDefinitionId(procDefId).activate();
return "Success";
} catch (Exception e) {
log.error("*** ERROR *** Could not activate procDefId: " + e);
return "Error";
}
}

/**
* Delete a running process instance given an array of procInstIds
*/
public String deleteRunningProcInst(List<String> procInstIds) {
try {
for (String procInstId : procInstIds) {
runtimeService.deleteProcessInstance(procInstId, "User requested delete from processes page.", true, true, true);
log.debug("DELETED PROCESS INSTANCE");
}
return "Success";
} catch (Exception e) {
return "Error: " + e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -81,6 +82,13 @@ public void runResultsTest() throws IOException {

findOnPage("CWS - History");

WebElement hideLineCheckbox = findElByXPath("//input[@id='hide-log-lines-checkbox']");
waitForElement(hideLineCheckbox);

sleep(10000);

hideLineCheckbox.click();

if (findOnPage("History Page.")
&& findOnPage("Command 'mkdir Test' exit code: 0")
&& findOnPage("Command 'ls' exit code: 0")
Expand Down
Loading

0 comments on commit edf5658

Please sign in to comment.