13c6047168a5f0366cd4ce5434e651c4f56b8bbd
[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.data;
23
24 import org.onap.ccsdk.features.sdnr.wt.common.database.data.AliasesEntry;
25 import org.onap.ccsdk.features.sdnr.wt.common.database.data.EsVersion;
26
27 public enum Release {
28
29     EL_ALTO("el alto", "_v1", new EsVersion(2, 2, 0), new EsVersion(2, 2, 0)), FRANKFURT_R1("frankfurt-R1", "-v2",
30             new EsVersion(6, 4, 3), new EsVersion(6, 8, 6)), FRANKFURT_R2("frankfurt-R2", "", new EsVersion(6, 4, 3),
31                     new EsVersion(6, 8, 6)), FRANKFURT_R3("frankfurt-R3", "", new EsVersion(6, 4, 3),
32                             new EsVersion(6, 8, 6)),
33
34     GUILIN("guilin", "", new EsVersion(6, 4, 3), new EsVersion(6, 8, 6));
35
36     public static final Release CURRENT_RELEASE = Release.FRANKFURT_R1;
37
38     private final String value;
39     private final String dbSuffix;
40     private final EsVersion minDbVersion;
41     private final EsVersion maxDbVersion;
42
43     private Release(String s, String dbsuffix, EsVersion minDbVersion, EsVersion maxDbVersion) {
44         this.value = s;
45         this.dbSuffix = dbsuffix;
46         this.minDbVersion = minDbVersion;
47         this.maxDbVersion = maxDbVersion;
48     }
49
50     @Override
51     public String toString() {
52         return this.value;
53     }
54
55     public String getValue() {
56         return value;
57     }
58
59     public static Release getValueOf(String s) throws Exception {
60         //s = s.toLowerCase();
61         for (Release p : Release.values()) {
62             if (p.value.equals(s)) {
63                 return p;
64             }
65         }
66         throw new Exception("value not found");
67     }
68
69     public static Release getValueBySuffix(String suffix) {
70         for (Release r : Release.values()) {
71             if (r.dbSuffix.equals(suffix))
72                 return r;
73         }
74         return null;
75     }
76
77     public static String getDbSuffix(AliasesEntry entry) throws Exception {
78         ComponentName comp = ComponentName.getValueOf(entry.getAlias());
79         if (comp != null) {
80             return entry.getIndex().substring(entry.getAlias().length());
81         }
82         return null;
83     }
84
85     /**
86      * @return
87      */
88     public String getDBSuffix() {
89         return this.dbSuffix;
90     }
91
92     /**
93      * @return
94      */
95     public EsVersion getDBVersion() {
96         return this.minDbVersion;
97     }
98
99     /**
100      * @param dbVersion2
101      * @return
102      */
103     public boolean isDbInRange(EsVersion dbVersion) {
104         return dbVersion.isNewerOrEqualThan(minDbVersion) && dbVersion.isOlderOrEqualThan(maxDbVersion);
105     }
106 }