use of org.ovirt.engine.api.v3.types.V3Fault in project ovirt-engine by oVirt.
the class V3InvalidValueExceptionMapper method toResponse.
@Override
public Response toResponse(InvalidValueException exception) {
V3Fault fault = new V3Fault();
fault.setReason("Invalid value");
fault.setDetail(exception.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(fault).build();
}
use of org.ovirt.engine.api.v3.types.V3Fault in project ovirt-engine by oVirt.
the class V3ClusterHelper method assignCompatiblePolicy.
/**
* Makes sure that the V4 cluster has a reference to a scheduling policy that is compatible with the one specified
* by the given V3 cluster. If that isn't possible throws an exception that will result in an HTTP error response
* sent to the caller.
*/
public static void assignCompatiblePolicy(V3Cluster v3Cluster, Cluster v4Cluster) {
V3SchedulingPolicy v3Policy = v3Cluster.getSchedulingPolicy();
SchedulingPolicy v4Policy = v4Cluster.getSchedulingPolicy();
boolean v3IsSet = v3Policy != null && (v3Policy.isSetName() || v3Policy.isSetPolicy());
boolean v4IsSet = v4Policy != null && (v4Policy.isSetName() || v4Policy.isSetId());
if (v3IsSet && !v4IsSet) {
SchedulingPolicy v4CompatiblePolicy = findCompatiblePolicy(v3Policy);
if (v4CompatiblePolicy != null) {
v4Policy = new SchedulingPolicy();
v4Policy.setId(v4CompatiblePolicy.getId());
v4Cluster.setSchedulingPolicy(v4Policy);
} else {
V3Fault fault = new V3Fault();
fault.setReason("Operation Failed");
fault.setDetail("Can't find a compatible scheduling policy.");
Response response = Response.serverError().entity(fault).build();
throw new WebApplicationException(response);
}
}
}
use of org.ovirt.engine.api.v3.types.V3Fault in project ovirt-engine by oVirt.
the class V3IOExceptionMapper method toResponse.
@Override
public Response toResponse(IOException exception) {
// Check if the cause of the exception is an invalid value, and generate a specific error message:
Throwable cause = exception.getCause();
if (cause instanceof InvalidValueException) {
V3Fault fault = new V3Fault();
fault.setReason("Invalid value");
fault.setDetail(cause.getMessage());
return Response.status(Status.BAD_REQUEST).entity(fault).build();
}
// the request:
try {
log.error("IO exception while processing \"{}\" request for path \"{}\"", request.getMethod(), uriInfo.getPath());
log.error("Exception", exception);
V3UsageFinder finder = new V3UsageFinder();
V3UsageMessage usage = finder.getUsageMessage(uriInfo, request);
return Response.status(Status.BAD_REQUEST).entity(usage).build();
} catch (Exception error) {
throw new WebApplicationException(error, Response.status(Status.INTERNAL_SERVER_ERROR).build());
}
}
Aggregations