예제 #1
0
 def failed(self, error):
     err_json = dict(msg=str(error))
     
     #check whether success node exist
     node_list = Service.check_task(task_id=str(self.task_id))
     successflag =False
     for node in node_list:
             if node.status==2:
                 successflag=True
                 break
     # update task
     if successflag:
         Service.update_task(task_id=self.task_id, status=Service.STATUS_PartlySuccess, err=json.dumps(err_json))
     else:
        
         Service.update_task(task_id=self.task_id, status=Service.STATUS_FAILED, err=json.dumps(err_json))
예제 #2
0
파일: api.py 프로젝트: bppan/opendcp
def check_task():
    try:
        #read http params
        req_json = request.get_json(force=True, silent=True)
        if req_json is None:
            raise JsonEncodeException
        global_id = request.headers["X-CORRELATION-ID"]
        if global_id is None:
            return_failed(-1, "X-CORRELATION-ID is Empty"), 400
        source = request.headers["X-SOURCE"]
        if source is None:
            return_failed(-1, "X-SOURCE is Empty"), 400

        Logger.debug("Check request json:" + json.dumps(req_json) +
                     str(global_id))
        task_id = conform_param(req_json, "id", param_type=int, allowNone=True)
        task_name = conform_param(req_json,
                                  "name",
                                  param_type=basestring,
                                  allowNone=True)

        #load task by id or name
        if task_id is None:
            if task_name is None:
                raise ParamErrorException("key task_id/task_name not found")
            else:
                task = Service.get_task_by_name(task_name)
                if task is None:
                    return return_failed(
                        -1,
                        "no task found for specified name:" + task_name), 404
        else:
            task = Service.get_task_by_id(task_id)
            if task is None:
                return return_failed(
                    -1, "no task found for specified id:" + str(task_id)), 404

        node_list = Service.check_task(task_id=str(task.id))

        #return status data
        ret_node = []
        for node in node_list:
            ret_node.append(
                dict(
                    ip=node.ip,
                    status=node.status,
                    #log=json.loads(node.log),
                    log=node.log,
                ))

        ret_task = dict(
            id=task.id,
            status=task.status,
            err=task.err,
        )

        return return_success(content={
            "task": ret_task,
            "nodes": ret_node
        }), 200
    except JsonEncodeException:
        Logger.error("try check_task exception --------------@")
        return return_failed(-1, "json encode error"), 400
    except Exception as e:
        Logger.error("try check_task exception -------------->$ %s" % (str(e)))
        return return_failed(-1, e.message), 500