Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exec subcommand to CLI #17797

Merged
merged 42 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fbe7d6b
Add exec/testRun command to CLI
twalluxio Jul 18, 2023
a935eb8
Add exec/testJournalCrash command to CLI
twalluxio Jul 18, 2023
fe74f5d
Add exec/testHms command to CLI
twalluxio Jul 18, 2023
9fc2b11
Add exec/testHdfsMount command to CLI
twalluxio Jul 18, 2023
769a48c
Add exec/testUfsIO command to CLI
twalluxio Jul 18, 2023
947b6b1
Add exec/testUfs command to CLI
twalluxio Jul 18, 2023
fb4e105
Add exec/class command to CLI
twalluxio Jul 18, 2023
49bd1a8
Add exec service to CLI
twalluxio Jul 18, 2023
87bd2bb
Allow custom flags to input and read for class.go
twalluxio Jul 18, 2023
0c6f4ec
Updated class.go, solved requested change & minor updates
twalluxio Jul 18, 2023
f1ad788
removed unnecessary JavaClassName definition
twalluxio Jul 19, 2023
1fa7e3b
removed fetchValue function
twalluxio Jul 19, 2023
232e6d8
format update on imports
twalluxio Jul 19, 2023
85e453c
Update cli/src/alluxio.org/cli/cmd/exec/test_hdfs_mount.go
twalluxio Jul 19, 2023
5bc78df
omit flags
twalluxio Jul 26, 2023
1bbc8a1
Implementing MarkFlagRequired
twalluxio Jul 26, 2023
9fab0e3
throw error if path is not specified
twalluxio Jul 26, 2023
2e0a159
throw error if none of JAR, module, nor a java class is specified
twalluxio Jul 26, 2023
f6520a1
edit misleading error message
twalluxio Jul 26, 2023
e444d2c
set known default value, add dependency of flags and requried flags
twalluxio Jul 26, 2023
438e919
add flag --test
twalluxio Jul 26, 2023
9c11295
add number check
twalluxio Jul 26, 2023
616a35e
edit test names
twalluxio Jul 26, 2023
8e2177f
remove ufsIOTest, but stored test_ufsio.go for future usage
twalluxio Jul 26, 2023
69c4c96
remove test_ufsio.go
twalluxio Jul 26, 2023
c2323dd
Update cli/src/alluxio.org/cli/cmd/exec/test_hdfs_mount.go
twalluxio Jul 26, 2023
6892de0
remove error checks on cmd.MarkFlagRequired
twalluxio Jul 27, 2023
7282fa4
simplify logic in class.go
twalluxio Jul 27, 2023
122f0ba
remove checking empty for required flags
twalluxio Jul 27, 2023
a07ab77
rearrange import order
twalluxio Jul 27, 2023
b5a15e3
edit numeric flags to integer
twalluxio Jul 27, 2023
6a38ac7
Update cli/src/alluxio.org/cli/cmd/exec/test_ufs.go
twalluxio Jul 27, 2023
fbf12e5
Update cli/src/alluxio.org/cli/cmd/exec/test_hdfs_mount.go
twalluxio Jul 27, 2023
822a93e
Update cli/src/alluxio.org/cli/cmd/exec/test_hdfs_mount.go
twalluxio Jul 27, 2023
ac1b53f
Update cli/src/alluxio.org/cli/cmd/exec/test_hms.go
twalluxio Jul 27, 2023
41c23f5
Update cli/src/alluxio.org/cli/cmd/exec/test_ufs.go
twalluxio Jul 27, 2023
da09f6f
Update cli/src/alluxio.org/cli/cmd/exec/test_journal_crash.go
twalluxio Jul 27, 2023
5b369f6
fix bug in test_hdfs_mount.go
twalluxio Jul 28, 2023
997d157
remove if not expecting arguments
twalluxio Jul 28, 2023
9a7d443
add number check
twalluxio Jul 28, 2023
012ba22
move up flag --totalTime
twalluxio Jul 28, 2023
a3b691e
enforce no args
twalluxio Jul 28, 2023
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
70 changes: 70 additions & 0 deletions cli/src/alluxio.org/cli/cmd/exec/class.go
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 exec

