-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: refactor metadata config and change http address to grpc address #170
Changes from 4 commits
7cb6600
9e43ed9
251c284
be6d838
1876444
fe885f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,10 +86,14 @@ func NewGatewayService(cfg *GatewayConfig) (*Gateway, error) { | |
return nil, err | ||
} | ||
} | ||
if g.metadata, err = client.NewMetadataClient(g.config.MetadataServiceAddress); err != nil { | ||
log.Warnw("failed to create metadata client", "err", err) | ||
return nil, err | ||
|
||
if cfg.MetadataServiceAddress != "" { | ||
if g.metadata, err = client.NewMetadataClient(cfg.MetadataServiceAddress); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. metadata handler needs to check g.metadata != nil There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If metadata is nil, will metadata related requests(the metadata handler) cause the gateway to crash? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed, add if statement for error response and create errorJSONResponse for response(Clyde said we will provide JSON type in phase 1 api) |
||
log.Errorw("failed to create metadata client", "error", err) | ||
return nil, err | ||
} | ||
} | ||
|
||
log.Debugw("gateway succeed to init") | ||
return g, nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,40 @@ import ( | |
|
||
"github.com/bnb-chain/greenfield-storage-provider/model" | ||
"github.com/bnb-chain/greenfield-storage-provider/pkg/log" | ||
stypes "github.com/bnb-chain/greenfield-storage-provider/service/metadata/types" | ||
"github.com/gorilla/mux" | ||
metatypes "github.com/bnb-chain/greenfield-storage-provider/service/metadata/types" | ||
) | ||
|
||
// getUserBucketsHandler handle get object request | ||
func (g *Gateway) getUserBucketsHandler(w http.ResponseWriter, r *http.Request) { | ||
vars := mux.Vars(r) | ||
var ( | ||
err error | ||
errDescription *errorDescription | ||
reqContext *requestContext | ||
statusCode = http.StatusOK | ||
) | ||
|
||
req := &stypes.MetadataServiceGetUserBucketsRequest{ | ||
AccountId: vars["account_id"], | ||
reqContext = newRequestContext(r) | ||
defer func() { | ||
if errDescription != nil { | ||
statusCode = errDescription.statusCode | ||
_ = errDescription.errorJSONResponse(w, reqContext) | ||
} | ||
if statusCode == http.StatusOK { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. StatusCode can be omitted, and errDescription.statusCode can be used directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
log.Infof("action(%v) statusCode(%v) %v", getUserBucketsRouterName, statusCode, reqContext.generateRequestDetail()) | ||
} else { | ||
log.Errorf("action(%v) statusCode(%v) %v", getUserBucketsRouterName, statusCode, reqContext.generateRequestDetail()) | ||
} | ||
}() | ||
|
||
if g.metadata == nil { | ||
log.Errorw("failed to get user buckets due to not config metadata") | ||
errDescription = NotExistComponentError | ||
return | ||
} | ||
|
||
req := &metatypes.MetadataServiceGetUserBucketsRequest{ | ||
AccountId: reqContext.accountID, | ||
} | ||
ctx := log.Context(context.Background(), req) | ||
resp, err := g.metadata.GetUserBuckets(ctx, req) | ||
if err != nil { | ||
|
@@ -36,11 +58,35 @@ func (g *Gateway) getUserBucketsHandler(w http.ResponseWriter, r *http.Request) | |
|
||
// listObjectsByBucketNameHandler handle list objects by bucket name request | ||
func (g *Gateway) listObjectsByBucketNameHandler(w http.ResponseWriter, r *http.Request) { | ||
vars := mux.Vars(r) | ||
var ( | ||
err error | ||
errDescription *errorDescription | ||
reqContext *requestContext | ||
statusCode = http.StatusOK | ||
) | ||
|
||
reqContext = newRequestContext(r) | ||
defer func() { | ||
if errDescription != nil { | ||
statusCode = errDescription.statusCode | ||
_ = errDescription.errorJSONResponse(w, reqContext) | ||
} | ||
if statusCode == http.StatusOK { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
log.Infof("action(%v) statusCode(%v) %v", listObjectsByBucketRouterName, statusCode, reqContext.generateRequestDetail()) | ||
} else { | ||
log.Errorf("action(%v) statusCode(%v) %v", listObjectsByBucketRouterName, statusCode, reqContext.generateRequestDetail()) | ||
} | ||
}() | ||
|
||
if g.metadata == nil { | ||
log.Errorw("failed to list objects by bucket name due to not config metadata") | ||
errDescription = NotExistComponentError | ||
return | ||
} | ||
|
||
req := &stypes.MetadataServiceListObjectsByBucketNameRequest{ | ||
BucketName: vars["bucket_name"], | ||
AccountId: vars["account_id"], | ||
req := &metatypes.MetadataServiceListObjectsByBucketNameRequest{ | ||
BucketName: reqContext.bucketName, | ||
AccountId: reqContext.accountID, | ||
} | ||
|
||
ctx := log.Context(context.Background(), req) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mete->meta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed