Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/actioncontext/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ var (
MustLock: true,
PG: true,
}
SyncRestore = Properties{
Name: "sync_restore",
MustLock: true,
PG: true,
}
SyncResync = Properties{
Name: "sync_resync",
MustLock: true,
Expand Down
30 changes: 19 additions & 11 deletions core/datarecv/keymeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,26 @@ func (t *KeyMeta) Decode() ([]byte, error) {
}

func (t *KeyMeta) CacheFile() (string, error) {
filename := filepath.Join(rawconfig.Paths.Run, t.Path.FQN(), "key", t.Key)
err := t.CacheFileAt(filename)
if err != nil {
return "", err
}
return filename, nil
}

func (t *KeyMeta) CacheFileAt(path string) error {
ds, err := object.NewDataStore(t.Path, object.WithVolatile(true))
if !ds.Allow(t.From) {
return "", fmt.Errorf("the %s namespace is not allowed to access %s keys", t.From, t.Path)
return fmt.Errorf("the %s namespace is not allowed to access %s keys", t.From, t.Path)
}
filename := filepath.Join(rawconfig.Paths.Run, t.Path.FQN(), "key", t.Key)
dsModTime, err := t.Path.ModTime()
if err != nil {
return "", err
return err
}
kvInstall := object.KVInstall{
Required: true,
ToPath: filename,
ToPath: path,
FromPattern: t.Key,
FromStore: t.Path,
AccessControl: object.KVInstallAccessControl{
Expand All @@ -140,27 +148,27 @@ func (t *KeyMeta) CacheFile() (string, error) {
MakedirPerm: defaultSecDirPerm,
},
}
fileinfo, err := os.Stat(filename)
fileinfo, err := os.Stat(path)
if errors.Is(err, os.ErrNotExist) {
// cache file does not exist... install
if err := ds.InstallKeyTo(kvInstall); err != nil {
return "", err
return err
}
return filename, nil
return nil
} else if err != nil {
return "", err
return err
}

if fileinfo.ModTime() == dsModTime {
// cache file is up to date... serve as is
return filename, nil
return nil
}

// cache file is outdated... reinstall
if err := ds.InstallKeyTo(kvInstall); err != nil {
return "", err
return err
}
return filename, nil
return nil
}

func (t *KeyMeta) String() string {
Expand Down
1 change: 1 addition & 0 deletions core/driverdb/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
_ "github.com/opensvc/om3/v3/drivers/resiphost"
_ "github.com/opensvc/om3/v3/drivers/resiproute"
_ "github.com/opensvc/om3/v3/drivers/ressharenfs"
_ "github.com/opensvc/om3/v3/drivers/ressyncplakar"
_ "github.com/opensvc/om3/v3/drivers/ressyncrsync"
_ "github.com/opensvc/om3/v3/drivers/ressyncsymsnapvx"
_ "github.com/opensvc/om3/v3/drivers/ressyncsymsrdfs"
Expand Down
1 change: 1 addition & 0 deletions core/object/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type (
SetProvisioned(context.Context) error
SetUnprovisioned(context.Context) error
SyncFull(context.Context) error
SyncRestore(context.Context, string, string) error
SyncResync(context.Context) error
SyncSplit(context.Context) error
SyncUpdate(context.Context) error
Expand Down
28 changes: 28 additions & 0 deletions core/object/actor_sync_restore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package object

import (
"context"

"github.com/opensvc/om3/v3/core/actioncontext"
"github.com/opensvc/om3/v3/core/resource"
)

func (t *actor) SyncRestore(ctx context.Context, to, src string) error {
ctx = actioncontext.WithProps(ctx, actioncontext.SyncRestore)
if err := t.validateAction(); err != nil {
return err
}
t.setenv("sync_restore", false)
unlock, err := t.lockAction(ctx)
if err != nil {
return err
}
defer unlock()
return t.lockedSyncRestore(ctx, to, src)
}

func (t *actor) lockedSyncRestore(ctx context.Context, to, src string) error {
return t.action(ctx, func(ctx context.Context, r resource.Driver) error {
return resource.Restore(ctx, r, to, src)
})
}
20 changes: 20 additions & 0 deletions core/om/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,26 @@ func newCmdObjectInstanceSyncFull(kind string) *cobra.Command {
return cmd
}

func newCmdObjectInstanceSyncRestore(kind string) *cobra.Command {
var options commands.CmdObjectInstanceSyncRestore
cmd := &cobra.Command{
Use: "restore",
Short: "restore",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run(kind)
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
commoncmd.FlagsLock(flags, &options.OptsLock)
commoncmd.FlagsResourceSelector(cmd, &options.OptsResourceSelector)
commoncmd.FlagForce(flags, &options.Force)
flags.StringVarP(&options.To, "to", "t", "", "restore in the path given")
flags.StringVar(&options.Src, "src", "", "the source to restore")
hiddenFlagLocal(flags, &options.Local)
return cmd
}

func newCmdObjectInstanceSyncResync(kind string) *cobra.Command {
var options commands.CmdObjectInstanceSyncResync
cmd := &cobra.Command{
Expand Down
2 changes: 2 additions & 0 deletions core/om/kind_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func init() {
cmdObjectInstanceSync.AddCommand(
newCmdObjectInstanceSyncIngest(kind),
newCmdObjectInstanceSyncFull(kind),
newCmdObjectInstanceSyncRestore(kind),
newCmdObjectInstanceSyncResync(kind),
newCmdObjectInstanceSyncSplit(kind),
newCmdObjectInstanceSyncUpdate(kind),
Expand Down Expand Up @@ -180,6 +181,7 @@ func init() {
cmdObjectSync.AddCommand(
newCmdObjectInstanceSyncFull(kind),
newCmdObjectInstanceSyncIngest(kind),
newCmdObjectInstanceSyncRestore(kind),
newCmdObjectInstanceSyncResync(kind),
newCmdObjectInstanceSyncSplit(kind),
newCmdObjectInstanceSyncUpdate(kind),
Expand Down
2 changes: 2 additions & 0 deletions core/om/kind_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func init() {
cmdObjectInstanceSync.AddCommand(
newCmdObjectInstanceSyncFull(kind),
newCmdObjectInstanceSyncIngest(kind),
newCmdObjectInstanceSyncRestore(kind),
newCmdObjectInstanceSyncResync(kind),
newCmdObjectInstanceSyncSplit(kind),
newCmdObjectInstanceSyncUpdate(kind),
Expand Down Expand Up @@ -182,6 +183,7 @@ func init() {
cmdObjectSync.AddCommand(
newCmdObjectInstanceSyncFull(kind),
newCmdObjectInstanceSyncIngest(kind),
newCmdObjectInstanceSyncRestore(kind),
newCmdObjectInstanceSyncResync(kind),
newCmdObjectInstanceSyncSplit(kind),
newCmdObjectInstanceSyncUpdate(kind),
Expand Down
2 changes: 2 additions & 0 deletions core/om/kind_vol.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func init() {
cmdObjectInstanceSync.AddCommand(
newCmdObjectInstanceSyncFull(kind),
newCmdObjectInstanceSyncIngest(kind),
newCmdObjectInstanceSyncRestore(kind),
newCmdObjectInstanceSyncResync(kind),
newCmdObjectInstanceSyncSplit(kind),
newCmdObjectInstanceSyncUpdate(kind),
Expand Down Expand Up @@ -177,6 +178,7 @@ func init() {
cmdObjectSync.AddCommand(
newCmdObjectInstanceSyncFull(kind),
newCmdObjectInstanceSyncIngest(kind),
newCmdObjectInstanceSyncRestore(kind),
newCmdObjectInstanceSyncResync(kind),
newCmdObjectInstanceSyncSplit(kind),
newCmdObjectInstanceSyncUpdate(kind),
Expand Down
47 changes: 47 additions & 0 deletions core/omcmd/object_instance_sync_restore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package omcmd

import (
"context"

"github.com/opensvc/om3/v3/core/actioncontext"
"github.com/opensvc/om3/v3/core/commoncmd"
"github.com/opensvc/om3/v3/core/naming"
"github.com/opensvc/om3/v3/core/object"
"github.com/opensvc/om3/v3/core/objectaction"
)

type (
CmdObjectInstanceSyncRestore struct {
OptsGlobal
commoncmd.OptsLock
commoncmd.OptsResourceSelector
Local bool
Force bool
To string
Src string
}
)

func (t *CmdObjectInstanceSyncRestore) Run(kind string) error {
mergedSelector := commoncmd.MergeSelector("", t.ObjectSelector, kind, "")
return objectaction.New(
objectaction.WithObjectSelector(mergedSelector),
objectaction.WithRID(t.RID),
objectaction.WithTag(t.Tag),
objectaction.WithSubset(t.Subset),
objectaction.WithOutput(t.Output),
objectaction.WithColor(t.Color),
objectaction.WithIgnoreNotFound(t.IgnoreNotFound),
objectaction.WithLocal(t.Local),
objectaction.WithLocalFunc(func(ctx context.Context, p naming.Path) (interface{}, error) {
o, err := object.NewActor(p)
if err != nil {
return nil, err
}
ctx = actioncontext.WithLockDisabled(ctx, t.Disable)
ctx = actioncontext.WithLockTimeout(ctx, t.Timeout)
ctx = actioncontext.WithForce(ctx, t.Force)
return nil, o.SyncRestore(ctx, t.To, t.Src)
}),
).Do()
}
17 changes: 17 additions & 0 deletions core/ox/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2640,6 +2640,23 @@ func newCmdObjectInstanceSyncFull(kind string) *cobra.Command {
return cmd
}

func newCmdObjectInstanceSyncRestore(kind string) *cobra.Command {
var options commands.CmdObjectInstanceSyncRestore
cmd := &cobra.Command{
Use: "restore",
Short: "restore",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run(kind)
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
commoncmd.FlagsLock(flags, &options.OptsLock)
commoncmd.FlagsResourceSelector(cmd, &options.OptsResourceSelector)
commoncmd.FlagForce(flags, &options.Force)
return cmd
}

func newCmdObjectInstanceSyncResync(kind string) *cobra.Command {
var options commands.CmdObjectInstanceSyncResync
cmd := &cobra.Command{
Expand Down
1 change: 1 addition & 0 deletions core/ox/kind_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func init() {
cmdObjectInstanceSync.AddCommand(
newCmdObjectInstanceSyncIngest(kind),
newCmdObjectInstanceSyncFull(kind),
newCmdObjectInstanceSyncRestore(kind),
newCmdObjectInstanceSyncResync(kind),
newCmdObjectInstanceSyncSplit(kind),
newCmdObjectInstanceSyncUpdate(kind),
Expand Down
1 change: 0 additions & 1 deletion core/ox/kind_ccfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func init() {

root.AddCommand(
cmdObject,
commoncmd.NewCmdMonitor(),
)
cmdObject.AddGroup(
commoncmd.NewGroupOrchestratedActions(),
Expand Down
1 change: 1 addition & 0 deletions core/ox/kind_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func init() {
cmdObjectInstanceSync.AddCommand(
newCmdObjectInstanceSyncIngest(kind),
newCmdObjectInstanceSyncFull(kind),
newCmdObjectInstanceSyncRestore(kind),
newCmdObjectInstanceSyncResync(kind),
newCmdObjectInstanceSyncSplit(kind),
newCmdObjectInstanceSyncUpdate(kind),
Expand Down
1 change: 1 addition & 0 deletions core/ox/kind_vol.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func init() {
cmdObjectInstanceSync.AddCommand(
newCmdObjectInstanceSyncIngest(kind),
newCmdObjectInstanceSyncFull(kind),
newCmdObjectInstanceSyncRestore(kind),
newCmdObjectInstanceSyncResync(kind),
newCmdObjectInstanceSyncSplit(kind),
newCmdObjectInstanceSyncUpdate(kind),
Expand Down
28 changes: 28 additions & 0 deletions core/oxcmd/object_instance_sync_restore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package oxcmd

import (
"github.com/opensvc/om3/v3/core/commoncmd"
"github.com/opensvc/om3/v3/core/objectaction"
)

type (
CmdObjectInstanceSyncRestore struct {
OptsGlobal
commoncmd.OptsLock
commoncmd.OptsResourceSelector
Force bool
}
)

func (t *CmdObjectInstanceSyncRestore) Run(kind string) error {
mergedSelector := commoncmd.MergeSelector("", t.ObjectSelector, kind, "")
return objectaction.New(
objectaction.WithObjectSelector(mergedSelector),
objectaction.WithRID(t.RID),
objectaction.WithTag(t.Tag),
objectaction.WithSubset(t.Subset),
objectaction.WithOutput(t.Output),
objectaction.WithColor(t.Color),
objectaction.WithIgnoreNotFound(t.IgnoreNotFound),
).Do()
}
3 changes: 3 additions & 0 deletions core/resource/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ type (
booter interface {
Boot(ctx context.Context) error
}
restorer interface {
Restore(context.Context, string, string) error
}
resyncer interface {
Resync(context.Context) error
}
Expand Down
17 changes: 17 additions & 0 deletions core/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,23 @@ func Resync(ctx context.Context, r Driver) error {
return nil
}

func Restore(ctx context.Context, r Driver, to, src string) error {
var i any = r
s, ok := i.(restorer)
if !ok {
return ErrActionNotSupported
}
defer EvalStatus(ctx, r)
if r.IsDisabled() || r.IsActionDisabled() {
return ErrDisabled
}
Setenv(r)
if err := s.Restore(ctx, to, src); err != nil {
return err
}
return nil
}

// Split execute the resource Split function, if implemented by the driver.
func Split(ctx context.Context, r Driver) error {
var i any = r
Expand Down
Loading
Loading