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

FlowActionReport - disable stop report when stopFlow is called internally by startFlow #316

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 0 deletions dil/src/main/java/org/assimbly/dil/loader/FlowLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ private void removeRouteConfiguration(String flowId) {
ModelCamelContext modelContext = (ModelCamelContext) context;

List<RouteConfigurationDefinition> routeConfigurationsToRemove = modelContext.getRouteConfigurationDefinitions().stream()
.filter(Objects::nonNull) // Exclude null entries
.filter(routeConfig -> routeConfig.getId().startsWith(flowId))
.toList(); // Collect into a new list to avoid modifying the original list during iteration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ public String startFlow(String id, long timeout) {
initFlowActionReport(id, "Start");

if(hasFlow(id)) {
stopFlow(id, timeout);
stopFlow(id, timeout, false);
}

boolean addFlow = false;
Expand Down Expand Up @@ -1346,13 +1346,12 @@ public String startFlow(String id, long timeout) {
if (!result.equals("loaded") && !result.equals("started")){
if(result.equalsIgnoreCase("error")){
String startReport = loadReport;
stopFlow(id, timeout);
stopFlow(id, timeout, false);
loadReport = startReport;
}else{
finishFlowActionReport(id, "error",result,"error");
}
}else if(result.equals("loaded")) {

List<Route> steps = getRoutesByFlowId(id);

log.info("Starting " + steps.size() + " steps");
Expand All @@ -1373,7 +1372,7 @@ public String startFlow(String id, long timeout) {

}catch (Exception e) {
if(context.isStarted()) {
stopFlow(id, stopTimeout);
stopFlow(id, stopTimeout, false);
finishFlowActionReport(id, "error","Start flow failed | error=" + e.getMessage(),"error");
log.error("Start flow failed. | flowid=" + id,e);
}else{
Expand Down Expand Up @@ -1426,14 +1425,7 @@ private ServiceStatus startStep(Route route){
public String restartFlow(String id, long timeout) {

try {

if(hasFlow(id)) {
stopFlow(id, timeout);
startFlow(id, timeout);
}else {
startFlow(id, timeout);
}

startFlow(id, timeout);
}catch (Exception e) {
log.error("Restart flow failed. | flowid=" + id,e);
finishFlowActionReport(id, "error", e.getMessage(),"error");
Expand All @@ -1444,8 +1436,14 @@ public String restartFlow(String id, long timeout) {
}

public String stopFlow(String id, long timeout) {
return stopFlow(id, timeout, true);
}

public String stopFlow(String id, long timeout, boolean enableReport) {

initFlowActionReport(id, "stop");
if(enableReport) {
initFlowActionReport(id, "stop");
}

try {

Expand All @@ -1467,10 +1465,14 @@ public String stopFlow(String id, long timeout) {

}

finishFlowActionReport(id, "stop","Stopped flow successfully","info");
if(enableReport) {
finishFlowActionReport(id, "stop", "Stopped flow successfully", "info");
}

}catch (Exception e) {
finishFlowActionReport(id, "error","Stop flow failed | error=" + e.getMessage(),"error");
if(enableReport) {
finishFlowActionReport(id, "error", "Stop flow failed | error=" + e.getMessage(), "error");
}
log.error("Stop flow failed. | flowid=" + id,e);
}

Expand Down Expand Up @@ -2337,7 +2339,7 @@ public String getStats(String mediaType) throws Exception {
}

return stats;

}

private double getMemoryUsage(){
Expand Down