Skip to content

Commit

Permalink
OAK Compact command
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Nov 29, 2024
1 parent 70f19bd commit d5bc61e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
32 changes: 32 additions & 0 deletions cmd/aem/oak.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (c *CLI) oakCmd() *cobra.Command {
Short: "Manages OAK repository",
}
cmd.AddCommand(c.oakIndexCmd())
cmd.AddCommand(c.oakCompactCmd())
return cmd
}

Expand Down Expand Up @@ -195,3 +196,34 @@ func oakIndexByFlags(cmd *cobra.Command, i pkg.Instance) (*pkg.OAKIndex, error)
}
return nil, fmt.Errorf("flag 'name' is required")
}

func (c *CLI) oakCompactCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "compact",
Short: "Compact OAK store",
Run: func(cmd *cobra.Command, args []string) {
instances, err := c.aem.InstanceManager().Some()
if err != nil {
c.Error(err)
return
}
compacted, err := pkg.InstanceProcess(c.aem, instances, func(instance pkg.Instance) (map[string]any, error) {
if err := instance.OAK().Compact(); err != nil {
return nil, err
}
return map[string]any{
OutputChanged: true,
"instance": instance,
}, nil
})
if err != nil {
c.Error(err)
return
}
c.SetOutput("compacted", compacted)
c.Changed("store compacted")
},
}
oakIndexDefineFlags(cmd)
return cmd
}
8 changes: 8 additions & 0 deletions pkg/oak.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ func NewOAK(instance *Instance) *OAK {
func (o *OAK) IndexManager() *OAKIndexManager {
return o.indexManager
}

func (o *OAK) oakRun() *OakRun {
return o.instance.manager.aem.vendorManager.oakRun
}

func (o *OAK) Compact() error {
return o.instance.manager.aem.vendorManager.oakRun.Compact(o.instance.local.Dir())
}
24 changes: 23 additions & 1 deletion pkg/oak_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ func (or OakRun) SetPassword(instanceDir string, user string, password string) e
return nil
}

func (or OakRun) StoreDir(instanceDir string) string {
return fmt.Sprintf("%s/%s", instanceDir, or.StorePath)
}

func (or OakRun) RunScript(instanceDir string, scriptFile string) error {
storeDir := fmt.Sprintf("%s/%s", instanceDir, or.StorePath)
storeDir := or.StoreDir(instanceDir)
cmd, err := or.vendorManager.javaManager.Command(
"-Djava.io.tmpdir="+pathx.Canonical(or.vendorManager.aem.baseOpts.TmpDir),
"-jar", or.JarFile(),
Expand All @@ -114,3 +118,21 @@ func (or OakRun) RunScript(instanceDir string, scriptFile string) error {
}
return nil
}

func (or OakRun) Compact(instanceDir string) error {
storeDir := or.StoreDir(instanceDir)
cmd, err := or.vendorManager.javaManager.Command(
"-Djava.io.tmpdir="+pathx.Canonical(or.vendorManager.aem.baseOpts.TmpDir),
"-jar", or.JarFile(),
"compact", storeDir,
)
if err != nil {
return err
}
bytes, err := cmd.CombinedOutput()
if err != nil {
log.Error(string(bytes))
return fmt.Errorf("cannot run Oak Run compact command for instance dir '%s': %w", instanceDir, err)
}
return nil
}

0 comments on commit d5bc61e

Please sign in to comment.