Exemplo n.º 1
0
def _host_profile_id_invalid():
    """
    sends an http 400 response to the caller
    """
    abort(
        falcon.HTTP_400,
        'Malformed request, invalid value for profile_id')
Exemplo n.º 2
0
    def on_post(self, req, resp, tenant_id):
        tenant = find_tenant(self.db, tenant_id=tenant_id,
                             when_not_found=_tenant_not_found)

        body = load_body(req)
        hostname = body['hostname']
        ip_address = body['ip_address']
        
        # Check if the tenant already has a host with this hostname
        for host in tenant.hosts:
            if host.hostname == hostname:
                abort(400, 'Host with hostname {0} already exists with'
                           ' id={1}'.format(hostname, host.id))

        # Create the new host definition
        new_host = Host(hostname, ip_address)
        
        self.db.add(new_host)
        tenant.hosts.append(new_host)
        self.db().commit()

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/hosts/{1}'
                        .format(tenant_id, new_host.id))
Exemplo n.º 3
0
def _token_time_limit_not_reached():
    """
    sends an http 409 response to the caller
    """
    abort(falcon.HTTP_409,
          'Message tokens can only be changed once every {0} hours'
          .format(MIN_TOKEN_TIME_LIMIT_HRS))
Exemplo n.º 4
0
def _profile_producer_ids_invalid():
    """
    sends an http 400 response to the caller
    """
    abort(
        falcon.HTTP_400,
        'Malformed request, event_producer_ids must be a list of integers')
Exemplo n.º 5
0
def _token_time_limit_not_reached():
    """
    sends an http 409 response to the caller
    """
    abort(
        falcon.HTTP_409,
        'Message tokens can only be changed once every {0} hours'.format(
            MIN_TOKEN_TIME_LIMIT_HRS))
Exemplo n.º 6
0
    def _validate_req_body_on_post(self, body):
        """
        This method validates the on_post request body
        """
        try:
            validate_event_message_body(body)

        except MessageValidationError as ex:
            abort(falcon.HTTP_400, ex.message)
Exemplo n.º 7
0
    def on_post(self, req, resp, tenant_id):
        body = load_body(req)

        self._validate_req_body_on_post(body)

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

        if not tenant:
            _tenant_not_found()

        hostname = body['hostname']

        # Check if the tenant already has a host with this hostname
        for host in tenant.hosts:
            if host.hostname == hostname:
                abort(falcon.HTTP_400,
                      'Host with hostname {0} already exists with id={1}'
                      .format(hostname, host.get_id()))

        ip_address_v4 = None
        if 'ip_address_v4' in body.keys():
            ip_address_v4 = body['ip_address_v4']

        ip_address_v6 = None
        if 'ip_address_v6' in body.keys():
            ip_address_v6 = body['ip_address_v6']

        profile_id = None
        #if profile id is not in post message, then use a null profile
        if 'profile_id' in body.keys():
            if body['profile_id']:
                profile_id = body['profile_id']

        #if profile id is in post message, then make sure it is valid profile
        if profile_id:
            #verify the profile exists and belongs to the tenant
            profile = find_host_profile(tenant, profile_id=profile_id)
            if not profile:
                _profile_not_found()

        # Create the new host definition
        new_host = Host(
            self.db.next_sequence_value(tenant.tenant_id),
            hostname, ip_address_v4,
            ip_address_v6, profile_id)

        tenant.hosts.append(new_host)
        self.db.update('tenant', tenant.format_for_save())

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/hosts/{1}'
                        .format(tenant_id, new_host.get_id()))
Exemplo n.º 8
0
    def on_get(self, req, resp, hostname):
        """
        Retrieve the status of a specified worker node
        """
        # find the worker in db
        worker = worker_util.find_worker(hostname)

        if worker is None:
            api.abort(falcon.HTTP_404, "Unable to locate worker.")

        resp.status = falcon.HTTP_200
        resp.body = api.format_response_body({"status": worker.get_status()})
Exemplo n.º 9
0
    def on_get(self, req, resp, hostname):
        """
        Retrieve the status of a specified worker node
        """
        #find the worker in db
        worker = worker_util.find_worker(hostname)

        if worker is None:
            api.abort(falcon.HTTP_404, 'Unable to locate worker.')

        resp.status = falcon.HTTP_200
        resp.body = api.format_response_body({'status': worker.get_status()})
