use fallback api infos last; init service with markets-path.
This commit is contained in:
parent
4b6fa79ea2
commit
00c3432e5a
@ -128,7 +128,7 @@ var AuthApiInfoToken = &cli.Command{
|
|||||||
|
|
||||||
// TODO: Log in audit log when it is implemented
|
// TODO: Log in audit log when it is implemented
|
||||||
|
|
||||||
currentEnv, _ := cliutil.EnvsForRepo(t)
|
currentEnv, _ := cliutil.EnvsForAPIInfos(t)
|
||||||
fmt.Printf("%s=%s:%s\n", currentEnv, string(token), ainfo.Addr)
|
fmt.Printf("%s=%s:%s\n", currentEnv, string(token), ainfo.Addr)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -62,23 +62,23 @@ func flagsForRepo(t repo.RepoType) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnvsForRepo returns the environment variables to use in order of precedence
|
// EnvsForAPIInfos returns the environment variables to use in order of precedence
|
||||||
// to determine the API endpoint of the specified node type.
|
// to determine the API endpoint of the specified node type.
|
||||||
//
|
//
|
||||||
// It returns the current variables and deprecated ones separately, so that
|
// It returns the current variables and deprecated ones separately, so that
|
||||||
// the user can log a warning when deprecated ones are found to be in use.
|
// the user can log a warning when deprecated ones are found to be in use.
|
||||||
func EnvsForRepo(t repo.RepoType) (current []string, deprecated []string) {
|
func EnvsForAPIInfos(t repo.RepoType) (primary string, fallbacks []string, deprecated []string) {
|
||||||
switch t {
|
switch t {
|
||||||
case repo.FullNode:
|
case repo.FullNode:
|
||||||
return []string{"FULLNODE_API_INFO"}, nil
|
return "FULLNODE_API_INFO", nil, nil
|
||||||
case repo.StorageMiner:
|
case repo.StorageMiner:
|
||||||
// TODO remove deprecated deprecation period
|
// TODO remove deprecated deprecation period
|
||||||
return []string{"MINER_API_INFO"}, []string{"STORAGE_API_INFO"}
|
return "MINER_API_INFO", nil, []string{"STORAGE_API_INFO"}
|
||||||
case repo.Worker:
|
case repo.Worker:
|
||||||
return []string{"WORKER_API_INFO"}, nil
|
return "WORKER_API_INFO", nil, nil
|
||||||
case repo.Markets:
|
case repo.Markets:
|
||||||
// support split markets-miner and monolith deployments.
|
// support split markets-miner and monolith deployments.
|
||||||
return []string{"MARKETS_API_INFO", "MINER_API_INFO"}, nil
|
return "MARKETS_API_INFO", []string{"MINER_API_INFO"}, nil
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("Unknown repo type: %v", t))
|
panic(fmt.Sprintf("Unknown repo type: %v", t))
|
||||||
}
|
}
|
||||||
@ -106,18 +106,20 @@ func GetAPIInfo(ctx *cli.Context, t repo.RepoType) (APIInfo, error) {
|
|||||||
return APIInfo{Addr: strma}, nil
|
return APIInfo{Addr: strma}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
currentEnv, deprecatedEnv := EnvsForRepo(t)
|
//
|
||||||
for _, env := range currentEnv {
|
// Note: it is not correct/intuitive to prefer environment variables over
|
||||||
env, ok := os.LookupEnv(env)
|
// CLI flags (repo flags below).
|
||||||
|
//
|
||||||
|
primaryEnv, fallbacksEnvs, deprecatedEnvs := EnvsForAPIInfos(t)
|
||||||
|
env, ok := os.LookupEnv(primaryEnv)
|
||||||
if ok {
|
if ok {
|
||||||
return ParseApiInfo(env), nil
|
return ParseApiInfo(env), nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for _, env := range deprecatedEnv {
|
for _, env := range deprecatedEnvs {
|
||||||
env, ok := os.LookupEnv(env)
|
env, ok := os.LookupEnv(env)
|
||||||
if ok {
|
if ok {
|
||||||
log.Warnf("Using deprecated env(%s) value, please use env(%s) instead.", env, currentEnv)
|
log.Warnf("Using deprecated env(%s) value, please use env(%s) instead.", env, primaryEnv)
|
||||||
return ParseApiInfo(env), nil
|
return ParseApiInfo(env), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,6 +158,13 @@ func GetAPIInfo(ctx *cli.Context, t repo.RepoType) (APIInfo, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, env := range fallbacksEnvs {
|
||||||
|
env, ok := os.LookupEnv(env)
|
||||||
|
if ok {
|
||||||
|
return ParseApiInfo(env), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return APIInfo{}, fmt.Errorf("could not determine API endpoint for node type: %v", t)
|
return APIInfo{}, fmt.Errorf("could not determine API endpoint for node type: %v", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
"gopkg.in/cheggaaa/pb.v1"
|
"gopkg.in/cheggaaa/pb.v1"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
paramfetch "github.com/filecoin-project/go-paramfetch"
|
"github.com/filecoin-project/go-paramfetch"
|
||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
|
||||||
lapi "github.com/filecoin-project/lotus/api"
|
lapi "github.com/filecoin-project/lotus/api"
|
||||||
@ -72,7 +72,9 @@ var restoreCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := restore(ctx, cctx, storageCfg, nil, func(api lapi.FullNode, maddr address.Address, peerid peer.ID, mi miner.MinerInfo) error {
|
repoPath := cctx.String(FlagMinerRepo)
|
||||||
|
|
||||||
|
if err := restore(ctx, cctx, repoPath, storageCfg, nil, func(api lapi.FullNode, maddr address.Address, peerid peer.ID, mi miner.MinerInfo) error {
|
||||||
log.Info("Checking proof parameters")
|
log.Info("Checking proof parameters")
|
||||||
|
|
||||||
if err := paramfetch.GetParams(ctx, build.ParametersJSON(), build.SrsJSON(), uint64(mi.SectorSize)); err != nil {
|
if err := paramfetch.GetParams(ctx, build.ParametersJSON(), build.SrsJSON(), uint64(mi.SectorSize)); err != nil {
|
||||||
@ -94,7 +96,7 @@ var restoreCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func restore(ctx context.Context, cctx *cli.Context, strConfig *stores.StorageConfig, manageConfig func(*config.StorageMiner) error, after func(api lapi.FullNode, addr address.Address, peerid peer.ID, mi miner.MinerInfo) error) error {
|
func restore(ctx context.Context, cctx *cli.Context, targetPath string, strConfig *stores.StorageConfig, manageConfig func(*config.StorageMiner) error, after func(api lapi.FullNode, addr address.Address, peerid peer.ID, mi miner.MinerInfo) error) error {
|
||||||
if cctx.Args().Len() != 1 {
|
if cctx.Args().Len() != 1 {
|
||||||
return xerrors.Errorf("expected 1 argument")
|
return xerrors.Errorf("expected 1 argument")
|
||||||
}
|
}
|
||||||
@ -142,8 +144,7 @@ func restore(ctx context.Context, cctx *cli.Context, strConfig *stores.StorageCo
|
|||||||
|
|
||||||
log.Info("Checking if repo exists")
|
log.Info("Checking if repo exists")
|
||||||
|
|
||||||
repoPath := cctx.String(FlagMinerRepo)
|
r, err := repo.NewFS(targetPath)
|
||||||
r, err := repo.NewFS(repoPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,12 @@ var serviceCmd = &cli.Command{
|
|||||||
return xerrors.Errorf("--api-sector-index is required without the sector storage module enabled")
|
return xerrors.Errorf("--api-sector-index is required without the sector storage module enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := restore(ctx, cctx, &stores.StorageConfig{}, func(cfg *config.StorageMiner) error {
|
repoPath := cctx.String(FlagMarketsRepo)
|
||||||
|
if repoPath == "" {
|
||||||
|
return xerrors.Errorf("please provide Lotus markets repo path via flag %s", FlagMarketsRepo)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := restore(ctx, cctx, repoPath, &stores.StorageConfig{}, func(cfg *config.StorageMiner) error {
|
||||||
cfg.Subsystems.EnableMarkets = es.Contains(MarketsService)
|
cfg.Subsystems.EnableMarkets = es.Contains(MarketsService)
|
||||||
cfg.Subsystems.EnableMining = false
|
cfg.Subsystems.EnableMining = false
|
||||||
cfg.Subsystems.EnableSealing = false
|
cfg.Subsystems.EnableSealing = false
|
||||||
|
@ -22,8 +22,10 @@ import (
|
|||||||
|
|
||||||
var log = logging.Logger("main")
|
var log = logging.Logger("main")
|
||||||
|
|
||||||
const FlagMinerRepo = "miner-repo"
|
const (
|
||||||
const FlagMarketsRepo = "markets-repo"
|
FlagMinerRepo = "miner-repo"
|
||||||
|
FlagMarketsRepo = "markets-repo"
|
||||||
|
)
|
||||||
|
|
||||||
// TODO remove after deprecation period
|
// TODO remove after deprecation period
|
||||||
const FlagMinerRepoDeprecation = "storagerepo"
|
const FlagMinerRepoDeprecation = "storagerepo"
|
||||||
|
@ -43,6 +43,7 @@ GLOBAL OPTIONS:
|
|||||||
--actor value, -a value specify other actor to check state for (read only)
|
--actor value, -a value specify other actor to check state for (read only)
|
||||||
--color use color in display output (default: depends on output being a TTY)
|
--color use color in display output (default: depends on output being a TTY)
|
||||||
--miner-repo value, --storagerepo value Specify miner repo path. flag(storagerepo) and env(LOTUS_STORAGE_PATH) are DEPRECATION, will REMOVE SOON (default: "~/.lotusminer") [$LOTUS_MINER_PATH, $LOTUS_STORAGE_PATH]
|
--miner-repo value, --storagerepo value Specify miner repo path. flag(storagerepo) and env(LOTUS_STORAGE_PATH) are DEPRECATION, will REMOVE SOON (default: "~/.lotusminer") [$LOTUS_MINER_PATH, $LOTUS_STORAGE_PATH]
|
||||||
|
--markets-repo value Markets repo path [$LOTUS_MARKETS_PATH]
|
||||||
--call-on-markets (experimental; may be removed) call this command against a markets node; use only with common commands like net, auth, pprof, etc. whose target may be ambiguous (default: false)
|
--call-on-markets (experimental; may be removed) call this command against a markets node; use only with common commands like net, auth, pprof, etc. whose target may be ambiguous (default: false)
|
||||||
--vv enables very verbose mode, useful for debugging the CLI (default: false)
|
--vv enables very verbose mode, useful for debugging the CLI (default: false)
|
||||||
--help, -h show help (default: false)
|
--help, -h show help (default: false)
|
||||||
|
Loading…
Reference in New Issue
Block a user