Skip to content
Snippets Groups Projects
Commit a050d439 authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

Clearing up the CLMC service and separating aggregation API from a potential whoami API

parent 25a1b12c
No related branches found
No related tags found
No related merge requests found
Showing
with 34 additions and 31 deletions
......@@ -23,7 +23,7 @@
"""
from pyramid.config import Configurator
from clmcservice.utilities import validate_conf_file, RUNNING_FLAG, MALFORMED_FLAG, CONF_FILE_ATTRIBUTE, CONF_OBJECT, AGGREGATOR_CONFIG_SECTION
from clmcservice.aggregationapi.utilities import validate_conf_file, RUNNING_FLAG, MALFORMED_FLAG, CONF_FILE_ATTRIBUTE, CONF_OBJECT, AGGREGATOR_CONFIG_SECTION
def main(global_config, **settings):
......@@ -41,15 +41,15 @@ def main(global_config, **settings):
config = Configurator(settings=settings)
config.add_route('aggregator_config', '/aggregator/config')
config.add_view('clmcservice.views.AggregatorConfig', attr='get', request_method='GET')
config.add_view('clmcservice.views.AggregatorConfig', attr='put', request_method='PUT')
config.add_view('clmcservice.aggregationapi.views.AggregatorConfig', attr='get', request_method='GET')
config.add_view('clmcservice.aggregationapi.views.AggregatorConfig', attr='put', request_method='PUT')
config.add_route('aggregator_controller', '/aggregator/control')
config.add_view('clmcservice.views.AggregatorController', attr='get', request_method='GET')
config.add_view('clmcservice.views.AggregatorController', attr='put', request_method='PUT')
config.add_view('clmcservice.aggregationapi.views.AggregatorController', attr='get', request_method='GET')
config.add_view('clmcservice.aggregationapi.views.AggregatorController', attr='put', request_method='PUT')
config.add_route('round_trip_time_query', '/query/round-trip-time')
config.add_view('clmcservice.views.RoundTripTimeQuery', attr='get', request_method='GET')
config.add_view('clmcservice.aggregationapi.views.RoundTripTimeQuery', attr='get', request_method='GET')
config.scan()
return config.make_wsgi_app()
__all__ = ['aggregator']
......@@ -26,7 +26,7 @@ from threading import Thread, Event
from influxdb import InfluxDBClient
from time import time, sleep
from urllib.parse import urlparse
from clmcservice.utilities import generate_e2e_delay_report
from clmcservice.aggregationapi.utilities import generate_e2e_delay_report
import getopt
import logging
......
......@@ -23,7 +23,7 @@
"""
from clmcservice.utilities import generate_e2e_delay_report
from clmcservice.aggregationapi.utilities import generate_e2e_delay_report
"""
A python module which provides auxiliary functions to mimic the behaviour of an InfluxDBClient when unit testing the aggregator.
......
__all__ = ['utilities', 'views']
......@@ -25,7 +25,7 @@
from pyramid import testing
from pyramid.httpexceptions import HTTPBadRequest
from time import sleep
from clmcservice.utilities import CONF_FILE_ATTRIBUTE, CONF_OBJECT, AGGREGATOR_CONFIG_SECTION, CONFIG_ATTRIBUTES, PROCESS_ATTRIBUTE, RUNNING_FLAG, MALFORMED_FLAG, URL_REGEX
from clmcservice.aggregationapi.utilities import CONF_FILE_ATTRIBUTE, CONF_OBJECT, AGGREGATOR_CONFIG_SECTION, CONFIG_ATTRIBUTES, PROCESS_ATTRIBUTE, RUNNING_FLAG, MALFORMED_FLAG, URL_REGEX
import pytest
import os
import signal
......@@ -57,7 +57,7 @@ class TestAggregatorAPI(object):
Tests the GET method for the configuration of the aggregator.
"""
from clmcservice.views import AggregatorConfig # nested import so that importing the class view is part of the test itself
from clmcservice.aggregationapi.views import AggregatorConfig # nested import so that importing the class view is part of the test itself
assert int(self.registry.get_settings()[CONF_OBJECT][AGGREGATOR_CONFIG_SECTION].get('aggregator_report_period')) == 5, "Initial report period is 5 seconds."
assert self.registry.get_settings()[CONF_OBJECT][AGGREGATOR_CONFIG_SECTION].get('aggregator_database_name') == 'CLMCMetrics', "Initial database name the aggregator uses is CLMCMetrics."
......@@ -102,7 +102,7 @@ class TestAggregatorAPI(object):
:param output_value: the expected output value, None for expecting an Exception
"""
from clmcservice.views import AggregatorConfig, AggregatorController # nested import so that importing the class view is part of the test itself
from clmcservice.aggregationapi.views import AggregatorConfig, AggregatorController # nested import so that importing the class view is part of the test itself
assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running."
assert int(self.registry.get_settings()[CONF_OBJECT][AGGREGATOR_CONFIG_SECTION].get('aggregator_report_period')) == 5, "Initial report period is 5 seconds."
......@@ -144,7 +144,7 @@ class TestAggregatorAPI(object):
Tests starting the aggregator through an API call.
"""
from clmcservice.views import AggregatorController # nested import so that importing the class view is part of the test itself
from clmcservice.aggregationapi.views import AggregatorController # nested import so that importing the class view is part of the test itself
assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running."
assert self.registry.get_settings().get(PROCESS_ATTRIBUTE) is None, "Initially no aggregator process is running."
......@@ -167,7 +167,7 @@ class TestAggregatorAPI(object):
Tests stopping the aggregator through an API call.
"""
from clmcservice.views import AggregatorController # nested import so that importing the class view is part of the test itself
from clmcservice.aggregationapi.views import AggregatorController # nested import so that importing the class view is part of the test itself
assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running."
assert self.registry.get_settings().get(PROCESS_ATTRIBUTE) is None, "Initially no aggregator process is running."
......@@ -207,7 +207,7 @@ class TestAggregatorAPI(object):
Tests restarting the aggregator through an API call.
"""
from clmcservice.views import AggregatorController # nested import so that importing the class view is part of the test itself
from clmcservice.aggregationapi.views import AggregatorController # nested import so that importing the class view is part of the test itself
assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running."
assert self.registry.get_settings().get(PROCESS_ATTRIBUTE) is None, "Initially no aggregator process is running."
......@@ -250,7 +250,7 @@ class TestAggregatorAPI(object):
Tests sending a malformed type of action to the aggregator through an API call.
"""
from clmcservice.views import AggregatorController # nested import so that importing the class view is part of the test itself
from clmcservice.aggregationapi.views import AggregatorController # nested import so that importing the class view is part of the test itself
assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running."
assert self.registry.get_settings().get(PROCESS_ATTRIBUTE) is None, "Initially no aggregator process is running."
......@@ -273,7 +273,7 @@ class TestAggregatorAPI(object):
Tests the GET method for the status of the aggregator.
"""
from clmcservice.views import AggregatorController # nested import so that importing the class view is part of the test itself
from clmcservice.aggregationapi.views import AggregatorController # nested import so that importing the class view is part of the test itself
assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running."
assert self.registry.get_settings().get(PROCESS_ATTRIBUTE) is None, "Initially no aggregator process is running."
......@@ -315,7 +315,7 @@ class TestAggregatorAPI(object):
Tests the behaviour of the malformed configuration flag of the aggregator when doing a sequence of API calls.
"""
from clmcservice.views import AggregatorController, AggregatorConfig # nested import so that importing the class view is part of the test itself
from clmcservice.aggregationapi.views import AggregatorController, AggregatorConfig # nested import so that importing the class view is part of the test itself
assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running."
assert not self.registry.get_settings().get(MALFORMED_FLAG), "Initially aggregator is not in a malformed state"
......@@ -391,7 +391,7 @@ class TestAggregatorAPI(object):
Tests the behaviour of the service when in unconfigured state.
"""
from clmcservice.views import AggregatorConfig, AggregatorController
from clmcservice.aggregationapi.views import AggregatorConfig, AggregatorController
self.registry.get_settings()[CONF_OBJECT] = None # unconfigured state - conf object is None
......
......@@ -27,7 +27,7 @@ from pyramid.httpexceptions import HTTPBadRequest, HTTPInternalServerError
from influxdb import InfluxDBClient
from urllib.parse import urlparse
from subprocess import Popen
from clmcservice.utilities import validate_config_content, validate_action_content, validate_round_trip_query_params, \
from clmcservice.aggregationapi.utilities import validate_config_content, validate_action_content, validate_round_trip_query_params, \
CONF_OBJECT, CONF_FILE_ATTRIBUTE, AGGREGATOR_CONFIG_SECTION, CONFIG_ATTRIBUTES, ROUND_TRIP_ATTRIBUTES, RUNNING_FLAG, PROCESS_ATTRIBUTE, MALFORMED_FLAG, COMMENT_ATTRIBUTE, COMMENT_VALUE
import os
import os.path
......@@ -215,11 +215,10 @@ class AggregatorController(object):
:return: the process object of the started aggregator script
"""
dir_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'aggregation')
python_interpreter = sys.executable
command = [python_interpreter, 'aggregator.py', '--period', str(config.get('aggregator_report_period')), '--database',
command = [python_interpreter, '-m', 'clmcservice.aggregation.aggregator', '--period', str(config.get('aggregator_report_period')), '--database',
config.get('aggregator_database_name'), '--url', config.get('aggregator_database_url')]
process = Popen(command, cwd=dir_path)
process = Popen(command)
log.info("\nStarted aggregator process with PID: {0}\n".format(process.pid))
......@@ -254,6 +253,8 @@ class AggregatorController(object):
@view_defaults(route_name='round_trip_time_query', renderer='json')
class RoundTripTimeQuery(object):
# TODO This API endpoint has not been tested, neither has the formula used to calculate round trip time.
"""
A class-based view for querying the round trip time in a given range.
"""
......
......@@ -23,7 +23,6 @@
"""
import pytest
import random
import time
import requests
import urllib.parse
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment