This repository was archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
PMM-3921 MongoDB Management API. #178
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7740410
PMM-3921 Mongodb management api.
fc469c1
PMM-3921 Fix linter err.
42e1405
PMM-3921 Fix service names.
252efa0
PMM-3921 Fix credentials.
9f17944
PMM-3921 Fix deps.
a0ea91d
Merge branch 'PMM-2.0' into PMM-3921-mongodb-management-api
ec80f28
PMM-3921 Fix codestyle.
c916fed
PMM-3921 Fix codestyle.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // pmm-managed | ||
| // Copyright (C) 2017 Percona LLC | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package grpc | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/percona/pmm/api/managementpb" | ||
|
|
||
| "github.com/percona/pmm-managed/services/management" | ||
| ) | ||
|
|
||
| type mongodbServer struct { | ||
| svc *management.MongoDBService | ||
| } | ||
|
|
||
| // NewManagementMongoDBServer creates Management MongoDB Server. | ||
| func NewManagementMongoDBServer(s *management.MongoDBService) managementpb.MongoDBServer { | ||
| return &mongodbServer{svc: s} | ||
| } | ||
|
|
||
| // AddMongoDB adds "MongoDB Service", "MongoDB Exporter Agent" and "QAN MongoDB Profiler". | ||
| func (s *mongodbServer) AddMongoDB(ctx context.Context, req *managementpb.AddMongoDBRequest) (*managementpb.AddMongoDBResponse, error) { | ||
| return s.svc.Add(ctx, req) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // pmm-managed | ||
| // Copyright (C) 2017 Percona LLC | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package management | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/AlekSi/pointer" | ||
| "github.com/percona/pmm/api/inventorypb" | ||
| "github.com/percona/pmm/api/managementpb" | ||
| "gopkg.in/reform.v1" | ||
|
|
||
| "github.com/percona/pmm-managed/models" | ||
|
|
||
| // FIXME Refactor, as service shouldn't depend on other service in one abstraction level. | ||
| // https://jira.percona.com/browse/PMM-3541 | ||
| // See also main_test.go | ||
| "github.com/percona/pmm-managed/services/inventory" | ||
| ) | ||
|
|
||
| // MongoDBService MongoDB Management Service. | ||
| //nolint:unused | ||
| type MongoDBService struct { | ||
| db *reform.DB | ||
| registry registry | ||
| } | ||
|
|
||
| // NewMongoDBService creates new MySQL Management Service. | ||
| func NewMongoDBService(db *reform.DB, registry registry) *MongoDBService { | ||
| return &MongoDBService{db, registry} | ||
| } | ||
|
|
||
| // Add adds "MongoDB Service", "MongoDB Exporter Agent" and "QAN MongoDB Profiler". | ||
| func (s *MongoDBService) Add(ctx context.Context, req *managementpb.AddMongoDBRequest) (res *managementpb.AddMongoDBResponse, err error) { | ||
| res = &managementpb.AddMongoDBResponse{} | ||
|
|
||
| if e := s.db.InTransaction(func(tx *reform.TX) error { | ||
| service, err := models.AddNewService(tx.Querier, models.MongoDBServiceType, &models.AddDBMSServiceParams{ | ||
| ServiceName: req.ServiceName, | ||
| NodeID: req.NodeId, | ||
| Address: pointer.ToStringOrNil(req.Address), | ||
| Port: pointer.ToUint16OrNil(uint16(req.Port)), | ||
| }) | ||
|
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| invService, err := inventory.ToInventoryService(service) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| res.Service = invService.(*inventorypb.MongoDBService) | ||
|
|
||
| if req.MongodbExporter { | ||
| params := &models.AddExporterAgentParams{ | ||
| PMMAgentID: req.PmmAgentId, | ||
| ServiceID: invService.ID(), | ||
| Username: req.Username, | ||
| Password: req.Password, | ||
| } | ||
| row, err := models.AgentAddExporter(tx.Querier, models.MongoDBExporterType, params) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| agent, err := inventory.ToInventoryAgent(tx.Querier, row, s.registry) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| res.MongodbExporter = agent.(*inventorypb.MongoDBExporter) | ||
| } | ||
|
|
||
| if req.QanMongodbProfiler { | ||
| params := &models.AddExporterAgentParams{ | ||
| PMMAgentID: req.PmmAgentId, | ||
| ServiceID: invService.ID(), | ||
| Username: req.Username, | ||
| Password: req.Password, | ||
| } | ||
|
|
||
| row, err := models.AgentAddExporter(tx.Querier, models.QANMongoDBProfilerAgentType, params) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| qAgent, err := inventory.ToInventoryAgent(tx.Querier, row, s.registry) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| res.QanMongodbProfiler = qAgent.(*inventorypb.QANMongoDBProfilerAgent) | ||
| } | ||
|
|
||
| return nil | ||
| }); e != nil { | ||
| return nil, e | ||
| } | ||
|
|
||
| s.registry.SendSetStateRequest(ctx, req.PmmAgentId) | ||
|
|
||
| return res, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.