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.istanbul;
24 import java.io.IOException;
25 import java.util.HashMap;
27 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
28 import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterSettingsRequest;
29 import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ClusterSettingsResponse;
30 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo7;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.KeepDataSearchHitConverter;
36 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.MariaDBTableInfo;
37 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release;
38 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter;
39 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.honolulu.HonoluluReleaseInformation;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
44 public class IstanbulReleaseInformation extends ReleaseInformation {
46 private final Logger LOG = LoggerFactory.getLogger(IstanbulReleaseInformation.class);
48 public static final String TIMEZONE_TYPE_FORMAT =
49 "CHAR(6) DEFAULT NULL CHECK (`%s` regexp '^[+-]\\\\d\\\\d:\\\\d\\\\d$')";
50 public static final String TABLENAME_CONTROLLER_FORMAT = "controller%s";
51 public static final String TABLEMAPPING_CONTROLLER =
52 "`id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,`desc` VARCHAR(255) CHARACTER SET utf8 ,primary key(id)";
53 private static final String TABLEMAPPING_CONNECTIONLOG_FORMAT = "`id` int(11) NOT NULL AUTO_INCREMENT,\n"
54 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n" + "`timestamp` DATETIME(3) ,\n"
55 + "`status` VARCHAR(100) CHARACTER SET utf8 ,\n" + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n"
56 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
57 private static final String TABLEMAPPING_EVENTLOG_FORMAT = "`id` int(11) NOT NULL AUTO_INCREMENT,\n"
58 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n"
59 + "`source-type` VARCHAR(100) CHARACTER SET utf8 ,\n" + "`object-id` VARCHAR(255) CHARACTER SET utf8 ,\n"
60 + "`timestamp` DATETIME(3) ,\n" + "`timestamp-tz` " + String.format(TIMEZONE_TYPE_FORMAT, "timestamp-tz")
61 + " ,\n" + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`counter` INTEGER ,\n"
62 + "`attribute-name` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`new-value` VARCHAR(255) CHARACTER SET utf8 ,\n"
63 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
64 private static final String TABLEMAPPING_FAULTCURRENT_FORMAT = "`id` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\n"
65 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n"
66 + "`object-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`timestamp` DATETIME(3) ,\n" + "`timestamp-tz` "
67 + String.format(TIMEZONE_TYPE_FORMAT, "timestamp-tz") + " ,\n"
68 + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`counter` INTEGER ,\n"
69 + "`severity` VARCHAR(100) CHARACTER SET utf8 ,\n" + "`problem` VARCHAR(255) CHARACTER SET utf8 ,\n"
70 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
71 private static final String TABLEMAPPING_FAULTLOG_FORMAT = "`id` int(11) NOT NULL AUTO_INCREMENT,\n"
72 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n"
73 + "`source-type` VARCHAR(100) CHARACTER SET utf8 ,\n" + "`object-id` VARCHAR(255) CHARACTER SET utf8 ,\n"
74 + "`timestamp` DATETIME(3) ,\n" + "`timestamp-tz` " + String.format(TIMEZONE_TYPE_FORMAT, "timestamp-tz")
75 + " ,\n" + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`counter` INTEGER ,\n"
76 + "`severity` VARCHAR(100) CHARACTER SET utf8 ,\n" + "`problem` VARCHAR(255) CHARACTER SET utf8 ,\n"
77 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
78 private static final String TABLEMAPPING_GUICUTTHROUGH_FORMAT = "`id` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\n"
79 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n"
80 + "`name` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`weburi` VARCHAR(255) CHARACTER SET utf8 ,\n"
81 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
82 private static final String TABLEMAPPING_HISTORICALPM15M_FORMAT = "`id` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\n"
83 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n" + "`performance-data` JSON ,\n"
84 + "`granularity-period` VARCHAR(100) CHARACTER SET utf8 ,\n" + "`time-stamp` DATETIME(3) ,\n"
85 + "`time-stamp-tz` " + String.format(TIMEZONE_TYPE_FORMAT, "time-stamp-tz") + " ,\n"
86 + "`node-name` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`uuid-interface` VARCHAR(255) CHARACTER SET utf8 ,\n"
87 + "`layer-protocol-name` VARCHAR(255) CHARACTER SET utf8 ,\n"
88 + "`radio-signal-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`suspect-interval-flag` BOOLEAN ,\n"
89 + "`scanner-id` VARCHAR(255) CHARACTER SET utf8 ,\n"
90 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
91 private static final String TABLEMAPPING_HISTORICALPM24H_FORMAT = "`id` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\n"
92 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n" + "`performance-data` JSON ,\n"
93 + "`granularity-period` VARCHAR(100) CHARACTER SET utf8 ,\n" + "`time-stamp` DATETIME(3) ,\n"
94 + "`time-stamp-tz` " + String.format(TIMEZONE_TYPE_FORMAT, "time-stamp-tz") + " ,\n"
95 + "`node-name` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`uuid-interface` VARCHAR(255) CHARACTER SET utf8 ,\n"
96 + "`layer-protocol-name` VARCHAR(255) CHARACTER SET utf8 ,\n"
97 + "`radio-signal-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`suspect-interval-flag` BOOLEAN ,\n"
98 + "`scanner-id` VARCHAR(255) CHARACTER SET utf8 ,\n"
99 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
100 private static final String TABLEMAPPING_INVENTORY_FORMAT = "`id` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\n"
101 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n"
102 + "`version` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`type-name` VARCHAR(255) CHARACTER SET utf8 ,\n"
103 + "`date` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`description` VARCHAR(1024) CHARACTER SET utf8 ,\n"
104 + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`uuid` VARCHAR(255) CHARACTER SET utf8 ,\n"
105 + "`part-type-id` VARCHAR(255) CHARACTER SET utf8 ,\n"
106 + "`model-identifier` VARCHAR(255) CHARACTER SET utf8 ,\n"
107 + "`manufacturer-identifier` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`tree-level` BIGINT ,\n"
108 + "`parent-uuid` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`contained-holder` JSON ,\n"
109 + "`serial` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`manufacturer-name` VARCHAR(255) CHARACTER SET utf8 ,\n"
110 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
111 private static final String TABLEMAPPING_MAINTENANCE_FORMAT = "`id` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\n"
112 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n" + "`active` BOOLEAN ,\n"
113 + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`description` VARCHAR(1024) CHARACTER SET utf8 ,\n"
114 + "`problem` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`start` DATETIME(3) ,\n" + "`start-tz` "
115 + String.format(TIMEZONE_TYPE_FORMAT, "start-tz") + " ,\n" + "`end` DATETIME(3) ,\n" + "`end-tz` "
116 + String.format(TIMEZONE_TYPE_FORMAT, "end-tz") + " ,\n"
117 + "`object-id-ref` VARCHAR(255) CHARACTER SET utf8 ,\n"
118 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
119 private static final String TABLEMAPPING_MEDIATORSERVER_FORMAT =
120 "`id` int(11) NOT NULL AUTO_INCREMENT,\n" + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n"
121 + "`name` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`url` VARCHAR(255) CHARACTER SET utf8 ,\n"
122 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
123 private static final String TABLEMAPPING_NETWORKELEMENT_FORMAT = "`id` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\n"
124 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n"
125 + "`password` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`host` VARCHAR(255) CHARACTER SET utf8 ,\n"
126 + "`port` BIGINT ,\n" + "`status` VARCHAR(100) CHARACTER SET utf8 ,\n"
127 + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`username` VARCHAR(255) CHARACTER SET utf8 ,\n"
128 + "`is-required` BOOLEAN ,\n" + "`core-model-capability` VARCHAR(255) CHARACTER SET utf8 ,\n"
129 + "`device-type` VARCHAR(100) CHARACTER SET utf8 ,\n"
130 + "`device-function` VARCHAR(512) CHARACTER SET utf8 ,\n" + "`node-details` JSON ,\n"
131 + "`tls-key` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`mount-method` VARCHAR(255) CHARACTER SET utf8 ,\n"
132 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
133 private static final String TABLEMAPPING_USERDATA_FORMAT = "`id` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\n"
134 + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n" + "`value` JSON ,\n"
135 + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)";
138 public IstanbulReleaseInformation() {
139 super(Release.ISTANBUL_R1, createDBMap(), createMariaDBMap(Release.ISTANBUL_R1.getDBSuffix()));
142 public static Map<ComponentName, MariaDBTableInfo> createMariaDBMap(String suffix) {
143 Map<ComponentName, MariaDBTableInfo> map = new HashMap<>();
144 map.put(ComponentName.CONNECTIONLOG,
145 new MariaDBTableInfo(Entity.Connectionlog.getName(), TABLEMAPPING_CONNECTIONLOG_FORMAT));
146 map.put(ComponentName.EVENTLOG, new MariaDBTableInfo(Entity.Eventlog.getName(), TABLEMAPPING_EVENTLOG_FORMAT));
147 map.put(ComponentName.FAULTCURRENT,
148 new MariaDBTableInfo(Entity.Faultcurrent.getName(), TABLEMAPPING_FAULTCURRENT_FORMAT));
149 map.put(ComponentName.FAULTLOG, new MariaDBTableInfo(Entity.Faultlog.getName(), TABLEMAPPING_FAULTLOG_FORMAT));
150 map.put(ComponentName.GUICUTTHROUGH,
151 new MariaDBTableInfo(Entity.Guicutthrough.getName(), TABLEMAPPING_GUICUTTHROUGH_FORMAT));
152 map.put(ComponentName.HISTORICAL_PERFORMANCE_15M,
153 new MariaDBTableInfo(Entity.Historicalperformance15min.getName(), TABLEMAPPING_HISTORICALPM15M_FORMAT));
154 map.put(ComponentName.HISTORICAL_PERFORMANCE_24H,
155 new MariaDBTableInfo(Entity.Historicalperformance24h.getName(), TABLEMAPPING_HISTORICALPM24H_FORMAT));
156 map.put(ComponentName.INVENTORY,
157 new MariaDBTableInfo(Entity.Inventoryequipment.getName(), TABLEMAPPING_INVENTORY_FORMAT));
158 map.put(ComponentName.MAINTENANCE,
159 new MariaDBTableInfo(Entity.Maintenancemode.getName(), TABLEMAPPING_MAINTENANCE_FORMAT));
160 map.put(ComponentName.MEDIATOR_SERVER,
161 new MariaDBTableInfo(Entity.MediatorServer.getName(), TABLEMAPPING_MEDIATORSERVER_FORMAT));
162 map.put(ComponentName.REQUIRED_NETWORKELEMENT,
163 new MariaDBTableInfo(Entity.NetworkelementConnection.getName(), TABLEMAPPING_NETWORKELEMENT_FORMAT));
164 map.put(ComponentName.USERDATA, new MariaDBTableInfo(Entity.Userdata.getName(), TABLEMAPPING_USERDATA_FORMAT));
168 public static Map<ComponentName, DatabaseInfo> createDBMap() {
169 Map<ComponentName, DatabaseInfo> map = HonoluluReleaseInformation.createDBMap();
170 map.put(ComponentName.USERDATA, new DatabaseInfo7("userdata", "userdata", "{}"));
171 map.put(ComponentName.REQUIRED_NETWORKELEMENT, new DatabaseInfo7("networkelement-connection",
172 "networkelement-connection",
173 "{\"node-id\": {\"type\": \"keyword\"},\"host\": {\"type\": \"keyword\"},\"port\": "
174 + "{\"type\": \"long\"},\"username\": {\"type\": \"keyword\"},\"password\": {\"type\": \"keyword\"},"
175 + "\"core-model-capability\": {\"type\": \"keyword\"},\"device-type\": {\"type\": \"keyword\"},"
176 + "\"device-function\": {\"type\": \"keyword\"},\"is-required\": {\"type\": \"boolean\"},"
177 + "\"status\": {\"type\": \"keyword\"},\"tls-key\": {\"type\": \"keyword\"},"
178 + "\"mount-method\": {\"type\":\"keyword\"}}",
179 "{\"index\":{\"max_result_window\": 20000,\"number_of_shards\":%d,\"number_of_replicas\":%d},"
180 +"\"analysis\":{\"analyzer\":{\"content\":{\"type\":\"custom\",\"tokenizer\":\"whitespace\"}}}}"
186 public SearchHitConverter getConverter(Release dst, ComponentName comp) {
187 if (dst == Release.ISTANBUL_R1) {
188 return new KeepDataSearchHitConverter(comp);
194 public boolean runPreInitCommands(HtDatabaseClient dbClient) {
195 ClusterSettingsResponse response = null;
197 response = dbClient.setupClusterSettings(new ClusterSettingsRequest(false).maxCompilationsPerMinute(400));
198 } catch (IOException e) {
199 LOG.warn("problem setting up cluster: {}", e);
201 return response == null ? false : response.isAcknowledged();
205 public boolean runPostInitCommands(HtDatabaseClient dbClient) {
210 public boolean runPreInitCommands(SqlDBClient dbClient) {
211 boolean success = dbClient.createTable(
212 String.format(TABLENAME_CONTROLLER_FORMAT, this.getReleas().getDBSuffix()), TABLEMAPPING_CONTROLLER);
217 public boolean runPostInitCommands(SqlDBClient dbClient) {