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;
26 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
27 import org.onap.ccsdk.features.sdnr.wt.common.database.data.IndicesEntryList;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo;
30 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.KeepDataSearchHitConverter;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.elalto.ElAltoReleaseInformation;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.FrankfurtReleaseInformation;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.FrankfurtReleaseInformationR2;
36 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.guilin.GuilinReleaseInformation;
38 public abstract class ReleaseInformation {
41 private final Release release;
42 private final Map<ComponentName, DatabaseInfo> dbMap;
46 public ReleaseInformation(Release r, Map<ComponentName, DatabaseInfo> dbMap) {
50 // end of constructors
53 * get database alias for component
56 * @return alias or null if not exists
58 public String getAlias(ComponentName name) {
59 return this.getAlias(name, "");
62 public String getAlias(ComponentName name, String prefix) {
63 return dbMap.get(name) == null ? null : prefix + dbMap.get(name).alias;
67 * get index name for component
70 * @return null if component does not exists in this release, otherwise index name
72 public String getIndex(ComponentName comp) {
73 return this.getIndex(comp, "");
77 * get index name for component with prefix
81 * @return null if component does not exists in this release, otherwise index name
83 public String getIndex(ComponentName comp, String prefix) {
84 return dbMap.get(comp) == null ? null : (prefix + dbMap.get(comp).getIndex(this.release.getDBSuffix()));
88 * get database datatype (doctype) for component
91 * @return datatype or null if not exists
93 public String getDataType(ComponentName name) {
94 return dbMap.get(name) == null ? null : dbMap.get(name).doctype;
97 public String getDatabaseMapping(ComponentName name) {
98 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping();
102 * get database doctype definition for component
105 * @return mappings or null if not exists
107 public String getDatabaseMapping(ComponentName name, boolean useStrict) {
108 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping(useStrict);
112 * get database settings definition for component
115 * @return settings or null if not exists
117 public String getDatabaseSettings(ComponentName name, int shards, int replicas) {
118 return dbMap.get(name) == null ? null : dbMap.get(name).getSettings(shards, replicas);
122 * get converter for component data
124 * @param dst destination release
125 * @param comp component to convert
128 public SearchHitConverter getConverter(Release dst, ComponentName comp) {
129 if (dst == this.release && this.getComponents().contains(comp)) {
130 return new KeepDataSearchHitConverter(comp);
135 public static ReleaseInformation getInstance(Release r) {
138 return new ElAltoReleaseInformation();
140 return new FrankfurtReleaseInformation();
142 return new FrankfurtReleaseInformationR2();
144 return new GuilinReleaseInformation();
153 public Set<ComponentName> getComponents() {
154 return dbMap.keySet();
161 public boolean hasOwnDbIndex(ComponentName component) {
162 return this.getDatabaseMapping(component) != null;
167 * @return true if components of this release are covered by the given indices
169 protected boolean containsIndices(IndicesEntryList indices) {
171 if (this.dbMap.size() <= 0) {
174 for (DatabaseInfo entry : this.dbMap.values()) {
175 String dbIndexName = entry.getIndex(this.release.getDBSuffix());
176 if (indices.findByIndex(dbIndexName) == null) {
186 * @return if succeeded or not
188 protected abstract boolean runPreInitCommands(HtDatabaseClient dbClient);
193 * @return if succeeded or not
195 protected abstract boolean runPostInitCommands(HtDatabaseClient dbClient);