[
https://issues.apache.org/jira/browse/BEAM-12988?focusedWorklogId=660973&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-660973
]
ASF GitHub Bot logged work on BEAM-12988:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 06/Oct/21 14:52
Start Date: 06/Oct/21 14:52
Worklog Time Spent: 10m
Work Description: damondouglas commented on a change in pull request
#15645:
URL: https://github.com/apache/beam/pull/15645#discussion_r723348897
##########
File path: playground/backend/internal/fs_tool/fs.go
##########
@@ -0,0 +1,113 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package fs_tool
+
+import (
+ pb "beam.apache.org/playground/backend/internal/api"
+ "fmt"
+ "github.com/google/uuid"
+ "io/fs"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+)
+
+const parentBaseFileFolder = "internal"
+
+// Folder contains names of folders with executable and compiled files (/src
and /bin for java SDK)
+type Folder struct {
+ ExecutableFolder string
+ CompiledFolder string
+}
+
+// Extension contains executable and compiled files' extensions (.java and
.class for java SDK)
+type Extension struct {
+ ExecutableExtension string
+ CompiledExtension string
+}
+
+type LifeCycle struct {
+ folderGlobs *[]string
+ Folder Folder
+ Extension Extension
+ pipelineId uuid.UUID
+}
+
+// NewLifeCycle returns a corresponding LifeCycle depending on the given SDK.
+func NewLifeCycle(sdk pb.Sdk, pipelineId uuid.UUID) (*LifeCycle, error) {
+ switch sdk {
+ case pb.Sdk_SDK_JAVA:
+ return newJavaLifeCycle(pipelineId), nil
+ default:
+ return nil, fmt.Errorf("%s isn't supported now", sdk)
+ }
+}
+
+// CreateFolders creates all folder by folderGlobs.
+func (l *LifeCycle) CreateFolders() error {
+ for _, folder := range *l.folderGlobs {
+ err := os.MkdirAll(folder, fs.ModePerm)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// DeleteFolders deletes all folder by folderGlobs.
Review comment:
I imagine someone reading this in a web godoc would not know what
`folderGlobs` is because it would be hidden.
```
// DeleteFolders deletes all previously provisioned folders
```
##########
File path: playground/backend/internal/fs_tool/fs.go
##########
@@ -0,0 +1,113 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package fs_tool
+
+import (
+ pb "beam.apache.org/playground/backend/internal/api"
+ "fmt"
+ "github.com/google/uuid"
+ "io/fs"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+)
+
+const parentBaseFileFolder = "internal"
+
+// Folder contains names of folders with executable and compiled files (/src
and /bin for java SDK)
+type Folder struct {
+ ExecutableFolder string
+ CompiledFolder string
+}
+
+// Extension contains executable and compiled files' extensions (.java and
.class for java SDK)
+type Extension struct {
+ ExecutableExtension string
+ CompiledExtension string
+}
+
+type LifeCycle struct {
+ folderGlobs *[]string
Review comment:
This could be changed to:
```
folderGlobs []string
```
##########
File path: playground/backend/internal/fs_tool/fs.go
##########
@@ -0,0 +1,113 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package fs_tool
+
+import (
+ pb "beam.apache.org/playground/backend/internal/api"
+ "fmt"
+ "github.com/google/uuid"
+ "io/fs"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+)
+
+const parentBaseFileFolder = "internal"
+
+// Folder contains names of folders with executable and compiled files (/src
and /bin for java SDK)
+type Folder struct {
+ ExecutableFolder string
+ CompiledFolder string
+}
+
+// Extension contains executable and compiled files' extensions (.java and
.class for java SDK)
+type Extension struct {
+ ExecutableExtension string
+ CompiledExtension string
+}
+
+type LifeCycle struct {
+ folderGlobs *[]string
+ Folder Folder
+ Extension Extension
+ pipelineId uuid.UUID
+}
+
+// NewLifeCycle returns a corresponding LifeCycle depending on the given SDK.
+func NewLifeCycle(sdk pb.Sdk, pipelineId uuid.UUID) (*LifeCycle, error) {
+ switch sdk {
+ case pb.Sdk_SDK_JAVA:
+ return newJavaLifeCycle(pipelineId), nil
+ default:
+ return nil, fmt.Errorf("%s isn't supported now", sdk)
+ }
+}
+
+// CreateFolders creates all folder by folderGlobs.
+func (l *LifeCycle) CreateFolders() error {
+ for _, folder := range *l.folderGlobs {
+ err := os.MkdirAll(folder, fs.ModePerm)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// DeleteFolders deletes all folder by folderGlobs.
+func (l *LifeCycle) DeleteFolders() error {
+ for _, folder := range *l.folderGlobs {
+ err := os.RemoveAll(folder)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// CreateExecutableFile creates executable file (file.java for java SDK).
Review comment:
// CreateExecutableFile creates an executable file (i.e. file.java for
the Java SDK).
##########
File path: playground/backend/internal/fs_tool/fs.go
##########
@@ -0,0 +1,113 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package fs_tool
+
+import (
+ pb "beam.apache.org/playground/backend/internal/api"
+ "fmt"
+ "github.com/google/uuid"
+ "io/fs"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+)
+
+const parentBaseFileFolder = "internal"
+
+// Folder contains names of folders with executable and compiled files (/src
and /bin for java SDK)
+type Folder struct {
+ ExecutableFolder string
+ CompiledFolder string
+}
+
+// Extension contains executable and compiled files' extensions (.java and
.class for java SDK)
+type Extension struct {
+ ExecutableExtension string
+ CompiledExtension string
+}
+
+type LifeCycle struct {
+ folderGlobs *[]string
+ Folder Folder
+ Extension Extension
+ pipelineId uuid.UUID
+}
+
+// NewLifeCycle returns a corresponding LifeCycle depending on the given SDK.
+func NewLifeCycle(sdk pb.Sdk, pipelineId uuid.UUID) (*LifeCycle, error) {
+ switch sdk {
+ case pb.Sdk_SDK_JAVA:
+ return newJavaLifeCycle(pipelineId), nil
+ default:
+ return nil, fmt.Errorf("%s isn't supported now", sdk)
+ }
+}
+
+// CreateFolders creates all folder by folderGlobs.
+func (l *LifeCycle) CreateFolders() error {
+ for _, folder := range *l.folderGlobs {
+ err := os.MkdirAll(folder, fs.ModePerm)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// DeleteFolders deletes all folder by folderGlobs.
+func (l *LifeCycle) DeleteFolders() error {
+ for _, folder := range *l.folderGlobs {
+ err := os.RemoveAll(folder)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// CreateExecutableFile creates executable file (file.java for java SDK).
+func (l *LifeCycle) CreateExecutableFile(code string) (string, error) {
+ if _, err := os.Stat(l.Folder.ExecutableFolder); os.IsNotExist(err) {
+ return "", err
+ }
+
+ fileName := getFileName(l.pipelineId, l.Extension.ExecutableExtension)
+ filePath := filepath.Join(l.Folder.ExecutableFolder, fileName)
+ err := ioutil.WriteFile(filePath, []byte(code), 0600)
Review comment:
Could we use `os.WriteFile` instead of `ioutil.WriteFile`? Please see
https://golang.org/doc/go1.16#ioutil.
Also, may we hoist `0600` to the top of the file as a constant?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 660973)
Time Spent: 2h 20m (was: 2h 10m)
> Implement FileSystem service
> ----------------------------
>
> Key: BEAM-12988
> URL: https://issues.apache.org/jira/browse/BEAM-12988
> Project: Beam
> Issue Type: Sub-task
> Components: beam-playground
> Reporter: Ilya Kozyrev
> Assignee: Aydar Zaynutdinov
> Priority: P3
> Time Spent: 2h 20m
> Remaining Estimate: 0h
>
> We need to have a go module that helps us to communicate with the file system.
>
> Server and controller take code as a string, but executor requires the
> prepared folder structure on fs and Java code located in the file. For this
> purpose, we need to implement an additional module that will be responsible
> for that.
> This module should have the following functionality:
> * Take SDK in the constructor and be able to manage functionality depends on
> SDK.
> * Create directory structure on fs for specific SDK. This structure will use
> for compilation and running code.
> * Write Java code from string to file on FS
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)