db interactions

This commit is contained in:
rushtehrani
2019-12-11 20:34:17 -08:00
parent 0b10fc9dd9
commit d765069256
15 changed files with 388 additions and 81 deletions

View File

@@ -8,6 +8,7 @@ go get -u github.com/pressly/goose/cmd/goose
Note: Up migration are automatically executed when the application is run. Note: Up migration are automatically executed when the application is run.
```bash ```bash
goose -dir db create <name> sql # Create migration in db folder
goose -dir db postgres "${DB_DATASOURCE}" up # Migrate the DB to the most recent version available goose -dir db postgres "${DB_DATASOURCE}" up # Migrate the DB to the most recent version available
goose -dir db postgres "${DB_DATASOURCE}" down # Roll back the version by 1 goose -dir db postgres "${DB_DATASOURCE}" down # Roll back the version by 1
goose help # See all available commands goose help # See all available commands

View File

@@ -191,27 +191,30 @@ func init() {
func init() { proto.RegisterFile("workflow.proto", fileDescriptor_892c7f566756b0be) } func init() { proto.RegisterFile("workflow.proto", fileDescriptor_892c7f566756b0be) }
var fileDescriptor_892c7f566756b0be = []byte{ var fileDescriptor_892c7f566756b0be = []byte{
// 318 bytes of a gzipped FileDescriptorProto // 356 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x4e, 0xc2, 0x40, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x41, 0x4f, 0xf2, 0x30,
0x10, 0x86, 0x53, 0x8a, 0x84, 0x0e, 0x11, 0xc9, 0x46, 0x62, 0xd3, 0x70, 0x20, 0xf5, 0x82, 0x97, 0x18, 0xc7, 0x33, 0xc6, 0xfb, 0x86, 0x3d, 0x44, 0x24, 0x8d, 0xe8, 0xb2, 0x70, 0x20, 0xf5, 0x82,
0x36, 0x60, 0xb8, 0x78, 0x33, 0xbe, 0x80, 0xa9, 0x26, 0x1e, 0x75, 0xc0, 0x91, 0x54, 0x4b, 0x77, 0x89, 0xd9, 0x02, 0x86, 0x0b, 0x27, 0x8d, 0x89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f4, 0x4a, 0xcb, 0x9c, 0xd3, 0xd3, 0xbf, 0x65, 0xec, 0xbb, 0x92, 0xc3, 0xad,
0x70, 0x47, 0xff, 0xf5, 0x5b, 0x3b, 0xfb, 0x09, 0x00, 0x00, 0xff, 0xff, 0x76, 0xfd, 0x6f, 0x76,
0xb9, 0x02, 0x00, 0x00,
} }
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
@@ -227,7 +230,8 @@ const _ = grpc.SupportPackageIsVersion4
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type WorkflowServiceClient interface { type WorkflowServiceClient interface {
// Creates a Workflow // Creates a Workflow
Create(ctx context.Context, in *CreateWorkflowRequest, opts ...grpc.CallOption) (*Workflow, error) CreateWorkflow(ctx context.Context, in *CreateWorkflowRequest, opts ...grpc.CallOption) (*Workflow, error)
CreateWorkflowTemplate(ctx context.Context, in *CreateWorkflowTemplateRequest, opts ...grpc.CallOption) (*WorkflowTemplate, error)
} }
type workflowServiceClient struct { type workflowServiceClient struct {
@@ -238,9 +242,18 @@ func NewWorkflowServiceClient(cc *grpc.ClientConn) WorkflowServiceClient {
return &workflowServiceClient{cc} return &workflowServiceClient{cc}
} }
func (c *workflowServiceClient) Create(ctx context.Context, in *CreateWorkflowRequest, opts ...grpc.CallOption) (*Workflow, error) { func (c *workflowServiceClient) CreateWorkflow(ctx context.Context, in *CreateWorkflowRequest, opts ...grpc.CallOption) (*Workflow, error) {
out := new(Workflow) out := new(Workflow)
err := c.cc.Invoke(ctx, "/api.WorkflowService/Create", in, out, opts...) err := c.cc.Invoke(ctx, "/api.WorkflowService/CreateWorkflow", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *workflowServiceClient) CreateWorkflowTemplate(ctx context.Context, in *CreateWorkflowTemplateRequest, opts ...grpc.CallOption) (*WorkflowTemplate, error) {
out := new(WorkflowTemplate)
err := c.cc.Invoke(ctx, "/api.WorkflowService/CreateWorkflowTemplate", in, out, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -250,35 +263,57 @@ func (c *workflowServiceClient) Create(ctx context.Context, in *CreateWorkflowRe
// WorkflowServiceServer is the server API for WorkflowService service. // WorkflowServiceServer is the server API for WorkflowService service.
type WorkflowServiceServer interface { type WorkflowServiceServer interface {
// Creates a Workflow // Creates a Workflow
Create(context.Context, *CreateWorkflowRequest) (*Workflow, error) CreateWorkflow(context.Context, *CreateWorkflowRequest) (*Workflow, error)
CreateWorkflowTemplate(context.Context, *CreateWorkflowTemplateRequest) (*WorkflowTemplate, error)
} }
// UnimplementedWorkflowServiceServer can be embedded to have forward compatible implementations. // UnimplementedWorkflowServiceServer can be embedded to have forward compatible implementations.
type UnimplementedWorkflowServiceServer struct { type UnimplementedWorkflowServiceServer struct {
} }
func (*UnimplementedWorkflowServiceServer) Create(ctx context.Context, req *CreateWorkflowRequest) (*Workflow, error) { func (*UnimplementedWorkflowServiceServer) CreateWorkflow(ctx context.Context, req *CreateWorkflowRequest) (*Workflow, error) {
return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") return nil, status.Errorf(codes.Unimplemented, "method CreateWorkflow not implemented")
}
func (*UnimplementedWorkflowServiceServer) CreateWorkflowTemplate(ctx context.Context, req *CreateWorkflowTemplateRequest) (*WorkflowTemplate, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreateWorkflowTemplate not implemented")
} }
func RegisterWorkflowServiceServer(s *grpc.Server, srv WorkflowServiceServer) { func RegisterWorkflowServiceServer(s *grpc.Server, srv WorkflowServiceServer) {
s.RegisterService(&_WorkflowService_serviceDesc, srv) s.RegisterService(&_WorkflowService_serviceDesc, srv)
} }
func _WorkflowService_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _WorkflowService_CreateWorkflow_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CreateWorkflowRequest) in := new(CreateWorkflowRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
if interceptor == nil { if interceptor == nil {
return srv.(WorkflowServiceServer).Create(ctx, in) return srv.(WorkflowServiceServer).CreateWorkflow(ctx, in)
} }
info := &grpc.UnaryServerInfo{ info := &grpc.UnaryServerInfo{
Server: srv, Server: srv,
FullMethod: "/api.WorkflowService/Create", FullMethod: "/api.WorkflowService/CreateWorkflow",
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WorkflowServiceServer).Create(ctx, req.(*CreateWorkflowRequest)) return srv.(WorkflowServiceServer).CreateWorkflow(ctx, req.(*CreateWorkflowRequest))
}
return interceptor(ctx, in, info, handler)
}
func _WorkflowService_CreateWorkflowTemplate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CreateWorkflowTemplateRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(WorkflowServiceServer).CreateWorkflowTemplate(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/api.WorkflowService/CreateWorkflowTemplate",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WorkflowServiceServer).CreateWorkflowTemplate(ctx, req.(*CreateWorkflowTemplateRequest))
} }
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
@@ -288,8 +323,12 @@ var _WorkflowService_serviceDesc = grpc.ServiceDesc{
HandlerType: (*WorkflowServiceServer)(nil), HandlerType: (*WorkflowServiceServer)(nil),
Methods: []grpc.MethodDesc{ Methods: []grpc.MethodDesc{
{ {
MethodName: "Create", MethodName: "CreateWorkflow",
Handler: _WorkflowService_Create_Handler, Handler: _WorkflowService_CreateWorkflow_Handler,
},
{
MethodName: "CreateWorkflowTemplate",
Handler: _WorkflowService_CreateWorkflowTemplate_Handler,
}, },
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},

View File

@@ -31,7 +31,7 @@ var _ = runtime.String
var _ = utilities.NewDoubleArray var _ = utilities.NewDoubleArray
var _ = descriptor.ForMessage var _ = descriptor.ForMessage
func request_WorkflowService_Create_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { func request_WorkflowService_CreateWorkflow_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq CreateWorkflowRequest var protoReq CreateWorkflowRequest
var metadata runtime.ServerMetadata var metadata runtime.ServerMetadata
@@ -61,12 +61,12 @@ func request_WorkflowService_Create_0(ctx context.Context, marshaler runtime.Mar
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "namespace", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "namespace", err)
} }
msg, err := client.Create(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) msg, err := client.CreateWorkflow(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err return msg, metadata, err
} }
func local_request_WorkflowService_Create_0(ctx context.Context, marshaler runtime.Marshaler, server WorkflowServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { func local_request_WorkflowService_CreateWorkflow_0(ctx context.Context, marshaler runtime.Marshaler, server WorkflowServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq CreateWorkflowRequest var protoReq CreateWorkflowRequest
var metadata runtime.ServerMetadata var metadata runtime.ServerMetadata
@@ -96,7 +96,77 @@ func local_request_WorkflowService_Create_0(ctx context.Context, marshaler runti
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "namespace", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "namespace", err)
} }
msg, err := server.Create(ctx, &protoReq) msg, err := server.CreateWorkflow(ctx, &protoReq)
return msg, metadata, err
}
func request_WorkflowService_CreateWorkflowTemplate_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq CreateWorkflowTemplateRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.WorkflowTemplate); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["namespace"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "namespace")
}
protoReq.Namespace, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "namespace", err)
}
msg, err := client.CreateWorkflowTemplate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_WorkflowService_CreateWorkflowTemplate_0(ctx context.Context, marshaler runtime.Marshaler, server WorkflowServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq CreateWorkflowTemplateRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.WorkflowTemplate); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["namespace"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "namespace")
}
protoReq.Namespace, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "namespace", err)
}
msg, err := server.CreateWorkflowTemplate(ctx, &protoReq)
return msg, metadata, err return msg, metadata, err
} }
@@ -106,7 +176,7 @@ func local_request_WorkflowService_Create_0(ctx context.Context, marshaler runti
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
func RegisterWorkflowServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server WorkflowServiceServer) error { func RegisterWorkflowServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server WorkflowServiceServer) error {
mux.Handle("POST", pattern_WorkflowService_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { mux.Handle("POST", pattern_WorkflowService_CreateWorkflow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context()) ctx, cancel := context.WithCancel(req.Context())
defer cancel() defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
@@ -115,14 +185,34 @@ func RegisterWorkflowServiceHandlerServer(ctx context.Context, mux *runtime.Serv
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
} }
resp, md, err := local_request_WorkflowService_Create_0(rctx, inboundMarshaler, server, req, pathParams) resp, md, err := local_request_WorkflowService_CreateWorkflow_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md) ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil { if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
} }
forward_WorkflowService_Create_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) forward_WorkflowService_CreateWorkflow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_WorkflowService_CreateWorkflowTemplate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_WorkflowService_CreateWorkflowTemplate_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_WorkflowService_CreateWorkflowTemplate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
}) })
@@ -167,7 +257,7 @@ func RegisterWorkflowServiceHandler(ctx context.Context, mux *runtime.ServeMux,
// "WorkflowServiceClient" to call the correct interceptors. // "WorkflowServiceClient" to call the correct interceptors.
func RegisterWorkflowServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client WorkflowServiceClient) error { func RegisterWorkflowServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client WorkflowServiceClient) error {
mux.Handle("POST", pattern_WorkflowService_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { mux.Handle("POST", pattern_WorkflowService_CreateWorkflow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context()) ctx, cancel := context.WithCancel(req.Context())
defer cancel() defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
@@ -176,14 +266,34 @@ func RegisterWorkflowServiceHandlerClient(ctx context.Context, mux *runtime.Serv
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
} }
resp, md, err := request_WorkflowService_Create_0(rctx, inboundMarshaler, client, req, pathParams) resp, md, err := request_WorkflowService_CreateWorkflow_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md) ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil { if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
} }
forward_WorkflowService_Create_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) forward_WorkflowService_CreateWorkflow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_WorkflowService_CreateWorkflowTemplate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_WorkflowService_CreateWorkflowTemplate_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_WorkflowService_CreateWorkflowTemplate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
}) })
@@ -191,9 +301,13 @@ func RegisterWorkflowServiceHandlerClient(ctx context.Context, mux *runtime.Serv
} }
var ( var (
pattern_WorkflowService_Create_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"apis", "v1beta1", "namespace", "workflows"}, "", runtime.AssumeColonVerbOpt(true))) pattern_WorkflowService_CreateWorkflow_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"apis", "v1beta1", "namespace", "workflows"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_WorkflowService_CreateWorkflowTemplate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"apis", "v1beta1", "namespace", "workflow_templates"}, "", runtime.AssumeColonVerbOpt(true)))
) )
var ( var (
forward_WorkflowService_Create_0 = runtime.ForwardResponseMessage forward_WorkflowService_CreateWorkflow_0 = runtime.ForwardResponseMessage
forward_WorkflowService_CreateWorkflowTemplate_0 = runtime.ForwardResponseMessage
) )

