diff options
author | 2019-03-26 08:28:21 +0000 | |
---|---|---|
committer | 2019-03-26 08:28:21 +0000 | |
commit | c25ab4f11ff8944142229ba92d514f2ae58ec966 (patch) | |
tree | c4a5b80ff14be0d03a37965c4fb7b3ac0aba2851 /test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap | |
parent | 54a0cae5a7d672285a02c64e1f98baa9b221a6f7 (diff) |
Create VES event with multiple files
Change-Id: Ibd3ac4f887b296167fa24b176ac2d5b8cd4722d6
Issue-ID: DCAEGEN2-1225
Signed-off-by: RehanRaza <muhammad.rehan.raza@est.tech>
Diffstat (limited to 'test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap')
5 files changed, 96 insertions, 186 deletions
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/FileProvider.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/FileProvider.java index 9361e4ceb..9eb733227 100644 --- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/FileProvider.java +++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/FileProvider.java @@ -7,34 +7,34 @@ import java.util.List; public class FileProvider { - public static ArrayList<String> getFiles() { + private FileProvider() {} - List<String> files = QueryFiles(); + public static List<String> getFiles() { - Collections.sort(files); + List<String> files = queryFiles(); - ArrayList<String> fileListSorted = new ArrayList<String>(); + files.sort(Collections.reverseOrder()); + + List<String> fileListSorted = new ArrayList<>(); for (String f : files) { - System.out.println("Next file: " + f); fileListSorted.add(f); } return fileListSorted; } - private static List<String> QueryFiles() { + private static List<String> queryFiles() { File folder = new File("./files/onap/"); File[] listOfFiles = folder.listFiles(); - ArrayList<String> results = new ArrayList<String>(); + List<String> results = new ArrayList<>(); if (listOfFiles.length == 0) { - return null; + return results; // TODO: this should be a thrown exception catched in the Simulator class } for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { - System.out.println("File: " + listOfFiles[i].getName()); results.add(listOfFiles[i].getName()); } } 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 index 3ebf5674a..545a56882 100644 --- 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 @@ -20,9 +20,18 @@ package org.onap.pnfsimulator.message; +import static org.onap.pnfsimulator.message.MessageConstants.COMPRESSION; +import static org.onap.pnfsimulator.message.MessageConstants.COMPRESSION_VALUE; import static org.onap.pnfsimulator.message.MessageConstants.EVENT_ID; +import static org.onap.pnfsimulator.message.MessageConstants.FILE_FORMAT_TYPE; +import static org.onap.pnfsimulator.message.MessageConstants.FILE_FORMAT_TYPE_VALUE; +import static org.onap.pnfsimulator.message.MessageConstants.FILE_FORMAT_VERSION; +import static org.onap.pnfsimulator.message.MessageConstants.FILE_FORMAT_VERSION_VALUE; +import static org.onap.pnfsimulator.message.MessageConstants.HASH_MAP; 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.LOCATION; +import static org.onap.pnfsimulator.message.MessageConstants.NAME; 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; @@ -31,14 +40,20 @@ import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FI 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.REPORTING_ENTITY_NAME; import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE; import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE_NUMBER; +import static org.onap.pnfsimulator.message.MessageConstants.SOURCE_NAME; import static org.onap.pnfsimulator.message.MessageConstants.START_EPOCH_MICROSEC; +import static org.onap.pnfsimulator.message.MessageConstants.TIME_ZONE_OFFSET; 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 java.io.File; +import java.util.List; +import java.util.TimeZone; +import org.json.JSONArray; import org.json.JSONObject; final class JSONObjectFactory { @@ -47,6 +62,7 @@ final class JSONObjectFactory { JSONObject commonEventHeader = new JSONObject(); long timestamp = System.currentTimeMillis(); commonEventHeader.put(EVENT_ID, generateEventId()); + commonEventHeader.put(TIME_ZONE_OFFSET, generateTimeZone(timestamp)); commonEventHeader.put(LAST_EPOCH_MICROSEC, timestamp); commonEventHeader.put(PRIORITY, PRIORITY_NORMAL); commonEventHeader.put(SEQUENCE, SEQUENCE_NUMBER); @@ -54,6 +70,10 @@ final class JSONObjectFactory { commonEventHeader.put(INTERNAL_HEADER_FIELDS, new JSONObject()); commonEventHeader.put(VERSION, VERSION_NUMBER); commonEventHeader.put(VES_EVENT_LISTENER_VERSION, VES_EVENT_LISTENER_VERSION_NUMBER); + String absPath = System.getProperty("user.dir"); + String nodeName = absPath.substring(absPath.lastIndexOf(File.separator)+1); + commonEventHeader.put(SOURCE_NAME, nodeName); + commonEventHeader.put(REPORTING_ENTITY_NAME, nodeName); return commonEventHeader; } @@ -71,11 +91,39 @@ final class JSONObjectFactory { return notificationFields; } + static JSONArray generateArrayOfNamedHashMap(List<String> fileList, String xnfUrl) { + JSONArray arrayOfNamedHashMap = new JSONArray(); + + for (String fileName : fileList) { + JSONObject namedHashMap = new JSONObject(); + namedHashMap.put(NAME, fileName); + + JSONObject hashMap = new JSONObject(); + hashMap.put(FILE_FORMAT_TYPE, FILE_FORMAT_TYPE_VALUE); + hashMap.put(LOCATION, xnfUrl.concat(fileName)); + hashMap.put(FILE_FORMAT_VERSION, FILE_FORMAT_VERSION_VALUE); + hashMap.put(COMPRESSION, COMPRESSION_VALUE); + namedHashMap.put(HASH_MAP, hashMap); + + arrayOfNamedHashMap.put(namedHashMap); + } + + + return arrayOfNamedHashMap; + } + static String generateEventId() { String timeAsString = String.valueOf(System.currentTimeMillis()); - return String.format("registration_%s", - timeAsString.substring(timeAsString.length() - 11, timeAsString.length() - 3)); + return String.format("FileReady_%s", timeAsString); + } + + static String generateTimeZone(long timestamp) { + TimeZone timeZone = TimeZone.getDefault(); + int offsetInMillis = timeZone.getOffset(timestamp); + String offsetHHMM = String.format("%02d:%02d", Math.abs(offsetInMillis / 3600000), + Math.abs((offsetInMillis / 60000) % 60)); + return ("UTC" + (offsetInMillis >= 0 ? "+" : "-") + offsetHHMM); } 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 index 95e8f69f3..6ff6e5dc8 100644 --- 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 @@ -43,6 +43,7 @@ public final class MessageConstants { //parameters static final String DOMAIN = "domain"; static final String EVENT_ID = "eventId"; + static final String TIME_ZONE_OFFSET = "timeZoneOffset"; static final String EVENT_TYPE = "eventType"; static final String LAST_EPOCH_MICROSEC = "lastEpochMicrosec"; static final String PRIORITY = "priority"; @@ -51,6 +52,8 @@ public final class MessageConstants { static final String INTERNAL_HEADER_FIELDS = "internalHeaderFields"; static final String VERSION = "version"; static final String VES_EVENT_LISTENER_VERSION = "vesEventListenerVersion"; + static final String SOURCE_NAME = "sourceName"; + static final String REPORTING_ENTITY_NAME = "reportingEntityName"; //constant values static final int SEQUENCE_NUMBER = 0; static final String VERSION_NUMBER = "4.0.1"; @@ -71,9 +74,20 @@ public final class MessageConstants { // Notifications //parameters static final String NOTIFICATION_FIELDS_VERSION = "notificationFieldsVersion"; + static final String ARRAY_OF_NAMED_HASH_MAP = "arrayOfNamedHashMap"; + static final String NAME = "name"; + static final String HASH_MAP = "hashMap"; + static final String FILE_FORMAT_TYPE = "fileFormatType"; + static final String LOCATION = "location"; + static final String FILE_FORMAT_VERSION = "fileFormatVersion"; + static final String COMPRESSION = "compression"; + //constant values static final String NOTIFICATION_FIELDS_VERSION_VALUE = "2.0"; static final String DOMAIN_NOTIFICATION ="notification"; + static final String FILE_FORMAT_TYPE_VALUE = "org.3GPP.32.435#measCollec"; + static final String FILE_FORMAT_VERSION_VALUE = "V10"; + static final String COMPRESSION_VALUE = "gzip"; 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 index 839d40269..c86362509 100644 --- 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 @@ -17,6 +17,7 @@ package org.onap.pnfsimulator.message; +import static org.onap.pnfsimulator.message.MessageConstants.ARRAY_OF_NAMED_HASH_MAP; 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; @@ -25,7 +26,8 @@ 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.ArrayList; +import java.util.List; import java.util.Map; import java.util.Optional; import org.json.JSONArray; @@ -35,6 +37,13 @@ public class MessageProvider { public JSONObject createMessage(JSONObject commonEventHeaderParams, Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams) { + List<String> emptyList = new ArrayList<>(); + String emptyString = ""; + return createMessage(commonEventHeaderParams, pnfRegistrationParams, notificationParams, emptyList, emptyString); + } + + public JSONObject createMessage(JSONObject commonEventHeaderParams, Optional<JSONObject> pnfRegistrationParams, + Optional<JSONObject> notificationParams, List<String> fileList, String xnfUrl) { if (!pnfRegistrationParams.isPresent() && !notificationParams.isPresent()) { throw new IllegalArgumentException( @@ -59,6 +68,8 @@ public class MessageProvider { JSONObject notificationFields = JSONObjectFactory.generateNotificationFields(); notificationParams.ifPresent(jsonObject -> { copyParametersToFields(jsonObject.toMap(), notificationFields); + JSONArray arrayOfNamedHashMap = JSONObjectFactory.generateArrayOfNamedHashMap(fileList, xnfUrl); + notificationFields.put(ARRAY_OF_NAMED_HASH_MAP, arrayOfNamedHashMap); commonEventHeader.put(DOMAIN, DOMAIN_NOTIFICATION); event.put(NOTIFICATION_FIELDS, notificationFields); }); @@ -74,150 +85,4 @@ public class MessageProvider { 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); - - event.put(COMMON_EVENT_HEADER, commonEventHeader); - JSONObject root = new JSONObject(); - root.put(EVENT, event); - return root; - - } - - public JSONObject createOneVesEvent(String xnfUrl, String fileName) { - - 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", "ftpes://".concat(xnfUrl).concat(fileName)); - hm.put("fileFormatType", "org.3GPP.32.435#measCollec"); - hm.put("fileFormatVersion", "V10"); - hm.put("compression", "gzip"); - - JSONObject aonhElement = new JSONObject(); - aonhElement.put("name", fileName); - aonhElement.put("hashMap", hm); - - JSONArray aonh = new JSONArray(); - aonh.put(aonhElement); - - nof.put("arrayOfNamedHashMap", aonh); - - 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 eventContent = new JSONObject(); - eventContent.put("commonEventHeader", ceh); - eventContent.put("notificationFields", nof); - - - JSONObject event = new JSONObject(); - event.put("event", eventContent); - - System.out.println("VES messages to be sent: "); - System.out.println(event.toString()); - - return event; - - // @formatter:off - /* - { - "event": { - "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" - { <== "aonhElement" - "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 - } } diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java index 917e4eb63..cb58e3c7a 100644 --- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java +++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java @@ -20,13 +20,11 @@ package org.onap.pnfsimulator.simulator; import static java.lang.Integer.parseInt; import static org.onap.pnfsimulator.message.MessageConstants.MESSAGE_INTERVAL; import static org.onap.pnfsimulator.message.MessageConstants.TEST_DURATION; -import static org.onap.pnfsimulator.message.MessageConstants.VES_SERVER_URL; import com.github.fge.jsonschema.core.exceptions.ProcessingException; import java.io.IOException; import java.time.Duration; -import java.util.ArrayList; +import java.util.List; import java.util.Optional; -import org.json.JSONArray; import org.json.JSONObject; import org.onap.pnfsimulator.ConfigurationProvider; import org.onap.pnfsimulator.FileProvider; @@ -54,35 +52,20 @@ public class SimulatorFactory { public Simulator create(JSONObject simulatorParams, JSONObject commonEventHeaderParams, Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams) throws ProcessingException, IOException, ValidationException { + PnfSimConfig configuration = ConfigurationProvider.getConfigInstance(); + String xnfUrl = "sftp://onap:pano@" + configuration.getIpsftp() + "/"; + String vesUrl = configuration.getVesip() + "/eventListener/v7"; + Duration duration = Duration.ofSeconds(parseInt(simulatorParams.getString(TEST_DURATION))); Duration interval = Duration.ofSeconds(parseInt(simulatorParams.getString(MESSAGE_INTERVAL))); - String vesUrl = simulatorParams.getString(VES_SERVER_URL); - JSONObject messageBody = - messageProvider.createMessage(commonEventHeaderParams, pnfRegistrationParams, notificationParams); + List<String> fileList = FileProvider.getFiles(); + JSONObject messageBody = messageProvider + .createMessage(commonEventHeaderParams, pnfRegistrationParams, notificationParams, fileList, xnfUrl); validator.validate(messageBody.toString(), DEFAULT_OUTPUT_SCHEMA_PATH); - JSONArray messageBodyArray = new JSONArray(); - - PnfSimConfig configuration = ConfigurationProvider.getConfigInstance(); - String xnfUrl = configuration.getIpsftp() + "/"; - - ArrayList<String> fileList = FileProvider.getFiles(); - - // for (String f : fileList) { - // System.out.println("f processed from fileList: " + f.toString()); - // JSONObject vesEvent = messageProvider.createOneVes(commonEventHeaderParams, - // pnfRegistrationParams, - // notificationParams, url, f); - // messageBodyArray.put(vesEvent); - // } - - String fileName = fileList.get(1); - System.out.println("f processed from fileList: " + fileName.toString()); - JSONObject vesEvent = messageProvider.createOneVesEvent(xnfUrl, fileName); - - return Simulator.builder().withVesUrl(configuration.getVesip()).withDuration(duration).withInterval(interval) - .withMessageBody(vesEvent).build(); + return Simulator.builder().withVesUrl(vesUrl).withDuration(duration).withInterval(interval) + .withMessageBody(messageBody).build(); } } |