debian-forge-composer/internal/weldr/compose.go
Tom Gundersen df7a0fec22 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>
2020-05-18 11:50:15 +02:00

70 lines
2.5 KiB
Go

package weldr
import (
"sort"
"time"
"github.com/google/uuid"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/store"
)
type ComposeEntry struct {
ID uuid.UUID `json:"id"`
Blueprint string `json:"blueprint"`
Version string `json:"version"`
ComposeType common.ImageType `json:"compose_type"`
ImageSize uint64 `json:"image_size"` // This is user-provided image size, not actual file size
QueueStatus common.ImageBuildState `json:"queue_status"`
JobCreated float64 `json:"job_created"`
JobStarted float64 `json:"job_started,omitempty"`
JobFinished float64 `json:"job_finished,omitempty"`
Uploads []uploadResponse `json:"uploads,omitempty"`
}
func composeToComposeEntry(id uuid.UUID, compose store.Compose, state common.ComposeState, queued, started, finished time.Time, includeUploads bool) *ComposeEntry {
var composeEntry ComposeEntry
composeEntry.ID = id
composeEntry.Blueprint = compose.Blueprint.Name
composeEntry.Version = compose.Blueprint.Version
composeEntry.ComposeType = compose.ImageBuilds[0].ImageType
if includeUploads {
composeEntry.Uploads = targetsToUploadResponses(compose.ImageBuilds[0].Targets)
}
switch state {
case common.CWaiting:
composeEntry.QueueStatus = common.IBWaiting
composeEntry.JobCreated = float64(queued.UnixNano()) / 1000000000
case common.CRunning:
composeEntry.QueueStatus = common.IBRunning
composeEntry.JobCreated = float64(queued.UnixNano()) / 1000000000
composeEntry.JobStarted = float64(started.UnixNano()) / 1000000000
case common.CFinished:
composeEntry.QueueStatus = common.IBFinished
composeEntry.ImageSize = compose.ImageBuilds[0].Size
composeEntry.JobCreated = float64(queued.UnixNano()) / 1000000000
composeEntry.JobStarted = float64(started.UnixNano()) / 1000000000
composeEntry.JobFinished = float64(finished.UnixNano()) / 1000000000
case common.CFailed:
composeEntry.QueueStatus = common.IBFailed
composeEntry.JobCreated = float64(queued.UnixNano()) / 1000000000
composeEntry.JobStarted = float64(started.UnixNano()) / 1000000000
composeEntry.JobFinished = float64(finished.UnixNano()) / 1000000000
default:
panic("invalid compose state")
}
return &composeEntry
}
func sortComposeEntries(entries []*ComposeEntry) {
sort.Slice(entries, func(i, j int) bool {
return entries[i].ID.String() < entries[j].ID.String()
})
}