Skip to content

Commit

Permalink
Merge pull request #11 from weiwei04/compass-dev
Browse files Browse the repository at this point in the history
add rest api
  • Loading branch information
Wei Wei authored Aug 28, 2017
2 parents 40e6457 + 3ae17ce commit 46e887c
Show file tree
Hide file tree
Showing 34 changed files with 4,858 additions and 682 deletions.
23 changes: 0 additions & 23 deletions .idea/libraries/GOPATH__compass_.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
bootstrap:
glide install
glide update --strip-vendor
glide install --strip-vendor

build-compass:
cd cmd/compass && go build
Expand Down
3 changes: 2 additions & 1 deletion _plugin/fusion-tunnel.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
export COMPASS_ADDR=$TILLER_HOST
export COMPASS_ADDR=http://192.168.66.11:32589
export HELM_REGISTRY_ADDR=http://192.168.66.11:32588
$HELM_PLUGIN_DIR/fusion $@
1 change: 1 addition & 0 deletions cmd/compass/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN apt-get update \
&& apt-get install -y locales \
&& apt-get install -y less \
&& apt-get install -y curl \
&& apt-get install -y dnsutils \
&& dpkg-reconfigure -f noninteractive locales \
&& locale-gen C.UTF-8 \
&& /usr/sbin/update-locale LANG=C.UTF-8 \
Expand Down
103 changes: 24 additions & 79 deletions cmd/compass/compass.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,96 +2,41 @@ package main

import (
"flag"
"net"
"os"
"syscall"
//"fmt"

"time"

"os/signal"

"github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
"github.com/grpc-ecosystem/go-grpc-middleware/tags"
compassapi "github.com/weiwei04/compass/pkg/api/services/compass"
compass "github.com/weiwei04/compass/pkg/services/compass"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"google.golang.org/grpc"
tillerapi "k8s.io/helm/pkg/proto/hapi/services"
"github.com/weiwei04/compass/pkg/services/compass"
//"go.uber.org/zap"
)

var (
grpcAddr = flag.String("listen", ":8910", "address:port to listen on")
enableTracing = flag.Bool("trace", false, "enable rpc tracing")
tillerAddr = flag.String("tiller", "127.0.0.1:44134", "tiller address, default: 127.0.0.1:44134")
registryAddr = flag.String("registry", "http://helm-registry:8900", "registry address, default: http://helm-registry:8900")
grpcAddr = flag.String("rpcAddr", "127.0.0.1:8910", "address:port to listen on")
restAddr = flag.String("httpAddr", ":8911", "address:port to listen on")
//enableTracing = flag.Bool("trace", false, "enable rpc tracing")
tillerAddr = flag.String("tiller", "127.0.0.1:44134", "tiller address, default: :44134")
registryAddr = flag.String("registry", "http://helm-registry:8900", "registry address, default: http://helm-registry:8900")
mock = flag.Bool("mock", false, "enable mock, default false")
)

var count int

func main() {
flag.Parse()
runGRPCServer()
runServer()
}

func runGRPCServer() {
zapLogger, _ := zap.NewProduction()
defer zapLogger.Sync()
sugger := zapLogger.Sugar()

grpc_zap.ReplaceGrpcLogger(zapLogger)

zapOpts := []grpc_zap.Option{
grpc_zap.WithDurationField(func(duration time.Duration) zapcore.Field {
return zap.Int64("grpc.time_ns", duration.Nanoseconds())
}),
}

grpcSrv := grpc.NewServer(
grpc_middleware.WithUnaryServerChain(
grpc_ctxtags.UnaryServerInterceptor(),
grpc_zap.UnaryServerInterceptor(zapLogger, zapOpts...),
),
grpc_middleware.WithStreamServerChain(
grpc_ctxtags.StreamServerInterceptor(),
grpc_zap.StreamServerInterceptor(zapLogger, zapOpts...),
),
)
lstn, err := net.Listen("tcp", *grpcAddr)
if err != nil {
sugger.Errorf("listen on %s failed, err %s", *grpcAddr, err)
return
}

compassSrv := compass.NewCompassServer(compass.Config{
func runServer() {
//logger, err := zap.NewProduction()
//if err != nil {
// panic(fmt.Sprintf("New Logger failed, err:%s", err))
//}
config := compass.Config{
TillerAddr: *tillerAddr,
RegistryAddr: *registryAddr,
})
if err := compassSrv.Start(); err != nil {
sugger.Errorf("start compass server failed, err %s", err)
return
}
defer compassSrv.Shutdown()

compassapi.RegisterCompassServiceServer(grpcSrv, compassSrv)
tillerapi.RegisterReleaseServiceServer(grpcSrv, compassSrv)
srvErrCh := make(chan error)
go func() {
sugger.Infof("compass server start to serve")
srvErrCh <- grpcSrv.Serve(lstn)
}()

stopCh := make(chan os.Signal, 1)
signal.Notify(stopCh, syscall.SIGTERM)
signal.Notify(stopCh, syscall.SIGINT)
go func() {
<-stopCh
grpcSrv.GracefulStop()
}()

if err := <-srvErrCh; err != nil {
sugger.Infof("compass server stoped with err %s", err)
os.Exit(1)
} else {
sugger.Info("compass server stoped")
RPCAddr: *grpcAddr,
RESTAddr: *restAddr,
Mock: *mock,
//Logger: logger,
}
srv := compass.NewServer(config)
srv.Serve()
}
6 changes: 4 additions & 2 deletions cmd/fusion/fusion.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"os"

"flag"
"github.com/urfave/cli"
"github.com/weiwei04/compass/pkg/clicommands"
"os"
)

const (
Expand All @@ -15,6 +15,8 @@ const (
)

func main() {
flag.Set("logtostderr", "true")
flag.Parse()
app := cli.NewApp()
app.Name = "fusion"
app.Version = "0.0.1"
Expand Down
72 changes: 56 additions & 16 deletions glide.lock

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

48 changes: 30 additions & 18 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
package: github.com/weiwei04/compass
import:
- package: golang.org/x/net
subpackages:
- context
- package: github.com/golang/protobuf
version: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef
- package: github.com/caicloud/helm-registry
version: ~0.1.1
subpackages:
- proto
- ptypes/any
- ptypes/timestamp
- package: google.golang.org/grpc
version: 1.2.1
- package: github.com/prometheus/client_golang
version: 0.8.0
- package: k8s.io/helm
version: ~2.5.0
- package: go.uber.org/zap
version: ~1.4.1
- pkg/rest/v1
- package: github.com/grpc-ecosystem/go-grpc-middleware
subpackages:
- logging/zap
- tags
- package: github.com/urfave/cli
version: ~1.19.1
version: ~1.20.0
- package: go.uber.org/zap
version: ~1.5.0
subpackages:
- zapcore
- package: google.golang.org/grpc
version: v1.5.2
subpackages:
- metadata
- package: gopkg.in/yaml.v2
- package: github.com/caicloud/helm-registry
- package: k8s.io/helm
version: ~2.6.0
subpackages:
- pkg/chartutil
- pkg/proto/hapi/chart
- pkg/proto/hapi/services
- package: github.com/grpc-ecosystem/grpc-gateway
version: ~1.2.2
- package: golang.org/x/text
version: b19bf474d317b857955b12035d2c5acb57ce8b01
- package: golang.org/x/net
version: c8c74377599bd978aee1cf3b9b63a8634051cec2
- package: github.com/stretchr/testify
version: ~1.1.4
- package: github.com/golang/glog
Loading

0 comments on commit 46e887c

Please sign in to comment.