Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI - Initiators, Deployments, Processes, Logs #167

Merged
merged 23 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4bb49fd
Move css to separate file, implement hide LINE:
wcgunter Jul 31, 2023
3ff5d54
Add statefulness for filters
wcgunter Jul 31, 2023
afe9680
Start adding copy buttons
wcgunter Jul 31, 2023
4ecd2f1
Merge branch 'develop' into UI-misc-1
wcgunter Jul 31, 2023
6aa08ca
Handle hide log lines toggle
wcgunter Jul 31, 2023
4f660f8
Add rest of copy buttons
wcgunter Jul 31, 2023
c7b3ef2
Fix js thinking strs were images
wcgunter Jul 31, 2023
97fa98b
Add delay to click
wcgunter Jul 31, 2023
33e9d4b
Move status filtering to datatables, add css file
wcgunter Jul 31, 2023
7cb86d4
Update how data is loaded (use dt.rows.add())
wcgunter Jul 31, 2023
c1a239d
Add ability to suspend/resume proc defs
wcgunter Jul 31, 2023
1596f50
Fix infinite rapid update on deployments page
wcgunter Jul 31, 2023
9105dac
Fix null in procInstId & proc start columns
wcgunter Jul 31, 2023
a1ae1ee
Add ability to cancel running process
wcgunter Aug 1, 2023
e822f0d
Fix logs erroring
wcgunter Aug 1, 2023
29ea9c9
Fix error w/ output vars on process page, inits
wcgunter Aug 1, 2023
2a1e821
Update proc page to display type except for str
wcgunter Aug 1, 2023
03aed0f
Sped-up initiators enable-all
wcgunter Aug 1, 2023
4552d1a
Enable all reflect status of all initiators
wcgunter Aug 1, 2023
0f04a94
Fix interaction w/ procdef-level stats
wcgunter Aug 1, 2023
1af3f27
Add param to detect if we can used cached qstr
wcgunter Aug 1, 2023
59947e2
Add delay to open all in new tab
wcgunter Aug 1, 2023
8eb5ac0
Remove autocomplete for process instances (slow)
wcgunter Aug 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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