コード例 #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
コード例 #2
0
ファイル: CENTER.py プロジェクト: maqg/wcrobot
    def post(self):

        self.db = dbmysql.mysqldb()

        if isSystemWindows():
            filePath = "var/tmp/" + getUuid()
        else:
            filePath = "/tmp/" + getUuid()

        # get the request file to cache path
        try:
            file_metas = self.request.files['file']
        except:
            file_metas = self.request.files['filename']

        for meta in file_metas:
            with open(filePath, 'wb') as up:
                up.write(meta['body'])

        argObj = appendBaseArg({}, self.request)
        argObj["paras"]["role"] = 7
        argObj["paras"]["accountId"] = DEFAULT_ACCOUNT_ID

        api_key = self.get_argument("api", None)
        if (not api_key):
            self.write(
                buildFailureReply(UNACCP_PARAS, errorMsg="api key error"))
            self.finish()
            return

        argObj["paras"]["filePath"] = filePath
        argObj["api"] = UPLOAD_API_MAP.get(api_key)
        if (not argObj["api"]):
            self.write(buildFailureReply(UNACCP_PARAS, errorMsg=api_key))
            self.finish()
            return

        session = getSession(self.db,
                             sessionId="00000000000000000000000000000000")

        argObj["session"] = session
        retObj = doDispatching(argObj, session, API_PROTOS)
        self.write(buildReply(retObj))
        self.finish()
コード例 #3
0
ファイル: TUNDRA.py プロジェクト: maqg/tundra
    def post(self):

        try:
            file_metas = self.request.files["file"]
        except:
            file_metas = self.request.files["filename"]

        fileName = file_metas[0].get("filename") or "unknown"
        if isSystemWindows():
            filePath = "var/tmp/" + fileName + ".XXXX" + getUuid()
        else:
            filePath = "/tmp/" + fileName + ".XXXX" + getUuid()

        for meta in file_metas:
            with open(filePath, 'wb') as up:
                up.write(meta['body'])

        retObj = buildRetObj(OCT_SUCCESS, data=filePath)
        self.write(buildReply(retObj))
        self.finish()
コード例 #4
0
def newSession(db, userObj):

    session = Session(db, getUuid())
    session.username = userObj["name"]
    session.cookie = {
        "id": userObj["id"],
        "name": userObj["name"],
        "role": userObj["role"]
    }
    session.role = userObj["role"]
    session.username = userObj["name"]
    session.userId = userObj["id"]

    session.add()

    return session.toObj()
コード例 #5
0
ファイル: Quota.py プロジェクト: maqg/wcrobot
	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
コード例 #6
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
コード例 #7
0
ファイル: initData.py プロジェクト: maqg/quantum
def createSql(productType, obj):

    header = "INSERT INTO tb_product (ID, P_Name, P_Type, P_TypeName, P_Info, "
    header += "P_Description, P_LastSync, P_CreateTime) VALUES ("

    typeName = obj["name"]
    products = obj["products"]

    for product in products:
        sql = "'%s'" % getUuid()
        sql += ",'%s'" % product["name"]
        sql += ",'%s'" % productType
        sql += ",'%s'" % typeName
        sql += ",'%s'" % transToStr(product)
        sql += ",'%s'" % product.get("desc") or ""
        sql += ",'%ld'" % now
        sql += ",'%ld'" % now

        print(header + sql + ");")
コード例 #8
0
ファイル: Account.py プロジェクト: maqg/wcrobot
    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
コード例 #9
0
ファイル: Agent.py プロジェクト: maqg/quantum
    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
コード例 #10
0
ファイル: Session.py プロジェクト: maqg/wcrobot
    def add(self):

        self.myId = getUuid()
        self.createTime = get_current_time()
        self.expireTime = get_current_time() + SESSION_EXPIRE_TIME

        obj = {
            "ID": self.myId,
            "S_UserId": self.userId,
            "S_UserName": self.username,
            "S_UserType": self.role,
            "S_Cookie": transToStr(self.cookie),
            "S_CreateTime": self.createTime,
            "S_ExpireTime": self.expireTime,
        }

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

        return OCT_SUCCESS
コード例 #11
0
ファイル: Product.py プロジェクト: maqg/tundra
    def add(self):

        self.myId = getUuid()

        obj = {
            "ID": self.myId,
            "P_Name": self.name,
            "P_Type": self.type,
            "P_TypeName": PRODUCT_TYPES[self.type],
            "P_Description": self.desc,
            "P_Info": transToStr(self.infoObj),
            "P_CreateTime": get_current_time(),
            "P_LastSync": get_current_time()
        }

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

        DEBUG(obj)

        return OCT_SUCCESS
コード例 #12
0
ファイル: PricingResult.py プロジェクト: maqg/tundra
    def add(self):

        self.myId = getUuid()

        obj = {
            "ID": self.myId,
            "QR_Name": self.name,
            "QR_Type": self.type,
            "QR_Price": self.price,
            "QR_Points": self.points,
            "QR_Info": transToStr(self.info),
            "QR_Paras": transToStr(self.paras),
            "QR_CreateTime": get_current_time(),
            "QR_Description": self.desc,
        }

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

        DEBUG(obj)

        return OCT_SUCCESS
コード例 #13
0
ファイル: AGENT.py プロジェクト: maqg/quantum
def sendMsg():
    DEBUG("### Send msg thread start...")

    if not os.path.exists(CONFIG_FILE_PATH):
        ERROR("agent config file not exist")
        return

    obj = fileToObj(CONFIG_FILE_PATH)

    serverIp = obj.get("serverIp")
    if not serverIp:
        ERROR("can't find server ip in config file")
        return

    agentId = obj.get("agentId")
    if not agentId:
        agentId = getUuid()
        obj["agentId"] = agentId

        fd = open(CONFIG_FILE_PATH, "w")
        fd.write(transToStr(obj, indent=4))
        fd.close()

    while True:

        if lock.acquire():
            for func in funcList:
                msg_type = func["type"]

                if len(msg[msg_type]) < 1:
                    continue

                now = get_current_time()
                if (now - func["lastSend"]) > func["SendInterval"] * 1000:
                    func["lastSend"] = now

                    api = "octlink.quantum.v1.sync.APISyncMsg"
                    paras = {
                        "agentId": agentId,
                        "type": msg_type,
                        "data": transToStr(msg[msg_type][-1]),
                        "timeout": 0
                    }
                    session_uuid = "00000000000000000000000000000000"

                    (retCode, retObj) = api_call(serverIp,
                                                 "9999",
                                                 api,
                                                 paras,
                                                 session_key=session_uuid,
                                                 async=False,
                                                 https=False)
                    if (retCode):
                        ERROR("connect to server error")
                        continue

                    DEBUG("send msg OK!")

            lock.release()

        sleep(60)