env: Move each component into a separate struct
This commit cleans up the distillery code by making each component a distinct struct. Each of these components is also returned by by a new Component() function that replaces the Stacks() function.
This commit is contained in:
parent
2a14d93d3c
commit
09431c4869
16 changed files with 265 additions and 148 deletions
|
|
@ -156,7 +156,7 @@ func (bi backupInstance) makeSnapshot(context wisski_distillery.Context, path st
|
|||
defer nquads.Close()
|
||||
|
||||
// TODO: Add a progress bar?
|
||||
_, err = dis.TriplestoreBackup(nquads, instance.GraphDBRepository)
|
||||
_, err = dis.Triplestore().Backup(nquads, instance.GraphDBRepository)
|
||||
return err
|
||||
}, context.IOStream, "Backing up Triplestore"); err != nil {
|
||||
return errBackupFailed.Wrap(err)
|
||||
|
|
@ -175,7 +175,7 @@ func (bi backupInstance) makeSnapshot(context wisski_distillery.Context, path st
|
|||
defer sql.Close()
|
||||
|
||||
// TODO: Add a progress bar?
|
||||
return dis.SQLBackup(context.IOStream, sql, instance.SqlDatabase)
|
||||
return dis.SQL().Backup(context.IOStream, sql, instance.SqlDatabase)
|
||||
}, context.IOStream, "Backing up Triplestore"); err != nil {
|
||||
return errBackupFailed.Wrap(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ func (mma makeMysqlAccount) Run(context wisski_distillery.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
code, err := context.Environment.SQLShell(context.IOStream, "-e", query)
|
||||
code, err := context.Environment.SQL().OpenShell(context.IOStream, "-e", query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ func (mysql) Description() wisski_distillery.Description {
|
|||
}
|
||||
|
||||
func (ms mysql) Run(context wisski_distillery.Context) error {
|
||||
code, err := context.Environment.SQLShell(context.IOStream, ms.Positionals.Args...)
|
||||
code, err := context.Environment.SQL().OpenShell(context.IOStream, ms.Positionals.Args...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ func (upc updateprefixconfig) Run(context wisski_distillery.Context) error {
|
|||
return errPrefixUpdateFailed.WithMessageF(err)
|
||||
}
|
||||
|
||||
target := dis.ResolverPrefixConfig()
|
||||
resolver := dis.Resolver()
|
||||
target := resolver.ConfigPath()
|
||||
|
||||
// print the configuration
|
||||
config, err := os.OpenFile(target, os.O_WRONLY, fs.ModePerm)
|
||||
|
|
@ -69,7 +70,7 @@ func (upc updateprefixconfig) Run(context wisski_distillery.Context) error {
|
|||
|
||||
// and restart the resolver to apply the config!
|
||||
logging.LogMessage(context.IOStream, "restarting resolver stack")
|
||||
if err := dis.ResolverStack().Restart(context.IOStream); err != nil {
|
||||
if err := resolver.Stack().Restart(context.IOStream); err != nil {
|
||||
return errPrefixUpdateFailed.WithMessageF(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func (p provision) Run(context wisski_distillery.Context) error {
|
|||
|
||||
// create the sql
|
||||
if err := logging.LogOperation(func() error {
|
||||
if err := dis.SQLProvision(instance.SqlDatabase, instance.SqlUser, instance.SqlPassword); err != nil {
|
||||
if err := dis.SQL().Provision(instance.SqlDatabase, instance.SqlUser, instance.SqlPassword); err != nil {
|
||||
return errProvisionGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ func (p provision) Run(context wisski_distillery.Context) error {
|
|||
|
||||
// create the triplestore
|
||||
if err := logging.LogOperation(func() error {
|
||||
if err := dis.TriplestoreProvision(instance.GraphDBRepository, instance.Domain(), instance.GraphDBUser, instance.GraphDBPassword); err != nil {
|
||||
if err := dis.Triplestore().Provision(instance.GraphDBRepository, instance.Domain(), instance.GraphDBUser, instance.GraphDBPassword); err != nil {
|
||||
return errProvisionGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
11
cmd/purge.go
11
cmd/purge.go
|
|
@ -77,14 +77,15 @@ func (p purge) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// remove the triplestore
|
||||
ts := dis.Triplestore()
|
||||
logging.LogOperation(func() error {
|
||||
logging.LogMessage(context.IOStream, "Removing user %s", instance.GraphDBUser)
|
||||
if err := dis.TriplestorePurgeUser(instance.GraphDBUser); err != nil {
|
||||
if err := ts.PurgeUser(instance.GraphDBUser); err != nil {
|
||||
context.EPrintln(err)
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Removing repository %s", instance.GraphDBRepository)
|
||||
if err := dis.TriplestorePurgeRepo(instance.GraphDBRepository); err != nil {
|
||||
if err := ts.PurgeRepo(instance.GraphDBRepository); err != nil {
|
||||
context.EPrintln(err)
|
||||
}
|
||||
|
||||
|
|
@ -93,13 +94,15 @@ func (p purge) Run(context wisski_distillery.Context) error {
|
|||
|
||||
// remove the sql
|
||||
logging.LogOperation(func() error {
|
||||
sql := dis.SQL()
|
||||
|
||||
logging.LogMessage(context.IOStream, "Removing user %s", instance.SqlUser)
|
||||
if err := dis.SQLPurgeUser(instance.SqlUser); err != nil {
|
||||
if err := sql.PurgeUser(instance.SqlUser); err != nil {
|
||||
context.EPrintln(err)
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Removing database %s", instance.SqlDatabase)
|
||||
if err := dis.SQLPurgeDatabase(instance.SqlDatabase); err != nil {
|
||||
if err := sql.PurgeUser(instance.SqlDatabase); err != nil {
|
||||
context.EPrintln(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -122,16 +122,17 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
if err := logging.LogOperation(func() error {
|
||||
for _, stack := range dis.Stacks() {
|
||||
for _, component := range dis.Components() {
|
||||
stack := component.Stack()
|
||||
if err := logging.LogOperation(func() error {
|
||||
return stack.Install(context.IOStream, ctx)
|
||||
}, context.IOStream, "Installing docker stack %q", stack.Dir); err != nil {
|
||||
}, context.IOStream, "Installing docker stack %q", component.Name()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := logging.LogOperation(func() error {
|
||||
return stack.Update(context.IOStream, true)
|
||||
}, context.IOStream, "Updating docker stack %q", stack.Dir); err != nil {
|
||||
}, context.IOStream, "Updating docker stack %q", component.Name()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -149,13 +150,13 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
if err := logging.LogOperation(func() error {
|
||||
return dis.SQLBootstrap(context.IOStream)
|
||||
return dis.SQL().Bootstrap(context.IOStream)
|
||||
}, context.IOStream, "Bootstraping SQL database"); err != nil {
|
||||
return errBootstrapSQL.WithMessageF(err)
|
||||
}
|
||||
|
||||
if err := logging.LogOperation(func() error {
|
||||
return dis.TriplestoreBootstrap(context.IOStream)
|
||||
return dis.Triplestore().Bootstrap(context.IOStream)
|
||||
}, context.IOStream, "Bootstraping Triplestore"); err != nil {
|
||||
return errBootstrapTriplestore.WithMessageF(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue