diff --git a/cmd/multinode/main.go b/cmd/multinode/main.go index a4177e1e2..d20d2f2bf 100644 --- a/cmd/multinode/main.go +++ b/cmd/multinode/main.go @@ -242,7 +242,12 @@ func cmdAdd(cmd *cobra.Command, args []string) (err error) { } service := nodes.NewService(log, dialer, db.Nodes()) - err = service.Add(ctx, node.NodeID, apiSecret[:], node.PublicAddress) + err = service.Add(ctx, nodes.Node{ + ID: node.NodeID, + APISecret: apiSecret[:], + PublicAddress: node.PublicAddress, + Name: node.Name, + }) if err != nil { return err } diff --git a/multinode/console/controllers/nodes.go b/multinode/console/controllers/nodes.go index a096990d0..480853144 100644 --- a/multinode/console/controllers/nodes.go +++ b/multinode/console/controllers/nodes.go @@ -66,7 +66,7 @@ func (controller *Nodes) Add(w http.ResponseWriter, r *http.Request) { return } - if err = controller.service.Add(ctx, id, apiSecret[:], payload.PublicAddress); err != nil { + if err = controller.service.Add(ctx, nodes.Node{ID: id, APISecret: apiSecret[:], PublicAddress: payload.PublicAddress}); err != nil { switch { case nodes.ErrNodeNotReachable.Has(err): controller.serveError(w, http.StatusNotFound, ErrNodes.Wrap(err)) diff --git a/multinode/multinodedb/nodes.go b/multinode/multinodedb/nodes.go index ce8aa06d7..8ce97f056 100644 --- a/multinode/multinodedb/nodes.go +++ b/multinode/multinodedb/nodes.go @@ -102,15 +102,15 @@ func (n *nodesdb) Get(ctx context.Context, id storj.NodeID) (_ nodes.Node, err e } // Add creates new node in NodesDB. -func (n *nodesdb) Add(ctx context.Context, id storj.NodeID, apiSecret []byte, publicAddress string) (err error) { +func (n *nodesdb) Add(ctx context.Context, node nodes.Node) (err error) { defer mon.Task()(&ctx)(&err) _, err = n.methods.Create_Node( ctx, - dbx.Node_Id(id.Bytes()), - dbx.Node_Name(""), - dbx.Node_PublicAddress(publicAddress), - dbx.Node_ApiSecret(apiSecret), + dbx.Node_Id(node.ID.Bytes()), + dbx.Node_Name(node.Name), + dbx.Node_PublicAddress(node.PublicAddress), + dbx.Node_ApiSecret(node.APISecret), ) return ErrNodesDB.Wrap(err) diff --git a/multinode/nodes/nodes.go b/multinode/nodes/nodes.go index 540df2cae..574aca867 100644 --- a/multinode/nodes/nodes.go +++ b/multinode/nodes/nodes.go @@ -25,8 +25,7 @@ type DB interface { // because paging doesn't necessarily mean pagination in computing. ListPaged(ctx context.Context, cursor Cursor) (page Page, err error) // Add creates new node in NodesDB. - // TODO: pass Node entity instead of set of a parameters. - Add(ctx context.Context, id storj.NodeID, apiSecret []byte, publicAddress string) error + Add(ctx context.Context, node Node) error // Remove removed node from NodesDB. Remove(ctx context.Context, id storj.NodeID) error // UpdateName will update name of the specified node in database. diff --git a/multinode/nodes/nodes_test.go b/multinode/nodes/nodes_test.go index 1c2b23f2b..a4445ac3a 100644 --- a/multinode/nodes/nodes_test.go +++ b/multinode/nodes/nodes_test.go @@ -26,7 +26,7 @@ func TestNodesDB(t *testing.T) { apiSecret := []byte("secret") publicAddress := "228.13.38.1:8081" - err := nodesRepository.Add(ctx, nodeID, apiSecret, publicAddress) + err := nodesRepository.Add(ctx, nodes.Node{ID: nodeID, APISecret: apiSecret, PublicAddress: publicAddress}) assert.NoError(t, err) node, err := nodesRepository.Get(ctx, nodeID) @@ -72,7 +72,7 @@ func TestNodesDB(t *testing.T) { Name: fmt.Sprintf("%d", i), } nodeList = append(nodeList, node) - err := nodesRepository.Add(ctx, node.ID, node.APISecret, node.PublicAddress) + err := nodesRepository.Add(ctx, node) require.NoError(t, err) } page, err := nodesRepository.ListPaged(ctx, nodes.Cursor{ diff --git a/multinode/nodes/service.go b/multinode/nodes/service.go index 7631fc651..4b25781ad 100644 --- a/multinode/nodes/service.go +++ b/multinode/nodes/service.go @@ -48,13 +48,13 @@ func NewService(log *zap.Logger, dialer rpc.Dialer, nodes DB) *Service { } // Add adds new node to the system. -func (service *Service) Add(ctx context.Context, id storj.NodeID, apiSecret []byte, publicAddress string) (err error) { +func (service *Service) Add(ctx context.Context, node Node) (err error) { defer mon.Task()(&ctx)(&err) // trying to connect to node to check its availability. conn, err := service.dialer.DialNodeURL(ctx, storj.NodeURL{ - ID: id, - Address: publicAddress, + ID: node.ID, + Address: node.PublicAddress, }) if err != nil { return ErrNodeNotReachable.Wrap(err) @@ -65,7 +65,7 @@ func (service *Service) Add(ctx context.Context, id storj.NodeID, apiSecret []by nodeClient := multinodepb.NewDRPCNodeClient(conn) header := &multinodepb.RequestHeader{ - ApiKey: apiSecret, + ApiKey: node.APISecret, } // making test request to check node api key. @@ -77,7 +77,7 @@ func (service *Service) Add(ctx context.Context, id storj.NodeID, apiSecret []by return Error.Wrap(err) } - return Error.Wrap(service.nodes.Add(ctx, id, apiSecret, publicAddress)) + return Error.Wrap(service.nodes.Add(ctx, node)) } // List returns list of all nodes.