You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@yunikorn.apache.org by pb...@apache.org on 2023/07/21 14:36:20 UTC
[yunikorn-k8shim] branch master updated: [YUNIKORN-1866] Cleanup pkg/simulation/gang code directory (#641)
This is an automated email from the ASF dual-hosted git repository.
pbacsko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git
The following commit(s) were added to refs/heads/master by this push:
new af94107e [YUNIKORN-1866] Cleanup pkg/simulation/gang code directory (#641)
af94107e is described below
commit af94107e28882c61595e848fd629cc6227aa6298
Author: Manikandan R <ma...@gmail.com>
AuthorDate: Fri Jul 21 16:36:07 2023 +0200
[YUNIKORN-1866] Cleanup pkg/simulation/gang code directory (#641)
Closes: #641
Signed-off-by: Peter Bacsko <pb...@cloudera.com>
---
pkg/simulation/gang/gangclient/gangclient.go | 97 ----------------------------
pkg/simulation/gang/webserver/handlers.go | 58 -----------------
pkg/simulation/gang/webserver/routes.go | 46 -------------
pkg/simulation/gang/webserver/webserver.go | 26 --------
pkg/simulation/gang/webserver/webservice.go | 76 ----------------------
5 files changed, 303 deletions(-)
diff --git a/pkg/simulation/gang/gangclient/gangclient.go b/pkg/simulation/gang/gangclient/gangclient.go
deleted file mode 100644
index 31951f47..00000000
--- a/pkg/simulation/gang/gangclient/gangclient.go
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- 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"
- "errors"
- "log"
- "net/http"
- "os"
- "strconv"
- "strings"
- "time"
-)
-
-func main() {
- jobID := os.Getenv("JOB_ID")
- if jobID == "" {
- err := errors.New("can't get the jobID from env")
- log.Fatal(err)
- }
- serviceName := os.Getenv("SERVICE_NAME")
- if serviceName == "" {
- err := errors.New("can't get the service name from env")
- log.Fatal(err)
- }
- memberAmount, err := strconv.Atoi(os.Getenv("MEMBER_AMOUNT"))
- if err != nil {
- err = errors.New("can't get the member amount from env")
- log.Fatal(err)
- }
- taskExecutionSeconds, err := strconv.Atoi(os.Getenv("TASK_EXECUTION_SECONDS"))
- if err != nil {
- err = errors.New("can't get the task execution seconds from env")
- log.Fatal(err)
- }
- serviceName = strings.ToUpper(serviceName) + "_SERVICE_HOST"
- serviceIP := os.Getenv(serviceName)
- err = addRequest(serviceIP, jobID)
- if err != nil {
- log.Fatal(err)
- }
- // Check if we satisfy gang minMember or not every 2 second
- for {
- number, err := checkRequest(serviceIP, jobID)
- if err != nil {
- log.Fatal(err)
- }
- if number >= memberAmount {
- log.Printf("satisfy gang minMember.")
- log.Printf("start to run task.")
- log.Printf("Task will run for %d min and %d sec.", taskExecutionSeconds/60, taskExecutionSeconds-((taskExecutionSeconds/60)*60))
- time.Sleep(time.Duration(taskExecutionSeconds) * time.Second)
- break
- }
- log.Printf("The ready member and expected member: %d/%d", number, memberAmount)
- time.Sleep(2 * time.Second)
- }
-}
-
-func addRequest(ip string, jobID string) error {
- _, err := http.Get("http://" + ip + ":8863" + "/ws/v1/add/" + jobID)
- if err != nil {
- return err
- }
- return nil
-}
-
-func checkRequest(ip string, jobID string) (int, error) {
- resp, err := http.Get("http://" + ip + ":8863" + "/ws/v1/check/" + jobID)
- var value int
- if err != nil {
- return -1, err
- }
- defer resp.Body.Close()
- err = json.NewDecoder(resp.Body).Decode(&value)
- if err != nil {
- return -1, err
- }
- return value, nil
-}
diff --git a/pkg/simulation/gang/webserver/handlers.go b/pkg/simulation/gang/webserver/handlers.go
deleted file mode 100644
index e394735e..00000000
--- a/pkg/simulation/gang/webserver/handlers.go
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- 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)
- jobID := vars["jobID"]
- jobMember[jobID]++
- if err := json.NewEncoder(w).Encode(jobMember); err != nil {
- log.Printf("Add task %s fail.", jobID)
- http.Error(w, err.Error(), http.StatusInternalServerError)
- }
-}
-
-func checkJobReady(w http.ResponseWriter, r *http.Request) {
- writeHeader(w)
- vars := mux.Vars(r)
- jobID := vars["jobID"]
- if err := json.NewEncoder(w).Encode(jobMember[jobID]); err != nil {
- log.Printf("Check job %s Member fail", jobID)
- http.Error(w, err.Error(), http.StatusInternalServerError)
- }
-}
diff --git a/pkg/simulation/gang/webserver/routes.go b/pkg/simulation/gang/webserver/routes.go
deleted file mode 100644
index 9f902a8e..00000000
--- a/pkg/simulation/gang/webserver/routes.go
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- 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 (
- "net/http"
-)
-
-type route struct {
- Name string
- Method string
- Pattern string
- HandlerFunc http.HandlerFunc
-}
-type routes []route
-
-var webRoutes = routes{
- route{
- "Counter",
- "GET",
- "/ws/v1/add/{jobID}",
- setTaskReady,
- },
- route{
- "Counter",
- "GET",
- "/ws/v1/check/{jobID}",
- checkJobReady,
- },
-}
diff --git a/pkg/simulation/gang/webserver/webserver.go b/pkg/simulation/gang/webserver/webserver.go
deleted file mode 100644
index f1c6f92f..00000000
--- a/pkg/simulation/gang/webserver/webserver.go
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- 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
-
-var jobMember = make(map[string]int)
-
-func main() {
- webapp := NewWebApp()
- webapp.StartWebApp()
-}
diff --git a/pkg/simulation/gang/webserver/webservice.go b/pkg/simulation/gang/webserver/webservice.go
deleted file mode 100644
index 07568318..00000000
--- a/pkg/simulation/gang/webserver/webservice.go
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- 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 (
- "context"
- "log"
- "net/http"
- "sync"
- "time"
-
- "github.com/gorilla/mux"
-)
-
-var lock sync.RWMutex
-
-type WebService struct {
- httpServer *http.Server
-}
-
-func newRouter() *mux.Router {
- router := mux.NewRouter().StrictSlash(true)
- for _, webRoute := range webRoutes {
- handler := loggingHandler(webRoute.HandlerFunc, webRoute.Name)
- router.Methods(webRoute.Method).Path(webRoute.Pattern).Name(webRoute.Name).Handler(handler)
- }
- return router
-}
-
-func loggingHandler(inner http.Handler, name string) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- start := time.Now()
- inner.ServeHTTP(w, r)
- log.Printf("%s %s %s %s", r.Method, r.RequestURI, name, time.Since(start))
- })
-}
-
-func (m *WebService) StartWebApp() {
- router := newRouter()
- m.httpServer = &http.Server{Addr: ":8863", Handler: router}
- log.Println("web-app started with port 8863")
- httpError := m.httpServer.ListenAndServe()
- if httpError != nil && httpError != http.ErrServerClosed {
- log.Println("HTTP server error.")
- }
-}
-
-func NewWebApp() *WebService {
- m := &WebService{}
- return m
-}
-
-func (m *WebService) StopWebApp() error {
- if m.httpServer != nil {
- ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
- defer cancel()
- return m.httpServer.Shutdown(ctx)
- }
- return nil
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: issues-help@yunikorn.apache.org