Skip to content

Commit

Permalink
Parameters of Controllers to **kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepSampe committed Oct 24, 2017
1 parent 22c21c4 commit 1c73a97
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion api/api/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def run():

# Workload metric definitions
for key in r.keys('workload_metric:*'):
r.hset(key, 'enabled', False)
r.hset(key, 'status', 'Stopped')

# Workload metric Actors
for key in r.keys('metric:*'):
Expand Down
8 changes: 3 additions & 5 deletions api/controllers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,16 @@ def start_controller_instance(instance_id, controller_name, controller_class_nam

controller_location = os.path.join(controller_name, controller_class_name)
parameters = parameters.strip().split(',')
# params = {}
params = list()
params = {}
for parameter in parameters:
param_name, value = parameter.split('=')
# params[param_name] = value
params.append(value)
params[param_name] = value

actor_id = controller_name+':'+instance_id

try:
if instance_id not in controller_actors:
controller_actors[instance_id] = host.spawn(actor_id, controller_location, params)
controller_actors[instance_id] = host.spawn(actor_id, controller_location, **params)
controller_actors[instance_id].run()
logger.info("Controller, Started controller actor: "+controller_location)
except Exception as e:
Expand Down
49 changes: 26 additions & 23 deletions api/metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def metric_module_list(request):
workload_metrics = []
for key in keys:
metric = r.hgetall(key)
to_json_bools(metric, 'in_flow', 'out_flow', 'ssync', 'enabled')
to_json_bools(metric, 'put', 'get', 'ssync')
workload_metrics.append(metric)
sorted_workload_metrics = sorted(workload_metrics, key=lambda x: int(itemgetter('id')(x)))
return JSONResponse(sorted_workload_metrics, status=status.HTTP_200_OK)
Expand All @@ -98,9 +98,9 @@ def metric_module_list(request):

def start_metric(actor_id):
host = create_local_host()
logger.info("Metric, Starting workload metric actor: " + str(actor_id))
try:
if actor_id not in metric_actors:
logger.info("Metric, Starting workload metric actor: " + str(actor_id))
metric_actors[actor_id] = host.spawn(actor_id, settings.METRIC_MODULE,
[actor_id, "metric." + actor_id])
metric_actors[actor_id].init_consum()
Expand Down Expand Up @@ -134,7 +134,7 @@ def metric_module_detail(request, metric_module_id):
if request.method == 'GET':
metric = r.hgetall("workload_metric:" + str(metric_id))

to_json_bools(metric, 'in_flow', 'out_flow', 'ssync', 'enabled')
to_json_bools(metric, 'put', 'get', 'ssync')
return JSONResponse(metric, status=status.HTTP_200_OK)

elif request.method == 'POST':
Expand All @@ -143,29 +143,32 @@ def metric_module_detail(request, metric_module_id):
except ParseError:
return JSONResponse("Invalid format or empty request", status=status.HTTP_400_BAD_REQUEST)

if len(data) == 1:
# Enable/disable button
redis_data = r.hgetall('workload_metric:' + str(metric_id))
redis_data.update(data)
data = redis_data
redis_data = r.hgetall('workload_metric:' + str(metric_id))
redis_data.update(data)
data = redis_data
to_json_bools(data, 'put', 'get', 'ssync')

if 'metric_name' not in data:
metric_name = r.hget('workload_metric:' + str(metric_id), 'metric_name').split('.')[0]
else:
metric_name = data['metric_name'].split('.')[0]

if data['enabled']:
if data['status'] == 'Running':
try:
if data['in_flow'] == 'True':
if data['put'] == True:
start_metric('put_'+metric_name)
if data['out_flow'] == 'True':
else:
stop_metric('put_'+metric_name)
if data['get'] == True:
start_metric('get_'+metric_name)
else:
stop_metric('get_'+metric_name)
except Exception:
data['enabled'] = False
data['status'] = 'Stopped'
else:
if data['in_flow'] == 'True':
if data['put'] == True:
stop_metric('put_'+metric_name)
if data['out_flow'] == 'True':
if data['get'] == True:
stop_metric('get_'+metric_name)

try:
Expand All @@ -179,11 +182,11 @@ def metric_module_detail(request, metric_module_id):
wm_data = r.hgetall('workload_metric:' + str(metric_id))
metric_name = wm_data['metric_name'].split('.')[0]

if wm_data['in_flow'] == 'True':
if wm_data['put'] == 'True':
actor_id = 'put_'+metric_name
if actor_id in metric_actors:
stop_metric(actor_id)
if wm_data['out_flow'] == 'True':
if wm_data['get'] == 'True':
actor_id = 'get_'+metric_name
if actor_id in metric_actors:
stop_metric(actor_id)
Expand All @@ -206,18 +209,18 @@ class MetricModuleData(APIView):
Upload or download a metric module data.
"""
parser_classes = (MultiPartParser, FormParser,)

def put(self, request, metric_module_id):
data = {}

try:
r = get_redis_connection()
except RedisError:
return JSONResponse('Error connecting with DB', status=status.HTTP_500_INTERNAL_SERVER_ERROR)

try:
file_obj = request.FILES['file']

make_sure_path_exists(settings.WORKLOAD_METRICS_DIR)
path = save_file(file_obj, settings.WORKLOAD_METRICS_DIR)
data['metric_name'] = os.path.basename(path)
Expand All @@ -230,7 +233,7 @@ def put(self, request, metric_module_id):
return JSONResponse(e.message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

r.hmset('workload_metric:' + str(metric_module_id), data)

return JSONResponse("Data updated", status=status.HTTP_201_CREATED)
except DataError:
return JSONResponse("Error updating data", status=status.HTTP_400_BAD_REQUEST)
Expand Down Expand Up @@ -268,9 +271,9 @@ def post(self, request):

if data['enabled']:
metric_name = data['metric_name'].split('.')[0]
if data['in_flow']:
if data['put']:
start_metric('put_'+metric_name)
if data['out_flow']:
if data['get']:
start_metric('get_'+metric_name)

return JSONResponse(data, status=status.HTTP_201_CREATED)
Expand Down

0 comments on commit 1c73a97

Please sign in to comment.