Skip to content

Commit

Permalink
PMM-12913 migrate /v1/inventory/Nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Mar 24, 2024
1 parent 39b9316 commit b20073a
Show file tree
Hide file tree
Showing 26 changed files with 12,761 additions and 12,892 deletions.
34 changes: 17 additions & 17 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,23 @@ clean: clean_swagger ## Remove generated files
find api -name '*.validate.go' -print -delete

SPECS="\
api/agentlocal/v1 \
api/server/v1 \
api/user/v1 \
api/inventory/v1 \
api/management/v1 \
api/management/v1/agent \
api/management/v1/node \
api/management/v1/service \
api/actions/v1 \
api/alerting/v1 \
api/advisors/v1 \
api/backup/v1 \
api/dump/v1 \
api/role/v1 \
api/qan/v1 \
api/platform/v1"; \
for API in $$SPECS; do \
api/agentlocal/v1 \
api/server/v1 \
api/user/v1 \
api/inventory/v1 \
api/management/v1 \
api/management/v1/agent \
api/management/v1/node \
api/management/v1/service \
api/actions/v1 \
api/alerting/v1 \
api/advisors/v1 \
api/backup/v1 \
api/dump/v1 \
api/role/v1 \
api/qan/v1 \
api/platform/v1"; \
for API in $$SPECS; do \
rm -fr $$API/json/client $$API/json/models $$API/json/$$(basename $$API).json ; \
done
rm -f api/swagger/swagger.json api/swagger/swagger-dev.json
Expand Down
4 changes: 1 addition & 3 deletions admin/commands/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ func (cmd *AnnotationCommand) getCurrentNode() (*nodes.GetNodeOKBody, error) {
}

params := &nodes.GetNodeParams{
Body: nodes.GetNodeBody{
NodeID: status.NodeID,
},
NodeID: status.NodeID,
Context: Ctx,
}

Expand Down
4 changes: 2 additions & 2 deletions admin/commands/inventory/list_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (cmd *ListNodesCommand) RunCmd() (commands.Result, error) {
}

params := &nodes.ListNodesParams{
Body: nodes.ListNodesBody{NodeType: nodeType},
Context: commands.Ctx,
NodeType: nodeType,
Context: commands.Ctx,
}
result, err := client.Default.NodesService.ListNodes(params)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions admin/commands/inventory/remove_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package inventory

