Move WissKI Parts to new ingredients system
This commit is contained in:
parent
b5b1ce2340
commit
42b8cbd865
83 changed files with 1016 additions and 646 deletions
|
|
@ -34,10 +34,6 @@ func auto[C component.Component](context ctx) component.Component {
|
|||
|
||||
// register returns all components of the distillery
|
||||
func (dis *Distillery) register(context ctx) []component.Component {
|
||||
dis.poolInit.Do(func() {
|
||||
dis.pool.Init = component.Init
|
||||
})
|
||||
|
||||
return collection.MapSlice(
|
||||
dis.allComponents(),
|
||||
func(f initFunc) component.Component {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func (Pathbuilders) SnapshotName() string { return "pathbuilders" }
|
|||
|
||||
func (pbs *Pathbuilders) Snapshot(wisski models.Instance, context component.StagingContext) error {
|
||||
return context.AddDirectory(".", func() error {
|
||||
builders, err := pbs.Instances.Instance(wisski).AllPathbuilders(nil)
|
||||
builders, err := pbs.Instances.Instance(wisski).Pathbuilder().GetAll(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/locker"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/tkw1536/goprogram/lib/collection"
|
||||
"github.com/tkw1536/goprogram/status"
|
||||
|
|
@ -46,7 +47,8 @@ type Snapshot struct {
|
|||
func (snapshots *Exporter) NewSnapshot(instance *wisski.WissKI, io stream.IOStream, desc SnapshotDescription) (snapshot Snapshot) {
|
||||
|
||||
logging.LogMessage(io, "Locking instance")
|
||||
if err := instance.TryLock(); err != nil {
|
||||
if !instance.Locker().TryLock() {
|
||||
err := locker.Locked
|
||||
io.EPrintln(err)
|
||||
logging.LogMessage(io, "Aborting snapshot creation")
|
||||
|
||||
|
|
@ -56,7 +58,7 @@ func (snapshots *Exporter) NewSnapshot(instance *wisski.WissKI, io stream.IOStre
|
|||
}
|
||||
defer func() {
|
||||
logging.LogMessage(io, "Unlocking instance")
|
||||
instance.Unlock()
|
||||
instance.Locker().Unlock()
|
||||
}()
|
||||
|
||||
// setup the snapshot
|
||||
|
|
@ -85,7 +87,7 @@ func (snapshots *Exporter) NewSnapshot(instance *wisski.WissKI, io stream.IOStre
|
|||
|
||||
func (snapshot *Snapshot) makeParts(ios stream.IOStream, snapshots *Exporter, instance *wisski.WissKI, needsRunning bool) map[string]error {
|
||||
if !needsRunning && !snapshot.Description.Keepalive {
|
||||
stack := instance.Barrel()
|
||||
stack := instance.Barrel().Stack()
|
||||
|
||||
logging.LogMessage(ios, "Stopping instance")
|
||||
snapshot.ErrStop = stack.Down(ios)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
_ "embed"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/static"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/info"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/timex"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
|
@ -65,7 +65,7 @@ func (home *Home) homeRender() ([]byte, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
context.Instances = make([]wisski.WissKIInfo, len(wissKIs))
|
||||
context.Instances = make([]info.WissKIInfo, len(wissKIs))
|
||||
|
||||
// determine their infos
|
||||
var eg errgroup.Group
|
||||
|
|
@ -73,7 +73,7 @@ func (home *Home) homeRender() ([]byte, error) {
|
|||
i := i
|
||||
wissKI := instance
|
||||
eg.Go(func() (err error) {
|
||||
context.Instances[i], err = wissKI.Info(true)
|
||||
context.Instances[i], err = wissKI.Info().Fetch(true)
|
||||
return
|
||||
})
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ func (home *Home) homeRender() ([]byte, error) {
|
|||
}
|
||||
|
||||
type HomeContext struct {
|
||||
Instances []wisski.WissKIInfo
|
||||
Instances []info.WissKIInfo
|
||||
|
||||
Time time.Time
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/config"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/static"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/info"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ type indexPageContext struct {
|
|||
|
||||
Config *config.Config
|
||||
|
||||
Instances []wisski.WissKIInfo
|
||||
Instances []info.WissKIInfo
|
||||
|
||||
TotalCount int
|
||||
RunningCount int
|
||||
|
|
@ -31,18 +31,18 @@ type indexPageContext struct {
|
|||
Backups []models.Export
|
||||
}
|
||||
|
||||
func (info *Info) indexPageAPI(r *http.Request) (idx indexPageContext, err error) {
|
||||
func (nfo *Info) indexPageAPI(r *http.Request) (idx indexPageContext, err error) {
|
||||
var group errgroup.Group
|
||||
|
||||
group.Go(func() error {
|
||||
// list all the instances
|
||||
all, err := info.Instances.All()
|
||||
all, err := nfo.Instances.All()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// get all of their info!
|
||||
idx.Instances = make([]wisski.WissKIInfo, len(all))
|
||||
idx.Instances = make([]info.WissKIInfo, len(all))
|
||||
for i, instance := range all {
|
||||
{
|
||||
i := i
|
||||
|
|
@ -50,7 +50,7 @@ func (info *Info) indexPageAPI(r *http.Request) (idx indexPageContext, err error
|
|||
|
||||
// store the info for this group!
|
||||
group.Go(func() (err error) {
|
||||
idx.Instances[i], err = instance.Info(true)
|
||||
idx.Instances[i], err = instance.Info().Fetch(true)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
|
@ -61,12 +61,12 @@ func (info *Info) indexPageAPI(r *http.Request) (idx indexPageContext, err error
|
|||
|
||||
// get the log entries
|
||||
group.Go(func() (err error) {
|
||||
idx.Backups, err = info.SnapshotsLog.For("")
|
||||
idx.Backups, err = nfo.SnapshotsLog.For("")
|
||||
return
|
||||
})
|
||||
|
||||
// get the static properties
|
||||
idx.Config = info.Config
|
||||
idx.Config = nfo.Config
|
||||
idx.Time = time.Now().UTC()
|
||||
|
||||
group.Wait()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/static"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/info"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
||||
)
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ type instancePageContext struct {
|
|||
Time time.Time
|
||||
|
||||
Instance models.Instance
|
||||
Info wisski.WissKIInfo
|
||||
Info info.WissKIInfo
|
||||
}
|
||||
|
||||
func (info *Info) instancePageAPI(r *http.Request) (is instancePageContext, err error) {
|
||||
|
|
@ -40,7 +40,7 @@ func (info *Info) instancePageAPI(r *http.Request) (is instancePageContext, err
|
|||
is.Instance = instance.Instance
|
||||
|
||||
// get some more info about the wisski
|
||||
is.Info, err = instance.Info(false)
|
||||
is.Info, err = instance.Info().Fetch(false)
|
||||
if err != nil {
|
||||
return is, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,13 +23,13 @@ var socketInstanceActions = map[string]instanceActionFunc{
|
|||
)
|
||||
},
|
||||
"rebuild": func(_ *Info, instance *wisski.WissKI, str stream.IOStream) error {
|
||||
return instance.Build(str, true)
|
||||
return instance.Barrel().Build(str, true)
|
||||
},
|
||||
"update": func(_ *Info, instance *wisski.WissKI, str stream.IOStream) error {
|
||||
return instance.BlindUpdate(str)
|
||||
return instance.Drush().Update(str)
|
||||
},
|
||||
"cron": func(_ *Info, instance *wisski.WissKI, str stream.IOStream) error {
|
||||
return instance.Cron(str)
|
||||
return instance.Drush().Cron(str)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,37 +25,37 @@ func (instances *Instances) Create(slug string) (wissKI *wisski.WissKI, err erro
|
|||
wissKI = new(wisski.WissKI)
|
||||
instances.use(wissKI)
|
||||
|
||||
wissKI.Instance.Slug = slug
|
||||
wissKI.Instance.FilesystemBase = filepath.Join(instances.Path(), wissKI.Domain())
|
||||
wissKI.Liquid.Instance.Slug = slug
|
||||
wissKI.Liquid.Instance.FilesystemBase = filepath.Join(instances.Path(), wissKI.Domain())
|
||||
|
||||
wissKI.Instance.OwnerEmail = ""
|
||||
wissKI.Instance.AutoBlindUpdateEnabled = true
|
||||
wissKI.Liquid.Instance.OwnerEmail = ""
|
||||
wissKI.Liquid.Instance.AutoBlindUpdateEnabled = true
|
||||
|
||||
// sql
|
||||
|
||||
wissKI.Instance.SqlDatabase = instances.Config.MysqlDatabasePrefix + slug
|
||||
wissKI.Instance.SqlUsername = instances.Config.MysqlUserPrefix + slug
|
||||
wissKI.Liquid.Instance.SqlDatabase = instances.Config.MysqlDatabasePrefix + slug
|
||||
wissKI.Liquid.Instance.SqlUsername = instances.Config.MysqlUserPrefix + slug
|
||||
|
||||
wissKI.Instance.SqlPassword, err = instances.Config.NewPassword()
|
||||
wissKI.Liquid.Instance.SqlPassword, err = instances.Config.NewPassword()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// triplestore
|
||||
|
||||
wissKI.Instance.GraphDBRepository = instances.Config.GraphDBRepoPrefix + slug
|
||||
wissKI.Instance.GraphDBUsername = instances.Config.GraphDBUserPrefix + slug
|
||||
wissKI.Liquid.Instance.GraphDBRepository = instances.Config.GraphDBRepoPrefix + slug
|
||||
wissKI.Liquid.Instance.GraphDBUsername = instances.Config.GraphDBUserPrefix + slug
|
||||
|
||||
wissKI.Instance.GraphDBPassword, err = instances.Config.NewPassword()
|
||||
wissKI.Liquid.Instance.GraphDBPassword, err = instances.Config.NewPassword()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// drupal
|
||||
|
||||
wissKI.DrupalUsername = "admin" // TODO: Change this!
|
||||
wissKI.Liquid.DrupalUsername = "admin" // TODO: Change this!
|
||||
|
||||
wissKI.DrupalPassword, err = instances.Config.NewPassword()
|
||||
wissKI.Liquid.DrupalPassword, err = instances.Config.NewPassword()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,8 @@ import (
|
|||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter/logger"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/meta"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances/malt"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/sql"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/triplestore"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
|
|
@ -21,10 +19,8 @@ import (
|
|||
type Instances struct {
|
||||
component.Base
|
||||
|
||||
TS *triplestore.Triplestore
|
||||
SQL *sql.SQL
|
||||
Meta *meta.Meta
|
||||
ExporterLog *logger.Logger
|
||||
Malt *malt.Malt
|
||||
SQL *sql.SQL
|
||||
}
|
||||
|
||||
func (instances *Instances) Path() string {
|
||||
|
|
@ -41,11 +37,7 @@ var errSQL = exit.Error{
|
|||
|
||||
// use uses the non-nil wisski instance with this instances
|
||||
func (instances *Instances) use(wisski *wisski.WissKI) {
|
||||
wisski.Core = instances.Still
|
||||
wisski.SQL = instances.SQL
|
||||
wisski.TS = instances.TS
|
||||
wisski.Meta = instances.Meta
|
||||
wisski.ExporterLog = instances.ExporterLog
|
||||
wisski.Liquid.Malt = instances.Malt
|
||||
}
|
||||
|
||||
// WissKI returns the WissKI with the provided slug, if it exists.
|
||||
|
|
@ -65,7 +57,7 @@ func (instances *Instances) WissKI(slug string) (wissKI *wisski.WissKI, err erro
|
|||
wissKI = new(wisski.WissKI)
|
||||
|
||||
// find the instance by slug
|
||||
query := table.Where(&models.Instance{Slug: slug}).Find(&wissKI.Instance)
|
||||
query := table.Where(&models.Instance{Slug: slug}).Find(&wissKI.Liquid.Instance)
|
||||
switch {
|
||||
case query.Error != nil:
|
||||
return nil, errSQL.WithMessageF(query.Error)
|
||||
|
|
@ -166,7 +158,7 @@ func (instances *Instances) find(order bool, query func(table *gorm.DB) *gorm.DB
|
|||
results = make([]*wisski.WissKI, len(bks))
|
||||
for i, bk := range bks {
|
||||
results[i] = new(wisski.WissKI)
|
||||
results[i].Instance = bk
|
||||
results[i].Liquid.Instance = bk
|
||||
instances.use(results[i])
|
||||
}
|
||||
|
||||
|
|
|
|||
19
internal/dis/component/instances/malt/malt.go
Normal file
19
internal/dis/component/instances/malt/malt.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package malt
|
||||
|
||||
import (
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter/logger"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/meta"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/sql"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/triplestore"
|
||||
)
|
||||
|
||||
// Malt is a component passed to every WissKI ingredient
|
||||
type Malt struct {
|
||||
component.Base
|
||||
|
||||
TS *triplestore.Triplestore
|
||||
SQL *sql.SQL
|
||||
Meta *meta.Meta
|
||||
ExporterLog *logger.Logger
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/sql"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/tkw1536/goprogram/lib/collection"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
|
@ -177,42 +176,3 @@ func (s Storage) Purge() error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// StorageFor returns a storage for the given key.
|
||||
func StorageFor[Value any](key Key) func(storage *Storage) SpecifcStorage[Value] {
|
||||
return func(storage *Storage) SpecifcStorage[Value] {
|
||||
return SpecifcStorage[Value]{storage: storage, key: key}
|
||||
}
|
||||
}
|
||||
|
||||
type SpecifcStorage[Value any] struct {
|
||||
storage *Storage
|
||||
key Key
|
||||
}
|
||||
|
||||
func (sf SpecifcStorage[Value]) Get() (value Value, err error) {
|
||||
err = sf.storage.Get(sf.key, &value)
|
||||
return
|
||||
}
|
||||
|
||||
func (sf SpecifcStorage[Value]) GetAll() (values []Value, err error) {
|
||||
err = sf.storage.GetAll(sf.key, func(index, total int) any {
|
||||
if values == nil {
|
||||
values = make([]Value, total)
|
||||
}
|
||||
return &values[index]
|
||||
})
|
||||
return values, err
|
||||
}
|
||||
|
||||
func (sf SpecifcStorage[Value]) Set(value Value) error {
|
||||
return sf.storage.Set(sf.key, value)
|
||||
}
|
||||
|
||||
func (sf SpecifcStorage[Value]) SetAll(values ...Value) error {
|
||||
return sf.storage.SetAll(sf.key, collection.AsAny(values)...)
|
||||
}
|
||||
|
||||
func (sf SpecifcStorage[Value]) Delete() error {
|
||||
return sf.storage.Delete(sf.key)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,14 +30,14 @@ func (resolver *Resolver) AllPrefixes() (map[string]string, error) {
|
|||
gPrefixes := make(map[string]string)
|
||||
var lastErr error
|
||||
for _, instance := range instances {
|
||||
if instance.NoPrefix() {
|
||||
if instance.Prefixes().NoPrefix() {
|
||||
continue
|
||||
}
|
||||
url := instance.URL().String()
|
||||
|
||||
// failed to fetch prefixes for this particular instance
|
||||
// => skip it!
|
||||
prefixes, err := instance.PrefixesCached()
|
||||
prefixes, err := instance.Prefixes().PrefixesCached()
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/home"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/info"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances/malt"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/meta"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/resolver"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/sql"
|
||||
|
|
@ -114,8 +115,10 @@ func (dis *Distillery) allComponents() []initFunc {
|
|||
sql.PollInterval = time.Second
|
||||
}),
|
||||
|
||||
// instainces
|
||||
auto[*instances.Instances],
|
||||
auto[*meta.Meta],
|
||||
auto[*malt.Malt],
|
||||
|
||||
// Snapshots
|
||||
auto[*exporter.Exporter],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue