Search in sources :

Example 1 with Payload

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

the class VmMapper method map.

@Mapping(from = VmPayload.class, to = Payload.class)
public static Payload map(VmPayload entity, Payload template) {
    if (entity.getDeviceType() != null || entity.getFiles().isEmpty()) {
        Payload model = template != null ? template : new Payload();
        if (entity.getDeviceType() != null) {
            org.ovirt.engine.api.model.VmDeviceType deviceType = map(entity.getDeviceType(), null);
            if (deviceType != null) {
                model.setType(deviceType);
            }
        }
        model.setVolumeId(entity.getVolumeId());
        if (entity.getFiles().size() > 0) {
            model.setFiles(new Files());
            for (Map.Entry<String, String> entry : entity.getFiles().entrySet()) {
                File file = new File();
                file.setName(entry.getKey());
                file.setContent(entry.getValue());
                model.getFiles().getFiles().add(file);
            }
        }
        return model;
    }
    return null;
}
Also used : VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Payload(org.ovirt.engine.api.model.Payload) Files(org.ovirt.engine.api.model.Files) Map(java.util.Map) File(org.ovirt.engine.api.model.File)

Example 2 with Payload

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

the class V3PayloadInAdapter method adapt.

@Override
public Payload adapt(V3Payload from) {
    Payload to = new Payload();
    if (from.isSetFiles()) {
        to.setFiles(new Files());
        to.getFiles().getFiles().addAll(adaptIn(from.getFiles().getFiles()));
    }
    to.setType(VmDeviceType.fromValue(from.getType()));
    if (from.isSetVolumeId()) {
        to.setVolumeId(from.getVolumeId());
    }
    return to;
}
Also used : V3Payload(org.ovirt.engine.api.v3.types.V3Payload) Payload(org.ovirt.engine.api.model.Payload) Files(org.ovirt.engine.api.model.Files)

Example 3 with Payload

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

the class BackendVmDeviceHelper method setPayload.

public static void setPayload(BackendResource resouce, Vm vm) {
    try {
        VmPayload payload = resouce.getEntity(VmPayload.class, QueryType.GetVmPayload, new IdQueryParameters(new Guid(vm.getId())), null, true);
        if (payload != null) {
            Payload p = resouce.getMappingLocator().getMapper(VmPayload.class, Payload.class).map(payload, null);
            Payloads payloads = new Payloads();
            payloads.getPayloads().add(p);
            vm.setPayloads(payloads);
        }
    } catch (WebApplicationException ex) {
        if (ex.getResponse().getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
        // It's legal to not receive a payload for this VM, so the exception is caught and ignored.
        // (TODO: 'getEntity()' should be refactored to make it the programmer's decision,
        // whether to throw an exception or not in case the entity is not found.) Then
        // this try-catch won't be necessary.
        } else {
            throw ex;
        }
    }
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) WebApplicationException(javax.ws.rs.WebApplicationException) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Payload(org.ovirt.engine.api.model.Payload) Guid(org.ovirt.engine.core.compat.Guid) Payloads(org.ovirt.engine.api.model.Payloads)

Example 4 with Payload

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

the class VmMapperTest method testPayloadMapToVmPaylod.

@Test
public void testPayloadMapToVmPaylod() {
    Payload payload = new Payload();
    payload.setType(VmDeviceType.CDROM);
    payload.setVolumeId("CD-VOL");
    VmPayload vmPayload = VmMapper.map(payload, null);
    assertEquals(payload.getType().name(), vmPayload.getDeviceType().name());
    assertEquals(payload.getVolumeId(), vmPayload.getVolumeId());
}
Also used : VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Payload(org.ovirt.engine.api.model.Payload) Test(org.junit.Test)

Example 5 with Payload

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

the class VmMapperTest method testVmPayloadMapToPaylod.

@Test
public void testVmPayloadMapToPaylod() {
    VmPayload vmPayload = new VmPayload();
    vmPayload.setDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType.CDROM);
    vmPayload.setVolumeId("CD-VOL");
    Payload payload = VmMapper.map(vmPayload, null);
    assertEquals(vmPayload.getDeviceType().name(), payload.getType().name());
    assertEquals(vmPayload.getVolumeId(), payload.getVolumeId());
}
Also used : VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Payload(org.ovirt.engine.api.model.Payload) Test(org.junit.Test)

Aggregations

Payload (org.ovirt.engine.api.model.Payload)5 VmPayload (org.ovirt.engine.core.common.businessentities.VmPayload)4 Test (org.junit.Test)2 Files (org.ovirt.engine.api.model.Files)2 Map (java.util.Map)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 File (org.ovirt.engine.api.model.File)1 Payloads (org.ovirt.engine.api.model.Payloads)1 V3Payload (org.ovirt.engine.api.v3.types.V3Payload)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1 Guid (org.ovirt.engine.core.compat.Guid)1