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); } } }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { Volume volume = (Volume)state.getResource(); List<Snapshot> snapshots = null; if (VolumeConstants.PROCESS_RESTORE_FROM_BACKUP.equalsIgnoreCase(process.getName())) { snapshots = objectManager.children(volume, Snapshot.class); } else if (VolumeConstants.PROCESS_REVERT.equalsIgnoreCase(process.getName())) { Snapshot snapshot = objectManager.loadResource(Snapshot.class, state.getData().get("snapshotId").toString()); Map<Object, Object> criteria = new HashMap<Object, Object>(); criteria.put(SNAPSHOT.VOLUME_ID, volume.getId()); criteria.put(SNAPSHOT.REMOVED, null); criteria.put(SNAPSHOT.ID, new Condition(ConditionType.GT, snapshot.getId())); snapshots = objectManager.find(Snapshot.class, criteria); } else { throw new IllegalStateException("Unknown process: " + process.getName()); } for (Snapshot s : snapshots) { if (s.getRemoved() == null) { objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, s, null); } } return null; }
backup.setSnapshotId(snapshot.getId()); backup.setVolumeId(snapshot.getVolumeId()); backup.setBackupTargetId(targetId);
/** * {@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()); }