Skip to content
Snippets Groups Projects
Commit dccb6aec authored by Björn Vonheiden's avatar Björn Vonheiden
Browse files

Enable reset with cli parameters in run uc py

Use the parameters -res and -reso to reset the kubernetes cluster.
With -reso only the cluster is resetted in nothing else is executed.
With -res the cluster gets resetted before execution of the usecase.
parent d26a1c92
No related branches found
No related tags found
2 merge requests!42Integerate theodolite and run uc python scripts,!24run UC as python implementation
...@@ -4,6 +4,7 @@ from kubernetes.stream import stream ...@@ -4,6 +4,7 @@ from kubernetes.stream import stream
import logging # logging import logging # logging
from os import path # path utilities from os import path # path utilities
import subprocess # execute bash commands import subprocess # execute bash commands
import sys # for exit of program
import time # process sleep import time # process sleep
import yaml # convert from file to yaml object import yaml # convert from file to yaml object
...@@ -64,6 +65,14 @@ def load_variables(): ...@@ -64,6 +65,14 @@ def load_variables():
metavar='EXECUTION_MINUTES', metavar='EXECUTION_MINUTES',
help='Duration in minutes subexperiments should be \ help='Duration in minutes subexperiments should be \
executed for') executed for')
parser.add_argument('--reset', '-res',
dest='reset',
action="store_true",
help='Resets the environment before execution')
parser.add_argument('--reset-only', '-reso',
dest='reset_only',
action="store_true",
help='Only resets the environment. Ignores all other parameters')
args = parser.parse_args() args = parser.parse_args()
print(args) print(args)
...@@ -287,10 +296,17 @@ def run_evaluation_script(): ...@@ -287,10 +296,17 @@ def run_evaluation_script():
def delete_resource(obj, del_func): def delete_resource(obj, del_func):
"""
Helper function to delete kuberentes resources.
First tries to delete with the kuberentes object.
Then it uses the dict representation of yaml to delete the object.
:param obj: Either kubernetes resource object or yaml as a dict.
:param del_func: The function that need to be executed for deletion
"""
try: try:
del_func(obj.metadata.name, 'default') del_func(obj.metadata.name, 'default')
except Exception as e: except Exception as e:
logging.info('Error deleting resource with api object, try with dict.') logging.debug('Error deleting resource with api object, try with dict.')
try: try:
del_func(obj['metadata']['name'], 'default') del_func(obj['metadata']['name'], 'default')
except Exception as e: except Exception as e:
...@@ -462,43 +478,61 @@ def stop_lag_exporter(): ...@@ -462,43 +478,61 @@ def stop_lag_exporter():
print(output) print(output)
return return
# def start():
# def reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics):
# """
# def stop(): Stop the applications, delete topics, reset zookeeper and stop lag exporter.
# """
stop_applications(wg, app_svc, app_svc_monitor, app_jmx, app_deploy)
print('---------------------')
delete_topics(topics)
print('---------------------')
reset_zookeeper()
print('---------------------')
stop_lag_exporter()
def main(): def main():
load_variables() load_variables()
print('---------------------') print('---------------------')
wg, app_svc, app_svc_monitor, app_jmx, app_deploy = load_yaml_files()
print('---------------------')
initialize_kubernetes_api() initialize_kubernetes_api()
print('---------------------') print('---------------------')
topics = [('input', args.partitions), topics = [('input', args.partitions),
('output', args.partitions), ('output', args.partitions),
('aggregation-feedback', args.partitions), ('aggregation-feedback', args.partitions),
('configuration', 1)] ('configuration', 1)]
if args.reset_only:
print('Reset only cluster')
reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics)
sys.exit()
if args.reset:
print('Reset cluster before execution')
reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics)
print('---------------------')
create_topics(topics) create_topics(topics)
print('---------------------') print('---------------------')
wg, app_svc, app_svc_monitor, app_jmx, app_deploy = load_yaml_files()
print('---------------------')
wg = start_workload_generator(wg) wg = start_workload_generator(wg)
print('---------------------') print('---------------------')
app_svc, app_svc_monitor, app_jmx, app_deploy = start_application( app_svc, app_svc_monitor, app_jmx, app_deploy = start_application(
app_svc, app_svc,
app_svc_monitor, app_svc_monitor,
app_jmx, app_jmx,
app_deploy) app_deploy)
print('---------------------') print('---------------------')
wait_execution() wait_execution()
print('---------------------') print('---------------------')
stop_applications(wg, app_svc, app_svc_monitor, app_jmx, app_deploy)
print('---------------------') reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics)
delete_topics(topics)
print('---------------------')
reset_zookeeper()
print('---------------------')
stop_lag_exporter()
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment