Ejemplo n.º 1
0
def get_job_script(JobID):
	"""Return the job payload script, or raise NotImplemented if unavailable."""
	if FASRC:
		#at FASRC, we have our slurmctld prolog store the script in a database
		shv = ['mysql', 'slurm_jobscripts', '-BNr', '-e', 'select script from jobscripts where id_job = %d;' % int(JobID)]
		return util.runsh(shv)
	else:
		raise NotImplementedError("job script retrieval requires implementation in config.py")
Ejemplo n.º 2
0
def get_job_script(JobID):
    """Return the job payload script, or raise NotImplemented if unavailable."""
    if FASRC:
        #at FASRC, we have our slurmctld prolog store the script in a database
        shv = [
            'mysql', 'slurm_jobscripts', '-BNr', '-e',
            'select script from jobscripts where id_job = %d;' % int(JobID)
        ]
        return util.runsh(shv)
    else:
        raise NotImplementedError(
            "job script retrieval requires implementation in config.py")
Ejemplo n.º 3
0
	def load_data(self, keys=[]):
		for key in keys:
			if not self.has_key(key):
				#--- sacct data

				#(not implemented yet)


				#--- other one-off queries

				if key == 'JobScript':
					try:
						self['JobScript'] = config.get_job_script(self['JobID'])
					except NotImplementedError:
						self['JobScript'] = None
					
				elif key == 'SacctReport':
					shv = ['sacct', '--format', _sacct_format_readable, '-j', self['JobID']]
					self['SacctReport'] = util.runsh(shv).rstrip()


				#--- derived

				if key == 'ReqMem_bytes_total':
					if self.has_key('ReqMem_bytes_per_core') and self['ReqMem_bytes_per_core'] is not None:
						if self.has_key('ReqMem_bytes_per_node') and self['ReqMem_bytes_per_node'] is not None:
							raise Exception("both memory-per-node and memory-per-core used, and this cannot handle that")
						self['ReqMem_bytes_total'] = self['ReqMem_bytes_per_core'] * self['NCPUS']
					elif self.has_key('ReqMem_bytes_per_node') and self['ReqMem_bytes_per_node'] is not None:
						self['ReqMem_bytes_total'] = self['ReqMem_bytes_per_node'] * self['NNodes']
					else:
						self['ReqMem_bytes_total'] = None

				elif key == 'CPU_Efficiency':
					if self.has_key('TotalCPU') and \
						self.has_key('CPUTime') and self['CPUTime']!=0:
						self['CPU_Efficiency'] = float(self['TotalCPU'])/self['CPUTime']
					else:
						self['CPU_Efficiency'] = None

				elif key == 'CPU_Wasted':
					if self.has_key('TotalCPU') and self.has_key('CPUTime'):
						self['CPU_Wasted'] = max(self['CPUTime'] - self['TotalCPU'], 0)
					else:
						self['CPU_Efficiency'] = None

				elif key == 'JobScriptPreview':
					try:
						self['JobScriptPreview'] = slurmmon.job_script_preview(self['JobScript'], self)
					except KeyError:
						self['JobScriptPreview'] = None
Ejemplo n.º 4
0
def get_jobs_running_on_host(hostname):
	"""Return jobs running on the given host."""
	shv = ['squeue', '-o', '%A %u %C %D', '--noheader', '-w', hostname]
	stdout = util.runsh(shv).strip()
	for line in stdout.split('\n'):
		line = line.strip()
		if line!='':
			try:
				JobID, User, NCPUS, NNodes = line.split()

				j = Job()
				j['JobID'] = JobID
				j['User'] = User
				j['NCPUS'] = NCPUS
				j['NNodes'] = NNodes

				yield j

			except Exception, e:
				sys.stderr.write("*** ERROR *** unable to parse squeue job text [%r]: %s\n" % (line, e))
Ejemplo n.º 5
0
def get_jobs_running_on_host(hostname):
    """Return jobs running on the given host."""
    shv = ['squeue', '-o', '%A %u %C %D', '--noheader', '-w', hostname]
    stdout = util.runsh(shv).strip()
    for line in stdout.split('\n'):
        line = line.strip()
        if line != '':
            try:
                JobID, User, NCPUS, NNodes = line.split()

                j = Job()
                j['JobID'] = JobID
                j['User'] = User
                j['NCPUS'] = NCPUS
                j['NNodes'] = NNodes

                yield j

            except Exception, e:
                sys.stderr.write(
                    "*** ERROR *** unable to parse squeue job text [%r]: %s\n"
                    % (line, e))
Ejemplo n.º 6
0
	def test_shquote_runsh(self):
		"""That echo is identity for a funky_string."""
		self.assertEqual(
			u.runsh('echo -n %s' % u.shquote(ShTestCase.funky_string)),
			ShTestCase.funky_string
		)
Ejemplo n.º 7
0
	def test_runsh_list(self):
		"""That runsh() works on an argv list."""
		self.assertEqual(
			u.runsh(['echo','foo']),
			'foo\n',
		)
Ejemplo n.º 8
0
	def test_runsh_string(self):
		"""That runsh() works on sh code as a string."""
		self.assertEqual(
			u.runsh('echo foo'),
			'foo\n',
		)
Ejemplo n.º 9
0
    def load_data(self, keys=[]):
        for key in keys:
            if not self.has_key(key):
                #--- sacct data

                #(not implemented yet)

                #--- other one-off queries

                if key == 'JobScript':
                    try:
                        self['JobScript'] = config.get_job_script(
                            self['JobID'])
                    except NotImplementedError:
                        self['JobScript'] = None

                elif key == 'SacctReport':
                    shv = [
                        'sacct', '--format', _sacct_format_readable, '-j',
                        self['JobID']
                    ]
                    self['SacctReport'] = util.runsh(shv).rstrip()

                #--- derived

                if key == 'ReqMem_bytes_total':
                    if self.has_key('ReqMem_bytes_per_core') and self[
                            'ReqMem_bytes_per_core'] is not None:
                        if self.has_key('ReqMem_bytes_per_node') and self[
                                'ReqMem_bytes_per_node'] is not None:
                            raise Exception(
                                "both memory-per-node and memory-per-core used, and this cannot handle that"
                            )
                        self['ReqMem_bytes_total'] = self[
                            'ReqMem_bytes_per_core'] * self['NCPUS']
                    elif self.has_key('ReqMem_bytes_per_node') and self[
                            'ReqMem_bytes_per_node'] is not None:
                        self['ReqMem_bytes_total'] = self[
                            'ReqMem_bytes_per_node'] * self['NNodes']
                    else:
                        self['ReqMem_bytes_total'] = None

                elif key == 'CPU_Efficiency':
                    if self.has_key('TotalCPU') and \
                     self.has_key('CPUTime') and self['CPUTime']!=0:
                        self['CPU_Efficiency'] = float(
                            self['TotalCPU']) / self['CPUTime']
                    else:
                        self['CPU_Efficiency'] = None

                elif key == 'CPU_Wasted':
                    if self.has_key('TotalCPU') and self.has_key('CPUTime'):
                        self['CPU_Wasted'] = max(
                            self['CPUTime'] - self['TotalCPU'], 0)
                    else:
                        self['CPU_Efficiency'] = None

                elif key == 'JobScriptPreview':
                    try:
                        self['JobScriptPreview'] = slurmmon.job_script_preview(
                            self['JobScript'], self)
                    except KeyError:
                        self['JobScriptPreview'] = None