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;
44 public abstract class ReleaseInformation {
47 private final Release release;
48 private final Map<ComponentName, DatabaseInfo> dbMap;
49 private Map<ComponentName, MariaDBTableInfo> mariadbMap;
53 public ReleaseInformation(Release r, Map<ComponentName, DatabaseInfo> dbMap) {
54 this(r, dbMap, new HashMap<>());
57 public ReleaseInformation(Release r, Map<ComponentName, DatabaseInfo> dbMap,
58 Map<ComponentName, MariaDBTableInfo> mariadbMap) {
61 this.mariadbMap = mariadbMap;
63 // end of constructors
65 protected Release getReleas() {
70 * get database alias for component
73 * @return alias or null if not exists
75 public String getAlias(ComponentName name) {
76 return this.getAlias(name, "");
79 public String getAlias(ComponentName name, String prefix) {
80 return dbMap.get(name) == null ? null : prefix + dbMap.get(name).alias;
84 * get index name for component
87 * @return null if component does not exists in this release, otherwise index name
89 public String getIndex(ComponentName comp) {
90 return this.getIndex(comp, "");
94 * get index name for component with prefix
98 * @return null if component does not exists in this release, otherwise index name
100 public String getIndex(ComponentName comp, String prefix) {
101 return dbMap.get(comp) == null ? null : (prefix + dbMap.get(comp).getIndex(this.release.getDBSuffix()));
105 * get database datatype (doctype) for component
108 * @return datatype or null if not exists
110 public String getDataType(ComponentName name) {
111 return dbMap.get(name) == null ? null : dbMap.get(name).doctype;
114 public String getDatabaseMapping(ComponentName name) {
115 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping();
119 * get database doctype definition for component
122 * @return mappings or null if not exists
124 public String getDatabaseMapping(ComponentName name, boolean useStrict) {
125 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping(useStrict);
129 * get database settings definition for component
132 * @return settings or null if not exists
134 public String getDatabaseSettings(ComponentName name, int shards, int replicas) {
135 return dbMap.get(name) == null ? null : dbMap.get(name).getSettings(shards, replicas);
138 public String getDatabaseMapping(ComponentName name, SdnrDbType dbType) {
141 return this.getDatabaseMapping(name);
143 return mariadbMap.get(name) == null ? null
144 : mariadbMap.get(name).getMapping(this.release.getDBSuffix());
151 * get converter for component data
153 * @param dst destination release
154 * @param comp component to convert
157 public SearchHitConverter getConverter(Release dst, ComponentName comp) {
158 if (dst == this.release && this.getComponents().contains(comp)) {
159 return new KeepDataSearchHitConverter(comp);
164 public static ReleaseInformation getInstance(Release r) {
167 return new ElAltoReleaseInformation();
169 return new FrankfurtReleaseInformation();
171 return new FrankfurtReleaseInformationR2();
173 return new GuilinReleaseInformation();
175 return new HonoluluReleaseInformation();
177 return new IstanbulReleaseInformation();
186 public Set<ComponentName> getComponents() {
187 return dbMap.keySet();
194 public boolean hasOwnDbIndex(ComponentName component) {
195 return this.getDatabaseMapping(component) != null;
200 * @return true if components of this release are covered by the given indices
202 public boolean containsIndices(IndicesEntryList indices) {
204 if (this.dbMap.size() <= 0) {
207 for (DatabaseInfo entry : this.dbMap.values()) {
208 String dbIndexName = entry.getIndex(this.release.getDBSuffix());
209 if (indices.findByIndex(dbIndexName) == null) {
219 * @return if succeeded or not
221 public abstract boolean runPreInitCommands(HtDatabaseClient dbClient);
223 public abstract boolean runPreInitCommands(SqlDBClient dbClient);
228 * @return if succeeded or not
230 public abstract boolean runPostInitCommands(HtDatabaseClient dbClient);
232 public abstract boolean runPostInitCommands(SqlDBClient dbClient);