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;
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.setup.data.ComponentName;
30 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.KeepDataSearchHitConverter;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.elalto.ElAltoReleaseInformation;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.FrankfurtReleaseInformation;
36 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.FrankfurtReleaseInformationR2;
37 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.guilin.GuilinReleaseInformation;
38 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.guilin.GuilinReleaseInformationR2;
40 public abstract class ReleaseInformation {
43 private final Release release;
44 private final Map<ComponentName, DatabaseInfo> dbMap;
48 public ReleaseInformation(Release r, Map<ComponentName, DatabaseInfo> dbMap) {
52 // end of constructors
55 * get database alias for component
58 * @return alias or null if not exists
60 public String getAlias(ComponentName name) {
61 return this.getAlias(name, "");
64 public String getAlias(ComponentName name, String prefix) {
65 return dbMap.get(name) == null ? null : prefix + dbMap.get(name).alias;
69 * get index name for component
72 * @return null if component does not exists in this release, otherwise index name
74 public String getIndex(ComponentName comp) {
75 return this.getIndex(comp, "");
79 * get index name for component with prefix
83 * @return null if component does not exists in this release, otherwise index name
85 public String getIndex(ComponentName comp, String prefix) {
86 return dbMap.get(comp) == null ? null : (prefix + dbMap.get(comp).getIndex(this.release.getDBSuffix()));
90 * get database datatype (doctype) for component
93 * @return datatype or null if not exists
95 public String getDataType(ComponentName name) {
96 return dbMap.get(name) == null ? null : dbMap.get(name).doctype;
99 public String getDatabaseMapping(ComponentName name) {
100 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping();
104 * get database doctype definition for component
107 * @return mappings or null if not exists
109 public String getDatabaseMapping(ComponentName name, boolean useStrict) {
110 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping(useStrict);
114 * get database settings definition for component
117 * @return settings or null if not exists
119 public String getDatabaseSettings(ComponentName name, int shards, int replicas) {
120 return dbMap.get(name) == null ? null : dbMap.get(name).getSettings(shards, replicas);
124 * get converter for component data
126 * @param dst destination release
127 * @param comp component to convert
130 public SearchHitConverter getConverter(Release dst, ComponentName comp) {
131 if (dst == this.release && this.getComponents().contains(comp)) {
132 return new KeepDataSearchHitConverter(comp);
137 public static ReleaseInformation getInstance(Release r) {
140 return new ElAltoReleaseInformation();
142 return new FrankfurtReleaseInformation();
144 return new FrankfurtReleaseInformationR2();
146 return new GuilinReleaseInformation();
148 return new GuilinReleaseInformationR2();
157 public Set<ComponentName> getComponents() {
158 return dbMap.keySet();
165 public boolean hasOwnDbIndex(ComponentName component) {
166 return this.getDatabaseMapping(component) != null;
171 * @return true if components of this release are covered by the given indices
173 protected boolean containsIndices(IndicesEntryList indices) {
175 if (this.dbMap.size() <= 0) {
178 for (DatabaseInfo entry : this.dbMap.values()) {
179 String dbIndexName = entry.getIndex(this.release.getDBSuffix());
180 if (indices.findByIndex(dbIndexName) == null) {
190 * @return if succeeded or not
192 protected abstract boolean runPreInitCommands(HtDatabaseClient dbClient);
197 * @return if succeeded or not
199 protected abstract boolean runPostInitCommands(HtDatabaseClient dbClient);