Move to frostfs-node
Signed-off-by: Pavel Karpy <p.karpy@yadro.com>
This commit is contained in:
parent
42554a9298
commit
923f84722a
934 changed files with 3470 additions and 3451 deletions
125
cmd/frostfs-ir/defaults.go
Normal file
125
cmd/frostfs-ir/defaults.go
Normal file
|
@ -0,0 +1,125 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func newConfig(path string) (*viper.Viper, error) {
|
||||
const innerRingPrefix = "neofs_ir"
|
||||
|
||||
var (
|
||||
err error
|
||||
v = viper.New()
|
||||
)
|
||||
|
||||
v.SetEnvPrefix(innerRingPrefix)
|
||||
v.AutomaticEnv()
|
||||
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
|
||||
defaultConfiguration(v)
|
||||
|
||||
if path != "" {
|
||||
v.SetConfigFile(path)
|
||||
if strings.HasSuffix(path, ".json") {
|
||||
v.SetConfigType("json")
|
||||
} else {
|
||||
v.SetConfigType("yml")
|
||||
}
|
||||
err = v.ReadInConfig()
|
||||
}
|
||||
|
||||
return v, err
|
||||
}
|
||||
|
||||
func defaultConfiguration(cfg *viper.Viper) {
|
||||
cfg.SetDefault("logger.level", "info")
|
||||
|
||||
cfg.SetDefault("pprof.address", "localhost:6060")
|
||||
cfg.SetDefault("pprof.shutdown_timeout", "30s")
|
||||
|
||||
cfg.SetDefault("prometheus.address", "localhost:9090")
|
||||
cfg.SetDefault("prometheus.shutdown_timeout", "30s")
|
||||
|
||||
cfg.SetDefault("without_mainnet", false)
|
||||
|
||||
cfg.SetDefault("node.persistent_state.path", ".frostfs-ir-state")
|
||||
|
||||
cfg.SetDefault("morph.endpoint.client", []string{})
|
||||
cfg.SetDefault("morph.dial_timeout", 15*time.Second)
|
||||
cfg.SetDefault("morph.validators", []string{})
|
||||
cfg.SetDefault("morph.switch_interval", 2*time.Minute)
|
||||
|
||||
cfg.SetDefault("mainnet.endpoint.client", []string{})
|
||||
cfg.SetDefault("mainnet.dial_timeout", 15*time.Second)
|
||||
cfg.SetDefault("mainnet.switch_interval", 2*time.Minute)
|
||||
|
||||
cfg.SetDefault("wallet.path", "") // inner ring node NEP-6 wallet
|
||||
cfg.SetDefault("wallet.address", "") // account address
|
||||
cfg.SetDefault("wallet.password", "") // password
|
||||
|
||||
cfg.SetDefault("contracts.netmap", "")
|
||||
cfg.SetDefault("contracts.frostfs", "")
|
||||
cfg.SetDefault("contracts.balance", "")
|
||||
cfg.SetDefault("contracts.container", "")
|
||||
cfg.SetDefault("contracts.audit", "")
|
||||
cfg.SetDefault("contracts.proxy", "")
|
||||
cfg.SetDefault("contracts.processing", "")
|
||||
cfg.SetDefault("contracts.reputation", "")
|
||||
cfg.SetDefault("contracts.subnet", "")
|
||||
cfg.SetDefault("contracts.proxy", "")
|
||||
|
||||
cfg.SetDefault("timers.emit", "0")
|
||||
cfg.SetDefault("timers.stop_estimation.mul", 1)
|
||||
cfg.SetDefault("timers.stop_estimation.div", 4)
|
||||
cfg.SetDefault("timers.collect_basic_income.mul", 1)
|
||||
cfg.SetDefault("timers.collect_basic_income.div", 2)
|
||||
cfg.SetDefault("timers.distribute_basic_income.mul", 3)
|
||||
cfg.SetDefault("timers.distribute_basic_income.div", 4)
|
||||
|
||||
cfg.SetDefault("workers.netmap", "10")
|
||||
cfg.SetDefault("workers.balance", "10")
|
||||
cfg.SetDefault("workers.frostfs", "10")
|
||||
cfg.SetDefault("workers.container", "10")
|
||||
cfg.SetDefault("workers.alphabet", "10")
|
||||
cfg.SetDefault("workers.reputation", "10")
|
||||
cfg.SetDefault("workers.subnet", "10")
|
||||
|
||||
cfg.SetDefault("netmap_cleaner.enabled", true)
|
||||
cfg.SetDefault("netmap_cleaner.threshold", 3)
|
||||
|
||||
cfg.SetDefault("emit.storage.amount", 0)
|
||||
cfg.SetDefault("emit.mint.cache_size", 1000)
|
||||
cfg.SetDefault("emit.mint.threshold", 1)
|
||||
cfg.SetDefault("emit.mint.value", 20000000) // 0.2 Fixed8
|
||||
cfg.SetDefault("emit.gas.balance_threshold", 0)
|
||||
|
||||
cfg.SetDefault("audit.task.exec_pool_size", 10)
|
||||
cfg.SetDefault("audit.task.queue_capacity", 100)
|
||||
cfg.SetDefault("audit.timeout.get", "5s")
|
||||
cfg.SetDefault("audit.timeout.head", "5s")
|
||||
cfg.SetDefault("audit.timeout.rangehash", "5s")
|
||||
cfg.SetDefault("audit.timeout.search", "10s")
|
||||
cfg.SetDefault("audit.pdp.max_sleep_interval", "5s")
|
||||
cfg.SetDefault("audit.pdp.pairs_pool_size", "10")
|
||||
cfg.SetDefault("audit.por.pool_size", "10")
|
||||
|
||||
cfg.SetDefault("settlement.basic_income_rate", 0)
|
||||
cfg.SetDefault("settlement.audit_fee", 0)
|
||||
|
||||
cfg.SetDefault("indexer.cache_timeout", 15*time.Second)
|
||||
|
||||
cfg.SetDefault("locode.db.path", "")
|
||||
|
||||
// extra fee values for working mode without notary contract
|
||||
cfg.SetDefault("fee.main_chain", 5000_0000) // 0.5 Fixed8
|
||||
cfg.SetDefault("fee.side_chain", 2_0000_0000) // 2.0 Fixed8
|
||||
cfg.SetDefault("fee.named_container_register", 25_0000_0000) // 25.0 Fixed8
|
||||
|
||||
cfg.SetDefault("control.authorized_keys", []string{})
|
||||
cfg.SetDefault("control.grpc.endpoint", "")
|
||||
|
||||
cfg.SetDefault("governance.disable", false)
|
||||
}
|
144
cmd/frostfs-ir/main.go
Normal file
144
cmd/frostfs-ir/main.go
Normal file
|
@ -0,0 +1,144 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/TrueCloudLab/frostfs-node/misc"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/innerring"
|
||||
httputil "github.com/TrueCloudLab/frostfs-node/pkg/util/http"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
// ErrorReturnCode returns when application crashed at initialization stage.
|
||||
ErrorReturnCode = 1
|
||||
|
||||
// SuccessReturnCode returns when application closed without panic.
|
||||
SuccessReturnCode = 0
|
||||
)
|
||||
|
||||
func exitErr(err error) {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(ErrorReturnCode)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
configFile := flag.String("config", "", "path to config")
|
||||
versionFlag := flag.Bool("version", false, "frostfs-ir node version")
|
||||
flag.Parse()
|
||||
|
||||
if *versionFlag {
|
||||
fmt.Print(misc.BuildInfo("NeoFS Inner Ring node"))
|
||||
|
||||
os.Exit(SuccessReturnCode)
|
||||
}
|
||||
|
||||
cfg, err := newConfig(*configFile)
|
||||
exitErr(err)
|
||||
|
||||
var logPrm logger.Prm
|
||||
|
||||
err = logPrm.SetLevelString(
|
||||
cfg.GetString("logger.level"),
|
||||
)
|
||||
exitErr(err)
|
||||
|
||||
log, err := logger.NewLogger(&logPrm)
|
||||
exitErr(err)
|
||||
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
|
||||
defer cancel()
|
||||
|
||||
intErr := make(chan error) // internal inner ring errors
|
||||
|
||||
httpServers := initHTTPServers(cfg, log)
|
||||
|
||||
innerRing, err := innerring.New(ctx, log, cfg, intErr)
|
||||
exitErr(err)
|
||||
|
||||
// start HTTP servers
|
||||
for i := range httpServers {
|
||||
srv := httpServers[i]
|
||||
go func() {
|
||||
exitErr(srv.Serve())
|
||||
}()
|
||||
}
|
||||
|
||||
// start inner ring
|
||||
err = innerRing.Start(ctx, intErr)
|
||||
exitErr(err)
|
||||
|
||||
log.Info("application started",
|
||||
zap.String("version", misc.Version))
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case err := <-intErr:
|
||||
log.Info("internal error", zap.String("msg", err.Error()))
|
||||
}
|
||||
|
||||
innerRing.Stop()
|
||||
|
||||
// shut down HTTP servers
|
||||
for i := range httpServers {
|
||||
srv := httpServers[i]
|
||||
|
||||
go func() {
|
||||
err := srv.Shutdown()
|
||||
if err != nil {
|
||||
log.Debug("could not shutdown HTTP server",
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
log.Info("application stopped")
|
||||
}
|
||||
|
||||
func initHTTPServers(cfg *viper.Viper, log *logger.Logger) []*httputil.Server {
|
||||
items := []struct {
|
||||
cfgPrefix string
|
||||
handler func() http.Handler
|
||||
}{
|
||||
{"pprof", httputil.Handler},
|
||||
{"prometheus", promhttp.Handler},
|
||||
}
|
||||
|
||||
httpServers := make([]*httputil.Server, 0, len(items))
|
||||
|
||||
for _, item := range items {
|
||||
if !cfg.GetBool(item.cfgPrefix + ".enabled") {
|
||||
log.Info(item.cfgPrefix + " is disabled, skip")
|
||||
continue
|
||||
}
|
||||
|
||||
addr := cfg.GetString(item.cfgPrefix + ".address")
|
||||
|
||||
var prm httputil.Prm
|
||||
|
||||
prm.Address = addr
|
||||
prm.Handler = item.handler()
|
||||
|
||||
httpServers = append(httpServers,
|
||||
httputil.New(prm,
|
||||
httputil.WithShutdownTimeout(
|
||||
cfg.GetDuration(item.cfgPrefix+".shutdown_timeout"),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return httpServers
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue