Skip to content

Commit

Permalink
Merge pull request #155 from unarxiv/dashboard
Browse files Browse the repository at this point in the history
Dashboard
  • Loading branch information
Xiaozhe Yao committed Dec 10, 2018
2 parents 6536f1a + 4003720 commit 85c6eb7
Show file tree
Hide file tree
Showing 31 changed files with 758 additions and 57 deletions.
11 changes: 10 additions & 1 deletion Makefile
Expand Up @@ -8,7 +8,10 @@ default:
@echo "\tmake publish"
test:

format:
build-arm:
cd cli && env GOOS=linux GOARCH=arm go build cli/

format-py:
autoflake -i cvpm/*.py
# autoflake -i cvpm/**/*.py

Expand All @@ -18,6 +21,9 @@ format:
yapf -i cvpm/*.py
# yapf -i cvpm/**/*.py

format-go:
gofmt -l -s -w *.go

docs:
cd docs && npm run docs:build

Expand All @@ -32,4 +38,7 @@ clean:
publish-test:
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

publish-prod:
twine upload dist/*

.PHONY: docs
3 changes: 1 addition & 2 deletions Pipfile
Expand Up @@ -13,11 +13,10 @@ toml = "*"
requests = "*"
pillow = "*"
numpy = "*"
autoflake = "*"
isort = "*"
yapf = "*"
gevent = "*"

flask-cors="*"

[requires]

Expand Down
58 changes: 58 additions & 0 deletions cli/daemon.go
Expand Up @@ -20,6 +20,7 @@ const DaemonPort = "10590"

// Definition of Running Repos
var RunningRepos []Repository
var RunningSolvers []RepoSolver
var socketServer *socketio.Server

// Struct of a Request to Run Repo
Expand All @@ -34,6 +35,10 @@ type RunRepoRequest struct {
func PostRunningRepoHandler(c *gin.Context) {
var runRepoRequest RunRepoRequest
c.BindJSON(&runRepoRequest)
log.Println(runRepoRequest.Port)
if runRepoRequest.Port == "" {
runRepoRequest.Port = findNextOpenPort(8080)
}
go runRepo(runRepoRequest.Vendor, runRepoRequest.Name, runRepoRequest.Solver, runRepoRequest.Port)
c.JSON(http.StatusOK, gin.H{
"code": "success",
Expand All @@ -46,6 +51,40 @@ func GetRunningReposHandler(c *gin.Context) {
c.JSON(http.StatusOK, RunningRepos)
}

//
func GetRunningSolversHandler(c *gin.Context) {
c.JSON(http.StatusOK, RunningSolvers)
}

func GetRunningSolversByPackageHandler(c *gin.Context) {
vendor := c.Param("vendor")
packageName := c.Param("package")
var runningSolversInPackage []RepoSolver
for _, runningSolver := range RunningSolvers {
if runningSolver.Vendor == vendor && runningSolver.Package == packageName {
runningSolversInPackage = append(runningSolversInPackage, runningSolver)
}
}
c.JSON(http.StatusOK, runningSolversInPackage)
}

// Handle Post Repos Request -> Install Package
type addRepoRequest struct {
RepoType string `json:type`
URL string `json:url`
}
func PostReposHandler(c *gin.Context) {
config := readConfig()
var _addRepoRequest addRepoRequest
c.BindJSON(&_addRepoRequest)
if (_addRepoRequest.RepoType == "git") {
InstallFromGit(_addRepoRequest.URL)
c.JSON(http.StatusOK, config.Repositories)
} else {
c.JSON(http.StatusBadRequest, config.Repositories)
}
}

// Handle Get Request -> Get All Repos
func GetReposHandler(c *gin.Context) {
config := readConfig()
Expand All @@ -59,6 +98,11 @@ func GetRepoMetaHandler(c *gin.Context) {
c.JSON(http.StatusOK, GetMetaInfo(vendor, name))
}

// Handle Get System Information
func GetSystemHandler(c *gin.Context) {
c.JSON(http.StatusOK, getSystemInfo())
}

// Handle Socket Request
func socketHandler(c *gin.Context) {
socketServer.On("connection", func(so socketio.Socket) {
Expand Down Expand Up @@ -94,6 +138,11 @@ func BeforeResponse() gin.HandlerFunc {
c.Writer.Header().Set("cvpm-version", "0.0.3@alpha")
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS")
c.Writer.Header().Set("Access-Control-Allow-Headers", "authorization, origin, content-type, accept")
if c.Request.Method == "OPTIONS" {
c.Writer.WriteHeader(http.StatusOK)
}
}
}

Expand All @@ -117,9 +166,18 @@ func runServer(port string) {
"daemon": "running",
})
})
// System Related Handlers
r.GET("/system", GetSystemHandler)
// Repo Related Routes
r.GET("/repo/meta/:vendor/:name", GetRepoMetaHandler)
r.POST("/repo/running", PostRunningRepoHandler)
r.GET("/repos", GetReposHandler)
r.GET("/repos/running", GetRunningReposHandler)

// Solver Related Routers
r.GET("/solvers/running", GetRunningSolversHandler)
r.GET("/solvers/running/:vendor/:package", GetRunningSolversByPackageHandler)
// Socket Related Routes
r.GET("/socket.io/", socketHandler)
r.POST("/socket.io/", socketHandler)
r.Handle("WS", "/socket.io/", socketHandler)
Expand Down
28 changes: 11 additions & 17 deletions cli/handler.go
Expand Up @@ -25,6 +25,12 @@ import (
"syscall"
)

// Run Repo Response Struct
type RunRepoResponse struct {
Code string `json:code`
Port string `json:port`
}

// Handle User Login
func LoginHandler(c *cli.Context) User {
reader := bufio.NewReader(os.Stdin)
Expand All @@ -51,21 +57,10 @@ func InstallHandler(c *cli.Context) {
} else {
color.Cyan("Installing to " + localFolder)
}
var repoFolder string
var repo Repository
// Download Codebase
if strings.HasPrefix(remoteURL, "https://github.com") {
repo = CloneFromGit(remoteURL, localFolder)
InstallFromGit(remoteURL)
}
repoFolder = repo.LocalFolder
// Install Dependencies
color.Cyan("Installing Dependencies... please wait patiently")
InstallDependencies(repoFolder)
color.Blue("Generating Runners")
GeneratingRunners(repoFolder)
color.Cyan("Adding to Local Configuration")
config.Repositories = addRepo(config.Repositories, repo)
writeConfig(config)
}

// Handle List
Expand Down Expand Up @@ -100,10 +95,6 @@ func RepoHandler(c *cli.Context) {
case "run":
solverstring := c.Args().Get(1)
runningPort := c.Args().Get(2)
if (runningPort == "") {
runningPort = findNextOpenPort(8080)
color.Red("No Running Port specified! Server will listen on: " + runningPort)
}
runParams := strings.Split(solverstring, "/")
color.Cyan("Running " + runParams[0] + "/" + runParams[1] + "/" + runParams[2])
requestParams := map[string]string{
Expand All @@ -112,7 +103,10 @@ func RepoHandler(c *cli.Context) {
"solver": runParams[2],
"port": runningPort,
}
ClientPost("repo/running", requestParams)
resp := ClientPost("repo/running", requestParams)
var respJson RunRepoResponse
log.Println(resp.JSON(respJson))
color.Red("No port is specified, solver will running on" + respJson.Port)
case "ps":
requestParams := map[string]string{}
ClientGet("repos", requestParams)
Expand Down
3 changes: 2 additions & 1 deletion cli/query.go
Expand Up @@ -7,7 +7,7 @@ import (
"os/user"
)

func ClientPost(endpoint string, params map[string]string) {
func ClientPost(endpoint string, params map[string]string) *grequests.Response {
url := "http://127.0.0.1:10590/" + endpoint
currentUser, err := user.Current()
if err != nil {
Expand All @@ -24,6 +24,7 @@ func ClientPost(endpoint string, params map[string]string) {
if resp.Ok != true {
log.Fatal("Bad Response from Daemon")
}
return resp
}

func ClientGet(endpoint string, params map[string]string) {
Expand Down
22 changes: 21 additions & 1 deletion cli/repository.go
Expand Up @@ -36,6 +36,13 @@ type solvers struct {
Solvers []solver
}

type RepoSolver struct {
Vendor string
Package string
SolverName string
Port string
}

func readRepos() []Repository {
configs := readConfig()
repos := configs.Repositories
Expand Down Expand Up @@ -80,7 +87,8 @@ func runRepo(Vendor string, Name string, Solver string, Port string) {
for _, file := range files {
if file.Name() == "runner_"+Solver+".py" {
existed = true
RunningRepos = append(RunningRepos, existed_repo)
RunningRepos = append(RunningRepos, Repository{Vendor, Name, Solver, Port})
RunningSolvers = append(RunningSolvers, RepoSolver{Vendor: Vendor, Package: Name, SolverName: Solver, Port: Port})
runfileFullPath := filepath.Join(existed_repo.LocalFolder, file.Name())
python([]string{runfileFullPath, Port})
}
Expand Down Expand Up @@ -157,3 +165,15 @@ func GetMetaInfo(Vendor string, Name string) RepositoryMetaInfo {
}
return repositoryMeta
}

// Install Repository from Git
func InstallFromGit(remoteURL string) {
config := readConfig()
var repo Repository
repo = CloneFromGit(remoteURL, config.Local.LocalFolder)
repoFolder := repo.LocalFolder
InstallDependencies(repoFolder)
GeneratingRunners(repoFolder)
config.Repositories = addRepo(config.Repositories, repo)
writeConfig(config)
}
30 changes: 30 additions & 0 deletions cli/system.go
@@ -0,0 +1,30 @@
package main

import (
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/mem"
)

type SystemInfo struct {
CpuName string `json:"cpu"`
Memory uint64 `json:"memory"`
Platform string `json:"platform"`
Os string `json:"os"`
PlatformVersion string `json:"platformVersion"`
}

func getSystemInfo() SystemInfo {
var systemInfo SystemInfo
v, _ := mem.VirtualMemory()
systemInfo.Memory = v.Total
platform, _ := host.Info()
systemInfo.Platform = platform.Platform
systemInfo.PlatformVersion = platform.PlatformVersion
systemInfo.Os = platform.OS

// Handle CPU
cpuInfo, _ := cpu.Info()
systemInfo.CpuName = cpuInfo[0].ModelName
return systemInfo
}
2 changes: 1 addition & 1 deletion cli/utils.go
@@ -1,11 +1,11 @@
package main

import (
"strconv"
"net"
"os"
"os/user"
"path/filepath"
"strconv"
"time"
)

Expand Down
5 changes: 5 additions & 0 deletions cvpm/server.py
Expand Up @@ -8,9 +8,14 @@
from werkzeug.datastructures import ImmutableMultiDict
from werkzeug.utils import secure_filename

# extensions
from flask_cors import CORS

logger = logging.getLogger()
logger.setLevel("INFO")

server = Flask(__name__)
CORS(server)

ALLOWED_EXTENSIONS_TRAIN = set(['zip'])
ALLOWED_EXTENSIONS_INFER = set(['jpg', 'jpeg', 'png'])
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Expand Up @@ -23,7 +23,7 @@
"vue-markdown": "2.2.4",
"vue-router": "3.0.2",
"vue-socket.io": "3.0.4",
"vuetify": "1.3.11"
"vuetify": "^1.3.12"
},
"devDependencies": {
"autoprefixer": "7.2.6",
Expand Down
45 changes: 45 additions & 0 deletions dashboard/src/components/CVPM-Actions.vue
@@ -0,0 +1,45 @@
<template>
<v-card>
<v-card-title>
<h2>Actions</h2>
</v-card-title>
<v-card-actions>
<v-btn color="indigo darken-1" outline @click="triggerDialog('test')">Test</v-btn>
</v-card-actions>
<v-dialog v-model="enableTest">
<cvpm-request
v-if="enableTest"
v-on:closeDialog="triggerDialog('test')"
:config="config"
:vendor="vendor"
:packageName="packageName"
></cvpm-request>
</v-dialog>
</v-card>
</template>

<script>
import cvpmRequest from '@/components/CVPM-Request'
export default {
data () {
return {
enableTest: false
}
},
methods: {
triggerDialog (name) {
if (name === 'test') {
this.enableTest = !this.enableTest
} else {
}
}
},
components: {
'cvpm-request': cvpmRequest
},
props: ['config', 'vendor', 'packageName']
}
</script>

<style>
</style>
6 changes: 3 additions & 3 deletions dashboard/src/components/CVPM-Git-Import.vue
Expand Up @@ -42,9 +42,9 @@
</v-expansion-panel>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="indigo darken-1" flat @click="closeDialog()">Close</v-btn>
<v-btn color="indigo darken-1" flat @click="fetchMeta()">Fetch Meta</v-btn>
<v-btn color="indigo darken-1" flat @click="save()">Install</v-btn>
<v-btn color="indigo darken-1" outline @click="closeDialog()">Close</v-btn>
<v-btn color="indigo darken-1" outline @click="fetchMeta()">Fetch Meta</v-btn>
<v-btn color="indigo darken-1" outline @click="save()">Install</v-btn>
</v-card-actions>
</v-card>
</template>
Expand Down

0 comments on commit 85c6eb7

Please sign in to comment.