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.so.bpmn.common.DefaultToShortClassNameBeanNameGenerator;
33 import org.onap.so.db.catalog.beans.Workflow;
34 import org.onap.so.db.catalog.client.CatalogDbClient;
35 import org.onap.so.logging.jaxrs.filter.MDCTaskDecorator;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.beans.factory.annotation.Value;
40 import org.springframework.boot.SpringApplication;
41 import org.springframework.boot.autoconfigure.SpringBootApplication;
42 import org.springframework.context.annotation.Bean;
43 import org.springframework.context.annotation.ComponentScan;
44 import org.springframework.context.annotation.ComponentScan.Filter;
45 import org.springframework.context.annotation.FilterType;
46 import org.springframework.context.annotation.Primary;
47 import org.springframework.scheduling.annotation.EnableAsync;
48 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
55 @SpringBootApplication
57 @ComponentScan(basePackages = {"org.onap"}, nameGenerator = DefaultToShortClassNameBeanNameGenerator.class,
58 excludeFilters = {@Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)})
60 public class MSOInfrastructureApplication {
62 private static final Logger logger = LoggerFactory.getLogger(MSOInfrastructureApplication.class);
64 private ProcessEngine processEngine;
67 private CatalogDbClient catalogDbClient;
69 @Value("${mso.async.core-pool-size}")
70 private int corePoolSize;
72 @Value("${mso.async.max-pool-size}")
73 private int maxPoolSize;
75 @Value("${mso.async.queue-capacity}")
76 private int queueCapacity;
78 private static final String LOGS_DIR = "logs_dir";
79 private static final String BPMN_SUFFIX = ".bpmn";
80 private static final String SDC_SOURCE = "sdc";
83 private static void setLogsDir() {
84 if (System.getProperty(LOGS_DIR) == null) {
85 System.getProperties().setProperty(LOGS_DIR, "./logs/bpmn/");
89 public static void main(String... args) {
90 SpringApplication.run(MSOInfrastructureApplication.class, args);
91 System.getProperties().setProperty("mso.config.path", ".");
96 public void postConstruct() {
98 DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
99 deployCustomWorkflows(deploymentBuilder);
100 } catch (Exception e) {
101 logger.warn("Unable to invoke deploymentBuilder: " + e.getMessage());
106 public void cleanup(ProcessEngine processEngine, ProcessApplicationInfo processApplicationInfo,
107 List<ProcessEngine> processEngines) {}
111 public Executor asyncExecutor() {
112 ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
113 executor.setTaskDecorator(new MDCTaskDecorator());
114 executor.setCorePoolSize(corePoolSize);
115 executor.setMaxPoolSize(maxPoolSize);
116 executor.setQueueCapacity(queueCapacity);
117 executor.setThreadNamePrefix("Camunda-");
118 executor.initialize();
122 public void deployCustomWorkflows(DeploymentBuilder deploymentBuilder) {
123 logger.debug("Attempting to deploy custom workflows");
125 List<Workflow> workflows = catalogDbClient.findWorkflowBySource(SDC_SOURCE);
126 if (workflows != null && workflows.size() != 0) {
127 for (Workflow workflow : workflows) {
128 String workflowName = workflow.getName();
129 String workflowBody = workflow.getBody();
130 if (!workflowName.endsWith(BPMN_SUFFIX)) {
131 workflowName += BPMN_SUFFIX;
133 if (workflowBody != null) {
134 logger.info("{} {}", "Deploying custom workflow", workflowName);
135 deploymentBuilder.addString(workflowName, workflowBody);
138 deploymentBuilder.enableDuplicateFiltering(true);
139 deploymentBuilder.deploy();
141 } catch (Exception e) {
142 logger.warn("Unable to deploy custom workflows, " + e.getMessage());