def saveWorkflowState(self): status = self.getStatus() taskstate = TaskState(self.taskData.id, self._pause, self.submitTime, self.startTime, self.finishedTime, self.getState(), self._outputDirId, self.taskData.name, self.taskData.flowId, self.wfData.name, status, self.formatError() if status=='Error' else '', self.userId) if self._taskStateId: TaskStateDao.modifyTaskState(self._taskStateId, taskstate, self.userId) else: self._taskStateId = TaskStateDao.addTaskState(taskstate) self.lastTaskState = TaskStateDao.lastTaskState(self.taskData.id, self.userId)
def queryTaskStateByArgs(): userid = getUserId() sortName = flask.request.form.get('sortName') sortOrder = flask.request.form.get('sortOrder') pageSize = flask.request.form.get('pageSize') pageNumber = flask.request.form.get('pageNumber') config.Log.info('sortname = %s, sortorder = %s, pageSize = %s, pagenumber = %s, userid = %s' % (sortName, sortOrder, pageSize, pageNumber, userid)) taskstatelist = TaskStateDao.queryByArgs(sortName, sortOrder, pageSize, pageNumber, userid) states = {} states['rows'] = [taskstate.dumpDetail() for taskstate in taskstatelist] states['total'] = TaskStateDao.queryCount(userid) return flask.jsonify(states)
def queryTaskStatus(): userid = getUserId() flowid = flask.request.form.get('flowid') if not flowid: code = ErrorCode.NoFlowIdInReq return flask.jsonify({'code': code}) taskIdList = TaskDao.queryTaskIdByFlowId(flowid, userid) if taskIdList == []: code = ErrorCode.NotFindTaskByFlowId return flask.jsonify({'code': code}) taskstateList = [] message = {} for taskid in taskIdList: taskstate = TaskStateDao.lastTaskState(taskid, userid) if taskstate: taskstateList.append(taskstate) else: message[taskid] = 'NotRuning' for info in taskstateList: if info.endTime: message[info.taskId] = 'NotRuning' else: message[info.taskId] = 'Runing' return flask.jsonify(message)
def deleteTask(): taskId = flask.request.form.get('id') if not taskId: return flask.jsonify({'code': ErrorCode.NoTaskIdInReq}) try: _requestTaskServerRetCode(taskId, TaskRequestType.StopTask) except: config.Log.info('can not kill module') TaskStateDao.deleteTaskState(taskId, getUserId()) code = TaskDao.deleteTask(taskId, getUserId()) try: lltsIdList = StateClanDao.delByTaskId(taskId, getUserId()) except: config.Log.info('can not kill module while delete task') return flask.jsonify({'code': code})
def listTaskDir(userid, taskId, userId): task = TaskDao.queryTask(taskId, userId) if not task: return {'code': ErrorCode.NotFindTaskById} token = getTokenByuserid(userid) def _listDir(dirid): ret = [] dirs = listDir(token, dirid) for d in dirs: if d['type'] == 'dir': ret.append({ 'type': 'dir', 'path': d['path'], 'children': _listDir(d['id']) }) elif d['type'] == 'file': obj = {'type': 'file', 'path': d['path']} ft = checkFileType(d['path']) if ft == FileType.TIFF_FILE: obj['url'] = tiffserver.queryWMSUrl( d['metadataid'], userid) elif ft == FileType.SHP_FILE: obj['url'] = shpserver.queryWMSUrl(d['metadataid'], userid) else: obj['url'] = dataserver.getPreviewUrl(d['metadataid']) ret.append(obj) return ret dirs = listDir(token, task.dir) taskState = TaskStateDao.lastTaskState(taskId, userId) inputs = None outputs = None for d in dirs: if d['path'] == config.INPUT_DIR_NAME: inputs = _listDir(d['id']) elif taskState and str(d['id']) == taskState.fsId: outputs = _listDir(d['id']) return { 'code': ErrorCode.NoError, 'type': 'dir', 'path': task.name, 'children': [{ 'type': 'dir', 'path': config.INPUT_DIR_NAME, 'children': inputs or [] }, { 'type': 'dir', 'path': config.OUTPUT_DIR_NAME, 'children': outputs or [] }] }
def delWorkFlow(): userId = getUserId() # 删除流程 flowId = flask.request.form.get('id') if not flowId: return flask.jsonify({'code': ErrorCode.NoFlowIdInReq}) flow = WorkFlowDao.queryWorkflow(flowId, userId) if flow.userId != userId: return flask.jsonify({'code': ErrorCode.CannotDeleteMutualFlow}) UiDataDao.deleteUiDataByFlowId(flowId, userId) taskIdList = TaskDao.queryTaskIdByFlowId(flowId, userId) for id in taskIdList: TaskStateDao.deleteTaskState(id, userId) TaskDao.deleteByFlowId(flowId, userId) code = WorkFlowDao.deleteWorkflow(flowId, userId) return flask.jsonify({'code': code})
def getTaskState(id): taskstate = TaskStateDao.lastTaskState(id, getUserId()) if taskstate: clan = json.loads(taskstate.clan) if taskstate.endTime: runtime = taskstate.endTime - taskstate.startTime else: runtime = time.time() - taskstate.startTime clan['runTime'] = runtime return flask.jsonify(clan) else: return flask.jsonify({})
def listInputOutputDir(userid, taskId, userId): token = getTokenByuserid(userid) task = TaskDao.queryTask(taskId, userId) inputid = None outputid = None inputname = None outputname = None if not task: return {'code': ErrorCode.NotFindTaskById} dirs = listDir(userid, task.dir) taskState = TaskStateDao.lastTaskState(taskId, userId) for d in dirs: if d['path'] == config.INPUT_DIR_NAME: inputid = d['id'] inputname = d['path'] elif taskState and str(d['id']) == taskState.fsId: outputid = d['id'] outputname = d['path'] return { 'code': ErrorCode.NoError, 'type': 'dir', 'path': task.name, 'children': [{ 'type': 'dir', 'path': inputname, 'id': inputid, 'children': [] }, { 'type': 'dir', 'path': outputname, 'id': outputid, 'children': [] }] }
def prepareFsDir(self): if self._dirInit: return config.Log.info('start prepareFsDir') userid = self.userId username = LoginInfoDao.queryUsernameByuserid(userid) def _createLocalFiles(dirId, fsRoot, createFile = True): fs.createDir(fsRoot) dirs = webos.listDir(userid, dirId) config.Log.info(dirs) for d in dirs: fpath = os.path.join(fsRoot, d['path']) if d['type'] == 'dir': _createLocalFiles(d['id'], fpath) elif createFile: ft = webos.checkFileType(fpath) if ft == webos.FileType.NORMAL_FILE: dataserver.downloadFile(d['metadataid'], fpath) self.taskData.replaceArgs(d['metadataid'], fpath) elif ft == webos.FileType.TIFF_FILE: url = tiffserver.queryDataUrl(d['metadataid'], userid) if not url: raise MsgException(ErrorCode.GetNetimgUrlFaild, u'get netimg url faild. metadataid = %s' % d['metadataid']) self.taskData.replaceArgs(d['metadataid'], url) else: # TODO url for shp pass # 重命名历史输出目录并创建新的输出目录 try: dirs = webos.listDir(userid, self.taskData.rootDir) config.Log.info(dirs) except: config.Log.info(traceback.format_exc()) config.Log.info('listDir error') return ErrorCode.ListDirError config.Log.info('prepare list dir: %s' % dirs) for d in dirs: if d['path'] == config.INPUT_DIR_NAME: _createLocalFiles(d['id'], os.path.join(self._rootDir, config.INPUT_DIR_NAME)) elif d['path'] == config.OUTPUT_DIR_NAME: config.Log.info('output fs id: %s' % d['id']) pretaskstate = TaskStateDao.queryByFsId(d['id'], self.userId) config.Log.info('pretaskstate: %s' % pretaskstate) if pretaskstate: webos.rename(userid, d['id'], self.taskData.rootDir, '%s_%s' % ('output', pretaskstate.id)) self._outputDirId = fs.prepareOutputDirOnWebos(userid, username, self.taskData.rootDir, self.wfData.obj) # _createLocalFiles(odirid, self.taskData.dirClassify, os.path.join(self._rootDir, 'output'), False) else: self._outputDirId = d['id'] # _createLocalFiles(d['id'], self.taskData.dirClassify, os.path.join(self._rootDir, 'output'), False) if not self._outputDirId: self._outputDirId = fs.prepareOutputDirOnWebos(userid, username, self.taskData.rootDir, self.wfData.obj) self._dirInit = True config.Log.info('download all file')