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
46 * "nodeName": "SDN-Controller-5a150173d678",
48 * "timeStamp": "2019-10-07T09:57:08.2Z",
49 * "objectId": "Sim2230",
50 * "attributeName": "ConnectionStatus",
51 * "newValue": "connecting",
52 * "type": "AttributeValueChangedNotificationXml"
59 * "timestamp": "2020-01-28T12:00:10.2Z",
60 * "status": "Connected",
65 public class FrankfurtConnectionlogConverter extends BaseSearchHitConverter {
67 public FrankfurtConnectionlogConverter() {
68 super(ComponentName.CONNECTIONLOG);
72 * @source eventlog searchhit converted to connectionlog entry
75 public SearchHit convert(SearchHit source) {
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")) {
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());
93 data.put("status", ConnectionLogStatus.UnableToConnect.getName());
96 } else if (eventType.equals("ObjectCreationNotificationXml")) {
97 data.put("status", ConnectionLogStatus.Mounted.getName());
99 } else if (eventType.equals("ObjectDeletionNotificationXml")) {
100 data.put("status", ConnectionLogStatus.Unmounted.getName());
103 return this.getSearchHit(source.getIndex(), source.getType(), source.getId(), data);
107 public ComponentData convert(DataContainer container) {
108 Map<ComponentName, ComponentData> src = container.getComponents();
109 if (!src.containsKey(ComponentName.EVENTLOG)) {
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));