aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/jakarta/JakartaReleaseInformation.java
blob: cf369925c011ca810b0d7c7008a422bbcafec8b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * ============LICENSE_START=======================================================
 * ONAP : ccsdk features
 * ================================================================================
 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
 * All rights reserved.
 * ================================================================================
 * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
 * =================================================================================================
c * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 *
 */
package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.jakarta;

import java.io.IOException;
import java.util.Map;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterSettingsRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ClusterSettingsResponse;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo7;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.KeepDataSearchHitConverter;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.MariaDBTableInfo;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.istanbul.IstanbulReleaseInformation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JakartaReleaseInformation extends ReleaseInformation {

    private static final String TABLENAME_CONTROLLER_FORMAT = IstanbulReleaseInformation.TABLENAME_CONTROLLER_FORMAT;
    private static final String TABLEMAPPING_CONTROLLER = IstanbulReleaseInformation.TABLEMAPPING_CONTROLLER;
    private static final String TIMEZONE_TYPE_FORMAT = IstanbulReleaseInformation.TIMEZONE_TYPE_FORMAT;
    private final Logger LOG = LoggerFactory.getLogger(JakartaReleaseInformation.class);

    private static final String TABLEMAPPING_CMLOG_FORMAT = "`id` int(11) NOT NULL AUTO_INCREMENT,\n"
            + "`controller-id` VARCHAR(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,\n"
            + "`source-type` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_bin ,\n"
            + "`object-id` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin ,\n" + "`timestamp` DATETIME(3) ,\n" + "`timestamp-tz` "
            + String.format(TIMEZONE_TYPE_FORMAT, "timestamp-tz") + " ,\n"
            + "`node-id` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin ,\n" + "`counter` INTEGER ,\n"
            + "`notification-type` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_bin ,\n"
            + "`notification-id` VARCHAR(40) CHARACTER SET utf8 COLLATE utf8_bin ,\n"
            + "`source-indicator` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_bin ,\n"
            + "`path` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin ,\n" + "`operation` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_bin ,\n"
            + "`value` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin ,\n" + "primary key(id),foreign key(`controller-id`) "
            + "references `controller%s`(id) ";

    public JakartaReleaseInformation() {
        super(Release.JAKARTA_R1, createDBMap(), createMariaDBMap());
    }

    private static Map<ComponentName, DatabaseInfo> createDBMap() {
        Map<ComponentName, DatabaseInfo> map = IstanbulReleaseInformation.createDBMap();
        map.put(ComponentName.CMLOG, new DatabaseInfo7("cmlog", "cmlog",
                "{\"node-id\": {\"type\": \"keyword\"},\"counter\": {\"type\": \"long\"},"
                        + "\"notification-id\": {\"type\": \"date\"},\"notification-type\": {\"type\": \"keyword\"},"
                        + "\"object-id\": {\"type\": \"long\"},\"operation\":{\"type\": \"keyword\"},"
                        + "\"path\": {\"type\": \"long\"},\"source-indicator\":{\"type\": \"keyword\"},"
                        + "\"source-type\": {\"type\": \"long\"},\"timestamp\":{\"type\": \"keyword\"},"
                        + "\"value\":{\"type\": \"keyword\"}}"));
        return map;
    }

    private static Map<ComponentName, MariaDBTableInfo> createMariaDBMap() {
        Map<ComponentName, MariaDBTableInfo> map =
                IstanbulReleaseInformation.createMariaDBMap(Release.JAKARTA_R1.getDBSuffix());
        map.put(ComponentName.CMLOG, new MariaDBTableInfo(Entity.Cmlog.getName(), TABLEMAPPING_CMLOG_FORMAT));
        return map;
    }

    @Override
    public SearchHitConverter getConverter(Release dst, ComponentName comp) {
        if (dst == Release.JAKARTA_R1) {
            return new KeepDataSearchHitConverter(comp);
        }
        return null;
    }

    @Override
    public boolean runPreInitCommands(HtDatabaseClient dbClient) {
        ClusterSettingsResponse response = null;
        try {
            response = dbClient.setupClusterSettings(new ClusterSettingsRequest(false).maxCompilationsPerMinute(400));
        } catch (IOException e) {
            LOG.warn("problem setting up cluster: {}", e);
        }
        return response == null ? false : response.isAcknowledged();
    }

    @Override
    public boolean runPostInitCommands(HtDatabaseClient dbClient) {
        return true;
    }

    @Override
    public boolean runPreInitCommands(SqlDBClient dbClient) {
        boolean success = dbClient.createTable(
                String.format(TABLENAME_CONTROLLER_FORMAT, this.getReleas().getDBSuffix()), TABLEMAPPING_CONTROLLER);
        return success;
    }

    @Override
    public boolean runPostInitCommands(SqlDBClient dbClient) {
        return true;
    }

}