예제 #1
0
파일: memTable.py 프로젝트: houht/mypaas
 def reloadAppInstanceInfo(self, db):
     """
     @summary: 重载应用实例信息到内存
     """
     instanceInfoModule = InstanceInfoModule(db)
     ResourceStat.instanceInfoList = instanceInfoModule.getEffectiveInstanceList(
     )
예제 #2
0
파일: taskProcess.py 프로젝트: houht/mypaas
    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')
예제 #3
0
파일: appControl.py 프로젝트: houht/mypaas
    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')
예제 #4
0
파일: appControl.py 프로젝트: houht/mypaas
    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')
예제 #5
0
파일: taskProcess.py 프로젝트: houht/mypaas
    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')
예제 #6
0
파일: appControl.py 프로젝트: houht/mypaas
    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))
예제 #7
0
파일: appDrop.py 프로젝트: houht/mypaas
 def appDrop_error(self, json_msg):
     ""
     
     
     #写任务执行结果
     #部署失败,taskStatus=10等待部署,dealwith=open
     #写应用实例信息
     self.logger.debug('appDrop_error: received deploy error message')
     jsonParser = JsonParser()
     
     dealwithId = json_msg['taskId']
     instanceId = json_msg['content']['instanceId']
     
     self.logger.debug('appDrop_error: dealwithId=%s,instanceId=%s'%(dealwithId,instanceId))
     
     
     #获取数据操作对象
     db = self.__getDb()
     
     #读取任务处理表(DealwithInfoModule)
     self.logger.debug('appDrop_error: read dealwithinfo by dealwithid')
     dealwithInfoModule = DealwithInfoModule(db)
     dealwithInfo = dealwithInfoModule.getById(dealwithId)
     taskId = dealwithInfo['taskId']
     
     #读取任务信息表(TaskinfoModule)
     self.logger.debug('appDrop_error: read task info')
     taskinfoModule = TaskinfoModule(db)
     taskinfo = taskinfoModule.getById(taskId)
     businessId = taskinfo['businessId']
     
     
     #写任务处理表(DealwithInfoModule) 接收到的消息
     self.logger.debug('appDrop_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('appDrop_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)
     
     
     #修改应用实例表(InstanceInfoModule)
     self.logger.debug('appDrop_error: update instanceinfo ')
     iim_param = {}
     iim_param['instanceId'] = businessId
     iim_param['status'] = 'dropFail' 
     instanceInfoModule = InstanceInfoModule(db)
     instanceInfoModule.update(iim_param)
     
     
     #修改应用表(AppInfoModule)
     self.logger.debug('appDrop_error: update appinfo status')
     # 获取appid
     instanceInfo = instanceInfoModule.getById(businessId)
     appId = instanceInfo['app_id']
     iim_param = {}
     iim_param['appId'] = appId
     iim_param['status'] = 'dropFail'
     AppInfoModule = AppInfoModule(db)
     AppInfoModule.update(iim_param)
     
     db.close()
     self.logger.debug('appDrop_error: drop app process was over')
예제 #8
0
파일: appDrop.py 프로젝트: houht/mypaas
 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))
예제 #9
0
파일: appDrop.py 프로젝트: houht/mypaas
 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')
예제 #10
0
파일: appDeploy.py 프로젝트: houht/mypaas
    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))
예제 #11
0
파일: appDeploy.py 프로젝트: houht/mypaas
    def appDeploy_error(self, json_msg):
        """
        @summary: 任务执行结果
        @param:taskinfo 任务内容
        """
        #写任务执行结果
        #部署失败,taskStatus=10等待部署,dealwith=open
        #写应用实例信息
        self.logger.debug('appDeploy_error: received deploy error message')
        jsonParser = JsonParser()

        dealwithId = json_msg['taskId']
        serviceId = json_msg['content']['serviceId']
        instanceId = json_msg['content']['instanceId']
        self.logger.debug(
            'appDeploy_error: dealwithId=%s,serviceId=%s,instanceId=%s' %
            (dealwithId, serviceId, instanceId))

        #获取数据操作对象
        db = self.__getDb()

        #读取任务处理表(DealwithInfoModule)
        self.logger.debug('appDeploy_error: read dealwithinfo by dealwithid')
        dealwithInfoModule = DealwithInfoModule(db)
        dealwithInfo = dealwithInfoModule.getById(dealwithId)
        taskId = dealwithInfo['taskId']

        #写任务处理表(DealwithInfoModule) 接收到的消息
        self.logger.debug(
            'appDeploy_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('appDeploy_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('appDeploy_error: task status=%s, is not 40' %
                                taskStatus)
            return
        #读取部署询问广播次数20
        self.logger.debug('appDeploy_error: read ask times')
        dealwithInfoList = dealwithInfoModule.getById(dealwithId, '20')
        if len(dealwithInfoList) > 4:
            #写失败
            #读取任务信息表(TaskinfoModule)
            self.logger.debug(
                'appDeploy_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(
                'appDeploy_error: update instanceinfo status=failed,businessid=%s'
                % businessId)
            'status=failed'
            iim_param = {}
            iim_param['instanceId'] = businessId
            iim_param['status'] = 'failed'
            instanceInfoModule = InstanceInfoModule(db)
            instanceInfoModule.update(iim_param)
        else:
            #将任务表 继续部署taskStatus=10,dealwith=open
            #读取任务信息表(TaskinfoModule)
            self.logger.debug(
                'appDeploy_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('appDeploy_error: deploy error process was over')
예제 #12
0
파일: appDeploy.py 프로젝트: houht/mypaas
    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')
예제 #13
0
파일: appDeploy.py 프로젝트: houht/mypaas
    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))