Example #1
0
def delete(source_: Source):
    if source_.pipelines:
        raise Exception(
            f"Can't delete. Source is used by {', '.join([p.name for p in source_.pipelines])} pipelines"
        )
    Session.delete(source_)
    Session.commit()
Example #2
0
def create_notifications(pipeline_):
    if notifies := pipeline_.config.get("notifications"):
        pipeline_.notifications = PiplineNotifications()
        if no_data_notification := notifies.get('no_data'):
            pipeline_.notifications.no_data_notification = NoDataNotifications(
                pipeline_,
                no_data_notification,
            )
            Session.add(pipeline_.notifications.no_data_notification)
Example #3
0
def get_by_id(pipeline_id: str) -> Pipeline:
    pipeline_ = Session.query(Pipeline).filter(
        Pipeline.name == pipeline_id).first()
    if not pipeline_:
        raise PipelineNotExistsException(
            f"Pipeline {pipeline_id} doesn't exist")
    return pipeline_
Example #4
0
class SessionManager:
    def __init__(self, entity):
        self.entity = entity
        self.session = Session()
        if not self.session.object_session(self.entity):
            self.session.add(self.entity)

    def __enter__(self):
        return self.session

    def __exit__(self, exc_type, exc_value, exc_traceback):
        if exc_value:
            self.session.expunge(self.entity)
            return False
        self.session.commit()
        return True
Example #5
0
def get_all() -> List[Source]:
    return Session.query(Source).all()
Example #6
0
def save(destination_: HttpDestination):
    if not Session.object_session(destination_):
        Session.add(destination_)
    Session.commit()
Example #7
0
def get_by_type(source_type: str) -> List[Source]:
    return Session.query(Source).filter(Source.type == source_type).all()
Example #8
0
def exists(url: str) -> bool:
    return bool(Session.query(
        Session.query(StreamSets).filter(StreamSets.url == url).exists()
    ).scalar())
Example #9
0
from agent.pipeline.notifications import PiplineNotifications, NoDataNotifications
from agent.modules.db import Session


def create_notifications(pipeline_):
    if notifies := pipeline_.config.get("notifications"):
        pipeline_.notifications = PiplineNotifications()
        if no_data_notification := notifies.get('no_data'):
            pipeline_.notifications.no_data_notification = NoDataNotifications(
                pipeline_,
                no_data_notification,
            )
            Session.add(pipeline_.notifications.no_data_notification)
        Session.add(pipeline_.notifications)
Example #10
0
def get_by_url(url: str) -> StreamSets:
    streamsets = Session.query(StreamSets).filter(StreamSets.url == url).first()
    if not streamsets:
        raise StreamsetsNotExistsException(f'StreamSets with url {url} doesn\'t exist')
    return streamsets
Example #11
0
def delete(streamsets: StreamSets):
    Session.delete(streamsets)
    Session.commit()
Example #12
0
def exists(source_name: str) -> bool:
    return Session.query(
        Session.query(Source).filter(
            Source.name == source_name).exists()).scalar()
Example #13
0
def save(source_: Source):
    if not Session.object_session(source_):
        Session.add(source_)
    Session.commit()
Example #14
0
def exists() -> bool:
    return Session.query(Session.query(HttpDestination).exists()).scalar()
Example #15
0
def get() -> HttpDestination:
    destination_ = Session.query(HttpDestination).first()
    if not destination_:
        raise DestinationNotExists(f"Destination does not exist")
    return destination_
Example #16
0
def delete_auth_token(token: AuthenticationToken):
    Session.delete(token)
    Session.commit()
Example #17
0
def save_auth_token(token: AuthenticationToken):
    if not Session.object_session(token):
        Session.add(token)
    Session.commit()
Example #18
0
def delete():
    if not exists():
        return
    Session.delete(get())
    Session.commit()
Example #19
0
def get_last_edited(source_type: str) -> Optional[Source]:
    return Session.query(Source).filter(Source.type == source_type).order_by(
        Source.last_edited.desc()).first()
Example #20
0
def add_deleted_pipeline_id(pipeline_id: str):
    Session.execute(
        f"INSERT INTO deleted_pipelines VALUES ('{pipeline_id}') ON CONFLICT DO NOTHING"
    )
    Session.commit()
Example #21
0
def get_all() -> List[StreamSets]:
    return Session.query(StreamSets).all()
Example #22
0
def get_all_names() -> List[str]:
    return list(map(lambda row: row[0], Session.query(Source.name).all()))
Example #23
0
def save(streamsets: StreamSets):
    if not Session.object_session(streamsets):
        Session.add(streamsets)
    Session.commit()
Example #24
0
def get_by_streamsets_url(streamsets_url: str) -> List[Pipeline]:
    return Session.query(Pipeline).filter(
        Pipeline.streamsets.has(url=streamsets_url)).all()
Example #25
0
def get_all_names() -> List[str]:
    res = list(map(
        lambda row: row[0],
        Session.query(StreamSets.url).all()
    ))
    return res
Example #26
0
def get(source_id: int) -> Source:
    source_ = Session.query(Source).get(source_id)
    if not source_:
        raise SourceNotExists(f"Source ID = {source_id} doesn't exist")
    return source_
Example #27
0
def get(id_: int) -> StreamSets:
    streamsets = Session.query(StreamSets).filter(StreamSets.id == id_).first()
    if not streamsets:
        raise StreamsetsNotExistsException(f'StreamSets with id {id_} doesn\'t exist')
    return streamsets
Example #28
0
def get_by_name(source_name: str) -> Source:
    source_ = Session.query(Source).filter(Source.name == source_name).first()
    if not source_:
        raise SourceNotExists(f"Source config {source_name} doesn't exist")
    return source_
Example #29
0
def find_by_name_beginning(name_part: str) -> List[Source]:
    return Session.query(Source).filter(
        Source.name.like(f'{name_part}%')).all()
Example #30
0
def remove_deleted_pipeline_id(pipeline_id: str):
    Session.execute(
        f"DELETE FROM deleted_pipelines WHERE pipeline_id = '{pipeline_id}'")
    Session.commit()