From 67c5818fc1b4c13613cac9b0e0399225fe4c5809 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 20 Dec 2022 14:01:50 +0300 Subject: [PATCH] [#2] Rename internals Signed-off-by: Denis Kirillov --- .gitignore | 2 +- README.md | 14 +++++++------- app.go | 8 ++++---- config/config.env | 12 ++++++------ config/config.yaml | 12 ++++++------ docs/gate-configuration.md | 14 +++++++------- downloader/download.go | 6 +++--- downloader/head.go | 4 ++-- metrics/metrics.go | 2 +- resolver/frostfs.go | 35 +++++++++++++++++++++++++++++++++++ resolver/neofs.go | 35 ----------------------------------- resolver/resolver.go | 18 +++++++++--------- uploader/filter.go | 4 ++-- uploader/upload.go | 4 ++-- 14 files changed, 85 insertions(+), 85 deletions(-) create mode 100644 resolver/frostfs.go delete mode 100644 resolver/neofs.go diff --git a/.gitignore b/.gitignore index ebadc7a..c4a98d8 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ temp test.sh testfile .blast.yml -.neofs-cli.yml +.frostfs-cli.yml .cache diff --git a/README.md b/README.md index 0c05b60..e336a6d 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ FrostFS nodes with weighted load balancing). If you launch HTTP gateway in bundle with [frostfs-dev-env](https://github.com/TrueCloudLab/frostfs-dev-env), you can get the IP address of the node in the output of `make hosts` command -(with s0*.neofs.devenv name). +(with s0*.frostfs.devenv name). These two commands are functionally equivalent, they run the gate with one backend node (and otherwise default settings): @@ -96,7 +96,7 @@ You can provide a wallet via `--wallet` or `-w` flag. You can also specify the a (if no address provided default one will be used). If wallet is used, you need to set `HTTP_GW_WALLET_PASSPHRASE` variable to decrypt the wallet. If no wallet provided, the gateway autogenerates a key pair it will use for FrostFS requests. ``` -$ frostfs-http-gw -p $NEOFS_NODE -w $WALLET_PATH --address $ACCOUNT_ADDRESS +$ frostfs-http-gw -p $FROSTFS_NODE -w $WALLET_PATH --address $ACCOUNT_ADDRESS ``` Example: ``` @@ -206,7 +206,7 @@ Steps to start using name resolving: 1. Enable NNS resolving in config (`rpc_endpoint` must be a valid neo rpc node, see [configs](./config) for other examples): ```yaml -rpc_endpoint: http://morph-chain.neofs.devenv:30333 +rpc_endpoint: http://morph-chain.frostfs.devenv:30333 resolve_order: - nns ``` @@ -216,13 +216,13 @@ you can check if your container (e.g. with `container-name` name) is registered ```shell $ curl -s --data '{"id":1,"jsonrpc":"2.0","method":"getcontractstate","params":[1]}' \ - http://morph-chain.neofs.devenv:30333 | jq -r '.result.hash' + http://morph-chain.frostfs.devenv:30333 | jq -r '.result.hash' 0x8e6c3cd4b976b28e84a3788f6ea9e2676c15d667 $ docker exec -it morph_chain neo-go \ contract testinvokefunction \ - -r http://morph-chain.neofs.devenv:30333 0x8e6c3cd4b976b28e84a3788f6ea9e2676c15d667 \ + -r http://morph-chain.frostfs.devenv:30333 0x8e6c3cd4b976b28e84a3788f6ea9e2676c15d667 \ resolve string:container-name.container int:16 \ | jq -r '.stack[0].value | if type=="array" then .[0].value else . end' \ | base64 -d && echo @@ -240,7 +240,7 @@ $ curl http://localhost:8082/get_by_attribute/container-name/FileName/object-nam You can create a container via [frostfs-cli](https://github.com/TrueCloudLab/frostfs-node/releases): ``` -$ frostfs-cli -r $NEOFS_NODE -w $WALLET container create --policy $POLICY --basic-acl $ACL +$ frostfs-cli -r $FROSTFS_NODE -w $WALLET container create --policy $POLICY --basic-acl $ACL ``` where `$WALLET` is a path to user wallet, `$ACL` -- hex encoded basic ACL value or keywords 'private, 'public-read', 'public-read-write' and @@ -259,7 +259,7 @@ the file `wallets/wallet.key`. To create a file via [frostfs-cli](https://github.com/TrueCloudLab/frostfs-node/releases), run a command below: ``` -$ frostfs-cli -r $NEOFS_NODE -k $KEY object put --file $FILENAME --cid $CID +$ frostfs-cli -r $FROSTFS_NODE -k $KEY object put --file $FILENAME --cid $CID ``` where `$KEY` -- the key, please read the information [above](#create-a-container), diff --git a/app.go b/app.go index 80c36f0..3328e54 100644 --- a/app.go +++ b/app.go @@ -123,9 +123,9 @@ func newApp(ctx context.Context, opt ...Option) App { a.webServer.DisablePreParseMultipartForm = true a.webServer.StreamRequestBody = a.cfg.GetBool(cfgWebStreamRequestBody) // -- -- -- -- -- -- -- -- -- -- -- -- -- -- - key, err = getNeoFSKey(a) + key, err = getFrostFSKey(a) if err != nil { - a.log.Fatal("failed to get neofs credentials", zap.Error(err)) + a.log.Fatal("failed to get frostfs credentials", zap.Error(err)) } var owner user.ID @@ -194,7 +194,7 @@ func (a *app) initResolver() { func (a *app) getResolverConfig() ([]string, *resolver.Config) { resolveCfg := &resolver.Config{ - NeoFS: resolver.NewNeoFSResolver(a.pool), + FrostFS: resolver.NewFrostFSResolver(a.pool), RPCAddress: a.cfg.GetString(cfgRPCEndpoint), } @@ -266,7 +266,7 @@ func remove(list []string, element string) []string { return list } -func getNeoFSKey(a *app) (*ecdsa.PrivateKey, error) { +func getFrostFSKey(a *app) (*ecdsa.PrivateKey, error) { walletPath := a.cfg.GetString(cfgWalletPath) if len(walletPath) == 0 { diff --git a/config/config.env b/config/config.env index fbf7327..4f13bb0 100644 --- a/config/config.env +++ b/config/config.env @@ -27,13 +27,13 @@ HTTP_GW_SERVER_1_TLS_CERT_FILE=/path/to/tls/cert HTTP_GW_SERVER_1_TLS_KEY_FILE=/path/to/tls/key # Nodes configuration. -# This configuration make the gateway use the first node (grpc://s01.neofs.devenv:8080) -# while it's healthy. Otherwise, the gateway use the second node (grpc://s01.neofs.devenv:8080) +# This configuration make the gateway use the first node (grpc://s01.frostfs.devenv:8080) +# while it's healthy. Otherwise, the gateway use the second node (grpc://s01.frostfs.devenv:8080) # for 10% of requests and the third node for 90% of requests. # Peer 1. # Endpoint. -HTTP_GW_PEERS_0_ADDRESS=grpc://s01.neofs.devenv:8080 +HTTP_GW_PEERS_0_ADDRESS=grpc://s01.frostfs.devenv:8080 # Until nodes with the same priority level are healthy # nodes with other priority are not used. # The lower the value, the higher the priority. @@ -41,11 +41,11 @@ HTTP_GW_PEERS_0_PRIORITY=1 # Load distribution proportion for nodes with the same priority. HTTP_GW_PEERS_0_WEIGHT=1 # Peer 2. -HTTP_GW_PEERS_1_ADDRESS=grpc://s02.neofs.devenv:8080 +HTTP_GW_PEERS_1_ADDRESS=grpc://s02.frostfs.devenv:8080 HTTP_GW_PEERS_1_PRIORITY=2 HTTP_GW_PEERS_1_WEIGHT=1 # Peer 3. -HTTP_GW_PEERS_2_ADDRESS=grpc://s03.neofs.devenv:8080 +HTTP_GW_PEERS_2_ADDRESS=grpc://s03.frostfs.devenv:8080 HTTP_GW_PEERS_2_PRIORITY=2 HTTP_GW_PEERS_2_WEIGHT=9 @@ -72,7 +72,7 @@ HTTP_GW_STREAM_REQUEST_BODY=true HTTP_GW_MAX_REQUEST_BODY_SIZE=4194304 # RPC endpoint to be able to use nns container resolving. -HTTP_GW_RPC_ENDPOINT=http://morph-chain.neofs.devenv:30333 +HTTP_GW_RPC_ENDPOINT=http://morph-chain.frostfs.devenv:30333 # The order in which resolvers are used to find an container id by name. HTTP_GW_RESOLVE_ORDER="nns dns" diff --git a/config/config.yaml b/config/config.yaml index fc2fada..71bab50 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -26,13 +26,13 @@ server: key_file: /path/to/key # Nodes configuration. -# This configuration make the gateway use the first node (grpc://s01.neofs.devenv:8080) -# while it's healthy. Otherwise, the gateway use the second node (grpc://s01.neofs.devenv:8080) +# This configuration make the gateway use the first node (grpc://s01.frostfs.devenv:8080) +# while it's healthy. Otherwise, the gateway use the second node (grpc://s01.frostfs.devenv:8080) # for 10% of requests and the third node for 90% of requests. peers: 0: # Endpoint. - address: grpc://s01.neofs.devenv:8080 + address: grpc://s01.frostfs.devenv:8080 # Until nodes with the same priority level are healthy # nodes with other priority are not used. @@ -42,11 +42,11 @@ peers: # Load distribution proportion for nodes with the same priority. weight: 1 1: - address: grpc://s02.neofs.devenv:8080 + address: grpc://s02.frostfs.devenv:8080 priority: 2 weight: 1 2: - address: grpc://s03.neofs.devenv:8080 + address: grpc://s03.frostfs.devenv:8080 priority: 2 weight: 9 @@ -80,7 +80,7 @@ web: max_request_body_size: 4194304 # RPC endpoint to be able to use nns container resolving. -rpc_endpoint: http://morph-chain.neofs.devenv:30333 +rpc_endpoint: http://morph-chain.frostfs.devenv:30333 # The order in which resolvers are used to find an container id by name. resolve_order: - nns diff --git a/docs/gate-configuration.md b/docs/gate-configuration.md index 2f65670..d955d2a 100644 --- a/docs/gate-configuration.md +++ b/docs/gate-configuration.md @@ -57,7 +57,7 @@ $ cat http.log # General section ```yaml -rpc_endpoint: http://morph-chain.neofs.devenv:30333 +rpc_endpoint: http://morph-chain.frostfs.devenv:30333 resolve_order: - nns - dns @@ -98,23 +98,23 @@ wallet: ```yaml # Nodes configuration -# This configuration makes the gateway use the first node (node1.neofs:8080) -# while it's healthy. Otherwise, gateway uses the second node (node2.neofs:8080) -# for 10% of requests and the third node (node3.neofs:8080) for 90% of requests. +# This configuration makes the gateway use the first node (node1.frostfs:8080) +# while it's healthy. Otherwise, gateway uses the second node (node2.frostfs:8080) +# for 10% of requests and the third node (node3.frostfs:8080) for 90% of requests. # Until nodes with the same priority level are healthy # nodes with other priority are not used. # The lower the value, the higher the priority. peers: 0: - address: node1.neofs:8080 + address: node1.frostfs:8080 priority: 1 weight: 1 1: - address: node2.neofs:8080 + address: node2.frostfs:8080 priority: 2 weight: 0.1 2: - address: node3.neofs:8080 + address: node3.frostfs:8080 priority: 2 weight: 0.9 ``` diff --git a/downloader/download.go b/downloader/download.go index f34ab62..b3881a6 100644 --- a/downloader/download.go +++ b/downloader/download.go @@ -111,7 +111,7 @@ func (r request) receiveFile(clnt *pool.Pool, objectAddress oid.Address) { rObj, err := clnt.GetObject(r.appCtx, prm) if err != nil { - r.handleNeoFSErr(err, start) + r.handleFrostFSErr(err, start) return } @@ -224,7 +224,7 @@ func bearerToken(ctx context.Context) *bearer.Token { return nil } -func (r *request) handleNeoFSErr(err error, start time.Time) { +func (r *request) handleFrostFSErr(err error, start time.Time) { r.log.Error( "could not receive object", zap.Stringer("elapsed", time.Since(start)), @@ -500,7 +500,7 @@ func (d *Downloader) zipObject(zipWriter *zip.Writer, addr oid.Address, btoken * resGet, err := d.pool.GetObject(d.appCtx, prm) if err != nil { - return fmt.Errorf("get NeoFS object: %v", err) + return fmt.Errorf("get FrostFS object: %v", err) } objWriter, err := d.addObjectToZip(zipWriter, &resGet.Header) diff --git a/downloader/head.go b/downloader/head.go index 2487b23..3fd243e 100644 --- a/downloader/head.go +++ b/downloader/head.go @@ -44,7 +44,7 @@ func (r request) headObject(clnt *pool.Pool, objectAddress oid.Address) { obj, err := clnt.HeadObject(r.appCtx, prm) if err != nil { - r.handleNeoFSErr(err, start) + r.handleFrostFSErr(err, start) return } @@ -94,7 +94,7 @@ func (r request) headObject(clnt *pool.Pool, objectAddress oid.Address) { return &resObj, nil }) if err != nil && err != io.EOF { - r.handleNeoFSErr(err, start) + r.handleFrostFSErr(err, start) return } } diff --git a/metrics/metrics.go b/metrics/metrics.go index 84b7114..da57d64 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -10,7 +10,7 @@ import ( ) const ( - namespace = "neofs_http_gw" + namespace = "frostfs_http_gw" stateSubsystem = "state" poolSubsystem = "pool" diff --git a/resolver/frostfs.go b/resolver/frostfs.go new file mode 100644 index 0000000..0a1f255 --- /dev/null +++ b/resolver/frostfs.go @@ -0,0 +1,35 @@ +package resolver + +import ( + "context" + "errors" + "fmt" + + "github.com/TrueCloudLab/frostfs-sdk-go/pool" +) + +// FrostFSResolver represents virtual connection to the FrostFS network. +// It implements resolver.FrostFS. +type FrostFSResolver struct { + pool *pool.Pool +} + +// NewFrostFSResolver creates new FrostFSResolver using provided pool.Pool. +func NewFrostFSResolver(p *pool.Pool) *FrostFSResolver { + return &FrostFSResolver{pool: p} +} + +// SystemDNS implements resolver.FrostFS interface method. +func (x *FrostFSResolver) SystemDNS(ctx context.Context) (string, error) { + networkInfo, err := x.pool.NetworkInfo(ctx) + if err != nil { + return "", fmt.Errorf("read network info via client: %w", err) + } + + domain := networkInfo.RawNetworkParameter("SystemDNS") + if domain == nil { + return "", errors.New("system DNS parameter not found or empty") + } + + return string(domain), nil +} diff --git a/resolver/neofs.go b/resolver/neofs.go deleted file mode 100644 index 308a060..0000000 --- a/resolver/neofs.go +++ /dev/null @@ -1,35 +0,0 @@ -package resolver - -import ( - "context" - "errors" - "fmt" - - "github.com/TrueCloudLab/frostfs-sdk-go/pool" -) - -// NeoFSResolver represents virtual connection to the NeoFS network. -// It implements resolver.NeoFS. -type NeoFSResolver struct { - pool *pool.Pool -} - -// NewNeoFSResolver creates new NeoFSResolver using provided pool.Pool. -func NewNeoFSResolver(p *pool.Pool) *NeoFSResolver { - return &NeoFSResolver{pool: p} -} - -// SystemDNS implements resolver.NeoFS interface method. -func (x *NeoFSResolver) SystemDNS(ctx context.Context) (string, error) { - networkInfo, err := x.pool.NetworkInfo(ctx) - if err != nil { - return "", fmt.Errorf("read network info via client: %w", err) - } - - domain := networkInfo.RawNetworkParameter("SystemDNS") - if domain == nil { - return "", errors.New("system DNS parameter not found or empty") - } - - return string(domain), nil -} diff --git a/resolver/resolver.go b/resolver/resolver.go index 686a147..24f8835 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -19,9 +19,9 @@ const ( // ErrNoResolvers returns when trying to resolve container without any resolver. var ErrNoResolvers = errors.New("no resolvers") -// NeoFS represents virtual connection to the NeoFS network. -type NeoFS interface { - // SystemDNS reads system DNS network parameters of the NeoFS. +// FrostFS represents virtual connection to the FrostFS network. +type FrostFS interface { + // SystemDNS reads system DNS network parameters of the FrostFS. // // Returns exactly on non-zero value. Returns any error encountered // which prevented the parameter to be read. @@ -29,7 +29,7 @@ type NeoFS interface { } type Config struct { - NeoFS NeoFS + FrostFS FrostFS RPCAddress string } @@ -135,7 +135,7 @@ func (r *ContainerResolver) equals(resolverNames []string) bool { func newResolver(name string, cfg *Config) (*Resolver, error) { switch name { case DNSResolver: - return NewDNSResolver(cfg.NeoFS) + return NewDNSResolver(cfg.FrostFS) case NNSResolver: return NewNNSResolver(cfg.RPCAddress) default: @@ -143,17 +143,17 @@ func newResolver(name string, cfg *Config) (*Resolver, error) { } } -func NewDNSResolver(neoFS NeoFS) (*Resolver, error) { - if neoFS == nil { +func NewDNSResolver(frostFS FrostFS) (*Resolver, error) { + if frostFS == nil { return nil, fmt.Errorf("pool must not be nil for DNS resolver") } var dns ns.DNS resolveFunc := func(ctx context.Context, name string) (*cid.ID, error) { - domain, err := neoFS.SystemDNS(ctx) + domain, err := frostFS.SystemDNS(ctx) if err != nil { - return nil, fmt.Errorf("read system DNS parameter of the NeoFS: %w", err) + return nil, fmt.Errorf("read system DNS parameter of the FrostFS: %w", err) } domain = name + "." + domain diff --git a/uploader/filter.go b/uploader/filter.go index 0ee5b66..2942f6d 100644 --- a/uploader/filter.go +++ b/uploader/filter.go @@ -13,7 +13,7 @@ import ( "go.uber.org/zap" ) -var neofsAttributeHeaderPrefixes = [...][]byte{[]byte("Neofs-"), []byte("NEOFS-"), []byte("neofs-")} +var frostfsAttributeHeaderPrefixes = [...][]byte{[]byte("Neofs-"), []byte("NEOFS-"), []byte("neofs-")} func systemTranslator(key, prefix []byte) []byte { // replace the specified prefix with `__NEOFS__` @@ -46,7 +46,7 @@ func filterHeaders(l *zap.Logger, header *fasthttp.RequestHeader) (map[string]st clearKey := bytes.TrimPrefix(key, prefix) // checks that it's a system NeoFS header - for _, system := range neofsAttributeHeaderPrefixes { + for _, system := range frostfsAttributeHeaderPrefixes { if bytes.HasPrefix(clearKey, system) { clearKey = systemTranslator(clearKey, system) break diff --git a/uploader/upload.go b/uploader/upload.go index c60beef..9c881de 100644 --- a/uploader/upload.go +++ b/uploader/upload.go @@ -182,8 +182,8 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) { } if idObj, err = u.pool.PutObject(u.appCtx, prm); err != nil { - log.Error("could not store file in neofs", zap.Error(err)) - response.Error(c, "could not store file in neofs: "+err.Error(), fasthttp.StatusBadRequest) + log.Error("could not store file in frostfs", zap.Error(err)) + response.Error(c, "could not store file in frostfs: "+err.Error(), fasthttp.StatusBadRequest) return }