View File

@@ -7,12 +7,19 @@ import "workflow_template.proto";
service WorkflowService { service WorkflowService {
// Creates a Workflow // Creates a Workflow
rpc Create (CreateWorkflowRequest) returns (Workflow) { rpc CreateWorkflow (CreateWorkflowRequest) returns (Workflow) {
option (google.api.http) = { option (google.api.http) = {
post: "/apis/v1beta1/{namespace}/workflows" post: "/apis/v1beta1/{namespace}/workflows"
body: "workflow" body: "workflow"
}; };
} }
rpc CreateWorkflowTemplate (CreateWorkflowTemplateRequest) returns (WorkflowTemplate) {
option (google.api.http) = {
post: "/apis/v1beta1/{namespace}/workflow_templates"
body: "workflowTemplate"
};
}
} }
message CreateWorkflowRequest { message CreateWorkflowRequest {

View File

@@ -11,10 +11,42 @@
"application/json" "application/json"
], ],
"paths": { "paths": {
"/apis/v1beta1/{namespace}/workflow_templates": {
"post": {
"operationId": "CreateWorkflowTemplate",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/apiWorkflowTemplate"
}
}
},
"parameters": [
{
"name": "namespace",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/apiWorkflowTemplate"
}
}
],
"tags": [
"WorkflowService"
]
}
},
"/apis/v1beta1/{namespace}/workflows": { "/apis/v1beta1/{namespace}/workflows": {
"post": { "post": {
"summary": "Creates a Workflow", "summary": "Creates a Workflow",
"operationId": "Create", "operationId": "CreateWorkflow",
"responses": { "responses": {
"200": { "200": {
"description": "A successful response.", "description": "A successful response.",
@@ -86,6 +118,9 @@
"name": { "name": {
"type": "string" "type": "string"
}, },
"version": {
"type": "string"
},
"manifest": { "manifest": {
"type": "string" "type": "string"
} }

View File

@@ -20,9 +20,57 @@ var _ = math.Inf
// proto package needs to be updated. // proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type CreateWorkflowTemplateRequest struct {
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
WorkflowTemplate *WorkflowTemplate `protobuf:"bytes,2,opt,name=workflowTemplate,proto3" json:"workflowTemplate,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *CreateWorkflowTemplateRequest) Reset() { *m = CreateWorkflowTemplateRequest{} }
func (m *CreateWorkflowTemplateRequest) String() string { return proto.CompactTextString(m) }
func (*CreateWorkflowTemplateRequest) ProtoMessage() {}
func (*CreateWorkflowTemplateRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_b9a07547748a96e8, []int{0}
}
func (m *CreateWorkflowTemplateRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_CreateWorkflowTemplateRequest.Unmarshal(m, b)
}
func (m *CreateWorkflowTemplateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_CreateWorkflowTemplateRequest.Marshal(b, m, deterministic)
}
func (m *CreateWorkflowTemplateRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_CreateWorkflowTemplateRequest.Merge(m, src)
}
func (m *CreateWorkflowTemplateRequest) XXX_Size() int {
return xxx_messageInfo_CreateWorkflowTemplateRequest.Size(m)
}
func (m *CreateWorkflowTemplateRequest) XXX_DiscardUnknown() {
xxx_messageInfo_CreateWorkflowTemplateRequest.DiscardUnknown(m)
}
var xxx_messageInfo_CreateWorkflowTemplateRequest proto.InternalMessageInfo
func (m *CreateWorkflowTemplateRequest) GetNamespace() string {
if m != nil {
return m.Namespace
}
return ""
}
func (m *CreateWorkflowTemplateRequest) GetWorkflowTemplate() *WorkflowTemplate {
if m != nil {
return m.WorkflowTemplate
}
return nil
}
type WorkflowTemplate struct { type WorkflowTemplate struct {
Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"` Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"`
Manifest string `protobuf:"bytes,4,opt,name=manifest,proto3" json:"manifest,omitempty"` Manifest string `protobuf:"bytes,4,opt,name=manifest,proto3" json:"manifest,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
@@ -33,7 +81,7 @@ func (m *WorkflowTemplate) Reset() { *m = WorkflowTemplate{} }
func (m *WorkflowTemplate) String() string { return proto.CompactTextString(m) } func (m *WorkflowTemplate) String() string { return proto.CompactTextString(m) }
func (*WorkflowTemplate) ProtoMessage() {} func (*WorkflowTemplate) ProtoMessage() {}
func (*WorkflowTemplate) Descriptor() ([]byte, []int) { func (*WorkflowTemplate) Descriptor() ([]byte, []int) {
return fileDescriptor_b9a07547748a96e8, []int{0} return fileDescriptor_b9a07547748a96e8, []int{1}
} }
func (m *WorkflowTemplate) XXX_Unmarshal(b []byte) error { func (m *WorkflowTemplate) XXX_Unmarshal(b []byte) error {
@@ -68,6 +116,13 @@ func (m *WorkflowTemplate) GetName() string {
return "" return ""
} }
func (m *WorkflowTemplate) GetVersion() string {
if m != nil {
return m.Version
}
return ""
}
func (m *WorkflowTemplate) GetManifest() string { func (m *WorkflowTemplate) GetManifest() string {
if m != nil { if m != nil {
return m.Manifest return m.Manifest
@@ -76,19 +131,25 @@ func (m *WorkflowTemplate) GetManifest() string {
} }
func init() { func init() {
proto.RegisterType((*CreateWorkflowTemplateRequest)(nil), "api.CreateWorkflowTemplateRequest")
proto.RegisterType((*WorkflowTemplate)(nil), "api.WorkflowTemplate") proto.RegisterType((*WorkflowTemplate)(nil), "api.WorkflowTemplate")
} }
func init() { proto.RegisterFile("workflow_template.proto", fileDescriptor_b9a07547748a96e8) } func init() { proto.RegisterFile("workflow_template.proto", fileDescriptor_b9a07547748a96e8) }
var fileDescriptor_b9a07547748a96e8 = []byte{ var fileDescriptor_b9a07547748a96e8 = []byte{
// 116 bytes of a gzipped FileDescriptorProto // 193 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2f, 0xcf, 0x2f, 0xca, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2f, 0xcf, 0x2f, 0xca,
0x4e, 0xcb, 0xc9, 0x2f, 0x8f, 0x2f, 0x49, 0xcd, 0x2d, 0xc8, 0x49, 0x2c, 0x49, 0xd5, 0x2b, 0x28, 0x4e, 0xcb, 0xc9, 0x2f, 0x8f, 0x2f, 0x49, 0xcd, 0x2d, 0xc8, 0x49, 0x2c, 0x49, 0xd5, 0x2b, 0x28,
0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x0a, 0xe1, 0x12, 0x08, 0x87, 0xca, 0x87, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x6a, 0x60, 0xe4, 0x92, 0x75, 0x2e, 0x4a,
0x40, 0xa5, 0x85, 0x04, 0xb8, 0x98, 0x4b, 0x33, 0x53, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x4d, 0x2c, 0x49, 0x0d, 0x87, 0x2a, 0x0b, 0x81, 0xaa, 0x0a, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e,
0x40, 0x4c, 0x21, 0x21, 0x2e, 0x96, 0xbc, 0xc4, 0xdc, 0x54, 0x09, 0x26, 0xb0, 0x10, 0x98, 0x2d, 0x11, 0x92, 0xe1, 0xe2, 0xcc, 0x4b, 0xcc, 0x4d, 0x2d, 0x2e, 0x48, 0x4c, 0x4e, 0x95, 0x60, 0x54,
0x24, 0xc5, 0xc5, 0x91, 0x9b, 0x98, 0x97, 0x99, 0x96, 0x5a, 0x5c, 0x22, 0xc1, 0x02, 0x16, 0x87, 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x08, 0x08, 0x39, 0x72, 0x09, 0x94, 0xa3, 0x69, 0x94, 0x60, 0x52,
0xf3, 0x93, 0xd8, 0xc0, 0x36, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xa0, 0x43, 0x79, 0x28, 0x60, 0xd4, 0xe0, 0x36, 0x12, 0xd5, 0x4b, 0x2c, 0xc8, 0xd4, 0xc3, 0x30, 0x15, 0x43, 0xb9, 0x52,
0x7c, 0x00, 0x00, 0x00, 0x1e, 0x97, 0x00, 0xba, 0x2a, 0x21, 0x01, 0x2e, 0xe6, 0xd2, 0xcc, 0x14, 0xa8, 0x75, 0x20, 0xa6,
0x90, 0x10, 0x17, 0x0b, 0xc8, 0x56, 0xb0, 0xe1, 0x9c, 0x41, 0x60, 0xb6, 0x90, 0x04, 0x17, 0x7b,
0x59, 0x6a, 0x51, 0x71, 0x66, 0x7e, 0x9e, 0x04, 0x33, 0x58, 0x18, 0xc6, 0x15, 0x92, 0xe2, 0xe2,
0xc8, 0x4d, 0xcc, 0xcb, 0x4c, 0x4b, 0x2d, 0x2e, 0x91, 0x60, 0x01, 0x4b, 0xc1, 0xf9, 0x49, 0x6c,
0x60, 0xef, 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x01, 0xe2, 0x84, 0xe2, 0x19, 0x01, 0x00,
0x00,
} }

View File

@@ -2,9 +2,14 @@ syntax = "proto3";
package api; package api;
message CreateWorkflowTemplateRequest {
string namespace = 1;
WorkflowTemplate workflowTemplate = 2;
}
message WorkflowTemplate { message WorkflowTemplate {
string uid = 1; string uid = 1;
string name = 2; string name = 2;
string version = 3;
string manifest = 4; string manifest = 4;
} }

View File

@@ -4,7 +4,6 @@ CREATE TABLE workflow_templates
id serial PRIMARY KEY, id serial PRIMARY KEY,
uid varchar(36) UNIQUE NOT NULL CHECK(uid <> ''), uid varchar(36) UNIQUE NOT NULL CHECK(uid <> ''),
name text UNIQUE NOT NULL CHECK(name <> ''), name text UNIQUE NOT NULL CHECK(name <> ''),
manifest text,
-- auditing info -- auditing info
created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'), created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'),

View File

@@ -0,0 +1,15 @@
-- +goose Up
CREATE TABLE workflow_template_versions
(
id serial PRIMARY KEY,
workflow_template_id integer NOT NULL REFERENCES workflow_templates ON DELETE CASCADE,
version timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'),
manifest jsonb NOT NULL,
-- auditing info
created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'),
modified_at timestamp
);
-- +goose Down
DROP TABLE workflow_template_versions;

View File

@@ -6,10 +6,6 @@ import (
) )
func (r *ResourceManager) CreateWorkflow(namespace string, workflow *model.Workflow) (createdWorkflow *model.Workflow, err error) { func (r *ResourceManager) CreateWorkflow(namespace string, workflow *model.Workflow) (createdWorkflow *model.Workflow, err error) {
if err != nil {
return
}
opts := &argo.Options{ opts := &argo.Options{
Namespace: namespace, Namespace: namespace,
} }
@@ -30,3 +26,7 @@ func (r *ResourceManager) CreateWorkflow(namespace string, workflow *model.Workf
return return
} }
func (r *ResourceManager) CreateWorkflowTemplate(namespace string, workflowTemplate *model.WorkflowTemplate) (createdWorkflowTemplate *model.WorkflowTemplate, err error) {
return r.workflowRepository.CreateWorkflowTemplate(workflowTemplate)
}

View File

@@ -1,5 +1,7 @@
package model package model
import "github.com/google/uuid"
type WorkflowTemplate struct { type WorkflowTemplate struct {
ID uint64 ID uint64
UID string UID string
@@ -10,3 +12,13 @@ type WorkflowTemplate struct {
func (wt *WorkflowTemplate) GetManifest() []byte { func (wt *WorkflowTemplate) GetManifest() []byte {
return []byte(wt.Manifest) return []byte(wt.Manifest)
} }
func (wt *WorkflowTemplate) GenerateUID() (string, error) {
uid, err := uuid.NewRandom()
if err != nil {
return "", err
}
wt.UID = uid.String()
return wt.UID, nil
}

View File

@@ -21,8 +21,8 @@ func (db *DB) BaseConnection() *sql.DB {
return db.DB.DB return db.DB.DB
} }
func (db *DB) NamedQueryWithStructScan(query string, dest interface{}) (err error) { func (db *DB) QueryStructScan(query string, args []interface{}, dest interface{}) (err error) {
rows, err := db.NamedQuery(query, dest) rows, err := db.Queryx(query, args)
if err != nil { if err != nil {
return return
} }

View File

@@ -2,28 +2,35 @@ package repository
import ( import (
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/onepanelio/core/model" "github.com/onepanelio/core/model"
) )
type WorkflowRepository struct { type WorkflowRepository struct {
db *DB db *DB
sb sq.StatementBuilderType
} }
func NewWorkflowRepository(db *DB) *WorkflowRepository { func NewWorkflowRepository(db *DB) *WorkflowRepository {
return &WorkflowRepository{db: db} return &WorkflowRepository{db: db, sb: sq.StatementBuilder.PlaceholderFormat(sq.Dollar)}
} }
func (w *WorkflowRepository) Create(workflow *model.Workflow) (err error) { func (r *WorkflowRepository) CreateWorkflowTemplate(workflowTemplate *model.WorkflowTemplate) (*model.WorkflowTemplate, error) {
sql, _, err := sq.Insert("workflows"). uid, err := workflowTemplate.GenerateUID()
SetMap(sq.Eq{
"UID": workflow.UID,
}).ToSql()
if err != nil { if err != nil {
return return nil, err
} }
err = w.db.NamedQueryWithStructScan(sql, workflow) err = r.sb.Insert("workflow_templates").
SetMap(sq.Eq{
"uid": uid,
"name": workflowTemplate.Name,
}).
Suffix("RETURNING id, uid").
RunWith(r.db.BaseConnection()).
QueryRow().Scan(&workflowTemplate.ID, &workflowTemplate.UID)
if err != nil {
return nil, err
}
return return workflowTemplate, nil
} }

View File

@@ -8,24 +8,23 @@ import (
"github.com/onepanelio/core/model" "github.com/onepanelio/core/model"
) )
func TestWorkflowRepositoryCreate(t *testing.T) { func TestWorkflowRepositoryCreateWorkflowTemplate(t *testing.T) {
uid, err := uuid.NewRandom() uid, err := uuid.NewRandom()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return
} }
workflow := &model.Workflow{ workflowTemplate := &model.WorkflowTemplate{
UID: uid.String(), UID: uid.String(),
} }
sql, args, err := sq.Insert("workflows"). sql, args, err := sq.Insert("workflow_templates").
SetMap(sq.Eq{ SetMap(sq.Eq{
"UID": workflow.UID, "UID": workflowTemplate.UID,
}).ToSql() }).ToSql()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return
} }
t.Log(args) t.Log(sql, args)
t.Log(sql)
} }

View File

@@ -17,7 +17,7 @@ func NewWorkflowServer(resourceManager *manager.ResourceManager) *WorkflowServer
return &WorkflowServer{resourceManager: resourceManager} return &WorkflowServer{resourceManager: resourceManager}
} }
func (w *WorkflowServer) Create(ctx context.Context, req *api.CreateWorkflowRequest) (*api.Workflow, error) { func (s *WorkflowServer) CreateWorkflow(ctx context.Context, req *api.CreateWorkflowRequest) (*api.Workflow, error) {
workflow := &model.Workflow{ workflow := &model.Workflow{
WorkflowTemplate: model.WorkflowTemplate{ WorkflowTemplate: model.WorkflowTemplate{
Manifest: req.Workflow.WorkflowTemplate.Manifest, Manifest: req.Workflow.WorkflowTemplate.Manifest,
@@ -30,7 +30,7 @@ func (w *WorkflowServer) Create(ctx context.Context, req *api.CreateWorkflowRequ
}) })
} }
createdWorkflow, err := w.resourceManager.CreateWorkflow(req.Namespace, workflow) createdWorkflow, err := s.resourceManager.CreateWorkflow(req.Namespace, workflow)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -41,3 +41,16 @@ func (w *WorkflowServer) Create(ctx context.Context, req *api.CreateWorkflowRequ
return req.Workflow, nil return req.Workflow, nil
} }
func (s *WorkflowServer) CreateWorkflowTemplate(ctx context.Context, req *api.CreateWorkflowTemplateRequest) (*api.WorkflowTemplate, error) {
workflowTemplate := &model.WorkflowTemplate{
Name: req.WorkflowTemplate.Name,
}
workflowTemplate, err := s.resourceManager.CreateWorkflowTemplate(req.Namespace, workflowTemplate)
if err != nil {
return nil, err
}
req.WorkflowTemplate.Uid = workflowTemplate.UID
return req.WorkflowTemplate, nil
}