Search in sources :

Example 1 with V3Cluster

use of org.ovirt.engine.api.v3.types.V3Cluster 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 2 with V3Cluster

use of org.ovirt.engine.api.v3.types.V3Cluster in project ovirt-engine by oVirt.

the class V3ClusterInAdapter method adapt.

@Override
public Cluster adapt(V3Cluster from) {
    Cluster to = new Cluster();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptIn(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetBallooningEnabled()) {
        to.setBallooningEnabled(from.isBallooningEnabled());
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetCpu()) {
        to.setCpu(adaptIn(from.getCpu()));
    }
    if (from.isSetDataCenter()) {
        to.setDataCenter(adaptIn(from.getDataCenter()));
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDisplay()) {
        to.setDisplay(adaptIn(from.getDisplay()));
    }
    if (from.isSetErrorHandling()) {
        to.setErrorHandling(adaptIn(from.getErrorHandling()));
    }
    if (from.isSetFencingPolicy()) {
        to.setFencingPolicy(adaptIn(from.getFencingPolicy()));
    }
    if (from.isSetGlusterService()) {
        to.setGlusterService(from.isGlusterService());
    }
    if (from.isSetHaReservation()) {
        to.setHaReservation(from.isHaReservation());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetKsm()) {
        to.setKsm(adaptIn(from.getKsm()));
    }
    if (from.isSetMaintenanceReasonRequired()) {
        to.setMaintenanceReasonRequired(from.isMaintenanceReasonRequired());
    }
    if (from.isSetManagementNetwork()) {
        to.setManagementNetwork(adaptIn(from.getManagementNetwork()));
    }
    if (from.isSetMemoryPolicy()) {
        to.setMemoryPolicy(adaptIn(from.getMemoryPolicy()));
    }
    if (from.isSetMigration()) {
        to.setMigration(adaptIn(from.getMigration()));
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetOptionalReason()) {
        to.setOptionalReason(from.isOptionalReason());
    }
    if (from.isSetRequiredRngSources()) {
        to.setRequiredRngSources(new Cluster.RequiredRngSourcesList());
        to.getRequiredRngSources().getRequiredRngSources().addAll(adaptRngSources(from));
    }
    if (from.isSetSchedulingPolicy()) {
        to.setSchedulingPolicy(adaptIn(from.getSchedulingPolicy()));
    }
    if (from.isSetSerialNumber()) {
        to.setSerialNumber(adaptIn(from.getSerialNumber()));
    }
    if (from.isSetSupportedVersions()) {
        to.setSupportedVersions(new Versions());
        to.getSupportedVersions().getVersions().addAll(adaptIn(from.getSupportedVersions().getVersions()));
    }
    if (from.isSetThreadsAsCores()) {
        to.setThreadsAsCores(from.isThreadsAsCores());
    }
    if (from.isSetTrustedService()) {
        to.setTrustedService(from.isTrustedService());
    }
    if (from.isSetTunnelMigration()) {
        to.setTunnelMigration(from.isTunnelMigration());
    }
    if (from.isSetVersion()) {
        to.setVersion(adaptIn(from.getVersion()));
    }
    if (from.isSetVirtService()) {
        to.setVirtService(from.isVirtService());
    }
    return to;
}
Also used : Versions(org.ovirt.engine.api.model.Versions) V3Cluster(org.ovirt.engine.api.v3.types.V3Cluster) Cluster(org.ovirt.engine.api.model.Cluster)

Example 3 with V3Cluster

use of org.ovirt.engine.api.v3.types.V3Cluster in project ovirt-engine by oVirt.

the class V3ClusterOutAdapter method adapt.

@Override
public V3Cluster adapt(Cluster from) {
    V3Cluster to = new V3Cluster();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptOut(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptOut(from.getActions()));
    }
    if (from.isSetBallooningEnabled()) {
        to.setBallooningEnabled(from.isBallooningEnabled());
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetCpu()) {
        to.setCpu(adaptOut(from.getCpu()));
    }
    if (from.isSetDataCenter()) {
        to.setDataCenter(adaptOut(from.getDataCenter()));
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDisplay()) {
        to.setDisplay(adaptOut(from.getDisplay()));
    }
    if (from.isSetErrorHandling()) {
        to.setErrorHandling(adaptOut(from.getErrorHandling()));
    }
    if (from.isSetFencingPolicy()) {
        to.setFencingPolicy(adaptOut(from.getFencingPolicy()));
    }
    if (from.isSetGlusterService()) {
        to.setGlusterService(from.isGlusterService());
    }
    if (from.isSetHaReservation()) {
        to.setHaReservation(from.isHaReservation());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetKsm()) {
        to.setKsm(adaptOut(from.getKsm()));
    }
    if (from.isSetMaintenanceReasonRequired()) {
        to.setMaintenanceReasonRequired(from.isMaintenanceReasonRequired());
    }
    if (from.isSetManagementNetwork()) {
        to.setManagementNetwork(adaptOut(from.getManagementNetwork()));
    }
    if (from.isSetMemoryPolicy()) {
        to.setMemoryPolicy(adaptOut(from.getMemoryPolicy()));
    }
    if (from.isSetMigration()) {
        to.setMigration(adaptOut(from.getMigration()));
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetOptionalReason()) {
        to.setOptionalReason(from.isOptionalReason());
    }
    if (from.isSetRequiredRngSources()) {
        to.setRequiredRngSources(new V3RngSources());
        to.getRequiredRngSources().getRngSources().addAll(adaptRngSources(from));
    }
    if (from.isSetSerialNumber()) {
        to.setSerialNumber(adaptOut(from.getSerialNumber()));
    }
    if (from.isSetSupportedVersions()) {
        to.setSupportedVersions(new V3SupportedVersions());
        to.getSupportedVersions().getVersions().addAll(adaptOut(from.getSupportedVersions().getVersions()));
    }
    if (from.isSetThreadsAsCores()) {
        to.setThreadsAsCores(from.isThreadsAsCores());
    }
    if (from.isSetTrustedService()) {
        to.setTrustedService(from.isTrustedService());
    }
    if (from.isSetTunnelMigration()) {
        to.setTunnelMigration(from.isTunnelMigration());
    }
    if (from.isSetVersion()) {
        to.setVersion(adaptOut(from.getVersion()));
    }
    if (from.isSetVirtService()) {
        to.setVirtService(from.isVirtService());
    }
    // In V3 the scheduling policy was part of the cluster, so we need to retrieve the details and populate the
    // "policy" and "thresholds" elements:
    SchedulingPolicy fromPolicy = from.getSchedulingPolicy();
    if (fromPolicy != null && fromPolicy.isSetId()) {
        SystemResource systemResource = BackendApiResource.getInstance();
        SchedulingPoliciesResource policiesResource = systemResource.getSchedulingPoliciesResource();
        SchedulingPolicyResource policyResource = policiesResource.getPolicyResource(fromPolicy.getId());
        try {
            fromPolicy = policyResource.get();
        } catch (WebApplicationException exception) {
        // If an application exception is generated while retrieving the details of the scheduling policy it
        // is safe to ignore it, as it may be that the user just doesn't have permission to see the policy, but
        // she may still have permissions to see the other details of the cluster.
        }
        V3SchedulingPolicy toPolicy = to.getSchedulingPolicy();
        if (toPolicy == null) {
            toPolicy = new V3SchedulingPolicy();
            to.setSchedulingPolicy(toPolicy);
        }
        if (fromPolicy.isSetId()) {
            toPolicy.setId(fromPolicy.getId());
        }
        if (fromPolicy.isSetHref()) {
            toPolicy.setHref(fromPolicy.getHref());
        }
        if (fromPolicy.isSetName() && !toPolicy.isSetPolicy()) {
            toPolicy.setPolicy(fromPolicy.getName());
        }
        Properties fromProperties = fromPolicy.getProperties();
        if (fromProperties != null) {
            Integer fromDuration = getIntegerProperty(fromProperties, "CpuOverCommitDurationMinutes");
            if (fromDuration != null) {
                V3SchedulingPolicyThresholds toThresholds = toPolicy.getThresholds();
                if (toThresholds == null) {
                    toThresholds = new V3SchedulingPolicyThresholds();
                    toPolicy.setThresholds(toThresholds);
                }
                toThresholds.setDuration(fromDuration);
            }
            Integer fromHigh = getIntegerProperty(fromProperties, "HighUtilization");
            if (fromHigh != null) {
                V3SchedulingPolicyThresholds toThresholds = toPolicy.getThresholds();
                if (toThresholds == null) {
                    toThresholds = new V3SchedulingPolicyThresholds();
                    toPolicy.setThresholds(toThresholds);
                }
                toThresholds.setHigh(fromHigh);
            }
            Integer fromLow = getIntegerProperty(fromProperties, "LowUtilization");
            if (fromLow != null) {
                V3SchedulingPolicyThresholds toThresholds = toPolicy.getThresholds();
                if (toThresholds == null) {
                    toThresholds = new V3SchedulingPolicyThresholds();
                    toPolicy.setThresholds(toThresholds);
                }
                toThresholds.setLow(fromLow);
            }
        }
    }
    return to;
}
Also used : V3Cluster(org.ovirt.engine.api.v3.types.V3Cluster) V3SchedulingPolicyThresholds(org.ovirt.engine.api.v3.types.V3SchedulingPolicyThresholds) V3RngSources(org.ovirt.engine.api.v3.types.V3RngSources) SchedulingPoliciesResource(org.ovirt.engine.api.resource.SchedulingPoliciesResource) WebApplicationException(javax.ws.rs.WebApplicationException) V3SchedulingPolicy(org.ovirt.engine.api.v3.types.V3SchedulingPolicy) SchedulingPolicyResource(org.ovirt.engine.api.resource.SchedulingPolicyResource) V3SupportedVersions(org.ovirt.engine.api.v3.types.V3SupportedVersions) SystemResource(org.ovirt.engine.api.resource.SystemResource) SchedulingPolicy(org.ovirt.engine.api.model.SchedulingPolicy) V3SchedulingPolicy(org.ovirt.engine.api.v3.types.V3SchedulingPolicy) Properties(org.ovirt.engine.api.model.Properties)

