Beispiel #1
0
    def add(self):

        self.myId = getUuid()
        self.startTime = get_current_time()
        self.finishTime = get_current_time()

        obj = {
            "ID": self.myId,
            "AT_AccountId": self.accountId,
            "AT_ApiId": self.apiId,
            "AT_Type": self.type,
            "AT_Name": self.name,
            "AT_State": self.state,
            "AT_User": self.user or "",
            "AT_Request": transToStr(self.request),
            "AT_Reply": transToStr(self.reply),
            "AT_StartTime": get_current_time(),
            "AT_CreateTime": get_current_time(),
        }

        if (self.state == API_STATE_FINISHED
                or self.state == API_STATE_FAILED):
            obj["AT_FinishTime"] = get_current_time()

        ret = self.db.insert(TB_APITRACE, obj)
        if ret == -1:
            WARNING("add api %s error for db operation" % self.myId)
            return DB_ERR

        return OCT_SUCCESS
Beispiel #2
0
def deleteApi(db, arg):
    apiId = arg["paras"].get("id")
    api = getApi(db, apiId=apiId)
    if (not api):
        WARNING("api %s not exist" % apiId)
        return SEGMENT_NOT_EXIST

    return api.delete()
Beispiel #3
0
def updateApiReply(db, arg):
    apiId = arg.get("id")
    api = getApi(db, apiId=apiId)
    if (not api):
        WARNING("api %s not exist" % apiId)
        return SEGMENT_NOT_EXIST
    # TBD
    return api.updateReply()
Beispiel #4
0
def updateApiReply(db, apiId, state, reply={}):
    api = getApi(db, apiId=apiId)
    if (not api):
        WARNING("api %s not exist" % apiId)
        return SEGMENT_NOT_EXIST

    api.state = state
    api.reply = reply
    return api.updateReply()
Beispiel #5
0
    def delete(self):

        cond = "WHERE ID='%s'" % self.myId
        ret = self.db.delete(TB_APITRACE, cond=cond)
        if ret == -1:
            WARNING("delete api %s error for db operation" % self.apiId)
            return DB_ERR

        return 0
Beispiel #6
0
	def updateLogin(self):
		
		userObj = {
			"U_LastLogin": get_current_time(),
		}
		
		cond = "WHERE ID='%s'" % self.myId
		ret = self.db.update(TB_ACCOUNT, userObj, cond=cond)
		if (ret == -1):
			WARNING("update user %s error for db operation" % self.name)
			return DB_ERR
Beispiel #7
0
def getPricingResult(db, myId):
    cond = "WHERE ID='%s'" % (myId)

    dbObj = db.fetchone(TB_QUERYRESULT, cond=cond)
    if (not dbObj):
        WARNING("product %s not exist" % cond)
        return None

    obj = PricingResult(db, dbObj=dbObj)
    obj.loadFromObj()

    return obj
Beispiel #8
0
def getAgent(db, agentId):
    cond = "WHERE ID='%s'" % (agentId)

    dbObj = db.fetchone(TB_AGENT, cond=cond)
    if (not dbObj):
        WARNING("agent %s not exist" % cond)
        return None

    agent = Agent(db, dbObj=dbObj)
    agent.loadFromObj()

    return agent
Beispiel #9
0
def getSoftProduct(db, key):
    cond = "WHERE P_Type='%s' AND P_Info LIKE '%%%s%%'" % (
        PRODUCT_TYPE_SOFTWARE, key)
    dbObj = db.fetchone(TB_PRODUCT, cond=cond)
    if (not dbObj):
        WARNING("product %s not exist" % cond)
        return None

    obj = Product(db, dbObj=dbObj)
    obj.loadFromObj()

    return obj
Beispiel #10
0
    def delete(self):

        cond = "WHERE ID='%s'" % self.myId

        DEBUG("to delete session %s" % (self.myId))

        ret = self.db.delete(TB_SESSION, cond=cond)
        if ret == -1:
            WARNING("delete session %s error for db operation" % self.myId)
            return DB_ERR

        return 0
Beispiel #11
0
    def updateLogin(self):

        robotObj = {
            "R_LastLogin": get_current_time(),
            "R_UId": self.uId,
        }

        cond = "WHERE ID='%s'" % self.myId
        ret = self.db.update(TB_ROBOT, robotObj, cond=cond)
        if (ret == -1):
            WARNING("update robot %s error for db operation" % self.name)
            return DB_ERR
