support version selection

This commit is contained in:
rushtehrani
2019-12-13 13:19:05 -08:00
parent 2179af0d76
commit a59b9504bd
9 changed files with 77 additions and 39 deletions

View File

@@ -171,6 +171,10 @@ func local_request_WorkflowService_CreateWorkflowTemplate_0(ctx context.Context,
} }
var (
filter_WorkflowService_GetWorkflowTemplate_0 = &utilities.DoubleArray{Encoding: map[string]int{"namespace": 0, "uid": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
)
func request_WorkflowService_GetWorkflowTemplate_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { func request_WorkflowService_GetWorkflowTemplate_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetWorkflowTemplateRequest var protoReq GetWorkflowTemplateRequest
var metadata runtime.ServerMetadata var metadata runtime.ServerMetadata
@@ -204,6 +208,13 @@ func request_WorkflowService_GetWorkflowTemplate_0(ctx context.Context, marshale
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "uid", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "uid", err)
} }
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WorkflowService_GetWorkflowTemplate_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.GetWorkflowTemplate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) msg, err := client.GetWorkflowTemplate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err return msg, metadata, err
@@ -242,6 +253,10 @@ func local_request_WorkflowService_GetWorkflowTemplate_0(ctx context.Context, ma
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "uid", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "uid", err)
} }
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_WorkflowService_GetWorkflowTemplate_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.GetWorkflowTemplate(ctx, &protoReq) msg, err := server.GetWorkflowTemplate(ctx, &protoReq)
return msg, metadata, err return msg, metadata, err

View File