import (
"github.com/palantir/stacktrace"
"github.com/spf13/cobra"

"alluxio.org/cli/env"
)

var Class = &ClassCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "class",
},
}

type ClassCommand struct {
*env.BaseJavaCommand
mainClass string
jarFile string
module string
}

func (c *ClassCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *ClassCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: "class",
Short: "Run the main method of an Alluxio class.",
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
cmd.Flags().StringVar(&c.jarFile, "jar", "",
"Determine a JAR file to run.")
cmd.Flags().StringVar(&c.module, "m", "",
"Determine a module to run.")
cmd.MarkFlagsMutuallyExclusive("jar", "m")
return cmd
}

func (c *ClassCommand) Run(args []string) error {
var javaArgs []string
if c.jarFile != "" {
javaArgs = append(javaArgs, "-jar", c.jarFile)
} else if c.module != "" {
javaArgs = append(javaArgs, "-m", c.module)
} else if len(args) != 0 {
c.JavaClassName = args[0]
Kai-Zhang marked this conversation as resolved.
Show resolved Hide resolved
} else {
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
return stacktrace.Propagate(nil, "None of JAR, module, nor a java class is specified")
}

if len(args) > 1 {
javaArgs = append(javaArgs, args[1:]...)
Kai-Zhang marked this conversation as resolved.
Show resolved Hide resolved
}
return c.Base().Run(javaArgs)
}
27 changes: 27 additions & 0 deletions cli/src/alluxio.org/cli/cmd/exec/exec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 exec

import "alluxio.org/cli/env"

var Service = &env.Service{
Name: "exec",
Description: "Run the main method of an Alluxio class, or end-to-end tests on an Alluxio cluster.",
Commands: []env.Command{
Class,
TestHdfsMount,
TestHms,
TestJournalCrash,
TestRun,
TestUfs,
},
}
78 changes: 78 additions & 0 deletions cli/src/alluxio.org/cli/cmd/exec/test_hdfs_mount.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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 exec

import (
"fmt"

"github.com/spf13/cobra"

"alluxio.org/cli/env"
)

var TestHdfsMount = &TestHdfsMountCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "hdfsMountTest",
JavaClassName: "alluxio.cli.ValidateHdfsMount",
ShellJavaOpts: fmt.Sprintf(env.JavaOptFormat, env.ConfAlluxioLoggerType, "Console"),
},
}

type TestHdfsMountCommand struct {
*env.BaseJavaCommand
path string
readonly bool
shared bool
option string
}

func (c *TestHdfsMountCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *TestHdfsMountCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: "hdfsMountTest",
Args: cobra.NoArgs,
Short: "Tests runs a set of validations against the given hdfs path.",
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
cmd.Flags().StringVar(&c.path, "path", "",
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
"specifies the HDFS path you want to validate.")
cmd.Flags().BoolVar(&c.readonly, "readonly", false,
"mount point is readonly in Alluxio.")
cmd.Flags().BoolVar(&c.shared, "shared", false,
"mount point is shared.")
cmd.Flags().StringVar(&c.option, "option", "",
"options associated with this mount point.")
cmd.MarkFlagRequired("path")
return cmd
}

func (c *TestHdfsMountCommand) Run(args []string) error {
var javaArgs []string
javaArgs = append(javaArgs, c.path)
if !c.readonly {
javaArgs = append(javaArgs, "--readonly")
}
if c.shared != false {
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
javaArgs = append(javaArgs, "--shared")
}
if c.option != "" {
javaArgs = append(javaArgs, "--option", c.option)
}

javaArgs = append(javaArgs, args...)
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
return c.Base().Run(javaArgs)
}
76 changes: 76 additions & 0 deletions cli/src/alluxio.org/cli/cmd/exec/test_hms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 exec

import (
"strconv"

"github.com/spf13/cobra"

"alluxio.org/cli/env"
)

var TestHms = &TestHmsCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "hiveMetastoreTest",
JavaClassName: "alluxio.cli.HmsTests",
},
}

type TestHmsCommand struct {
*env.BaseJavaCommand
metastore string
database string
tables string
socketTimeout int
}

