Implementing Create NS
[so.git] / so-etsi-nfvo / so-etsi-nfvo-ns-lcm / so-etsi-nfvo-ns-lcm-bpmn-flows / src / main / java / org / onap / so / etsi / nfvo / ns / lcm / bpmn / flows / CamundaDatabaseConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows;
21
22
23 import static org.slf4j.LoggerFactory.getLogger;
24 import javax.sql.DataSource;
25 import org.slf4j.Logger;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.boot.context.properties.ConfigurationProperties;
28 import org.springframework.context.annotation.Bean;
29 import org.springframework.context.annotation.Configuration;
30 import org.springframework.context.annotation.Primary;
31 import org.springframework.context.annotation.Profile;
32 import org.springframework.jmx.export.MBeanExporter;
33 import org.springframework.transaction.annotation.EnableTransactionManagement;
34 import com.zaxxer.hikari.HikariConfig;
35 import com.zaxxer.hikari.HikariDataSource;
36
37 /**
38  * @author Waqas Ikram (waqas.ikram@est.tech)
39  *
40  */
41 @Configuration
42 @EnableTransactionManagement
43 @Profile({"!test"})
44 public class CamundaDatabaseConfiguration {
45
46     private static final Logger logger = getLogger(CamundaDatabaseConfiguration.class);
47
48     @Autowired(required = false)
49     private MBeanExporter mBeanExporter;
50
51     @Bean
52     @ConfigurationProperties(prefix = "spring.datasource.hikari.camunda")
53     public HikariConfig camundaDbConfig() {
54         logger.debug("Creating HikariConfig bean ... ");
55         return new HikariConfig();
56     }
57
58     @Primary
59     @Bean(name = "dataSource")
60     public DataSource dataSource() {
61         if (mBeanExporter != null) {
62             mBeanExporter.addExcludedBean("dataSource");
63         }
64         logger.debug("Creating HikariDataSource bean ... ");
65         final HikariConfig hikariConfig = this.camundaDbConfig();
66         return new HikariDataSource(hikariConfig);
67     }
68
69 }