Skip to content

Commit

Permalink
controller exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepSampe committed Oct 28, 2017
1 parent d10997d commit dd039ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions api/controllers/actors/abstract_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

class AbstractController(object):

_ask = ['get_target']
_tell = ['update', 'run', 'stop_actor', 'notify']
_ask = ['get_target', 'run']
_tell = ['update', 'stop_actor', 'notify']

def __init__(self):
self.rmq_user = settings.RABBITMQ_USERNAME
Expand All @@ -38,7 +38,8 @@ def _subscribe_metrics(self):
metric_actor = self.host.lookup(metric)
metric_actor.attach(self.proxy)
except NotFoundError as e:
logger.error(e)
logger.error(str(e))
raise e

def _connect_rmq(self):
parameters = pika.ConnectionParameters(host=self.rmq_host,
Expand Down Expand Up @@ -69,6 +70,7 @@ def _init_consum(self, queue, routing_key):
self.consumer.start_consuming()
except Exception as e:
logger.error(str(e))
raise e

def notify(self, body):
"""
Expand Down
16 changes: 8 additions & 8 deletions api/controllers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ class ControllerData(APIView):
Upload or download a global controller.
"""
parser_classes = (MultiPartParser, FormParser,)

def put(self, request, controller_id):
data = {}
try:
r = get_redis_connection()
except RedisError:
return JSONResponse('Error connecting with DB', status=500)
return JSONResponse('Error connecting with DB', status=500)

try:
file_obj = request.FILES['file']
make_sure_path_exists(settings.CONTROLLERS_DIR)
Expand All @@ -115,7 +114,6 @@ def put(self, request, controller_id):
return JSONResponse("Error updating data", status=status.HTTP_400_BAD_REQUEST)
except ValueError:
return JSONResponse("Error starting controller", status=status.HTTP_400_BAD_REQUEST)


def post(self, request):
try:
Expand Down Expand Up @@ -253,6 +251,8 @@ def instance_detail(request, instance_id):
return JSONResponse("Data updated", status=status.HTTP_201_CREATED)
except DataError:
return JSONResponse("Error updating data", status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
return JSONResponse("Error starting the controller: "+str(e), status=status.HTTP_400_BAD_REQUEST)

elif request.method == 'DELETE':
try:
Expand Down Expand Up @@ -290,8 +290,8 @@ def start_controller_instance(instance_id, controller_name, controller_class_nam
controller_actors[instance_id].run()
logger.info("Controller, Started controller actor: "+controller_location)
except Exception as e:
logger.error(str(e.message))
raise ValueError
logger.error(str(e))
raise e


def stop_controller_instance(instance_id):
Expand All @@ -302,4 +302,4 @@ def stop_controller_instance(instance_id):
logger.info("Controller, Stopped controller actor: " + str(instance_id))
except Exception as e:
logger.error(str(e))
raise ValueError
raise e
File renamed without changes.

0 comments on commit dd039ea

Please sign in to comment.