Example 4 with V3Cluster

use of org.ovirt.engine.api.v3.types.V3Cluster in project ovirt-engine by oVirt.

the class V3ClusterServer method update.

@PUT
@Consumes({ "application/xml", "application/json" })
public V3Cluster update(V3Cluster v3Cluster) {
    Cluster v4Cluster = adaptIn(v3Cluster);
    assignCompatiblePolicy(v3Cluster, v4Cluster);
    try {
        return adaptOut(getDelegate().update(v4Cluster));
    } catch (WebApplicationException exception) {
        throw adaptException(exception);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Cluster(org.ovirt.engine.api.model.Cluster) V3Cluster(org.ovirt.engine.api.v3.types.V3Cluster) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 5 with V3Cluster

use of org.ovirt.engine.api.v3.types.V3Cluster in project ovirt-engine by oVirt.

the class V3ClustersServer method add.

@POST
@Consumes({ "application/xml", "application/json" })
public Response add(V3Cluster v3Cluster) {
    Cluster v4Cluster = adaptIn(v3Cluster);
    assignCompatiblePolicy(v3Cluster, v4Cluster);
    try {
        return adaptResponse(getDelegate().add(v4Cluster));
    } catch (WebApplicationException exception) {
        throw adaptException(exception);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Cluster(org.ovirt.engine.api.model.Cluster) V3Cluster(org.ovirt.engine.api.v3.types.V3Cluster) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

WebApplicationException (javax.ws.rs.WebApplicationException)4 V3Cluster (org.ovirt.engine.api.v3.types.V3Cluster)4 Cluster (org.ovirt.engine.api.model.Cluster)3 Consumes (javax.ws.rs.Consumes)2 SchedulingPolicy (org.ovirt.engine.api.model.SchedulingPolicy)2 V3SchedulingPolicy (org.ovirt.engine.api.v3.types.V3SchedulingPolicy)2 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Response (javax.ws.rs.core.Response)1 Properties (org.ovirt.engine.api.model.Properties)1 Versions (org.ovirt.engine.api.model.Versions)1 SchedulingPoliciesResource (org.ovirt.engine.api.resource.SchedulingPoliciesResource)1 SchedulingPolicyResource (org.ovirt.engine.api.resource.SchedulingPolicyResource)1 SystemResource (org.ovirt.engine.api.resource.SystemResource)1 V3Fault (org.ovirt.engine.api.v3.types.V3Fault)1 V3RngSources (org.ovirt.engine.api.v3.types.V3RngSources)1 V3SchedulingPolicyThresholds (org.ovirt.engine.api.v3.types.V3SchedulingPolicyThresholds)1 V3SupportedVersions (org.ovirt.engine.api.v3.types.V3SupportedVersions)1