def do_cluster_housekeeping(): JBoxEBSHousekeep.log_debug("starting cluster housekeeping") detached_disks = JBoxDiskState.get_detached_disks() time_now = datetime.datetime.now(pytz.utc) for disk_key in detached_disks: disk_info = JBoxDiskState(disk_key=disk_key) user_id = disk_info.get_user_id() sess_props = JBoxSessionProps(unique_sessname(user_id)) incomplete_snapshots = [] modified = False for snap_id in disk_info.get_snapshot_ids(): if not EBSVol.is_snapshot_complete(snap_id): incomplete_snapshots.append(snap_id) continue JBoxEBSHousekeep.log_debug("updating latest snapshot of user %s to %s", user_id, snap_id) old_snap_id = sess_props.get_snapshot_id() sess_props.set_snapshot_id(snap_id) modified = True if old_snap_id is not None: EBSVol.delete_snapshot(old_snap_id) if modified: sess_props.save() disk_info.set_snapshot_ids(incomplete_snapshots) disk_info.save() if len(incomplete_snapshots) == 0: if (time_now - disk_info.get_detach_time()).total_seconds() > 24 * 60 * 60: vol_id = disk_info.get_volume_id() JBoxEBSHousekeep.log_debug("volume %s for user %s unused for too long", vol_id, user_id) disk_info.delete() EBSVol.detach_volume(vol_id, delete=True) else: JBoxEBSHousekeep.log_debug("ongoing snapshots of user %s: %r", user_id, incomplete_snapshots) JBoxEBSHousekeep.log_debug("finished cluster housekeeping")
def do_cluster_housekeeping(): JBoxEBSHousekeep.log_debug("starting cluster housekeeping") detached_disks = JBoxDiskState.get_detached_disks() time_now = datetime.datetime.now(pytz.utc) for disk_key in detached_disks: disk_info = JBoxDiskState(disk_key=disk_key) user_id = disk_info.get_user_id() sess_props = JBoxSessionProps(Compute.get_install_id(), unique_sessname(user_id)) incomplete_snapshots = [] modified = False for snap_id in disk_info.get_snapshot_ids(): if not EBSVol.is_snapshot_complete(snap_id): incomplete_snapshots.append(snap_id) continue JBoxEBSHousekeep.log_debug("updating latest snapshot of user %s to %s", user_id, snap_id) old_snap_id = sess_props.get_snapshot_id() sess_props.set_snapshot_id(snap_id) modified = True if old_snap_id is not None: EBSVol.delete_snapshot(old_snap_id) if modified: sess_props.save() disk_info.set_snapshot_ids(incomplete_snapshots) disk_info.save() if len(incomplete_snapshots) == 0: if (time_now - disk_info.get_detach_time()).total_seconds() > 24*60*60: vol_id = disk_info.get_volume_id() JBoxEBSHousekeep.log_debug("volume %s for user %s unused for too long", vol_id, user_id) disk_info.delete() EBSVol.detach_volume(vol_id, delete=True) else: JBoxEBSHousekeep.log_debug("ongoing snapshots of user %s: %r", user_id, incomplete_snapshots) JBoxEBSHousekeep.log_debug("finished cluster housekeeping")
def release(self, backup=False): sess_props = JBoxSessionProps(Compute.get_install_id(), self.sessname) existing_disk = JBoxDiskState(cluster_id=CompEC2.INSTALL_ID, region_id=CompEC2.REGION, user_id=sess_props.get_user_id()) existing_disk.set_state(JBoxDiskState.STATE_DETACHING) existing_disk.save() disk_id = self.disk_path.split('/')[-1] if backup: snap_id = self._backup() else: snap_id = None vol_id = EBSVol.get_volume_id_from_device(disk_id) EBSVol.detach_volume(vol_id, delete=False) if snap_id is not None: existing_disk.add_snapshot_id(snap_id) existing_disk.set_state(JBoxDiskState.STATE_DETACHED) existing_disk.save()