55fa0d88a0023aad4b8254932f10906600c14352
[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.elalto;
23
24 import java.util.Map;
25
26 import org.json.JSONObject;
27 import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.BaseSearchHitConverter;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentData;
30 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DataContainer;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.data.ConnectionLogStatus;
33
34 /**
35  * 
36  * @author Michael Dürre
37  * 
38  *         Convert data from el alto to frankfurt
39  * 
40  *         src: eventlog dst: connectionlog
41  * 
42  * 
43  *         { "event": { "nodeName": "SDN-Controller-5a150173d678", "counter": "48", "timeStamp":
44  *         "2019-10-07T09:57:08.2Z", "objectId": "Sim2230", "attributeName": "ConnectionStatus", "newValue":
45  *         "connecting", "type": "AttributeValueChangedNotificationXml" } }
46  * 
47  *         =>
48  * 
49  *         { "timestamp": "2020-01-28T12:00:10.2Z", "status": "Connected", "node-id": "sim1" }
50  * 
51  */
52 public class FrankfurtConnectionlogConverter extends BaseSearchHitConverter {
53
54     public FrankfurtConnectionlogConverter() {
55         super(ComponentName.CONNECTIONLOG);
56     }
57
58     /**
59      * @source eventlog searchhit converted to connectionlog entry
60      */
61     @Override
62     public SearchHit convert(SearchHit source) {
63
64         JSONObject data = new JSONObject();
65         JSONObject inner = source.getSource().getJSONObject("event");
66         String eventType = inner.getString("type");
67         String eventSource = inner.getString("nodeName");
68         if (!eventSource.startsWith("SDN-Controller")) {
69             return null;
70         }
71         data.put("node-id", inner.getString("objectId"));
72         data.put("timestamp", inner.getString("timeStamp"));
73         if (eventType.equals("AttributeValueChangedNotificationXml")) {
74             String event = inner.getString("newValue").toLowerCase();
75             if (event.equals("connected")) {
76                 data.put("status", ConnectionLogStatus.Connected.getName());
77             } else if (event.equals("connecting")) {
78                 data.put("status", ConnectionLogStatus.Connecting.getName());
79             } else {
80                 data.put("status", ConnectionLogStatus.UnableToConnect.getName());
81             }
82
83         } else if (eventType.equals("ObjectCreationNotificationXml")) {
84             data.put("status", ConnectionLogStatus.Mounted.getName());
85
86         } else if (eventType.equals("ObjectDeletionNotificationXml")) {
87             data.put("status", ConnectionLogStatus.Unmounted.getName());
88         }
89
90         return this.getSearchHit(source.getIndex(), source.getType(), source.getId(), data);
91     }
92
93     @Override
94     public ComponentData convert(DataContainer container) {
95         Map<ComponentName, ComponentData> src = container.getComponents();
96         if (!src.containsKey(ComponentName.EVENTLOG)) {
97             return null;
98         }
99         ComponentData eventData = src.get(ComponentName.EVENTLOG);
100         ComponentData dstData = new ComponentData(ComponentName.CONNECTIONLOG);
101         for (SearchHit sh : eventData) {
102             dstData.add(this.convert(sh));
103         }
104         return dstData;
105     }
106
107 }