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