X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=it%2Fotf.git;a=blobdiff_plain;f=otf-camunda%2Fsrc%2Fmain%2Fjava%2Forg%2Foran%2Fotf%2Fcamunda%2Fconfiguration%2FOTFJobConfiguration.java;fp=otf-camunda%2Fsrc%2Fmain%2Fjava%2Forg%2Foran%2Fotf%2Fcamunda%2Fconfiguration%2FOTFJobConfiguration.java;h=6ece823a8b916358e4ceb3b24311de580bc67722;hp=0000000000000000000000000000000000000000;hb=14f6f95c84a4a1fa8774190db4a03fd0214ec55f;hpb=f49bd1efeaaddd4891c1f329b18d8cfb28b3e75b diff --git a/otf-camunda/src/main/java/org/oran/otf/camunda/configuration/OTFJobConfiguration.java b/otf-camunda/src/main/java/org/oran/otf/camunda/configuration/OTFJobConfiguration.java new file mode 100644 index 0000000..6ece823 --- /dev/null +++ b/otf-camunda/src/main/java/org/oran/otf/camunda/configuration/OTFJobConfiguration.java @@ -0,0 +1,73 @@ +/* Copyright (c) 2019 AT&T Intellectual Property. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +##############################################################################*/ + + +package org.oran.otf.camunda.configuration; + +import org.oran.otf.camunda.configuration.listener.OTFJobExecutorStartingEventListener; +import org.camunda.bpm.engine.impl.jobexecutor.JobExecutor; +import org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration; +import org.camunda.bpm.spring.boot.starter.configuration.impl.DefaultJobConfiguration; +import org.camunda.bpm.spring.boot.starter.event.JobExecutorStartingEventListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration +public class OTFJobConfiguration extends DefaultJobConfiguration { + @Autowired protected JobExecutor jobExecutor; + + @Override + protected void configureJobExecutor(SpringProcessEngineConfiguration configuration) { + int podNumber = -1; + String[] hostnameSplit = {"0", "0", "0"}; + + try { + String hostname = System.getenv("HOSTNAME"); + hostnameSplit = hostname.split("-"); + podNumber = Integer.parseInt(hostnameSplit[2]); + } catch (Exception e) { + podNumber = 1; + } + + //if (podNumber == 1) { + camundaBpmProperties.getJobExecution().setLockTimeInMillis(43200000); + camundaBpmProperties.getJobExecution().setBackoffTimeInMillis(90); + camundaBpmProperties.getJobExecution().setMaxBackoff(450L); + camundaBpmProperties.getJobExecution().setWaitIncreaseFactor(2f); + + super.configureJobExecutor(configuration); + + configuration.getJobExecutor().setLockTimeInMillis(43200000); + configuration.getJobExecutor().setBackoffTimeInMillis(90); + configuration.getJobExecutor().setMaxBackoff(450L); + configuration.getJobExecutor().setWaitIncreaseFactor(2); + + + // configuration.getJobExecutor().setAutoActivate(false); + // } + } + + @Bean + @Primary + @ConditionalOnProperty(prefix = "camunda.bpm.job-execution", name = "enabled", havingValue = "true", matchIfMissing = true) + @ConditionalOnBean(JobExecutor.class) + public static JobExecutorStartingEventListener jobExecutorStartingEventListener() { + return new OTFJobExecutorStartingEventListener(); + } +}