store: merge the compose package into the store
The types exposed by the compose package are only used in the store API, so move them there where they belong. Making the ownership of the types clear, rather than having them live in a package for themselves, will make it clearer how the types can be modified in follow-up commits. Also remove the JSON annotations, as these types are no longer used for serialization. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
571a21c3ac
commit
df7a0fec22
7 changed files with 44 additions and 52 deletions
|
|
@ -1,6 +1,4 @@
|
||||||
// Package compose encapsulates the concept of a compose. It is a separate module from common, because it includes
|
package store
|
||||||
// target which in turn includes common and thus it would create a cyclic dependency, which is forbidden in golang.
|
|
||||||
package compose
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -22,20 +20,19 @@ func (ste *StateTransitionError) Error() string {
|
||||||
|
|
||||||
// ImageBuild represents a single image build inside a compose
|
// ImageBuild represents a single image build inside a compose
|
||||||
type ImageBuild struct {
|
type ImageBuild struct {
|
||||||
Id int `json:"id"`
|
Id int
|
||||||
ImageType common.ImageType `json:"image_type"`
|
ImageType common.ImageType
|
||||||
Manifest *osbuild.Manifest `json:"manifest"`
|
Manifest *osbuild.Manifest
|
||||||
Targets []*target.Target `json:"targets"`
|
Targets []*target.Target
|
||||||
JobCreated time.Time `json:"job_created"`
|
JobCreated time.Time
|
||||||
JobStarted time.Time `json:"job_started"`
|
JobStarted time.Time
|
||||||
JobFinished time.Time `json:"job_finished"`
|
JobFinished time.Time
|
||||||
Size uint64 `json:"size"`
|
Size uint64
|
||||||
JobId uuid.UUID `json:"jobid,omitempty"`
|
JobId uuid.UUID
|
||||||
|
|
||||||
// Kept for backwards compatibility. Image builds which were done
|
// Kept for backwards compatibility. Image builds which were done
|
||||||
// before the move to the job queue use this to store whether they
|
// before the move to the job queue use this to store whether they
|
||||||
// finished successfully.
|
// finished successfully.
|
||||||
QueueStatus common.ImageBuildState `json:"queue_status,omitempty"`
|
QueueStatus common.ImageBuildState
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy creates a copy of the ImageBuild structure
|
// DeepCopy creates a copy of the ImageBuild structure
|
||||||
|
|
@ -80,8 +77,8 @@ func (ib *ImageBuild) GetLocalTargetOptions() *target.LocalTargetOptions {
|
||||||
// It contains all the information necessary to generate the inputs for the job, as
|
// It contains all the information necessary to generate the inputs for the job, as
|
||||||
// well as the job's state.
|
// well as the job's state.
|
||||||
type Compose struct {
|
type Compose struct {
|
||||||
Blueprint *blueprint.Blueprint `json:"blueprint"`
|
Blueprint *blueprint.Blueprint
|
||||||
ImageBuilds []ImageBuild `json:"image_builds"`
|
ImageBuilds []ImageBuild
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy creates a copy of the Compose structure
|
// DeepCopy creates a copy of the Compose structure
|
||||||
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||||
"github.com/osbuild/osbuild-composer/internal/common"
|
"github.com/osbuild/osbuild-composer/internal/common"
|
||||||
"github.com/osbuild/osbuild-composer/internal/compose"
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/target"
|
"github.com/osbuild/osbuild-composer/internal/target"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -50,10 +49,10 @@ func FixtureBase() *Store {
|
||||||
s := New(nil)
|
s := New(nil)
|
||||||
|
|
||||||
s.blueprints[bName] = b
|
s.blueprints[bName] = b
|
||||||
s.composes = map[uuid.UUID]compose.Compose{
|
s.composes = map[uuid.UUID]Compose{
|
||||||
uuid.MustParse("30000000-0000-0000-0000-000000000000"): compose.Compose{
|
uuid.MustParse("30000000-0000-0000-0000-000000000000"): Compose{
|
||||||
Blueprint: &b,
|
Blueprint: &b,
|
||||||
ImageBuilds: []compose.ImageBuild{
|
ImageBuilds: []ImageBuild{
|
||||||
{
|
{
|
||||||
QueueStatus: common.IBWaiting,
|
QueueStatus: common.IBWaiting,
|
||||||
ImageType: common.Qcow2Generic,
|
ImageType: common.Qcow2Generic,
|
||||||
|
|
@ -62,9 +61,9 @@ func FixtureBase() *Store {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
uuid.MustParse("30000000-0000-0000-0000-000000000001"): compose.Compose{
|
uuid.MustParse("30000000-0000-0000-0000-000000000001"): Compose{
|
||||||
Blueprint: &b,
|
Blueprint: &b,
|
||||||
ImageBuilds: []compose.ImageBuild{
|
ImageBuilds: []ImageBuild{
|
||||||
{
|
{
|
||||||
QueueStatus: common.IBRunning,
|
QueueStatus: common.IBRunning,
|
||||||
ImageType: common.Qcow2Generic,
|
ImageType: common.Qcow2Generic,
|
||||||
|
|
@ -74,9 +73,9 @@ func FixtureBase() *Store {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
uuid.MustParse("30000000-0000-0000-0000-000000000002"): compose.Compose{
|
uuid.MustParse("30000000-0000-0000-0000-000000000002"): Compose{
|
||||||
Blueprint: &b,
|
Blueprint: &b,
|
||||||
ImageBuilds: []compose.ImageBuild{
|
ImageBuilds: []ImageBuild{
|
||||||
{
|
{
|
||||||
QueueStatus: common.IBFinished,
|
QueueStatus: common.IBFinished,
|
||||||
ImageType: common.Qcow2Generic,
|
ImageType: common.Qcow2Generic,
|
||||||
|
|
@ -87,9 +86,9 @@ func FixtureBase() *Store {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
uuid.MustParse("30000000-0000-0000-0000-000000000003"): compose.Compose{
|
uuid.MustParse("30000000-0000-0000-0000-000000000003"): Compose{
|
||||||
Blueprint: &b,
|
Blueprint: &b,
|
||||||
ImageBuilds: []compose.ImageBuild{
|
ImageBuilds: []ImageBuild{
|
||||||
{
|
{
|
||||||
QueueStatus: common.IBFailed,
|
QueueStatus: common.IBFailed,
|
||||||
ImageType: common.Qcow2Generic,
|
ImageType: common.Qcow2Generic,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||||
"github.com/osbuild/osbuild-composer/internal/common"
|
"github.com/osbuild/osbuild-composer/internal/common"
|
||||||
"github.com/osbuild/osbuild-composer/internal/compose"
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||||
"github.com/osbuild/osbuild-composer/internal/target"
|
"github.com/osbuild/osbuild-composer/internal/target"
|
||||||
)
|
)
|
||||||
|
|
@ -91,18 +90,18 @@ func newWorkspaceFromV0(workspaceStruct workspaceV0) map[string]blueprint.Bluepr
|
||||||
return workspace
|
return workspace
|
||||||
}
|
}
|
||||||
|
|
||||||
func newComposesFromV0(composesStruct composesV0) map[uuid.UUID]compose.Compose {
|
func newComposesFromV0(composesStruct composesV0) map[uuid.UUID]Compose {
|
||||||
composes := make(map[uuid.UUID]compose.Compose)
|
composes := make(map[uuid.UUID]Compose)
|
||||||
|
|
||||||
for composeID, composeStruct := range composesStruct {
|
for composeID, composeStruct := range composesStruct {
|
||||||
c := compose.Compose{
|
c := Compose{
|
||||||
Blueprint: composeStruct.Blueprint,
|
Blueprint: composeStruct.Blueprint,
|
||||||
}
|
}
|
||||||
if len(composeStruct.ImageBuilds) == 0 {
|
if len(composeStruct.ImageBuilds) == 0 {
|
||||||
panic("the was a compose with zero image builds, that is forbidden")
|
panic("the was a compose with zero image builds, that is forbidden")
|
||||||
}
|
}
|
||||||
for _, imgBuild := range composeStruct.ImageBuilds {
|
for _, imgBuild := range composeStruct.ImageBuilds {
|
||||||
ib := compose.ImageBuild{
|
ib := ImageBuild{
|
||||||
Id: imgBuild.ID,
|
Id: imgBuild.ID,
|
||||||
ImageType: imgBuild.ImageType,
|
ImageType: imgBuild.ImageType,
|
||||||
Manifest: imgBuild.Manifest,
|
Manifest: imgBuild.Manifest,
|
||||||
|
|
@ -229,7 +228,7 @@ func newStoreFromV0(storeStruct storeV0) *Store {
|
||||||
return &store
|
return &store
|
||||||
}
|
}
|
||||||
|
|
||||||
func newComposesV0(composes map[uuid.UUID]compose.Compose) composesV0 {
|
func newComposesV0(composes map[uuid.UUID]Compose) composesV0 {
|
||||||
composesStruct := make(composesV0)
|
composesStruct := make(composesV0)
|
||||||
for composeID, compose := range composes {
|
for composeID, compose := range composes {
|
||||||
c := composeV0{
|
c := composeV0{
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/compose"
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||||
"github.com/osbuild/osbuild-composer/internal/jsondb"
|
"github.com/osbuild/osbuild-composer/internal/jsondb"
|
||||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||||
|
|
@ -39,7 +38,7 @@ const StoreDBName = "state"
|
||||||
type Store struct {
|
type Store struct {
|
||||||
blueprints map[string]blueprint.Blueprint
|
blueprints map[string]blueprint.Blueprint
|
||||||
workspace map[string]blueprint.Blueprint
|
workspace map[string]blueprint.Blueprint
|
||||||
composes map[uuid.UUID]compose.Compose
|
composes map[uuid.UUID]Compose
|
||||||
sources map[string]SourceConfig
|
sources map[string]SourceConfig
|
||||||
blueprintsChanges map[string]map[string]blueprint.Change
|
blueprintsChanges map[string]map[string]blueprint.Change
|
||||||
blueprintsCommits map[string][]string
|
blueprintsCommits map[string][]string
|
||||||
|
|
@ -319,7 +318,7 @@ func (s *Store) TagBlueprint(name string) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) GetCompose(id uuid.UUID) (compose.Compose, bool) {
|
func (s *Store) GetCompose(id uuid.UUID) (Compose, bool) {
|
||||||
s.mu.RLock()
|
s.mu.RLock()
|
||||||
defer s.mu.RUnlock()
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
|
|
@ -329,11 +328,11 @@ func (s *Store) GetCompose(id uuid.UUID) (compose.Compose, bool) {
|
||||||
|
|
||||||
// GetAllComposes creates a deep copy of all composes present in this store
|
// GetAllComposes creates a deep copy of all composes present in this store
|
||||||
// and returns them as a dictionary with compose UUIDs as keys
|
// and returns them as a dictionary with compose UUIDs as keys
|
||||||
func (s *Store) GetAllComposes() map[uuid.UUID]compose.Compose {
|
func (s *Store) GetAllComposes() map[uuid.UUID]Compose {
|
||||||
s.mu.RLock()
|
s.mu.RLock()
|
||||||
defer s.mu.RUnlock()
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
composes := make(map[uuid.UUID]compose.Compose)
|
composes := make(map[uuid.UUID]Compose)
|
||||||
|
|
||||||
for id, singleCompose := range s.composes {
|
for id, singleCompose := range s.composes {
|
||||||
newCompose := singleCompose.DeepCopy()
|
newCompose := singleCompose.DeepCopy()
|
||||||
|
|
@ -415,9 +414,9 @@ func (s *Store) PushCompose(composeID uuid.UUID, manifest *osbuild.Manifest, ima
|
||||||
|
|
||||||
// FIXME: handle or comment this possible error
|
// FIXME: handle or comment this possible error
|
||||||
_ = s.change(func() error {
|
_ = s.change(func() error {
|
||||||
s.composes[composeID] = compose.Compose{
|
s.composes[composeID] = Compose{
|
||||||
Blueprint: bp,
|
Blueprint: bp,
|
||||||
ImageBuilds: []compose.ImageBuild{
|
ImageBuilds: []ImageBuild{
|
||||||
{
|
{
|
||||||
Manifest: manifest,
|
Manifest: manifest,
|
||||||
ImageType: imageTypeCommon,
|
ImageType: imageTypeCommon,
|
||||||
|
|
@ -474,9 +473,9 @@ func (s *Store) PushTestCompose(composeID uuid.UUID, manifest *osbuild.Manifest,
|
||||||
|
|
||||||
// FIXME: handle or comment this possible error
|
// FIXME: handle or comment this possible error
|
||||||
_ = s.change(func() error {
|
_ = s.change(func() error {
|
||||||
s.composes[composeID] = compose.Compose{
|
s.composes[composeID] = Compose{
|
||||||
Blueprint: bp,
|
Blueprint: bp,
|
||||||
ImageBuilds: []compose.ImageBuild{
|
ImageBuilds: []ImageBuild{
|
||||||
{
|
{
|
||||||
QueueStatus: status,
|
QueueStatus: status,
|
||||||
Manifest: manifest,
|
Manifest: manifest,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ import (
|
||||||
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||||
"github.com/osbuild/osbuild-composer/internal/common"
|
"github.com/osbuild/osbuild-composer/internal/common"
|
||||||
"github.com/osbuild/osbuild-composer/internal/compose"
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||||
"github.com/osbuild/osbuild-composer/internal/store"
|
"github.com/osbuild/osbuild-composer/internal/store"
|
||||||
|
|
@ -146,7 +145,7 @@ func (api *API) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||||
// Returns the state of the image in `compose` and the times the job was
|
// Returns the state of the image in `compose` and the times the job was
|
||||||
// queued, started, and finished. Assumes that there's only one image in the
|
// queued, started, and finished. Assumes that there's only one image in the
|
||||||
// compose. Returns CWaiting on error.
|
// compose. Returns CWaiting on error.
|
||||||
func (api *API) getComposeState(compose compose.Compose) (state common.ComposeState, queued, started, finished time.Time) {
|
func (api *API) getComposeState(compose store.Compose) (state common.ComposeState, queued, started, finished time.Time) {
|
||||||
if len(compose.ImageBuilds) == 0 {
|
if len(compose.ImageBuilds) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/common"
|
"github.com/osbuild/osbuild-composer/internal/common"
|
||||||
"github.com/osbuild/osbuild-composer/internal/compose"
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/target"
|
"github.com/osbuild/osbuild-composer/internal/target"
|
||||||
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||||
|
|
@ -434,7 +433,7 @@ func TestBlueprintsDepsolve(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompose(t *testing.T) {
|
func TestCompose(t *testing.T) {
|
||||||
expectedComposeLocal := &compose.Compose{
|
expectedComposeLocal := &store.Compose{
|
||||||
Blueprint: &blueprint.Blueprint{
|
Blueprint: &blueprint.Blueprint{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Version: "0.0.0",
|
Version: "0.0.0",
|
||||||
|
|
@ -443,7 +442,7 @@ func TestCompose(t *testing.T) {
|
||||||
Groups: []blueprint.Group{},
|
Groups: []blueprint.Group{},
|
||||||
Customizations: nil,
|
Customizations: nil,
|
||||||
},
|
},
|
||||||
ImageBuilds: []compose.ImageBuild{
|
ImageBuilds: []store.ImageBuild{
|
||||||
{
|
{
|
||||||
QueueStatus: common.IBWaiting,
|
QueueStatus: common.IBWaiting,
|
||||||
ImageType: common.Qcow2Generic,
|
ImageType: common.Qcow2Generic,
|
||||||
|
|
@ -459,7 +458,7 @@ func TestCompose(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expectedComposeLocalAndAws := &compose.Compose{
|
expectedComposeLocalAndAws := &store.Compose{
|
||||||
Blueprint: &blueprint.Blueprint{
|
Blueprint: &blueprint.Blueprint{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Version: "0.0.0",
|
Version: "0.0.0",
|
||||||
|
|
@ -468,7 +467,7 @@ func TestCompose(t *testing.T) {
|
||||||
Groups: []blueprint.Group{},
|
Groups: []blueprint.Group{},
|
||||||
Customizations: nil,
|
Customizations: nil,
|
||||||
},
|
},
|
||||||
ImageBuilds: []compose.ImageBuild{
|
ImageBuilds: []store.ImageBuild{
|
||||||
{
|
{
|
||||||
QueueStatus: common.IBWaiting,
|
QueueStatus: common.IBWaiting,
|
||||||
ImageType: common.Qcow2Generic,
|
ImageType: common.Qcow2Generic,
|
||||||
|
|
@ -505,7 +504,7 @@ func TestCompose(t *testing.T) {
|
||||||
Body string
|
Body string
|
||||||
ExpectedStatus int
|
ExpectedStatus int
|
||||||
ExpectedJSON string
|
ExpectedJSON string
|
||||||
ExpectedCompose *compose.Compose
|
ExpectedCompose *store.Compose
|
||||||
IgnoreFields []string
|
IgnoreFields []string
|
||||||
}{
|
}{
|
||||||
{true, "POST", "/api/v0/compose", `{"blueprint_name": "http-server","compose_type": "qcow2","branch": "master"}`, http.StatusBadRequest, `{"status":false,"errors":[{"id":"UnknownBlueprint","msg":"Unknown blueprint name: http-server"}]}`, nil, []string{"build_id"}},
|
{true, "POST", "/api/v0/compose", `{"blueprint_name": "http-server","compose_type": "qcow2","branch": "master"}`, http.StatusBadRequest, `{"status":false,"errors":[{"id":"UnknownBlueprint","msg":"Unknown blueprint name: http-server"}]}`, nil, []string{"build_id"}},
|
||||||
|
|
@ -526,7 +525,7 @@ func TestCompose(t *testing.T) {
|
||||||
require.Equalf(t, 1, len(composes), "%s: bad compose count in store", c.Path)
|
require.Equalf(t, 1, len(composes), "%s: bad compose count in store", c.Path)
|
||||||
|
|
||||||
// I have no idea how to get the compose in better way
|
// I have no idea how to get the compose in better way
|
||||||
var composeStruct compose.Compose
|
var composeStruct store.Compose
|
||||||
for _, c := range composes {
|
for _, c := range composes {
|
||||||
composeStruct = c
|
composeStruct = c
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/osbuild/osbuild-composer/internal/common"
|
"github.com/osbuild/osbuild-composer/internal/common"
|
||||||
"github.com/osbuild/osbuild-composer/internal/compose"
|
"github.com/osbuild/osbuild-composer/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ComposeEntry struct {
|
type ComposeEntry struct {
|
||||||
|
|
@ -22,7 +22,7 @@ type ComposeEntry struct {
|
||||||
Uploads []uploadResponse `json:"uploads,omitempty"`
|
Uploads []uploadResponse `json:"uploads,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func composeToComposeEntry(id uuid.UUID, compose compose.Compose, state common.ComposeState, queued, started, finished time.Time, includeUploads bool) *ComposeEntry {
|
func composeToComposeEntry(id uuid.UUID, compose store.Compose, state common.ComposeState, queued, started, finished time.Time, includeUploads bool) *ComposeEntry {
|
||||||
var composeEntry ComposeEntry
|
var composeEntry ComposeEntry
|
||||||
|
|
||||||
composeEntry.ID = id
|
composeEntry.ID = id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue