d683731997301897c0c0f6940502ede2eb7f8ea8
[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 
41  * dst: connectionlog
42  * 
43  * 
44  * { 
45  *     "event": { 
46  *         "nodeName": "SDN-Controller-5a150173d678", 
47  *         "counter": "48", 
48  *         "timeStamp": "2019-10-07T09:57:08.2Z", 
49  *         "objectId": "Sim2230",
50  *         "attributeName": "ConnectionStatus", 
51  *         "newValue": "connecting",
52  *         "type": "AttributeValueChangedNotificationXml" 
53  *     } 
54  * }
55  * 
56  * => 
57  * 
58  * { 
59  *     "timestamp": "2020-01-28T12:00:10.2Z", 
60  *     "status": "Connected",
61  *     "node-id": "sim1" 
62  * }
63  * 
64  */
65 public class FrankfurtConnectionlogConverter extends BaseSearchHitConverter {
66
67         public FrankfurtConnectionlogConverter() {
68                 super(ComponentName.CONNECTIONLOG);
69         }
70
71         /**
72          * @source eventlog searchhit converted to connectionlog entry
73          */
74         @Override
75         public SearchHit convert(SearchHit source) {
76
77                 JSONObject data = new JSONObject();
78                 JSONObject inner = source.getSource().getJSONObject("event");
79                 String eventType = inner.getString("type");
80                 String eventSource = inner.getString("nodeName");
81                 if (!eventSource.startsWith("SDN-Controller")) {
82                         return null;
83                 }
84                 data.put("node-id", inner.getString("objectId"));
85                 data.put("timestamp", inner.getString("timeStamp"));
86                 if (eventType.equals("AttributeValueChangedNotificationXml")) {
87                         String event = inner.getString("newValue").toLowerCase();
88                         if (event.equals("connected")) {
89                                 data.put("status", ConnectionLogStatus.Connected.getName());
90                         } else if (event.equals("connecting")) {
91                                 data.put("status", ConnectionLogStatus.Connecting.getName());
92                         } else {
93                                 data.put("status", ConnectionLogStatus.UnableToConnect.getName());
94                         }
95
96                 } else if (eventType.equals("ObjectCreationNotificationXml")) {
97                         data.put("status", ConnectionLogStatus.Mounted.getName());
98
99                 } else if (eventType.equals("ObjectDeletionNotificationXml")) {
100                         data.put("status", ConnectionLogStatus.Unmounted.getName());
101                 }
102
103                 return this.getSearchHit(source.getIndex(), source.getType(), source.getId(), data);
104         }
105
106         @Override
107         public ComponentData convert(DataContainer container) {
108                 Map<ComponentName, ComponentData> src = container.getComponents();
109                 if (!src.containsKey(ComponentName.EVENTLOG)) {
110                         return null;
111                 }
112                 ComponentData eventData = src.get(ComponentName.EVENTLOG);
113                 ComponentData dstData = new ComponentData(ComponentName.CONNECTIONLOG);
114                 for (SearchHit sh : eventData) {
115                         dstData.add(this.convert(sh));
116                 }
117                 return dstData;
118         }
119
120 }