def vmDestroyOk(self, json_msg): """ @summary: 任务执行结果 @param:json_msg 消息内容 """ #写任务执行结果 #关闭成功,taskStatus=50,dealwith=close #写应用实例信息 self.logger.debug('vmDestroyOk: received close ok from mq') jsonParser = JsonParser() dealwithId = json_msg['taskId'] #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('vmDestroyOk: read dealwithinfo') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] # 读取task表 taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] #写任务处理表(DealwithInfoModule) 接收到的信息 self.logger.debug('vmDestroyOk: write received deploy message') 'dealwithId,taskId,dealwithType,message,status' dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '50' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' dealwithInfoModule.insert(dim_param) #修改任务信息表(TaskinfoModule) self.logger.debug( 'vmDestroyOk: update taskinfo status taskStatus=50,dealwith=close') 'taskStatus=50,dealwith=close' tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '50' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改vm表(VmInfoModule) self.logger.debug('vmDestroyOk: update instanceinfo ') iim_param = {} iim_param['vmId'] = businessId iim_param['status'] = 'stoped' vminfo = VminfoModule(db) vminfo.update(iim_param) db.close() self.logger.debug('vmDestroyOk: close was over')
def ReduceInstance(self, instanceId): "" self.logger.debug('ReduceInstance: begin') # 1 更改instance状态 iim_param = {} iim_param['instanceId'] = instanceId iim_param['status'] = 'droping' instanceInfoModule = InstanceInfoModule(db) instanceInfoModule.update(iim_param) # 2 新建任务 tim_param = {} tim_param['taskId'] = UUIDUtils.getId() tim_param['taskType'] = 'appDrop' tim_param['dealwith'] = 'open' tim_param['taskStatus'] = '10' info = {} info['instanceId'] = instanceId tim_param['content'] = str(self.js.encode(info)) tim_param['businessId'] = instanceId taskinfoModule = TaskinfoModule(db) res = taskinfoModule.insert(tim_param) self.logger.debug('ReduceInstance: end')
def IncreaseInstance(self, appId): "" self.logger.debug('IncreaseInstance: begin') # 获取数据对象 db = self.__getDb() jsonParser = JsonParser() # 1 查询app信息 appInfoModule = AppInfoModule(db) appInfo = appInfoModule.getById(appId) # 准备参数 command = {} command['domain'] = appInfo['domain'] command['cpu'] = appInfo['cpu'] command['mem'] = appInfo['mem'] command['disk'] = appInfo['disk'] command['serviceId'] = appInfo['serviceId'] command['domain'] = appInfo['domain'] command['appName'] = appInfo['appName'] command['appFileId'] = appInfo['appFileId'] command['appEnv'] = appInfo['appEnv'] command['userEnv'] = appInfo['userEnv'] # 2 新建instance instanceId = UUIDUtils.getId() iim_param = {} iim_param['instanceId'] = instanceId iim_param['appId'] = appId iim_param['status'] = 'deploy' instanceInfoModule = InstanceInfoModule(db) instanceInfoModule.insert(iim_param) # 3 新建任务 tim_param = {} tim_param['taskId'] = UUIDUtils.getId() tim_param['taskType'] = 'appDeploy' tim_param['dealwith'] = 'open' tim_param['taskStatus'] = '10' tim_param['content'] = str(jsonParser.encode(command)) tim_param['businessId'] = instanceId taskinfoModule = TaskinfoModule(db) res = taskinfoModule.insert(tim_param) self.logger.debug('IncreaseInstance: end')
def vmDrop_error(self, json_msg): "" #写任务执行结果 #部署失败,taskStatus=10等待部署,dealwith=open #写应用实例信息 self.logger.debug('vmDrop_error: received deploy error message') jsonParser = JsonParser() dealwithId = json_msg['taskId'] self.logger.debug('vmDrop_error: dealwithId=%s' % (dealwithId)) #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('vmDrop_error: read dealwithinfo by dealwithid') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] #读取任务信息表(TaskinfoModule) self.logger.debug('vmDrop_error: read task info') taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] #写任务处理表(DealwithInfoModule) 接收到的消息 self.logger.debug( 'vmDrop_error: received message to dealwithinfo table') dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '91' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' #修改任务信息表(TaskinfoModule) self.logger.debug( 'vmDrop_error: update taskinfo status taskStatus=90,dealwith=close' ) tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '91' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改应用实例表(VmInfo) iim_param = {} iim_param['vmId'] = businessId iim_param['status'] = 'dropFail' vminfo = VminfoModule(db) vminfo.update(iim_param) db.close() self.logger.debug('vmDrop_error: drop vm process was over')
def processVmRunStat(self): """ @summary: 虚拟机和应用资源使用监控信息入库 """ nowTime = time.localtime(time.time()) now = time.strftime('%Y-%m-%d %H:%M:%S', nowTime) cur_tableTime = time.strftime('%Y%m', nowTime) #获取数据操作对象 db = self.__getDb() if MonitorDbAction.tableTime != cur_tableTime: self.createTable(db, cur_tableTime) MonitorDbAction.tableTime = cur_tableTime vmRunInfos = self.vmUseStat.cleanAllVmRunInfo( keepTime=self.monitor_keep_max_time) vm_running_param = [] appinstance_running_param = [] for info in vmRunInfos: keys = info.keys() logId = UUIDUtils.getId() vmName = info['vmName'] status = info['vmState'] cpuRate = float(0) memRate = float(0) flow = long(0) eventTime = info['eventTime'] receiveTime = info['receiveTime'] if 'cpuRate' in keys: cpuRate = float(info['cpuRate']) if 'memRate' in keys: memRate = float(info['memRate']) if 'flow' in keys: flow = long(info['flow']) if 'instanceId' in keys and info['instanceId'] is not None and len( info['instanceId']) > 0: #app 应用 监控 appinstance_running_param.append( (logId, info['instanceId'], status, cpuRate, memRate, flow, eventTime, receiveTime)) else: #vm 监控 vm_running_param.append( (logId, vmName, status, cpuRate, memRate, flow, eventTime, receiveTime)) try: if len(vm_running_param) != 0: sql = "insert into log_vm_running" + MonitorDbAction.tableTime + "(logId,vmName,status,cpuRate,memRate,flow,eventTime,receiveTime,createTime)values(%s,%s,%s,%s,%s,%s,%s,%s,now())" db.insertMany(sql, vm_running_param) except Exception, e: self.logger.error("insert vm running info to db was error,msg:" + str(e))
def appCloseError(self, json_msg): """ @summary: 任务执行结果 @param:json_msg 消息内容 """ #写任务执行结果 #启动失败,taskStatus=31,dealwith=close #写应用实例信息 self.logger.debug('appCloseError: received close error from mq') jsonParser = JsonParser() dealwithId = json_msg['taskId'] instanceId = json_msg['content']['instanceId'] #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('appCloseError: read dealwithinfo') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] #写任务处理表(DealwithInfoModule) 接收到的信息 self.logger.debug('appCloseError: write received start message') 'dealwithId,taskId,dealwithType,message,status' dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '51' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'failure' dealwithInfoModule.insert(dim_param) #修改任务信息表(TaskinfoModule) self.logger.debug( 'appCloseError: update taskinfo status taskStatus=51,dealwith=close' ) 'taskStatus=51,dealwith=close' tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '51' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改应用实例表(InstanceInfoModule) self.logger.debug('appCloseError: update instanceinfo ') 'status=closeFail' iim_param = {} iim_param['instanceId'] = instanceId iim_param['status'] = 'closeFail' instanceInfoModule = InstanceInfoModule(db) instanceInfoModule.update(iim_param) db.close() self.logger.debug('appCloseError: close was over')
def appStartOk(self, json_msg): """ @summary: 任务执行结果 @param:json_msg 消息内容 """ #写任务执行结果 #部署成功,taskStatus=90部署成功,dealwith=close #写应用实例信息 self.logger.debug('appStartOk: received start ok from mq') jsonParser = JsonParser() dealwithId = json_msg['taskId'] instanceId = json_msg['content']['instanceId'] #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('appStartOk: read dealwithinfo') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] #写任务处理表(DealwithInfoModule) 接收到的信息 self.logger.debug('appStartOk: write received deploy message') 'dealwithId,taskId,dealwithType,message,status' dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '30' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' dealwithInfoModule.insert(dim_param) #修改任务信息表(TaskinfoModule) self.logger.debug( 'appStartOk: update taskinfo status taskStatus=30,dealwith=close') 'taskStatus=30,dealwith=close' tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '30' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改应用实例表(InstanceInfoModule) self.logger.debug('appStartOk: update instanceinfo ') 'status=running' iim_param = {} iim_param['instanceId'] = instanceId iim_param['status'] = 'running' instanceInfoModule = InstanceInfoModule(db) instanceInfoModule.update(iim_param) db.close() self.logger.debug('appStartOk: start was over')
def vmProxyError(self, json_msg): """ @summary: 任务执行结果 @param:json_msg 消息内容 """ #写任务执行结果 #启动失败,taskStatus=31,dealwith=close #写应用实例信息 self.logger.debug('vmProxyError: received start error from mq') jsonParser = JsonParser() dealwithId = json_msg['taskId'] #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('vmProxyError: read dealwithinfo') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] # 读取task表 taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] #写任务处理表(DealwithInfoModule) 接收到的信息 self.logger.debug('vmProxyError: write received start message') dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '31' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'failure' dealwithInfoModule.insert(dim_param) #修改任务信息表(TaskinfoModule) self.logger.debug( 'vmProxyError: update taskinfo status taskStatus=31,dealwith=close' ) tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '31' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) db.close() self.logger.debug('vmProxyError: proxy was over')
def processVmRunStat(self): """ @summary: 虚拟机和应用资源使用监控信息入库 """ nowTime = time.localtime(time.time()) now = time.strftime('%Y-%m-%d %H:%M:%S', nowTime) cur_tableTime = time.strftime('%Y%m', nowTime) #获取数据操作对象 db = self.__getDb() if WarnDbAction.tableTime != cur_tableTime: self.createTable(db, cur_tableTime) WarnDbAction.tableTime = cur_tableTime vmWarnInfos = self.vmWarnStat.getAllVmWarnInfo() vm_warn_param = [] appinstance_warn_param = [] warnKeys = vmWarnInfos.keys() for key in warnKeys: info = None try: info = vmWarnInfos[key] except: pass if info is None or info['in2db'] == False: continue logId = UUIDUtils.getId() keys = info.keys() if 'instanceId' in keys and info['instanceId'] is not None and len( info['instanceId']) > 0: #app 应用 监控 appinstance_warn_param.append( (logId, info['instanceId'], info['warnType'], info['vmState'], info['cpuRate'], info['memRate'], info['flow'], info['eventTime'], info['receiveTime'], info['duration'], info['times'], info['maxDuration'])) else: #vm 监控 vm_warn_param.append( (logId, info['vmName'], info['warnType'], info['vmState'], info['cpuRate'], info['memRate'], info['flow'], info['eventTime'], info['receiveTime'], info['duration'], info['times'], info['maxDuration'])) try: if len(vm_warn_param) != 0: sql = "insert into log_vm_warning" + WarnDbAction.tableTime + "(logId,vmName,warnType,status,cpuRate,memRate,flow,eventTime,receiveTime,createTime,duration,times,maxDuration)values(%s,%s,%s,%s,%s,%s,%s,%s,%s,now(),%s,%s,%s)" db.insertMany(sql, vm_warn_param) except Exception, e: self.logger.error("insert vm warn info to db was error,msg:" + str(e))
def vmCreate_10(self, taskinfo): """ @summary: 待创建任务 @param:taskinfo 任务内容 """ #发送ask广播action=bdct.vm.deploy.ask #更改taskStatus=20等待资源,dealwith=close self.logger.debug('vmCreate_10: begin dealwith task') jsonParser = JsonParser() taskId = taskinfo['taskId'] content = taskinfo['content'] businessId = taskinfo['businessId'] contentObj = jsonParser.decode(content) cpu = contentObj['cpu'] mem = contentObj['mem'] disk = contentObj['size'] imageId = contentObj['imageId'] #获取数据操作对象 db = self.__getDb() router_key = 'bdct.vm.create.ask' action = 'vm.create.ask' dealwithId = UUIDUtils.getId() # 查询vm类型 vmImage = VmImageModule(db) ImageInfo = vmImage.getByImageId(imageId) vmType = ImageInfo['vtype'] #创建询问广播消息 message = {} message['action'] = action message['taskId'] = dealwithId message['content'] = {} message['content']['cpu'] = cpu message['content']['mem'] = mem message['content']['disk'] = disk message['content']['vmType'] = vmType message = jsonParser.encode(message) #写任务处理表库(DealwithInfoModule) self.logger.debug( 'vmCreate_10: write send ask message to dealwithInfo table') dim_param = {} dim_param['dealwithId'] = dealwithId dim_param['taskId'] = taskId dim_param['dealwithType'] = '20' dim_param['message'] = message dim_param['status'] = 'success' dealwithInfoModule = DealwithInfoModule(db) dealwithInfoModule.insert(dim_param) self.logger.debug('vmCreate_10: begin change task status') #开启事物 db.begin() try: #修改任务信息表(TaskinfoModule) self.logger.debug('vmCreate_10: update task status') tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '20' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #发送广播消息 self.logger.debug( 'vmCreate_10: send ask message to the bdct of mq') self.mq.send_bdct_message(router_key, message) db.end() self.logger.debug('vmCreate_10: process task is over') except Exception, e: db.end(option='rollback') self.logger.error( 'vmCreate_10: process task error, error message: ' + str(e))
def vmProxyOk(self, json_msg): """ @summary: 任务执行结果 @param:json_msg 消息内容 """ #写任务执行结果 #部署成功,taskStatus=90部署成功,dealwith=close #写应用实例信息 self.logger.debug('vmProxyOk: received start ok from mq') jsonParser = JsonParser() dealwithId = json_msg['taskId'] content = json_msg['content'] proxyIp = content['proxyIp'] proxyPort = content['proxyPort'] #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('vmProxyOk: read dealwithinfo') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] # 读取task表 taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] #写任务处理表(DealwithInfoModule) 接收到的信息 self.logger.debug('vmProxyOk: write received message') dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '30' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' dealwithInfoModule.insert(dim_param) #修改任务信息表(TaskinfoModule) self.logger.debug( 'vmProxyOk: update taskinfo status taskStatus=30,dealwith=close') tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '30' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改vmnet表 self.logger.debug('vmProxyOk: update vmnet ') tim_param = {} iim_param = {} iim_param['netId'] = businessId iim_param['proxyIP'] = proxyIp iim_param['proxyPort'] = proxyPort vmnet = VmnetModule(db) vmnet.update(iim_param) db.close() self.logger.debug('vmProxyOk: start was over')
def vmProxy(self, taskinfo): """ @summary: 任务执行结果 @param:json_msg 消息内容 """ self.logger.debug('vmProxy: begin dealwith task') jsonParser = JsonParser() taskId = taskinfo['taskId'] content = taskinfo['content'] businessId = taskinfo['businessId'] content = jsonParser.decode(content) #获取数据操作对象 db = self.__getDb() #读取应用实例信息表 dealwithInfoModule = DealwithInfoModule(db) # 类型 proxyType = content['type'] proxyPort = content['port'] # 查询vm信息 vmId = content['vmId'] vm = VminfoModule(db) vmInfo = vm.getById(vmId) if not vmInfo or not vmInfo['engineId']: #写任务信息表 self.logger.debug( 'vmProxy: update task status taskStatus=40 and dealwith=close') tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '31' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #写任务处理表(DealwithInfoModule) 启动申请 self.logger.debug('vmProxy: write message to dealwithinfo table') message = {} dealwithId = UUIDUtils.getId() message['action'] = 'network.portproxy.error' message['taskId'] = dealwithId message['content'] = {} message['instanceId'] = businessId message['errorCode'] = '2011' message['errorMessage'] = 'vm not exist.' message = jsonParser.encode(message) dim_param = {} dim_param['dealwithId'] = dealwithId dim_param['taskId'] = taskId dim_param['dealwithType'] = '31' dim_param['message'] = message dim_param['status'] = 'failure' dealwithInfoModule.insert(dim_param) return self.logger.debug('vmProxy: start send mq msg.') engineId = vmInfo['engineId'] vmName = vmInfo['vmName'] ip = vmInfo['ip'] router_key = engineId + ".network.portproxy.apply" action = ".network.portproxy.apply" dealwithId = UUIDUtils.getId() message = {} message['action'] = action message['taskId'] = dealwithId message['content'] = {} message['content']['vmName'] = vmName message['content']['type'] = proxyType message['content']['ip'] = ip message['content']['port'] = proxyPort message = jsonParser.encode(message) #写任务处理表(DealwithInfoModule) 启动申请消息 dim_param = {} dim_param['dealwithId'] = dealwithId dim_param['taskId'] = taskId dim_param['dealwithType'] = '20' dim_param['message'] = message dim_param['status'] = 'success' dealwithInfoModule.insert(dim_param) #开启事物 self.logger.debug('vmProxy: begin change the task status') db.begin() try: #更新任务信息表 状态 self.logger.debug( 'vmProxy: update task status taskStatus=20 and dealwith=close') tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '20' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #发送广播消息 self.logger.debug('vmProxy: send vm proxy request to task of mq') self.mq.send_task_message(router_key, message) db.end() self.logger.debug('vmProxy: send vm proxy request was over') except Exception, e: db.end(option='rollback') self.logger.debug( 'vmProxy: process status error, error message: ' + str(e))
def appDeploy_can(self, json_msg): """ @summary: 资源应答处理,向第一个应答的引擎下发部署任务 @param:taskinfo 任务内容 """ #发送部署任务 action=task_rst.app.deploy.can #更改taskStatus=30等待部署结果,dealwith=close #写应用实例信息 self.logger.debug('appDeploy_can: received deploy ask reply from mq') jsonParser = JsonParser() dealwithId = json_msg['taskId'] engineId = json_msg['content']['engineId'] self.logger.debug('appDeploy_can: reply engineId: ' + engineId + ",taskId: " + dealwithId) #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug( 'appDeploy_can: read task dealwithinfo by dealwithid: ' + dealwithId) dealwithInfoModule = DealwithInfoModule(db) self.logger.debug('appDeploy_can: ssss1111 ') dealwithInfo = dealwithInfoModule.getById(dealwithId) self.logger.debug('appDeploy_can: ssss22222 ') taskId = dealwithInfo['taskId'] self.logger.debug('appDeploy_can: ssss33333 ') #读取任务信息表(TaskinfoModule) self.logger.debug('appDeploy_can: read task info by taskId: ' + taskId) taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] content = taskinfo['content'] taskStatus = taskinfo['taskStatus'] if taskStatus != '20': '已经接收到资源应答,并且执行了部署' self.logger.debug( 'appDeploy_can: the task has access to resources: taskStatus:' + taskStatus) return #写任务处理表(DealwithInfoModule) 接收应答 self.logger.debug( 'appDeploy_can: write received ask reply message to dealwithinfo table' ) 'dealwithId,taskId,dealwithType,message,status' dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '30' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' dealwithInfoModule = DealwithInfoModule(db) dealwithInfoModule.insert(dim_param) #部署申请开始----------------------------- self.logger.debug('appDeploy_can: begin deploy the task to engine') contentObj = jsonParser.decode(content) #资源参数 cpu = contentObj['cpu'] mem = contentObj['mem'] disk = contentObj['disk'] serviceId = contentObj['serviceId'] #软件信息 domain = contentObj['domain'] appName = contentObj['appName'] appFileId = contentObj['appFileId'] #环境变量 contentKeys = contentObj.keys() appEnv = None userEnv = None if 'appEnv' in contentKeys: appEnv = contentObj['appEnv'] if 'userEnv' in contentKeys: userEnv = contentObj['userEnv'] #”listenPort” action = 'app.deploy.apply' router_key = engineId + ".app.deploy.apply" dealwithId = UUIDUtils.getId() #部署部署申请消息 message = {} message['action'] = action message['taskId'] = dealwithId message['content'] = {} message['content']['cpu'] = cpu message['content']['mem'] = mem message['content']['disk'] = disk message['content']['serviceId'] = serviceId message['content']['instanceId'] = businessId message['content']['domain'] = domain message['content']['appName'] = appName message['content']['filename'] = appFileId message['content']['param'] = {} if appEnv is not None: message['content']['env'] = appEnv if userEnv is not None: message['content']['userEnv'] = userEnv message = jsonParser.encode(message) #写任务处理表(DealwithInfoModule) 部署申请 self.logger.debug( 'appDeploy_can: write deploy message to dealwithinfo table') dim_param = {} dim_param['dealwithId'] = dealwithId dim_param['taskId'] = taskId dim_param['dealwithType'] = '40' dim_param['message'] = message dim_param['status'] = 'success' dealwithInfoModule.insert(dim_param) #开启事物 self.logger.debug('appDeploy_can: begin change the task status') db.begin() try: #修改任务信息表(TaskinfoModule) self.logger.debug( 'appDeploy_can: update task status taskStatus=40 and dealwith=close' ) 'taskStatus=40,dealwith=close' tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '40' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改应用实例表(InstanceInfoModule) self.logger.debug( 'appDeploy_can: update instanceinfo status engineId=%s' % engineId) 'engineId=$engineId' iim_param = {} iim_param['instanceId'] = businessId iim_param['engineId'] = engineId instanceInfoModule = InstanceInfoModule(db) instanceInfoModule.update(iim_param) #发送广播消息 self.logger.debug( 'appDeploy_can: send deploy request to task of mq') self.mq.send_task_message(router_key, message) db.end() self.logger.debug('appDeploy_can: send deploy request was over') except Exception, e: db.end(option='rollback') self.logger.debug( 'appDeploy_can: process status error, error message: ' + str(e))
def appDeploy_ok(self, json_msg): """ @summary: 任务执行结果 @param:taskinfo 任务内容 """ #写任务执行结果 #部署成功,taskStatus=90部署成功,dealwith=close #写应用实例信息 self.logger.debug('appDeploy_can: received deploy ok from mq') jsonParser = JsonParser() dealwithId = json_msg['taskId'] serviceId = json_msg['content']['serviceId'] instanceId = json_msg['content']['instanceId'] self.logger.debug( 'appDeploy_ok: received dealwithId: %s,serviceId: %s,instanceId: %s' % (dealwithId, serviceId, instanceId)) app_ip = None app_port = None content_keys = json_msg['content'].keys() if 'param' in content_keys: param = json_msg['content']['param'] param_keys = param.keys() if 'ip' in param_keys: app_ip = param['ip'] app_port = param['port'] #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('appDeploy_ok: read dealwithinfo') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] #读取任务信息表(TaskinfoModule) self.logger.debug('appDeploy_ok: read tas info') taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] content = taskinfo['content'] taskStatus = taskinfo['taskStatus'] #写任务处理表(DealwithInfoModule) 接收到的信息 self.logger.debug('appDeploy_ok: write received deploy message') 'dealwithId,taskId,dealwithType,message,status' dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '90' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' dealwithInfoModule = DealwithInfoModule(db) dealwithInfoModule.insert(dim_param) #修改任务信息表(TaskinfoModule) self.logger.debug( 'appDeploy_ok: update taskinfo status taskStatus=90,dealwith=close' ) 'taskStatus=90,dealwith=close' tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '90' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改应用实例表(InstanceInfoModule) self.logger.debug('appDeploy_ok: update instanceinfo ip=%s,port=%s' % (app_ip, app_port)) 'status=deployed' iim_param = {} iim_param['instanceId'] = businessId iim_param['status'] = 'deployed' if app_ip is not None: iim_param['ip'] = app_ip if app_port is not None: iim_param['port'] = app_port iim_param['beginTime'] = 'now' instanceInfoModule = InstanceInfoModule(db) instanceInfoModule.update(iim_param) db.close() self.logger.debug('appDeploy_ok: deploy was over')
def appDeploy_10(self, taskinfo): """ @summary: 待部署任务 @param:taskinfo 任务内容 """ #发送ask广播action=bdct.app.deploy.ask #更改taskStatus=20等待资源,dealwith=close self.logger.debug('appDeploy_10: begin dealwith task') jsonParser = JsonParser() taskId = taskinfo['taskId'] content = taskinfo['content'] businessId = taskinfo['businessId'] contentObj = jsonParser.decode(content) cpu = contentObj['cpu'] mem = contentObj['mem'] disk = contentObj['disk'] serviceId = contentObj['serviceId'] #获取数据操作对象 db = self.__getDb() router_key = 'bdct.app.deploy.ask' action = 'app.deploy.ask' dealwithId = UUIDUtils.getId() #部署询问广播消息 message = {} message['action'] = action message['taskId'] = dealwithId message['content'] = {} message['content']['cpu'] = cpu message['content']['mem'] = mem message['content']['disk'] = disk message['content']['serviceId'] = serviceId message = jsonParser.encode(message) #写任务处理表库(DealwithInfoModule) self.logger.debug( 'appDeploy_10: write send ask message to dealwithInfo table') 'dealwithId,taskId,dealwithType,message,status' dim_param = {} dim_param['dealwithId'] = dealwithId dim_param['taskId'] = taskId dim_param['dealwithType'] = '20' dim_param['message'] = message dim_param['status'] = 'success' print "1999" dealwithInfoModule = DealwithInfoModule(db) dealwithInfoModule.insert(dim_param) self.logger.debug('appDeploy_10: begin change task status') #开启事物 db.begin() try: #修改任务信息表(TaskinfoModule) self.logger.debug('appDeploy_10: update task status') 'taskStatus=20,dealwith=close' tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '20' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改应用实例表(InstanceInfoModule) self.logger.debug('appDeploy_10: update instance status') 'status=deploy' iim_param = {} iim_param['instanceId'] = businessId iim_param['status'] = 'deploy' instanceInfoModule = InstanceInfoModule(db) instanceInfoModule.update(iim_param) #发送广播消息 self.logger.debug( 'appDeploy_10: send ask message to the bdct of mq') self.mq.send_bdct_message(router_key, message) db.end() self.logger.debug('appDeploy_10: process task is over') except Exception, e: db.end(option='rollback') self.logger.error( 'appDeploy_10: process task error, error message: ' + str(e))
def vmCreate_can(self, json_msg): """ @summary: 资源应答处理,向第一个应答的引擎下发创建任务 @param:taskinfo 任务内容 """ #发送创建任务 action=task_rst.vm.deploy.can #更改taskStatus=30等待创建结果,dealwith=close #写应用实例信息 self.logger.debug('vmCreate_can: received vmcreate ask reply from mq') jsonParser = JsonParser() dealwithId = json_msg['taskId'] engineId = json_msg['content']['engineId'] engineIp = json_msg['content']['engineIp'] self.logger.debug('vmCreate_can: reply engineId: ' + engineId + ",taskId: " + dealwithId) #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug( 'vmCreate_can: read task dealwithinfo by dealwithid: ' + dealwithId) dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] #读取任务信息表(TaskinfoModule) self.logger.debug('vmCreate_can: read task info by taskId: ' + taskId) taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] content = taskinfo['content'] taskStatus = taskinfo['taskStatus'] if taskStatus != '20': '已经接收到资源应答,并且执行了创建' self.logger.debug( 'vmCreate_can: the task has access to resources: taskStatus:' + taskStatus) return #写任务处理表(DealwithInfoModule) 接收应答 self.logger.debug( 'vmCreate_can: write received ask reply message to dealwithinfo table' ) 'dealwithId,taskId,dealwithType,message,status' dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '30' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' dealwithInfoModule = DealwithInfoModule(db) dealwithInfoModule.insert(dim_param) #创建申请开始----------------------------- self.logger.debug('vmCreate_can: begin deploy the task to engine') contentObj = jsonParser.decode(content) #资源参数 vmName = contentObj['vmName'] cpu = contentObj['cpu'] mem = contentObj['mem'] disk = contentObj['size'] imageId = contentObj['imageId'] # 查询vm类型 vmImage = VmImageModule(db) ImageInfo = vmImage.getByImageId(imageId) vmType = ImageInfo['vtype'] action = 'vm.create.apply' router_key = engineId + ".vm.create.apply" dealwithId = UUIDUtils.getId() #创建创建申请消息 message = {} message['action'] = action message['taskId'] = dealwithId message['content'] = {} message['content']['vmName'] = vmName message['content']['cpu'] = cpu message['content']['mem'] = mem message['content']['disk'] = disk message['content']['vmType'] = vmType # 磁盘 if 'attachDisks' in contentObj: message['content']['attachDisks'] = contentObj['attachDisks'] # 主机名 if 'hostName' in contentObj: message['content']['hostName'] = contentObj['hostName'] message['content']['imageId'] = imageId message = jsonParser.encode(message) # 暂时没有 # host # attachDisks #写任务处理表(DealwithInfoModule) 创建申请 self.logger.debug( 'vmCreate_can: write deploy message to dealwithinfo table') dim_param = {} dim_param['dealwithId'] = dealwithId dim_param['taskId'] = taskId dim_param['dealwithType'] = '40' dim_param['message'] = message dim_param['status'] = 'success' dealwithInfoModule.insert(dim_param) #开启事物 self.logger.debug('vmCreate_can: begin change the task status') db.begin() try: #修改任务信息表(TaskinfoModule) self.logger.debug( 'vmCreate_can: update task status taskStatus=40 and dealwith=close' ) tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '40' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改应用实例表(InstanceInfoModule) self.logger.debug('vmCreate_can: update vminfo engineId=%s' % engineId) iim_param = {} iim_param['vmId'] = businessId iim_param['engineId'] = engineId iim_param['engineIp'] = engineIp #engineIp vminfo = VminfoModule(db) vminfo.update(iim_param) #发送广播消息 self.logger.debug( 'vmCreate_can: send deploy request to task of mq') self.mq.send_task_message(router_key, message) db.end() self.logger.debug('vmCreate_can: send deploy request was over') except Exception, e: db.end(option='rollback') self.logger.debug( 'vmCreate_can: process status error, error message: ' + str(e))
def vmCreate_error(self, json_msg): """ @summary: 任务执行结果 @param:taskinfo 任务内容 """ #写任务执行结果 #创建失败,taskStatus=10等待创建,dealwith=open #写应用实例信息 self.logger.debug('vmCreate_error: received deploy error message') jsonParser = JsonParser() dealwithId = json_msg['taskId'] self.logger.debug('vmCreate_error: dealwithId=%s' % dealwithId) #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('vmCreate_error: read dealwithinfo by dealwithid') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] #写任务处理表(DealwithInfoModule) 接收到的消息 self.logger.debug( 'vmCreate_error: received received message to dealwithinfo table') 'dealwithId,taskId,dealwithType,message,status' dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '91' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' #读取任务信息表(TaskinfoModule) self.logger.debug('vmCreate_error: read task info by taskid=%s' % taskId) taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] taskStatus = taskinfo['taskStatus'] if taskStatus != '40': self.logger.warning('vmCreate_error: task status=%s, is not 40' % taskStatus) return #读取创建询问广播次数20 self.logger.debug('vmCreate_error: read ask times') dealwithInfoList = dealwithInfoModule.getById(dealwithId, '20') if len(dealwithInfoList) > 4: #写失败 #读取任务信息表(TaskinfoModule) self.logger.debug( 'vmCreate_error: read ask times>4,write task process error') taskinfoModule = TaskinfoModule(db) tim_param = {} tim_param['taskStatus'] = '91' tim_param['dealwith'] = 'close' tim_param['taskId'] = taskId taskinfoModule.update(tim_param) #修改应用实例表(InstanceInfoModule) self.logger.debug( 'vmCreate_error: update vminfo status=failed,businessid=%s' % businessId) iim_param = {} iim_param['vmId'] = businessId iim_param['status'] = 'createFail' vminfo = VminfoModule(db) vminfo.update(iim_param) else: #将任务表 继续创建taskStatus=10,dealwith=open #读取任务信息表(TaskinfoModule) self.logger.debug( 'vmCreate_error: read ask times<=4,write task process to reprocess,taskStatus=10,dealwith=open,taskId=%s' % taskId) taskinfoModule = TaskinfoModule(db) tim_param = {} tim_param['taskStatus'] = '10' tim_param['dealwith'] = 'open' tim_param['taskId'] = taskId taskinfoModule.update(tim_param) db.close() self.logger.debug('vmCreate_error: error process was over')
def vmCreate_ok(self, json_msg): """ @summary: 任务执行结果 @param:taskinfo 任务内容 """ #写任务执行结果 #创建成功,taskStatus=90创建成功,dealwith=close #写应用实例信息 self.logger.debug('vmCreate_ok: received deploy ok from mq') jsonParser = JsonParser() # 返回参数 dealwithId = json_msg['taskId'] ip = json_msg['content']['ip'] vncPort = json_msg['content']['vncPort'] vncPasswd = json_msg['content']['vncPasswd'] self.logger.debug('vmCreate_ok: received dealwithId: %s ' % dealwithId) #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('vmCreate_ok: read dealwithinfo') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] #读取任务信息表(TaskinfoModule) self.logger.debug('vmCreate_ok: read tas info') taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] content = taskinfo['content'] taskStatus = taskinfo['taskStatus'] #写任务处理表(DealwithInfoModule) 接收到的信息 self.logger.debug('vmCreate_ok: write received deploy message') 'dealwithId,taskId,dealwithType,message,status' dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '90' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' dealwithInfoModule = DealwithInfoModule(db) dealwithInfoModule.insert(dim_param) #修改任务信息表(TaskinfoModule) self.logger.debug( 'vmCreate_ok: update taskinfo status taskStatus=90,dealwith=close') 'taskStatus=90,dealwith=close' tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '90' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改应用实例表(InstanceInfoModule) self.logger.debug('vmCreate_ok: update vminfo ') iim_param = {} iim_param['vmId'] = businessId iim_param['ip'] = ip iim_param['vncPort'] = vncPort iim_param['vncPasswd'] = vncPasswd iim_param['status'] = 'created' iim_param['beginTime'] = 'now' vminfo = VminfoModule(db) vminfo.update(iim_param) db.close() self.logger.debug('vmCreate_ok: deploy was over')
def appStart(self, taskinfo): """ @summary: 软件启动 @param:taskinfo 任务内容 """ self.logger.debug('appStart: begin dealwith task') jsonParser = JsonParser() taskId = taskinfo['taskId'] content = taskinfo['content'] businessId = taskinfo['businessId'] #获取数据操作对象 db = self.__getDb() #读取应用实例信息表 dealwithInfoModule = DealwithInfoModule(db) instanceInfoModule = InstanceInfoModule(db) instanceInfo = instanceInfoModule.getById(businessId) if not instanceInfo or not instanceInfo['engineId']: #写任务信息表 self.logger.debug( 'appDeploy_can: update task status taskStatus=40 and dealwith=close' ) 'taskStatus=40,dealwith=close' tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '31' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #写任务处理表(DealwithInfoModule) 启动申请 self.logger.debug( 'appDeploy_can: write deploy message to dealwithinfo table') message = {} dealwithId = UUIDUtils.getId() message['action'] = 'app.start.error' message['taskId'] = dealwithId message['content'] = {} message['instanceId'] = businessId message['errorCode'] = '2011' message['errorMessage'] = 'app instance not exist' message = jsonParser.encode(message) dim_param = {} dim_param['dealwithId'] = dealwithId dim_param['taskId'] = taskId dim_param['dealwithType'] = '31' dim_param['message'] = message dim_param['status'] = 'failure' dealwithInfoModule.insert(dim_param) return engineId = instanceInfo['engineId'] router_key = engineId + ".app.start.apply" action = ".app.start.apply" dealwithId = UUIDUtils.getId() message = {} message['action'] = action message['taskId'] = dealwithId message['content'] = {} message['content']['instanceId'] = businessId message = jsonParser.encode(message) #写任务处理表(DealwithInfoModule) 启动申请消息 dim_param = {} dim_param['dealwithId'] = dealwithId dim_param['taskId'] = taskId dim_param['dealwithType'] = '20' dim_param['message'] = message dim_param['status'] = 'success' dealwithInfoModule.insert(dim_param) #开启事物 self.logger.debug('appStart: begin change the task status') db.begin() try: #更新任务信息表 状态 self.logger.debug( 'appStart: update task status taskStatus=20 and dealwith=close' ) 'taskStatus=40,dealwith=close' tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '20' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #发送广播消息 self.logger.debug('appStart: send app start request to task of mq') self.mq.send_task_message(router_key, message) db.end() self.logger.debug('appStart: send app start request was over') except Exception, e: db.end(option='rollback') self.logger.debug( 'appStart: process status error, error message: ' + str(e))
def appDrop_ok(self, json_msg): "" #写任务执行结果 #部署成功,taskStatus=90部署成功,dealwith=close #写应用实例信息 self.logger.debug('appDrop_ok: received drop app ok from mq') jsonParser = JsonParser() dealwithId = json_msg['taskId'] instanceId = json_msg['content']['instanceId'] #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('appDrop_ok: read dealwithinfo') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] #读取任务信息表(TaskinfoModule) self.logger.debug('appDrop_ok: read task info') taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] #写任务处理表(DealwithInfoModule) 接收到的信息 self.logger.debug('appDrop_ok: write received drop app message') dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '90' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' dealwithInfoModule = DealwithInfoModule(db) dealwithInfoModule.insert(dim_param) #修改任务信息表(TaskinfoModule) self.logger.debug('appDrop_ok: update taskinfo status taskStatus=90,dealwith=close') tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '90' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改应用实例表(InstanceInfoModule) self.logger.debug('appDrop_ok: update instanceinfo ') iim_param = {} iim_param['instanceId'] = businessId iim_param['status'] = 'destroyed' instanceInfoModule = InstanceInfoModule(db) instanceInfoModule.update(iim_param) #修改应用表(AppInfoModule) self.logger.debug('appDrop_ok: update appinfo status') # 获取appid instanceInfo = instanceInfoModule.getById(businessId) appId = instanceInfo['appId'] iim_param = {} iim_param['appId'] = appId iim_param['status'] = 'destroyed' AppInfoModule = AppInfoModule(db) AppInfoModule.update(iim_param) db.close() self.logger.debug('appDrop_ok: drop app was over')
def appDrop_10(self, taskinfo): "" self.logger.debug('appDrop_10: begin drop app ') jsonParser = JsonParser() instanceId = taskinfo['businessId'] taskId = taskinfo['taskId'] #获取数据操作对象 db = self.__getDb() # 查询instance表 instanceInfoModule = InstanceInfoModule(db) instanceInfo = instanceInfoModule.getById(instanceId) # 获取engineid engineId = instanceInfo['engineId'] # 发现消息 action = 'app.drop.apply' router_key = engineId + ".app.drop.apply" dealwithId = UUIDUtils.getId() # 删除应用消息 message = {} message['action'] = action message['taskId'] = dealwithId message['content'] = {} message['content']['instanceId'] = instanceId message = jsonParser.encode(message) #写任务处理表库(DealwithInfoModule) self.logger.debug('appDrop_10: write drop message to dealwithInfo table') dim_param = {} dim_param['dealwithId'] = dealwithId dim_param['taskId'] = taskId dim_param['dealwithType'] = '20' dim_param['message'] = message dim_param['status'] = 'success' dealwithInfoModule = DealwithInfoModule(db) dealwithInfoModule.insert(dim_param) #开启事物 db.begin() try : #修改任务信息表(TaskinfoModule) self.logger.debug('appDrop_10: update task status') tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '20' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #发送消息 self.logger.debug('appDrop_10: send drop app request to task of mq') self.mq.send_task_message(router_key, message) db.end() self.logger.debug('appDrop_10: process task is over') except Exception,e: db.end(option='rollback') self.logger.error('appDrop_10: process task error, error message: '+str(e))
def vmDrop_ok(self, json_msg): "" #写任务执行结果 #部署成功,taskStatus=90部署成功,dealwith=close #写应用实例信息 self.logger.debug('vmDrop_ok: received drop vm ok from mq') jsonParser = JsonParser() dealwithId = json_msg['taskId'] #获取数据操作对象 db = self.__getDb() #读取任务处理表(DealwithInfoModule) self.logger.debug('vmDrop_ok: read dealwithinfo') dealwithInfoModule = DealwithInfoModule(db) dealwithInfo = dealwithInfoModule.getById(dealwithId) taskId = dealwithInfo['taskId'] #读取任务信息表(TaskinfoModule) self.logger.debug('vmDrop_ok: read task info') taskinfoModule = TaskinfoModule(db) taskinfo = taskinfoModule.getById(taskId) businessId = taskinfo['businessId'] #写任务处理表(DealwithInfoModule) 接收到的信息 self.logger.debug('vmDrop_ok: write received drop vm message') dim_param = {} dim_param['dealwithId'] = UUIDUtils.getId() dim_param['taskId'] = taskId dim_param['dealwithType'] = '90' dim_param['message'] = jsonParser.encode(json_msg) dim_param['status'] = 'success' dealwithInfoModule = DealwithInfoModule(db) dealwithInfoModule.insert(dim_param) #修改任务信息表(TaskinfoModule) self.logger.debug( 'vmDrop_ok: update taskinfo status taskStatus=90,dealwith=close') tim_param = {} tim_param['taskId'] = taskId tim_param['taskStatus'] = '90' tim_param['dealwith'] = 'close' taskinfoModule = TaskinfoModule(db) res = taskinfoModule.update(tim_param) #修改vm表(VmInfoModule) self.logger.debug('vmDrop_ok: update VmInfo ') iim_param = {} iim_param['vmId'] = businessId iim_param['status'] = 'destroyed' vminfo = VminfoModule(db) vminfo.update(iim_param) db.close() self.logger.debug('vmDrop_ok: drop vm was over')