import (
"github.com/AlekSi/pointer"

"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventory/v1/json/client"
nodes "github.com/percona/pmm/api/inventory/v1/json/client/nodes_service"
Expand All @@ -41,10 +43,8 @@ type RemoveNodeCommand struct {
// RunCmd runs the command for RemoveNodeCommand.
func (cmd *RemoveNodeCommand) RunCmd() (commands.Result, error) {
params := &nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{
NodeID: cmd.NodeID,
Force: cmd.Force,
},
NodeID: cmd.NodeID,
Force: pointer.ToBool(cmd.Force),
Context: commands.Ctx,
}
_, err := client.Default.NodesService.RemoveNode(params)
Expand Down
11 changes: 4 additions & 7 deletions admin/commands/management/unregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package management

import (
"github.com/AlekSi/pointer"
"github.com/pkg/errors"

"github.com/percona/pmm/admin/agentlocal"
Expand Down Expand Up @@ -65,9 +66,7 @@ func (cmd *UnregisterCommand) RunCmd() (commands.Result, error) {
nodeID = status.NodeID
node, err := client.Default.NodesService.GetNode(&nodes.GetNodeParams{
Context: commands.Ctx,
Body: nodes.GetNodeBody{
NodeID: nodeID,
},
NodeID: nodeID,
})
if err != nil {
return nil, err
Expand All @@ -79,10 +78,8 @@ func (cmd *UnregisterCommand) RunCmd() (commands.Result, error) {
}

params := &nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{
NodeID: nodeID,
Force: cmd.Force,
},
NodeID: nodeID,
Force: pointer.ToBool(cmd.Force),
Context: commands.Ctx,
}

Expand Down
4 changes: 1 addition & 3 deletions api-tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ func RemoveNodes(t TestingT, nodeIDs ...string) {

for _, nodeID := range nodeIDs {
params := &nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{
NodeID: nodeID,
},
NodeID: nodeID,
Context: context.Background(),
}
res, err := client.Default.NodesService.RemoveNode(params)
Expand Down
59 changes: 21 additions & 38 deletions api-tests/inventory/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
nodes "github.com/percona/pmm/api/inventory/v1/json/client/nodes_service"
services "github.com/percona/pmm/api/inventory/v1/json/client/services_service"
"github.com/percona/pmm/api/inventory/v1/types"
)

func TestNodes(t *testing.T) {
Expand Down Expand Up @@ -77,10 +78,8 @@ func TestNodes(t *testing.T) {
}, "There should be a remote node with id `%s`", remoteNodeID)

res, err = client.Default.NodesService.ListNodes(&nodes.ListNodesParams{
Body: nodes.ListNodesBody{
NodeType: pointer.ToString(nodes.ListNodesBodyNodeTypeNODETYPEGENERICNODE),
},
Context: pmmapitests.Context,
NodeType: pointer.ToString(types.NodeTypeGenericNode),
Context: pmmapitests.Context,
})
require.NoError(t, err)
require.NotEmptyf(t, res.Payload.Generic, "There should be at least one generic node")
Expand Down Expand Up @@ -125,7 +124,7 @@ func TestGetNode(t *testing.T) {
}

params := &nodes.GetNodeParams{
Body: nodes.GetNodeBody{NodeID: nodeID},
NodeID: nodeID,
Context: pmmapitests.Context,
}
res, err := client.Default.NodesService.GetNode(params)
Expand All @@ -137,7 +136,7 @@ func TestGetNode(t *testing.T) {
t.Parallel()

params := &nodes.GetNodeParams{
Body: nodes.GetNodeBody{NodeID: "pmm-not-found"},
NodeID: "pmm-not-found",
Context: pmmapitests.Context,
}
res, err := client.Default.NodesService.GetNode(params)
Expand All @@ -149,7 +148,6 @@ func TestGetNode(t *testing.T) {
t.Parallel()

params := &nodes.GetNodeParams{
Body: nodes.GetNodeBody{},
Context: pmmapitests.Context,
}
res, err := client.Default.NodesService.GetNode(params)
Expand Down Expand Up @@ -182,7 +180,7 @@ func TestGenericNode(t *testing.T) {

// Check that the node exists in DB.
getNodeRes, err := client.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{NodeID: nodeID},
NodeID: nodeID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -249,7 +247,7 @@ func TestContainerNode(t *testing.T) {

// Check that the node exists in DB.
getNodeRes, err := client.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{NodeID: nodeID},
NodeID: nodeID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -319,7 +317,7 @@ func TestRemoteNode(t *testing.T) {

// Check node exists in DB.
getNodeRes, err := client.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{NodeID: nodeID},
NodeID: nodeID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -378,9 +376,7 @@ func TestRemoveNode(t *testing.T) {
nodeID := node.Generic.NodeID

removeResp, err := client.Default.NodesService.RemoveNode(&nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{
NodeID: nodeID,
},
NodeID: nodeID,
Context: context.Background(),
})
assert.NoError(t, err)
Expand Down Expand Up @@ -412,17 +408,15 @@ func TestRemoveNode(t *testing.T) {
serviceID := service.Mysql.ServiceID

removeResp, err := client.Default.NodesService.RemoveNode(&nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{
NodeID: node.Generic.NodeID,
},
NodeID: node.Generic.NodeID,
Context: context.Background(),
})
pmmapitests.AssertAPIErrorf(t, err, 400, codes.FailedPrecondition, `Node with ID %q has services.`, node.Generic.NodeID)
assert.Nil(t, removeResp)

// Check that node and service isn't removed.
getServiceResp, err := client.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{NodeID: node.Generic.NodeID},
NodeID: node.Generic.NodeID,
Context: pmmapitests.Context,
})
assert.NotNil(t, getServiceResp)
Expand All @@ -448,10 +442,8 @@ func TestRemoveNode(t *testing.T) {

// Remove with force flag.
params := &nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{
NodeID: node.Generic.NodeID,
Force: true,
},
NodeID: node.Generic.NodeID,
Force: pointer.ToBool(true),
Context: pmmapitests.Context,
}
res, err := client.Default.NodesService.RemoveNode(params)
Expand All @@ -460,7 +452,7 @@ func TestRemoveNode(t *testing.T) {

// Check that the node and agents are removed.
getServiceResp, err = client.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{NodeID: node.Generic.NodeID},
NodeID: node.Generic.NodeID,
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, "Node with ID %q not found.", node.Generic.NodeID)
Expand Down Expand Up @@ -499,20 +491,16 @@ func TestRemoveNode(t *testing.T) {
_ = pmmapitests.AddPMMAgent(t, node.Generic.NodeID)

removeResp, err := client.Default.NodesService.RemoveNode(&nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{
NodeID: node.Generic.NodeID,
},
NodeID: node.Generic.NodeID,
Context: context.Background(),
})
pmmapitests.AssertAPIErrorf(t, err, 400, codes.FailedPrecondition, `Node with ID %q has pmm-agent.`, node.Generic.NodeID)
assert.Nil(t, removeResp)

// Remove with force flag.
params := &nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{
NodeID: node.Generic.NodeID,
Force: true,
},
NodeID: node.Generic.NodeID,
Force: pointer.ToBool(true),
Context: pmmapitests.Context,
}
res, err := client.Default.NodesService.RemoveNode(params)
Expand All @@ -521,7 +509,7 @@ func TestRemoveNode(t *testing.T) {

// Check that the node and agents are removed.
getServiceResp, err := client.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{NodeID: node.Generic.NodeID},
NodeID: node.Generic.NodeID,
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, "Node with ID %q not found.", node.Generic.NodeID)
Expand All @@ -539,9 +527,7 @@ func TestRemoveNode(t *testing.T) {
t.Parallel()
nodeID := "not-exist-node-id"
removeResp, err := client.Default.NodesService.RemoveNode(&nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{
NodeID: nodeID,
},
NodeID: nodeID,
Context: context.Background(),
})
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, `Node with ID %q not found.`, nodeID)
Expand All @@ -551,7 +537,6 @@ func TestRemoveNode(t *testing.T) {
t.Run("Empty params", func(t *testing.T) {
t.Parallel()
removeResp, err := client.Default.NodesService.RemoveNode(&nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{},
Context: context.Background(),
})
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid RemoveNodeRequest.NodeId: value length must be at least 1 runes")
Expand All @@ -562,10 +547,8 @@ func TestRemoveNode(t *testing.T) {
t.Parallel()

removeResp, err := client.Default.NodesService.RemoveNode(&nodes.RemoveNodeParams{
Body: nodes.RemoveNodeBody{
NodeID: "pmm-server",
Force: true,
},
NodeID: "pmm-server",
Force: pointer.ToBool(true),
Context: context.Background(),
})
pmmapitests.AssertAPIErrorf(t, err, 403, codes.PermissionDenied, "PMM Server node can't be removed.")
Expand Down
4 changes: 1 addition & 3 deletions api-tests/management/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ func TestAddExternal(t *testing.T) {

// Check that node is created and its fields.
node, err := inventoryClient.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{
NodeID: nodeID,
},
NodeID: nodeID,
Context: pmmapitests.Context,
})
assert.NoError(t, err)
Expand Down
4 changes: 1 addition & 3 deletions api-tests/management/haproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ func TestAddHAProxy(t *testing.T) {

// Check that node is created and its fields.
node, err := inventoryClient.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{
NodeID: nodeID,
},
NodeID: nodeID,
Context: pmmapitests.Context,
})
assert.NoError(t, err)
Expand Down
4 changes: 1 addition & 3 deletions api-tests/management/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ func assertNodeCreated(t pmmapitests.TestingT, nodeID string, expectedResult nod
t.Helper()

nodeOK, err := inventoryClient.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{
NodeID: nodeID,
},
NodeID: nodeID,
Context: pmmapitests.Context,
})
assert.NoError(t, err)
Expand Down
8 changes: 2 additions & 6 deletions api-tests/management/rds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ func TestAddRds(t *testing.T) {
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, fmt.Sprintf(`Agent with ID "%s" not found.`, body.RDSExporter.AgentID))

_, err = inventoryClient.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{
NodeID: body.Mysql.NodeID,
},
NodeID: body.Mysql.NodeID,
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, fmt.Sprintf(`Node with ID "%s" not found.`, body.Mysql.NodeID))
Expand Down Expand Up @@ -167,9 +165,7 @@ func TestAddRds(t *testing.T) {
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, fmt.Sprintf(`Agent with ID "%s" not found.`, body.RDSExporter.AgentID))

_, err = inventoryClient.Default.NodesService.GetNode(&nodes.GetNodeParams{
Body: nodes.GetNodeBody{
NodeID: body.Postgresql.NodeID,
},
NodeID: body.Postgresql.NodeID,
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, fmt.Sprintf(`Node with ID "%s" not found.`, body.Postgresql.NodeID))
Expand Down
8 changes: 4 additions & 4 deletions api/MIGRATION_TO_V3.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ POST /v1/inventory/Agents/Remove DELETE /v1/inventory/agents/
POST /v1/inventory/Agents/GetLogs GET /v1/inventory/agents/{id}/logs ✅

**NodesService** **NodesService**
POST /v1/inventory/Nodes/Add POST /v1/inventory/nodes
POST /v1/inventory/Nodes/Get GET /v1/inventory/nodes/{id}
POST /v1/inventory/Nodes/Delete DELETE /v1/inventory/nodes/{id}
POST /v1/inventory/Nodes/List GET /v1/inventory/nodes
POST /v1/inventory/Nodes/Add POST /v1/inventory/nodes
POST /v1/inventory/Nodes/Get GET /v1/inventory/nodes/{node_id} ✅
POST /v1/inventory/Nodes/Delete DELETE /v1/inventory/nodes/{node_id} ✅
POST /v1/inventory/Nodes/List GET /v1/inventory/nodes

**ServicesService** **ServicesService**
POST /v1/inventory/Services/Add POST /v1/inventory/services
Expand Down
Loading

0 comments on commit b20073a

Please sign in to comment.