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