Skip to content

Commit

Permalink
Merge pull request #288 from unarxiv/xzyaoi/feat/envs-for-runner
Browse files Browse the repository at this point in the history
Xzyaoi/feat/envs for runner
  • Loading branch information
Xiaozhe Yao authored Mar 20, 2019
2 parents 33bb618 + 66942c0 commit d9ec721
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ docs:
cd docs && npm run docs:build

package:
python setup.py sdist bdist_wheel
python3 setup.py sdist bdist_wheel

clean:
rm -rf build
Expand Down
2 changes: 1 addition & 1 deletion cli/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions cli/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ You can uninstall that service by using cvpm daemon uninstall */
package main

import (
"bytes"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -229,17 +231,26 @@ func ReverseProxy(c *gin.Context) {
})
}
// the solver is running
body, err := ioutil.ReadAll(c.Request.Body)
log.Println(body)
if err != nil {
log.Println(err)
raven.CaptureErrorAndWait(err, nil)
}
target := url.URL{
Scheme: "http",
Host: "localhost:" + runningPort,
Path: "/infer",
}

director := func(req *http.Request) {
req.Host = target.Host
req.URL.Host = req.Host
req.URL.Scheme = target.Scheme
req.URL.Path = target.Path
req.Body = ioutil.NopCloser(bytes.NewBuffer(body))
}

