cloudapi: Move most of getComposeStatusImpl into a function
This will make it easier to use the status in responses. Related: RHEL-60120
This commit is contained in:
parent
b2d803306c
commit
24b939d4c7
1 changed files with 24 additions and 14 deletions
|
|
@ -305,21 +305,31 @@ func (h *apiHandlers) getComposeStatusImpl(ctx echo.Context, id string) error {
|
|||
return HTTPError(ErrorInvalidComposeId)
|
||||
}
|
||||
|
||||
response, err := h.getJobIDComposeStatus(jobId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
// getJobIDComposeStatus returns the ComposeStatus for the job
|
||||
// or an HTTPError
|
||||
func (h *apiHandlers) getJobIDComposeStatus(jobId uuid.UUID) (ComposeStatus, error) {
|
||||
jobType, err := h.server.workers.JobType(jobId)
|
||||
if err != nil {
|
||||
return HTTPError(ErrorComposeNotFound)
|
||||
return ComposeStatus{}, HTTPError(ErrorComposeNotFound)
|
||||
}
|
||||
|
||||
if jobType == worker.JobTypeOSBuild {
|
||||
var result worker.OSBuildJobResult
|
||||
jobInfo, err := h.server.workers.OSBuildJobInfo(jobId, &result)
|
||||
if err != nil {
|
||||
return HTTPError(ErrorMalformedOSBuildJobResult)
|
||||
return ComposeStatus{}, HTTPError(ErrorMalformedOSBuildJobResult)
|
||||
}
|
||||
|
||||
jobError, err := h.server.workers.JobDependencyChainErrors(jobId)
|
||||
if err != nil {
|
||||
return HTTPError(ErrorGettingBuildDependencyStatus)
|
||||
return ComposeStatus{}, HTTPError(ErrorGettingBuildDependencyStatus)
|
||||
}
|
||||
|
||||
var uploadStatuses *[]UploadStatus
|
||||
|
|
@ -330,7 +340,7 @@ func (h *apiHandlers) getComposeStatusImpl(ctx echo.Context, id string) error {
|
|||
tr := result.TargetResults[idx]
|
||||
us, err := h.targetResultToUploadStatus(jobId, tr)
|
||||
if err != nil {
|
||||
return HTTPError(ErrorUnknownUploadTarget)
|
||||
return ComposeStatus{}, HTTPError(ErrorUnknownUploadTarget)
|
||||
}
|
||||
us.Status = uploadStatusFromJobStatus(jobInfo.JobStatus, result.JobError)
|
||||
statuses[idx] = *us
|
||||
|
|
@ -344,7 +354,7 @@ func (h *apiHandlers) getComposeStatusImpl(ctx echo.Context, id string) error {
|
|||
}
|
||||
}
|
||||
|
||||
return ctx.JSON(http.StatusOK, ComposeStatus{
|
||||
return ComposeStatus{
|
||||
ObjectReference: ObjectReference{
|
||||
Href: fmt.Sprintf("/api/image-builder-composer/v2/composes/%v", jobId),
|
||||
Id: jobId.String(),
|
||||
|
|
@ -357,20 +367,20 @@ func (h *apiHandlers) getComposeStatusImpl(ctx echo.Context, id string) error {
|
|||
UploadStatus: us0, // add the first upload status to the old top-level field
|
||||
UploadStatuses: uploadStatuses,
|
||||
},
|
||||
})
|
||||
}, nil
|
||||
} else if jobType == worker.JobTypeKojiFinalize {
|
||||
var result worker.KojiFinalizeJobResult
|
||||
finalizeInfo, err := h.server.workers.KojiFinalizeJobInfo(jobId, &result)
|
||||
if err != nil {
|
||||
return HTTPError(ErrorMalformedOSBuildJobResult)
|
||||
return ComposeStatus{}, HTTPError(ErrorMalformedOSBuildJobResult)
|
||||
}
|
||||
if len(finalizeInfo.Deps) < 2 {
|
||||
return HTTPError(ErrorUnexpectedNumberOfImageBuilds)
|
||||
return ComposeStatus{}, HTTPError(ErrorUnexpectedNumberOfImageBuilds)
|
||||
}
|
||||
var initResult worker.KojiInitJobResult
|
||||
_, err = h.server.workers.KojiInitJobInfo(finalizeInfo.Deps[0], &initResult)
|
||||
if err != nil {
|
||||
return HTTPError(ErrorMalformedOSBuildJobResult)
|
||||
return ComposeStatus{}, HTTPError(ErrorMalformedOSBuildJobResult)
|
||||
}
|
||||
var buildJobResults []worker.OSBuildJobResult
|
||||
var buildJobStatuses []ImageStatus
|
||||
|
|
@ -378,11 +388,11 @@ func (h *apiHandlers) getComposeStatusImpl(ctx echo.Context, id string) error {
|
|||
var buildJobResult worker.OSBuildJobResult
|
||||
buildInfo, err := h.server.workers.OSBuildJobInfo(finalizeInfo.Deps[i], &buildJobResult)
|
||||
if err != nil {
|
||||
return HTTPError(ErrorMalformedOSBuildJobResult)
|
||||
return ComposeStatus{}, HTTPError(ErrorMalformedOSBuildJobResult)
|
||||
}
|
||||
buildJobError, err := h.server.workers.JobDependencyChainErrors(finalizeInfo.Deps[i])
|
||||
if err != nil {
|
||||
return HTTPError(ErrorGettingBuildDependencyStatus)
|
||||
return ComposeStatus{}, HTTPError(ErrorGettingBuildDependencyStatus)
|
||||
}
|
||||
|
||||
var uploadStatuses *[]UploadStatus
|
||||
|
|
@ -395,7 +405,7 @@ func (h *apiHandlers) getComposeStatusImpl(ctx echo.Context, id string) error {
|
|||
if tr.Name != target.TargetNameKoji {
|
||||
us, err := h.targetResultToUploadStatus(jobId, tr)
|
||||
if err != nil {
|
||||
return HTTPError(ErrorUnknownUploadTarget)
|
||||
return ComposeStatus{}, HTTPError(ErrorUnknownUploadTarget)
|
||||
}
|
||||
us.Status = uploadStatusFromJobStatus(buildInfo.JobStatus, result.JobError)
|
||||
statuses = append(statuses, *us)
|
||||
|
|
@ -433,9 +443,9 @@ func (h *apiHandlers) getComposeStatusImpl(ctx echo.Context, id string) error {
|
|||
if buildID != 0 {
|
||||
response.KojiStatus.BuildId = &buildID
|
||||
}
|
||||
return ctx.JSON(http.StatusOK, response)
|
||||
return response, nil
|
||||
} else {
|
||||
return HTTPError(ErrorInvalidJobType)
|
||||
return ComposeStatus{}, HTTPError(ErrorInvalidJobType)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue