added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / Application.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;\r
18 \r
19 import java.util.List;\r
20 import java.util.concurrent.Executor;\r
21 import org.camunda.bpm.application.PostDeploy;\r
22 import org.camunda.bpm.application.PreUndeploy;\r
23 import org.camunda.bpm.application.ProcessApplicationInfo;\r
24 import org.camunda.bpm.engine.ProcessEngine;\r
25 import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;\r
26 import org.slf4j.Logger;\r
27 import org.slf4j.LoggerFactory;\r
28 import org.springframework.beans.factory.annotation.Value;\r
29 import org.springframework.boot.SpringApplication;\r
30 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;\r
31 import org.springframework.boot.autoconfigure.SpringBootApplication;\r
32 import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;\r
33 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;\r
34 import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;\r
35 import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;\r
36 import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;\r
37 import org.springframework.context.annotation.Bean;\r
38 import org.springframework.context.annotation.ComponentScan;\r
39 import org.springframework.context.annotation.Primary;\r
40 import org.springframework.scheduling.annotation.EnableAsync;\r
41 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;\r
42 \r
43 @SpringBootApplication\r
44 @EnableAsync\r
45 @ComponentScan(basePackages = "org.oran.otf")\r
46 @EnableProcessApplication\r
47 @EnableAutoConfiguration(\r
48     exclude = {\r
49         ErrorMvcAutoConfiguration.class,\r
50         DataSourceAutoConfiguration.class,\r
51         HibernateJpaAutoConfiguration.class,\r
52         MongoDataAutoConfiguration.class,\r
53         MongoAutoConfiguration.class\r
54     })\r
55 public class Application {\r
56   public static void main(String[] args) {\r
57     SpringApplication.run(Application.class, args);\r
58 \r
59   }\r
60 \r
61   private static final Logger logger = LoggerFactory.getLogger(Application.class);\r
62 \r
63   @Value("${otf.camunda.executor.async.core-pool-size}")\r
64   private int corePoolSize;\r
65 \r
66   @Value("${otf.camunda.executor.async.max-pool-size}")\r
67   private int maxPoolSize;\r
68 \r
69   @Value("${otf.camunda.executor.async.queue-capacity}")\r
70   private int queueCapacity;\r
71 \r
72   private static final String LOGS_DIR = "logs_dir";\r
73 \r
74 \r
75   private static void setLogsDir() {\r
76     if (System.getProperty(LOGS_DIR) == null) {\r
77       System.getProperties().setProperty(LOGS_DIR, "./logs/camunda/");\r
78     }\r
79   }\r
80 \r
81   @PostDeploy\r
82   public void postDeploy(ProcessEngine processEngineInstance) {}\r
83 \r
84   @PreUndeploy\r
85   public void cleanup(ProcessEngine processEngine, ProcessApplicationInfo processApplicationInfo,\r
86       List<ProcessEngine> processEngines) {}\r
87 \r
88   @Bean\r
89   @Primary\r
90   public Executor asyncExecutor() {\r
91     ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();\r
92     //executor.setTaskDecorator(new MDCTaskDecorator());\r
93     executor.setCorePoolSize(corePoolSize);\r
94     executor.setMaxPoolSize(maxPoolSize);\r
95     executor.setQueueCapacity(queueCapacity);\r
96     executor.setThreadNamePrefix("Camunda-");\r
97     executor.initialize();\r
98     return executor;\r
99   }\r
100 }\r