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

Use right images in run uc python and fix some code flaws

parent 15a3e0f7
No related branches found
No related tags found
2 merge requests!42Integerate theodolite and run uc python scripts,!24run UC as python implementation
import argparse # parse arguments from cli import argparse # parse arguments from cli
from kubernetes import client, config # kubernetes api from kubernetes import client, config # kubernetes api
from kubernetes.stream import stream 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 time # process sleep import time # process sleep
import yaml # convert from file to yaml object import yaml # convert from file to yaml object
coreApi = None # acces kubernetes core api coreApi = None # acces kubernetes core api
appsApi = None # acces kubernetes apps api appsApi = None # acces kubernetes apps api
...@@ -131,12 +131,12 @@ def load_yaml_files(): ...@@ -131,12 +131,12 @@ def load_yaml_files():
print('Load kubernetes yaml files') print('Load kubernetes yaml files')
wg = load_yaml('uc-workload-generator/base/workloadGenerator.yaml') wg = load_yaml('uc-workload-generator/base/workloadGenerator.yaml')
app_svc = load_yaml('uc-application/base/aggregation-service.yaml') app_svc = load_yaml('uc-application/base/aggregation-service.yaml')
app_svc_monitor = load_yaml('uc-application/base/service-monitor.yaml') app_svc_monitor = load_yaml('uc-application/base/service-monitor.yaml')
app_jmx = load_yaml('uc-application/base/jmx-configmap.yaml') app_jmx = load_yaml('uc-application/base/jmx-configmap.yaml')
app_deploy = load_yaml('uc-application/base/aggregation-deployment.yaml') app_deploy = load_yaml('uc-application/base/aggregation-deployment.yaml')
print('Kubernetes yaml files loaded') print('Kubernetes yaml files loaded')
return wg, app_svc, app_svc_monitor ,app_jmx, app_deploy return wg, app_svc, app_svc_monitor, app_jmx, app_deploy
def start_workload_generator(wg_yaml): def start_workload_generator(wg_yaml):
...@@ -156,7 +156,8 @@ def start_workload_generator(wg_yaml): ...@@ -156,7 +156,8 @@ def start_workload_generator(wg_yaml):
wg_yaml['spec']['replicas'] = wl_instances wg_yaml['spec']['replicas'] = wl_instances
# TODO: acces over name of container # TODO: acces over name of container
wg_containter = wg_yaml['spec']['template']['spec']['containers'][0] wg_containter = wg_yaml['spec']['template']['spec']['containers'][0]
wg_containter['image'] = 'soerenhenning/uc' + args.uc_id + '-wg:latest' wg_containter['image'] = 'theodolite/theodolite-uc' + args.uc_id + \
+ '-workload-generator:latest'
# TODO: acces over name of attribute # TODO: acces over name of attribute
wg_containter['env'][1]['value'] = str(num_sensors) wg_containter['env'][1]['value'] = str(num_sensors)
wg_containter['env'][2]['value'] = str(wl_instances) wg_containter['env'][2]['value'] = str(wl_instances)
...@@ -204,7 +205,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml): ...@@ -204,7 +205,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml):
group="monitoring.coreos.com", group="monitoring.coreos.com",
version="v1", version="v1",
namespace="default", namespace="default",
plural="servicemonitors", # From CustomResourceDefinition of ServiceMonitor plural="servicemonitors", # CustomResourceDef of ServiceMonitor
body=svc_monitor_yaml, body=svc_monitor_yaml,
) )
print("ServiceMonitor '%s' created." % svc_monitor['metadata']['name']) print("ServiceMonitor '%s' created." % svc_monitor['metadata']['name'])
...@@ -225,7 +226,8 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml): ...@@ -225,7 +226,8 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml):
deploy_yaml['spec']['replicas'] = args.instances deploy_yaml['spec']['replicas'] = args.instances
# TODO: acces over name of container # TODO: acces over name of container
app_container = deploy_yaml['spec']['template']['spec']['containers'][0] app_container = deploy_yaml['spec']['template']['spec']['containers'][0]
app_container['image'] = 'soerenhenning/uc' + args.uc_id + '-app:latest' app_container['image'] = 'theodolite/theodolite-uc' + args.uc_id \
+ '-kstreams-app:latest'
# TODO: acces over name of attribute # TODO: acces over name of attribute
app_container['env'][1]['value'] = str(args.commit_interval_ms) app_container['env'][1]['value'] = str(args.commit_interval_ms)
app_container['resources']['limits']['memory'] = args.memory_limit app_container['resources']['limits']['memory'] = args.memory_limit
...@@ -279,6 +281,7 @@ def delete_resource(obj, del_func): ...@@ -279,6 +281,7 @@ def delete_resource(obj, del_func):
return return
print('Resource deleted') print('Resource deleted')
def stop_applications(wg, app_svc, app_svc_monitor, app_jmx, app_deploy): def stop_applications(wg, app_svc, app_svc_monitor, app_jmx, app_deploy):
"""Stops the applied applications and delete resources. """Stops the applied applications and delete resources.
:param wg: The workload generator statefull set. :param wg: The workload generator statefull set.
...@@ -324,13 +327,16 @@ def delete_topics(topics): ...@@ -324,13 +327,16 @@ def delete_topics(topics):
num_topics_command = [ num_topics_command = [
'/bin/sh', '/bin/sh',
'-c', '-c',
f'kafka-topics --zookeeper my-confluent-cp-zookeeper:2181 --list | sed -n -E "/^(theodolite-.*|input|output|configuration)( - marked for deletion)?$/p" | wc -l' f'kafka-topics --zookeeper my-confluent-cp-zookeeper:2181 --list \
| sed -n -E "/^(theodolite-.*|input|output|configuration)\
( - marked for deletion)?$/p" | wc -l'
] ]
topics_deletion_command = [ topics_deletion_command = [
'/bin/sh', '/bin/sh',
'-c', '-c',
f'kafka-topics --zookeeper my-confluent-cp-zookeeper:2181 --delete --topic "input|output|configuration|theodolite-.*"' f'kafka-topics --zookeeper my-confluent-cp-zookeeper:2181 --delete \
--topic "input|output|configuration|theodolite-.*"'
] ]
# Wait that topics get deleted # Wait that topics get deleted
...@@ -397,11 +403,15 @@ def main(): ...@@ -397,11 +403,15 @@ def main():
('configuration', 1)] ('configuration', 1)]
create_topics(topics) create_topics(topics)
print('---------------------') print('---------------------')
wg, app_svc, app_svc_monitor, app_jmx, app_deploy = load_yaml_files() wg, app_svc, app_svc_monitor, app_jmx, app_deploy = load_yaml_files()
print('---------------------') 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) app_svc, app_svc_monitor, app_jmx, app_deploy = start_application(
app_svc,
app_svc_monitor,
app_jmx,
app_deploy)
print('---------------------') print('---------------------')
wait_execution() wait_execution()
print('---------------------') print('---------------------')
......
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