Refactor component/extras into snapshotting

This commit is contained in:
Tom Wiesing 2022-10-04 10:25:51 +02:00
parent 6d9c83c842
commit 6f409be8b2
No known key found for this signature in database
9 changed files with 81 additions and 79 deletions

View file

@ -6,7 +6,6 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/component"
"github.com/FAU-CDI/wisski-distillery/internal/component/control"
"github.com/FAU-CDI/wisski-distillery/internal/component/extras"
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/component/snapshots"
"github.com/FAU-CDI/wisski-distillery/internal/component/sql"
@ -25,6 +24,16 @@ type components struct {
pool component.Pool
}
// c initializes a component of the provided type
func c[C component.Component](dis *Distillery, thread int32, init func(component C, thread int32)) C {
return component.InitComponent(&dis.pool, thread, dis.Core, init)
}
// cc is like c, but with init set to nil
func cc[C component.Component](dis *Distillery, thread int32) C {
return c[C](dis, thread, nil)
}
//
// Individual Components
//
@ -34,22 +43,22 @@ func (c *components) thread() int32 {
}
func (dis *Distillery) cWeb(thread int32) *web.Web {
return component.PutComponent[*web.Web](&dis.pool, thread, dis.Core, nil)
return component.InitComponent[*web.Web](&dis.pool, thread, dis.Core, nil)
}
func (dis *Distillery) cControl(thread int32) *control.Control {
return component.PutComponent(&dis.pool, thread, dis.Core, func(control *control.Control, thread int32) {
return component.InitComponent(&dis.pool, thread, dis.Core, func(control *control.Control, thread int32) {
control.ResolverFile = core.PrefixConfig
control.Instances = dis.cInstances(thread)
})
}
func (dis *Distillery) cSSH(thread int32) *ssh.SSH {
return component.PutComponent[*ssh.SSH](&dis.pool, thread, dis.Core, nil)
return component.InitComponent[*ssh.SSH](&dis.pool, thread, dis.Core, nil)
}
func (dis *Distillery) cSQL(thread int32) *sql.SQL {
return component.PutComponent(&dis.pool, thread, dis.Core, func(sql *sql.SQL, thread int32) {
return component.InitComponent(&dis.pool, thread, dis.Core, func(sql *sql.SQL, thread int32) {
sql.ServerURL = dis.Upstream.SQL
sql.PollContext = dis.Context()
sql.PollInterval = time.Second
@ -57,7 +66,7 @@ func (dis *Distillery) cSQL(thread int32) *sql.SQL {
}
func (dis *Distillery) cTriplestore(thread int32) *triplestore.Triplestore {
return component.PutComponent(&dis.pool, thread, dis.Core, func(ts *triplestore.Triplestore, thread int32) {
return component.InitComponent(&dis.pool, thread, dis.Core, func(ts *triplestore.Triplestore, thread int32) {
ts.BaseURL = "http://" + dis.Upstream.Triplestore
ts.PollContext = dis.Context()
ts.PollInterval = time.Second
@ -65,14 +74,14 @@ func (dis *Distillery) cTriplestore(thread int32) *triplestore.Triplestore {
}
func (dis *Distillery) cInstances(thread int32) *instances.Instances {
return component.PutComponent(&dis.pool, thread, dis.Core, func(instances *instances.Instances, thread int32) {
return component.InitComponent(&dis.pool, thread, dis.Core, func(instances *instances.Instances, thread int32) {
instances.SQL = dis.cSQL(thread)
instances.TS = dis.cTriplestore(thread)
})
}
func (dis *Distillery) cSnapshotManager(thread int32) *snapshots.Manager {
return component.PutComponent(&dis.pool, thread, dis.Core, func(snapshots *snapshots.Manager, thread int32) {
return component.InitComponent(&dis.pool, thread, dis.Core, func(snapshots *snapshots.Manager, thread int32) {
snapshots.SQL = dis.cSQL(thread)
snapshots.Instances = dis.cInstances(thread)
snapshots.Snapshotable = dis.cSnapshotable(thread)
@ -80,28 +89,6 @@ func (dis *Distillery) cSnapshotManager(thread int32) *snapshots.Manager {
})
}
//
// EXTRAS COMPONENTS
//
func (dis *Distillery) cExtrasConfig(thread int32) *extras.Config {
return component.PutComponent[*extras.Config](&dis.pool, thread, dis.Core, nil)
}
func (dis *Distillery) cExtrasBookkeeping(thread int32) *extras.Bookkeeping {
return component.PutComponent[*extras.Bookkeeping](&dis.pool, thread, dis.Core, nil)
}
func (dis *Distillery) cExtrasFilesystem(thread int32) *extras.Filesystem {
return component.PutComponent[*extras.Filesystem](&dis.pool, thread, dis.Core, nil)
}
func (dis *Distillery) cExtrasPathbuilders(thread int32) *extras.Pathbuilders {
return component.PutComponent(&dis.pool, thread, dis.Core, func(pbs *extras.Pathbuilders, thread int32) {
pbs.Instances = dis.cInstances(thread)
})
}
//
// ALL COMPONENTS
//
@ -114,12 +101,15 @@ func (dis *Distillery) cComponents(thread int32) []component.Component {
dis.cTriplestore(thread),
dis.cSQL(thread),
dis.cInstances(thread),
dis.cSnapshotManager(thread),
dis.cExtrasConfig(thread),
dis.cExtrasBookkeeping(thread),
dis.cExtrasFilesystem(thread),
dis.cExtrasPathbuilders(thread),
// Snapshots
dis.cSnapshotManager(thread),
cc[*snapshots.Config](dis, thread),
cc[*snapshots.Bookkeeping](dis, thread),
cc[*snapshots.Filesystem](dis, thread),
c(dis, thread, func(pbs *snapshots.Pathbuilders, thread int32) {
pbs.Instances = dis.cInstances(thread)
}),
}
}
@ -147,12 +137,12 @@ func (dis *Distillery) cSnapshotable(thread int32) []component.Snapshotable {
return getComponentSubtype[component.Snapshotable](dis, thread)
}
func getComponentSubtype[T component.Component](dis *Distillery, thread int32) (components []T) {
func getComponentSubtype[C component.Component](dis *Distillery, thread int32) (components []C) {
all := dis.cComponents(thread)
components = make([]T, 0, len(all))
components = make([]C, 0, len(all))
for _, c := range all {
sc, ok := c.(T)
sc, ok := c.(C)
if !ok {
continue
}

View file

@ -1,3 +1,4 @@
// Package dis provides the main distillery
package dis
import (