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.guilin.GuilinReleaseInformation;
38 public abstract class ReleaseInformation {
40 private final Release release;
41 private final Map<ComponentName, DatabaseInfo> dbMap;
43 public ReleaseInformation(Release r, Map<ComponentName, DatabaseInfo> dbMap) {
49 * get database alias for component
51 * @return alias or null if not exists
53 public String getAlias(ComponentName name) {
54 return this.getAlias(name,"");
56 public String getAlias(ComponentName name,String prefix) {
57 return dbMap.get(name) == null ? null : prefix+dbMap.get(name).alias;
64 public String getIndex(ComponentName name) {
65 return this.getIndex(name,"");
67 public String getIndex(ComponentName name,String prefix) {
68 return dbMap.get(name) == null ? null : (prefix+dbMap.get(name).getIndex(this.release.getDBSuffix()));
72 * get database datatype (doctype) for component
74 * @return datatype or null if not exists
76 public String getDataType(ComponentName name) {
77 return dbMap.get(name) == null ? null : dbMap.get(name).doctype;
80 public String getDatabaseMapping(ComponentName name) {
81 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping();
84 * get database doctype definition for component
86 * @return mappings or null if not exists
88 public String getDatabaseMapping(ComponentName name,boolean useStrict) {
89 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping(useStrict);
92 * get database settings definition for component
94 * @return settings or null if not exists
96 public String getDatabaseSettings(ComponentName name,int shards,int replicas) {
97 return dbMap.get(name) == null ? null : dbMap.get(name).getSettings(shards, replicas);
101 * get converter for component data
102 * @param dst destination release
103 * @param comp component to convert
106 public SearchHitConverter getConverter(Release dst, ComponentName comp) {
107 if(dst==this.release && this.getComponents().contains(comp)) {
108 return new KeepDataSearchHitConverter(comp);
113 public static ReleaseInformation getInstance(Release r) {
116 return new ElAltoReleaseInformation();
118 return new FrankfurtReleaseInformation();
120 return new GuilinReleaseInformation();
129 public Set<ComponentName> getComponents() {
130 return dbMap.keySet();
137 public boolean hasOwnDbIndex(ComponentName component) {
138 return this.getDatabaseMapping(component)!=null;
143 * @return true if components of this release are covered by the given indices
145 protected boolean containsIndices(IndicesEntryList indices) {
147 if(this.dbMap.size()<=0) {
150 for(DatabaseInfo entry:this.dbMap.values()) {
151 String dbIndexName = entry.getIndex(this.release.getDBSuffix());
152 if(indices.findByIndex(dbIndexName)==null) {
162 * @return if succeeded or not
164 protected abstract boolean runPreInitCommands(HtDatabaseClient dbClient);
170 * @return if succeeded or not
172 protected abstract boolean runPostInitCommands(HtDatabaseClient dbClient);