From 6dc41862e9cb29c5c20550db909c0f4b6975660f Mon Sep 17 00:00:00 2001 From: Cody Roseborough Date: Tue, 14 Jun 2016 11:44:47 -0700 Subject: [PATCH 1/4] Adds GetAutodiscoverPaths() to Controlproxy Adds GetAutodiscoverPaths() to controlproxy to fulfil the managesMetrics interface. Adjust Godeps to correct grpc version. --- control/control_grpc_server.go | 8 + grpc/common/common.pb.go | 157 ++++++++-------- grpc/controlproxy/controlproxy.go | 9 + grpc/controlproxy/controlproxy_test.go | 26 +++ grpc/controlproxy/rpc/control.pb.go | 239 +++++++++++++++---------- grpc/controlproxy/rpc/control.proto | 5 + 6 files changed, 282 insertions(+), 162 deletions(-) diff --git a/control/control_grpc_server.go b/control/control_grpc_server.go index 5583aef02..6d47a1926 100644 --- a/control/control_grpc_server.go +++ b/control/control_grpc_server.go @@ -140,6 +140,14 @@ func (pc *ControlGRPCServer) MatchQueryToNamespaces(ctx context.Context, r *rpc. return reply, nil } +func (pc *ControlGRPCServer) GetAutodiscoverPaths(ctx context.Context, _ *common.Empty) (*rpc.GetAutodiscoverPathsReply, error) { + paths := pc.control.GetAutodiscoverPaths() + reply := &rpc.GetAutodiscoverPathsReply{ + Paths: paths, + } + return reply, nil +} + //-------- util --------------- func convertNSS(nss []core.Namespace) []*rpc.ArrString { diff --git a/grpc/common/common.pb.go b/grpc/common/common.pb.go index 3a4bcbd74..ffd3a7358 100644 --- a/grpc/common/common.pb.go +++ b/grpc/common/common.pb.go @@ -51,7 +51,9 @@ 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.ProtoPackageIsVersion1 +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type Time struct { Sec int64 `protobuf:"varint,1,opt,name=sec" json:"sec,omitempty"` @@ -72,8 +74,8 @@ func (*Empty) ProtoMessage() {} func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } type SnapError struct { - ErrorString string `protobuf:"bytes,1,opt,name=error_string" json:"error_string,omitempty"` - ErrorFields map[string]string `protobuf:"bytes,2,rep,name=error_fields" json:"error_fields,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + ErrorString string `protobuf:"bytes,1,opt,name=error_string,json=errorString" json:"error_string,omitempty"` + ErrorFields map[string]string `protobuf:"bytes,2,rep,name=error_fields,json=errorFields" json:"error_fields,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` } func (m *SnapError) Reset() { *m = SnapError{} } @@ -100,14 +102,14 @@ func (*Label) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } // core.Metric type Metric struct { - Namespace []*NamespaceElement `protobuf:"bytes,1,rep,name=Namespace" json:"Namespace,omitempty"` - Version int64 `protobuf:"varint,2,opt,name=Version" json:"Version,omitempty"` - Config *ConfigMap `protobuf:"bytes,3,opt,name=Config" json:"Config,omitempty"` - LastAdvertisedTime *Time `protobuf:"bytes,4,opt,name=LastAdvertisedTime" json:"LastAdvertisedTime,omitempty"` - Tags map[string]string `protobuf:"bytes,5,rep,name=Tags" json:"Tags,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` - Timestamp *Time `protobuf:"bytes,6,opt,name=Timestamp" json:"Timestamp,omitempty"` - Unit string `protobuf:"bytes,7,opt,name=Unit" json:"Unit,omitempty"` - Description string `protobuf:"bytes,8,opt,name=Description" json:"Description,omitempty"` + Namespace []*NamespaceElement `protobuf:"bytes,1,rep,name=Namespace,json=namespace" json:"Namespace,omitempty"` + Version int64 `protobuf:"varint,2,opt,name=Version,json=version" json:"Version,omitempty"` + Config *ConfigMap `protobuf:"bytes,3,opt,name=Config,json=config" json:"Config,omitempty"` + LastAdvertisedTime *Time `protobuf:"bytes,4,opt,name=LastAdvertisedTime,json=lastAdvertisedTime" json:"LastAdvertisedTime,omitempty"` + Tags map[string]string `protobuf:"bytes,5,rep,name=Tags,json=tags" json:"Tags,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + Timestamp *Time `protobuf:"bytes,6,opt,name=Timestamp,json=timestamp" json:"Timestamp,omitempty"` + Unit string `protobuf:"bytes,7,opt,name=Unit,json=unit" json:"Unit,omitempty"` + Description string `protobuf:"bytes,8,opt,name=Description,json=description" json:"Description,omitempty"` // Types that are valid to be assigned to Data: // *Metric_StringData // *Metric_Float32Data @@ -128,22 +130,22 @@ type isMetric_Data interface { } type Metric_StringData struct { - StringData string `protobuf:"bytes,9,opt,name=string_data,oneof"` + StringData string `protobuf:"bytes,9,opt,name=string_data,json=stringData,oneof"` } type Metric_Float32Data struct { - Float32Data float32 `protobuf:"fixed32,10,opt,name=float32_data,oneof"` + Float32Data float32 `protobuf:"fixed32,10,opt,name=float32_data,json=float32Data,oneof"` } type Metric_Float64Data struct { - Float64Data float64 `protobuf:"fixed64,11,opt,name=float64_data,oneof"` + Float64Data float64 `protobuf:"fixed64,11,opt,name=float64_data,json=float64Data,oneof"` } type Metric_Int32Data struct { - Int32Data int32 `protobuf:"varint,12,opt,name=int32_data,oneof"` + Int32Data int32 `protobuf:"varint,12,opt,name=int32_data,json=int32Data,oneof"` } type Metric_Int64Data struct { - Int64Data int64 `protobuf:"varint,13,opt,name=int64_data,oneof"` + Int64Data int64 `protobuf:"varint,13,opt,name=int64_data,json=int64Data,oneof"` } type Metric_BytesData struct { - BytesData []byte `protobuf:"bytes,14,opt,name=bytes_data,proto3,oneof"` + BytesData []byte `protobuf:"bytes,14,opt,name=bytes_data,json=bytesData,proto3,oneof"` } func (*Metric_StringData) isMetric_Data() {} @@ -360,9 +362,9 @@ func _Metric_OneofSizer(msg proto.Message) (n int) { } type NamespaceElement struct { - Value string `protobuf:"bytes,1,opt,name=Value" json:"Value,omitempty"` - Description string `protobuf:"bytes,2,opt,name=Description" json:"Description,omitempty"` - Name string `protobuf:"bytes,3,opt,name=Name" json:"Name,omitempty"` + Value string `protobuf:"bytes,1,opt,name=Value,json=value" json:"Value,omitempty"` + Description string `protobuf:"bytes,2,opt,name=Description,json=description" json:"Description,omitempty"` + Name string `protobuf:"bytes,3,opt,name=Name,json=name" json:"Name,omitempty"` } func (m *NamespaceElement) Reset() { *m = NamespaceElement{} } @@ -372,10 +374,10 @@ func (*NamespaceElement) Descriptor() ([]byte, []int) { return fileDescriptor0, // core.SubscribedPlugin type SubscribedPlugin struct { - TypeName string `protobuf:"bytes,1,opt,name=TypeName" json:"TypeName,omitempty"` - Name string `protobuf:"bytes,2,opt,name=Name" json:"Name,omitempty"` - Version int64 `protobuf:"varint,3,opt,name=Version" json:"Version,omitempty"` - Config *ConfigMap `protobuf:"bytes,4,opt,name=Config" json:"Config,omitempty"` + TypeName string `protobuf:"bytes,1,opt,name=TypeName,json=typeName" json:"TypeName,omitempty"` + Name string `protobuf:"bytes,2,opt,name=Name,json=name" json:"Name,omitempty"` + Version int64 `protobuf:"varint,3,opt,name=Version,json=version" json:"Version,omitempty"` + Config *ConfigMap `protobuf:"bytes,4,opt,name=Config,json=config" json:"Config,omitempty"` } func (m *SubscribedPlugin) Reset() { *m = SubscribedPlugin{} } @@ -391,11 +393,11 @@ func (m *SubscribedPlugin) GetConfig() *ConfigMap { } type ConfigMap struct { - IntMap map[string]int64 `protobuf:"bytes,1,rep,name=IntMap" json:"IntMap,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` - StringMap map[string]string `protobuf:"bytes,2,rep,name=StringMap" json:"StringMap,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + IntMap map[string]int64 `protobuf:"bytes,1,rep,name=IntMap,json=intMap" json:"IntMap,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` + StringMap map[string]string `protobuf:"bytes,2,rep,name=StringMap,json=stringMap" json:"StringMap,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` // double is float64 - FloatMap map[string]float64 `protobuf:"bytes,3,rep,name=FloatMap" json:"FloatMap,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"fixed64,2,opt,name=value"` - BoolMap map[string]bool `protobuf:"bytes,4,rep,name=BoolMap" json:"BoolMap,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` + FloatMap map[string]float64 `protobuf:"bytes,3,rep,name=FloatMap,json=floatMap" json:"FloatMap,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"fixed64,2,opt,name=value"` + BoolMap map[string]bool `protobuf:"bytes,4,rep,name=BoolMap,json=boolMap" json:"BoolMap,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` } func (m *ConfigMap) Reset() { *m = ConfigMap{} } @@ -433,9 +435,9 @@ func (m *ConfigMap) GetBoolMap() map[string]bool { // core.Plugin type Plugin struct { - TypeName string `protobuf:"bytes,1,opt,name=TypeName" json:"TypeName,omitempty"` - Name string `protobuf:"bytes,2,opt,name=Name" json:"Name,omitempty"` - Version int64 `protobuf:"varint,3,opt,name=Version" json:"Version,omitempty"` + TypeName string `protobuf:"bytes,1,opt,name=TypeName,json=typeName" json:"TypeName,omitempty"` + Name string `protobuf:"bytes,2,opt,name=Name,json=name" json:"Name,omitempty"` + Version int64 `protobuf:"varint,3,opt,name=Version,json=version" json:"Version,omitempty"` } func (m *Plugin) Reset() { *m = Plugin{} } @@ -455,46 +457,57 @@ func init() { proto.RegisterType((*Plugin)(nil), "common.Plugin") } +func init() { + proto.RegisterFile("github.com/intelsdi-x/snap/grpc/common/common.proto", fileDescriptor0) +} + var fileDescriptor0 = []byte{ - // 630 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x9c, 0x54, 0xef, 0x4f, 0xd3, 0x40, - 0x18, 0xa6, 0xb4, 0xeb, 0xd6, 0xb7, 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0x9d, 0xbb, 0xe0, 0x2f, 0xfa, 0xbc, 0x3f, 0x3a, - 0x5b, 0x45, 0xd7, 0x79, 0x03, 0xeb, 0xb7, 0x4c, 0x3e, 0x10, 0x76, 0xa7, 0x0b, 0x6b, 0x37, 0x2d, - 0xde, 0x2f, 0xb0, 0xb4, 0x20, 0x86, 0x60, 0xd1, 0xe1, 0x3f, 0xf8, 0x2d, 0xfd, 0xad, 0xf8, 0x00, - 0xee, 0x7f, 0xa6, 0x3e, 0x74, 0xf5, 0x37, 0xb3, 0xff, 0x37, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x86, - 0x01, 0x7e, 0x6a, 0x05, 0x00, 0x00, + // 738 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x55, 0xdd, 0x6e, 0xd3, 0x4c, + 0x10, 0xfd, 0x1c, 0x3b, 0x4e, 0x3c, 0x4e, 0xab, 0x7c, 0x2b, 0x2e, 0xac, 0x48, 0xd0, 0x62, 0x6e, + 0x0a, 0x82, 0x44, 0xb4, 0xa5, 0x94, 0xb6, 0xaa, 0x44, 0x69, 0x2a, 0x90, 0x5a, 0x84, 0xdc, 0xd2, + 0x4b, 0x2a, 0x27, 0xde, 0x84, 0x15, 0xf6, 0xda, 0xf2, 0x6e, 0xaa, 0xe6, 0x09, 0x78, 0x22, 0xde, + 0x88, 0x3b, 0x5e, 0x82, 0xfd, 0xb1, 0x53, 0xa7, 0x01, 0x45, 0x95, 0xb8, 0x69, 0x67, 0xce, 0x9e, + 0x33, 0xbb, 0x33, 0x7b, 0xbc, 0x81, 0xad, 0x31, 0xe1, 0x5f, 0x27, 0x83, 0xee, 0x30, 0x4d, 0x7a, + 0x84, 0x72, 0x1c, 0xb3, 0x88, 0xbc, 0xb8, 0xe9, 0x31, 0x1a, 0x66, 0xbd, 0x71, 0x9e, 0x0d, 0x7b, + 0x62, 0x21, 0x49, 0x69, 0xf1,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, 0x94, 0xba, 0xa0, 0x38, 0x0a, 0xab, 0x10, 0xca, 0x1a, 0x2b, 0xf2, 0x8e, 0x0a, + 0xc2, 0x6d, 0x85, 0xc1, 0x94, 0x63, 0xa6, 0x09, 0xab, 0x82, 0xd0, 0x92, 0x04, 0x85, 0x49, 0x42, + 0xe7, 0xb5, 0x98, 0x58, 0x39, 0xc4, 0xfb, 0x38, 0xf2, 0xc8, 0x06, 0x4b, 0xd6, 0xf4, 0xbf, 0x40, + 0xfb, 0xae, 0x85, 0xa4, 0xea, 0x52, 0xa9, 0x8c, 0x8a, 0xea, 0xee, 0x70, 0x6b, 0x8b, 0xc3, 0x15, + 0x57, 0x22, 0x6b, 0x29, 0x4f, 0x95, 0x36, 0xfe, 0x6e, 0x40, 0xfb, 0x7c, 0x32, 0x90, 0xa4, 0x01, + 0x8e, 0x3e, 0xc5, 0x93, 0x31, 0xa1, 0xa8, 0x03, 0xcd, 0x8b, 0x69, 0x86, 0x15, 0x59, 0xef, 0xd1, + 0xe4, 0x45, 0x3e, 0x2b, 0x52, 0xf9, 0x16, 0xaa, 0x46, 0x36, 0xff, 0x66, 0x64, 0x6b, 0x89, 0x91, + 0xfd, 0x5f, 0x26, 0x38, 0x33, 0x14, 0xbd, 0x02, 0xfb, 0x03, 0xe5, 0x22, 0x2a, 0x3e, 0xa8, 0x87, + 0x0b, 0xc2, 0xae, 0x5e, 0xd7, 0xfe, 0xb4, 0x89, 0x4a, 0xd0, 0xa1, 0x78, 0x7f, 0x94, 0x55, 0xa4, + 0x52, 0x3f, 0x26, 0xeb, 0x8b, 0xca, 0x19, 0x45, 0x8b, 0x1d, 0x56, 0xe6, 0x68, 0x1f, 0x9a, 0x27, + 0xd2, 0x21, 0x52, 0x6e, 0x2a, 0xf9, 0xda, 0xa2, 0xbc, 0x64, 0x68, 0x75, 0x73, 0x54, 0xa4, 0x68, + 0x17, 0x1a, 0x47, 0x69, 0x1a, 0x4b, 0xad, 0xa5, 0xb4, 0x8f, 0x16, 0xb5, 0x05, 0x41, 0x4b, 0x1b, + 0x03, 0x9d, 0x75, 0xde, 0x80, 0x5b, 0xe9, 0x66, 0x99, 0x51, 0xcc, 0x8a, 0x51, 0x3a, 0x07, 0xb0, + 0x3a, 0xdf, 0xce, 0x7d, 0x6c, 0xd6, 0xd9, 0x87, 0x95, 0xb9, 0x6e, 0x96, 0x89, 0x8d, 0xaa, 0x78, + 0x0f, 0x5a, 0xd5, 0x76, 0x96, 0x69, 0x9b, 0xd5, 0x17, 0x37, 0x00, 0xfb, 0x5f, 0x9b, 0x6d, 0x60, + 0xab, 0xdf, 0xb0, 0xad, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xfa, 0xc3, 0x4f, 0x62, 0xfa, 0x06, + 0x00, 0x00, } diff --git a/grpc/controlproxy/controlproxy.go b/grpc/controlproxy/controlproxy.go index e38adc8c0..53795b05d 100644 --- a/grpc/controlproxy/controlproxy.go +++ b/grpc/controlproxy/controlproxy.go @@ -197,6 +197,15 @@ func (c ControlProxy) MatchQueryToNamespaces(namespace core.Namespace) ([]core.N return nss, nil } +func (c ControlProxy) GetAutodiscoverPaths() []string { + req := &common.Empty{} + reply, err := c.Client.GetAutodiscoverPaths(getContext(), req) + if err != nil { + return nil + } + return reply.Paths +} + ///---------Util------------------------------------------------------------------------- func getPluginType(t core.PluginType) int32 { val := int32(-1) diff --git a/grpc/controlproxy/controlproxy_test.go b/grpc/controlproxy/controlproxy_test.go index 48b3582cd..74de12cdf 100644 --- a/grpc/controlproxy/controlproxy_test.go +++ b/grpc/controlproxy/controlproxy_test.go @@ -49,6 +49,14 @@ type mockClient struct { SubscribeReply *rpc.SubscribeDepsReply UnsubscribeReply *rpc.SubscribeDepsReply MatchReply *rpc.ExpandWildcardsReply + AutoDiscoReply *rpc.GetAutodiscoverPathsReply +} + +func (mc mockClient) GetAutodiscoverPaths(ctx context.Context, _ *common.Empty, opts ...grpc.CallOption) (*rpc.GetAutodiscoverPathsReply, error) { + if mc.RpcErr { + return nil, rpcErr + } + return mc.AutoDiscoReply, nil } func (mc mockClient) GetPluginContentTypes(ctx context.Context, in *rpc.GetPluginContentTypesRequest, opts ...grpc.CallOption) (*rpc.GetPluginContentTypesReply, error) { @@ -540,3 +548,21 @@ func TestMatchQueryToNamespaces(t *testing.T) { }) } + +func TestGetAutoDiscoverPaths(t *testing.T) { + Convey("Able to call successfully", t, func() { + reply := &rpc.GetAutodiscoverPathsReply{ + Paths: []string{"a", "titanium", "poodle"}, + } + proxy := ControlProxy{Client: mockClient{AutoDiscoReply: reply}} + val := proxy.GetAutodiscoverPaths() + So(val, ShouldNotBeNil) + So(val, ShouldResemble, []string{"a", "titanium", "poodle"}) + }) + + Convey("returns nil on rpc error", t, func() { + proxy := ControlProxy{Client: mockClient{RpcErr: true}} + val := proxy.GetAutodiscoverPaths() + So(val, ShouldBeNil) + }) +} diff --git a/grpc/controlproxy/rpc/control.pb.go b/grpc/controlproxy/rpc/control.pb.go index 1b2a47cbe..928e07b19 100644 --- a/grpc/controlproxy/rpc/control.pb.go +++ b/grpc/controlproxy/rpc/control.pb.go @@ -45,6 +45,7 @@ It has these top-level messages: ExpandWildcardsRequest ArrString ExpandWildcardsReply + GetAutodiscoverPathsReply */ package rpc @@ -65,7 +66,9 @@ 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.ProtoPackageIsVersion1 +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type SerrorReply struct { } @@ -76,12 +79,12 @@ func (*SerrorReply) ProtoMessage() {} func (*SerrorReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } type PubProcMetricsRequest struct { - ContentType string `protobuf:"bytes,1,opt,name=ContentType" json:"ContentType,omitempty"` - Content []byte `protobuf:"bytes,2,opt,name=Content,proto3" json:"Content,omitempty"` - PluginName string `protobuf:"bytes,3,opt,name=PluginName" json:"PluginName,omitempty"` - PluginVersion int64 `protobuf:"varint,4,opt,name=PluginVersion" json:"PluginVersion,omitempty"` - Config *common.ConfigMap `protobuf:"bytes,5,opt,name=Config" json:"Config,omitempty"` - TaskId string `protobuf:"bytes,6,opt,name=TaskId" json:"TaskId,omitempty"` + ContentType string `protobuf:"bytes,1,opt,name=ContentType,json=contentType" json:"ContentType,omitempty"` + Content []byte `protobuf:"bytes,2,opt,name=Content,json=content,proto3" json:"Content,omitempty"` + PluginName string `protobuf:"bytes,3,opt,name=PluginName,json=pluginName" json:"PluginName,omitempty"` + PluginVersion int64 `protobuf:"varint,4,opt,name=PluginVersion,json=pluginVersion" json:"PluginVersion,omitempty"` + Config *common.ConfigMap `protobuf:"bytes,5,opt,name=Config,json=config" json:"Config,omitempty"` + TaskId string `protobuf:"bytes,6,opt,name=TaskId,json=taskId" json:"TaskId,omitempty"` } func (m *PubProcMetricsRequest) Reset() { *m = PubProcMetricsRequest{} } @@ -97,7 +100,7 @@ func (m *PubProcMetricsRequest) GetConfig() *common.ConfigMap { } type ErrorReply struct { - Errors []string `protobuf:"bytes,1,rep,name=Errors" json:"Errors,omitempty"` + Errors []string `protobuf:"bytes,1,rep,name=Errors,json=errors" json:"Errors,omitempty"` } func (m *ErrorReply) Reset() { *m = ErrorReply{} } @@ -106,9 +109,9 @@ func (*ErrorReply) ProtoMessage() {} func (*ErrorReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } type ProcessMetricsReply struct { - ContentType string `protobuf:"bytes,1,opt,name=ContentType" json:"ContentType,omitempty"` - Content []byte `protobuf:"bytes,2,opt,name=Content,proto3" json:"Content,omitempty"` - Errors []string `protobuf:"bytes,3,rep,name=Errors" json:"Errors,omitempty"` + ContentType string `protobuf:"bytes,1,opt,name=ContentType,json=contentType" json:"ContentType,omitempty"` + Content []byte `protobuf:"bytes,2,opt,name=Content,json=content,proto3" json:"Content,omitempty"` + Errors []string `protobuf:"bytes,3,rep,name=Errors,json=errors" json:"Errors,omitempty"` } func (m *ProcessMetricsReply) Reset() { *m = ProcessMetricsReply{} } @@ -117,9 +120,9 @@ func (*ProcessMetricsReply) ProtoMessage() {} func (*ProcessMetricsReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } type GetPluginContentTypesRequest struct { - Name string `protobuf:"bytes,1,opt,name=Name" json:"Name,omitempty"` - PluginType int32 `protobuf:"varint,2,opt,name=PluginType" json:"PluginType,omitempty"` - Version int32 `protobuf:"varint,3,opt,name=Version" json:"Version,omitempty"` + Name string `protobuf:"bytes,1,opt,name=Name,json=name" json:"Name,omitempty"` + PluginType int32 `protobuf:"varint,2,opt,name=PluginType,json=pluginType" json:"PluginType,omitempty"` + Version int32 `protobuf:"varint,3,opt,name=Version,json=version" json:"Version,omitempty"` } func (m *GetPluginContentTypesRequest) Reset() { *m = GetPluginContentTypesRequest{} } @@ -128,9 +131,9 @@ func (*GetPluginContentTypesRequest) ProtoMessage() {} func (*GetPluginContentTypesRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } type GetPluginContentTypesReply struct { - AcceptedTypes []string `protobuf:"bytes,1,rep,name=AcceptedTypes" json:"AcceptedTypes,omitempty"` - ReturnedTypes []string `protobuf:"bytes,2,rep,name=ReturnedTypes" json:"ReturnedTypes,omitempty"` - Error string `protobuf:"bytes,3,opt,name=Error" json:"Error,omitempty"` + AcceptedTypes []string `protobuf:"bytes,1,rep,name=AcceptedTypes,json=acceptedTypes" json:"AcceptedTypes,omitempty"` + ReturnedTypes []string `protobuf:"bytes,2,rep,name=ReturnedTypes,json=returnedTypes" json:"ReturnedTypes,omitempty"` + Error string `protobuf:"bytes,3,opt,name=Error,json=error" json:"Error,omitempty"` } func (m *GetPluginContentTypesReply) Reset() { *m = GetPluginContentTypesReply{} } @@ -139,8 +142,8 @@ func (*GetPluginContentTypesReply) ProtoMessage() {} func (*GetPluginContentTypesReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } type ValidateDepsRequest struct { - Metrics []*common.Metric `protobuf:"bytes,1,rep,name=Metrics" json:"Metrics,omitempty"` - Plugins []*common.SubscribedPlugin `protobuf:"bytes,2,rep,name=Plugins" json:"Plugins,omitempty"` + Metrics []*common.Metric `protobuf:"bytes,1,rep,name=Metrics,json=metrics" json:"Metrics,omitempty"` + Plugins []*common.SubscribedPlugin `protobuf:"bytes,2,rep,name=Plugins,json=plugins" json:"Plugins,omitempty"` } func (m *ValidateDepsRequest) Reset() { *m = ValidateDepsRequest{} } @@ -163,7 +166,7 @@ func (m *ValidateDepsRequest) GetPlugins() []*common.SubscribedPlugin { } type ValidateDepsReply struct { - Errors []*common.SnapError `protobuf:"bytes,1,rep,name=Errors" json:"Errors,omitempty"` + Errors []*common.SnapError `protobuf:"bytes,1,rep,name=Errors,json=errors" json:"Errors,omitempty"` } func (m *ValidateDepsReply) Reset() { *m = ValidateDepsReply{} } @@ -179,9 +182,9 @@ func (m *ValidateDepsReply) GetErrors() []*common.SnapError { } type SubscribeDepsRequest struct { - Metrics []*common.Metric `protobuf:"bytes,1,rep,name=Metrics" json:"Metrics,omitempty"` - Plugins []*common.Plugin `protobuf:"bytes,2,rep,name=Plugins" json:"Plugins,omitempty"` - TaskId string `protobuf:"bytes,3,opt,name=TaskId" json:"TaskId,omitempty"` + Metrics []*common.Metric `protobuf:"bytes,1,rep,name=Metrics,json=metrics" json:"Metrics,omitempty"` + Plugins []*common.Plugin `protobuf:"bytes,2,rep,name=Plugins,json=plugins" json:"Plugins,omitempty"` + TaskId string `protobuf:"bytes,3,opt,name=TaskId,json=taskId" json:"TaskId,omitempty"` } func (m *SubscribeDepsRequest) Reset() { *m = SubscribeDepsRequest{} } @@ -204,7 +207,7 @@ func (m *SubscribeDepsRequest) GetPlugins() []*common.Plugin { } type SubscribeDepsReply struct { - Errors []*common.SnapError `protobuf:"bytes,1,rep,name=Errors" json:"Errors,omitempty"` + Errors []*common.SnapError `protobuf:"bytes,1,rep,name=Errors,json=errors" json:"Errors,omitempty"` } func (m *SubscribeDepsReply) Reset() { *m = SubscribeDepsReply{} } @@ -220,7 +223,7 @@ func (m *SubscribeDepsReply) GetErrors() []*common.SnapError { } type Map struct { - Entries []*MapEntry `protobuf:"bytes,1,rep,name=Entries" json:"Entries,omitempty"` + Entries []*MapEntry `protobuf:"bytes,1,rep,name=Entries,json=entries" json:"Entries,omitempty"` } func (m *Map) Reset() { *m = Map{} } @@ -236,8 +239,8 @@ func (m *Map) GetEntries() []*MapEntry { } type MapEntry struct { - Key string `protobuf:"bytes,1,opt,name=Key" json:"Key,omitempty"` - Value string `protobuf:"bytes,2,opt,name=Value" json:"Value,omitempty"` + Key string `protobuf:"bytes,1,opt,name=Key,json=key" json:"Key,omitempty"` + Value string `protobuf:"bytes,2,opt,name=Value,json=value" json:"Value,omitempty"` } func (m *MapEntry) Reset() { *m = MapEntry{} } @@ -246,10 +249,10 @@ func (*MapEntry) ProtoMessage() {} func (*MapEntry) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{11} } type CollectMetricsRequest struct { - TaskID string `protobuf:"bytes,1,opt,name=TaskID" json:"TaskID,omitempty"` - Metrics []*common.Metric `protobuf:"bytes,2,rep,name=Metrics" json:"Metrics,omitempty"` - Deadline *common.Time `protobuf:"bytes,3,opt,name=Deadline" json:"Deadline,omitempty"` - AllTags map[string]*Map `protobuf:"bytes,4,rep,name=AllTags" json:"AllTags,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + TaskID string `protobuf:"bytes,1,opt,name=TaskID,json=taskID" json:"TaskID,omitempty"` + Metrics []*common.Metric `protobuf:"bytes,2,rep,name=Metrics,json=metrics" json:"Metrics,omitempty"` + Deadline *common.Time `protobuf:"bytes,3,opt,name=Deadline,json=deadline" json:"Deadline,omitempty"` + AllTags map[string]*Map `protobuf:"bytes,4,rep,name=AllTags,json=allTags" json:"AllTags,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` } func (m *CollectMetricsRequest) Reset() { *m = CollectMetricsRequest{} } @@ -279,8 +282,8 @@ func (m *CollectMetricsRequest) GetAllTags() map[string]*Map { } type CollectMetricsReply struct { - Metrics []*common.Metric `protobuf:"bytes,1,rep,name=Metrics" json:"Metrics,omitempty"` - Errors []string `protobuf:"bytes,2,rep,name=Errors" json:"Errors,omitempty"` + Metrics []*common.Metric `protobuf:"bytes,1,rep,name=Metrics,json=metrics" json:"Metrics,omitempty"` + Errors []string `protobuf:"bytes,2,rep,name=Errors,json=errors" json:"Errors,omitempty"` } func (m *CollectMetricsReply) Reset() { *m = CollectMetricsReply{} } @@ -296,7 +299,7 @@ func (m *CollectMetricsReply) GetMetrics() []*common.Metric { } type ExpandWildcardsRequest struct { - Namespace []*common.NamespaceElement `protobuf:"bytes,1,rep,name=Namespace" json:"Namespace,omitempty"` + Namespace []*common.NamespaceElement `protobuf:"bytes,1,rep,name=Namespace,json=namespace" json:"Namespace,omitempty"` } func (m *ExpandWildcardsRequest) Reset() { *m = ExpandWildcardsRequest{} } @@ -312,7 +315,7 @@ func (m *ExpandWildcardsRequest) GetNamespace() []*common.NamespaceElement { } type ArrString struct { - S []*common.NamespaceElement `protobuf:"bytes,1,rep,name=S" json:"S,omitempty"` + S []*common.NamespaceElement `protobuf:"bytes,1,rep,name=S,json=s" json:"S,omitempty"` } func (m *ArrString) Reset() { *m = ArrString{} } @@ -328,8 +331,8 @@ func (m *ArrString) GetS() []*common.NamespaceElement { } type ExpandWildcardsReply struct { - NSS []*ArrString `protobuf:"bytes,1,rep,name=NSS" json:"NSS,omitempty"` - Error *common.SnapError `protobuf:"bytes,2,opt,name=Error" json:"Error,omitempty"` + NSS []*ArrString `protobuf:"bytes,1,rep,name=NSS,json=nSS" json:"NSS,omitempty"` + Error *common.SnapError `protobuf:"bytes,2,opt,name=Error,json=error" json:"Error,omitempty"` } func (m *ExpandWildcardsReply) Reset() { *m = ExpandWildcardsReply{} } @@ -351,6 +354,15 @@ func (m *ExpandWildcardsReply) GetError() *common.SnapError { return nil } +type GetAutodiscoverPathsReply struct { + Paths []string `protobuf:"bytes,1,rep,name=Paths,json=paths" json:"Paths,omitempty"` +} + +func (m *GetAutodiscoverPathsReply) Reset() { *m = GetAutodiscoverPathsReply{} } +func (m *GetAutodiscoverPathsReply) String() string { return proto.CompactTextString(m) } +func (*GetAutodiscoverPathsReply) ProtoMessage() {} +func (*GetAutodiscoverPathsReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{17} } + func init() { proto.RegisterType((*SerrorReply)(nil), "rpc.SerrorReply") proto.RegisterType((*PubProcMetricsRequest)(nil), "rpc.PubProcMetricsRequest") @@ -369,6 +381,7 @@ func init() { proto.RegisterType((*ExpandWildcardsRequest)(nil), "rpc.ExpandWildcardsRequest") proto.RegisterType((*ArrString)(nil), "rpc.ArrString") proto.RegisterType((*ExpandWildcardsReply)(nil), "rpc.ExpandWildcardsReply") + proto.RegisterType((*GetAutodiscoverPathsReply)(nil), "rpc.GetAutodiscoverPathsReply") } // Reference imports to suppress errors if they are not otherwise used. @@ -392,6 +405,7 @@ type MetricManagerClient interface { SubscribeDeps(ctx context.Context, in *SubscribeDepsRequest, opts ...grpc.CallOption) (*SubscribeDepsReply, error) UnsubscribeDeps(ctx context.Context, in *SubscribeDepsRequest, opts ...grpc.CallOption) (*SubscribeDepsReply, error) MatchQueryToNamespaces(ctx context.Context, in *ExpandWildcardsRequest, opts ...grpc.CallOption) (*ExpandWildcardsReply, error) + GetAutodiscoverPaths(ctx context.Context, in *common.Empty, opts ...grpc.CallOption) (*GetAutodiscoverPathsReply, error) } type metricManagerClient struct { @@ -483,6 +497,15 @@ func (c *metricManagerClient) MatchQueryToNamespaces(ctx context.Context, in *Ex return out, nil } +func (c *metricManagerClient) GetAutodiscoverPaths(ctx context.Context, in *common.Empty, opts ...grpc.CallOption) (*GetAutodiscoverPathsReply, error) { + out := new(GetAutodiscoverPathsReply) + err := grpc.Invoke(ctx, "/rpc.MetricManager/GetAutodiscoverPaths", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for MetricManager service type MetricManagerServer interface { @@ -496,6 +519,7 @@ type MetricManagerServer interface { SubscribeDeps(context.Context, *SubscribeDepsRequest) (*SubscribeDepsReply, error) UnsubscribeDeps(context.Context, *SubscribeDepsRequest) (*SubscribeDepsReply, error) MatchQueryToNamespaces(context.Context, *ExpandWildcardsRequest) (*ExpandWildcardsReply, error) + GetAutodiscoverPaths(context.Context, *common.Empty) (*GetAutodiscoverPathsReply, error) } func RegisterMetricManagerServer(s *grpc.Server, srv MetricManagerServer) { @@ -664,6 +688,24 @@ func _MetricManager_MatchQueryToNamespaces_Handler(srv interface{}, ctx context. return interceptor(ctx, in, info, handler) } +func _MetricManager_GetAutodiscoverPaths_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(common.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MetricManagerServer).GetAutodiscoverPaths(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rpc.MetricManager/GetAutodiscoverPaths", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MetricManagerServer).GetAutodiscoverPaths(ctx, req.(*common.Empty)) + } + return interceptor(ctx, in, info, handler) +} + var _MetricManager_serviceDesc = grpc.ServiceDesc{ ServiceName: "rpc.MetricManager", HandlerType: (*MetricManagerServer)(nil), @@ -704,62 +746,79 @@ var _MetricManager_serviceDesc = grpc.ServiceDesc{ MethodName: "MatchQueryToNamespaces", Handler: _MetricManager_MatchQueryToNamespaces_Handler, }, + { + MethodName: "GetAutodiscoverPaths", + Handler: _MetricManager_GetAutodiscoverPaths_Handler, + }, }, Streams: []grpc.StreamDesc{}, } +func init() { + proto.RegisterFile("github.com/intelsdi-x/snap/grpc/controlproxy/rpc/control.proto", fileDescriptor0) +} + var fileDescriptor0 = []byte{ - // 821 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 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50, 0x88, 0x8c, 0x4a, - 0x96, 0x1a, 0x4a, 0x08, 0x01, 0x9c, 0xda, 0xe1, 0xc0, 0x72, 0x4e, 0xf4, 0x11, 0x56, 0x24, 0x1e, - 0xb4, 0x02, 0x65, 0x61, 0xbb, 0xc0, 0xc4, 0xb7, 0x5c, 0x47, 0x59, 0xa0, 0x66, 0x09, 0xed, 0x40, - 0x9e, 0x9e, 0xfd, 0x6a, 0x0d, 0x94, 0x1c, 0xfd, 0x96, 0x9b, 0x4b, 0xf5, 0x88, 0x98, 0xb0, 0xb6, - 0x75, 0x0f, 0x55, 0x20, 0xdf, 0xd3, 0xfd, 0xcb, 0x8f, 0xa6, 0x92, 0x67, 0x48, 0xda, 0x06, 0x40, - 0x2b, 0xe1, 0xca, 0xbc, 0xfc, 0xcb, 0xa7, 0x64, 0x24, 0xea, 0x3d, 0x86, 0x1a, 0xe3, 0x8d, 0x7d, - 0x3f, 0xa1, 0xce, 0xc2, 0xee, 0x46, 0x7c, 0x02, 0x26, 0x71, 0xb0, 0x33, 0xd8, 0x38, 0xc2, 0x81, - 0xe0, 0x3d, 0x75, 0x3c, 0x91, 0xa3, 0x04, 0x0b, 0x3c, 0x45, 0x01, 0x97, 0xa4, 0xcd, 0xaf, 0x60, - 0x88, 0x39, 0x76, 0x45, 0x9c, 0x30, 0xd3, 0x21, 0xa7, 0x7d, 0x06, 0xf5, 0x1a, 0x48, 0x46, 0x93, - 0xaa, 0xb4, 0x6f, 0x18, 0xd8, 0x0b, 0xb0, 0xc9, 0xad, 0x22, 0x29, 0x66, 0xee, 0xe0, 0x20, 0x24, - 0x4e, 0x6c, 0xce, 0x72, 0x73, 0x19, 0x72, 0x9c, 0xae, 0x90, 0x58, 0xd3, 0xa1, 0x76, 0xa1, 0xdb, - 0x96, 0xa9, 0x07, 0xf8, 0x10, 0x7b, 0x09, 0xc9, 0x2d, 0x28, 0x44, 0x52, 0x70, 0x34, 0xb9, 0x59, - 0x89, 0x35, 0x16, 0x66, 0xf4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 0x76, 0x8f, 0xdf, 0x08, 0x20, 0xa8, 0xa4, 0x2c, 0x7e, 0x8a, 0xf4, 0x0e, 0x4a, 0xd3, 0x3b, 0x0b, - 0x89, 0xd8, 0x94, 0x4d, 0xa9, 0xae, 0xa6, 0x78, 0x04, 0x46, 0x0b, 0xca, 0x33, 0x5b, 0x05, 0x09, - 0x19, 0xd3, 0x76, 0x9a, 0xba, 0x96, 0xe6, 0x12, 0x30, 0x47, 0x50, 0x3d, 0x77, 0xfc, 0xff, 0x00, - 0xd4, 0x81, 0xd5, 0xb6, 0x1e, 0x18, 0xc3, 0xb3, 0x10, 0x93, 0x71, 0xcf, 0x4d, 0xba, 0xfb, 0x1f, - 0x8a, 0xdf, 0xcf, 0xf3, 0xdf, 0x02, 0xbb, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x71, 0xbc, 0x72, - 0xd1, 0x87, 0x08, 0x00, 0x00, + // 973 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x56, 0x4d, 0x6f, 0xdb, 0x46, + 0x13, 0x8e, 0x44, 0x4b, 0xb4, 0x47, 0x96, 0xfd, 0x66, 0xfd, 0xf1, 0x32, 0x6c, 0xe1, 0xa6, 0x44, + 0xd0, 0x38, 0x87, 0x4a, 0xa8, 0x0c, 0x14, 0x45, 0x0f, 0x09, 0xd4, 0x48, 0x70, 0x8b, 0xc0, 0x81, + 0x4a, 0xaa, 0xc9, 0xa9, 0x87, 0x15, 0xb9, 0x95, 0x09, 0x53, 0x24, 0xcb, 0x5d, 0x06, 0xd6, 0xa5, + 0x40, 0x7b, 0xee, 0x4f, 0xec, 0x8f, 0xe9, 0x7e, 0x91, 0x22, 0x55, 0xc6, 0x6e, 0x9b, 0x9e, 0xec, + 0x9d, 0x19, 0xce, 0xcc, 0xf3, 0xcc, 0xec, 0xb3, 0x82, 0xe7, 0xcb, 0x90, 0x5d, 0xe7, 0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, 0xba, 0xb2, 0x58, 0x97, 0xc9, 0x93, 0xf3, 0x04, 0x60, 0x5a, 0x82, + 0x15, 0x51, 0xf2, 0x44, 0x39, 0x1a, 0x43, 0x44, 0x49, 0x22, 0xa8, 0x13, 0xc2, 0x91, 0x20, 0x80, + 0x50, 0x5a, 0x72, 0x20, 0xc2, 0x3f, 0x84, 0x81, 0x4d, 0x29, 0xa3, 0x56, 0x2a, 0x82, 0x8f, 0x2f, + 0x09, 0x53, 0xe0, 0x2b, 0xc9, 0x4b, 0xd6, 0x11, 0xec, 0x48, 0xce, 0x54, 0xb1, 0x9d, 0x58, 0xb0, + 0x55, 0xb2, 0x29, 0xdb, 0x10, 0x85, 0x3a, 0x05, 0x9b, 0x45, 0x17, 0x05, 0x8f, 0x86, 0x74, 0x9a, + 0xef, 0xd4, 0xd1, 0xf9, 0x05, 0xec, 0xf7, 0x54, 0x13, 0xf8, 0xf8, 0x14, 0xc6, 0xbe, 0x4f, 0x52, + 0x46, 0x02, 0x69, 0xd5, 0xac, 0xf4, 0x71, 0xd5, 0x28, 0xa2, 0x5c, 0xc2, 0xf2, 0x2c, 0x2e, 0xa2, + 0xda, 0x2a, 0x2a, 0xab, 0x1a, 0xd1, 0x31, 0x74, 0x24, 0x5e, 0x3d, 0xec, 0x8e, 0x84, 0xeb, 0x50, + 0x38, 0x7a, 0x83, 0xa3, 0x30, 0xc0, 0x8c, 0x4c, 0x48, 0x5a, 0x82, 0x3c, 0x07, 0x53, 0x13, 0x2d, + 0x4b, 0xf6, 0x46, 0x07, 0xc5, 0x64, 0x95, 0xd9, 0x35, 0x57, 0xca, 0x8d, 0x46, 0x60, 0xaa, 0xee, + 0x55, 0xd9, 0xde, 0xc8, 0x2a, 0x22, 0xbd, 0x7c, 0x41, 0xfd, 0x2c, 0x5c, 0x90, 0x40, 0x05, 0xb8, + 0xa6, 0x62, 0x84, 0x3a, 0xcf, 0xe1, 0x61, 0xbd, 0xa8, 0xc0, 0xfa, 0xac, 0x36, 0xf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 0xcd, 0x4e, 0x95, 0xec, 0x5b, 0x38, 0xa8, + 0xef, 0x0c, 0xb2, 0xdf, 0xbf, 0xbd, 0xb6, 0xd5, 0xe8, 0x53, 0x99, 0x5e, 0xc0, 0x01, 0x7f, 0xc8, + 0xa3, 0x90, 0x5e, 0xd7, 0x33, 0x35, 0xbe, 0xee, 0xf6, 0xa1, 0x6a, 0x6a, 0xf3, 0x43, 0x40, 0xb6, + 0x52, 0x7f, 0x05, 0xef, 0x4c, 0xa0, 0x5a, 0x69, 0x78, 0x36, 0x79, 0xa6, 0x6f, 0x60, 0xbf, 0xaa, + 0xc0, 0x48, 0xc5, 0x36, 0xbc, 0x04, 0xf6, 0x69, 0x83, 0x47, 0xe5, 0x98, 0x42, 0xbf, 0x26, 0x80, + 0x48, 0xd1, 0xd8, 0x24, 0xcc, 0xf6, 0xff, 0x9b, 0x5c, 0x2a, 0xcd, 0x25, 0x1c, 0xfe, 0x10, 0xd3, + 0xff, 0x20, 0x91, 0x0b, 0xa7, 0x57, 0x98, 0xf9, 0xd7, 0xdf, 0xe7, 0x24, 0x5b, 0xcf, 0x93, 0xf2, + 0x7e, 0x7c, 0xc8, 0xf0, 0x2f, 0xe1, 0xb8, 0x69, 0xdb, 0x51, 0xbf, 0xb8, 0x1f, 0xd3, 0x55, 0xca, + 0xd6, 0xf6, 0x59, 0xb1, 0x93, 0xcd, 0xf7, 0xc2, 0x79, 0xb0, 0xe8, 0xca, 0xdf, 0x76, 0x17, 0x7f, + 0x06, 0x00, 0x00, 0xff, 0xff, 0xc7, 0xca, 0xcd, 0x72, 0x57, 0x0a, 0x00, 0x00, } diff --git a/grpc/controlproxy/rpc/control.proto b/grpc/controlproxy/rpc/control.proto index fb3c993e9..c41790865 100644 --- a/grpc/controlproxy/rpc/control.proto +++ b/grpc/controlproxy/rpc/control.proto @@ -33,6 +33,7 @@ service MetricManager { rpc SubscribeDeps(SubscribeDepsRequest) returns (SubscribeDepsReply) {} rpc UnsubscribeDeps(SubscribeDepsRequest) returns (SubscribeDepsReply) {} rpc MatchQueryToNamespaces(ExpandWildcardsRequest) returns (ExpandWildcardsReply) {} + rpc GetAutodiscoverPaths(common.Empty) returns (GetAutodiscoverPathsReply) {} } // managesMetrics from scheduler @@ -121,3 +122,7 @@ message ExpandWildcardsReply { repeated ArrString NSS = 1; common.SnapError Error = 2; } + +message GetAutodiscoverPathsReply{ + repeated string Paths = 1; +} From 58a60c39237dcaffbd80b16cd5ab3477e17cdfb8 Mon Sep 17 00:00:00 2001 From: Olivier Bourdon Date: Thu, 2 Jun 2016 13:56:06 +0200 Subject: [PATCH 2/4] Add tasks creation and activation when some found in auto_discover_path --- mgmt/rest/client/task.go | 6 +- mgmt/rest/config.go | 5 +- mgmt/rest/rbody/task.go | 10 +- mgmt/rest/request/task.go | 39 -------- mgmt/rest/rest_func_test.go | 6 +- mgmt/rest/server.go | 14 --- mgmt/rest/task.go | 126 +----------------------- mgmt/tribe/worker/worker.go | 4 +- pkg/task/task.go | 190 ++++++++++++++++++++++++++++++++++++ scheduler/scheduler.go | 163 +++++++++++++++++++++++++++++++ scheduler/scheduler_test.go | 9 ++ 11 files changed, 380 insertions(+), 192 deletions(-) delete mode 100644 mgmt/rest/request/task.go create mode 100644 pkg/task/task.go diff --git a/mgmt/rest/client/task.go b/mgmt/rest/client/task.go index 07589820c..02fbe1d9f 100644 --- a/mgmt/rest/client/task.go +++ b/mgmt/rest/client/task.go @@ -29,7 +29,7 @@ import ( "time" "github.com/intelsdi-x/snap/mgmt/rest/rbody" - "github.com/intelsdi-x/snap/mgmt/rest/request" + "github.com/intelsdi-x/snap/pkg/task" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -49,8 +49,8 @@ type Schedule struct { // Otherwise, it's in the Stopped state. CreateTask is accomplished through a POST HTTP JSON request. // A ScheduledTask is returned if it succeeds, otherwise an error is returned. func (c *Client) CreateTask(s *Schedule, wf *wmap.WorkflowMap, name string, deadline string, startTask bool) *CreateTaskResult { - t := request.TaskCreationRequest{ - Schedule: request.Schedule{ + t := task.TaskCreationRequest{ + Schedule: task.Schedule{ Type: s.Type, Interval: s.Interval, }, diff --git a/mgmt/rest/config.go b/mgmt/rest/config.go index b49dd636d..8ab3e327b 100644 --- a/mgmt/rest/config.go +++ b/mgmt/rest/config.go @@ -26,6 +26,7 @@ import ( "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/cdata" "github.com/intelsdi-x/snap/mgmt/rest/rbody" + "github.com/intelsdi-x/snap/pkg/task" "github.com/julienschmidt/httprouter" ) @@ -87,7 +88,7 @@ func (s *Server) deletePluginConfigItem(w http.ResponseWriter, r *http.Request, } src := []string{} - errCode, err := marshalBody(&src, r.Body) + errCode, err := task.MarshalBody(&src, r.Body) if errCode != 0 && err != nil { respond(400, rbody.FromError(err), w) return @@ -129,7 +130,7 @@ func (s *Server) setPluginConfigItem(w http.ResponseWriter, r *http.Request, p h } src := cdata.NewNode() - errCode, err := marshalBody(src, r.Body) + errCode, err := task.MarshalBody(src, r.Body) if errCode != 0 && err != nil { respond(400, rbody.FromError(err), w) return diff --git a/mgmt/rest/rbody/task.go b/mgmt/rest/rbody/task.go index ae372476f..e3b40049c 100644 --- a/mgmt/rest/rbody/task.go +++ b/mgmt/rest/rbody/task.go @@ -25,8 +25,8 @@ import ( "time" "github.com/intelsdi-x/snap/core" - "github.com/intelsdi-x/snap/mgmt/rest/request" "github.com/intelsdi-x/snap/pkg/schedule" + "github.com/intelsdi-x/snap/pkg/task" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -121,7 +121,7 @@ type ScheduledTask struct { Name string `json:"name"` Deadline string `json:"deadline"` Workflow *wmap.WorkflowMap `json:"workflow,omitempty"` - Schedule *request.Schedule `json:"schedule,omitempty"` + Schedule *task.Schedule `json:"schedule,omitempty"` CreationTimestamp int64 `json:"creation_timestamp,omitempty"` LastRunTimestamp int64 `json:"last_run_timestamp,omitempty"` HitCount int `json:"hit_count,omitempty"` @@ -217,7 +217,7 @@ func (s *ScheduledTaskEnabled) ResponseBodyType() string { func assertSchedule(s schedule.Schedule, t *AddScheduledTask) { switch v := s.(type) { case *schedule.SimpleSchedule: - t.Schedule = &request.Schedule{ + t.Schedule = &task.Schedule{ Type: "simple", Interval: v.Interval.String(), } @@ -225,7 +225,7 @@ func assertSchedule(s schedule.Schedule, t *AddScheduledTask) { case *schedule.WindowedSchedule: startTime := v.StartTime.Unix() stopTime := v.StopTime.Unix() - t.Schedule = &request.Schedule{ + t.Schedule = &task.Schedule{ Type: "windowed", Interval: v.Interval.String(), StartTimestamp: &startTime, @@ -233,7 +233,7 @@ func assertSchedule(s schedule.Schedule, t *AddScheduledTask) { } return case *schedule.CronSchedule: - t.Schedule = &request.Schedule{ + t.Schedule = &task.Schedule{ Type: "cron", Interval: v.Entry(), } diff --git a/mgmt/rest/request/task.go b/mgmt/rest/request/task.go deleted file mode 100644 index 80c3fb82d..000000000 --- a/mgmt/rest/request/task.go +++ /dev/null @@ -1,39 +0,0 @@ -/* -http://www.apache.org/licenses/LICENSE-2.0.txt - - -Copyright 2015 Intel Corporation - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package request - -import ( - "github.com/intelsdi-x/snap/scheduler/wmap" -) - -type TaskCreationRequest struct { - Name string `json:"name"` - Deadline string `json:"deadline"` - Workflow *wmap.WorkflowMap `json:"workflow"` - Schedule Schedule `json:"schedule"` - Start bool `json:"start"` -} - -type Schedule struct { - Type string `json:"type,omitempty"` - Interval string `json:"interval,omitempty"` - StartTimestamp *int64 `json:"start_timestamp,omitempty"` - StopTimestamp *int64 `json:"stop_timestamp,omitempty"` -} diff --git a/mgmt/rest/rest_func_test.go b/mgmt/rest/rest_func_test.go index 331638d3b..6c4e6a38d 100644 --- a/mgmt/rest/rest_func_test.go +++ b/mgmt/rest/rest_func_test.go @@ -45,8 +45,8 @@ import ( "github.com/intelsdi-x/snap/core/cdata" "github.com/intelsdi-x/snap/core/ctypes" "github.com/intelsdi-x/snap/mgmt/rest/rbody" - "github.com/intelsdi-x/snap/mgmt/rest/request" "github.com/intelsdi-x/snap/pkg/cfgfile" + "github.com/intelsdi-x/snap/pkg/task" "github.com/intelsdi-x/snap/scheduler" "github.com/intelsdi-x/snap/scheduler/wmap" . "github.com/smartystreets/goconvey/convey" @@ -252,8 +252,8 @@ func createTask(sample, name, interval string, noStart bool, port int) *rbody.AP uri := fmt.Sprintf("http://localhost:%d/v1/tasks", port) - t := request.TaskCreationRequest{ - Schedule: request.Schedule{Type: "simple", Interval: interval}, + t := task.TaskCreationRequest{ + Schedule: task.Schedule{Type: "simple", Interval: interval}, Workflow: wf, Name: name, Start: !noStart, diff --git a/mgmt/rest/server.go b/mgmt/rest/server.go index dc155f576..e2fbe0d54 100644 --- a/mgmt/rest/server.go +++ b/mgmt/rest/server.go @@ -23,8 +23,6 @@ import ( "encoding/json" "errors" "fmt" - "io" - "io/ioutil" "net" "net/http" "strings" @@ -470,18 +468,6 @@ func respond(code int, b rbody.Body, w http.ResponseWriter) { fmt.Fprint(w, string(j)) } -func marshalBody(in interface{}, body io.ReadCloser) (int, error) { - b, err := ioutil.ReadAll(body) - if err != nil { - return 500, err - } - err = json.Unmarshal(b, in) - if err != nil { - return 400, err - } - return 0, nil -} - func parseNamespace(ns string) []string { if strings.Index(ns, "/") == 0 { ns = ns[1:] diff --git a/mgmt/rest/task.go b/mgmt/rest/task.go index 1f42b9021..1372a6abc 100644 --- a/mgmt/rest/task.go +++ b/mgmt/rest/task.go @@ -22,7 +22,6 @@ package rest import ( "errors" "fmt" - "io" "net/http" "sort" "strings" @@ -33,9 +32,7 @@ import ( "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/mgmt/rest/rbody" - "github.com/intelsdi-x/snap/mgmt/rest/request" - cschedule "github.com/intelsdi-x/snap/pkg/schedule" - "github.com/intelsdi-x/snap/scheduler/wmap" + mtask "github.com/intelsdi-x/snap/pkg/task" ) var ( @@ -47,66 +44,12 @@ var ( ErrTaskDisabledNotRunnable = errors.New("Task is disabled. Cannot be started") ) -type configItem struct { - Key string `json:"key"` - Value interface{} `json:"value"` -} - -type task struct { - ID uint64 `json:"id"` - Config map[string][]configItem `json:"config"` - Name string `json:"name"` - Deadline string `json:"deadline"` - Workflow wmap.WorkflowMap `json:"workflow"` - Schedule cschedule.Schedule `json:"schedule"` - CreationTime time.Time `json:"creation_timestamp,omitempty"` - LastRunTime time.Time `json:"last_run_timestamp,omitempty"` - HitCount uint `json:"hit_count,omitempty"` - MissCount uint `json:"miss_count,omitempty"` - FailedCount uint `json:"failed_count,omitempty"` - LastFailureMessage string `json:"last_failure_message,omitempty"` - State string `json:"task_state"` -} - func (s *Server) addTask(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { - - tr, err := marshalTask(r.Body) - if err != nil { - respond(500, rbody.FromError(err), w) - return - } - - sch, err := makeSchedule(tr.Schedule) + task, err := mtask.CreateTaskFromContent(r.Body, nil, s.mt.CreateTask) if err != nil { respond(500, rbody.FromError(err), w) return } - - var opts []core.TaskOption - if tr.Deadline != "" { - dl, err := time.ParseDuration(tr.Deadline) - if err != nil { - respond(500, rbody.FromError(err), w) - return - } - opts = append(opts, core.TaskDeadlineDuration(dl)) - } - - if tr.Name != "" { - opts = append(opts, core.SetTaskName(tr.Name)) - } - opts = append(opts, core.OptionStopOnFailure(10)) - - task, errs := s.mt.CreateTask(sch, tr.Workflow, tr.Start, opts...) - if errs != nil && len(errs.Errors()) != 0 { - var errMsg string - for _, e := range errs.Errors() { - errMsg = errMsg + e.Error() + " -- " - } - respond(500, rbody.FromError(errors.New(errMsg[:len(errMsg)-4])), w) - return - } - taskB := rbody.AddSchedulerTaskFromTask(task) taskB.Href = taskURI(r.Host, task) respond(201, taskB, w) @@ -311,71 +254,6 @@ func (s *Server) enableTask(w http.ResponseWriter, r *http.Request, p httprouter respond(200, task, w) } -func marshalTask(body io.ReadCloser) (*request.TaskCreationRequest, error) { - var tr request.TaskCreationRequest - errCode, err := marshalBody(&tr, body) - if errCode != 0 && err != nil { - return nil, err - } - return &tr, nil -} - -func makeSchedule(s request.Schedule) (cschedule.Schedule, error) { - switch s.Type { - case "simple": - d, err := time.ParseDuration(s.Interval) - if err != nil { - return nil, err - } - sch := cschedule.NewSimpleSchedule(d) - - err = sch.Validate() - if err != nil { - return nil, err - } - return sch, nil - case "windowed": - d, err := time.ParseDuration(s.Interval) - if err != nil { - return nil, err - } - - var start, stop *time.Time - if s.StartTimestamp != nil { - t := time.Unix(*s.StartTimestamp, 0) - start = &t - } - if s.StopTimestamp != nil { - t := time.Unix(*s.StopTimestamp, 0) - stop = &t - } - sch := cschedule.NewWindowedSchedule( - d, - start, - stop, - ) - - err = sch.Validate() - if err != nil { - return nil, err - } - return sch, nil - case "cron": - if s.Interval == "" { - return nil, errors.New("missing cron entry ") - } - sch := cschedule.NewCronSchedule(s.Interval) - - err := sch.Validate() - if err != nil { - return nil, err - } - return sch, nil - default: - return nil, errors.New("unknown schedule type " + s.Type) - } -} - type TaskWatchHandler struct { streamCount int alive bool diff --git a/mgmt/tribe/worker/worker.go b/mgmt/tribe/worker/worker.go index 603664dca..a33b0df43 100644 --- a/mgmt/tribe/worker/worker.go +++ b/mgmt/tribe/worker/worker.go @@ -35,8 +35,8 @@ import ( "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/mgmt/rest/client" - "github.com/intelsdi-x/snap/mgmt/rest/request" "github.com/intelsdi-x/snap/pkg/schedule" + "github.com/intelsdi-x/snap/pkg/task" "github.com/intelsdi-x/snap/scheduler" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -514,7 +514,7 @@ func (w worker) isPluginLoaded(n, t string, v int) bool { return false } -func getSchedule(s *request.Schedule) schedule.Schedule { +func getSchedule(s *task.Schedule) schedule.Schedule { switch s.Type { case "simple": d, e := time.ParseDuration(s.Interval) diff --git a/pkg/task/task.go b/pkg/task/task.go new file mode 100644 index 000000000..f5a1a8538 --- /dev/null +++ b/pkg/task/task.go @@ -0,0 +1,190 @@ +/* +http://www.apache.org/licenses/LICENSE-2.0.txt + + +Copyright 2015 Intel Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package task + +import ( + "encoding/json" + "errors" + "io" + "io/ioutil" + "time" + + "github.com/intelsdi-x/snap/core" + "github.com/intelsdi-x/snap/pkg/schedule" + "github.com/intelsdi-x/snap/scheduler/wmap" +) + +type TaskCreationRequest struct { + Name string `json:"name"` + Deadline string `json:"deadline"` + Workflow *wmap.WorkflowMap `json:"workflow"` + Schedule Schedule `json:"schedule"` + Start bool `json:"start"` +} + +type Schedule struct { + Type string `json:"type,omitempty"` + Interval string `json:"interval,omitempty"` + StartTimestamp *int64 `json:"start_timestamp,omitempty"` + StopTimestamp *int64 `json:"stop_timestamp,omitempty"` +} + +type configItem struct { + Key string `json:"key"` + Value interface{} `json:"value"` +} + +type task struct { + ID uint64 `json:"id"` + Config map[string][]configItem `json:"config"` + Name string `json:"name"` + Deadline string `json:"deadline"` + Workflow wmap.WorkflowMap `json:"workflow"` + Schedule schedule.Schedule `json:"schedule"` + CreationTime time.Time `json:"creation_timestamp,omitempty"` + LastRunTime time.Time `json:"last_run_timestamp,omitempty"` + HitCount uint `json:"hit_count,omitempty"` + MissCount uint `json:"miss_count,omitempty"` + FailedCount uint `json:"failed_count,omitempty"` + LastFailureMessage string `json:"last_failure_message,omitempty"` + State string `json:"task_state"` +} + +// +func CreateTaskFromContent(body io.ReadCloser, + mode *bool, + fp func(sch schedule.Schedule, + wfMap *wmap.WorkflowMap, + startOnCreate bool, + opts ...core.TaskOption) (core.Task, core.TaskErrors)) (core.Task, error) { + tr, err := marshalTask(body) + if err != nil { + return nil, err + } + + sch, err := makeSchedule(tr.Schedule) + if err != nil { + return nil, err + } + + var opts []core.TaskOption + if tr.Deadline != "" { + dl, err := time.ParseDuration(tr.Deadline) + if err != nil { + return nil, err + } + opts = append(opts, core.TaskDeadlineDuration(dl)) + } + + if tr.Name != "" { + opts = append(opts, core.SetTaskName(tr.Name)) + } + opts = append(opts, core.OptionStopOnFailure(10)) + + if mode == nil { + mode = &tr.Start + } + task, errs := fp(sch, tr.Workflow, *mode, opts...) + if errs != nil && len(errs.Errors()) != 0 { + var errMsg string + for _, e := range errs.Errors() { + errMsg = errMsg + e.Error() + " -- " + } + return nil, errors.New(errMsg[:len(errMsg)-4]) + } + return task, nil +} + +func marshalTask(body io.ReadCloser) (*TaskCreationRequest, error) { + var tr TaskCreationRequest + errCode, err := MarshalBody(&tr, body) + if errCode != 0 && err != nil { + return nil, err + } + return &tr, nil +} + +func makeSchedule(s Schedule) (schedule.Schedule, error) { + switch s.Type { + case "simple": + d, err := time.ParseDuration(s.Interval) + if err != nil { + return nil, err + } + sch := schedule.NewSimpleSchedule(d) + + err = sch.Validate() + if err != nil { + return nil, err + } + return sch, nil + case "windowed": + d, err := time.ParseDuration(s.Interval) + if err != nil { + return nil, err + } + + var start, stop *time.Time + if s.StartTimestamp != nil { + t := time.Unix(*s.StartTimestamp, 0) + start = &t + } + if s.StopTimestamp != nil { + t := time.Unix(*s.StopTimestamp, 0) + stop = &t + } + sch := schedule.NewWindowedSchedule( + d, + start, + stop, + ) + + err = sch.Validate() + if err != nil { + return nil, err + } + return sch, nil + case "cron": + if s.Interval == "" { + return nil, errors.New("missing cron entry ") + } + sch := schedule.NewCronSchedule(s.Interval) + + err := sch.Validate() + if err != nil { + return nil, err + } + return sch, nil + default: + return nil, errors.New("unknown schedule type " + s.Type) + } +} + +func MarshalBody(in interface{}, body io.ReadCloser) (int, error) { + b, err := ioutil.ReadAll(body) + if err != nil { + return 500, err + } + err = json.Unmarshal(b, in) + if err != nil { + return 400, err + } + return 0, nil +} diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index aebad465f..f23ecc703 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -22,9 +22,17 @@ package scheduler import ( "errors" "fmt" + "io/ioutil" + "os" + "path" + "path/filepath" + "strings" "time" log "github.com/Sirupsen/logrus" + + "github.com/ghodss/yaml" + "github.com/intelsdi-x/gomit" "github.com/intelsdi-x/snap/core" @@ -32,6 +40,7 @@ import ( "github.com/intelsdi-x/snap/core/scheduler_event" "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/pkg/schedule" + mtask "github.com/intelsdi-x/snap/pkg/task" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -70,6 +79,7 @@ type managesMetrics interface { publishesMetrics processesMetrics managesPluginContentTypes + GetAutodiscoverPaths() []string ValidateDeps([]core.Metric, []core.SubscribedPlugin) []serror.SnapError SubscribeDeps(string, []core.Metric, []core.Plugin) []serror.SnapError UnsubscribeDeps(string, []core.Metric, []core.Plugin) []serror.SnapError @@ -107,6 +117,111 @@ type managesWork interface { Work(job) queuedJob } +// Implemented as a separate function so that defer calls +// are properly handled and cleanup done properly +// (like for the removal of temporary Yaml to JSON conversion) +func autoDiscoverTasks(taskFiles []os.FileInfo, fullPath string, + fp func(sch schedule.Schedule, + wfMap *wmap.WorkflowMap, + startOnCreate bool, + opts ...core.TaskOption) (core.Task, core.TaskErrors)) { + // Note that the list of files is sorted by name due to ioutil.ReadDir + // default behaviour. See go doc ioutil.ReadDir + for _, file := range taskFiles { + f, err := os.Open(path.Join(fullPath, file.Name())) + if err != nil { + log.WithFields(log.Fields{ + "_block": "autoDiscoverTasks", + "_module": "scheduler", + "autodiscoverpath": fullPath, + "task": file.Name(), + }).Error("Opening file ", err) + continue + } + defer f.Close() + if !strings.HasSuffix(file.Name(), ".json") { + fc, err := ioutil.ReadAll(f) + if err != nil { + log.WithFields( + log.Fields{ + "_block": "autoDiscoverTasks", + "_module": "scheduler", + "autodiscoverpath": fullPath, + "task": file.Name(), + }).Error("Reading Yaml file ", err) + continue + } + js, err := yaml.YAMLToJSON(fc) + if err != nil { + log.WithFields( + log.Fields{ + "_block": "autoDiscoverTasks", + "_module": "scheduler", + "autodiscoverpath": fullPath, + "task": file.Name(), + }).Error("Parsing Yaml file ", err) + continue + } + tfile, err := ioutil.TempFile(os.TempDir(), "yaml2json") + if err != nil { + log.WithFields( + log.Fields{ + "_block": "autoDiscoverTasks", + "_module": "scheduler", + "autodiscoverpath": fullPath, + "task": file.Name(), + }).Error("Creating temporary file ", err) + continue + } + defer os.Remove(tfile.Name()) + err = ioutil.WriteFile(tfile.Name(), js, 0644) + if err != nil { + log.WithFields( + log.Fields{ + "_block": "autoDiscoverTasks", + "_module": "scheduler", + "autodiscoverpath": fullPath, + "task": file.Name(), + }).Error("Writing JSON file from Yaml ", err) + continue + } + f, err = os.Open(tfile.Name()) + if err != nil { + log.WithFields(log.Fields{ + "_block": "autoDiscoverTasks", + "_module": "scheduler", + "autodiscoverpath": fullPath, + "task": file.Name(), + }).Error("Opening temporary file ", err) + continue + } + defer f.Close() + } + mode := true + task, err := mtask.CreateTaskFromContent(f, &mode, fp) + if err != nil { + log.WithFields(log.Fields{ + "_block": "autoDiscoverTasks", + "_module": "scheduler", + "autodiscoverpath": fullPath, + "task": file.Name(), + }).Error(err) + continue + } + //TODO: see if the following is really mandatory + //in which case mgmt/rest/rbody/task.go contents might also + //move into pkg/task + //rbody.AddSchedulerTaskFromTask(task) + log.WithFields(log.Fields{ + "_block": "autoDiscoverTasks", + "_module": "scheduler", + "autodiscoverpath": fullPath, + "task-file-name": file.Name(), + "task-ID": task.ID(), + }).Info("Loading task") + } +} + // New returns an instance of the scheduler // The MetricManager must be set before the scheduler can be started. // The MetricManager must be started before it can be used. @@ -525,6 +640,54 @@ func (s *scheduler) Start() error { "_block": "start-scheduler", }).Info("scheduler started") + //Autodiscover + autoDiscoverPaths := s.metricManager.GetAutodiscoverPaths() + if autoDiscoverPaths != nil && len(autoDiscoverPaths) != 0 { + schedulerLogger.WithFields(log.Fields{ + "_block": "start-scheduler", + }).Info("auto discover path is enabled") + for _, pa := range autoDiscoverPaths { + fullPath, err := filepath.Abs(pa) + if err != nil { + schedulerLogger.WithFields(log.Fields{ + "_block": "start-scheduler", + "autodiscoverpath": pa, + }).Fatal(err) + } + schedulerLogger.WithFields(log.Fields{ + "_block": "start-scheduler", + }).Info("autoloading tasks from: ", fullPath) + files, err := ioutil.ReadDir(fullPath) + if err != nil { + schedulerLogger.WithFields(log.Fields{ + "_block": "start-scheduler", + "autodiscoverpath": pa, + }).Fatal(err) + } + var taskFiles []os.FileInfo + for _, file := range files { + if file.IsDir() { + schedulerLogger.WithFields(log.Fields{ + "_block": "start-scheduler", + "autodiscoverpath": pa, + }).Warning("Ignoring subdirectory: ", file.Name()) + continue + } + // tasks files (JSON and YAML) + fname := strings.ToLower(file.Name()) + if !strings.HasSuffix(fname, ".json") && !strings.HasSuffix(fname, ".yaml") && !strings.HasSuffix(fname, ".yml") { + continue + } + taskFiles = append(taskFiles, file) + } + autoDiscoverTasks(taskFiles, fullPath, s.CreateTask) + } + } else { + schedulerLogger.WithFields(log.Fields{ + "_block": "start-scheduler", + }).Info("auto discover path is disabled") + } + return nil } diff --git a/scheduler/scheduler_test.go b/scheduler/scheduler_test.go index b916d0d6d..ae36a89d0 100644 --- a/scheduler/scheduler_test.go +++ b/scheduler/scheduler_test.go @@ -44,6 +44,7 @@ type mockMetricManager struct { failuredSoFar int acceptedContentTypes map[string][]string returnedContentTypes map[string][]string + autodiscoverPaths []string } func (m *mockMetricManager) lazyContentType(key string) { @@ -119,6 +120,14 @@ func (m *mockMetricManager) ExpandWildcards(core.Namespace) ([]core.Namespace, s return nil, nil } +func (m *mockMetricManager) SetAutodiscoverPaths(paths []string) { + m.autodiscoverPaths = paths +} + +func (m *mockMetricManager) GetAutodiscoverPaths() []string { + return m.autodiscoverPaths +} + type mockMetricManagerError struct { errs []error } From 0c1c23297c69d51c0331fd618d179d09802bd668 Mon Sep 17 00:00:00 2001 From: Olivier Bourdon Date: Mon, 6 Jun 2016 15:10:07 +0200 Subject: [PATCH 3/4] Tests added --- pkg/task/task.go | 11 +- pkg/task/task_test.go | 339 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+), 2 deletions(-) create mode 100644 pkg/task/task_test.go diff --git a/pkg/task/task.go b/pkg/task/task.go index f5a1a8538..be8c74ab2 100644 --- a/pkg/task/task.go +++ b/pkg/task/task.go @@ -67,13 +67,17 @@ type task struct { State string `json:"task_state"` } -// +// Function used to create a task according to content (1st parameter) +// . Content can be retrieved from a configuration file or a HTTP REST request body +// . Mode is used to specify if the created task should start right away or not +// . function pointer is responsible for effectively creating and returning the created task func CreateTaskFromContent(body io.ReadCloser, mode *bool, fp func(sch schedule.Schedule, wfMap *wmap.WorkflowMap, startOnCreate bool, opts ...core.TaskOption) (core.Task, core.TaskErrors)) (core.Task, error) { + tr, err := marshalTask(body) if err != nil { return nil, err @@ -101,6 +105,9 @@ func CreateTaskFromContent(body io.ReadCloser, if mode == nil { mode = &tr.Start } + if fp == nil { + return nil, errors.New("Missing workflow creation routine") + } task, errs := fp(sch, tr.Workflow, *mode, opts...) if errs != nil && len(errs.Errors()) != 0 { var errMsg string @@ -163,7 +170,7 @@ func makeSchedule(s Schedule) (schedule.Schedule, error) { return sch, nil case "cron": if s.Interval == "" { - return nil, errors.New("missing cron entry ") + return nil, errors.New("missing cron entry") } sch := schedule.NewCronSchedule(s.Interval) diff --git a/pkg/task/task_test.go b/pkg/task/task_test.go new file mode 100644 index 000000000..cdec8af24 --- /dev/null +++ b/pkg/task/task_test.go @@ -0,0 +1,339 @@ +// +build small + +/* +http://www.apache.org/licenses/LICENSE-2.0.txt + + +Copyright 2016 Intel Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package task + +import ( + "errors" + "fmt" + "os" + "testing" + "time" + + "github.com/intelsdi-x/snap/core" + "github.com/intelsdi-x/snap/core/serror" + "github.com/intelsdi-x/snap/pkg/schedule" + "github.com/intelsdi-x/snap/scheduler/wmap" + . "github.com/smartystreets/goconvey/convey" +) + +type TaskReq1 struct { + Name string `json:"name"` + Start bool `json:"start"` +} + +type taskErrors struct { + errs []serror.SnapError +} + +func (t *taskErrors) Errors() []serror.SnapError { + return t.errs +} + +const ( + DUMMY_FILE = "dummy.txt" + YAML_FILE = "../../examples/tasks/mock-file.yaml" + JSON_FILE = "../../examples/tasks/mock-file.json" + DUMMY_TYPE = "dummy" +) + +func koRoutine(sch schedule.Schedule, + wfMap *wmap.WorkflowMap, + startOnCreate bool, + opts ...core.TaskOption) (core.Task, core.TaskErrors) { + // Create a container for task errors + te := &taskErrors{ + errs: make([]serror.SnapError, 0), + } + te.errs = append(te.errs, serror.New(errors.New("Dummy error"))) + return nil, te +} + +func okRoutine(sch schedule.Schedule, + wfMap *wmap.WorkflowMap, + startOnCreate bool, + opts ...core.TaskOption) (core.Task, core.TaskErrors) { + return nil, nil +} + +func TestMarshalBodyTask(t *testing.T) { + + Convey("Non existing file", t, func() { + file, err := os.Open(DUMMY_FILE) + So(file, ShouldBeNil) + So(err.Error(), ShouldEqual, fmt.Sprintf("open %s: no such file or directory", DUMMY_FILE)) + code, err := MarshalBody(nil, file) + So(code, ShouldEqual, 500) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "invalid argument") + }) + + Convey("Bad JSON file", t, func() { + var tr TaskReq1 + file, err := os.Open(YAML_FILE) + So(file, ShouldNotBeNil) + So(err, ShouldBeNil) + code, err := MarshalBody(&tr, file) + So(code, ShouldEqual, 400) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "invalid character '-' in numeric literal") + }) + + Convey("Proper JSON file", t, func() { + var tr TaskReq1 + file, err := os.Open(JSON_FILE) + So(file, ShouldNotBeNil) + So(err, ShouldBeNil) + code, err := MarshalBody(&tr, file) + So(code, ShouldEqual, 0) + So(err, ShouldBeNil) + }) +} + +func TestMarshalTask(t *testing.T) { + + Convey("Non existing file", t, func() { + file, err := os.Open(DUMMY_FILE) + So(file, ShouldBeNil) + So(err.Error(), ShouldEqual, fmt.Sprintf("open %s: no such file or directory", DUMMY_FILE)) + task, err := marshalTask(file) + So(task, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "invalid argument") + }) + + Convey("Bad JSON file", t, func() { + file, err := os.Open(YAML_FILE) + So(file, ShouldNotBeNil) + So(err, ShouldBeNil) + task, err := marshalTask(file) + So(task, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "invalid character '-' in numeric literal") + }) + + Convey("Proper JSON file", t, func() { + file, err := os.Open(JSON_FILE) + So(file, ShouldNotBeNil) + So(err, ShouldBeNil) + task, err := marshalTask(file) + So(err, ShouldBeNil) + So(task, ShouldNotBeNil) + So(task.Name, ShouldEqual, "") + So(task.Deadline, ShouldEqual, "") + So(task.Schedule.Type, ShouldEqual, "simple") + So(task.Schedule.Interval, ShouldEqual, "1s") + So(task.Schedule.StartTimestamp, ShouldBeNil) + So(task.Schedule.StopTimestamp, ShouldBeNil) + So(task.Start, ShouldEqual, false) + }) +} + +func TestMakeSchedule(t *testing.T) { + + Convey("Bad schedule type", t, func() { + sched1 := &Schedule{Type: DUMMY_TYPE} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, fmt.Sprintf("unknown schedule type %s", DUMMY_TYPE)) + }) + + Convey("Simple schedule with bad duration", t, func() { + sched1 := &Schedule{Type: "simple", Interval: "dummy"} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldStartWith, "time: invalid duration ") + }) + + Convey("Simple schedule with invalid duration", t, func() { + sched1 := &Schedule{Type: "simple", Interval: "-1s"} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "Interval must be greater than 0") + }) + + Convey("Simple schedule with proper duration", t, func() { + sched1 := &Schedule{Type: "simple", Interval: "1s"} + rsched, err := makeSchedule(*sched1) + So(err, ShouldBeNil) + So(rsched, ShouldNotBeNil) + So(rsched.GetState(), ShouldEqual, 0) + }) + + Convey("Windowed schedule with bad duration", t, func() { + sched1 := &Schedule{Type: "windowed", Interval: "dummy"} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldStartWith, "time: invalid duration ") + }) + + Convey("Windowed schedule with invalid duration", t, func() { + sched1 := &Schedule{Type: "windowed", Interval: "-1s"} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "Interval must be greater than 0") + }) + + Convey("Windowed schedule with stop in the past", t, func() { + now := time.Now() + startSecs := now.Unix() + stopSecs := startSecs - 3600 + sched1 := &Schedule{Type: "windowed", Interval: "1s", + StartTimestamp: &startSecs, StopTimestamp: &stopSecs} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "Stop time is in the past") + }) + + Convey("Windowed schedule with stop before start", t, func() { + now := time.Now() + startSecs := now.Unix() + stopSecs := startSecs + 600 + startSecs = stopSecs + 600 + sched1 := &Schedule{Type: "windowed", Interval: "1s", + StartTimestamp: &startSecs, StopTimestamp: &stopSecs} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "Stop time cannot occur before start time") + }) + + Convey("Windowed schedule with stop before start", t, func() { + now := time.Now() + startSecs := now.Unix() + stopSecs := startSecs + 600 + sched1 := &Schedule{Type: "windowed", Interval: "1s", + StartTimestamp: &startSecs, StopTimestamp: &stopSecs} + rsched, err := makeSchedule(*sched1) + So(err, ShouldBeNil) + So(rsched, ShouldNotBeNil) + So(rsched.GetState(), ShouldEqual, 0) + }) + + Convey("Cron schedule with bad duration", t, func() { + sched1 := &Schedule{Type: "cron", Interval: ""} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "missing cron entry") + }) + + Convey("Cron schedule with invalid duration", t, func() { + sched1 := &Schedule{Type: "windowed", Interval: "-1s"} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "Interval must be greater than 0") + }) + + Convey("Cron schedule with too few fields entry", t, func() { + sched1 := &Schedule{Type: "cron", Interval: "1 2 3"} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldStartWith, "Expected 5 or 6 fields, found ") + }) + + Convey("Cron schedule with 5 fields entry", t, func() { + sched1 := &Schedule{Type: "cron", Interval: "1 2 3 4 5"} + rsched, err := makeSchedule(*sched1) + So(err, ShouldBeNil) + So(rsched, ShouldNotBeNil) + }) + + Convey("Cron schedule with 6 fields entry", t, func() { + sched1 := &Schedule{Type: "cron", Interval: "1 2 3 4 5 6"} + rsched, err := makeSchedule(*sched1) + So(err, ShouldBeNil) + So(rsched, ShouldNotBeNil) + }) + + Convey("Cron schedule with too many fields entry", t, func() { + sched1 := &Schedule{Type: "cron", Interval: "1 2 3 4 5 6 7 8"} + rsched, err := makeSchedule(*sched1) + So(rsched, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldStartWith, "Expected 5 or 6 fields, found ") + }) +} + +func TestCreateTaskFromContent(t *testing.T) { + + Convey("Non existing file", t, func() { + file, err := os.Open(DUMMY_FILE) + So(file, ShouldBeNil) + So(err.Error(), ShouldEqual, fmt.Sprintf("open %s: no such file or directory", DUMMY_FILE)) + autoStart := true + task, err := CreateTaskFromContent(file, &autoStart, nil) + So(task, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "invalid argument") + }) + + Convey("Bad JSON file", t, func() { + file, err := os.Open(YAML_FILE) + So(file, ShouldNotBeNil) + So(err, ShouldBeNil) + autoStart := true + task, err := CreateTaskFromContent(file, &autoStart, nil) + So(task, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "invalid character '-' in numeric literal") + }) + + Convey("Proper JSON file no workflow routine", t, func() { + file, err := os.Open(JSON_FILE) + So(file, ShouldNotBeNil) + So(err, ShouldBeNil) + autoStart := true + task, err := CreateTaskFromContent(file, &autoStart, nil) + So(task, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "Missing workflow creation routine") + }) + + Convey("Proper JSON file erroring routine", t, func() { + file, err := os.Open(JSON_FILE) + So(file, ShouldNotBeNil) + So(err, ShouldBeNil) + autoStart := true + task, err := CreateTaskFromContent(file, &autoStart, koRoutine) + So(task, ShouldBeNil) + So(err, ShouldNotBeNil) + So(err.Error(), ShouldEqual, "Dummy error") + }) + + Convey("Proper JSON file proper routine", t, func() { + file, err := os.Open(JSON_FILE) + So(file, ShouldNotBeNil) + So(err, ShouldBeNil) + autoStart := true + task, err := CreateTaskFromContent(file, &autoStart, okRoutine) + So(task, ShouldBeNil) + So(err, ShouldBeNil) + }) +} From dfc1e3c3793e605c1d62b668a6b0888cf1badfee Mon Sep 17 00:00:00 2001 From: Joel Cooklin Date: Sun, 12 Jun 2016 20:32:03 -0700 Subject: [PATCH 4/4] Removes task pkg Updating protobuf revisionId --- Godeps/Godeps.json | 2 +- core/schedule.go | 90 +++++++++++++++ core/task.go | 85 ++++++++++++++ {pkg/task => core}/task_test.go | 11 +- mgmt/rest/client/task.go | 6 +- mgmt/rest/config.go | 5 +- mgmt/rest/rbody/task.go | 9 +- mgmt/rest/rest_func_test.go | 7 +- mgmt/rest/task.go | 3 +- mgmt/tribe/worker/worker.go | 3 +- pkg/task/task.go | 197 -------------------------------- scheduler/scheduler.go | 3 +- scheduler/scheduler_test.go | 2 +- 13 files changed, 197 insertions(+), 226 deletions(-) create mode 100644 core/schedule.go rename {pkg/task => core}/task_test.go (97%) delete mode 100644 pkg/task/task.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index a8f5158b1..698940947 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -79,7 +79,7 @@ }, { "ImportPath": "github.com/golang/protobuf/proto", - "Rev": "b982704f8bb716bb608144408cff30e15fbde841" + "Rev": "8616e8ee5e20a1704615e6c8d7afcdac06087a67" }, { "ImportPath": "github.com/hashicorp/go-msgpack/codec", diff --git a/core/schedule.go b/core/schedule.go new file mode 100644 index 000000000..04a9c1a4c --- /dev/null +++ b/core/schedule.go @@ -0,0 +1,90 @@ +/* +http://www.apache.org/licenses/LICENSE-2.0.txt + + +Copyright 2015 Intel Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package core + +import ( + "errors" + "time" + + "github.com/intelsdi-x/snap/pkg/schedule" +) + +type Schedule struct { + Type string `json:"type,omitempty"` + Interval string `json:"interval,omitempty"` + StartTimestamp *int64 `json:"start_timestamp,omitempty"` + StopTimestamp *int64 `json:"stop_timestamp,omitempty"` +} + +func makeSchedule(s Schedule) (schedule.Schedule, error) { + switch s.Type { + case "simple": + d, err := time.ParseDuration(s.Interval) + if err != nil { + return nil, err + } + sch := schedule.NewSimpleSchedule(d) + + err = sch.Validate() + if err != nil { + return nil, err + } + return sch, nil + case "windowed": + d, err := time.ParseDuration(s.Interval) + if err != nil { + return nil, err + } + + var start, stop *time.Time + if s.StartTimestamp != nil { + t := time.Unix(*s.StartTimestamp, 0) + start = &t + } + if s.StopTimestamp != nil { + t := time.Unix(*s.StopTimestamp, 0) + stop = &t + } + sch := schedule.NewWindowedSchedule( + d, + start, + stop, + ) + + err = sch.Validate() + if err != nil { + return nil, err + } + return sch, nil + case "cron": + if s.Interval == "" { + return nil, errors.New("missing cron entry") + } + sch := schedule.NewCronSchedule(s.Interval) + + err := sch.Validate() + if err != nil { + return nil, err + } + return sch, nil + default: + return nil, errors.New("unknown schedule type " + s.Type) + } +} diff --git a/core/task.go b/core/task.go index 8982d8adf..9e9d932a6 100644 --- a/core/task.go +++ b/core/task.go @@ -20,6 +20,10 @@ limitations under the License. package core import ( + "encoding/json" + "errors" + "io" + "io/ioutil" "time" log "github.com/Sirupsen/logrus" @@ -150,3 +154,84 @@ func SetTaskID(id string) TaskOption { type TaskErrors interface { Errors() []serror.SnapError } + +type TaskCreationRequest struct { + Name string `json:"name"` + Deadline string `json:"deadline"` + Workflow *wmap.WorkflowMap `json:"workflow"` + Schedule Schedule `json:"schedule"` + Start bool `json:"start"` +} + +// Function used to create a task according to content (1st parameter) +// . Content can be retrieved from a configuration file or a HTTP REST request body +// . Mode is used to specify if the created task should start right away or not +// . function pointer is responsible for effectively creating and returning the created task +func CreateTaskFromContent(body io.ReadCloser, + mode *bool, + fp func(sch schedule.Schedule, + wfMap *wmap.WorkflowMap, + startOnCreate bool, + opts ...TaskOption) (Task, TaskErrors)) (Task, error) { + + tr, err := marshalTask(body) + if err != nil { + return nil, err + } + + sch, err := makeSchedule(tr.Schedule) + if err != nil { + return nil, err + } + + var opts []TaskOption + if tr.Deadline != "" { + dl, err := time.ParseDuration(tr.Deadline) + if err != nil { + return nil, err + } + opts = append(opts, TaskDeadlineDuration(dl)) + } + + if tr.Name != "" { + opts = append(opts, SetTaskName(tr.Name)) + } + opts = append(opts, OptionStopOnFailure(10)) + + if mode == nil { + mode = &tr.Start + } + if fp == nil { + return nil, errors.New("Missing workflow creation routine") + } + task, errs := fp(sch, tr.Workflow, *mode, opts...) + if errs != nil && len(errs.Errors()) != 0 { + var errMsg string + for _, e := range errs.Errors() { + errMsg = errMsg + e.Error() + " -- " + } + return nil, errors.New(errMsg[:len(errMsg)-4]) + } + return task, nil +} + +func marshalTask(body io.ReadCloser) (*TaskCreationRequest, error) { + var tr TaskCreationRequest + errCode, err := MarshalBody(&tr, body) + if errCode != 0 && err != nil { + return nil, err + } + return &tr, nil +} + +func MarshalBody(in interface{}, body io.ReadCloser) (int, error) { + b, err := ioutil.ReadAll(body) + if err != nil { + return 500, err + } + err = json.Unmarshal(b, in) + if err != nil { + return 400, err + } + return 0, nil +} diff --git a/pkg/task/task_test.go b/core/task_test.go similarity index 97% rename from pkg/task/task_test.go rename to core/task_test.go index cdec8af24..0bd721968 100644 --- a/pkg/task/task_test.go +++ b/core/task_test.go @@ -19,7 +19,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package task +package core import ( "errors" @@ -28,7 +28,6 @@ import ( "testing" "time" - "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/pkg/schedule" "github.com/intelsdi-x/snap/scheduler/wmap" @@ -50,15 +49,15 @@ func (t *taskErrors) Errors() []serror.SnapError { const ( DUMMY_FILE = "dummy.txt" - YAML_FILE = "../../examples/tasks/mock-file.yaml" - JSON_FILE = "../../examples/tasks/mock-file.json" + YAML_FILE = "../examples/tasks/mock-file.yaml" + JSON_FILE = "../examples/tasks/mock-file.json" DUMMY_TYPE = "dummy" ) func koRoutine(sch schedule.Schedule, wfMap *wmap.WorkflowMap, startOnCreate bool, - opts ...core.TaskOption) (core.Task, core.TaskErrors) { + opts ...TaskOption) (Task, TaskErrors) { // Create a container for task errors te := &taskErrors{ errs: make([]serror.SnapError, 0), @@ -70,7 +69,7 @@ func koRoutine(sch schedule.Schedule, func okRoutine(sch schedule.Schedule, wfMap *wmap.WorkflowMap, startOnCreate bool, - opts ...core.TaskOption) (core.Task, core.TaskErrors) { + opts ...TaskOption) (Task, TaskErrors) { return nil, nil } diff --git a/mgmt/rest/client/task.go b/mgmt/rest/client/task.go index 02fbe1d9f..4e1d39849 100644 --- a/mgmt/rest/client/task.go +++ b/mgmt/rest/client/task.go @@ -28,8 +28,8 @@ import ( "strings" "time" + "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/mgmt/rest/rbody" - "github.com/intelsdi-x/snap/pkg/task" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -49,8 +49,8 @@ type Schedule struct { // Otherwise, it's in the Stopped state. CreateTask is accomplished through a POST HTTP JSON request. // A ScheduledTask is returned if it succeeds, otherwise an error is returned. func (c *Client) CreateTask(s *Schedule, wf *wmap.WorkflowMap, name string, deadline string, startTask bool) *CreateTaskResult { - t := task.TaskCreationRequest{ - Schedule: task.Schedule{ + t := core.TaskCreationRequest{ + Schedule: core.Schedule{ Type: s.Type, Interval: s.Interval, }, diff --git a/mgmt/rest/config.go b/mgmt/rest/config.go index 8ab3e327b..40c1062ec 100644 --- a/mgmt/rest/config.go +++ b/mgmt/rest/config.go @@ -26,7 +26,6 @@ import ( "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/cdata" "github.com/intelsdi-x/snap/mgmt/rest/rbody" - "github.com/intelsdi-x/snap/pkg/task" "github.com/julienschmidt/httprouter" ) @@ -88,7 +87,7 @@ func (s *Server) deletePluginConfigItem(w http.ResponseWriter, r *http.Request, } src := []string{} - errCode, err := task.MarshalBody(&src, r.Body) + errCode, err := core.MarshalBody(&src, r.Body) if errCode != 0 && err != nil { respond(400, rbody.FromError(err), w) return @@ -130,7 +129,7 @@ func (s *Server) setPluginConfigItem(w http.ResponseWriter, r *http.Request, p h } src := cdata.NewNode() - errCode, err := task.MarshalBody(src, r.Body) + errCode, err := core.MarshalBody(src, r.Body) if errCode != 0 && err != nil { respond(400, rbody.FromError(err), w) return diff --git a/mgmt/rest/rbody/task.go b/mgmt/rest/rbody/task.go index e3b40049c..5f13dd31f 100644 --- a/mgmt/rest/rbody/task.go +++ b/mgmt/rest/rbody/task.go @@ -26,7 +26,6 @@ import ( "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/pkg/schedule" - "github.com/intelsdi-x/snap/pkg/task" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -121,7 +120,7 @@ type ScheduledTask struct { Name string `json:"name"` Deadline string `json:"deadline"` Workflow *wmap.WorkflowMap `json:"workflow,omitempty"` - Schedule *task.Schedule `json:"schedule,omitempty"` + Schedule *core.Schedule `json:"schedule,omitempty"` CreationTimestamp int64 `json:"creation_timestamp,omitempty"` LastRunTimestamp int64 `json:"last_run_timestamp,omitempty"` HitCount int `json:"hit_count,omitempty"` @@ -217,7 +216,7 @@ func (s *ScheduledTaskEnabled) ResponseBodyType() string { func assertSchedule(s schedule.Schedule, t *AddScheduledTask) { switch v := s.(type) { case *schedule.SimpleSchedule: - t.Schedule = &task.Schedule{ + t.Schedule = &core.Schedule{ Type: "simple", Interval: v.Interval.String(), } @@ -225,7 +224,7 @@ func assertSchedule(s schedule.Schedule, t *AddScheduledTask) { case *schedule.WindowedSchedule: startTime := v.StartTime.Unix() stopTime := v.StopTime.Unix() - t.Schedule = &task.Schedule{ + t.Schedule = &core.Schedule{ Type: "windowed", Interval: v.Interval.String(), StartTimestamp: &startTime, @@ -233,7 +232,7 @@ func assertSchedule(s schedule.Schedule, t *AddScheduledTask) { } return case *schedule.CronSchedule: - t.Schedule = &task.Schedule{ + t.Schedule = &core.Schedule{ Type: "cron", Interval: v.Entry(), } diff --git a/mgmt/rest/rest_func_test.go b/mgmt/rest/rest_func_test.go index 6c4e6a38d..45804fd72 100644 --- a/mgmt/rest/rest_func_test.go +++ b/mgmt/rest/rest_func_test.go @@ -1,4 +1,4 @@ -// +build legacy +/// +build legacy /* http://www.apache.org/licenses/LICENSE-2.0.txt @@ -46,7 +46,6 @@ import ( "github.com/intelsdi-x/snap/core/ctypes" "github.com/intelsdi-x/snap/mgmt/rest/rbody" "github.com/intelsdi-x/snap/pkg/cfgfile" - "github.com/intelsdi-x/snap/pkg/task" "github.com/intelsdi-x/snap/scheduler" "github.com/intelsdi-x/snap/scheduler/wmap" . "github.com/smartystreets/goconvey/convey" @@ -252,8 +251,8 @@ func createTask(sample, name, interval string, noStart bool, port int) *rbody.AP uri := fmt.Sprintf("http://localhost:%d/v1/tasks", port) - t := task.TaskCreationRequest{ - Schedule: task.Schedule{Type: "simple", Interval: interval}, + t := core.TaskCreationRequest{ + Schedule: core.Schedule{Type: "simple", Interval: interval}, Workflow: wf, Name: name, Start: !noStart, diff --git a/mgmt/rest/task.go b/mgmt/rest/task.go index 1372a6abc..221c96af5 100644 --- a/mgmt/rest/task.go +++ b/mgmt/rest/task.go @@ -32,7 +32,6 @@ import ( "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/mgmt/rest/rbody" - mtask "github.com/intelsdi-x/snap/pkg/task" ) var ( @@ -45,7 +44,7 @@ var ( ) func (s *Server) addTask(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { - task, err := mtask.CreateTaskFromContent(r.Body, nil, s.mt.CreateTask) + task, err := core.CreateTaskFromContent(r.Body, nil, s.mt.CreateTask) if err != nil { respond(500, rbody.FromError(err), w) return diff --git a/mgmt/tribe/worker/worker.go b/mgmt/tribe/worker/worker.go index a33b0df43..6419af5e8 100644 --- a/mgmt/tribe/worker/worker.go +++ b/mgmt/tribe/worker/worker.go @@ -36,7 +36,6 @@ import ( "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/mgmt/rest/client" "github.com/intelsdi-x/snap/pkg/schedule" - "github.com/intelsdi-x/snap/pkg/task" "github.com/intelsdi-x/snap/scheduler" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -514,7 +513,7 @@ func (w worker) isPluginLoaded(n, t string, v int) bool { return false } -func getSchedule(s *task.Schedule) schedule.Schedule { +func getSchedule(s *core.Schedule) schedule.Schedule { switch s.Type { case "simple": d, e := time.ParseDuration(s.Interval) diff --git a/pkg/task/task.go b/pkg/task/task.go deleted file mode 100644 index be8c74ab2..000000000 --- a/pkg/task/task.go +++ /dev/null @@ -1,197 +0,0 @@ -/* -http://www.apache.org/licenses/LICENSE-2.0.txt - - -Copyright 2015 Intel Corporation - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package task - -import ( - "encoding/json" - "errors" - "io" - "io/ioutil" - "time" - - "github.com/intelsdi-x/snap/core" - "github.com/intelsdi-x/snap/pkg/schedule" - "github.com/intelsdi-x/snap/scheduler/wmap" -) - -type TaskCreationRequest struct { - Name string `json:"name"` - Deadline string `json:"deadline"` - Workflow *wmap.WorkflowMap `json:"workflow"` - Schedule Schedule `json:"schedule"` - Start bool `json:"start"` -} - -type Schedule struct { - Type string `json:"type,omitempty"` - Interval string `json:"interval,omitempty"` - StartTimestamp *int64 `json:"start_timestamp,omitempty"` - StopTimestamp *int64 `json:"stop_timestamp,omitempty"` -} - -type configItem struct { - Key string `json:"key"` - Value interface{} `json:"value"` -} - -type task struct { - ID uint64 `json:"id"` - Config map[string][]configItem `json:"config"` - Name string `json:"name"` - Deadline string `json:"deadline"` - Workflow wmap.WorkflowMap `json:"workflow"` - Schedule schedule.Schedule `json:"schedule"` - CreationTime time.Time `json:"creation_timestamp,omitempty"` - LastRunTime time.Time `json:"last_run_timestamp,omitempty"` - HitCount uint `json:"hit_count,omitempty"` - MissCount uint `json:"miss_count,omitempty"` - FailedCount uint `json:"failed_count,omitempty"` - LastFailureMessage string `json:"last_failure_message,omitempty"` - State string `json:"task_state"` -} - -// Function used to create a task according to content (1st parameter) -// . Content can be retrieved from a configuration file or a HTTP REST request body -// . Mode is used to specify if the created task should start right away or not -// . function pointer is responsible for effectively creating and returning the created task -func CreateTaskFromContent(body io.ReadCloser, - mode *bool, - fp func(sch schedule.Schedule, - wfMap *wmap.WorkflowMap, - startOnCreate bool, - opts ...core.TaskOption) (core.Task, core.TaskErrors)) (core.Task, error) { - - tr, err := marshalTask(body) - if err != nil { - return nil, err - } - - sch, err := makeSchedule(tr.Schedule) - if err != nil { - return nil, err - } - - var opts []core.TaskOption - if tr.Deadline != "" { - dl, err := time.ParseDuration(tr.Deadline) - if err != nil { - return nil, err - } - opts = append(opts, core.TaskDeadlineDuration(dl)) - } - - if tr.Name != "" { - opts = append(opts, core.SetTaskName(tr.Name)) - } - opts = append(opts, core.OptionStopOnFailure(10)) - - if mode == nil { - mode = &tr.Start - } - if fp == nil { - return nil, errors.New("Missing workflow creation routine") - } - task, errs := fp(sch, tr.Workflow, *mode, opts...) - if errs != nil && len(errs.Errors()) != 0 { - var errMsg string - for _, e := range errs.Errors() { - errMsg = errMsg + e.Error() + " -- " - } - return nil, errors.New(errMsg[:len(errMsg)-4]) - } - return task, nil -} - -func marshalTask(body io.ReadCloser) (*TaskCreationRequest, error) { - var tr TaskCreationRequest - errCode, err := MarshalBody(&tr, body) - if errCode != 0 && err != nil { - return nil, err - } - return &tr, nil -} - -func makeSchedule(s Schedule) (schedule.Schedule, error) { - switch s.Type { - case "simple": - d, err := time.ParseDuration(s.Interval) - if err != nil { - return nil, err - } - sch := schedule.NewSimpleSchedule(d) - - err = sch.Validate() - if err != nil { - return nil, err - } - return sch, nil - case "windowed": - d, err := time.ParseDuration(s.Interval) - if err != nil { - return nil, err - } - - var start, stop *time.Time - if s.StartTimestamp != nil { - t := time.Unix(*s.StartTimestamp, 0) - start = &t - } - if s.StopTimestamp != nil { - t := time.Unix(*s.StopTimestamp, 0) - stop = &t - } - sch := schedule.NewWindowedSchedule( - d, - start, - stop, - ) - - err = sch.Validate() - if err != nil { - return nil, err - } - return sch, nil - case "cron": - if s.Interval == "" { - return nil, errors.New("missing cron entry") - } - sch := schedule.NewCronSchedule(s.Interval) - - err := sch.Validate() - if err != nil { - return nil, err - } - return sch, nil - default: - return nil, errors.New("unknown schedule type " + s.Type) - } -} - -func MarshalBody(in interface{}, body io.ReadCloser) (int, error) { - b, err := ioutil.ReadAll(body) - if err != nil { - return 500, err - } - err = json.Unmarshal(b, in) - if err != nil { - return 400, err - } - return 0, nil -} diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index f23ecc703..fea992ce6 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -40,7 +40,6 @@ import ( "github.com/intelsdi-x/snap/core/scheduler_event" "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/pkg/schedule" - mtask "github.com/intelsdi-x/snap/pkg/task" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -198,7 +197,7 @@ func autoDiscoverTasks(taskFiles []os.FileInfo, fullPath string, defer f.Close() } mode := true - task, err := mtask.CreateTaskFromContent(f, &mode, fp) + task, err := core.CreateTaskFromContent(f, &mode, fp) if err != nil { log.WithFields(log.Fields{ "_block": "autoDiscoverTasks", diff --git a/scheduler/scheduler_test.go b/scheduler/scheduler_test.go index ae36a89d0..c06b46e9e 100644 --- a/scheduler/scheduler_test.go +++ b/scheduler/scheduler_test.go @@ -1,4 +1,4 @@ -// +build legacy +/// +build legacy /* http://www.apache.org/licenses/LICENSE-2.0.txt