public Incident createIncident(IncidentContext context, String message) { IncidentEntity newIncident = IncidentEntity.createAndInsertIncident(type, context, message); if(context.getExecutionId() != null) { newIncident.createRecursiveIncidents(); } return newIncident; }
private void removeIncidents() { for (IncidentEntity incident : getIncidents()) { if (isReplacedByParent()) { incident.setExecution(getReplacedBy()); } else { incident.delete(); } } }
protected static IncidentEntity create(String incidentType) { String incidentId = Context.getProcessEngineConfiguration() .getDbSqlSessionFactory() .getIdGenerator() .getNextId(); // decorate new incident IncidentEntity newIncident = new IncidentEntity(); newIncident.setId(incidentId); newIncident.setIncidentTimestamp(ClockUtil.getCurrentTime()); newIncident.setIncidentType(incidentType); newIncident.setCauseIncidentId(incidentId); newIncident.setRootCauseIncidentId(incidentId); return newIncident; }
/** Instantiate recursive a new incident a super execution * (i.e. super process instance) which is affected from this * incident. * For example: a super process instance called via CallActivity * a new process instance on which an incident happened, so that * the super process instance has an incident too. */ protected void createRecursiveIncidents(String rootCauseIncidentId, List<IncidentEntity> createdIncidents) { final ExecutionEntity execution = getExecution(); if(execution != null) { ExecutionEntity superExecution = execution.getProcessInstance().getSuperExecution(); if (superExecution != null) { // create a new incident IncidentEntity newIncident = create(incidentType); newIncident.setExecution(superExecution); newIncident.setActivityId(superExecution.getCurrentActivityId()); newIncident.setProcessDefinitionId(superExecution.getProcessDefinitionId()); newIncident.setTenantId(superExecution.getTenantId()); // set cause and root cause newIncident.setCauseIncidentId(id); newIncident.setRootCauseIncidentId(rootCauseIncidentId); // insert new incident (and create a new historic incident) insert(newIncident); // add new incident to result set createdIncidents.add(newIncident); newIncident.createRecursiveIncidents(rootCauseIncidentId, createdIncidents); } } }
public static IncidentEntity createAndInsertIncident(String incidentType, IncidentContext context, String message) { // create new incident IncidentEntity newIncident = create(incidentType); newIncident.setIncidentMessage(message); // set properties from incident context newIncident.setConfiguration(context.getConfiguration()); newIncident.setActivityId(context.getActivityId()); newIncident.setProcessDefinitionId(context.getProcessDefinitionId()); newIncident.setTenantId(context.getTenantId()); newIncident.setJobDefinitionId(context.getJobDefinitionId()); if (context.getExecutionId() != null) { // fetch execution ExecutionEntity execution = Context .getCommandContext() .getExecutionManager() .findExecutionById(context.getExecutionId()); if (execution != null) { // link incident with execution newIncident.setExecution(execution); } else { LOG.executionNotFound(context.getExecutionId()); } } // insert new incident (and create a new historic incident) insert(newIncident); return newIncident; }
protected void remove(boolean resolved) { ExecutionEntity execution = getExecution(); if(execution != null) { // Extract possible super execution of the assigned execution ExecutionEntity superExecution = null; if (execution.getId().equals(execution.getProcessInstanceId())) { superExecution = execution.getSuperExecution(); } else { superExecution = execution.getProcessInstance().getSuperExecution(); } if (superExecution != null) { // get the incident, where this incident is the cause IncidentEntity parentIncident = superExecution.getIncidentByCauseIncidentId(getId()); if (parentIncident != null) { // remove the incident parentIncident.remove(resolved); } } // remove link to execution execution.removeIncident(this); } // always delete the incident Context .getCommandContext() .getDbEntityManager() .delete(this); // update historic incident HistoryEventType eventType = resolved ? HistoryEventTypes.INCIDENT_RESOLVE : HistoryEventTypes.INCIDENT_DELETE; fireHistoricIncidentEvent(eventType); }
protected void removeIncident(IncidentContext context, boolean incidentResolved) { List<Incident> incidents = Context .getCommandContext() .getIncidentManager() .findIncidentByConfiguration(context.getConfiguration()); for (Incident currentIncident : incidents) { IncidentEntity incident = (IncidentEntity) currentIncident; if (incidentResolved) { incident.resolve(); } else { incident.delete(); } } } }
@Override public Incident handleIncident(IncidentContext context, String message) { return IncidentEntity.createAndInsertIncident(incidentType, context, message); }
ProcessDefinitionEntity definition = incidentEntity.getProcessDefinition(); if (definition != null) { evt.setProcessDefinitionKey(definition.getKey()); ExecutionEntity execution = incidentEntity.getExecution(); if (execution != null) { evt.setRootProcessInstanceId(execution.getRootProcessInstanceId());
ExecutionEntity execution = executionsMap.get(incident.getExecutionId()); incident.setExecution(execution);
@Override public void handle(MigratingInstanceParseContext parseContext, IncidentEntity incident) { if (incident.getConfiguration() != null && isFailedJobIncident(incident)) { handleFailedJobIncident(parseContext, incident); } else if (incident.getConfiguration() != null && isExternalTaskIncident(incident)) { handleExternalTaskIncident(parseContext, incident); } else { handleIncident(parseContext, incident); } }
public void setExecution(ExecutionEntity execution) { if (execution != null) { executionId = execution.getId(); processInstanceId = execution.getProcessInstanceId(); execution.addIncident(this); } else { ExecutionEntity oldExecution = getExecution(); if (oldExecution != null) { oldExecution.removeIncident(this); } executionId = null; processInstanceId = null; } }
@Override public void deleteIncident(IncidentContext context) { List<Incident> incidents = Context.getCommandContext().getIncidentManager() .findIncidentByConfigurationAndIncidentType(context.getConfiguration(), incidentType); ((IncidentEntity) incidents.get(0)).delete(); }
public List<IncidentEntity> createRecursiveIncidents() { List<IncidentEntity> createdIncidents = new ArrayList<IncidentEntity>(); createRecursiveIncidents(id, createdIncidents); return createdIncidents; }
public IncidentEntity getIncidentByCauseIncidentId(String causeIncidentId) { for (IncidentEntity incident : getIncidents()) { if (incident.getCauseIncidentId() != null && incident.getCauseIncidentId().equals(causeIncidentId)) { return incident; } } return null; }
protected static void insert(IncidentEntity incident) { // persist new incident Context .getCommandContext() .getDbEntityManager() .insert(incident); incident.fireHistoricIncidentEvent(HistoryEventTypes.INCIDENT_CREATE); }
@Override public boolean isDetached() { return incident.getExecutionId() == null; }
/** Instantiate recursive a new incident a super execution * (i.e. super process instance) which is affected from this * incident. * For example: a super process instance called via CallActivity * a new process instance on which an incident happened, so that * the super process instance has an incident too. */ protected void createRecursiveIncidents(String rootCauseIncidentId, List<IncidentEntity> createdIncidents) { final ExecutionEntity execution = getExecution(); if(execution != null) { ExecutionEntity superExecution = execution.getProcessInstance().getSuperExecution(); if (superExecution != null) { // create a new incident IncidentEntity newIncident = create(incidentType); newIncident.setExecution(superExecution); newIncident.setActivityId(superExecution.getCurrentActivityId()); newIncident.setProcessDefinitionId(superExecution.getProcessDefinitionId()); newIncident.setTenantId(superExecution.getTenantId()); // set cause and root cause newIncident.setCauseIncidentId(id); newIncident.setRootCauseIncidentId(rootCauseIncidentId); // insert new incident (and create a new historic incident) insert(newIncident); // add new incident to result set createdIncidents.add(newIncident); newIncident.createRecursiveIncidents(rootCauseIncidentId, createdIncidents); } } }
public static IncidentEntity createAndInsertIncident(String incidentType, IncidentContext context, String message) { // create new incident IncidentEntity newIncident = create(incidentType); newIncident.setIncidentMessage(message); // set properties from incident context newIncident.setConfiguration(context.getConfiguration()); newIncident.setActivityId(context.getActivityId()); newIncident.setProcessDefinitionId(context.getProcessDefinitionId()); newIncident.setTenantId(context.getTenantId()); newIncident.setJobDefinitionId(context.getJobDefinitionId()); if (context.getExecutionId() != null) { // fetch execution ExecutionEntity execution = Context .getCommandContext() .getExecutionManager() .findExecutionById(context.getExecutionId()); if (execution != null) { // link incident with execution newIncident.setExecution(execution); } else { LOG.executionNotFound(context.getExecutionId()); } } // insert new incident (and create a new historic incident) insert(newIncident); return newIncident; }
protected void remove(boolean resolved) { ExecutionEntity execution = getExecution(); if(execution != null) { // Extract possible super execution of the assigned execution ExecutionEntity superExecution = null; if (execution.getId().equals(execution.getProcessInstanceId())) { superExecution = execution.getSuperExecution(); } else { superExecution = execution.getProcessInstance().getSuperExecution(); } if (superExecution != null) { // get the incident, where this incident is the cause IncidentEntity parentIncident = superExecution.getIncidentByCauseIncidentId(getId()); if (parentIncident != null) { // remove the incident parentIncident.remove(resolved); } } // remove link to execution execution.removeIncident(this); } // always delete the incident Context .getCommandContext() .getDbEntityManager() .delete(this); // update historic incident HistoryEventType eventType = resolved ? HistoryEventTypes.INCIDENT_RESOLVE : HistoryEventTypes.INCIDENT_DELETE; fireHistoricIncidentEvent(eventType); }