Ejemplo n.º 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()
Ejemplo n.º 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)
Ejemplo n.º 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_
Ejemplo n.º 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
Ejemplo n.º 5
0
def get_all() -> List[Source]:
    return Session.query(Source).all()
Ejemplo n.º 6
0
def save(destination_: HttpDestination):
    if not Session.object_session(destination_):
        Session.add(destination_)
    Session.commit()
Ejemplo n.º 7
0
def get_by_type(source_type: str) -> List[Source]:
    return Session.query(Source).filter(Source.type == source_type).all()
Ejemplo n.º 8
0
def exists(url: str) -> bool:
    return bool(Session.query(
        Session.query(StreamSets).filter(StreamSets.url == url).exists()
    ).scalar())
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 11
0
def delete(streamsets: StreamSets):
    Session.delete(streamsets)
    Session.commit()
Ejemplo n.º 12
0
def exists(source_name: str) -> bool:
    return Session.query(
        Session.query(Source).filter(
            Source.name == source_name).exists()).scalar()
Ejemplo n.º 13
0
def save(source_: Source):
    if not Session.object_session(source_):
        Session.add(source_)
    Session.commit()
Ejemplo n.º 14
0
def exists() -> bool:
    return Session.query(Session.query(HttpDestination).exists()).scalar()
Ejemplo n.º 15
0
def get() -> HttpDestination:
    destination_ = Session.query(HttpDestination).first()
    if not destination_:
        raise DestinationNotExists(f"Destination does not exist")
    return destination_
Ejemplo n.º 16
0
def delete_auth_token(token: AuthenticationToken):
    Session.delete(token)
    Session.commit()
Ejemplo n.º 17
0
def save_auth_token(token: AuthenticationToken):
    if not Session.object_session(token):
        Session.add(token)
    Session.commit()
Ejemplo n.º 18
0
def delete():
    if not exists():
        return
    Session.delete(get())
    Session.commit()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 21
0
def get_all() -> List[StreamSets]:
    return Session.query(StreamSets).all()
Ejemplo n.º 22
0
def get_all_names() -> List[str]:
    return list(map(lambda row: row[0], Session.query(Source.name).all()))
Ejemplo n.º 23
0
def save(streamsets: StreamSets):
    if not Session.object_session(streamsets):
        Session.add(streamsets)
    Session.commit()
Ejemplo n.º 24
0
def get_by_streamsets_url(streamsets_url: str) -> List[Pipeline]:
    return Session.query(Pipeline).filter(
        Pipeline.streamsets.has(url=streamsets_url)).all()
Ejemplo n.º 25
0
def get_all_names() -> List[str]:
    res = list(map(
        lambda row: row[0],
        Session.query(StreamSets.url).all()
    ))
    return res
Ejemplo n.º 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_
Ejemplo n.º 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
Ejemplo n.º 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_
Ejemplo n.º 29
0
def find_by_name_beginning(name_part: str) -> List[Source]:
    return Session.query(Source).filter(
        Source.name.like(f'{name_part}%')).all()
Ejemplo n.º 30
0
def remove_deleted_pipeline_id(pipeline_id: str):
    Session.execute(
        f"DELETE FROM deleted_pipelines WHERE pipeline_id = '{pipeline_id}'")
    Session.commit()