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;
37 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.honolulu.HonoluluReleaseInformation;
39 public abstract class ReleaseInformation {
42 private final Release release;
43 private final Map<ComponentName, DatabaseInfo> dbMap;
47 public ReleaseInformation(Release r, Map<ComponentName, DatabaseInfo> dbMap) {
51 // end of constructors
54 * get database alias for component
57 * @return alias or null if not exists
59 public String getAlias(ComponentName name) {
60 return this.getAlias(name, "");
63 public String getAlias(ComponentName name, String prefix) {
64 return dbMap.get(name) == null ? null : prefix + dbMap.get(name).alias;
68 * get index name for component
71 * @return null if component does not exists in this release, otherwise index name
73 public String getIndex(ComponentName comp) {
74 return this.getIndex(comp, "");
78 * get index name for component with prefix
82 * @return null if component does not exists in this release, otherwise index name
84 public String getIndex(ComponentName comp, String prefix) {
85 return dbMap.get(comp) == null ? null : (prefix + dbMap.get(comp).getIndex(this.release.getDBSuffix()));
89 * get database datatype (doctype) for component
92 * @return datatype or null if not exists
94 public String getDataType(ComponentName name) {
95 return dbMap.get(name) == null ? null : dbMap.get(name).doctype;
98 public String getDatabaseMapping(ComponentName name) {
99 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping();
103 * get database doctype definition for component
106 * @return mappings or null if not exists
108 public String getDatabaseMapping(ComponentName name, boolean useStrict) {
109 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping(useStrict);
113 * get database settings definition for component
116 * @return settings or null if not exists
118 public String getDatabaseSettings(ComponentName name, int shards, int replicas) {
119 return dbMap.get(name) == null ? null : dbMap.get(name).getSettings(shards, replicas);
123 * get converter for component data
125 * @param dst destination release
126 * @param comp component to convert
129 public SearchHitConverter getConverter(Release dst, ComponentName comp) {
130 if (dst == this.release && this.getComponents().contains(comp)) {
131 return new KeepDataSearchHitConverter(comp);
136 public static ReleaseInformation getInstance(Release r) {
139 return new ElAltoReleaseInformation();
141 return new FrankfurtReleaseInformation();
143 return new FrankfurtReleaseInformationR2();
145 return new GuilinReleaseInformation();
147 return new HonoluluReleaseInformation();
156 public Set<ComponentName> getComponents() {
157 return dbMap.keySet();
164 public boolean hasOwnDbIndex(ComponentName component) {
165 return this.getDatabaseMapping(component) != null;
170 * @return true if components of this release are covered by the given indices
172 protected boolean containsIndices(IndicesEntryList indices) {
174 if (this.dbMap.size() <= 0) {
177 for (DatabaseInfo entry : this.dbMap.values()) {
178 String dbIndexName = entry.getIndex(this.release.getDBSuffix());
179 if (indices.findByIndex(dbIndexName) == null) {
189 * @return if succeeded or not
191 protected abstract boolean runPreInitCommands(HtDatabaseClient dbClient);
196 * @return if succeeded or not
198 protected abstract boolean runPostInitCommands(HtDatabaseClient dbClient);