5c5aa2a8b37a837bc77abf5fe26500b92fd73751
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup;
23
24 import java.util.Map;
25 import java.util.Set;
26
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.guilin.GuilinReleaseInformation;
36
37 public abstract class ReleaseInformation {
38
39         private final Release release;
40         private final Map<ComponentName, DatabaseInfo> dbMap;
41
42         public ReleaseInformation(Release r, Map<ComponentName, DatabaseInfo> dbMap) {
43                 this.release = r;
44                 this.dbMap = dbMap;
45         }
46
47         /**
48          * get database alias for component
49          * @param name
50          * @return alias or null if not exists
51          */
52         public String getAlias(ComponentName name) {
53                 return this.getAlias(name,"");
54         }
55         public String getAlias(ComponentName name,String prefix) {
56                 return dbMap.get(name) == null ? null : prefix+dbMap.get(name).alias;
57         }
58
59         /**
60          * @param c
61          * @return
62          */
63         public String getIndex(ComponentName name) {
64                 return this.getIndex(name,"");
65         }
66         public String getIndex(ComponentName name,String prefix) {
67                 return dbMap.get(name) == null ? null : (prefix+dbMap.get(name).getIndex(this.release.getDBSuffix())); 
68         }
69
70         /**
71                  * get database datatype (doctype) for component
72                  * @param name
73                  * @return datatype or null if not exists
74                  */
75         public String getDataType(ComponentName name) {
76                 return dbMap.get(name) == null ? null : dbMap.get(name).doctype;
77         }
78
79         /**
80          * get database doctype definition for component
81          * @param name
82          * @return mappings or null if not exists
83          */
84         public String getDatabaseMapping(ComponentName name) {
85                 return dbMap.get(name) == null ? null : dbMap.get(name).getMapping();
86         }
87         /**
88          * get database settings definition for component
89          * @param name
90          * @return settings or null if not exists
91          */
92         public String getDatabaseSettings(ComponentName name,int shards,int replicas) {
93                 return dbMap.get(name) == null ? null : dbMap.get(name).getSettings(shards, replicas);
94         }
95
96         /**
97          * get converter for component data
98          * @param dst destination release
99          * @param comp component to convert
100          * @return
101          */
102         public SearchHitConverter getConverter(Release dst, ComponentName comp) {
103                 if(dst==this.release && this.getComponents().contains(comp)) {
104                         return new KeepDataSearchHitConverter(comp);
105                 }
106                 return null;
107         }
108
109         public static ReleaseInformation getInstance(Release r) {
110                 switch (r) {
111                 case EL_ALTO:
112                         return new ElAltoReleaseInformation();
113                 case FRANKFURT_R1:
114                         return new FrankfurtReleaseInformation();
115                 case GUILIN:
116                         return new GuilinReleaseInformation();
117                 default:
118                         return null;
119                 }
120         }
121
122         /**
123          * @return
124          */
125         public Set<ComponentName> getComponents() {
126                 return dbMap.keySet();
127         }
128
129         /**
130          * @param component
131          * @return
132          */
133         public boolean hasOwnDbIndex(ComponentName component) {
134                 return this.getDatabaseMapping(component)!=null;
135         }
136
137         /**
138          * @param indices
139          * @return true if components of this release are covered by the given indices
140          */
141         protected boolean containsIndices(IndicesEntryList indices) {
142                 
143                 if(this.dbMap.size()<=0) {
144                         return false;
145                 }
146                 for(DatabaseInfo entry:this.dbMap.values()) {
147                         String dbIndexName = entry.getIndex(this.release.getDBSuffix());
148                         if(indices.findByIndex(dbIndexName)==null) {
149                                 return false;
150                         }
151                 }
152                 return true;
153                 
154         }
155         
156
157 }