af9ab2899e1b86398f69f4aa69e68d2e8dad7684
[so.git] / bpmn / mso-infrastructure-bpmn / src / main / java / org / onap / so / bpmn / infrastructure / MSOInfrastructureApplication.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure;
24
25 import java.util.List;
26 import java.util.concurrent.Executor;
27
28 import org.camunda.bpm.application.PostDeploy;
29 import org.camunda.bpm.application.PreUndeploy;
30 import org.camunda.bpm.application.ProcessApplicationInfo;
31 import org.camunda.bpm.engine.ProcessEngine;
32 import org.onap.so.bpmn.common.DefaultToShortClassNameBeanNameGenerator;
33 import org.onap.so.logging.jaxrs.filter.MDCTaskDecorator;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Value;
37 import org.springframework.boot.SpringApplication;
38 import org.springframework.boot.autoconfigure.SpringBootApplication;
39 import org.springframework.context.annotation.Bean;
40 import org.springframework.context.annotation.ComponentScan;
41 import org.springframework.context.annotation.ComponentScan.Filter;
42 import org.springframework.context.annotation.FilterType;
43 import org.springframework.context.annotation.Primary;
44 import org.springframework.scheduling.annotation.EnableAsync;
45 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
46
47 /**
48  * @since Version 1.0
49  *
50  */
51
52 @SpringBootApplication
53 @EnableAsync
54 @ComponentScan(basePackages = { "org.onap" }, nameGenerator = DefaultToShortClassNameBeanNameGenerator.class, excludeFilters = {
55                                 @Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class) })
56 public class MSOInfrastructureApplication {
57
58         private static final Logger logger = LoggerFactory.getLogger(MSOInfrastructureApplication.class);
59
60         @Value("${mso.async.core-pool-size}")
61         private int corePoolSize;
62
63         @Value("${mso.async.max-pool-size}")
64         private int maxPoolSize;
65
66         @Value("${mso.async.queue-capacity}")
67         private int queueCapacity;
68
69         private static final String LOGS_DIR = "logs_dir";
70
71
72         private static void setLogsDir() {
73                 if (System.getProperty(LOGS_DIR) == null) {
74                         System.getProperties().setProperty(LOGS_DIR, "./logs/bpmn/");
75                 }
76         }
77
78         public static void main(String... args) {
79                 SpringApplication.run(MSOInfrastructureApplication.class, args);
80                 System.getProperties().setProperty("mso.config.path", ".");
81                 setLogsDir();
82         }
83
84         @PostDeploy
85         public void postDeploy(ProcessEngine processEngineInstance) {
86         }
87
88         @PreUndeploy
89         public void cleanup(ProcessEngine processEngine, ProcessApplicationInfo processApplicationInfo,
90                         List<ProcessEngine> processEngines) {
91         }
92
93         @Bean
94         @Primary
95         public Executor asyncExecutor() {
96                 ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
97                 executor.setTaskDecorator(new MDCTaskDecorator());
98                 executor.setCorePoolSize(corePoolSize);
99                 executor.setMaxPoolSize(maxPoolSize);
100                 executor.setQueueCapacity(queueCapacity);
101                 executor.setThreadNamePrefix("Camunda-");
102                 executor.initialize();
103                 return executor;
104         }
105 }