proxy := httputil.NewSingleHostReverseProxy(&target)
proxy.Director = director
proxy.ServeHTTP(c.Writer, c.Request)
Expand All @@ -262,10 +273,13 @@ func runServer(port string) {
}
r := gin.Default()
r.Use(BeforeResponse())
r.Use(gin.Recovery())
watchLogs(socketServer)
r.Use(static.Serve("/", static.LocalFile(webuiFolder, false)))
r.Use(static.Serve("/webui", static.LocalFile(webuiFolder, false)))
r.Use(auth.InspectorStats())
r.Use(gin.Logger())
// Reverse Proxy for solvers
r.POST("/engine/solvers/:vendor/:name/:solver", ReverseProxy)
// Status Related Handlers
r.GET("/status", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
Expand All @@ -284,8 +298,6 @@ func runServer(port string) {
r.GET("/solvers/running", GetRunningSolversHandler)
r.GET("/solvers/running/:vendor/:package", GetRunningSolversByPackageHandler)
r.DELETE("/solvers/running/:vendor/:name/:solver", StopInferProcess)
// Reverse Proxy for solvers
r.POST("/engine/solvers/:vendor/:name/:solver", ReverseProxy)
// Socket Related Routes
r.GET("/socket.io/", socketHandler)
r.POST("/socket.io/", socketHandler)
Expand Down
1 change: 1 addition & 0 deletions cli/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func InputAndParseConfigContent(label string, validate promptui.ValidateFunc) st
return result
}

// ConfigHandler Handles Config Related
func ConfigHandler(c *cli.Context) {
prevConfig := readConfig()
var nextConfig CvpmConfig
Expand Down
43 changes: 43 additions & 0 deletions cli/virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
*/
package main

import (
"log"

"github.com/cvpm-contrib/database"
)

// Constants
// SUPPORTEDVIRTUALENV declares all supported virtual environment method
var SUPPORTEDVIRTUALENV = []string{"venv"}
Expand All @@ -24,6 +30,14 @@ type VirtualEnv struct {
RepositoryFolder string
}

// EnvironmentVariable declares the envs for runner to RUN
type EnvironmentVariable struct {
Key string `db:"env-Key"`
Value string `db:"env-Var"`
Vendor string `db:"env-Vendor`
PackageName string `db:"env-PackageName"`
}

func (virtualenv VirtualEnv) validate() bool {
if isStringInSlice(virtualenv.Name, SUPPORTEDVIRTUALENV) {
return true
Expand All @@ -38,3 +52,32 @@ func (virtualenv VirtualEnv) initiate() {
func (virtualenv VirtualEnv) triggerEnable() {

}

func QueryVariables(Vendor string, PackageName string) []EnvironmentVariable {
var envs []EnvironmentVariable
sess := database.GetDBInstance()
envCollection := sess.Collection("environment")
res := envCollection.Find()
err := res.All(&envs)
if err != nil {
log.Fatalf("res.All(): %q\n", err)
}
database.CloseDB(sess)
return envs
}

func AddNewEnvToPackage(Vendor string, PackageName string, Key string, Value string) {
envObject := EnvironmentVariable{
Vendor: Vendor,
PackageName: PackageName,
Key: Key,
Value: Value,
}
sess := database.GetDBInstance()
envCollection := sess.Collection("environment")
err := envCollection.InsertReturning(&envObject)
if err != nil {
panic(err)
}
database.CloseDB(sess)
}
3 changes: 2 additions & 1 deletion cvpm/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
gevent
flask
toml
psutil
psutil
pillow
2 changes: 1 addition & 1 deletion cvpm/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
server = Flask(__name__)

ALLOWED_EXTENSIONS_TRAIN = set(['zip'])
ALLOWED_EXTENSIONS_INFER = set(['jpg', 'jpeg', 'png'])
ALLOWED_EXTENSIONS_INFER = set(['jpg', 'jpeg', 'png', 'zip'])
UPLOAD_FOLDER = './temp'

server.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
Expand Down
10 changes: 9 additions & 1 deletion cvpm/utility.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from urllib.request import urlopen

from pathlib import Path
import numpy as np
import PIL.Image
import requests
Expand All @@ -13,6 +13,14 @@ def load_image_file(file, mode='RGB'):
im = im.convert(mode)
return np.array(im)

def save_image(filename,target_name):
home = str(Path.home())
assets_path = os.path.join(home, 'cvpm', 'webui','results')
target_file = os.path.join(assets_path, target_name)
if not os.path.isdir(assets_path):
os.makedirs(assets_path)
os.rename(filename, target_file)
return target_name

class Downloader(object):
def __init__(self):
Expand Down
12 changes: 8 additions & 4 deletions dashboard/src/components/CVPM-Actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ export default {
}
},
vendor: {
type: String,
default: ''
type: Array,
default: function () {
return []
}
},
packageName: {
type: String,
default: ''
type: Array,
default: function () {
return []
}
}
},
data () {
Expand Down
6 changes: 2 additions & 4 deletions dashboard/src/components/CVPM-Repo-Meta.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ export default {
},
props: {
config: {
type: Object,
default: function () {
return {}
}
type: String,
default: ''
},
dependency: {
type: String,
Expand Down
12 changes: 8 additions & 4 deletions dashboard/src/components/CVPM-Repo-Solver.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ export default {
}
},
vendor: {
type: String,
default: ''
type: Array,
default: function () {
return []
}
},
packageName: {
type: String,
default: ''
type: Array,
default: function () {
return []
}
}
},
data () {
Expand Down
6 changes: 6 additions & 0 deletions dashboard/src/components/CVPM-Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export default {
loading: {
type: Boolean,
default: false
},
items: {
type: Array,
default: function () {
return []
}
}
},
data () {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/components/basic/CVPM-Image-Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ref="uploadInput"
type="file"
name="file"
accept="image/*"
accept="*"
:multiple="false"
@change="uploadFile($event)"
>
Expand Down
12 changes: 8 additions & 4 deletions dashboard/src/components/basic/CVPM-Solver-Selection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ export default {
}
},
vendor: {
type: String,
default: ''
type: Array,
default: function () {
return []
}
},
packageName: {
type: String,
default: ''
type: Array,
default: function () {
return []
}
}
},
data () {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/pages/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default {
return {
readme: '',
config: '',
parsedConfig: '',
parsedConfig: {},
diskSize: '',
dependency: '',
messageList: []
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/services/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SystemService {
for (let i = 0; i < parameters.length; i++) {
payload.append(parameters[i].key, parameters[i].value)
}
axios.post(this.endpoint + '/solvers/' + vendor + '/' + packageName + '/' + solver, payload).then(function (res) {
axios.post(this.endpoint + '/engine/solvers/' + vendor + '/' + packageName + '/' + solver, payload).then(function (res) {
resolve(res)
}).catch(function (err) {
reject(err)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setuptools.setup(
name="cvpm",
version="0.0.2.1",
version="0.0.2.4",
author="Xiaozhe Yao",
author_email="xiaozhe.yaoi@gmail.com",
description="Computer Vision Package Manager",
Expand Down
16 changes: 16 additions & 0 deletions templates/runner.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#coding:utf-8
import os
import argparse
import sys
os.chdir(sys.path[0])

parser = argparse.ArgumentParser(description='CVPM Runner')
parser.add_argument('port', type=int, help='Listening on Port')

args = parser.parse_args()

from {{Package}}.{{Filename}} import {{Classname}}

solver = {{Classname}}()

solver.start(args.port)

0 comments on commit d9ec721

Please sign in to comment.