store: drop support for multi-image composes
The store only serves the weldr API, and that hard-codes the assumption of only one image build per compose all over the place. Move this assumption into the json serialization handler. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
e28fca493c
commit
fba2af5f51
7 changed files with 141 additions and 168 deletions
|
|
@ -146,17 +146,13 @@ func (api *API) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
|||
// queued, started, and finished. Assumes that there's only one image in the
|
||||
// compose. Returns CWaiting on error.
|
||||
func (api *API) getComposeState(compose store.Compose) (state common.ComposeState, queued, started, finished time.Time) {
|
||||
if len(compose.ImageBuilds) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
jobId := compose.ImageBuilds[0].JobID
|
||||
jobId := compose.ImageBuild.JobID
|
||||
|
||||
// backwards compatibility: composes that were around before splitting
|
||||
// the job queue from the store still contain their valid status and
|
||||
// times. Return those here as a fallback.
|
||||
if jobId == uuid.Nil {
|
||||
switch compose.ImageBuilds[0].QueueStatus {
|
||||
switch compose.ImageBuild.QueueStatus {
|
||||
case common.IBWaiting:
|
||||
state = common.CWaiting
|
||||
case common.IBRunning:
|
||||
|
|
@ -166,9 +162,9 @@ func (api *API) getComposeState(compose store.Compose) (state common.ComposeStat
|
|||
case common.IBFailed:
|
||||
state = common.CFailed
|
||||
}
|
||||
queued = compose.ImageBuilds[0].JobCreated
|
||||
started = compose.ImageBuilds[0].JobStarted
|
||||
finished = compose.ImageBuilds[0].JobFinished
|
||||
queued = compose.ImageBuild.JobCreated
|
||||
started = compose.ImageBuild.JobStarted
|
||||
finished = compose.ImageBuild.JobFinished
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1813,7 +1809,7 @@ func (api *API) composeStatusHandler(writer http.ResponseWriter, request *http.R
|
|||
continue
|
||||
} else if filterStatus != "" && state.ToString() != filterStatus {
|
||||
continue
|
||||
} else if filterImageType != "" && compose.ImageBuilds[0].ImageType.Name() != filterImageType {
|
||||
} else if filterImageType != "" && compose.ImageBuild.ImageType.Name() != filterImageType {
|
||||
continue
|
||||
}
|
||||
filteredUUIDs = append(filteredUUIDs, id)
|
||||
|
|
@ -1884,12 +1880,12 @@ func (api *API) composeInfoHandler(writer http.ResponseWriter, request *http.Req
|
|||
// Weldr API assumes only one image build per compose, that's why only the
|
||||
// 1st build is considered
|
||||
state, _, _, _ := api.getComposeState(compose)
|
||||
reply.ComposeType = compose.ImageBuilds[0].ImageType.Name()
|
||||
reply.ComposeType = compose.ImageBuild.ImageType.Name()
|
||||
reply.QueueStatus = state.ToString()
|
||||
reply.ImageSize = compose.ImageBuilds[0].Size
|
||||
reply.ImageSize = compose.ImageBuild.Size
|
||||
|
||||
if isRequestVersionAtLeast(params, 1) {
|
||||
reply.Uploads = targetsToUploadResponses(compose.ImageBuilds[0].Targets)
|
||||
reply.Uploads = targetsToUploadResponses(compose.ImageBuild.Targets)
|
||||
}
|
||||
|
||||
err = json.NewEncoder(writer).Encode(reply)
|
||||
|
|
@ -1932,10 +1928,10 @@ func (api *API) composeImageHandler(writer http.ResponseWriter, request *http.Re
|
|||
return
|
||||
}
|
||||
|
||||
imageName := compose.ImageBuilds[0].ImageType.Filename()
|
||||
imageMime := compose.ImageBuilds[0].ImageType.MIMEType()
|
||||
imageName := compose.ImageBuild.ImageType.Filename()
|
||||
imageMime := compose.ImageBuild.ImageType.MIMEType()
|
||||
|
||||
reader, fileSize, err := api.store.GetImageBuildImage(uuid, 0)
|
||||
reader, fileSize, err := api.store.GetImageBuildImage(uuid)
|
||||
|
||||
// TODO: this might return misleading error
|
||||
if err != nil {
|
||||
|
|
@ -1991,7 +1987,7 @@ func (api *API) composeLogsHandler(writer http.ResponseWriter, request *http.Req
|
|||
return
|
||||
}
|
||||
|
||||
resultReader, err := api.store.GetImageBuildResult(id, 0)
|
||||
resultReader, err := api.store.GetImageBuildResult(id)
|
||||
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
|
|
@ -2084,7 +2080,7 @@ func (api *API) composeLogHandler(writer http.ResponseWriter, request *http.Requ
|
|||
return
|
||||
}
|
||||
|
||||
resultReader, err := api.store.GetImageBuildResult(id, 0)
|
||||
resultReader, err := api.store.GetImageBuildResult(id)
|
||||
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
|
|
|
|||
|
|
@ -446,17 +446,15 @@ func TestCompose(t *testing.T) {
|
|||
Groups: []blueprint.Group{},
|
||||
Customizations: nil,
|
||||
},
|
||||
ImageBuilds: []store.ImageBuild{
|
||||
{
|
||||
QueueStatus: common.IBWaiting,
|
||||
ImageType: imgType,
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
// skip Uuid and Created fields - they are ignored
|
||||
Name: "org.osbuild.local",
|
||||
Options: &target.LocalTargetOptions{
|
||||
Filename: "test.img",
|
||||
},
|
||||
ImageBuild: store.ImageBuild{
|
||||
QueueStatus: common.IBWaiting,
|
||||
ImageType: imgType,
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
// skip Uuid and Created fields - they are ignored
|
||||
Name: "org.osbuild.local",
|
||||
Options: &target.LocalTargetOptions{
|
||||
Filename: "test.img",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -471,30 +469,28 @@ func TestCompose(t *testing.T) {
|
|||
Groups: []blueprint.Group{},
|
||||
Customizations: nil,
|
||||
},
|
||||
ImageBuilds: []store.ImageBuild{
|
||||
{
|
||||
QueueStatus: common.IBWaiting,
|
||||
ImageType: imgType,
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
Name: "org.osbuild.aws",
|
||||
Status: common.IBWaiting,
|
||||
ImageName: "test_upload",
|
||||
Options: &target.AWSTargetOptions{
|
||||
Filename: "test.img",
|
||||
Region: "frankfurt",
|
||||
AccessKeyID: "accesskey",
|
||||
SecretAccessKey: "secretkey",
|
||||
Bucket: "clay",
|
||||
Key: "imagekey",
|
||||
},
|
||||
ImageBuild: store.ImageBuild{
|
||||
QueueStatus: common.IBWaiting,
|
||||
ImageType: imgType,
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
Name: "org.osbuild.aws",
|
||||
Status: common.IBWaiting,
|
||||
ImageName: "test_upload",
|
||||
Options: &target.AWSTargetOptions{
|
||||
Filename: "test.img",
|
||||
Region: "frankfurt",
|
||||
AccessKeyID: "accesskey",
|
||||
SecretAccessKey: "secretkey",
|
||||
Bucket: "clay",
|
||||
Key: "imagekey",
|
||||
},
|
||||
{
|
||||
// skip Uuid and Created fields - they are ignored
|
||||
Name: "org.osbuild.local",
|
||||
Options: &target.LocalTargetOptions{
|
||||
Filename: "test.img",
|
||||
},
|
||||
},
|
||||
{
|
||||
// skip Uuid and Created fields - they are ignored
|
||||
Name: "org.osbuild.local",
|
||||
Options: &target.LocalTargetOptions{
|
||||
Filename: "test.img",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -535,9 +531,9 @@ func TestCompose(t *testing.T) {
|
|||
break
|
||||
}
|
||||
|
||||
require.NotNilf(t, composeStruct.ImageBuilds[0].Manifest, "%s: the compose in the store did not contain a blueprint", c.Path)
|
||||
require.NotNilf(t, composeStruct.ImageBuild.Manifest, "%s: the compose in the store did not contain a blueprint", c.Path)
|
||||
// TODO: find some (reasonable) way to verify the contents of the pipeline
|
||||
composeStruct.ImageBuilds[0].Manifest = nil
|
||||
composeStruct.ImageBuild.Manifest = nil
|
||||
|
||||
if diff := cmp.Diff(composeStruct, *c.ExpectedCompose, test.IgnoreDates(), test.IgnoreUuids(), test.Ignore("Targets.Options.Location"), test.CompareImageTypes()); diff != "" {
|
||||
t.Errorf("%s: compose in store isn't the same as expected, diff:\n%s", c.Path, diff)
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ func composeToComposeEntry(id uuid.UUID, compose store.Compose, state common.Com
|
|||
composeEntry.ID = id
|
||||
composeEntry.Blueprint = compose.Blueprint.Name
|
||||
composeEntry.Version = compose.Blueprint.Version
|
||||
composeEntry.ComposeType = compose.ImageBuilds[0].ImageType.Name()
|
||||
composeEntry.ComposeType = compose.ImageBuild.ImageType.Name()
|
||||
|
||||
if includeUploads {
|
||||
composeEntry.Uploads = targetsToUploadResponses(compose.ImageBuilds[0].Targets)
|
||||
composeEntry.Uploads = targetsToUploadResponses(compose.ImageBuild.Targets)
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
|
@ -46,7 +46,7 @@ func composeToComposeEntry(id uuid.UUID, compose store.Compose, state common.Com
|
|||
|
||||
case common.CFinished:
|
||||
composeEntry.QueueStatus = common.IBFinished
|
||||
composeEntry.ImageSize = compose.ImageBuilds[0].Size
|
||||
composeEntry.ImageSize = compose.ImageBuild.Size
|
||||
composeEntry.JobCreated = float64(queued.UnixNano()) / 1000000000
|
||||
composeEntry.JobStarted = float64(started.UnixNano()) / 1000000000
|
||||
composeEntry.JobFinished = float64(finished.UnixNano()) / 1000000000
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue