Ejemplo n.º 1
0
    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')
Ejemplo n.º 2
0
    def process_action(self, message):
        ""
        self.logger.debug("received mq message")
        # 1 返回信息
        routing_key = message.delivery_info['routing_key']
        exchange = message.delivery_info['exchange']
        msg = message.body
        action = routing_key.split('.', 1)[1]
        self.logger.debug(action + ":" + msg)
        self.logger.info('action: %s ;message: %s' % (action, str(msg)))

        js = JsonParser()
        json_msg = js.decode(msg)

        # 2 json格式报错,日志记录
        if json_msg == -1:
            self.logger.error('josn format error!')
            return

        # 3业务处理
        try:
            self.bs.processMq(action, json_msg)
        except Exception, e:
            log = str(e)
            self.logger.error(log)
Ejemplo n.º 3
0
    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')
Ejemplo n.º 4
0
    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')
Ejemplo n.º 5
0
    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')
Ejemplo n.º 6
0
    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')
Ejemplo n.º 7
0
    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')
Ejemplo n.º 8
0
    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')
Ejemplo n.º 9
0
    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')
Ejemplo n.º 10
0
    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')
Ejemplo n.º 11
0
    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))
Ejemplo n.º 12
0
    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')
Ejemplo n.º 13
0
    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))
Ejemplo n.º 14
0
 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')
Ejemplo n.º 15
0
 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))
Ejemplo n.º 16
0
    def processVmRunStat(self) :
        """
        @summary: 虚拟机和应用资源使用监控信息入库
        """
        _time = time.time()
        nowTime = time.localtime(_time)
        now = time.strftime('%Y-%m-%d %H:%M:%S',nowTime)
        cur_tableTime = time.strftime('%Y%m',nowTime)
        #获取数据操作对象
        db = self.__getDb()
        self.logger.debug("this is running 1......")
        #重新载入
        if WarnAction.resourceLoadTime is None or _time - WarnAction.resourceLoadTime > self.warn_resource_keep_max_time :
            self.logger.debug("this is running 2......")
            self.resourceStat.reloadVmInfo(db)
            self.logger.debug("this is running 3......")
            self.resourceStat.reloadAppInstanceInfo(db)
            self.logger.debug("this is running 4......")
            WarnAction.resourceLoadTime = _time
            
            
        vmRunInfos = self.vmUseStat.getAllVmRunInfo()
        
        rule = '''{
                   "highWarn":{"cpu":90,"mem":90,"flow":8388608,"duration":3},
                   "lowWarn":{"cpu":10,"mem":40,"flow":8000,"duration":240},
                   "overtime":300
                }'''
        jp = JsonParser()
        rule = jp.decode(rule)
        self.logger.debug("warn info:"+str(self.vmWarnStat.getAllVmWarnInfo()))
        #appInstanceKeys = WarnAction.appInstance.keys()
        #vmInstanceKeys = WarnAction.vmInstance.keys()
        instanceIds = []
        vmNames = []
        
        load_effective_time = 1800
        for info in vmRunInfos :
            keys = info.keys()
            self.logger.debug("this is running 5......")
            vmName = info['vmName']
            status = info['vmState']
            self.logger.debug("this is running 6......")
            flag = 'normal'
            cpuRate = float(0)
            memRate = float(0)
            flow = long(0)
            
            instanceId = ''
            
            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'])
            
            vmInfo = None
            instanceInfo = None

            if 'instanceId' in keys and info['instanceId'] :
                instanceInfo = self.resourceStat.getInstanceInfo(info['instanceId'])
            else:
                vmInfo = self.resourceStat.getVmInfo(vmName)
                
            if vmInfo is None and instanceInfo is None:
                continue
                        
            #规则信息
            ruleKeys = rule.keys()
            hightFlag = False
            lowFlag = False
            hightDuration = 0
            lowDuration = 0
            
            if 'overtime' in ruleKeys:
                maxDuration = float(rule['overtime'])                
                overtime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(_time - maxDuration))
                #过期事件不处理
                if receiveTime < overtime :
                    continue
                    
            if 'lowWarn' in ruleKeys:
                lowWarn = rule['lowWarn']
                lowWarnKeys = lowWarn.keys()
                
                lowFlag = True
                if 'cpu' in lowWarnKeys:
                    if cpuRate >= float(lowWarn['cpu']):
                        lowFlag = False
                if 'mem' in lowWarnKeys:
                    if memRate >= float(lowWarn['mem']):
                        lowFlag = False
                if 'flow' in lowWarnKeys:
                    if flow >= long(lowWarn['flow']):
                        lowFlag = False
                if 'duration' in lowWarnKeys:
                    lowDuration = int(lowWarn['duration'])

            if 'highWarn' in ruleKeys:
                highWarn = rule['highWarn']
                highWarnKeys = highWarn.keys()
                hightFlag = True
                if 'cpu' in highWarnKeys:
                    if cpuRate < float(highWarn['cpu']):
                        hightFlag = False
                if 'mem' in highWarnKeys:
                    if memRate < float(highWarn['mem']):
                        hightFlag = False
                if 'flow' in highWarnKeys:
                    if flow < long(highWarn['flow']):
                        hightFlag = False
                if 'duration' in highWarnKeys:
                    hightDuration = int(highWarn['duration'])
                
            #根据运行状态,判断是否告警
            maxDuration = 0
            if "running" == status:
                if hightFlag:
                    flag = 'highWarn'
                    maxDuration = hightDuration
                if lowFlag:
                    flag = 'lowWarn'
                    maxDuration = lowDuration              
                
            elif "paused" == status:
                flag = 'paused'
                if instanceInfo is not None and instanceInfo['status'] != 'running':
                     flag = 'normal'
                elif vmInfo is not None and vmInfo['status'] != 'running':
                     flag = 'normal'
            elif "shutdown" == status:
                flag = 'shutdown'
                if instanceInfo is not None and instanceInfo['status'] != 'running':
                     flag = 'normal'
                elif vmInfo is not None and vmInfo['status'] != 'running':
                     flag = 'normal'
            elif "crashed" == status:
                flag = 'crashed'
            
            #处理过的应用实例和虚拟机
            if instanceInfo:
                instanceIds.append(instanceInfo['instanceId'])
            elif vmInfo:
                vmNames.append(vmInfo['vmName'])
                
                
            #告警处理
            if flag == 'normal':
                self.vmWarnStat.removeVmRunInfo('vmName')
                if instanceInfo:
                    #主要考虑warnType=overtime的应用,vmName设置的值为instanceId
                    self.vmWarnStat.removeVmRunInfo(instanceInfo['instanceId'])
            else :
                self.vmWarnStat.addVmRunInfo(info, flag, maxDuration) 
        self.logger.debug("this is running 7......")                         
        #没有监控信息的虚拟机告警
        vmInfoList = self.resourceStat.getAllVmInfoList()
        for info in vmInfoList:
            if info['vmName'] not in vmNames:
                ruleKeys = rule.keys()
                tmp = {}
                tmp['vmName'] = info['vmName']
                tmp['vmState'] = 'shutdown'
                tmp['eventTime'] = now
                tmp['receiveTime'] = now
                flag = 'overtime'
                maxDuration = -1
                if 'overtime' in ruleKeys:
                    maxDuration = float(rule['overtime'])
                
                self.vmWarnStat.addVmRunInfo(tmp, flag, maxDuration)
        self.logger.debug("this is running 8......")
        
        #没有监控信息的应用实例告警
        appInstanceInfoList = self.resourceStat.getAllAppInstanceInfoList()
        for info in appInstanceInfoList:
            if info['instanceId'] not in instanceIds:
                ruleKeys = rule.keys()
                tmp = {}
                tmp['instanceId'] = info['instanceId']
                tmp['vmName'] = info['instanceId']
                tmp['vmState'] = 'shutdown'
                tmp['eventTime'] = now
                tmp['receiveTime'] = now
                flag = 'overtime'
                maxDuration = -1
                if 'overtime' in ruleKeys:
                    maxDuration = float(rule['overtime'])
                self.vmWarnStat.addVmRunInfo(tmp, flag, maxDuration)
        self.logger.debug("this is running 9......")
Ejemplo n.º 17
0
    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))
Ejemplo n.º 18
0
    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')
Ejemplo n.º 19
0
    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))
Ejemplo n.º 20
0
    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))
Ejemplo n.º 21
0
    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))
Ejemplo n.º 22
0
                
                self.vmWarnStat.addVmRunInfo(tmp, flag, maxDuration)
        self.logger.debug("this is running 8......")
        
        #没有监控信息的应用实例告警
        appInstanceInfoList = self.resourceStat.getAllAppInstanceInfoList()
        for info in appInstanceInfoList:
            if info['instanceId'] not in instanceIds:
                ruleKeys = rule.keys()
                tmp = {}
                tmp['instanceId'] = info['instanceId']
                tmp['vmName'] = info['instanceId']
                tmp['vmState'] = 'shutdown'
                tmp['eventTime'] = now
                tmp['receiveTime'] = now
                flag = 'overtime'
                maxDuration = -1
                if 'overtime' in ruleKeys:
                    maxDuration = float(rule['overtime'])
                self.vmWarnStat.addVmRunInfo(tmp, flag, maxDuration)
        self.logger.debug("this is running 9......")
                
if __name__ == "__main__" :   
    rule = '''{
                   "highWarn":{"cpu":90,"mem":90,"flow":8388608,"duration":3},
                   "lowWarn":{"cpu":10,"mem":40,"flow":8000,"duration":240}
                }'''
    jp = JsonParser()
    rule = jp.decode(rule)
    print rule['highWarn']['cpu']