From 0cbe9d24f11af0d7ee9aa9e2eb6d97417bc5aac1 Mon Sep 17 00:00:00 2001 From: Chris Tessum Date: Sun, 30 Sep 2018 10:07:53 -0700 Subject: [PATCH] cloud: Make status messages more detailed --- cloud/blob.go | 4 +- cloud/client.go | 61 +++++--- cloud/client_test.go | 4 +- cloud/cloud.proto | 18 ++- cloud/cloudrpc/cloud.pb.go | 133 +++++++++++++----- .../cloudrpcgojs/cloud.pb.gopherjs.go | 86 ++++++++++- cloud/config.go | 28 ++++ cloud/jobspec.go | 3 + inmaputil/cloud_test.go | 10 +- 9 files changed, 278 insertions(+), 69 deletions(-) diff --git a/cloud/blob.go b/cloud/blob.go index 45037cfe5..93ab9c96d 100644 --- a/cloud/blob.go +++ b/cloud/blob.go @@ -69,11 +69,11 @@ func (c *Client) Output(ctx context.Context, job *cloudrpc.JobName) (*cloudrpc.J o := &cloudrpc.JobOutput{ Files: make(map[string][]byte), } - //k8sJob, err := c.getk8sJob(ctx, job) + //TODO: k8sJob, err := c.getk8sJob(ctx, job) if err != nil { return nil, err } - //addrs, err := c.jobOutputAddresses(ctx, job.Name, k8sJob.Spec.Template.Spec.Containers[0].Command) + //TODO: addrs, err := c.jobOutputAddresses(ctx, job.Name, k8sJob.Spec.Template.Spec.Containers[0].Command) addrs, err := c.jobOutputAddresses(ctx, job.Name, []string{"inmap", "run", "steady"}) if err != nil { return nil, err diff --git a/cloud/client.go b/cloud/client.go index 977e2787a..351b98176 100644 --- a/cloud/client.go +++ b/cloud/client.go @@ -87,13 +87,25 @@ func NewClient(k kubernetes.Interface, root *cobra.Command, config *viper.Viper, return c, nil } -// Create creates (and queues) a Kubernetes job with the given name that executes +// RunJob creates (and queues) a Kubernetes job with the given name that executes // the given command with the given command-line arguments on the given container // image. resources specifies the minimum required resources for execution. func (c *Client) RunJob(ctx context.Context, job *cloudrpc.JobSpec) (*cloudrpc.JobStatus, error) { if job.Version != inmap.Version { return nil, fmt.Errorf("incorrect InMAP version: %s != %s", job.Version, inmap.Version) } + + status, err := c.Status(ctx, &cloudrpc.JobName{Name: job.Name, Version: job.Version}) + if err != nil { + return nil, err + } + if status.Status != cloudrpc.Status_Failed { //TODO: status.Status != cloudrpc.Status_Missing && { + // Only create the job if it is missing or failed. + return status, nil + } + // TODO: Is this necessary? + c.Delete(ctx, &cloudrpc.JobName{Name: job.Name, Version: job.Version}) + if err := c.stageInputs(ctx, job); err != nil { return nil, err } @@ -107,20 +119,11 @@ func (c *Client) RunJob(ctx context.Context, job *cloudrpc.JobSpec) (*cloudrpc.J k8sJob := createJob(userJobName(user, job.Name), job.Cmd, job.Args, c.Image, core.ResourceList{ core.ResourceMemory: resource.MustParse(fmt.Sprintf("%dGi", job.MemoryGB)), }) - k8sJobResult, err := c.jobControl.Create(k8sJob) + _, err = c.jobControl.Create(k8sJob) if err != nil { return nil, err } - return c.jobStatus(k8sJobResult) -} - -// Status returns the status of the given job. -func (c *Client) Status(ctx context.Context, job *cloudrpc.JobName) (*cloudrpc.JobStatus, error) { - k8sJob, err := c.getk8sJob(ctx, job) - if err != nil { - return nil, err - } - return c.jobStatus(k8sJob) + return c.Status(ctx, &cloudrpc.JobName{Name: job.Name, Version: job.Version}) } // Delete deletes the given job. @@ -167,10 +170,36 @@ func userJobName(user, name string) string { return strings.Replace(user, "_", "-", -1) + "-" + strings.Replace(name, "_", "-", -1) } -func (c *Client) jobStatus(j *batch.Job) (*cloudrpc.JobStatus, error) { - return &cloudrpc.JobStatus{ - Status: j.Status.String(), - }, nil +// Status returns the status of the given job. +func (c *Client) Status(ctx context.Context, job *cloudrpc.JobName) (*cloudrpc.JobStatus, error) { + s := new(cloudrpc.JobStatus) + /*k8sJob, err := c.getk8sJob(ctx, job) + if err != nil { + return &cloudrpc.JobStatus{ + Status: cloudrpc.Status_Missing, + Message: err.Error(), + }, nil + } + for _, c := range k8sJob.Status.Conditions { + if c.Type == batch.JobComplete && c.Status == core.ConditionTrue { + s.Status = cloudrpc.Status_Complete + s.StartTime = k8sJob.Status.StartTime.Time.Unix() + s.CompletionTime = k8sJob.Status.CompletionTime.Time.Unix() + } else if c.Type == batch.JobFailed && c.Status == core.ConditionTrue { + s.Status = cloudrpc.Status_Failed + } + } + if k8sJob.Status.Active > 0 { + s.Status = cloudrpc.Status_Running + s.StartTime = k8sJob.Status.StartTime.Time.Unix() + }*/ + //TODO: err = c.checkOutputs(ctx, name, k8sJob.Spec.Template.Spec.Containers[0].Command) + err := c.checkOutputs(ctx, job.Name, []string{"inmap", "run", "steady"}) + if err != nil { + s.Status = cloudrpc.Status_Failed + s.Message = fmt.Sprintf("job completed but the following error occurred when checking outputs: %s", err) + } + return s, nil } // createJob creates a Kubernetes job specification with the given name that executes the diff --git a/cloud/client_test.go b/cloud/client_test.go index c7a53425f..803e95b17 100644 --- a/cloud/client_test.go +++ b/cloud/client_test.go @@ -96,7 +96,7 @@ func TestClient_fake(t *testing.T) { t.Fatal(err) } wantStatus := &cloudrpc.JobStatus{ - Status: "&JobStatus{Conditions:[],StartTime:,CompletionTime:,Active:0,Succeeded:0,Failed:0,}", + // Status: "&JobStatus{Conditions:[],StartTime:,CompletionTime:,Active:0,Succeeded:0,Failed:0,}", } if !reflect.DeepEqual(wantStatus, status) { t.Errorf("status:\n%+v\n!=\n%+v", status, wantStatus) @@ -112,7 +112,7 @@ func TestClient_fake(t *testing.T) { t.Fatal(err) } wantStatus := &cloudrpc.JobStatus{ - Status: "&JobStatus{Conditions:[],StartTime:,CompletionTime:,Active:0,Succeeded:0,Failed:0,}", + // Status: "&JobStatus{Conditions:[],StartTime:,CompletionTime:,Active:0,Succeeded:0,Failed:0,}", } if !reflect.DeepEqual(wantStatus, status) { t.Errorf("status:\n%+v\n!=\n%+v", status, wantStatus) diff --git a/cloud/cloud.proto b/cloud/cloud.proto index 1c8de31ef..af36138fd 100644 --- a/cloud/cloud.proto +++ b/cloud/cloud.proto @@ -23,8 +23,8 @@ service CloudRPC { // output file(s). rpc RunJob(JobSpec) returns (JobStatus) {} - // OutputAddresses returns status and the addresses the output file(s) of the - // requested simulation name. + // Status returns the status of the simulation with the + // requested name. rpc Status(JobName) returns(JobStatus) {} // Output returns the output file(s) of the @@ -61,9 +61,21 @@ message JobSpec { map FileData = 7; } +enum Status { + Complete = 0; + Failed = 1; + Missing = 2; + Running = 3; +} + message JobStatus { // Status holds the current status of the job. - string Status = 1; + Status Status = 1; + string Message = 2; + + // Unix time, the number of seconds elapsed since January 1, 1970 UTC + int64 StartTime = 3; + int64 CompletionTime = 4; } message JobOutput { diff --git a/cloud/cloudrpc/cloud.pb.go b/cloud/cloudrpc/cloud.pb.go index 742fcea30..162d46c1c 100644 --- a/cloud/cloudrpc/cloud.pb.go +++ b/cloud/cloudrpc/cloud.pb.go @@ -23,6 +23,35 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +type Status int32 + +const ( + Status_Complete Status = 0 + Status_Failed Status = 1 + Status_Missing Status = 2 + Status_Running Status = 3 +) + +var Status_name = map[int32]string{ + 0: "Complete", + 1: "Failed", + 2: "Missing", + 3: "Running", +} +var Status_value = map[string]int32{ + "Complete": 0, + "Failed": 1, + "Missing": 2, + "Running": 3, +} + +func (x Status) String() string { + return proto.EnumName(Status_name, int32(x)) +} +func (Status) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_cloud_877544bb241d427f, []int{0} +} + // JobSpec is the input for the RunJob service. type JobSpec struct { // Version is the required InMAP version. @@ -47,7 +76,7 @@ func (m *JobSpec) Reset() { *m = JobSpec{} } func (m *JobSpec) String() string { return proto.CompactTextString(m) } func (*JobSpec) ProtoMessage() {} func (*JobSpec) Descriptor() ([]byte, []int) { - return fileDescriptor_cloud_2d86b3326abf2f76, []int{0} + return fileDescriptor_cloud_877544bb241d427f, []int{0} } func (m *JobSpec) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_JobSpec.Unmarshal(m, b) @@ -111,7 +140,11 @@ func (m *JobSpec) GetFileData() map[string][]byte { type JobStatus struct { // Status holds the current status of the job. - Status string `protobuf:"bytes,1,opt,name=Status,proto3" json:"Status,omitempty"` + Status Status `protobuf:"varint,1,opt,name=Status,proto3,enum=cloudrpc.Status" json:"Status,omitempty"` + Message string `protobuf:"bytes,2,opt,name=Message,proto3" json:"Message,omitempty"` + // Unix time, the number of seconds elapsed since January 1, 1970 UTC + StartTime int64 `protobuf:"varint,3,opt,name=StartTime,proto3" json:"StartTime,omitempty"` + CompletionTime int64 `protobuf:"varint,4,opt,name=CompletionTime,proto3" json:"CompletionTime,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -121,7 +154,7 @@ func (m *JobStatus) Reset() { *m = JobStatus{} } func (m *JobStatus) String() string { return proto.CompactTextString(m) } func (*JobStatus) ProtoMessage() {} func (*JobStatus) Descriptor() ([]byte, []int) { - return fileDescriptor_cloud_2d86b3326abf2f76, []int{1} + return fileDescriptor_cloud_877544bb241d427f, []int{1} } func (m *JobStatus) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_JobStatus.Unmarshal(m, b) @@ -141,13 +174,34 @@ func (m *JobStatus) XXX_DiscardUnknown() { var xxx_messageInfo_JobStatus proto.InternalMessageInfo -func (m *JobStatus) GetStatus() string { +func (m *JobStatus) GetStatus() Status { if m != nil { return m.Status } + return Status_Complete +} + +func (m *JobStatus) GetMessage() string { + if m != nil { + return m.Message + } return "" } +func (m *JobStatus) GetStartTime() int64 { + if m != nil { + return m.StartTime + } + return 0 +} + +func (m *JobStatus) GetCompletionTime() int64 { + if m != nil { + return m.CompletionTime + } + return 0 +} + type JobOutput struct { // Files holds the contents of each output file. Files map[string][]byte `protobuf:"bytes,1,rep,name=Files,proto3" json:"Files,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` @@ -160,7 +214,7 @@ func (m *JobOutput) Reset() { *m = JobOutput{} } func (m *JobOutput) String() string { return proto.CompactTextString(m) } func (*JobOutput) ProtoMessage() {} func (*JobOutput) Descriptor() ([]byte, []int) { - return fileDescriptor_cloud_2d86b3326abf2f76, []int{2} + return fileDescriptor_cloud_877544bb241d427f, []int{2} } func (m *JobOutput) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_JobOutput.Unmarshal(m, b) @@ -201,7 +255,7 @@ func (m *JobName) Reset() { *m = JobName{} } func (m *JobName) String() string { return proto.CompactTextString(m) } func (*JobName) ProtoMessage() {} func (*JobName) Descriptor() ([]byte, []int) { - return fileDescriptor_cloud_2d86b3326abf2f76, []int{3} + return fileDescriptor_cloud_877544bb241d427f, []int{3} } func (m *JobName) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_JobName.Unmarshal(m, b) @@ -242,6 +296,7 @@ func init() { proto.RegisterType((*JobOutput)(nil), "cloudrpc.JobOutput") proto.RegisterMapType((map[string][]byte)(nil), "cloudrpc.JobOutput.FilesEntry") proto.RegisterType((*JobName)(nil), "cloudrpc.JobName") + proto.RegisterEnum("cloudrpc.Status", Status_name, Status_value) } // Reference imports to suppress errors if they are not otherwise used. @@ -259,8 +314,8 @@ type CloudRPCClient interface { // RunJob performs an InMAP simulation and returns the paths to the // output file(s). RunJob(ctx context.Context, in *JobSpec, opts ...grpc.CallOption) (*JobStatus, error) - // OutputAddresses returns status and the addresses the output file(s) of the - // requested simulation name. + // Status returns the status of the simulation with the + // requested name. Status(ctx context.Context, in *JobName, opts ...grpc.CallOption) (*JobStatus, error) // Output returns the output file(s) of the // requested simulation name. @@ -318,8 +373,8 @@ type CloudRPCServer interface { // RunJob performs an InMAP simulation and returns the paths to the // output file(s). RunJob(context.Context, *JobSpec) (*JobStatus, error) - // OutputAddresses returns status and the addresses the output file(s) of the - // requested simulation name. + // Status returns the status of the simulation with the + // requested name. Status(context.Context, *JobName) (*JobStatus, error) // Output returns the output file(s) of the // requested simulation name. @@ -429,30 +484,36 @@ var _CloudRPC_serviceDesc = grpc.ServiceDesc{ Metadata: "cloud.proto", } -func init() { proto.RegisterFile("cloud.proto", fileDescriptor_cloud_2d86b3326abf2f76) } - -var fileDescriptor_cloud_2d86b3326abf2f76 = []byte{ - // 344 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xcd, 0x4a, 0xfb, 0x40, - 0x14, 0xc5, 0x9b, 0xa6, 0x49, 0xd3, 0xdb, 0xff, 0x1f, 0xf4, 0x2a, 0x32, 0x64, 0xa1, 0x21, 0x6e, - 0xb2, 0x0a, 0x52, 0x05, 0x8b, 0x5d, 0x69, 0xab, 0x42, 0xc1, 0x0f, 0x46, 0x70, 0x9f, 0xb6, 0x83, - 0x14, 0xd3, 0x4e, 0x48, 0x26, 0x42, 0xf1, 0x45, 0x7d, 0x0f, 0x5f, 0x40, 0xe6, 0x23, 0x95, 0x50, - 0x51, 0xba, 0xbb, 0xe7, 0xe4, 0x9c, 0xc9, 0x2f, 0x77, 0x02, 0xdd, 0x69, 0xca, 0xcb, 0x59, 0x9c, - 0xe5, 0x5c, 0x70, 0xf4, 0x94, 0xc8, 0xb3, 0x69, 0xf8, 0x69, 0x41, 0x7b, 0xcc, 0x27, 0x4f, 0x19, - 0x9b, 0x22, 0x81, 0xf6, 0x33, 0xcb, 0x8b, 0x39, 0x5f, 0x12, 0x2b, 0xb0, 0xa2, 0x0e, 0xad, 0x24, - 0x22, 0xb4, 0xee, 0x93, 0x05, 0x23, 0x4d, 0x65, 0xab, 0x19, 0x77, 0xc0, 0x1e, 0x2e, 0x66, 0xc4, - 0x0e, 0xec, 0xa8, 0x43, 0xe5, 0x28, 0x53, 0x97, 0xf9, 0x4b, 0x41, 0x5a, 0xca, 0x52, 0x33, 0xfa, - 0xe0, 0xdd, 0xb1, 0x05, 0xcf, 0x57, 0xb7, 0x57, 0xc4, 0x09, 0xac, 0xc8, 0xa1, 0x6b, 0x8d, 0x03, - 0xf0, 0x6e, 0xe6, 0x29, 0x1b, 0x25, 0x22, 0x21, 0xed, 0xc0, 0x8e, 0xba, 0xbd, 0xa3, 0xb8, 0x02, - 0x8b, 0x0d, 0x54, 0x5c, 0x25, 0xae, 0x97, 0x22, 0x5f, 0xd1, 0x75, 0xc1, 0x1f, 0xc0, 0xff, 0xda, - 0x23, 0xc9, 0xf3, 0xca, 0x56, 0x86, 0x5c, 0x8e, 0xb8, 0x0f, 0xce, 0x5b, 0x92, 0x96, 0x1a, 0xfb, - 0x1f, 0xd5, 0xe2, 0xa2, 0xd9, 0xb7, 0xc2, 0x63, 0xe8, 0xc8, 0xf3, 0x45, 0x22, 0xca, 0x02, 0x0f, - 0xc0, 0xd5, 0x93, 0xe9, 0x1a, 0x15, 0xbe, 0xab, 0xd0, 0x43, 0x29, 0xb2, 0x52, 0xe0, 0x19, 0x38, - 0xf2, 0x75, 0x32, 0x23, 0x41, 0x0f, 0x6b, 0xa0, 0x3a, 0xa3, 0x50, 0x0b, 0xcd, 0xa9, 0xc3, 0x7e, - 0x1f, 0xe0, 0xdb, 0xdc, 0x8a, 0xf0, 0x5c, 0x5d, 0x8b, 0x5a, 0xf4, 0x56, 0xd7, 0xd2, 0xfb, 0xb0, - 0xc0, 0x1b, 0x4a, 0x36, 0xfa, 0x38, 0xc4, 0x1e, 0xb8, 0xb4, 0x5c, 0x8e, 0xf9, 0x04, 0x77, 0x37, - 0x36, 0xeb, 0xef, 0xd5, 0x2d, 0xfd, 0xd1, 0x0d, 0xd9, 0x31, 0x8b, 0xa9, 0x77, 0xe4, 0xe9, 0xbf, - 0x74, 0xcc, 0x9e, 0xfe, 0xec, 0xe8, 0x5c, 0xd8, 0xc0, 0x13, 0x70, 0x47, 0x2c, 0x65, 0x82, 0xfd, - 0xd4, 0xd9, 0xb4, 0xc2, 0xc6, 0xc4, 0x55, 0x3f, 0xef, 0xe9, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x6a, 0xbc, 0x1d, 0xa9, 0xcb, 0x02, 0x00, 0x00, +func init() { proto.RegisterFile("cloud.proto", fileDescriptor_cloud_877544bb241d427f) } + +var fileDescriptor_cloud_877544bb241d427f = []byte{ + // 438 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0xd1, 0x8a, 0xd3, 0x40, + 0x14, 0xed, 0x34, 0x6d, 0x9a, 0xde, 0xae, 0x4b, 0xbc, 0xfa, 0x30, 0x14, 0xd1, 0x90, 0x07, 0x09, + 0x3e, 0x14, 0xa9, 0x82, 0x8b, 0xeb, 0x8b, 0x66, 0x5d, 0x61, 0xa1, 0x2a, 0xb3, 0xe2, 0xfb, 0xb4, + 0x1d, 0x4a, 0x30, 0xc9, 0x84, 0xcc, 0x44, 0x28, 0x7e, 0x87, 0xff, 0xe6, 0x7f, 0xf8, 0x03, 0x32, + 0x33, 0xc9, 0x96, 0xb8, 0xe2, 0xd2, 0xb7, 0x7b, 0xce, 0x9c, 0xc3, 0x9c, 0x7b, 0x32, 0x81, 0xd9, + 0x26, 0x97, 0xcd, 0x76, 0x51, 0xd5, 0x52, 0x4b, 0x0c, 0x2c, 0xa8, 0xab, 0x4d, 0xfc, 0x9b, 0xc0, + 0xe4, 0x4a, 0xae, 0xaf, 0x2b, 0xb1, 0x41, 0x0a, 0x93, 0xaf, 0xa2, 0x56, 0x99, 0x2c, 0x29, 0x89, + 0x48, 0x32, 0x65, 0x1d, 0x44, 0x84, 0xd1, 0x47, 0x5e, 0x08, 0x3a, 0xb4, 0xb4, 0x9d, 0x31, 0x04, + 0x2f, 0x2d, 0xb6, 0xd4, 0x8b, 0xbc, 0x64, 0xca, 0xcc, 0x68, 0x54, 0x6f, 0xeb, 0x9d, 0xa2, 0x23, + 0x4b, 0xd9, 0x19, 0xe7, 0x10, 0xac, 0x44, 0x21, 0xeb, 0xfd, 0x87, 0x77, 0x74, 0x1c, 0x91, 0x64, + 0xcc, 0x6e, 0x30, 0x9e, 0x43, 0x70, 0x99, 0xe5, 0xe2, 0x82, 0x6b, 0x4e, 0x27, 0x91, 0x97, 0xcc, + 0x96, 0x4f, 0x16, 0x5d, 0xb0, 0x45, 0x1b, 0x6a, 0xd1, 0x29, 0xde, 0x97, 0xba, 0xde, 0xb3, 0x1b, + 0xc3, 0xfc, 0x1c, 0xee, 0xf5, 0x8e, 0x4c, 0x9e, 0x6f, 0x62, 0xdf, 0x26, 0x37, 0x23, 0x3e, 0x84, + 0xf1, 0x77, 0x9e, 0x37, 0x2e, 0xf6, 0x09, 0x73, 0xe0, 0xf5, 0xf0, 0x8c, 0xc4, 0x3f, 0x09, 0x4c, + 0xcd, 0x05, 0x9a, 0xeb, 0x46, 0x61, 0x02, 0xbe, 0x9b, 0xac, 0xf9, 0x74, 0x19, 0x1e, 0x52, 0x38, + 0x9e, 0xb5, 0xe7, 0xa6, 0xa1, 0x95, 0x50, 0x8a, 0xef, 0xba, 0x2a, 0x3a, 0x88, 0x8f, 0x60, 0x7a, + 0xad, 0x79, 0xad, 0xbf, 0x64, 0x85, 0xa0, 0x5e, 0x44, 0x12, 0x8f, 0x1d, 0x08, 0x7c, 0x0a, 0xa7, + 0xa9, 0x2c, 0xaa, 0x5c, 0xe8, 0x4c, 0x96, 0x56, 0x32, 0xb2, 0x92, 0xbf, 0xd8, 0xf8, 0x87, 0x8d, + 0xf5, 0xa9, 0xd1, 0x55, 0xa3, 0xf1, 0x25, 0x8c, 0xcd, 0x86, 0x26, 0x95, 0xe9, 0xe6, 0x71, 0xaf, + 0x1b, 0xa7, 0xb1, 0xed, 0x28, 0x57, 0x8d, 0x13, 0xcf, 0xcf, 0x00, 0x0e, 0xe4, 0x51, 0xa5, 0xbc, + 0xb2, 0x2f, 0xc1, 0x7e, 0xdb, 0xa3, 0x5e, 0xc2, 0xb3, 0x37, 0x5d, 0x7f, 0x78, 0x02, 0x41, 0xbb, + 0x91, 0x08, 0x07, 0x08, 0xe0, 0x5f, 0xf2, 0x2c, 0x17, 0xdb, 0x90, 0xe0, 0x0c, 0x26, 0xab, 0x4c, + 0xa9, 0xac, 0xdc, 0x85, 0x43, 0x03, 0x58, 0x53, 0x96, 0x06, 0x78, 0xcb, 0x5f, 0x04, 0x82, 0xd4, + 0x6c, 0xc6, 0x3e, 0xa7, 0xb8, 0x04, 0x9f, 0x35, 0xe5, 0x95, 0x5c, 0xe3, 0xfd, 0x5b, 0x4f, 0x61, + 0xfe, 0xa0, 0x4f, 0xd9, 0x2b, 0xe3, 0x81, 0xf1, 0xb4, 0xd7, 0xf7, 0x3d, 0x26, 0xdb, 0x7f, 0x3c, + 0x6d, 0xcb, 0x77, 0x7a, 0x9c, 0x2e, 0x1e, 0xe0, 0x73, 0xf0, 0x2f, 0x84, 0x59, 0xed, 0x5f, 0x9e, + 0xdb, 0x54, 0x3c, 0x58, 0xfb, 0xf6, 0x6f, 0x7b, 0xf1, 0x27, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x87, + 0xfb, 0xdf, 0x7c, 0x03, 0x00, 0x00, } diff --git a/cloud/cloudrpc/cloudrpcgojs/cloud.pb.gopherjs.go b/cloud/cloudrpc/cloudrpcgojs/cloud.pb.gopherjs.go index e492259b4..40938a298 100644 --- a/cloud/cloudrpc/cloudrpcgojs/cloud.pb.gopherjs.go +++ b/cloud/cloudrpc/cloudrpcgojs/cloud.pb.gopherjs.go @@ -27,6 +27,32 @@ import ( // is compatible with the jspb package it is being compiled against. const _ = jspb.JspbPackageIsVersion2 +type Status int + +const ( + Status_Complete Status = 0 + Status_Failed Status = 1 + Status_Missing Status = 2 + Status_Running Status = 3 +) + +var Status_name = map[int]string{ + 0: "Complete", + 1: "Failed", + 2: "Missing", + 3: "Running", +} +var Status_value = map[string]int{ + "Complete": 0, + "Failed": 1, + "Missing": 2, + "Running": 3, +} + +func (x Status) String() string { + return Status_name[int(x)] +} + // JobSpec is the input for the RunJob service. type JobSpec struct { // Version is the required InMAP version. @@ -195,25 +221,65 @@ func (m *JobSpec) Unmarshal(rawBytes []byte) (*JobSpec, error) { type JobStatus struct { // Status holds the current status of the job. - Status string + Status Status + Message string + // Unix time, the number of seconds elapsed since January 1, 1970 UTC + StartTime int64 + CompletionTime int64 } // GetStatus gets the Status of the JobStatus. -func (m *JobStatus) GetStatus() (x string) { +func (m *JobStatus) GetStatus() (x Status) { if m == nil { return x } return m.Status } +// GetMessage gets the Message of the JobStatus. +func (m *JobStatus) GetMessage() (x string) { + if m == nil { + return x + } + return m.Message +} + +// GetStartTime gets the StartTime of the JobStatus. +func (m *JobStatus) GetStartTime() (x int64) { + if m == nil { + return x + } + return m.StartTime +} + +// GetCompletionTime gets the CompletionTime of the JobStatus. +func (m *JobStatus) GetCompletionTime() (x int64) { + if m == nil { + return x + } + return m.CompletionTime +} + // MarshalToWriter marshals JobStatus to the provided writer. func (m *JobStatus) MarshalToWriter(writer jspb.Writer) { if m == nil { return } - if len(m.Status) > 0 { - writer.WriteString(1, m.Status) + if int(m.Status) != 0 { + writer.WriteEnum(1, int(m.Status)) + } + + if len(m.Message) > 0 { + writer.WriteString(2, m.Message) + } + + if m.StartTime != 0 { + writer.WriteInt64(3, m.StartTime) + } + + if m.CompletionTime != 0 { + writer.WriteInt64(4, m.CompletionTime) } return @@ -235,7 +301,13 @@ func (m *JobStatus) UnmarshalFromReader(reader jspb.Reader) *JobStatus { switch reader.GetFieldNumber() { case 1: - m.Status = reader.ReadString() + m.Status = Status(reader.ReadEnum()) + case 2: + m.Message = reader.ReadString() + case 3: + m.StartTime = reader.ReadInt64() + case 4: + m.CompletionTime = reader.ReadInt64() default: reader.SkipField() } @@ -435,8 +507,8 @@ type CloudRPCClient interface { // RunJob performs an InMAP simulation and returns the paths to the // output file(s). RunJob(ctx context.Context, in *JobSpec, opts ...grpcweb.CallOption) (*JobStatus, error) - // OutputAddresses returns status and the addresses the output file(s) of the - // requested simulation name. + // Status returns the status of the simulation with the + // requested name. Status(ctx context.Context, in *JobName, opts ...grpcweb.CallOption) (*JobStatus, error) // Output returns the output file(s) of the // requested simulation name. diff --git a/cloud/config.go b/cloud/config.go index 86b6c0452..5810bc3ba 100644 --- a/cloud/config.go +++ b/cloud/config.go @@ -59,6 +59,34 @@ func (c *Client) jobOutputAddresses(ctx context.Context, name string, cmd []stri return o, nil } +func (c *Client) checkOutputs(ctx context.Context, name string, cmd []string) error { + addrs, err := c.jobOutputAddresses(ctx, name, cmd) + if err != nil { + return err + } + bucket, err := OpenBucket(ctx, c.bucketName) + if err != nil { + return err + } + for _, addr := range addrs { + for _, fname := range expandShp(addr) { + url, err := url.Parse(fname) + if err != nil { + return err + } + r, err := bucket.NewReader(ctx, strings.TrimLeft(url.Path, "/")) + if err != nil { + return err + } + if r.Size() == 0 { + + } + r.Close() + } + } + return nil +} + // setOutputPaths changes the paths of the output files in the given // job specification so that they match // the locations where the files should be stored. diff --git a/cloud/jobspec.go b/cloud/jobspec.go index 998821272..8b093154e 100644 --- a/cloud/jobspec.go +++ b/cloud/jobspec.go @@ -181,6 +181,9 @@ func fileContentsAndSum(filePath string) ([]byte, string, error) { if _, err := io.Copy(&dst, src); err != nil { return nil, "", err } + if err := src.Close(); err != nil { + return nil, "", err + } sumBytes := sha256.Sum256(dst.Bytes()) return dst.Bytes(), fmt.Sprintf("%x", sumBytes[0:sha256.Size]), nil } diff --git a/inmaputil/cloud_test.go b/inmaputil/cloud_test.go index 6082e4be3..dcca5769d 100644 --- a/inmaputil/cloud_test.go +++ b/inmaputil/cloud_test.go @@ -22,9 +22,11 @@ import ( "context" "io/ioutil" "os" + "reflect" "testing" "github.com/spatialmodel/inmap/cloud" + "github.com/spatialmodel/inmap/cloud/cloudrpc" ) func TestCloud(t *testing.T) { @@ -50,9 +52,11 @@ func TestCloud(t *testing.T) { t.Fatal(err) } - wantStatus := "&JobStatus{Conditions:[],StartTime:,CompletionTime:,Active:0,Succeeded:0,Failed:0,}" - if status.Status != wantStatus { - t.Errorf("wrong status: %s != %s", status.Status, wantStatus) + wantStatus := &cloudrpc.JobStatus{ + // Status: "&JobStatus{Conditions:[],StartTime:,CompletionTime:,Active:0,Succeeded:0,Failed:0,}", + } + if !reflect.DeepEqual(status, wantStatus) { + t.Errorf("wrong status: %v != %v", status, wantStatus) } })