worker: adapt to new oapi-codegen
This commit is contained in:
parent
b2700903ae
commit
17416bf60b
4 changed files with 26 additions and 50 deletions
|
|
@ -130,11 +130,9 @@ func APIError(code ServiceErrorCode, serviceError *serviceError, c echo.Context)
|
|||
}
|
||||
|
||||
return &Error{
|
||||
ObjectReference: ObjectReference{
|
||||
Href: fmt.Sprintf("%s/errors/%d", BasePath, se.code),
|
||||
Id: fmt.Sprintf("%d", se.code),
|
||||
Kind: "Error",
|
||||
},
|
||||
Href: fmt.Sprintf("%s/errors/%d", BasePath, se.code),
|
||||
Id: fmt.Sprintf("%d", se.code),
|
||||
Kind: "Error",
|
||||
Code: fmt.Sprintf("%s%d", ErrorCodePrefix, se.code),
|
||||
OperationId: operationID, // set operation id from context
|
||||
Reason: se.reason,
|
||||
|
|
|
|||
|
|
@ -196,11 +196,7 @@ func (c *Client) registerWorker() error {
|
|||
return err
|
||||
}
|
||||
|
||||
workerID, err := uuid.Parse(wresp.WorkerId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.workerID = workerID
|
||||
c.workerID = wresp.WorkerId
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -955,11 +955,9 @@ func (h *apiHandlers) GetOpenapi(ctx echo.Context) error {
|
|||
|
||||
func (h *apiHandlers) GetStatus(ctx echo.Context) error {
|
||||
return ctx.JSON(http.StatusOK, &api.StatusResponse{
|
||||
ObjectReference: api.ObjectReference{
|
||||
Href: fmt.Sprintf("%s/status", api.BasePath),
|
||||
Id: "status",
|
||||
Kind: "Status",
|
||||
},
|
||||
Href: fmt.Sprintf("%s/status", api.BasePath),
|
||||
Id: "status",
|
||||
Kind: "Status",
|
||||
Status: "OK",
|
||||
})
|
||||
}
|
||||
|
|
@ -1030,11 +1028,9 @@ func (h *apiHandlers) RequestJob(ctx echo.Context) error {
|
|||
}
|
||||
|
||||
response := api.RequestJobResponse{
|
||||
ObjectReference: api.ObjectReference{
|
||||
Href: fmt.Sprintf("%s/jobs", api.BasePath),
|
||||
Id: jobId.String(),
|
||||
Kind: "RequestJob",
|
||||
},
|
||||
Href: fmt.Sprintf("%s/jobs", api.BasePath),
|
||||
Id: jobId.String(),
|
||||
Kind: "RequestJob",
|
||||
Location: fmt.Sprintf("%s/jobs/%v", api.BasePath, jobToken),
|
||||
ArtifactLocation: fmt.Sprintf("%s/jobs/%v/artifacts/", api.BasePath, jobToken),
|
||||
Type: jobType,
|
||||
|
|
@ -1062,11 +1058,9 @@ func (h *apiHandlers) GetJob(ctx echo.Context, tokenstr string) error {
|
|||
|
||||
if jobId == uuid.Nil {
|
||||
return ctx.JSON(http.StatusOK, api.GetJobResponse{
|
||||
ObjectReference: api.ObjectReference{
|
||||
Href: fmt.Sprintf("%s/jobs/%v", api.BasePath, token),
|
||||
Id: token.String(),
|
||||
Kind: "JobStatus",
|
||||
},
|
||||
Href: fmt.Sprintf("%s/jobs/%v", api.BasePath, token),
|
||||
Id: token.String(),
|
||||
Kind: "JobStatus",
|
||||
Canceled: false,
|
||||
})
|
||||
}
|
||||
|
|
@ -1079,11 +1073,9 @@ func (h *apiHandlers) GetJob(ctx echo.Context, tokenstr string) error {
|
|||
}
|
||||
|
||||
return ctx.JSON(http.StatusOK, api.GetJobResponse{
|
||||
ObjectReference: api.ObjectReference{
|
||||
Href: fmt.Sprintf("%s/jobs/%v", api.BasePath, token),
|
||||
Id: token.String(),
|
||||
Kind: "JobStatus",
|
||||
},
|
||||
Href: fmt.Sprintf("%s/jobs/%v", api.BasePath, token),
|
||||
Id: token.String(),
|
||||
Kind: "JobStatus",
|
||||
Canceled: jobInfo.JobStatus.Canceled,
|
||||
})
|
||||
}
|
||||
|
|
@ -1169,21 +1161,15 @@ func (h *apiHandlers) PostWorkers(ctx echo.Context) error {
|
|||
}
|
||||
|
||||
return ctx.JSON(http.StatusCreated, api.PostWorkersResponse{
|
||||
ObjectReference: api.ObjectReference{
|
||||
Href: fmt.Sprintf("%s/workers", api.BasePath),
|
||||
Id: workerID.String(),
|
||||
Kind: "WorkerID",
|
||||
},
|
||||
WorkerId: workerID.String(),
|
||||
Href: fmt.Sprintf("%s/workers", api.BasePath),
|
||||
Id: workerID.String(),
|
||||
Kind: "WorkerID",
|
||||
WorkerId: workerID,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *apiHandlers) PostWorkerStatus(ctx echo.Context, workerIdstr string) error {
|
||||
workerID, err := uuid.Parse(workerIdstr)
|
||||
if err != nil {
|
||||
return api.HTTPErrorWithInternal(api.ErrorMalformedWorkerId, err)
|
||||
}
|
||||
err = h.server.jobs.UpdateWorkerStatus(workerID)
|
||||
func (h *apiHandlers) PostWorkerStatus(ctx echo.Context, workerID uuid.UUID) error {
|
||||
err := h.server.jobs.UpdateWorkerStatus(workerID)
|
||||
|
||||
if err == jobqueue.ErrWorkerNotExist {
|
||||
return api.HTTPErrorWithInternal(api.ErrorWorkerIdNotFound, err)
|
||||
|
|
|
|||
|
|
@ -1499,12 +1499,10 @@ func TestWorkerWatch(t *testing.T) {
|
|||
reply := test.TestRouteWithReply(t, server.Handler(), false, "POST", "/api/worker/v1/workers", fmt.Sprintf(`{"arch":"%s"}`, arch.Current().String()), 201, `{"href":"/api/worker/v1/workers","kind":"WorkerID","id": "15"}`, "id", "worker_id")
|
||||
var resp api.PostWorkersResponse
|
||||
require.NoError(t, json.Unmarshal(reply, &resp))
|
||||
workerID, err := uuid.Parse(resp.WorkerId)
|
||||
require.NoError(t, err)
|
||||
|
||||
test.TestRoute(t, server.Handler(), false, "POST", fmt.Sprintf("/api/worker/v1/workers/%s/status", workerID), "{}", 200, "")
|
||||
test.TestRoute(t, server.Handler(), false, "POST", fmt.Sprintf("/api/worker/v1/workers/%s/status", resp.WorkerId), "{}", 200, "")
|
||||
time.Sleep(time.Millisecond * 400)
|
||||
test.TestRoute(t, server.Handler(), false, "POST", fmt.Sprintf("/api/worker/v1/workers/%s/status", workerID), "", 400,
|
||||
test.TestRoute(t, server.Handler(), false, "POST", fmt.Sprintf("/api/worker/v1/workers/%s/status", resp.WorkerId), "", 400,
|
||||
`{"href":"/api/worker/v1/errors/18","code":"IMAGE-BUILDER-WORKER-18","id":"18","kind":"Error","message":"Given worker id doesn't exist","reason":"Given worker id doesn't exist"}`,
|
||||
"operation_id")
|
||||
}
|
||||
|
|
@ -1514,9 +1512,7 @@ func TestRequestJobForWorker(t *testing.T) {
|
|||
reply := test.TestRouteWithReply(t, server.Handler(), false, "POST", "/api/worker/v1/workers", fmt.Sprintf(`{"arch":"%s"}`, arch.Current().String()), 201, `{"href":"/api/worker/v1/workers","kind":"WorkerID","id": "15"}`, "id", "worker_id")
|
||||
var resp api.PostWorkersResponse
|
||||
require.NoError(t, json.Unmarshal(reply, &resp))
|
||||
workerID, err := uuid.Parse(resp.WorkerId)
|
||||
require.NoError(t, err)
|
||||
test.TestRoute(t, server.Handler(), false, "POST", fmt.Sprintf("/api/worker/v1/workers/%s/status", workerID), "{}", 200, "")
|
||||
test.TestRoute(t, server.Handler(), false, "POST", fmt.Sprintf("/api/worker/v1/workers/%s/status", resp.WorkerId), "{}", 200, "")
|
||||
|
||||
distroStruct := newTestDistro(t)
|
||||
arch, err := distroStruct.GetArch(test_distro.TestArchName)
|
||||
|
|
@ -1539,7 +1535,7 @@ func TestRequestJobForWorker(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Can request a job with worker ID
|
||||
j, _, typ, args, dynamicArgs, err := server.RequestJob(context.Background(), arch.Name(), []string{worker.JobTypeOSBuild}, []string{""}, workerID)
|
||||
j, _, typ, args, dynamicArgs, err := server.RequestJob(context.Background(), arch.Name(), []string{worker.JobTypeOSBuild}, []string{""}, resp.WorkerId)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, jobId, j)
|
||||
require.Equal(t, worker.JobTypeOSBuild, typ)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue