def delete(self, dep_id): fmlogging.debug("Executing DELETE for dep id:%s" % dep_id) info = utils.get_app_and_service_info(APP_STORE_PATH, "app_ids.txt", dep_id) resp_data = {} response = jsonify(**resp_data) cloud_data = {} if info: cloud_data['type'] = info['cloud'] task_def = task_definition.TaskDefinition('', cloud_data, '') # update app status to DELETING self._update_app_status(info) # dispatch the handler thread delegatethread = mgr.Manager(task_def=task_def, action="delete", info=info) thread.start_new_thread(start_thread, (delegatethread, )) response.status_code = 202 else: response.status_code = 404 return response
def put(self, dep_id): fmlogging.debug("Executing PUT to secure service with deploy id:%s" % dep_id) info = utils.get_service_info(SERVICE_STORE_PATH, "service_ids.txt", dep_id) resp_data = {} response = jsonify(**resp_data) cloud_data = {} if info: cloud_data['type'] = info['cloud'] if cloud_data['type'] != 'local-docker': task_def = task_definition.TaskDefinition('', cloud_data, '') # update service status to SECURING utils.update_service_status(info, constants.SECURING) # dispatch the handler thread delegatethread = mgr.Manager(task_def=task_def, action="secure", info=info) thread.start_new_thread(start_thread, (delegatethread, )) response.status_code = 202 else: response.status_code = 405 else: response.status_code = 404 return response
def post(self): #args = parser.parse_args() fmlogging.debug("Received POST request.") args = request.get_json(force=True) response = jsonify() response.status_code = 201 args_dict = dict(args) try: # Handle service deployment if not 'app' in args_dict and (args_dict['service'] and args_dict['cloud']): cloud_data = args['cloud'] cloud = cloud_data['type'] service_data = args['service'] service_data[0]['lock'] = "false" # Currently supporting single service service_obj = service.Service(service_data[0]) task_name = service_name = service_obj.get_service_name() version = '' # get new version for service deployment service_data, service_version = self._update_service_data( service_data, service_name, version) task_def = task_definition.TaskDefinition( '', cloud_data, service_data) service_id = utils.get_id(SERVICE_STORE_PATH, "service_ids.txt", service_name, service_version, '', '', '', cloud, cloud_data) fmlogging.debug("Service id:%s" % service_id) response.headers['location'] = ( '/deployments/{service_id}').format(service_id=service_id) elif args['app'] and args['service'] and args[ 'cloud']: #handle app and service deployment app_data = args['app'] cloud_data = args['cloud'] service_data = args['service'] service_data[0]['lock'] = "true" task_name = app_name = app_data['app_name'] app_tar_name = app_data['app_tar_name'] content = app_data['app_content'] cloud = cloud_data['type'] app_location, app_version = self._store_app_contents( app_name, app_tar_name, content) app_data['app_location'] = app_location app_data['app_version'] = app_version service_name = service.Service( service_data[0]).get_service_type() + "-" + app_name service_data, service_version = self._update_service_data( service_data, service_name, app_version) task_def = task_definition.TaskDefinition( app_data, cloud_data, service_data) service_id = utils.get_id(SERVICE_STORE_PATH, "service_ids.txt", service_name, service_version, '', '', '', cloud, cloud_data) fmlogging.debug("Service id:%s" % service_id) app_id = utils.get_id(APP_STORE_PATH, "app_ids.txt", app_name, app_version, service_name, service_version, service_id, cloud, cloud_data) fmlogging.debug("App id:%s" % app_id) response.headers['location'] = ( '/deployments/{app_id}').format(app_id=app_id) elif 'app' in args_dict and 'cloud' in args_dict: app_data = args['app'] cloud_data = args['cloud'] task_name = app_name = app_data['app_name'] app_tar_name = app_data['app_tar_name'] content = app_data['app_content'] cloud = cloud_data['type'] app_location, app_version = self._store_app_contents( app_name, app_tar_name, content) app_data['app_location'] = app_location app_data['app_version'] = app_version task_def = task_definition.TaskDefinition( app_data, cloud_data, '') app_id = utils.get_id(APP_STORE_PATH, "app_ids.txt", app_name, app_version, '', '', '', cloud, cloud_data) fmlogging.debug("App id:%s" % app_id) response.headers['location'] = ( '/deployments/{app_id}').format(app_id=app_id) # dispatch the handler thread delegatethread = mgr.Manager(task_name, task_def) thread.start_new_thread(start_thread, (delegatethread, )) fmlogging.debug("Location header:%s" % response.headers['location']) fmlogging.debug("Response:%s" % response) except OSError as oe: fmlogging.error(oe) # Send back service unavailable status response.status_code = 503 return response
def get(self, dep_id): fmlogging.debug("Executing GET for app:%s" % dep_id) info = utils.get_app_and_service_info(APP_STORE_PATH, "app_ids.txt", dep_id) app_exists = False if info: status_data = {} status_data['name'] = info['app_name'] status_data['version'] = info['app_version'] status_data['cloud'] = info['cloud'] if os.path.exists(constants.APP_STORE_PATH + "/" + info['app_name'] + "/" + info['app_version']): app_exists = True dep_log_file_name = info['app_version'] + constants.DEPLOY_LOG prefix = os.getenv('HOST_HOME') fmlogging.debug("HOST_HOME: %s" % prefix) fmlogging.debug( "Inside get_logs - prefix value for log file path:%s" % prefix) if not prefix: prefix = constants.APP_STORE_PATH fmlogging.debug( "Inside get_logs - prefix value for log file path:%s" % prefix) dep_log_file = prefix + "/" + info['app_name'] + "/" dep_log_file = dep_log_file + info[ 'app_version'] + "/" + dep_log_file_name if prefix == constants.APP_STORE_PATH: if not os.path.exists(dep_log_file): dep_log_file = "" status_data['dep_log_location'] = dep_log_file # Get runtime log cloud_data = {} cloud_data['type'] = info['cloud'] task_def = task_definition.TaskDefinition('', cloud_data, '') mgr.Manager(task_def=task_def).get_logs(info) app_log_file_name = info['app_version'] + constants.RUNTIME_LOG app_log_file = prefix + "/" + info['app_name'] + "/" app_log_file = app_log_file + info[ 'app_version'] + "/" + app_log_file_name if prefix == constants.APP_STORE_PATH: if not os.path.exists(app_log_file): app_log_file = "" status_data['run_log_location'] = app_log_file resp_data = {} resp_data['data'] = status_data response = jsonify(**resp_data) response.status_code = 200 if not app_exists: resp_data = {} response = jsonify(**resp_data) response.status_code = 404 return response