Kubernetes and Incident Handler

I have a problem regarding the incident handler in Camunda version 7.13.

In my current setup, on my station, it works. The app is running in IDEA and has a setup with a mysql database. It is a spring boot microservice env and it is build and run using java 11. On my testing env it is not working. Basiccally the handleIncident it is not triggered. It is a kubernetes environment.

Are there any arhitectural concerns regarding working in kubernetes containers?

There is nothing special in running camunda apps in k8s. The incident handler should work as usual.

Could you provide more details about what happens (exception etc.) and what is expected but does not happen?

Hi @fml2 . When my spring boot app starts I am injecting the handler on post construct level:

Slf4j
RequiredArgsConstructor
Configuration
public class CamundaHandlerConfig {

private final ProcessEngineConfigurationImpl processEngineConfiguration;
private final ExternalTaskIncidentHandler camundaIncidentHandler;

PostConstruct
public void injectExternalTaskIncidentHandler() {
    log.info("Injecting ExternalTaskIncidentHandler in ProcessEngineConfiguration");
    List<IncidentHandler> customIncidentHandlers = processEngineConfiguration.getCustomIncidentHandlers();
    customIncidentHandlers.add(camundaIncidentHandler);
    processEngineConfiguration.setCustomIncidentHandlers(customIncidentHandlers);
}

}

The camundaIncidentHandler looks like this:

Slf4j
Configuration
public class ExternalTaskIncidentHandler extends DefaultIncidentHandler {

private static final String INCIDENT_TYPE = "failedExternalTask";

private final IncidentNotifier handler;

public ExternalTaskIncidentHandler(IncidentNotifier handler) {
    super(INCIDENT_TYPE);
    this.handler = handler;
}

Override
public String getIncidentHandlerType() {
    return INCIDENT_TYPE;
}

Override
public Incident handleIncident(IncidentContext context, String message) {
    log.debug("incident {} created for execution {}", context.getJobDefinitionId(), context.getExecutionId());
    IncidentEntity incidentEntity = (IncidentEntity) super.handleIncident(context, message);
    handler.notifyIncident(incidentEntity, message);
    return incidentEntity;
}

}

The same code, when an incident happens on local setup (IDEA + a locally mysql server instance) gets triggered, the handleIncident call is working. When I run it on testing env it doesn’t work.

Hrm… I’m not sure @PostConstruct is the right tool here. It is from the Spring space. It might work but I have not used it myself.

In order the things to work for sure you have to hook into the engine’s lifecycle, i.e. create an engine plugin and use one of its “pre…” or “post…” methods to inject the handler.

Hi @fml2. I appreciate your interest on this topic. Somehow I don’t seem to understand how to integrate camunda plugins in my current setup. We are running camunda in a spring context. In pom.xml we have the following dependencies:

< dependency >
< groupId >org.camunda.bpm.springboot</ groupId >
< artifactId >camunda-bpm-spring-boot-starter-webapp</ artifactId >
< version >${camunda.version}</ version >
</ dependency >
< dependency >
< groupId >org.camunda.bpm.springboot</ groupId >
< artifactId >camunda-bpm-spring-boot-starter-rest</ artifactId >
< version >${camunda.version}</ version >
</ dependency >

The documentation (Process Engine Plugins | docs.camunda.org), I think it is from a “stand-alone point of view”.

How should it look? Create a jar (why?), place it in my pom.xml and in my yml, reference to the engine class?

Thanks,
Claudiu

I assume you create a spring boot application with an embedded engine. Then you just have to create a spring bean (i.e. a class annotated with @Component) that implements the interface ProcessEnginePlugin. It will be automatically picked up and its code executed.

There is a good base class SpringBootProcessEnginePlugin. You’d then put your own code into one of the class’ methods. I’m just not sure which one to use. I think it should not be preInit, but that’s without any warranty. You have to try.