Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(engine): hatchery as a uservice - auth #3326

Merged
merged 43 commits into from
Sep 20, 2018
Merged

Conversation

yesnault
Copy link
Member

@yesnault yesnault commented Sep 14, 2018

close #3315 (with 5f461f6 too)

Signed-off-by: Yvonnick Esnault yvonnick.esnault@corp.ovh.com

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
@yesnault
Copy link
Member Author

WIP do not merge yet

@yesnault yesnault changed the title feat(engine): add type, model type and ratio in hatchery table WIP feat(engine): add type, model type and ratio in hatchery table Sep 14, 2018
@@ -34,37 +32,35 @@ func (api *API) registerHatcheryHandler() service.Handler {
return sdk.WrapError(err, "registerHatcheryHandler> Cannot load hatchery %s", hatch.Name)
}

tx, errBegin := api.mustDB().Begin()
defer tx.Rollback()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return value of tx.Rollback is not checked

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
@ovh ovh deleted a comment from ovh-cds Sep 15, 2018
@ovh ovh deleted a comment from ovh-cds Sep 15, 2018
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
@yesnault yesnault changed the title WIP feat(engine): add type, model type and ratio in hatchery table feat(engine): add type, model type and ratio in hatchery table Sep 16, 2018
@ovh-cds
Copy link
Collaborator

ovh-cds commented Sep 16, 2018

CDS Report ut-engine#5975.1 ✘

  • Stage 1
    • Engine Test with DB ✘

if hatchery.RatioService == 100 {
where = " AND contains_service = true "
} else if hatchery.RatioService == 0 {
where = " AND (contains_service is NULL or contains_service = false) "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains_service is NULL . is mandatory ???

@@ -89,6 +89,7 @@ type JobRun struct {
ExecGroups sql.NullString `db:"exec_groups"`
PlatformPluginBinaries sql.NullString `db:"platform_plugin_binaries"`
BookedBy sdk.Hatchery `db:"-"`
ContainsService sql.NullBool `db:"contains_service"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sql.Bool ? ( is false is applied on old lines)


ALTER TABLE hatchery
ADD COLUMN worker_model_id BIGINT,
ADD COLUMN model_type VARCHAR(50) DEFAULT '',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used

-- +migrate Up

ALTER TABLE hatchery
ADD COLUMN worker_model_id BIGINT,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove worker_model_id, localhatchery must check requirement from its path

var errg error
h.UID, errg = generateID()
hatchery.UID, errg = generateID()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not using sdk.UUID() ?

)

// Hatchery is a gorp wrapper around sdk.Hatchery
type Hatchery sdk.Hatchery
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this type should be private

Cmd: "worker --api={{.API}} --token={{.Token}} --basedir={{.BaseDir}} --model={{.Model}} --name={{.Name}} --hatchery={{.Hatchery}} --hatchery-name={{.HatcheryName}} --insecure={{.HTTPInsecure}} --booked-workflow-job-id={{.WorkflowJobID}} --booked-pb-job-id={{.PipelineBuildJobID}} --single-use --force-exit",
}
if err := worker.InsertWorkerModel(db, &hatchery.Model); err != nil && strings.Contains(err.Error(), "idx_worker_model_name") {
return sdk.ErrModelNameExist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be we should update the model and not raise an error

}
return nil, err
return nil, sdk.ErrNotFound
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really ?


var h sdk.Hatchery
var wmID sql.NullInt64
var hatchery Hatchery
hasher := sha512.New()
hashed := base64.StdEncoding.EncodeToString(hasher.Sum([]byte(token)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


return nil
}

func generateID() (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this, sdk.UUID exists

}
if svcs[i].Type == "hatchery" {
log.Info("killDeadServices> Delete dead hatchery: %v", &svcs[i].Name)
if err := hatchery.DeleteHatcheryByName(db, svcs[i].Name); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't have to delete manually the hatchery when we remove the service. There should be a foreign key and a delete cascade

}
case <-ctx.Done():
if err := ctx.Err(); err != nil {
log.Error("Exiting killDeadServices: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return ?

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
@ovh ovh deleted a comment from ovh-cds Sep 17, 2018
@ovh ovh deleted a comment from ovh-cds Sep 17, 2018
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
@yesnault yesnault changed the title feat(engine): add type, model type and ratio in hatchery table WIP feat(engine): add type, model type and ratio in hatchery table Sep 17, 2018
@ovh ovh deleted a comment from ovh-cds Sep 18, 2018
@ovh ovh deleted a comment from ovh-cds Sep 18, 2018
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
@@ -248,7 +246,6 @@ func (api *API) InitRouter() {
r.Handle("/project/{permProjectKey}/push/workflows", r.POST(api.postWorkflowPushHandler))

// Workflows run
r.Handle("/project/{permProjectKey}/runs", r.GET(api.getWorkflowAllRunsHandler, EnableTracing()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not delete this

WHERE (
hatchery.group_id = ANY(
services.type = 'hatchery'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the sdk constant

WHERE (
hatchery.group_id = ANY(
services.type = 'hatchery'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

}

if _, err := workflow.LoadNodeJobRunQueue(ctx, api.mustDB(), api.Cache, permissions, groupsID, usr, nil, nil, nil); err != nil {
if _, err := workflow.LoadNodeJobRunQueue(ctx, api.mustDB(), api.Cache, "", nil, permissions, groupsID, usr, nil, nil, nil); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too mush optional parameters
we need more specialized function of an option struct

@@ -136,18 +136,6 @@ func (api *API) searchWorkflowRun(ctx context.Context, w http.ResponseWriter, r
return service.WriteJSON(w, runs, code)
}

func (api *API) getWorkflowAllRunsHandler() service.Handler {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope

@@ -60,14 +60,29 @@ func LoadNodeJobRunQueue(ctx context.Context, db gorp.SqlExecutor, store cache.S
statuses = []string{sdk.StatusWaiting.String()}
}

var where string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sql query is unreadable :(
how can we improve this code ?

@@ -753,7 +754,15 @@ func getSinceUntilLimitHeader(ctx context.Context, w http.ResponseWriter, r *htt
limit, _ = strconv.Atoi(limitHeader)
}

return since, until, limit
ratioServiceHeader := r.Header.Get("X-CDS-Ratio-Service")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why header and not queryParam ?

@@ -702,7 +702,7 @@ func (api *API) countWorkflowJobQueueHandler() service.Handler {

func (api *API) getWorkflowJobQueueHandler() service.Handler {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
since, until, limit := getSinceUntilLimitHeader(ctx, w, r)
since, until, limit, modelType, ratioService := getQueueHeaders(ctx, w, r)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any tests on this new options

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests added

}
}

for _, r := range tmp {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare capa here with a good length or capacity :)

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
@ovh-cds

This comment has been minimized.

@ovh-cds

This comment has been minimized.

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
@ovh-cds

This comment has been minimized.

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
@ovh-cds
Copy link
Collaborator

ovh-cds commented Sep 20, 2018

CDS Report build-engine-cli-tools#6067.0 ✘

  • Build minimal
    • cds cli legacy ✔
    • cdsctl linux ✘
    • Engine Build linux amd64 ✔
    • tools/debpacker ✔
    • tools/os-ansible-inventory ✔
    • Worker linux amd64 / 386 ✔

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
"github.com/stretchr/testify/assert"

"github.com/ovh/cds/engine/api/services"
"github.com/ovh/cds/engine/api/sessionstore"
"github.com/ovh/cds/sdk/namesgenerator"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix(hatchery): take job from queue full
7 participants