[
https://issues.apache.org/jira/browse/BEAM-13124?focusedWorklogId=700125&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-700125
]
ASF GitHub Bot logged work on BEAM-13124:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 22/Dec/21 16:38
Start Date: 22/Dec/21 16:38
Worklog Time Spent: 10m
Work Description: AydarZaynutdinov commented on a change in pull request
#16277:
URL: https://github.com/apache/beam/pull/16277#discussion_r774023127
##########
File path: playground/backend/internal/utils/system_utils.go
##########
@@ -16,14 +16,59 @@
package utils
import (
+ "beam.apache.org/playground/backend/internal/environment"
+ "beam.apache.org/playground/backend/internal/logger"
+ "net/http"
+ "os"
+ "path/filepath"
"reflect"
"runtime"
"strings"
)
+const (
+ executableFiles = "executable_files"
+)
+
// GetFuncName returns the name of the received func
func GetFuncName(i interface{}) string {
fullName := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
splitName := strings.Split(fullName, ".")
return splitName[len(splitName)-1]
}
+
+// GetReadinessFunction returns the function that checks the readiness of the
server to process a new code processing request
+func GetReadinessFunction(envs *environment.Environment) func(writer
http.ResponseWriter, request *http.Request) {
+ return func(writer http.ResponseWriter, request *http.Request) {
+ if checkNumOfTheParallelJobs(envs.ApplicationEnvs.WorkingDir(),
envs.BeamSdkEnvs.NumOfParallelJobs()) {
+ writer.WriteHeader(http.StatusOK)
+ } else {
+ writer.WriteHeader(http.StatusLocked)
+ }
+ }
+}
+
+// checkNumOfTheParallelJobs checks the number of already working code
processing.
+// It counts by the number of the
/path/to/workingDir/executable_files/{pipelineId} folders.
+// If it is equals or more than numOfParallelJobs, then returns false.
+// If it is less than numOfParallelJobs, then returns true.
+func checkNumOfTheParallelJobs(workingDir string, numOfParallelJobs int) bool {
+ // TODO add getting of dir executable_files from environments.
Review comment:
Added.
##########
File path: playground/backend/internal/utils/system_utils_test.go
##########
@@ -42,3 +45,86 @@ func TestGetFuncName(t *testing.T) {
})
}
}
+
+func Test_checkNumOfTheParallelJobs(t *testing.T) {
+ baseFileFolder := "executable_files"
+ type args struct {
+ workingDir string
+ numOfParallelJobs int
+ }
+ tests := []struct {
+ name string
+ args args
+ prepareFunc func()
+ want bool
+ }{
+ {
+ // Test case with calling checkNumOfTheParallelJobs
when there is no code processing folders.
+ // As a result, want to receive true
+ name: "there is no code processing folders",
+ args: args{
+ workingDir: "",
+ numOfParallelJobs: 0,
+ },
+ prepareFunc: func() {},
+ want: true,
+ },
+ {
+ // Test case with calling checkNumOfTheParallelJobs
when there is one code processing folder.
+ // As a result, want to receive true
+ name: "there is one code processing folder",
+ args: args{
+ workingDir: "",
+ numOfParallelJobs: 2,
+ },
+ prepareFunc: func() {
+ err :=
os.MkdirAll(filepath.Join(baseFileFolder, "1"), fs.ModePerm)
+ if err != nil {
+ panic(err)
+ }
+ },
+ want: true,
+ },
+ {
+ // Test case with calling checkNumOfTheParallelJobs
when the number of the code processing folders is equals numOfParallelJobs.
+ // As a result, want to receive false
+ name: "there is one code processing folder",
+ args: args{
+ workingDir: "",
+ numOfParallelJobs: 1,
+ },
+ prepareFunc: func() {
+ err :=
os.MkdirAll(filepath.Join(baseFileFolder, "1"), fs.ModePerm)
+ if err != nil {
+ panic(err)
+ }
+ },
+ want: false,
+ },
+ {
+ // Test case with calling checkNumOfTheParallelJobs
when the number of the code processing folders is more than numOfParallelJobs.
+ // As a result, want to receive false
+ name: "there is one code processing folder",
Review comment:
Changed.
--
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: 700125)
Time Spent: 2h 40m (was: 2.5h)
> [Playground] Create readiness endpoint
> --------------------------------------
>
> Key: BEAM-13124
> URL: https://issues.apache.org/jira/browse/BEAM-13124
> Project: Beam
> Issue Type: New Feature
> Components: beam-playground
> Reporter: Artur Khanin
> Assignee: Aydar Zaynutdinov
> Priority: P3
> Labels: beam-playground-backend, beam-playground-beta-launch,
> beam-playground-sprint-5
> Time Spent: 2h 40m
> Remaining Estimate: 0h
>
> Need to add a new endpoint to check the instance's readiness. If the instance
> is ready to receive one more code to process it this endpoint should return
> status 200, in another case, it returns some error status (423 for example).
--
This message was sent by Atlassian Jira
(v8.20.1#820001)