diff options
author | Pawel <pawel.kasperkiewicz@nokia.com> | 2020-07-30 16:30:39 +0200 |
---|---|---|
committer | Pawel <pawel.kasperkiewicz@nokia.com> | 2020-08-26 08:42:44 +0200 |
commit | 50592c30fed4908bbf860f9018cc5f94f8bd2303 (patch) | |
tree | 151aefb0b21e3fbabc89c39a5731643bbbdd4edb /src/main/java/org/onap/dcae/controller | |
parent | 79efedef7af08038b49821c410db1b11e038f653 (diff) |
Config fetch for VESCollector through DCAE-SDK (CBS Client)
Issue-ID: DCAEGEN2-2212
Signed-off-by: Pawel <pawel.kasperkiewicz@nokia.com>
Change-Id: I25072b340b5c9f2f538d39e5befb1331804b7bba
Signed-off-by: Pawel <pawel.kasperkiewicz@nokia.com>
Diffstat (limited to 'src/main/java/org/onap/dcae/controller')
7 files changed, 0 insertions, 648 deletions
diff --git a/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java b/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java deleted file mode 100644 index 0b2c197d..00000000 --- a/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java +++ /dev/null @@ -1,130 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.onap.dcaegen2.collectors.ves - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * 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.dcae.controller; - -import io.vavr.CheckedRunnable; -import io.vavr.Tuple2; -import io.vavr.collection.Map; -import io.vavr.control.Try; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.FileNotFoundException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; - -import static io.vavr.API.Try; -import static org.onap.dcae.common.publishing.VavrUtils.*; -import static org.onap.dcae.controller.Conversions.toList; - -class ConfigFilesFacade { - - private static Logger log = LoggerFactory.getLogger(ConfigFilesFacade.class); - - private final Path dMaaPConfigPath; - private final Path propertiesPath; - - public ConfigFilesFacade(Path dMaaPConfigPath, Path propertiesPath) { - this.dMaaPConfigPath = dMaaPConfigPath; - this.propertiesPath = propertiesPath; - } - - Try<Map<String, String>> readCollectorProperties() { - log.info(f("Reading collector properties from path: '%s'", propertiesPath)); - return Try(this::readProperties) - .map(prop -> toList(prop.getKeys()).toMap(k -> k, k -> (String) prop.getProperty(k))) - .mapFailure(enhanceError("Unable to read properties configuration from path '%s'", propertiesPath)) - .onFailure(logError(log)) - .peek(props -> log.info(f("Read following collector properties: '%s'", props))); - } - - Try<JSONObject> readDMaaPConfiguration() { - log.info(f("Reading DMaaP configuration from file: '%s'", dMaaPConfigPath)); - return readFile(dMaaPConfigPath) - .recover(FileNotFoundException.class, __ -> "{}") - .mapFailure(enhanceError("Unable to read DMaaP configuration from file '%s'", dMaaPConfigPath)) - .flatMap(Conversions::toJson) - .onFailure(logError(log)) - .peek(props -> log.info(f("Read following DMaaP properties: '%s'", props))); - } - - Try<Void> writeDMaaPConfiguration(JSONObject dMaaPConfiguration) { - log.info(f("Writing DMaaP configuration '%s' into file '%s'", dMaaPConfiguration, dMaaPConfigPath)); - return writeFile(dMaaPConfigPath, indentConfiguration(dMaaPConfiguration.toString())) - .mapFailure(enhanceError("Could not save new DMaaP configuration to path '%s'", dMaaPConfigPath)) - .onFailure(logError(log)) - .peek(__ -> log.info("Written successfully")); - } - - - Try<Void> writeProperties(Map<String, String> properties) { - log.info(f("Writing properties configuration '%s' into file '%s'", properties, propertiesPath)); - return Try.run(saveProperties(properties)) - .mapFailure(enhanceError("Could not save properties to path '%s'", properties)) - .onFailure(logError(log)) - .peek(__ -> log.info("Written successfully")); - } - - private Try<String> readFile(Path path) { - return Try(() -> new String(Files.readAllBytes(path), StandardCharsets.UTF_8)) - .mapFailure(enhanceError("Could not read content from path: '%s'", path)); - } - - private Try<Void> writeFile(Path path, String content) { - return Try.run(() -> Files.write(path, content.getBytes())) - .mapFailure(enhanceError("Could not write content to path: '%s'", path)); - } - - private PropertiesConfiguration readProperties() throws ConfigurationException { - PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); - propertiesConfiguration.setDelimiterParsingDisabled(true); - propertiesConfiguration.load(propertiesPath.toFile()); - return propertiesConfiguration; - } - - private CheckedRunnable saveProperties(Map<String, String> properties) { - return () -> { - PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(propertiesPath.toFile()); - propertiesConfiguration.setEncoding(null); - for (Tuple2<String, String> property : properties) { - updateProperty(propertiesConfiguration, property); - } - propertiesConfiguration.save(); - }; - } - - private void updateProperty(PropertiesConfiguration propertiesConfiguration, Tuple2<String, String> property) { - if (propertiesConfiguration.containsKey(property._1)) { - propertiesConfiguration.setProperty(property._1, property._2); - } else { - propertiesConfiguration.addProperty(property._1, property._2); - } - } - - private String indentConfiguration(String configuration) { - return new JSONObject(configuration).toString(4); - } - -} diff --git a/src/main/java/org/onap/dcae/controller/ConfigLoader.java b/src/main/java/org/onap/dcae/controller/ConfigLoader.java deleted file mode 100644 index dbf52823..00000000 --- a/src/main/java/org/onap/dcae/controller/ConfigLoader.java +++ /dev/null @@ -1,144 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.onap.dcaegen2.collectors.ves - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * 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.dcae.controller; - -import static org.onap.dcae.common.publishing.DMaaPConfigurationParser.parseToDomainMapping; -import static org.onap.dcae.controller.ConfigParsing.getDMaaPConfig; -import static org.onap.dcae.controller.ConfigParsing.getProperties; -import static org.onap.dcae.controller.EnvPropertiesReader.readEnvProps; - -import io.vavr.Function0; -import io.vavr.Function1; -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import io.vavr.control.Try; -import java.nio.file.Path; -import java.util.function.Consumer; -import org.json.JSONObject; -import org.onap.dcae.VesApplication; -import org.onap.dcae.common.publishing.PublisherConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ConfigLoader { - - private static final String SKIP_MSG = "Skipping dynamic configuration update"; - private static Logger log = LoggerFactory.getLogger(ConfigLoader.class); - private final Consumer<Map<String, PublisherConfig>> eventPublisherReconfigurer; - private final ConfigFilesFacade configFilesFacade; - private final Function1<EnvProps, Try<JSONObject>> configurationSource; - private final Function0<Map<String, String>> envVariablesSupplier; - private boolean toRestart = false; - - ConfigLoader(Consumer<Map<String, PublisherConfig>> eventPublisherReconfigurer, - ConfigFilesFacade configFilesFacade, - Function1<EnvProps, Try<JSONObject>> configurationSource, - Function0<Map<String, String>> envVariablesSupplier) { - this.eventPublisherReconfigurer = eventPublisherReconfigurer; - this.configFilesFacade = configFilesFacade; - this.configurationSource = configurationSource; - this.envVariablesSupplier = envVariablesSupplier; - } - - public static ConfigLoader create( - Consumer<Map<String, PublisherConfig>> eventPublisherReconfigurer, - Path dMaaPConfigFile, Path propertiesConfigFile) { - return new ConfigLoader(eventPublisherReconfigurer, - new ConfigFilesFacade(dMaaPConfigFile, propertiesConfigFile), - ConfigSource::getAppConfig, - () -> HashMap.ofAll(System.getenv())); - } - - public void updateConfig() { - log.info("Trying to dynamically update config from Config Binding Service"); - readEnvProps(envVariablesSupplier.get()) - .onEmpty(() -> log.warn(SKIP_MSG)).forEach(this::updateConfig); - } - - private void updateConfig(EnvProps props) { - configurationSource.apply(props) - .onFailure(logSkip()) - .onSuccess(newConf -> { - updateConfigurationProperties(newConf); - updateDMaaPProperties(newConf); - reloadApplication(); - } - ); - } - - private void reloadApplication() { - if(toRestart){ - log.info("New app config - Application will be restarted"); - VesApplication.restartApplication(); - } - } - - private void updateDMaaPProperties(JSONObject newConf) { - configFilesFacade.readDMaaPConfiguration() - .onFailure(logSkip()) - .onSuccess(oldDMaaPConf -> getDMaaPConfig(newConf) - .onEmpty(() -> log.warn(SKIP_MSG)) - .forEach(newDMaaPConf -> compareAndOverwriteDMaaPConfig(oldDMaaPConf, newDMaaPConf))); - } - - - private void updateConfigurationProperties(JSONObject newConf) { - configFilesFacade.readCollectorProperties() - .onFailure(logSkip()) - .onSuccess(oldProps -> compareAndOverwritePropertiesConfig(newConf, oldProps)); - } - - private void compareAndOverwritePropertiesConfig(JSONObject newConf, Map<String, String> oldProps) { - Map<String, String> newProperties = getProperties(newConf); - Map<String, String> result = oldProps.filterKeys((s) -> newProperties.keySet().contains(s)); - if (!result.equals(newProperties)) { - configFilesFacade.writeProperties(newProperties) - .onSuccess(__ -> { - toRestart= true; - log.info("New properties configuration written to file"); - }) - .onFailure(logSkip()); - } else { - log.info("Collector properties from CBS are the same as currently used ones. " + SKIP_MSG); - } - } - - private void compareAndOverwriteDMaaPConfig(JSONObject oldDMaaPConf, JSONObject newDMaaPConf) { - if (!oldDMaaPConf.toString().equals(newDMaaPConf.toString())) { - parseToDomainMapping(newDMaaPConf) - .onFailure(exc -> log.error(SKIP_MSG, exc)) - .onSuccess(eventPublisherReconfigurer) - .onSuccess(parsedConfig -> - configFilesFacade.writeDMaaPConfiguration(newDMaaPConf) - .onFailure(logSkip()) - .onSuccess(__ -> { - toRestart= true; - log.info("New dMaaP configuration written to file"); - })); - } else { - log.info("DMaaP config from CBS is the same as currently used one. " + SKIP_MSG); - } - } - - private Consumer<Throwable> logSkip() { - return __ -> log.error(SKIP_MSG); - } -} diff --git a/src/main/java/org/onap/dcae/controller/ConfigParsing.java b/src/main/java/org/onap/dcae/controller/ConfigParsing.java deleted file mode 100644 index e1644222..00000000 --- a/src/main/java/org/onap/dcae/controller/ConfigParsing.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.onap.dcaegen2.collectors.ves - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * 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.dcae.controller; - -import static io.vavr.API.Try; -import static io.vavr.API.Tuple; -import static org.onap.dcae.common.publishing.VavrUtils.f; -import static org.onap.dcae.controller.Conversions.toList; - -import io.vavr.collection.Map; -import io.vavr.control.Option; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -interface ConfigParsing { - - Logger log = LoggerFactory.getLogger(ConfigParsing.class); - - static Option<JSONObject> getDMaaPConfig(JSONObject configuration) { - log.info(f("Getting DMaaP configuration from app configuration: '%s'", configuration)); - return toList(configuration.toMap().entrySet().iterator()) - .filter(t -> t.getKey().startsWith("streams_publishes")) - .headOption() - .flatMap(e -> Try(() -> configuration.getJSONObject(e.getKey())).toOption()) - .onEmpty(() -> log.warn(f("App configuration '%s' is missing DMaaP configuration ('streams_publishes' key) " - + "or DMaaP configuration is not a valid json document", configuration))) - .peek(dMaaPConf -> log.info(f("Found following DMaaP configuration: '%s'", dMaaPConf))); - } - - static Map<String, String> getProperties(JSONObject configuration) { - log.info(f("Getting properties configuration from app configuration: '%s'", configuration)); - Map<String, String> confEntries = toList(configuration.toMap().entrySet().iterator()) - .toMap(e -> Tuple(e.getKey(), String.valueOf(e.getValue()))) - .filterKeys(e -> !e.startsWith("streams_publishes")); - log.info(f("Found following app properties: '%s'", confEntries)); - return confEntries; - } - -} diff --git a/src/main/java/org/onap/dcae/controller/ConfigSource.java b/src/main/java/org/onap/dcae/controller/ConfigSource.java deleted file mode 100644 index a9e439e4..00000000 --- a/src/main/java/org/onap/dcae/controller/ConfigSource.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.onap.dcaegen2.collectors.ves - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * 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.dcae.controller; - -import static io.vavr.API.Try; -import static org.onap.dcae.common.publishing.VavrUtils.enhanceError; -import static org.onap.dcae.common.publishing.VavrUtils.f; -import static org.onap.dcae.controller.Conversions.toJson; -import static org.onap.dcae.controller.Conversions.toJsonArray; - -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.Unirest; -import io.vavr.control.Try; -import org.json.JSONArray; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -final class ConfigSource { - - private static final Logger log = LoggerFactory.getLogger(ConfigSource.class); - - static Try<JSONObject> getAppConfig(EnvProps envProps) { - log.info("Fetching app configuration from CBS"); - return callConsulForCBSConfiguration(envProps) - .peek(strBody -> log.info(f("Received following CBS configuration from Consul '%s'", strBody))) - .flatMap(Conversions::toJsonArray) - .flatMap(ConfigSource::withdrawCatalog) - .flatMap(json -> constructFullCBSUrl(envProps, json)) - .flatMap(cbsUrl -> callCBSForAppConfig(envProps, cbsUrl)) - .flatMap(Conversions::toJson) - .peek(jsonNode -> log.info(f("Received app configuration: '%s'", jsonNode))) - .onFailure(exc -> log.error("Could not fetch application config", exc)); - } - - private static Try<String> callConsulForCBSConfiguration(EnvProps envProps) { - return executeGet(envProps.consulProtocol + "://" + envProps.consulHost + ":" + - envProps.consulPort + "/v1/catalog/service/" + envProps.cbsName) - .mapFailure(enhanceError("Unable to retrieve CBS configuration from Consul")); - } - - private static Try<String> constructFullCBSUrl(EnvProps envProps, JSONObject json) { - return Try(() -> envProps.cbsProtocol + "://" + json.get("ServiceAddress").toString() + ":" + - json.get("ServicePort").toString()) - .mapFailure(enhanceError("ServiceAddress / ServicePort missing from CBS conf: '%s'", json)); - } - - private static Try<JSONObject> withdrawCatalog(JSONArray json) { - return Try(() -> new JSONObject(json.get(0).toString())) - .mapFailure(enhanceError("CBS response '%s' is in invalid format," - + " most probably is it not a list of configuration objects", json)); - } - - private static Try<String> callCBSForAppConfig(EnvProps envProps, String cbsUrl) { - log.info("Calling CBS for application config"); - return executeGet(cbsUrl + "/service_component/" + envProps.appName) - .mapFailure(enhanceError("Unable to fetch configuration from CBS")); - } - - - private static Try<String> executeGet(String url) { - log.info(f("Calling HTTP GET on url: '%s'", url)); - return Try(() -> Unirest.get(url).asString()) - .mapFailure(enhanceError("Http call (GET '%s') failed.", url)) - .filter( - res -> res.getStatus() == 200, - res -> new RuntimeException(f("HTTP call (GET '%s') failed with status %s and body '%s'", - url, res.getStatus(), res.getBody()))) - .map(HttpResponse::getBody) - .peek(body -> log.info(f("HTTP GET on '%s' returned body '%s'", url, body))); - } - -} diff --git a/src/main/java/org/onap/dcae/controller/Conversions.java b/src/main/java/org/onap/dcae/controller/Conversions.java deleted file mode 100644 index e8f7cc0c..00000000 --- a/src/main/java/org/onap/dcae/controller/Conversions.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.onap.dcaegen2.collectors.ves - * ================================================================================ - * 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.dcae.controller; - -import static org.onap.dcae.common.publishing.VavrUtils.enhanceError; - -import io.vavr.API; -import io.vavr.collection.List; -import io.vavr.control.Try; -import java.util.Iterator; -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.stream.StreamSupport; -import org.json.JSONArray; -import org.json.JSONObject; - -/** - * @author Pawel Szalapski (pawel.szalapski@nokia.com) - */ -interface Conversions { - - static Try<JSONObject> toJson(String strBody) { - return API.Try(() -> new JSONObject(strBody)) - .mapFailure(enhanceError("Value '%s' is not a valid JSON document", strBody)); - } - - static Try<JSONArray> toJsonArray(String strBody) { - return API.Try(() -> new JSONArray(strBody)) - .mapFailure(enhanceError("Value '%s' is not a valid JSON array", strBody)); - } - - static <T> List<T> toList(Iterator<T> iterator) { - return List.ofAll(StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)); - } - -} diff --git a/src/main/java/org/onap/dcae/controller/EnvPropertiesReader.java b/src/main/java/org/onap/dcae/controller/EnvPropertiesReader.java deleted file mode 100644 index 319caa65..00000000 --- a/src/main/java/org/onap/dcae/controller/EnvPropertiesReader.java +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.onap.dcaegen2.collectors.ves - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * 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.dcae.controller; - -import io.vavr.collection.Map; -import io.vavr.control.Option; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static io.vavr.API.List; -import static io.vavr.API.Try; -import static org.onap.dcae.common.publishing.VavrUtils.f; - -final class EnvPropertiesReader { - - private final static Logger log = LoggerFactory.getLogger(EnvPropertiesReader.class); - - static Option<EnvProps> readEnvProps(Map<String, String> environmentVariables) { - log.info("Loading necessary environment variables for dynamic configuration update"); - int consulPort = getConsulPort(environmentVariables); - String consulProtocol = getConsulProtocol(environmentVariables); - String cbsProtocol = getCbsProtocol(environmentVariables); - Option<String> consulHost = getConsulHost(environmentVariables); - Option<String> cbsServiceName = getCBSName(environmentVariables); - Option<String> vesCollectorAppName = getAppName(environmentVariables); - return Option.sequence(List(consulHost, cbsServiceName, vesCollectorAppName)) - .map(e -> new EnvProps(consulProtocol, e.get(0), consulPort, cbsProtocol, e.get(1), e.get(2))) - .onEmpty(() -> log.warn("Some required environment variables are missing")) - .peek(props -> log.info(f("Discovered following environment variables: '%s'", props))); - } - - private static Option<String> getAppName(Map<String, String> environmentVariables) { - return environmentVariables.get("HOSTNAME") - .orElse(environmentVariables.get("SERVICE_NAME")) - .onEmpty(() -> log.warn("App service name (as registered in CBS) (env var: 'HOSTNAME' / 'SERVICE_NAME') " - + "is missing error environment variables.")); - } - - private static Option<String> getCBSName(Map<String, String> environmentVariables) { - return environmentVariables.get("CONFIG_BINDING_SERVICE") - .onEmpty(() -> log.warn("Name of CBS Service (as registered in Consul) (env var: 'CONFIG_BINDING_SERVICE') " - + "is missing from environment variables.")); - } - - private static Integer getConsulPort(Map<String, String> environmentVariables) { - return environmentVariables.get("CONSUL_PORT") - .flatMap(str -> Try(() -> Integer.valueOf(str)) - .onFailure(exc -> log.warn("Consul port is not an integer value", exc)) - .toOption()) - .onEmpty(() -> log.warn("Consul port (env var: 'CONSUL_PORT') is missing from environment variables. " - + "Using default value of 8500")) - .getOrElse(8500); - } - - private static Option<String> getConsulHost(Map<String, String> environmentVariables) { - return environmentVariables.get("CONSUL_HOST") - .onEmpty(() -> log.warn("Consul host (env var: 'CONSUL_HOST') (without port) " - + "is missing from environment variables.")); - } - - private static String getConsulProtocol(Map<String, String> environmentVariables) { - return getProtocolFrom("CONSUL_PROTOCOL", environmentVariables); - } - - private static String getCbsProtocol(Map<String, String> environmentVariables) { - return getProtocolFrom("CBS_PROTOCOL", environmentVariables); - } - - private static String getProtocolFrom(String variableName, Map<String, String> environmentVariables) { - return environmentVariables.get(variableName) - .onEmpty(() -> log.warn("Consul protocol (env var: '" + variableName + "') is missing " - + "from environment variables.")) - .getOrElse("http"); - } - -} diff --git a/src/main/java/org/onap/dcae/controller/EnvProps.java b/src/main/java/org/onap/dcae/controller/EnvProps.java deleted file mode 100644 index 5f7d08d5..00000000 --- a/src/main/java/org/onap/dcae/controller/EnvProps.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.onap.dcaegen2.collectors.ves - * ================================================================================ - * 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.dcae.controller; - -import java.util.Objects; - -/** - * @author Pawel Szalapski (pawel.szalapski@nokia.com) - */ -final class EnvProps { - - final String consulProtocol; - final String consulHost; - final int consulPort; - final String cbsName; - final String cbsProtocol; - final String appName; - - EnvProps(String consulProtocol, String consulHost, int consulPort, String cbsProtocol, String cbsName, String appName) { - this.consulProtocol = consulProtocol; - this.consulHost = consulHost; - this.consulPort = consulPort; - this.cbsProtocol = cbsProtocol; - this.cbsName = cbsName; - this.appName = appName; - } - - @Override - public String toString() { - return "EnvProps{" + - "consulProtocol='" + consulProtocol + '\'' + - ", consulHost='" + consulHost + '\'' + - ", consulPort=" + consulPort + - ", cbsProtocol='" + cbsProtocol + '\'' + - ", cbsName='" + cbsName + '\'' + - ", appName='" + appName + '\'' + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - EnvProps envProps = (EnvProps) o; - return consulPort == envProps.consulPort && - Objects.equals(consulProtocol, envProps.consulProtocol) && - Objects.equals(consulHost, envProps.consulHost) && - Objects.equals(cbsProtocol, envProps.cbsProtocol) && - Objects.equals(cbsName, envProps.cbsName) && - Objects.equals(appName, envProps.appName); - } - - @Override - public int hashCode() { - return Objects.hash(consulProtocol, consulHost, consulPort, cbsProtocol, cbsName, appName); - } -}
\ No newline at end of file |