snapshots: Handle as separate components

This commit is contained in:
Tom Wiesing 2022-10-02 18:17:47 +02:00
parent 698f04e13e
commit 3b112f1b8e
No known key found for this signature in database
27 changed files with 960 additions and 789 deletions

View file

@ -1,6 +1,7 @@
package dis
import (
"sync/atomic"
"time"
"github.com/FAU-CDI/wisski-distillery/internal/component"
@ -13,7 +14,6 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/component/triplestore"
"github.com/FAU-CDI/wisski-distillery/internal/component/web"
"github.com/FAU-CDI/wisski-distillery/internal/core"
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
)
// components holds the various components of the distillery
@ -21,68 +21,61 @@ import (
//
// The caller is responsible for syncronizing access across multiple goroutines.
type components struct {
// installable components
web lazy.Lazy[*web.Web]
control lazy.Lazy[*control.Control]
ssh lazy.Lazy[*ssh.SSH]
ts lazy.Lazy[*triplestore.Triplestore]
sql lazy.Lazy[*sql.SQL]
// other components
instances lazy.Lazy[*instances.Instances]
snapshots lazy.Lazy[*snapshots.Manager]
// extras components
extrasConfig lazy.Lazy[*extras.Config]
t int32 // t is the previously used thread id!
pool component.Pool
}
//
// Individual Components
//
func (dis *Distillery) Web() *web.Web {
return component.Initialize(dis.Core, &dis.components.web, nil)
func (c *components) thread() int32 {
return atomic.AddInt32(&c.t, 1)
}
func (d *Distillery) Control() *control.Control {
return component.Initialize(d.Core, &d.components.control, func(control *control.Control) {
func (dis *Distillery) cWeb(thread int32) *web.Web {
return component.PutComponent[*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) {
control.ResolverFile = core.PrefixConfig
control.Instances = d.Instances()
control.Instances = dis.cInstances(thread)
})
}
func (dis *Distillery) SSH() *ssh.SSH {
return component.Initialize(dis.Core, &dis.components.ssh, nil)
func (dis *Distillery) cSSH(thread int32) *ssh.SSH {
return component.PutComponent[*ssh.SSH](&dis.pool, thread, dis.Core, nil)
}
func (dis *Distillery) SQL() *sql.SQL {
return component.Initialize(dis.Core, &dis.components.sql, func(sql *sql.SQL) {
func (dis *Distillery) cSQL(thread int32) *sql.SQL {
return component.PutComponent(&dis.pool, thread, dis.Core, func(sql *sql.SQL, thread int32) {
sql.ServerURL = dis.Upstream.SQL
sql.PollContext = dis.Context()
sql.PollInterval = time.Second
})
}
func (dis *Distillery) Triplestore() *triplestore.Triplestore {
return component.Initialize(dis.Core, &dis.components.ts, func(ts *triplestore.Triplestore) {
func (dis *Distillery) cTriplestore(thread int32) *triplestore.Triplestore {
return component.PutComponent(&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
})
}
func (dis *Distillery) Instances() *instances.Instances {
return component.Initialize(dis.Core, &dis.components.instances, func(instances *instances.Instances) {
instances.SQL = dis.SQL()
instances.TS = dis.Triplestore()
func (dis *Distillery) cInstances(thread int32) *instances.Instances {
return component.PutComponent(&dis.pool, thread, dis.Core, func(instances *instances.Instances, thread int32) {
instances.SQL = dis.cSQL(thread)
instances.TS = dis.cTriplestore(thread)
})
}
func (dis *Distillery) SnapshotManager() *snapshots.Manager {
return component.Initialize(dis.Core, &dis.components.snapshots, func(snapshots *snapshots.Manager) {
snapshots.SQL = dis.SQL()
snapshots.TS = dis.Triplestore()
func (dis *Distillery) cSnapshotManager(thread int32) *snapshots.Manager {
return component.PutComponent(&dis.pool, thread, dis.Core, func(snapshots *snapshots.Manager, thread int32) {
snapshots.Instances = dis.cInstances(thread)
snapshots.Snapshotable = dis.cSnapshotable(thread)
snapshots.Backupable = dis.cBackupable(thread)
})
}
@ -90,26 +83,42 @@ func (dis *Distillery) SnapshotManager() *snapshots.Manager {
// EXTRAS COMPONENTS
//
func (dis *Distillery) ExtrasConfig() *extras.Config {
return component.Initialize(dis.Core, &dis.components.extrasConfig, nil)
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
//
func (dis *Distillery) Components() []component.Component {
func (dis *Distillery) cComponents(thread int32) []component.Component {
return []component.Component{
dis.Web(),
dis.Control(),
dis.SSH(),
dis.Triplestore(),
dis.SQL(),
dis.Instances(),
dis.SnapshotManager(),
dis.cWeb(thread),
dis.cControl(thread),
dis.cSSH(thread),
dis.cTriplestore(thread),
dis.cSQL(thread),
dis.cInstances(thread),
dis.cSnapshotManager(thread),
// extras components
dis.ExtrasConfig(),
dis.cExtrasConfig(thread),
dis.cExtrasBookkeeping(thread),
dis.cExtrasFilesystem(thread),
dis.cExtrasPathbuilders(thread),
}
}
@ -117,29 +126,28 @@ func (dis *Distillery) Components() []component.Component {
// COMPONENT SUBTYPE GETTERS
//
// Backupable returns all the components that can be backuped up.
func (dis *Distillery) Backupable() []component.Backupable {
return getComponentSubtype[component.Backupable](dis)
func (dis *Distillery) cInstallables(thread int32) []component.Installable {
return getComponentSubtype[component.Installable](dis, thread)
}
// Installables returns all components that can be installed
func (dis *Distillery) Installables() []component.Installable {
return getComponentSubtype[component.Installable](dis)
func (dis *Distillery) cUpdateable(thread int32) []component.Updatable {
return getComponentSubtype[component.Updatable](dis, thread)
}
// Installables returns all components that can be installed
func (dis *Distillery) Updateable() []component.Updatable {
return getComponentSubtype[component.Updatable](dis)
func (dis *Distillery) cBackupable(thread int32) []component.Backupable {
return getComponentSubtype[component.Backupable](dis, thread)
}
// Provisionable returns all components which can be provisioned
func (dis *Distillery) Provisionable() []component.Provisionable {
return getComponentSubtype[component.Provisionable](dis)
func (dis *Distillery) cProvisionable(thread int32) []component.Provisionable {
return getComponentSubtype[component.Provisionable](dis, thread)
}
// getComponentSubtype gets all components of type T
func getComponentSubtype[T component.Component](dis *Distillery) (components []T) {
all := dis.Components()
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) {
all := dis.cComponents(thread)
components = make([]T, 0, len(all))
for _, c := range all {

View file

@ -4,6 +4,12 @@ import (
"context"
"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/instances"
"github.com/FAU-CDI/wisski-distillery/internal/component/snapshots"
"github.com/FAU-CDI/wisski-distillery/internal/component/sql"
"github.com/FAU-CDI/wisski-distillery/internal/component/ssh"
"github.com/FAU-CDI/wisski-distillery/internal/component/triplestore"
)
// Distillery represents a WissKI Distillery
@ -34,3 +40,33 @@ type Upstream struct {
func (dis *Distillery) Context() context.Context {
return context.Background()
}
//
// PUBLIC COMPONENT GETTERS
//
func (dis *Distillery) Control() *control.Control {
return dis.cControl(dis.thread())
}
func (dis *Distillery) SSH() *ssh.SSH {
return dis.cSSH(dis.thread())
}
func (dis *Distillery) SQL() *sql.SQL {
return dis.cSQL(dis.thread())
}
func (dis *Distillery) Triplestore() *triplestore.Triplestore {
return dis.cTriplestore(dis.thread())
}
func (dis *Distillery) Instances() *instances.Instances {
return dis.cInstances(dis.thread())
}
func (dis *Distillery) SnapshotManager() *snapshots.Manager {
return dis.cSnapshotManager(dis.thread())
}
func (dis *Distillery) Installable() []component.Installable { return dis.cInstallables(dis.thread()) }
func (dis *Distillery) Updatable() []component.Updatable { return dis.cUpdateable(dis.thread()) }
func (dis *Distillery) Provisionable() []component.Provisionable {
return dis.cProvisionable(dis.thread())
}