Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Change server arguments #96

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions cmd/blast/dispatcher_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"os/signal"
"syscall"

"github.com/mosuka/blast/config"
"github.com/mosuka/blast/dispatcher"
"github.com/mosuka/blast/logutils"
"github.com/urfave/cli"
Expand Down Expand Up @@ -80,19 +79,7 @@ func dispatcherStart(c *cli.Context) error {
httpLogCompress,
)

// create cluster config
clusterConfig := config.DefaultClusterConfig()
if managerAddr != "" {
clusterConfig.ManagerAddr = managerAddr
}

// create node config
nodeConfig := &config.NodeConfig{
GRPCAddr: grpcAddr,
HTTPAddr: httpAddr,
}

svr, err := dispatcher.NewServer(clusterConfig, nodeConfig, logger, grpcLogger, httpAccessLogger)
svr, err := dispatcher.NewServer(managerAddr, grpcAddr, httpAddr, logger, grpcLogger, httpAccessLogger)
if err != nil {
return err
}
Expand Down
25 changes: 0 additions & 25 deletions config/cluster_config.go

This file was deleted.

76 changes: 0 additions & 76 deletions config/cluster_config_test.go

This file was deleted.

57 changes: 0 additions & 57 deletions config/node_config.go

This file was deleted.

54 changes: 0 additions & 54 deletions config/node_config_test.go

This file was deleted.

2 changes: 0 additions & 2 deletions dispatcher/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type GRPCService struct {
updateManagersStopCh chan struct{}
updateManagersDoneCh chan struct{}

//indexers map[string]interface{}
indexers map[string]*index.Cluster
indexerClients map[string]map[string]*indexer.GRPCClient
updateIndexersStopCh chan struct{}
Expand All @@ -66,7 +65,6 @@ func NewGRPCService(managerGrpcAddress string, logger *zap.Logger) (*GRPCService
managers: &management.Cluster{Nodes: make(map[string]*management.Node, 0)},
managerClients: make(map[string]*manager.GRPCClient, 0),

//indexers: make(map[string]interface{}, 0),
indexers: make(map[string]*index.Cluster, 0),
indexerClients: make(map[string]map[string]*indexer.GRPCClient, 0),
}, nil
Expand Down
33 changes: 17 additions & 16 deletions dispatcher/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,60 @@ package dispatcher

import (
accesslog "github.com/mash/go-accesslog"
"github.com/mosuka/blast/config"
"go.uber.org/zap"
)

type Server struct {
clusterConfig *config.ClusterConfig
nodeConfig *config.NodeConfig
logger *zap.Logger
grpcLogger *zap.Logger
httpLogger accesslog.Logger
managerGrpcAddress string
grpcAddress string
httpAddress string
logger *zap.Logger
grpcLogger *zap.Logger
httpLogger accesslog.Logger

grpcService *GRPCService
grpcServer *GRPCServer
httpRouter *Router
httpServer *HTTPServer
}

func NewServer(clusterConfig *config.ClusterConfig, nodeConfig *config.NodeConfig, logger *zap.Logger, grpcLogger *zap.Logger, httpLogger accesslog.Logger) (*Server, error) {
func NewServer(managerGrpcAddress string, grpcAddress string, httpAddress string, logger *zap.Logger, grpcLogger *zap.Logger, httpLogger accesslog.Logger) (*Server, error) {
return &Server{
clusterConfig: clusterConfig,
nodeConfig: nodeConfig,
logger: logger,
grpcLogger: grpcLogger,
httpLogger: httpLogger,
managerGrpcAddress: managerGrpcAddress,
grpcAddress: grpcAddress,
httpAddress: httpAddress,
logger: logger,
grpcLogger: grpcLogger,
httpLogger: httpLogger,
}, nil
}

func (s *Server) Start() {
var err error

// create gRPC service
s.grpcService, err = NewGRPCService(s.clusterConfig.ManagerAddr, s.logger)
s.grpcService, err = NewGRPCService(s.managerGrpcAddress, s.logger)
if err != nil {
s.logger.Fatal(err.Error())
return
}

// create gRPC server
s.grpcServer, err = NewGRPCServer(s.nodeConfig.GRPCAddr, s.grpcService, s.grpcLogger)
s.grpcServer, err = NewGRPCServer(s.grpcAddress, s.grpcService, s.grpcLogger)
if err != nil {
s.logger.Fatal(err.Error())
return
}

// create HTTP router
s.httpRouter, err = NewRouter(s.nodeConfig.GRPCAddr, s.logger)
s.httpRouter, err = NewRouter(s.grpcAddress, s.logger)
if err != nil {
s.logger.Fatal(err.Error())
return
}

// create HTTP server
s.httpServer, err = NewHTTPServer(s.nodeConfig.HTTPAddr, s.httpRouter, s.logger, s.httpLogger)
s.httpServer, err = NewHTTPServer(s.httpAddress, s.httpRouter, s.logger, s.httpLogger)
if err != nil {
s.logger.Fatal(err.Error())
return
Expand Down
39 changes: 17 additions & 22 deletions dispatcher/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"testing"
"time"

"github.com/mosuka/blast/config"
"github.com/mosuka/blast/indexer"
"github.com/mosuka/blast/logutils"
"github.com/mosuka/blast/manager"
Expand Down Expand Up @@ -534,27 +533,23 @@ func TestServer_Start(t *testing.T) {
t.Fatalf("expected content to see %v, saw %v", expIndexerCluster2, actIndexerCluster2)
}

////
//// dispatcher
////
//dispatcherManagerGrpcAddress := managerGrpcAddress1
//dispatcherGrpcAddress := fmt.Sprintf(":%d", testutils.TmpPort())
//dispatcherHttpAddress := fmt.Sprintf(":%d", testutils.TmpPort())
//
// dispatcher
//dispatcher1, err := NewServer(dispatcherManagerGrpcAddress, dispatcherGrpcAddress, dispatcherHttpAddress, logger.Named("dispatcher1"), grpcLogger.Named("dispatcher1"), httpAccessLogger)
//defer func() {
// dispatcher1.Stop()
//}()
//if err != nil {
// t.Fatalf("%v", err)
//}
//// start server
//dispatcher1.Start()
//
// create cluster config
dispatcherClusterConfig1 := config.DefaultClusterConfig()
dispatcherClusterConfig1.ManagerAddr = managerGrpcAddress1
// create node config
dispatcherNodeConfig := testutils.TmpNodeConfig()
defer func() {
_ = os.RemoveAll(dispatcherNodeConfig.DataDir)
}()
dispatcher1, err := NewServer(dispatcherClusterConfig1, dispatcherNodeConfig, logger.Named("dispatcher1"), grpcLogger.Named("dispatcher1"), httpAccessLogger)
defer func() {
dispatcher1.Stop()
}()
if err != nil {
t.Fatalf("%v", err)
}
// start server
dispatcher1.Start()

// sleep
time.Sleep(5 * time.Second)
//// sleep
//time.Sleep(5 * time.Second)
}
Loading