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

Refactored states transitions - endpoint configuration [issue #61]

parent 3c8cbd64
No related branches found
No related tags found
No related merge requests found
......@@ -75,7 +75,8 @@ class Sim(object):
# Simulate configuration of the ip endpoints
# endpoint state->mu, sigma, secs normal distribution
config_delay_dist = {"placing": [10, 0.68], "booting": [10, 0.68], "connecting": [10, 0.68], "unplaced": [10, 0.68]}
config_delay_dist = {"unplaced": [1, 0.68], "placing": [10, 0.68], "placed": [1, 0.68], "booting": [10, 0.68], "booted": [2, 0.68],
"connecting": [10, 0.68], "connected": [8, 0.68]}
# Simulation configuration of the media component (MC) state changes
# "MC state", [average (sec), stddev]
......@@ -83,6 +84,17 @@ class Sim(object):
print("\nSimulation started. Generating data...")
# Move endpoints from state unplaced to state placing
max_delay = 0
for ip_endpoint in ip_endpoints:
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_time = self._changeVMState(agent_db_client, sim_time, ip_endpoint, config_delay_dist['unplaced'][0],
config_delay_dist['unplaced'][0] * config_delay_dist['unplaced'][1], 0.7,
'unplaced', 'placing')
max_delay = max(delay_time, max_delay)
sim_time += max_delay
# Place endpoints
max_delay = 0
for ip_endpoint in ip_endpoints:
......@@ -94,6 +106,17 @@ class Sim(object):
max_delay = max(delay_time, max_delay)
sim_time += max_delay
# Move endpoints from state placed to state booting
max_delay = 0
for ip_endpoint in ip_endpoints:
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_time = self._changeVMState(agent_db_client, sim_time, ip_endpoint, config_delay_dist['placed'][0],
config_delay_dist['placed'][0] * config_delay_dist['placed'][1], 0.7,
'placed', 'booting')
max_delay = max(delay_time, max_delay)
sim_time += max_delay
# Boot endpoints
max_delay = 0
for ip_endpoint in ip_endpoints:
......@@ -131,6 +154,17 @@ class Sim(object):
sim_time += max_delay
# Move endpoints from state booted to state connecting
max_delay = 0
for ip_endpoint in ip_endpoints:
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_time = self._changeVMState(agent_db_client, sim_time, ip_endpoint, config_delay_dist['booted'][0],
config_delay_dist['booted'][0] * config_delay_dist['booted'][1], 0.7,
'booted', 'connecting')
max_delay = max(delay_time, max_delay)
sim_time += max_delay
# Connect endpoints
max_delay = 0
for ip_endpoint in ip_endpoints:
......@@ -221,9 +255,9 @@ class Sim(object):
for ip_endpoint in ip_endpoints:
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_time = self._changeVMState(agent_db_client, sim_time, ip_endpoint, config_delay_dist['placing'][0],
config_delay_dist['unplaced'][0] * config_delay_dist['unplaced'][1], 0.25,
'placed', 'unplaced')
delay_time = self._changeVMState(agent_db_client, sim_time, ip_endpoint, config_delay_dist['connected'][0],
config_delay_dist['connected'][0] * config_delay_dist['connected'][1], 0.25,
'connected', 'unplaced')
max_delay = max(delay_time, max_delay)
sim_time += max_delay
......@@ -388,7 +422,7 @@ if __name__ == "__main__":
elif opt in ('-t','--time'):
simTime = arg
if ( genOpt == True ):
if genOpt == True:
print( "Running simulation to generate data" )
print( "Time period for this simulation: " + str(simTime) + " seconds" )
else:
......
......@@ -45,9 +45,6 @@ def simulator( streaming_sim_config ):
simulator = Sim( influx_url, influx_db_name, agent1_url, agent2_url )
dbs = simulator.db_client.get_list_database()
dbs = [db.get("name") for db in dbs]
simulator.reset()
return simulator
\ No newline at end of file
......@@ -8,7 +8,7 @@ class TestSimulation(object):
"""
A testing class used to group all the tests related to the simulation data
"""
@pytest.fixture(scope='class')
@pytest.fixture(scope='class', autouse=True)
def run_simulator( self, simulator ):
simulator.run( 3600 )
......@@ -26,11 +26,11 @@ class TestSimulation(object):
{"time": "1970-01-01T00:00:00Z", "count_RX_BYTES_PORT_M": 7200, "count_TX_BYTES_PORT_M": 7200}),
('SELECT count(*) FROM "CLMCMetrics"."autogen"."endpoint_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache1\'',
{"time": "1970-01-01T00:00:00Z", "count_unplaced": 4, "count_avg_unplaced": 4, "count_placing": 4, "count_avg_placing": 4, "count_placed": 4, "count_avg_placed": 4, "count_booting": 4, "count_avg_booting": 4, "count_booted": 4,
"count_avg_booted": 4, "count_connecting": 4, "count_avg_connecting": 4, "count_connected": 4, "count_avg_connected": 4, "count_cpus": 4, "count_memory": 4, "count_storage": 4}),
{"time": "1970-01-01T00:00:00Z", "count_unplaced": 7, "count_avg_unplaced": 7, "count_placing": 7, "count_avg_placing": 7, "count_placed": 7, "count_avg_placed": 7, "count_booting": 7, "count_avg_booting": 7, "count_booted": 7,
"count_avg_booted": 7, "count_connecting": 7, "count_avg_connecting": 7, "count_connected": 7, "count_avg_connected": 7, "count_cpus": 7, "count_memory": 7, "count_storage": 7}),
('SELECT count(*) FROM "CLMCMetrics"."autogen"."endpoint_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache2\'',
{"time": "1970-01-01T00:00:00Z", "count_unplaced": 4, "count_avg_unplaced": 4, "count_placing": 4, "count_avg_placing": 4, "count_placed": 4, "count_avg_placed": 4, "count_booting": 4, "count_avg_booting": 4, "count_booted": 4,
"count_avg_booted": 4, "count_connecting": 4, "count_avg_connecting": 4, "count_connected": 4, "count_avg_connected": 4, "count_cpus": 4, "count_memory": 4, "count_storage": 4}),
{"time": "1970-01-01T00:00:00Z", "count_unplaced": 7, "count_avg_unplaced": 7, "count_placing": 7, "count_avg_placing": 7, "count_placed": 7, "count_avg_placed": 7, "count_booting": 7, "count_avg_booting": 7, "count_booted": 7,
"count_avg_booted": 7, "count_connecting": 7, "count_avg_connecting": 7, "count_connected": 7, "count_avg_connected": 7, "count_cpus": 7, "count_memory": 7, "count_storage": 7}),
('SELECT count(*) FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache1\'',
......@@ -38,7 +38,7 @@ class TestSimulation(object):
('SELECT count(*) FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache2\'',
{"time" : "1970-01-01T00:00:00Z", "count_avg_running" : 3604, "count_avg_starting" : 3604, "count_avg_stopped" : 3604, "count_avg_stopping" : 3604, "count_running" : 3604, "count_starting" : 3604, "count_stopped" : 3604, "count_stopping" : 3604}),
])
def test_simulation( self, run_simulator, influx_db, query, expected_result ):
def test_simulation( self, influx_db, query, expected_result ):
"""
This is the entry point of the test. This method will be found and executed when the module is ran using pytest
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment