예제 #1
0
func GetJobStatus(s *drmaa.Session, jobId string) (ijs InternalJobStatus, er *drmaa.Error) {
	/* check status of job - could slow down qmaster when having lots of clients.
	   Grid Engine DRMAA2 implementation will solve this. */
	pt, err := s.JobPs(jobId)

	if err != nil {
		return ijs, err
	}

	if pt != drmaa.PsRunning {
		err2 := makeError("Job is not in running state.", drmaa.InvalidJob)
		return ijs, &err2
	}

	if cjs, found := getValidJobStatusFromCache(jobId); found == false {
		/* job is not cached yet or outdated - we need to fetch it */
		//qstat := fmt.Sprint("-xml -j ", jobId)
		cmd := exec.Command("qstat", "-xml", "-j", jobId)
		out, err := cmd.Output()
		if err != nil {
			log.Fatal("Could not execute qstat -xml -j")
			err := makeError("Could not execute qstat.", drmaa.InternalError)
			return ijs, &err
		}

		js, err := parseXML(out)

		if err != nil {
			log.Fatal("Could not parse xml output of qstat.")
			err := makeError("Could not parse XML output of qstat.", drmaa.InternalError)
			return ijs, &err
		}

		// Cache job status
		cachedJobStatus[jobId] = jobStatusCache{time.Now(), js}

		return js, nil
	} else {
		/* return cached job status */
		return cjs, nil
	}

	/* unreachable */
	return ijs, nil
}
예제 #2
0
// Waits for running job, determines hostname and sends it down channel.
func waitForRunning(s drmaa.Session, jobId string, hostCh chan string) {
	// Wait for running job
	d, _ := time.ParseDuration("500ms")
	ps, _ := s.JobPs(jobId)
	for ps != drmaa.PsRunning {
		time.Sleep(d)
		ps, _ = s.JobPs(jobId)
	}

	// Get hostname
	jobStatus, err := gestatus.GetJobStatus(&s, jobId)
	if err != nil {
		fmt.Printf("Error in getting hostname for job %s: %s\n", jobId, err.Error())
		hostCh <- ""
		return
	}
	hostname := jobStatus.DestinationHostList()
	hostCh <- strings.Join(hostname, "")
}