--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * PROJECT
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018 Nokia. All rights reserved.s
+ * ================================================================================
+ * 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;
+
+import java.io.IOException;
+import org.apache.commons.configuration.ConfigurationException;
+
+public class ApplicationException extends RuntimeException {
+
+ public ApplicationException(ConfigurationException ex) {
+ super(ex);
+ }
+
+ public ApplicationException(String message, Exception ex) {
+ super(message,ex);
+ }
+
+ public ApplicationException(IOException ex) {
+ super(ex);
+ }
+}
package org.onap.dcae;
+import static io.vavr.API.Tuple;
+import static java.lang.String.format;
+import static java.nio.file.Files.readAllBytes;
+
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.JsonLoader;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import io.vavr.collection.HashMap;
import io.vavr.collection.List;
import io.vavr.collection.Map;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import javax.annotation.Nullable;
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 javax.annotation.Nullable;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Base64;
-
-import static io.vavr.API.Tuple;
-import static java.lang.String.format;
-import static java.nio.file.Files.readAllBytes;
-import static java.util.Arrays.stream;
-
/**
* Abstraction over application configuration.
* Its job is to provide easily discoverable (by method names lookup) and type safe access to configuration properties.
Map<String, String> parsedArgs = argsParser.apply(args);
configurationFileLocation = findOutConfigurationFileLocation(parsedArgs);
loadPropertiesFromFile();
- parsedArgs.filterKeys(k -> !k.equals("c")).forEach(this::updateProperty);
+ parsedArgs.filterKeys(k -> !"c".equals(k)).forEach(this::updateProperty);
loadedJsonSchemas = loadJsonSchemas();
}
properties.load(configurationFileLocation);
} catch (ConfigurationException ex) {
log.error("Cannot load properties cause:", ex);
- throw new RuntimeException(ex);
+ throw new ApplicationException(ex);
}
}
private Map<String, JsonSchema> loadJsonSchemas() {
return jsonSchema().toMap().entrySet().stream()
- .map(versionToFilePath -> readSchemaForVersion(versionToFilePath))
+ .map(this::readSchemaForVersion)
.collect(HashMap.collector());
}
JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema(schemaNode);
return Tuple(versionToFilePath.getKey(), schema);
} catch (IOException | ProcessingException e) {
- throw new RuntimeException("Could not read schema from path: " + versionToFilePath.getValue(), e);
+ throw new ApplicationException("Could not read schema from path: " + versionToFilePath.getValue(), e);
}
}
Paths.get(properties.dMaaPConfigurationFileLocation()),
properties.configurationFileLocation());
scheduledThreadPoolExecutor
- .scheduleAtFixedRate(() -> configLoader.updateConfig(),
+ .scheduleAtFixedRate(configLoader::updateConfig,
properties.configurationUpdateFrequency(),
properties.configurationUpdateFrequency(),
TimeUnit.MINUTES);
public Option<AnyNode> getAsOption(String key) {
try {
AnyNode value = get(key);
- if (value.toString().equals("null")) {
+ if ("null".equals(value.toString())) {
return Option.none();
}
return Option.some(value);
private final DMaaPPublishersCache publishersCache;
private final Logger outputLogger;
- DMaaPEventPublisher(DMaaPPublishersCache DMaaPPublishersCache,
+ DMaaPEventPublisher(DMaaPPublishersCache publishersCache,
Logger outputLogger) {
- this.publishersCache = DMaaPPublishersCache;
+ this.publishersCache = publishersCache;
this.outputLogger = outputLogger;
}
Try<Map<String, String>> readCollectorProperties() {
log.info(f("Reading collector properties from path: '%s'", propertiesPath));
- return Try(() -> readProperties())
+ 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))
log.info("Trying to dynamically update config from Config Binding Service");
readEnvProps(envVariablesSupplier.get())
.onEmpty(() -> log.warn(SKIP_MSG))
- .forEach(props -> updateConfig(props));
+ .forEach(this::updateConfig);
}
private void updateConfig(EnvProps props) {
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;
log.info("Fetching app configuration from CBS");
return callConsulForCBSConfiguration(envProps)
.peek(strBody -> log.info(f("Received following CBS configuration from Consul '%s'", strBody)))
- .flatMap(strBody -> toJsonArray(strBody))
- .flatMap(json -> withdrawCatalog(json))
+ .flatMap(Conversions::toJsonArray)
+ .flatMap(ConfigSource::withdrawCatalog)
.flatMap(json -> constructFullCBSUrl(envProps, json))
.flatMap(cbsUrl -> callCBSForAppConfig(envProps, cbsUrl))
- .flatMap(strBody -> toJson(strBody))
+ .flatMap(Conversions::toJson)
.peek(jsonNode -> log.info(f("Received app configuration: '%s'", jsonNode)))
.onFailure(exc -> log.error("Could not fetch application config", exc));
}
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(res -> res.getBody())
+ .map(HttpResponse::getBody)
.peek(body -> log.info(f("HTTP GET on '%s' returned body '%s'", url, body)));
}
package org.onap.dcae.restapi;
+import org.onap.dcae.ApplicationException;
import org.onap.dcae.ApplicationSettings;
import org.onap.dcae.common.SSLContextCreator;
import org.slf4j.Logger;
return new String(readAllBytes(location));
} catch (IOException e) {
log.error("Could not read keystore password from: '" + location + "'.", e);
- throw new RuntimeException(e);
+ throw new ApplicationException(e);
}
}
}
\ No newline at end of file
import org.json.JSONArray;
import org.json.JSONObject;
+import org.onap.dcae.ApplicationException;
import org.onap.dcae.ApplicationSettings;
import org.onap.dcae.common.VESLogger;
import org.slf4j.Logger;
}
return report.isSuccess();
} catch (Exception e) {
- throw new RuntimeException("Unable to validate against schema", e);
+ throw new ApplicationException("Unable to validate against schema", e);
}
}