Exemplo n.º 10
0
    def on_post(self, req, resp, tenant_id, validated_body):
        """
        Create a a new event Producer for a specified Tenant
        when an HTTP Post is received
        """
        body = validated_body['event_producer']

        tenant = tenant_util.find_tenant(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 = tenant_util.find_event_producer(
            tenant, producer_name=event_producer_name)
        if producer:
            api.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
        producer_id = tenant_util.create_event_producer(
            tenant,
            event_producer_name,
            event_producer_pattern,
            event_producer_durable,
            event_producer_encrypted,
            event_producer_sinks)

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/producers/{1}'
                        .format(tenant_id, producer_id))
Exemplo n.º 11
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.º 12
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.º 13
0
    def on_post(self, req, resp, tenant_id, validated_body):
        """
        Create a a new event Producer for a specified Tenant
        when an HTTP Post is received
        """
        body = validated_body['event_producer']

        tenant = tenant_util.find_tenant(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 = tenant_util.find_event_producer(
            tenant, producer_name=event_producer_name)
        if producer:
            api.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
        producer_id = tenant_util.create_event_producer(
            tenant, event_producer_name, event_producer_pattern,
            event_producer_durable, event_producer_encrypted,
            event_producer_sinks)

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/producers/{1}'.format(tenant_id, producer_id))
Exemplo n.º 14
0
    def on_put(self, req, resp, tenant_id, event_producer_id, validated_body):
        """
        Make an update to a specified Event Producer's configuration
        when an HTTP PUT is received
        """

        body = validated_body['event_producer']

        #verify the tenant exists
        tenant = tenant_util.find_tenant(tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        #verify the event_producer exists and belongs to the tenant
        event_producer = tenant_util.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 = tenant_util.find_event_producer(
                tenant, producer_name=body['name'])
            if duplicate_producer:
                api.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']

        #save the tenant document
        tenant_util.save_tenant(tenant)

        resp.status = falcon.HTTP_200
Exemplo n.º 15
0
    def on_put(self, req, resp, tenant_id, event_producer_id, validated_body):
        """
        Make an update to a specified Event Producer's configuration
        when an HTTP PUT is received
        """

        body = validated_body['event_producer']

        #verify the tenant exists
        tenant = tenant_util.find_tenant(tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        #verify the event_producer exists and belongs to the tenant
        event_producer = tenant_util.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 = tenant_util.find_event_producer(
                tenant,  producer_name=body['name'])
            if duplicate_producer:
                api.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']

        #save the tenant document
        tenant_util.save_tenant(tenant)

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

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

        if tenant:
            abort(falcon.HTTP_400, 'Tenant with tenant_id {0} '
                  'already exists'.format(tenant_id))

        new_tenant = Tenant(tenant_id)
        self.db.add(new_tenant)
        self.db.commit()

        resp.status = falcon.HTTP_201
        resp.set_header('Location', '/v1/{0}'.format(tenant_id))
Exemplo n.º 17
0
    def on_put(self, req, resp, tenant_id, host_id):
        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 hosts exists and belongs to the tenant
        host = find_host(tenant, host_id=host_id)
        if not host:
            _host_not_found()

        if 'hostname' in body.keys() and host.hostname != body['hostname']:
            # Check if the tenant already has a host with this hostname
            hostname = str(body['hostname'])
            for duplicate_host in tenant.hosts:
                if duplicate_host.hostname == hostname:
                    abort(falcon.HTTP_400,
                          'Host with hostname {0} already exists with'
                          ' id={1}'.format(hostname, duplicate_host.get_id()))
            host.hostname = hostname

        if 'ip_address_v4' in body.keys():
            host.ip_address_v4 = body['ip_address_v4']

        if 'ip_address_v6' in body.keys():
            host.ip_address_v6 = body['ip_address_v6']

        if 'profile_id' in body.keys():
            if body['profile_id']:
                host.profile = int(body['profile_id'])
            else:
                host.profile = None

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

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

        resp.status = falcon.HTTP_200
Exemplo n.º 18
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.º 19
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.º 20
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.º 21
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.º 22
0
    def on_post(self, req, resp, validated_body):
        """
        Create a new tenant when a HTTP POST is received
        """

        body = validated_body['tenant']
        tenant_id = str(body['tenant_id'])

        tenant_name = body.get('tenant_name', tenant_id)

        #validate that tenant does not already exists
        tenant = tenant_util.find_tenant(tenant_id=tenant_id)
        if tenant:
            api.abort(falcon.HTTP_400, 'Tenant with tenant_id {0} '
                      'already exists'.format(tenant_id))

        tenant_util.create_tenant(tenant_id=tenant_id, tenant_name=tenant_name)

        resp.status = falcon.HTTP_201
        resp.set_header('Location', '/v1/{0}'.format(tenant_id))
Exemplo n.º 23
0
    def on_post(self, req, resp, validated_body):
        """
        Create a new tenant when a HTTP POST is received
        """

        body = validated_body['tenant']
        tenant_id = str(body['tenant_id'])

        tenant_name = body.get('tenant_name', tenant_id)

        #validate that tenant does not already exists
        tenant = tenant_util.find_tenant(tenant_id=tenant_id)
        if tenant:
            api.abort(
                falcon.HTTP_400, 'Tenant with tenant_id {0} '
                'already exists'.format(tenant_id))

        tenant_util.create_tenant(tenant_id=tenant_id, tenant_name=tenant_name)

        resp.status = falcon.HTTP_201
        resp.set_header('Location', '/v1/{0}'.format(tenant_id))
Exemplo n.º 24
0
    def on_post(self, req, resp, validated_body):

        body = validated_body['tenant']
        tenant_id = str(body['tenant_id'])

        tenant_name = body.get('tenant_name', tenant_id)

        #validate that tenant does not already exists
        tenant = find_tenant(self.db, tenant_id=tenant_id)
        if tenant:
            abort(falcon.HTTP_400, 'Tenant with tenant_id {0} '
                  'already exists'.format(tenant_id))

        #create new token for the tenant
        new_token = Token()
        new_tenant = Tenant(tenant_id, new_token, tenant_name=tenant_name)

        self.db.put('tenant', new_tenant.format())
        self.db.create_sequence(new_tenant.tenant_id)
        resp.status = falcon.HTTP_201
        resp.set_header('Location', '/v1/{0}'.format(tenant_id))
Exemplo n.º 25
0
    def on_post(self, req, resp, tenant_id):
        tenant = find_tenant(self.db, tenant_id=tenant_id,
                             when_not_found=_tenant_not_found)

        body = load_body(req)
        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

        # Check if the event_producer already has a profile with this name
        for event_producer in tenant.event_producers:
            if event_producer.name == event_producer_name:
                abort(falcon.HTTP_400,
                      'Producer {0} with name {1} already exists.'
                      .format(event_producer.id, event_producer.name))

        # Create the new profile for the host
        new_event_producer = EventProducer(tenant.id, event_producer_name,
                                           event_producer_pattern,
                                           event_producer_durable,
                                           event_producer_encrypted)

        self.db.add(new_event_producer)
        tenant.event_producers.append(new_event_producer)
        self.db.commit()

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/producers/{1}'
                        .format(tenant_id, new_event_producer.id))
Exemplo n.º 26
0
    def on_post(self, req, resp, validated_body):

        body = validated_body['tenant']
        tenant_id = str(body['tenant_id'])

        tenant_name = body.get('tenant_name', tenant_id)

        #validate that tenant does not already exists
        tenant = find_tenant(self.db, tenant_id=tenant_id)
        if tenant:
            abort(
                falcon.HTTP_400, 'Tenant with tenant_id {0} '
                'already exists'.format(tenant_id))

        #create new token for the tenant
        new_token = Token()
        new_tenant = Tenant(tenant_id, new_token, tenant_name=tenant_name)

        self.db.put('tenant', new_tenant.format())
        self.db.create_sequence(new_tenant.tenant_id)
        resp.status = falcon.HTTP_201
        resp.set_header('Location', '/v1/{0}'.format(tenant_id))
Exemplo n.º 27
0
    def on_post(self, req, resp, tenant_id):
        tenant = find_tenant(self.db, tenant_id=tenant_id,
                             when_not_found=_tenant_not_found)

        body = load_body(req)
        hostname = body['hostname']
        ip_address = body['ip_address']

        #if profile id is not in post message, then use a null profile
        if 'profile_id' in body.keys():
            profile_id = body['profile_id']
        else:
            profile_id = None
            profile = None

        #if profile id is in post message, then make sure it is valid profile
        if profile_id:
            profile = find_host_profile(self.db, id=profile_id,
                                        when_not_found=_profile_not_found)

        # Check if the tenant already has a host with this hostname
        for host in tenant.hosts:
            if host.hostname == hostname:
                abort(falcon.HTTP_400,
                      'Host with hostname {0} already exists with'
                      ' id={1}'.format(hostname, host.id))

        # Create the new host definition
        new_host = Host(hostname, ip_address, profile)

        self.db.add(new_host)
        tenant.hosts.append(new_host)
        self.db().commit()

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/hosts/{1}'
                        .format(tenant_id, new_host.id))
Exemplo n.º 28
0
    def on_post(self, req, resp, tenant_id):
        tenant = find_tenant(self.db, tenant_id=tenant_id,
                             when_not_found=_tenant_not_found)

        body = load_body(req)
        profile_name = body['name']

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

        # Create the new profile for the host
        new_host_profile = HostProfile(tenant.id, profile_name)
        tenant.profiles.append(new_host_profile)

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

            for event_producer_id in event_producer_ids:
                event_producer = find_event_producer(self.db,
                                                     id=event_producer_id,
                                                     when_not_found=
                                                     _producer_not_found)
                if event_producer in tenant.event_producers:
                    new_host_profile.event_producers.append(event_producer)
                else:
                    _producer_not_found()

        self.db.add(new_host_profile)
        self.db.commit()

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/profiles/{1}'
                        .format(tenant_id, new_host_profile.id))
