diff --git a/Makefile b/Makefile index e150143bb9..f523c97415 100644 --- a/Makefile +++ b/Makefile @@ -52,13 +52,13 @@ checkprotos: generate ## check if protobufs needs to be generated again # imports vet: binaries ## run go vet @echo "🐳 $@" - @test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v 'constant [0-9]* not a string in call to Errorf' | grep -v 'exit status 1' | tee /dev/stderr)" + @test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v 'constant [0-9]* not a string in call to Errorf' | grep -v 'timestamp_test.go' | grep -v 'exit status 1' | tee /dev/stderr)" fmt: ## run go fmt @echo "🐳 $@" @test -z "$$(gofmt -s -l . | grep -v vendor/ | grep -v ".pb.go$$" | tee /dev/stderr)" || \ (echo "👹 please format Go code with 'gofmt -s'" && false) - @test -z "$$(find . -path ./vendor -prune -o -name '*.proto' -type f -exec grep -Hn -e "^ " {} \; | tee /dev/stderr)" || \ + @test -z "$$(find . -path ./vendor -prune -o ! -name timestamp.proto -name '*.proto' -type f -exec grep -Hn -e "^ " {} \; | tee /dev/stderr)" || \ (echo "👹 please indent proto files with tabs only" && false) @test -z "$$(find . -path ./vendor -prune -o -name '*.proto' -type f -exec grep -Hn "id = " {} \; | grep -v gogoproto.customname | tee /dev/stderr)" || \ (echo "👹 id fields in proto files must have a gogoproto.customname set" && false) diff --git a/agent/agent.go b/agent/agent.go index bdb7860e9d..725b25e627 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -10,6 +10,7 @@ import ( "github.com/docker/swarm-v2/agent/exec" "github.com/docker/swarm-v2/api" "github.com/docker/swarm-v2/log" + "github.com/docker/swarm-v2/protobuf/ptypes" "golang.org/x/net/context" "google.golang.org/grpc" ) @@ -404,6 +405,13 @@ func (a *Agent) updateStatus(ctx context.Context, report taskStatusReport) error status.State = report.state } + tsp, err := ptypes.TimestampProto(report.timestamp) + if err != nil { + return err + } + + status.Timestamp = tsp + if reflect.DeepEqual(status, original) { return errTaskStatusUpdateNoChange } @@ -522,10 +530,11 @@ func (a *Agent) removeTask(ctx context.Context, t *api.Task) error { } type taskStatusReport struct { - taskID string - state api.TaskState - err error - response chan error + timestamp time.Time + taskID string + state api.TaskState + err error + response chan error } func (a *Agent) report(ctx context.Context, taskID string, state api.TaskState, errs ...error) error { @@ -543,10 +552,12 @@ func (a *Agent) report(ctx context.Context, taskID string, state api.TaskState, select { case a.statusq <- taskStatusReport{ - taskID: taskID, - state: state, - err: err, - response: response}: + timestamp: time.Now(), + taskID: taskID, + state: state, + err: err, + response: response, + }: select { case err := <-response: return err diff --git a/api/gen.go b/api/gen.go index 5737aeb699..6e58694b9f 100644 --- a/api/gen.go +++ b/api/gen.go @@ -1,4 +1,4 @@ -//go:generate protoc -I.:../vendor:../vendor/github.com/gogo/protobuf --gogoswarm_out=plugins=grpc+deepcopy+raftproxy,import_path=github.com/docker/swarm-v2/api,Mgogoproto/gogo.proto=github.com/gogo/protobuf/gogoproto:. types.proto specs.proto objects.proto cluster.proto dispatcher.proto raft.proto +//go:generate protoc -I.:../vendor:../vendor/github.com/gogo/protobuf --gogoswarm_out=plugins=grpc+deepcopy+raftproxy,import_path=github.com/docker/swarm-v2/api,Mgogoproto/gogo.proto=github.com/gogo/protobuf/gogoproto,Mtimestamp/timestamp.proto=github.com/docker/swarm-v2/api/timestamp:. types.proto specs.proto objects.proto cluster.proto dispatcher.proto raft.proto // BUG(stevvooe): The generation line below is nearly identical to the line // above, except that deepcopy is disabled. There is a bug in deepcopy that diff --git a/api/timestamp/gen.go b/api/timestamp/gen.go new file mode 100644 index 0000000000..460b71ebfd --- /dev/null +++ b/api/timestamp/gen.go @@ -0,0 +1,3 @@ +//go:generate protoc -I.:../../vendor:../../vendor/github.com/gogo/protobuf --gogoswarm_out=plugins=grpc+deepcopy+raftproxy,import_path=github.com/docker/swarm-v2/api/timestamp,Mgogoproto/gogo.proto=github.com/gogo/protobuf/gogoproto:. timestamp.proto + +package timestamp diff --git a/api/timestamp/timestamp.pb.go b/api/timestamp/timestamp.pb.go new file mode 100644 index 0000000000..178b6fe487 --- /dev/null +++ b/api/timestamp/timestamp.pb.go @@ -0,0 +1,469 @@ +// Code generated by protoc-gen-gogo. +// source: timestamp.proto +// DO NOT EDIT! + +/* + Package timestamp is a generated protocol buffer package. + + It is generated from these files: + timestamp.proto + + It has these top-level messages: + Timestamp +*/ +package timestamp + +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" + +import strings "strings" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import sort "sort" +import strconv "strconv" +import reflect "reflect" + +import io "io" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +const _ = proto.GoGoProtoPackageIsVersion1 + +// A Timestamp represents a point in time independent of any time zone +// or calendar, represented as seconds and fractions of seconds at +// nanosecond resolution in UTC Epoch time. It is encoded using the +// Proleptic Gregorian Calendar which extends the Gregorian calendar +// backwards to year one. It is encoded assuming all minutes are 60 +// seconds long, i.e. leap seconds are "smeared" so that no leap second +// table is needed for interpretation. Range is from +// 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. +// By restricting to that range, we ensure that we can convert to +// and from RFC 3339 date strings. +// See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). +// +// Example 1: Compute Timestamp from POSIX `time()`. +// +// Timestamp timestamp; +// timestamp.set_seconds(time(NULL)); +// timestamp.set_nanos(0); +// +// Example 2: Compute Timestamp from POSIX `gettimeofday()`. +// +// struct timeval tv; +// gettimeofday(&tv, NULL); +// +// Timestamp timestamp; +// timestamp.set_seconds(tv.tv_sec); +// timestamp.set_nanos(tv.tv_usec * 1000); +// +// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. +// +// FILETIME ft; +// GetSystemTimeAsFileTime(&ft); +// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; +// +// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z +// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. +// Timestamp timestamp; +// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); +// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); +// +// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. +// +// long millis = System.currentTimeMillis(); +// +// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) +// .setNanos((int) ((millis % 1000) * 1000000)).build(); +// +// +// Example 5: Compute Timestamp from current time in Python. +// +// now = time.time() +// seconds = int(now) +// nanos = int((now - seconds) * 10**9) +// timestamp = Timestamp(seconds=seconds, nanos=nanos) +// +// +type Timestamp struct { + // Represents seconds of UTC time since Unix epoch + // 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to + // 9999-12-31T23:59:59Z inclusive. + Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"` + // Non-negative fractions of a second at nanosecond resolution. Negative + // second values with fractions must still have non-negative nanos values + // that count forward in time. Must be from 0 to 999,999,999 + // inclusive. + Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"` +} + +func (m *Timestamp) Reset() { *m = Timestamp{} } +func (*Timestamp) ProtoMessage() {} +func (*Timestamp) Descriptor() ([]byte, []int) { return fileDescriptorTimestamp, []int{0} } + +func init() { + proto.RegisterType((*Timestamp)(nil), "docker.cluster.api.Timestamp") +} + +func (m *Timestamp) Copy() *Timestamp { + if m == nil { + return nil + } + + o := &Timestamp{ + Seconds: m.Seconds, + Nanos: m.Nanos, + } + + return o +} + +func (this *Timestamp) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "×tamp.Timestamp{") + s = append(s, "Seconds: "+fmt.Sprintf("%#v", this.Seconds)+",\n") + s = append(s, "Nanos: "+fmt.Sprintf("%#v", this.Nanos)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringTimestamp(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func extensionToGoStringTimestamp(e map[int32]github_com_gogo_protobuf_proto.Extension) string { + if e == nil { + return "nil" + } + s := "map[int32]proto.Extension{" + keys := make([]int, 0, len(e)) + for k := range e { + keys = append(keys, int(k)) + } + sort.Ints(keys) + ss := []string{} + for _, k := range keys { + ss = append(ss, strconv.Itoa(k)+": "+e[int32(k)].GoString()) + } + s += strings.Join(ss, ",") + "}" + return s +} +func (m *Timestamp) Marshal() (data []byte, err error) { + size := m.Size() + data = make([]byte, size) + n, err := m.MarshalTo(data) + if err != nil { + return nil, err + } + return data[:n], nil +} + +func (m *Timestamp) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Seconds != 0 { + data[i] = 0x8 + i++ + i = encodeVarintTimestamp(data, i, uint64(m.Seconds)) + } + if m.Nanos != 0 { + data[i] = 0x10 + i++ + i = encodeVarintTimestamp(data, i, uint64(m.Nanos)) + } + return i, nil +} + +func encodeFixed64Timestamp(data []byte, offset int, v uint64) int { + data[offset] = uint8(v) + data[offset+1] = uint8(v >> 8) + data[offset+2] = uint8(v >> 16) + data[offset+3] = uint8(v >> 24) + data[offset+4] = uint8(v >> 32) + data[offset+5] = uint8(v >> 40) + data[offset+6] = uint8(v >> 48) + data[offset+7] = uint8(v >> 56) + return offset + 8 +} +func encodeFixed32Timestamp(data []byte, offset int, v uint32) int { + data[offset] = uint8(v) + data[offset+1] = uint8(v >> 8) + data[offset+2] = uint8(v >> 16) + data[offset+3] = uint8(v >> 24) + return offset + 4 +} +func encodeVarintTimestamp(data []byte, offset int, v uint64) int { + for v >= 1<<7 { + data[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + data[offset] = uint8(v) + return offset + 1 +} + +func (m *Timestamp) Size() (n int) { + var l int + _ = l + if m.Seconds != 0 { + n += 1 + sovTimestamp(uint64(m.Seconds)) + } + if m.Nanos != 0 { + n += 1 + sovTimestamp(uint64(m.Nanos)) + } + return n +} + +func sovTimestamp(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozTimestamp(x uint64) (n int) { + return sovTimestamp(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *Timestamp) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Timestamp{`, + `Seconds:` + fmt.Sprintf("%v", this.Seconds) + `,`, + `Nanos:` + fmt.Sprintf("%v", this.Nanos) + `,`, + `}`, + }, "") + return s +} +func valueToStringTimestamp(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *Timestamp) Unmarshal(data []byte) error { + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTimestamp + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Timestamp: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Timestamp: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Seconds", wireType) + } + m.Seconds = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTimestamp + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + m.Seconds |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Nanos", wireType) + } + m.Nanos = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTimestamp + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + m.Nanos |= (int32(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTimestamp(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTimestamp + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTimestamp(data []byte) (n int, err error) { + l := len(data) + iNdEx := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTimestamp + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTimestamp + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if data[iNdEx-1] < 0x80 { + break + } + } + return iNdEx, nil + case 1: + iNdEx += 8 + return iNdEx, nil + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTimestamp + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + iNdEx += length + if length < 0 { + return 0, ErrInvalidLengthTimestamp + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTimestamp + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + innerWire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + innerWireType := int(innerWire & 0x7) + if innerWireType == 4 { + break + } + next, err := skipTimestamp(data[start:]) + if err != nil { + return 0, err + } + iNdEx = start + next + } + return iNdEx, nil + case 4: + return iNdEx, nil + case 5: + iNdEx += 4 + return iNdEx, nil + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + } + panic("unreachable") +} + +var ( + ErrInvalidLengthTimestamp = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTimestamp = fmt.Errorf("proto: integer overflow") +) + +var fileDescriptorTimestamp = []byte{ + // 196 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0x2f, 0xc9, 0xcc, 0x4d, + 0x2d, 0x2e, 0x49, 0xcc, 0x2d, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x4a, 0xc9, 0x4f, + 0xce, 0x4e, 0x2d, 0xd2, 0x4b, 0xce, 0x29, 0x2d, 0x2e, 0x01, 0xd2, 0x89, 0x05, 0x99, 0x4a, 0xd6, + 0x5c, 0x9c, 0x21, 0x30, 0x65, 0x42, 0x12, 0x5c, 0xec, 0xc5, 0xa9, 0xc9, 0xf9, 0x79, 0x29, 0xc5, + 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0xcc, 0x41, 0x30, 0xae, 0x90, 0x08, 0x17, 0x6b, 0x5e, 0x62, 0x5e, + 0x7e, 0xb1, 0x04, 0x13, 0x50, 0x9c, 0x35, 0x08, 0xc2, 0x71, 0x2a, 0x38, 0xf1, 0x50, 0x8e, 0xe1, + 0x06, 0x10, 0x7f, 0x78, 0x28, 0xc7, 0xd8, 0xf0, 0x48, 0x8e, 0xf1, 0x04, 0x10, 0x5f, 0x00, 0xe2, + 0x07, 0x40, 0xcc, 0x25, 0x9c, 0x9c, 0x9f, 0xab, 0x97, 0x9e, 0x9f, 0x9f, 0x9e, 0x93, 0x0a, 0x71, + 0x40, 0x52, 0x69, 0x9a, 0x13, 0x1f, 0xdc, 0xb6, 0x00, 0x90, 0x50, 0x00, 0xe3, 0x02, 0x46, 0xc6, + 0x1f, 0x8c, 0x8c, 0x8b, 0x98, 0x98, 0xdd, 0x03, 0x9c, 0x56, 0x31, 0xc9, 0xb9, 0x43, 0xd4, 0x07, + 0x40, 0xd5, 0xeb, 0x85, 0xa7, 0xe6, 0xe4, 0x78, 0xe7, 0xe5, 0x97, 0xe7, 0x85, 0x54, 0x16, 0xa4, + 0x16, 0x27, 0xb1, 0x81, 0x0d, 0x32, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x15, 0xf6, 0xa8, 0xfe, + 0xdc, 0x00, 0x00, 0x00, +} diff --git a/api/timestamp/timestamp.proto b/api/timestamp/timestamp.proto new file mode 100644 index 0000000000..22dc6676dd --- /dev/null +++ b/api/timestamp/timestamp.proto @@ -0,0 +1,121 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package docker.cluster.api; + +// TODO(stevvooe): We cannot use the google version because of the naive size +// and deepcopy extensions. For now, we just generate this ourselves. This can +// be fixed. +// package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; + +// TODO(stevvooe): Commenting this out from the maddening behavior of google's +// Go protobuf implementation. + +//option go_package = "github.com/golang/protobuf/ptypes/timestamp"; + +option java_package = "com.google.protobuf"; +option java_outer_classname = "TimestampProto"; +option java_multiple_files = true; +option java_generate_equals_and_hash = true; +option objc_class_prefix = "GPB"; + +// A Timestamp represents a point in time independent of any time zone +// or calendar, represented as seconds and fractions of seconds at +// nanosecond resolution in UTC Epoch time. It is encoded using the +// Proleptic Gregorian Calendar which extends the Gregorian calendar +// backwards to year one. It is encoded assuming all minutes are 60 +// seconds long, i.e. leap seconds are "smeared" so that no leap second +// table is needed for interpretation. Range is from +// 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. +// By restricting to that range, we ensure that we can convert to +// and from RFC 3339 date strings. +// See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). +// +// Example 1: Compute Timestamp from POSIX `time()`. +// +// Timestamp timestamp; +// timestamp.set_seconds(time(NULL)); +// timestamp.set_nanos(0); +// +// Example 2: Compute Timestamp from POSIX `gettimeofday()`. +// +// struct timeval tv; +// gettimeofday(&tv, NULL); +// +// Timestamp timestamp; +// timestamp.set_seconds(tv.tv_sec); +// timestamp.set_nanos(tv.tv_usec * 1000); +// +// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. +// +// FILETIME ft; +// GetSystemTimeAsFileTime(&ft); +// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; +// +// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z +// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. +// Timestamp timestamp; +// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); +// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); +// +// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. +// +// long millis = System.currentTimeMillis(); +// +// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) +// .setNanos((int) ((millis % 1000) * 1000000)).build(); +// +// +// Example 5: Compute Timestamp from current time in Python. +// +// now = time.time() +// seconds = int(now) +// nanos = int((now - seconds) * 10**9) +// timestamp = Timestamp(seconds=seconds, nanos=nanos) +// +// +message Timestamp { + + // Represents seconds of UTC time since Unix epoch + // 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to + // 9999-12-31T23:59:59Z inclusive. + int64 seconds = 1; + + // Non-negative fractions of a second at nanosecond resolution. Negative + // second values with fractions must still have non-negative nanos values + // that count forward in time. Must be from 0 to 999,999,999 + // inclusive. + int32 nanos = 2; +} diff --git a/api/types.pb.go b/api/types.pb.go index fe6e32e493..f4600aa940 100644 --- a/api/types.pb.go +++ b/api/types.pb.go @@ -97,6 +97,7 @@ package api import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" +import docker_cluster_api "github.com/docker/swarm-v2/api/timestamp" import _ "github.com/gogo/protobuf/gogoproto" import strings "strings" @@ -456,8 +457,9 @@ func _Container_NetworkAttachment_OneofSizer(msg proto.Message) (n int) { } type TaskStatus struct { + Timestamp *docker_cluster_api.Timestamp `protobuf:"bytes,1,opt,name=timestamp" json:"timestamp,omitempty"` // State expresses the current state of the task. - State TaskState `protobuf:"varint,1,opt,name=state,proto3,enum=docker.cluster.api.TaskState" json:"state,omitempty"` + State TaskState `protobuf:"varint,2,opt,name=state,proto3,enum=docker.cluster.api.TaskState" json:"state,omitempty"` // Err is set if the task is in an error state. // // The following states should report a companion error: @@ -465,7 +467,7 @@ type TaskStatus struct { // FAILED, REJECTED // // TODO(stevvooe) Integrate this field with the error interface. - Err string `protobuf:"bytes,2,opt,name=err,proto3" json:"err,omitempty"` + Err string `protobuf:"bytes,3,opt,name=err,proto3" json:"err,omitempty"` } func (m *TaskStatus) Reset() { *m = TaskStatus{} } @@ -709,8 +711,9 @@ func (m *TaskStatus) Copy() *TaskStatus { } o := &TaskStatus{ - State: m.State, - Err: m.Err, + Timestamp: m.Timestamp.Copy(), + State: m.State, + Err: m.Err, } return o @@ -927,8 +930,11 @@ func (this *TaskStatus) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 6) + s := make([]string, 0, 7) s = append(s, "&api.TaskStatus{") + if this.Timestamp != nil { + s = append(s, "Timestamp: "+fmt.Sprintf("%#v", this.Timestamp)+",\n") + } s = append(s, "State: "+fmt.Sprintf("%#v", this.State)+",\n") s = append(s, "Err: "+fmt.Sprintf("%#v", this.Err)+",\n") s = append(s, "}") @@ -1407,13 +1413,23 @@ func (m *TaskStatus) MarshalTo(data []byte) (int, error) { _ = i var l int _ = l + if m.Timestamp != nil { + data[i] = 0xa + i++ + i = encodeVarintTypes(data, i, uint64(m.Timestamp.Size())) + n8, err := m.Timestamp.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n8 + } if m.State != 0 { - data[i] = 0x8 + data[i] = 0x10 i++ i = encodeVarintTypes(data, i, uint64(m.State)) } if len(m.Err) > 0 { - data[i] = 0x12 + data[i] = 0x1a i++ i = encodeVarintTypes(data, i, uint64(len(m.Err))) i += copy(data[i:], m.Err) @@ -1539,11 +1555,11 @@ func (m *IPAMOptions) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintTypes(data, i, uint64(m.Driver.Size())) - n8, err := m.Driver.MarshalTo(data[i:]) + n9, err := m.Driver.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n8 + i += n9 } if len(m.Configurations) > 0 { for _, msg := range m.Configurations { @@ -1775,6 +1791,10 @@ func (m *Container_NetworkAttachment_NetworkID) Size() (n int) { func (m *TaskStatus) Size() (n int) { var l int _ = l + if m.Timestamp != nil { + l = m.Timestamp.Size() + n += 1 + l + sovTypes(uint64(l)) + } if m.State != 0 { n += 1 + sovTypes(uint64(m.State)) } @@ -2001,6 +2021,7 @@ func (this *TaskStatus) String() string { return "nil" } s := strings.Join([]string{`&TaskStatus{`, + `Timestamp:` + strings.Replace(fmt.Sprintf("%v", this.Timestamp), "Timestamp", "docker_cluster_api.Timestamp", 1) + `,`, `State:` + fmt.Sprintf("%v", this.State) + `,`, `Err:` + fmt.Sprintf("%v", this.Err) + `,`, `}`, @@ -3186,6 +3207,39 @@ func (m *TaskStatus) Unmarshal(data []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Timestamp == nil { + m.Timestamp = &docker_cluster_api.Timestamp{} + } + if err := m.Timestamp.Unmarshal(data[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) } @@ -3204,7 +3258,7 @@ func (m *TaskStatus) Unmarshal(data []byte) error { break } } - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Err", wireType) } @@ -4028,82 +4082,84 @@ var ( ) var fileDescriptorTypes = []byte{ - // 1220 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x94, 0x56, 0xcf, 0x73, 0xdb, 0xc4, - 0x17, 0x8f, 0xfc, 0x5b, 0xcf, 0x4e, 0xab, 0xec, 0x37, 0xdf, 0x8e, 0x2b, 0xda, 0xb4, 0x15, 0xed, - 0x50, 0x38, 0xb8, 0x8c, 0x03, 0x4c, 0x27, 0x39, 0x29, 0xfe, 0xd1, 0x9a, 0x26, 0xb2, 0x67, 0xed, - 0x34, 0x53, 0x2e, 0x19, 0x45, 0xda, 0x38, 0x22, 0x96, 0x64, 0x56, 0x72, 0x82, 0x39, 0x71, 0x64, - 0xe8, 0x85, 0x3b, 0xc3, 0x70, 0xa0, 0x7f, 0x05, 0x7f, 0x41, 0x8f, 0x1c, 0x39, 0x31, 0xb4, 0x27, - 0x8e, 0xfc, 0x09, 0xec, 0x4a, 0x2b, 0xd9, 0x71, 0x0c, 0x84, 0x83, 0xe2, 0x7d, 0x6f, 0x3f, 0xfb, - 0xde, 0xfb, 0xbc, 0x1f, 0xbb, 0x81, 0x72, 0x38, 0x1d, 0x93, 0xa0, 0x36, 0xa6, 0x7e, 0xe8, 0x23, - 0x64, 0xfb, 0xd6, 0x29, 0xa1, 0x35, 0x6b, 0x34, 0x09, 0x42, 0xf6, 0x6b, 0x8e, 0x1d, 0x75, 0x7d, - 0xe8, 0x0f, 0xfd, 0x68, 0xfb, 0x11, 0x5f, 0xc5, 0x48, 0xed, 0x0e, 0x14, 0x9f, 0x13, 0x1a, 0x38, - 0xbe, 0x87, 0xd6, 0x21, 0xef, 0x78, 0x36, 0xf9, 0xb2, 0x2a, 0xdd, 0x95, 0x1e, 0xe6, 0x70, 0x2c, - 0x68, 0x2f, 0x40, 0xc6, 0x24, 0xf0, 0x27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f, 0xa5, 0x46, 0x77, 0xaf, 0xb7, 0xdb, 0x1a, 0xb4, 0x14, 0x79, 0x21, 0xe2, - 0x86, 0xef, 0x8e, 0x47, 0x84, 0x13, 0xbb, 0x03, 0x85, 0xb6, 0xde, 0xd9, 0x65, 0xdc, 0x41, 0xfd, - 0x1f, 0xc3, 0x5c, 0x4f, 0x31, 0x6d, 0xd3, 0x19, 0xc5, 0xe9, 0xc1, 0xad, 0x4f, 0xe3, 0x37, 0xa8, - 0xbc, 0xe0, 0x0b, 0x93, 0xcf, 0xd9, 0xe3, 0x1f, 0x83, 0xda, 0x1d, 0x43, 0xdf, 0xed, 0x7c, 0xd6, - 0x52, 0x2a, 0x0b, 0xa0, 0xb6, 0xe3, 0x99, 0x23, 0xe7, 0x2b, 0x82, 0xde, 0x61, 0xcf, 0x1c, 0x4b, - 0x8e, 0xb2, 0xaa, 0xae, 0x31, 0xc0, 0x6a, 0x0a, 0x68, 0xb2, 0xdc, 0xa8, 0x6b, 0xdf, 0xfc, 0xb4, - 0xb1, 0xf2, 0xf3, 0xab, 0x8d, 0x59, 0xfd, 0x77, 0x6e, 0xbd, 0x7e, 0xb3, 0xb1, 0xf2, 0x2b, 0xfb, - 0xfe, 0x7c, 0xb3, 0x21, 0x7d, 0xfd, 0x76, 0x43, 0x7a, 0xcd, 0xbe, 0x5f, 0xd8, 0xf7, 0x3b, 0xfb, - 0x8e, 0x0a, 0xd1, 0x3f, 0x6d, 0x9b, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x93, 0x2a, 0x55, 0x14, - 0xed, 0x09, 0x00, 0x00, + // 1249 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x94, 0x56, 0x4d, 0x73, 0xdb, 0x44, + 0x18, 0x8e, 0xbf, 0xed, 0xd7, 0x4e, 0xab, 0x2c, 0xa1, 0xe3, 0x8a, 0x36, 0x6d, 0x45, 0x3b, 0x14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0, 0xd8, 0xd1, 0xbb, 0x7b, 0x58, 0x3b, 0xa8, 0xef, 0x20, 0xe6, + 0x7c, 0x8a, 0xe9, 0x98, 0xce, 0x38, 0xa6, 0x87, 0xb6, 0x3f, 0x8f, 0xbf, 0x60, 0xd5, 0xa5, 0x58, + 0x94, 0x7d, 0x89, 0x7f, 0x1d, 0x62, 0x50, 0xa7, 0x6b, 0xe8, 0x7b, 0xdd, 0x2f, 0xda, 0x4a, 0x6d, + 0x09, 0xd4, 0x71, 0x3c, 0x73, 0xec, 0x7c, 0xc3, 0xc8, 0x7b, 0xf8, 0x91, 0x44, 0x72, 0x94, 0x75, + 0x75, 0x03, 0x01, 0xeb, 0x29, 0xa0, 0x85, 0xdc, 0xa8, 0x1b, 0xdf, 0xfd, 0xb2, 0xb5, 0xf6, 0xeb, + 0x8b, 0xad, 0xf9, 0xf9, 0xef, 0x5e, 0x7a, 0xf9, 0x6a, 0x6b, 0xed, 0x77, 0x7c, 0xfe, 0x7e, 0xb5, + 0x95, 0xf9, 0xf6, 0xf5, 0x56, 0xe6, 0x25, 0x3e, 0xbf, 0xe1, 0xf3, 0x27, 0x3e, 0xcf, 0x8a, 0xd1, + 0x5f, 0xbe, 0x5b, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x46, 0x98, 0x98, 0xb2, 0x46, 0x0a, 0x00, + 0x00, } diff --git a/api/types.proto b/api/types.proto index a451945c65..3f9ddc8654 100644 --- a/api/types.proto +++ b/api/types.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package docker.cluster.api; +import "timestamp/timestamp.proto"; // TODO(stevvooe): use our own until we fix gogoproto/deepcopy import "gogoproto/gogo.proto"; // This file contains types that are common to objects and spec or that are not @@ -135,8 +136,10 @@ enum TaskState { } message TaskStatus { + Timestamp timestamp = 1; + // State expresses the current state of the task. - TaskState state = 1; + TaskState state = 2; // Err is set if the task is in an error state. // @@ -145,7 +148,7 @@ message TaskStatus { // FAILED, REJECTED // // TODO(stevvooe) Integrate this field with the error interface. - string err = 2; + string err = 3; // TODO(stevvooe): Report on runtime statistics. } diff --git a/manager/state/pb/store.pb.go b/manager/state/pb/store.pb.go index d6e9e2d018..d57932c1f2 100644 --- a/manager/state/pb/store.pb.go +++ b/manager/state/pb/store.pb.go @@ -19,8 +19,8 @@ import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" import _ "github.com/gogo/protobuf/gogoproto" -import docker_cluster_api2 "github.com/docker/swarm-v2/api" import docker_cluster_api3 "github.com/docker/swarm-v2/api" +import docker_cluster_api4 "github.com/docker/swarm-v2/api" import strings "strings" import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" @@ -60,11 +60,11 @@ func (Snapshot_Version) EnumDescriptor() ([]byte, []int) { return fileDescriptor // StoreSnapshot is used to store snapshots of the store. type StoreSnapshot struct { - Nodes []*docker_cluster_api2.Node `protobuf:"bytes,1,rep,name=nodes" json:"nodes,omitempty"` - Services []*docker_cluster_api2.Service `protobuf:"bytes,2,rep,name=services" json:"services,omitempty"` - Networks []*docker_cluster_api2.Network `protobuf:"bytes,3,rep,name=networks" json:"networks,omitempty"` - Tasks []*docker_cluster_api2.Task `protobuf:"bytes,4,rep,name=tasks" json:"tasks,omitempty"` - Volumes []*docker_cluster_api2.Volume `protobuf:"bytes,5,rep,name=volumes" json:"volumes,omitempty"` + Nodes []*docker_cluster_api3.Node `protobuf:"bytes,1,rep,name=nodes" json:"nodes,omitempty"` + Services []*docker_cluster_api3.Service `protobuf:"bytes,2,rep,name=services" json:"services,omitempty"` + Networks []*docker_cluster_api3.Network `protobuf:"bytes,3,rep,name=networks" json:"networks,omitempty"` + Tasks []*docker_cluster_api3.Task `protobuf:"bytes,4,rep,name=tasks" json:"tasks,omitempty"` + Volumes []*docker_cluster_api3.Volume `protobuf:"bytes,5,rep,name=volumes" json:"volumes,omitempty"` } func (m *StoreSnapshot) Reset() { *m = StoreSnapshot{} } @@ -73,7 +73,7 @@ func (*StoreSnapshot) Descriptor() ([]byte, []int) { return fileDescriptorStore, // ClusterSnapshot stores cluster membership information in snapshots. type ClusterSnapshot struct { - Members []*docker_cluster_api3.RaftNode `protobuf:"bytes,1,rep,name=members" json:"members,omitempty"` + Members []*docker_cluster_api4.RaftNode `protobuf:"bytes,1,rep,name=members" json:"members,omitempty"` Removed []uint64 `protobuf:"varint,2,rep,name=removed" json:"removed,omitempty"` } @@ -436,11 +436,11 @@ func (this *StoreSnapshot) String() string { return "nil" } s := strings.Join([]string{`&StoreSnapshot{`, - `Nodes:` + strings.Replace(fmt.Sprintf("%v", this.Nodes), "Node", "docker_cluster_api2.Node", 1) + `,`, - `Services:` + strings.Replace(fmt.Sprintf("%v", this.Services), "Service", "docker_cluster_api2.Service", 1) + `,`, - `Networks:` + strings.Replace(fmt.Sprintf("%v", this.Networks), "Network", "docker_cluster_api2.Network", 1) + `,`, - `Tasks:` + strings.Replace(fmt.Sprintf("%v", this.Tasks), "Task", "docker_cluster_api2.Task", 1) + `,`, - `Volumes:` + strings.Replace(fmt.Sprintf("%v", this.Volumes), "Volume", "docker_cluster_api2.Volume", 1) + `,`, + `Nodes:` + strings.Replace(fmt.Sprintf("%v", this.Nodes), "Node", "docker_cluster_api3.Node", 1) + `,`, + `Services:` + strings.Replace(fmt.Sprintf("%v", this.Services), "Service", "docker_cluster_api3.Service", 1) + `,`, + `Networks:` + strings.Replace(fmt.Sprintf("%v", this.Networks), "Network", "docker_cluster_api3.Network", 1) + `,`, + `Tasks:` + strings.Replace(fmt.Sprintf("%v", this.Tasks), "Task", "docker_cluster_api3.Task", 1) + `,`, + `Volumes:` + strings.Replace(fmt.Sprintf("%v", this.Volumes), "Volume", "docker_cluster_api3.Volume", 1) + `,`, `}`, }, "") return s @@ -450,7 +450,7 @@ func (this *ClusterSnapshot) String() string { return "nil" } s := strings.Join([]string{`&ClusterSnapshot{`, - `Members:` + strings.Replace(fmt.Sprintf("%v", this.Members), "RaftNode", "docker_cluster_api3.RaftNode", 1) + `,`, + `Members:` + strings.Replace(fmt.Sprintf("%v", this.Members), "RaftNode", "docker_cluster_api4.RaftNode", 1) + `,`, `Removed:` + fmt.Sprintf("%v", this.Removed) + `,`, `}`, }, "") @@ -531,7 +531,7 @@ func (m *StoreSnapshot) Unmarshal(data []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Nodes = append(m.Nodes, &docker_cluster_api2.Node{}) + m.Nodes = append(m.Nodes, &docker_cluster_api3.Node{}) if err := m.Nodes[len(m.Nodes)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { return err } @@ -562,7 +562,7 @@ func (m *StoreSnapshot) Unmarshal(data []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Services = append(m.Services, &docker_cluster_api2.Service{}) + m.Services = append(m.Services, &docker_cluster_api3.Service{}) if err := m.Services[len(m.Services)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { return err } @@ -593,7 +593,7 @@ func (m *StoreSnapshot) Unmarshal(data []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Networks = append(m.Networks, &docker_cluster_api2.Network{}) + m.Networks = append(m.Networks, &docker_cluster_api3.Network{}) if err := m.Networks[len(m.Networks)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { return err } @@ -624,7 +624,7 @@ func (m *StoreSnapshot) Unmarshal(data []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Tasks = append(m.Tasks, &docker_cluster_api2.Task{}) + m.Tasks = append(m.Tasks, &docker_cluster_api3.Task{}) if err := m.Tasks[len(m.Tasks)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { return err } @@ -655,7 +655,7 @@ func (m *StoreSnapshot) Unmarshal(data []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Volumes = append(m.Volumes, &docker_cluster_api2.Volume{}) + m.Volumes = append(m.Volumes, &docker_cluster_api3.Volume{}) if err := m.Volumes[len(m.Volumes)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { return err } @@ -736,7 +736,7 @@ func (m *ClusterSnapshot) Unmarshal(data []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Members = append(m.Members, &docker_cluster_api3.RaftNode{}) + m.Members = append(m.Members, &docker_cluster_api4.RaftNode{}) if err := m.Members[len(m.Members)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { return err } diff --git a/protobuf/ptypes/doc.go b/protobuf/ptypes/doc.go new file mode 100644 index 0000000000..8a77dad4dc --- /dev/null +++ b/protobuf/ptypes/doc.go @@ -0,0 +1,9 @@ +// Package ptypes is a copy of the golang/protobuf/ptypes that we'll need to +// use with our regenerated ptypes until google gets their act together and +// makes their "Well Known Types" actually usable by other parties. +// +// It is more likely that this issue will be resolved by gogo. +// +// Note that this is not a vendoring of the package. We have to change the +// types to match the generated types. +package ptypes diff --git a/protobuf/ptypes/timestamp.go b/protobuf/ptypes/timestamp.go new file mode 100644 index 0000000000..a5b816a5fa --- /dev/null +++ b/protobuf/ptypes/timestamp.go @@ -0,0 +1,125 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package ptypes + +// This file implements operations on google.protobuf.Timestamp. + +import ( + "errors" + "fmt" + "time" + + tspb "github.com/docker/swarm-v2/api/timestamp" +) + +const ( + // Seconds field of the earliest valid Timestamp. + // This is time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC).Unix(). + minValidSeconds = -62135596800 + // Seconds field just after the latest valid Timestamp. + // This is time.Date(10000, 1, 1, 0, 0, 0, 0, time.UTC).Unix(). + maxValidSeconds = 253402300800 +) + +// validateTimestamp determines whether a Timestamp is valid. +// A valid timestamp represents a time in the range +// [0001-01-01, 10000-01-01) and has a Nanos field +// in the range [0, 1e9). +// +// If the Timestamp is valid, validateTimestamp returns nil. +// Otherwise, it returns an error that describes +// the problem. +// +// Every valid Timestamp can be represented by a time.Time, but the converse is not true. +func validateTimestamp(ts *tspb.Timestamp) error { + if ts == nil { + return errors.New("timestamp: nil Timestamp") + } + if ts.Seconds < minValidSeconds { + return fmt.Errorf("timestamp: %v before 0001-01-01", ts) + } + if ts.Seconds >= maxValidSeconds { + return fmt.Errorf("timestamp: %v after 10000-01-01", ts) + } + if ts.Nanos < 0 || ts.Nanos >= 1e9 { + return fmt.Errorf("timestamp: %v: nanos not in range [0, 1e9)", ts) + } + return nil +} + +// Timestamp converts a google.protobuf.Timestamp proto to a time.Time. +// It returns an error if the argument is invalid. +// +// Unlike most Go functions, if Timestamp returns an error, the first return value +// is not the zero time.Time. Instead, it is the value obtained from the +// time.Unix function when passed the contents of the Timestamp, in the UTC +// locale. This may or may not be a meaningful time; many invalid Timestamps +// do map to valid time.Times. +// +// A nil Timestamp returns an error. The first return value in that case is +// undefined. +func Timestamp(ts *tspb.Timestamp) (time.Time, error) { + // Don't return the zero value on error, because corresponds to a valid + // timestamp. Instead return whatever time.Unix gives us. + var t time.Time + if ts == nil { + t = time.Unix(0, 0).UTC() // treat nil like the empty Timestamp + } else { + t = time.Unix(ts.Seconds, int64(ts.Nanos)).UTC() + } + return t, validateTimestamp(ts) +} + +// TimestampProto converts the time.Time to a google.protobuf.Timestamp proto. +// It returns an error if the resulting Timestamp is invalid. +func TimestampProto(t time.Time) (*tspb.Timestamp, error) { + seconds := t.Unix() + nanos := int32(t.Sub(time.Unix(seconds, 0))) + ts := &tspb.Timestamp{ + Seconds: seconds, + Nanos: nanos, + } + if err := validateTimestamp(ts); err != nil { + return nil, err + } + return ts, nil +} + +// TimestampString returns the RFC 3339 string for valid Timestamps. For invalid +// Timestamps, it returns an error message in parentheses. +func TimestampString(ts *tspb.Timestamp) string { + t, err := Timestamp(ts) + if err != nil { + return fmt.Sprintf("(%v)", err) + } + return t.Format(time.RFC3339Nano) +} diff --git a/protobuf/ptypes/timestamp_test.go b/protobuf/ptypes/timestamp_test.go new file mode 100644 index 0000000000..fa53384918 --- /dev/null +++ b/protobuf/ptypes/timestamp_test.go @@ -0,0 +1,140 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package ptypes + +import ( + "math" + "testing" + "time" + + tspb "github.com/docker/swarm-v2/api/timestamp" + "github.com/golang/protobuf/proto" +) + +var tests = []struct { + ts *tspb.Timestamp + valid bool + t time.Time +}{ + // The timestamp representing the Unix epoch date. + {&tspb.Timestamp{0, 0}, true, utcDate(1970, 1, 1)}, + // The smallest representable timestamp. + {&tspb.Timestamp{math.MinInt64, math.MinInt32}, false, + time.Unix(math.MinInt64, math.MinInt32).UTC()}, + // The smallest representable timestamp with non-negative nanos. + {&tspb.Timestamp{math.MinInt64, 0}, false, time.Unix(math.MinInt64, 0).UTC()}, + // The earliest valid timestamp. + {&tspb.Timestamp{minValidSeconds, 0}, true, utcDate(1, 1, 1)}, + //"0001-01-01T00:00:00Z"}, + // The largest representable timestamp. + {&tspb.Timestamp{math.MaxInt64, math.MaxInt32}, false, + time.Unix(math.MaxInt64, math.MaxInt32).UTC()}, + // The largest representable timestamp with nanos in range. + {&tspb.Timestamp{math.MaxInt64, 1e9 - 1}, false, + time.Unix(math.MaxInt64, 1e9-1).UTC()}, + // The largest valid timestamp. + {&tspb.Timestamp{maxValidSeconds - 1, 1e9 - 1}, true, + time.Date(9999, 12, 31, 23, 59, 59, 1e9-1, time.UTC)}, + // The smallest invalid timestamp that is larger than the valid range. + {&tspb.Timestamp{maxValidSeconds, 0}, false, time.Unix(maxValidSeconds, 0).UTC()}, + // A date before the epoch. + {&tspb.Timestamp{-281836800, 0}, true, utcDate(1961, 1, 26)}, + // A date after the epoch. + {&tspb.Timestamp{1296000000, 0}, true, utcDate(2011, 1, 26)}, + // A date after the epoch, in the middle of the day. + {&tspb.Timestamp{1296012345, 940483}, true, + time.Date(2011, 1, 26, 3, 25, 45, 940483, time.UTC)}, +} + +func TestValidateTimestamp(t *testing.T) { + for _, s := range tests { + got := validateTimestamp(s.ts) + if (got == nil) != s.valid { + t.Errorf("validateTimestamp(%v) = %v, want %v", s.ts, got, s.valid) + } + } +} + +func TestTimestamp(t *testing.T) { + for _, s := range tests { + got, err := Timestamp(s.ts) + if (err == nil) != s.valid { + t.Errorf("Timestamp(%v) error = %v, but valid = %t", s.ts, err, s.valid) + } else if s.valid && got != s.t { + t.Errorf("Timestamp(%v) = %v, want %v", s.ts, got, s.t) + } + } + // Special case: a nil Timestamp is an error, but returns the 0 Unix time. + got, err := Timestamp(nil) + want := time.Unix(0, 0).UTC() + if got != want { + t.Errorf("Timestamp(nil) = %v, want %v", got, want) + } + if err == nil { + t.Errorf("Timestamp(nil) error = nil, expected error") + } +} + +func TestTimestampProto(t *testing.T) { + for _, s := range tests { + got, err := TimestampProto(s.t) + if (err == nil) != s.valid { + t.Errorf("TimestampProto(%v) error = %v, but valid = %t", s.t, err, s.valid) + } else if s.valid && !proto.Equal(got, s.ts) { + t.Errorf("TimestampProto(%v) = %v, want %v", s.t, got, s.ts) + } + } + // No corresponding special case here: no time.Time results in a nil Timestamp. +} + +func TestTimestampString(t *testing.T) { + for _, test := range []struct { + ts *tspb.Timestamp + want string + }{ + // Not much testing needed because presumably time.Format is + // well-tested. + {&tspb.Timestamp{0, 0}, "1970-01-01T00:00:00Z"}, + + // NOTE(stevvooe): Had to change this to match gogoprotobuf string output. + {&tspb.Timestamp{minValidSeconds - 1, 0}, "(timestamp: &Timestamp{Seconds:-62135596801,Nanos:0,} before 0001-01-01)"}, + } { + got := TimestampString(test.ts) + if got != test.want { + t.Errorf("TimestampString(%v) = %q, want %q", test.ts, got, test.want) + } + } +} + +func utcDate(year, month, day int) time.Time { + return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC) +}