void validateSnapshotRemove(ApiRequest request) { Snapshot snapshot = objectManager.loadResource(Snapshot.class, request.getId()); Map<Object, Object> criteria = new HashMap<Object, Object>(); criteria.put(SNAPSHOT.VOLUME_ID, snapshot.getVolumeId()); criteria.put(SNAPSHOT.REMOVED, null); criteria.put(SNAPSHOT.ID, new Condition(ConditionType.GT, snapshot.getId())); List<Snapshot> snapshots = objectManager.find(Snapshot.class, criteria); if (snapshots.size() == 0) { throw new ClientVisibleException(ResponseCodes.BAD_REQUEST, ValidationErrorCodes.INVALID_STATE, "This snapshot cannot be removed because it is the latest one for the volume.", null); } } }
if (!snapshot.getVolumeId().equals(volumeId)) { throw new ClientVisibleException(ResponseCodes.UNPROCESSABLE_ENTITY, ValidationErrorCodes.INVALID_REFERENCE, "Snapshot is not for the specified volume.", null);
backup.setAccountId(snapshot.getAccountId()); backup.setSnapshotId(snapshot.getId()); backup.setVolumeId(snapshot.getVolumeId()); backup.setBackupTargetId(targetId); backup = objectManager.create(backup);
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.Snapshot from) { setId(from.getId()); setName(from.getName()); setAccountId(from.getAccountId()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState()); setCreated(from.getCreated()); setRemoved(from.getRemoved()); setRemoveTime(from.getRemoveTime()); setData(from.getData()); setVolumeId(from.getVolumeId()); }