added generic fabric support to SO
[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.logger.MsoLogger;
33 import org.springframework.beans.factory.annotation.Value;
34 import org.springframework.boot.SpringApplication;
35 import org.springframework.boot.autoconfigure.SpringBootApplication;
36 import org.springframework.context.annotation.Bean;
37 import org.springframework.context.annotation.ComponentScan;
38 import org.springframework.context.annotation.ComponentScan.Filter;
39 import org.springframework.context.annotation.FilterType;
40 import org.springframework.scheduling.annotation.EnableAsync;
41 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
42
43 /**
44  * @since Version 1.0
45  *
46  */
47
48 @SpringBootApplication
49 @EnableProcessApplication("MSO Common Application")
50 @EnableAsync
51 @ComponentScan(basePackages = { "org.onap" }, nameGenerator = DefaultToShortClassNameBeanNameGenerator.class, excludeFilters = {
52                                 @Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)})
53 public class MSOCommonApplication {
54
55         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,
56                         MSOCommonApplication.class);
57
58         @Value("${mso.async.core-pool-size}")
59         private int corePoolSize;
60
61         @Value("${mso.async.max-pool-size}")
62         private int maxPoolSize;
63
64         @Value("${mso.async.queue-capacity}")
65         private int queueCapacity;
66
67         private static final String LOGS_DIR = "logs_dir";
68
69
70         private static void setLogsDir() {
71                 if (System.getProperty(LOGS_DIR) == null) {
72                         System.getProperties().setProperty(LOGS_DIR, "./logs/bpmn/");
73                 }
74         }
75
76         public static void main(String... args) {
77                 SpringApplication.run(MSOCommonApplication.class, args);
78                 System.getProperties().setProperty("mso.config.path", ".");
79                 setLogsDir();
80         }
81
82         @PostDeploy
83         public void postDeploy(ProcessEngine processEngineInstance) {
84                 long startTime = System.currentTimeMillis();
85
86                 msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
87                                 "Post deployment complete...");
88         }
89
90         @PreUndeploy
91         public void cleanup(ProcessEngine processEngine, ProcessApplicationInfo processApplicationInfo,
92                         List<ProcessEngine> processEngines) {
93                 long startTime = System.currentTimeMillis();
94
95                 msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
96                                 "Pre Undeploy complete...");
97
98         }
99
100         @Bean
101         public Executor asyncExecutor() {
102                 ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
103
104                 executor.setCorePoolSize(corePoolSize);
105                 executor.setMaxPoolSize(maxPoolSize);
106                 executor.setQueueCapacity(queueCapacity);
107                 executor.setThreadNamePrefix("Camunda-");
108                 executor.initialize();
109                 return executor;
110         }
111 }