Search in sources :

Example 6 with DiskProfile

use of org.ovirt.engine.api.model.DiskProfile in project ovirt-engine by oVirt.

the class DiskProfileMapper method map.

@Mapping(from = org.ovirt.engine.core.common.businessentities.profiles.DiskProfile.class, to = DiskProfile.class)
public static DiskProfile map(org.ovirt.engine.core.common.businessentities.profiles.DiskProfile entity, DiskProfile template) {
    DiskProfile model = template != null ? template : new DiskProfile();
    if (entity.getId() != null) {
        model.setId(entity.getId().toString());
    }
    if (entity.getName() != null) {
        model.setName(entity.getName());
    }
    if (entity.getDescription() != null) {
        model.setDescription(entity.getDescription());
    }
    if (entity.getStorageDomainId() != null) {
        model.setStorageDomain(new StorageDomain());
        model.getStorageDomain().setId(entity.getStorageDomainId().toString());
    }
    if (entity.getQosId() != null) {
        model.setQos(new Qos());
        model.getQos().setId(entity.getQosId().toString());
    }
    return model;
}
Also used : StorageDomain(org.ovirt.engine.api.model.StorageDomain) Qos(org.ovirt.engine.api.model.Qos) DiskProfile(org.ovirt.engine.api.model.DiskProfile)

Example 7 with DiskProfile

use of org.ovirt.engine.api.model.DiskProfile in project ovirt-engine by oVirt.

the class AbstractBackendDiskProfilesResource method mapCollection.

protected DiskProfiles mapCollection(List<org.ovirt.engine.core.common.businessentities.profiles.DiskProfile> entities) {
    DiskProfiles collection = new DiskProfiles();
    Map<Guid, Qos> qosMap = new HashMap<>();
    for (org.ovirt.engine.core.common.businessentities.profiles.DiskProfile entity : entities) {
        DiskProfile profile = populate(map(entity), entity);
        collection.getDiskProfiles().add(profile);
        if (entity.getQosId() != null) {
            qosMap.put(entity.getQosId(), profile.getQos());
        }
    }
    handleQosDataCenterLinks(qosMap);
    for (DiskProfile diskProfile : collection.getDiskProfiles()) {
        addLinks(diskProfile);
    }
    return collection;
}
Also used : Qos(org.ovirt.engine.api.model.Qos) StorageQos(org.ovirt.engine.core.common.businessentities.qos.StorageQos) DiskProfiles(org.ovirt.engine.api.model.DiskProfiles) HashMap(java.util.HashMap) Guid(org.ovirt.engine.core.compat.Guid) DiskProfile(org.ovirt.engine.api.model.DiskProfile)

Example 8 with DiskProfile

use of org.ovirt.engine.api.model.DiskProfile in project ovirt-engine by oVirt.

the class BackendDiskProfileResourceTest method getModel.

static DiskProfile getModel(int index) {
    DiskProfile model = new DiskProfile();
    model.setId(GUIDS[index].toString());
    model.setName(NAMES[index]);
    model.setDescription(DESCRIPTIONS[index]);
    return model;
}
Also used : DiskProfile(org.ovirt.engine.api.model.DiskProfile)

Example 9 with DiskProfile

use of org.ovirt.engine.api.model.DiskProfile in project ovirt-engine by oVirt.

the class BackendDiskProfileResourceTest method testConflictedUpdate.

@Test
public void testConflictedUpdate() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpEntityQueryExpectations(1, 0, false);
    DiskProfile model = getModel(1);
    model.setId(GUIDS[1].toString());
    try {
        resource.update(model);
        fail("expected WebApplicationException");
    } catch (WebApplicationException wae) {
        verifyImmutabilityConstraint(wae);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) DiskProfile(org.ovirt.engine.api.model.DiskProfile) Test(org.junit.Test)

Example 10 with DiskProfile

use of org.ovirt.engine.api.model.DiskProfile in project ovirt-engine by oVirt.

the class DiskMapper method mapDiskImageToDiskFields.

private static void mapDiskImageToDiskFields(DiskImage entity, Disk model) {
    if (entity.getImageId() != null) {
        model.setImageId(entity.getImageId().toString());
    }
    model.setProvisionedSize(entity.getSize());
    if (entity.hasActualSize()) {
        model.setActualSize(entity.getActualSizeInBytes());
        if (entity.isAllowSnapshot()) {
            model.setTotalSize((long) entity.getActualDiskWithSnapshotsSizeInBytes());
        }
    }
    if (entity.getSnapshotId() != null) {
        model.setSnapshot(new Snapshot());
        model.getSnapshot().setId(entity.getSnapshotId().toString());
    }
    if (entity.getVolumeFormat() != null) {
        model.setFormat(map(entity.getVolumeFormat(), null));
    }
    if (entity.getQcowCompat() != null) {
        model.setQcowVersion(mapQcowCompat(entity.getQcowCompat()));
    }
    if (entity.getImageStatus() != null) {
        model.setStatus(mapDiskStatus(entity.getImageStatus()));
    }
    model.setSparse(VolumeType.Sparse == entity.getVolumeType());
    if (entity.getStorageIds() != null && entity.getStorageIds().size() > 0) {
        if (!model.isSetStorageDomains()) {
            model.setStorageDomains(new StorageDomains());
        }
        for (Guid id : entity.getStorageIds()) {
            StorageDomain storageDomain = new StorageDomain();
            storageDomain.setId(id.toString());
            model.getStorageDomains().getStorageDomains().add(storageDomain);
        }
    }
    if (entity.getQuotaId() != null) {
        Quota quota = new Quota();
        quota.setId(entity.getQuotaId().toString());
        // Add DataCenter to the quota, so links are properly created
        if (entity.getStoragePoolId() != null) {
            quota.setDataCenter(new DataCenter());
            quota.getDataCenter().setId(entity.getStoragePoolId().toString());
        }
        model.setQuota(quota);
    }
    if (entity.getDiskProfileId() != null) {
        DiskProfile diskProfile = new DiskProfile();
        diskProfile.setId(entity.getDiskProfileId().toString());
        model.setDiskProfile(diskProfile);
    }
    if (entity.getCinderVolumeType() != null) {
        OpenStackVolumeType volumeType = model.getOpenstackVolumeType();
        if (volumeType == null) {
            volumeType = new OpenStackVolumeType();
            model.setOpenstackVolumeType(volumeType);
        }
        volumeType.setName(entity.getCinderVolumeType());
    }
}
Also used : OpenStackVolumeType(org.ovirt.engine.api.model.OpenStackVolumeType) Snapshot(org.ovirt.engine.api.model.Snapshot) StorageDomain(org.ovirt.engine.api.model.StorageDomain) DataCenter(org.ovirt.engine.api.model.DataCenter) Quota(org.ovirt.engine.api.model.Quota) Guid(org.ovirt.engine.core.compat.Guid) StorageDomains(org.ovirt.engine.api.model.StorageDomains) DiskProfile(org.ovirt.engine.api.model.DiskProfile)

Aggregations

DiskProfile (org.ovirt.engine.api.model.DiskProfile)10 StorageDomain (org.ovirt.engine.api.model.StorageDomain)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 Test (org.junit.Test)3 Qos (org.ovirt.engine.api.model.Qos)2 Guid (org.ovirt.engine.core.compat.Guid)2 HashMap (java.util.HashMap)1 Response (javax.ws.rs.core.Response)1 DataCenter (org.ovirt.engine.api.model.DataCenter)1 DiskProfiles (org.ovirt.engine.api.model.DiskProfiles)1 OpenStackVolumeType (org.ovirt.engine.api.model.OpenStackVolumeType)1 Quota (org.ovirt.engine.api.model.Quota)1 Snapshot (org.ovirt.engine.api.model.Snapshot)1 StorageDomains (org.ovirt.engine.api.model.StorageDomains)1 DiskProfileParameters (org.ovirt.engine.core.common.action.DiskProfileParameters)1 StorageQos (org.ovirt.engine.core.common.businessentities.qos.StorageQos)1