Skip to content

Commit

Permalink
refactor(api): remove old workflow structure (#4296)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Jun 17, 2019
1 parent 974762d commit 6977b79
Show file tree
Hide file tree
Showing 82 changed files with 1,309 additions and 4,473 deletions.
4 changes: 0 additions & 4 deletions engine/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,6 @@ func (a *API) Serve(ctx context.Context) error {
sdk.GoRoutine(ctx, "migrate.KeyMigration", func(ctx context.Context) {
migrate.KeyMigration(a.Cache, a.DBConnectionFactory.GetDBMap, &sdk.User{Admin: true})
}, a.PanicDump())

migrate.Add(sdk.Migration{Name: "WorkflowOldStruct", Release: "0.38.1", Mandatory: true, ExecFunc: func(ctx context.Context) error {
return migrate.WorkflowRunOldModel(ctx, a.DBConnectionFactory.GetDBMap)
}})
migrate.Add(sdk.Migration{Name: "WorkflowNotification", Release: "0.38.1", Mandatory: true, ExecFunc: func(ctx context.Context) error {
return migrate.WorkflowNotifications(a.Cache, a.DBConnectionFactory.GetDBMap)
}})
Expand Down
6 changes: 3 additions & 3 deletions engine/api/application/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ func LoadByWorkflowID(db gorp.SqlExecutor, workflowID int64) ([]sdk.Application,
apps := []sdk.Application{}
query := fmt.Sprintf(`SELECT DISTINCT %s
FROM application
JOIN workflow_node_context ON workflow_node_context.application_id = application.id
JOIN workflow_node ON workflow_node.id = workflow_node_context.workflow_node_id
JOIN workflow ON workflow.id = workflow_node.workflow_id
JOIN w_node_context ON w_node_context.application_id = application.id
JOIN w_node ON w_node.id = w_node_context.node_id
JOIN workflow ON workflow.id = w_node.workflow_id
WHERE workflow.id = $1`, appRows)

if _, err := db.Select(&apps, query, workflowID); err != nil {
Expand Down
1 change: 0 additions & 1 deletion engine/api/application/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func TestLoadByWorkflowID(t *testing.T) {
}

test.NoError(t, workflow.RenameNode(db, &w))
(&w).RetroMigrate()

proj, _ = project.LoadByID(db, cache, proj.ID, u, project.LoadOptions.WithApplications, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, project.LoadOptions.WithGroups)

Expand Down
2 changes: 1 addition & 1 deletion engine/api/ascode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func Test_postPerformImportAsCodeHandler(t *testing.T) {
t.Logf("RequestURI: %s", r.URL.Path)
switch r.URL.Path {
case "/task/bulk":
hooks := map[string]sdk.WorkflowNodeHook{}
hooks := map[string]sdk.NodeHook{}
if err := service.UnmarshalBody(r, &hooks); err != nil {
return nil, sdk.WithStack(err)
}
Expand Down
6 changes: 3 additions & 3 deletions engine/api/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ func LoadEnvironmentByName(db gorp.SqlExecutor, projectKey, envName string) (*sd
func LoadByWorkflowID(db gorp.SqlExecutor, workflowID int64) ([]sdk.Environment, error) {
envs := []sdk.Environment{}
query := `SELECT DISTINCT environment.* FROM environment
JOIN workflow_node_context ON workflow_node_context.environment_id = environment.id
JOIN workflow_node ON workflow_node.id = workflow_node_context.workflow_node_id
JOIN workflow ON workflow.id = workflow_node.workflow_id
JOIN w_node_context ON w_node_context.environment_id = environment.id
JOIN w_node ON w_node.id = w_node_context.node_id
JOIN workflow ON workflow.id = w_node.workflow_id
WHERE workflow.id = $1`

if _, err := db.Select(&envs, query, workflowID); err != nil {
Expand Down
45 changes: 17 additions & 28 deletions engine/api/event/publish_workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,36 +84,25 @@ func PublishWorkflowNodeRun(db gorp.SqlExecutor, nr sdk.WorkflowNodeRun, w sdk.W
var nodeName string
var app sdk.Application
var env sdk.Environment
n := w.GetNode(nr.WorkflowNodeID)
if n == nil {
// check on workflow data
wnode := w.WorkflowData.NodeByID(nr.WorkflowNodeID)
if wnode == nil {
log.Warning("PublishWorkflowNodeRun> Unable to publish event on node %d", nr.WorkflowNodeID)
return
}
nodeName = wnode.Name
if wnode.Context != nil && wnode.Context.PipelineID != 0 {
pipName = w.Pipelines[wnode.Context.PipelineID].Name
}

if wnode.Context != nil && wnode.Context.ApplicationID != 0 {
app = w.Applications[wnode.Context.ApplicationID]
}
if wnode.Context != nil && wnode.Context.EnvironmentID != 0 {
env = w.Environments[wnode.Context.EnvironmentID]
}
e.NodeType = wnode.Type
} else {
nodeName = n.Name
pipName = w.Pipelines[n.PipelineID].Name
if n.Context != nil && n.Context.Application != nil {
app = *n.Context.Application
}
if n.Context != nil && n.Context.Environment != nil {
env = *n.Context.Environment
}
// check on workflow data
wnode := w.WorkflowData.NodeByID(nr.WorkflowNodeID)
if wnode == nil {
log.Warning("PublishWorkflowNodeRun> Unable to publish event on node %d", nr.WorkflowNodeID)
return
}
nodeName = wnode.Name
if wnode.Context != nil && wnode.Context.PipelineID != 0 {
pipName = w.Pipelines[wnode.Context.PipelineID].Name
}

if wnode.Context != nil && wnode.Context.ApplicationID != 0 {
app = w.Applications[wnode.Context.ApplicationID]
}
if wnode.Context != nil && wnode.Context.EnvironmentID != 0 {
env = w.Environments[wnode.Context.EnvironmentID]
}
e.NodeType = wnode.Type

// Try to get gerrit variable
var project, changeID, branch, revision, url string
Expand Down
11 changes: 4 additions & 7 deletions engine/api/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (api *API) getHookPollingVCSEvents() service.Handler {
lastExec := time.Now()
workflowID, errV := requestVarInt(r, "workflowID")
if errV != nil {
return sdk.WrapError(sdk.ErrWrongRequest, "getHookPollingVCSEvents> cannot convert workflowID to int %s", errV)
return errV
}

if r.Header.Get("X-CDS-Last-Execution") != "" {
Expand All @@ -36,22 +36,19 @@ func (api *API) getHookPollingVCSEvents() service.Handler {

h, errL := workflow.LoadHookByUUID(api.mustDB(), uuid)
if errL != nil {
return sdk.WrapError(errL, "getHookPollingVCSEvents> cannot load hook")
}
if h == nil {
return sdk.ErrNotFound
return errL
}

proj, errProj := project.Load(api.mustDB(), api.Cache, h.Config[sdk.HookConfigProject].Value, nil)
if errProj != nil {
return sdk.WrapError(errProj, "getHookPollingVCSEvents> cannot load project")
return errProj
}

//get the client for the repositories manager
vcsServer := repositoriesmanager.GetProjectVCSServer(proj, vcsServerParam)
client, errR := repositoriesmanager.AuthorizedClient(ctx, api.mustDB(), api.Cache, proj.Key, vcsServer)
if errR != nil {
return sdk.WrapError(errR, "getHookPollingVCSEvents> Unable to get client for %s %s", proj.Key, vcsServerParam)
return errR
}

//Check if the polling if disabled
Expand Down
6 changes: 3 additions & 3 deletions engine/api/migrate/gitclone_key_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ func migrateActionGitClonePipeline(db gorp.SqlExecutor, store cache.Store, p pip
if err != nil {
return err
}
node := w.GetNodeByName(p.WorkflowNodeName)
node := w.WorkflowData.NodeByName(p.WorkflowNodeName)
if node == nil {
return sdk.ErrWorkflowNodeNotFound
}
if node.Context != nil && node.Context.Application != nil {
p.AppName = node.Context.Application.Name
if node.Context != nil && node.Context.ApplicationID != 0 {
p.AppName = w.Applications[node.Context.ApplicationID].Name
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/api/migrate/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// MinCompatibleRelease represent the minimum release which is working with these migrations, need to update when we delete migration in our codebase
const MinCompatibleRelease = "0.38.1"
const MinCompatibleRelease = "0.39.3"

var migrations = []sdk.Migration{}

Expand Down
62 changes: 0 additions & 62 deletions engine/api/migrate/workflow_run_old_model.go

This file was deleted.

5 changes: 3 additions & 2 deletions engine/api/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ func LoadByWorkflowID(db gorp.SqlExecutor, workflowID int64) ([]sdk.Pipeline, er
pips := []Pipeline{}
query := `SELECT DISTINCT pipeline.*
FROM pipeline
JOIN workflow_node ON pipeline.id = workflow_node.pipeline_id
JOIN workflow ON workflow_node.workflow_id = workflow.id
JOIN w_node_context ON pipeline.id = w_node_context.pipeline_id
JOIN w_node ON w_node.id = w_node_context.node_id
JOIN workflow ON w_node.workflow_id = workflow.id
WHERE workflow.id = $1`

if _, err := db.Select(&pips, query, workflowID); err != nil {
Expand Down
1 change: 0 additions & 1 deletion engine/api/pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func TestLoadByWorkflowID(t *testing.T) {
}

test.NoError(t, workflow.RenameNode(db, &w))
(&w).RetroMigrate()

proj, _ = project.LoadByID(db, cache, proj.ID, u, project.LoadOptions.WithApplications, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, project.LoadOptions.WithGroups)

Expand Down
3 changes: 1 addition & 2 deletions engine/api/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ func (api *API) getProjectsHandler() service.Handler {
return err
}

wapps := w.GetApplications()
//Checks the workflow use one of the applications
wapps:
for _, a := range wapps {
for _, a := range w.Applications {
for _, b := range apps {
if a.Name == b.Name {
ws = append(ws, p.Workflows[i])
Expand Down
2 changes: 0 additions & 2 deletions engine/api/project_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func Test_ProjectPerms(t *testing.T) {
ProjectKey: proj.Key,
}

(&newWf).RetroMigrate()

//Prepare request
vars := map[string]string{
"permProjectKey": proj.Key,
Expand Down
Loading

0 comments on commit 6977b79

Please sign in to comment.