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.elalto;
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;
36 * @author Michael Dürre
38 * Convert data from el alto to frankfurt
40 * src: eventlog dst: connectionlog
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" } }
49 * { "timestamp": "2020-01-28T12:00:10.2Z", "status": "Connected", "node-id": "sim1" }
52 public class FrankfurtConnectionlogConverter extends BaseSearchHitConverter {
54 public FrankfurtConnectionlogConverter() {
55 super(ComponentName.CONNECTIONLOG);
59 * @source eventlog searchhit converted to connectionlog entry
62 public SearchHit convert(SearchHit source) {
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")) {
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());
80 data.put("status", ConnectionLogStatus.UnableToConnect.getName());
83 } else if (eventType.equals("ObjectCreationNotificationXml")) {
84 data.put("status", ConnectionLogStatus.Mounted.getName());
86 } else if (eventType.equals("ObjectDeletionNotificationXml")) {
87 data.put("status", ConnectionLogStatus.Unmounted.getName());
90 return this.getSearchHit(source.getIndex(), source.getType(), source.getId(), data);
94 public ComponentData convert(DataContainer container) {
95 Map<ComponentName, ComponentData> src = container.getComponents();
96 if (!src.containsKey(ComponentName.EVENTLOG)) {
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));