update: database records for all resources.

This commit is contained in:
Andrey Melnikov
2020-04-27 09:32:45 -07:00
parent d42bffa0e2
commit 1920eb5ed0
18 changed files with 851 additions and 303 deletions

View File

@@ -1296,6 +1296,20 @@
"in": "path",
"required": true,
"type": "string"
},
{
"name": "pageSize",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "page",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
"tags": [
@@ -2106,6 +2120,18 @@
"items": {
"$ref": "#/definitions/WorkflowTemplate"
}
},
"page": {
"type": "integer",
"format": "int32"
},
"pages": {
"type": "integer",
"format": "int32"
},
"totalCount": {
"type": "integer",
"format": "int32"
}
}
},

View File

@@ -107,7 +107,6 @@ message ListCronWorkflowsResponse {
int32 totalCount = 5;
}
message CronWorkflow {
string name = 1;
string schedule = 2;

View File

@@ -333,6 +333,8 @@ func (m *ListWorkflowTemplateVersionsResponse) GetWorkflowTemplates() []*Workflo
type ListWorkflowTemplatesRequest struct {
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
PageSize int32 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"`
Page int32 `protobuf:"varint,3,opt,name=page,proto3" json:"page,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -370,9 +372,26 @@ func (m *ListWorkflowTemplatesRequest) GetNamespace() string {
return ""
}
func (m *ListWorkflowTemplatesRequest) GetPageSize() int32 {
if m != nil {
return m.PageSize
}
return 0
}
func (m *ListWorkflowTemplatesRequest) GetPage() int32 {
if m != nil {
return m.Page
}
return 0
}
type ListWorkflowTemplatesResponse struct {
Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"`
WorkflowTemplates []*WorkflowTemplate `protobuf:"bytes,2,rep,name=workflowTemplates,proto3" json:"workflowTemplates,omitempty"`
Page int32 `protobuf:"varint,3,opt,name=page,proto3" json:"page,omitempty"`
Pages int32 `protobuf:"varint,4,opt,name=pages,proto3" json:"pages,omitempty"`
TotalCount int32 `protobuf:"varint,5,opt,name=totalCount,proto3" json:"totalCount,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -417,6 +436,27 @@ func (m *ListWorkflowTemplatesResponse) GetWorkflowTemplates() []*WorkflowTempla
return nil
}
func (m *ListWorkflowTemplatesResponse) GetPage() int32 {
if m != nil {
return m.Page
}
return 0
}
func (m *ListWorkflowTemplatesResponse) GetPages() int32 {
if m != nil {
return m.Pages
}
return 0
}
func (m *ListWorkflowTemplatesResponse) GetTotalCount() int32 {
if m != nil {
return m.TotalCount
}
return 0
}
type ArchiveWorkflowTemplateRequest struct {
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"`
@@ -767,69 +807,72 @@ func init() {
func init() { proto.RegisterFile("workflow_template.proto", fileDescriptor_b9a07547748a96e8) }
var fileDescriptor_b9a07547748a96e8 = []byte{
// 987 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x97, 0x4f, 0x6f, 0x1b, 0x45,
0x14, 0xc0, 0x35, 0x76, 0x9c, 0xc6, 0xaf, 0x20, 0xa5, 0x0f, 0x92, 0x6c, 0x96, 0xa4, 0x35, 0xd3,
0x44, 0x72, 0x11, 0xb2, 0xd5, 0xc0, 0x29, 0x2d, 0xa2, 0x6e, 0x5a, 0x0a, 0x34, 0x07, 0xb4, 0xa5,
0x45, 0xea, 0x05, 0x26, 0xbb, 0xe3, 0xb0, 0xea, 0x66, 0x77, 0xf1, 0x8c, 0x13, 0x4a, 0xb0, 0x44,
0xe1, 0xc0, 0x8d, 0x0b, 0x7f, 0x04, 0x42, 0xea, 0x19, 0x09, 0x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0xf9, 0x86, 0xe1, 0x9b,
0x13, 0x78, 0xcc, 0x8e, 0x4e, 0x8c, 0x45, 0x3b, 0x0f, 0xef, 0xe2, 0x3b, 0x53, 0xaa, 0x38, 0x93,
0x3d, 0xbf, 0x30, 0x58, 0xc9, 0xe9, 0x44, 0xf0, 0x32, 0x99, 0x32, 0xbc, 0xf3, 0x31, 0x37, 0x86,
0x0b, 0x25, 0x81, 0xb8, 0x49, 0xd6, 0x5f, 0x37, 0xb7, 0x27, 0x20, 0x17, 0xb1, 0x6e, 0x7c, 0xca,
0x60, 0x35, 0xb7, 0xa6, 0xe1, 0x66, 0xde, 0x25, 0xee, 0xa9, 0x79, 0xe6, 0x72, 0x2a, 0x96, 0x4e,
0xf7, 0x02, 0xe2, 0x98, 0x80, 0xb1, 0x3b, 0x93, 0x8a, 0xfd, 0x03, 0x83, 0xd5, 0x86, 0xe3, 0xe4,
0x00, 0xc6, 0x89, 0xd1, 0x70, 0x9c, 0xd1, 0x80, 0xde, 0x25, 0xa0, 0x5b, 0x7c, 0x0a, 0xa0, 0xed,
0xb4, 0x95, 0x78, 0xca, 0x60, 0xdd, 0x92, 0xa1, 0x27, 0x6c, 0x99, 0x03, 0xb7, 0x4a, 0x14, 0x89,
0xcc, 0x58, 0x80, 0xe6, 0x2c, 0x00, 0x7f, 0x64, 0xf0, 0xd2, 0x2d, 0x19, 0x75, 0x87, 0x99, 0x7c,
0xb8, 0x42, 0x0c, 0xb1, 0x04, 0xcd, 0xfc, 0x17, 0xdc, 0xdb, 0x04, 0x77, 0xf3, 0x95, 0x1b, 0x93,
0xc3, 0xd5, 0x8f, 0x1f, 0xc9, 0xc7, 0x9d, 0xbd, 0x79, 0xfa, 0x15, 0x7f, 0xed, 0xdf, 0x00, 0x00,
0x00, 0xff, 0xff, 0xa7, 0xb2, 0x1d, 0x6c, 0xd5, 0x0f, 0x00, 0x00,
// 1031 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0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x02, 0x9a, 0x70, 0xc6, 0x1d, 0xfb, 0x7b, 0x02, 0x6b, 0x35, 0xd7, 0xcd, 0x00, 0x34, 0x85, 0x51,
0x73, 0xdd, 0xc9, 0x80, 0xde, 0x41, 0xa0, 0x5b, 0x6c, 0x0e, 0xa0, 0x9d, 0x64, 0x94, 0x78, 0x42,
0x60, 0xc3, 0x11, 0x91, 0xcf, 0x1b, 0x22, 0x03, 0x6e, 0x0d, 0x29, 0x62, 0x9d, 0xa9, 0x00, 0xed,
0xb3, 0x00, 0xfc, 0x81, 0xc0, 0x0b, 0xb7, 0x84, 0x9e, 0x0e, 0x53, 0xf9, 0xe8, 0x2a, 0x32, 0x18,
0x0d, 0x5c, 0xf9, 0x2f, 0xb8, 0xb7, 0x10, 0xee, 0xe6, 0x4b, 0x37, 0x66, 0x87, 0xab, 0x1e, 0x3f,
0x14, 0x8f, 0xba, 0xfb, 0x0b, 0xf8, 0x2f, 0xc0, 0x2b, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x1b,
0x1a, 0x80, 0x9b, 0x50, 0x10, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.

View File

@@ -572,6 +572,10 @@ func local_request_WorkflowTemplateService_ListWorkflowTemplateVersions_0(ctx co
}
var (
filter_WorkflowTemplateService_ListWorkflowTemplates_0 = &utilities.DoubleArray{Encoding: map[string]int{"namespace": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
)
func request_WorkflowTemplateService_ListWorkflowTemplates_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowTemplateServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ListWorkflowTemplatesRequest
var metadata runtime.ServerMetadata
@@ -594,6 +598,13 @@ func request_WorkflowTemplateService_ListWorkflowTemplates_0(ctx context.Context
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "namespace", err)
}
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_WorkflowTemplateService_ListWorkflowTemplates_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.ListWorkflowTemplates(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
@@ -621,6 +632,10 @@ func local_request_WorkflowTemplateService_ListWorkflowTemplates_0(ctx context.C
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "namespace", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_WorkflowTemplateService_ListWorkflowTemplates_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.ListWorkflowTemplates(ctx, &protoReq)
return msg, metadata, err

View File

@@ -125,11 +125,16 @@ message ListWorkflowTemplateVersionsResponse {
message ListWorkflowTemplatesRequest {
string namespace = 1;
int32 pageSize = 2;
int32 page = 3;
}
message ListWorkflowTemplatesResponse {
int32 count = 1;
repeated WorkflowTemplate workflowTemplates = 2;
int32 page = 3;
int32 pages = 4;
int32 totalCount = 5;
}
message ArchiveWorkflowTemplateRequest {

View File

@@ -0,0 +1,23 @@
-- +goose Up
CREATE TABLE cron_workflows
(
id serial PRIMARY KEY,
uid varchar(36) UNIQUE NOT NULL CHECK(uid <> ''),
name varchar(255),
workflow_template_version_id INT REFERENCES workflow_template_versions,
schedule varchar(255),
timezone varchar(255),
suspend boolean,
concurrency_policy varchar(255),
starting_deadline_seconds INT,
successful_jobs_history_limit INT,
failed_jobs_history_limit INT,
workflow_spec TEXT,
-- auditing info
created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'),
modified_at timestamp
);
-- +goose Down
DROP TABLE cron_workflows;

View File

@@ -0,0 +1,15 @@
-- +goose Up
CREATE TABLE labels
(
id serial PRIMARY KEY,
key varchar(255),
value varchar(255),
resource varchar(255),
resource_id INTEGER,
-- auditing info
created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc')
);
-- +goose Down
DROP TABLE labels;

View File

@@ -0,0 +1,24 @@
-- +goose Up
ALTER TABLE workflow_executions
ADD COLUMN started_at TIMESTAMP,
ADD COLUMN workflow_template_version_id INT REFERENCES workflow_template_versions,
ADD COLUMN phase VARCHAR(50),
ADD COLUMN cron_workflow_id INT REFERENCES cron_workflows,
DROP COLUMN failed_at,
DROP COLUMN workflow_template_id
;
UPDATE workflow_executions
SET started_at = created_at,
phase = 'Succeeded'
;
-- +goose Down
ALTER TABLE workflow_executions
DROP COLUMN started_at,
DROP COLUMN workflow_template_version_id,
DROP COLUMN phase,
DROP COLUMN cron_workflow_id,
ADD COLUMN failed_at TIMESTAMP,
ADD COLUMN workflow_template_id INT
;

View File

@@ -2,15 +2,17 @@ package v1
import (
"fmt"
sq "github.com/Masterminds/squirrel"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
argojson "github.com/argoproj/pkg/json"
"github.com/onepanelio/core/pkg/util"
"github.com/onepanelio/core/pkg/util/label"
"github.com/onepanelio/core/pkg/util/pagination"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"regexp"
"sort"
"strings"
)
@@ -162,6 +164,32 @@ func (c *Client) CreateCronWorkflow(namespace string, cronWorkflow *CronWorkflow
// Manifests could get big, don't return them in this case.
cronWorkflow.WorkflowExecution.WorkflowTemplate.Manifest = ""
workflowSpec, err := yaml.Marshal(argoCreatedCronWorkflow.Spec.WorkflowSpec)
if err != nil {
return nil, err
}
_, err = sb.Insert("cron_workflows").
SetMap(sq.Eq{
"uid": cronWorkflow.UID,
"name": cronWorkflow.Name,
"workflow_template_version_id": workflowTemplate.WorkflowTemplateVersionId,
"schedule": cronWorkflow.Schedule,
"timezone": cronWorkflow.Timezone,
"suspend": cronWorkflow.Suspend,
"concurrency_policy": cronWorkflow.ConcurrencyPolicy,
"starting_deadline_seconds": cronWorkflow.StartingDeadlineSeconds,
"successful_jobs_history_limit": cronWorkflow.SuccessfulJobsHistoryLimit,
"failed_jobs_history_limit": cronWorkflow.FailedJobsHistoryLimit,
"workflow_spec": workflowSpec,
}).
Suffix("RETURNING id").
RunWith(c.DB.DB).
Exec()
if err != nil {
return nil, err
}
return cronWorkflow, nil
}
return nil, nil
@@ -261,53 +289,42 @@ func (c *Client) DeleteCronWorkflowLabel(namespace, name string, keysToDelete ..
return wf.Labels, nil
}
func (c *Client) ListCronWorkflows(namespace, workflowTemplateUID string) (cronWorkflows []*CronWorkflow, err error) {
listOptions := ListOptions{}
if workflowTemplateUID != "" {
listOptions.LabelSelector = "onepanel.io/workflow-template-uid=" + workflowTemplateUID
}
cronWorkflowList, err := c.ArgoprojV1alpha1().CronWorkflows(namespace).List(listOptions)
func (c *Client) ListCronWorkflows(namespace, workflowTemplateUID string, pagination *pagination.PaginationRequest) (cronWorkflows []*CronWorkflow, err error) {
sb := c.cronWorkflowSelectBuilder(namespace, workflowTemplateUID).
OrderBy("cw.created_at DESC")
sb = *pagination.ApplyToSelect(&sb)
query, args, err := sb.ToSql()
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Error": err.Error(),
}).Error("CronWorkflows not found.")
return nil, util.NewUserError(codes.NotFound, "CronWorkflows not found.")
}
cwfs := cronWorkflowList.Items
sort.Slice(cwfs, func(i, j int) bool {
ith := cwfs[i].CreationTimestamp.Time
jth := cwfs[j].CreationTimestamp.Time
//Most recent first
return ith.After(jth)
})
for _, cwf := range cwfs {
var parameters []WorkflowExecutionParameter
for _, param := range cwf.Spec.WorkflowSpec.Arguments.Parameters {
parameters = append(parameters, WorkflowExecutionParameter{
Name: param.Name,
Value: param.Value,
})
return nil, err
}
cronWorkflows = append(cronWorkflows, &CronWorkflow{
CreatedAt: cwf.CreationTimestamp.UTC(),
UID: string(cwf.ObjectMeta.UID),
Name: cwf.Name,
Schedule: cwf.Spec.Schedule,
Timezone: cwf.Spec.Timezone,
Suspend: cwf.Spec.Suspend,
ConcurrencyPolicy: string(cwf.Spec.ConcurrencyPolicy),
StartingDeadlineSeconds: cwf.Spec.StartingDeadlineSeconds,
SuccessfulJobsHistoryLimit: cwf.Spec.SuccessfulJobsHistoryLimit,
FailedJobsHistoryLimit: cwf.Spec.FailedJobsHistoryLimit,
WorkflowExecution: &WorkflowExecution{
if err := c.DB.Select(&cronWorkflows, query, args...); err != nil {
return nil, err
}
for _, cwf := range cronWorkflows {
parameters, err := cwf.GetParametersFromWorkflowSpec()
if err != nil {
continue
}
cwf.WorkflowExecution = &WorkflowExecution{
Parameters: parameters,
},
})
}
}
return
}
func (c *Client) CountCronWorkflows(namespace, workflowTemplateUID string) (count int, err error) {
err = c.cronWorkflowSelectBuilderNoColumns(namespace, workflowTemplateUID).
Columns("COUNT(*)").
RunWith(c.DB.DB).
QueryRow().
Scan(&count)
return
}
@@ -434,6 +451,7 @@ func (c *Client) createCronWorkflow(namespace string, workflowTemplateId *uint64
newParams = append(newParams, param)
}
cwf.Spec.WorkflowSpec.Arguments.Parameters = newParams
wf.Spec.Arguments.Parameters = newParams
}
if opts.Labels != nil {
cwf.ObjectMeta.Labels = *opts.Labels
@@ -471,7 +489,46 @@ func (c *Client) createCronWorkflow(namespace string, workflowTemplateId *uint64
}
func (c *Client) TerminateCronWorkflow(namespace, name string) (err error) {
query, args, err := sb.Select().
Columns("cw.id", "cw.created_at", "cw.uid", "cw.name", "cw.workflow_template_version_id").
Columns("cw.schedule", "cw.timezone", "cw.suspend", "cw.concurrency_policy", "cw.starting_deadline_seconds").
Columns("cw.successful_jobs_history_limit", "cw.failed_jobs_history_limit", "cw.workflow_spec", "wtv.version").
From("cron_workflows cw").
Join("workflow_template_versions wtv ON wtv.id = cw.workflow_template_version_id").
Join("workflow_templates wt ON wt.id = wtv.workflow_template_id").
Where(sq.Eq{
"wt.namespace": namespace,
"cw.name": name,
}).
ToSql()
cronWorkflow := &CronWorkflow{}
if err := c.DB.Get(cronWorkflow, query, args...); err != nil {
return err
}
query = `DELETE FROM workflow_executions
WHERE cron_workflow_id = $1`
if _, err := c.DB.Exec(query, cronWorkflow.ID); err != nil {
return err
}
query = `DELETE FROM cron_workflows
USING workflow_template_versions, workflow_templates
WHERE cron_workflows.workflow_template_version_id = workflow_template_versions.id
AND workflow_template_versions.workflow_template_id = workflow_templates.id
AND workflow_templates.namespace = $1
AND cron_workflows.name = $2`
if _, err := c.DB.Exec(query, namespace, name); err != nil {
return err
}
err = c.ArgoprojV1alpha1().CronWorkflows(namespace).Delete(name, nil)
if err != nil && strings.Contains(err.Error(), "not found") {
err = nil
}
return
}
@@ -487,3 +544,25 @@ func unmarshalCronWorkflows(cwfBytes []byte, strict bool) (cwfs wfv1.CronWorkflo
}
return
}
func (c *Client) cronWorkflowSelectBuilder(namespace string, workflowTemplateUid string) sq.SelectBuilder {
sb := c.cronWorkflowSelectBuilderNoColumns(namespace, workflowTemplateUid).
Columns("cw.id", "cw.created_at", "cw.uid", "cw.name", "cw.workflow_template_version_id").
Columns("cw.schedule", "cw.timezone", "cw.suspend", "cw.concurrency_policy", "cw.starting_deadline_seconds").
Columns("cw.successful_jobs_history_limit", "cw.failed_jobs_history_limit", "cw.workflow_spec", "wtv.version")
return sb
}
func (c *Client) cronWorkflowSelectBuilderNoColumns(namespace string, workflowTemplateUid string) sq.SelectBuilder {
sb := sb.Select().
From("cron_workflows cw").
Join("workflow_template_versions wtv ON wtv.id = cw.workflow_template_version_id").
Join("workflow_templates wt ON wt.id = wtv.workflow_template_id").
Where(sq.Eq{
"wt.namespace": namespace,
"wt.uid": workflowTemplateUid,
})
return sb
}

82
pkg/labels.go Normal file
View File

@@ -0,0 +1,82 @@
package v1
import (
sq "github.com/Masterminds/squirrel"
)
func (c *Client) InsertLabelsBuilder(resource string, resourceId uint64, keyValues map[string]string) sq.InsertBuilder {
sb := sb.Insert("labels").
Columns("resource", "resource_id", "key", "value")
for key, value := range keyValues {
sb = sb.Values(resource, resourceId, key, value)
}
return sb
}
func (c *Client) GetDbLabels(resource string, ids ...uint64) (labels []*Label, err error) {
if len(ids) == 0 {
return make([]*Label, 0), nil
}
tx, err := c.DB.Begin()
if err != nil {
return nil, err
}
whereIn := "resource_id IN (?"
for i := range ids {
if i == 0 {
continue
}
whereIn += ",?"
}
whereIn += ")"
defer tx.Rollback()
query, args, err := sb.Select("id", "key", "value", "resource", "resource_id").
From("labels").
Where(whereIn, ids).
Where(sq.Eq{
"resource": resource,
}).
ToSql()
if err != nil {
return nil, err
}
allArgs := make([]interface{}, 0)
for _, arg := range args[0].([]uint64) {
allArgs = append(allArgs, arg)
}
allArgs = append(allArgs, args[1])
err = c.DB.Select(&labels, query, allArgs...)
if err != nil {
return nil, err
}
return
}
func (c *Client) GetDbLabelsMapped(resource string, ids ...uint64) (result map[uint64]map[string]string, err error) {
dbLabels, err := c.GetDbLabels(resource, ids...)
if err != nil {
return
}
result = make(map[uint64]map[string]string)
for _, dbLabel := range dbLabels {
_, ok := result[dbLabel.ResourceId]
if !ok {
result[dbLabel.ResourceId] = make(map[string]string)
}
result[dbLabel.ResourceId][dbLabel.Key] = dbLabel.Value
}
return
}

View File

@@ -13,6 +13,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
TypeWorkflowTemplate string = "workflow_template"
TypeWorkflowTemplateVersion string = "workflow_template_version"
TypeWorkflowExecution string = "workflow_execution"
TypeCronWorkflow string = "cron_workflow"
)
type Namespace struct {
Name string
Labels map[string]string
@@ -42,17 +49,63 @@ type Metric struct {
type CronWorkflow struct {
ID uint64
CreatedAt time.Time `db:"created_at"`
ModifiedAt *time.Time `db:"modified_at"`
UID string
Name string
GenerateName string
Schedule string
Timezone string
Suspend bool
ConcurrencyPolicy string
StartingDeadlineSeconds *int64
SuccessfulJobsHistoryLimit *int32
FailedJobsHistoryLimit *int32
ConcurrencyPolicy string `db:"concurrency_policy"`
StartingDeadlineSeconds *int64 `db:"starting_deadline_seconds"`
SuccessfulJobsHistoryLimit *int32 `db:"successful_jobs_history_limit"`
FailedJobsHistoryLimit *int32 `db:"failed_jobs_history_limit"`
WorkflowExecution *WorkflowExecution
WorkflowSpec string `db:"workflow_spec"`
Labels []*Label
Version int64
WorkflowTemplateVersionId uint64 `db:"workflow_template_version_id"`
}
func (cw *CronWorkflow) GetParametersFromWorkflowSpec() ([]WorkflowExecutionParameter, error) {
var parameters []WorkflowExecutionParameter
mappedData := make(map[string]interface{})
if err := yaml.Unmarshal([]byte(cw.WorkflowSpec), mappedData); err != nil {
return nil, err
}
arguments, ok := mappedData["arguments"]
if !ok {
return parameters, nil
}
argumentsMap := arguments.(map[interface{}]interface{})
parametersRaw, ok := argumentsMap["parameters"]
if !ok {
return parameters, nil
}
parametersArray, ok := parametersRaw.([]interface{})
for _, parameter := range parametersArray {
paramMap, ok := parameter.(map[interface{}]interface{})
if !ok {
continue
}
name := paramMap["name"].(string)
value := paramMap["value"].(string)
workflowParameter := WorkflowExecutionParameter{
Name: name,
Value: &value,
}
parameters = append(parameters, workflowParameter)
}
return parameters, nil
}
type WorkflowTemplate struct {
@@ -62,12 +115,22 @@ type WorkflowTemplate struct {
Name string
Manifest string
Version int64
Versions int64 `db:"versions"`
Versions int64 `db:"versions"` // How many versions there are of this template total.
IsLatest bool
IsArchived bool `db:"is_archived"`
ArgoWorkflowTemplate *wfv1.WorkflowTemplate
Labels map[string]string
WorkflowExecutionStatisticReport *WorkflowExecutionStatisticReport
WorkflowTemplateVersionId uint64 `db:"workflow_template_version_id"` // Reference to the associated workflow template version.
}
type Label struct {
ID uint64
CreatedAt time.Time `db:"created_at"`
Key string
Value string
Resource string
ResourceId uint64 `db:"resource_id"`
}
type WorkflowExecutionStatisticReport struct {
@@ -293,17 +356,6 @@ func (wt *WorkflowTemplate) AddWorkflowTemplateParametersFromAnnotations(spec ma
arguments["parameters"] = parameters
}
const (
WorfklowPending WorkflowExecutionPhase = "Pending"
WorfklowRunning WorkflowExecutionPhase = "Running"
WorfklowSucceeded WorkflowExecutionPhase = "Succeeded"
WorfklowSkipped WorkflowExecutionPhase = "Skipped"
WorfklowFailed WorkflowExecutionPhase = "Failed"
WorfklowError WorkflowExecutionPhase = "Error"
)
type WorkflowExecutionPhase string
type WorkflowExecution struct {
ID uint64
CreatedAt time.Time `db:"created_at"`
@@ -312,10 +364,10 @@ type WorkflowExecution struct {
GenerateName string
Parameters []WorkflowExecutionParameter
Manifest string
Phase WorkflowExecutionPhase
StartedAt time.Time
FinishedAt time.Time
WorkflowTemplate *WorkflowTemplate
Phase wfv1.NodePhase
StartedAt *time.Time `db:"started_at"`
FinishedAt *time.Time `db:"finished_at"`
WorkflowTemplate *WorkflowTemplate `db:"workflow_template"`
Labels map[string]string
}
@@ -400,3 +452,33 @@ func FilePathToExtension(path string) string {
return path[dotIndex+1:]
}
func WorkflowTemplatesToIds(workflowTemplates []*WorkflowTemplate) (ids []uint64) {
mappedIds := make(map[uint64]bool)
// This is to make sure we don't have duplicates
for _, workflowTemplate := range workflowTemplates {
mappedIds[workflowTemplate.ID] = true
}
for id := range mappedIds {
ids = append(ids, id)
}
return
}
func WorkflowTemplatesToVersionIds(workflowTemplates []*WorkflowTemplate) (ids []uint64) {
mappedIds := make(map[uint64]bool)
// This is to make sure we don't have duplicates
for _, workflowTemplate := range workflowTemplates {
mappedIds[workflowTemplate.WorkflowTemplateVersionId] = true
}
for id := range mappedIds {
ids = append(ids, id)
}
return
}

View File

@@ -0,0 +1,46 @@
package pagination
import (
"github.com/Masterminds/squirrel"
"math"
)
type PaginationRequest struct {
Page uint64
PageSize uint64
}
func NewRequest(page, pageSize int32) PaginationRequest {
if page == 0 {
page = 1
}
if pageSize == 0 {
pageSize = 15
}
return PaginationRequest{
Page: uint64(page),
PageSize: uint64(pageSize),
}
}
func (pr *PaginationRequest) Offset() uint64 {
// start at page 1.
return (pr.Page - 1) * pr.PageSize
}
func (pr *PaginationRequest) CalculatePages(count int) int32 {
return int32(math.Ceil(float64(count) / float64(pr.PageSize)))
}
func (pr *PaginationRequest) ApplyToSelect(sb *squirrel.SelectBuilder) *squirrel.SelectBuilder {
if pr == nil {
return sb
}
result := sb.Limit(pr.PageSize).
Offset(pr.Offset())
return &result
}

View File

@@ -1,5 +1,7 @@
package ptr
import "time"
func Bool(value bool) *bool {
return &value
}
@@ -15,3 +17,7 @@ func Int64(value int64) *int64 {
func String(value string) *string {
return &value
}
func Time(value time.Time) *time.Time {
return &value
}

View File

@@ -10,10 +10,11 @@ import (
"github.com/ghodss/yaml"
"github.com/onepanelio/core/api"
"github.com/onepanelio/core/pkg/util/label"
"github.com/onepanelio/core/pkg/util/pagination"
"github.com/onepanelio/core/pkg/util/ptr"
"io"
"io/ioutil"
"regexp"
"sort"
"strconv"
"strings"
"time"
@@ -192,7 +193,7 @@ func addEnvToTemplate(template *wfv1.Template, key string, value string) {
}
}
func (c *Client) createWorkflow(namespace string, workflowTemplateId *uint64, wf *wfv1.Workflow, opts *WorkflowExecutionOptions) (createdWorkflow *wfv1.Workflow, err error) {
func (c *Client) createWorkflow(namespace string, workflowTemplateId uint64, workflowTemplateVersionId uint64, wf *wfv1.Workflow, opts *WorkflowExecutionOptions) (createdWorkflow *wfv1.Workflow, err error) {
if opts == nil {
opts = &WorkflowExecutionOptions{}
}
@@ -237,7 +238,7 @@ func (c *Client) createWorkflow(namespace string, workflowTemplateId *uint64, wf
return nil, err
}
err = InjectExitHandlerWorkflowExecutionStatistic(wf, namespace, workflowTemplateId)
err = InjectExitHandlerWorkflowExecutionStatistic(wf, namespace, &workflowTemplateId)
if err != nil {
return nil, err
}
@@ -249,7 +250,7 @@ func (c *Client) createWorkflow(namespace string, workflowTemplateId *uint64, wf
}
//Create an entry for workflow_executions statistic
//CURL code will hit the API endpoint that will update the db row
err = c.InsertPreWorkflowExecutionStatistic(namespace, createdWorkflow.Name, int64(*workflowTemplateId), time.Now())
err = c.InsertPreWorkflowExecutionStatistic(namespace, createdWorkflow.Name, int64(workflowTemplateId), workflowTemplateVersionId, createdWorkflow.CreationTimestamp.UTC())
if err != nil {
return nil, err
}
@@ -332,7 +333,7 @@ func (c *Client) CreateWorkflowExecution(namespace string, workflow *WorkflowExe
var createdWorkflows []*wfv1.Workflow
for _, wf := range workflows {
createdWorkflow, err := c.createWorkflow(namespace, &workflowTemplate.ID, &wf, opts)
createdWorkflow, err := c.createWorkflow(namespace, workflowTemplate.ID, workflowTemplate.WorkflowTemplateVersionId, &wf, opts)
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
@@ -365,7 +366,7 @@ func (c *Client) CreateWorkflowExecution(namespace string, workflow *WorkflowExe
return workflow, nil
}
func (c *Client) InsertPreWorkflowExecutionStatistic(namespace, name string, workflowTemplateID int64, createdAt time.Time) error {
func (c *Client) InsertPreWorkflowExecutionStatistic(namespace, name string, workflowTemplateID int64, workflowTemplateVersionId uint64, createdAt time.Time) error {
tx, err := c.DB.Begin()
if err != nil {
return err
@@ -373,10 +374,11 @@ func (c *Client) InsertPreWorkflowExecutionStatistic(namespace, name string, wor
defer tx.Rollback()
insertMap := sq.Eq{
"workflow_template_id": workflowTemplateID,
"workflow_template_version_id": workflowTemplateVersionId,
"name": name,
"namespace": namespace,
"created_at": createdAt.UTC(),
"phase": wfv1.NodePending,
}
_, err = sb.Insert("workflow_executions").
@@ -391,7 +393,7 @@ func (c *Client) InsertPreWorkflowExecutionStatistic(namespace, name string, wor
return err
}
func (c *Client) FinishWorkflowExecutionStatisticViaExitHandler(namespace, name string, workflowTemplateID int64, workflowOutcomeIsSuccess bool) (err error) {
func (c *Client) FinishWorkflowExecutionStatisticViaExitHandler(namespace, name string, workflowTemplateID int64, phase wfv1.NodePhase, startedAt time.Time) (err error) {
tx, err := c.DB.Begin()
if err != nil {
return err
@@ -399,15 +401,11 @@ func (c *Client) FinishWorkflowExecutionStatisticViaExitHandler(namespace, name
defer tx.Rollback()
updateMap := sq.Eq{
"workflow_template_id": workflowTemplateID,
"started_at": startedAt.UTC(),
"name": name,
"namespace": namespace,
}
if workflowOutcomeIsSuccess {
updateMap["finished_at"] = time.Now().UTC()
} else {
updateMap["failed_at"] = time.Now().UTC()
"finished_at": time.Now().UTC(),
"phase": phase,
}
_, err = sb.Update("workflow_executions").
@@ -423,6 +421,30 @@ func (c *Client) FinishWorkflowExecutionStatisticViaExitHandler(namespace, name
}
func (c *Client) CronStartWorkflowExecutionStatisticInsert(namespace, name string, workflowTemplateID int64) (err error) {
query, args, err := c.workflowTemplatesSelectBuilder(namespace).
Where(sq.Eq{
"wt.id": workflowTemplateID,
}).
ToSql()
if err != nil {
return err
}
workflowTemplate := &WorkflowTemplate{}
if err := c.DB.Get(workflowTemplate, query, args...); err != nil {
return err
}
query, args, err = c.cronWorkflowSelectBuilder(namespace, workflowTemplate.UID).ToSql()
if err != nil {
return err
}
cronWorkflow := &CronWorkflow{}
if err := c.DB.Get(cronWorkflow, query, args...); err != nil {
return err
}
tx, err := c.DB.Begin()
if err != nil {
return err
@@ -430,10 +452,11 @@ func (c *Client) CronStartWorkflowExecutionStatisticInsert(namespace, name strin
defer tx.Rollback()
insertMap := sq.Eq{
"workflow_template_id": workflowTemplateID,
"workflow_template_version_id": cronWorkflow.WorkflowTemplateVersionId,
"name": name,
"namespace": namespace,
"created_at": time.Now().UTC(),
"phase": wfv1.NodePending,
"cron_workflow_id": cronWorkflow.ID,
}
_, err = sb.Insert("workflow_executions").
@@ -497,9 +520,9 @@ func (c *Client) GetWorkflowExecution(namespace, name string) (workflow *Workflo
UID: string(wf.UID),
CreatedAt: wf.CreationTimestamp.UTC(),
Name: wf.Name,
Phase: WorkflowExecutionPhase(wf.Status.Phase),
StartedAt: wf.Status.StartedAt.UTC(),
FinishedAt: wf.Status.FinishedAt.UTC(),
Phase: wf.Status.Phase,
StartedAt: ptr.Time(wf.Status.StartedAt.UTC()),
FinishedAt: ptr.Time(wf.Status.FinishedAt.UTC()),
Manifest: string(manifest),
WorkflowTemplate: workflowTemplate,
}
@@ -507,67 +530,27 @@ func (c *Client) GetWorkflowExecution(namespace, name string) (workflow *Workflo
return
}
func (c *Client) ListWorkflowExecutions(namespace, workflowTemplateUID, workflowTemplateVersion string) (workflows []*WorkflowExecution, err error) {
opts := &WorkflowExecutionOptions{}
if workflowTemplateUID != "" {
labelSelect := fmt.Sprintf("%s=%s", workflowTemplateUIDLabelKey, workflowTemplateUID)
if workflowTemplateVersion != "" {
labelSelect = fmt.Sprintf("%s,%s=%s", labelSelect, workflowTemplateVersionLabelKey, workflowTemplateVersion)
}
opts.ListOptions = &ListOptions{
LabelSelector: labelSelect,
}
}
workflowList, err := c.ArgoprojV1alpha1().Workflows(namespace).List(*opts.ListOptions)
func (c *Client) ListWorkflowExecutions(namespace, workflowTemplateUID, workflowTemplateVersion string, paginator *pagination.PaginationRequest) (workflows []*WorkflowExecution, err error) {
sb := workflowExecutionsSelectBuilder(namespace, workflowTemplateUID, workflowTemplateVersion).
OrderBy("we.created_at DESC")
sb = *paginator.ApplyToSelect(&sb)
query, args, err := sb.ToSql()
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"WorkflowTemplateUID": workflowTemplateUID,
"WorkflowTemplateVersion": workflowTemplateVersion,
"Error": err.Error(),
}).Error("Workflows not found.")
return nil, util.NewUserError(codes.NotFound, "Workflows not found.")
return nil, err
}
wfs := workflowList.Items
sort.Slice(wfs, func(i, j int) bool {
ith := wfs[i].CreationTimestamp.Time
jth := wfs[j].CreationTimestamp.Time
//Most recent first
return ith.After(jth)
})
if err := c.DB.Select(&workflows, query, args...); err != nil {
return nil, err
}
return
}
for _, wf := range wfs {
execution := &WorkflowExecution{
Name: wf.ObjectMeta.Name,
UID: string(wf.ObjectMeta.UID),
Phase: WorkflowExecutionPhase(wf.Status.Phase),
StartedAt: wf.Status.StartedAt.UTC(),
FinishedAt: wf.Status.FinishedAt.UTC(),
CreatedAt: wf.CreationTimestamp.UTC(),
}
versionString, ok := wf.Labels[workflowTemplateVersionLabelKey]
if ok {
versionNumber, err := strconv.ParseInt(versionString, 10, 64)
if err == nil {
execution.WorkflowTemplate = &WorkflowTemplate{
Version: versionNumber,
}
} else {
log.WithFields(log.Fields{
"Namespace": namespace,
"WorkflowTemplateUID": workflowTemplateUID,
"WorkflowExecutionUID": wf.UID,
"Error": "Unable to get workflow template version",
}).Error("Unable to get workflow template version")
}
}
workflows = append(workflows, execution)
}
func (c *Client) CountWorkflowExecutions(namespace, workflowTemplateUID, workflowTemplateVersion string) (count int, err error) {
err = workflowExecutionsSelectBuilderNoColumns(namespace, workflowTemplateUID, workflowTemplateVersion).
Columns("COUNT(*)").
RunWith(c.DB.DB).
QueryRow().
Scan(&count)
return
}
@@ -644,8 +627,8 @@ func (c *Client) WatchWorkflowExecution(namespace, name string) (<-chan *Workflo
workflowWatcher <- &WorkflowExecution{
CreatedAt: workflow.CreationTimestamp.UTC(),
StartedAt: workflow.Status.StartedAt.UTC(),
FinishedAt: workflow.Status.FinishedAt.UTC(),
StartedAt: ptr.Time(workflow.Status.StartedAt.UTC()),
FinishedAt: ptr.Time(workflow.Status.FinishedAt.UTC()),
UID: string(workflow.UID),
Name: workflow.Name,
Manifest: string(manifest),
@@ -1152,7 +1135,7 @@ func (c *Client) SetWorkflowTemplateLabels(namespace, name, prefix string, keyVa
func (c *Client) GetWorkflowExecutionStatisticsForTemplates(workflowTemplates ...*WorkflowTemplate) (err error) {
if len(workflowTemplates) == 0 {
return errors.New("GetWorkflowExecutionStatisticsForTemplates requires at least 1 id")
return nil
}
tx, err := c.DB.Begin()
@@ -1160,7 +1143,7 @@ func (c *Client) GetWorkflowExecutionStatisticsForTemplates(workflowTemplates ..
return err
}
whereIn := "workflow_template_id IN (?"
whereIn := "wtv.workflow_template_id IN (?"
for i := range workflowTemplates {
if i == 0 {
continue
@@ -1179,16 +1162,17 @@ func (c *Client) GetWorkflowExecutionStatisticsForTemplates(workflowTemplates ..
statsSelect := `
workflow_template_id,
MAX(created_at) last_executed,
COUNT(*) FILTER (WHERE finished_At IS NULL AND failed_at IS NULL) running,
COUNT(*) FILTER (WHERE finished_at IS NOT NULL) completed,
COUNT(*) FILTER (WHERE failed_at IS NOT NULL) failed,
MAX(we.created_at) last_executed,
COUNT(*) FILTER (WHERE finished_at IS NULL AND (phase = 'Running' OR phase = 'Pending')) running,
COUNT(*) FILTER (WHERE finished_at IS NOT NULL AND phase = 'Succeeded') completed,
COUNT(*) FILTER (WHERE finished_at IS NOT NULL AND (phase = 'Failed' OR phase = 'Error')) failed,
COUNT(*) total`
query, args, err := sb.Select(statsSelect).
From("workflow_executions").
From("workflow_executions we").
Join("workflow_template_versions wtv ON wtv.id = we.workflow_template_version_id").
Where(whereIn, ids...).
GroupBy("workflow_template_id").
GroupBy("wtv.workflow_template_id").
ToSql()
if err != nil {
@@ -1336,3 +1320,28 @@ func InjectInitHandlerWorkflowExecutionStatistic(wf *wfv1.Workflow, namespace st
}
return nil
}
func workflowExecutionsSelectBuilderNoColumns(namespace, workflowTemplateUID, workflowTemplateVersion string) sq.SelectBuilder {
whereMap := sq.Eq{
"wt.namespace": namespace,
"wt.uid": workflowTemplateUID,
}
if workflowTemplateVersion != "" {
whereMap["wtv.version"] = workflowTemplateVersion
}
sb := sb.Select().
From("workflow_executions we").
LeftJoin("workflow_template_versions wtv ON wtv.id = we.workflow_template_version_id").
LeftJoin("workflow_templates wt ON wt.id = wtv.workflow_template_id").
Where(whereMap)
return sb
}
func workflowExecutionsSelectBuilder(namespace, workflowTemplateUID, workflowTemplateVersion string) sq.SelectBuilder {
sb := workflowExecutionsSelectBuilderNoColumns(namespace, workflowTemplateUID, workflowTemplateVersion)
sb = sb.Columns("we.id", "we.created_at", "we.uid", "we.name", "we.phase", "we.started_at", "we.finished_at", `wtv.version "workflow_template.version"`)
return sb
}

View File

@@ -4,6 +4,7 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/onepanelio/core/pkg/util/pagination"
"regexp"
"strconv"
"strings"
@@ -49,19 +50,31 @@ func (c *Client) createWorkflowTemplate(namespace string, workflowTemplate *Work
return nil, err
}
_, err = sb.Insert("workflow_template_versions").
workflowTemplateVersion := WorkflowTemplateVersion{}
err = sb.Insert("workflow_template_versions").
SetMap(sq.Eq{
"workflow_template_id": workflowTemplate.ID,
"version": versionUnix,
"is_latest": true,
"manifest": workflowTemplate.Manifest,
}).
Suffix("RETURNING id").
RunWith(tx).
Exec()
QueryRow().Scan(&workflowTemplateVersion.ID)
if err != nil {
return nil, err
}
if len(workflowTemplate.Labels) > 0 {
_, err = c.InsertLabelsBuilder(TypeWorkflowTemplateVersion, workflowTemplateVersion.ID, workflowTemplate.Labels).
RunWith(tx).
Exec()
if err != nil {
return nil, err
}
}
argoWft, err := createArgoWorkflowTemplate(workflowTemplate, versionUnix)
argoWft, err = c.ArgoprojV1alpha1().WorkflowTemplates(namespace).Create(argoWft)
if err != nil {
@@ -99,13 +112,58 @@ func (c *Client) workflowTemplatesVersionSelectBuilder(namespace string) sq.Sele
return sb
}
func (c *Client) GetWorkflowTemplateDb(namespace, name string) (workflowTemplate *WorkflowTemplate, err error) {
query, args, err := c.workflowTemplatesSelectBuilder(namespace).
Where(sq.Eq{
"name": name,
}).
ToSql()
if err != nil {
return nil, err
}
if err := c.DB.Get(workflowTemplate, query, args...); err != nil {
return nil, err
}
return
}
// "latest" will get you the latest version
func (c *Client) GetWorkflowTemplateVersionDb(namespace, name, version string) (workflowTemplateVersion *WorkflowTemplateVersion, err error) {
whereMap := sq.Eq{
"wt.name": name,
}
if version == "latest" {
whereMap["wtv.is_latest"] = "true"
} else {
whereMap["wtv.version"] = version
}
query, args, err := c.workflowTemplatesVersionSelectBuilder(namespace).
Where(whereMap).
ToSql()
if err != nil {
return nil, err
}
if err := c.DB.Get(workflowTemplateVersion, query, args...); err != nil {
return nil, err
}
return
}
func (c *Client) getWorkflowTemplate(namespace, uid string, version int64) (workflowTemplate *WorkflowTemplate, err error) {
workflowTemplate = &WorkflowTemplate{
WorkflowExecutionStatisticReport: &WorkflowExecutionStatisticReport{},
}
sb := c.workflowTemplatesSelectBuilder(namespace).
Column("wtv.manifest").
Columns("wtv.manifest", "wtv.id workflow_template_version_id").
Join("workflow_template_versions wtv ON wt.id = wtv.workflow_template_id").
Where(sq.Eq{"wt.uid": uid})
@@ -121,12 +179,7 @@ func (c *Client) getWorkflowTemplate(namespace, uid string, version int64) (work
}
if err = c.DB.Get(workflowTemplate, query, args...); err == sql.ErrNoRows {
err = nil
workflowTemplate = nil
}
if workflowTemplate == nil {
return workflowTemplate, nil
return nil, nil
}
versionAsString := "latest"
@@ -147,6 +200,13 @@ func (c *Client) getWorkflowTemplate(namespace, uid string, version int64) (work
workflowTemplate.Version = templateVersion
labelsMap, err := c.GetDbLabelsMapped(TypeWorkflowTemplateVersion, workflowTemplate.WorkflowTemplateVersionId)
if err != nil {
return workflowTemplate, err
}
workflowTemplate.Labels = labelsMap[workflowTemplate.WorkflowTemplateVersionId]
return workflowTemplate, nil
}
@@ -227,18 +287,20 @@ func (c *Client) listWorkflowTemplateVersions(namespace, uid string) (workflowTe
return
}
func (c *Client) listWorkflowTemplates(namespace string) (workflowTemplateVersions []*WorkflowTemplate, err error) {
func (c *Client) listWorkflowTemplates(namespace string, paginator *pagination.PaginationRequest) (workflowTemplateVersions []*WorkflowTemplate, err error) {
workflowTemplateVersions = []*WorkflowTemplate{}
query, args, err := c.workflowTemplatesSelectBuilder(namespace).
Column("COUNT(wtv.*) versions").
Options("DISTINCT ON (wt.id)").
sb := c.workflowTemplatesSelectBuilder(namespace).
Column("COUNT(wtv.*) versions, MAX(wtv.id) workflow_template_version_id").
Join("workflow_template_versions wtv ON wtv.workflow_template_id = wt.id").
GroupBy("wt.id", "wt.created_at", "wt.uid", "wt.name", "wt.is_archived").
Where(sq.Eq{
"wt.is_archived": false,
}).
OrderBy("wt.id desc").ToSql()
OrderBy("wt.created_at DESC")
sb = *paginator.ApplyToSelect(&sb)
query, args, err := sb.ToSql()
if err != nil {
return
}
@@ -248,6 +310,21 @@ func (c *Client) listWorkflowTemplates(namespace string) (workflowTemplateVersio
return
}
func (c *Client) CountWorkflowTemplates(namespace string) (count int, err error) {
err = sb.Select("COUNT( DISTINCT( wt.id ))").
From("workflow_templates wt").
Join("workflow_template_versions wtv ON wtv.workflow_template_id = wt.id").
Where(sq.Eq{
"wt.namespace": namespace,
"wt.is_archived": false,
}).
RunWith(c.DB.DB).
QueryRow().
Scan(&count)
return
}
func (c *Client) archiveWorkflowTemplate(namespace, uid string) (bool, error) {
query, args, err := sb.Update("workflow_templates").
Set("is_archived", true).
@@ -342,18 +419,28 @@ func (c *Client) CreateWorkflowTemplateVersion(namespace string, workflowTemplat
return nil, err
}
_, err = sb.Insert("workflow_template_versions").
workflowTemplateVersionId := uint64(0)
err = sb.Insert("workflow_template_versions").
SetMap(sq.Eq{
"workflow_template_id": workflowTemplateDb.ID,
"version": versionUnix,
"is_latest": true,
"manifest": workflowTemplate.Manifest,
}).
Suffix("RETURNING id").
RunWith(tx).
QueryRow().Scan(&workflowTemplateVersionId)
if err != nil {
return nil, err
}
_, err = c.InsertLabelsBuilder(TypeWorkflowTemplateVersion, workflowTemplateVersionId, workflowTemplate.Labels).
RunWith(tx).
Exec()
if err != nil {
return nil, err
}
if err := tx.Commit(); err != nil {
return nil, err
}
@@ -452,8 +539,8 @@ func (c *Client) ListWorkflowTemplateVersions(namespace, uid string) (workflowTe
return
}
func (c *Client) ListWorkflowTemplates(namespace string) (workflowTemplateVersions []*WorkflowTemplate, err error) {
workflowTemplateVersions, err = c.listWorkflowTemplates(namespace)
func (c *Client) ListWorkflowTemplates(namespace string, paginator *pagination.PaginationRequest) (workflowTemplateVersions []*WorkflowTemplate, err error) {
workflowTemplateVersions, err = c.listWorkflowTemplates(namespace, paginator)
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
@@ -470,17 +557,18 @@ func (c *Client) ListWorkflowTemplates(namespace string) (workflowTemplateVersio
}).Error("Unable to get Workflow Execution Statistic for Templates.")
return nil, util.NewUserError(codes.NotFound, "Unable to get Workflow Execution Statistic for Templates.")
}
for _, workflowTemplate := range workflowTemplateVersions {
labels, err := c.GetWorkflowTemplateLabels(namespace, workflowTemplate.UID, label.TagPrefix, workflowTemplate.Version)
labelsMap, err := c.GetDbLabelsMapped(TypeWorkflowTemplateVersion, WorkflowTemplatesToVersionIds(workflowTemplateVersions)...)
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Error": err.Error(),
}).Error("Unable to get GetWorkflowTemplateLabels for Templates.")
continue
}).Error("Unable to get Workflow Template Labels")
return nil, err
}
workflowTemplate.Labels = labels
for _, workflowTemplate := range workflowTemplateVersions {
workflowTemplate.Labels = labelsMap[workflowTemplate.WorkflowTemplateVersionId]
}
return

View File

@@ -5,10 +5,10 @@ import (
"github.com/golang/protobuf/ptypes/empty"
"github.com/onepanelio/core/api"
v1 "github.com/onepanelio/core/pkg"
"github.com/onepanelio/core/pkg/util/pagination"
"github.com/onepanelio/core/pkg/util/ptr"
"github.com/onepanelio/core/server/auth"
"github.com/onepanelio/core/server/converter"
"math"
)
type CronWorkflowServer struct{}
@@ -255,11 +255,8 @@ func (c *CronWorkflowServer) ListCronWorkflows(ctx context.Context, req *api.Lis
return nil, err
}
if req.PageSize <= 0 {
req.PageSize = 15
}
cronWorkflows, err := client.ListCronWorkflows(req.Namespace, req.WorkflowTemplateUid)
paginator := pagination.NewRequest(req.Page, req.PageSize)
cronWorkflows, err := client.ListCronWorkflows(req.Namespace, req.WorkflowTemplateUid, &paginator)
if err != nil {
return nil, err
}
@@ -268,27 +265,17 @@ func (c *CronWorkflowServer) ListCronWorkflows(ctx context.Context, req *api.Lis
apiCronWorkflows = append(apiCronWorkflows, apiCronWorkflow(cwf))
}
pages := int32(math.Ceil(float64(len(apiCronWorkflows)) / float64(req.PageSize)))
if req.Page > pages {
req.Page = pages
}
if req.Page <= 0 {
req.Page = 1
}
start := (req.Page - 1) * req.PageSize
end := start + req.PageSize
if end >= int32(len(apiCronWorkflows)) {
end = int32(len(apiCronWorkflows))
count, err := client.CountCronWorkflows(req.Namespace, req.WorkflowTemplateUid)
if err != nil {
return nil, err
}
return &api.ListCronWorkflowsResponse{
Count: end - start,
CronWorkflows: apiCronWorkflows[start:end],
Page: req.Page,
Pages: pages,
TotalCount: int32(len(apiCronWorkflows)),
Count: int32(len(apiCronWorkflows)),
CronWorkflows: apiCronWorkflows,
Page: int32(paginator.Page),
Pages: paginator.CalculatePages(count),
TotalCount: int32(count),
}, nil
}

View File

@@ -2,10 +2,12 @@ package server
import (
"context"
"github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/onepanelio/core/pkg/util"
"github.com/onepanelio/core/pkg/util/pagination"
"github.com/onepanelio/core/server/converter"
"google.golang.org/grpc/codes"
"math"
argov1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sort"
"strings"
"time"
@@ -36,10 +38,10 @@ func apiWorkflowExecution(wf *v1.WorkflowExecution) (workflow *api.WorkflowExecu
Manifest: wf.Manifest,
}
if !wf.StartedAt.IsZero() {
if wf.StartedAt != nil && !wf.StartedAt.IsZero() {
workflow.StartedAt = wf.StartedAt.Format(time.RFC3339)
}
if !wf.FinishedAt.IsZero() {
if wf.FinishedAt != nil && !wf.FinishedAt.IsZero() {
workflow.FinishedAt = wf.FinishedAt.Format(time.RFC3339)
}
@@ -81,19 +83,27 @@ func (s *WorkflowServer) CreateWorkflowExecution(ctx context.Context, req *api.C
func (s *WorkflowServer) AddWorkflowExecutionStatistics(ctx context.Context, request *api.AddWorkflowExecutionStatisticRequest) (*empty.Empty, error) {
client := ctx.Value("kubeClient").(*v1.Client)
workflowOutcomeIsSuccess := false
phase := v1alpha1.NodeFailed
if request.Statistics.WorkflowStatus == "Succeeded" {
workflowOutcomeIsSuccess = true
phase = v1alpha1.NodeSucceeded
}
err := client.FinishWorkflowExecutionStatisticViaExitHandler(request.Namespace, request.Name,
request.Statistics.WorkflowTemplateId, workflowOutcomeIsSuccess)
workflow, err := client.ArgoprojV1alpha1().Workflows(request.Namespace).Get(request.Name, argov1.GetOptions{})
if err != nil {
return &empty.Empty{}, err
}
err = client.FinishWorkflowExecutionStatisticViaExitHandler(request.Namespace, request.Name,
request.Statistics.WorkflowTemplateId, phase, workflow.Status.StartedAt.UTC())
if err != nil {
return &empty.Empty{}, err
}
return &empty.Empty{}, nil
}
// @todo we should not pass in an id into the request.
// instead pass in the cron workflow uid, we can load the cron workflow from db that way and get
// all required data.
func (s *WorkflowServer) CronStartWorkflowExecutionStatistic(ctx context.Context, request *api.CronStartWorkflowExecutionStatisticRequest) (*empty.Empty, error) {
client := ctx.Value("kubeClient").(*v1.Client)
err := client.CronStartWorkflowExecutionStatisticInsert(request.Namespace, request.Name, request.WorkflowTemplateId)
@@ -213,11 +223,8 @@ func (s *WorkflowServer) ListWorkflowExecutions(ctx context.Context, req *api.Li
return nil, err
}
if req.PageSize <= 0 {
req.PageSize = 15
}
workflows, err := client.ListWorkflowExecutions(req.Namespace, req.WorkflowTemplateUid, req.WorkflowTemplateVersion)
paginator := pagination.NewRequest(req.Page, req.PageSize)
workflows, err := client.ListWorkflowExecutions(req.Namespace, req.WorkflowTemplateUid, req.WorkflowTemplateVersion, &paginator)
if err != nil {
return nil, err
}
@@ -227,27 +234,17 @@ func (s *WorkflowServer) ListWorkflowExecutions(ctx context.Context, req *api.Li
apiWorkflowExecutions = append(apiWorkflowExecutions, apiWorkflowExecution(wf))
}
pages := int32(math.Ceil(float64(len(apiWorkflowExecutions)) / float64(req.PageSize)))
if req.Page > pages {
req.Page = pages
}
if req.Page <= 0 {
req.Page = 1
}
start := (req.Page - 1) * req.PageSize
end := start + req.PageSize
if end >= int32(len(apiWorkflowExecutions)) {
end = int32(len(apiWorkflowExecutions))
count, err := client.CountWorkflowExecutions(req.Namespace, req.WorkflowTemplateUid, req.WorkflowTemplateVersion)
if err != nil {
return nil, err
}
return &api.ListWorkflowExecutionsResponse{
Count: end - start,
WorkflowExecutions: apiWorkflowExecutions[start:end],
Page: req.Page,
Pages: pages,
TotalCount: int32(len(apiWorkflowExecutions)),
Count: int32(len(apiWorkflowExecutions)),
WorkflowExecutions: apiWorkflowExecutions,
Page: int32(paginator.Page),
Pages: paginator.CalculatePages(count),
TotalCount: int32(count),
}, nil
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/onepanelio/core/api"
v1 "github.com/onepanelio/core/pkg"
"github.com/onepanelio/core/pkg/util/label"
"github.com/onepanelio/core/pkg/util/pagination"
"github.com/onepanelio/core/server/auth"
"github.com/onepanelio/core/server/converter"
"strings"
@@ -208,7 +209,8 @@ func (s *WorkflowTemplateServer) ListWorkflowTemplates(ctx context.Context, req
return nil, err
}
workflowTemplates, err := client.ListWorkflowTemplates(req.Namespace)
paginator := pagination.NewRequest(req.Page, req.PageSize)
workflowTemplates, err := client.ListWorkflowTemplates(req.Namespace, &paginator)
if err != nil {
return nil, err
}
@@ -218,9 +220,17 @@ func (s *WorkflowTemplateServer) ListWorkflowTemplates(ctx context.Context, req
apiWorkflowTemplates = append(apiWorkflowTemplates, apiWorkflowTemplate(wtv))
}
count, err := client.CountWorkflowTemplates(req.Namespace)
if err != nil {
return nil, err
}
return &api.ListWorkflowTemplatesResponse{
Count: int32(len(apiWorkflowTemplates)),
WorkflowTemplates: apiWorkflowTemplates,
Page: int32(paginator.Page),
Pages: paginator.CalculatePages(count),
TotalCount: int32(count),
}, nil
}
@@ -276,7 +286,19 @@ func (s *WorkflowTemplateServer) AddWorkflowTemplateLabels(ctx context.Context,
keyValues[item.Key] = item.Value
}
labels, err := client.SetWorkflowTemplateLabels(req.Namespace, req.Name, "tags.onepanel.io/", keyValues, false)
labels, err := client.SetWorkflowTemplateLabels(req.Namespace, req.Name, label.TagPrefix, keyValues, false)
if err != nil {
return nil, err
}
workflowTemplateVersion, err := client.GetWorkflowTemplateVersionDb(req.Namespace, req.Name, "latest")
if err != nil {
return nil, err
}
_, err = client.InsertLabelsBuilder(v1.TypeWorkflowTemplateVersion, workflowTemplateVersion.ID, keyValues).
RunWith(client.DB.DB).
Exec()
if err != nil {
return nil, err
}