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