code cleanup

This commit is contained in:
rushtehrani
2019-12-10 11:49:27 -08:00
parent 0996aa830d
commit 7fd5a0b1fe
15 changed files with 73 additions and 63 deletions

2
.vscode/launch.json vendored
View File

@@ -9,7 +9,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"program": "${workspaceRoot}/main.go",
"env": {},
"args": []
}

View File

@@ -4,4 +4,10 @@
},
"go.lintTool": "golangci-lint",
"go.useLanguageServer": true,
"protoc": {
"path": "/usr/local/bin/protoc",
"options": [
"--proto_path=${workspaceRoot}/api"
]
}
}

View File

@@ -73,7 +73,7 @@ func (m *CreateWorkflowRequest) GetWorkflow() *Workflow {
}
type Workflow struct {
Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,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"`
Parameters []*Parameter `protobuf:"bytes,3,rep,name=parameters,proto3" json:"parameters,omitempty"`
WorkflowTemplate *WorkflowTemplate `protobuf:"bytes,4,opt,name=workflowTemplate,proto3" json:"workflowTemplate,omitempty"`
@@ -107,9 +107,9 @@ func (m *Workflow) XXX_DiscardUnknown() {
var xxx_messageInfo_Workflow proto.InternalMessageInfo
func (m *Workflow) GetUuid() string {
func (m *Workflow) GetUid() string {
if m != nil {
return m.Uuid
return m.Uid
}
return ""
}
@@ -191,27 +191,27 @@ func init() {
func init() { proto.RegisterFile("workflow.proto", fileDescriptor_892c7f566756b0be) }
var fileDescriptor_892c7f566756b0be = []byte{
// 319 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x4e, 0xf2, 0x40,
0x14, 0x85, 0x53, 0xe0, 0x27, 0xf4, 0x92, 0x1f, 0xcd, 0x44, 0x62, 0xd3, 0xb0, 0x20, 0x75, 0x83,
0x9b, 0x36, 0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a, 0x82, 0x41, 0xcb, 0xe4, 0xea,
0xef, 0xe5, 0xb2, 0xc3, 0xf4, 0x97, 0x3d, 0x9a, 0x82, 0xef, 0xd8, 0x2e, 0x93, 0xb7, 0x93, 0xe9,
0x08, 0xfe, 0xad, 0x30, 0x2f, 0x6d, 0xd0, 0xea, 0x63, 0xb2, 0x81, 0x03, 0x0b, 0xbf, 0x26, 0xb9,
0xca, 0xe6, 0xc4, 0x9e, 0xa0, 0x5d, 0x75, 0xca, 0x42, 0xb3, 0xfc, 0xcf, 0x82, 0xc3, 0xfd, 0xc2,
0xa2, 0xe9, 0xdb, 0xe7, 0xd7, 0x7b, 0x23, 0x89, 0x4e, 0xb6, 0x2f, 0xa8, 0x92, 0xd5, 0x78, 0x46,
0x1a, 0xc7, 0xc9, 0xab, 0xeb, 0x7c, 0x93, 0xd8, 0xc8, 0xea, 0xdc, 0xb5, 0x3b, 0x6b, 0x9b, 0x67,
0x3c, 0xfb, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x33, 0xb5, 0x82, 0xa3, 0x14, 0x02, 0x00, 0x00,
// 318 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x4e, 0xc2, 0x40,
0x10, 0x86, 0x53, 0x8a, 0x84, 0x0e, 0x11, 0xc9, 0x46, 0x62, 0xd3, 0x70, 0x20, 0xf5, 0x82, 0x97,
0x36, 0x60, 0xb8, 0x78, 0x33, 0xbe, 0x80, 0xa9, 0x26, 0x1e, 0x75, 0xc0, 0x91, 0x54, 0x4b, 0x77,
0xdd, 0x5d, 0xe0, 0x60, 0xb8, 0xf8, 0x0a, 0x3e, 0x82, 0x8f, 0xe4, 0x2b, 0xf8, 0x20, 0x86, 0x2d,
0xbb, 0x42, 0xf4, 0x36, 0x9d, 0xf9, 0xfb, 0xcd, 0xbf, 0xff, 0x40, 0x7b, 0xc5, 0xe5, 0xcb, 0x53,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xfc, 0xdf, 0x78, 0xa3, 0xfd, 0xb8, 0xe2,
0xf1, 0xfb, 0xd7, 0xf7, 0x47, 0x2d, 0x8d, 0x4f, 0x37, 0xf7, 0x53, 0xe9, 0x72, 0x38, 0x21, 0x8d,
0xc3, 0xf4, 0xcd, 0x25, 0xbe, 0x4e, 0xad, 0x65, 0x75, 0xe1, 0xb2, 0x9d, 0x34, 0xcc, 0x11, 0xcf,
0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x67, 0x35, 0xdb, 0xc1, 0x12, 0x02, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.

View File

@@ -21,7 +21,7 @@ message CreateWorkflowRequest {
}
message Workflow {
string uuid = 1;
string uid = 1;
string name = 2;
repeated Parameter parameters = 3;

View File

@@ -60,7 +60,7 @@
"apiWorkflow": {
"type": "object",
"properties": {
"uuid": {
"uid": {
"type": "string"
},
"name": {
@@ -80,7 +80,7 @@
"apiWorkflowTemplate": {
"type": "object",
"properties": {
"uuid": {
"uid": {
"type": "string"
},
"name": {

View File

@@ -21,7 +21,7 @@ var _ = math.Inf
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type WorkflowTemplate struct {
Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,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"`
Manifest string `protobuf:"bytes,4,opt,name=manifest,proto3" json:"manifest,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@@ -54,9 +54,9 @@ func (m *WorkflowTemplate) XXX_DiscardUnknown() {
var xxx_messageInfo_WorkflowTemplate proto.InternalMessageInfo
func (m *WorkflowTemplate) GetUuid() string {
func (m *WorkflowTemplate) GetUid() string {
if m != nil {
return m.Uuid
return m.Uid
}
return ""
}
@@ -82,13 +82,13 @@ func init() {
func init() { proto.RegisterFile("workflow_template.proto", fileDescriptor_b9a07547748a96e8) }
var fileDescriptor_b9a07547748a96e8 = []byte{
// 115 bytes of a gzipped FileDescriptorProto
// 116 bytes of a gzipped FileDescriptorProto
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,
0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x0a, 0xe3, 0x12, 0x08, 0x87, 0xca, 0x87,
0x40, 0xa5, 0x85, 0x84, 0xb8, 0x58, 0x4a, 0x4b, 0x33, 0x53, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38,
0x83, 0xc0, 0x6c, 0x90, 0x58, 0x5e, 0x62, 0x6e, 0xaa, 0x04, 0x13, 0x44, 0x0c, 0xc4, 0x16, 0x92,
0xe2, 0xe2, 0xc8, 0x4d, 0xcc, 0xcb, 0x4c, 0x4b, 0x2d, 0x2e, 0x91, 0x60, 0x01, 0x8b, 0xc3, 0xf9,
0x49, 0x6c, 0x60, 0x3b, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe4, 0xe9, 0x1d, 0x6a, 0x7e,
0x00, 0x00, 0x00,
0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x0a, 0xe1, 0x12, 0x08, 0x87, 0xca, 0x87,
0x40, 0xa5, 0x85, 0x04, 0xb8, 0x98, 0x4b, 0x33, 0x53, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83,
0x40, 0x4c, 0x21, 0x21, 0x2e, 0x96, 0xbc, 0xc4, 0xdc, 0x54, 0x09, 0x26, 0xb0, 0x10, 0x98, 0x2d,
0x24, 0xc5, 0xc5, 0x91, 0x9b, 0x98, 0x97, 0x99, 0x96, 0x5a, 0x5c, 0x22, 0xc1, 0x02, 0x16, 0x87,
0xf3, 0x93, 0xd8, 0xc0, 0x36, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xa0, 0x43, 0x79, 0x28,
0x7c, 0x00, 0x00, 0x00,
}

View File

@@ -3,7 +3,7 @@ syntax = "proto3";
package api;
message WorkflowTemplate {
string uuid = 1;
string uid = 1;
string name = 2;
string manifest = 4;

View File

@@ -13,7 +13,7 @@ type Parameter = wfv1.Parameter
type Options struct {
Name string
GenerateName string
GeneratedName string
Entrypoint string
Parameters []Parameter
ServiceAccount string
@@ -45,8 +45,8 @@ func (c *Client) create(wf *Workflow, opts *Options) (createdWorkflow *Workflow,
if opts.Name != "" {
wf.ObjectMeta.Name = opts.Name
}
if opts.GenerateName != "" {
wf.ObjectMeta.GenerateName = opts.GenerateName
if opts.GeneratedName != "" {
wf.ObjectMeta.GenerateName = opts.GeneratedName
}
if opts.Entrypoint != "" {
wf.Spec.Entrypoint = opts.Entrypoint

View File

@@ -20,12 +20,13 @@ func (r *ResourceManager) CreateWorkflow(namespace string, workflow *model.Workf
})
}
createdWorkflows, err := r.workflowClient.Create(workflow.WorkflowTemplate.ToBytes(), opts)
createdWorkflows, err := r.workflowClient.Create(workflow.WorkflowTemplate.GetManifest(), opts)
if err != nil {
return
}
createdWorkflow = workflow
createdWorkflow.Name = createdWorkflows[0].Name
createdWorkflow.UID = string(createdWorkflows[0].ObjectMeta.UID)
return
}

View File

@@ -1,11 +1,10 @@
package model
import "github.com/google/uuid"
type Workflow struct {
ID uint64
UUID uuid.UUID
UID string
Name string
GeneratedName string
Parameters []Parameter
WorkflowTemplate WorkflowTemplate
}
@@ -14,14 +13,3 @@ type Parameter struct {
Name string
Value *string
}
type WorkflowTemplate struct {
ID uint64
UUID uuid.UUID
Name string
Manifest string
}
func (wt *WorkflowTemplate) ToBytes() []byte {
return []byte(wt.Manifest)
}

View File

@@ -0,0 +1,12 @@
package model
type WorkflowTemplate struct {
ID uint64
UID string
Name string
Manifest string
}
func (wt *WorkflowTemplate) GetManifest() []byte {
return []byte(wt.Manifest)
}

View File

@@ -6,5 +6,5 @@ func TestWorkflowTemplateToBytes(t *testing.T) {
w := &WorkflowTemplate{
Manifest: "test",
}
t.Log(w.ToBytes())
t.Log(w.GetManifest())
}

View File

@@ -21,7 +21,7 @@ func NewWorkflowRepository(db *DB) *WorkflowRepository {
func (w *WorkflowRepository) Create(workflow *model.Workflow) (err error) {
sql, _, err := sq.Insert("workflows").
SetMap(sq.Eq{
"UUID": workflow.UUID,
"UID": workflow.UID,
}).ToSql()
if err != nil {
return

View File

@@ -9,18 +9,18 @@ import (
)
func TestWorkflowRepositoryCreate(t *testing.T) {
uuid, err := uuid.NewRandom()
uid, err := uuid.NewRandom()
if err != nil {
t.Error(err)
return
}
workflow := &model.Workflow{
UUID: uuid,
UID: uid.String(),
}
sql, args, err := sq.Insert("workflows").
SetMap(sq.Eq{
"UUID": workflow.UUID,
"UID": workflow.UID,
}).ToSql()
if err != nil {
t.Error(err)

View File

@@ -34,7 +34,10 @@ func (w *WorkflowServer) Create(ctx context.Context, req *api.CreateWorkflowRequ
if err != nil {
return nil, err
}
req.Workflow.Name = createdWorkflow.Name
req.Workflow = &api.Workflow{
Name: createdWorkflow.Name,
Uid: createdWorkflow.UID,
}
return req.Workflow, nil
}