HuangTing-Yao commented on a change in pull request #201:
URL:
https://github.com/apache/incubator-yunikorn-k8shim/pull/201#discussion_r513181165
##########
File path: Makefile
##########
@@ -153,6 +156,32 @@ adm_image: admission
docker build ./deployments/image/admission -t
${REGISTRY}/yunikorn:admission-${VERSION}
@rm -f ./deployments/image/admission/${POD_ADMISSION_CONTROLLER_BINARY}
+# Build gang web server and client binary in a production ready version
+.PHONY: gang
+gang:
Review comment:
done
##########
File path: Makefile
##########
@@ -153,6 +156,32 @@ adm_image: admission
docker build ./deployments/image/admission -t
${REGISTRY}/yunikorn:admission-${VERSION}
@rm -f ./deployments/image/admission/${POD_ADMISSION_CONTROLLER_BINARY}
+# Build gang web server and client binary in a production ready version
+.PHONY: gang
+gang:
+ @echo "building gang web client binary"
+ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
+ go build -a -o=${GANG_BIN_DIR}/${GANG_CLIENT_BINARY} -ldflags \
+ '-extldflags "-static" -X main.version=${VERSION} -X main.date=${DATE}'
\
+ -tags netgo -installsuffix netgo \
+ ./pkg/gang/gangclient
+ @echo "building gang web server binary"
+ go build -a -o=${GANG_BIN_DIR}/${GANG_SERVER_BINARY} -ldflags \
+ '-extldflags "-static" -X main.version=${VERSION} -X main.date=${DATE}'
\
+ -tags netgo -installsuffix netgo \
+ ./pkg/gang/webserver
+
+# Build gang test images based on the production ready version
+.PHONY: gang_image
Review comment:
done
##########
File path: pkg/gang/webserver/handlers.go
##########
@@ -0,0 +1,56 @@
+/*
+ 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 main
+
+import (
+ "encoding/json"
+ "log"
+ "net/http"
+
+ "github.com/gorilla/mux"
+)
+
+func writeHeader(w http.ResponseWriter) {
+ w.Header().Set("Content-Type", "application/json; charset=UTF-8")
+ w.Header().Set("Access-Control-Allow-Origin", "*")
+ w.Header().Set("Access-Control-Allow-Credentials", "true")
+ w.Header().Set("Access-Control-Allow-Methods", "GET,POST,HEAD,OPTIONS")
+ w.Header().Set("Access-Control-Allow-Headers",
"X-Requested-With,Content-Type,Accept,Origin")
+}
+
+func setTaskReady(w http.ResponseWriter, r *http.Request) {
+ writeHeader(w)
+ lock.Lock()
+ defer lock.Unlock()
+ vars := mux.Vars(r)
+ jobName := vars["jobName"]
+ jobMember[jobName]++
+ if err := json.NewEncoder(w).Encode(jobMember); err != nil {
+ log.Printf("Add task %s fail.", jobName)
Review comment:
done
##########
File path: pkg/gang/webserver/handlers.go
##########
@@ -0,0 +1,56 @@
+/*
+ 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 main
+
+import (
+ "encoding/json"
+ "log"
+ "net/http"
+
+ "github.com/gorilla/mux"
+)
+
+func writeHeader(w http.ResponseWriter) {
+ w.Header().Set("Content-Type", "application/json; charset=UTF-8")
+ w.Header().Set("Access-Control-Allow-Origin", "*")
+ w.Header().Set("Access-Control-Allow-Credentials", "true")
+ w.Header().Set("Access-Control-Allow-Methods", "GET,POST,HEAD,OPTIONS")
+ w.Header().Set("Access-Control-Allow-Headers",
"X-Requested-With,Content-Type,Accept,Origin")
+}
+
+func setTaskReady(w http.ResponseWriter, r *http.Request) {
+ writeHeader(w)
+ lock.Lock()
+ defer lock.Unlock()
+ vars := mux.Vars(r)
+ jobName := vars["jobName"]
+ jobMember[jobName]++
+ if err := json.NewEncoder(w).Encode(jobMember); err != nil {
+ log.Printf("Add task %s fail.", jobName)
+ }
+}
+
+func checkJobReady(w http.ResponseWriter, r *http.Request) {
+ writeHeader(w)
+ vars := mux.Vars(r)
+ jobName := vars["jobName"]
+ if err := json.NewEncoder(w).Encode(jobMember[jobName]); err != nil {
+ log.Printf("Check job %s Member fail", jobName)
Review comment:
done
##########
File path: pkg/gang/gangclient/gangclient.go
##########
@@ -0,0 +1,84 @@
+/*
+ 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 main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "strconv"
+ "strings"
+ "time"
+)
+
+func main() {
+ jobName := os.Getenv("jobName")
+ serviceName := os.Getenv("serviceName")
+ memberAmount, err := strconv.Atoi(os.Getenv("memberAmount"))
+ if err != nil {
+ memberAmount = 10
+ }
+ runtimeMin, err := strconv.Atoi(os.Getenv("runtimeMin"))
+ if err != nil {
+ runtimeMin = 1
+ }
+ serviceName = strings.ToUpper(serviceName) + "_SERVICE_HOST"
+ serviceIP := os.Getenv(serviceName)
+ addRequest(serviceIP, jobName)
+ // Check if we satisfy gang minMember or not every 2 second
+ for {
+ number := checkRequest(serviceIP, jobName)
+ if number >= memberAmount {
+ fmt.Println("satisfy gang minMember.")
+ fmt.Println("start to run job.")
+ time.Sleep(time.Duration(runtimeMin) * time.Minute) //
means the application start running job
+ break
+ }
+ time.Sleep(2 * time.Second)
Review comment:
done
##########
File path: pkg/gang/gangclient/gangclient.go
##########
@@ -0,0 +1,84 @@
+/*
+ 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 main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "strconv"
+ "strings"
+ "time"
+)
+
+func main() {
+ jobName := os.Getenv("jobName")
Review comment:
done
##########
File path: pkg/gang/gangclient/gangclient.go
##########
@@ -0,0 +1,84 @@
+/*
+ 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 main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "strconv"
+ "strings"
+ "time"
+)
+
+func main() {
+ jobName := os.Getenv("jobName")
+ serviceName := os.Getenv("serviceName")
+ memberAmount, err := strconv.Atoi(os.Getenv("memberAmount"))
+ if err != nil {
+ memberAmount = 10
Review comment:
done
##########
File path: pkg/gang/gangclient/gangclient.go
##########
@@ -0,0 +1,84 @@
+/*
+ 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 main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "strconv"
+ "strings"
+ "time"
+)
+
+func main() {
+ jobName := os.Getenv("jobName")
+ serviceName := os.Getenv("serviceName")
+ memberAmount, err := strconv.Atoi(os.Getenv("memberAmount"))
+ if err != nil {
+ memberAmount = 10
+ }
+ runtimeMin, err := strconv.Atoi(os.Getenv("runtimeMin"))
+ if err != nil {
+ runtimeMin = 1
Review comment:
done
##########
File path: pkg/gang/gangclient/gangclient.go
##########
@@ -0,0 +1,84 @@
+/*
+ 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 main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "strconv"
+ "strings"
+ "time"
+)
+
+func main() {
+ jobName := os.Getenv("jobName")
+ serviceName := os.Getenv("serviceName")
+ memberAmount, err := strconv.Atoi(os.Getenv("memberAmount"))
+ if err != nil {
+ memberAmount = 10
+ }
+ runtimeMin, err := strconv.Atoi(os.Getenv("runtimeMin"))
+ if err != nil {
+ runtimeMin = 1
+ }
+ serviceName = strings.ToUpper(serviceName) + "_SERVICE_HOST"
+ serviceIP := os.Getenv(serviceName)
+ addRequest(serviceIP, jobName)
+ // Check if we satisfy gang minMember or not every 2 second
+ for {
+ number := checkRequest(serviceIP, jobName)
+ if number >= memberAmount {
+ fmt.Println("satisfy gang minMember.")
+ fmt.Println("start to run job.")
+ time.Sleep(time.Duration(runtimeMin) * time.Minute) //
means the application start running job
+ break
+ }
+ time.Sleep(2 * time.Second)
+ }
+}
+
+func addRequest(ip string, jobName string) {
+ resp, err := http.Get("http://" + ip + ":8863" + "/ws/v1/add/" +
jobName)
+ if err != nil {
+ fmt.Println(err)
+ }
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ fmt.Println("Get request body fail.")
Review comment:
done
##########
File path: pkg/gang/gangclient/gangclient.go
##########
@@ -0,0 +1,84 @@
+/*
+ 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 main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "strconv"
+ "strings"
+ "time"
+)
+
+func main() {
+ jobName := os.Getenv("jobName")
+ serviceName := os.Getenv("serviceName")
+ memberAmount, err := strconv.Atoi(os.Getenv("memberAmount"))
+ if err != nil {
+ memberAmount = 10
+ }
+ runtimeMin, err := strconv.Atoi(os.Getenv("runtimeMin"))
+ if err != nil {
+ runtimeMin = 1
+ }
+ serviceName = strings.ToUpper(serviceName) + "_SERVICE_HOST"
+ serviceIP := os.Getenv(serviceName)
+ addRequest(serviceIP, jobName)
+ // Check if we satisfy gang minMember or not every 2 second
+ for {
+ number := checkRequest(serviceIP, jobName)
+ if number >= memberAmount {
+ fmt.Println("satisfy gang minMember.")
+ fmt.Println("start to run job.")
+ time.Sleep(time.Duration(runtimeMin) * time.Minute) //
means the application start running job
+ break
+ }
+ time.Sleep(2 * time.Second)
+ }
+}
+
+func addRequest(ip string, jobName string) {
+ resp, err := http.Get("http://" + ip + ":8863" + "/ws/v1/add/" +
jobName)
+ if err != nil {
+ fmt.Println(err)
+ }
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ fmt.Println("Get request body fail.")
+ }
+ fmt.Println(string(body))
+}
+
+func checkRequest(ip string, jobName string) int {
+ resp, err := http.Get("http://" + ip + ":8863" + "/ws/v1/check/" +
jobName)
+ var value int
+ if err != nil {
+ fmt.Println("Check jobMember fail.")
Review comment:
done
##########
File path: pkg/gang/gangclient/gangclient.go
##########
@@ -0,0 +1,84 @@
+/*
+ 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 main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "strconv"
+ "strings"
+ "time"
+)
+
+func main() {
+ jobName := os.Getenv("jobName")
+ serviceName := os.Getenv("serviceName")
+ memberAmount, err := strconv.Atoi(os.Getenv("memberAmount"))
+ if err != nil {
+ memberAmount = 10
+ }
+ runtimeMin, err := strconv.Atoi(os.Getenv("runtimeMin"))
+ if err != nil {
+ runtimeMin = 1
+ }
+ serviceName = strings.ToUpper(serviceName) + "_SERVICE_HOST"
+ serviceIP := os.Getenv(serviceName)
+ addRequest(serviceIP, jobName)
+ // Check if we satisfy gang minMember or not every 2 second
+ for {
+ number := checkRequest(serviceIP, jobName)
+ if number >= memberAmount {
+ fmt.Println("satisfy gang minMember.")
+ fmt.Println("start to run job.")
+ time.Sleep(time.Duration(runtimeMin) * time.Minute) //
means the application start running job
+ break
+ }
+ time.Sleep(2 * time.Second)
+ }
+}
+
+func addRequest(ip string, jobName string) {
+ resp, err := http.Get("http://" + ip + ":8863" + "/ws/v1/add/" +
jobName)
+ if err != nil {
+ fmt.Println(err)
+ }
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ fmt.Println("Get request body fail.")
+ }
+ fmt.Println(string(body))
+}
+
+func checkRequest(ip string, jobName string) int {
+ resp, err := http.Get("http://" + ip + ":8863" + "/ws/v1/check/" +
jobName)
+ var value int
+ if err != nil {
+ fmt.Println("Check jobMember fail.")
+ }
+ defer resp.Body.Close()
+ err = json.NewDecoder(resp.Body).Decode(&value)
+ if err != nil {
+ fmt.Println("Decode fail.")
Review comment:
done
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]