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

add commit ms as default again for kubernetes deployment and overwrite existing env variables

parent e3f96988
No related branches found
No related tags found
No related merge requests found
...@@ -41,8 +41,8 @@ def initialize_kubernetes_api(): ...@@ -41,8 +41,8 @@ def initialize_kubernetes_api():
config.load_kube_config() # try using local config config.load_kube_config() # try using local config
except config.config_exception.ConfigException as e: except config.config_exception.ConfigException as e:
# load config from pod, if local config is not available # load config from pod, if local config is not available
logging.debug('Failed loading local Kubernetes configuration,' logging.debug(
+ ' try from cluster') 'Failed loading local Kubernetes configuration try from cluster')
logging.debug(e) logging.debug(e)
config.load_incluster_config() config.load_incluster_config()
...@@ -58,8 +58,7 @@ def create_topics(topics): ...@@ -58,8 +58,7 @@ def create_topics(topics):
# Calling exec and waiting for response # Calling exec and waiting for response
print('Create topics') print('Create topics')
for (topic, partitions) in topics: for (topic, partitions) in topics:
print('Create topic ' + topic + ' with #' + str(partitions) print(f'Create topic {topic} with #{partitions} partitions')
+ ' partitions')
exec_command = [ exec_command = [
'/bin/sh', '/bin/sh',
'-c', '-c',
...@@ -86,7 +85,7 @@ def load_yaml(file_path): ...@@ -86,7 +85,7 @@ def load_yaml(file_path):
with f: with f:
return yaml.safe_load(f) return yaml.safe_load(f)
except Exception as e: except Exception as e:
logging.error('Error opening file %s' % file_path) logging.error('Error opening file %s', file_path)
logging.error(e) logging.error(e)
...@@ -105,6 +104,15 @@ def load_yaml_files(): ...@@ -105,6 +104,15 @@ def load_yaml_files():
return wg, app_svc, app_svc_monitor, app_jmx, app_deploy return wg, app_svc, app_svc_monitor, app_jmx, app_deploy
def replace_env_value(container, key, value):
"""
Special method to replace in a container with kubernetes env values
the value of a given parameter.
"""
next(filter(lambda x: x['name'] == key, container))[
'value'] = value
def start_workload_generator(wg_yaml, dim_value, uc_id): def start_workload_generator(wg_yaml, dim_value, uc_id):
"""Starts the workload generator. """Starts the workload generator.
:param wg_yaml: The yaml object for the workload generator. :param wg_yaml: The yaml object for the workload generator.
...@@ -139,22 +147,22 @@ def start_workload_generator(wg_yaml, dim_value, uc_id): ...@@ -139,22 +147,22 @@ def start_workload_generator(wg_yaml, dim_value, uc_id):
'-workload-generator:latest' '-workload-generator:latest'
# Set environment variables # Set environment variables
next(filter(lambda x: x['name'] == 'NUM_SENSORS', wg_containter['env']))[ replace_env_value(wg_containter['env'], 'NUM_SENSORS', str(num_sensors))
'value'] = str(num_sensors) replace_env_value(wg_containter['env'], 'INSTANCES', str(wl_instances))
next(filter(lambda x: x['name'] == 'INSTANCES', wg_containter['env']))[
'value'] = str(wl_instances)
if uc_id == '2': # Special configuration for uc2 if uc_id == '2': # Special configuration for uc2
next(filter(lambda x: x['name'] == 'NUM_NESTED_GROUPS', wg_containter['env']))[ replace_env_value(
'value'] = str(num_nested_groups) wg_containter['env'], 'NUM_NESTED_GROUPS', str(num_nested_groups))
try: try:
wg_ss = appsApi.create_namespaced_deployment( wg_ss = appsApi.create_namespaced_deployment(
namespace=namespace, namespace=namespace,
body=wg_yaml body=wg_yaml
) )
print("Deployment '%s' created." % wg_ss.metadata.name) print(f'Deployment {wg_ss.metadata.name} created.')
return wg_ss return wg_ss
except client.rest.ApiException as e: except client.rest.ApiException as e:
print("Deployment creation error: %s" % e.reason) print(f'Deployment creation error: {e.reason}')
return wg_yaml return wg_yaml
...@@ -185,10 +193,10 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, ...@@ -185,10 +193,10 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml,
try: try:
svc = coreApi.create_namespaced_service( svc = coreApi.create_namespaced_service(
namespace=namespace, body=svc_yaml) namespace=namespace, body=svc_yaml)
print("Service '%s' created." % svc.metadata.name) print(f'Service {svc.metadata.name} created.')
except client.rest.ApiException as e: except client.rest.ApiException as e:
svc = svc_yaml svc = svc_yaml
logging.error("Service creation error: %s" % e.reason) logging.error("Service creation error: %s", e.reason)
# Create custom object service monitor # Create custom object service monitor
try: try:
...@@ -199,29 +207,37 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, ...@@ -199,29 +207,37 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml,
plural="servicemonitors", # CustomResourceDef of ServiceMonitor plural="servicemonitors", # CustomResourceDef of ServiceMonitor
body=svc_monitor_yaml, body=svc_monitor_yaml,
) )
print("ServiceMonitor '%s' created." % svc_monitor['metadata']['name']) print(f"ServiceMonitor '{svc_monitor['metadata']['name']}' created.")
except client.rest.ApiException as e: except client.rest.ApiException as e:
svc_monitor = svc_monitor_yaml svc_monitor = svc_monitor_yaml
logging.error("ServiceMonitor creation error: %s" % e.reason) logging.error("ServiceMonitor creation error: %s", e.reason)
# Apply jmx config map for aggregation service # Apply jmx config map for aggregation service
try: try:
jmx_cm = coreApi.create_namespaced_config_map( jmx_cm = coreApi.create_namespaced_config_map(
namespace=namespace, body=jmx_yaml) namespace=namespace, body=jmx_yaml)
print("ConfigMap '%s' created." % jmx_cm.metadata.name) print(f"ConfigMap '{jmx_cm.metadata.name}' created.")
except client.rest.ApiException as e: except client.rest.ApiException as e:
jmx_cm = jmx_yaml jmx_cm = jmx_yaml
logging.error("ConfigMap creation error: %s" % e.reason) logging.error("ConfigMap creation error: %s", e.reason)
# Create deployment # Create deployment
deploy_yaml['spec']['replicas'] = instances deploy_yaml['spec']['replicas'] = instances
app_container = next(filter( app_container = next(filter(
lambda x: x['name'] == 'uc-application', deploy_yaml['spec']['template']['spec']['containers'])) lambda x: x['name'] == 'uc-application',
deploy_yaml['spec']['template']['spec']['containers']))
app_container['image'] = 'theodolite/theodolite-uc' + uc_id \ app_container['image'] = 'theodolite/theodolite-uc' + uc_id \
+ '-kstreams-app:latest' + '-kstreams-app:latest'
# Set configurations environment parameters for SPE # Set configurations environment parameters for SPE
for k, v in configurations.items(): for k, v in configurations.items():
# check if environment variable is already definde in yaml
env = next(filter(lambda x: x['name'] == k,
app_container['env']), None)
if env is not None:
env['value'] = v # replace value
else:
# create new environment pair
conf = {'name': k, 'value': v} conf = {'name': k, 'value': v}
app_container['env'].append(conf) app_container['env'].append(conf)
...@@ -235,10 +251,10 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, ...@@ -235,10 +251,10 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml,
namespace=namespace, namespace=namespace,
body=deploy_yaml body=deploy_yaml
) )
print("Deployment '%s' created." % app_deploy.metadata.name) print(f"Deployment '{app_deploy.metadata.name}' created.")
except client.rest.ApiException as e: except client.rest.ApiException as e:
app_deploy = deploy_yaml app_deploy = deploy_yaml
logging.error("Deployment creation error: %s" % e.reason) logging.error("Deployment creation error: %s", e.reason)
return svc, svc_monitor, jmx_cm, app_deploy return svc, svc_monitor, jmx_cm, app_deploy
...@@ -252,7 +268,7 @@ def wait_execution(execution_minutes): ...@@ -252,7 +268,7 @@ def wait_execution(execution_minutes):
for i in range(execution_minutes): for i in range(execution_minutes):
time.sleep(60) time.sleep(60)
print(f"Executed: {i+1} minutes") print(f'Executed: {i+1} minutes')
print('Execution finished') print('Execution finished')
return return
...@@ -267,7 +283,8 @@ def run_evaluation(exp_id, uc_id, dim_value, instances, execution_minutes, prome ...@@ -267,7 +283,8 @@ def run_evaluation(exp_id, uc_id, dim_value, instances, execution_minutes, prome
:param int execution_minutes: How long the use case where executed. :param int execution_minutes: How long the use case where executed.
""" """
print('Run evaluation function') print('Run evaluation function')
lag_analysis.main(exp_id, f'uc{uc_id}', dim_value, instances, execution_minutes, prometheus_base_url, result_path) lag_analysis.main(exp_id, f'uc{uc_id}', dim_value, instances,
execution_minutes, prometheus_base_url, result_path)
return return
...@@ -319,7 +336,7 @@ def stop_applications(wg, app_svc, app_svc_monitor, app_jmx, app_deploy): ...@@ -319,7 +336,7 @@ def stop_applications(wg, app_svc, app_svc_monitor, app_jmx, app_deploy):
name=app_svc_monitor['metadata']['name']) name=app_svc_monitor['metadata']['name'])
print('Resource deleted') print('Resource deleted')
except Exception as e: except Exception as e:
print("Error deleting service monitor") print('Error deleting service monitor')
print('Delete jmx config map') print('Delete jmx config map')
delete_resource(app_jmx, coreApi.delete_namespaced_config_map) delete_resource(app_jmx, coreApi.delete_namespaced_config_map)
...@@ -372,7 +389,7 @@ def delete_topics(topics): ...@@ -372,7 +389,7 @@ def delete_topics(topics):
stderr=True, stdin=False, stderr=True, stdin=False,
stdout=True, tty=False) stdout=True, tty=False)
if resp == '0': if resp == '0':
print("Topics deleted") print('Topics deleted')
break break
return return
......
...@@ -26,6 +26,8 @@ spec: ...@@ -26,6 +26,8 @@ spec:
value: "http://my-confluent-cp-schema-registry:8081" value: "http://my-confluent-cp-schema-registry:8081"
- name: JAVA_OPTS - name: JAVA_OPTS
value: "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=5555" value: "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=5555"
- name: COMMIT_INTERVAL_MS # Set as default for the applications
value: "100"
resources: resources:
limits: limits:
memory: 4Gi memory: 4Gi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment