diff options
-rw-r--r-- | netconfsimulator/Dockerfile_app | 2 | ||||
-rw-r--r-- | netconfsimulator/pom.xml | 4 | ||||
-rw-r--r-- | netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java | 11 | ||||
-rw-r--r-- | pnfsimulator/Dockerfile | 2 | ||||
-rw-r--r-- | pnfsimulator/integration/pom.xml | 4 | ||||
-rw-r--r-- | pnfsimulator/pom.xml | 4 | ||||
-rw-r--r-- | pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java | 22 | ||||
-rw-r--r-- | pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java | 2 | ||||
-rw-r--r-- | pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeywordTest.java | 48 | ||||
-rw-r--r-- | pom.xml | 4 |
10 files changed, 78 insertions, 25 deletions
diff --git a/netconfsimulator/Dockerfile_app b/netconfsimulator/Dockerfile_app index 589be17..d1cc447 100644 --- a/netconfsimulator/Dockerfile_app +++ b/netconfsimulator/Dockerfile_app @@ -1,4 +1,4 @@ -FROM docker.io/openjdk:8-jre-alpine +FROM docker.io/openjdk:11-jre-slim ARG VERSION=${version} diff --git a/netconfsimulator/pom.xml b/netconfsimulator/pom.xml index 86f3ecd..6dbdf0c 100644 --- a/netconfsimulator/pom.xml +++ b/netconfsimulator/pom.xml @@ -35,8 +35,8 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <maven.compiler.source>1.8</maven.compiler.source> - <maven.compiler.target>1.8</maven.compiler.target> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format> <docker.registry>nexus3.onap.org:10003</docker.registry> <docker.image.tag>latest</docker.image.tag> diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java index 1b99220..6bd8390 100644 --- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java +++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java @@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.kafka.core.ConsumerFactory; import org.springframework.stereotype.Service; +import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.Collections; @@ -53,7 +54,7 @@ public class StoreService { String clientId = Long.toString(Instant.now().getEpochSecond()); try (Consumer<String, String> consumer = consumerFactory.createConsumer(clientId, clientId)) { consumer.subscribe(TOPICS_TO_SUBSCRIBE); - ConsumerRecords<String, String> consumerRecords = consumer.poll(CONSUMING_DURATION_IN_MS); + ConsumerRecords<String, String> consumerRecords = pollConsumerRecords(consumer); consumerRecords.forEach( consumerRecord -> messages.add(new Message(consumerRecord.timestamp(), consumerRecord.value()))); @@ -65,7 +66,7 @@ public class StoreService { List<Message> getLastMessages(long offset) { List<Message> messages = new ArrayList<>(); try (Consumer<String, String> consumer = createConsumer(offset)) { - ConsumerRecords<String, String> consumerRecords = consumer.poll(CONSUMING_DURATION_IN_MS); + ConsumerRecords<String, String> consumerRecords = pollConsumerRecords(consumer); consumerRecords.forEach(consumerRecord -> messages.add(new Message(consumerRecord.timestamp(), consumerRecord.value()))); } @@ -82,10 +83,14 @@ public class StoreService { private void seekConsumerTo(Consumer<String, String> consumer, long offsetFromLastIndex) { consumer.seekToEnd(consumer.assignment()); - consumer.poll(CONSUMING_DURATION_IN_MS); + pollConsumerRecords(consumer); TopicPartition topicPartition = consumer.assignment().iterator().next(); long topicCurrentSize = consumer.position(topicPartition); long indexToSeek = offsetFromLastIndex > topicCurrentSize ? 0 : topicCurrentSize - offsetFromLastIndex; consumer.seek(topicPartition, indexToSeek); } + + private ConsumerRecords<String, String> pollConsumerRecords(Consumer<String, String> consumer) { + return consumer.poll(Duration.ofMillis(CONSUMING_DURATION_IN_MS)); + } } diff --git a/pnfsimulator/Dockerfile b/pnfsimulator/Dockerfile index 7cadcf4..52e507c 100644 --- a/pnfsimulator/Dockerfile +++ b/pnfsimulator/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/openjdk:8-jre-alpine +FROM docker.io/openjdk:11-jre-slim ARG VERSION=${version} diff --git a/pnfsimulator/integration/pom.xml b/pnfsimulator/integration/pom.xml index e411735..5b8e738 100644 --- a/pnfsimulator/integration/pom.xml +++ b/pnfsimulator/integration/pom.xml @@ -39,8 +39,8 @@ </repositories> <properties> - <maven.compiler.source>1.8</maven.compiler.source> - <maven.compiler.target>1.8</maven.compiler.target> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> </properties> <dependencies> diff --git a/pnfsimulator/pom.xml b/pnfsimulator/pom.xml index 251feb2..436571d 100644 --- a/pnfsimulator/pom.xml +++ b/pnfsimulator/pom.xml @@ -37,8 +37,8 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <maven.compiler.source>1.8</maven.compiler.source> - <maven.compiler.target>1.8</maven.compiler.target> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format> <simulator.main.class>org.onap.pnfsimulator.Main</simulator.main.class> <docker.image.tag>latest</docker.image.tag> diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java index 3647ecc..401dc77 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java @@ -96,14 +96,14 @@ public class SimulatorController { @PostMapping("test") @Deprecated - public ResponseEntity test(@Valid @RequestBody SimulatorRequest simulatorRequest) { + public ResponseEntity<Map<String,Object>> test(@Valid @RequestBody SimulatorRequest simulatorRequest) { MDC.put("test", "test"); LOGGER.info(ENTRY, simulatorRequest.toString()); return buildResponse(OK, ImmutableMap.of(MESSAGE, "message1234")); } @PostMapping(value = "start") - public ResponseEntity start(@RequestHeader HttpHeaders headers, + public ResponseEntity<Map<String,Object>> start(@RequestHeader HttpHeaders headers, @Valid @RequestBody SimulatorRequest triggerEventRequest) { logContextHeaders(headers, "/simulator/start"); LOGGER.info(ENTRY, "Simulator started"); @@ -140,7 +140,7 @@ public class SimulatorController { @GetMapping("all-events") @Deprecated - public ResponseEntity allEvents() { + public ResponseEntity<Map<String,Object>> allEvents() { List<EventData> eventDataList = eventDataService.getAllEvents(); StringBuilder sb = new StringBuilder(); eventDataList.forEach(e -> sb.append(e).append(System.lineSeparator())); @@ -151,33 +151,33 @@ public class SimulatorController { } @GetMapping("config") - public ResponseEntity getConfig() { + public ResponseEntity<Map<String,Object>> getConfig() { SimulatorConfig configToGet = simulatorService.getConfiguration(); return buildResponse(OK, ImmutableMap.of("simulatorConfig", configToGet)); } @PutMapping("config") - public ResponseEntity updateConfig(@Valid @RequestBody SimulatorConfig newConfig) { + public ResponseEntity<Map<String,Object>> updateConfig(@Valid @RequestBody SimulatorConfig newConfig) { SimulatorConfig updatedConfig = simulatorService.updateConfiguration(newConfig); return buildResponse(OK, ImmutableMap.of("simulatorConfig", updatedConfig)); } @PostMapping("cancel/{jobName}") - public ResponseEntity cancelEvent(@PathVariable String jobName) throws SchedulerException { + public ResponseEntity<Map<String,Object>> cancelEvent(@PathVariable String jobName) throws SchedulerException { LOGGER.info(ENTRY, "Cancel called on {}.", replaceBreakingCharacters(jobName)); boolean isCancelled = simulatorService.cancelEvent(jobName); return createCancelEventResponse(isCancelled); } @PostMapping("cancel") - public ResponseEntity cancelAllEvent() throws SchedulerException { + public ResponseEntity<Map<String,Object>> cancelAllEvent() throws SchedulerException { LOGGER.info(ENTRY, "Cancel called on all jobs"); boolean isCancelled = simulatorService.cancelAllEvents(); return createCancelEventResponse(isCancelled); } @PostMapping("event") - public ResponseEntity sendEventDirectly(@RequestHeader HttpHeaders headers, @Valid @RequestBody FullEvent event) + public ResponseEntity<Map<String,Object>> sendEventDirectly(@RequestHeader HttpHeaders headers, @Valid @RequestBody FullEvent event) throws IOException, GeneralSecurityException { logContextHeaders(headers, "/simulator/event"); LOGGER.info(ENTRY, "Trying to send one-time event directly to VES Collector"); @@ -189,7 +189,7 @@ public class SimulatorController { return jobName.replaceAll(BREAKING_CHARACTER_REGEX, "_"); } - private ResponseEntity processRequest(SimulatorRequest triggerEventRequest) + private ResponseEntity<Map<String,Object>> processRequest(SimulatorRequest triggerEventRequest) throws IOException, SchedulerException, GeneralSecurityException { String jobName = simulatorService.triggerEvent(triggerEventRequest); @@ -197,7 +197,7 @@ public class SimulatorController { return buildResponse(OK, ImmutableMap.of(MESSAGE, "Request started", "jobName", jobName)); } - private ResponseEntity buildResponse(HttpStatus endStatus, Map<String, Object> parameters) { + private ResponseEntity<Map<String,Object>> buildResponse(HttpStatus endStatus, Map<String, Object> parameters) { ResponseBuilder builder = ResponseBuilder .status(endStatus) .put(TIMESTAMP, DateUtil.getTimestamp(responseDateFormat)); @@ -212,7 +212,7 @@ public class SimulatorController { MDC.put(SERVICE_NAME, serviceName); } - private ResponseEntity createCancelEventResponse(boolean isCancelled) { + private ResponseEntity<Map<String,Object>> createCancelEventResponse(boolean isCancelled) { if (isCancelled) { return buildResponse(OK, ImmutableMap.of(MESSAGE, "Event(s) was cancelled")); } else { diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java index 5fca25a..1fdd7cf 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java @@ -50,7 +50,7 @@ public class ResponseBuilder { return this; } - public ResponseEntity build() { + public ResponseEntity<Map<String,Object>> build() { if (body.isEmpty()) { return ResponseEntity.status(httpStatus).build(); diff --git a/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeywordTest.java b/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeywordTest.java new file mode 100644 index 0000000..6477fbf --- /dev/null +++ b/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeywordTest.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * Simulator + * ================================================================================ + * Copyright (C) 2020 Nokia. 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.simulator.keywords; + + +import io.vavr.Tuple1; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +class TwoParameterKeywordTest { + @Test + public void whenGivenKeywordShouldReturnTwoParameterKeywordObjectWithParsedValues() { + //given + final String expectedName = "TEST"; + final Integer expectedParam1 = 123; + final Integer expectedParam2 = 456; + + String keyword = "#" + expectedName + "(" + expectedParam1 + "," + expectedParam2 + ")"; + + //when + Tuple1<TwoParameterKeyword> keywordTuple = TwoParameterKeyword.twoParameterKeyword(keyword); + TwoParameterKeyword twoParameterKeyword = keywordTuple._1(); + + //then + assertEquals(twoParameterKeyword.getName(), expectedName); + assertEquals(twoParameterKeyword.getAdditionalParameter1(), expectedParam1); + assertEquals(twoParameterKeyword.getAdditionalParameter2(), expectedParam2); + } +}
\ No newline at end of file @@ -46,8 +46,8 @@ <releaseNexusPath>/content/repositories/releases/</releaseNexusPath> <stagingNexusPath>/content/repositories/staging/</stagingNexusPath> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <maven.compiler.source>1.8</maven.compiler.source> - <maven.compiler.target>1.8</maven.compiler.target> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> <docker-maven-plugin.version>0.31.0</docker-maven-plugin.version> <skipDockerPush>true</skipDockerPush> <sonar.coverage.jacoco.xmlReportPaths>${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml |