Search in sources :

Example 1 with Snapshot

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

the class BackendSnapshotResourceTest method testGetWithPopulate.

@Test
public void testGetWithPopulate() throws Exception {
    List<String> populates = new ArrayList<>();
    populates.add("true");
    String ovfData = "data";
    org.ovirt.engine.core.common.businessentities.Snapshot resultSnapshot = new org.ovirt.engine.core.common.businessentities.Snapshot();
    resultSnapshot.setVmConfiguration(ovfData);
    resultSnapshot.setId(SNAPSHOT_ID);
    when(httpHeaders.getRequestHeader(BackendResource.POPULATE)).thenReturn(populates);
    setUriInfo(setUpBasicUriExpectations());
    setUpGetEntityExpectations(asList(getEntity(1)));
    setUpEntityQueryExpectations(QueryType.GetSnapshotBySnapshotId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { SNAPSHOT_ID }, resultSnapshot);
    Snapshot snapshot = resource.get();
    verifyModel(snapshot, 1);
    assertNotNull(snapshot.getInitialization());
    assertNotNull(snapshot.getInitialization().getConfiguration());
    assertEquals(ovfData, snapshot.getInitialization().getConfiguration().getData());
    assertEquals(ConfigurationType.OVF, snapshot.getInitialization().getConfiguration().getType());
}
Also used : Snapshot(org.ovirt.engine.api.model.Snapshot) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with Snapshot

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

the class BackendSnapshotsResourceTest method doTestAddAsync.

private void doTestAddAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus creationStatus) throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    String ovfData = "data";
    org.ovirt.engine.core.common.businessentities.Snapshot resultSnapshot0 = new org.ovirt.engine.core.common.businessentities.Snapshot();
    resultSnapshot0.setVmConfiguration(ovfData);
    resultSnapshot0.setId(SNAPSHOT_IDS[0]);
    setUpEntityQueryExpectations(QueryType.GetSnapshotBySnapshotId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { SNAPSHOT_IDS[0] }, resultSnapshot0);
    setUpCreationExpectations(ActionType.CreateSnapshotForVm, CreateSnapshotForVmParameters.class, new String[] { "Description", "VmId" }, new Object[] { DESCRIPTIONS[0], VM_ID }, true, true, GUIDS[0], asList(TASK_ID), asList(new AsyncTaskStatus(asyncStatus)), QueryType.GetAllVmSnapshotsByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { VM_ID }, getEntity(0));
    Snapshot snapshot = new Snapshot();
    snapshot.setDescription(DESCRIPTIONS[0]);
    Response response = collection.add(snapshot);
    assertEquals(202, response.getStatus());
    assertTrue(response.getEntity() instanceof Snapshot);
    Snapshot responseSnapshot = (Snapshot) response.getEntity();
    verifyModel(responseSnapshot, 0);
    verifyAllContent(responseSnapshot, ConfigurationType.OVF, ovfData);
    Snapshot created = (Snapshot) response.getEntity();
    assertNotNull(created.getCreationStatus());
    assertEquals(creationStatus.value(), created.getCreationStatus());
}
Also used : Response(javax.ws.rs.core.Response) Snapshot(org.ovirt.engine.api.model.Snapshot) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)

Example 3 with Snapshot

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

the class BackendSnapshotDisksResource method map.

public void map(Disk disk, String snapshotId) {
    disk.setSnapshot(new Snapshot());
    disk.getSnapshot().setId(snapshotId);
}
Also used : Snapshot(org.ovirt.engine.api.model.Snapshot)

Example 4 with Snapshot

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

the class BackendSnapshotsResource method mapCollection.

protected Snapshots mapCollection(List<org.ovirt.engine.core.common.businessentities.Snapshot> entities) {
    Snapshots snapshots = new Snapshots();
    for (org.ovirt.engine.core.common.businessentities.Snapshot entity : entities) {
        Snapshot snapshot = map(entity, null);
        snapshot = populate(snapshot, entity);
        snapshot = addLinks(snapshot);
        try {
            snapshot = addVmConfiguration(entity, snapshot);
        } catch (WebFaultException wfe) {
            // right before listing the snapshots. See: https://bugzilla.redhat.com/1530603
            if (Response.Status.NOT_FOUND.getStatusCode() == wfe.getResponse().getStatus()) {
                log.warn("Missing VM configuration for snapshot \"{}\". " + "Excluding the snapshot from response.", snapshot.getDescription());
                continue;
            }
            throw wfe;
        }
        snapshots.getSnapshots().add(snapshot);
    }
    return snapshots;
}
Also used : Snapshot(org.ovirt.engine.api.model.Snapshot) Snapshots(org.ovirt.engine.api.model.Snapshots)

Example 5 with Snapshot

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

the class BackendVmDisksResourceTest method testAttachDiskSnapshot.

@Test
public void testAttachDiskSnapshot() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    Guid snapshotId = Guid.newGuid();
    Disk model = getModel();
    model.setSnapshot(new Snapshot());
    model.getSnapshot().setId(snapshotId.toString());
    // means this is an existing disk --> attach
    model.setId(DISK_ID.toString());
    setUpCreationExpectations(ActionType.AttachDiskToVm, AttachDetachVmDiskParameters.class, new String[] { "VmId", "EntityInfo", "SnapshotId" }, new Object[] { VM_ID, new EntityInfo(VdcObjectType.Disk, DISK_ID), snapshotId }, true, true, null, null, null, QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { DISK_ID }, asList(getEntity(0)));
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Snapshot(org.ovirt.engine.api.model.Snapshot) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.api.model.Disk) Test(org.junit.Test)

Aggregations

Snapshot (org.ovirt.engine.api.model.Snapshot)14 Test (org.junit.Test)4 Response (javax.ws.rs.core.Response)3 ArrayList (java.util.ArrayList)2 Snapshots (org.ovirt.engine.api.model.Snapshots)2 Vm (org.ovirt.engine.api.model.Vm)2 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)2 Guid (org.ovirt.engine.core.compat.Guid)2 UriInfo (javax.ws.rs.core.UriInfo)1 Action (org.ovirt.engine.api.model.Action)1 Cdroms (org.ovirt.engine.api.model.Cdroms)1 CustomProperties (org.ovirt.engine.api.model.CustomProperties)1 DataCenter (org.ovirt.engine.api.model.DataCenter)1 Disk (org.ovirt.engine.api.model.Disk)1 DiskAttachment (org.ovirt.engine.api.model.DiskAttachment)1 DiskAttachments (org.ovirt.engine.api.model.DiskAttachments)1 DiskProfile (org.ovirt.engine.api.model.DiskProfile)1 Floppies (org.ovirt.engine.api.model.Floppies)1 KatelloErrata (org.ovirt.engine.api.model.KatelloErrata)1 Nics (org.ovirt.engine.api.model.Nics)1