When an invalid configuartion was entered (from file of from consul)
the periodic polling for updates was stopped. This is fixed.
Improved error messages when an invalid configiration was intered.
Previuosly it often was just a NullPointerException when a mandatory
element was not found. Now, the missing element will be logged.
Change-Id: Id28dd268429c0174a84f490e6fb48ef5614c0966
Issue-ID: NONRTRIC-204
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
JsonObject ricAsJson = ricElem.getAsJsonObject();
JsonElement controllerNameElement = ricAsJson.get(CONTROLLER);
ImmutableRicConfig ricConfig = ImmutableRicConfig.builder() //
JsonObject ricAsJson = ricElem.getAsJsonObject();
JsonElement controllerNameElement = ricAsJson.get(CONTROLLER);
ImmutableRicConfig ricConfig = ImmutableRicConfig.builder() //
- .name(ricAsJson.get("name").getAsString()) //
- .baseUrl(ricAsJson.get("baseUrl").getAsString()) //
- .managedElementIds(parseManagedElementIds(ricAsJson.get("managedElementIds").getAsJsonArray())) //
+ .name(get(ricAsJson, "name").getAsString()) //
+ .baseUrl(get(ricAsJson, "baseUrl").getAsString()) //
+ .managedElementIds(parseManagedElementIds(get(ricAsJson, "managedElementIds").getAsJsonArray())) //
.controllerName(controllerNameElement != null ? controllerNameElement.getAsString() : "") //
.build();
result.add(ricConfig);
.controllerName(controllerNameElement != null ? controllerNameElement.getAsString() : "") //
.build();
result.add(ricConfig);
for (JsonElement element : getAsJsonArray(config, CONTROLLER)) {
JsonObject controllerAsJson = element.getAsJsonObject();
ImmutableControllerConfig controllerConfig = ImmutableControllerConfig.builder() //
for (JsonElement element : getAsJsonArray(config, CONTROLLER)) {
JsonObject controllerAsJson = element.getAsJsonObject();
ImmutableControllerConfig controllerConfig = ImmutableControllerConfig.builder() //
- .name(controllerAsJson.get("name").getAsString()) //
- .baseUrl(controllerAsJson.get("baseUrl").getAsString()) //
- .password(controllerAsJson.get("password").getAsString()) //
- .userName(controllerAsJson.get("userName").getAsString()) // )
+ .name(get(controllerAsJson, "name").getAsString()) //
+ .baseUrl(get(controllerAsJson, "baseUrl").getAsString()) //
+ .password(get(controllerAsJson, "password").getAsString()) //
+ .userName(get(controllerAsJson, "userName").getAsString()) // )
.build();
if (result.put(controllerConfig.name(), controllerConfig) != null) {
.build();
if (result.put(controllerConfig.name(), controllerConfig) != null) {
private static JsonElement get(JsonObject obj, String memberName) throws ServiceException {
JsonElement elem = obj.get(memberName);
if (elem == null) {
private static JsonElement get(JsonObject obj, String memberName) throws ServiceException {
JsonElement elem = obj.get(memberName);
if (elem == null) {
- throw new ServiceException("Could not find member: " + memberName + " in: " + obj);
+ throw new ServiceException("Could not find member: '" + memberName + "' in: " + obj);
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapterFactory;
import java.io.BufferedInputStream;
import com.google.gson.TypeAdapterFactory;
import java.io.BufferedInputStream;
logger.debug("Starting refreshConfigTask");
stop();
refreshTask = createRefreshTask() //
logger.debug("Starting refreshConfigTask");
stop();
refreshTask = createRefreshTask() //
- .subscribe(
- notUsed -> logger.debug("Refreshed configuration data"), throwable -> logger
- .error("Configuration refresh terminated due to exception {}", throwable.getMessage()),
+ .subscribe(notUsed -> logger.debug("Refreshed configuration data"),
+ throwable -> logger.error("Configuration refresh terminated due to exception {}", throwable.toString()),
() -> logger.error("Configuration refresh terminated"));
}
() -> logger.error("Configuration refresh terminated"));
}
.flatMap(notUsed -> loadConfigurationFromFile()) //
.onErrorResume(this::ignoreError) //
.doOnNext(json -> logger.debug("loadFromFile succeeded")) //
.flatMap(notUsed -> loadConfigurationFromFile()) //
.onErrorResume(this::ignoreError) //
.doOnNext(json -> logger.debug("loadFromFile succeeded")) //
- .doOnTerminate(() -> logger.error("loadFromFile Terminate"));
+ .doOnTerminate(() -> logger.info("loadFromFile Terminate"));
Flux<JsonObject> loadFromConsul = getEnvironment(systemEnvironment) //
.flatMap(this::createCbsClient) //
Flux<JsonObject> loadFromConsul = getEnvironment(systemEnvironment) //
.flatMap(this::createCbsClient) //
.onErrorResume(this::ignoreError) //
.doOnNext(json -> logger.debug("loadFromConsul succeeded")) //
.doOnNext(json -> this.isConsulUsed = true) //
.onErrorResume(this::ignoreError) //
.doOnNext(json -> logger.debug("loadFromConsul succeeded")) //
.doOnNext(json -> this.isConsulUsed = true) //
- .doOnTerminate(() -> logger.error("loadFromConsul Terminated"));
+ .doOnTerminate(() -> logger.info("loadFromConsul Terminated"));
return Flux.merge(loadFromFile, loadFromConsul) //
.flatMap(this::parseConfiguration) //
.flatMap(this::updateConfig) //
.doOnNext(this::handleUpdatedRicConfig) //
.flatMap(configUpdate -> Flux.just(configUpdate.getType())) //
return Flux.merge(loadFromFile, loadFromConsul) //
.flatMap(this::parseConfiguration) //
.flatMap(this::updateConfig) //
.doOnNext(this::handleUpdatedRicConfig) //
.flatMap(configUpdate -> Flux.just(configUpdate.getType())) //
- .doOnTerminate(() -> logger.error("Configuration refresh task is terminated"));
+ .doOnTerminate(() -> handleTerminate("Configuration refresh task is terminated"));
+ }
+
+ private void handleTerminate(String info) {
+ logger.error(info);
}
Mono<EnvProperties> getEnvironment(Properties systemEnvironment) {
}
Mono<EnvProperties> getEnvironment(Properties systemEnvironment) {
private Flux<JsonObject> periodicConfigurationUpdates(CbsClient cbsClient) {
final Duration initialDelay = Duration.ZERO;
final CbsRequest getConfigRequest = CbsRequests.getAll(RequestDiagnosticContext.create());
private Flux<JsonObject> periodicConfigurationUpdates(CbsClient cbsClient) {
final Duration initialDelay = Duration.ZERO;
final CbsRequest getConfigRequest = CbsRequests.getAll(RequestDiagnosticContext.create());
- return cbsClient.updates(getConfigRequest, initialDelay, CONSUL_CONFIG_REFRESH_INTERVAL);
+ return cbsClient.updates(getConfigRequest, initialDelay, CONSUL_CONFIG_REFRESH_INTERVAL) //
+ .onErrorResume(this::ignoreError);
}
private <R> Mono<R> ignoreError(Throwable throwable) {
}
private <R> Mono<R> ignoreError(Throwable throwable) {
ApplicationConfigParser parser = new ApplicationConfigParser();
return Mono.just(parser.parse(jsonObject));
} catch (ServiceException e) {
ApplicationConfigParser parser = new ApplicationConfigParser();
return Mono.just(parser.parse(jsonObject));
} catch (ServiceException e) {
- logger.error("Could not parse configuration {}", e.toString(), e);
- return Mono.error(e);
+ String str = e.toString();
+ logger.error("Could not parse configuration {}", str);
+ return Mono.empty();
appParser.parse(rootObject);
logger.debug("Local configuration file loaded: {}", filepath);
return Flux.just(rootObject);
appParser.parse(rootObject);
logger.debug("Local configuration file loaded: {}", filepath);
return Flux.just(rootObject);
- } catch (JsonSyntaxException | ServiceException | IOException e) {
- logger.debug("Local configuration file not loaded: {}", filepath, e);
+ } catch (Exception e) {
+ logger.error("Local configuration file not loaded: {}, {}", filepath, e.getMessage());
JsonObject jsonRootObject = getJsonRootObject();
JsonObject json = jsonRootObject.getAsJsonObject("config");
json.remove("ric");
JsonObject jsonRootObject = getJsonRootObject();
JsonObject json = jsonRootObject.getAsJsonObject("config");
json.remove("ric");
- final String message = "Could not find member: ric in: " + json;
+ final String message = "Could not find member: 'ric' in: " + json;
Exception actualException = assertThrows(ServiceException.class, () -> parserUnderTest.parse(jsonRootObject));
Exception actualException = assertThrows(ServiceException.class, () -> parserUnderTest.parse(jsonRootObject));