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

[BEAM-12971][Playground] Add java executor #15660

Merged
merged 1 commit into from
Oct 14, 2021

Conversation

daria-malkova
Copy link
Contributor

@daria-malkova daria-malkova commented Oct 5, 2021

[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:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

ValidatesRunner compliance status (on master branch)

Lang ULR Dataflow Flink Samza Spark Twister2
Go --- Build Status Build Status Build Status Build Status ---
Java Build Status Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Python --- Build Status
Build Status
Build Status
Build Status
Build Status
Build Status Build Status ---
XLang Build Status Build Status Build Status Build Status Build Status ---

Examples testing status on various runners

Lang ULR Dataflow Flink Samza Spark Twister2
Go --- --- --- --- --- --- ---
Java --- Build Status
Build Status
Build Status
--- --- --- --- ---
Python --- --- --- --- --- --- ---
XLang --- --- --- --- --- --- ---

Post-Commit SDK/Transform Integration Tests Status (on master branch)

Go Java Python
Build Status Build Status Build Status
Build Status
Build Status

Pre-Commit Tests Status (on master branch)

--- Java Python Go Website Whitespace Typescript
Non-portable Build Status
Build Status
Build Status
Build Status
Build Status
Build Status Build Status Build Status Build Status
Portable --- Build Status Build Status --- --- ---

See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests

See CI.md for more information about GitHub Actions CI.

@daria-malkova daria-malkova changed the title [BEAM-12971] Add java executor to compile java code [BEAM-12971][Playground] Add java executor Oct 5, 2021
@daria-malkova
Copy link
Contributor Author

R: @pabloem @damondouglas

type executor interface {
// Validate validates executable file.
// Executor interface for all executors (Java/Python/Go/SCIO)
type Executor interface {
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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{}
Copy link
Contributor

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)
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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 {
Copy link
Contributor

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?

@daria-malkova daria-malkova changed the title [BEAM-12971][Playground] Add java executor WIP:[BEAM-12971][Playground] Add java executor Oct 6, 2021
@daria-malkova daria-malkova changed the title WIP:[BEAM-12971][Playground] Add java executor [BEAM-12971][Playground] Add java executor Oct 6, 2021
// Return error if it occurs
Compile(filePath string) error
type validatorWithArgs struct {
validator func(filePath string, args ...interface{}) error
Copy link
Contributor

@damondouglas damondouglas Oct 7, 2021

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
}

Copy link
Contributor

@damondouglas damondouglas left a 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?

Copy link
Contributor

@damondouglas damondouglas left a comment

Choose a reason for hiding this comment

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

@pabloem LGTM

@pabloem pabloem merged commit 22edf27 into apache:master Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants