@Override public V3Snapshot adapt(Snapshot from) { V3Snapshot to = new V3Snapshot(); if (from.isSetLinks()) { to.getLinks().addAll(adaptOut(from.getLinks())); if (from.isSetActions()) { to.setActions(adaptOut(from.getActions())); if (from.isSetBios()) { to.setBios(adaptOut(from.getBios())); if (from.isSetCdroms()) { to.setCdroms(new V3CdRoms()); to.getCdroms().getCdRoms().addAll(adaptOut(from.getCdroms().getCdroms())); if (from.isSetCluster()) { to.setCluster(adaptOut(from.getCluster())); if (from.isSetComment()) { to.setComment(from.getComment()); if (from.isSetConsole()) { to.setConsole(adaptOut(from.getConsole())); if (from.isSetCpu()) { to.setCpu(adaptOut(from.getCpu())); if (from.isSetCpuProfile()) { to.setCpuProfile(adaptOut(from.getCpuProfile()));
@Mapping(from = org.ovirt.engine.core.common.businessentities.Snapshot.class, to = Snapshot.class) public static Snapshot map(org.ovirt.engine.core.common.businessentities.Snapshot entity, Snapshot template) { Snapshot model = template != null ? template : new Snapshot(); model.setId(entity.getId().toString()); if (entity.getDescription() != null) { model.setDescription(entity.getDescription()); } if (entity.getCreationDate() != null) { model.setDate(DateMapper.map(entity.getCreationDate(), null)); } if (entity.getStatus() != null) { model.setSnapshotStatus(map(entity.getStatus(), null)); } if (entity.getType() != null) { model.setSnapshotType(map(entity.getType(), null)); } model.setPersistMemorystate(entity.containsMemory()); return model; }
public static Snapshot map(String configuration, ConfigurationType type, Snapshot snapshot) { snapshot.setInitialization(new Initialization()); snapshot.getInitialization().setConfiguration(new Configuration()); snapshot.getInitialization().getConfiguration().setData(configuration); snapshot.getInitialization().getConfiguration().setType(type); return snapshot; } }
protected Response doAdd(Snapshot snapshot, boolean block) { validateParameters(snapshot, "description"); CreateSnapshotForVmParameters snapshotParams = new CreateSnapshotForVmParameters(parentId, snapshot.getDescription()); if (snapshot.isSetPersistMemorystate()) { snapshotParams.setSaveMemory(snapshot.isPersistMemorystate()); } if (snapshot.isSetDiskAttachments()) { Map<Guid, Guid> diskToImageIds = mapDisks(snapshot.getDiskAttachments()); snapshotParams.setDiskIds(new TreeSet<>(diskToImageIds.keySet())); snapshotParams.setDiskToImageIds(diskToImageIds); } return performCreate(ActionType.CreateSnapshotForVm, snapshotParams, new SnapshotIdResolver(), block); }
@Override public Snapshot adapt(V3Snapshot from) { Snapshot to = new Snapshot(); if (from.isSetLinks()) { to.getLinks().addAll(adaptIn(from.getLinks())); to.setActions(adaptIn(from.getActions())); to.setBios(adaptIn(from.getBios())); to.setCdroms(new Cdroms()); to.getCdroms().getCdroms().addAll(adaptIn(from.getCdroms().getCdRoms())); to.setCluster(adaptIn(from.getCluster())); to.setComment(from.getComment()); to.setConsole(adaptIn(from.getConsole())); to.setCpu(adaptIn(from.getCpu())); to.setCpuProfile(adaptIn(from.getCpuProfile())); to.setCpuShares(from.getCpuShares()); to.setCreationTime(from.getCreationTime()); to.setCustomCpuModel(from.getCustomCpuModel()); to.setCustomEmulatedMachine(from.getCustomEmulatedMachine());
private Guid getSnapshotId(Snapshots snapshots) { return asGuid(snapshots.getSnapshots().get(0).getId()); }
@Override protected void verifyModel(Snapshot model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertEquals(DESCRIPTIONS[index], model.getDescription()); verifyLinks(model); }
@Override protected Disk addLinks(Disk model, String... subCollectionMembersToExclude) { Snapshot snapshotInfo = model.getSnapshot(); model.setSnapshot(null); super.addLinks(model, subCollectionMembersToExclude); if (snapshotInfo != null) { org.ovirt.engine.core.common.businessentities.Snapshot snapshot = getEntity(org.ovirt.engine.core.common.businessentities.Snapshot.class, QueryType.GetSnapshotBySnapshotId, new IdQueryParameters(asGuid(snapshotInfo.getId())), snapshotInfo.getId()); Vm vm = new Vm(); vm.setId(snapshot.getVmId().toString()); snapshotInfo.setVm(vm); model.setSnapshot(snapshotInfo); LinkHelper.addLinks(snapshotInfo, null, false); model.setSnapshot(snapshotInfo); } return model; }
new Object[] { VM_ID }, getEntity(0)); Snapshot snapshot = new Snapshot(); snapshot.setDescription(DESCRIPTIONS[0]); verifyAllContent(responseSnapshot, ConfigurationType.OVF, ovfData); Snapshot created = (Snapshot)response.getEntity(); assertNotNull(created.getCreationStatus()); assertEquals(creationStatus.value(), created.getCreationStatus());
/** * Create an instance of {@link Snapshot } * */ public Snapshot createSnapshot() { return new Snapshot(); }
public static void validateAdd(Snapshot snapshot) { if (snapshot == null) { throw new ValidationException("Parameter 'snapshot' is mandatory but was not provided."); } if (snapshot.getDescription()==null) { throw new ValidationException("Parameter 'snapshot.description' is mandatory but was not provided."); } }
private void verifyAllContent(Snapshot model, ConfigurationType type, String data) { assertNotNull(model.getInitialization()); assertNotNull(model.getInitialization().getConfiguration()); assertEquals(data, model.getInitialization().getConfiguration().getData()); assertEquals(type, model.getInitialization().getConfiguration().getType()); }
private String getSnapshotId(Snapshots snapshots) { return (snapshots.getSnapshots() != null && !snapshots.getSnapshots().isEmpty()) ? snapshots.getSnapshots() .get(0) .getId() : Guid.Empty.toString(); }
@Test public void testPreviewSnapshot() { setUriInfo(setUpActionExpectations(ActionType.TryBackToAllSnapshotsOfVm, TryBackToAllSnapshotsOfVmParameters.class, new String[] { "VmId", "DstSnapshotId" }, new Object[] { GUIDS[0], GUIDS[1] })); Action action = new Action(); Snapshot snapshot = new Snapshot(); snapshot.setId(GUIDS[1].toString()); action.setSnapshot(snapshot); Response response = resource.previewSnapshot(action); verifyActionResponse(response); Action actionResponse = (Action)response.getEntity(); assertTrue(actionResponse.isSetStatus()); assertEquals(CreationStatus.COMPLETE.value(), actionResponse.getStatus()); }
@Override protected void verifyModel(Snapshot model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertEquals(DESCRIPTIONS[index], model.getDescription()); verifyLinks(model); } }
@Override protected Disk addLinks(Disk model, String... subCollectionMembersToExclude) { Snapshot snapshotInfo = model.getSnapshot(); model.setSnapshot(null); super.addLinks(model, subCollectionMembersToExclude); if (snapshotInfo != null) { org.ovirt.engine.core.common.businessentities.Snapshot snapshot = getEntity(org.ovirt.engine.core.common.businessentities.Snapshot.class, QueryType.GetSnapshotBySnapshotId, new IdQueryParameters(asGuid(snapshotInfo.getId())), snapshotInfo.getId()); Vm vm = new Vm(); vm.setId(snapshot.getVmId().toString()); snapshotInfo.setVm(vm); model.setSnapshot(snapshotInfo); LinkHelper.addLinks(snapshotInfo, null, false); model.setSnapshot(snapshotInfo); } return model; }
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) { // Avoid adding the snapshot to the response if the VM configuration is missing. // This scenario might be caused by initiating a snapshot deletion request // 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; }
@Test public void testGetWithPopulate() { 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()); }