Beispiel #12
0
def getQuota(db, myId):

	cond = "WHERE ID='%s'" % (myId)

	dbObj = db.fetchone(TB_QUOTA, cond=cond)
	if (not dbObj):
		WARNING("quota %s not exist" % cond)
		return None

	item = Quota(db, dbObj=dbObj)
	item.loadFromObj()

	return item
Beispiel #13
0
    def update(self):

        obj = {
            "S_ExpireTime": get_current_time() + SESSION_EXPIRE_TIME,
        }

        cond = "WHERE ID='%s'" % self.myId
        ret = self.db.update(TB_SESSION, obj, cond=cond)
        if ret == -1:
            WARNING("update session %s error for db operation" % self.myId)
            return DB_ERR

        return 0
Beispiel #14
0
	def bindUkey(self):
		
		userObj = {
			"U_Ukey": self.ukey,
			"U_LastSync": get_current_time(),
		}
		
		cond = "WHERE ID='%s'" % self.myId
		ret = self.db.update(TB_ACCOUNT, userObj, cond=cond)
		if (ret == -1):
			WARNING("update user %s error for db operation" % self.name)
			return DB_ERR
		
		return 0
Beispiel #15
0
    def add(self):
        dbObj = {
            "M_Type": self.type,
            "M_AgentId": self.agentId,
            "M_Msg": self.msg,
            "M_Time": get_current_time()
        }

        ret = self.db.insert(TB_MSG, dbObj)
        if (ret == -1):
            WARNING("add msg error for db operation")
            return DB_ERR

        return OCT_SUCCESS
Beispiel #16
0
    def updateState(self):

        robotObj = {
            "R_State": self.state,
            "R_LastSync": get_current_time(),
        }

        cond = "WHERE ID='%s'" % self.myId
        ret = self.db.update(TB_ROBOT, robotObj, cond=cond)
        if (ret == -1):
            WARNING("update robot %s error for db operation" % self.name)
            return DB_ERR

        return 0
Beispiel #17
0
    def update(self):

        userObj = {
            "U_Email": self.email,
            "U_PhoneNumber": self.phone,
            "U_LastSync": get_current_time(),
        }

        cond = "WHERE ID='%s'" % self.myId
        ret = self.db.update(TB_ACCOUNT, userObj, cond=cond)
        if (ret == -1):
            WARNING("update user %s error for db operation" % self.name)
            return DB_ERR

        return 0
Beispiel #18
0
def getProduct(db, myId):
    if not myId:
        return None

    cond = "WHERE ID='%s'" % (myId)

    dbObj = db.fetchone(TB_PRODUCT, cond=cond)
    if (not dbObj):
        WARNING("product %s not exist" % cond)
        return None

    obj = Product(db, dbObj=dbObj)
    obj.loadFromObj()

    return obj
Beispiel #19
0
    def updatePrice(self):

        userObj = {
            "P_Info": transToStr(self.infoObj),
            "P_LastSync": get_current_time(),
            "P_Description": self.desc
        }

        cond = "WHERE ID='%s'" % self.myId
        ret = self.db.update(TB_PRODUCT, userObj, cond=cond)
        if (ret == -1):
            WARNING("update user %s error for db operation" % self.name)
            return DB_ERR

        return 0
Beispiel #20
0
def getApi(db, apiId=None, apiName=None, submoduleId=None):
    if (not apiId):
        return None

    cond = "WHERE ID='%s'" % (apiId)

    dbObj = db.fetchone(TB_APITRACE, cond=cond)
    if (not dbObj):
        WARNING("module %s not exist" % cond)
        return None

    api = Api(db, dbObj=dbObj)
    api.loadFromObj()

    return api
Beispiel #21
0
	def update(self):

		userObj = {
			"Q_Robots": self.robots,
			"Q_Message": self.messageCapacity,
			"Q_Group": self.group,
			"Q_LastSync": get_current_time(),
		}

		cond = "WHERE ID='%s'" % self.myId
		ret = self.db.update(TB_QUOTA, userObj, cond=cond)
		if (ret == -1):
			WARNING("update user %s error for db operation" % self.myId)
			return DB_ERR

		return 0
Beispiel #22
0
    def updateReply(self):

        obj = {
            "AT_Reply": transToStr(self.reply),
            "AT_State": API_STATE_FINISHED,
            "AT_FinishTime": get_current_time()
        }

        cond = "WHERE ID='%s'" % self.myId
        ret = self.db.update(TB_APITRACE, obj, cond=cond)
        if ret == -1:
            WARNING("update api request %s error for db operation" %
                    self.apiId)
            return DB_ERR

        return 0
Beispiel #23
0
	def resetPassword(self, newPassword):
		if (not newPassword):
			ERROR("new password not specified when doing password reset operation")
			return NOT_ENOUGH_PARAS
		
		userObj = {
			"U_Password": getEncPass(newPassword),
			"U_LastSync": get_current_time(),
		}
		
		cond = "WHERE ID='%s'" % self.myId
		ret = self.db.update(TB_ACCOUNT, userObj, cond=cond)
		if (ret == -1):
			WARNING("update user %s error for db operation" % self.name)
			return DB_ERR
		
		return OCT_SUCCESS
Beispiel #24
0
def getUser(db, userId=None, userName=None):
    if (not userId and not userName):
        return None

    if (userId):
        cond = "WHERE ID='%s'" % (userId)
    else:
        cond = "WHERE U_Name='%s'" % (userName)

    dbObj = db.fetchone(TB_ACCOUNT, cond=cond)
    if (not dbObj):
        WARNING("user %s not exist" % cond)
        return None

    user = Account(db, dbObj=dbObj)
    user.loadFromObj()

    return user
Beispiel #25
0
	def add(self):

		userObj = {
			"ID": getUuid(),
			"Q_Robots": self.robots,
			"Q_Message": self.messageCapacity,
			"Q_Group": self.group,
			"Q_LastSync": get_current_time(),
			"Q_CreateTime": get_current_time()
		}

		ret = self.db.insert(TB_QUOTA, userObj)
		if (ret == -1):
			WARNING("add user %s error for db operation" % self.myId)
			return DB_ERR

		DEBUG(userObj)

		return OCT_SUCCESS
Beispiel #26
0
def getRobot_byCond(db, robotId=None, robotName=None):

    if (not robotId and not robotName):
        return None

    if (robotId):
        cond = "WHERE ID='%s'" % (robotId)
    else:
        cond = "WHERE R_Name='%s'" % (robotName)

    dbObj = db.fetchone(TB_ROBOT, cond=cond)
    if (not dbObj):
        WARNING("robot %s not exist" % cond)
        return None

    robot = WCRobot(db, dbObj=dbObj)
    robot.loadFromObj()

    return robot
Beispiel #27
0
    def add(self):

        robotObj = {
            "ID": getUuid(),
            "R_UId": self.uId,
            "R_AccountId": self.accountId,
            "R_Name": self.name,
            "R_CreateTime": get_current_time(),
            "R_LastSync": get_current_time(),
        }

        ret = self.db.insert(TB_ROBOT, robotObj)
        if (ret == -1):
            WARNING("add robot %s error for db operation" % self.name)
            return DB_ERR

        DEBUG(robotObj)

        return OCT_SUCCESS
Beispiel #28
0
    def add(self):

        userObj = {
            "ID": getUuid(),
            "U_Name": self.name,
            "U_Password": getEncPass(self.password),
            "U_Email": self.email,
            "U_PhoneNumber": self.phone,
            "U_CreateTime": get_current_time(),
            "U_LastSync": get_current_time(),
        }

        ret = self.db.insert(TB_ACCOUNT, userObj)
        if (ret == -1):
            WARNING("add user %s error for db operation" % self.name)
            return DB_ERR

        DEBUG(userObj)

        return OCT_SUCCESS
Beispiel #29
0
    def add(self):
        if not self.myId:
            self.myId = getUuid()

        dbObj = {
            "ID": self.myId,
            "A_Name": self.name,
            "A_Address": self.address,
            "A_CreateTime": get_current_time(),
            "A_LastSync": get_current_time(),
        }

        ret = self.db.insert(TB_AGENT, dbObj)
        if (ret == -1):
            WARNING("add agent %s error for db operation" % self.name)
            return DB_ERR

        DEBUG(dbObj)

        return OCT_SUCCESS
Beispiel #30
0
    def logout(self):

        if self.state == ROBOT_STATE_OFFLINE:
            WARNING("robot %s already logout" % self.myId)
            return OCT_SUCCESS, None

        DEBUG(SystemConf.robots)

        if self.state == ROBOT_STATE_WAITINGSCAN or self.state == ROBOT_STATE_ONLINE:
            rob = SystemConf.robots.get(self.myId)
            if not rob:
                ERROR("rob thread %s not running" % self.myId)
            else:
                DEBUG("rob %s is gone to stop" % self.myId)
                rob.running_state = False
                del SystemConf.robots[self.myId]

        self.state = ROBOT_STATE_OFFLINE
        self.updateState()

        return OCT_SUCCESS, None