-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitorer.go
59 lines (48 loc) · 1.6 KB
/
monitorer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package gcpbatchtracker
import (
"context"
"encoding/json"
"fmt"
"cloud.google.com/go/batch/apiv1/batchpb"
"github.com/dgruber/drmaa2interface"
)
// All methods required for the DRMAA2 MonitoringSession
func (t *GCPBatchTracker) OpenMonitoringSession(name string) error {
// DRMAA2 sessions are just labels in Google Batch
return nil
}
func (t *GCPBatchTracker) GetAllJobIDs(filter *drmaa2interface.JobInfo) ([]string, error) {
// don't filter for session names
return listJobs(t, false)
}
func (t *GCPBatchTracker) GetAllQueueNames(filter []string) ([]string, error) {
// no queues in Google Batch
return []string{}, nil
}
func (t *GCPBatchTracker) GetAllMachines(filter []string) ([]drmaa2interface.Machine, error) {
// TODO: get machine types from Google Cloud API
return nil, fmt.Errorf("not yet implemented")
}
func (t *GCPBatchTracker) CloseMonitoringSession(name string) error {
return nil
}
// JobInfoFromMonitor might collect job state and job info in a
// different way as a JobSession with persistent storage does
func (t *GCPBatchTracker) JobInfoFromMonitor(jobID string) (drmaa2interface.JobInfo, error) {
// cached by ListJobs()
if ji, found := t.jcache.Get(jobID); found {
var jobInfo drmaa2interface.JobInfo
if err := json.Unmarshal(ji.([]byte), &jobInfo); err != nil {
fmt.Printf("could not unmarshal job info: %v", err)
return drmaa2interface.JobInfo{}, err
}
return jobInfo, nil
}
job, err := t.client.GetJob(context.Background(), &batchpb.GetJobRequest{
Name: jobID,
})
if err != nil {
return drmaa2interface.JobInfo{}, err
}
return BatchJobToJobInfo(t.project, job)
}