Beispiel #1
0
def UpdateTaskInfoD(args):

    task_id = args['task_id']
    service_id = args['service_id']
    task_begin = args['task_begin']
    task_end = args['task_end']
    task_message = args['task_message']
    task_status = args['task_status']

    if task_message == '':
        task_message = 'none'
        args['task_message'] = 'none'

    MySQL_engine.execution_options(isolation_level="READ COMMITTED")

    RetObj = {}

    if task_begin == '' and task_end == '':

        task_status = 0
        task_begin = datetime.now()

        args['task_begin'] = task_begin
        args['task_status'] = task_status

        vInsertRow = TaskInfo(task_id=task_id,
                              service_id=service_id,
                              task_begin=task_begin,
                              task_message=task_message,
                              task_status=task_status)

        with mysession_scope(RetObj) as MySession:
            MySession.add(vInsertRow)

        if RetObj['Code'] == '0':
            print "MySession Exception:[" + RetObj['Message'] + "]"
        else:
            RetObj['Code'] = '1'
            RetObj['TaskArgs'] = args
    else:

        task_end = datetime.now()
        args['task_end'] = task_end
        args['task_status'] = 1

        with mysession_scope(RetObj) as MySession:
            MySession.query(TaskInfo).filter(
                TaskInfo.task_id == task_id).update(args)

            RetObj['Code'] = '1'
            RetObj['TaskArgs'] = args

        if RetObj['Code'] == '0':
            print "MySession Exception:[" + RetObj['Message'] + "]"

    return RetObj
    def post(self):

        reg_data = reqparse.RequestParser()
        reg_data.add_argument('obj_id', type=str, location='args')
        args = reg_data.parse_args()

        obj_id = args['obj_id']

        MySQL_engine.execution_options(isolation_level="READ COMMITTED")

        RetObj = {}

        with mysession_scope( RetObj ) as MySession:
            vQuery = MySession.query( ServiceType ).filter(ServiceType.type_level==2).filter(ServiceType.type_uplevel==obj_id).order_by( ServiceType.obj_id )

            vtServiceTypes = vQuery.all()

            arrRows = []
            for vtServiceType in vtServiceTypes:
                arrRows.append( vtServiceType.toDict() )

            arrRows = formatdatetime( arrRows, 'type_date')

            RetObj['Code'] = '1'
            RetObj['RowsArray'] = arrRows

        if RetObj['Code'] == '0':
            print "MySession Exception:[" + RetObj['Message'] + "]"

        return my_make_response( RetObj )
    def post(self):

        MySQL_engine.execution_options(isolation_level="READ COMMITTED")

        RetObj = {}

        with mysession_scope(RetObj) as MySession:
            vQuerys = MySession.query(  ServiceInfo.service_id,
                                        ServiceInfo.service_status,
                                        ServiceInfo.service_url,
                                        ServiceInfo.service_func,
                                        ServiceInfo.service_owner,
                                        ServiceInfo.service_date,
                                        ServiceType.type_baseurl)\
                                .filter(    (ServiceInfo.service_status > 0) &
                                            (ServiceInfo.service_type == ServiceType.obj_id) )\
                                .order_by(  ServiceInfo.service_id).all()

            if len(vQuerys) == 0:
                RetObj['Code'] = '0'
                RetObj['Message'] = 'do not find any API service , registed!'
            else:
                arrRows = []
                for vQuery in vQuerys:
                    arrRows.append(vQuery.toDict())

                arrRows = formatdatetime(arrRows, 'type_date')

                RetObj['Code'] = 'redisplay'
                RetObj['RowsArray'] = arrRows

        if RetObj['Code'] == '0':
            print "MySession Exception:[" + RetObj['Message'] + "]"

        return RetObj
    def post(self):

        reg_data = reqparse.RequestParser()
        reg_data.add_argument('service_id', type=str, location='args')
        args = reg_data.parse_args()

        service_id = args['service_id']

        MySQL_engine.execution_options(isolation_level="READ COMMITTED")

        RetObj = {}

        if service_id != 'AUTO':
            with mysession_scope( RetObj ) as MySession:
                MySession.query(ServiceInfo).filter(ServiceInfo.service_id == service_id).delete()

                RetObj['Code'] = '1'
                RetObj['RowsArray'] = 'AAAAA'

            if RetObj['Code'] == '0':
                print "MySession Exception:[" + RetObj['Message'] + "]"
        else:
            RetObj['Code'] = '1'
            RetObj['RowsArray'] = 'BBBBB'

        return my_make_response( RetObj )
Beispiel #5
0
    def post(self):

        MySQL_engine.execution_options(isolation_level="READ COMMITTED")

        RetObj = {}
        vresult = ''
        vparam1 = ''

        vsqlstatement1 = "select now();"

        vsqlstatement2 = "select date_sub(now(), interval 60 minute)"

        vsqlstatement3 =" select c.type_name as name, count(*) as value " \
                        " from task_info as a, service_info as b , service_type as c " \
                        " where a.task_begin > DATE_FORMAT( (select now()),  '%Y-%m-%d') and " \
                                " a.service_id = b.service_id and " \
                                " b.service_type = c.type_id " \
                        " group by 1 "\
                        " order by 2 desc "

        arrRows = []
        vTimeLine = []
        vTimeLineObj = {}
        vTTimeLineObj = []
        vDataLine = []
        # vTopNumber = 10

        with mysession_scope(RetObj) as MySession:
            vresult = MySession.execute(text(vsqlstatement3))

            # if vTopNumber >= vresult.cursor._rowcount :
            #     vTopNumber = vresult.cursor._rowcount

            if vresult.cursor._rowcount > 0:
                for index in range(0, vresult.cursor._rowcount):
                    vMyRow = vresult.fetchone()
                    newobj = {}

                    for index2 in range(len(vMyRow)):
                        newobj[vMyRow._parent.keys[index2].encode(
                            'ascii')] = vMyRow[index2]

                        if index2 == 0:
                            vTimeLine.append(vMyRow[index2])

                    arrRows.append(newobj)

            RetObj['Code'] = '1'
            RetObj['TaskArgs'] = arrRows
            RetObj['TimeLine'] = vTimeLine

        if RetObj['Code'] == '0':
            print "MySession Exception:[" + RetObj['Message'] + "]"

        return my_make_response(RetObj)
    def post(self):

        MySQL_engine.execution_options(isolation_level="READ COMMITTED")

        RetObj = {}

        with mysession_scope( RetObj ) as MySession:
            vQuery = MySession.query( ServiceType ).filter(ServiceType.type_level==1).order_by( ServiceType.obj_id )

            vtServiceTypes = vQuery.all()

            arrRows = []
            for vtServiceType in vtServiceTypes:
                arrRows.append( vtServiceType.toDict() )

            arrRows = formatdatetime( arrRows, 'type_date')

            RetObj['Code'] = '1'
            RetObj['LEVEL_1'] = arrRows

        if RetObj['Code'] == '0':
            print "MySession Exception:[" + RetObj['Message'] + "]"

        return my_make_response( RetObj )
    def post(self):

        reg_data = reqparse.RequestParser()
        reg_data.add_argument('service_id', type=str, location='args')
        reg_data.add_argument('service_type', type=str, location='args')
        reg_data.add_argument('service_name', type=str, location='args')
        reg_data.add_argument('service_desc', type=str, location='args')
        reg_data.add_argument('service_url', type=str, location='args')
        reg_data.add_argument('service_func', type=str, location='args')
        reg_data.add_argument('service_owner', type=str, location='args')
        reg_data.add_argument('service_date', type=str, location='args')
        reg_data.add_argument('service_status', type=str, location='args')
        args = reg_data.parse_args()

        args['service_func'] = args['service_func'].lower()
        service_id = args['service_id']
        service_type = args['service_type']
        service_name = args['service_name']
        service_desc = args['service_desc']
        service_url = args['service_url']
        service_func = args['service_func']
        service_status = args['service_status']
        service_owner = args['service_owner']
        service_date = args['service_date']

        RetObj = {}

        if service_name == '':
            service_name = 'none'
            args['service_name'] = 'none'

        if service_desc == '':
            service_desc = 'none'
            args['service_desc'] = 'none'

        if service_url == '':
            service_url = 'none'
            args['service_url'] = 'none'

        if service_func == '':
            service_func = 'none'
            args['service_func'] = 'none'

        MySQL_engine.execution_options(isolation_level="READ COMMITTED")

        if service_id == 'AUTO' :

            with mysession_scope2( RetObj ) as MySession:
                vQuerys = MySession.query( func.max(ServiceInfo.service_id).label('col1') ).all()

                # vtServiceTypes = vQuery.all()
                if len(vQuerys) != 0:
                    for tempitem in vQuerys:
                        MaxService_id = tempitem.col1 + 1
                else:
                    MaxService_id = 10000001

                args['service_id'] = MaxService_id
                args['service_date'] = ''

                service_url = service_url.encode('ascii')

                service_url = service_url.replace('//', '/')

                print service_url

                if service_url[0] != '/' and service_url != 'none' :
                    service_url = '/' + service_url

                if service_url[ len(service_url) - 1 ] == '/' and len(service_url) != 1 :
                    service_url = service_url[ 0: (len(service_url) - 1 )]

                service_date = datetime.now()

                vInsertRow = ServiceInfo(service_id=MaxService_id,
                                         service_type=service_type,
                                         service_name=service_name,
                                         service_desc=service_desc,
                                         service_func=service_func,
                                         service_url=service_url,
                                         service_date=service_date,
                                         service_status=service_status,
                                         service_owner=service_owner
                                         )

                MySession.add(vInsertRow)

                vtServiceTypes = MySession.query(ServiceInfo).filter(
                    ServiceInfo.service_id == MaxService_id).all()

                arrRows = []
                for vtServiceType in vtServiceTypes:
                    arrRows.append(vtServiceType.toDict())

                arrRows = formatdatetime(arrRows, 'service_date')

                RetObj['Code'] = 'redisplay'
                RetObj['RowsArray'] = arrRows


            if RetObj['Code'] == '0':
                print "MySession Exception:[" + RetObj['Message'] + "]"
        else:
            service_url = service_url.encode('ascii')

            service_url = service_url.replace('//', '/')

            if service_url[0] != '/' and service_url != 'none' :
                service_url = '/' + service_url

            if service_url[len(service_url) - 1] == '/' and len(service_url) != 1:
                service_url = service_url[ 0: (len(service_url) - 1) ]

            args['service_url'] = service_url

            with mysession_scope( RetObj ) as MySession:
                MySession.query(ServiceInfo).filter(ServiceInfo.service_id == service_id).update(args)

                RetObj['Code'] = '1'
                RetObj['RowsArray'] = 'success'

            if RetObj['Code'] == '0':
                print "MySession Exception:[" + RetObj['Message'] + "]"

        return my_make_response( RetObj )
