Esempio n. 1
0
def event_error_tracking_create(request):
    record = EventErrorTracking()

    record.user_id = get_logged_user_id(request)

    _update_record(request, record)

    # The object this tracking item is for.
    event_error = DBSession.query(EventError).filter(
        EventError.id == record.event_error_id).first()

    new_state = getattr(record, 'new_state', None)
    if new_state:
        # Change the state of the event error.
        event_error.state = new_state

    if record.user_id != event_error.responsible_id:
        # Update the responsible of the event error.
        event_error.responsible_id = record.user_id

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 2
0
def event_tracking_create(request):
    record = EventTracking()

    record.user_id = get_logged_user_id(request)

    _update_record(request, record)

    # The object this tracking item is for.
    event = DBSession.query(Event).filter(
        Event.id == record.event_id
    ).first()

    new_state = getattr(record, 'new_state', None)
    if new_state:
        # Change the state of the event.
        event.state = new_state

    if record.user_id != event.responsible_id:
        # Update the responsible of the event.
        event.responsible_id = record.user_id

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 3
0
def event_node_create(request):
    record = EventNode()

    _update_record(request, record)

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 4
0
def envelope_create(request):
    record = Envelope()

    _update_record(request, record)

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
def emitter_profile_create(request):
    record = EmitterProfile()

    _update_record(request, record)

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 6
0
def input_descriptor_create(request):
    record = InputDescriptor()

    _update_record(request, record)

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
def input_descriptor_create(request):
    record = InputDescriptor()

    _update_record(request, record)

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
def emitter_profile_create(request):
    record = EmitterProfile()

    _update_record(request, record)

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 9
0
def envelope_create(request):
    record = Envelope()

    _update_record(request, record)

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 10
0
def service_create(request):
    record = Service()

    _update_record(request, record)

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 11
0
def emitter_create(request):
    record = Emitter()

    _update_record(request, record)
    record.password = gen_password(request.json_body['password'])

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 12
0
def role_create(request):
    record = Role()

    _update_record(request, record)
    record.password = gen_password(request.json_body['password'])

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 13
0
def emission_profile_create(request):
    record = EmissionProfile()

    record.owner_id = get_logged_user_id(request)

    _update_record(request, record)

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 14
0
def emission_profile_create(request):
    record = EmissionProfile()

    record.owner_id = get_logged_user_id(request)

    _update_record(request, record)

    DBSession.add(record)
    DBSession.flush()
    DBSession.refresh(record)

    return record.as_dict()
Esempio n. 15
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from xbus.monitor.models.monitor import (
         BaseModel,
         MyModel,
         )
     DBSession.configure(bind=engine)
     BaseModel.metadata.create_all(engine)
     with transaction.manager:
         model = MyModel(name='one', value=55)
         DBSession.add(model)
Esempio n. 16
0
def _ensure_item_clearing_event_type(request):
    """Ensure an event type used when issuing Xbus requests related to data
    clearing items exists; otherwise, create it. It will have the "immediate
    reply" flag set.
    """

    session = DBSession()

    if session.query(EventType).filter(
            EventType.name == DATA_CLEARING_EVENT_TYPE).count() == 0:
        # Create an event type.
        event_type = EventType()
        event_type.description = (
            'Event type to carry Xbus requests related to data clearing items.'
        )
        event_type.immediate_reply = True
        event_type.name = DATA_CLEARING_EVENT_TYPE
        session.add(event_type)
        transaction.commit()
Esempio n. 17
0
def _ensure_item_clearing_event_type(request):
    """Ensure an event type used when issuing Xbus requests related to data
    clearing items exists; otherwise, create it. It will have the "immediate
    reply" flag set.
    """

    session = DBSession()

    if session.query(EventType).filter(
        EventType.name == DATA_CLEARING_EVENT_TYPE
    ).count() == 0:
        # Create an event type.
        event_type = EventType()
        event_type.description = (
            'Event type to carry Xbus requests related to data clearing items.'
        )
        event_type.immediate_reply = True
        event_type.name = DATA_CLEARING_EVENT_TYPE
        session.add(event_type)
        transaction.commit()
Esempio n. 18
0
def load_config(raw_xml):

    root = ElementTree.fromstring(raw_xml)
    session = DBSession()
    services = {}
    events = {}
    profiles = {}

    for service_elem in root.findall('service'):
        name = service_elem.get('name')
        consumer = service_elem.get('consumer', False)
        desc = service_elem.text.strip()
        q = session.query(Service)
        q = q.filter(Service.name == name)
        service = q.first()
        if not service:
            service = Service(name=name)
            session.add(service)
        service.consumer = consumer
        service.description = desc
        services[name] = service

    for role_elem in root.findall('role'):
        login = role_elem.get('login')
        if not login:
            login = role_elem.get('name')
        service_name = role_elem.get('service')
        service = services.get(service_name)
        if not service:
            q1 = session.query(Service)
            q1 = q1.filter(Service.name == service_name)
            service = q1.first()
            if not service:
                raise Exception('Unknown service {}'.format(service_name))
            services[service_name] = service
        q2 = session.query(Role)
        q2 = q2.filter(Role.login == login)
        role = q2.first()
        if not role:
            role = Role(login=login)
            session.add(role)
        role.service = service

    for event_elem in root.findall('event_type'):
        name = event_elem.get('name')
        desc = event_elem.text.strip()
        q1 = session.query(EventType)
        q1 = q1.filter(EventType.name == name)
        event = q1.first()
        if not event:
            event = EventType(name=name)
            session.add(event)
        service.description = desc
        events[name] = event

        elem_levels = [iter(event_elem)]
        node_levels = [event_elem]
        while elem_levels:

            try:
                elem = next(elem_levels[-1])
            except StopIteration:
                del elem_levels[-1]
                del node_levels[-1]
                continue

            if len(node_levels) > 1:
                parents = [node_levels[-1]]
                start = False
            else:
                parents = []
                start = True

            service_name = elem.get('service')
            service = services.get(service_name)
            if not service:
                q2 = session.query(Service)
                q2 = q2.filter(Service.name == service_name)
                service = q2.first()
                if not service:
                    raise Exception('Unknown service {}'.format(service_name))
                services[service_name] = service

            node = EventNode(type=event,
                             service=service,
                             parents=parents,
                             start=start)
            if elem.tag == 'worker':
                node_levels.append(node)
                elem_levels.append(iter(elem))

    for profile_elem in root.findall('profile'):
        name = profile_elem.get('name')
        desc = profile_elem.text.strip()

        event_types = []
        for type_elem in profile_elem.findall('event_type'):
            type_name = type_elem.get('name')
            event_type = events.get(type_name)
            if not event_type:
                q1 = session.query(EventType)
                q1 = q1.filter(EventType.name == type_name)
                event_type = q1.first()
                if not event_type:
                    raise Exception('Unknown event type {}'.format(type_name))
                events[type_name] = event_type
            event_types.append(event_type)

        q2 = session.query(EmitterProfile)
        q2 = q2.filter(EmitterProfile.name == name)
        profile = q2.first()
        if not profile:
            profile = EmitterProfile(name=name)
            session.add(profile)
        profile.description = desc
        profile.event_types = event_types
        profiles[name] = profile

    for emitter_elem in root.findall('emitter'):
        login = emitter_elem.get('login')
        if not login:
            login = emitter_elem.get('name')

        profile_name = emitter_elem.get('profile')
        profile = services.get(profile_name)
        if not profile:
            q1 = session.query(EmitterProfile)
            q1 = q1.filter(EmitterProfile.name == profile_name)
            profile = q1.first()
            if not profile:
                raise Exception('Unknown profile {}'.format(profile_name))
            profiles[profile_name] = profile
        q2 = session.query(Emitter)
        q2 = q2.filter(Emitter.login == login)
        emitter = q2.first()
        if not emitter:
            emitter = Emitter(login=login)
            session.add(emitter)
        emitter.profile = profile
Esempio n. 19
0
def load_config(raw_xml):

    root = ElementTree.fromstring(raw_xml)
    session = DBSession()
    services = {}
    events = {}
    profiles = {}

    for service_elem in root.findall('service'):
        name = service_elem.get('name')
        consumer = service_elem.get('consumer', False)
        desc = service_elem.text.strip()
        q = session.query(Service)
        q = q.filter(Service.name == name)
        service = q.first()
        if not service:
            service = Service(name=name)
            session.add(service)
        service.consumer = consumer
        service.description = desc
        services[name] = service

    for role_elem in root.findall('role'):
        login = role_elem.get('login')
        if not login:
            login = role_elem.get('name')
        service_name = role_elem.get('service')
        service = services.get(service_name)
        if not service:
            q1 = session.query(Service)
            q1 = q1.filter(Service.name == service_name)
            service = q1.first()
            if not service:
                raise Exception('Unknown service {}'.format(service_name))
            services[service_name] = service
        q2 = session.query(Role)
        q2 = q2.filter(Role.login == login)
        role = q2.first()
        if not role:
            role = Role(login=login)
            session.add(role)
        role.service = service

    for event_elem in root.findall('event_type'):
        name = event_elem.get('name')
        desc = event_elem.text.strip()
        q1 = session.query(EventType)
        q1 = q1.filter(EventType.name == name)
        event = q1.first()
        if not event:
            event = EventType(name=name)
            session.add(event)
        service.description = desc
        events[name] = event

        elem_levels = [iter(event_elem)]
        node_levels = [event_elem]
        while elem_levels:

            try:
                elem = next(elem_levels[-1])
            except StopIteration:
                del elem_levels[-1]
                del node_levels[-1]
                continue

            if len(node_levels) > 1:
                parents = [node_levels[-1]]
                start = False
            else:
                parents = []
                start = True

            service_name = elem.get('service')
            service = services.get(service_name)
            if not service:
                q2 = session.query(Service)
                q2 = q2.filter(Service.name == service_name)
                service = q2.first()
                if not service:
                    raise Exception('Unknown service {}'.format(service_name))
                services[service_name] = service

            node = EventNode(
                type=event, service=service, parents=parents, start=start
            )
            if elem.tag == 'worker':
                node_levels.append(node)
                elem_levels.append(iter(elem))

    for profile_elem in root.findall('profile'):
        name = profile_elem.get('name')
        desc = profile_elem.text.strip()

        event_types = []
        for type_elem in profile_elem.findall('event_type'):
            type_name = type_elem.get('name')
            event_type = events.get(type_name)
            if not event_type:
                q1 = session.query(EventType)
                q1 = q1.filter(EventType.name == type_name)
                event_type = q1.first()
                if not event_type:
                    raise Exception('Unknown event type {}'.format(type_name))
                events[type_name] = event_type
            event_types.append(event_type)

        q2 = session.query(EmitterProfile)
        q2 = q2.filter(EmitterProfile.name == name)
        profile = q2.first()
        if not profile:
            profile = EmitterProfile(name=name)
            session.add(profile)
        profile.description = desc
        profile.event_types = event_types
        profiles[name] = profile

    for emitter_elem in root.findall('emitter'):
        login = emitter_elem.get('login')
        if not login:
            login = emitter_elem.get('name')

        profile_name = emitter_elem.get('profile')
        profile = services.get(profile_name)
        if not profile:
            q1 = session.query(EmitterProfile)
            q1 = q1.filter(EmitterProfile.name == profile_name)
            profile = q1.first()
            if not profile:
                raise Exception('Unknown profile {}'.format(profile_name))
            profiles[profile_name] = profile
        q2 = session.query(Emitter)
        q2 = q2.filter(Emitter.login == login)
        emitter = q2.first()
        if not emitter:
            emitter = Emitter(login=login)
            session.add(emitter)
        emitter.profile = profile