2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 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.setup;
24 import java.util.HashMap;
27 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
28 import org.onap.ccsdk.features.sdnr.wt.common.database.data.IndicesEntryList;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient;
30 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.SdnrDbType;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.KeepDataSearchHitConverter;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.MariaDBTableInfo;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release;
36 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter;
37 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.elalto.ElAltoReleaseInformation;
38 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.FrankfurtReleaseInformation;
39 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.FrankfurtReleaseInformationR2;
40 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.guilin.GuilinReleaseInformation;
41 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.honolulu.HonoluluReleaseInformation;
42 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.istanbul.IstanbulReleaseInformation;
43 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.jakarta.JakartaReleaseInformation;
45 public abstract class ReleaseInformation {
48 private final Release release;
49 private final Map<ComponentName, DatabaseInfo> dbMap;
50 private Map<ComponentName, MariaDBTableInfo> mariadbMap;
54 public ReleaseInformation(Release r, Map<ComponentName, DatabaseInfo> dbMap) {
55 this(r, dbMap, new HashMap<>());
58 public ReleaseInformation(Release r, Map<ComponentName, DatabaseInfo> dbMap,
59 Map<ComponentName, MariaDBTableInfo> mariadbMap) {
62 this.mariadbMap = mariadbMap;
64 // end of constructors
66 protected Release getReleas() {
71 * get database alias for component
74 * @return alias or null if not exists
76 public String getAlias(ComponentName name) {
77 return this.getAlias(name, "");
80 public String getAlias(ComponentName name, String prefix) {
81 return dbMap.get(name) == null ? null : prefix + dbMap.get(name).alias;
85 * get index name for component
88 * @return null if component does not exists in this release, otherwise index name
90 public String getIndex(ComponentName comp) {
91 return this.getIndex(comp, "");
95 * get index name for component with prefix
99 * @return null if component does not exists in this release, otherwise index name
101 public String getIndex(ComponentName comp, String prefix) {
102 return dbMap.get(comp) == null ? null : (prefix + dbMap.get(comp).getIndex(this.release.getDBSuffix()));
106 * get database datatype (doctype) for component
109 * @return datatype or null if not exists
111 public String getDataType(ComponentName name) {
112 return dbMap.get(name) == null ? null : dbMap.get(name).doctype;
115 public String getDatabaseMapping(ComponentName name) {
116 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping();
120 * get database doctype definition for component
123 * @return mappings or null if not exists
125 public String getDatabaseMapping(ComponentName name, boolean useStrict) {
126 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping(useStrict);
130 * get database settings definition for component
133 * @return settings or null if not exists
135 public String getDatabaseSettings(ComponentName name, int shards, int replicas) {
136 return dbMap.get(name) == null ? null : dbMap.get(name).getSettings(shards, replicas);
139 public String getDatabaseMapping(ComponentName name, SdnrDbType dbType) {
142 return this.getDatabaseMapping(name);
144 return mariadbMap.get(name) == null ? null
145 : mariadbMap.get(name).getMapping(this.release.getDBSuffix());
152 * get converter for component data
154 * @param dst destination release
155 * @param comp component to convert
158 public SearchHitConverter getConverter(Release dst, ComponentName comp) {
159 if (dst == this.release && this.getComponents().contains(comp)) {
160 return new KeepDataSearchHitConverter(comp);
165 public static ReleaseInformation getInstance(Release r) {
168 return new ElAltoReleaseInformation();
170 return new FrankfurtReleaseInformation();
172 return new FrankfurtReleaseInformationR2();
174 return new GuilinReleaseInformation();
176 return new HonoluluReleaseInformation();
178 return new IstanbulReleaseInformation();
180 return new JakartaReleaseInformation();
189 public Set<ComponentName> getComponents() {
190 return dbMap.keySet();
197 public boolean hasOwnDbIndex(ComponentName component) {
198 return this.getDatabaseMapping(component) != null;
203 * @return true if components of this release are covered by the given indices
205 public boolean containsIndices(IndicesEntryList indices) {
207 if (this.dbMap.size() <= 0) {
210 for (DatabaseInfo entry : this.dbMap.values()) {
211 String dbIndexName = entry.getIndex(this.release.getDBSuffix());
212 if (indices.findByIndex(dbIndexName) == null) {
222 * @return if succeeded or not
224 public abstract boolean runPreInitCommands(HtDatabaseClient dbClient);
226 public abstract boolean runPreInitCommands(SqlDBClient dbClient);
231 * @return if succeeded or not
233 public abstract boolean runPostInitCommands(HtDatabaseClient dbClient);
235 public abstract boolean runPostInitCommands(SqlDBClient dbClient);