Exemplo n.º 1
0
def getDataUpdateList(ws=None,
                      schema=None,
                      table=None,
                      limit=10,
                      withKey=True):
    if not ws or not schema or not table:
        print "%s ERROR: No ws|updateCmd value passed" % (common.whoami())
        return None

    latestPKval = getLatestPKValue(schema, table)

    try:
        #Catch mismatched table construction
        if latestPKval[0] == 1146:
            return latestPKval
    except Exception as e:
        pass

    #TEMPORARY: catch if no PKval was returned
    if latestPKval == -1:
        print "%s TESTING: multiple primary keys in a table" % (
            common.whoami())
        return None

    updateCmd = masyncSR.getDataUpdateCommand(schema, table, latestPKval,
                                              limit)
    # print "%s: %s" % (common.whoami(), updateCmd)
    if updateCmd:
        ws.send(updateCmd)
        result = ws.recv()
        # print "%s: Received '%s\n\n'" % (common.whoami(), result)

        # Search for a smaller return limit in case buffer from server side is
        #   unable to handle the data amount returned
        if result.find("false") == 0:
            dataUpdate = getDataUpdateList(ws, schema, table, limit / 2,
                                           withKey)

            # Return data update
            return dataUpdate
        else:
            dataUpdate = common.parseBasicList(result, withKey)

            # Return data update
            return dataUpdate
    else:
        print "%s ERROR: No request message passed" % (common.whoami())
        return None
Exemplo n.º 2
0
def findTableExistence(ws=None, schema=None, table=None):
    if not ws or not schema or not table:
        print "%s ERROR: No ws|schema|table value passed" % (common.whoami())
        return None

    requestMsg = masyncSR.findTable(schema, table)
    if requestMsg:
        ws.send(requestMsg)
        result = ws.recv()
        #        print "%s: Received '%s\n\n'" % (common.whoami(), result)
        doesTableExist = len(common.parseBasicList(result))

        return doesTableExist
    else:
        print "%s ERROR: No request message passed" % (common.whoami())
        return None
Exemplo n.º 3
0
def getTableList(ws=None, schema=None):
    if not ws or not schema:
        print "%s ERROR: No ws|schema value passed" % (common.whoami())
        return None

    requestMsg = masyncSR.showTables(schema)
    if requestMsg:
        ws.send(requestMsg)
        result = ws.recv()
        #        print "%s: Received '%s\n\n'" % (common.whoami(), result)
        tableList = common.parseBasicList(result)

        return tableList
    else:
        print "%s ERROR: No request message passed" % (common.whoami())
        return None
Exemplo n.º 4
0
def getSchemaList(ws=None):
    if not ws:
        print "%s ERROR: No ws value passed" % (common.whoami())
        return None

    requestMsg = masyncSR.showSchemas()
    if requestMsg:
        ws.send(requestMsg)
        result = ws.recv()
        #        print "%s: Received '%s'" % (common.whoami(), result)
        schemaList = common.parseBasicList(result)

        return schemaList
    else:
        print "%s ERROR: No request message passed" % (common.whoami())
        return None
Exemplo n.º 5
0
def comparePKValuesSCandWSS(ws=None, schema=None, table=None, rankOffset=None):
    # Get latest PK Value from Local Server
    mainPKandVal = getLatestPKValue(schema, table)

    # TODO: Check latest value available on WSS
    mainPK = None
    pkValLocalMax = None
    qWSSPKval = None

    try:
        for key, value in mainPKandVal.iteritems():
            mainPK = key
            pkValLocalMax = value

        if rankOffset > 0 and rankOffset is not None:
            # Quick fix in case we want the Nth highest PK for delayed received SMS
            qWSSPKval = "SELECT DISTINCT(%s) as %s FROM %s ORDER BY %s DESC LIMIT 1 OFFSET %s" % (
                mainPK, mainPK, table, mainPK, rankOffset)
        else:
            qWSSPKval = "SELECT MAX(%s) as %s FROM %s" % (mainPK, mainPK,
                                                          table)

        print "WSS Query: %s, rankOffset: %s" % (qWSSPKval, rankOffset)
        wsspkvalCmd = masyncSR.compReadQuery(schema, qWSSPKval)
        # print wsspkvalCmd
        if wsspkvalCmd:
            ws.send(wsspkvalCmd)
            result = ws.recv()
            # print "%s: Received '%s\n\n'" % (common.whoami(), result)
            dataWSSpkval = (common.parseBasicList(result, True))[0]
            print dataWSSpkval

            # Compare latest PK Value from Local Server and WSS
            pkValWSS = None
            for key, value in dataWSSpkval.iteritems():
                pkValWSS = value

            if pkValLocalMax > pkValWSS:
                # print "Local Data is more updated. Update Websocket Server data"
                return dataWSSpkval
            else:
                print "%s: No need to update Websocket Server data using Special Client" % (
                    table)
                return False
    except:
        return False