func (c *TestHmsCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *TestHmsCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: "hiveMetastoreTest",
Short: "Test the configuration, connectivity, and permission of an existing hive metastore.",
RunE: func(cmd *cobra.Command, args []string) error {
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
return c.Run(args)
},
})
cmd.Flags().StringVarP(&c.metastore, "metastore", "m", "",
"Uri(s) to connect to hive metastore.")
cmd.Flags().StringVarP(&c.database, "database", "d", "default",
"Database to run tests against.")
cmd.Flags().StringVarP(&c.tables, "table", "t", "",
"Tables to run tests against.\n"+
"Multiple tables should be separated with comma.")
cmd.Flags().IntVarP(&c.socketTimeout, "socketTimeout", "s", -1,
"Socket timeout of hive metastore client in minutes.\n"+
"Consider increasing this if you have tables with a lot of metadata.")
cmd.MarkFlagRequired("metastore")
return cmd
}

func (c *TestHmsCommand) Run(args []string) error {
var javaArgs []string
javaArgs = append(javaArgs, "-m", c.metastore)
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
if c.database != "" {
javaArgs = append(javaArgs, "-d", c.database)
}
if c.tables != "" {
javaArgs = append(javaArgs, "-t", c.tables)
}
javaArgs = append(javaArgs, "-st", strconv.Itoa(c.socketTimeout))

javaArgs = append(javaArgs, args...)
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
return c.Base().Run(javaArgs)
}
82 changes: 82 additions & 0 deletions cli/src/alluxio.org/cli/cmd/exec/test_journal_crash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 exec

import (
"fmt"
"strconv"

"github.com/spf13/cobra"

"alluxio.org/cli/env"
)

var TestJournalCrash = &TestJournalCrashCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "journalCrashTest",
JavaClassName: "alluxio.cli.JournalCrashTest",
ShellJavaOpts: fmt.Sprintf(env.JavaOptFormat, env.ConfAlluxioLoggerType, "Console"),
},
}

type TestJournalCrashCommand struct {
*env.BaseJavaCommand
creates int
deletes int
maxAlive int
renames int
testDir string
totalTime int
}

func (c *TestJournalCrashCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *TestJournalCrashCommand) ToCommand() *cobra.Command {
cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: "journalCrashTest",
Short: "Test the Master Journal System in a crash scenario.",
RunE: func(cmd *cobra.Command, args []string) error {
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
return c.Run(args)
},
})
cmd.Flags().IntVar(&c.creates, "creates", 2,
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
"Number of Client Threads to request create operations.")
cmd.Flags().IntVar(&c.deletes, "deletes", 2,
"Number of Client Threads to request create/delete operations.")
cmd.Flags().IntVar(&c.maxAlive, "maxAlive", 5,
"The maximum time a master should ever be alive during the test, in seconds.")
cmd.Flags().IntVar(&c.renames, "renames", 2,
"Number of Client Threads to request create/rename operations.")
cmd.Flags().StringVar(&c.testDir, "testDir", "/default_tests_files",
"Test Directory on Alluxio.")
cmd.Flags().IntVar(&c.totalTime, "totalTime", 20,
"The total time to run this test, in seconds. This value should be greater than [maxAlive].")
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
return cmd
}

func (c *TestJournalCrashCommand) Run(args []string) error {
var javaArgs []string

javaArgs = append(javaArgs, "-creates", strconv.Itoa(c.creates))
javaArgs = append(javaArgs, "-deletes", strconv.Itoa(c.deletes))
javaArgs = append(javaArgs, "-maxAlive", strconv.Itoa(c.maxAlive))
javaArgs = append(javaArgs, "-renames", strconv.Itoa(c.renames))
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
if c.testDir != "" {
javaArgs = append(javaArgs, "-testDir", c.testDir)
}
javaArgs = append(javaArgs, "-totalTime", strconv.Itoa(c.totalTime))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set with group of other flags above since the order of flags doesn't matter


javaArgs = append(javaArgs, args...)
twalluxio marked this conversation as resolved.
Show resolved Hide resolved
return c.Base().Run(javaArgs)
}
Loading
Loading