Exemplo n.º 1
0
    def on_put(self, req, resp, tenant_id, event_producer_id, validated_body):

        body = validated_body['event_producer']

        #verify the tenant exists
        tenant = find_tenant(self.db, tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        #verify the event_producer exists and belongs to the tenant
        event_producer = find_event_producer(tenant,
                                             producer_id=event_producer_id)
        if not event_producer:
            _producer_not_found()

        #if a key is present, update the event_producer with the value
        if 'name' in body.keys() and event_producer.name != body['name']:
            #if the tenant already has a profile with this name then abort
            duplicate_producer = \
                find_event_producer(tenant,  producer_name=body['name'])
            if duplicate_producer:
                abort(
                    falcon.HTTP_400,
                    'EventProducer with name {0} already exists with id={1}.'.
                    format(duplicate_producer.name,
                           duplicate_producer.get_id()))
            event_producer.name = body['name']

        if 'pattern' in body:
            event_producer.pattern = str(body['pattern'])

        if 'durable' in body:
            event_producer.durable = body['durable']

        if 'encrypted' in body:
            event_producer.encrypted = body['encrypted']

        if 'sinks' in body:
            event_producer.sinks = body['sinks']

        self.db.update('tenant', tenant.format_for_save())

        resp.status = falcon.HTTP_200
Exemplo n.º 2
0
    def on_put(self, req, resp, tenant_id, event_producer_id, validated_body):

        body = validated_body['event_producer']

        #verify the tenant exists
        tenant = find_tenant(self.db, tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        #verify the event_producer exists and belongs to the tenant
        event_producer = find_event_producer(tenant,
                                             producer_id=event_producer_id)
        if not event_producer:
            _producer_not_found()

        #if a key is present, update the event_producer with the value
        if 'name' in body.keys() and event_producer.name != body['name']:
            #if the tenant already has a profile with this name then abort
            duplicate_producer = \
                find_event_producer(tenant,  producer_name=body['name'])
            if duplicate_producer:
                abort(falcon.HTTP_400,
                      'EventProducer with name {0} already exists with id={1}.'
                      .format(duplicate_producer.name,
                              duplicate_producer.get_id()))
            event_producer.name = body['name']

        if 'pattern' in body:
            event_producer.pattern = str(body['pattern'])

        if 'durable' in body:
            event_producer.durable = body['durable']

        if 'encrypted' in body:
            event_producer.encrypted = body['encrypted']

        if 'sinks' in body:
            event_producer.sinks = body['sinks']

        self.db.update('tenant', tenant.format_for_save())

        resp.status = falcon.HTTP_200
Exemplo n.º 3
0
    def on_post(self, req, resp, tenant_id, validated_body):
        body = validated_body['event_producer']

        tenant = find_tenant(self.db, tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        event_producer_name = body['name']
        event_producer_pattern = body['pattern']

        #if durable or encrypted aren't specified, set to False
        if 'durable' in body.keys():
            event_producer_durable = body['durable']
        else:
            event_producer_durable = False

        if 'encrypted' in body.keys():
            event_producer_encrypted = body['encrypted']
        else:
            event_producer_encrypted = False

        if 'sinks' in body.keys():
            event_producer_sinks = body['sinks']
        else:
            event_producer_sinks = None

        # Check if the tenant already has an event producer with this name
        producer = find_event_producer(tenant,
                                       producer_name=event_producer_name)
        if producer:
            abort(falcon.HTTP_400,
                  'Event producer with name {0} already exists with id={1}.'
                  .format(producer.name, producer.get_id()))

        # Create the new profile for the host
        new_event_producer = EventProducer(
            self.db.next_sequence_value(tenant.tenant_id),
            event_producer_name,
            event_producer_pattern,
            event_producer_durable,
            event_producer_encrypted,
            event_producer_sinks)

        tenant.event_producers.append(new_event_producer)
        self.db.update('tenant', tenant.format_for_save())

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/producers/{1}'
                        .format(tenant_id, new_event_producer.get_id()))
Exemplo n.º 4
0
    def on_post(self, req, resp, tenant_id, validated_body):
        body = validated_body['event_producer']

        tenant = find_tenant(self.db, tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        event_producer_name = body['name']
        event_producer_pattern = body['pattern']

        #if durable or encrypted aren't specified, set to False
        if 'durable' in body.keys():
            event_producer_durable = body['durable']
        else:
            event_producer_durable = False

        if 'encrypted' in body.keys():
            event_producer_encrypted = body['encrypted']
        else:
            event_producer_encrypted = False

        if 'sinks' in body.keys():
            event_producer_sinks = body['sinks']
        else:
            event_producer_sinks = None

        # Check if the tenant already has an event producer with this name
        producer = find_event_producer(tenant,
                                       producer_name=event_producer_name)
        if producer:
            abort(
                falcon.HTTP_400,
                'Event producer with name {0} already exists with id={1}.'.
                format(producer.name, producer.get_id()))

        # Create the new profile for the host
        new_event_producer = EventProducer(
            self.db.next_sequence_value(tenant.tenant_id), event_producer_name,
            event_producer_pattern, event_producer_durable,
            event_producer_encrypted, event_producer_sinks)

        tenant.event_producers.append(new_event_producer)
        self.db.update('tenant', tenant.format_for_save())

        resp.status = falcon.HTTP_201
        resp.set_header(
            'Location',
            '/v1/{0}/producers/{1}'.format(tenant_id,
                                           new_event_producer.get_id()))
Exemplo n.º 5
0
    def on_get(self, req, resp, tenant_id, event_producer_id):
        #verify the tenant exists
        tenant = find_tenant(self.db, tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        #verify the event_producer exists and belongs to the tenant
        event_producer = find_event_producer(tenant,
                                             producer_id=event_producer_id)
        if not event_producer:
            _producer_not_found()

        resp.status = falcon.HTTP_200
        resp.body = format_response_body(
            {'event_producer': event_producer.format()})
Exemplo n.º 6
0
    def on_get(self, req, resp, tenant_id, event_producer_id):
        #verify the tenant exists
        tenant = find_tenant(self.db, tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        #verify the event_producer exists and belongs to the tenant
        event_producer = find_event_producer(tenant,
                                             producer_id=event_producer_id)
        if not event_producer:
            _producer_not_found()

        resp.status = falcon.HTTP_200
        resp.body = format_response_body(
            {'event_producer': event_producer.format()})
Exemplo n.º 7
0
    def on_put(self, req, resp, tenant_id, profile_id):
        #load the message
        body = load_body(req)

        self._validate_req_body_on_put(body)

        #verify the tenant exists
        tenant = find_tenant(self.db, tenant_id=tenant_id)
        if not tenant:
            _tenant_not_found()

        #verify the profile exists and belongs to the tenant
        profile = find_host_profile(tenant, profile_id=profile_id)
        if not profile:
            _profile_not_found()

        #if attributes are present in message, update the profile
        if 'name' in body.keys() and body['name'] != profile.name:

            #if the tenant already has a profile with this name then abort
            duplicate_profile = find_host_profile(tenant,
                                                  profile_name=body['name'])
            if duplicate_profile:
                abort(falcon.HTTP_400,
                      'Profile with name {0} already exists with id={1}.'
                      .format(duplicate_profile.name,
                              duplicate_profile.get_id()))

            profile.name = body['name']

        if 'event_producer_ids' in body.keys():
            producer_ids = body['event_producer_ids']

            for producer_id in producer_ids:

                #abort if any of the event_producers being passed in are not
                # valid event_producers for this tenant

                if not find_event_producer(tenant, producer_id=producer_id):
                    _producer_not_found()

            #update the list of event_producers
            profile.event_producers = producer_ids

        self.db.update('tenant', tenant.format_for_save())
        resp.status = falcon.HTTP_200
Exemplo n.º 8
0
    def on_delete(self, req, resp, tenant_id, event_producer_id):
        #verify the tenant exists
        tenant = find_tenant(self.db, tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        #verify the event_producer exists and belongs to the tenant
        event_producer = find_event_producer(tenant,
                                             producer_id=event_producer_id)
        if not event_producer:
            _producer_not_found()

        #remove any references to the event producer being deleted
        tenant.event_producers.remove(event_producer)

        self.db.update('tenant', tenant.format_for_save())

        resp.status = falcon.HTTP_200
Exemplo n.º 9
0
    def on_delete(self, req, resp, tenant_id, event_producer_id):
        #verify the tenant exists
        tenant = find_tenant(self.db, tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        #verify the event_producer exists and belongs to the tenant
        event_producer = find_event_producer(tenant,
                                             producer_id=event_producer_id)
        if not event_producer:
            _producer_not_found()

        #remove any references to the event producer being deleted
        tenant.event_producers.remove(event_producer)

        self.db.update('tenant', tenant.format_for_save())

        resp.status = falcon.HTTP_200
Exemplo n.º 10
0
    def on_post(self, req, resp, tenant_id):
        body = load_body(req)

        self._validate_req_body_on_post(body)

        tenant = find_tenant(self.db, tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        profile_name = body['name']

        # Check if the tenant already has a profile with this name
        profile = find_host_profile(tenant, profile_name=profile_name)
        if profile:
            abort(falcon.HTTP_400,
                  'Profile with name {0} already exists with id={1}.'
                  .format(profile.name, profile.get_id()))

        # Create the new profile for the host
        new_host_profile = HostProfile(
            self.db.next_sequence_value(tenant.tenant_id), profile_name)

        if 'event_producer_ids' in body.keys():
            producer_ids = body['event_producer_ids']

            for producer_id in producer_ids:

                #abort if any of the event_producers being passed in are not
                # valid event_producers for this tenant
                if not find_event_producer(tenant, producer_id=producer_id):
                    _producer_not_found()

            #update the list of event_producers
            new_host_profile.event_producers = producer_ids

        tenant.profiles.append(new_host_profile)
        self.db.update('tenant', tenant.format_for_save())

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/profiles/{1}'
                        .format(tenant_id, new_host_profile.get_id()))
Exemplo n.º 11
0
def add_correlation_info_to_message(tenant, message):
    #match the producer by the message pname
    producer = find_event_producer(
        tenant, producer_name=message['pname'])

    #if the producer is not found, create a default producer
    if not producer:
        producer = EventProducer(_id=None, name="default", pattern="default")

    #create correlation dictionary
    correlation_dict = {
        'tenant_name': tenant.tenant_name,
        'ep_id': producer.get_id(),
        'pattern': producer.pattern,
        'durable': producer.durable,
        'encrypted': producer.encrypted,
        '@timestamp': timeutils.utcnow(),
        'sinks': producer.sinks,
        "destinations": dict()
    }

    #configure sink dispatch
    destinations = dict()
    for sink in producer.sinks:
        correlation_dict["destinations"][sink] = {
            'transaction_id': None,
            'transaction_time': None
        }

    #todo(sgonzales) persist message and create job
    if producer.durable:
        durable_job_id = str(uuid4())
        correlation_dict.update({'job_id': durable_job_id})

    message.update({
        "meniscus": {
            "tenant": tenant.tenant_id,
            "correlation": correlation_dict
        }
    })

    return message
Exemplo n.º 12
0
def add_correlation_info_to_message(tenant, message):
    #match the producer by the message pname
    producer = find_event_producer(tenant, producer_name=message['pname'])

    #if the producer is not found, create a default producer
    if not producer:
        producer = EventProducer(_id=None, name="default", pattern="default")

    #create correlation dictionary
    correlation_dict = {
        'tenant_name': tenant.tenant_name,
        'ep_id': producer.get_id(),
        'pattern': producer.pattern,
        'durable': producer.durable,
        'encrypted': producer.encrypted,
        '@timestamp': timeutils.utcnow(),
        'sinks': producer.sinks,
        "destinations": dict()
    }

    #configure sink dispatch
    destinations = dict()
    for sink in producer.sinks:
        correlation_dict["destinations"][sink] = {
            'transaction_id': None,
            'transaction_time': None
        }

    #todo(sgonzales) persist message and create job
    if producer.durable:
        durable_job_id = str(uuid4())
        correlation_dict.update({'job_id': durable_job_id})

    message.update({
        "meniscus": {
            "tenant": tenant.tenant_id,
            "correlation": correlation_dict
        }
    })

    return message
Exemplo n.º 13
0
 def test_find_event_producer_by_name_returns_none(self):
     tenant = find_tenant(self.ds_handler, '12345')
     producer = find_event_producer(tenant, producer_name='not_name')
     self.assertEquals(producer, None)
Exemplo n.º 14
0
 def test_find_event_producer_by_name_returns_instance(self):
     tenant = find_tenant(self.ds_handler, '12345')
     producer = find_event_producer(tenant, producer_name='system.auth')
     self.assertIsInstance(producer, EventProducer)
Exemplo n.º 15
0
 def test_find_event_producer_by_id_returns_none(self):
     tenant = find_tenant(self.ds_handler, '12345')
     producer = find_event_producer(tenant, producer_id=130)
     self.assertEquals(producer, None)
Exemplo n.º 16
0
 def test_find_event_producer_by_id_returns_instance(self):
     tenant = find_tenant(self.ds_handler, '12345')
     producer = find_event_producer(tenant, producer_id=123)
     self.assertIsInstance(producer, EventProducer)
Exemplo n.º 17
0
 def test_find_event_producer_by_name_returns_none(self):
     tenant = find_tenant(self.ds_handler, '12345')
     producer = find_event_producer(tenant, producer_name='not_name')
     self.assertEquals(producer, None)
Exemplo n.º 18
0
 def test_find_event_producer_by_name_returns_instance(self):
     tenant = find_tenant(self.ds_handler, '12345')
     producer = find_event_producer(tenant, producer_name='system.auth')
     self.assertIsInstance(producer, EventProducer)
Exemplo n.º 19
0
 def test_find_event_producer_by_id_returns_none(self):
     tenant = find_tenant(self.ds_handler, '12345')
     producer = find_event_producer(tenant, producer_id=130)
     self.assertEquals(producer, None)
Exemplo n.º 20
0
 def test_find_event_producer_by_id_returns_instance(self):
     tenant = find_tenant(self.ds_handler, '12345')
     producer = find_event_producer(tenant, producer_id=123)
     self.assertIsInstance(producer, EventProducer)