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