Skip to content

Commit

Permalink
Add ServerError
Browse files Browse the repository at this point in the history
  • Loading branch information
watal authored and Motok1 committed Oct 19, 2022
1 parent a1aca99 commit ab697eb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/polad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func main() {
o.GrpcAddr = c.Global.GrpcServer.Address
o.GrpcPort = c.Global.GrpcServer.Port
o.TedEnable = c.Global.Ted.Enable
if err := server.NewPce(o, logger, tedElemsChan); err != nil {
logger.Panic("Failed to create New Server", zap.Error(err))
if serverErr := server.NewPce(o, logger, tedElemsChan); serverErr.Error != nil {
logger.Panic("Failed to create New Server", zap.String("server", serverErr.Server), zap.Error(serverErr.Error))
}
}
11 changes: 11 additions & 0 deletions pkg/server/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2022 NTT Communications Corporation
//
// This software is released under the MIT License.
// see https://github.com/nttcom/pola/blob/main/LICENSE

package server

type ServerError struct {
Error error
Server string
}
18 changes: 12 additions & 6 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type PceOptions struct {
TedEnable bool
}

func NewPce(o *PceOptions, logger *zap.Logger, tedElemsChan chan []table.TedElem) error {
func NewPce(o *PceOptions, logger *zap.Logger, tedElemsChan chan []table.TedElem) ServerError {
var s *Server
if o.TedEnable {
s = &Server{
Expand Down Expand Up @@ -73,19 +73,25 @@ func NewPce(o *PceOptions, logger *zap.Logger, tedElemsChan chan []table.TedElem

s.logger = logger
lspChan := make(chan Lsp)
errChan := make(chan error)
errChan := make(chan ServerError)
// Start PCEP listen
go func() {
if err := s.Listen(o.PcepAddr, o.PcepPort, lspChan); err != nil {
errChan <- err
errChan <- ServerError{
Server: "pcep",
Error: err,
}
}
}()
// Start gRPC listen
go func() {
grpcServer := grpc.NewServer()
apiServer := NewAPIServer(s, grpcServer)
if err := apiServer.Serve(o.GrpcAddr, o.GrpcPort); err != nil {
errChan <- err
errChan <- ServerError{
Server: "grpc",
Error: err,
}
}
}()

Expand All @@ -95,8 +101,8 @@ func NewPce(o *PceOptions, logger *zap.Logger, tedElemsChan chan []table.TedElem
// Overwrite LSP
s.removeLsp(lsp)
s.lspList = append(s.lspList, lsp)
case err := <-errChan:
return err
case serverError := <-errChan:
return serverError
}
}
}
Expand Down

0 comments on commit ab697eb

Please sign in to comment.