Beispiel #8
0
    def post(self):

        MySQL_engine.execution_options(isolation_level="READ COMMITTED")

        RetObj = {}
        vresult = ''
        vparam1 = ''

        vsqlstatement1 = "select now();"

        vsqlstatement2 = " select date_sub(now(), interval 60 minute) "

        vsqlstatement3 ="select c.type_name as ServiceType, " \
                                "DATE_FORMAT (a.task_begin, '%Y-%m-%d %H:%i') as TaskStartTime, " \
                                "count(*) as TotalNum "\
                        "from task_info as a, service_info as b, service_type as c "\
                        "where a.task_begin >= :param1 and " \
                        "a.service_id = b.service_id and " \
                        "b.service_type = c.type_id " \
                        " group by 1, 2 "

        arrRows = []
        vTimeLine = []
        vTimeLineObj = {}
        vTTimeLineObj = []
        vDataLine = []

        with mysession_scope(RetObj) as MySession:
            vresult = MySession.execute(text(vsqlstatement2))

            if vresult.cursor._rowcount > 0:
                vMyRow = vresult.fetchone()

                vparam1 = str(vMyRow[0])
                vStartTime = vMyRow[0]
                vStartName = ''
                vTimeLine = GetTimeLine(vStartTime)

                vresult = MySession.execute(text(vsqlstatement3),
                                            {"param1": vparam1})

                if vresult.cursor._rowcount > 0:

                    for index in range(vresult.cursor._rowcount):
                        vMyRow = vresult.fetchone()
                        newobj = {}

                        for index2 in range(len(vMyRow)):
                            newobj[vMyRow._parent.keys[index2].encode(
                                'ascii')] = vMyRow[index2]

                        arrRows.append(newobj)

                        if vStartName == '':
                            vStartName = newobj['ServiceType']

                        if newobj['ServiceType'] != vStartName or index == (
                                vresult.cursor._rowcount - 1):
                            vTimeLineObj['name'] = str(vStartName)
                            vTimeLineObj['type'] = 'line'

                            for index3 in range(len(vTimeLine)):
                                vDataLineData = 0
                                for index4 in range(len(arrRows)):
                                    vtempstr = arrRows[index4][
                                        'TaskStartTime'].encode('ascii')

                                    if vTimeLine[index3] == str(
                                            arrRows[index4]
                                        ['TaskStartTime'].encode('ascii')):
                                        vDataLineData = arrRows[index4][
                                            'TotalNum']

                                vDataLine.append(vDataLineData)

                            vTimeLineObj['data'] = vDataLine

                            vStartName = newobj['ServiceType']
                            vTTimeLineObj.append(vTimeLineObj)
                            vTimeLineObj = {}
                            arrRows = []
                            vDataLine = []

            RetObj['Code'] = '1'
            RetObj['TaskArgs'] = vTTimeLineObj
            RetObj['TimeLine'] = vTimeLine

        if RetObj['Code'] == '0':
            print "MySession Exception:[" + RetObj['Message'] + "]"

        return my_make_response(RetObj)
