예제 #1
0
    def _set_synced_after(func, *args, **kwargs):
        call_args = inspect.getcallargs(func, *args, **kwargs)
        self = call_args['self']
        sync_result = constants.ResourceSync.SUCCEED
        ret = None
        try:
            ret = func(*args, **kwargs)
        except Exception:
            sync_result = constants.ResourceSync.FAILED
        lock = coordination.Lock(self.storage_id)
        with lock:
            try:
                storage = db.storage_get(self.context, self.storage_id)
            except exception.StorageNotFound:
                LOG.warn('Storage %s not found when set synced' %
                         self.storage_id)
            else:
                # One sync task done, sync status minus 1
                # When sync status get to 0
                # means all the sync tasks are completed
                if storage['sync_status'] != constants.SyncStatus.SYNCED:
                    storage['sync_status'] -= sync_result
                    db.storage_update(self.context, self.storage_id,
                                      {'sync_status': storage['sync_status']})

        return ret
예제 #2
0
파일: api.py 프로젝트: zhilong-xu/delfin
    def update_access_info(self, context, access_info):
        """Validate and update access information."""
        helper.encrypt_password(context, access_info)
        driver = self.driver_manager.get_driver(context,
                                                cache_on_load=False,
                                                **access_info)
        storage_new = driver.get_storage(context)

        # Need to validate storage response from driver
        storage_id = access_info['storage_id']
        helper.check_storage_consistency(context, storage_id, storage_new)
        access_info = db.access_info_update(context, storage_id, access_info)
        db.storage_update(context, storage_id, storage_new)

        LOG.info("Access information updated successfully.")
        return access_info
예제 #3
0
    def sync(self):
        """
        :return:
        """
        LOG.info('Syncing storage device for storage id:{0}'.format(
            self.storage_id))
        try:
            storage = self.driver_api.get_storage(self.context,
                                                  self.storage_id)

            db.storage_update(self.context, self.storage_id, storage)
        except Exception as e:
            msg = _('Failed to update storage entry in DB: {0}'.format(e))
            LOG.error(msg)
            raise
        else:
            LOG.info("Syncing storage successful!!!")
예제 #4
0
def _set_synced_if_ok(context, storage_id, resource_count):
    try:
        storage = db.storage_get(context, storage_id)
    except exception.StorageNotFound:
        msg = 'Storage %s not found when try to set sync_status' \
              % storage_id
        raise exception.InvalidInput(message=msg)
    else:
        last_update = storage['updated_at'] or storage['created_at']
        current_time = timeutils.utcnow()
        interval = (current_time - last_update).seconds
        # If last synchronization was within
        # CONF.sync_task_expiration(in seconds), and the sync status
        # is bigger than 0, it means some sync task is still running,
        # the new sync task should not launch
        if interval < CONF.sync_task_expiration and \
                storage['sync_status'] > 0:
            raise exception.StorageIsSyncing(storage['id'])
        storage['sync_status'] = resource_count * constants.ResourceSync.START
        db.storage_update(context, storage['id'], storage)
예제 #5
0
def update_storage(context, storage_id, storage):
    return db.storage_update(context, storage_id, storage)