-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[BEAM-12971][Playground] Add java executor #15660
Conversation
type executor interface { | ||
// Validate validates executable file. | ||
// Executor interface for all executors (Java/Python/Go/SCIO) | ||
type Executor interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May we consider breaking this into three interfaces Validater
, Compiler
, and Runner
with Validate
, Compile
, and Run
methods?
// Return result of validation (true/false) and error if it occurs | ||
Validate(filePath string) (bool, error) | ||
Validate(fileName string) (bool, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just return error
? Returning nil
in this setting would perhaps mean that the validation passes? Additionally, should we have the fileName be a private property of the struct implementing the Validate method? There may be other validations of the system state where information may be needed more than just the fileName possibly.
// Return logs and error if it occurs | ||
Run(filePath string) (string, error) | ||
Run(fileName string) (string, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we look to how the https://pkg.go.dev/os/exec package designs its codebase for insight into the method signatures? The code seems to follow a configuration constructor like Command
, where the Cmd
struct stores internally what it will be executing. I wonder if it even just makes sense to have a Command method that uses the https://pkg.go.dev/os/exec package internally and returns Cmd
instead of implementing our own Run
method.
package executors | ||
|
||
// GoExecutor for Go code | ||
type GoExecutor struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to have the struct agnostic to what it is executing and have a single struct that will implement the life cycle stages - validate, compile, and run? The language specifics may be specific helpers in the configuration of this one executer struct maybe. This then questions whether even having an interface makes sense if there will be only a single struct that implements the life cycle stages.
|
||
func (javaExec *JavaExecutor) Validate(fileName string) (bool, error) { | ||
filePath := filepath.Join(javaExec.fs.GetSrcPath(), fileName) | ||
return fs_tool.CheckPathIsValid(filePath, javaExtension) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that firewall rules will prevent potential security breaches but should we consider additional redundant security checks as part of the validation? For example, pattern matching certain package imports or classes that may be used to make network calls? Should their be checks against an allowed pattern of imports? Multiple layers of security may be helpful to mitigate the risk of this application. This relates to the signature of this method suggested above in the interface section as being empty and allowing for potentially multiple and combined validations.
return nil | ||
} | ||
|
||
func (javaExec *JavaExecutor) Run(className string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above regarding the method signature. Perhaps it makes sense to have a Command method that returns a *Cmd
.
) | ||
|
||
// IsExist checks if file exists | ||
func IsExist(filePath string) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of IsExist
, may we consider the following:
func IsNotExist(filePath string) bool {
_, err := os.Stat(filePath)
return errors.Is(err, fs.ErrNotExist)
}
See https://pkg.go.dev/os#IsNotExist for details.
} | ||
|
||
// IsCorrectExtension checks if the file has correct extension (.java, .go, .py) | ||
func IsCorrectExtension(filePath string, correctExtension string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be one of the list of validators if we are using the multiple validators approach to the relevant life cycle stage?
// Return error if it occurs | ||
Compile(filePath string) error | ||
type validatorWithArgs struct { | ||
validator func(filePath string, args ...interface{}) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not blocking of the PR but I think this might be a good candidate for an interface in the future. Below is just an example.
type Validator interface {
Validate(opts ...Option) error
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add the 1. go.sum and 2. protobuf generated files (playground/backend/internal/api) to this PR?
1cd68d7
to
daca914
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pabloem LGTM
[BEAM-12971] Add java executor to compile java code in created file system environment.
Executing java code with the use of cmd executor. Use javac/java for compilation/executing the java code.
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
R: @username
).[BEAM-XXX] Fixes bug in ApproximateQuantiles
, where you replaceBEAM-XXX
with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
ValidatesRunner
compliance status (on master branch)Examples testing status on various runners
Post-Commit SDK/Transform Integration Tests Status (on master branch)
Pre-Commit Tests Status (on master branch)
See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI.