diff options
author | 2019-03-29 10:30:33 +0000 | |
---|---|---|
committer | 2019-03-29 10:30:33 +0000 | |
commit | a2f942369425233e9029bdce452cd3a363e617cb (patch) | |
tree | 4fac3cc5f6c3a866c6ac561997dd6d5496798108 /test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org | |
parent | b42c19352ae5659679ad8631bdcf5cd0f8291c52 (diff) |
Update VES event with latest file in each ROP
Change-Id: I64e8ac7ba99c28d299a711741dcc1c6f8bc9e47e
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')
2 files changed, 61 insertions, 38 deletions
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java index 9b4725fd1..5c6405742 100644 --- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java +++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java @@ -17,12 +17,20 @@ package org.onap.pnfsimulator.simulator; +import com.github.fge.jsonschema.core.exceptions.ProcessingException; +import java.io.IOException; import java.time.Duration; import java.time.Instant; +import java.util.List; import java.util.Map; +import java.util.Optional; import org.json.JSONObject; +import org.onap.pnfsimulator.FileProvider; +import org.onap.pnfsimulator.message.MessageProvider; import org.onap.pnfsimulator.simulator.client.HttpClientAdapter; import org.onap.pnfsimulator.simulator.client.HttpClientAdapterImpl; +import org.onap.pnfsimulator.simulator.validation.JSONValidator; +import org.onap.pnfsimulator.simulator.validation.ValidationException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; @@ -41,6 +49,11 @@ public class Simulator extends Thread { private Duration duration; private Duration interval; private Instant endTime; + private JSONObject commonEventHeaderParams; + private Optional<JSONObject> pnfRegistrationParams; + private Optional<JSONObject> notificationParams; + private String xnfUrl; + private static final String DEFAULT_OUTPUT_SCHEMA_PATH = "json_schema/output_validator_ves_schema_30.0.1.json"; private Simulator() {} @@ -55,11 +68,19 @@ public class Simulator extends Thread { endTime = Instant.now().plus(duration); while (isEndless || runningTimeNotExceeded()) { try { + List<String> fileList = FileProvider.getFiles(); + MessageProvider messageProvider = new MessageProvider(); + JSONValidator validator = new JSONValidator(); + + messageBody = messageProvider.createMessage(this.commonEventHeaderParams, this.pnfRegistrationParams, + this.notificationParams, fileList, this.xnfUrl); + validator.validate(messageBody.toString(), DEFAULT_OUTPUT_SCHEMA_PATH); + LOGGER.info("Message to be sent:\n" + getMessage()); httpClient.send(messageBody.toString(), vesUrl); Thread.sleep(interval.toMillis()); - } catch (InterruptedException e) { - LOGGER.info("Simulation interrupted"); + } catch (InterruptedException | ValidationException | ProcessingException | IOException e) { + LOGGER.info("Simulation stopped due to an exception"); return; } } @@ -96,16 +117,21 @@ public class Simulator extends Thread { private String vesUrl; private HttpClientAdapter httpClient; - private JSONObject messageBody; + //private JSONObject messageBody; private Duration duration; private Duration interval; + private Optional<JSONObject> notificationParams; + private Optional<JSONObject> pnfRegistrationParams; + private JSONObject commonEventHeaderParams; + private String xnfUrl; private Builder() { this.vesUrl = ""; this.httpClient = new HttpClientAdapterImpl(); - this.messageBody = new JSONObject(); + //this.messageBody = new JSONObject(); this.duration = Duration.ZERO; this.interval = Duration.ZERO; + this.commonEventHeaderParams = new JSONObject(); } public Builder withVesUrl(String vesUrl) { @@ -118,10 +144,10 @@ public class Simulator extends Thread { return this; } - public Builder withMessageBody(JSONObject messageBody) { + /*public Builder withMessageBody(JSONObject messageBody) { this.messageBody = messageBody; return this; - } + }*/ public Builder withDuration(Duration duration) { this.duration = duration; @@ -134,13 +160,37 @@ public class Simulator extends Thread { return this; } + public Builder withCommonEventHeaderParams(JSONObject commonEventHeaderParams) { + this.commonEventHeaderParams = commonEventHeaderParams; + return this; + } + + public Builder withNotificationParams(Optional<JSONObject> notificationParams) { + this.notificationParams = notificationParams; + return this; + } + + public Builder withPnfRegistrationParams(Optional<JSONObject> pnfRegistrationParams) { + this.pnfRegistrationParams = pnfRegistrationParams; + return this; + } + + public Builder withXnfUrl(String xnfUrl) { + this.xnfUrl = xnfUrl; + return this; + } + public Simulator build() { Simulator simulator = new Simulator(); simulator.vesUrl = this.vesUrl; simulator.httpClient = this.httpClient; - simulator.messageBody = this.messageBody; + //simulator.messageBody = this.messageBody; simulator.duration = this.duration; simulator.interval = this.interval; + simulator.xnfUrl = this.xnfUrl; + simulator.commonEventHeaderParams = this.commonEventHeaderParams; + simulator.pnfRegistrationParams = this.pnfRegistrationParams; + simulator.notificationParams = this.notificationParams; simulator.isEndless = duration.equals(Duration.ZERO); return simulator; } 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 54af2b9a0..a01c2e0c6 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,42 +20,21 @@ 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 com.github.fge.jsonschema.core.exceptions.ProcessingException; -import java.io.IOException; import java.time.Duration; -import java.util.List; import java.util.Optional; import org.json.JSONObject; import org.onap.pnfsimulator.ConfigurationProvider; -import org.onap.pnfsimulator.FileProvider; import org.onap.pnfsimulator.PnfSimConfig; -import org.onap.pnfsimulator.message.MessageProvider; -import org.onap.pnfsimulator.simulator.validation.JSONValidator; -import org.onap.pnfsimulator.simulator.validation.ValidationException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class SimulatorFactory { - private static final String DEFAULT_OUTPUT_SCHEMA_PATH = "json_schema/output_validator_ves_schema_30.0.1.json"; - - private MessageProvider messageProvider; - private JSONValidator validator; - - @Autowired - public SimulatorFactory(MessageProvider messageProvider, JSONValidator validator) { - this.messageProvider = messageProvider; - this.validator = validator; - } - public Simulator create(JSONObject simulatorParams, JSONObject commonEventHeaderParams, - Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams) - throws ProcessingException, IOException, ValidationException { + Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams) { PnfSimConfig configuration = ConfigurationProvider.getConfigInstance(); String xnfUrl = null; - if (configuration.getDefaultfileserver().equals("sftp")) { xnfUrl = configuration.getUrlsftp() + "/"; } else if (configuration.getDefaultfileserver().equals("ftps")) { @@ -63,17 +42,11 @@ public class SimulatorFactory { } String urlVes = configuration.getUrlves(); - Duration duration = Duration.ofSeconds(parseInt(simulatorParams.getString(TEST_DURATION))); Duration interval = Duration.ofSeconds(parseInt(simulatorParams.getString(MESSAGE_INTERVAL))); - List<String> fileList = FileProvider.getFiles(); - JSONObject messageBody = messageProvider.createMessage(commonEventHeaderParams, pnfRegistrationParams, - notificationParams, fileList, xnfUrl); - validator.validate(messageBody.toString(), DEFAULT_OUTPUT_SCHEMA_PATH); - - return Simulator.builder().withVesUrl(urlVes).withDuration(duration).withInterval(interval) - .withMessageBody(messageBody).build(); - + return Simulator.builder().withVesUrl(urlVes).withXnfUrl(xnfUrl).withDuration(duration) + .withCommonEventHeaderParams(commonEventHeaderParams).withNotificationParams(notificationParams) + .withPnfRegistrationParams(pnfRegistrationParams).withInterval(interval).build(); } } |