def get(self, uuid): """ Get the status of this particular thread. Use the uuid to grab the correct thread. return the progress and status of the thread. """ try: appGlobal = config['pylons.app_globals'] thread = appGlobal.threadMgr.getThreadByUuid(uuid) if (thread == None): script = manifestutil.getPackageScriptPath('agent', 'active', 'agent', 'uuid') tmp = [script, uuid] cmds = [] for cmd in tmp: cmds.append(cmd.encode('ascii', 'ignore')) cmdout = utils.runsyscmdwstdout(cmds) if cmdout: # make sure it's a valid json result = json.loads(cmdout) # return status as raw return statusResultRaw(request, response, result) else: return errorResult(request, response, Errors.STATUS_UUID_NOT_FOUND, 'Unable to find thread with uuid(%s)' % uuid, controller = self) except Exception as excep: return errorResult(request, response, error = Errors.UNKNOWN_ERROR, errorMsg = 'Unknown error for get status(%s) - %s, %s' % (uuid, str(excep), traceback.format_exc()), controller = self) return statusResult(request, response, thread, controller = self, maxProgress = 99 if thread.isAlive() else 100)
def getExecOutput(self, uuid): """ get script output with an uuid """ LOG.info('get ouput for %s' % uuid) try: script = os.path.join(manifestutil.manifestPath('agent'), 'agent', 'cronus', 'scripts', 'execoutput') LOG.info('execoutput script %s' % script) if not uuid or uuid == '': raise AgentException(Errors.INVALID_REQUEST, 'uuid cannot be empty') tmp = [script, uuid] cmds = [] for cmd in tmp: cmds.append(cmd.encode('ascii', 'ignore')) cmdout = utils.runsyscmdwstdout(cmds) return cmdout except Exception as excep: return errorResult(request, response, error = Errors.UNKNOWN_ERROR, errorMsg = 'Error when get execoutput %s - %s' % (str(excep), traceback.format_exc(2)), controller = self)
def getTaskSlaReport(self, task, threshold=0, starttime=0, fmt='raw'): """ get task SLA report """ LOG.info('generating task SLA report') try: script = os.path.join(manifestutil.manifestPath('agent'), 'agent', 'cronus', 'scripts', 'perfmetric') LOG.info('task sla report script %s' % script) if not task or task == '': raise AgentException(Errors.INVALID_REQUEST, 'task name cannot be empty') tmp = [script, task, str(threshold), str(starttime), fmt] cmds = [] for cmd in tmp: cmds.append(cmd.encode('ascii', 'ignore')) cmdout = utils.runsyscmdwstdout(cmds) result = json.loads(cmdout) return doneResult(request, response, result=result, controller = self) except Exception as excep: return errorResult(request, response, error = Errors.UNKNOWN_ERROR, errorMsg = 'Error when getting task sla report %s - %s' % (str(excep), traceback.format_exc(2)), controller = self)
def getGuidOutput(self, guid): """ get script output with a guid """ LOG.info('get ouput for %s' % guid) try: script = manifestutil.getPackageScriptPath('agent', 'active', 'agent', 'execoutput') LOG.info('execoutput script %s' % script) if not guid or guid == '': raise AgentException(Errors.INVALID_REQUEST, 'guid cannot be empty') tmp = [script, 'guid', guid] cmds = [] for cmd in tmp: cmds.append(cmd.encode('ascii', 'ignore')) cmdout = utils.runsyscmdwstdout(cmds) response.content_type = 'text/plain' return cmdout except Exception as excep: return errorResult(request, response, error = Errors.UNKNOWN_ERROR, errorMsg = 'Error when get execoutput %s - %s' % (str(excep), traceback.format_exc(2)), controller = self)