Search in sources :

Example 1 with V3Fault

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();
}
Also used : V3Fault(org.ovirt.engine.api.v3.types.V3Fault)

Example 2 with V3Fault

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);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) V3Fault(org.ovirt.engine.api.v3.types.V3Fault) WebApplicationException(javax.ws.rs.WebApplicationException) V3SchedulingPolicy(org.ovirt.engine.api.v3.types.V3SchedulingPolicy) SchedulingPolicy(org.ovirt.engine.api.model.SchedulingPolicy) V3SchedulingPolicy(org.ovirt.engine.api.v3.types.V3SchedulingPolicy)

Example 3 with V3Fault

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());
    }
}
Also used : InvalidValueException(org.ovirt.engine.api.utils.InvalidValueException) V3Fault(org.ovirt.engine.api.v3.types.V3Fault) WebApplicationException(javax.ws.rs.WebApplicationException) V3UsageMessage(org.ovirt.engine.api.v3.types.V3UsageMessage) IOException(java.io.IOException) InvalidValueException(org.ovirt.engine.api.utils.InvalidValueException) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

V3Fault (org.ovirt.engine.api.v3.types.V3Fault)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 IOException (java.io.IOException)1 Response (javax.ws.rs.core.Response)1 SchedulingPolicy (org.ovirt.engine.api.model.SchedulingPolicy)1 InvalidValueException (org.ovirt.engine.api.utils.InvalidValueException)1 V3SchedulingPolicy (org.ovirt.engine.api.v3.types.V3SchedulingPolicy)1 V3UsageMessage (org.ovirt.engine.api.v3.types.V3UsageMessage)1