@@ -66,6 +66,13 @@
"in": "path", "in": "path",
"required": true, "required": true,
"type": "string" "type": "string"
},
{
"name": "version",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
} }
], ],
"tags": [ "tags": [
@@ -194,7 +201,8 @@
"type": "string" "type": "string"
}, },
"version": { "version": {
"type": "string" "type": "integer",
"format": "int32"
}, },
"manifest": { "manifest": {
"type": "string" "type": "string"

View File

@@ -70,6 +70,7 @@ func (m *CreateWorkflowTemplateRequest) GetWorkflowTemplate() *WorkflowTemplate
type GetWorkflowTemplateRequest struct { type GetWorkflowTemplateRequest struct {
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"` Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"`
Version int32 `protobuf:"varint,3,opt,name=version,proto3" json:"version,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
@@ -114,6 +115,13 @@ func (m *GetWorkflowTemplateRequest) GetUid() string {
return "" return ""
} }
func (m *GetWorkflowTemplateRequest) GetVersion() int32 {
if m != nil {
return m.Version
}
return 0
}
type ListWorkflowTemplateVersionsRequest struct { type ListWorkflowTemplateVersionsRequest struct {
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"` Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"`
@@ -211,7 +219,7 @@ func (m *ListWorkflowTemplateVersionsResponse) GetCount() int32 {
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"` Version int32 `protobuf:"varint,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:"-"`
@@ -257,11 +265,11 @@ func (m *WorkflowTemplate) GetName() string {
return "" return ""
} }
func (m *WorkflowTemplate) GetVersion() string { func (m *WorkflowTemplate) GetVersion() int32 {
if m != nil { if m != nil {
return m.Version return m.Version
} }
return "" return 0
} }
func (m *WorkflowTemplate) GetManifest() string { func (m *WorkflowTemplate) GetManifest() string {
@@ -282,22 +290,22 @@ func init() {
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{
// 263 bytes of a gzipped FileDescriptorProto // 266 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x3f, 0x4f, 0xc3, 0x30, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x3d, 0x4f, 0xc3, 0x30,
0x10, 0xc5, 0x65, 0xd2, 0x02, 0x39, 0x96, 0x70, 0x02, 0x61, 0x55, 0x20, 0x45, 0x81, 0xa1, 0x53, 0x10, 0x95, 0x49, 0x03, 0xe4, 0x58, 0x82, 0x05, 0xc2, 0xaa, 0x40, 0x8a, 0x02, 0x43, 0xa6, 0x0c,
0x06, 0xf8, 0x04, 0xa8, 0x03, 0x4b, 0xa7, 0x88, 0x3f, 0x23, 0x32, 0xe5, 0x2a, 0x59, 0x34, 0xb6, 0xf0, 0x0b, 0x50, 0x07, 0x16, 0x26, 0x8b, 0x8f, 0x11, 0x99, 0x72, 0x91, 0x2c, 0x1a, 0xdb, 0xe4,
0xc9, 0x39, 0x64, 0x85, 0x6f, 0x8e, 0xea, 0xa6, 0x45, 0x4a, 0x44, 0x87, 0x6c, 0xf7, 0x2e, 0xef, 0x1c, 0xb2, 0xc2, 0x3f, 0x47, 0x75, 0x53, 0x2a, 0x25, 0x6a, 0x87, 0x6e, 0xf7, 0x92, 0xf7, 0xee,
0xde, 0xfd, 0x2e, 0x32, 0x5c, 0x34, 0xb6, 0xfa, 0x58, 0xae, 0x6c, 0xf3, 0xea, 0xa9, 0x74, 0x2b, 0xbd, 0x7b, 0x32, 0x5c, 0x74, 0xb6, 0xf9, 0xac, 0x16, 0xb6, 0x7b, 0xf3, 0x58, 0xbb, 0x85, 0xf2,
0xe5, 0x29, 0x77, 0x95, 0xf5, 0x16, 0x23, 0xe5, 0x74, 0xf6, 0x2d, 0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, 0x59, 0xc3, 0x84, 0x33, 0x38, 0xed, 0x5e, 0xc8, 0x52, 0xa4, 0xd1, 0xff, 0x7f, 0xa4, 0x46, 0x2f, 0xab, 0xdf, 0xb4, 0xa7, 0x61, 0xfe, 0xcb, 0xe0, 0x66, 0xf7, 0x5e, 0x72, 0xd6, 0x10,
0xef, 0xc7, 0x33, 0x18, 0x2f, 0x6c, 0x6d, 0x7c, 0x20, 0x18, 0x17, 0x1b, 0x91, 0x19, 0x48, 0xba, 0xf2, 0x19, 0x9c, 0x0e, 0x6f, 0x27, 0xc1, 0xb2, 0x68, 0x7b, 0x57, 0x63, 0x3e, 0x3f, 0x83, 0x78,
0xc3, 0x5b, 0x52, 0xb1, 0x23, 0x45, 0x84, 0xd1, 0xfa, 0x90, 0x16, 0x3e, 0xd4, 0x28, 0xe1, 0xe8, 0x6e, 0x5b, 0xe3, 0x43, 0x82, 0x58, 0xae, 0x40, 0x6e, 0x20, 0x1d, 0x8a, 0xd7, 0x49, 0xd9, 0xa6,
0x6b, 0x03, 0x2a, 0xa3, 0xd0, 0xde, 0x4a, 0x9c, 0xc0, 0x71, 0xa9, 0x8c, 0x5e, 0x12, 0x7b, 0x39, 0x1a, 0x0e, 0x93, 0xe5, 0x21, 0x7d, 0xf8, 0x30, 0x6f, 0xaf, 0x8b, 0x4f, 0xe1, 0xb8, 0x56, 0x46,
0x0a, 0x9f, 0x76, 0xfa, 0xed, 0x30, 0xbc, 0x93, 0xbb, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe8, 0x57, 0x48, 0x5e, 0x4c, 0x82, 0xe2, 0x1f, 0xbf, 0x1f, 0x86, 0x17, 0x74, 0xf7, 0x17, 0x00, 0x00,
0x92, 0xc7, 0xce, 0x42, 0x02, 0x00, 0x00, 0xff, 0xff, 0xf9, 0x1d, 0xa0, 0xf0, 0x5c, 0x02, 0x00, 0x00,
} }

View File

@@ -10,6 +10,7 @@ message CreateWorkflowTemplateRequest {
message GetWorkflowTemplateRequest { message GetWorkflowTemplateRequest {
string namespace = 1; string namespace = 1;
string uid = 2; string uid = 2;
int32 version = 3;
} }
message ListWorkflowTemplateVersionsRequest { message ListWorkflowTemplateVersionsRequest {
@@ -25,6 +26,6 @@ message ListWorkflowTemplateVersionsResponse {
message WorkflowTemplate { message WorkflowTemplate {
string uid = 1; string uid = 1;
string name = 2; string name = 2;
string version = 3; int32 version = 3;
string manifest = 4; string manifest = 4;
} }

View File

@@ -3,7 +3,7 @@ CREATE TABLE workflow_template_versions
( (
id serial PRIMARY KEY, id serial PRIMARY KEY,
workflow_template_id integer NOT NULL REFERENCES workflow_templates ON DELETE CASCADE, workflow_template_id integer NOT NULL REFERENCES workflow_templates ON DELETE CASCADE,
version timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'), version integer NOT NULL,
manifest text NOT NULL, manifest text NOT NULL,
-- auditing info -- auditing info

View File

@@ -8,7 +8,7 @@ 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) {
workflowTemplate, err := r.workflowRepository.GetWorkflowTemplate(workflow.WorkflowTemplate.UID) workflowTemplate, err := r.workflowRepository.GetWorkflowTemplate(workflow.WorkflowTemplate.UID, workflow.WorkflowTemplate.Version)
if err != nil { if err != nil {
return nil, util.NewUserError(codes.NotFound, "Workflow template not found.") return nil, util.NewUserError(codes.NotFound, "Workflow template not found.")
} }
@@ -43,8 +43,8 @@ func (r *ResourceManager) CreateWorkflowTemplate(namespace string, workflowTempl
return return
} }
func (r *ResourceManager) GetWorkflowTemplate(namespace, uid string) (workflowTemplate *model.WorkflowTemplate, err error) { func (r *ResourceManager) GetWorkflowTemplate(namespace, uid string, version int32) (workflowTemplate *model.WorkflowTemplate, err error) {
workflowTemplate, err = r.workflowRepository.GetWorkflowTemplate(uid) workflowTemplate, err = r.workflowRepository.GetWorkflowTemplate(uid, version)
if err != nil { if err != nil {
return nil, util.NewUserError(codes.NotFound, "Workflow template not found.") return nil, util.NewUserError(codes.NotFound, "Workflow template not found.")
} }

View File

@@ -1,8 +1,6 @@
package model package model
import ( import (
"time"
"github.com/google/uuid" "github.com/google/uuid"
) )
@@ -11,7 +9,7 @@ type WorkflowTemplate struct {
UID string UID string
Name string Name string
Manifest string Manifest string
Version *time.Time Version int32
} }
func (wt *WorkflowTemplate) GetManifestBytes() []byte { func (wt *WorkflowTemplate) GetManifestBytes() []byte {

View File

@@ -1,6 +1,8 @@
package repository package repository
import ( import (
"time"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/onepanelio/core/model" "github.com/onepanelio/core/model"
) )
@@ -42,6 +44,7 @@ func (r *WorkflowRepository) CreateWorkflowTemplate(workflowTemplate *model.Work
SetMap(sq.Eq{ SetMap(sq.Eq{
"workflow_template_id": workflowTemplate.ID, "workflow_template_id": workflowTemplate.ID,
"manifest": workflowTemplate.Manifest, "manifest": workflowTemplate.Manifest,
"version": int32(time.Now().Unix()),
}). }).
Suffix("RETURNING version"). Suffix("RETURNING version").
RunWith(tx). RunWith(tx).
@@ -57,20 +60,24 @@ func (r *WorkflowRepository) CreateWorkflowTemplate(workflowTemplate *model.Work
return workflowTemplate, nil return workflowTemplate, nil
} }
func (r *WorkflowRepository) GetWorkflowTemplate(uid string) (workflowTemplate *model.WorkflowTemplate, err error) { func (r *WorkflowRepository) GetWorkflowTemplate(uid string, version int32) (workflowTemplate *model.WorkflowTemplate, err error) {
workflowTemplate = &model.WorkflowTemplate{} workflowTemplate = &model.WorkflowTemplate{}
query, args, err := r.sb.Select("wt.uid", "wtv.version", "wtv.manifest"). query := r.sb.Select("wt.uid", "wtv.version", "wtv.manifest").
From("workflow_template_versions wtv"). From("workflow_template_versions wtv").
Join("workflow_templates wt ON wt.id = wtv.workflow_template_id"). Join("workflow_templates wt ON wt.id = wtv.workflow_template_id").
Where(sq.Eq{"wt.uid": uid}). Where(sq.Eq{"wt.uid": uid}).
OrderBy("wtv.version desc"). OrderBy("wtv.version desc").
Limit(1).ToSql() Limit(1)
if version != 0 {
query = query.Where(sq.Eq{"wtv.version": version})
}
sql, args, err := query.ToSql()
if err != nil { if err != nil {
return return
} }
err = r.db.Get(workflowTemplate, query, args...) err = r.db.Get(workflowTemplate, sql, args...)
return return
} }

View File

@@ -24,7 +24,8 @@ func NewWorkflowServer(resourceManager *manager.ResourceManager) *WorkflowServer
func (s *WorkflowServer) CreateWorkflow(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{
UID: req.Workflow.WorkflowTemplate.Uid, UID: req.Workflow.WorkflowTemplate.Uid,
Version: req.Workflow.WorkflowTemplate.Version,
}, },
} }
for _, param := range req.Workflow.Parameters { for _, param := range req.Workflow.Parameters {
@@ -56,20 +57,20 @@ func (s *WorkflowServer) CreateWorkflowTemplate(ctx context.Context, req *api.Cr
return nil, userError.GRPCError() return nil, userError.GRPCError()
} }
req.WorkflowTemplate.Uid = workflowTemplate.UID req.WorkflowTemplate.Uid = workflowTemplate.UID
req.WorkflowTemplate.Version = workflowTemplate.Version.String() req.WorkflowTemplate.Version = workflowTemplate.Version
return req.WorkflowTemplate, nil return req.WorkflowTemplate, nil
} }
func (s *WorkflowServer) GetWorkflowTemplate(ctx context.Context, req *api.GetWorkflowTemplateRequest) (*api.WorkflowTemplate, error) { func (s *WorkflowServer) GetWorkflowTemplate(ctx context.Context, req *api.GetWorkflowTemplateRequest) (*api.WorkflowTemplate, error) {
workflowTemplate, err := s.resourceManager.GetWorkflowTemplate(req.Namespace, req.Uid) workflowTemplate, err := s.resourceManager.GetWorkflowTemplate(req.Namespace, req.Uid, req.Version)
if errors.As(err, &userError) { if errors.As(err, &userError) {
return nil, userError.GRPCError() return nil, userError.GRPCError()
} }
return &api.WorkflowTemplate{ return &api.WorkflowTemplate{
Uid: workflowTemplate.UID, Uid: workflowTemplate.UID,
Version: workflowTemplate.Version.String(), Version: workflowTemplate.Version,
Manifest: workflowTemplate.Manifest, Manifest: workflowTemplate.Manifest,
}, nil }, nil
} }
@@ -85,7 +86,7 @@ func (s *WorkflowServer) ListWorkflowTemplateVersions(ctx context.Context, req *
workflowTemplates = append(workflowTemplates, &api.WorkflowTemplate{ workflowTemplates = append(workflowTemplates, &api.WorkflowTemplate{
Uid: wtv.UID, Uid: wtv.UID,
Name: wtv.Name, Name: wtv.Name,
Version: wtv.Version.String(), Version: wtv.Version,
Manifest: wtv.Manifest, Manifest: wtv.Manifest,
}) })
} }