Change loopback to observatory just to call the observatory extension functions
This commit is contained in:
parent
d29b156d76
commit
0735bbcb41
@ -13,8 +13,8 @@ OLD_VERSIONS = $(wildcard old_versions/*.sql)
|
|||||||
# @see http://www.postgresql.org/docs/current/static/extend-pgxs.html
|
# @see http://www.postgresql.org/docs/current/static/extend-pgxs.html
|
||||||
DATA = $(NEW_EXTENSION_ARTIFACT) \
|
DATA = $(NEW_EXTENSION_ARTIFACT) \
|
||||||
$(OLD_VERSIONS) \
|
$(OLD_VERSIONS) \
|
||||||
cdb_dataservices_server--0.7.1--0.7.2.sql \
|
cdb_dataservices_server--0.7.2--0.7.3.sql \
|
||||||
cdb_dataservices_server--0.7.2--0.7.1.sql
|
cdb_dataservices_server--0.7.3--0.7.2.sql
|
||||||
|
|
||||||
REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql)))
|
REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql)))
|
||||||
TEST_DIR = test/
|
TEST_DIR = test/
|
||||||
|
113
server/extension/cdb_dataservices_server--0.7.2--0.7.3.sql
Normal file
113
server/extension/cdb_dataservices_server--0.7.2--0.7.3.sql
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.7.3'" to load this file. \quit
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._obs_server_conn_str(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT)
|
||||||
|
RETURNS text AS $$
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||||
|
|
||||||
|
return user_obs_snapshot_config.connection_str
|
||||||
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshot(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
geom geometry(Geometry, 4326),
|
||||||
|
time_span TEXT DEFAULT '2009 - 2013',
|
||||||
|
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||||
|
RETURNS json AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT cdb_observatory.OBS_GetDemographicSnapshot(geom, time_span, geometry_level);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_demographic_snapshot(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
geom geometry(Geometry, 4326),
|
||||||
|
time_span TEXT DEFAULT '2009 - 2013',
|
||||||
|
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||||
|
RETURNS json AS $$
|
||||||
|
from cartodb_services.metrics import QuotaService
|
||||||
|
import json
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||||
|
|
||||||
|
quota_service = QuotaService(user_obs_snapshot_config, redis_conn)
|
||||||
|
if not quota_service.check_user_quota():
|
||||||
|
plpy.error('You have reached the limit of your quota')
|
||||||
|
|
||||||
|
try:
|
||||||
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetDemographicSnapshot($1, $2, $3, $4, $5) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text", "text"])
|
||||||
|
result = plpy.execute(obs_plan, [username, orgname, geom, time_span, geometry_level])
|
||||||
|
if result:
|
||||||
|
quota_service.increment_success_service_use()
|
||||||
|
return result[0]['snapshot']
|
||||||
|
else:
|
||||||
|
quota_service.increment_empty_service_use()
|
||||||
|
return None
|
||||||
|
except BaseException as e:
|
||||||
|
import sys, traceback
|
||||||
|
type_, value_, traceback_ = sys.exc_info()
|
||||||
|
quota_service.increment_failed_service_use()
|
||||||
|
error_msg = 'There was an error trying to use get_geographic_snapshot: {0}'.format(e)
|
||||||
|
plpy.notice(traceback.format_tb(traceback_))
|
||||||
|
plpy.error(error_msg)
|
||||||
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshot(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
geom geometry(Geometry, 4326),
|
||||||
|
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||||
|
RETURNS json AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT cdb_observatory.OBS_GetSegmentSnapshot(geom, geometry_level);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_segment_snapshot(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
geom geometry(Geometry, 4326),
|
||||||
|
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||||
|
RETURNS json AS $$
|
||||||
|
from cartodb_services.metrics import QuotaService
|
||||||
|
import json
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||||
|
|
||||||
|
quota_service = QuotaService(user_obs_snapshot_config, redis_conn)
|
||||||
|
if not quota_service.check_user_quota():
|
||||||
|
plpy.error('You have reached the limit of your quota')
|
||||||
|
|
||||||
|
try:
|
||||||
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetSegmentSnapshot($1, $2, $3, $4) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
||||||
|
result = plpy.execute(obs_plan, [username, orgname, geom, geometry_level])
|
||||||
|
if result:
|
||||||
|
quota_service.increment_success_service_use()
|
||||||
|
return result[0]['snapshot']
|
||||||
|
else:
|
||||||
|
quota_service.increment_empty_service_use()
|
||||||
|
return None
|
||||||
|
except BaseException as e:
|
||||||
|
import sys, traceback
|
||||||
|
type_, value_, traceback_ = sys.exc_info()
|
||||||
|
quota_service.increment_failed_service_use()
|
||||||
|
error_msg = 'There was an error trying to use get_segment_snapshot: {0}'.format(e)
|
||||||
|
plpy.notice(traceback.format_tb(traceback_))
|
||||||
|
plpy.error(error_msg)
|
||||||
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu;
|
103
server/extension/cdb_dataservices_server--0.7.3--0.7.2.sql
Normal file
103
server/extension/cdb_dataservices_server--0.7.3--0.7.2.sql
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.7.2'" to load this file. \quit
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server._OBS_GetDemographicSnapshot(text, text, geometry(Geometry, 4326), text, text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server._OBS_GetSegmentSnapshot(text, text, geometry(Geometry, 4326), text);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_demographic_snapshot(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
geom geometry(Geometry, 4326),
|
||||||
|
time_span TEXT DEFAULT '2009 - 2013',
|
||||||
|
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||||
|
RETURNS json AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT cdb_dataservices_server._obs_get_demographic_snapshot (username, orgname, geom, time_span, geometry_level);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._obs_get_demographic_snapshot(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
geom geometry(Geometry, 4326),
|
||||||
|
time_span TEXT DEFAULT '2009 - 2013',
|
||||||
|
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||||
|
RETURNS json AS $$
|
||||||
|
from cartodb_services.metrics import QuotaService
|
||||||
|
import json
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||||
|
|
||||||
|
quota_service = QuotaService(user_obs_snapshot_config, redis_conn)
|
||||||
|
if not quota_service.check_user_quota():
|
||||||
|
plpy.error('You have reached the limit of your quota')
|
||||||
|
|
||||||
|
try:
|
||||||
|
obs_plan = plpy.prepare("SELECT cdb_observatory.OBS_GetDemographicSnapshot($1, $2, $3) as snapshot;", ["geometry(Geometry, 4326)", "text", "text"])
|
||||||
|
result = plpy.execute(obs_plan, [geom, time_span, geometry_level])
|
||||||
|
if result:
|
||||||
|
quota_service.increment_success_service_use()
|
||||||
|
return result[0]['snapshot']
|
||||||
|
else:
|
||||||
|
quota_service.increment_empty_service_use()
|
||||||
|
return None
|
||||||
|
except BaseException as e:
|
||||||
|
import sys, traceback
|
||||||
|
type_, value_, traceback_ = sys.exc_info()
|
||||||
|
quota_service.increment_failed_service_use()
|
||||||
|
error_msg = 'There was an error trying to use get_geographic_snapshot: {0}'.format(e)
|
||||||
|
plpy.notice(traceback.format_tb(traceback_))
|
||||||
|
plpy.error(error_msg)
|
||||||
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_segment_snapshot(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
geom geometry(Geometry, 4326),
|
||||||
|
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||||
|
RETURNS json AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT cdb_dataservices_server._obs_get_segment_snapshot (username, orgname, geom, geometry_level);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._obs_get_segment_snapshot(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
geom geometry(Geometry, 4326),
|
||||||
|
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||||
|
RETURNS json AS $$
|
||||||
|
from cartodb_services.metrics import QuotaService
|
||||||
|
import json
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||||
|
|
||||||
|
quota_service = QuotaService(user_obs_snapshot_config, redis_conn)
|
||||||
|
if not quota_service.check_user_quota():
|
||||||
|
plpy.error('You have reached the limit of your quota')
|
||||||
|
|
||||||
|
try:
|
||||||
|
obs_plan = plpy.prepare("SELECT cdb_observatory.OBS_GetSegmentSnapshot($1, $2) as snapshot;", ["geometry(Geometry, 4326)", "text"])
|
||||||
|
result = plpy.execute(obs_plan, [geom, geometry_level])
|
||||||
|
if result:
|
||||||
|
quota_service.increment_success_service_use()
|
||||||
|
return result[0]['snapshot']
|
||||||
|
else:
|
||||||
|
quota_service.increment_empty_service_use()
|
||||||
|
return None
|
||||||
|
except BaseException as e:
|
||||||
|
import sys, traceback
|
||||||
|
type_, value_, traceback_ = sys.exc_info()
|
||||||
|
quota_service.increment_failed_service_use()
|
||||||
|
error_msg = 'There was an error trying to use get_segment_snapshot: {0}'.format(e)
|
||||||
|
plpy.notice(traceback.format_tb(traceback_))
|
||||||
|
plpy.error(error_msg)
|
||||||
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu;
|
@ -1,5 +1,5 @@
|
|||||||
comment = 'CartoDB dataservices server extension'
|
comment = 'CartoDB dataservices server extension'
|
||||||
default_version = '0.7.2'
|
default_version = '0.7.3'
|
||||||
requires = 'plpythonu, plproxy, postgis, cdb_geocoder'
|
requires = 'plpythonu, plproxy, postgis, cdb_geocoder'
|
||||||
superuser = true
|
superuser = true
|
||||||
schema = cdb_dataservices_server
|
schema = cdb_dataservices_server
|
||||||
|
@ -16,7 +16,7 @@ RETURNS text AS $$
|
|||||||
return user_obs_snapshot_config.connection_str
|
return user_obs_snapshot_config.connection_str
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_demographic_snapshot(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshot(
|
||||||
username TEXT,
|
username TEXT,
|
||||||
orgname TEXT,
|
orgname TEXT,
|
||||||
geom geometry(Geometry, 4326),
|
geom geometry(Geometry, 4326),
|
||||||
@ -24,10 +24,10 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_demographic_snapshot(
|
|||||||
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||||
RETURNS json AS $$
|
RETURNS json AS $$
|
||||||
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
SELECT cdb_dataservices_server._obs_get_demographic_snapshot (username, orgname, geom, time_span, geometry_level);
|
SELECT cdb_observatory.OBS_GetDemographicSnapshot(geom, time_span, geometry_level);
|
||||||
$$ LANGUAGE plproxy;
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._obs_get_demographic_snapshot(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_demographic_snapshot(
|
||||||
username TEXT,
|
username TEXT,
|
||||||
orgname TEXT,
|
orgname TEXT,
|
||||||
geom geometry(Geometry, 4326),
|
geom geometry(Geometry, 4326),
|
||||||
@ -47,8 +47,8 @@ RETURNS json AS $$
|
|||||||
plpy.error('You have reached the limit of your quota')
|
plpy.error('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT cdb_observatory.OBS_GetDemographicSnapshot($1, $2, $3) as snapshot;", ["geometry(Geometry, 4326)", "text", "text"])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetDemographicSnapshot($1, $2, $3, $4, $5) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text", "text"])
|
||||||
result = plpy.execute(obs_plan, [geom, time_span, geometry_level])
|
result = plpy.execute(obs_plan, [username, orgname, geom, time_span, geometry_level])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
quota_service.increment_success_service_use()
|
||||||
return result[0]['snapshot']
|
return result[0]['snapshot']
|
||||||
@ -66,17 +66,17 @@ RETURNS json AS $$
|
|||||||
quota_service.increment_total_service_use()
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_segment_snapshot(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshot(
|
||||||
username TEXT,
|
username TEXT,
|
||||||
orgname TEXT,
|
orgname TEXT,
|
||||||
geom geometry(Geometry, 4326),
|
geom geometry(Geometry, 4326),
|
||||||
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
geometry_level TEXT DEFAULT '"us.census.tiger".block_group')
|
||||||
RETURNS json AS $$
|
RETURNS json AS $$
|
||||||
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
SELECT cdb_dataservices_server._obs_get_segment_snapshot (username, orgname, geom, geometry_level);
|
SELECT cdb_observatory.OBS_GetSegmentSnapshot(geom, geometry_level);
|
||||||
$$ LANGUAGE plproxy;
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._obs_get_segment_snapshot(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_segment_snapshot(
|
||||||
username TEXT,
|
username TEXT,
|
||||||
orgname TEXT,
|
orgname TEXT,
|
||||||
geom geometry(Geometry, 4326),
|
geom geometry(Geometry, 4326),
|
||||||
@ -95,8 +95,8 @@ RETURNS json AS $$
|
|||||||
plpy.error('You have reached the limit of your quota')
|
plpy.error('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT cdb_observatory.OBS_GetSegmentSnapshot($1, $2) as snapshot;", ["geometry(Geometry, 4326)", "text"])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetSegmentSnapshot($1, $2, $3, $4) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
||||||
result = plpy.execute(obs_plan, [geom, geometry_level])
|
result = plpy.execute(obs_plan, [username, orgname, geom, geometry_level])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
quota_service.increment_success_service_use()
|
||||||
return result[0]['snapshot']
|
return result[0]['snapshot']
|
||||||
|
Loading…
Reference in New Issue
Block a user