diff options
author | TamasBakai <tamas.bakai@est.tech> | 2019-03-19 09:56:28 +0000 |
---|---|---|
committer | TamasBakai <tamas.bakai@est.tech> | 2019-03-19 09:56:28 +0000 |
commit | 114c21c9ff09fd80851e8419b575ea75f5e0a206 (patch) | |
tree | 7a573cda93d7acff46a129fb0e6e24863e274d67 /test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message | |
parent | db4bd69a91545c22580f3c9c57237df82cf1b80e (diff) |
ROP file processing in mass-pnf-simulator
Change-Id: I66203ff66e9d91865f8eee06bef01e55bcd6c39c
Issue-ID: DCAEGEN2-1225
Signed-off-by: TamasBakai <tamas.bakai@est.tech>
Diffstat (limited to 'test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message')
3 files changed, 403 insertions, 0 deletions
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java new file mode 100644 index 000000000..3ebf5674a --- /dev/null +++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java @@ -0,0 +1,85 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA 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.pnfsimulator.message; + +import static org.onap.pnfsimulator.message.MessageConstants.EVENT_ID; +import static org.onap.pnfsimulator.message.MessageConstants.INTERNAL_HEADER_FIELDS; +import static org.onap.pnfsimulator.message.MessageConstants.LAST_EPOCH_MICROSEC; +import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS_VERSION; +import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS_VERSION_VALUE; +import static org.onap.pnfsimulator.message.MessageConstants.PNF_LAST_SERVICE_DATE; +import static org.onap.pnfsimulator.message.MessageConstants.PNF_MANUFACTURE_DATE; +import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS_VERSION; +import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS_VERSION_VALUE; +import static org.onap.pnfsimulator.message.MessageConstants.PRIORITY; +import static org.onap.pnfsimulator.message.MessageConstants.PRIORITY_NORMAL; +import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE; +import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE_NUMBER; +import static org.onap.pnfsimulator.message.MessageConstants.START_EPOCH_MICROSEC; +import static org.onap.pnfsimulator.message.MessageConstants.VERSION; +import static org.onap.pnfsimulator.message.MessageConstants.VERSION_NUMBER; +import static org.onap.pnfsimulator.message.MessageConstants.VES_EVENT_LISTENER_VERSION; +import static org.onap.pnfsimulator.message.MessageConstants.VES_EVENT_LISTENER_VERSION_NUMBER; + +import org.json.JSONObject; + +final class JSONObjectFactory { + + static JSONObject generateConstantCommonEventHeader() { + JSONObject commonEventHeader = new JSONObject(); + long timestamp = System.currentTimeMillis(); + commonEventHeader.put(EVENT_ID, generateEventId()); + commonEventHeader.put(LAST_EPOCH_MICROSEC, timestamp); + commonEventHeader.put(PRIORITY, PRIORITY_NORMAL); + commonEventHeader.put(SEQUENCE, SEQUENCE_NUMBER); + commonEventHeader.put(START_EPOCH_MICROSEC, timestamp); + commonEventHeader.put(INTERNAL_HEADER_FIELDS, new JSONObject()); + commonEventHeader.put(VERSION, VERSION_NUMBER); + commonEventHeader.put(VES_EVENT_LISTENER_VERSION, VES_EVENT_LISTENER_VERSION_NUMBER); + return commonEventHeader; + } + + static JSONObject generatePnfRegistrationFields() { + JSONObject pnfRegistrationFields = new JSONObject(); + pnfRegistrationFields.put(PNF_REGISTRATION_FIELDS_VERSION, PNF_REGISTRATION_FIELDS_VERSION_VALUE); + pnfRegistrationFields.put(PNF_LAST_SERVICE_DATE, String.valueOf(System.currentTimeMillis())); + pnfRegistrationFields.put(PNF_MANUFACTURE_DATE, String.valueOf(System.currentTimeMillis())); + return pnfRegistrationFields; + } + + static JSONObject generateNotificationFields() { + JSONObject notificationFields = new JSONObject(); + notificationFields.put(NOTIFICATION_FIELDS_VERSION, NOTIFICATION_FIELDS_VERSION_VALUE); + return notificationFields; + } + + + static String generateEventId() { + String timeAsString = String.valueOf(System.currentTimeMillis()); + return String.format("registration_%s", + timeAsString.substring(timeAsString.length() - 11, timeAsString.length() - 3)); + } + + private JSONObjectFactory() { + + } + +} diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java new file mode 100644 index 000000000..95e8f69f3 --- /dev/null +++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA 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.pnfsimulator.message; + +public final class MessageConstants { + + public static final String SIMULATOR_PARAMS = "simulatorParams"; + public static final String COMMON_EVENT_HEADER_PARAMS = "commonEventHeaderParams"; + public static final String PNF_REGISTRATION_PARAMS = "pnfRegistrationParams"; + public static final String NOTIFICATION_PARAMS = "notificationParams"; + + static final String COMMON_EVENT_HEADER = "commonEventHeader"; + static final String PNF_REGISTRATION_FIELDS = "pnfRegistrationFields"; + static final String NOTIFICATION_FIELDS = "notificationFields"; + static final String EVENT = "event"; + + //============================================================================================= + //Simulation parameters + public static final String VES_SERVER_URL = "vesServerUrl"; + public static final String TEST_DURATION = "testDuration"; + public static final String MESSAGE_INTERVAL = "messageInterval"; + + //============================================================================================= + //commonEventHeader + //parameters + static final String DOMAIN = "domain"; + static final String EVENT_ID = "eventId"; + static final String EVENT_TYPE = "eventType"; + static final String LAST_EPOCH_MICROSEC = "lastEpochMicrosec"; + static final String PRIORITY = "priority"; + static final String SEQUENCE = "sequence"; + static final String START_EPOCH_MICROSEC = "startEpochMicrosec"; + static final String INTERNAL_HEADER_FIELDS = "internalHeaderFields"; + static final String VERSION = "version"; + static final String VES_EVENT_LISTENER_VERSION = "vesEventListenerVersion"; + //constant values + static final int SEQUENCE_NUMBER = 0; + static final String VERSION_NUMBER = "4.0.1"; + static final String VES_EVENT_LISTENER_VERSION_NUMBER = "7.0.1"; + static final String PRIORITY_NORMAL = "Normal"; + + //============================================================================================= + //PNF registration + //parameters + static final String PNF_REGISTRATION_FIELDS_VERSION = "pnfRegistrationFieldsVersion"; + static final String PNF_LAST_SERVICE_DATE = "lastServiceDate"; + static final String PNF_MANUFACTURE_DATE = "manufactureDate"; + //constant values + static final String PNF_REGISTRATION_FIELDS_VERSION_VALUE = "2.0"; + static final String DOMAIN_PNF_REGISTRATION ="pnfRegistration"; + + //============================================================================================= + // Notifications + //parameters + static final String NOTIFICATION_FIELDS_VERSION = "notificationFieldsVersion"; + //constant values + static final String NOTIFICATION_FIELDS_VERSION_VALUE = "2.0"; + static final String DOMAIN_NOTIFICATION ="notification"; + + private MessageConstants() { + } + +} diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java new file mode 100644 index 000000000..d59e82968 --- /dev/null +++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java @@ -0,0 +1,237 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ Copyright (C) + * 2018 NOKIA 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.pnfsimulator.message; + +import static org.onap.pnfsimulator.message.MessageConstants.COMMON_EVENT_HEADER; +import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN; +import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN_NOTIFICATION; +import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN_PNF_REGISTRATION; +import static org.onap.pnfsimulator.message.MessageConstants.EVENT; +import static org.onap.pnfsimulator.message.MessageConstants.EVENT_TYPE; +import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS; +import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import org.json.JSONArray; +import org.json.JSONObject; + +public class MessageProvider { + + public JSONObject createMessage(JSONObject commonEventHeaderParams, Optional<JSONObject> pnfRegistrationParams, + Optional<JSONObject> notificationParams) { + + if (!pnfRegistrationParams.isPresent() && !notificationParams.isPresent()) { + throw new IllegalArgumentException( + "Both PNF registration and notification parameters objects are not present"); + } + JSONObject event = new JSONObject(); + + JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader(); + Map<String, Object> commonEventHeaderFields = commonEventHeaderParams.toMap(); + commonEventHeaderFields.forEach((key, value) -> { + commonEventHeader.put(key, value); + }); + + JSONObject pnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields(); + pnfRegistrationParams.ifPresent(jsonObject -> { + copyParametersToFields(jsonObject.toMap(), pnfRegistrationFields); + commonEventHeader.put(DOMAIN, DOMAIN_PNF_REGISTRATION); + commonEventHeader.put(EVENT_TYPE, DOMAIN_PNF_REGISTRATION); + event.put(PNF_REGISTRATION_FIELDS, pnfRegistrationFields); + }); + + JSONObject notificationFields = JSONObjectFactory.generateNotificationFields(); + notificationParams.ifPresent(jsonObject -> { + copyParametersToFields(jsonObject.toMap(), notificationFields); + commonEventHeader.put(DOMAIN, DOMAIN_NOTIFICATION); + event.put(NOTIFICATION_FIELDS, notificationFields); + }); + + event.put(COMMON_EVENT_HEADER, commonEventHeader); + JSONObject root = new JSONObject(); + root.put(EVENT, event); + return root; + } + + private void copyParametersToFields(Map<String, Object> paramersMap, JSONObject fieldsJsonObject) { + paramersMap.forEach((key, value) -> { + fieldsJsonObject.put(key, value); + }); + } + + public JSONObject createOneVes(JSONObject commonEventHeaderParams, Optional<JSONObject> pnfRegistrationParams, + Optional<JSONObject> notificationParams, String url, String fileName) { + + + if (!pnfRegistrationParams.isPresent() && !notificationParams.isPresent()) { + throw new IllegalArgumentException( + "Both PNF registration and notification parameters objects are not present"); + } + JSONObject event = new JSONObject(); + + JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader(); + Map<String, Object> commonEventHeaderFields = commonEventHeaderParams.toMap(); + commonEventHeaderFields.forEach((key, value) -> { + commonEventHeader.put(key, value); + }); + + JSONObject pnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields(); + pnfRegistrationParams.ifPresent(jsonObject -> { + copyParametersToFields(jsonObject.toMap(), pnfRegistrationFields); + commonEventHeader.put(DOMAIN, DOMAIN_PNF_REGISTRATION); + commonEventHeader.put(EVENT_TYPE, DOMAIN_PNF_REGISTRATION); + event.put(PNF_REGISTRATION_FIELDS, pnfRegistrationFields); + }); + + JSONObject notificationFields = JSONObjectFactory.generateNotificationFields(); + + Map hashMap = new HashMap(); + hashMap.put("location", "LOCATION_DUMMY"); + hashMap.put("fileFormatType", "org.3GPP.32.435#measCollec"); + hashMap.put("fileFormatVersion", "V10"); + hashMap.put("compression", "gzip"); + + + JSONObject jsonHashMap = new JSONObject(); + jsonHashMap.put("hashmap", jsonHashMap); + + JSONArray jsonArrayOfNamedHashMap = new JSONArray(); + jsonArrayOfNamedHashMap.put(jsonHashMap); + + + + // // notification.put("name", "NAME_DUMMY"); + // JSONObject notification = new JSONObject(); + // + // notificationParams.ifPresent(jsonObject -> { + // copyParametersToFields(notification, notificationFields); + // commonEventHeader.put(DOMAIN, DOMAIN_NOTIFICATION); + // event.put(NOTIFICATION_FIELDS, notificationFields); + // }); + + + // notificationParams.ifPresent(jsonObject -> { + // copyParametersToFields(jsonObject.toMap(), notificationFields); + // commonEventHeader.put(DOMAIN, DOMAIN_NOTIFICATION); + // event.put(NOTIFICATION_FIELDS, notificationFields); + // }); + + event.put(COMMON_EVENT_HEADER, commonEventHeader); + JSONObject root = new JSONObject(); + root.put(EVENT, event); + return root; + + } + + public JSONObject createOneVesEvent(String xnfUrl, String fileName) { + + String notificationFields; + JSONObject nof = new JSONObject(); + + nof.put("notificationFieldsVersion", "2.0"); + + nof.put("changeType", "FileReady"); + nof.put("changeIdentifier", "PM_MEAS_FILES"); + + JSONObject hm = new JSONObject(); + hm.put("location", xnfUrl.concat(fileName)); + hm.put("fileFormatType", "org.3GPP.32.435#measCollec"); + hm.put("fileFormatVersion", "V10"); + hm.put("compression", "gzip"); + + JSONObject aonh = new JSONObject(); + aonh.put("name", fileName); + + aonh.put("hashMap", hm); + + nof.put("arrayOfNamedHashMap", aonh); + + String nofString = nof.toString(); + + JSONObject ceh = new JSONObject(); // commonEventHandler + ceh.put("startEpochMicrosec", "1551865758690"); + ceh.put("sourceId", "val13"); + ceh.put("eventId", "registration_51865758"); + ceh.put("nfcNamingCode", "oam"); + ceh.put("priority", "Normal"); + ceh.put("version", "4.0.1"); + ceh.put("reportingEntityName", "NOK6061ZW3"); + ceh.put("sequence", "0"); + ceh.put("domain", "notification"); + ceh.put("lastEpochMicrosec", "1551865758690"); + ceh.put("eventName", "pnfRegistration_Nokia_5gDu"); + ceh.put("vesEventListenerVersion", "7.0.1"); + ceh.put("sourceName", "NOK6061ZW3"); + ceh.put("nfNamingCode", "gNB"); + + JSONObject ihf = new JSONObject(); // internalHeaderFields + ceh.put("internalHeaderFields", ihf); + + JSONObject event = new JSONObject(); + event.put("commonEventHeader", ceh); + event.put("notificationFields", nof); + + System.out.println("event: "); + System.out.println(event.toString()); + + return event; + + // @formatter:off + /* + { + "commonEventHeader": { <== "ceh" + "startEpochMicrosec": "1551865758690", + "sourceId": "val13", + "eventId": "registration_51865758", + "nfcNamingCode": "oam", + "internalHeaderFields": {}, <== "ihf" + "priority": "Normal", + "version": "4.0.1", + "reportingEntityName": "NOK6061ZW3", + "sequence": "0", + "domain": "notification", + "lastEpochMicrosec": "1551865758690", + "eventName": "pnfRegistration_Nokia_5gDu", + "vesEventListenerVersion": "7.0.1", + "sourceName": "NOK6061ZW3", + "nfNamingCode": "gNB" + }, + "notificationFields": { <== "nof" + "": "", + "notificationFieldsVersion": "2.0", + "changeType": "FileReady", + "changeIdentifier": "PM_MEAS_FILES", + "arrayOfNamedHashMap": { <== "aonh" + "name": "A20161224.1030-1045.bin.gz", + "hashMap": { <== "hm" + "location": "ftpes://192.169.0.1:22/ftp/rop/A20161224.1030-1045.bin.gz", + "fileFormatType": "org.3GPP.32.435#measCollec", + "fileFormatVersion": "V10", + "compression": "gzip" + } + } + } + } + + */ + // @formatter:on + + } + +} |