2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb;
24 import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
25 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.DatabaseIdGenerator;
28 public class SqlDBConfig implements Configuration {
30 private static final String SECTION_MARKER_MARIADB = "mariadb";
32 private static final String PROPERTY_KEY_DBURL = "url";
33 private static final String PROPERTY_KEY_USERNAME = "username";
34 private static final String PROPERTY_KEY_PASSWORD = "password";
35 private static final String PROPERTY_KEY_CONTROLLERID = "controllerId";
36 private static final String PROPERTY_KEY_DBSUFFIX = "suffix";
39 private static final String DEFAULT_VALUE_DBURL = "${SDNRDBURL}";
40 private static final String DEFAULT_VALUE_DBUSERNAME = "${SDNRDBUSERNAME}";
41 private static final String DEFAULT_VALUE_DBPASSWORD = "${SDNRDBPASSWORD}";
42 private static final String DEFAULT_VALUE_CONTROLLERID = DatabaseIdGenerator.getControllerId();
43 private static final String DEFAULT_VALUE_DBSUFFIX = "-v6";
45 private final ConfigurationFileRepresentation configuration;
47 public SqlDBConfig(ConfigurationFileRepresentation configuration) {
49 this.configuration = configuration;
50 this.configuration.addSection(SECTION_MARKER_MARIADB);
59 public String getUrl() {
60 return configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBURL);
63 public void setUrl(String url) {
64 configuration.setProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBURL, url);
68 public String getUsername() {
69 return this.configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_USERNAME);
72 public String getPassword() {
73 return this.configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_PASSWORD);
76 public String getControllerId() {
77 String v = this.configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_CONTROLLERID);
78 return (v == null || v.equals("null") || v.isEmpty()) ? null : v;
81 public String getDbSuffix() {
82 return this.configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBSUFFIX);
86 public String getSectionName() {
87 return SECTION_MARKER_MARIADB;
91 public synchronized void defaults() {
92 // Add default if not available
93 configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBURL, DEFAULT_VALUE_DBURL);
94 configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_USERNAME,
95 DEFAULT_VALUE_DBUSERNAME);
96 configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_PASSWORD,
97 DEFAULT_VALUE_DBPASSWORD);
98 configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_CONTROLLERID,
99 DEFAULT_VALUE_CONTROLLERID);
100 configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBSUFFIX, DEFAULT_VALUE_DBSUFFIX);
105 public void setControllerId(String id) {
106 configuration.setProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_CONTROLLERID, id);
109 public void setDbSuffix(String suffix) {
110 configuration.setProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBSUFFIX, suffix);