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 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 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 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 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 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 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 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_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 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')