Skip to content

Commit

Permalink
add stop infer engine method in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermi committed Feb 3, 2019
1 parent 4049794 commit 333f763
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cli/daemon.go
Expand Up @@ -160,6 +160,41 @@ func BeforeResponse() gin.HandlerFunc {
}
}

// Delete Running Solver Process
func StopInferProcess(c *gin.Context) {
vendor := c.Param("vendor")
name := c.Param("name")
solver := c.Param("solver")
var runningPort string
for _, runningSolver := range RunningSolvers {
if runningSolver.Vendor == vendor && runningSolver.Package == name && runningSolver.SolverName == solver {
runningPort = runningSolver.Port
}
}
// if the solver is not found
if runningPort == "" {
c.JSON(http.StatusNotFound, gin.H{
"error": "404",
"info": "Solver Not Running, if you want to force it running, please attach a force=true in your request body",
"help": "https://cvpm.autoai.org",
})
}
stopReturnValue := StopInferEngine(runningPort)
if !stopReturnValue {
c.JSON(http.StatusForbidden, gin.H{
"error": "403",
"info": "Bad request from the infer engine",
"help": "https://cvpm.autoai.org",
})
} else {
c.JSON(http.StatusOK, gin.H{
"error": "200",
"info": "Successfully stopped",
"help": "https://cvpm.autoai.org",
})
}
}

// Reverse Proxy for Calling Solvers and return real results
func ReverseProxy(c *gin.Context) {
vendor := c.Param("vendor")
Expand Down Expand Up @@ -232,6 +267,7 @@ func runServer(port string) {
// Solver Related Routers
r.GET("/solvers/running", GetRunningSolversHandler)
r.GET("/solvers/running/:vendor/:package", GetRunningSolversByPackageHandler)
r.DELETE("/solvers/:vendor/:name/:solver", StopInferProcess)
// Reverse Proxy for solvers
r.POST("/solvers/:vendor/:name/:solver", ReverseProxy)
// Socket Related Routes
Expand Down
3 changes: 3 additions & 0 deletions cli/process.go
Expand Up @@ -2,6 +2,9 @@
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.

// This file (process.go) handles two things:
// 1. Shell Command, like Python/Pip.
// 2. Daemon Process, typically goroutine.
package main

import (
Expand Down
13 changes: 13 additions & 0 deletions cli/query.go
Expand Up @@ -49,3 +49,16 @@ func ClientGet(endpoint string, params map[string]string) {
log.Fatal("Bad Response from Daemon")
}
}

func StopInferEngine(port string) bool {
url := "http://127.0.0.1:" + port + "/"
resp, err := grequests.Get(url, &grequests.RequestOptions{})
if err != nil {
log.Fatal(err)
}
if resp.Ok != true {
log.Fatal("Bad Response from Infer Engine")
return false
}
return true
}
4 changes: 4 additions & 0 deletions cvpm/server.py
Expand Up @@ -96,6 +96,10 @@ def train():
else:
return json.dumps({"error": "not supported!", "code": "404"}), 404

@server.route("/exit", methods=["GET"])
def exit_server():
# Exit under request
exit()

def run_server(solver, port=None):
if port is None:
Expand Down

0 comments on commit 333f763

Please sign in to comment.