2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.bpmn.infrastructure;
25 import java.util.List;
26 import java.util.concurrent.Executor;
27 import javax.annotation.PostConstruct;
28 import org.camunda.bpm.application.PreUndeploy;
29 import org.camunda.bpm.application.ProcessApplicationInfo;
30 import org.camunda.bpm.engine.ProcessEngine;
31 import org.camunda.bpm.engine.repository.DeploymentBuilder;
32 import org.onap.logging.filter.spring.MDCTaskDecorator;
33 import org.onap.so.bpmn.common.DefaultToShortClassNameBeanNameGenerator;
34 import org.onap.so.db.catalog.beans.Workflow;
35 import org.onap.so.db.catalog.client.CatalogDbClient;
36 import org.onap.so.logger.LoggingAnchor;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.beans.factory.annotation.Value;
41 import org.springframework.boot.SpringApplication;
42 import org.springframework.boot.autoconfigure.SpringBootApplication;
43 import org.springframework.context.annotation.Bean;
44 import org.springframework.context.annotation.ComponentScan;
45 import org.springframework.context.annotation.ComponentScan.Filter;
46 import org.springframework.context.annotation.FilterType;
47 import org.springframework.context.annotation.Primary;
48 import org.springframework.scheduling.annotation.EnableAsync;
49 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
56 @SpringBootApplication
58 @ComponentScan(basePackages = {"org.onap"}, nameGenerator = DefaultToShortClassNameBeanNameGenerator.class,
59 excludeFilters = {@Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)})
61 public class MSOInfrastructureApplication {
63 private static final Logger logger = LoggerFactory.getLogger(MSOInfrastructureApplication.class);
65 private ProcessEngine processEngine;
68 private CatalogDbClient catalogDbClient;
70 @Value("${mso.async.core-pool-size}")
71 private int corePoolSize;
73 @Value("${mso.async.max-pool-size}")
74 private int maxPoolSize;
76 @Value("${mso.async.queue-capacity}")
77 private int queueCapacity;
79 private static final String LOGS_DIR = "logs_dir";
80 private static final String BPMN_SUFFIX = ".bpmn";
81 private static final String SDC_SOURCE = "sdc";
84 private static void setLogsDir() {
85 if (System.getProperty(LOGS_DIR) == null) {
86 System.getProperties().setProperty(LOGS_DIR, "./logs/bpmn/");
90 public static void main(String... args) {
91 SpringApplication.run(MSOInfrastructureApplication.class, args);
92 System.getProperties().setProperty("mso.config.path", ".");
97 public void postConstruct() {
99 DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
100 deployCustomWorkflows(deploymentBuilder);
101 } catch (Exception e) {
102 logger.warn("Unable to invoke deploymentBuilder ", e);
107 public void cleanup(ProcessEngine processEngine, ProcessApplicationInfo processApplicationInfo,
108 List<ProcessEngine> processEngines) {}
112 public Executor asyncExecutor() {
113 ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
114 executor.setTaskDecorator(new MDCTaskDecorator());
115 executor.setCorePoolSize(corePoolSize);
116 executor.setMaxPoolSize(maxPoolSize);
117 executor.setQueueCapacity(queueCapacity);
118 executor.setThreadNamePrefix("Camunda-");
119 executor.initialize();
123 public void deployCustomWorkflows(DeploymentBuilder deploymentBuilder) {
124 logger.debug("Attempting to deploy custom workflows");
126 List<Workflow> workflows = catalogDbClient.findWorkflowBySource(SDC_SOURCE);
127 if (workflows != null && !workflows.isEmpty()) {
128 for (Workflow workflow : workflows) {
129 String workflowName = workflow.getName();
130 String workflowBody = workflow.getBody();
131 if (!workflowName.endsWith(BPMN_SUFFIX)) {
132 workflowName += BPMN_SUFFIX;
134 if (workflowBody != null) {
135 logger.info(LoggingAnchor.TWO, "Deploying custom workflow", workflowName);
136 deploymentBuilder.addString(workflowName, workflowBody);
138 deploymentBuilder.enableDuplicateFiltering(true);
140 deploymentBuilder.deploy();
142 } catch (Exception e) {
143 logger.warn("Unable to deploy custom workflows ", e);