summaryrefslogtreecommitdiffstats
path: root/datafile-app-server/src/main
diff options
context:
space:
mode:
authormicdzied <michal.1.dziedzic@nokia.com>2019-01-08 09:38:12 +0100
committermicdzied <michal.1.dziedzic@nokia.com>2019-01-08 09:40:22 +0100
commita224b4adbe65b476cdbd74efb3169aacbf292382 (patch)
tree17386959d44d82eb9c65ee3da24c5b862d62eb98 /datafile-app-server/src/main
parentf5791850232005aaf47c639f89f76007c67beff7 (diff)
use sdk-cbs
Change-Id: I615d57927c163d022683ad3cae2703adda48cf88 Issue-ID: DCAEGEN2-1064 Signed-off-by: micdzied <michal.1.dziedzic@nokia.com>
Diffstat (limited to 'datafile-app-server/src/main')
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfiguration.java18
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/EnvironmentProcessor.java4
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/EnvProperties.java41
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DatafileConfigurationProvider.java102
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/HttpGetClient.java91
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java2
6 files changed, 11 insertions, 247 deletions
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfiguration.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfiguration.java
index f7722053..34ccd76c 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfiguration.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfiguration.java
@@ -23,13 +23,14 @@ import java.util.Properties;
import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
-import org.onap.dcaegen2.collectors.datafile.model.EnvProperties;
-import org.onap.dcaegen2.collectors.datafile.service.DatafileConfigurationProvider;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuration.EnvProperties;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.ReactiveCloudConfigurationProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -42,14 +43,13 @@ import reactor.core.scheduler.Schedulers;
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Configuration
+@ComponentScan("org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers")
@EnableConfigurationProperties
@EnableScheduling
@Primary
-public class CloudConfiguration extends AppConfig {
-
+public class CloudConfiguration extends AppConfig {
private static final Logger logger = LoggerFactory.getLogger(CloudConfiguration.class);
-
- private DatafileConfigurationProvider datafileConfigurationProvider;
+ private ReactiveCloudConfigurationProvider reactiveCloudConfigurationProvider;
private DmaapPublisherConfiguration dmaapPublisherCloudConfiguration;
private DmaapConsumerConfiguration dmaapConsumerCloudConfiguration;
private FtpesConfig ftpesCloudConfiguration;
@@ -58,8 +58,8 @@ public class CloudConfiguration extends AppConfig {
private Properties systemEnvironment;
@Autowired
- public void setThreadPoolTaskScheduler(DatafileConfigurationProvider datafileConfigurationProvider) {
- this.datafileConfigurationProvider = datafileConfigurationProvider;
+ public void setThreadPoolTaskScheduler(ReactiveCloudConfigurationProvider reactiveCloudConfigurationProvider) {
+ this.reactiveCloudConfigurationProvider = reactiveCloudConfigurationProvider;
}
@@ -78,7 +78,7 @@ public class CloudConfiguration extends AppConfig {
private void parsingConfigSuccess(EnvProperties envProperties) {
logger.info("Fetching Datafile Collector configuration from ConfigBindingService/Consul");
- datafileConfigurationProvider.callForDataFileCollectorConfiguration(envProperties)
+ reactiveCloudConfigurationProvider.callForServiceConfigurationReactive(envProperties)
.subscribe(this::parseCloudConfig, this::cloudConfigError);
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/EnvironmentProcessor.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/EnvironmentProcessor.java
index 9f6b2737..106725ce 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/EnvironmentProcessor.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/EnvironmentProcessor.java
@@ -21,8 +21,8 @@ package org.onap.dcaegen2.collectors.datafile.configuration;
import java.util.Optional;
import java.util.Properties;
import org.onap.dcaegen2.collectors.datafile.exceptions.EnvironmentLoaderException;
-import org.onap.dcaegen2.collectors.datafile.model.EnvProperties;
-import org.onap.dcaegen2.collectors.datafile.model.ImmutableEnvProperties;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuration.EnvProperties;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuration.ImmutableEnvProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/EnvProperties.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/EnvProperties.java
deleted file mode 100644
index 86549343..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/EnvProperties.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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.dcaegen2.collectors.datafile.model;
-
-import org.immutables.value.Value;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 9/19/18
- */
-@Value.Immutable(prehash = true)
-public interface EnvProperties {
-
- @Value.Parameter
- String consulHost();
-
- @Value.Parameter
- Integer consulPort();
-
- @Value.Parameter
- String cbsName();
-
- @Value.Parameter
- String appName();
-
-}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DatafileConfigurationProvider.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DatafileConfigurationProvider.java
deleted file mode 100644
index aca87e5b..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DatafileConfigurationProvider.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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.dcaegen2.collectors.datafile.service;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-import org.onap.dcaegen2.collectors.datafile.model.EnvProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-import org.springframework.web.util.DefaultUriBuilderFactory;
-import reactor.core.publisher.Mono;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 9/19/18
- */
-@Service
-public class DatafileConfigurationProvider {
-
- private static final Logger logger = LoggerFactory.getLogger(DatafileConfigurationProvider.class);
-
- private final HttpGetClient httpGetClient;
-
- DatafileConfigurationProvider() {
- this(new HttpGetClient());
- }
-
- DatafileConfigurationProvider(HttpGetClient httpGetClient) {
- this.httpGetClient = httpGetClient;
- }
-
- public Mono<JsonObject> callForDataFileCollectorConfiguration(EnvProperties envProperties) {
- return callConsulForConfigBindingServiceEndpoint(envProperties)
- .flatMap(this::callConfigBindingServiceForDatafileConfiguration);
- }
-
- private Mono<String> callConsulForConfigBindingServiceEndpoint(EnvProperties envProperties) {
- logger.info("Retrieving Config Binding Service endpoint from Consul");
- return httpGetClient.callHttpGet(getConsulUrl(envProperties), JsonArray.class)
- .flatMap(jsonArray -> this.createConfigBindingServiceUrl(jsonArray, envProperties.appName()));
-
- }
-
- private String getConsulUrl(EnvProperties envProperties) {
- return getUri(envProperties.consulHost(), envProperties.consulPort(), "/v1/catalog/service",
- envProperties.cbsName());
- }
-
- private Mono<JsonObject> callConfigBindingServiceForDatafileConfiguration(String configBindingServiceUri) {
- logger.info("Retrieving Datafile configuration");
- return httpGetClient.callHttpGet(configBindingServiceUri, JsonObject.class);
- }
-
-
- private Mono<String> createConfigBindingServiceUrl(JsonArray jsonArray, String appName) {
- return getConfigBindingObject(jsonArray)
- .flatMap(jsonObject -> buildConfigBindingServiceUrl(jsonObject, appName));
- }
-
- private Mono<String> buildConfigBindingServiceUrl(JsonObject jsonObject, String appName) {
- return Mono.just(getUri(jsonObject.get("ServiceAddress").getAsString(),
- jsonObject.get("ServicePort").getAsInt(), "/service_component", appName));
- }
-
- private Mono<JsonObject> getConfigBindingObject(JsonArray jsonArray) {
- try {
- if (jsonArray.size() > 0) {
- return Mono.just(jsonArray.get(0).getAsJsonObject());
- } else {
- throw new IllegalStateException("JSON Array was empty");
- }
- } catch (IllegalStateException e) {
- logger.warn("Failed to retrieve JSON Object from array", e);
- return Mono.error(e);
- }
- }
-
- private String getUri(String host, Integer port, String... paths) {
- return new DefaultUriBuilderFactory().builder()
- .scheme("http")
- .host(host)
- .port(port)
- .path(String.join("/", paths))
- .build().toString();
- }
-}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/HttpGetClient.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/HttpGetClient.java
deleted file mode 100644
index 796dbbd8..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/HttpGetClient.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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.dcaegen2.collectors.datafile.service;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonSyntaxException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.reactive.function.client.ClientResponse;
-import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
-import org.springframework.web.reactive.function.client.WebClient;
-import reactor.core.publisher.Mono;
-
-
-public class HttpGetClient {
-
- private static final Logger logger = LoggerFactory.getLogger(HttpGetClient.class);
-
- private final WebClient webClient;
- private final Gson gson;
-
- HttpGetClient() {
- this(WebClient.builder().filter(logRequest()).filter(logResponse()).build());
- }
-
- HttpGetClient(WebClient webClient) {
- this.webClient = webClient;
- this.gson = new Gson();
- }
-
- <T> Mono<T> callHttpGet(String url, Class<T> genericClassDeclaration) {
- return webClient
- .get()
- .uri(url)
- .retrieve()
- .onStatus(HttpStatus::is4xxClientError, response -> Mono.error(getException(response)))
- .onStatus(HttpStatus::is5xxServerError, response -> Mono.error(getException(response)))
- .bodyToMono(String.class)
- .flatMap(body -> getJsonFromRequest(body, genericClassDeclaration));
- }
-
- private RuntimeException getException(ClientResponse response) {
- return new RuntimeException(String.format("Request for cloud config failed: HTTP %d",
- response.statusCode().value()));
- }
-
- private <T> Mono<T> getJsonFromRequest(String body, Class<T> genericClassDeclaration) {
- try {
- return Mono.just(parseJson(body, genericClassDeclaration));
- } catch (JsonSyntaxException | IllegalStateException e) {
- return Mono.error(e);
- }
- }
-
- private <T> T parseJson(String body, Class<T> genericClassDeclaration) {
- return gson.fromJson(body, genericClassDeclaration);
- }
-
- private static ExchangeFilterFunction logResponse() {
- return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
- logger.info("Response status {}", clientResponse.statusCode());
- return Mono.just(clientResponse);
- });
- }
-
- private static ExchangeFilterFunction logRequest() {
- return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> {
- logger.info("Request: {} {}", clientRequest.method(), clientRequest.url());
- clientRequest.headers()
- .forEach((name, values) -> values.forEach(value -> logger.info("{}={}", name, value)));
- return Mono.just(clientRequest);
- });
- }
-}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java
index b861653a..c03d903a 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java
@@ -47,10 +47,8 @@ public class XnfCollectorTaskImpl implements XnfCollectorTask {
private static final String FTPES = "ftpes";
private static final String FTPS = "ftps";
private static final String SFTP = "sftp";
-
private static final Logger logger = LoggerFactory.getLogger(XnfCollectorTaskImpl.class);
private Config datafileAppConfig;
-
private final FtpsClient ftpsClient;
private final SftpClient sftpClient;
private RetryTimer retryTimer;