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());
}
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());
}
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);
}
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;
}
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());
}
Aggregations