diff --git a/api/api.swagger.json b/api/api.swagger.json index b390eb7..0bbb20c 100644 --- a/api/api.swagger.json +++ b/api/api.swagger.json @@ -1706,6 +1706,12 @@ }, "workflowExecution": { "$ref": "#/definitions/WorkflowExecution" + }, + "labels": { + "type": "array", + "items": { + "$ref": "#/definitions/KeyValue" + } } } }, diff --git a/api/cron_workflow.pb.go b/api/cron_workflow.pb.go index afca7c8..7078e81 100644 --- a/api/cron_workflow.pb.go +++ b/api/cron_workflow.pb.go @@ -366,6 +366,7 @@ type CronWorkflow struct { SuccessfulJobsHistoryLimit int32 `protobuf:"varint,7,opt,name=successfulJobsHistoryLimit,proto3" json:"successfulJobsHistoryLimit,omitempty"` FailedJobsHistoryLimit int32 `protobuf:"varint,8,opt,name=failedJobsHistoryLimit,proto3" json:"failedJobsHistoryLimit,omitempty"` WorkflowExecution *WorkflowExecution `protobuf:"bytes,9,opt,name=workflowExecution,proto3" json:"workflowExecution,omitempty"` + Labels []*KeyValue `protobuf:"bytes,10,rep,name=labels,proto3" json:"labels,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -459,6 +460,13 @@ func (m *CronWorkflow) GetWorkflowExecution() *WorkflowExecution { return nil } +func (m *CronWorkflow) GetLabels() []*KeyValue { + if m != nil { + return m.Labels + } + return nil +} + func init() { proto.RegisterType((*TerminateCronWorkflowRequest)(nil), "api.TerminateCronWorkflowRequest") proto.RegisterType((*GetCronWorkflowRequest)(nil), "api.GetCronWorkflowRequest") @@ -472,53 +480,55 @@ func init() { func init() { proto.RegisterFile("cron_workflow.proto", fileDescriptor_989cccaad551a50c) } var fileDescriptor_989cccaad551a50c = []byte{ - // 735 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0x41, 0x4f, 0xdb, 0x48, - 0x14, 0xc7, 0x65, 0x42, 0x20, 0x79,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x6c, 0xda, 0xbf, 0x27, 0x26, 0x2a, 0x9d, 0xb3, 0xb5, - 0x1a, 0x2a, 0xba, 0xe6, 0x5c, 0x76, 0xcf, 0xce, 0x95, 0xd3, 0x67, 0xbf, 0xff, 0xf7, 0x1d, 0x49, - 0xf2, 0xce, 0x00, 0x92, 0x75, 0x86, 0x14, 0x64, 0xa4, 0x65, 0x0c, 0x03, 0xd9, 0xd1, 0x20, 0x5b, - 0x76, 0x75, 0x4c, 0x90, 0xb6, 0x72, 0x35, 0xc0, 0xd3, 0x82, 0x5f, 0x06, 0x7c, 0x96, 0x2c, 0xe9, - 0x5a, 0xc3, 0xdd, 0x77, 0x18, 0xc8, 0x86, 0x06, 0xf9, 0x8b, 0xfc, 0x20, 0x08, 0xf9, 0x62, 0x40, - 0x29, 0x73, 0xfe, 0x49, 0x45, 0x17, 0x18, 0xe1, 0x5a, 0xd6, 0xf2, 0x50, 0xb5, 0xeb, 0x1a, 0xb6, - 0xd2, 0x2c, 0x9c, 0xac, 0x8e, 0xc9, 0x22, 0x9f, 0x3e, 0x22, 0x0f, 0xc6, 0xcd, 0x75, 0x2e, 0x87, - 0x7a, 0xe2, 0x15, 0xf9, 0x60, 0xc0, 0xfc, 0xd0, 0xfb, 0x8f, 0xfc, 0xa6, 0x79, 0x6f, 0xba, 0x1b, - 0xad, 0x72, 0xb5, 0x7d, 0xed, 0x56, 0x3b, 0xd7, 0x6e, 0x75, 0x37, 0xb9, 0x76, 0xed, 0x87, 0xfa, - 0x57, 0xee, 0xfd, 0xf1, 0xdf, 0xf8, 0x78, 0x7a, 0x5d, 0x1d, 0xd5, 0xa9, 0x56, 0x9b, 0xd2, 0x53, - 0xfe, 0xfd, 0x3d, 0x00, 0x00, 0xff, 0xff, 0x38, 0x39, 0x79, 0x74, 0x11, 0x08, 0x00, 0x00, + // 759 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95,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f5, 0x82, 0x5e, 0xf2, 0xfb, 0x8f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x84, + 0xa9, 0x70, 0xbc, 0x38, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/api/cron_workflow.proto b/api/cron_workflow.proto index cd39dee..5dbb3d7 100644 --- a/api/cron_workflow.proto +++ b/api/cron_workflow.proto @@ -92,4 +92,6 @@ message CronWorkflow { int32 failedJobsHistoryLimit = 8; WorkflowExecution workflowExecution = 9; + + repeated KeyValue labels = 10; } \ No newline at end of file diff --git a/pkg/cron_workflow.go b/pkg/cron_workflow.go index 03581d0..ac0020c 100644 --- a/pkg/cron_workflow.go +++ b/pkg/cron_workflow.go @@ -17,6 +17,15 @@ import ( ) func (c *Client) UpdateCronWorkflow(namespace string, name string, cronWorkflow *CronWorkflow) (*CronWorkflow, error) { + err := c.cronWorkflowSelectBuilderNoColumns(namespace, cronWorkflow.WorkflowExecution.WorkflowTemplate.UID). + Columns("cw.id"). + RunWith(c.DB). + QueryRow(). + Scan(&cronWorkflow.ID) + if err != nil { + return nil, err + } + workflow := cronWorkflow.WorkflowExecution workflowTemplate, err := c.GetWorkflowTemplate(namespace, workflow.WorkflowTemplate.UID, workflow.WorkflowTemplate.Version) if err != nil { @@ -91,6 +100,13 @@ func (c *Client) UpdateCronWorkflow(namespace string, name string, cronWorkflow if err != nil { return nil, err } + + tx, err := c.DB.Begin() + if err != nil { + return nil, err + } + defer tx.Rollback() + _, err = sb.Update("cron_workflows"). SetMap(sq.Eq{ "schedule": cronWorkflow.Schedule, @@ -101,15 +117,39 @@ func (c *Client) UpdateCronWorkflow(namespace string, name string, cronWorkflow "successful_jobs_history_limit": cronWorkflow.SuccessfulJobsHistoryLimit, "failed_jobs_history_limit": cronWorkflow.FailedJobsHistoryLimit, "workflow_spec": workflowSpec, - }). - Suffix("RETURNING id"). - RunWith(c.DB.DB). + }).Where(sq.Eq{ + "id": cronWorkflow.ID, + }). + RunWith(tx). Exec() - if err != nil { return nil, err } + // delete all labels then replace + _, err = sb.Delete("labels"). + Where(sq.Eq{ + "resource": TypeCronWorkflow, + "resource_id": cronWorkflow.ID, + }).RunWith(tx). + Exec() + if err != nil { + return nil, err + } + + if len(cronWorkflow.Labels) > 0 { + _, err = c.InsertLabelsBuilder(TypeCronWorkflow, cronWorkflow.ID, cronWorkflow.Labels). + RunWith(tx). + Exec() + if err != nil { + return nil, err + } + } + + if err := tx.Commit(); err != nil { + return nil, err + } + return cronWorkflow, nil } return nil, nil @@ -191,7 +231,14 @@ func (c *Client) CreateCronWorkflow(namespace string, cronWorkflow *CronWorkflow if err != nil { return nil, err } - _, err = sb.Insert("cron_workflows"). + + tx, err := c.DB.Begin() + if err != nil { + return nil, err + } + defer tx.Rollback() + + err = sb.Insert("cron_workflows"). SetMap(sq.Eq{ "uid": cronWorkflow.UID, "name": cronWorkflow.Name, @@ -206,13 +253,27 @@ func (c *Client) CreateCronWorkflow(namespace string, cronWorkflow *CronWorkflow "workflow_spec": workflowSpec, }). Suffix("RETURNING id"). - RunWith(c.DB.DB). - Exec() + RunWith(tx). + QueryRow(). + Scan(&cronWorkflow.ID) if err != nil { return nil, err } + if len(cronWorkflow.Labels) > 0 { + _, err = c.InsertLabelsBuilder(TypeCronWorkflow, cronWorkflow.ID, cronWorkflow.Labels). + RunWith(tx). + Exec() + if err != nil { + return nil, err + } + } + + if err := tx.Commit(); err != nil { + return nil, err + } + return cronWorkflow, nil } return nil, nil @@ -327,6 +388,7 @@ func (c *Client) ListCronWorkflows(namespace, workflowTemplateUID string, pagina return nil, err } + // @todo remove this once we get the manifest in the db. for _, cwf := range cronWorkflows { parameters, err := cwf.GetParametersFromWorkflowSpec() if err != nil { @@ -338,6 +400,19 @@ func (c *Client) ListCronWorkflows(namespace, workflowTemplateUID string, pagina } } + labelsMap, err := c.GetDbLabelsMapped(TypeCronWorkflow, CronWorkflowsToIds(cronWorkflows)...) + if err != nil { + log.WithFields(log.Fields{ + "Namespace": namespace, + "Error": err.Error(), + }).Error("Unable to get Workflow Template Labels") + return nil, err + } + + for _, resource := range cronWorkflows { + resource.Labels = labelsMap[resource.ID] + } + return } diff --git a/pkg/types.go b/pkg/types.go index f0c77ec..a7c8a11 100644 --- a/pkg/types.go +++ b/pkg/types.go @@ -78,7 +78,7 @@ type CronWorkflow struct { FailedJobsHistoryLimit *int32 `db:"failed_jobs_history_limit"` WorkflowExecution *WorkflowExecution WorkflowSpec string `db:"workflow_spec"` - Labels []*Label + Labels map[string]string Version int64 WorkflowTemplateVersionId uint64 `db:"workflow_template_version_id"` } @@ -539,6 +539,21 @@ func WorkflowTemplateVersionsToIds(resources []*WorkflowTemplateVersion) (ids [] return } +func CronWorkflowsToIds(resources []*CronWorkflow) (ids []uint64) { + mappedIds := make(map[uint64]bool) + + // This is to make sure we don't have duplicates + for _, resource := range resources { + mappedIds[resource.ID] = true + } + + for id := range mappedIds { + ids = append(ids, id) + } + + return +} + type WorkspaceTemplate struct { ID uint64 UID string diff --git a/server/cron_workflow_server.go b/server/cron_workflow_server.go index 02317a4..705b488 100644 --- a/server/cron_workflow_server.go +++ b/server/cron_workflow_server.go @@ -18,12 +18,17 @@ func NewCronWorkflowServer() *CronWorkflowServer { } func apiCronWorkflow(cwf *v1.CronWorkflow) (cronWorkflow *api.CronWorkflow) { + if cwf == nil { + return nil + } + cronWorkflow = &api.CronWorkflow{ Name: cwf.Name, Schedule: cwf.Schedule, Timezone: cwf.Timezone, Suspend: cwf.Suspend, ConcurrencyPolicy: cwf.ConcurrencyPolicy, + Labels: converter.MappingToKeyValue(cwf.Labels), } if cwf.StartingDeadlineSeconds != nil { @@ -60,7 +65,6 @@ func (c *CronWorkflowServer) CreateCronWorkflow(ctx context.Context, req *api.Cr } workflow := &v1.WorkflowExecution{ - Labels: converter.APIKeyValueToLabel(req.CronWorkflow.WorkflowExecution.Labels), WorkflowTemplate: &v1.WorkflowTemplate{ UID: req.CronWorkflow.WorkflowExecution.WorkflowTemplate.Uid, Version: req.CronWorkflow.WorkflowExecution.WorkflowTemplate.Version, @@ -82,15 +86,14 @@ func (c *CronWorkflowServer) CreateCronWorkflow(ctx context.Context, req *api.Cr SuccessfulJobsHistoryLimit: &req.CronWorkflow.SuccessfulJobsHistoryLimit, FailedJobsHistoryLimit: &req.CronWorkflow.FailedJobsHistoryLimit, WorkflowExecution: workflow, + Labels: converter.APIKeyValueToLabel(req.CronWorkflow.Labels), } cwf, err := client.CreateCronWorkflow(req.Namespace, &cronWorkflow) if err != nil { return nil, err } - if cwf == nil { - return nil, nil - } + return apiCronWorkflow(cwf), nil } @@ -122,6 +125,7 @@ func (c *CronWorkflowServer) UpdateCronWorkflow(ctx context.Context, req *api.Up SuccessfulJobsHistoryLimit: &req.CronWorkflow.SuccessfulJobsHistoryLimit, FailedJobsHistoryLimit: &req.CronWorkflow.FailedJobsHistoryLimit, WorkflowExecution: workflow, + Labels: converter.APIKeyValueToLabel(req.CronWorkflow.Labels), } cwf, err := client.UpdateCronWorkflow(req.Namespace, req.Name, &cronWorkflow)