added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / camunda / configuration / OTFJobConfiguration.java
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 (file)
index 0000000..6ece823
--- /dev/null
@@ -0,0 +1,73 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+package org.oran.otf.camunda.configuration;\r
+\r
+import org.oran.otf.camunda.configuration.listener.OTFJobExecutorStartingEventListener;\r
+import org.camunda.bpm.engine.impl.jobexecutor.JobExecutor;\r
+import org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration;\r
+import org.camunda.bpm.spring.boot.starter.configuration.impl.DefaultJobConfiguration;\r
+import org.camunda.bpm.spring.boot.starter.event.JobExecutorStartingEventListener;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;\r
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;\r
+import org.springframework.context.annotation.Bean;\r
+import org.springframework.context.annotation.Configuration;\r
+import org.springframework.context.annotation.Primary;\r
+\r
+@Configuration\r
+public class OTFJobConfiguration extends DefaultJobConfiguration {\r
+  @Autowired protected JobExecutor jobExecutor;\r
+\r
+  @Override\r
+  protected void configureJobExecutor(SpringProcessEngineConfiguration configuration) {\r
+    int podNumber = -1;\r
+    String[] hostnameSplit = {"0", "0", "0"};\r
+\r
+    try {\r
+      String hostname = System.getenv("HOSTNAME");\r
+      hostnameSplit = hostname.split("-");\r
+      podNumber = Integer.parseInt(hostnameSplit[2]);\r
+    } catch (Exception e) {\r
+      podNumber = 1;\r
+    }\r
+\r
+    //if (podNumber == 1) {\r
+      camundaBpmProperties.getJobExecution().setLockTimeInMillis(43200000);\r
+      camundaBpmProperties.getJobExecution().setBackoffTimeInMillis(90);\r
+      camundaBpmProperties.getJobExecution().setMaxBackoff(450L);\r
+      camundaBpmProperties.getJobExecution().setWaitIncreaseFactor(2f);\r
+\r
+      super.configureJobExecutor(configuration);\r
+\r
+      configuration.getJobExecutor().setLockTimeInMillis(43200000);\r
+      configuration.getJobExecutor().setBackoffTimeInMillis(90);\r
+      configuration.getJobExecutor().setMaxBackoff(450L);\r
+      configuration.getJobExecutor().setWaitIncreaseFactor(2);\r
+\r
+\r
+      // configuration.getJobExecutor().setAutoActivate(false);\r
+   // }\r
+  }\r
+\r
+  @Bean\r
+  @Primary\r
+  @ConditionalOnProperty(prefix = "camunda.bpm.job-execution", name = "enabled", havingValue = "true", matchIfMissing = true)\r
+  @ConditionalOnBean(JobExecutor.class)\r
+  public static JobExecutorStartingEventListener jobExecutorStartingEventListener() {\r
+    return new OTFJobExecutorStartingEventListener();\r
+  }\r
+}\r