def cleanup_uploadjobs(uploadjob_ids): """Delete UploadJobs @param uploadjobs_ids: the list of id of jobs to delete """ gw = SystemGateway() return gw.cleanup_uploadjobs(uploadjob_ids)
def get_node_for_shard(node_id, shard_id): """Get the StorageNode for the specified node_id, shard_id. raise DoesNotExist if the node isn't there. """ gw = SystemGateway() return gw.get_node(node_id, shard_id)
def cleanup_uploadjobs(shard_id, uploadjob_ids): """Delete UploadJobs @param shard_id: the shard to use for the query. @param uploadjobs_ids: the list of id of jobs to delete """ gw = SystemGateway() return gw.cleanup_uploadjobs(shard_id, uploadjob_ids)
def get_status_by_id(user_id, dl_id): """Get the status of the download.""" gw = SystemGateway() try: download = gw.get_download_by_id(user_id, dl_id) except errors.DoesNotExist: return UNKNOWN return get_status_from_download(user_id, download)
def get_failed_downloads(start_date, end_date): """Get the failed downloads between start_date and end_date.""" gw = SystemGateway() downloads = [] for shard_id in get_shard_ids(): downloads.extend( list(gw.get_failed_downloads(shard_id, start_date, end_date))) return downloads
def get_failed_downloads(start_date, end_date): """Get the failed downloads between start_date and end_date.""" gw = SystemGateway() downloads = [] for shard_id in get_shard_ids(): downloads.extend(list(gw.get_failed_downloads( shard_id, start_date, end_date))) return downloads
def get_abandoned_uploadjobs(last_active, limit=1000): """Return the live resumable uploadjobs. @param last_active_before: datetime, a filter of the when_started field. @param limit: the limit on the number of results """ gw = SystemGateway() return gw.get_abandoned_uploadjobs(last_active, limit)
def make_storage_user(user_id, username, visible_name, max_storage_bytes, shard_id=None): """Create or update a StorageUser.""" gw = SystemGateway() if not shard_id: shard_id = get_new_user_shard_id(user_id) return gw.create_or_update_user( user_id, username, visible_name, max_storage_bytes, shard_id=shard_id)
def download_update(user_id, download_id, status=None, node_id=None, error_message=None): """Update a download directly. Typically this isn't used. """ gw = SystemGateway() return gw.update_download(user_id, download_id, status=status, node_id=node_id, error_message=error_message)
def get_abandoned_uploadjobs(shard_id, last_active, limit=1000): """Return the live resumable uploadjobs. @param shard_id: the shard to use for the query. @param last_active_before: datetime, a filter of the when_started field. @param limit: the limit on the number of results """ gw = SystemGateway() return gw.get_abandoned_uploadjobs(shard_id, last_active, limit)
def get_status(user_id, volume_id, path, download_url, dl_key): """Get the status of the download.""" gw = SystemGateway() try: download = gw.get_download( user_id, volume_id, path, download_url, dl_key) except errors.DoesNotExist: return UNKNOWN return get_status_from_download(user_id, download)
def get_status(user_id, volume_id, path, download_url, dl_key): """Get the status of the download.""" gw = SystemGateway() try: download = gw.get_download(user_id, volume_id, path, download_url, dl_key) except errors.DoesNotExist: return UNKNOWN return get_status_from_download(user_id, download)
def claim_shareoffer(user_id, username, visible_name, share_offer_id): """Claim a shared folder offer sent to an email. Used when a user has been offered a shared folder, but has not subscribed yet and they are not a storageuser. This will create a storageuser in an inactive state so they will have the share once they subscribe. """ gw = SystemGateway() return gw.claim_shareoffer(user_id, username, visible_name, share_offer_id)
def get_or_make_download(user_id, volume_id, path, download_url, dl_key): """Get or make a download if it doesn't already exist.""" gw = SystemGateway() try: download = gw.get_download(user_id, volume_id, path, download_url, dl_key) except errors.DoesNotExist: download = gw.make_download(user_id, volume_id, path, download_url, dl_key) return download
def get_or_make_download(user_id, volume_id, path, download_url, dl_key): """Get or make a download if it doesn't already exist.""" gw = SystemGateway() try: download = gw.get_download( user_id, volume_id, path, download_url, dl_key) except errors.DoesNotExist: download = gw.make_download( user_id, volume_id, path, download_url, dl_key) return download
def get_storage_user(user_id=None, username=None, session_id=None, active_only=True, readonly=False): """Get a storage user. readonly kwarg is just to not raise LockedUserError in case the user is locked. """ gw = SystemGateway() user = gw.get_user(user_id=user_id, username=username, session_id=session_id, ignore_lock=readonly) if active_only and (user is None or not user.is_active): raise errors.DoesNotExist("User does not exist.") return user
def get_status_from_download(user_id, download): """Gets the status from a download object.""" gw = SystemGateway() if download.status == model.DOWNLOAD_STATUS_COMPLETE: # check if the file is actually present user = gw.get_user(user_id) try: gw.get_node(download.node_id, user.shard_id) except errors.DoesNotExist: return DOWNLOADED_NOT_PRESENT return download.status
class UserDAO(object): """DAO to retrieve data not associated to a specific user in context.""" def __init__(self): from backends.filesync.data.gateway import SystemGateway self._gateway = SystemGateway() def get_random_user_id(self): """Retrieves a random user id from the gateway.""" return self._gateway.get_random_user_id()
def make_user(self, user_id=None, username=None, visible_name=None, max_storage_bytes=2**20, shard_id=default_shard_id): if username is None: username = self.get_unique_unicode() if visible_name is None: visible_name = self.get_unique_unicode() if user_id is None: user_id = self.get_unique_integer() user = SystemGateway().create_or_update_user(user_id, username, visible_name, max_storage_bytes, shard_id=shard_id) storage_tm.commit() return user
def test_txlogs_when_user_signs_up(self): """Check that when a user signs up we get a txlog for the new user and one for their root UDF. """ user_id = self.obj_factory.get_unique_integer() name = self.obj_factory.get_unique_unicode() user = SystemGateway().create_or_update_user( user_id, name, name, max_storage_bytes=user_id, shard_id=self.obj_factory.sstore_name) udf = self.sstore.find(UserVolume, owner_id=user.id).one() udf_txlog = self.sstore.find( TransactionLog, op_type=TransactionLog.OP_UDF_CREATED).one() self.assertTxLogDetailsMatchesUserVolumeDetails( udf_txlog, udf, TransactionLog.OP_UDF_CREATED) user_txlog = self.sstore.find( TransactionLog, op_type=TransactionLog.OP_USER_CREATED).one() self.assertTxLogDetailsMatchesUserDetails(user, user_txlog)
def download_complete(user_id, download_id, hash, crc32, size, deflated_size, mimetype, storage_key): """Complete the download.""" gw = SystemGateway() return gw.download_complete(user_id, download_id, hash, crc32, size, deflated_size, mimetype, storage_key)
def download_start(user_id, download_id): """Start the download.""" SystemGateway().update_download(user_id, download_id, status=model.DOWNLOAD_STATUS_DOWNLOADING)
def download_error(user_id, download_id, message): """Mark the download as in error.""" return SystemGateway().update_download(user_id, download_id, status=model.DOWNLOAD_STATUS_ERROR, error_message=message)
def get_download_by_id(user_id, download_id): """Get a download by its ID.""" gw = SystemGateway() return gw.get_download_by_id(user_id, download_id)
def get_failed_downloads(start_date, end_date): """Get the failed downloads between start_date and end_date.""" gw = SystemGateway() return gw.get_failed_downloads(start_date, end_date)
def get_user_info_for_shard(user_id, shard_id): """Get the UserInfo dao (read only) for the user_id, shard_id.""" gw = SystemGateway() return gw.get_user_info(user_id, shard_id)
def get_download(user_id, udf_id, file_path, download_url, download_key=None): """Get a download by its UDF, file path and download URL and key.""" gw = SystemGateway() return gw.get_download(user_id, udf_id, file_path, download_url, download_key)
def get_download(user_id, udf_id, file_path, download_url, download_key=None): """Get a download by its UDF, file path and download URL and key.""" gw = SystemGateway() return gw.get_download( user_id, udf_id, file_path, download_url, download_key)
def get_public_directory(public_key): """Get a public directory.""" gw = SystemGateway() return gw.get_public_directory(public_key)
def make_download(user_id, udf_id, file_path, download_url, download_key=None): """Create a new download object.""" gw = SystemGateway() return gw.make_download( user_id, udf_id, file_path, download_url, download_key)
def get_public_file(public_key, use_uuid=False): """Get a public file.""" gw = SystemGateway() return gw.get_public_file(public_key, use_uuid=use_uuid)
def get_shareoffer(shareoffer_id): """Get a Share Offer.""" gw = SystemGateway() return gw.get_shareoffer(shareoffer_id)
def make_storage_user(user_id, username, visible_name, max_storage_bytes): """Create or update a StorageUser.""" gw = SystemGateway() return gw.create_or_update_user( user_id, username, visible_name, max_storage_bytes)
def make_download(user_id, udf_id, file_path, download_url, download_key=None): """Create a new download object.""" gw = SystemGateway() return gw.make_download(user_id, udf_id, file_path, download_url, download_key)
def make_storage_user(user_id, username, visible_name, max_storage_bytes, shard_id=None): """Create or update a StorageUser.""" gw = SystemGateway() if not shard_id: shard_id = get_new_user_shard_id(user_id) return gw.create_or_update_user(user_id, username, visible_name, max_storage_bytes, shard_id=shard_id)
def __init__(self): from backends.filesync.data.gateway import SystemGateway self._gateway = SystemGateway()