Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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
Exemplo n.º 8
0
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 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)
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
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)
Exemplo n.º 16
0
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
Exemplo n.º 18
0
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
Exemplo n.º 19
0
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)
Exemplo n.º 20
0
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
Exemplo n.º 21
0
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
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
Exemplo n.º 23
0
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 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)
Exemplo n.º 25
0
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()
Exemplo n.º 26
0
 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
Exemplo n.º 27
0
    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)
Exemplo n.º 32
0
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)
Exemplo n.º 33
0
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)
Exemplo n.º 35
0
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)
Exemplo n.º 36
0
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)
Exemplo n.º 37
0
def get_public_directory(public_key):
    """Get a public directory."""
    gw = SystemGateway()
    return gw.get_public_directory(public_key)
Exemplo n.º 38
0
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)
Exemplo n.º 39
0
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)
Exemplo n.º 40
0
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)
Exemplo n.º 41
0
def get_shareoffer(shareoffer_id):
    """Get a Share Offer."""
    gw = SystemGateway()
    return gw.get_shareoffer(shareoffer_id)
Exemplo n.º 42
0
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)
Exemplo n.º 44
0
def get_shareoffer(shareoffer_id):
    """Get a Share Offer."""
    gw = SystemGateway()
    return gw.get_shareoffer(shareoffer_id)
Exemplo n.º 45
0
def get_public_directory(public_key):
    """Get a public directory."""
    gw = SystemGateway()
    return gw.get_public_directory(public_key)
Exemplo n.º 46
0
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)
Exemplo n.º 47
0
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)
Exemplo n.º 48
0
 def __init__(self):
     from backends.filesync.data.gateway import SystemGateway
     self._gateway = SystemGateway()
Exemplo n.º 49
0
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)