Exemple #1
0
def delete_feed(feed):
    session = db.get_session()
    try:
        f = db.lookup_feed(db_session=session, feed_name=feed)
        if not f:
            raise ResourceNotFound(resource=feed, detail={})
        elif f.enabled:
            raise ConflictingRequest(
                message="Cannot delete an enabled feed. Disable the feed first",
                detail={},
            )
    except AnchoreApiError:
        raise
    except Exception as e:
        return jsonify(make_response_error(e, in_httpcode=500)), 500
    finally:
        session.rollback()

    try:
        f = sync.DataFeeds.delete_feed(feed)
        if f:
            return jsonify(_marshall_feed_response(f).to_json()), 200
        else:
            raise ResourceNotFound(feed, detail={})
    except KeyError as e:
        raise ResourceNotFound(resource=str(e), detail={"feed": feed})
    except AnchoreApiError:
        raise
    except Exception as e:
        return jsonify(make_response_error(e, in_httpcode=500)), 500
Exemple #2
0
    def __init__(self, metadata=None):
        if not metadata:
            db = get_session()
            metadata = lookup_feed(db, self.__feed_name__)
            if not metadata:
                raise Exception("Must have feed metadata in db already, should sync metadata before invoking instance operations")

        super(AnchoreServiceFeed, self).__init__(metadata=metadata)
Exemple #3
0
    def update_counts(self):
        """
        Self-contained unit of work to update the row counts for each feed group in the feed group metadata
        :return:
        """

        db = get_session()
        try:
            logger.debug('Updating group counts for feed {}'.format(self.__feed_name__))
            my_meta = lookup_feed(db, self.__feed_name__)
            for group in my_meta.groups:
                group.count = self.record_count(group.name, db)
                logger.info('Updating feed group {} record count = {}'.format(group.name, group.count))
            db.commit()
        except Exception:
            db.rollback()
            logger.error('Could not update group counts')
            raise