store: create compose id from PushCompose
Every caller had to make their own uuid and pass that into PushCompose(). Make PushCompose() create the id and return it.
This commit is contained in:
parent
a6338410bc
commit
cef7267a2d
4 changed files with 20 additions and 21 deletions
|
|
@ -39,7 +39,6 @@ func TestBasic(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
id := uuid.MustParse("ffffffff-ffff-ffff-ffff-ffffffffffff")
|
||||
distroStruct := fedoratest.New()
|
||||
arch, err := distroStruct.GetArch("x86_64")
|
||||
if err != nil {
|
||||
|
|
@ -52,17 +51,16 @@ func TestCreate(t *testing.T) {
|
|||
store := store.New(nil)
|
||||
api := jobqueue.New(nil, store)
|
||||
|
||||
err = store.PushCompose(imageType, id, &blueprint.Blueprint{}, nil, nil, nil, 0, nil)
|
||||
id, err := store.PushCompose(imageType, &blueprint.Blueprint{}, nil, nil, nil, 0, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("error pushing compose: %v", err)
|
||||
}
|
||||
|
||||
test.TestRoute(t, api, false, "POST", "/job-queue/v1/jobs", `{}`, http.StatusCreated,
|
||||
`{"id":"ffffffff-ffff-ffff-ffff-ffffffffffff","image_build_id":0,"manifest":{"sources":{},"pipeline":{}},"targets":[]}`, "created", "uuid")
|
||||
`{"id":"`+id.String()+`","image_build_id":0,"manifest":{"sources":{},"pipeline":{}},"targets":[]}`, "created")
|
||||
}
|
||||
|
||||
func testUpdateTransition(t *testing.T, from, to string, expectedStatus int, expectedResponse string) {
|
||||
id := uuid.MustParse("ffffffff-ffff-ffff-ffff-ffffffffffff")
|
||||
distroStruct := fedoratest.New()
|
||||
arch, err := distroStruct.GetArch("x86_64")
|
||||
if err != nil {
|
||||
|
|
@ -75,20 +73,22 @@ func testUpdateTransition(t *testing.T, from, to string, expectedStatus int, exp
|
|||
store := store.New(nil)
|
||||
api := jobqueue.New(nil, store)
|
||||
|
||||
id := uuid.Nil
|
||||
if from != "VOID" {
|
||||
err := store.PushCompose(imageType, id, &blueprint.Blueprint{}, nil, nil, nil, 0, nil)
|
||||
id, err = store.PushCompose(imageType, &blueprint.Blueprint{}, nil, nil, nil, 0, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("error pushing compose: %v", err)
|
||||
}
|
||||
|
||||
if from != "WAITING" {
|
||||
test.SendHTTP(api, false, "POST", "/job-queue/v1/jobs", `{}`)
|
||||
if from != "RUNNING" {
|
||||
test.SendHTTP(api, false, "PATCH", "/job-queue/v1/jobs/ffffffff-ffff-ffff-ffff-ffffffffffff/builds/0", `{"status":"`+from+`"}`)
|
||||
test.SendHTTP(api, false, "PATCH", "/job-queue/v1/jobs/"+id.String()+"/builds/0", `{"status":"`+from+`"}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test.TestNonJsonRoute(t, api, false, "PATCH", "/job-queue/v1/jobs/ffffffff-ffff-ffff-ffff-ffffffffffff/builds/0", `{"status":"`+to+`"}`, expectedStatus, expectedResponse)
|
||||
test.TestNonJsonRoute(t, api, false, "PATCH", "/job-queue/v1/jobs/"+id.String()+"/builds/0", `{"status":"`+to+`"}`, expectedStatus, expectedResponse)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -205,8 +205,7 @@ func (api *API) submit(writer http.ResponseWriter, request *http.Request, _ http
|
|||
}
|
||||
|
||||
// Push the requested compose to the store
|
||||
composeUUID := uuid.New()
|
||||
err = api.store.PushCompose(imageType, composeUUID, &blueprint.Blueprint{}, repoConfigs, packages, buildPackages, 0, nil)
|
||||
composeID, err := api.store.PushCompose(imageType, &blueprint.Blueprint{}, repoConfigs, packages, buildPackages, 0, nil)
|
||||
if err != nil {
|
||||
if api.logger != nil {
|
||||
api.logger.Println("RCM API failed to push compose:", err)
|
||||
|
|
@ -222,7 +221,7 @@ func (api *API) submit(writer http.ResponseWriter, request *http.Request, _ http
|
|||
var reply struct {
|
||||
UUID uuid.UUID `json:"compose_id"`
|
||||
}
|
||||
reply.UUID = composeUUID
|
||||
reply.UUID = composeID
|
||||
// TODO: handle error
|
||||
_ = json.NewEncoder(writer).Encode(reply)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -553,11 +553,13 @@ func (s *Store) getImageBuildDirectory(composeID uuid.UUID, imageBuildID int) st
|
|||
return fmt.Sprintf("%s/%d", s.getComposeDirectory(composeID), imageBuildID)
|
||||
}
|
||||
|
||||
func (s *Store) PushCompose(imageType distro.ImageType, composeID uuid.UUID, bp *blueprint.Blueprint, repos []rpmmd.RepoConfig, packages, buildPackages []rpmmd.PackageSpec, size uint64, targets []*target.Target) error {
|
||||
func (s *Store) PushCompose(imageType distro.ImageType, bp *blueprint.Blueprint, repos []rpmmd.RepoConfig, packages, buildPackages []rpmmd.PackageSpec, size uint64, targets []*target.Target) (uuid.UUID, error) {
|
||||
if targets == nil {
|
||||
targets = []*target.Target{}
|
||||
}
|
||||
|
||||
composeID := uuid.New()
|
||||
|
||||
// Compatibility layer for image types in Weldr API v0
|
||||
imageTypeCommon, exists := common.ImageTypeFromCompatString(imageType.Name())
|
||||
if !exists {
|
||||
|
|
@ -569,7 +571,7 @@ func (s *Store) PushCompose(imageType distro.ImageType, composeID uuid.UUID, bp
|
|||
|
||||
err := os.MkdirAll(outputDir, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create output directory for job %v: %#v", composeID, err)
|
||||
return uuid.Nil, fmt.Errorf("cannot create output directory for job %v: %#v", composeID, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -580,7 +582,7 @@ func (s *Store) PushCompose(imageType distro.ImageType, composeID uuid.UUID, bp
|
|||
|
||||
manifestStruct, err := imageType.Manifest(bp.Customizations, allRepos, packages, buildPackages, imageType.Size(size))
|
||||
if err != nil {
|
||||
return err
|
||||
return uuid.Nil, err
|
||||
}
|
||||
// FIXME: handle or comment this possible error
|
||||
_ = s.change(func() error {
|
||||
|
|
@ -606,7 +608,7 @@ func (s *Store) PushCompose(imageType distro.ImageType, composeID uuid.UUID, bp
|
|||
Targets: targets,
|
||||
}
|
||||
|
||||
return nil
|
||||
return composeID, nil
|
||||
}
|
||||
|
||||
// DeleteCompose deletes the compose from the state file and also removes all files on disk that are
|
||||
|
|
|
|||
|
|
@ -1458,12 +1458,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
reply := ComposeReply{
|
||||
BuildID: uuid.New(),
|
||||
Status: true,
|
||||
}
|
||||
|
||||
err = api.store.PushCompose(imageType, reply.BuildID, bp, api.allRepositories(), packages, buildPackages, cr.Size, targets)
|
||||
composeID, err := api.store.PushCompose(imageType, bp, api.allRepositories(), packages, buildPackages, cr.Size, targets)
|
||||
|
||||
// TODO: we should probably do some kind of blueprint validation in future
|
||||
// for now, let's just 500 and bail out
|
||||
|
|
@ -1477,7 +1472,10 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
err = json.NewEncoder(writer).Encode(reply)
|
||||
err = json.NewEncoder(writer).Encode(ComposeReply{
|
||||
BuildID: composeID,
|
||||
Status: true,
|
||||
})
|
||||
common.PanicOnError(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue