From 4af5241ab25b0103d8ea680789aaf9a8696dfc75 Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Tue, 9 Mar 2021 12:54:38 +0100 Subject: Move pnf simulator to the new repo In the first phase we renamed project from pnf simulator to vesclient. Next steps: package rename, update Readme.md, upgrade project dependencies. Issue-ID: INT-1869 Signed-off-by: Bogumil Zebek Change-Id: I7714792f9739eb746c9c533e8ef41b9618a3a1d9 --- src/main/java/org/onap/pnfsimulator/Main.java | 59 +++++ .../java/org/onap/pnfsimulator/SwaggerConfig.java | 46 ++++ src/main/java/org/onap/pnfsimulator/db/Row.java | 39 ++++ .../java/org/onap/pnfsimulator/db/Storage.java | 41 ++++ .../org/onap/pnfsimulator/event/EventData.java | 67 ++++++ .../pnfsimulator/event/EventDataRepository.java | 26 +++ .../onap/pnfsimulator/event/EventDataService.java | 65 ++++++ .../pnfsimulator/filesystem/WatcherConfig.java | 39 ++++ .../filesystem/WatcherEventProcessor.java | 111 ++++++++++ .../pnfsimulator/filesystem/WatcherService.java | 44 ++++ .../pnfsimulator/filesystem/WatcherThread.java | 81 +++++++ .../onap/pnfsimulator/logging/MdcVariables.java | 35 +++ .../pnfsimulator/rest/SimulatorController.java | 241 +++++++++++++++++++++ .../onap/pnfsimulator/rest/TemplateController.java | 112 ++++++++++ .../onap/pnfsimulator/rest/model/FullEvent.java | 48 ++++ .../onap/pnfsimulator/rest/model/SearchExp.java | 42 ++++ .../pnfsimulator/rest/model/SimulatorParams.java | 46 ++++ .../pnfsimulator/rest/model/SimulatorRequest.java | 55 +++++ .../pnfsimulator/rest/model/TemplateRequest.java | 38 ++++ .../org/onap/pnfsimulator/rest/util/DateUtil.java | 35 +++ .../rest/util/JsonObjectDeserializer.java | 42 ++++ .../pnfsimulator/rest/util/ResponseBuilder.java | 62 ++++++ .../pnfsimulator/simulator/DbTemplateReader.java | 51 +++++ .../simulator/EventNotFoundException.java | 29 +++ .../simulator/FilesystemTemplateReader.java | 54 +++++ .../pnfsimulator/simulator/IncrementProvider.java | 26 +++ .../simulator/IncrementProviderImpl.java | 47 ++++ .../pnfsimulator/simulator/JsonTokenProcessor.java | 134 ++++++++++++ .../pnfsimulator/simulator/KeywordsExtractor.java | 129 +++++++++++ .../pnfsimulator/simulator/KeywordsHandler.java | 74 +++++++ .../simulator/KeywordsHandlerException.java | 28 +++ .../simulator/KeywordsValueProvider.java | 80 +++++++ .../pnfsimulator/simulator/SimulatorService.java | 132 +++++++++++ .../pnfsimulator/simulator/TemplatePatcher.java | 53 +++++ .../pnfsimulator/simulator/TemplateReader.java | 29 +++ .../simulator/TemplateVariablesReplacer.java | 50 +++++ .../client/HttpApacheResponseAdapterFactory.java | 45 ++++ .../simulator/client/HttpClientAdapter.java | 27 +++ .../simulator/client/HttpClientAdapterImpl.java | 119 ++++++++++ .../simulator/client/HttpResponseAdapter.java | 41 ++++ .../utils/ssl/CertAuthSslContextFactory.java | 53 +++++ .../client/utils/ssl/CertificateReader.java | 46 ++++ .../client/utils/ssl/HttpClientFactory.java | 104 +++++++++ .../client/utils/ssl/HttpClientFactoryFacade.java | 40 ++++ .../client/utils/ssl/PasswordConverter.java | 32 +++ .../client/utils/ssl/SSLContextFactory.java | 48 ++++ .../client/utils/ssl/SslAuthenticationHelper.java | 45 ++++ .../pnfsimulator/simulator/keywords/Keyword.java | 76 +++++++ .../simulator/keywords/NonParameterKeyword.java | 65 ++++++ .../simulator/keywords/SingleParameterKeyword.java | 73 +++++++ .../simulator/keywords/TwoParameterKeyword.java | 80 +++++++ .../pnfsimulator/simulator/scheduler/EventJob.java | 99 +++++++++ .../simulator/scheduler/EventScheduler.java | 120 ++++++++++ .../simulator/scheduler/QuartzConfiguration.java | 38 ++++ .../simulatorconfig/SimulatorConfig.java | 49 +++++ .../simulatorconfig/SimulatorConfigRepository.java | 26 +++ .../simulatorconfig/SimulatorConfigService.java | 52 +++++ .../template/FsToDbTemplateSynchronizer.java | 74 +++++++ .../org/onap/pnfsimulator/template/Template.java | 92 ++++++++ .../pnfsimulator/template/TemplateRepository.java | 26 +++ .../pnfsimulator/template/TemplateService.java | 81 +++++++ .../template/search/IllegalJsonValueException.java | 28 +++ .../pnfsimulator/template/search/JsonUtils.java | 104 +++++++++ .../template/search/TemplateSearchHelper.java | 95 ++++++++ .../handler/PrimitiveValueCriteriaBuilder.java | 103 +++++++++ .../search/viewmodel/FlatTemplateContent.java | 45 ++++ .../template/search/viewmodel/KeyValuePair.java | 40 ++++ 67 files changed, 4256 insertions(+) create mode 100644 src/main/java/org/onap/pnfsimulator/Main.java create mode 100644 src/main/java/org/onap/pnfsimulator/SwaggerConfig.java create mode 100644 src/main/java/org/onap/pnfsimulator/db/Row.java create mode 100644 src/main/java/org/onap/pnfsimulator/db/Storage.java create mode 100644 src/main/java/org/onap/pnfsimulator/event/EventData.java create mode 100644 src/main/java/org/onap/pnfsimulator/event/EventDataRepository.java create mode 100644 src/main/java/org/onap/pnfsimulator/event/EventDataService.java create mode 100644 src/main/java/org/onap/pnfsimulator/filesystem/WatcherConfig.java create mode 100644 src/main/java/org/onap/pnfsimulator/filesystem/WatcherEventProcessor.java create mode 100644 src/main/java/org/onap/pnfsimulator/filesystem/WatcherService.java create mode 100644 src/main/java/org/onap/pnfsimulator/filesystem/WatcherThread.java create mode 100644 src/main/java/org/onap/pnfsimulator/logging/MdcVariables.java create mode 100644 src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java create mode 100644 src/main/java/org/onap/pnfsimulator/rest/TemplateController.java create mode 100644 src/main/java/org/onap/pnfsimulator/rest/model/FullEvent.java create mode 100644 src/main/java/org/onap/pnfsimulator/rest/model/SearchExp.java create mode 100644 src/main/java/org/onap/pnfsimulator/rest/model/SimulatorParams.java create mode 100644 src/main/java/org/onap/pnfsimulator/rest/model/SimulatorRequest.java create mode 100644 src/main/java/org/onap/pnfsimulator/rest/model/TemplateRequest.java create mode 100644 src/main/java/org/onap/pnfsimulator/rest/util/DateUtil.java create mode 100644 src/main/java/org/onap/pnfsimulator/rest/util/JsonObjectDeserializer.java create mode 100644 src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/DbTemplateReader.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/EventNotFoundException.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/FilesystemTemplateReader.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/IncrementProvider.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/IncrementProviderImpl.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/JsonTokenProcessor.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/KeywordsExtractor.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandler.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandlerException.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/KeywordsValueProvider.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/SimulatorService.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/TemplatePatcher.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/TemplateReader.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/TemplateVariablesReplacer.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/HttpApacheResponseAdapterFactory.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapter.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/HttpResponseAdapter.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/CertAuthSslContextFactory.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/CertificateReader.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/HttpClientFactory.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/HttpClientFactoryFacade.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/PasswordConverter.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SSLContextFactory.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/keywords/Keyword.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/keywords/NonParameterKeyword.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/keywords/SingleParameterKeyword.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeyword.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventJob.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventScheduler.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulator/scheduler/QuartzConfiguration.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulatorconfig/SimulatorConfig.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulatorconfig/SimulatorConfigRepository.java create mode 100644 src/main/java/org/onap/pnfsimulator/simulatorconfig/SimulatorConfigService.java create mode 100644 src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java create mode 100644 src/main/java/org/onap/pnfsimulator/template/Template.java create mode 100644 src/main/java/org/onap/pnfsimulator/template/TemplateRepository.java create mode 100644 src/main/java/org/onap/pnfsimulator/template/TemplateService.java create mode 100644 src/main/java/org/onap/pnfsimulator/template/search/IllegalJsonValueException.java create mode 100644 src/main/java/org/onap/pnfsimulator/template/search/JsonUtils.java create mode 100644 src/main/java/org/onap/pnfsimulator/template/search/TemplateSearchHelper.java create mode 100644 src/main/java/org/onap/pnfsimulator/template/search/handler/PrimitiveValueCriteriaBuilder.java create mode 100644 src/main/java/org/onap/pnfsimulator/template/search/viewmodel/FlatTemplateContent.java create mode 100644 src/main/java/org/onap/pnfsimulator/template/search/viewmodel/KeyValuePair.java (limited to 'src/main/java/org/onap/pnfsimulator') diff --git a/src/main/java/org/onap/pnfsimulator/Main.java b/src/main/java/org/onap/pnfsimulator/Main.java new file mode 100644 index 0000000..708f27f --- /dev/null +++ b/src/main/java/org/onap/pnfsimulator/Main.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 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; + +import javax.annotation.PostConstruct; + +import org.onap.pnfsimulator.filesystem.WatcherService; +import org.onap.pnfsimulator.template.FsToDbTemplateSynchronizer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; + +@SpringBootApplication +@EnableAsync +public class Main { + + private final WatcherService watcherService; + private final FsToDbTemplateSynchronizer fsToDbTemplateSynchronizer; + + @Autowired + public Main(WatcherService watcherService, + FsToDbTemplateSynchronizer fsToDbTemplateSynchronizer) { + this.watcherService = watcherService; + this.fsToDbTemplateSynchronizer = fsToDbTemplateSynchronizer; + } + + // 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); + } + + @PostConstruct + public void createWatchers() { + fsToDbTemplateSynchronizer.synchronize(); + watcherService.createWatcher(); + } +} + + diff --git a/src/main/java/org/onap/pnfsimulator/SwaggerConfig.java b/src/main/java/org/onap/pnfsimulator/SwaggerConfig.java new file mode 100644 index 0000000..b6c6187 --- /dev/null +++ b/src/main/java/org/onap/pnfsimulator/SwaggerConfig.java @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 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; + +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; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableConfigurationProperties(SslAuthenticationHelper.class) +@EnableSwagger2 +public class SwaggerConfig { + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.basePackage("org.onap.pnfsimulator")) + .paths(PathSelectors.any()) + .build(); + } +} diff --git a/src/main/java/org/onap/pnfsimulator/db/Row.java b/src/main/java/org/onap/pnfsimulator/db/Row.java new file mode 100644 index 0000000..12745bf --- /dev/null +++ b/src/main/java/org/onap/pnfsimulator/db/Row.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * Simulator + * ================================================================================ + * Copyright (C) 2019 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.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") + @Getter + @Setter + private String id; + + + public String getId() { + return id; + } +} diff --git a/src/main/java/org/onap/pnfsimulator/db/Storage.java b/src/main/java/org/onap/pnfsimulator/db/Storage.java new file mode 100644 index 0000000..ad98ce0 --- /dev/null +++ b/src/main/java/org/onap/pnfsimulator/db/Storage.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * Simulator + * ================================================================================ + * Copyright (C) 2019 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.db; + +import com.google.gson.JsonObject; + +import java.util.List; +import java.util.Optional; + +public interface Storage { + + List getAll(); + + Optional get(String rowId); + + void persist(T row); + + boolean tryPersistOrOverwrite(T row, boolean overwrite); + + void delete(String rowId); + + List getIdsByContentCriteria(JsonObject queryJson); +} diff --git a/src/main/java/org/onap/pnfsimulator/event/EventData.java b/src/main/java/org/onap/pnfsimulator/event/EventData.java new file mode 100644 index 0000000..ff85367 --- /dev/null +++ b/src/main/java/org/onap/pnfsimulator/event/EventData.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 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.event; + +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; + + @Field("template") + @JsonInclude + private String template; + + @Field("patched") + @JsonInclude + private String patched; + + @Field("input") + @JsonInclude + private String input; + + @Field("keywords") + @JsonInclude + private String keywords; + + @Field("incrementValue") + @JsonInclude + private int incrementValue; + + protected EventData(String id, String template, String patched, String input, String keywords, int incrementValue) { + this.id = id; + this.template = template; + this.patched = patched; + this.input = input; + this.keywords = keywords; + this.incrementValue = incrementValue; + } +} diff --git a/src/main/java/org/onap/pnfsimulator/event/EventDataRepository.java b/src/main/java/org/onap/pnfsimulator/event/EventDataRepository.java new file mode 100644 index 0000000..d1a66ab --- /dev/null +++ b/src/main/java/org/onap/pnfsimulator/event/EventDataRepository.java @@ -0,0 +1,26 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 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.event; + +import org.springframework.data.mongodb.repository.MongoRepository; + +public interface EventDataRepository extends MongoRepository { +} diff --git a/src/main/java/org/onap/pnfsimulator/event/EventDataService.java b/src/main/java/org/onap/pnfsimulator/event/EventDataService.java new file mode 100644 index 0000000..266d56b --- /dev/null +++ b/src/main/java/org/onap/pnfsimulator/event/EventDataService.java @@ -0,0 +1,65 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 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.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 getAllEvents() { + return repository.findAll(); + } + + public Optional getById(String id) { + return repository.findById(id); + } +} diff --git a/src/main/java/org/onap/pnfsimulator/filesystem/WatcherConfig.java b/src/main/java/org/onap/pnfsimulator/filesystem/WatcherConfig.java new file mode 100644 index 0000000..3535e33 --- /dev/null +++ b/src/main/java/org/onap/pnfsimulator/filesystem/WatcherConfig.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * Simulator + * ================================================================================ + * Copyright (C) 2019 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.filesystem; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.task.TaskExecutor; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +@Configuration +public class WatcherConfig { + + @Bean + public TaskExecutor watcherTaskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setThreadNamePrefix("pnfsimulator_fs_watcher"); + executor.initialize(); + return executor; + } + +} diff --git a/src/main/java/org/onap/pnfsimulator/filesystem/WatcherEventProcessor.java b/src/main/java/org/onap/pnfsimulator/filesystem/WatcherEventProcessor.java new file mode 100644 index 0000000..c03491a --- /dev/null +++ b/src/main/java/org/onap/pnfsimulator/filesystem/WatcherEventProcessor.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * Simulator + * ================================================================================ + * Copyright (C) 2019 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.filesystem; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchEvent.Kind; +import java.time.Instant; +import java.util.Arrays; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import lombok.extern.slf4j.Slf4j; +import org.bson.BSONException; +import org.bson.json.JsonParseException; +import org.onap.pnfsimulator.db.Storage; +import org.onap.pnfsimulator.template.Template; +import org.bson.Document; + +@Slf4j +public enum WatcherEventProcessor { + CREATED(StandardWatchEventKinds.ENTRY_CREATE) { + @Override + public void processEvent(Path path, Storage