Exemplo n.º 29
0
    def on_post(self, req, resp, tenant_id):
        tenant = find_tenant(self.db, tenant_id=tenant_id,
                             when_not_found=_tenant_not_found)

        body = load_body(req)
        profile_name = body['name']

        # Check if the tenant already has a profile with this name
        for profile in tenant.profiles:
            if profile.name == profile_name:
                abort(400, 'Profile with name {0} already exists.'
                                .format(profile.name, profile.id))

        # Create the new profile for the host
        new_host_profile = HostProfile(tenant.id, profile_name)
        tenant.profiles.append(new_host_profile)
        
        self.db.add(new_host_profile)
        self.db.commit()

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/profiles/{1}'
                        .format(tenant_id, new_host_profile.id))
Exemplo n.º 30
0
    def on_post(self, req, resp, tenant_id):
        """
        This method is passed log event data by a tenant. The request will
        have a message token and a tenant id which must be validated either
        by the local cache or by a call to this workers coordinator.
        """

        #read message token from header
        message_token = req.get_header(MESSAGE_TOKEN, required=True)

        #Validate the tenant's JSON event log data as valid JSON.
        body = load_body(req)
        self._validate_req_body_on_post(body)

        tenant_identification = TenantIdentification(
            tenant_id, message_token)

        try:
            tenant = tenant_identification.get_validated_tenant()
            correlator = Correlator(tenant, body)
            correlator.process_message()
            try:
                self.router.route_message(correlator.message)
            except RoutingException as ex:
                abort(falcon.HTTP_500, 'error routing message')
            if correlator.is_durable():
                resp.status = falcon.HTTP_202
                resp.body = format_response_body(
                    correlator.get_durable_job_info())

            else:
                resp.status = falcon.HTTP_204

        except MessageAuthenticationError as ex:
            abort(falcon.HTTP_401, ex.message)
        except ResourceNotFoundError as ex:
            abort(falcon.HTTP_404, ex.message)
        except CoordinatorCommunicationError:
            abort(falcon.HTTP_500)
Exemplo n.º 31
0
    def on_post(self, req, resp, tenant_id, validated_body):
        """
        This method is passed log event data by a tenant. The request will
        have a message token and a tenant id which must be validated either
        by the local cache or by a call to this workers coordinator.
        """

        #read message token from header
        message_token = req.get_header(MESSAGE_TOKEN, required=True)

        #Validate the tenant's JSON event log data as valid JSON.
        message = validated_body['log_message']

        tenant_identification = correlator.TenantIdentification(
            tenant_id, message_token)

        try:
            tenant = tenant_identification.get_validated_tenant()
            message = correlator.add_correlation_info_to_message(
                tenant, message)

        except errors.MessageAuthenticationError as ex:
            abort(falcon.HTTP_401, ex.message)
        except errors.ResourceNotFoundError as ex:
            abort(falcon.HTTP_404, ex.message)
        except errors.CoordinatorCommunicationError:
            abort(falcon.HTTP_500)

        dispatch.persist_message(message)

        #if message is durable, return durable job info
        if message['meniscus']['correlation']['durable']:
            durable_job_id = message['meniscus']['correlation']['job_id']
            job_status_uri = "http://{0}/v1/job/{1}/status" \
                .format("meniscus_uri", durable_job_id)

            resp.status = falcon.HTTP_202
            resp.body = format_response_body(
                {
                    "job_id": durable_job_id,
                    "job_status_uri": job_status_uri
                }
            )

        else:
            resp.status = falcon.HTTP_204
