use of org.onosproject.net.config.InvalidConfigException in project onos by opennetworkinglab.
the class DistributedNetworkConfigStore method applyConfig.
@Override
public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) {
// Create the configuration and validate it.
C config = createConfig(subject, configClass, json);
try {
checkArgument(config.isValid(), INVALID_CONFIG_JSON);
} catch (RuntimeException e) {
ConfigFactory<S, C> configFactory = getConfigFactory(configClass);
String subjectKey = configFactory.subjectFactory().subjectClassKey();
String subjectString = configFactory.subjectFactory().subjectKey(config.subject());
String configKey = config.key();
throw new InvalidConfigException(subjectKey, subjectString, configKey, e);
}
// Insert the validated configuration and get it back.
Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json);
// was supplanted by someone else already.
return versioned.value() == json ? config : createConfig(subject, configClass, versioned.value());
}
use of org.onosproject.net.config.InvalidConfigException in project onos by opennetworkinglab.
the class InvalidConfigExceptionMapper method response.
@Override
protected Response.ResponseBuilder response(Response.Status status, Throwable exception) {
error = exception;
InvalidConfigException ex = (InvalidConfigException) exception;
ObjectMapper mapper = new ObjectMapper();
String message = messageFrom(exception);
ObjectNode result = mapper.createObjectNode().put("code", status.getStatusCode()).put("message", message).put("subjectKey", ex.subjectKey()).put("subject", ex.subject()).put("configKey", ex.configKey());
if (ex.getCause() instanceof InvalidFieldException) {
InvalidFieldException fieldException = (InvalidFieldException) ex.getCause();
result.put("field", fieldException.field()).put("reason", fieldException.reason());
}
return Response.status(status).entity(result.toString());
}
Aggregations