def presentCell(self, record: ResourceBase, **kwargs: object) -> XMLContent: proc = cast(PageProcessor[PageArgs], kwargs['proc']) action = Actions.RESUME if record.isSuspended() else Actions.SUSPEND return makeForm(args=PostArgs(proc.args, resource=record.getId()), setFocus=False)[submitButton(name='action', value=action)]
def presentCell(self, record: ResourceBase, **kwargs: object) -> XMLContent: if record.isReserved(): # TODO: Create a generic reserved-by system that works for all # resources types. if isinstance(record, TaskRunner): return createTaskLink(record) else: reservedBy = cast(str, record['reserved']) reservedType, reservedId = reservedBy.split('-', 1) if reservedType == 'J': # job return createJobLink(reservedId) elif reservedType == 'T': # task proc = cast(ResourceIndex_GET.Processor, kwargs['proc']) try: run = proc.taskRunDB[reservedId] except KeyError: return 'unknown task' return createTaskInfoLink(run.getJob().getId(), run.getName()) else: assert False, reservedBy return '?' elif record.isSuspended(): return record.getChangedUser() else: return '-'
def iterChangedBy(resource: ResourceBase) -> Iterator[XML]: user = resource.getChangedUser() if user: # Currently 'user' is always 'None' for custom resources yield xml.changedby( name = user, time = formatTimeAttr(resource.getChangedTime()), )
def _getResourceReservedBy(resource: ResourceBase) -> str: if isinstance(resource, TaskRunner): taskRun = resource.getRun() if taskRun is not None: return 'T-' + taskRun.getId() else: if resource.isReserved(): return cast(str, resource['reserved']) if resource.isSuspended(): userName = resource.getChangedUser() assert userName is not None return 'Z-' + userName return ''
def getResourceStatus(resource: ResourceBase) -> str: """Returns a status summary string for `resource`.""" connectionStatus = resource.getConnectionStatus() if connectionStatus in (ConnectionStatus.LOST, ConnectionStatus.WARNING): return connectionStatus.name.lower() elif resource.isReserved(): executionRun = resource.getRun() if executionRun is not None: alert = executionRun.getAlert() if alert: return alert return 'reserved' elif resource.isSuspended(): return 'suspended' elif connectionStatus is ConnectionStatus.CONNECTED: return 'free' else: return connectionStatus.name.lower()
def iterResourceContent(resource: ResourceBase) -> Iterator[XML]: # Resource type independent information for cap in resource.capabilities: yield xml.capability(name = cap) yield from iterChangedBy(resource) yield from iterReservedBy(resource) if isinstance(resource, TaskRunner): # Include Task Runner specific infomation. yield xml.taskrunner( connectionstatus = resource.getConnectionStatus(), version = cast(str, resource['runnerVersion']), exitonidle = resource.shouldExit(), lastsync = cast(Optional[int], resource['lastSync']), ) else: # Include information on custom resource type. yield xml.custom( description = resource.description )
def presentCell(self, record: ResourceBase, **kwargs: object) -> XMLContent: typeName = record.typeName if typeName.startswith('sf.'): for resType in reservedTypes: if resType.name == typeName: pageName = resType.editPage break else: return '-' else: pageName = 'ResourceEdit' return pageLink(pageName, DeleteArgs(id=record.getId()))['Edit']
def iterReservedBy(resource: ResourceBase) -> Iterator[XML]: if isinstance(resource, TaskRunner): # Resource is a Task Runner. runner = resource run = runner.getRun() if run: yield xml.reservedby[ xml.taskref( taskname = run.getName(), jobid = run.getJob().getId(), ) ] else: # Resource is of a custom type. if resource.isReserved(): yield xml.reservedby[ xml.userref( userid = cast(str, resource['reserved']) ) ]
def presentCell(self, record: ResourceBase, **kwargs: object) -> XMLContent: if isinstance(record, TaskRunner): return createTaskRunnerDetailsLink(record.getId()) else: return record.getId()