diff options
Diffstat (limited to 'pnfsimulator/src/main/java')
27 files changed, 274 insertions, 248 deletions
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/Main.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/Main.java index e0eace2..708f27f 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/Main.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/Main.java @@ -43,7 +43,9 @@ public class Main { this.fsToDbTemplateSynchronizer = fsToDbTemplateSynchronizer; } - public static void main(String[] args) { + // We are excluding this line in Sonar due to fact that + // Spring is handling arguments + public static void main(String[] args) { // NOSONAR SpringApplication.run(Main.class, args); } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/SwaggerConfig.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/SwaggerConfig.java index 6e0e18e..b6c6187 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/SwaggerConfig.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/SwaggerConfig.java @@ -20,7 +20,7 @@ package org.onap.pnfsimulator; -import org.onap.pnfsimulator.simulator.client.utils.ssl.SSLAuthenticationHelper; +import org.onap.pnfsimulator.simulator.client.utils.ssl.SslAuthenticationHelper; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -31,7 +31,7 @@ import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration -@EnableConfigurationProperties(SSLAuthenticationHelper.class) +@EnableConfigurationProperties(SslAuthenticationHelper.class) @EnableSwagger2 public class SwaggerConfig { diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/db/Row.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/db/Row.java index f9a167b..12745bf 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/db/Row.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/db/Row.java @@ -7,9 +7,9 @@ * 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. @@ -20,15 +20,20 @@ package org.onap.pnfsimulator.db; +import lombok.Getter; +import lombok.Setter; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Field; public abstract class Row { - @Id - @Field("_id") - protected String id; + @Id + @Field("_id") + @Getter + @Setter + private String id; - public String getId() { - return id; - } + + public String getId() { + return id; + } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventData.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventData.java index 23b1c21..ff85367 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventData.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventData.java @@ -24,12 +24,14 @@ import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Builder; import lombok.Getter; import lombok.Setter; +import lombok.ToString; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Field; @Builder @Getter @Setter +@ToString(exclude = "incrementValue") public class EventData { @Id private String id; @@ -62,15 +64,4 @@ public class EventData { this.keywords = keywords; this.incrementValue = incrementValue; } - - @Override - public String toString() { - return "EventData{" - + "id='" + id + '\'' - + ", template='" + template + '\'' - + ", patched='" + patched + '\'' - + ", input='" + input + '\'' - + ", keywords='" + keywords + '\'' - + '}'; - } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventDataService.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventDataService.java index 3568f01..266d56b 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventDataService.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventDataService.java @@ -21,43 +21,45 @@ package org.onap.pnfsimulator.event; import com.google.gson.JsonObject; + import java.util.List; import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class EventDataService { - private final EventDataRepository repository; - - @Autowired - public EventDataService(EventDataRepository repository) { - this.repository = repository; - } - - private EventData persistEventData(String templateString, String patchedString, String inputString, String keywordsString) { - EventData eventData = EventData.builder() - .template(templateString) - .patched(patchedString) - .input(inputString) - .keywords(keywordsString) - .build(); - return repository.save(eventData); - } - - public EventData persistEventData(JsonObject templateJson, JsonObject patchedJson, JsonObject inputJson, - JsonObject keywordsJson) { - return persistEventData(templateJson.toString(), - patchedJson.toString(), - inputJson.toString(), - keywordsJson.toString()); - } - - public List<EventData> getAllEvents() { - return repository.findAll(); - } - - public Optional<EventData> getById(String id) { - return repository.findById(id); - } + private final EventDataRepository repository; + + @Autowired + public EventDataService(EventDataRepository repository) { + this.repository = repository; + } + + private EventData persistEventData(String templateString, String patchedString, String inputString, String keywordsString) { + EventData eventData = EventData.builder() + .template(templateString) + .patched(patchedString) + .input(inputString) + .keywords(keywordsString) + .build(); + return repository.save(eventData); + } + + public EventData persistEventData(JsonObject templateJson, JsonObject patchedJson, JsonObject inputJson, + JsonObject keywordsJson) { + return persistEventData(templateJson.toString(), + patchedJson.toString(), + inputJson.toString(), + keywordsJson.toString()); + } + + public List<EventData> getAllEvents() { + return repository.findAll(); + } + + public Optional<EventData> getById(String id) { + return repository.findById(id); + } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/logging/MDCVariables.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/logging/MdcVariables.java index 5678f4f..4feb168 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/logging/MDCVariables.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/logging/MdcVariables.java @@ -20,7 +20,7 @@ package org.onap.pnfsimulator.logging; -public final class MDCVariables { +public final class MdcVariables { public static final String X_ONAP_REQUEST_ID = "X-ONAP-RequestID"; public static final String X_INVOCATION_ID = "X-InvocationID"; @@ -30,6 +30,6 @@ public final class MDCVariables { public static final String RESPONSE_CODE = "ResponseCode"; public static final String SERVICE_NAME = "ServiceName"; - private MDCVariables() { + private MdcVariables() { } } 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 0e4bd56..023b163 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java @@ -52,7 +52,6 @@ import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; import java.io.IOException; -import java.net.MalformedURLException; import java.security.GeneralSecurityException; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -60,13 +59,13 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import static org.onap.pnfsimulator.logging.MDCVariables.INSTANCE_UUID; -import static org.onap.pnfsimulator.logging.MDCVariables.INVOCATION_ID; -import static org.onap.pnfsimulator.logging.MDCVariables.REQUEST_ID; -import static org.onap.pnfsimulator.logging.MDCVariables.RESPONSE_CODE; -import static org.onap.pnfsimulator.logging.MDCVariables.SERVICE_NAME; -import static org.onap.pnfsimulator.logging.MDCVariables.X_INVOCATION_ID; -import static org.onap.pnfsimulator.logging.MDCVariables.X_ONAP_REQUEST_ID; +import static org.onap.pnfsimulator.logging.MdcVariables.INSTANCE_UUID; +import static org.onap.pnfsimulator.logging.MdcVariables.INVOCATION_ID; +import static org.onap.pnfsimulator.logging.MdcVariables.REQUEST_ID; +import static org.onap.pnfsimulator.logging.MdcVariables.RESPONSE_CODE; +import static org.onap.pnfsimulator.logging.MdcVariables.SERVICE_NAME; +import static org.onap.pnfsimulator.logging.MdcVariables.X_INVOCATION_ID; +import static org.onap.pnfsimulator.logging.MdcVariables.X_ONAP_REQUEST_ID; import static org.onap.pnfsimulator.rest.util.ResponseBuilder.MESSAGE; import static org.onap.pnfsimulator.rest.util.ResponseBuilder.TIMESTAMP; import static org.springframework.http.HttpStatus.ACCEPTED; @@ -83,6 +82,7 @@ public class SimulatorController { private static final Marker ENTRY = MarkerFactory.getMarker("ENTRY"); private static final String INCORRECT_TEMPLATE_MESSAGE = "Cannot start simulator, template %s is not in valid format: %s"; private static final String NOT_EXISTING_TEMPLATE = "Cannot start simulator - template %s not found."; + private static final String BREAKING_CHARACTER_REGEX = "[\n|\r|\t]"; private final DateFormat responseDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss,SSS"); private final SimulatorService simulatorService; private EventDataService eventDataService; @@ -94,16 +94,20 @@ public class SimulatorController { this.eventDataService = eventDataService; } + /** + * @deprecated + */ @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()); + String simulatorRequestString = simulatorRequest.toString(); + LOGGER.info(ENTRY, simulatorRequestString); 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"); @@ -118,13 +122,12 @@ public class SimulatorController { return buildResponse(BAD_REQUEST, ImmutableMap.of(MESSAGE, String .format(INCORRECT_TEMPLATE_MESSAGE, triggerEventRequest.getTemplateName(), e.getMessage()))); - } catch (GeneralSecurityException e ){ - MDC.put(RESPONSE_CODE, INTERNAL_SERVER_ERROR.toString() ); + } catch (GeneralSecurityException e) { + MDC.put(RESPONSE_CODE, INTERNAL_SERVER_ERROR.toString()); LOGGER.error("Client certificate validation failed: {}", e.getMessage()); return buildResponse(INTERNAL_SERVER_ERROR, ImmutableMap.of(MESSAGE, "Invalid or misconfigured client certificate")); - } - catch (IOException e) { + } catch (IOException e) { MDC.put(RESPONSE_CODE, BAD_REQUEST.toString()); LOGGER.warn("Json validation failed: {}", e.getMessage()); return buildResponse(BAD_REQUEST, @@ -139,9 +142,12 @@ public class SimulatorController { } } + /** + * @deprecated + */ @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())); @@ -152,41 +158,46 @@ 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 { - LOGGER.info(ENTRY, "Cancel called on {}.", jobName); + public ResponseEntity<Map<String,Object>> cancelEvent(@PathVariable String jobName) throws SchedulerException { + String jobNameNoBreakingCharacters = replaceBreakingCharacters(jobName); + LOGGER.info(ENTRY, "Cancel called on {}.", jobNameNoBreakingCharacters); 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) - throws IOException, GeneralSecurityException{ + 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"); simulatorService.triggerOneTimeEvent(event); return buildResponse(ACCEPTED, ImmutableMap.of(MESSAGE, "One-time direct event sent successfully")); } - private ResponseEntity processRequest(SimulatorRequest triggerEventRequest) + private String replaceBreakingCharacters(String jobName) { + return jobName.replaceAll(BREAKING_CHARACTER_REGEX, "_"); + } + + private ResponseEntity<Map<String,Object>> processRequest(SimulatorRequest triggerEventRequest) throws IOException, SchedulerException, GeneralSecurityException { String jobName = simulatorService.triggerEvent(triggerEventRequest); @@ -194,7 +205,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)); @@ -209,7 +220,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/TemplateController.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/TemplateController.java index 444e23b..7eaa9ff 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/TemplateController.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/TemplateController.java @@ -30,8 +30,6 @@ import org.onap.pnfsimulator.rest.model.TemplateRequest; import org.onap.pnfsimulator.rest.model.SearchExp; import org.onap.pnfsimulator.template.Template; import org.onap.pnfsimulator.template.search.IllegalJsonValueException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -53,7 +51,6 @@ public class TemplateController { static final String TEMPLATE_NOT_FOUND_MSG = "A template with given name does not exist"; static final String CANNOT_OVERRIDE_TEMPLATE_MSG = "Cannot overwrite existing template. Use override=true to override"; private final Storage<Template> service; - private static final Logger LOG = LoggerFactory.getLogger(TemplateController.class); @Autowired public TemplateController(Storage<Template> service) { @@ -61,7 +58,7 @@ public class TemplateController { } @GetMapping("list") - public ResponseEntity<?> list() { + public ResponseEntity<List<Template>> list() { return new ResponseEntity<>(service.getAll(), HttpStatus.OK); } @@ -77,7 +74,7 @@ public class TemplateController { } @PostMapping("upload") - public ResponseEntity<?> upload( + public ResponseEntity<String> upload( @RequestBody @Valid TemplateRequest templateRequest, @RequestParam(required = false) boolean override) { String msg = ""; @@ -91,7 +88,7 @@ public class TemplateController { } @PostMapping("search") - public ResponseEntity<?> searchByCriteria(@RequestBody SearchExp queryJson) { + public ResponseEntity<List<String>> searchByCriteria(@RequestBody SearchExp queryJson) { try { List<String> templateNames = service.getIdsByContentCriteria(queryJson.getSearchExpr()); return new ResponseEntity<>(templateNames, HttpStatus.OK); 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/main/java/org/onap/pnfsimulator/simulator/DBTemplateReader.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/DbTemplateReader.java index 6c11254..878591b 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/DBTemplateReader.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/DbTemplateReader.java @@ -23,27 +23,29 @@ package org.onap.pnfsimulator.simulator; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; + import java.io.IOException; + import org.onap.pnfsimulator.template.Template; import org.onap.pnfsimulator.template.TemplateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component -public class DBTemplateReader implements TemplateReader { - private final TemplateService service; - private final Gson gson; +public class DbTemplateReader implements TemplateReader { + private final TemplateService service; + private final Gson gson; - @Autowired - public DBTemplateReader(TemplateService service, Gson gson) { - this.service = service; - this.gson = gson; - } + @Autowired + public DbTemplateReader(TemplateService service, Gson gson) { + this.service = service; + this.gson = gson; + } - @Override - public JsonObject readTemplate(String templateName) throws IOException { - Template template = service.get(templateName).orElseThrow(() -> new IOException("Template does not exist")); - JsonElement jsonElement = gson.toJsonTree(template.getContent()); - return jsonElement.getAsJsonObject(); - } + @Override + public JsonObject readTemplate(String templateName) throws IOException { + Template template = service.get(templateName).orElseThrow(() -> new IOException("Template does not exist")); + JsonElement jsonElement = gson.toJsonTree(template.getContent()); + return jsonElement.getAsJsonObject(); + } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/EventNotFoundException.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/EventNotFoundException.java index 4f43d8c..01f6508 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/EventNotFoundException.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/EventNotFoundException.java @@ -21,8 +21,9 @@ package org.onap.pnfsimulator.simulator; public class EventNotFoundException extends RuntimeException { - private static final String NOT_FOUND = "Not found an event with id: "; - public EventNotFoundException(String eventId) { - super(NOT_FOUND + eventId); - } + private static final String NOT_FOUND = "Not found an event with id: "; + + public EventNotFoundException(String eventId) { + super(NOT_FOUND + eventId); + } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/IncrementProvider.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/IncrementProvider.java index ea87ae6..4a7cf02 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/IncrementProvider.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/IncrementProvider.java @@ -22,5 +22,5 @@ package org.onap.pnfsimulator.simulator; @FunctionalInterface public interface IncrementProvider { - int getAndIncrement(String id); + int getAndIncrement(String id); } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/IncrementProviderImpl.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/IncrementProviderImpl.java index 16c0a0e..9d4d3ec 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/IncrementProviderImpl.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/IncrementProviderImpl.java @@ -27,21 +27,21 @@ import org.springframework.stereotype.Service; @Service public class IncrementProviderImpl implements IncrementProvider { - private final EventDataRepository repository; + private final EventDataRepository repository; - @Autowired - public IncrementProviderImpl(EventDataRepository repository) { - this.repository = repository; - } + @Autowired + public IncrementProviderImpl(EventDataRepository repository) { + this.repository = repository; + } - @Override - public int getAndIncrement(String id) { - EventData eventData = repository.findById(id) - .orElseThrow(() -> new EventNotFoundException(id)); - int value = eventData.getIncrementValue() + 1; - eventData.setIncrementValue(value); - repository.save(eventData); - return value; - } + @Override + public int getAndIncrement(String id) { + EventData eventData = repository.findById(id) + .orElseThrow(() -> new EventNotFoundException(id)); + int value = eventData.getIncrementValue() + 1; + eventData.setIncrementValue(value); + repository.save(eventData); + return value; + } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsExtractor.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsExtractor.java index 23c383f..2dc52a1 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsExtractor.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsExtractor.java @@ -32,6 +32,7 @@ import static org.onap.pnfsimulator.simulator.KeywordsValueProvider.getTimestamp import static org.onap.pnfsimulator.simulator.keywords.NonParameterKeywordPatterns.$nonParameterKeyword; import static org.onap.pnfsimulator.simulator.keywords.SingleParameterKeywordPatterns.$singleParameterKeyword; import static org.onap.pnfsimulator.simulator.keywords.TwoParameterKeywordPatterns.$twoParameterKeyword; + import io.vavr.API.Match.Pattern1; import org.onap.pnfsimulator.simulator.keywords.Keyword; import org.onap.pnfsimulator.simulator.keywords.NonParameterKeyword; @@ -44,43 +45,53 @@ public class KeywordsExtractor { String substituteStringKeyword(String text, int increment) { return Match(text).of( - Case(isRandomStringParamKeyword(), - spk -> spk.substituteKeyword(getRandomString().apply(spk.getAdditionalParameter()))), - Case(isRandomStringNonParamKeyword(), - npk -> npk.substituteKeyword(getRandomLimitedString().apply())), - Case(isRandomIntegerParamKeyword(), - tpk -> tpk.substituteKeyword(getRandomInteger().apply(tpk.getAdditionalParameter1(), tpk.getAdditionalParameter2()))), - Case(isRandomIntegerNonParamKeyword(), - npk -> npk.substituteKeyword(getRandomLimitedInteger().apply())), - Case(isIncrementKeyword(), - ik -> ik.substituteKeyword(String.valueOf(increment))), - Case(isTimestampNonParamKeyword(), - npk -> npk.substituteKeyword(getEpochSecond().apply())), - Case( - $(), - () -> text - )); + Case(isRandomStringParamKeyword(), + spk -> spk.substituteKeyword(getRandomString().apply(spk.getAdditionalParameter())) + ), + Case(isRandomStringNonParamKeyword(), + npk -> npk.substituteKeyword(getRandomLimitedString().apply()) + ), + Case(isRandomIntegerParamKeyword(), + tpk -> tpk.substituteKeyword(getRandomInteger().apply( + tpk.getAdditionalParameter1(), + tpk.getAdditionalParameter2() + ) + ) + ), + Case(isRandomIntegerNonParamKeyword(), + npk -> npk.substituteKeyword(getRandomLimitedInteger().apply()) + ), + Case(isIncrementKeyword(), + ik -> ik.substituteKeyword(String.valueOf(increment)) + ), + Case(isTimestampNonParamKeyword(), + npk -> npk.substituteKeyword(getEpochSecond().apply()) + ), + Case( + $(), + () -> text + )); } Long substitutePrimitiveKeyword(String text) { return Match(text).of( - Case(isRandomPrimitiveIntegerParamKeyword(), - tpk -> - getRandomPrimitiveInteger().apply(tpk.getAdditionalParameter1(), tpk.getAdditionalParameter2())), - Case(isTimestampPrimitiveNonParamKeyword(), - tpk -> - getTimestampPrimitive().apply()), - Case( - $(), - () -> 0L - )); + Case(isRandomPrimitiveIntegerParamKeyword(), + tpk -> + getRandomPrimitiveInteger().apply(tpk.getAdditionalParameter1(), tpk.getAdditionalParameter2())), + Case(isTimestampPrimitiveNonParamKeyword(), + tpk -> + getTimestampPrimitive().apply()), + Case( + $(), + () -> 0L + )); } boolean isPrimitive(String text) { return Match(text).of( - Case(isRandomPrimitiveIntegerParamKeyword(), () -> true), - Case(isTimestampPrimitiveNonParamKeyword(), () -> true), - Case($(), () -> false)); + Case(isRandomPrimitiveIntegerParamKeyword(), () -> true), + Case(isTimestampPrimitiveNonParamKeyword(), () -> true), + Case($(), () -> false)); } private Pattern1<String, SingleParameterKeyword> isRandomStringParamKeyword() { diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/SimulatorService.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/SimulatorService.java index 155c0ff..02f50e4 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/SimulatorService.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/SimulatorService.java @@ -22,10 +22,6 @@ package org.onap.pnfsimulator.simulator; import com.google.common.base.Strings; import com.google.gson.JsonObject; -import java.io.IOException; -import java.net.MalformedURLException; -import java.security.GeneralSecurityException; -import java.util.Optional; import org.onap.pnfsimulator.event.EventData; import org.onap.pnfsimulator.event.EventDataService; import org.onap.pnfsimulator.rest.model.FullEvent; @@ -33,7 +29,7 @@ import org.onap.pnfsimulator.rest.model.SimulatorParams; import org.onap.pnfsimulator.rest.model.SimulatorRequest; import org.onap.pnfsimulator.simulator.client.HttpClientAdapter; import org.onap.pnfsimulator.simulator.client.HttpClientAdapterImpl; -import org.onap.pnfsimulator.simulator.client.utils.ssl.SSLAuthenticationHelper; +import org.onap.pnfsimulator.simulator.client.utils.ssl.SslAuthenticationHelper; import org.onap.pnfsimulator.simulator.scheduler.EventScheduler; import org.onap.pnfsimulator.simulatorconfig.SimulatorConfig; import org.onap.pnfsimulator.simulatorconfig.SimulatorConfigService; @@ -41,6 +37,10 @@ import org.quartz.SchedulerException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.Optional; + @Service public class SimulatorService { @@ -48,14 +48,14 @@ public class SimulatorService { private final TemplateReader templateReader; private final EventDataService eventDataService; private final EventScheduler eventScheduler; - private final SSLAuthenticationHelper sslAuthenticationHelper; + private final SslAuthenticationHelper sslAuthenticationHelper; private SimulatorConfigService simulatorConfigService; private static final JsonObject EMPTY_JSON_OBJECT = new JsonObject(); @Autowired public SimulatorService(TemplatePatcher templatePatcher, TemplateReader templateReader, EventScheduler eventScheduler, EventDataService eventDataService, - SimulatorConfigService simulatorConfigService, SSLAuthenticationHelper sslAuthenticationHelper) { + SimulatorConfigService simulatorConfigService, SslAuthenticationHelper sslAuthenticationHelper) { this.templatePatcher = templatePatcher; this.templateReader = templateReader; this.eventDataService = eventDataService; diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/TemplateReader.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/TemplateReader.java index bf06381..2471c08 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/TemplateReader.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/TemplateReader.java @@ -21,8 +21,9 @@ package org.onap.pnfsimulator.simulator; import com.google.gson.JsonObject; + import java.io.IOException; public interface TemplateReader { - JsonObject readTemplate(String templateName) throws IOException; + JsonObject readTemplate(String templateName) throws IOException; } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java index 6ea1157..7ddef86 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java @@ -20,22 +20,13 @@ package org.onap.pnfsimulator.simulator.client; -import static org.onap.pnfsimulator.logging.MDCVariables.REQUEST_ID; -import static org.onap.pnfsimulator.logging.MDCVariables.X_INVOCATION_ID; -import static org.onap.pnfsimulator.logging.MDCVariables.X_ONAP_REQUEST_ID; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.GeneralSecurityException; -import java.util.UUID; - import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.util.EntityUtils; -import org.onap.pnfsimulator.simulator.client.utils.ssl.SSLAuthenticationHelper; +import org.onap.pnfsimulator.simulator.client.utils.ssl.SslAuthenticationHelper; import org.onap.pnfsimulator.simulator.client.utils.ssl.SslSupportLevel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,6 +34,15 @@ import org.slf4j.MDC; import org.slf4j.Marker; import org.slf4j.MarkerFactory; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; +import java.util.UUID; + +import static org.onap.pnfsimulator.logging.MdcVariables.REQUEST_ID; +import static org.onap.pnfsimulator.logging.MdcVariables.X_INVOCATION_ID; +import static org.onap.pnfsimulator.logging.MdcVariables.X_ONAP_REQUEST_ID; + public class HttpClientAdapterImpl implements HttpClientAdapter { private static final int CONNECTION_TIMEOUT = 1000; @@ -55,14 +55,15 @@ public class HttpClientAdapterImpl implements HttpClientAdapter { .setSocketTimeout(CONNECTION_TIMEOUT) .build(); private static final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); - private SslSupportLevel sslSupportLevel; + private SslSupportLevel sslSupportLevel; private HttpClient client; private final String targetUrl; - public HttpClientAdapterImpl(String targetUrl, SSLAuthenticationHelper sslAuthenticationHelper) + public HttpClientAdapterImpl(String targetUrl, SslAuthenticationHelper sslAuthenticationHelper) throws IOException, GeneralSecurityException { - this.sslSupportLevel = sslAuthenticationHelper.isClientCertificateEnabled() ? - SslSupportLevel.CLIENT_CERT_AUTH : SslSupportLevel.getSupportLevelBasedOnProtocol(targetUrl); + this.sslSupportLevel = sslAuthenticationHelper.isClientCertificateEnabled() + ? SslSupportLevel.CLIENT_CERT_AUTH + : SslSupportLevel.getSupportLevelBasedOnProtocol(targetUrl); this.client = sslSupportLevel.getClient(CONFIG, sslAuthenticationHelper); this.targetUrl = targetUrl; } @@ -82,11 +83,11 @@ public class HttpClientAdapterImpl implements HttpClientAdapter { EntityUtils.consumeQuietly(response.getEntity()); LOGGER.info(INVOKE, "Message sent, ves response code: {}", response.getStatusLine()); } catch (IOException e) { - LOGGER.warn("Error sending message to ves: " + e.getMessage(), e.getCause()); + LOGGER.warn("Error sending message to ves: {}", e.getMessage(), e.getCause()); } } - public SslSupportLevel getSslSupportLevel(){ + public SslSupportLevel getSslSupportLevel() { return sslSupportLevel; } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SSLAuthenticationHelper.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java index eda17ef..ee5fdb7 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SSLAuthenticationHelper.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java @@ -29,7 +29,7 @@ import org.springframework.stereotype.Component; @ConfigurationProperties(prefix = "ssl") @RefreshScope @Primary -public class SSLAuthenticationHelper implements Serializable { +public class SslAuthenticationHelper implements Serializable { private boolean clientCertificateEnabled; private String clientCertificateDir; diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevel.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevel.java index 264a7d1..393a6c5 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevel.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevel.java @@ -40,16 +40,13 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.security.GeneralSecurityException; -import java.security.KeyManagementException; import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; import java.util.Optional; public enum SslSupportLevel { NONE { - public HttpClient getClient(RequestConfig requestConfig, SSLAuthenticationHelper sslAuthenticationHelper) { + public HttpClient getClient(RequestConfig requestConfig, SslAuthenticationHelper sslAuthenticationHelper) { LOGGER.info("<!-----IN SslSupportLevel.NONE, Creating BasicHttpClient for http protocol----!>"); return HttpClientBuilder .create() @@ -58,7 +55,7 @@ public enum SslSupportLevel { } }, ALWAYS_TRUST { - public HttpClient getClient(RequestConfig requestConfig, SSLAuthenticationHelper sslAuthenticationHelper) + public HttpClient getClient(RequestConfig requestConfig, SslAuthenticationHelper sslAuthenticationHelper) throws GeneralSecurityException, IOException { LoggerFactory.getLogger(SslSupportLevel.class).info("<!-----IN SslSupportLevel.ALWAYS_TRUST, Creating client with SSL support for https protocol----!>"); HttpClient client; @@ -71,7 +68,7 @@ public enum SslSupportLevel { .build(); } catch (GeneralSecurityException e) { - LOGGER.error("Could not initialize client due to SSL exception: {}. Default client without SSL support will be used instead.\nCause: {}", e.getMessage(), e.getCause()); + LOGGER.error("Could not initialize client due to SSL exception: {}. Default client without SSL support will be used instead.\nCause: {}", e.getMessage(), e.getCause().toString()); client = NONE.getClient(requestConfig, sslAuthenticationHelper); } return client; @@ -79,7 +76,7 @@ public enum SslSupportLevel { }, CLIENT_CERT_AUTH { @Override - public HttpClient getClient(RequestConfig requestConfig, SSLAuthenticationHelper sslAuthenticationHelper) + public HttpClient getClient(RequestConfig requestConfig, SslAuthenticationHelper sslAuthenticationHelper) throws GeneralSecurityException, IOException { SSLContext sslContext = SSLContexts.custom() @@ -114,7 +111,7 @@ public enum SslSupportLevel { return "https".equals(new URL(url).getProtocol()) ? SslSupportLevel.ALWAYS_TRUST : SslSupportLevel.NONE; } - public abstract HttpClient getClient(RequestConfig config, SSLAuthenticationHelper sslAuthenticationHelper) + public abstract HttpClient getClient(RequestConfig config, SslAuthenticationHelper sslAuthenticationHelper) throws GeneralSecurityException, IOException; } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/keywords/Keyword.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/keywords/Keyword.java index edafe8f..1bb1332 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/keywords/Keyword.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/keywords/Keyword.java @@ -21,10 +21,12 @@ package org.onap.pnfsimulator.simulator.keywords; import io.vavr.Function1; import io.vavr.Function2; + import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.stream.Collectors; + import lombok.Getter; @Getter @@ -34,7 +36,7 @@ public class Keyword { protected static final String NONLETTERS_REGEX = "([^a-zA-Z]+)"; protected static final Function1<String, String> OPTIONAL = - (regex) -> regex + "?"; + regex -> regex + "?"; private final String name; private final List<String> meaningfulParts; @@ -46,12 +48,12 @@ public class Keyword { * Returns list of independent parts inside the keyword. Current implementation assumes that customer can join keywords with integer values, so * keyword is decomposed to parts then some parts of the keyword is skipped because of replacement process. * - * @param matcher - Matcher to check find independent groups inside the keyword + * @param matcher - Matcher to check find independent groups inside the keyword * @param skipGroups Informs this method about which groups should be consider as part of the replacement process * @return list of independent parts inside the keywords */ - static List<String> extractPartsFrom(Matcher matcher, List skipGroups) { - List<String> parts = new ArrayList<String>(); + static List<String> extractPartsFrom(Matcher matcher, List<Integer> skipGroups) { + List<String> parts = new ArrayList<>(); for (int i = 1; i <= matcher.groupCount(); i++) { if (matcher.group(i) != null && !skipGroups.contains(i)) { parts.add(matcher.group(i)); diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventJob.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventJob.java index c4b40fc..21e0466 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventJob.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventJob.java @@ -25,7 +25,7 @@ import com.google.gson.JsonObject; import org.onap.pnfsimulator.simulator.KeywordsHandler; import org.onap.pnfsimulator.simulator.client.HttpClientAdapter; import org.onap.pnfsimulator.simulator.client.HttpClientAdapterImpl; -import org.onap.pnfsimulator.simulator.client.utils.ssl.SSLAuthenticationHelper; +import org.onap.pnfsimulator.simulator.client.utils.ssl.SslAuthenticationHelper; import org.quartz.Job; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; @@ -69,24 +69,28 @@ public class EventJob implements Job { LOGGER.error("Could not send event as client is not available"); } } + private Optional<HttpClientAdapter> getHttpClientAdapter(JobDataMap jobDataMap, String vesUrl) { HttpClientAdapter adapter = null; try { - adapter = (HttpClientAdapter) (jobDataMap.containsKey(CLIENT_ADAPTER) ? jobDataMap.get(CLIENT_ADAPTER) : - new HttpClientAdapterImpl(vesUrl, new SSLAuthenticationHelper())); + adapter = (HttpClientAdapter) ( + jobDataMap.containsKey(CLIENT_ADAPTER) + ? jobDataMap.get(CLIENT_ADAPTER) + : new HttpClientAdapterImpl(vesUrl, new SslAuthenticationHelper()) + ); } catch (MalformedURLException e) { LOGGER.error("Invalid format of vesServerUr: {}", vesUrl); - } catch (IOException | GeneralSecurityException e){ + } catch (IOException | GeneralSecurityException e) { LOGGER.error("Invalid configuration of client certificate"); } return Optional.ofNullable(adapter); } private void logEventDetails(String templateName, String vesUrl, String body, String jobKey) { - LOGGER.info(String.format("Job %s:Sending event to %s from template %s", - jobKey, vesUrl, templateName)); + LOGGER.info("Job {}:Sending event to {} from template {}", + jobKey, vesUrl, templateName); if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Job %s: Request body %s", jobKey, body)); + LOGGER.debug("Job {}: Request body {}", jobKey, body); } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventScheduler.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventScheduler.java index 08e24f8..5584cb1 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventScheduler.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventScheduler.java @@ -20,25 +20,10 @@ package org.onap.pnfsimulator.simulator.scheduler; -import static org.onap.pnfsimulator.simulator.scheduler.EventJob.BODY; -import static org.onap.pnfsimulator.simulator.scheduler.EventJob.CLIENT_ADAPTER; -import static org.onap.pnfsimulator.simulator.scheduler.EventJob.EVENT_ID; -import static org.onap.pnfsimulator.simulator.scheduler.EventJob.KEYWORDS_HANDLER; -import static org.onap.pnfsimulator.simulator.scheduler.EventJob.TEMPLATE_NAME; -import static org.onap.pnfsimulator.simulator.scheduler.EventJob.VES_URL; -import static org.quartz.SimpleScheduleBuilder.simpleSchedule; - import com.google.gson.JsonObject; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.security.GeneralSecurityException; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; import org.onap.pnfsimulator.simulator.KeywordsHandler; import org.onap.pnfsimulator.simulator.client.HttpClientAdapterImpl; -import org.onap.pnfsimulator.simulator.client.utils.ssl.SSLAuthenticationHelper; +import org.onap.pnfsimulator.simulator.client.utils.ssl.SslAuthenticationHelper; import org.quartz.JobBuilder; import org.quartz.JobDataMap; import org.quartz.JobDetail; @@ -51,23 +36,37 @@ import org.quartz.TriggerBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import static org.onap.pnfsimulator.simulator.scheduler.EventJob.BODY; +import static org.onap.pnfsimulator.simulator.scheduler.EventJob.CLIENT_ADAPTER; +import static org.onap.pnfsimulator.simulator.scheduler.EventJob.EVENT_ID; +import static org.onap.pnfsimulator.simulator.scheduler.EventJob.KEYWORDS_HANDLER; +import static org.onap.pnfsimulator.simulator.scheduler.EventJob.TEMPLATE_NAME; +import static org.onap.pnfsimulator.simulator.scheduler.EventJob.VES_URL; +import static org.quartz.SimpleScheduleBuilder.simpleSchedule; + @Component public class EventScheduler { private final Scheduler scheduler; private final KeywordsHandler keywordsHandler; - private final SSLAuthenticationHelper SSLAuthenticationHelper; + private final SslAuthenticationHelper sslAuthenticationHelper; @Autowired - public EventScheduler(Scheduler scheduler, KeywordsHandler keywordsHandler, SSLAuthenticationHelper SSLAuthenticationHelper) { + public EventScheduler(Scheduler scheduler, KeywordsHandler keywordsHandler, SslAuthenticationHelper sslAuthenticationHelper) { this.scheduler = scheduler; this.keywordsHandler = keywordsHandler; - this.SSLAuthenticationHelper = SSLAuthenticationHelper; + this.sslAuthenticationHelper = sslAuthenticationHelper; } public String scheduleEvent(String vesUrl, Integer repeatInterval, Integer repeatCount, - String templateName, String eventId, JsonObject body) + String templateName, String eventId, JsonObject body) throws SchedulerException, IOException, GeneralSecurityException { JobDetail jobDetail = createJobDetail(vesUrl, templateName, eventId, body); @@ -89,10 +88,10 @@ public class EventScheduler { private SimpleTrigger createTrigger(int interval, int repeatCount) { return TriggerBuilder.newTrigger() - .withSchedule(simpleSchedule() - .withIntervalInSeconds(interval) - .withRepeatCount(repeatCount - 1)) - .build(); + .withSchedule(simpleSchedule() + .withIntervalInSeconds(interval) + .withRepeatCount(repeatCount - 1)) + .build(); } private JobDetail createJobDetail(String vesUrl, String templateName, String eventId, JsonObject body) throws IOException, GeneralSecurityException { @@ -102,20 +101,20 @@ public class EventScheduler { jobDataMap.put(EVENT_ID, eventId); jobDataMap.put(KEYWORDS_HANDLER, keywordsHandler); jobDataMap.put(BODY, body); - jobDataMap.put(CLIENT_ADAPTER, new HttpClientAdapterImpl(vesUrl, SSLAuthenticationHelper)); + jobDataMap.put(CLIENT_ADAPTER, new HttpClientAdapterImpl(vesUrl, sslAuthenticationHelper)); return JobBuilder - .newJob(EventJob.class) - .withDescription(templateName) - .usingJobData(jobDataMap) - .build(); + .newJob(EventJob.class) + .withDescription(templateName) + .usingJobData(jobDataMap) + .build(); } private List<JobKey> getActiveJobsKeys() throws SchedulerException { return scheduler.getCurrentlyExecutingJobs() - .stream() - .map(JobExecutionContext::getJobDetail) - .map(JobDetail::getKey) - .collect(Collectors.toList()); + .stream() + .map(JobExecutionContext::getJobDetail) + .map(JobDetail::getKey) + .collect(Collectors.toList()); } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java index 881585b..0080813 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java @@ -20,12 +20,6 @@ package org.onap.pnfsimulator.template; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.stream.Stream; - import org.bson.json.JsonParseException; import org.onap.pnfsimulator.db.Storage; import org.onap.pnfsimulator.filesystem.WatcherEventProcessor; @@ -35,6 +29,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.stream.Stream; + @Service public class FsToDbTemplateSynchronizer { @@ -66,7 +66,7 @@ public class FsToDbTemplateSynchronizer { WatcherEventProcessor.MODIFIED.processEvent(path, storage); } catch (IOException | JsonParseException e) { LOGGER - .error("Cannot synchronize template: " + path.getFileName().toString(), e); + .error("Cannot synchronize template: {}", path.getFileName(), e); } }); } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/Template.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/Template.java index c84b8d0..121d7d4 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/Template.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/Template.java @@ -44,14 +44,14 @@ public class Template extends Row { private long lmod; public Template(String name, Document content, long lmod) { - this.id = name; + this.setId(name); this.content = content; this.lmod = lmod; this.flatContent = new JsonUtils().flatten(content); } public Template(String name, String template, long lmod) { - this.id = name; + this.setId(name); this.content = Document.parse(template); this.lmod = lmod; this.flatContent = new JsonUtils().flatten(this.content); @@ -72,21 +72,21 @@ public class Template extends Row { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - Template template = (Template) o; + Template template = (Template) object; return Objects.equals(content, template.content) - && Objects.equals(id, template.id) + && Objects.equals(getId(), template.getId()) && Objects.equals(lmod, template.lmod); } @Override public int hashCode() { - return Objects.hash(content, id); + return Objects.hash(content, getId()); } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/IllegalJsonValueException.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/IllegalJsonValueException.java index 6890382..1685536 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/IllegalJsonValueException.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/IllegalJsonValueException.java @@ -22,7 +22,7 @@ package org.onap.pnfsimulator.template.search; public class IllegalJsonValueException extends IllegalArgumentException { - IllegalJsonValueException(String s) { - super(s); + IllegalJsonValueException(String message) { + super(message); } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/viewmodel/FlatTemplateContent.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/viewmodel/FlatTemplateContent.java index 84235f7..8634052 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/viewmodel/FlatTemplateContent.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/viewmodel/FlatTemplateContent.java @@ -37,7 +37,7 @@ public class FlatTemplateContent extends Row { public FlatTemplateContent(String name, List<KeyValuePair> keyValues) { - this.id = name; + this.setId(name); this.keyValues = keyValues; } } diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/viewmodel/KeyValuePair.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/viewmodel/KeyValuePair.java index 5e44452..8f24334 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/viewmodel/KeyValuePair.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/search/viewmodel/KeyValuePair.java @@ -34,7 +34,7 @@ import lombok.ToString; */ public class KeyValuePair { - private String k; - private String v; + private String key; + private String value; } |