From 35078e2cade2baeef29f3965437582510befec26 Mon Sep 17 00:00:00 2001 From: Jozsef Csongvai Date: Wed, 15 Sep 2021 16:08:06 -0400 Subject: Add history ttl to all bpmn's programatically This enables camunda to set REMOVAL_TIME_ to entries written to the camundabpmn database, which can then be cleaned up after ttl has expired. Regular clean-up will improve database performance and prevent locking timeouts. Change-Id: I0803a0ebda9220daba7d505797c94ba47ade5921 Issue-ID: SO-3770 Signed-off-by: Jozsef Csongvai --- .../MSOInfrastructureApplication.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'bpmn') diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/MSOInfrastructureApplication.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/MSOInfrastructureApplication.java index 8d6e133a1c..24c9b0f85d 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/MSOInfrastructureApplication.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/MSOInfrastructureApplication.java @@ -28,7 +28,10 @@ import javax.annotation.PostConstruct; import org.camunda.bpm.application.PreUndeploy; import org.camunda.bpm.application.ProcessApplicationInfo; import org.camunda.bpm.engine.ProcessEngine; +import org.camunda.bpm.engine.RepositoryService; +import org.camunda.bpm.engine.repository.Deployment; import org.camunda.bpm.engine.repository.DeploymentBuilder; +import org.camunda.bpm.engine.repository.ProcessDefinition; import org.onap.logging.filter.spring.MDCTaskDecorator; import org.onap.so.bpmn.common.DefaultToShortClassNameBeanNameGenerator; import org.onap.so.db.catalog.beans.Workflow; @@ -76,6 +79,9 @@ public class MSOInfrastructureApplication { @Value("${mso.async.queue-capacity}") private int queueCapacity; + @Value("${mso.bpmn-history-ttl:14}") + private Integer bpmnHistoryTtl; + private static final String LOGS_DIR = "logs_dir"; private static final String BPMN_SUFFIX = ".bpmn"; private static final String SDC_SOURCE = "sdc"; @@ -102,8 +108,10 @@ public class MSOInfrastructureApplication { @PostConstruct public void postConstruct() { try { - DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment(); + RepositoryService repositoryService = processEngine.getRepositoryService(); + DeploymentBuilder deploymentBuilder = repositoryService.createDeployment(); deployCustomWorkflows(deploymentBuilder); + setBpmnTTL(repositoryService, bpmnHistoryTtl); } catch (Exception e) { logger.warn("Unable to invoke deploymentBuilder ", e); } @@ -149,4 +157,18 @@ public class MSOInfrastructureApplication { logger.warn("Unable to deploy custom workflows ", e); } } + + private void setBpmnTTL(RepositoryService repositoryService, Integer ttl) { + List deployments = repositoryService.createDeploymentQuery().list(); + for (Deployment deployment : deployments) { + List processDefinitions = + repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list(); + for (ProcessDefinition processDefinition : processDefinitions) { + if (!ttl.equals(processDefinition.getHistoryTimeToLive())) { + logger.info("Setting ttl {} for processdefinition {}", ttl, processDefinition.getName()); + repositoryService.updateProcessDefinitionHistoryTimeToLive(processDefinition.getId(), ttl); + } + } + } + } } -- cgit 1.2.3-korg