Skip to content

Commit

Permalink
Deactivate bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Apr 9, 2024
1 parent 2a45db8 commit bb06ddf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
10 changes: 5 additions & 5 deletions cmd/aem/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func (c *CLI) replCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "replication",
Short: "Manage replication (agents)",
Short: "Replicate nodes and manage agents",
Aliases: []string{"repl"},
}
cmd.AddCommand(c.replAgentCmd())
Expand Down Expand Up @@ -76,9 +76,9 @@ func (c *CLI) replDeactivateCmd() *cobra.Command {

func (c *CLI) replActivateTreeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "activate-tree",
Use: "tree",
Short: "Activate node and all its children",
Aliases: []string{"atr", "replicate-tree", "rtr"},
Aliases: []string{"activate-tree", "tree-activate"},
Run: func(cmd *cobra.Command, args []string) {
instance, err := c.aem.InstanceManager().One()
if err != nil {
Expand All @@ -105,13 +105,13 @@ func (c *CLI) replActivateTreeCmd() *cobra.Command {
}

c.SetOutput("path", startPath)
c.Ok("path activated")
c.Ok("tree activated")
},
}
cmd.Flags().StringP("path", "p", "", "Path to node")
_ = cmd.MarkFlagRequired("path")
cmd.Flags().Bool("only-modified", false, "Only activate modified nodes")
cmd.Flags().Bool("dry-run", false, "Only simulate activation")
cmd.Flags().Bool("only-modified", false, "Only activate modified nodes")
cmd.Flags().Bool("only-activated", false, "Only activate nodes that are not activated")
cmd.Flags().Bool("ignore-deactivated", false, "Ignore deactivated nodes")

Expand Down
24 changes: 21 additions & 3 deletions pkg/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pkg
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/cast"
"github.com/wttech/aemc/pkg/replication"
"github.com/wttech/aemc/pkg/sling"
"io"
Expand Down Expand Up @@ -43,7 +44,7 @@ func (r Replication) Activate(path string) error {

func (r Replication) Deactivate(path string) error {
log.Infof("%s > deactivating path '%s'", r.instance.IDColor(), path)
if err := r.replicate("activate", path); err != nil {
if err := r.replicate("deactivate", path); err != nil {
return err
}
log.Infof("%s > deactivated path '%s'", r.instance.IDColor(), path)
Expand Down Expand Up @@ -79,8 +80,25 @@ func (r Replication) replicate(cmd string, path string) error {
func (r Replication) ActivateTree(opts replication.ActivateTreeOpts) error {
log.Infof("%s > activating tree at path '%s'", r.instance.IDColor(), opts.StartPath)

// TODO implement it; handle flags 'only-modified', 'only-activated', 'dry-run', 'ignore-deactivated'

cmd := "activate"
if opts.DryRun {
cmd = "dryrun"
}
response, err := r.instance.http.Request().
SetFormData(map[string]string{
"cmd": cmd,
"path": opts.StartPath,
"onlymodified": cast.ToString(opts.OnlyModified),
"reactivate": cast.ToString(opts.OnlyActivated),
"ignoredeactivated": cast.ToString(opts.IgnoreDeactivated),
"__charset__": "UTF-8",
}).
Post(replication.ActivateTreePath)
if err != nil {
return fmt.Errorf("%s > cannot activate tree at path '%s': %w", r.instance.IDColor(), opts.StartPath, err)
} else if response.IsError() {
return fmt.Errorf("%s > cannot activate tree at path: %s: %s", r.instance.IDColor(), opts.StartPath, response.Status())
}
log.Infof("%s > activated tree at path '%s'", r.instance.IDColor(), opts.StartPath)
return nil
}
1 change: 1 addition & 0 deletions pkg/replication/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package replication

const (
ReplicateJsonPath = "/bin/replicate.json"
ActivateTreePath = "/libs/replication/treeactivation.html"
)

type ActivateTreeOpts struct {
Expand Down

0 comments on commit bb06ddf

Please sign in to comment.