Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 347 #365

Merged
merged 13 commits into from
Sep 25, 2020
Merged
1 change: 1 addition & 0 deletions deps.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export ORION_VERSION=2.2.0
export INFLUX_VERSION=1.2.2
export RETHINK_VERSION=2.3.5
export CRATE_VERSION=4.1.4
export TIMESCALE_VERSION=1.7.1-pg12

export REDIS_VERSION=3

Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ services:
- redisdata:/data

timescale:
image: timescale/timescaledb-postgis:1.7.1-pg12
image: timescale/timescaledb-postgis:${TIMESCALE_VERSION}
ports:
- "5432:5432"
# Don't expose container port 5432 with the same number outside of the
Expand Down
20 changes: 20 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
#!/bin/bash

test_suite_header () {
echo "======================================================================="
echo " $1 TESTS"
echo "======================================================================="
}

docker pull smartsdk/quantumleap
docker build --cache-from smartsdk/quantumleap -t smartsdk/quantumleap .

cd src/translators/tests
test_suite_header "TRANSLATOR"
sh run_tests.sh
tot=$?
cd -

cd src/reporter/tests
test_suite_header "REPORTER (Crate)"
sh run_tests.sh
loc=$?
if [ "$tot" -eq 0 ]; then
tot=$loc
fi
cd -

cd src/reporter/tests
test_suite_header "REPORTER (Timescale)"
sh run_tests.timescale.sh
loc=$?
if [ "$tot" -eq 0 ]; then
tot=$loc
fi
cd -

cd src/geocoding/tests
test_suite_header "GEO-CODING"
sh run_tests.sh
loc=$?
if [ "$tot" -eq 0 ]; then
Expand All @@ -25,6 +43,7 @@ fi
cd -

cd src/utils/tests
test_suite_header "UTILS"
sh run_tests.sh
loc=$?
if [ "$tot" -eq 0 ]; then
Expand All @@ -33,6 +52,7 @@ fi
cd -

cd src/tests/
test_suite_header "BACKWARD COMPAT & INTEGRATION"
sh run_tests.sh
loc=$?
if [ "$tot" -eq 0 ]; then
Expand Down
16 changes: 15 additions & 1 deletion specification/quantumleap.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
swagger: '2.0' # For 3.0 see (https://github.com/zalando/connexion/issues/420)
info:
title: "QuantumLeap API"
version: "0.7.5" # we'll keep it aligned with QL version
version: "0.7.6" # we'll keep it aligned with QL version
host: "localhost:8668" # it'll run in the same container, hence localhost.
produces:
- text/plain
Expand Down Expand Up @@ -313,6 +313,19 @@ parameters:
`40 42' 51'',74 0' 21''`.
Full details can be found in the Geographical Queries section of the specification:
http://fiware.github.io/specifications/ngsiv2/stable/."
dropTable:
in: query
name: dropTable
type: boolean
default: false
description: "Optional. Drop the table storing an entity type. When deleting
by entity type, setting this parameter to true will result in all entity
data for the given type being deleted, the entity table will be dropped
and the corresponding entry removed from the metadata table. This option
should only be used for maintenance after the devices whose data is written
to the table are decommissioned and no further writes are possible. In fact,
race conditions are possible if entities of that type are POSTed to the
notify endpoint while the underlying clean-up procedure is in progress."

################################################################################
# PATHS: META
Expand Down Expand Up @@ -1245,6 +1258,7 @@ paths:
# In Query...
- $ref: '#/parameters/fromDate'
- $ref: '#/parameters/toDate'
- $ref: '#/parameters/dropTable'
# In Header...
- $ref: '#/parameters/fiware-Service'
- $ref: '#/parameters/fiware-ServicePath'
Expand Down
33 changes: 16 additions & 17 deletions src/reporter/delete.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from exceptions.exceptions import AmbiguousNGSIIdError
from flask import request
from translators import crate
from .http import fiware_s, fiware_sp
from translators.factory import translator_for


def delete_entity(entity_id, type_=None, from_date=None, to_date=None):
fiware_s = request.headers.get('fiware-service', None)
fiware_sp = request.headers.get('fiware-servicepath', None)

try:
with crate.CrateTranslatorInstance() as trans:
deleted = trans.delete_entity(entity_id=entity_id,
entity_type=type_,
with translator_for(fiware_s()) as trans:
deleted = trans.delete_entity(eid=entity_id,
etype=type_,
from_date=from_date,
to_date=to_date,
fiware_service=fiware_s,
fiware_servicepath=fiware_sp,)
fiware_service=fiware_s(),
fiware_servicepath=fiware_sp(),)
except AmbiguousNGSIIdError as e:
return {
"error": "AmbiguousNGSIIdError",
Expand All @@ -32,16 +29,18 @@ def delete_entity(entity_id, type_=None, from_date=None, to_date=None):
return '{} records successfully deleted.'.format(deleted), 204


def delete_entities(entity_type, from_date=None, to_date=None):
fiware_s = request.headers.get('fiware-service', None)
fiware_sp = request.headers.get('fiware-servicepath', None)
def delete_entities(entity_type, from_date=None, to_date=None,
drop_table=False):
with translator_for(fiware_s()) as trans:
if drop_table:
trans.drop_table(etype=entity_type, fiware_service=fiware_s())
return 'entity table dropped', 204

with crate.CrateTranslatorInstance() as trans:
deleted = trans.delete_entities(entity_type=entity_type,
deleted = trans.delete_entities(etype=entity_type,
from_date=from_date,
to_date=to_date,
fiware_service=fiware_s,
fiware_servicepath=fiware_sp,)
fiware_service=fiware_s(),
fiware_servicepath=fiware_sp(),)
if deleted == 0:
r = {
"error": "Not Found",
Expand Down
15 changes: 15 additions & 0 deletions src/reporter/http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from flask import request


def fiware_s() -> str:
"""
:return: The content of the FiWare service header if any.
"""
return request.headers.get('fiware-service', None)


def fiware_sp() -> str:
"""
:return: The content of the FiWare service path header if any.
"""
return request.headers.get('fiware-servicepath', None)
Loading