added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / camunda / configuration / OTFJobConfiguration.java
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 package org.oran.otf.camunda.configuration;\r
18 \r
19 import org.oran.otf.camunda.configuration.listener.OTFJobExecutorStartingEventListener;\r
20 import org.camunda.bpm.engine.impl.jobexecutor.JobExecutor;\r
21 import org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration;\r
22 import org.camunda.bpm.spring.boot.starter.configuration.impl.DefaultJobConfiguration;\r
23 import org.camunda.bpm.spring.boot.starter.event.JobExecutorStartingEventListener;\r
24 import org.springframework.beans.factory.annotation.Autowired;\r
25 import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;\r
26 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;\r
27 import org.springframework.context.annotation.Bean;\r
28 import org.springframework.context.annotation.Configuration;\r
29 import org.springframework.context.annotation.Primary;\r
30 \r
31 @Configuration\r
32 public class OTFJobConfiguration extends DefaultJobConfiguration {\r
33   @Autowired protected JobExecutor jobExecutor;\r
34 \r
35   @Override\r
36   protected void configureJobExecutor(SpringProcessEngineConfiguration configuration) {\r
37     int podNumber = -1;\r
38     String[] hostnameSplit = {"0", "0", "0"};\r
39 \r
40     try {\r
41       String hostname = System.getenv("HOSTNAME");\r
42       hostnameSplit = hostname.split("-");\r
43       podNumber = Integer.parseInt(hostnameSplit[2]);\r
44     } catch (Exception e) {\r
45       podNumber = 1;\r
46     }\r
47 \r
48     //if (podNumber == 1) {\r
49       camundaBpmProperties.getJobExecution().setLockTimeInMillis(43200000);\r
50       camundaBpmProperties.getJobExecution().setBackoffTimeInMillis(90);\r
51       camundaBpmProperties.getJobExecution().setMaxBackoff(450L);\r
52       camundaBpmProperties.getJobExecution().setWaitIncreaseFactor(2f);\r
53 \r
54       super.configureJobExecutor(configuration);\r
55 \r
56       configuration.getJobExecutor().setLockTimeInMillis(43200000);\r
57       configuration.getJobExecutor().setBackoffTimeInMillis(90);\r
58       configuration.getJobExecutor().setMaxBackoff(450L);\r
59       configuration.getJobExecutor().setWaitIncreaseFactor(2);\r
60 \r
61 \r
62       // configuration.getJobExecutor().setAutoActivate(false);\r
63    // }\r
64   }\r
65 \r
66   @Bean\r
67   @Primary\r
68   @ConditionalOnProperty(prefix = "camunda.bpm.job-execution", name = "enabled", havingValue = "true", matchIfMissing = true)\r
69   @ConditionalOnBean(JobExecutor.class)\r
70   public static JobExecutorStartingEventListener jobExecutorStartingEventListener() {\r
71     return new OTFJobExecutorStartingEventListener();\r
72   }\r
73 }\r