def generateDelayedPlot( self, typeName, reportName, startTime, endTime, condDict, grouping, extraArgs=None, compress=True): """ It is used to encode the plot parameters used to create a certain plot. :param str typeName: the type of the monitoring :param int startTime: epoch time, start time of the plot :param int endTime: epoch time, end time of the plot :param dict condDict: is the conditions used to gnerate the plot: {'Status':['Running'],'grouping': ['Site'] } :param str grouping: is the grouping of the data for example: 'Site' :param dict extraArgs: epoch time which can be last day, last week, last month :param bool compress: apply compression of the encoded values. :return: S_OK(str) or S_ERROR() it returns the encoded plot parameters """ if not isinstance(extraArgs, dict): extraArgs = {} plotRequest = {'typeName': typeName, 'reportName': reportName, 'startTime': startTime, 'endTime': endTime, 'condDict': condDict, 'grouping': grouping, 'extraArgs': extraArgs} return codeRequestInFileId(plotRequest, compress)
def web_getPlotImgFromCache(self): """ Get plot image from cache. """ callback = {} if 'file' not in self.request.arguments: callback = { "success": "false", "error": "Maybe you forgot the file?" } self.finish(callback) return plotImageFile = str(self.request.arguments['file'][0]) retVal = extractRequestFromFileId(plotImageFile) if not retVal['OK']: callback = {"success": "false", "error": retVal['Value']} self.finish(callback) return fields = retVal['Value'] if "extraArgs" in fields: # in order to get the plot from the cache we have to clean the extraArgs... plotTitle = "" if 'plotTitle' in fields["extraArgs"]: plotTitle = fields["extraArgs"]["plotTitle"] fields["extraArgs"] = {} fields["extraArgs"]["plotTitle"] = plotTitle else: fields["extraArgs"] = {} retVal = codeRequestInFileId(fields) if not retVal['OK']: callback = {"success": "false", "error": retVal['Value']} self.finish(callback) return plotImageFile = retVal['Value']['plot'] transferClient = TransferClient("Monitoring/Monitoring") tempFile = tempfile.TemporaryFile() retVal = yield self.threadTask(transferClient.receiveFile, tempFile, plotImageFile) if not retVal['OK']: callback = {"success": "false", "error": retVal['Message']} self.finish(callback) return tempFile.seek(0) data = tempFile.read() self.set_header('Content-type', 'image/png') self.set_header( 'Content-Disposition', 'attachment; filename="%s.png"' % md5(plotImageFile).hexdigest()) self.set_header('Content-Length', len(data)) self.set_header('Content-Transfer-Encoding', 'Binary') self.set_header('Cache-Control', "no-cache, no-store, must-revalidate, max-age=0") self.set_header('Pragma', "no-cache") self.set_header('Expires', ( datetime.datetime.utcnow() - datetime.timedelta(minutes=-10)).strftime("%d %b %Y %H:%M:%S GMT")) self.finish(data)
def generateDelayedPlot( self, typeName, reportName, startTime, endTime, condDict, grouping, extraArgs = None, compress = True ): if type( extraArgs ) != types.DictType: extraArgs = {} plotRequest = { 'typeName' : typeName, 'reportName' : reportName, 'startTime' : startTime, 'endTime' : endTime, 'condDict' : condDict, 'grouping' : grouping, 'extraArgs' : extraArgs } return codeRequestInFileId( plotRequest, compress )
def web_getPlotImgFromCache(self): """ Get plot image from cache. """ callback = {} if 'file' not in self.request.arguments: callback = {"success": "false", "error": "Maybe you forgot the file?"} self.finish(callback) return plotImageFile = str(self.request.arguments['file'][0]) retVal = extractRequestFromFileId(plotImageFile) if not retVal['OK']: callback = {"success": "false", "error": retVal['Value']} self.finish(callback) return fields = retVal['Value'] if "extraArgs" in fields: # in order to get the plot from the cache we have to clean the extraArgs... plotTitle = "" if 'plotTitle' in fields["extraArgs"]: plotTitle = fields["extraArgs"]["plotTitle"] fields["extraArgs"] = {} fields["extraArgs"]["plotTitle"] = plotTitle else: fields["extraArgs"] = {} retVal = codeRequestInFileId(fields) if not retVal['OK']: callback = {"success": "false", "error": retVal['Value']} self.finish(callback) return plotImageFile = retVal['Value']['plot'] transferClient = TransferClient("Accounting/ReportGenerator") tempFile = tempfile.TemporaryFile() retVal = yield self.threadTask(transferClient.receiveFile, tempFile, plotImageFile) if not retVal['OK']: callback = {"success": "false", "error": retVal['Message']} self.finish(callback) return tempFile.seek(0) data = tempFile.read() self.set_header('Content-type', 'image/png') self.set_header('Content-Disposition', 'attachment; filename="%s.png"' % md5(plotImageFile).hexdigest()) self.set_header('Content-Length', len(data)) self.set_header('Content-Transfer-Encoding', 'Binary') self.set_header('Cache-Control', "no-cache, no-store, must-revalidate, max-age=0") self.set_header('Pragma', "no-cache") self.set_header( 'Expires', (datetime.datetime.utcnow() - datetime.timedelta(minutes=-10)).strftime("%d %b %Y %H:%M:%S GMT")) self.finish(data)
def generateDelayedPlot( self, typeName, reportName, startTime, endTime, condDict, grouping, extraArgs=None, compress=True ): if type(extraArgs) != types.DictType: extraArgs = {} plotRequest = { "typeName": typeName, "reportName": reportName, "startTime": startTime, "endTime": endTime, "condDict": condDict, "grouping": grouping, "extraArgs": extraArgs, } return codeRequestInFileId(plotRequest, compress)
def generateDelayedPlot( self, typeName, reportName, startTime, endTime, condDict, grouping, extraArgs=None, compress=True ): if not isinstance(extraArgs, dict): extraArgs = {} plotRequest = { "typeName": typeName, "reportName": reportName, "startTime": startTime, "endTime": endTime, "condDict": condDict, "grouping": grouping, "extraArgs": extraArgs, } return codeRequestInFileId(plotRequest, compress)
def generateDelayedPlot( self, typeName, reportName, startTime, endTime, condDict, grouping, extraArgs=None, compress=True): if not isinstance(extraArgs, dict): extraArgs = {} plotRequest = {'typeName': typeName, 'reportName': reportName, 'startTime': startTime, 'endTime': endTime, 'condDict': condDict, 'grouping': grouping, 'extraArgs': extraArgs} return codeRequestInFileId(plotRequest, compress)
def _getImages( self, requestParams ): if not requestParams[ 'name' ]: gLogger.warn( 'No name given' ) return { 'success': 'false', 'error': 'We need a Site Name to generate an Overview' } elementName = requestParams[ 'name' ][ 0 ] pub = RPCClient( 'ResourceStatus/Publisher' ) elementStatuses = pub.getElementStatuses( 'Site', str(elementName), None, 'all', None, None ) if not elementStatuses[ 'Value' ]: gLogger.error( 'element "%s" not found' % elementName ) return { 'success' : 'false', 'error' : 'element "%s" not found' % elementName } elementStatus = [ dict( zip( elementStatuses[ 'Columns' ], element ) ) for element in elementStatuses[ 'Value' ] ][ 0 ] plotDict1 = self.getPlotDict( elementStatus[ 'Name' ], 'FinalMajorStatus', 'RunningJobs', 'Job', plotTitle = 'Final Minor Status of jobs' ) image1 = codeRequestInFileId( plotDict1 )[ 'Value' ][ 'plot' ] plotDict2 = self.getPlotDict( elementStatus[ 'Name' ], 'GridStatus', 'NumberOfPilots', 'Pilot' ) image2 = codeRequestInFileId( plotDict2 )[ 'Value' ][ 'plot' ] plotDict3 = self.getPlotDict( elementStatus[ 'Name' ], 'JobType', 'RunningJobs', 'Job', plotTitle = 'Jobs by job type' ) image3 = codeRequestInFileId( plotDict3 )[ 'Value' ][ 'plot' ] plotDict4 = self.getPlotDict( elementStatus[ 'Name' ], 'JobSplitType', 'NumberOfJobs', 'WMSHistory', status = 'Running' ) image4 = codeRequestInFileId( plotDict4 )[ 'Value' ][ 'plot' ] plotDict5 = self.getPlotDict( elementStatus[ 'Name' ], 'Channel', 'SuceededTransfers', 'DataOperation' ) image5 = codeRequestInFileId( plotDict5 )[ 'Value' ][ 'plot' ] plotDict6 = self.getPlotDict( elementStatus[ 'Name' ], 'FinalStatus', 'FailedTransfers', 'DataOperation' ) image6 = codeRequestInFileId( plotDict6 )[ 'Value' ][ 'plot' ] return { 'success' : 'true', 'result' : [image1, image2, image3, image4, image5, image6], 'total' : 6 }
def _getImages(self, requestParams): if not requestParams['name']: gLogger.warn('No name given') return { 'success': 'false', 'error': 'We need a Site Name to generate an Overview' } elementName = requestParams['name'][0] pub = RPCClient('ResourceStatus/Publisher') elementStatuses = pub.getElementStatuses('Site', str(elementName), None, 'all', None, None) if not elementStatuses['Value']: gLogger.error('element "%s" not found' % elementName) return { 'success': 'false', 'error': 'element "%s" not found' % elementName } elementStatus = [ dict(zip(elementStatuses['Columns'], element)) for element in elementStatuses['Value'] ][0] plotDict1 = self.getPlotDict(elementStatus['Name'], 'FinalMajorStatus', 'RunningJobs', 'Job', plotTitle='Final Minor Status of jobs') image1 = codeRequestInFileId(plotDict1)['Value']['plot'] plotDict2 = self.getPlotDict(elementStatus['Name'], 'GridStatus', 'NumberOfPilots', 'Pilot') image2 = codeRequestInFileId(plotDict2)['Value']['plot'] plotDict3 = self.getPlotDict(elementStatus['Name'], 'JobType', 'RunningJobs', 'Job', plotTitle='Jobs by job type') image3 = codeRequestInFileId(plotDict3)['Value']['plot'] plotDict4 = self.getPlotDict(elementStatus['Name'], 'JobSplitType', 'NumberOfJobs', 'WMSHistory', status='Running') image4 = codeRequestInFileId(plotDict4)['Value']['plot'] plotDict5 = self.getPlotDict(elementStatus['Name'], 'Channel', 'SuceededTransfers', 'DataOperation') image5 = codeRequestInFileId(plotDict5)['Value']['plot'] plotDict6 = self.getPlotDict(elementStatus['Name'], 'FinalStatus', 'FailedTransfers', 'DataOperation') image6 = codeRequestInFileId(plotDict6)['Value']['plot'] return { 'success': 'true', 'result': [image1, image2, image3, image4, image5, image6], 'total': 6 }