Exemplo n.º 32
0
    def on_post(self, req, resp, tenant_id, validated_body):
        """
        This method is passed log event data by a tenant. The request will
        have a message token and a tenant id which must be validated either
        by the local cache or by a call to this workers coordinator.
        """

        #read message token from header
        message_token = req.get_header(MESSAGE_TOKEN, required=True)

        #Validate the tenant's JSON event log data as valid JSON.
        message = validated_body['log_message']

        tenant_identification = correlator.TenantIdentification(
            tenant_id, message_token)

        try:
            tenant = tenant_identification.get_validated_tenant()
            message = correlator.add_correlation_info_to_message(
                tenant, message)

        except errors.MessageAuthenticationError as ex:
            abort(falcon.HTTP_401, ex.message)
        except errors.ResourceNotFoundError as ex:
            abort(falcon.HTTP_404, ex.message)
        except errors.CoordinatorCommunicationError:
            abort(falcon.HTTP_500)

        dispatch.persist_message(message)

        #if message is durable, return durable job info
        if message['meniscus']['correlation']['durable']:
            durable_job_id = message['meniscus']['correlation']['job_id']
            job_status_uri = "http://{0}/v1/job/{1}/status" \
                .format("meniscus_uri", durable_job_id)

            resp.status = falcon.HTTP_202
            resp.body = format_response_body({
                "job_id": durable_job_id,
                "job_status_uri": job_status_uri
            })

        else:
            resp.status = falcon.HTTP_204
Exemplo n.º 33
0
def _producer_not_found():
    abort(falcon.HTTP_400, 'Unable to locate event producer.')
Exemplo n.º 34
0
def _message_token_is_invalid():
    """
    sends an http 404 response to the caller
    """
    api.abort(falcon.HTTP_404)
Exemplo n.º 35
0
def _producer_not_found():
    """
    sends an http 404 response to the caller
    """
    api.abort(falcon.HTTP_404, 'Unable to locate event producer.')
Exemplo n.º 36
0
def _producer_not_found():
    """
    sends an http 404 response to the caller
    """
    abort(falcon.HTTP_404, 'Unable to locate event producer.')
Exemplo n.º 37
0
def _tenant_not_found():
    """
    sends an http 404 response to the caller
    """
    api.abort(falcon.HTTP_404, 'Unable to locate tenant.')
Exemplo n.º 38
0
def _personality_not_valid():
    """
    sends an http 400 invalid personality request
    """
    abort(falcon.HTTP_400, 'invalid personality.')
Exemplo n.º 39
0
def _tenant_not_found():
    abort(falcon.HTTP_404, 'Unable to locate tenant.')
Exemplo n.º 40
0
def _message_token_is_invalid():
    """
    sends an http 404 response to the caller
    """
    abort(falcon.HTTP_404)
Exemplo n.º 41
0
def _worker_not_found():
    """
    sends an http 404 invalid worker not found
    """
    abort(falcon.HTTP_404, 'Unable to locate worker.')
Exemplo n.º 42
0
def _registration_not_valid():
    """
    sends an http 400 invalid registration request
    """
    abort(falcon.HTTP_400, 'invalid registration request.')
Exemplo n.º 43
0
def _profile_not_found():
    abort(falcon.HTTP_400, 'Unable to locate host profile.')
Exemplo n.º 44
0
def _worker_not_found():
    """
    sends an http 404 invalid worker not found
    """
    abort(falcon.HTTP_404, 'Unable to locate worker.')
Exemplo n.º 45
0
def _status_not_valid():
    """
    sends an http 400 invalid status request
    """
    abort(falcon.HTTP_400, 'invalid status.')
Exemplo n.º 46
0
def _tenant_not_found():
    """
    sends an http 404 response to the caller
    """
    abort(falcon.HTTP_404, 'Unable to locate tenant.')