forked from Alluxio/alluxio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add journal commands to CLI as part of Alluxio#17522 pr-link: Alluxio#17569 change-id: cid-5b23a8a36c129fc609d30fcfe5469c7ef9aefc51
- Loading branch information
Showing
6 changed files
with
221 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package journal | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"alluxio.org/cli/env" | ||
) | ||
|
||
var Backup = &BackupCommand{ | ||
BaseJavaCommand: &env.BaseJavaCommand{ | ||
CommandName: "backup", | ||
JavaClassName: "alluxio.cli.fsadmin.FileSystemAdminShell", | ||
Parameters: []string{"backup"}, | ||
}, | ||
} | ||
|
||
type BackupCommand struct { | ||
*env.BaseJavaCommand | ||
|
||
backupPath string | ||
local bool | ||
allowLeader bool | ||
bypassDelegation bool | ||
} | ||
|
||
func (c *BackupCommand) Base() *env.BaseJavaCommand { | ||
return c.BaseJavaCommand | ||
} | ||
|
||
func (c *BackupCommand) ToCommand() *cobra.Command { | ||
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{ | ||
Use: Backup.CommandName, | ||
Short: "Backup the local Alluxio master journal", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return c.Run(nil) | ||
}, | ||
}) | ||
cmd.Flags().StringVar(&c.backupPath, "path", "", "Directory to write backup file to") | ||
cmd.MarkFlagRequired("path") | ||
cmd.Flags().BoolVar(&c.local, "local", false, "If true, writes the backup file to the local filesystem instead of root UFS") | ||
cmd.Flags().BoolVar(&c.allowLeader, "allow-leader", false, "If true, allows the leader to take the backup when there are no standby masters") | ||
cmd.Flags().BoolVar(&c.bypassDelegation, "bypass-delegation", false, "If true, takes the backup on the leader even if standby masters are available") | ||
return cmd | ||
} | ||
|
||
func (c *BackupCommand) Run(_ []string) error { | ||
javaArgs := []string{c.backupPath} | ||
if c.local { | ||
javaArgs = append(javaArgs, "--local") | ||
} | ||
if c.allowLeader { | ||
javaArgs = append(javaArgs, "--allow-leader") | ||
} | ||
if c.bypassDelegation { | ||
javaArgs = append(javaArgs, "--bypass-delegation") | ||
} | ||
return c.Base().Run(javaArgs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package journal | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"alluxio.org/cli/env" | ||
) | ||
|
||
var Checkpoint = &CheckpointCommand{ | ||
BaseJavaCommand: &env.BaseJavaCommand{ | ||
CommandName: "checkpoint", | ||
JavaClassName: "alluxio.cli.fsadmin.FileSystemAdminShell", | ||
Parameters: []string{"journal", "checkpoint"}, | ||
}, | ||
} | ||
|
||
type CheckpointCommand struct { | ||
*env.BaseJavaCommand | ||
} | ||
|
||
func (c *CheckpointCommand) Base() *env.BaseJavaCommand { | ||
return c.BaseJavaCommand | ||
} | ||
|
||
func (c *CheckpointCommand) ToCommand() *cobra.Command { | ||
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{ | ||
Use: Checkpoint.CommandName, | ||
Short: "Create a checkpoint in the primary master journal system", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return c.Run(nil) | ||
}, | ||
}) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package journal | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/palantir/stacktrace" | ||
"github.com/spf13/cobra" | ||
|
||
"alluxio.org/cli/env" | ||
) | ||
|
||
var Read = &ReadCommand{ | ||
BaseJavaCommand: &env.BaseJavaCommand{ | ||
CommandName: "read", | ||
JavaClassName: "alluxio.master.journal.tool.JournalTool", | ||
UseServerClasspath: true, | ||
ShellJavaOpts: fmt.Sprintf(env.JavaOptFormat, env.ConfAlluxioLoggerType, "Console"), | ||
}, | ||
} | ||
|
||
type ReadCommand struct { | ||
*env.BaseJavaCommand | ||
|
||
end int | ||
inputDir string | ||
master string | ||
outputDir string | ||
start int | ||
} | ||
|
||
func (c *ReadCommand) Base() *env.BaseJavaCommand { | ||
return c.BaseJavaCommand | ||
} | ||
|
||
func (c *ReadCommand) ToCommand() *cobra.Command { | ||
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{ | ||
Use: Read.CommandName, | ||
Short: "Read an Alluxio journal file to a human-readable version", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return c.Run(nil) | ||
}, | ||
}) | ||
cmd.Flags().IntVar(&c.end, "end", -1, "end log sequence number (exclusive)") | ||
cmd.Flags().StringVar(&c.inputDir, "input-dir", "", "input directory on-disk to read the journal content from") | ||
cmd.Flags().StringVar(&c.master, "master", "FileSystemMaster", "name of the master class") | ||
cmd.Flags().StringVar(&c.outputDir, "output-dir", "", "output directory to write journal content to") | ||
cmd.Flags().IntVar(&c.start, "start", 0, "start log sequence number (inclusive)") | ||
return cmd | ||
} | ||
|
||
func (c *ReadCommand) Run(_ []string) error { | ||
var javaArgs []string | ||
if c.start < 0 { | ||
return stacktrace.NewError("start log sequence number must be non-negative but was %v", c.start) | ||
} | ||
if c.end < -1 { | ||
return stacktrace.NewError("end log sequence number must be non-negative but was %v", c.end) | ||
} | ||
if c.end != -1 { | ||
javaArgs = append(javaArgs, "-end", strconv.Itoa(c.end)) | ||
} | ||
if c.inputDir != "" { | ||
javaArgs = append(javaArgs, "-inputDir", c.inputDir) | ||
} | ||
if c.master != "FileSystemMaster" { | ||
javaArgs = append(javaArgs, "-master", c.master) | ||
} | ||
if c.outputDir != "" { | ||
javaArgs = append(javaArgs, "-outputDir", c.outputDir) | ||
} | ||
if c.start > 0 { | ||
javaArgs = append(javaArgs, "-start", strconv.Itoa(c.start)) | ||
} | ||
return c.Base().Run(javaArgs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters