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