Esempio n. 1
0
    def delete_device(req, device_id):
        """
        Deletes a single device.

        :param req: The received HTTP request, as created by Flask.
        :param device_id: The device to be removed.
        :return The removed device.
        :rtype JSON
        :raises HTTPRequestError: If no authorization token was provided (no
        tenant was informed)
        :raises HTTPRequestError: If this device could not be found in
        database.
        """

        tenant = init_tenant_context(req, db)
        orm_device = assert_device_exists(device_id)
        data = serialize_full_device(orm_device, tenant)

        kafka_handler = KafkaHandler()
        kafka_handler.remove(data, meta={"service": tenant})
        if CONFIG.orion:
            subscription_handler = PersistenceHandler(service=tenant)
            subscription_handler.remove(orm_device.persistence)

        db.session.delete(orm_device)
        db.session.commit()

        results = {'result': 'ok', 'removed_device': data}
        return results
Esempio n. 2
0
 def notifies_deletion_to_kafka(device, tenant):
     data = serialize_full_device(device, tenant)
     kafka_handler = KafkaHandler()
     kafka_handler.remove(data, meta={"service": tenant})
     if CONFIG.orion:
         subscription_handler = PersistenceHandler(service=tenant)
         subscription_handler.remove(device.persistence)