diff options
author | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2021-03-29 09:04:05 +0200 |
---|---|---|
committer | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2021-03-29 09:04:33 +0200 |
commit | 9fb395380431345b7da7a765651185815a9ac91d (patch) | |
tree | e9915a557d158c3f446c5dcd108afba9e307633a /sdnr/wt/devicemanager | |
parent | 38c3dd74dc9c43a6606680cc6df82062cd7cbd81 (diff) |
Map ORAN alarm-notif to VES fault
O-RAN (FrontHaul) deviceManager: o-ran-fm.yang/alarm-notif to VES:fault
Issue-ID: CCSDK-3161
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Change-Id: I3c0854ac3096160119220c341a2d8f2010facd8b
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/devicemanager')
14 files changed, 1299 insertions, 27 deletions
diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/NotificationProxyParser.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/NotificationProxyParser.java new file mode 100644 index 000000000..ea16f20bb --- /dev/null +++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/NotificationProxyParser.java @@ -0,0 +1,49 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * 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.devicemanager.service; + +import java.time.Instant; +import java.util.HashMap; +import org.opendaylight.yangtools.yang.binding.Notification; + +public interface NotificationProxyParser { + + /** + * parses the Notification proxy object created by ODL + * Returns a Map with class members as keys and the member values as values. + * The keys are in xpath notation. + * Ex: key = /notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/serial-number" + * value = "0005B94238A0" + * References: https://stackoverflow.com/questions/19633534/what-is-com-sun-proxy-proxy + */ + public HashMap<String, String> parseNotificationProxy(Notification notification); + + /** + * Gets the time at which the Event occurred if the notification is an instance of EventInstantAware. If not, then returns the current time + * Read notification time via {@link #EventInstantAware } interface. + * + * @param notification + * @return + */ + public Instant getTime(Notification notification); + +} diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorCfgService.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorCfgService.java index c274ff91c..5025b5bba 100644 --- a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorCfgService.java +++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorCfgService.java @@ -21,9 +21,18 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.service; +/* + * Interface that exposes a subset of the VES Collector configuration properties to clients that require them + */ + public interface VESCollectorCfgService { + /* gets the reportingEntityName (REPORTING_ENTITY_NAME) configured in the etc/devicemanager.properties configuration file */ String getReportingEntityName(); + + /* gets the log detail configuration (EVENTLOG_MSG_DETAIL) property value configured in the etc/devicemanager.properties configuration file */ String getEventLogMsgDetail(); + + /* gets the VES Collector enabled property (VES_COLLECTOR_ENABLED) value configured in the etc/devicemanager.properties configuration file */ boolean isVESCollectorEnabled(); } diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorService.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorService.java index 287f0f622..f93b599bf 100644 --- a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorService.java +++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorService.java @@ -21,7 +21,13 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.service; - +import com.fasterxml.jackson.core.JsonProcessingException; +import org.eclipse.jdt.annotation.NonNull; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO; /** * Interface used for publishing VES messages to the VES Collector @@ -31,9 +37,64 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.service; */ public interface VESCollectorService extends DeviceManagerService { + /** + * Gets the VES Collector configuration from etc/devicemanager.properties configuration file + */ VESCollectorCfgService getConfig(); - boolean publishVESMessage(String vesMsg); - public void registerForChanges(VESCollectorConfigChangeListener o); - public void deregister(VESCollectorConfigChangeListener o); + + /** + * publishes a VES message to the VES Collector by sending a REST request + * @param vesMsg + * @return + */ + boolean publishVESMessage(VESMessage vesMsg); + + /** + * clients interested in VES Collector configuration changes can call the registerForChanges method so as to be notified when configuration changes are made + */ + void registerForChanges(VESCollectorConfigChangeListener o); + + /** + * de-registering clients as part of cleanup + * @param o + */ + void deregister(VESCollectorConfigChangeListener o); + + /** + * Get a parser to parse {@link #org.opendaylight.yangtools.yang.binding.Notification } messages + * @return NotificationProxyParser object + */ + @NonNull + NotificationProxyParser getNotificationProxyParser(); + + /** + * Generates VES Event JSON containing commonEventHeader and notificationFields fields + * + * @param commonEventHeader + * @param notifFields + * @return VESMessage - representing the VESEvent JSON + * @throws JsonProcessingException + */ + VESMessage generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESNotificationFieldsPOJO notifFields) throws JsonProcessingException; + + /** + * Generates VES Event JSON containing commonEventHeader and faultFields fields + * + * @param commonEventHeader + * @param faultFields + * @return VESMessage - representing the VES Event JSON + * @throws JsonProcessingException + */ + VESMessage generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESFaultFieldsPOJO faultFields) throws JsonProcessingException; + + /** + * Generates VES Event JSON containing commonEventHeader and pnfRegistration fields + * + * @param commonEventHeader + * @param faultFields + * @return VESMessage - representing the VES Event JSON + * @throws JsonProcessingException + */ + VESMessage generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESPNFRegistrationFieldsPOJO faultFields) throws JsonProcessingException; } diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESEventMapper.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESEventMapper.java new file mode 100644 index 000000000..76c8305a2 --- /dev/null +++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESEventMapper.java @@ -0,0 +1,121 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * 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.devicemanager.service; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.opendaylight.yangtools.yang.binding.Notification; + +/* + * Interface for mapping ODL notification to VES event fields grouped by event type. + * Also includes the commonEventHeader which is applicable for all events. + * Ex: fault event, notification event. + * + * No base implementation exists for this interface. Clients that need to map their data into VES formats must implement this interface. + */ + +public abstract class VESEventMapper<N extends Notification,F extends Notification,T extends Notification> { + + /** + * Creates VESEvent mapping + */ + public abstract String createMapping(NetconfBindingAccessor netconfAccessor, + VESCollectorService vesCollectorService, Notification notification, String notifName, int sequenceNo, + Instant eventTime); + + /** + * Returns VES commonEventHeader fields + */ + public abstract VESCommonEventHeaderPOJO mapCommonEventHeader(N notification); + + /** + * Returns VES faultFields + */ + public abstract VESFaultFieldsPOJO mapFaultFields(F notification); + + /** + * Returns VES Notification Fields + */ + public abstract VESNotificationFieldsPOJO mapNotificationFields(T notification); + + /** + * Returns VES pnfRegistration domain fields + * + * @return + */ + public abstract VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields(); + + /** + * Generates VES Event JSON containing commonEventHeader and notificationFields fields + * + * @param commonEventHeader + * @param notifFields + * @return String - representing the VESEvent JSON + */ + String generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESNotificationFieldsPOJO notifFields) { + Map<String, Object> innerEvent = new HashMap<String, Object>(); + innerEvent.put("commonEventHeader", commonEventHeader); + innerEvent.put("notificationFields", notifFields); + + Map<String, Object> outerEvent = new HashMap<String, Object>(); + outerEvent.put("event", innerEvent); + try { + ObjectMapper objMapper = new ObjectMapper(); + return objMapper.writeValueAsString(outerEvent); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return null; + } + + /** + * Generates VES Event JSON containing commonEventHeader and faultFields fields + * + * @param commonEventHeader + * @param faultFields + * @return String - representing the VES Event JSON + */ + String generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESFaultFieldsPOJO faultFields) { + Map<String, Object> innerEvent = new HashMap<String, Object>(); + innerEvent.put("commonEventHeader", commonEventHeader); + innerEvent.put("faultFields", faultFields); + + Map<String, Object> outerEvent = new HashMap<String, Object>(); + outerEvent.put("event", innerEvent); + try { + ObjectMapper objMapper = new ObjectMapper(); + return objMapper.writeValueAsString(outerEvent); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESCommonEventHeaderPOJO.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESCommonEventHeaderPOJO.java new file mode 100644 index 000000000..db76b84c7 --- /dev/null +++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESCommonEventHeaderPOJO.java @@ -0,0 +1,196 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * 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.devicemanager.types; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonPropertyOrder({"domain", "eventId", "eventName", "eventType", "lastEpochMicrosec", "nfcNamingCode", "nfNamingCode", + "nfVendorName", "priority", "reportingEntityId", "reportingEntityName", "sequence", "sourceId", "sourceName", + "startEpochMicrosec", "timeZoneOffset", "version", "vesEventListenerVersion"}) + +public class VESCommonEventHeaderPOJO { + + private String domain = ""; + private String eventId = ""; + private String eventName = ""; + private String eventType = ""; + private long sequence = 0L; + private String priority = ""; + @JsonIgnore + private String reportingEntityId = ""; + private String reportingEntityName = ""; + private String sourceId = ""; + private String sourceName = ""; + private long startEpochMicrosec = 0L; + private long lastEpochMicrosec = 0L; + private String nfcNamingCode = ""; + private String nfNamingCode = ""; + private String nfVendorName = ""; + private String timeZoneOffset = "+00:00"; + private String version = "4.1"; + private String vesEventListenerVersion = "7.1.1"; + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public String getEventId() { + return eventId; + } + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public String getEventName() { + return eventName; + } + + public void setEventName(String eventName) { + this.eventName = eventName; + } + + public String getEventType() { + return eventType; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public Long getSequence() { + return sequence; + } + + public void setSequence(long sequenceNo) { + this.sequence = sequenceNo; + } + + public String getPriority() { + return priority; + } + + public void setPriority(String priority) { + this.priority = priority; + } + + public String getReportingEntityId() { + return reportingEntityId; + } + + public void setReportingEntityId(String reportingEntityId) { + this.reportingEntityId = reportingEntityId; + } + + public String getReportingEntityName() { + return reportingEntityName; + } + + public void setReportingEntityName(String reportingEntityName) { + this.reportingEntityName = reportingEntityName; + } + + public String getSourceId() { + return sourceId; + } + + public void setSourceId(String sourceId) { + this.sourceId = sourceId; + } + + public String getSourceName() { + return sourceName; + } + + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } + + public long getStartEpochMicrosec() { + return startEpochMicrosec; + } + + public void setStartEpochMicrosec(long startEpochMicrosec) { + this.startEpochMicrosec = startEpochMicrosec; + } + + public long getLastEpochMicrosec() { + return lastEpochMicrosec; + } + + public void setLastEpochMicrosec(long lastEpochMicrosec) { + this.lastEpochMicrosec = lastEpochMicrosec; + } + + public String getNfcNamingCode() { + return nfcNamingCode; + } + + public void setNfcNamingCode(String nfcNamingCode) { + this.nfcNamingCode = nfcNamingCode; + } + + public String getNfNamingCode() { + return nfNamingCode; + } + + public void setNfNamingCode(String nfNamingCode) { + this.nfNamingCode = nfNamingCode; + } + + public String getNfVendorName() { + return nfVendorName; + } + + public void setNfVendorName(String nfVendorName) { + this.nfVendorName = nfVendorName; + } + + public String getTimeZoneOffset() { + return timeZoneOffset; + } + + public void setTimeZoneOffset(String timeZoneOffset) { + this.timeZoneOffset = timeZoneOffset; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getVesEventListenerVersion() { + return vesEventListenerVersion; + } + + public void setVesEventListenerVersion(String vesEventListenerVersion) { + this.vesEventListenerVersion = vesEventListenerVersion; + } +} diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESFaultFieldsPOJO.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESFaultFieldsPOJO.java new file mode 100644 index 000000000..0f40ed3a4 --- /dev/null +++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESFaultFieldsPOJO.java @@ -0,0 +1,111 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * 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.devicemanager.types; + +import java.util.HashMap; + +public class VESFaultFieldsPOJO { + + //fault domain Fields + private String alarmCondition = ""; + private String alarmInterfaceA = ""; + private String eventCategory = ""; + private String eventSeverity = ""; + private String eventSourceType = ""; + private String faultFieldsVersion = "4.0"; + private String specificProblem = ""; + private String vfStatus = ""; + private HashMap<String, Object> alarmAdditionalInformation = new HashMap<String, Object>(); + + public String getAlarmCondition() { + return alarmCondition; + } + + public void setAlarmCondition(String alarmCondition) { + this.alarmCondition = alarmCondition; + } + + public String getAlarmInterfaceA() { + return alarmInterfaceA; + } + + public void setAlarmInterfaceA(String alarmInterfaceA) { + this.alarmInterfaceA = alarmInterfaceA; + } + + public String getEventCategory() { + return eventCategory; + } + + public void setEventCategory(String eventCategory) { + this.eventCategory = eventCategory; + } + + public String getEventSeverity() { + return eventSeverity; + } + + public void setEventSeverity(String eventSeverity) { + this.eventSeverity = eventSeverity; + } + + public String getEventSourceType() { + return eventSourceType; + } + + public void setEventSourceType(String eventSourceType) { + this.eventSourceType = eventSourceType; + } + + public String getFaultFieldsVersion() { + return faultFieldsVersion; + } + + public void setFaultFieldsVersion(String faultFieldsVersion) { + this.faultFieldsVersion = faultFieldsVersion; + } + + public String getSpecificProblem() { + return specificProblem; + } + + public void setSpecificProblem(String specificProblem) { + this.specificProblem = specificProblem; + } + + public String getVfStatus() { + return vfStatus; + } + + public void setVfStatus(String vfStatus) { + this.vfStatus = vfStatus; + } + + public HashMap<String, Object> getAlarmAdditionalInformation() { + return alarmAdditionalInformation; + } + + public void setAlarmAdditionalInformation(HashMap<String, Object> alarmAdditionalInformation) { + this.alarmAdditionalInformation = alarmAdditionalInformation; + } + +} diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESMessage.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESMessage.java new file mode 100644 index 000000000..2c5266f97 --- /dev/null +++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESMessage.java @@ -0,0 +1,35 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * 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.devicemanager.types; + +public class VESMessage { + + private String message; + + public VESMessage(String vesMessage) { + this.message = vesMessage; + } + + public String getMessage() { + return message; + } +} diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESNotificationFieldsPOJO.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESNotificationFieldsPOJO.java new file mode 100644 index 000000000..6beb04751 --- /dev/null +++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESNotificationFieldsPOJO.java @@ -0,0 +1,116 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * 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.devicemanager.types; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.ArrayList; +import java.util.HashMap; + +@JsonPropertyOrder({"arrayOfNamedHashMap", "changeContact", "changeIdentifier", "changeType", "newState", "oldState", + "notificationFieldsVersion"}) + +public class VESNotificationFieldsPOJO { + + private ArrayList<HashMap<String, Object>> arrayOfNamedHashMap = new ArrayList<HashMap<String, Object>>(); + @JsonIgnore + private HashMap<String, Object> namedHashMap = new HashMap<String, Object>(); + @JsonIgnore + private HashMap<String, String> hashMap = new HashMap<String, String>(); + @JsonIgnore + private String changeContact = ""; + private String changeIdentifier = ""; + private String changeType = ""; + @JsonIgnore + private String newState = ""; + @JsonIgnore + private String oldState = ""; + @JsonIgnore + private String stateInterface = ""; + private String notificationFieldsVersion = "2.0"; + + public ArrayList<HashMap<String, Object>> getArrayOfNamedHashMap() { + return arrayOfNamedHashMap; + } + + public void setArrayOfNamedHashMap(ArrayList<HashMap<String, Object>> arrayOfNamedHashMap) { + this.arrayOfNamedHashMap = arrayOfNamedHashMap; + } + + public String getChangeContact() { + return changeContact; + } + + public void setChangeContact(String changeContact) { + this.changeContact = changeContact; + } + + public String getChangeIdentifier() { + return changeIdentifier; + } + + public void setChangeIdentifier(String changeIdentifier) { + this.changeIdentifier = changeIdentifier; + } + + public String getChangeType() { + return changeType; + } + + public void setChangeType(String changeType) { + this.changeType = changeType; + } + + public String getNewState() { + return newState; + } + + public void setNewState(String newState) { + this.newState = newState; + } + + public String getOldState() { + return oldState; + } + + public void setOldState(String oldState) { + this.oldState = oldState; + } + + public String getStateInterface() { + return stateInterface; + } + + public void setStateInterface(String stateInterface) { + this.stateInterface = stateInterface; + } + + public String getNotificationFieldsVersion() { + return notificationFieldsVersion; + } + + public void setNotificationFieldsVersion(String notificationFieldsVersion) { + this.notificationFieldsVersion = notificationFieldsVersion; + } + + +}
\ No newline at end of file diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESPNFRegistrationFieldsPOJO.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESPNFRegistrationFieldsPOJO.java new file mode 100644 index 000000000..e564914da --- /dev/null +++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/types/VESPNFRegistrationFieldsPOJO.java @@ -0,0 +1,148 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * 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.devicemanager.types; + +import java.util.HashMap; +import java.util.Map; + +public class VESPNFRegistrationFieldsPOJO { + + private Map<String, String> additionalFields = new HashMap<String, String>(); + private String lastServiceDate = ""; + private String macAddress = ""; + private String manufactureDate = ""; + private String modelNumber = ""; + private String oamV4IpAddress = ""; + private String oamV6IpAddress = ""; + private String pnfRegistrationFieldsVersion = "2.0"; + private String serialNumber = ""; + private String softwareVersion = ""; + private String unitFamily = ""; + private String unitType = ""; + private String vendorName = ""; + + public Map<String, String> getAdditionalFields() { + return additionalFields; + } + + public void setAdditionalFields(Map<String, String> additionalFields) { + this.additionalFields = additionalFields; + } + + public String getLastServiceDate() { + return lastServiceDate; + } + + public void setLastServiceDate(String lastServiceDate) { + this.lastServiceDate = lastServiceDate; + } + + public String getMacAddress() { + return macAddress; + } + + public void setMacAddress(String macAddress) { + this.macAddress = macAddress; + } + + public String getManufactureDate() { + return manufactureDate; + } + + public void setManufactureDate(String manufactureDate) { + this.manufactureDate = manufactureDate; + } + + public String getModelNumber() { + return modelNumber; + } + + public void setModelNumber(String modelNumber) { + this.modelNumber = modelNumber; + } + + public String getOamV4IpAddress() { + return oamV4IpAddress; + } + + public void setOamV4IpAddress(String oamV4IpAddress) { + this.oamV4IpAddress = oamV4IpAddress; + } + + public String getOamV6IpAddress() { + return oamV6IpAddress; + } + + public void setOamV6IpAddress(String oamV6IpAddress) { + this.oamV6IpAddress = oamV6IpAddress; + } + + public String getPnfRegistrationFieldsVersion() { + return pnfRegistrationFieldsVersion; + } + + public void setPnfRegistrationFieldsVersion(String pnfRegistrationFieldsVersion) { + this.pnfRegistrationFieldsVersion = pnfRegistrationFieldsVersion; + } + + public String getSerialNumber() { + return serialNumber; + } + + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + public String getSoftwareVersion() { + return softwareVersion; + } + + public void setSoftwareVersion(String softwareVersion) { + this.softwareVersion = softwareVersion; + } + + public String getUnitFamily() { + return unitFamily; + } + + public void setUnitFamily(String unitFamily) { + this.unitFamily = unitFamily; + } + + public String getUnitType() { + return unitType; + } + + public void setUnitType(String unitType) { + this.unitType = unitType; + } + + public String getVendorName() { + return vendorName; + } + + public void setVendorName(String vendorName) { + this.vendorName = vendorName; + + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java index fd2929f1a..689336f5e 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java @@ -75,14 +75,14 @@ import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.DevicemanagerNotificationDelayService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorClient; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.MountPointService; import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -125,7 +125,7 @@ public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceMa private ConnectionStatusHousekeepingService housekeepingService; private NetconfNodeStateService netconfNodeStateService; private DataProvider dataProvider; - private VESCollectorClient vesCollectorClient; + private VESCollectorServiceImpl vesCollectorServiceImpl; // Handler private DeviceManagerNetconfConnectHandler deviceManagerNetconfConnectHandler; @@ -209,7 +209,7 @@ public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceMa this.aaiProviderClient = new AaiProviderClient(config, this); - this.vesCollectorClient = new VESCollectorClient(config); + this.vesCollectorServiceImpl = new VESCollectorServiceImpl(config); // EM String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + esConfig.getCluster(); @@ -273,13 +273,13 @@ public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceMa close(archiveCleanService); close(housekeepingService); close(deviceManagerNetconfConnectHandler); - close(vesCollectorClient); + close(vesCollectorServiceImpl); LOG.info("DeviceManagerImpl closing done"); } @Override public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerBindingNetworkElementFactory( - @NonNull L factory) { + @NonNull final L factory) { LOG.info("Factory registration {}", factory.getClass().getName()); factoryList.add(factory); @@ -416,7 +416,7 @@ public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceMa @Override public @NonNull VESCollectorService getVESCollectorService() { - return this.vesCollectorClient; + return this.vesCollectorServiceImpl; } } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/util/NotificationProxyParserImpl.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/util/NotificationProxyParserImpl.java new file mode 100644 index 000000000..802c05d0c --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/util/NotificationProxyParserImpl.java @@ -0,0 +1,343 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * 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.devicemanager.impl.util; + + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.time.Instant; +import java.util.HashMap; +import java.util.List; +import org.eclipse.jdt.annotation.NonNull; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser; +import org.opendaylight.yangtools.concepts.Identifier; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.EventInstantAware; +import org.opendaylight.yangtools.yang.binding.Identifiable; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.opendaylight.yangtools.yang.common.QName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NotificationProxyParserImpl implements NotificationProxyParser { + + + /* + * Converter of TR069 notifications to VES key, value hashmap. + * Notifications are received as cascade if proxy object. + * References: https://stackoverflow.com/questions/19633534/what-is-com-sun-proxy-proxy + * + * Attributes are provided by getters starting with "get", "is", "key". + * Proxy received: "com.sun.proxy.$ProxyNN". NN is a number. + * + * Example result: + * + * Expected output via VES in JSON + * { + * "event": { + * "commonEventHeader": { + * "domain": "notification", + * "eventId": "ABCD", + * "eventName": "Notification_LTE_Enterprise_C-RANSC_Cntrl-ACME", + * "eventType": "TR069_RAN_notification", + * "sequence": 0, + * "priority": "High", + * "reportingEntityId": "0005B942CDB4", + * "reportingEntityName": "ABCD", + * "sourceId": "0005B942CDB4", + * "sourceName": "ABCD", + * "startEpochMicrosec": 1569579510211, + * "lastEpochMicrosec": 1569579510211, + * "nfcNamingCode": "", + * "nfNamingCode": "", + * "nfVendorName": "", + * "timeZoneOffset": "+00:00", + * "version": "4.0.1", + * "vesEventListenerVersion": "7.0.1" + * }, + * "notificationFields": { + * "arrayOfNamedHashMap": [ + * { + * "name": "VALUECHANGE", + * "hashMap": { + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/serial-number": "0005B94238A0", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/software-version": "4.3.00.244", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/hardware-version": "1", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/provisioning-code": "", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/manufacturer": "ACME", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/product-class": "LTE_Enterprise_C-RANSC_Cntrl", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/manufacturer-oui": "0005B9", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[1]/index": "1", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[1]/fap-control/lte/rf-tx-status": "false", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[1]/fap-control/lte/op-state": "true", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[2]/index": "2", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[2]/fap-control/lte/rf-tx-status": "false", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[2]/fap-control/lte/op-state": "true", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[2]/cell-config/lte/ran/rf/phy-cell-id": "201", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/management-server/connection-request-url": "http://10.220.68.2/acscall", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/management-server/parameter-key": "none", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/management-server/connection-request-password": "password", + * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/management-server/connection-request-username": "0005B9-LTE_Enterprise_C-RANSC_Cntrl-0005B94238A0" + * }, + * } + * ], + * "changeContact": "", + * "changeIdentifier": "SessionID", + * "changeType": "ValueChange", + * "newState": "", + * "oldState": "", + * "stateInterface": "", + * "notificationFieldsVersion": "2.0", + * } + * } + * } + * + */ + private static final Logger log = LoggerFactory.getLogger(NotificationProxyParserImpl.class); + private Notification notification; + + @Override + public HashMap<String, String> parseNotificationProxy(Notification notification) + /*throws ORanNotificationMapperException*/ { + + try { + return extractFields(notification); + } catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException + | InvocationTargetException e) { + //throw new ORanNotificationMapperException("Mapping/JSON Creation problem", e); + log.info("Exception in performMapping method {}",e); + return null; + } + + } + + private HashMap<String, String> extractFields(Object o) throws IllegalAccessException, IllegalArgumentException, + InvocationTargetException, NoSuchFieldException, SecurityException { + String start = "/notification/" + getExtendedInterfaceName(Notification.class, o) + getXmlNameSpace(o); + return recurseExtractData(o, start, 0, new HashMap<String, String>()); + } + + private HashMap<String, String> recurseExtractData(Object o, String namePath, int level, + HashMap<String, String> result) + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + log.debug("In recurseExtractData - {} {} {}", namePath, level, log.isTraceEnabled() ? result : result.size()); + if (level > 20) { + log.warn("Level to deep protection ended the recusive loop."); + } else { + if (o != null) { + Class<?> classz = o.getClass(); + //notification/VALUECHANGE$$$eventInstantAware[@xmlns=urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notificationon] 0 {} + //org.opendaylight.yang.gen.v1.urn.org.onap.ccsdk.features.sdnr.northbound.onecell.notification.rev200622.VALUECHANGE$$$eventInstantAware + //if (Proxy.isProxyClass(classz)) { + handleInterface(classz, o, namePath, level, result); + //} + } else { + log.warn("Null not expected here."); + } + } + return result; + } + + private void handleInterface(Class<?> clazz, Object o, String namePath, int level, HashMap<String, String> result) + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + log.debug("In extract Interface {}", clazz); + if (clazz == null) { + log.warn("Loop with null class"); + return; + } + if (level > 20) { + log.warn("Level to deep protection ended the recusive loop."); + } + if (clazz.getName().contentEquals("org.opendaylight.mdsal.binding.dom.codec.impl.AugmentableCodecDataObject")) { + log.trace("Leave AugmentableCodecDataObject"); + return; + } + + Method[] methods = clazz.getDeclaredMethods(); + if (methods != null) { + for (Method method : methods) { + String methodName = method.getName(); + log.trace("Method {}", methodName); + if (methodName.startsWith("get")) { + if (!methodName.equals("getImplementedInterface")) { + handleGetterValue(method, methodName.substring(3), namePath, o, level, result); + } + } else if (methodName.startsWith("is")) { + handleGetterValue(method, methodName.substring(2), namePath, o, level, result); + } else if (methodName.equals("key")) { + handleGetterValue(method, methodName, namePath, o, level, result); + } + } + } + Class<?> sc = clazz.getSuperclass(); //Sodium + log.trace("Superclass is - {}", sc); + if (sc != null && !(sc.getName().contains("java.lang.reflect.Proxy")) && !Proxy.isProxyClass(sc)) { + handleInterface(sc, o, namePath, level + 1, result); + } + } + + private void handleGetterValue(Method method, String name, String namePath, Object o, int level, + HashMap<String, String> result) + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + log.debug("Begin: {}-{}-{}-{}", method.getName(), name, namePath, level); + if (!method.isAccessible()) { + method.setAccessible(true); + } + Object value = method.invoke(o); + namePath += "/" + convertCamelToKebabCase(name); + log.trace("Namepath {}", namePath); + if (value != null) { + Class<?> type = value.getClass(); + log.trace("Class {}", type.getSimpleName()); + if (List.class.isAssignableFrom(type)) { + int idx = 0; + String keyString; + for (Object listObject : (List<?>) value) { + if (listObject != null) { + if (Identifiable.class.isAssignableFrom(listObject.getClass())) { + keyString = getKeyString((Identifiable<?>) listObject); + } else { + keyString = String.valueOf(idx); + } + recurseExtractData(listObject, namePath + "[" + keyString + "]", level + 1, result); + } else { + log.warn("Null value received {} {} {}", namePath, idx, name); + } + idx++; + } + } else if (DataObject.class.isAssignableFrom(type)) { + recurseExtractData(value, namePath, level + 1, result); + } else if (Proxy.isProxyClass(type)) { + recurseExtractData(value, namePath, level + 1, result); + } else if (Identifier.class.isAssignableFrom(type)) { + //don't put the key + } else { + result.put(namePath, value.toString()); + } + } else { + log.trace("Null value"); + } + } + + private String getExtendedInterfaceName(Class<?> assignableClazz, Object o) { + Class<?> interfaces[] = o.getClass().getInterfaces(); + for (Class<?> oneInterface : interfaces) { + log.trace("In getExtendedInterfaceName, oneInterface = {}", oneInterface.getClass().getName()); + if (assignableClazz.isAssignableFrom(oneInterface)) { + return oneInterface.getSimpleName().contains("eventInstantAware")?oneInterface.getSimpleName().substring(0, oneInterface.getSimpleName().indexOf("$")):oneInterface.getSimpleName(); + } + } + log.trace("In getExtendedInterfaceName, o.getClass().getName() = {}", o.getClass().getName()); + return o.getClass().getSimpleName().contains("eventInstantAware")?o.getClass().getSimpleName().substring(0, o.getClass().getSimpleName().indexOf("$")):o.getClass().getSimpleName(); + } + + private String getXmlNameSpace(Object o) + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + Field f = o.getClass().getField("QNAME"); + Object couldQName = f.get(o); + if (couldQName instanceof QName) { + QName qname = (QName) couldQName; + return "[@xmlns=" + qname.getNamespace().toString() + "]"; + } + return ""; + } + + /*private String convertCamelToKebabCase(String camel) { + KebabCaseStrategy kbCase = new KebabCaseStrategy(); + return kbCase.translate(camel); + //return camel.replaceAll("([a-z0-9])([A-Z])", "$1-$2").toLowerCase(); + } */ + + /** + * @param input string in Camel Case + * @return String in Kebab case + * Inspiration from KebabCaseStrategy class of com.fasterxml.jackson.databind with an additional condition to handle numbers as well + * Using QNAME would have been a more fool proof solution, however it can lead to performance problems due to usage of Java reflection + */ + private String convertCamelToKebabCase(String input) + { + if (input == null) return input; // garbage in, garbage out + int length = input.length(); + if (length == 0) { + return input; + } + + StringBuilder result = new StringBuilder(length + (length >> 1)); + + int upperCount = 0; + + for (int i = 0; i < length; ++i) { + char ch = input.charAt(i); + char lc = Character.toLowerCase(ch); + + if (lc == ch) { // lower-case letter means we can get new word + // but need to check for multi-letter upper-case (acronym), where assumption + // is that the last upper-case char is start of a new word + if ((upperCount > 1) ){ + // so insert hyphen before the last character now + result.insert(result.length() - 1, '-'); + } else if ((upperCount == 1) && Character.isDigit(ch) && i != length-1) { + result.append('-'); + } + upperCount = 0; + } else { + // Otherwise starts new word, unless beginning of string + if ((upperCount == 0) && (i > 0)) { + result.append('-'); + } + ++upperCount; + } + result.append(lc); + } + return result.toString(); + } + + /** + * Key format like this: "FapServiceKey{_index=2}" + * + * @return + */ + private String getKeyString(Identifiable<?> indentifiableObject) { + String keyString = (indentifiableObject.key()).toString(); + int start = keyString.indexOf("=") + 1; + int end = keyString.length() - 1; + if (start > 0 && start < end) + return keyString.substring(keyString.indexOf("=") + 1, keyString.length() - 1); + else + throw new IllegalArgumentException("indentifiable object without key"); + } + + public Instant getTime(Notification notification) { + @NonNull + Instant time; + if (notification instanceof EventInstantAware) { // If notification class extends/implements the EventInstantAware + time = ((EventInstantAware) notification).eventInstant(); + log.info("Event time {}", time); + } else { + time = Instant.now(); + log.info("Defaulting to actual time of processing the notification - {}", time); + } + return time; + } +} diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/VESCollectorClient.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/VESCollectorServiceImpl.java index 70ff86009..47ac9c785 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/VESCollectorClient.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/VESCollectorServiceImpl.java @@ -21,6 +21,8 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.ArrayList; import java.util.Base64; @@ -28,31 +30,42 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import org.eclipse.jdt.annotation.NonNull; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener; import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPClient; import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.NotificationProxyParserImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorConfigChangeListener; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO; import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.config.VESCollectorCfgImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class VESCollectorClient implements VESCollectorService, IConfigChangedListener, AutoCloseable { - private static final Logger LOG = LoggerFactory.getLogger(VESCollectorClient.class); +public class VESCollectorServiceImpl implements VESCollectorService, IConfigChangedListener, AutoCloseable { + private static final Logger LOG = LoggerFactory.getLogger(VESCollectorServiceImpl.class); private final VESCollectorCfgImpl vesConfig; private final ConfigurationFileRepresentation cfg; private BaseHTTPClient httpClient; private final Map<String, String> headerMap; private List<VESCollectorConfigChangeListener> registeredObjects; + private final ObjectMapper objMapper; - public VESCollectorClient(ConfigurationFileRepresentation config) { + + public VESCollectorServiceImpl(ConfigurationFileRepresentation config) { registeredObjects = new ArrayList<VESCollectorConfigChangeListener>(); this.vesConfig = new VESCollectorCfgImpl(config); this.cfg = config; this.cfg.registerConfigChangedListener(this); + this.objMapper = new ObjectMapper(); - httpClient = new BaseHTTPClient(getBaseUrl()); + httpClient = new BaseHTTPClient(getBaseUrl(), this.vesConfig.isTrustAllCerts()); this.headerMap = new HashMap<>(); this.headerMap.put("Content-Type", "application/json"); @@ -84,15 +97,13 @@ public class VESCollectorClient implements VESCollectorService, IConfigChangedLi } - - @Override - public boolean publishVESMessage(String message) { - LOG.info("In VESClient - {} ", message); + public boolean publishVESMessage(VESMessage message) { + LOG.info("In VESClient - {} ", message.getMessage()); BaseHTTPResponse response; try { String uri = "eventListener" + "/" + getConfig().getVersion(); - response = httpClient.sendRequest(uri, "POST", message, headerMap); + response = httpClient.sendRequest(uri, "POST", message.getMessage(), headerMap); LOG.debug("finished with responsecode {}", response.code); return response.code == 200; } catch (IOException e) { @@ -109,7 +120,8 @@ public class VESCollectorClient implements VESCollectorService, IConfigChangedLi @Override public void onConfigChanged() { - httpClient.setBaseUrl(getBaseUrl()); + LOG.debug("In onConfigChanged - isTrustAllCerts = {} getBaseUrl = {}", getConfig().isTrustAllCerts(), getBaseUrl()); + httpClient = new BaseHTTPClient(getBaseUrl(), this.vesConfig.isTrustAllCerts()); setAuthorization(getConfig().getUsername(), getConfig().getPassword()); Iterator<VESCollectorConfigChangeListener> it = registeredObjects.iterator(); while (it.hasNext()) { @@ -128,4 +140,68 @@ public class VESCollectorClient implements VESCollectorService, IConfigChangedLi registeredObjects.remove(o); } + @Override + public @NonNull NotificationProxyParser getNotificationProxyParser() { + return new NotificationProxyParserImpl(); + } + + /** + * Generates VES Event JSON containing commonEventHeader and notificationFields fields + * + * @param commonEventHeader + * @param notifFields + * @return VESMessage - representing the VESEvent JSON + * @throws JsonProcessingException + */ + @Override + public VESMessage generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, + VESNotificationFieldsPOJO notifFields) throws JsonProcessingException { + Map<String, Object> innerEvent = new HashMap<String, Object>(); + innerEvent.put("commonEventHeader", commonEventHeader); + innerEvent.put("notificationFields", notifFields); + + Map<String, Object> outerEvent = new HashMap<String, Object>(); + outerEvent.put("event", innerEvent); + LOG.info("in generateVESEvent - {}", objMapper.writeValueAsString(outerEvent)); + return new VESMessage(objMapper.writeValueAsString(outerEvent)); + } + + /** + * Generates VES Event JSON containing commonEventHeader and faultFields fields + * + * @param commonEventHeader + * @param faultFields + * @return VESMessage - representing the VES Event JSON + * @throws JsonProcessingException + */ + @Override + public VESMessage generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESFaultFieldsPOJO faultFields) throws JsonProcessingException { + Map<String, Object> innerEvent = new HashMap<String, Object>(); + innerEvent.put("commonEventHeader", commonEventHeader); + innerEvent.put("faultFields", faultFields); + + Map<String, Object> outerEvent = new HashMap<String, Object>(); + outerEvent.put("event", innerEvent); + return new VESMessage(objMapper.writeValueAsString(outerEvent)); + } + + /** + * Generates VES Event JSON containing commonEventHeader and pnfRegistration fields + * + * @param commonEventHeader + * @param pnfRegistrationFields + * @return VESMessage - representing the VES Event JSON + * @throws JsonProcessingException + */ + @Override + public VESMessage generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESPNFRegistrationFieldsPOJO pnfRegistrationFields) throws JsonProcessingException { + Map<String, Object> innerEvent = new HashMap<String, Object>(); + innerEvent.put("commonEventHeader", commonEventHeader); + innerEvent.put("pnfRegistration", pnfRegistrationFields); + + Map<String, Object> outerEvent = new HashMap<String, Object>(); + outerEvent.put("event", innerEvent); + return new VESMessage(objMapper.writeValueAsString(outerEvent)); + } + } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java index c3bddc9b1..105b915c7 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java @@ -40,6 +40,7 @@ public class VESCollectorCfgImpl implements VESCollectorCfgService, Configuratio private static final String DEFAULT_VALUE_VES_COLLECTOR_PORT = "8080"; private static final String PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED = "VES_COLLECTOR_TLS_ENABLED"; + private static final String PROPERTY_KEY_VES_COLLECTOR_TRUST_ALL_CERTS = "VES_COLLECTOR_TRUST_ALL_CERTS"; private static final String PROPERTY_KEY_VES_COLLECTOR_USERNAME = "VES_COLLECTOR_USERNAME"; private static final String DEFAULT_VALUE_VES_COLLECTOR_USERNAME = "sample1"; @@ -109,10 +110,15 @@ public class VESCollectorCfgImpl implements VESCollectorCfgService, Configuratio return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_VERSION); } + public boolean isTrustAllCerts() { + return configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TRUST_ALL_CERTS); + } + @Override public synchronized void defaults() { configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_ENABLED, DEFAULT_VALUE_VES_COLLECTOR_ENABLED); configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED, Boolean.FALSE); + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TRUST_ALL_CERTS, Boolean.FALSE); configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_USERNAME, DEFAULT_VALUE_VES_COLLECTOR_USERNAME); configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_PASSWORD, diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestVESCollectorClient.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestVESCollectorClient.java index 99e7d7bf9..1ff8efafb 100644 --- a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestVESCollectorClient.java +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestVESCollectorClient.java @@ -29,7 +29,8 @@ import java.nio.charset.StandardCharsets; import org.junit.After; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorClient; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl; public class TestVESCollectorClient { @@ -41,17 +42,17 @@ public class TestVESCollectorClient { + "VES_COLLECTOR_PORT=8080\n" + "VES_COLLECTOR_TLS_ENABLED=true\n" + "VES_COLLECTOR_USERNAME=sample1\n" + "VES_COLLECTOR_PASSWORD=sample1\n" + "VES_COLLECTOR_VERSION=v7\n" + "REPORTING_ENTITY_NAME=ONAP SDN-R\n" + ""; - private static final String message = "Test Message"; + private static final VESMessage message = new VESMessage("Test Message"); private static final String CONFIG_FILE = "test.properties"; @Test public void testNoAuth() throws Exception { ConfigurationFileRepresentation vesCfg; - VESCollectorClient vesClient; + VESCollectorServiceImpl vesClient; Files.asCharSink(new File(CONFIG_FILE), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT_NO_AUTH); vesCfg = new ConfigurationFileRepresentation(CONFIG_FILE); - vesClient = new VESCollectorClient(vesCfg); + vesClient = new VESCollectorServiceImpl(vesCfg); vesClient.publishVESMessage(message); vesClient.close(); @@ -61,12 +62,12 @@ public class TestVESCollectorClient { @Test public void testAuth() throws Exception { ConfigurationFileRepresentation vesCfg; - VESCollectorClient vesClient; + VESCollectorServiceImpl vesClient; Files.asCharSink(new File("test.properties"), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT_AUTH); vesCfg = new ConfigurationFileRepresentation("test.properties"); - vesClient = new VESCollectorClient(vesCfg); + vesClient = new VESCollectorServiceImpl(vesCfg); vesClient.publishVESMessage(message); vesClient.close(); } |