Added simple initial Swarm setup with scalability

This commit is contained in:
frikky
2021-11-06 03:12:14 +01:00
parent 9dd618ecfe
commit 9a9ea3358d
529 changed files with 359 additions and 116 deletions
+7 -7
View File
@@ -594,7 +594,7 @@ class AppBase:
# An attempt at decomposing coroutine results
try:
if asyncio.iscoroutine(tmp):
print("In coroutine")
self.logger.info("[DEBUG] In coroutine (2)")
async def parse_value(tmp):
value = await asyncio.gather(
tmp
@@ -605,9 +605,9 @@ class AppBase:
tmp = asyncio.run(parse_value(tmp))
else:
print("Not in coroutine")
self.logger.info("[DEBUG] Not in coroutine (2)")
except Exception as e:
print("[ERROR] Failed to parse coroutine value for old app: {e}")
self.logger.warning("[ERROR] Failed to parse coroutine value for old app: {e}")
#self.logger.info("RET from execution: %s" % ret)
new_value = tmp
@@ -2615,7 +2615,7 @@ class AppBase:
# Forcing async wait in case of old apps that use async
try:
if asyncio.iscoroutine(newres):
print("In coroutine")
self.logger.info("[DEBUG] In coroutine (1)")
async def parse_value(newres):
value = await asyncio.gather(
newres
@@ -2625,9 +2625,9 @@ class AppBase:
newres = asyncio.run(parse_value(newres))
else:
print("Not in coroutine")
self.logger.info("[DEBUG] Not in coroutine (1)")
except Exception as e:
print("[ERROR] Failed to parse coroutine value for old app: {e}")
self.logger.warning("[ERROR] Failed to parse coroutine value for old app: {e}")
self.logger.info("\n[INFO] Returned from execution with types %s" % type(newres))
#self.logger.info("\n[INFO] Returned from execution with %s of types %s" % (newres, type(newres)))#, newres)
@@ -2890,7 +2890,7 @@ class AppBase:
port = int(exposed_port)
logger.info(f"[DEBUG] Starting webserver on port {port} (same as exposed port)")
from flask import Flask, request
from waitress import serve
#from waitress import serve
flask_app = Flask(__name__)
+2
View File
@@ -797,4 +797,6 @@ func getDockerImage(resp http.ResponseWriter, request *http.Request) {
resp.Write([]byte(fmt.Sprintf(`{"success": false, "message": "Couldn't export image"}`)))
return
}
//resp.WriteHeader(200)
}
+12 -9
View File
@@ -3345,10 +3345,6 @@ func verifySwagger(resp http.ResponseWriter, request *http.Request) {
buildSwaggerApp(resp, body, user)
}
func healthCheckHandler(resp http.ResponseWriter, request *http.Request) {
fmt.Fprint(resp, "OK")
}
// Creates osfs from folderpath with a basepath as directory base
func createFs(basepath, pathname string) (billy.Filesystem, error) {
log.Printf("[INFO] MemFS base: %s, pathname: %s", basepath, pathname)
@@ -5642,10 +5638,6 @@ func initHandlers() {
log.Printf("[DEBUG] Starting Shuffle backend - initializing database connection")
//requestCache = cache.New(5*time.Minute, 10*time.Minute)
dbclient, err = datastore.NewClient(ctx, gceProject, option.WithGRPCDialOption(grpc.WithNoProxy()))
if err != nil {
log.Fatalf("[DEBUG] Database client error during init: %s", err)
}
//es := shuffle.GetEsConfig()
elasticConfig := "elasticsearch"
@@ -5653,6 +5645,15 @@ func initHandlers() {
elasticConfig = ""
}
dbclient, err = datastore.NewClient(ctx, gceProject, option.WithGRPCDialOption(grpc.WithNoProxy()))
if err != nil {
if elasticConfig == "" {
log.Fatalf("[ERROR] Database client error during init: %s. Env: SHUFFLE_ELASTIC=false", err)
} else {
log.Printf("[DEBUG] Database client error during init: %s. Here for backwards compatibility: not critical.", err)
}
}
for {
_, err = shuffle.RunInit(*dbclient, storage.Client{}, gceProject, "onprem", true, elasticConfig)
if err != nil {
@@ -5674,7 +5675,7 @@ func initHandlers() {
}
r := mux.NewRouter()
r.HandleFunc("/api/v1/_ah/health", healthCheckHandler)
r.HandleFunc("/api/v1/_ah/health", shuffle.HealthCheckHandler)
// Make user related locations
// Fix user changes with org
@@ -5805,6 +5806,8 @@ func initHandlers() {
// This is a new API that validates if a key has been seen before.
// Not sure what the best course of action is for it.
r.HandleFunc("/api/v1/environments/{key}/stop", shuffle.HandleStopExecutions).Methods("GET", "POST", "OPTIONS")
//r.HandleFunc("/api/v1/environments/{key}/rerun", shuffle.HandleRerunExecutions).Methods("GET", "POST", "OPTIONS")
r.HandleFunc("/api/v1/orgs/{orgId}/validate_app_values", shuffle.HandleKeyValueCheck).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/orgs/{orgId}/get_cache", shuffle.HandleGetCacheKey).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/orgs/{orgId}/set_cache", shuffle.HandleSetCacheKey).Methods("POST", "OPTIONS")