Skip to content

Commit

Permalink
Restore ui (#671)
Browse files Browse the repository at this point in the history
* commit server,agents,clients, AMP Bootstrap and fixes reports (#519)

* add bootstrap feature to AMP cluster CLI (#306)

* update vendors (huge diff)

* serverless prototype (#539)

* commit server,agents,clients, AMP Bootstrap and fixes reports (#519)

* add bootstrap feature to AMP cluster CLI (#306)

* update vendors (huge diff)

* Revert "Amp version command - more useful info" (#611)

* Add functions to the ui (#605)

* KV ui (#606)

* Add functions to the ui

* add kv to ui

* bump version to 0.6.0-dev

* Added amp help command (#652)

* Included Long message in help command output

* remerge version
  • Loading branch information
generalhenry authored and qube committed Jan 12, 2017
1 parent f62f183 commit 0b18d7a
Show file tree
Hide file tree
Showing 23 changed files with 1,032 additions and 48 deletions.
6 changes: 4 additions & 2 deletions api/rpc/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package logs

import (
"encoding/json"
"strings"

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"strings"

"log"

"github.com/appcelerator/amp/config"
"github.com/appcelerator/amp/data/elasticsearch"
Expand All @@ -14,7 +17,6 @@ import (
"github.com/nats-io/go-nats-streaming"
"golang.org/x/net/context"
"gopkg.in/olivere/elastic.v3"
"log"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions cmd/adm-server/servercore/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package servercore

import (
"fmt"
"strings"
"time"

"github.com/appcelerator/amp/cmd/adm-agent/agentgrpc"
"github.com/appcelerator/amp/cmd/adm-server/servergrpc"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"strings"
"time"
)

// GetClientStream connect a bidirectionnal-stream
Expand Down
38 changes: 30 additions & 8 deletions cmd/amp-function-listener/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ package main

import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"path"
"strings"
"time"

"github.com/appcelerator/amp/api/rpc/function"
"github.com/appcelerator/amp/config"
"github.com/appcelerator/amp/data/storage"
Expand All @@ -12,13 +20,6 @@ import (
"github.com/julienschmidt/httprouter"
"github.com/nats-io/go-nats-streaming"
"golang.org/x/net/context"
"io/ioutil"
"log"
"net/http"
"os"
"path"
"strings"
"time"
)

// ## `amp-function-listener`
Expand Down Expand Up @@ -59,6 +60,27 @@ const (
listenAddr = ":80"
)

func allowCORS(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if origin := r.Header.Get("Origin"); origin != "" {
w.Header().Set("Access-Control-Allow-Origin", origin)
if r.Method == "OPTIONS" && r.Header.Get("Access-Control-Request-Method") != "" {
preflightHandler(w, r)
return
}
}
h.ServeHTTP(w, r)
})
}

func preflightHandler(w http.ResponseWriter, r *http.Request) {
headers := []string{"Content-Type", "Accept"}
w.Header().Set("Access-Control-Allow-Headers", strings.Join(headers, ","))
methods := []string{"GET", "HEAD", "POST", "PUT", "DELETE"}
w.Header().Set("Access-Control-Allow-Methods", strings.Join(methods, ","))
return
}

func main() {
log.Printf("%s (version: %s, build: %s)\n", os.Args[0], Version, Build)

Expand Down Expand Up @@ -94,7 +116,7 @@ func main() {
router.POST("/:function", Index)

log.Println("Start listening on", listenAddr)
log.Fatal(http.ListenAndServe(listenAddr, router))
log.Fatal(http.ListenAndServe(listenAddr, allowCORS(router)))
}

// Index index
Expand Down
9 changes: 5 additions & 4 deletions cmd/amp-log-worker/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package main

import (
"log"
"os"
"os/signal"
"time"

"github.com/appcelerator/amp/api/rpc/logs"
"github.com/appcelerator/amp/config"
"github.com/appcelerator/amp/data/elasticsearch"
"github.com/appcelerator/amp/pkg/nats-streaming"
"github.com/golang/protobuf/proto"
"github.com/nats-io/go-nats-streaming"
"golang.org/x/net/context"
"log"
"os"
"os/signal"
"time"
)

// build vars
Expand Down
11 changes: 11 additions & 0 deletions cmd/amp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ func main() {
})
})

// versionCmd represents the amp version
versionCmd := &cobra.Command{
Use: "version",
Short: "Display amp version",
Long: `Display amp version.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("amp (cli version: %s, build: %s)\n", Version, Build)
},
}
RootCmd.AddCommand(versionCmd)

// infoCmd represents the amp information
infoCmd := &cobra.Command{
Use: "info",
Expand Down
9 changes: 5 additions & 4 deletions cmd/ampadm/bootstrap-docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package main
import (
"bytes"
"errors"
"github.com/blang/semver"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
dockerclient "github.com/docker/docker/client"
"io/ioutil"
"net"
"net/http"
"os"
"os/exec"
"regexp"
"strings"

"github.com/blang/semver"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
dockerclient "github.com/docker/docker/client"
)

const (
Expand Down
13 changes: 7 additions & 6 deletions cmd/ampadm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ package main

import (
"fmt"
"io"
"os"
"sort"
"strings"
"text/tabwriter"
"time"

ampClient "github.com/appcelerator/amp/api/client"
"github.com/appcelerator/amp/cmd/adm-server/servergrpc"
dockerclient "github.com/docker/docker/client"
"github.com/fatih/color"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"google.golang.org/grpc"
"io"
"os"
"sort"
"strings"
"text/tabwriter"
"time"
)

const (
Expand Down
1 change: 1 addition & 0 deletions cmd/ampadm/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/appcelerator/amp/config"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/swarm"
Expand Down
5 changes: 5 additions & 0 deletions cmd/amplifier-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/appcelerator/amp/api/rpc/service"
"github.com/appcelerator/amp/api/rpc/stack"
"github.com/appcelerator/amp/api/rpc/stats"
"github.com/appcelerator/amp/api/rpc/storage"
"github.com/appcelerator/amp/api/rpc/topic"
)

Expand Down Expand Up @@ -76,6 +77,10 @@ func run() (err error) {
if err != nil {
return
}
err = storage.RegisterStorageHandlerFromEndpoint(ctx, mux, *amplifierEndpoint, opts)
if err != nil {
return
}

http.ListenAndServe(":3000", allowCORS(mux))
return
Expand Down
7 changes: 4 additions & 3 deletions examples/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"start": "node server.js",
"build": "rollup -c",
"build:watch": "npm run build -- -w",
"clean": "npm run clean:dist && rimraf node_modules",
"build:watch": "yarn build -- -w",
"clean": "yarn clean:dist && rimraf node_modules",
"clean:dist": "rimraf dist",
"lint": "eslint ./src/**"
},
Expand Down Expand Up @@ -36,7 +36,8 @@
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-svelte": "^1.2.0",
"rollup-watch": "^2.5.0",
"yamljs": "^0.2.8"
"yamljs": "^0.2.8",
"yarn": "^0.18.1"
},
"dependencies": {
"express": "^4.14.0"
Expand Down
2 changes: 2 additions & 0 deletions examples/ui/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ app.use(express.static('node_modules/codemirror/lib'))
app.use('/stacks', express.static('public'))
app.use('/topics', express.static('public'))
app.use('/stackEdit', express.static('public'))
app.use('/functions', express.static('public'))
app.use('/kv', express.static('public'))
app.use('/dist', express.static('dist'))

app.listen(3000)
24 changes: 24 additions & 0 deletions examples/ui/src/api/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default class Func {
constructor (data, api) {
this.id = data.id
this.name = data.name
this.image = data.image
this.api = api
}
async run (string) {
const base = 'http://localhost:4242/'
const path = this.id
const request = await fetch(base + path, {
method: 'POST',
body: string
}).catch(error => {
console.error(error)
throw new Error('Network error posting to ' + base + path)
})
return await request.text()
}
async remove () {
const results = await this.api.deleteJson(`function/${this.id}`)
return results
}
}
19 changes: 19 additions & 0 deletions examples/ui/src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import GrpcClient from './grpcClient'
import Stack from './stack'
import Topic from './topic'
import Func from './function'
import Storage from './storage'

export default class AmpApi extends GrpcClient {
constructor (base) {
Expand Down Expand Up @@ -37,4 +39,21 @@ export default class AmpApi extends GrpcClient {
const result = await this.postJson('topic', {topic})
return new Topic(result.topic, this)
}
async functions () {
const data = await this.getJson('function')
return data.functions ? data.functions.map(f => new Func(f, this)) : []
}
async createFunction (name, image) {
const func = {name, image}
const result = await this.postJson('function', {function: func})
return new Func(result.function, this)
}
async storageObjects () {
const data = await this.getJson('storage')
return data.list ? data.list.map(s => new Storage(s, this)) : []
}
async createStorageObject (key, val) {
const results = await this.putJson(`storage/${key}`, {val})
return new Storage(results, this)
}
}
15 changes: 15 additions & 0 deletions examples/ui/src/api/storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default class Storage {
constructor (data, api) {
this.key = data.key
this.val = data.val
this.api = api
}
async update () {
const results = await this.api.putJson(`storage/${this.key}`, {val: this.val})
return results
}
async remove () {
const results = await this.api.deleteJson(`storage/${this.key}`)
return results
}
}
Loading

0 comments on commit 0b18d7a

Please sign in to comment.