Beispiel #9
0
    def post(self):

        reg_data = reqparse.RequestParser()
        reg_data.add_argument('task_id', type=str, location='args')
        reg_data.add_argument('service_id', type=str, location='args')
        reg_data.add_argument('task_begin', type=str, location='args')
        reg_data.add_argument('task_end', type=str, location='args')
        reg_data.add_argument('task_message', type=str, location='args')
        reg_data.add_argument('task_status', type=str, location='args')

        args = reg_data.parse_args()

        task_id = args['task_id']
        service_id = args['service_id']
        task_begin = args['task_begin']
        task_end = args['task_end']
        task_message = args['task_message']
        task_status = args['task_status']

        if task_message == '':
            task_message = 'none'
            args['task_message'] = 'none'

        MySQL_engine.execution_options(isolation_level="READ COMMITTED")

        RetObj = {}

        if task_begin == '' and task_end == '':

            task_status = 0
            task_begin = datetime.now()

            args['task_begin'] = task_begin
            args['task_status'] = task_status

            vInsertRow = TaskInfo(
                task_id=task_id,
                service_id=service_id,
                task_begin=task_begin,
                # task_end=task_end,
                task_message=task_message,
                task_status=task_status)

            with mysession_scope(RetObj) as MySession:
                MySession.add(vInsertRow)

                RetObj['Code'] = '1'
                RetObj['TaskArgs'] = args

            if RetObj['Code'] == '0':
                print "MySession Exception:[" + RetObj['Message'] + "]"
        else:

            task_end = datetime.now()
            args['task_end'] = task_end
            args['task_status'] = 1

            with mysession_scope(RetObj) as MySession:
                MySession.query(TaskInfo).filter(
                    TaskInfo.task_id == task_id).update(args)

                RetObj['Code'] = '1'
                RetObj['TaskArgs'] = args

            if RetObj['Code'] == '0':
                print "MySession Exception:[" + RetObj['Message'] + "]"

        return my_make_response(RetObj)