15960d4269
* WIP creating admin node service - WIP changing the process pkg to accept multiple services - WIP looping over services passed to process - add netstate/service.go file and abstract it for service processing * implement goroutine to launch each process * goroutines working with multiple services * code review fixes * more code updates for review * Add pkg lock and mod files back in * code review updates * update process.Main with better concurrent error handling * Update error handling and pass ctx to StartService * Update error handling with channel implementation * Merge in upstream changes - Simplify error handling channels * updates * Updates per reviewable * fix test * Setup test exec * Scaffold test setup * process main test working * update admin process test * Test multiple processes done * Add error classes for testing, test main logger error * Updates to tests * Update how process.Main() handles configs * Complete merge * Update Gopkg and add Copyright * Fix cyclical import issue - Added .coverprofile to gitignore - Update admin main.go function call * remove unnecessary line * Updates * DRY up cmd/netstate package * update service function calls * updates * Trying no-ops in examples * rename netstate to pointerdb * trying to fix merge * dep ensure and run tests * remove flag.Parse * Update deps * Skip offending test in pkg/process, to be fixed later
80 lines
1.6 KiB
Go
80 lines
1.6 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package pointerdb
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"net"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
"go.uber.org/zap"
|
|
"google.golang.org/grpc"
|
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
|
|
|
proto "storj.io/storj/protos/pointerdb"
|
|
"storj.io/storj/storage/boltdb"
|
|
)
|
|
|
|
var (
|
|
port = flag.Int("port", 8080, "port")
|
|
dbPath = flag.String("pointerdbDB", "pointerdb.db", "pointerdb db path")
|
|
)
|
|
|
|
// Process fits the `Process` interface for services
|
|
func (s *Service) Process(ctx context.Context, _ *cobra.Command, _ []string) error {
|
|
if err := setEnv(); err != nil {
|
|
return err
|
|
}
|
|
|
|
bdb, err := boltdb.NewClient(s.logger, *dbPath, boltdb.PointerBucket)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer bdb.Close()
|
|
|
|
// start grpc server
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
grpcServer := grpc.NewServer()
|
|
|
|
proto.RegisterPointerDBServer(grpcServer, NewServer(bdb, s.logger))
|
|
s.logger.Debug(fmt.Sprintf("server listening on port %d", *port))
|
|
|
|
defer grpcServer.GracefulStop()
|
|
return grpcServer.Serve(lis)
|
|
}
|
|
|
|
// Service struct for process
|
|
type Service struct {
|
|
logger *zap.Logger
|
|
metrics *monkit.Registry
|
|
}
|
|
|
|
// SetLogger for process
|
|
func (s *Service) SetLogger(l *zap.Logger) error {
|
|
s.logger = l
|
|
return nil
|
|
}
|
|
|
|
func setEnv() error {
|
|
viper.SetEnvPrefix("API")
|
|
viper.AutomaticEnv()
|
|
return nil
|
|
}
|
|
|
|
// SetMetricHandler for process
|
|
func (s *Service) SetMetricHandler(m *monkit.Registry) error {
|
|
s.metrics = m
|
|
return nil
|
|
}
|
|
|
|
// InstanceID assigns a new instance ID to the process
|
|
func (s *Service) InstanceID() string { return "" }
|