03033edadc2b0ddaaa6f951cd74cdd5e73cf9319
[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  * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
9  * =================================================================================================
10 c * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *     http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  *
23  */
24 package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.jakarta;
25
26 import java.io.IOException;
27 import java.util.Map;
28 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
29 import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterSettingsRequest;
30 import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ClusterSettingsResponse;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo7;
36 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.KeepDataSearchHitConverter;
37 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.MariaDBTableInfo;
38 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release;
39 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter;
40 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.istanbul.IstanbulReleaseInformation;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 public class JakartaReleaseInformation extends ReleaseInformation {
46
47     private static final String TABLENAME_CONTROLLER_FORMAT = IstanbulReleaseInformation.TABLENAME_CONTROLLER_FORMAT;
48     private static final String TABLEMAPPING_CONTROLLER = IstanbulReleaseInformation.TABLEMAPPING_CONTROLLER;
49     private static final String TIMEZONE_TYPE_FORMAT = IstanbulReleaseInformation.TIMEZONE_TYPE_FORMAT;
50     private final Logger LOG = LoggerFactory.getLogger(JakartaReleaseInformation.class);
51
52     private static final String TABLEMAPPING_CMLOG_FORMAT =
53             "`id` int(11) NOT NULL AUTO_INCREMENT,\n" + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n"
54                     + "`source-type` VARCHAR(100) CHARACTER SET utf8 ,\n"
55                     + "`object-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`timestamp` DATETIME(3) ,\n"
56                     + "`timestamp-tz` " + String.format(TIMEZONE_TYPE_FORMAT, "timestamp-tz")
57                     + " ,\n" + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`counter` INTEGER ,\n"
58                     + "`notification-type` VARCHAR(100) CHARACTER SET utf8 ,\n"
59                     + "`notification-id` VARCHAR(40) CHARACTER SET utf8 ,\n"
60                     + "`source-indicator` VARCHAR(100) CHARACTER SET utf8 ,\n"
61                     + "`path` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`operation` VARCHAR(100) CHARACTER SET utf8 ,\n"
62                     + "`value` VARCHAR(255) CHARACTER SET utf8 ,\n" + "primary key(id)";
63
64     public JakartaReleaseInformation() {
65         super(Release.JAKARTA_R1, createDBMap(), createMariaDBMap());
66     }
67
68     private static Map<ComponentName, DatabaseInfo> createDBMap() {
69         Map<ComponentName, DatabaseInfo> map = IstanbulReleaseInformation.createDBMap();
70         map.put(ComponentName.CMLOG, new DatabaseInfo7("cmlog", "cmlog",
71                 "{\"node-id\": {\"type\": \"keyword\"},\"counter\": {\"type\": \"long\"},"
72                         + "\"notification-id\": {\"type\": \"date\"},\"notification-type\": {\"type\": \"keyword\"},"
73                         + "\"object-id\": {\"type\": \"long\"},\"operation\":{\"type\": \"keyword\"},"
74                         + "\"path\": {\"type\": \"long\"},\"source-indicator\":{\"type\": \"keyword\"},"
75                         + "\"source-type\": {\"type\": \"long\"},\"timestamp\":{\"type\": \"keyword\"},"
76                         + "\"value\":{\"type\": \"keyword\"}}"));
77         return map;
78     }
79
80     private static Map<ComponentName, MariaDBTableInfo> createMariaDBMap() {
81         Map<ComponentName, MariaDBTableInfo> map =
82                 IstanbulReleaseInformation.createMariaDBMap(Release.JAKARTA_R1.getDBSuffix());
83         map.put(ComponentName.CMLOG, new MariaDBTableInfo(Entity.Cmlog.getName(), TABLEMAPPING_CMLOG_FORMAT));
84         return map;
85     }
86
87     @Override
88     public SearchHitConverter getConverter(Release dst, ComponentName comp) {
89         if (dst == Release.JAKARTA_R1) {
90             return new KeepDataSearchHitConverter(comp);
91         }
92         return null;
93     }
94
95     @Override
96     public boolean runPreInitCommands(HtDatabaseClient dbClient) {
97         ClusterSettingsResponse response = null;
98         try {
99             response = dbClient.setupClusterSettings(new ClusterSettingsRequest(false).maxCompilationsPerMinute(400));
100         } catch (IOException e) {
101             LOG.warn("problem setting up cluster: {}", e);
102         }
103         return response == null ? false : response.isAcknowledged();
104     }
105
106     @Override
107     public boolean runPostInitCommands(HtDatabaseClient dbClient) {
108         return true;
109     }
110
111     @Override
112     public boolean runPreInitCommands(SqlDBClient dbClient) {
113         boolean success = dbClient.createTable(
114                 String.format(TABLENAME_CONTROLLER_FORMAT, this.getReleas().getDBSuffix()), TABLEMAPPING_CONTROLLER);
115         return success;
116     }
117
118     @Override
119     public boolean runPostInitCommands(SqlDBClient dbClient) {
120         return true;
121     }
122
123 }