From 1bb07aa65fb7984a3111aa3b38153201c857b730 Mon Sep 17 00:00:00 2001 From: yyhenryyy Date: Wed, 13 Mar 2024 20:35:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(mongodb):=20mongodb=E5=AE=B9=E9=87=8F?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=20#3510?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-services/go.work | 6 +- .../db-tools/dbactuator/.gitignore | 2 +- .../db-tools/dbactuator/LICENSE | 0 .../db-tools/dbactuator/Makefile | 0 .../db-tools/dbactuator/README.md | 0 .../db-tools/dbactuator/cmd/root.go | 6 +- .../example/add_shard_to_cluster.example.md | 0 .../example/cluster_balancer.example.md | 0 .../example/initiate_replicaset.example.md | 0 .../example/mongo_add_user.example.md | 0 .../example/mongo_deinstall.example.md | 0 .../example/mongo_del_user.example.md | 0 .../example/mongo_execute_script.example.md | 0 .../example/mongo_process_restart.example.md | 0 .../example/mongod_install.example.md | 0 .../example/mongod_replace.example.md | 0 .../example/mongod_step_down.example.md | 0 .../example/mongos_install.example.md | 0 .../example/os_mongo_init.example.md | 0 .../db-tools/dbactuator/go.mod | 2 +- .../db-tools/dbactuator/go.sum | 0 .../imgs/bk-dbactuator-mongo_structur.png | Bin .../db-tools/dbactuator/main.go | 2 +- .../db-tools/dbactuator/mylog/mylog.go | 0 .../atommongodb/add_shard_to_cluster.go | 8 +- .../pkg/atomjobs/atommongodb/add_user.go | 8 +- .../pkg/atomjobs/atommongodb/atommongodb.go | 0 .../pkg/atomjobs/atommongodb/backup.go | 18 +- .../pkg/atomjobs/atommongodb/base_job.go | 2 +- .../atomjobs/atommongodb/cluster_balancer.go | 8 +- .../pkg/atomjobs/atommongodb/del_user.go | 8 +- .../atommongodb/initiate_replicaset.go | 8 +- .../atomjobs/atommongodb/mongo_deinstall.go | 8 +- .../atommongodb/mongo_execute_script.go | 8 +- .../atommongodb/mongo_process_restart.go | 6 +- .../atommongodb/mongo_set_profiler.go | 8 +- .../atommongodb/mongod_change_oplogsize.go | 8 +- .../atomjobs/atommongodb/mongod_install.go | 8 +- .../atomjobs/atommongodb/mongod_replace.go | 8 +- .../atomjobs/atommongodb/mongos_install.go | 8 +- .../pkg/atomjobs/atommongodb/ns_filter.go | 0 .../pkg/atomjobs/atommongodb/pitr_restore.go | 10 +- .../pkg/atomjobs/atommongodb/remove_ns.go | 6 +- .../atommongodb/replicaset_stepdown.go | 6 +- .../pkg/atomjobs/atommongodb/restore.go | 10 +- .../pkg/atomjobs/atomsys/atomsys.go | 0 .../pkg/atomjobs/atomsys/os_mongo_init.go | 10 +- .../dbactuator/pkg/backupsys/backupsys.go | 6 +- .../dbactuator/pkg/common/exporter_conf.go | 4 +- .../dbactuator/pkg/common/filelock.go | 0 .../pkg/common/initiate_replicaset_conf.go | 0 .../dbactuator/pkg/common/media_pkg.go | 6 +- .../dbactuator/pkg/common/mongo_common.go | 4 +- .../dbactuator/pkg/common/mongo_init_shell.go | 0 .../dbactuator/pkg/common/mongo_user_conf.go | 0 .../dbactuator/pkg/common/mongod_conf.go | 0 .../dbactuator/pkg/common/mongos_conf.go | 0 .../pkg/common/repliccaset_member_conf.go | 0 .../db-tools/dbactuator/pkg/consts/consts.go | 0 .../dbactuator/pkg/consts/data_dir.go | 0 .../db-tools/dbactuator/pkg/consts/mongo.go | 4 +- .../db-tools/dbactuator/pkg/consts/test.go | 0 .../db-tools/dbactuator/pkg/consts/user.go | 0 .../dbactuator/pkg/customtime/customtime.go | 0 .../dbactuator/pkg/jobmanager/jobmanager.go | 8 +- .../dbactuator/pkg/jobruntime/jobrunner.go | 0 .../dbactuator/pkg/jobruntime/jobruntime.go | 6 +- .../db-tools/dbactuator/pkg/util/bkrepo.go | 2 +- .../db-tools/dbactuator/pkg/util/compress.go | 4 +- .../db-tools/dbactuator/pkg/util/file.go | 0 .../db-tools/dbactuator/pkg/util/net.go | 0 .../db-tools/dbactuator/pkg/util/osCmd.go | 2 +- .../db-tools/dbactuator/pkg/util/reflect.go | 0 .../db-tools/dbactuator/pkg/util/util.go | 2 +- .../db-tools/dbactuator/pkg/util/version.go | 0 .../db-tools/dbactuator/scripts/upload.sh | 0 .../db-tools/dbactuator/tests/test_mongo.sh | 0 .../db-tools/dbmon/.ci/codecc.yml | 0 .../db-tools/dbmon/.ci/open_source_check.yml | 0 .../dbmon/.ci/templates/open_source_gate.yml | 0 .../db-tools/dbmon/.gitignore | 0 .../{mongo => mongodb}/db-tools/dbmon/LICENSE | 0 .../db-tools/dbmon/Makefile | 2 +- .../db-tools/dbmon/README.md | 0 .../dbmon/cmd/dbmonheartbeat/dbmonhearbeat.go | 0 .../db-tools/dbmon/cmd/dbmonheartbeat/job.go | 6 +- .../db-tools/dbmon/cmd/debug.go | 6 +- .../db-tools/dbmon/cmd/mongojob/backup_job.go | 10 +- .../dbmon/cmd/mongojob/backup_task.go | 6 +- .../dbmon/cmd/mongojob/check_health_job.go | 10 +- .../db-tools/dbmon/cmd/mongojob/cmd.go | 2 +- .../db-tools/dbmon/cmd/mongojob/mongojob.go | 0 .../db-tools/dbmon/cmd/mongojob/msg.go | 6 +- .../db-tools/dbmon/cmd/root.go | 12 +- .../db-tools/dbmon/config/config.go | 0 .../db-tools/dbmon/config/instconfig.go | 0 .../db-tools/dbmon/dbmon-config.yaml | 0 .../db-tools/dbmon/embedfiles/embedfiles.go | 0 .../db-tools/dbmon/embedfiles/js/login-js | 0 .../{mongo => mongodb}/db-tools/dbmon/go.mod | 2 +- .../{mongo => mongodb}/db-tools/dbmon/go.sum | 0 .../{mongo => mongodb}/db-tools/dbmon/main.go | 2 +- .../db-tools/dbmon/models/mymongo/mymongo.go | 0 .../db-tools/dbmon/mylog/gin.go | 0 .../db-tools/dbmon/mylog/mylog.go | 2 +- .../db-tools/dbmon/package.sh | 0 .../db-tools/dbmon/pkg/consts/consts.go | 0 .../db-tools/dbmon/pkg/consts/data_dir.go | 0 .../dbmon/pkg/consts/event_categories.go | 0 .../db-tools/dbmon/pkg/consts/mongo.go | 0 .../db-tools/dbmon/pkg/httpapi/httpapi.go | 6 +- .../db-tools/dbmon/pkg/linuxproc/net_tcp.go | 0 .../db-tools/dbmon/pkg/mongoproc/mongoproc.go | 0 .../dbmon/pkg/sendwarning/bkmonitorbeat.go | 8 +- .../dbmon/pkg/sendwarning/sendwarning.go | 0 .../db-tools/dbmon/servers.yaml | 0 .../db-tools/dbmon/start.sh | 0 .../{mongo => mongodb}/db-tools/dbmon/stop.sh | 0 .../db-tools/dbmon/util/osCmd.go | 2 +- .../db-tools/dbmon/util/util.go | 4 +- .../db-tools/mongo-toolkit-go/.gitignore | 0 .../db-tools/mongo-toolkit-go/Makefile | 0 .../db-tools/mongo-toolkit-go/ReadMe | 0 .../db-tools/mongo-toolkit-go/VERSION | 0 .../cmd/mongo-toolkit-go/main.go | 2 +- .../cmd/mongo-toolkit-go/tools/dump.go | 10 +- .../cmd/mongo-toolkit-go/tools/pitr_backup.go | 6 +- .../mongo-toolkit-go/tools/pitr_recover.go | 4 +- .../cmd/mongo-toolkit-go/tools/restore.go | 6 +- .../cmd/mongo-toolkit-go/tools/root.go | 0 .../cmd/mongo-toolkit-go/tools/version.go | 0 .../db-tools/mongo-toolkit-go/go.mod | 2 +- .../db-tools/mongo-toolkit-go/go.sum | 0 .../pkg/backupsys/backup_client.go | 2 +- .../pkg/backupsys/backup_client_test.go | 0 .../mongo-toolkit-go/pkg/backupsys/query.go | 0 .../mongo-toolkit-go/pkg/backupsys/recover.go | 0 .../mongo-toolkit-go/pkg/disk/disk.go | 0 .../mongo-toolkit-go/pkg/disk/stat_darwin.go | 0 .../mongo-toolkit-go/pkg/disk/stat_linux.go | 0 .../pkg/fileperm/file-perm.go | 0 .../pkg/fileperm/is-writable.go | 0 .../db-tools/mongo-toolkit-go/pkg/mycmd/bg.go | 0 .../mongo-toolkit-go/pkg/mycmd/mycmd.go | 0 .../mongo-toolkit-go/pkg/mycmd/mycmd_test.go | 0 .../mongo-toolkit-go/pkg/mycmd/run.go | 0 .../mongo-toolkit-go/pkg/mymongo/index.go | 0 .../mongo-toolkit-go/pkg/mymongo/mymongo.go | 0 .../mongo-toolkit-go/pkg/mymongo/util.go | 0 .../mongo-toolkit-go/pkg/mymongo/version.go | 0 .../pkg/report/backup_record.go | 2 +- .../mongo-toolkit-go/pkg/report/report.go | 2 +- .../db-tools/mongo-toolkit-go/pkg/util/cmd.go | 0 .../db-tools/mongo-toolkit-go/pkg/util/fs.go | 0 .../toolkit/logical/db_collection.go | 2 +- .../mongo-toolkit-go/toolkit/logical/dump.go | 8 +- .../toolkit/logical/logical.go | 0 .../toolkit/logical/ns_filter.go | 0 .../toolkit/logical/ns_filter_test.go | 0 .../toolkit/logical/restore.go | 6 +- .../toolkit/logical/tmpdir.go | 0 .../mongo-toolkit-go/toolkit/pitr/backup.go | 6 +- .../toolkit/pitr/backup_record.go | 0 .../toolkit/pitr/backup_test.go | 0 .../mongo-toolkit-go/toolkit/pitr/filename.go | 2 +- .../toolkit/pitr/filename_test.go | 0 .../mongo-toolkit-go/toolkit/pitr/job.go | 8 +- .../mongo-toolkit-go/toolkit/pitr/meta.go | 2 +- .../mongo-toolkit-go/toolkit/pitr/metav2.go | 6 +- .../toolkit/pitr/metav2_test.go | 0 .../mongo-toolkit-go/toolkit/pitr/pitr.go | 0 .../mongo-toolkit-go/toolkit/pitr/recover.go | 4 +- .../toolkit/pitr/recover_helper.go | 0 .../mongo-toolkit-go/toolkit/pitr/report.go | 0 .../mongo-toolkit-go/toolkit/pitr/util.go | 0 .../atommongodb/add_shard_to_cluster.go | 248 ----- .../pkg/atomjobs/atommongodb/add_user.go | 263 ------ .../pkg/atomjobs/atommongodb/atommongodb.go | 2 - .../atomjobs/atommongodb/cluster_balancer.go | 159 ---- .../atommongodb/cluster_install_test.go | 889 ------------------ .../pkg/atomjobs/atommongodb/del_user.go | 204 ---- .../atommongodb/initiate_replicaset.go | 279 ------ .../atomjobs/atommongodb/mongo_deinstall.go | 230 ----- .../atommongodb/mongo_execute_script.go | 331 ------- .../atommongodb/mongo_process_restart.go | 399 -------- .../atommongodb/mongo_set_profiler.go | 186 ---- .../atomjobs/atommongodb/mongod_install.go | 492 ---------- .../atomjobs/atommongodb/mongod_replace.go | 356 ------- .../atomjobs/atommongodb/mongos_install.go | 440 --------- .../atommongodb/replicaset_install_test.go | 339 ------- .../atommongodb/replicaset_stepdown.go | 130 --- .../pkg/atomjobs/atomsys/os_mongo_init.go | 123 --- .../dbactuator/pkg/jobmanager/jobmanager.go | 16 - .../scene/mongodb/mongodb_scale_storage.py | 69 ++ .../bamboo/scene/mongodb/sub_task/__init__.py | 2 + .../scene/mongodb/sub_task/cluster_replace.py | 8 +- .../scene/mongodb/sub_task/cluster_scale.py | 77 ++ .../scene/mongodb/sub_task/increase_mongos.py | 8 +- .../scene/mongodb/sub_task/mongod_replace.py | 21 +- .../mongodb/sub_task/replicaset_replace.py | 10 +- .../mongodb/sub_task/replicaset_scale.py | 92 ++ .../backend/flow/engine/controller/mongodb.py | 9 + .../collections/mongodb/exec_actuator_job.py | 20 +- dbm-ui/backend/flow/urls.py | 2 + .../flow/utils/mongodb/mongodb_dataclass.py | 190 +++- dbm-ui/backend/flow/views/mongodb_scene.py | 12 + 206 files changed, 691 insertions(+), 5311 deletions(-) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/.gitignore (93%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/LICENSE (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/Makefile (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/README.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/cmd/root.go (96%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/add_shard_to_cluster.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/cluster_balancer.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/initiate_replicaset.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/mongo_add_user.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/mongo_deinstall.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/mongo_del_user.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/mongo_execute_script.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/mongo_process_restart.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/mongod_install.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/mongod_replace.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/mongod_step_down.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/mongos_install.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/example/os_mongo_init.example.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/go.mod (96%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/go.sum (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/imgs/bk-dbactuator-mongo_structur.png (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/main.go (69%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/mylog/mylog.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go (97%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go (97%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/atommongodb.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/backup.go (94%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/base_job.go (95%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go (95%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go (96%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go (97%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go (96%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go (96%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_change_oplogsize.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/ns_filter.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/pitr_restore.go (95%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/remove_ns.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go (95%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atommongodb/restore.go (96%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atomsys/atomsys.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go (92%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/backupsys/backupsys.go (97%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/common/exporter_conf.go (90%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/common/filelock.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/common/initiate_replicaset_conf.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/common/media_pkg.go (96%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/common/mongo_common.go (99%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/common/mongo_init_shell.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/common/mongo_user_conf.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/common/mongod_conf.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/common/mongos_conf.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/common/repliccaset_member_conf.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/consts/consts.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/consts/data_dir.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/consts/mongo.go (95%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/consts/test.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/consts/user.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/customtime/customtime.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/jobmanager/jobmanager.go (94%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/jobruntime/jobrunner.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/jobruntime/jobruntime.go (96%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/util/bkrepo.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/util/compress.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/util/file.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/util/net.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/util/osCmd.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/util/reflect.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/util/util.go (99%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/pkg/util/version.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/scripts/upload.sh (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbactuator/tests/test_mongo.sh (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/.ci/codecc.yml (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/.ci/open_source_check.yml (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/.ci/templates/open_source_gate.yml (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/.gitignore (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/LICENSE (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/Makefile (93%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/README.md (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/cmd/dbmonheartbeat/dbmonhearbeat.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/cmd/dbmonheartbeat/job.go (92%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/cmd/debug.go (94%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/cmd/mongojob/backup_job.go (94%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/cmd/mongojob/backup_task.go (93%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/cmd/mongojob/check_health_job.go (94%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/cmd/mongojob/cmd.go (97%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/cmd/mongojob/mongojob.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/cmd/mongojob/msg.go (94%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/cmd/root.go (93%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/config/config.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/config/instconfig.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/dbmon-config.yaml (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/embedfiles/embedfiles.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/embedfiles/js/login-js (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/go.mod (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/go.sum (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/main.go (75%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/models/mymongo/mymongo.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/mylog/gin.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/mylog/mylog.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/package.sh (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/pkg/consts/consts.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/pkg/consts/data_dir.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/pkg/consts/event_categories.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/pkg/consts/mongo.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/pkg/httpapi/httpapi.go (84%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/pkg/linuxproc/net_tcp.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/pkg/mongoproc/mongoproc.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go (97%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/pkg/sendwarning/sendwarning.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/servers.yaml (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/start.sh (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/stop.sh (100%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/util/osCmd.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/dbmon/util/util.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/.gitignore (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/Makefile (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/ReadMe (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/VERSION (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/main.go (83%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/dump.go (94%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_backup.go (95%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_recover.go (97%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/restore.go (94%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/root.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/version.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/go.mod (95%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/go.sum (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client.go (99%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client_test.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/backupsys/query.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/backupsys/recover.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/disk/disk.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/disk/stat_darwin.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/disk/stat_linux.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/fileperm/file-perm.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/fileperm/is-writable.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/mycmd/bg.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/mycmd/mycmd.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/mycmd/mycmd_test.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/mycmd/run.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/mymongo/index.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/mymongo/mymongo.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/mymongo/util.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/mymongo/version.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/report/backup_record.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/report/report.go (97%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/util/cmd.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/pkg/util/fs.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/logical/db_collection.go (97%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/logical/dump.go (96%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/logical/logical.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/logical/ns_filter.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/logical/ns_filter_test.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/logical/restore.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/logical/tmpdir.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/backup.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/backup_record.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/backup_test.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/filename.go (99%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/filename_test.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/job.go (96%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/meta.go (96%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/metav2.go (98%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/metav2_test.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/pitr.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/recover.go (99%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/recover_helper.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/report.go (100%) rename dbm-services/{mongo => mongodb}/db-tools/mongo-toolkit-go/toolkit/pitr/util.go (100%) delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/atommongodb.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_install_test.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_install_test.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go delete mode 100644 dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go create mode 100644 dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_storage.py create mode 100644 dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_scale.py create mode 100644 dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_scale.py diff --git a/dbm-services/go.work b/dbm-services/go.work index 2d782a1dc9..f0533167fc 100644 --- a/dbm-services/go.work +++ b/dbm-services/go.work @@ -27,7 +27,7 @@ use ( riak/db-tools/dbactuator riak/db-tools/riak-monitor sqlserver/db-tools/dbactuator - mongo/db-tools/dbmon - mongo/db-tools/mongo-toolkit-go - mongo/db-tools/dbactuator + mongodb/db-tools/dbmon + mongodb/db-tools/mongo-toolkit-go + mongodb/db-tools/dbactuator ) diff --git a/dbm-services/mongo/db-tools/dbactuator/.gitignore b/dbm-services/mongodb/db-tools/dbactuator/.gitignore similarity index 93% rename from dbm-services/mongo/db-tools/dbactuator/.gitignore rename to dbm-services/mongodb/db-tools/dbactuator/.gitignore index f6b4016d07..78a3838a7a 100644 --- a/dbm-services/mongo/db-tools/dbactuator/.gitignore +++ b/dbm-services/mongodb/db-tools/dbactuator/.gitignore @@ -1,7 +1,7 @@ .idea .vscode logs/* -bin/mongo-dbactuator +build/mongo-dbactuator scripts/upload_media.sh .codecc gonote diff --git a/dbm-services/mongo/db-tools/dbactuator/LICENSE b/dbm-services/mongodb/db-tools/dbactuator/LICENSE similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/LICENSE rename to dbm-services/mongodb/db-tools/dbactuator/LICENSE diff --git a/dbm-services/mongo/db-tools/dbactuator/Makefile b/dbm-services/mongodb/db-tools/dbactuator/Makefile similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/Makefile rename to dbm-services/mongodb/db-tools/dbactuator/Makefile diff --git a/dbm-services/mongo/db-tools/dbactuator/README.md b/dbm-services/mongodb/db-tools/dbactuator/README.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/README.md rename to dbm-services/mongodb/db-tools/dbactuator/README.md diff --git a/dbm-services/mongo/db-tools/dbactuator/cmd/root.go b/dbm-services/mongodb/db-tools/dbactuator/cmd/root.go similarity index 96% rename from dbm-services/mongo/db-tools/dbactuator/cmd/root.go rename to dbm-services/mongodb/db-tools/dbactuator/cmd/root.go index 62d7d6636b..e22ef4a4ad 100644 --- a/dbm-services/mongo/db-tools/dbactuator/cmd/root.go +++ b/dbm-services/mongodb/db-tools/dbactuator/cmd/root.go @@ -11,9 +11,9 @@ import ( "log" "os" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobmanager" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobmanager" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/spf13/cobra" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/example/add_shard_to_cluster.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/add_shard_to_cluster.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/add_shard_to_cluster.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/add_shard_to_cluster.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/cluster_balancer.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/cluster_balancer.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/cluster_balancer.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/cluster_balancer.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/initiate_replicaset.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/initiate_replicaset.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/initiate_replicaset.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/initiate_replicaset.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/mongo_add_user.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/mongo_add_user.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/mongo_add_user.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/mongo_add_user.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/mongo_deinstall.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/mongo_deinstall.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/mongo_deinstall.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/mongo_deinstall.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/mongo_del_user.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/mongo_del_user.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/mongo_del_user.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/mongo_del_user.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/mongo_execute_script.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/mongo_execute_script.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/mongo_execute_script.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/mongo_execute_script.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/mongo_process_restart.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/mongo_process_restart.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/mongo_process_restart.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/mongo_process_restart.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/mongod_install.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/mongod_install.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/mongod_install.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/mongod_install.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/mongod_replace.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/mongod_replace.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/mongod_replace.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/mongod_replace.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/mongod_step_down.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/mongod_step_down.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/mongod_step_down.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/mongod_step_down.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/mongos_install.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/mongos_install.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/mongos_install.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/mongos_install.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/example/os_mongo_init.example.md b/dbm-services/mongodb/db-tools/dbactuator/example/os_mongo_init.example.md similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/example/os_mongo_init.example.md rename to dbm-services/mongodb/db-tools/dbactuator/example/os_mongo_init.example.md diff --git a/dbm-services/mongo/db-tools/dbactuator/go.mod b/dbm-services/mongodb/db-tools/dbactuator/go.mod similarity index 96% rename from dbm-services/mongo/db-tools/dbactuator/go.mod rename to dbm-services/mongodb/db-tools/dbactuator/go.mod index 959cdaee7f..44e928a012 100644 --- a/dbm-services/mongo/db-tools/dbactuator/go.mod +++ b/dbm-services/mongodb/db-tools/dbactuator/go.mod @@ -1,4 +1,4 @@ -module dbm-services/mongo/db-tools/dbactuator +module dbm-services/mongodb/db-tools/dbactuator go 1.21 diff --git a/dbm-services/mongo/db-tools/dbactuator/go.sum b/dbm-services/mongodb/db-tools/dbactuator/go.sum similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/go.sum rename to dbm-services/mongodb/db-tools/dbactuator/go.sum diff --git a/dbm-services/mongo/db-tools/dbactuator/imgs/bk-dbactuator-mongo_structur.png b/dbm-services/mongodb/db-tools/dbactuator/imgs/bk-dbactuator-mongo_structur.png similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/imgs/bk-dbactuator-mongo_structur.png rename to dbm-services/mongodb/db-tools/dbactuator/imgs/bk-dbactuator-mongo_structur.png diff --git a/dbm-services/mongo/db-tools/dbactuator/main.go b/dbm-services/mongodb/db-tools/dbactuator/main.go similarity index 69% rename from dbm-services/mongo/db-tools/dbactuator/main.go rename to dbm-services/mongodb/db-tools/dbactuator/main.go index 9ae21d63e2..62a22fac1b 100644 --- a/dbm-services/mongo/db-tools/dbactuator/main.go +++ b/dbm-services/mongodb/db-tools/dbactuator/main.go @@ -5,7 +5,7 @@ Copyright © 2022 NAME HERE */ package main -import "dbm-services/mongo/db-tools/dbactuator/cmd" +import "dbm-services/mongodb/db-tools/dbactuator/cmd" func main() { cmd.Execute() diff --git a/dbm-services/mongo/db-tools/dbactuator/mylog/mylog.go b/dbm-services/mongodb/db-tools/dbactuator/mylog/mylog.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/mylog/mylog.go rename to dbm-services/mongodb/db-tools/dbactuator/mylog/mylog.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go similarity index 97% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go index 89ddcfc944..98cf8a0c01 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go similarity index 97% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go index e91209f29d..42aea967ad 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/atommongodb.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/atommongodb.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/atommongodb.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/atommongodb.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/backup.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/backup.go similarity index 94% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/backup.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/backup.go index 7e1662509b..6e044d5327 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/backup.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/backup.go @@ -1,15 +1,15 @@ package atommongodb import ( - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/report" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/report" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical" "encoding/json" "fmt" "path" diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/base_job.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/base_job.go similarity index 95% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/base_job.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/base_job.go index 612ca08f35..c1aa610052 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/base_job.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/base_job.go @@ -1,7 +1,7 @@ package atommongodb import ( - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" "fmt" "os" "os/user" diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go similarity index 95% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go index e75bc226d9..ff479f2406 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go @@ -8,10 +8,10 @@ import ( "strconv" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go similarity index 96% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go index 50f1944ade..6f1a7937ff 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go similarity index 97% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go index 5be66a87b5..a7998a8f0e 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go similarity index 96% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go index e5435a4093..62bdeb29bc 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go similarity index 98% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go index 5690724b65..e49af40407 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go @@ -12,10 +12,10 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go similarity index 98% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go index ad78fddef7..5dbf2cd4c7 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go @@ -9,9 +9,9 @@ import ( "strconv" "strings" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" "github.com/go-playground/validator/v10" "gopkg.in/yaml.v2" diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go similarity index 96% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go index 2622836d6b..08700c7b9e 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_change_oplogsize.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_change_oplogsize.go similarity index 98% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_change_oplogsize.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_change_oplogsize.go index 8625a5e332..2c4fc540ac 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_change_oplogsize.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_change_oplogsize.go @@ -1,10 +1,10 @@ package atommongodb import ( - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "encoding/json" "fmt" "os" diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go similarity index 98% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go index 3b97db89b7..a39929c775 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go @@ -9,10 +9,10 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go similarity index 98% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go index 5ec02864af..1be1ad55a4 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go similarity index 98% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go index 295ba0085b..a402638fd9 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go @@ -9,10 +9,10 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/ns_filter.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/ns_filter.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/ns_filter.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/ns_filter.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/pitr_restore.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/pitr_restore.go similarity index 95% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/pitr_restore.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/pitr_restore.go index c26944cda7..1fa13cb54a 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/pitr_restore.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/pitr_restore.go @@ -2,11 +2,11 @@ package atommongodb import ( "context" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr" "encoding/json" "fmt" "os" diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/remove_ns.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/remove_ns.go similarity index 98% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/remove_ns.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/remove_ns.go index 515e28bb54..ef495a3202 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/remove_ns.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/remove_ns.go @@ -2,9 +2,9 @@ package atommongodb import ( "context" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical" "encoding/json" "fmt" "strings" diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go similarity index 95% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go index 5d546d2295..6910070788 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go @@ -7,9 +7,9 @@ import ( "strconv" "strings" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/restore.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/restore.go similarity index 96% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/restore.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/restore.go index f4b3d947e8..268dcc8475 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb/restore.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/restore.go @@ -1,11 +1,11 @@ package atommongodb import ( - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical" "encoding/json" "fmt" "os" diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atomsys/atomsys.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atomsys/atomsys.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atomsys/atomsys.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atomsys/atomsys.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go similarity index 92% rename from dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go index 9cf9efda1f..1b3ae91af4 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go @@ -1,17 +1,17 @@ package atomsys import ( - "dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb" + "dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb" "encoding/json" "fmt" "os" "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/common" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/common" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "github.com/go-playground/validator/v10" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/backupsys/backupsys.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/backupsys/backupsys.go similarity index 97% rename from dbm-services/mongo/db-tools/dbactuator/pkg/backupsys/backupsys.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/backupsys/backupsys.go index 1ef15f9f0a..ba961a244a 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/backupsys/backupsys.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/backupsys/backupsys.go @@ -9,9 +9,9 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/mylog" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/mylog" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" ) // UploadTask 操作备份系统 diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/common/exporter_conf.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/exporter_conf.go similarity index 90% rename from dbm-services/mongo/db-tools/dbactuator/pkg/common/exporter_conf.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/common/exporter_conf.go index d275658bdd..c4492770ad 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/common/exporter_conf.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/exporter_conf.go @@ -1,8 +1,8 @@ package common import ( - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" "encoding/json" "fmt" "io/ioutil" diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/common/filelock.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/filelock.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/common/filelock.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/common/filelock.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/common/initiate_replicaset_conf.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/initiate_replicaset_conf.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/common/initiate_replicaset_conf.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/common/initiate_replicaset_conf.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/common/media_pkg.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/media_pkg.go similarity index 96% rename from dbm-services/mongo/db-tools/dbactuator/pkg/common/media_pkg.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/common/media_pkg.go index 3ae6d84ce1..511c7c372d 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/common/media_pkg.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/media_pkg.go @@ -7,9 +7,9 @@ import ( "regexp" "time" - "dbm-services/mongo/db-tools/dbactuator/mylog" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/mylog" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" ) // MediaPkg 通用介质包处理 diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/common/mongo_common.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongo_common.go similarity index 99% rename from dbm-services/mongo/db-tools/dbactuator/pkg/common/mongo_common.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongo_common.go index 3bb679fe01..09588bb587 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/common/mongo_common.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongo_common.go @@ -11,8 +11,8 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" ) // UnTarAndCreateSoftLinkAndChown 解压目录,创建软链接并修改属主 diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/common/mongo_init_shell.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongo_init_shell.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/common/mongo_init_shell.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongo_init_shell.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/common/mongo_user_conf.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongo_user_conf.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/common/mongo_user_conf.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongo_user_conf.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/common/mongod_conf.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongod_conf.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/common/mongod_conf.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongod_conf.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/common/mongos_conf.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongos_conf.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/common/mongos_conf.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/common/mongos_conf.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/common/repliccaset_member_conf.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/common/repliccaset_member_conf.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/common/repliccaset_member_conf.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/common/repliccaset_member_conf.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/consts/consts.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/consts/consts.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/consts/consts.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/consts/consts.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/consts/data_dir.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/consts/data_dir.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/consts/data_dir.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/consts/data_dir.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/consts/mongo.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/consts/mongo.go similarity index 95% rename from dbm-services/mongo/db-tools/dbactuator/pkg/consts/mongo.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/consts/mongo.go index 34a11d1a89..d522697cca 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/consts/mongo.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/consts/mongo.go @@ -1,8 +1,8 @@ package consts import ( - "dbm-services/mongo/db-tools/dbmon/pkg/consts" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/dbmon/pkg/consts" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" "fmt" "path" "time" diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/consts/test.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/consts/test.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/consts/test.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/consts/test.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/consts/user.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/consts/user.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/consts/user.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/consts/user.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/customtime/customtime.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/customtime/customtime.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/customtime/customtime.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/customtime/customtime.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/jobmanager/jobmanager.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/jobmanager/jobmanager.go similarity index 94% rename from dbm-services/mongo/db-tools/dbactuator/pkg/jobmanager/jobmanager.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/jobmanager/jobmanager.go index 7beeaf78dc..f316e6ad2b 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/jobmanager/jobmanager.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/jobmanager/jobmanager.go @@ -2,8 +2,8 @@ package jobmanager import ( - "dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atommongodb" - "dbm-services/mongo/db-tools/dbactuator/pkg/atomjobs/atomsys" + "dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb" + "dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atomsys" "fmt" "log" "runtime/debug" @@ -12,8 +12,8 @@ import ( "sync" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" ) // AtomJobCreatorFunc 原子任务创建接口 diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime/jobrunner.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime/jobrunner.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime/jobrunner.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime/jobrunner.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime/jobruntime.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime/jobruntime.go similarity index 96% rename from dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime/jobruntime.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime/jobruntime.go index 2c24493f5e..fb4526d086 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/jobruntime/jobruntime.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/jobruntime/jobruntime.go @@ -13,9 +13,9 @@ import ( "time" "dbm-services/common/go-pubpkg/logger" - "dbm-services/mongo/db-tools/dbactuator/mylog" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" - "dbm-services/mongo/db-tools/dbactuator/pkg/util" + "dbm-services/mongodb/db-tools/dbactuator/mylog" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/util" ) const ( diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/util/bkrepo.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/bkrepo.go similarity index 98% rename from dbm-services/mongo/db-tools/dbactuator/pkg/util/bkrepo.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/util/bkrepo.go index f2695eeac9..3d3ee4592a 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/util/bkrepo.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/bkrepo.go @@ -9,7 +9,7 @@ import ( "net/http" "os" - "dbm-services/mongo/db-tools/dbactuator/mylog" + "dbm-services/mongodb/db-tools/dbactuator/mylog" ) // FileServerInfo 文件服务器 diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/util/compress.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/compress.go similarity index 98% rename from dbm-services/mongo/db-tools/dbactuator/pkg/util/compress.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/util/compress.go index 4d54e3b734..1316a0084f 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/util/compress.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/compress.go @@ -9,8 +9,8 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/mylog" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/mylog" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" "github.com/dustin/go-humanize" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/util/file.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/file.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/util/file.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/util/file.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/util/net.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/net.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/util/net.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/util/net.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/util/osCmd.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/osCmd.go similarity index 98% rename from dbm-services/mongo/db-tools/dbactuator/pkg/util/osCmd.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/util/osCmd.go index 62750bf58b..18224cfe5d 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/util/osCmd.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/osCmd.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbactuator/mylog" + "dbm-services/mongodb/db-tools/dbactuator/mylog" ) // DealLocalCmdPid 处理本地命令得到pid diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/util/reflect.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/reflect.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/util/reflect.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/util/reflect.go diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/util/util.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/util.go similarity index 99% rename from dbm-services/mongo/db-tools/dbactuator/pkg/util/util.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/util/util.go index 31fc99c7c1..8c20d69329 100644 --- a/dbm-services/mongo/db-tools/dbactuator/pkg/util/util.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/util.go @@ -11,7 +11,7 @@ import ( "syscall" "time" - "dbm-services/mongo/db-tools/dbactuator/pkg/consts" + "dbm-services/mongodb/db-tools/dbactuator/pkg/consts" "golang.org/x/sys/unix" ) diff --git a/dbm-services/mongo/db-tools/dbactuator/pkg/util/version.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/util/version.go similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/pkg/util/version.go rename to dbm-services/mongodb/db-tools/dbactuator/pkg/util/version.go diff --git a/dbm-services/mongo/db-tools/dbactuator/scripts/upload.sh b/dbm-services/mongodb/db-tools/dbactuator/scripts/upload.sh similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/scripts/upload.sh rename to dbm-services/mongodb/db-tools/dbactuator/scripts/upload.sh diff --git a/dbm-services/mongo/db-tools/dbactuator/tests/test_mongo.sh b/dbm-services/mongodb/db-tools/dbactuator/tests/test_mongo.sh similarity index 100% rename from dbm-services/mongo/db-tools/dbactuator/tests/test_mongo.sh rename to dbm-services/mongodb/db-tools/dbactuator/tests/test_mongo.sh diff --git a/dbm-services/mongo/db-tools/dbmon/.ci/codecc.yml b/dbm-services/mongodb/db-tools/dbmon/.ci/codecc.yml similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/.ci/codecc.yml rename to dbm-services/mongodb/db-tools/dbmon/.ci/codecc.yml diff --git a/dbm-services/mongo/db-tools/dbmon/.ci/open_source_check.yml b/dbm-services/mongodb/db-tools/dbmon/.ci/open_source_check.yml similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/.ci/open_source_check.yml rename to dbm-services/mongodb/db-tools/dbmon/.ci/open_source_check.yml diff --git a/dbm-services/mongo/db-tools/dbmon/.ci/templates/open_source_gate.yml b/dbm-services/mongodb/db-tools/dbmon/.ci/templates/open_source_gate.yml similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/.ci/templates/open_source_gate.yml rename to dbm-services/mongodb/db-tools/dbmon/.ci/templates/open_source_gate.yml diff --git a/dbm-services/mongo/db-tools/dbmon/.gitignore b/dbm-services/mongodb/db-tools/dbmon/.gitignore similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/.gitignore rename to dbm-services/mongodb/db-tools/dbmon/.gitignore diff --git a/dbm-services/mongo/db-tools/dbmon/LICENSE b/dbm-services/mongodb/db-tools/dbmon/LICENSE similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/LICENSE rename to dbm-services/mongodb/db-tools/dbmon/LICENSE diff --git a/dbm-services/mongo/db-tools/dbmon/Makefile b/dbm-services/mongodb/db-tools/dbmon/Makefile similarity index 93% rename from dbm-services/mongo/db-tools/dbmon/Makefile rename to dbm-services/mongodb/db-tools/dbmon/Makefile index a56b95c3aa..b82e7d741c 100644 --- a/dbm-services/mongo/db-tools/dbmon/Makefile +++ b/dbm-services/mongodb/db-tools/dbmon/Makefile @@ -3,7 +3,7 @@ SHELL := /bin/bash VERSION = 0.0.1 GITHASH = `git rev-parse --short HEAD` GOVERSION = $(shell go version) -MODULE="dbm-services/mongo/db-tools/dbmon/cmd" +MODULE="dbm-services/mongodb/db-tools/dbmon/cmd" BUILD_FLAG = -ldflags "-X '${MODULE}.version=${VERSION}' -X '${MODULE}.githash=${GITHASH}' -X '${MODULE}.buildstamp=`date +%FT%T%z`' -X '${MODULE}.goversion=${GOVERSION}' " TRIMPATH = -gcflags="all=-trimpath=${PWD}" -asmflags="all=-trimpath=${PWD}" local: diff --git a/dbm-services/mongo/db-tools/dbmon/README.md b/dbm-services/mongodb/db-tools/dbmon/README.md similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/README.md rename to dbm-services/mongodb/db-tools/dbmon/README.md diff --git a/dbm-services/mongo/db-tools/dbmon/cmd/dbmonheartbeat/dbmonhearbeat.go b/dbm-services/mongodb/db-tools/dbmon/cmd/dbmonheartbeat/dbmonhearbeat.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/cmd/dbmonheartbeat/dbmonhearbeat.go rename to dbm-services/mongodb/db-tools/dbmon/cmd/dbmonheartbeat/dbmonhearbeat.go diff --git a/dbm-services/mongo/db-tools/dbmon/cmd/dbmonheartbeat/job.go b/dbm-services/mongodb/db-tools/dbmon/cmd/dbmonheartbeat/job.go similarity index 92% rename from dbm-services/mongo/db-tools/dbmon/cmd/dbmonheartbeat/job.go rename to dbm-services/mongodb/db-tools/dbmon/cmd/dbmonheartbeat/job.go index 020f2721d1..4add7a6dd8 100644 --- a/dbm-services/mongo/db-tools/dbmon/cmd/dbmonheartbeat/job.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/dbmonheartbeat/job.go @@ -6,9 +6,9 @@ import ( "strconv" "sync" - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/dbmon/mylog" - "dbm-services/mongo/db-tools/dbmon/pkg/sendwarning" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning" ) const MongoDbmonHeartBeatMetricName = "mongo_dbmon_heart_beat" diff --git a/dbm-services/mongo/db-tools/dbmon/cmd/debug.go b/dbm-services/mongodb/db-tools/dbmon/cmd/debug.go similarity index 94% rename from dbm-services/mongo/db-tools/dbmon/cmd/debug.go rename to dbm-services/mongodb/db-tools/dbmon/cmd/debug.go index 4f30dd6ead..aea0f7361c 100644 --- a/dbm-services/mongo/db-tools/dbmon/cmd/debug.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/debug.go @@ -1,9 +1,9 @@ package cmd import ( - "dbm-services/mongo/db-tools/dbmon/cmd/mongojob" - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/dbmon/cmd/mongojob" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/dbmon/mylog" "encoding/json" "fmt" "os" diff --git a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/backup_job.go b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/backup_job.go similarity index 94% rename from dbm-services/mongo/db-tools/dbmon/cmd/mongojob/backup_job.go rename to dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/backup_job.go index 1ff5455456..145ee4bc63 100644 --- a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/backup_job.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/backup_job.go @@ -1,11 +1,11 @@ package mongojob import ( - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/dbmon/mylog" - "dbm-services/mongo/db-tools/dbmon/pkg/consts" - "dbm-services/mongo/db-tools/dbmon/util" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/report" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/dbmon/pkg/consts" + "dbm-services/mongodb/db-tools/dbmon/util" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/report" "encoding/json" "fmt" "os" diff --git a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/backup_task.go b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/backup_task.go similarity index 93% rename from dbm-services/mongo/db-tools/dbmon/cmd/mongojob/backup_task.go rename to dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/backup_task.go index 01b034d60f..3f20fc5ab9 100644 --- a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/backup_task.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/backup_task.go @@ -1,9 +1,9 @@ package mongojob import ( - "dbm-services/mongo/db-tools/dbmon/mylog" - "dbm-services/mongo/db-tools/dbmon/pkg/consts" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd" + "dbm-services/mongodb/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/dbmon/pkg/consts" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd" "fmt" "strconv" "time" diff --git a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/check_health_job.go b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/check_health_job.go similarity index 94% rename from dbm-services/mongo/db-tools/dbmon/cmd/mongojob/check_health_job.go rename to dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/check_health_job.go index ac5abda421..88192fe53d 100644 --- a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/check_health_job.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/check_health_job.go @@ -1,16 +1,16 @@ package mongojob import ( - "dbm-services/mongo/db-tools/dbmon/pkg/linuxproc" + "dbm-services/mongodb/db-tools/dbmon/pkg/linuxproc" "fmt" "slices" "strings" "time" - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/dbmon/embedfiles" - "dbm-services/mongo/db-tools/dbmon/mylog" - "dbm-services/mongo/db-tools/dbmon/pkg/consts" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/dbmon/embedfiles" + "dbm-services/mongodb/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/dbmon/pkg/consts" "github.com/pkg/errors" ) diff --git a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/cmd.go b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/cmd.go similarity index 97% rename from dbm-services/mongo/db-tools/dbmon/cmd/mongojob/cmd.go rename to dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/cmd.go index 1ceb279f5c..3d2a25e735 100644 --- a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/cmd.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/cmd.go @@ -8,7 +8,7 @@ import ( "strings" "time" - log "dbm-services/mongo/db-tools/dbmon/mylog" + log "dbm-services/mongodb/db-tools/dbmon/mylog" ) // ExecResult DoCommandWithTimeout 的返回结果 diff --git a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/mongojob.go b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/mongojob.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/cmd/mongojob/mongojob.go rename to dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/mongojob.go diff --git a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/msg.go b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/msg.go similarity index 94% rename from dbm-services/mongo/db-tools/dbmon/cmd/mongojob/msg.go rename to dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/msg.go index ef6a2698c1..2062b4917d 100644 --- a/dbm-services/mongo/db-tools/dbmon/cmd/mongojob/msg.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/msg.go @@ -4,9 +4,9 @@ import ( "fmt" "strconv" - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/dbmon/mylog" - "dbm-services/mongo/db-tools/dbmon/pkg/sendwarning" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning" ) // GetBkMonitorEventSender Retrun a BkMonitorEventSender instance diff --git a/dbm-services/mongo/db-tools/dbmon/cmd/root.go b/dbm-services/mongodb/db-tools/dbmon/cmd/root.go similarity index 93% rename from dbm-services/mongo/db-tools/dbmon/cmd/root.go rename to dbm-services/mongodb/db-tools/dbmon/cmd/root.go index c35b879525..3fa1525f0b 100644 --- a/dbm-services/mongo/db-tools/dbmon/cmd/root.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/root.go @@ -2,8 +2,8 @@ package cmd import ( - "dbm-services/mongo/db-tools/dbmon/cmd/dbmonheartbeat" - "dbm-services/mongo/db-tools/dbmon/cmd/mongojob" + "dbm-services/mongodb/db-tools/dbmon/cmd/dbmonheartbeat" + "dbm-services/mongodb/db-tools/dbmon/cmd/mongojob" "fmt" "log" _ "net/http/pprof" // pprof TODO @@ -13,10 +13,10 @@ import ( "github.com/pkg/errors" "go.uber.org/zap/zapcore" - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/dbmon/mylog" - "dbm-services/mongo/db-tools/dbmon/pkg/consts" - "dbm-services/mongo/db-tools/dbmon/pkg/httpapi" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/dbmon/pkg/consts" + "dbm-services/mongodb/db-tools/dbmon/pkg/httpapi" "github.com/robfig/cron/v3" "github.com/spf13/cobra" diff --git a/dbm-services/mongo/db-tools/dbmon/config/config.go b/dbm-services/mongodb/db-tools/dbmon/config/config.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/config/config.go rename to dbm-services/mongodb/db-tools/dbmon/config/config.go diff --git a/dbm-services/mongo/db-tools/dbmon/config/instconfig.go b/dbm-services/mongodb/db-tools/dbmon/config/instconfig.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/config/instconfig.go rename to dbm-services/mongodb/db-tools/dbmon/config/instconfig.go diff --git a/dbm-services/mongo/db-tools/dbmon/dbmon-config.yaml b/dbm-services/mongodb/db-tools/dbmon/dbmon-config.yaml similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/dbmon-config.yaml rename to dbm-services/mongodb/db-tools/dbmon/dbmon-config.yaml diff --git a/dbm-services/mongo/db-tools/dbmon/embedfiles/embedfiles.go b/dbm-services/mongodb/db-tools/dbmon/embedfiles/embedfiles.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/embedfiles/embedfiles.go rename to dbm-services/mongodb/db-tools/dbmon/embedfiles/embedfiles.go diff --git a/dbm-services/mongo/db-tools/dbmon/embedfiles/js/login-js b/dbm-services/mongodb/db-tools/dbmon/embedfiles/js/login-js similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/embedfiles/js/login-js rename to dbm-services/mongodb/db-tools/dbmon/embedfiles/js/login-js diff --git a/dbm-services/mongo/db-tools/dbmon/go.mod b/dbm-services/mongodb/db-tools/dbmon/go.mod similarity index 98% rename from dbm-services/mongo/db-tools/dbmon/go.mod rename to dbm-services/mongodb/db-tools/dbmon/go.mod index b81a5fc408..a7398efea8 100644 --- a/dbm-services/mongo/db-tools/dbmon/go.mod +++ b/dbm-services/mongodb/db-tools/dbmon/go.mod @@ -1,4 +1,4 @@ -module dbm-services/mongo/db-tools/dbmon +module dbm-services/mongodb/db-tools/dbmon go 1.18 diff --git a/dbm-services/mongo/db-tools/dbmon/go.sum b/dbm-services/mongodb/db-tools/dbmon/go.sum similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/go.sum rename to dbm-services/mongodb/db-tools/dbmon/go.sum diff --git a/dbm-services/mongo/db-tools/dbmon/main.go b/dbm-services/mongodb/db-tools/dbmon/main.go similarity index 75% rename from dbm-services/mongo/db-tools/dbmon/main.go rename to dbm-services/mongodb/db-tools/dbmon/main.go index 173ebca04e..e72e81c063 100644 --- a/dbm-services/mongo/db-tools/dbmon/main.go +++ b/dbm-services/mongodb/db-tools/dbmon/main.go @@ -6,7 +6,7 @@ Copyright © 2022 NAME HERE package main import ( - "dbm-services/mongo/db-tools/dbmon/cmd" + "dbm-services/mongodb/db-tools/dbmon/cmd" ) func main() { diff --git a/dbm-services/mongo/db-tools/dbmon/models/mymongo/mymongo.go b/dbm-services/mongodb/db-tools/dbmon/models/mymongo/mymongo.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/models/mymongo/mymongo.go rename to dbm-services/mongodb/db-tools/dbmon/models/mymongo/mymongo.go diff --git a/dbm-services/mongo/db-tools/dbmon/mylog/gin.go b/dbm-services/mongodb/db-tools/dbmon/mylog/gin.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/mylog/gin.go rename to dbm-services/mongodb/db-tools/dbmon/mylog/gin.go diff --git a/dbm-services/mongo/db-tools/dbmon/mylog/mylog.go b/dbm-services/mongodb/db-tools/dbmon/mylog/mylog.go similarity index 98% rename from dbm-services/mongo/db-tools/dbmon/mylog/mylog.go rename to dbm-services/mongodb/db-tools/dbmon/mylog/mylog.go index 8d38e8b1a8..56dbced6ed 100644 --- a/dbm-services/mongo/db-tools/dbmon/mylog/mylog.go +++ b/dbm-services/mongodb/db-tools/dbmon/mylog/mylog.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbmon/pkg/consts" + "dbm-services/mongodb/db-tools/dbmon/pkg/consts" "github.com/robfig/cron/v3" "github.com/spf13/viper" diff --git a/dbm-services/mongo/db-tools/dbmon/package.sh b/dbm-services/mongodb/db-tools/dbmon/package.sh similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/package.sh rename to dbm-services/mongodb/db-tools/dbmon/package.sh diff --git a/dbm-services/mongo/db-tools/dbmon/pkg/consts/consts.go b/dbm-services/mongodb/db-tools/dbmon/pkg/consts/consts.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/pkg/consts/consts.go rename to dbm-services/mongodb/db-tools/dbmon/pkg/consts/consts.go diff --git a/dbm-services/mongo/db-tools/dbmon/pkg/consts/data_dir.go b/dbm-services/mongodb/db-tools/dbmon/pkg/consts/data_dir.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/pkg/consts/data_dir.go rename to dbm-services/mongodb/db-tools/dbmon/pkg/consts/data_dir.go diff --git a/dbm-services/mongo/db-tools/dbmon/pkg/consts/event_categories.go b/dbm-services/mongodb/db-tools/dbmon/pkg/consts/event_categories.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/pkg/consts/event_categories.go rename to dbm-services/mongodb/db-tools/dbmon/pkg/consts/event_categories.go diff --git a/dbm-services/mongo/db-tools/dbmon/pkg/consts/mongo.go b/dbm-services/mongodb/db-tools/dbmon/pkg/consts/mongo.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/pkg/consts/mongo.go rename to dbm-services/mongodb/db-tools/dbmon/pkg/consts/mongo.go diff --git a/dbm-services/mongo/db-tools/dbmon/pkg/httpapi/httpapi.go b/dbm-services/mongodb/db-tools/dbmon/pkg/httpapi/httpapi.go similarity index 84% rename from dbm-services/mongo/db-tools/dbmon/pkg/httpapi/httpapi.go rename to dbm-services/mongodb/db-tools/dbmon/pkg/httpapi/httpapi.go index 026ccd8714..55f9c66e40 100644 --- a/dbm-services/mongo/db-tools/dbmon/pkg/httpapi/httpapi.go +++ b/dbm-services/mongodb/db-tools/dbmon/pkg/httpapi/httpapi.go @@ -6,9 +6,9 @@ import ( "io" "net/http" - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/dbmon/mylog" - "dbm-services/mongo/db-tools/dbmon/pkg/consts" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/dbmon/pkg/consts" "github.com/gin-gonic/gin" ) diff --git a/dbm-services/mongo/db-tools/dbmon/pkg/linuxproc/net_tcp.go b/dbm-services/mongodb/db-tools/dbmon/pkg/linuxproc/net_tcp.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/pkg/linuxproc/net_tcp.go rename to dbm-services/mongodb/db-tools/dbmon/pkg/linuxproc/net_tcp.go diff --git a/dbm-services/mongo/db-tools/dbmon/pkg/mongoproc/mongoproc.go b/dbm-services/mongodb/db-tools/dbmon/pkg/mongoproc/mongoproc.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/pkg/mongoproc/mongoproc.go rename to dbm-services/mongodb/db-tools/dbmon/pkg/mongoproc/mongoproc.go diff --git a/dbm-services/mongo/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go b/dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go similarity index 97% rename from dbm-services/mongo/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go rename to dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go index ebf2bbe952..79400e0fbb 100644 --- a/dbm-services/mongo/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go +++ b/dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go @@ -3,15 +3,15 @@ package sendwarning // 用于发送bkMonitorMsg // 消息有两类,Event事件消息和TimeSeries时序消息 import ( - "dbm-services/mongo/db-tools/dbmon/mylog" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd" + "dbm-services/mongodb/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd" "encoding/json" "fmt" "strings" "time" - "dbm-services/mongo/db-tools/dbmon/pkg/consts" - "dbm-services/mongo/db-tools/dbmon/util" + "dbm-services/mongodb/db-tools/dbmon/pkg/consts" + "dbm-services/mongodb/db-tools/dbmon/util" ) // eventBodyItem 告警项 diff --git a/dbm-services/mongo/db-tools/dbmon/pkg/sendwarning/sendwarning.go b/dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning/sendwarning.go similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/pkg/sendwarning/sendwarning.go rename to dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning/sendwarning.go diff --git a/dbm-services/mongo/db-tools/dbmon/servers.yaml b/dbm-services/mongodb/db-tools/dbmon/servers.yaml similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/servers.yaml rename to dbm-services/mongodb/db-tools/dbmon/servers.yaml diff --git a/dbm-services/mongo/db-tools/dbmon/start.sh b/dbm-services/mongodb/db-tools/dbmon/start.sh similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/start.sh rename to dbm-services/mongodb/db-tools/dbmon/start.sh diff --git a/dbm-services/mongo/db-tools/dbmon/stop.sh b/dbm-services/mongodb/db-tools/dbmon/stop.sh similarity index 100% rename from dbm-services/mongo/db-tools/dbmon/stop.sh rename to dbm-services/mongodb/db-tools/dbmon/stop.sh diff --git a/dbm-services/mongo/db-tools/dbmon/util/osCmd.go b/dbm-services/mongodb/db-tools/dbmon/util/osCmd.go similarity index 98% rename from dbm-services/mongo/db-tools/dbmon/util/osCmd.go rename to dbm-services/mongodb/db-tools/dbmon/util/osCmd.go index 6d0ec7b075..32fe1fe89f 100644 --- a/dbm-services/mongo/db-tools/dbmon/util/osCmd.go +++ b/dbm-services/mongodb/db-tools/dbmon/util/osCmd.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "dbm-services/mongo/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/dbmon/mylog" ) // DealLocalCmdPid 处理本地命令得到pid diff --git a/dbm-services/mongo/db-tools/dbmon/util/util.go b/dbm-services/mongodb/db-tools/dbmon/util/util.go similarity index 98% rename from dbm-services/mongo/db-tools/dbmon/util/util.go rename to dbm-services/mongodb/db-tools/dbmon/util/util.go index f590a1e180..5656a16d71 100644 --- a/dbm-services/mongo/db-tools/dbmon/util/util.go +++ b/dbm-services/mongodb/db-tools/dbmon/util/util.go @@ -15,8 +15,8 @@ import ( "syscall" "time" - "dbm-services/mongo/db-tools/dbmon/mylog" - "dbm-services/mongo/db-tools/dbmon/pkg/consts" + "dbm-services/mongodb/db-tools/dbmon/mylog" + "dbm-services/mongodb/db-tools/dbmon/pkg/consts" "golang.org/x/sys/unix" ) diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/.gitignore b/dbm-services/mongodb/db-tools/mongo-toolkit-go/.gitignore similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/.gitignore rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/.gitignore diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/Makefile b/dbm-services/mongodb/db-tools/mongo-toolkit-go/Makefile similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/Makefile rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/Makefile diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/ReadMe b/dbm-services/mongodb/db-tools/mongo-toolkit-go/ReadMe similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/ReadMe rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/ReadMe diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/VERSION b/dbm-services/mongodb/db-tools/mongo-toolkit-go/VERSION similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/VERSION rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/VERSION diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/main.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/main.go similarity index 83% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/main.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/main.go index d429afc59c..156b92d8ec 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/main.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/main.go @@ -2,7 +2,7 @@ package main import ( - "dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools" ) var ( diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/dump.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/dump.go similarity index 94% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/dump.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/dump.go index 367fd68b28..d3fcbfad47 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/dump.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/dump.go @@ -2,11 +2,11 @@ package tools import ( "context" - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/report" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/report" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr" "path/filepath" "strings" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_backup.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_backup.go similarity index 95% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_backup.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_backup.go index 4f8230a480..2a08a2879e 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_backup.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_backup.go @@ -2,9 +2,9 @@ package tools import ( "context" - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_recover.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_recover.go similarity index 97% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_recover.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_recover.go index c2862996c7..d8f5f601f6 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_recover.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/pitr_recover.go @@ -1,8 +1,8 @@ package tools import ( - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr" "os" "path/filepath" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/restore.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/restore.go similarity index 94% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/restore.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/restore.go index 47e14b1f82..9cd7e67719 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/restore.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/restore.go @@ -2,9 +2,9 @@ package tools import ( "context" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr" "path/filepath" "strings" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/root.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/root.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/root.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/root.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/version.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/version.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/version.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/cmd/mongo-toolkit-go/tools/version.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/go.mod b/dbm-services/mongodb/db-tools/mongo-toolkit-go/go.mod similarity index 95% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/go.mod rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/go.mod index 298f00c6ab..03eda828cd 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/go.mod +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/go.mod @@ -1,4 +1,4 @@ -module dbm-services/mongo/db-tools/mongo-toolkit-go +module dbm-services/mongodb/db-tools/mongo-toolkit-go go 1.19 diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/go.sum b/dbm-services/mongodb/db-tools/mongo-toolkit-go/go.sum similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/go.sum rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/go.sum diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client.go similarity index 99% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client.go index 9d73520c6b..2124503b74 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client.go @@ -6,7 +6,7 @@ import ( "bytes" "context" "crypto/md5" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/util" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/util" "encoding/json" "fmt" "os" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client_test.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client_test.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client_test.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys/backup_client_test.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys/query.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys/query.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys/query.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys/query.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys/recover.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys/recover.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys/recover.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys/recover.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/disk/disk.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/disk/disk.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/disk/disk.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/disk/disk.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/disk/stat_darwin.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/disk/stat_darwin.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/disk/stat_darwin.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/disk/stat_darwin.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/disk/stat_linux.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/disk/stat_linux.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/disk/stat_linux.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/disk/stat_linux.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/fileperm/file-perm.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/fileperm/file-perm.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/fileperm/file-perm.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/fileperm/file-perm.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/fileperm/is-writable.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/fileperm/is-writable.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/fileperm/is-writable.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/fileperm/is-writable.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd/bg.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd/bg.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd/bg.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd/bg.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd/mycmd.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd/mycmd.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd/mycmd.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd/mycmd.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd/mycmd_test.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd/mycmd_test.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd/mycmd_test.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd/mycmd_test.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd/run.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd/run.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd/run.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd/run.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo/index.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo/index.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo/index.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo/index.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo/mymongo.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo/mymongo.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo/mymongo.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo/mymongo.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo/util.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo/util.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo/util.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo/util.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo/version.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo/version.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo/version.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo/version.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/report/backup_record.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/report/backup_record.go similarity index 98% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/report/backup_record.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/report/backup_record.go index 22ac808409..285eb63183 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/report/backup_record.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/report/backup_record.go @@ -1,7 +1,7 @@ package report import ( - "dbm-services/mongo/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/dbmon/config" ) // BackupRecord 包括 diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/report/report.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/report/report.go similarity index 97% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/report/report.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/report/report.go index 71011a21d4..a26955b38d 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/report/report.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/report/report.go @@ -2,7 +2,7 @@ package report import ( - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/fileperm" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/fileperm" "encoding/json" "fmt" "os" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/util/cmd.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/util/cmd.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/util/cmd.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/util/cmd.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/util/fs.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/util/fs.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/util/fs.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/util/fs.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/db_collection.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/db_collection.go similarity index 97% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/db_collection.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/db_collection.go index 52474ea0cc..b9da8bb1b3 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/db_collection.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/db_collection.go @@ -2,7 +2,7 @@ package logical import ( "context" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" "time" "github.com/pkg/errors" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/dump.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/dump.go similarity index 96% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/dump.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/dump.go index 114e38df48..5e2bfb6c4f 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/dump.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/dump.go @@ -1,10 +1,10 @@ package logical import ( - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/util" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/util" "fmt" "os" "path" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/logical.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/logical.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/logical.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/logical.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/ns_filter.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/ns_filter.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/ns_filter.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/ns_filter.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/ns_filter_test.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/ns_filter_test.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/ns_filter_test.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/ns_filter_test.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/restore.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/restore.go similarity index 98% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/restore.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/restore.go index 223451c5c1..e35d131c7e 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/restore.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/restore.go @@ -2,9 +2,9 @@ package logical import ( "bufio" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr" "fmt" "os" "path" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/tmpdir.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/tmpdir.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/logical/tmpdir.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/logical/tmpdir.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/backup.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/backup.go similarity index 98% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/backup.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/backup.go index fd1d149955..c96a2308c7 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/backup.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/backup.go @@ -3,9 +3,9 @@ package pitr import ( "bufio" "bytes" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/util" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/util" "fmt" "os" "os/exec" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/backup_record.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/backup_record.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/backup_record.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/backup_record.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/backup_test.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/backup_test.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/backup_test.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/backup_test.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/filename.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/filename.go similarity index 99% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/filename.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/filename.go index a19c4a7dfa..233b9b2fb6 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/filename.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/filename.go @@ -1,7 +1,7 @@ package pitr import ( - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" // log "github.com/sirupsen/logrus" "fmt" "path" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/filename_test.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/filename_test.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/filename_test.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/filename_test.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/job.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/job.go similarity index 96% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/job.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/job.go index dd44e8baa0..911944104b 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/job.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/job.go @@ -1,10 +1,10 @@ package pitr import ( - "dbm-services/mongo/db-tools/dbmon/config" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/report" + "dbm-services/mongodb/db-tools/dbmon/config" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/report" "time" log "github.com/sirupsen/logrus" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/meta.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/meta.go similarity index 96% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/meta.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/meta.go index 8d2da0bbaa..b233d06d57 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/meta.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/meta.go @@ -1,7 +1,7 @@ package pitr import ( - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" "encoding/json" "fmt" "os" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/metav2.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/metav2.go similarity index 98% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/metav2.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/metav2.go index bcb55314f5..93e9c76e0a 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/metav2.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/metav2.go @@ -2,9 +2,9 @@ package pitr import ( "bufio" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/backupsys" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/disk" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/backupsys" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/disk" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" "encoding/json" "fmt" "os" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/metav2_test.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/metav2_test.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/metav2_test.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/metav2_test.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/pitr.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/pitr.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/pitr.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/pitr.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/recover.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/recover.go similarity index 99% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/recover.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/recover.go index 75b6846db2..f2214b6106 100644 --- a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/recover.go +++ b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/recover.go @@ -3,8 +3,8 @@ package pitr import ( "bufio" "bytes" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mycmd" - "dbm-services/mongo/db-tools/mongo-toolkit-go/pkg/mymongo" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mycmd" + "dbm-services/mongodb/db-tools/mongo-toolkit-go/pkg/mymongo" "fmt" "io" "os" diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/recover_helper.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/recover_helper.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/recover_helper.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/recover_helper.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/report.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/report.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/report.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/report.go diff --git a/dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/util.go b/dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/util.go similarity index 100% rename from dbm-services/mongo/db-tools/mongo-toolkit-go/toolkit/pitr/util.go rename to dbm-services/mongodb/db-tools/mongo-toolkit-go/toolkit/pitr/util.go diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go deleted file mode 100644 index 8583a2e363..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_shard_to_cluster.go +++ /dev/null @@ -1,248 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// AddConfParams 参数 -type AddConfParams struct { - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - AdminUsername string `json:"adminUsername" validate:"required"` - AdminPassword string `json:"adminPassword" validate:"required"` - Shards map[string]string `json:"shard" validate:"required"` // key->clusterId,value->ip:port,ip:port 不包含隐藏节点 -} - -// AddShardToCluster 添加分片到集群 -type AddShardToCluster struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - Mongo string - OsUser string - ConfFilePath string - ConfFileContent string - ConfParams *AddConfParams -} - -// NewAddShardToCluster 实例化结构体 -func NewAddShardToCluster() jobruntime.JobRunner { - return &AddShardToCluster{} -} - -// Name 获取原子任务的名字 -func (a *AddShardToCluster) Name() string { - return "add_shard_to_cluster" -} - -// Run 运行原子任务 -func (a *AddShardToCluster) Run() error { - // 获取配置内容 - if err := a.makeConfContent(); err != nil { - return err - } - - // 生成js脚本 - if err := a.createAddShardToClusterScript(); err != nil { - return err - } - - // 执行js脚本 - if err := a.execScript(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (a *AddShardToCluster) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (a *AddShardToCluster) Rollback() error { - return nil -} - -// Init 初始化 -func (a *AddShardToCluster) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - a.runtime = runtime - a.runtime.Logger.Info("start to init") - a.BinDir = consts.UsrLocal - a.Mongo = filepath.Join(a.BinDir, "mongodb", "bin", "mongo") - a.ConfFilePath = filepath.Join("/", "tmp", "addShardToCluster.js") - a.OsUser = consts.GetProcessUser() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(a.runtime.PayloadDecoded), &a.ConfParams); err != nil { - a.runtime.Logger.Error(fmt.Sprintf( - "get parameters of initiateReplicaset fail by json.Unmarshal, error:%s", err)) - return fmt.Errorf("get parameters of initiateReplicaset fail by json.Unmarshal, error:%s", err) - } - a.runtime.Logger.Info("init successfully") - - // 进行校验 - if err := a.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (a *AddShardToCluster) checkParams() error { - // 校验重启配置参数 - validate := validator.New() - a.runtime.Logger.Info("start to validate parameters of addShardToCluster") - if err := validate.Struct(a.ConfParams); err != nil { - a.runtime.Logger.Error(fmt.Sprintf("validate parameters of addShardToCluster fail, error:%s", err)) - return fmt.Errorf("validate parameters of addShardToCluster fail, error:%s", err) - } - a.runtime.Logger.Info("validate parameters of addShardToCluster successfully") - return nil -} - -// makeConfContent 生成配置内容 -func (a *AddShardToCluster) makeConfContent() error { - a.runtime.Logger.Info("start to make config content of addShardToCluster") - var shards []string - for key, value := range a.ConfParams.Shards { - shards = append(shards, strings.Join([]string{key, "/", value}, "")) - } - - for _, v := range shards { - a.ConfFileContent += strings.Join([]string{"sh.addShard(\"", v, "\")\n"}, "") - } - a.runtime.Logger.Info("make config content of addShardToCluster successfully") - return nil -} - -// createAddShardToClusterScript 生成js脚本 -func (a *AddShardToCluster) createAddShardToClusterScript() error { - a.runtime.Logger.Info("start to create addShardToCluster script") - confFile, err := os.OpenFile(a.ConfFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, DefaultPerm) - defer confFile.Close() - if err != nil { - a.runtime.Logger.Error( - fmt.Sprintf("create script file of addShardToCluster fail, error:%s", err)) - return fmt.Errorf("create script file of addShardToCluster fail, error:%s", err) - } - - if _, err = confFile.WriteString(a.ConfFileContent); err != nil { - a.runtime.Logger.Error( - fmt.Sprintf("create script file of addShardToCluster write content fail, error:%s", - err)) - return fmt.Errorf("create script file of addShardToCluster write content fail, error:%s", - err) - } - a.runtime.Logger.Info("create addShardToCluster script successfully") - return nil -} - -// checkShard 检查shard是否已经加入到cluster中 -func (a *AddShardToCluster) checkShard() (bool, error) { - a.runtime.Logger.Info("start to check shard") - cmd := fmt.Sprintf( - "su %s -c '%s -u %s -p %s --host %s --port %d --quiet --authenticationDatabase=admin --eval \"db.getMongo().getDB(\\\"config\\\").shards.find()\" admin'", - a.OsUser, a.Mongo, a.ConfParams.AdminUsername, a.ConfParams.AdminPassword, a.ConfParams.IP, a.ConfParams.Port) - result, err := util.RunBashCmd( - cmd, - "", nil, - 10*time.Second) - if err != nil { - a.runtime.Logger.Error(fmt.Sprintf("get shard info fail, error:%s", err)) - return false, fmt.Errorf("get shard info fail, error:%s", err) - } - result = strings.Replace(result, "\n", "", -1) - if result == "" { - a.runtime.Logger.Info("check shard successfully") - return false, nil - } - - for k, _ := range a.ConfParams.Shards { - - if strings.Contains(result, k) { - continue - } - - return false, fmt.Errorf("add shard %s fail", k) - } - a.runtime.Logger.Info("check shard successfully") - return true, nil -} - -// execScript 执行脚本 -func (a *AddShardToCluster) execScript() error { - // 检查 - flag, err := a.checkShard() - if err != nil { - return err - } - if flag == true { - a.runtime.Logger.Info(fmt.Sprintf("shards have been added")) - // 删除脚本 - if err = a.removeScript(); err != nil { - return err - } - - return nil - } - - // 执行脚本 - a.runtime.Logger.Info("start to execute addShardToCluster script") - cmd := fmt.Sprintf("su %s -c '%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet %s'", - a.OsUser, a.Mongo, a.ConfParams.AdminUsername, a.ConfParams.AdminPassword, a.ConfParams.IP, a.ConfParams.Port, - a.ConfFilePath) - if _, err = util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - a.runtime.Logger.Error(fmt.Sprintf("execute addShardToCluster script fail, error:%s", err)) - return fmt.Errorf("execute addShardToCluster script fail, error:%s", err) - } - a.runtime.Logger.Info("execute addShardToCluster script successfully") - - // time.Sleep(15 * time.Second) - - // 检查 - flag, err = a.checkShard() - if err != nil { - return err - } - if flag == false { - a.runtime.Logger.Error(fmt.Sprintf("add shard fail, error:%s", err)) - return fmt.Errorf("add shard fail, error:%s", err) - } - - // 删除脚本 - if err = a.removeScript(); err != nil { - return err - } - - return nil -} - -// removeScript 删除脚本 -func (a *AddShardToCluster) removeScript() error { - // 删除脚本 - a.runtime.Logger.Info("start to remove addShardToCluster script") - if err := common.RemoveFile(a.ConfFilePath); err != nil { - a.runtime.Logger.Error(fmt.Sprintf("remove addShardToCluster script fail, error:%s", err)) - return fmt.Errorf("remove addShardToCluster script fail, error:%s", err) - } - a.runtime.Logger.Info("remove addShardToCluster script successfully") - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go deleted file mode 100644 index adb2cb4f5c..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go +++ /dev/null @@ -1,263 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "path/filepath" - "strconv" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// AddUserConfParams 参数 -type AddUserConfParams struct { - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - InstanceType string `json:"instanceType" validate:"required"` - Username string `json:"username" validate:"required"` - Password string `json:"password" validate:"required"` - AdminUsername string `json:"adminUsername"` - AdminPassword string `json:"adminPassword"` - AuthDb string `json:"authDb"` // 为方便管理用户,验证库默认为admin库 - Dbs []string `json:"dbs"` // 业务库 - Privileges []string `json:"privileges"` // 权限 - -} - -// AddUser 添加分片到集群 -type AddUser struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - Mongo string - PrimaryIP string - PrimaryPort int - OsUser string - ScriptContent string - ConfParams *AddUserConfParams -} - -// NewAddUser 实例化结构体 -func NewAddUser() jobruntime.JobRunner { - return &AddUser{} -} - -// Name 获取原子任务的名字 -func (u *AddUser) Name() string { - return "add_user" -} - -// Run 运行原子任务 -func (u *AddUser) Run() error { - // 生成脚本内容 - if err := u.makeScriptContent(); err != nil { - return err - } - - // 执行js脚本 - if err := u.execScript(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (u *AddUser) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (u *AddUser) Rollback() error { - return nil -} - -// Init 初始化 -func (u *AddUser) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - u.runtime = runtime - u.runtime.Logger.Info("start to init") - u.BinDir = consts.UsrLocal - u.Mongo = filepath.Join(u.BinDir, "mongodb", "bin", "mongo") - u.OsUser = consts.GetProcessUser() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(u.runtime.PayloadDecoded), &u.ConfParams); err != nil { - u.runtime.Logger.Error(fmt.Sprintf( - "get parameters of addUser fail by json.Unmarshal, error:%s", err)) - return fmt.Errorf("get parameters of addUser fail by json.Unmarshal, error:%s", err) - } - - // 获取primary信息 - if u.ConfParams.InstanceType == "mongos" { - u.PrimaryIP = u.ConfParams.IP - u.PrimaryPort = u.ConfParams.Port - } else { - var info string - var err error - // 安装时无需密码验证。安装成功后需要密码验证 - if u.ConfParams.AdminUsername != "" && u.ConfParams.AdminPassword != "" { - info, err = common.AuthGetPrimaryInfo(u.OsUser, u.Mongo, u.ConfParams.AdminUsername, - u.ConfParams.AdminPassword, u.ConfParams.IP, u.ConfParams.Port) - if err != nil { - u.runtime.Logger.Error(fmt.Sprintf( - "get primary db info of addUser fail, error:%s", err)) - return fmt.Errorf("get primary db info of addUser fail, error:%s", err) - } - getInfo := strings.Split(info, ":") - u.PrimaryIP = getInfo[0] - u.PrimaryPort, _ = strconv.Atoi(getInfo[1]) - } - } - u.runtime.Logger.Info("init successfully") - - // 进行校验 - if err := u.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (u *AddUser) checkParams() error { - // 校验重启配置参数 - validate := validator.New() - u.runtime.Logger.Info("start to validate parameters of addUser") - if err := validate.Struct(u.ConfParams); err != nil { - u.runtime.Logger.Error(fmt.Sprintf("validate parameters of addUser fail, error:%s", err)) - return fmt.Errorf("validate parameters of addUser fail, error:%s", err) - } - u.runtime.Logger.Info("validate parameters of addUser successfully") - return nil -} - -// makeScriptContent 生成user配置内容 -func (u *AddUser) makeScriptContent() error { - u.runtime.Logger.Info("start to make script content") - user := common.NewMongoUser() - user.User = u.ConfParams.Username - user.Pwd = u.ConfParams.Password - - // 判断验证db - if u.ConfParams.AuthDb == "" { - u.ConfParams.AuthDb = "admin" - } - - // 判断业务db是否存在 - if len(u.ConfParams.Dbs) == 0 { - u.ConfParams.Dbs = []string{"admin"} - } - - for _, db := range u.ConfParams.Dbs { - for _, privilege := range u.ConfParams.Privileges { - role := common.NewMongoRole() - role.Role = privilege - role.Db = db - user.Roles = append(user.Roles, role) - } - } - - content, err := user.GetContent() - if err != nil { - u.runtime.Logger.Error(fmt.Sprintf("make config content of addUser fail, error:%s", err)) - return fmt.Errorf("make config content of addUser fail, error:%s", err) - } - content = strings.Replace(content, "\"", "\\\"", -1) - - // 获取mongo版本 - mongoName := "mongod" - if u.ConfParams.InstanceType == "mongos" { - mongoName = "mongos" - } - version, err := common.CheckMongoVersion(u.BinDir, mongoName) - if err != nil { - u.runtime.Logger.Error(fmt.Sprintf("check mongo version fail, error:%s", err)) - return fmt.Errorf("check mongo version fail, error:%s", err) - } - mainVersion, _ := strconv.Atoi(strings.Split(version, ".")[0]) - if mainVersion >= 3 { - u.ScriptContent = strings.Join([]string{"db", - fmt.Sprintf("createUser(%s)", content)}, ".") - u.runtime.Logger.Info("make script content successfully") - return nil - } - u.ScriptContent = strings.Join([]string{"db", - fmt.Sprintf("addUser(%s)", content)}, ".") - u.runtime.Logger.Info("make script content successfully") - - return nil -} - -// checkUser 检查用户是否存在 -func (u *AddUser) checkUser() (bool, error) { - var flag bool - var err error - // 安装时检查管理用户是否存在无需密码验证。安装后检查业务用户是否存在需密码验证 - if u.ConfParams.AdminUsername != "" && u.ConfParams.AdminPassword != "" { - flag, err = common.AuthCheckUser(u.OsUser, u.Mongo, u.ConfParams.AdminUsername, u.ConfParams.AdminPassword, - u.PrimaryIP, u.PrimaryPort, u.ConfParams.AuthDb, u.ConfParams.Username) - } else { - flag, err = common.AuthCheckUser(u.OsUser, u.Mongo, u.ConfParams.Username, u.ConfParams.Password, - u.ConfParams.IP, u.ConfParams.Port, u.ConfParams.AuthDb, u.ConfParams.Username) - } - return flag, err -} - -// execScript 执行脚本 -func (u *AddUser) execScript() error { - var cmd string - if u.ConfParams.AdminUsername != "" && u.ConfParams.AdminPassword != "" { - // 检查用户是否存在 - flag, err := u.checkUser() - if err != nil { - return err - } - if flag == true { - u.runtime.Logger.Info("user:%s has been existed", u.ConfParams.Username) - return nil - } - cmd = fmt.Sprintf( - "su %s -c '%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet --eval \"%s\" %s'", - u.OsUser, u.Mongo, u.ConfParams.AdminUsername, u.ConfParams.AdminPassword, u.PrimaryIP, u.PrimaryPort, - u.ScriptContent, u.ConfParams.AuthDb) - } else if u.ConfParams.AdminUsername == "" && u.ConfParams.AdminPassword == "" { - // 复制集初始化后,马上创建db管理员用户,需要等3秒 - time.Sleep(time.Second * 3) - cmd = fmt.Sprintf( - "su %s -c '%s --host %s --port %d --quiet --eval \"%s\" %s'", - u.OsUser, u.Mongo, "127.0.0.1", u.ConfParams.Port, u.ScriptContent, u.ConfParams.AuthDb) - if u.ConfParams.AdminUsername != "" && u.ConfParams.AdminPassword != "" { - - } - } - - // 执行脚本 - u.runtime.Logger.Info("start to execute addUser script") - if _, err := util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - u.runtime.Logger.Error("execute addUser script fail, error:%s", err) - return fmt.Errorf("execute addUser script fail, error:%s", err) - } - u.runtime.Logger.Info("execute addUser script successfully") - - // 检查用户是否存在 - flag, err := u.checkUser() - if err != nil { - return err - } - if flag == false { - u.runtime.Logger.Error("add user:%s fail, error:%s", u.ConfParams.Username, err) - return fmt.Errorf("add user:%s fail, error:%s", u.ConfParams.Username, err) - } - - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/atommongodb.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/atommongodb.go deleted file mode 100644 index f022fb23e5..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/atommongodb.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package atommongodb mongodb原子任务 -package atommongodb diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go deleted file mode 100644 index 5ca283a094..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_balancer.go +++ /dev/null @@ -1,159 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - "strconv" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// BalancerConfParams 参数 -type BalancerConfParams struct { - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - Open bool `json:"open"` // true:打开 false:关闭 - AdminUsername string `json:"adminUsername" validate:"required"` - AdminPassword string `json:"adminPassword" validate:"required"` -} - -// Balancer 添加分片到集群 -type Balancer struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - Mongo string - OsUser string - ConfParams *BalancerConfParams -} - -// NewBalancer 实例化结构体 -func NewBalancer() jobruntime.JobRunner { - return &Balancer{} -} - -// Name 获取原子任务的名字 -func (b *Balancer) Name() string { - return "cluster_balancer" -} - -// Run 运行原子任务 -func (b *Balancer) Run() error { - // 执行脚本 - if err := b.execScript(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (b *Balancer) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (b *Balancer) Rollback() error { - return nil -} - -// Init 初始化 -func (b *Balancer) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - b.runtime = runtime - b.runtime.Logger.Info("start to init") - b.BinDir = consts.UsrLocal - b.Mongo = filepath.Join(b.BinDir, "mongodb", "bin", "mongo") - b.OsUser = consts.GetProcessUser() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(b.runtime.PayloadDecoded), &b.ConfParams); err != nil { - b.runtime.Logger.Error( - "get parameters of clusterBalancer fail by json.Unmarshal, error:%s", err) - return fmt.Errorf("get parameters of clusterBalancer fail by json.Unmarshal, error:%s", err) - } - b.runtime.Logger.Info("init successfully") - - // 进行校验 - if err := b.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (b *Balancer) checkParams() error { - // 校验配置参数 - validate := validator.New() - b.runtime.Logger.Info("start to validate parameters of clusterBalancer") - if err := validate.Struct(b.ConfParams); err != nil { - b.runtime.Logger.Error(fmt.Sprintf("validate parameters of clusterBalancer fail, error:%s", err)) - return fmt.Errorf("validate parameters of clusterBalancer fail, error:%s", err) - } - b.runtime.Logger.Info("validate parameters of clusterBalancer successfully") - return nil -} - -// execScript 执行脚本 -func (b *Balancer) execScript() error { - // 检查状态 - b.runtime.Logger.Info("start to get balancer status") - result, err := common.CheckBalancer(b.OsUser, b.Mongo, b.ConfParams.IP, b.ConfParams.Port, - b.ConfParams.AdminUsername, b.ConfParams.AdminPassword) - if err != nil { - b.runtime.Logger.Error("get cluster balancer status fail, error:%s", err) - return fmt.Errorf("get cluster balancer status fail, error:%s", err) - } - flag, _ := strconv.ParseBool(result) - b.runtime.Logger.Info("get balancer status successfully") - if flag == b.ConfParams.Open { - b.runtime.Logger.Info("balancer status has been %t", b.ConfParams.Open) - os.Exit(0) - } - - // 执行脚本 - var cmd string - if b.ConfParams.Open == true { - cmd = fmt.Sprintf( - "su %s -c '%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet --eval \"sh.startBalancer()\"'", - b.OsUser, b.Mongo, b.ConfParams.AdminUsername, b.ConfParams.AdminPassword, b.ConfParams.IP, b.ConfParams.Port) - } else { - cmd = fmt.Sprintf( - "su %s -c '%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet --eval \"sh.stopBalancer()\"'", - b.OsUser, b.Mongo, b.ConfParams.AdminUsername, b.ConfParams.AdminPassword, b.ConfParams.IP, b.ConfParams.Port) - } - b.runtime.Logger.Info("start to execute script") - _, err = util.RunBashCmd( - cmd, - "", nil, - 10*time.Second) - if err != nil { - b.runtime.Logger.Error("set cluster balancer status fail, error:%s", err) - return fmt.Errorf("set cluster balancer status fail, error:%s", err) - } - b.runtime.Logger.Info("execute script successfully") - - // 检查状态 - b.runtime.Logger.Info("start to check balancer status") - result, err = common.CheckBalancer(b.OsUser, b.Mongo, b.ConfParams.IP, b.ConfParams.Port, - b.ConfParams.AdminUsername, b.ConfParams.AdminPassword) - if err != nil { - b.runtime.Logger.Error("get cluster balancer status fail, error:%s", err) - return fmt.Errorf("get cluster balancer status fail, error:%s", err) - } - flag, _ = strconv.ParseBool(result) - b.runtime.Logger.Info("check balancer status successfully") - if flag == b.ConfParams.Open { - b.runtime.Logger.Info("set balancer status:%t successfully", b.ConfParams.Open) - } - - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_install_test.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_install_test.go deleted file mode 100644 index 1f8a809523..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/cluster_install_test.go +++ /dev/null @@ -1,889 +0,0 @@ -package atommongodb - -import ( - "fmt" - "net" - "path" - "strings" - "testing" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomsys" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" -) - -// TestShard1 安装shard1测试 -func TestShard1(t *testing.T) { - // 设置环境变量 - err := consts.SetMongoDataDir("") - if err != nil { - fmt.Println(fmt.Sprintf("Shard1 install SetMongoData fail, error:%s", err)) - t.Errorf("Shard1 install SetMongoData fail, error:%s", err) - return - } - err = consts.SetMongoBackupDir("") - if err != nil { - fmt.Println(fmt.Sprintf("Shard1 install SetMongoBackup fail, error:%s", err)) - t.Errorf("Shard1 install SetMongoBackup fail, error:%s", err) - return - } - - err = consts.SetProcessUser("") - if err != nil { - fmt.Println(fmt.Sprintf("Shard1 install SetProcessUser fail, error:%s", err)) - t.Errorf("Shard1 install SetProcessUser fail, error:%s", err) - return - } - err = consts.SetProcessUserGroup("") - if err != nil { - fmt.Println(fmt.Sprintf("Shard1 install SetProcessUserGroup fail, error:%s", err)) - t.Errorf("Shard1 install SetProcessUserGroup fail, error:%s", err) - return - } - - // 初始化节点 - osSysInitParam := "{\n\"user\":\"mysql\",\n\"password\":\"Qwe123d\"\n}" - osSysInit := &atomsys.OsMongoInit{} - osSysInitRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: osSysInitParam, - } - osSysInitRuntime.SetLogger() - if err := osSysInit.Init(osSysInitRuntime); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install osSysInit init fail, error:%s", err)) - t.Errorf("shard1 replicate install osSysInit init fail, error:%s", err) - return - } - if err := osSysInit.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install osSysInit run fail, error:%s", err)) - t.Errorf("shard1 replicate install osSysInit run fail, error:%s", err) - return - } - - // 获取本机IP地址 - var ip string - addrs, _ := net.InterfaceAddrs() - for _, addr := range addrs { - if !strings.Contains(addr.String(), "127.0.0.1") { - ip = strings.Split(addr.String(), "/")[0] - break - } - } - - // node1 - node1 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27001,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s1\",\n \"auth\": true,\n \"clusterRole\":\"shardsvr\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node1 = strings.Replace(node1, "{{ip}}", ip, -1) - - // node2 - node2 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27002,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s1\",\n \"auth\": true,\n \"clusterRole\":\"shardsvr\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node2 = strings.Replace(node2, "{{ip}}", ip, -1) - - // node3 - node3 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27003,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s1\",\n \"auth\": true,\n \"clusterRole\":\"shardsvr\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node3 = strings.Replace(node3, "{{ip}}", ip, -1) - - node1MongodInstall := NewMongoDBInstall() - node2MongodInstall := NewMongoDBInstall() - node3MongodInstall := NewMongoDBInstall() - - node1Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node1, - } - node1Runtime.SetLogger() - node2Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node2, - } - node2Runtime.SetLogger() - node3Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node3, - } - node3Runtime.SetLogger() - - // 安装节点 - if err := node1MongodInstall.Init(node1Runtime); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install node1 init fail, error:%s", err)) - t.Errorf("shard1 replicate install node1 init fail, error:%s", err) - return - } - if err := node1MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install node1 run fail, error:%s", err)) - t.Errorf("shard1 replicate install node1 run fail, error:%s", err) - return - } - if err := node2MongodInstall.Init(node2Runtime); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install node2 init fail, error:%s", err)) - t.Errorf("shard1 replicate install node2 init fail, error:%s", err) - return - } - if err := node2MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install node2 run fail, error:%s", err)) - t.Errorf("shard1 replicate install node2 run fail, error:%s", err) - return - } - if err := node3MongodInstall.Init(node3Runtime); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install node3 init fail, error:%s", err)) - t.Errorf("shard1 replicate install node3 init fail, error:%s", err) - return - } - if err := node3MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install node3 run fail, error:%s", err)) - t.Errorf("shard1 replicate install node3 run fail, error:%s", err) - return - } - - // 复制集初始化 - initReplicasetParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27001,\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s1\",\n \"configSvr\":false,\n \"ips\":[\n \"{{ip}}:27001\",\n \"{{ip}}:27002\",\n \"{{ip}}:27003\"\n ],\n \"priority\":{\n \"{{ip}}:27001\":1,\n \"{{ip}}:27002\":1,\n \"{{ip}}:27003\":0\n },\n \"hidden\":{\n \"{{ip}}:27001\":false,\n \"{{ip}}:27002\":false,\n \"{{ip}}:27003\":true\n }\n}" - initReplicasetParam = strings.Replace(initReplicasetParam, "{{ip}}", ip, -1) - initReplicasetRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: initReplicasetParam, - } - initReplicasetRuntime.SetLogger() - initReplicaset := NewInitiateReplicaset() - if err := initReplicaset.Init(initReplicasetRuntime); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install initReplicaset init fail, error:%s", err)) - t.Errorf("shard1 replicate install initReplicaset init fail, error:%s", err) - return - } - if err := initReplicaset.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install initReplicaset run fail, error:%s", err)) - t.Errorf("shard1 replicate install initReplicaset run fail, error:%s", err) - return - } - time.Sleep(time.Second * 3) - // 创建管理员用户 - addAdminUserParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27001,\n \"instanceType\":\"mongod\",\n \"username\":\"dba\",\n \"password\":\"dba\",\n \"adminUsername\":\"\",\n \"adminPassword\":\"\",\n \"authDb\":\"admin\",\n \"dbs\":[\n\n ],\n \"privileges\":[\n \"root\"\n ]\n}" - addAdminUserParam = strings.Replace(addAdminUserParam, "{{ip}}", ip, -1) - addAdminUserRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: addAdminUserParam, - } - addAdminUserRuntime.SetLogger() - addAdminUser := NewAddUser() - if err := addAdminUser.Init(addAdminUserRuntime); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install addAdminUser init fail, error:%s", err)) - t.Errorf("shard1 replicate install addAdminUser init fail, error:%s", err) - return - } - if err := addAdminUser.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard1 replicate install addAdminUser run fail, error:%s", err)) - t.Errorf("shard1 replicate install addAdminUser run fail, error:%s", err) - return - } -} - -// TestShard2 安装shard2测试 -func TestShard2(t *testing.T) { - // 设置环境变量 - err := consts.SetMongoDataDir("") - if err != nil { - fmt.Println(fmt.Sprintf("Shard2 install SetMongoData fail, error:%s", err)) - t.Errorf("Shard2 install SetMongoData fail, error:%s", err) - return - } - err = consts.SetMongoBackupDir("") - if err != nil { - fmt.Println(fmt.Sprintf("Shard2 install SetMongoBackup fail, error:%s", err)) - t.Errorf("Shard2 install SetMongoBackup fail, error:%s", err) - return - } - - err = consts.SetProcessUser("") - if err != nil { - fmt.Println(fmt.Sprintf("Shard2 install SetProcessUser fail, error:%s", err)) - t.Errorf("Shard2 install SetProcessUser fail, error:%s", err) - return - } - err = consts.SetProcessUserGroup("") - if err != nil { - fmt.Println(fmt.Sprintf("Shard2 install SetProcessUserGroup fail, error:%s", err)) - t.Errorf("Shard2 install SetProcessUserGroup fail, error:%s", err) - return - } - - // 初始化节点 - osSysInitParam := "{\n\"user\":\"mysql\",\n\"password\":\"Qwe123d\"\n}" - osSysInit := &atomsys.OsMongoInit{} - osSysInitRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: osSysInitParam, - } - osSysInitRuntime.SetLogger() - if err := osSysInit.Init(osSysInitRuntime); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install osSysInit init fail, error:%s", err)) - t.Errorf("shard2 replicate install osSysInit init fail, error:%s", err) - return - } - if err := osSysInit.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install osSysInit run fail, error:%s", err)) - t.Errorf("shard2 replicate install osSysInit run fail, error:%s", err) - return - } - - // 获取本机IP地址 - var ip string - addrs, _ := net.InterfaceAddrs() - for _, addr := range addrs { - if !strings.Contains(addr.String(), "127.0.0.1") { - ip = strings.Split(addr.String(), "/")[0] - break - } - } - - // node1 - node1 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27005,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s2\",\n \"auth\": true,\n \"clusterRole\":\"shardsvr\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node1 = strings.Replace(node1, "{{ip}}", ip, -1) - - // node2 - node2 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27006,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s2\",\n \"auth\": true,\n \"clusterRole\":\"shardsvr\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node2 = strings.Replace(node2, "{{ip}}", ip, -1) - - // node3 - node3 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27007,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s2\",\n \"auth\": true,\n \"clusterRole\":\"shardsvr\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node3 = strings.Replace(node3, "{{ip}}", ip, -1) - - node1MongodInstall := NewMongoDBInstall() - node2MongodInstall := NewMongoDBInstall() - node3MongodInstall := NewMongoDBInstall() - - node1Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node1, - } - node1Runtime.SetLogger() - node2Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node2, - } - node2Runtime.SetLogger() - node3Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node3, - } - node3Runtime.SetLogger() - - // 安装节点 - if err := node1MongodInstall.Init(node1Runtime); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install node1 init fail, error:%s", err)) - t.Errorf("shard2 replicate install node1 init fail, error:%s", err) - return - } - if err := node1MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install node1 run fail, error:%s", err)) - t.Errorf("shard2 replicate install node1 run fail, error:%s", err) - return - } - if err := node2MongodInstall.Init(node2Runtime); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install node2 init fail, error:%s", err)) - t.Errorf("shard2 replicate install node2 init fail, error:%s", err) - return - } - if err := node2MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install node2 run fail, error:%s", err)) - t.Errorf("shard2 replicate install node2 run fail, error:%s", err) - return - } - if err := node3MongodInstall.Init(node3Runtime); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install node3 init fail, error:%s", err)) - t.Errorf("shard2 replicate install node3 init fail, error:%s", err) - return - } - if err := node3MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install node3 run fail, error:%s", err)) - t.Errorf("shard2 replicate install node3 run fail, error:%s", err) - return - } - - // 复制集初始化 - initReplicasetParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27005,\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s2\",\n \"configSvr\":false,\n \"ips\":[\n \"{{ip}}:27005\",\n \"{{ip}}:27006\",\n \"{{ip}}:27007\"\n ],\n \"priority\":{\n \"{{ip}}:27005\":1,\n \"{{ip}}:27006\":1,\n \"{{ip}}:27007\":0\n },\n \"hidden\":{\n \"{{ip}}:27005\":false,\n \"{{ip}}:27006\":false,\n \"{{ip}}:27007\":true\n }\n}" - initReplicasetParam = strings.Replace(initReplicasetParam, "{{ip}}", ip, -1) - initReplicasetRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: initReplicasetParam, - } - initReplicasetRuntime.SetLogger() - initReplicaset := NewInitiateReplicaset() - if err := initReplicaset.Init(initReplicasetRuntime); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install initReplicaset init fail, error:%s", err)) - t.Errorf("shard2 replicate install initReplicaset init fail, error:%s", err) - return - } - if err := initReplicaset.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install initReplicaset run fail, error:%s", err)) - t.Errorf("shard2 replicate install initReplicaset run fail, error:%s", err) - return - } - time.Sleep(time.Second * 3) - // 创建管理员用户 - addAdminUserParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27005,\n \"instanceType\":\"mongod\",\n \"username\":\"dba\",\n \"password\":\"dba\",\n \"adminUsername\":\"\",\n \"adminPassword\":\"\",\n \"authDb\":\"admin\",\n \"dbs\":[\n\n ],\n \"privileges\":[\n \"root\"\n ]\n}" - addAdminUserParam = strings.Replace(addAdminUserParam, "{{ip}}", ip, -1) - addAdminUserRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: addAdminUserParam, - } - addAdminUserRuntime.SetLogger() - addAdminUser := NewAddUser() - if err := addAdminUser.Init(addAdminUserRuntime); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install addAdminUser init fail, error:%s", err)) - t.Errorf("shard2 replicate install addAdminUser init fail, error:%s", err) - return - } - if err := addAdminUser.Run(); err != nil { - fmt.Println(fmt.Sprintf("shard2 replicate install addAdminUser run fail, error:%s", err)) - t.Errorf("shard2 replicate install addAdminUser run fail, error:%s", err) - return - } -} - -// TestConfigDB 安装ConfigDB测试 -func TestConfigDB(t *testing.T) { - // 设置环境变量 - err := consts.SetMongoDataDir("") - if err != nil { - fmt.Println(fmt.Sprintf("configdb install SetMongoData fail, error:%s", err)) - t.Errorf("configdb install SetMongoData fail, error:%s", err) - return - } - err = consts.SetMongoBackupDir("") - if err != nil { - fmt.Println(fmt.Sprintf("configdb install SetMongoBackup fail, error:%s", err)) - t.Errorf("configdb install SetMongoBackup fail, error:%s", err) - return - } - - err = consts.SetProcessUser("") - if err != nil { - fmt.Println(fmt.Sprintf("configdb install SetProcessUser fail, error:%s", err)) - t.Errorf("configdb install SetProcessUser fail, error:%s", err) - return - } - err = consts.SetProcessUserGroup("") - if err != nil { - fmt.Println(fmt.Sprintf("configdb install SetProcessUserGroup fail, error:%s", err)) - t.Errorf("configdb install SetProcessUserGroup fail, error:%s", err) - return - } - - // 初始化节点 - osSysInitParam := "{\n\"user\":\"mysql\",\n\"password\":\"Qwe123d\"\n}" - osSysInit := &atomsys.OsMongoInit{} - osSysInitRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: osSysInitParam, - } - osSysInitRuntime.SetLogger() - if err := osSysInit.Init(osSysInitRuntime); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install osSysInit init fail, error:%s", err)) - t.Errorf("configdb replicate install osSysInit init fail, error:%s", err) - return - } - if err := osSysInit.Run(); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install osSysInit run fail, error:%s", err)) - t.Errorf("configdb replicate install osSysInit run fail, error:%s", err) - return - } - - // 获取本机IP地址 - var ip string - addrs, _ := net.InterfaceAddrs() - for _, addr := range addrs { - if !strings.Contains(addr.String(), "127.0.0.1") { - ip = strings.Split(addr.String(), "/")[0] - break - } - } - - // node1 - node1 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27020,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"conf\",\n \"auth\": true,\n \"clusterRole\":\"configsvr\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node1 = strings.Replace(node1, "{{ip}}", ip, -1) - - // node2 - node2 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27021,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"conf\",\n \"auth\": true,\n \"clusterRole\":\"configsvr\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node2 = strings.Replace(node2, "{{ip}}", ip, -1) - - // node3 - node3 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27022,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"conf\",\n \"auth\": true,\n \"clusterRole\":\"configsvr\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node3 = strings.Replace(node3, "{{ip}}", ip, -1) - // node4 - node4 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27004,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"conf\",\n \"auth\": true,\n \"clusterRole\":\"configsvr\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node4 = strings.Replace(node4, "{{ip}}", ip, -1) - - node1MongodInstall := NewMongoDBInstall() - node2MongodInstall := NewMongoDBInstall() - node3MongodInstall := NewMongoDBInstall() - node4MongodInstall := NewMongoDBInstall() - - node1Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node1, - } - node1Runtime.SetLogger() - node2Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node2, - } - node2Runtime.SetLogger() - node3Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node3, - } - node3Runtime.SetLogger() - node4Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node4, - } - node4Runtime.SetLogger() - - // 安装节点 - if err := node1MongodInstall.Init(node1Runtime); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install node1 init fail, error:%s", err)) - t.Errorf("configdb replicate install node1 init fail, error:%s", err) - return - } - if err := node1MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install node1 run fail, error:%s", err)) - t.Errorf("configdb replicate install node1 run fail, error:%s", err) - return - } - if err := node2MongodInstall.Init(node2Runtime); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install node2 init fail, error:%s", err)) - t.Errorf("configdb replicate install node2 init fail, error:%s", err) - return - } - if err := node2MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install node2 run fail, error:%s", err)) - t.Errorf("configdb replicate install node2 run fail, error:%s", err) - return - } - if err := node3MongodInstall.Init(node3Runtime); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install node3 init fail, error:%s", err)) - t.Errorf("configdb replicate install node3 init fail, error:%s", err) - return - } - if err := node3MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install node3 run fail, error:%s", err)) - t.Errorf("configdb replicate install node3 run fail, error:%s", err) - return - } - if err := node4MongodInstall.Init(node4Runtime); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install node4 init fail, error:%s", err)) - t.Errorf("configdb replicate install node4 init fail, error:%s", err) - return - } - if err := node4MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install node4 run fail, error:%s", err)) - t.Errorf("configdb replicate install node4 run fail, error:%s", err) - return - } - - // 复制集初始化 - initReplicasetParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27020,\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"conf\",\n \"configSvr\":true,\n \"ips\":[\n \"{{ip}}:27020\",\n \"{{ip}}:27021\",\n \"{{ip}}:27022\"\n ],\n \"priority\":{\n \"{{ip}}:27020\":1,\n \"{{ip}}:27021\":1,\n \"{{ip}}:27022\":0\n },\n \"hidden\":{\n \"{{ip}}:27020\":false,\n \"{{ip}}:27021\":false,\n \"{{ip}}:27022\":true\n }\n}" - initReplicasetParam = strings.Replace(initReplicasetParam, "{{ip}}", ip, -1) - initReplicasetRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: initReplicasetParam, - } - initReplicasetRuntime.SetLogger() - initReplicaset := NewInitiateReplicaset() - if err := initReplicaset.Init(initReplicasetRuntime); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install initReplicaset init fail, error:%s", err)) - t.Errorf("configdb replicate install initReplicaset init fail, error:%s", err) - return - } - if err := initReplicaset.Run(); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install initReplicaset run fail, error:%s", err)) - t.Errorf("configdb replicate install initReplicaset run fail, error:%s", err) - return - } - time.Sleep(time.Second * 3) - // 创建管理员用户 - addAdminUserParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27020,\n \"instanceType\":\"mongod\",\n \"username\":\"dba\",\n \"password\":\"dba\",\n \"adminUsername\":\"\",\n \"adminPassword\":\"\",\n \"authDb\":\"admin\",\n \"dbs\":[\n\n ],\n \"privileges\":[\n \"root\"\n ]\n}" - addAdminUserParam = strings.Replace(addAdminUserParam, "{{ip}}", ip, -1) - addAdminUserRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: addAdminUserParam, - } - addAdminUserRuntime.SetLogger() - addAdminUser := NewAddUser() - if err := addAdminUser.Init(addAdminUserRuntime); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install addAdminUser init fail, error:%s", err)) - t.Errorf("configdb replicate install addAdminUser init fail, error:%s", err) - return - } - if err := addAdminUser.Run(); err != nil { - fmt.Println(fmt.Sprintf("configdb replicate install addAdminUser run fail, error:%s", err)) - t.Errorf("configdb replicate install addAdminUser run fail, error:%s", err) - return - } -} - -// TestMongoS 安装mongos测试 -func TestMongoS(t *testing.T) { - // 设置环境变量 - err := consts.SetMongoDataDir("") - if err != nil { - fmt.Println(fmt.Sprintf("mongos install SetMongoData fail, error:%s", err)) - t.Errorf("mongos install SetMongoData fail, error:%s", err) - return - } - err = consts.SetMongoBackupDir("") - if err != nil { - fmt.Println(fmt.Sprintf("mongos install SetMongoBackup fail, error:%s", err)) - t.Errorf("mongos install SetMongoBackup fail, error:%s", err) - return - } - - err = consts.SetProcessUser("") - if err != nil { - fmt.Println(fmt.Sprintf("mongos install SetProcessUser fail, error:%s", err)) - t.Errorf("mongos install SetProcessUser fail, error:%s", err) - return - } - err = consts.SetProcessUserGroup("") - if err != nil { - fmt.Println(fmt.Sprintf("mongos install SetProcessUserGroup fail, error:%s", err)) - t.Errorf("mongos install SetProcessUserGroup fail, error:%s", err) - return - } - - // 初始化节点 - osSysInitParam := "{\n\"user\":\"mysql\",\n\"password\":\"Qwe123d\"\n}" - osSysInit := &atomsys.OsMongoInit{} - osSysInitRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: osSysInitParam, - } - osSysInitRuntime.SetLogger() - if err := osSysInit.Init(osSysInitRuntime); err != nil { - fmt.Println(fmt.Sprintf("mongos install osSysInit init fail, error:%s", err)) - t.Errorf("mongos install osSysInit init fail, error:%s", err) - return - } - if err := osSysInit.Run(); err != nil { - fmt.Println(fmt.Sprintf("mongos install osSysInit run fail, error:%s", err)) - t.Errorf("monogs install osSysInit run fail, error:%s", err) - return - } - - // 获取本机IP地址 - var ip string - addrs, _ := net.InterfaceAddrs() - for _, addr := range addrs { - if !strings.Contains(addr.String(), "127.0.0.1") { - ip = strings.Split(addr.String(), "/")[0] - break - } - } - mongos1Param := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27030,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongos\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"auth\": true,\n \"configDB\":[\"{{ip}}:27020\",\"{{ip}}:27021\",\"{{ip}}:27022\"],\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"destination\":\"file\"\n }\n}" - mongos2Param := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27031,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongos\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"auth\": true,\n \"configDB\":[\"{{ip}}:27020\",\"{{ip}}:27021\",\"{{ip}}:27022\"],\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"destination\":\"file\"\n }\n}" - mongos1Param = strings.Replace(mongos1Param, "{{ip}}", ip, -1) - mongos2Param = strings.Replace(mongos2Param, "{{ip}}", ip, -1) - - mongos1MongoSInstall := NewMongoSInstall() - mongos2MongoSInstall := NewMongoSInstall() - - mongos1Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: mongos1Param, - } - mongos1Runtime.SetLogger() - mongos2Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: mongos2Param, - } - mongos2Runtime.SetLogger() - - // 安装mongos - if err := mongos1MongoSInstall.Init(mongos1Runtime); err != nil { - fmt.Println(fmt.Sprintf("mongos1 install init fail, error:%s", err)) - t.Errorf("mongos1 install node1 init fail, error:%s", err) - return - } - if err := mongos1MongoSInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("mongos1 install node1 run fail, error:%s", err)) - t.Errorf("mongos1 install node1 run fail, error:%s", err) - return - } - if err := mongos2MongoSInstall.Init(mongos2Runtime); err != nil { - fmt.Println(fmt.Sprintf("mongos2 install init fail, error:%s", err)) - t.Errorf("mongos3 install init fail, error:%s", err) - return - } - if err := mongos2MongoSInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("mongos2 install node1 run fail, error:%s", err)) - t.Errorf("mongos2 install run fail, error:%s", err) - return - } - -} - -func TestCluster(t *testing.T) { - // 设置环境变量 - err := consts.SetMongoDataDir("") - if err != nil { - fmt.Println(fmt.Sprintf("cluster SetMongoData fail, error:%s", err)) - t.Errorf("cluster SetMongoData fail, error:%s", err) - return - } - err = consts.SetMongoBackupDir("") - if err != nil { - fmt.Println(fmt.Sprintf("cluster SetMongoBackup fail, error:%s", err)) - t.Errorf("cluster SetMongoBackup fail, error:%s", err) - return - } - - err = consts.SetProcessUser("") - if err != nil { - fmt.Println(fmt.Sprintf("cluster SetProcessUser fail, error:%s", err)) - t.Errorf("cluster SetProcessUser fail, error:%s", err) - return - } - err = consts.SetProcessUserGroup("") - if err != nil { - fmt.Println(fmt.Sprintf("cluster SetProcessUserGroup fail, error:%s", err)) - t.Errorf("cluster SetProcessUserGroup fail, error:%s", err) - return - } - - // 初始化节点 - osSysInitParam := "{\n\"user\":\"mysql\",\n\"password\":\"Qwe123d\"\n}" - osSysInit := &atomsys.OsMongoInit{} - osSysInitRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: osSysInitParam, - } - osSysInitRuntime.SetLogger() - if err := osSysInit.Init(osSysInitRuntime); err != nil { - fmt.Println(fmt.Sprintf("cluster osSysInit init fail, error:%s", err)) - t.Errorf("cluster osSysInit init fail, error:%s", err) - return - } - if err := osSysInit.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster osSysInit run fail, error:%s", err)) - t.Errorf("cluster osSysInit run fail, error:%s", err) - return - } - - // 获取本机IP地址 - var ip string - addrs, _ := net.InterfaceAddrs() - for _, addr := range addrs { - if !strings.Contains(addr.String(), "127.0.0.1") { - ip = strings.Split(addr.String(), "/")[0] - break - } - } - - // cluster添加shard - addShardParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27030,\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\",\n \"shard\":{\n \"test-test1-s1\":\"{{ip}}:27001,{{ip}}:27002\",\n \"test-test1-s2\":\"{{ip}}:27005,{{ip}}:27006\"\n }\n}" - addShardParam = strings.Replace(addShardParam, "{{ip}}", ip, -1) - addShard := NewAddShardToCluster() - - addShardRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: addShardParam, - } - addShardRuntime.SetLogger() - - if err := addShard.Init(addShardRuntime); err != nil { - fmt.Println(fmt.Sprintf("cluster addShard init fail, error:%s", err)) - t.Errorf("cluster addShard init fail, error:%s", err) - return - } - if err := addShard.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster addShard run fail, error:%s", err)) - t.Errorf("cluster addShard run fail, error:%s", err) - return - } - - // 创建业务用户 - addUserParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27030,\n \"instanceType\":\"mongos\",\n \"username\":\"test\",\n \"password\":\"test\",\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\",\n \"authDb\":\"admin\",\n \"dbs\":[\n\n ],\n \"privileges\":[\n \"readWriteAnyDatabase\"\n ]\n}" - addUserParam = strings.Replace(addUserParam, "{{ip}}", ip, -1) - addUserRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: addUserParam, - } - addUserRuntime.SetLogger() - addUser := NewAddUser() - if err := addUser.Init(addUserRuntime); err != nil { - fmt.Println(fmt.Sprintf("cluster addUser init fail, error:%s", err)) - t.Errorf("cluster addUser init fail, error:%s", err) - return - } - if err := addUser.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster addUser run fail, error:%s", err)) - t.Errorf("cluster addUser run fail, error:%s", err) - return - } - - // 删除业务用户 - delUserParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27030,\n \"instanceType\":\"mongos\",\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\",\n \"username\":\"test\",\n \"authDb\":\"admin\"\n}" - delUserParam = strings.Replace(delUserParam, "{{ip}}", ip, -1) - delUserRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: delUserParam, - } - delUserRuntime.SetLogger() - delUser := NewDelUser() - if err := delUser.Init(delUserRuntime); err != nil { - fmt.Println(fmt.Sprintf("cluster delUser init fail, error:%s", err)) - t.Errorf("cluster delUser init fail, error:%s", err) - return - } - if err := delUser.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster delUser run fail, error:%s", err)) - t.Errorf("cluster delUser run fail, error:%s", err) - return - } - - // 执行脚本 - execScriptParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27030,\n \"script\":\"var mongo = db;\\nmongo.getSisterDB('admin').runCommand({listDatabases:1}).databases.forEach (function (x) { print(x.name)});\\n\",\n \"type\":\"cluster\",\n \"secondary\": false,\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\",\n \"repoUrl\":\"\",\n \"repoUsername\":\"\",\n \"repoToken\":\"\",\n \"repoProject\":\"\",\n \"repoRepo\":\"\",\n \"repoPath\":\"\"\n}" - execScriptParam = strings.Replace(execScriptParam, "{{ip}}", ip, -1) - execScriptRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: execScriptParam, - } - execScriptRuntime.SetLogger() - execScript := NewExecScript() - if err := execScript.Init(execScriptRuntime); err != nil { - fmt.Println(fmt.Sprintf("cluster execScript init fail, error:%s", err)) - t.Errorf("cluster execScript init fail, error:%s", err) - return - } - if err := execScript.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster execScript run fail, error:%s", err)) - t.Errorf("cluster execScript run fail, error:%s", err) - return - } - - // 重启mongod - restartParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27005,\n \"instanceType\":\"mongod\",\n \"singleNodeInstallRestart\":false, \n \"auth\":true,\n \"cacheSizeGB\": 2,\n \"mongoSConfDbOld\":\"\",\n \"MongoSConfDbNew\":\"\",\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\"\n}" - restartParam = strings.Replace(restartParam, "{{ip}}", ip, -1) - restartRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: restartParam, - } - restartRuntime.SetLogger() - restart := NewMongoRestart() - if err := restart.Init(restartRuntime); err != nil { - fmt.Println(fmt.Sprintf("cluster shard mongod restart init fail, error:%s", err)) - t.Errorf("cluster shard mongod restart init fail, error:%s", err) - return - } - if err := restart.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster shard mongod restart run fail, error:%s", err)) - t.Errorf("cluster shard mongod restart run fail, error:%s", err) - return - } - - time.Sleep(time.Second * 3) - // 替换config节点 - replaceParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27020,\n \"sourceIP\":\"{{ip}}\",\n \"sourcePort\":27020,\n \"sourceDown\":false,\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\",\n \"targetIP\":\"{{ip}}\",\n \"targetPort\":27004,\n \"targetPriority\":\"\",\n \"targetHidden\":\"\"\n}" - replaceParam = strings.Replace(replaceParam, "{{ip}}", ip, -1) - replaceRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: replaceParam, - } - replaceRuntime.SetLogger() - replace := NewMongoDReplace() - if err := replace.Init(replaceRuntime); err != nil { - fmt.Println(fmt.Sprintf("cluster replace config mongod init fail, error:%s", err)) - t.Errorf("cluster replace config mongod init fail, error:%s", err) - return - } - if err := replace.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster replace config mongod run fail, error:%s", err)) - t.Errorf("cluster replace config mongod run fail, error:%s", err) - return - } - - // 重启mongos - restart1Param := "{\n \"ip\":\"{{ip}}\",\n \"port\":27030,\n \"instanceType\":\"mongos\",\n \"singleNodeInstallRestart\":false, \n \"auth\":true,\n \"cacheSizeGB\": 0,\n \"mongoSConfDbOld\":\"{{ip}}:27020\",\n \"MongoSConfDbNew\":\"{{ip}}:27004\",\n \"adminUsername\":\"\",\n \"adminPassword\":\"\"\n}" - restart1Param = strings.Replace(restart1Param, "{{ip}}", ip, -1) - restart1Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: restart1Param, - } - restart1Runtime.SetLogger() - restart1 := NewMongoRestart() - if err := restart1.Init(restart1Runtime); err != nil { - fmt.Println(fmt.Sprintf("cluster mongos port:%d restart init fail, error:%s", 27030, err)) - t.Errorf("cluster mongos port:%d restart init fail, error:%s", 27030, err) - return - } - if err := restart1.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster mongos port:%d restart run fail, error:%s", 27030, err)) - t.Errorf("cluster mongos restart port:%d run fail, error:%s", 27030, err) - return - } - - restart2Param := "{\n \"ip\":\"{{ip}}\",\n \"port\":27031,\n \"instanceType\":\"mongos\",\n \"singleNodeInstallRestart\":false, \n \"auth\":true,\n \"cacheSizeGB\": 0,\n \"mongoSConfDbOld\":\"{{ip}}:27020\",\n \"MongoSConfDbNew\":\"{{ip}}:27004\",\n \"adminUsername\":\"\",\n \"adminPassword\":\"\"\n}" - restart2Param = strings.Replace(restart2Param, "{{ip}}", ip, -1) - restart2Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: restart2Param, - } - restart2Runtime.SetLogger() - restart2 := NewMongoRestart() - if err := restart2.Init(restart2Runtime); err != nil { - fmt.Println(fmt.Sprintf("cluster mongos port:%d restart init fail, error:%s", 27031, err)) - t.Errorf("cluster mongos port:%d restart init fail, error:%s", 27031, err) - return - } - if err := restart2.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster mongos port:%d restart run fail, error:%s", 27031, err)) - t.Errorf("cluster mongos restart port:%d run fail, error:%s", 27031, err) - return - } - - time.Sleep(time.Second * 3) - // 下架mongos - for _, i := range []int{27030, 27031} { - deinstallParam := fmt.Sprintf("{\n \"ip\":\"{{ip}}\",\n \"port\":%d,\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"nodeInfo\":[\n \"{{ip}}\"\n ],\n \"instanceType\":\"mongos\"\n}", i) - deinstallParam = strings.Replace(deinstallParam, "{{ip}}", ip, -1) - deinstallRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: deinstallParam, - } - deinstallRuntime.SetLogger() - deinstal := NewDeInstall() - if err := deinstal.Init(deinstallRuntime); err != nil { - fmt.Println(fmt.Sprintf("cluster deinstal mongos port:%d init fail, error:%s", i, err)) - t.Errorf("cluster deinstal mongos port:%d init fail, error:%s", i, err) - return - } - if err := deinstal.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster deinstal mongos deinstal port:%d run fail, error:%s", i, err)) - t.Errorf("cluster deinstal mongos port:%d run fail, error:%s", i, err) - return - } - } - - time.Sleep(time.Second * 2) - // 下架shard - for _, i := range []int{27001, 27002, 27003, 27005, 27006, 27007} { - deinstallParam := fmt.Sprintf("{\n \"ip\":\"{{ip}}\",\n \"port\":%d,\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"nodeInfo\":[\n \"{{ip}}\"\n ],\n \"instanceType\":\"mongod\"\n}", i) - deinstallParam = strings.Replace(deinstallParam, "{{ip}}", ip, -1) - deinstallRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: deinstallParam, - } - deinstallRuntime.SetLogger() - deinstal := NewDeInstall() - if err := deinstal.Init(deinstallRuntime); err != nil { - fmt.Println(fmt.Sprintf("cluster deinstal shard mongod port:%d init fail, error:%s", i, err)) - t.Errorf("cluster deinstal shard mongod port:%d init fail, error:%s", i, err) - return - } - if err := deinstal.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster deinstal shard mongod deinstal port:%d run fail, error:%s", i, err)) - t.Errorf("cluster deinstal shard mongod port:%d run fail, error:%s", i, err) - return - } - } - - time.Sleep(time.Second * 2) - // 下架configdb - for _, i := range []int{27004, 27021, 27022} { - deinstallParam := fmt.Sprintf("{\n \"ip\":\"{{ip}}\",\n \"port\":%d,\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"nodeInfo\":[\n \"{{ip}}\"\n ],\n \"instanceType\":\"mongod\"\n}", i) - deinstallParam = strings.Replace(deinstallParam, "{{ip}}", ip, -1) - deinstallRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: deinstallParam, - } - deinstallRuntime.SetLogger() - deinstal := NewDeInstall() - if err := deinstal.Init(deinstallRuntime); err != nil { - fmt.Println(fmt.Sprintf("cluster deinstal configdb mongod port:%d init fail, error:%s", i, err)) - t.Errorf("cluster deinstal configdb mongod port:%d init fail, error:%s", i, err) - return - } - if err := deinstal.Run(); err != nil { - fmt.Println(fmt.Sprintf("cluster deinstal configdb mongod deinstal port:%d run fail, error:%s", i, err)) - t.Errorf("cluster deinstal configdb mongod port:%d run fail, error:%s", i, err) - return - } - } - - // 删除相关目录 - dbData := path.Join(consts.GetMongoDataDir(), "mongodata") - dbLog := path.Join(consts.GetMongoBackupDir(), "mongolog") - softInstall := path.Join(consts.UsrLocal, "mongodb") - cmd := fmt.Sprintf("rm -rf %s;rm -rf %s;rm -rf %s", dbData, dbLog, softInstall) - if _, err = util.RunBashCmd(cmd, "", nil, 10*time.Second); err != nil { - fmt.Println(fmt.Sprintf("delete directories fail, error:%s", err)) - t.Errorf("delete directories fail, error:%s", err) - } - -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go deleted file mode 100644 index 56a872c0ab..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go +++ /dev/null @@ -1,204 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "path/filepath" - "strconv" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// DelUserConfParams 参数 -type DelUserConfParams struct { - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - InstanceType string `json:"instanceType" validate:"required"` - AdminUsername string `json:"adminUsername" validate:"required"` - AdminPassword string `json:"adminPassword" validate:"required"` - Username string `json:"username" validate:"required"` - AuthDb string `json:"authDb"` // 为方便管理用户,验证库默认为admin库 -} - -// DelUser 添加分片到集群 -type DelUser struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - Mongo string - OsUser string - PrimaryIP string - PrimaryPort int - ScriptContent string - ConfParams *DelUserConfParams -} - -// NewDelUser 实例化结构体 -func NewDelUser() jobruntime.JobRunner { - return &DelUser{} -} - -// Name 获取原子任务的名字 -func (d *DelUser) Name() string { - return "delete_user" -} - -// Run 运行原子任务 -func (d *DelUser) Run() error { - // 生成脚本内容 - if err := d.makeScriptContent(); err != nil { - return err - } - - // 执行js脚本 - if err := d.execScript(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (d *DelUser) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (d *DelUser) Rollback() error { - return nil -} - -// Init 初始化 -func (d *DelUser) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - d.runtime = runtime - d.runtime.Logger.Info("start to init") - d.BinDir = consts.UsrLocal - d.Mongo = filepath.Join(d.BinDir, "mongodb", "bin", "mongo") - d.OsUser = consts.GetProcessUser() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(d.runtime.PayloadDecoded), &d.ConfParams); err != nil { - d.runtime.Logger.Error(fmt.Sprintf( - "get parameters of deleteUser fail by json.Unmarshal, error:%s", err)) - return fmt.Errorf("get parameters of deleteUser fail by json.Unmarshal, error:%s", err) - } - - // 获取primary信息 - if d.ConfParams.InstanceType == "mongos" { - d.PrimaryIP = d.ConfParams.IP - d.PrimaryPort = d.ConfParams.Port - } else { - info, err := common.AuthGetPrimaryInfo(d.OsUser, d.Mongo, d.ConfParams.AdminUsername, d.ConfParams.AdminPassword, - d.ConfParams.IP, d.ConfParams.Port) - if err != nil { - d.runtime.Logger.Error(fmt.Sprintf( - "get primary db info of addUser fail, error:%s", err)) - return fmt.Errorf("get primary db info of addUser fail, error:%s", err) - } - getInfo := strings.Split(info, ":") - d.PrimaryIP = getInfo[0] - d.PrimaryPort, _ = strconv.Atoi(getInfo[1]) - } - d.runtime.Logger.Info("init successfully") - - // 进行校验 - if err := d.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (d *DelUser) checkParams() error { - // 校验重启配置参数 - validate := validator.New() - d.runtime.Logger.Info("start to validate parameters of deleteUser") - if err := validate.Struct(d.ConfParams); err != nil { - d.runtime.Logger.Error(fmt.Sprintf("validate parameters of deleteUser fail, error:%s", err)) - return fmt.Errorf("validate parameters of deleteUser fail, error:%s", err) - } - d.runtime.Logger.Info("validate parameters of deleteUser successfully") - return nil -} - -// makeScriptContent 生成user配置内容 -func (d *DelUser) makeScriptContent() error { - d.runtime.Logger.Info("start to make deleteUser script content") - // 判断验证db - if d.ConfParams.AuthDb == "" { - d.ConfParams.AuthDb = "admin" - } - - // 获取mongo版本 - mongoName := "mongod" - if d.ConfParams.InstanceType == "mongos" { - mongoName = "mongos" - } - version, err := common.CheckMongoVersion(d.BinDir, mongoName) - if err != nil { - d.runtime.Logger.Error(fmt.Sprintf("check mongo version fail, error:%s", err)) - return fmt.Errorf("check mongo version fail, error:%s", err) - } - mainVersion, _ := strconv.Atoi(strings.Split(version, ".")[0]) - if mainVersion >= 3 { - d.ScriptContent = strings.Join([]string{fmt.Sprintf("db.getMongo().getDB('%s')", d.ConfParams.AuthDb), - fmt.Sprintf("dropUser('%s')", d.ConfParams.Username)}, ".") - d.runtime.Logger.Info("make deleteUser script content successfully") - return nil - } - d.ScriptContent = strings.Join([]string{fmt.Sprintf("db.getMongo().getDB('%s')", d.ConfParams.AuthDb), - fmt.Sprintf("removeUser('%s')", d.ConfParams.Username)}, ".") - d.runtime.Logger.Info("make deleteUser script content successfully") - return nil -} - -// execScript 执行脚本 -func (d *DelUser) execScript() error { - // 检查 - flag, err := common.AuthCheckUser(d.OsUser, d.Mongo, d.ConfParams.AdminUsername, d.ConfParams.AdminPassword, - d.PrimaryIP, d.PrimaryPort, d.ConfParams.AuthDb, d.ConfParams.Username) - if err != nil { - return err - } - if flag == false { - d.runtime.Logger.Info(fmt.Sprintf("user:%s is not existed", d.ConfParams.Username)) - return nil - } - - // 执行脚本 - d.runtime.Logger.Info("start to execute deleteUser script") - cmd := fmt.Sprintf( - "su %s -c \"%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet --eval \\\"%s\\\"\"", - d.OsUser, d.Mongo, d.ConfParams.AdminUsername, d.ConfParams.AdminPassword, d.PrimaryIP, - d.PrimaryPort, d.ScriptContent) - if _, err := util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - d.runtime.Logger.Error(fmt.Sprintf("execute addUser script fail, error:%s", err)) - return fmt.Errorf("execute addUser script fail, error:%s", err) - } - - time.Sleep(2 * time.Second) - - // 检查 - flag, err = common.AuthCheckUser(d.OsUser, d.Mongo, d.ConfParams.AdminUsername, d.ConfParams.AdminPassword, - d.PrimaryIP, d.PrimaryPort, d.ConfParams.AuthDb, d.ConfParams.Username) - if err != nil { - return err - } - if flag == true { - d.runtime.Logger.Error(fmt.Sprintf("delete user:%s fail, error:%s", d.ConfParams.Username, err)) - return fmt.Errorf("delete user:%s fail, error:%s", d.ConfParams.Username, err) - } - d.runtime.Logger.Info("execute deleteUser script successfully") - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go deleted file mode 100644 index df3b9f76bc..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/initiate_replicaset.go +++ /dev/null @@ -1,279 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// InitConfParams 参数 -type InitConfParams struct { - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - App string `json:"app" validate:"required"` - AreaId string `json:"areaId" validate:"required"` - SetId string `json:"setId" validate:"required"` - ConfigSvr bool `json:"configSvr"` // shardsvr configsvr - Ips []string `json:"ips" validate:"required"` // ip:port - Priority map[string]int `json:"priority" validate:"required"` // key->ip:port,value->priority - Hidden map[string]bool `json:"hidden" validate:"required"` // key->ip:port,value->hidden(true or false) -} - -// InitiateReplicaset 复制集初始化 -type InitiateReplicaset struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - Mongo string - OsUser string - ConfFilePath string - ConfFileContent string - ConfParams *InitConfParams - ClusterId string - StatusChan chan int -} - -// NewInitiateReplicaset 实例化结构体 -func NewInitiateReplicaset() jobruntime.JobRunner { - return &InitiateReplicaset{} -} - -// Name 获取原子任务的名字 -func (i *InitiateReplicaset) Name() string { - return "init_replicaset" -} - -// Run 运行原子任务 -func (i *InitiateReplicaset) Run() error { - // 获取配置内容 - if err := i.makeConfContent(); err != nil { - return err - } - - // 生成js脚本 - if err := i.createInitiateReplicasetScript(); err != nil { - return err - } - - // 执行js脚本 - if err := i.execScript(); err != nil { - return err - } - - // 检查状态 - go i.checkStatus() - - // 获取状态 - if err := i.getStatus(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (i *InitiateReplicaset) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (i *InitiateReplicaset) Rollback() error { - return nil -} - -// Init 初始化 -func (i *InitiateReplicaset) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - i.runtime = runtime - i.runtime.Logger.Info("start to init") - i.BinDir = consts.UsrLocal - i.Mongo = filepath.Join(i.BinDir, "mongodb", "bin", "mongo") - i.OsUser = consts.GetProcessUser() - i.ConfFilePath = filepath.Join("/", "tmp", "initiateReplicaset.js") - i.StatusChan = make(chan int, 1) - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(i.runtime.PayloadDecoded), &i.ConfParams); err != nil { - i.runtime.Logger.Error(fmt.Sprintf( - "get parameters of initiateReplicaset fail by json.Unmarshal, error:%s", err)) - return fmt.Errorf("get parameters of initiateReplicaset fail by json.Unmarshal, error:%s", err) - } - i.ClusterId = strings.Join([]string{i.ConfParams.App, i.ConfParams.AreaId, i.ConfParams.SetId}, "-") - i.runtime.Logger.Info("init successfully") - - // 进行校验 - if err := i.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (i *InitiateReplicaset) checkParams() error { - // 校验重启配置参数 - validate := validator.New() - i.runtime.Logger.Info("start to validate parameters of initiateReplicaset") - if err := validate.Struct(i.ConfParams); err != nil { - i.runtime.Logger.Error(fmt.Sprintf("validate parameters of initiateReplicaset fail, error:%s", err)) - return fmt.Errorf("validate parameters of initiateReplicaset fail, error:%s", err) - } - i.runtime.Logger.Info("validate parameters of initiateReplicaset successfully") - return nil -} - -// makeConfContent 获取配置内容 -func (i *InitiateReplicaset) makeConfContent() error { - i.runtime.Logger.Info("start to make config content of initiateReplicaset") - jsonConfReplicaset := common.NewJsonConfReplicaset() - jsonConfReplicaset.Id = i.ClusterId - for index, value := range i.ConfParams.Ips { - member := common.NewMember() - member.Id = index - member.Host = i.ConfParams.Ips[index] - member.Priority = i.ConfParams.Priority[value] - member.Hidden = i.ConfParams.Hidden[value] - jsonConfReplicaset.Members = append(jsonConfReplicaset.Members, member) - } - jsonConfReplicaset.ConfigSvr = i.ConfParams.ConfigSvr - - var err error - confJson, err := json.Marshal(jsonConfReplicaset) - if err != nil { - i.runtime.Logger.Error( - fmt.Sprintf("config content of initiateReplicaset json Marshal fial, error:%s", err)) - return fmt.Errorf("config content of initiateReplicaset json Marshal fial, error:%s", err) - } - i.ConfFileContent = strings.Join([]string{"var config=", - string(confJson), "\n", "rs.initiate(config)\n"}, "") - i.runtime.Logger.Info("make config content of initiateReplicaset successfully") - return nil -} - -// createInitiateReplicasetScript 生成js脚本 -func (i *InitiateReplicaset) createInitiateReplicasetScript() error { - i.runtime.Logger.Info("start to create initiateReplicaset script") - confFile, err := os.OpenFile(i.ConfFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, DefaultPerm) - defer confFile.Close() - if err != nil { - i.runtime.Logger.Error( - fmt.Sprintf("create script file of initiateReplicaset json Marshal fail, error:%s", err)) - return fmt.Errorf("create script file of initiateReplicaset json Marshal fail, error:%s", err) - } - - if _, err = confFile.WriteString(i.ConfFileContent); err != nil { - i.runtime.Logger.Error( - fmt.Sprintf("create script file of initiateReplicaset write content fail, error:%s", - err)) - return fmt.Errorf("create script file of initiateReplicaset write content fail, error:%s", - err) - } - i.runtime.Logger.Info("create initiateReplicaset script successfully") - return nil -} - -// getPrimaryInfo 检查状态 -func (i *InitiateReplicaset) getPrimaryInfo() (bool, error) { - i.runtime.Logger.Info("start to check replicaset status") - result, err := common.InitiateReplicasetGetPrimaryInfo(i.OsUser, i.Mongo, i.ConfParams.IP, i.ConfParams.Port) - if err != nil { - i.runtime.Logger.Error(fmt.Sprintf("get initiateReplicaset primary info fail, error:%s", err)) - return false, fmt.Errorf("get initiateReplicaset primary info fail, error:%s", err) - } - i.runtime.Logger.Info("check replicaset status successfully") - for _, v := range i.ConfParams.Ips { - if v == result { - return true, nil - } - } - - return false, nil -} - -// checkStatus 检查复制集状态 -func (i *InitiateReplicaset) checkStatus() { - for { - result, err := common.NoAuthGetPrimaryInfo(i.OsUser, i.Mongo, i.ConfParams.IP, i.ConfParams.Port) - if err != nil { - i.runtime.Logger.Error("check replicaset status fail, error:%s", err) - fmt.Sprintf("check replicaset status fail, error:%s\n", err) - panic(fmt.Sprintf("check replicaset status fail, error:%s\n", err)) - } - if result != "" { - i.StatusChan <- 1 - } - time.Sleep(2 * time.Second) - } -} - -// execScript 执行脚本 -func (i *InitiateReplicaset) execScript() error { - // 检查 - flag, err := i.getPrimaryInfo() - if err != nil { - return err - } - if flag == true { - i.runtime.Logger.Info("replicaset has been initiated") - if err = i.removeScript(); err != nil { - return err - } - - return nil - } - - // 执行脚本 - i.runtime.Logger.Info("start to execute initiateReplicaset script") - cmd := fmt.Sprintf("su %s -c \"%s --host %s --port %d --quiet %s\"", - i.OsUser, i.Mongo, "127.0.0.1", i.ConfParams.Port, i.ConfFilePath) - if _, err = util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - i.runtime.Logger.Error("execute initiateReplicaset script fail, error:%s", err) - return fmt.Errorf("execute initiateReplicaset script fail, error:%s", err) - } - i.runtime.Logger.Info("execute initiateReplicaset script successfully") - return nil -} - -// getStatus 检查复制集状态,是否创建成功 -func (i *InitiateReplicaset) getStatus() error { - for { - select { - case status := <-i.StatusChan: - if status == 1 { - i.runtime.Logger.Info("initiate replicaset successfully") - // 删除脚本 - if err := i.removeScript(); err != nil { - return err - } - return nil - } - default: - - } - } -} - -// removeScript 删除脚本 -func (i *InitiateReplicaset) removeScript() error { - // 删除脚本 - i.runtime.Logger.Info("start to remove initiateReplicaset script") - if err := common.RemoveFile(i.ConfFilePath); err != nil { - i.runtime.Logger.Error(fmt.Sprintf("remove initiateReplicaset script fail, error:%s", err)) - return fmt.Errorf("remove initiateReplicaset script fail, error:%s", err) - } - i.runtime.Logger.Info("remove initiateReplicaset script successfully") - - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go deleted file mode 100644 index 00a8415ae8..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_deinstall.go +++ /dev/null @@ -1,230 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "path/filepath" - "strconv" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// DeInstallConfParams 参数 -type DeInstallConfParams struct { - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - App string `json:"app" validate:"required"` - AreaId string `json:"areaId" validate:"required"` - NodeInfo []string `json:"nodeInfo" validate:"required"` // []string ip,ip 如果为复制集节点,则为复制集所有节点的ip;如果为mongos,则为mongos的ip - InstanceType string `json:"instanceType" validate:"required"` // mongod mongos -} - -// DeInstall 添加分片到集群 -type DeInstall struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - DataDir string - BackupDir string - DbpathDir string - InstallPath string - PortDir string - LogPortDir string - DbPathRenameDir string - LogPathRenameDir string - Mongo string - OsUser string - ServiceStatus bool - IPInfo string - ConfParams *DeInstallConfParams -} - -// NewDeInstall 实例化结构体 -func NewDeInstall() jobruntime.JobRunner { - return &DeInstall{} -} - -// Name 获取原子任务的名字 -func (d *DeInstall) Name() string { - return "mongo_deinstall" -} - -// Run 运行原子任务 -func (d *DeInstall) Run() error { - // 检查实例状态 - if err := d.checkMongoService(); err != nil { - return err - } - - // 关闭进程 - if err := d.shutdownProcess(); err != nil { - return err - } - - // rename目录 - if err := d.DirRename(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (d *DeInstall) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (d *DeInstall) Rollback() error { - return nil -} - -// Init 初始化 -func (d *DeInstall) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - d.runtime = runtime - d.runtime.Logger.Info("start to init") - d.BinDir = consts.UsrLocal - d.DataDir = consts.GetMongoDataDir() - d.BackupDir = consts.GetMongoBackupDir() - - d.OsUser = consts.GetProcessUser() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(d.runtime.PayloadDecoded), &d.ConfParams); err != nil { - d.runtime.Logger.Error( - "get parameters of deInstall fail by json.Unmarshal, error:%s", err) - return fmt.Errorf("get parameters of deInstall fail by json.Unmarshal, error:%s", err) - } - - // 获取各种目录 - d.InstallPath = filepath.Join(d.BinDir, "mongodb") - d.Mongo = filepath.Join(d.BinDir, "mongodb", "bin", "mongo") - strPort := strconv.Itoa(d.ConfParams.Port) - d.PortDir = filepath.Join(d.DataDir, "mongodata", strPort) - d.DbpathDir = filepath.Join(d.DataDir, "mongodata", strPort, "db") - d.DbPathRenameDir = filepath.Join(d.DataDir, "mongodata", fmt.Sprintf("%s_%s_%s_%d", - d.ConfParams.InstanceType, d.ConfParams.App, d.ConfParams.AreaId, d.ConfParams.Port)) - d.IPInfo = strings.Join(d.ConfParams.NodeInfo, "|") - d.LogPortDir = filepath.Join(d.BackupDir, "mongolog", strPort) - d.LogPathRenameDir = filepath.Join(d.BackupDir, "mongolog", fmt.Sprintf("%s_%s_%s_%d", - d.ConfParams.InstanceType, d.ConfParams.App, d.ConfParams.AreaId, d.ConfParams.Port)) - - // 进行校验 - if err := d.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (d *DeInstall) checkParams() error { - // 校验配置参数 - d.runtime.Logger.Info("start to validate parameters") - validate := validator.New() - d.runtime.Logger.Info("start to validate parameters of deInstall") - if err := validate.Struct(d.ConfParams); err != nil { - d.runtime.Logger.Error("validate parameters of deInstall fail, error:%s", err) - return fmt.Errorf("validate parameters of deInstall fail, error:%s", err) - } - return nil -} - -// checkMongoService 检查mongo服务 -func (d *DeInstall) checkMongoService() error { - d.runtime.Logger.Info("start to check process status") - flag, _, err := common.CheckMongoService(d.ConfParams.Port) - if err != nil { - d.runtime.Logger.Error("get mongo service status fail, error:%s", err) - return fmt.Errorf("get mongo service status fail, error:%s", err) - } - d.ServiceStatus = flag - return nil -} - -// checkConnection 检查连接 -func (d *DeInstall) checkConnection() error { - d.runtime.Logger.Info("start to check connection") - cmd := fmt.Sprintf( - "source /etc/profile;netstat -nat | grep %d |awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr |grep -Ewv '0.0.0.0|127.0.0.1|%s' || true", - d.ConfParams.Port, d.IPInfo) - - result, err := util.RunBashCmd( - cmd, - "", nil, - 10*time.Second) - if err != nil { - d.runtime.Logger.Error("check connection fail, error:%s", err) - return fmt.Errorf("check connection fail, error:%s", err) - } - result = strings.Replace(result, "\n", "", -1) - if result != "" { - d.runtime.Logger.Error("check connection fail, there are some connections") - return fmt.Errorf("check connection fail, there are some connections") - } - return nil -} - -// shutdownProcess 关闭进程 -func (d *DeInstall) shutdownProcess() error { - if d.ServiceStatus == true { - d.runtime.Logger.Info("start to shutdown service") - // 检查连接 - if err := d.checkConnection(); err != nil { - return err - } - - // 关闭进程 - if err := common.ShutdownMongoProcess(d.OsUser, d.ConfParams.InstanceType, d.BinDir, d.DbpathDir, - d.ConfParams.Port); err != nil { - d.runtime.Logger.Error("shutdown mongo service fail, error:%s", err) - return fmt.Errorf("shutdown mongo service fail, error:%s", err) - } - } - - return nil -} - -// DirRename 打包数据目录 -func (d *DeInstall) DirRename() error { - // renameDb数据目录 - flag := util.FileExists(d.PortDir) - if flag == true { - d.runtime.Logger.Info("start to rename db directory") - cmd := fmt.Sprintf( - "mv %s %s", - d.PortDir, d.DbPathRenameDir) - if _, err := util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - d.runtime.Logger.Error("rename db directory fail, error:%s", err) - return fmt.Errorf("rename db directory fail, error:%s", err) - } - } - - // renameDb日志目录 - flag = util.FileExists(d.LogPortDir) - if flag == true { - d.runtime.Logger.Info("start to rename log directory") - cmd := fmt.Sprintf( - "mv %s %s", - d.LogPortDir, d.LogPathRenameDir) - if _, err := util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - d.runtime.Logger.Error("rename log directory fail, error:%s", err) - return fmt.Errorf("rename log directory fail, error:%s", err) - } - } - - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go deleted file mode 100644 index 76f480c41c..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_execute_script.go +++ /dev/null @@ -1,331 +0,0 @@ -package atommongodb - -import ( - "encoding/base64" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "os" - "path/filepath" - "strconv" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// ExecScriptConfParams 参数 -type ExecScriptConfParams struct { - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - Script string `json:"script" validate:"required"` - Type string `json:"type" validate:"required"` // cluster:执行脚本为传入的mongos replicaset:执行脚本为指定节点 - Secondary bool `json:"secondary"` // 复制集是否在secondary节点执行script - AdminUsername string `json:"adminUsername" validate:"required"` - AdminPassword string `json:"adminPassword" validate:"required"` - RepoUrl string `json:"repoUrl"` // 制品库url - RepoUsername string `json:"repoUsername"` // 制品库用户名 - RepoToken string `json:"repoToken"` // 制品库token - RepoProject string `json:"repoProject"` // 制品库project - RepoRepo string `json:"repoRepo"` // 制品库repo - RepoPath string `json:"repoPath"` // 制品库路径 -} - -// ExecScript 添加分片到集群 -type ExecScript struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - Mongo string - OsUser string - OsGroup string - execIP string - execPort int - ScriptDir string - ScriptContent string - ScriptFilePath string - ResultFilePath string - ConfParams *ExecScriptConfParams -} - -// NewExecScript 实例化结构体 -func NewExecScript() jobruntime.JobRunner { - return &ExecScript{} -} - -// Name 获取原子任务的名字 -func (e *ExecScript) Name() string { - return "mongo_execute_script" -} - -// Run 运行原子任务 -func (e *ExecScript) Run() error { - // 生成script内容 - if err := e.makeScriptContent(); err != nil { - return err - } - - // 创建script文件 - if err := e.creatScriptFile(); err != nil { - return err - } - - // 执行脚本生成结果文件 - if err := e.execScript(); err != nil { - return err - } - - // 上传结果文件到制品库 - if err := e.uploadFile(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (e *ExecScript) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (e *ExecScript) Rollback() error { - return nil -} - -// Init 初始化 -func (e *ExecScript) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - e.runtime = runtime - e.runtime.Logger.Info("start to init") - e.BinDir = consts.UsrLocal - e.OsUser = consts.GetProcessUser() - e.OsGroup = consts.GetProcessUserGroup() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(e.runtime.PayloadDecoded), &e.ConfParams); err != nil { - e.runtime.Logger.Error( - "get parameters of execScript fail by json.Unmarshal, error:%s", err) - return fmt.Errorf("get parameters of execScript fail by json.Unmarshal, error:%s", err) - } - - // 获取各种目录 - e.Mongo = filepath.Join(e.BinDir, "mongodb", "bin", "mongo") - e.ScriptDir = filepath.Join("/", "home", e.OsUser, e.runtime.UID) - e.ScriptFilePath = filepath.Join(e.ScriptDir, strings.Join([]string{"script", "js"}, ".")) - e.ResultFilePath = filepath.Join(e.ScriptDir, strings.Join([]string{"result", "txt"}, ".")) - e.runtime.Logger.Info("init successfully") - - // 复制集获取执行脚本的IP端口 默认为primary节点 可以指定secondary节点 - if e.ConfParams.Type == "cluster" { - e.execIP = e.ConfParams.IP - e.execPort = e.ConfParams.Port - } - if e.ConfParams.Type == "replicaset" { - primaryInfo, err := common.AuthGetPrimaryInfo(e.OsUser, e.Mongo, e.ConfParams.AdminUsername, - e.ConfParams.AdminPassword, - e.ConfParams.IP, e.ConfParams.Port) - if err != nil { - e.runtime.Logger.Error("init get primary info fail, error:%s", err) - return fmt.Errorf("init get primary info fail, error:%s", err) - } - e.execIP = strings.Split(primaryInfo, ":")[0] - e.execPort, _ = strconv.Atoi(strings.Split(primaryInfo, ":")[1]) - if e.ConfParams.Secondary == true { - _, _, _, _, _, memberInfo, err := common.GetNodeInfo(e.OsUser, e.Mongo, e.ConfParams.IP, e.ConfParams.Port, - e.ConfParams.AdminUsername, e.ConfParams.AdminPassword, e.ConfParams.IP, e.ConfParams.Port) - if err != nil { - e.runtime.Logger.Error("init get member info fail, error:%s", err) - return fmt.Errorf("init get member info fail, error:%s", err) - } - for _, v := range memberInfo { - if v["state"] == "2" && v["hidden"] == "false" { - e.execIP = strings.Split(v["name"], ":")[0] - e.execPort, _ = strconv.Atoi(strings.Split(v["name"], ":")[1]) - } - } - } - } - - // 进行校验 - if err := e.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (e *ExecScript) checkParams() error { - // 校验配置参数 - e.runtime.Logger.Info("start to validate parameters") - validate := validator.New() - e.runtime.Logger.Info("start to validate parameters of deInstall") - if err := validate.Struct(e.ConfParams); err != nil { - e.runtime.Logger.Error("validate parameters of execScript fail, error:%s", err) - return fmt.Errorf("validate parameters of execScript fail, error:%s", err) - } - e.runtime.Logger.Info("validate parameters successfully") - return nil -} - -// makeScriptContent 生成script内容 -func (e *ExecScript) makeScriptContent() error { - // 复制集,判断在primary节点还是在secondary节点执行脚本 - e.runtime.Logger.Info("start to make script content") - if e.ConfParams.Type == "replicaset" && e.ConfParams.Secondary == true { - // 获取mongo版本呢 - mongoName := "mongod" - version, err := common.CheckMongoVersion(e.BinDir, mongoName) - if err != nil { - e.runtime.Logger.Error("get mongo service version fail, error:%s", err) - return fmt.Errorf("get mongo service version fail, error:%s", err) - } - splitVersion := strings.Split(version, ".") - mainVersion, _ := strconv.ParseFloat(strings.Join([]string{splitVersion[0], splitVersion[1]}, "."), 32) - - // secondary执行script - secondaryOk := "rs.slaveOk()\n" - if mainVersion >= 3.6 { - secondaryOk = "rs.secondaryOk()\n" - } - e.ScriptContent = strings.Join([]string{secondaryOk, e.ConfParams.Script}, "") - e.runtime.Logger.Info("make script content successfully") - return nil - } - e.ScriptContent = e.ConfParams.Script - e.runtime.Logger.Info("make script content successfully") - return nil -} - -// creatScriptFile 创建script文件 -func (e *ExecScript) creatScriptFile() error { - // 创建目录 - e.runtime.Logger.Info("start to make script directory") - if err := util.MkDirsIfNotExists([]string{e.ScriptDir}); err != nil { - e.runtime.Logger.Error("create script directory:%s fail, error:%s", e.ScriptDir, err) - return fmt.Errorf("create script directory:%s fail, error:%s", e.ScriptDir, err) - } - - // 创建文件 - e.runtime.Logger.Info("start to create script file") - script, err := os.OpenFile(e.ScriptFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, DefaultPerm) - defer script.Close() - if err != nil { - e.runtime.Logger.Error( - fmt.Sprintf("create script file fail, error:%s", err)) - return fmt.Errorf("create script file fail, error:%s", err) - } - if _, err = script.WriteString(e.ScriptContent); err != nil { - e.runtime.Logger.Error( - fmt.Sprintf("script file write content fail, error:%s", - err)) - return fmt.Errorf("script file write content fail, error:%s", - err) - } - e.runtime.Logger.Info("create script file successfully") - // 修改配置文件属主 - e.runtime.Logger.Info("start to execute chown command for script file") - if _, err = util.RunBashCmd( - fmt.Sprintf("chown -R %s.%s %s", e.OsUser, e.OsGroup, e.ScriptDir), - "", nil, - 10*time.Second); err != nil { - e.runtime.Logger.Error(fmt.Sprintf("chown auth config file fail, error:%s", err)) - return fmt.Errorf("chown auth config file fail, error:%s", err) - } - e.runtime.Logger.Info("start to execute chown command for script file successfully") - return nil -} - -// execScript 执行脚本 -func (e *ExecScript) execScript() error { - e.runtime.Logger.Info("start to execute script") - cmd := fmt.Sprintf( - "su %s -c \"%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet %s > %s\"", - e.OsUser, e.Mongo, e.ConfParams.AdminUsername, e.ConfParams.AdminPassword, e.execIP, e.execPort, - e.ScriptFilePath, e.ResultFilePath) - cmdX := fmt.Sprintf( - "su %s -c \"%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet %s > %s\"", - e.OsUser, e.Mongo, e.ConfParams.AdminUsername, "xxx", e.execIP, e.execPort, - e.ScriptFilePath, e.ResultFilePath) - if _, err := util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - e.runtime.Logger.Error("execute script:%s fail, error:%s", cmdX, err) - return fmt.Errorf("execute script:%s fail, error:%s", cmdX, err) - } - e.runtime.Logger.Info("execute script:%s successfully", cmdX) - return nil -} - -// Output 请求响应结构体 -type Output struct { - Code int `json:"code"` - Message string `json:"message"` -} - -// uploadFile 上传结果文件 -func (e *ExecScript) uploadFile() error { - if e.ConfParams.RepoUrl == "" { - return nil - } - e.runtime.Logger.Info("start to upload result file") - // url - url := strings.Join([]string{e.ConfParams.RepoUrl, e.ConfParams.RepoProject, e.ConfParams.RepoRepo, - e.ConfParams.RepoPath, e.runtime.UID, "result.txt"}, "/") - - // 生成请求body内容 - file, err := ioutil.ReadFile(e.ResultFilePath) - if err != nil { - e.runtime.Logger.Error("get result file content fail, error:%s", err) - return fmt.Errorf("get result file content fail, error:%s", err) - } - - // 生成请求 - request, err := http.NewRequest("PUT", url, strings.NewReader(string(file))) - if err != nil { - e.runtime.Logger.Error("create request for uploading result file fail, error:%s", err) - return fmt.Errorf("create request for uploading result file fail, error:%s", err) - } - - // 设置请求头 - auth := base64.StdEncoding.EncodeToString([]byte(strings.Join([]string{e.ConfParams.RepoUsername, - e.ConfParams.RepoToken}, ":"))) - request.Header.Set("Authorization", "Basic "+auth) - request.Header.Set("X-BKREPO-EXPIRES", "30") - request.Header.Set("X-BKREPO-OVERWRITE", "true") - request.Header.Set("Content-Type", "multipart/form-data") - if err != nil { - e.runtime.Logger.Error("set request head for uploading result file fail, error:%s", err) - return fmt.Errorf("set request head for uploading result file fail, error:%s", err) - } - - // 执行请求 - response, err := http.DefaultClient.Do(request) - defer response.Body.Close() - if err != nil { - e.runtime.Logger.Error("request server for uploading result file fail, error:%s", err) - return fmt.Errorf("request server for uploading result file fail, error:%s", err) - } - - // 解析响应 - resp, err := ioutil.ReadAll(response.Body) - if err != nil { - e.runtime.Logger.Error("read data from response fail, error:%s", err) - return fmt.Errorf("read data from response fail, error:%s", err) - } - output := Output{} - _ = json.Unmarshal(resp, &output) - if output.Code != 0 && output.Message == "" { - e.runtime.Logger.Error("upload file fail, error:%s", output.Message) - return fmt.Errorf("upload file fail, error:%s", output.Message) - } - e.runtime.Logger.Info("upload result file successfully") - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go deleted file mode 100644 index 220687a5ac..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_process_restart.go +++ /dev/null @@ -1,399 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strconv" - "strings" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - - "github.com/go-playground/validator/v10" - "gopkg.in/yaml.v2" -) - -// RestartConfParams 重启进程参数 -type RestartConfParams struct { - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - InstanceType string `json:"instanceType" validate:"required"` // mongos mongod - SingleNodeInstallRestart bool `json:"singleNodeInstallRestart"` // mongod替换节点安装后重启 - Auth bool `json:"auth"` // true->auth false->noauth - CacheSizeGB int `json:"cacheSizeGB"` // 可选,重启mongod的参数 - MongoSConfDbOld string `json:"mongoSConfDbOld"` // 可选,ip:port - MongoSConfDbNew string `json:"MongoSConfDbNew"` // 可选,ip:port - AdminUsername string `json:"adminUsername"` - AdminPassword string `json:"adminPassword"` -} - -// MongoRestart 重启mongo进程 -type MongoRestart struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - DataDir string - DbpathDir string - Mongo string - OsUser string // MongoDB安装在哪个用户下 - OsGroup string - ConfParams *RestartConfParams - AuthConfFilePath string - NoAuthConfFilePath string -} - -// NewMongoRestart 实例化结构体 -func NewMongoRestart() jobruntime.JobRunner { - return &MongoRestart{} -} - -// Name 获取原子任务的名字 -func (r *MongoRestart) Name() string { - return "mongo_restart" -} - -// Run 运行原子任务 -func (r *MongoRestart) Run() error { - // 修改配置文件参数 - if err := r.changeParam(); err != nil { - return err - } - - // mongod的primary进行主备切换 - if err := r.RsStepDown(); err != nil { - return err - } - - // 关闭服务 - if err := r.shutdown(); err != nil { - return err - } - - // 启动服务 - if err := r.startup(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (r *MongoRestart) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (r *MongoRestart) Rollback() error { - return nil -} - -// Init 初始化 -func (r *MongoRestart) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - r.runtime = runtime - r.runtime.Logger.Info("start to init") - r.BinDir = consts.UsrLocal - r.DataDir = consts.GetRedisDataDir() - r.OsUser = consts.GetProcessUser() - r.OsGroup = consts.GetProcessUserGroup() - r.Mongo = filepath.Join(r.BinDir, "mongodb", "bin", "mongo") - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(r.runtime.PayloadDecoded), &r.ConfParams); err != nil { - r.runtime.Logger.Error(fmt.Sprintf( - "get parameters of mongo restart fail by json.Unmarshal, error:%s", err)) - return fmt.Errorf("get parameters of mongo restart fail by json.Unmarshal, error:%s", err) - } - - // 设置各种路径 - strPort := strconv.Itoa(r.ConfParams.Port) - r.DbpathDir = filepath.Join(r.DataDir, "mongodata", strPort, "db") - r.AuthConfFilePath = filepath.Join(r.DataDir, "mongodata", strPort, "mongo.conf") - r.NoAuthConfFilePath = filepath.Join(r.DataDir, "mongodata", strPort, "noauth.conf") - r.runtime.Logger.Info("init successfully") - - // 安装前进行校验 - if err := r.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (r *MongoRestart) checkParams() error { - // 校验重启配置参数 - validate := validator.New() - r.runtime.Logger.Info("start to validate parameters of restart") - if err := validate.Struct(r.ConfParams); err != nil { - r.runtime.Logger.Error(fmt.Sprintf("validate parameters of restart fail, error:%s", err)) - return fmt.Errorf("validate parameters of restart fail, error:%s", err) - } - r.runtime.Logger.Info("validate parameters of restart successfully") - return nil -} - -// changeParam 修改参数 -func (r *MongoRestart) changeParam() error { - if r.ConfParams.InstanceType == "mongos" && - r.ConfParams.MongoSConfDbOld != "" && r.ConfParams.MongoSConfDbNew != "" { - if err := r.changeConfigDb(); err != nil { - return err - } - return nil - } - if err := r.changeCacheSizeGB(); err != nil { - return err - } - return nil -} - -// changeConfigDb 修改mongoS的ConfigDb参数 -func (r *MongoRestart) changeConfigDb() error { - r.runtime.Logger.Info("start to change configDB value of config file") - // 获取配置文件内容 - readAuthConfFileContent, _ := ioutil.ReadFile(r.AuthConfFilePath) - readNoAuthConfFileContent, _ := ioutil.ReadFile(r.NoAuthConfFilePath) - - // 修改configDB配置 - yamlAuthMongoSConf := common.NewYamlMongoSConf() - yamlNoAuthMongoSConf := common.NewYamlMongoSConf() - _ = yaml.Unmarshal(readAuthConfFileContent, yamlAuthMongoSConf) - _ = yaml.Unmarshal(readNoAuthConfFileContent, yamlNoAuthMongoSConf) - yamlAuthMongoSConf.Sharding.ConfigDB = strings.Replace(yamlAuthMongoSConf.Sharding.ConfigDB, - r.ConfParams.MongoSConfDbOld, r.ConfParams.MongoSConfDbNew, -1) - yamlNoAuthMongoSConf.Sharding.ConfigDB = strings.Replace(yamlNoAuthMongoSConf.Sharding.ConfigDB, - r.ConfParams.MongoSConfDbOld, r.ConfParams.MongoSConfDbNew, -1) - authConfFileContent, _ := yamlAuthMongoSConf.GetConfContent() - noAuthConfFileContent, _ := yamlNoAuthMongoSConf.GetConfContent() - - // 修改authConfFile - authConfFile, err := os.OpenFile(r.AuthConfFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, DefaultPerm) - defer authConfFile.Close() - if err != nil { - r.runtime.Logger.Error( - fmt.Sprintf("create auth config file fail, error:%s", err)) - return fmt.Errorf("create auth config file fail, error:%s", err) - } - if _, err = authConfFile.WriteString(string(authConfFileContent)); err != nil { - r.runtime.Logger.Error( - fmt.Sprintf("change configDB value of auth config file write content fail, error:%s", - err)) - return fmt.Errorf("change configDB value of auth config file write content fail, error:%s", - err) - } - - // 修改noAuthConfFile - noAuthConfFile, err := os.OpenFile(r.NoAuthConfFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, DefaultPerm) - defer noAuthConfFile.Close() - if err != nil { - r.runtime.Logger.Error(fmt.Sprintf("create no auth config file fail, error:%s", err)) - return fmt.Errorf("create no auth config file fail, error:%s", err) - } - if _, err = noAuthConfFile.WriteString(string(noAuthConfFileContent)); err != nil { - r.runtime.Logger.Error( - fmt.Sprintf("change configDB value of no auth config file write content fail, error:%s", - err)) - return fmt.Errorf("change configDB value of no auth config file write content fail, error:%s", - err) - } - r.runtime.Logger.Info("change configDB value of config file successfully") - - return nil -} - -// changeCacheSizeGB 修改CacheSizeGB -func (r *MongoRestart) changeCacheSizeGB() error { - if r.ConfParams.CacheSizeGB == 0 { - return nil - } - - // 检查mongo版本 - r.runtime.Logger.Info("start to check mongo version") - version, err := common.CheckMongoVersion(r.BinDir, "mongod") - if err != nil { - r.runtime.Logger.Error(fmt.Sprintf("check mongo version fail, error:%s", err)) - return fmt.Errorf("check mongo version fail, error:%s", err) - } - mainVersion, _ := strconv.Atoi(strings.Split(version, ".")[0]) - r.runtime.Logger.Info("check mongo version successfully") - - if mainVersion >= 3 { - r.runtime.Logger.Info("start to change CacheSizeGB value of config file") - // 获取配置文件内容 - readAuthConfFileContent, _ := ioutil.ReadFile(r.AuthConfFilePath) - readNoAuthConfFileContent, _ := ioutil.ReadFile(r.NoAuthConfFilePath) - - // 修改CacheSizeGB大小并写入文件 - yamlAuthConfFile := common.NewYamlMongoDBConf() - yamlNoAuthConfFile := common.NewYamlMongoDBConf() - _ = yaml.Unmarshal(readAuthConfFileContent, &yamlAuthConfFile) - _ = yaml.Unmarshal(readNoAuthConfFileContent, &yamlNoAuthConfFile) - if r.ConfParams.CacheSizeGB == 0 { - return nil - } - if r.ConfParams.CacheSizeGB != yamlAuthConfFile.Storage.WiredTiger.EngineConfig.CacheSizeGB { - yamlAuthConfFile.Storage.WiredTiger.EngineConfig.CacheSizeGB = r.ConfParams.CacheSizeGB - yamlNoAuthConfFile.Storage.WiredTiger.EngineConfig.CacheSizeGB = r.ConfParams.CacheSizeGB - authConfFileContent, _ := yamlAuthConfFile.GetConfContent() - noAuthConfFileContent, _ := yamlNoAuthConfFile.GetConfContent() - - // 修改authConfFile - authConfFile, err := os.OpenFile(r.AuthConfFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, DefaultPerm) - defer authConfFile.Close() - if err != nil { - r.runtime.Logger.Error( - fmt.Sprintf("create auth config file fail, error:%s", err)) - return fmt.Errorf("create auth config file fail, error:%s", err) - } - if _, err = authConfFile.WriteString(string(authConfFileContent)); err != nil { - r.runtime.Logger.Error( - fmt.Sprintf("change CacheSizeGB value of auth config file write content fail, error:%s", - err)) - return fmt.Errorf("change CacheSizeGB value of auth config file write content fail, error:%s", - err) - } - - // 修改noAuthConfFile - noAuthConfFile, err := os.OpenFile(r.NoAuthConfFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, DefaultPerm) - defer noAuthConfFile.Close() - if err != nil { - r.runtime.Logger.Error(fmt.Sprintf("create no auth config file fail, error:%s", err)) - return fmt.Errorf("create no auth config file fail, error:%s", err) - } - if _, err = noAuthConfFile.WriteString(string(noAuthConfFileContent)); err != nil { - r.runtime.Logger.Error( - fmt.Sprintf("change CacheSizeGB value of no auth config file write content fail, error:%s", - err)) - return fmt.Errorf("change CacheSizeGB value of no auth config file write content fail, error:%s", - err) - } - } - r.runtime.Logger.Info("change CacheSizeGB value of config file successfully") - } - return nil -} - -// checkPrimary 检查该节点是否是primary -func (r *MongoRestart) checkPrimary() (bool, error) { - r.runtime.Logger.Info("start to check if it is primary") - var info string - var err error - // 安装时无需密码验证。安装成功后需要密码验证 - if r.ConfParams.AdminUsername != "" && r.ConfParams.AdminPassword != "" { - info, err = common.AuthGetPrimaryInfo(r.OsUser, r.Mongo, r.ConfParams.AdminUsername, - r.ConfParams.AdminPassword, r.ConfParams.IP, r.ConfParams.Port) - } else { - info, err = common.NoAuthGetPrimaryInfo(r.OsUser, r.Mongo, - r.ConfParams.IP, r.ConfParams.Port) - } - if err != nil { - r.runtime.Logger.Error("get primary info fail, error:%s", err) - return false, fmt.Errorf("get primary info fail, error:%s", err) - } - if info == fmt.Sprintf("%s:%d", r.ConfParams.IP, r.ConfParams.Port) { - return true, nil - } - r.runtime.Logger.Info("check if it is primary successfully") - return false, nil -} - -// RsStepDown 主备切换 -func (r *MongoRestart) RsStepDown() error { - if r.ConfParams.InstanceType != "mongos" { - if r.ConfParams.SingleNodeInstallRestart == true { - return nil - } - r.runtime.Logger.Info("start to check mongod service before rsStepDown") - flag, _, err := common.CheckMongoService(r.ConfParams.Port) - if err != nil { - r.runtime.Logger.Error("check mongod service fail, error:%s", err) - return fmt.Errorf("check mongod service fail, error:%s", err) - } - r.runtime.Logger.Info("check mongod service before rsStepDown successfully") - if flag == false { - return nil - } - - // 检查是否是primary - flag1, err := r.checkPrimary() - if err != nil { - return err - } - if flag1 == true { - r.runtime.Logger.Info("start to convert primary secondary db") - // 安装时无需密码验证。安装成功后需要密码验证 - var flag2 bool - if r.ConfParams.AdminUsername != "" && r.ConfParams.AdminPassword != "" { - flag2, err = common.AuthRsStepDown(r.OsUser, r.Mongo, r.ConfParams.IP, r.ConfParams.Port, - r.ConfParams.AdminUsername, r.ConfParams.AdminPassword) - } else { - flag2, err = common.NoAuthRsStepDown(r.OsUser, r.Mongo, r.ConfParams.IP, r.ConfParams.Port) - } - if err != nil { - r.runtime.Logger.Error("convert primary secondary db fail, error:%s", err) - return fmt.Errorf("convert primary secondary db fail, error:%s", err) - } - if flag2 == true { - r.runtime.Logger.Info("convert primary secondary db successfully") - return nil - } - } - } - - return nil -} - -// shutdown 关闭服务 -func (r *MongoRestart) shutdown() error { - // 检查服务是否存在 - r.runtime.Logger.Info("start to check %s service", r.ConfParams.InstanceType) - result, _, err := common.CheckMongoService(r.ConfParams.Port) - if err != nil { - r.runtime.Logger.Error("check %s service fail, error:%s", r.ConfParams.InstanceType, err) - return fmt.Errorf("check %s service fail, error:%s", r.ConfParams.InstanceType, err) - } - if result != true { - r.runtime.Logger.Info("%s service has been close", r.ConfParams.InstanceType) - return nil - } - r.runtime.Logger.Info("check %s service successfully", r.ConfParams.InstanceType) - - // 关闭服务 - r.runtime.Logger.Info("start to shutdown %s", r.ConfParams.InstanceType) - if err = common.ShutdownMongoProcess(r.OsUser, r.ConfParams.InstanceType, r.BinDir, r.DbpathDir, - r.ConfParams.Port); err != nil { - r.runtime.Logger.Error(fmt.Sprintf("shutdown %s fail, error:%s", r.ConfParams.InstanceType, err)) - return fmt.Errorf("shutdown %s fail, error:%s", r.ConfParams.InstanceType, err) - } - r.runtime.Logger.Info("shutdown %s successfully", r.ConfParams.InstanceType) - return nil -} - -// startup 开启服务 -func (r *MongoRestart) startup() error { - // 检查服务是否存在 - r.runtime.Logger.Info("start to check %s service", r.ConfParams.InstanceType) - result, _, err := common.CheckMongoService(r.ConfParams.Port) - if err != nil { - r.runtime.Logger.Error("check %s service fail, error:%s", r.ConfParams.InstanceType, err) - return fmt.Errorf("check %s service fail, error:%s", r.ConfParams.InstanceType, err) - } - if result == true { - r.runtime.Logger.Info("%s service has been open", r.ConfParams.InstanceType) - return nil - } - r.runtime.Logger.Info("check %s service successfully", r.ConfParams.InstanceType) - - // 开启服务 - r.runtime.Logger.Info("start to startup %s", r.ConfParams.InstanceType) - if err = common.StartMongoProcess(r.BinDir, r.ConfParams.Port, r.OsUser, r.ConfParams.Auth); err != nil { - r.runtime.Logger.Error("startup %s fail, error:%s", r.ConfParams.InstanceType, err) - return fmt.Errorf("startup %s fail, error:%s", r.ConfParams.InstanceType, err) - } - r.runtime.Logger.Info("startup %s successfully", r.ConfParams.InstanceType) - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go deleted file mode 100644 index 4094831552..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongo_set_profiler.go +++ /dev/null @@ -1,186 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "path/filepath" - "strconv" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// SetProfilerConfParams 参数 -type SetProfilerConfParams struct { - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - DbName string `json:"dbName" validate:"required"` - Level int `json:"level" validate:"required"` - ProfileSize int `json:"profileSize"` // 单位:GB - AdminUsername string `json:"adminUsername" validate:"required"` - AdminPassword string `json:"adminPassword" validate:"required"` -} - -// SetProfiler 添加分片到集群 -type SetProfiler struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - Mongo string - OsUser string - PrimaryIP string - PrimaryPort int - ConfParams *SetProfilerConfParams -} - -// NewSetProfiler 实例化结构体 -func NewSetProfiler() jobruntime.JobRunner { - return &SetProfiler{} -} - -// Name 获取原子任务的名字 -func (s *SetProfiler) Name() string { - return "mongo_set_profiler" -} - -// Run 运行原子任务 -func (s *SetProfiler) Run() error { - // 生成script内容 - if err := s.setProfileSize(); err != nil { - return err - } - - // 执行脚本生成结果文件 - if err := s.setProfileLevel(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (s *SetProfiler) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (s *SetProfiler) Rollback() error { - return nil -} - -// Init 初始化 -func (s *SetProfiler) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - s.runtime = runtime - s.runtime.Logger.Info("start to init") - s.BinDir = consts.UsrLocal - s.OsUser = consts.GetProcessUser() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(s.runtime.PayloadDecoded), &s.ConfParams); err != nil { - s.runtime.Logger.Error( - "get parameters of setProfiler fail by json.Unmarshal, error:%s", err) - return fmt.Errorf("get parameters of setProfiler fail by json.Unmarshal, error:%s", err) - } - - // 获取primary信息 - info, err := common.AuthGetPrimaryInfo(s.OsUser, s.Mongo, s.ConfParams.AdminUsername, s.ConfParams.AdminPassword, - s.ConfParams.IP, s.ConfParams.Port) - if err != nil { - s.runtime.Logger.Error("get primary db info fail, error:%s", err) - return fmt.Errorf("get primary db info fail, error:%s", err) - } - sliceInfo := strings.Split(info, ":") - s.PrimaryIP = sliceInfo[0] - s.PrimaryPort, _ = strconv.Atoi(sliceInfo[1]) - - // 获取各种目录 - s.Mongo = filepath.Join(s.BinDir, "mongodb", "bin", "mongo") - s.runtime.Logger.Info("init successfully") - - // 进行校验 - if err = s.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (s *SetProfiler) checkParams() error { - // 校验配置参数 - s.runtime.Logger.Info("start to validate parameters") - validate := validator.New() - s.runtime.Logger.Info("start to validate parameters of deInstall") - if err := validate.Struct(s.ConfParams); err != nil { - s.runtime.Logger.Error("validate parameters of setProfiler fail, error:%s", err) - return fmt.Errorf("validate parameters of setProfiler fail, error:%s", err) - } - s.runtime.Logger.Info("validate parameters successfully") - return nil -} - -// setProfileSize 设置profile大小 -func (s *SetProfiler) setProfileSize() error { - // 获取profile级别 - status, err := common.GetProfilingLevel(s.OsUser, s.Mongo, s.ConfParams.IP, s.ConfParams.Port, - s.ConfParams.AdminUsername, s.ConfParams.AdminPassword, s.ConfParams.DbName) - if err != nil { - s.runtime.Logger.Error("get profile level fail, error:%s", err) - return fmt.Errorf("get profile level fail, error:%s", err) - } - if status != 0 { - if err = common.SetProfilingLevel(s.OsUser, s.Mongo, s.ConfParams.IP, s.ConfParams.Port, s.ConfParams.AdminUsername, - s.ConfParams.AdminPassword, s.ConfParams.DbName, 0); err != nil { - s.runtime.Logger.Error("set profile level 0 fail, error:%s", err) - return fmt.Errorf("set profile level 0 fail, error:%s", err) - } - } - - // 删除profile.system - cmd := fmt.Sprintf( - "su %s \"%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet --eval \\\"db.getMongo().getDB('%s').system.profile.drop()\\\"\"", - s.OsUser, s.Mongo, s.ConfParams.AdminUsername, s.ConfParams.AdminPassword, s.ConfParams.IP, s.ConfParams.Port, - s.ConfParams.DbName) - if _, err = util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - s.runtime.Logger.Error("delete system.profile fail, error:%s", err) - return fmt.Errorf("set system.profile fail, error:%s", err) - } - - // 设置profile.system - s.runtime.Logger.Info("start to set system.profile size") - profileSizeBytes := s.ConfParams.ProfileSize * 1024 * 1024 * 1024 - cmd = fmt.Sprintf( - "su %s \"%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet --eval \\\"db.getMongo().getDB('%s').createCollection('system.profile',{ capped: true, size:%d })\\\"\"", - s.OsUser, s.Mongo, s.ConfParams.AdminUsername, s.ConfParams.AdminPassword, s.ConfParams.IP, s.ConfParams.Port, - s.ConfParams.DbName, profileSizeBytes) - if _, err = util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - s.runtime.Logger.Error("set system.profile size fail, error:%s", err) - return fmt.Errorf("set system.profile size fail, error:%s", err) - } - s.runtime.Logger.Info("set system.profile size successfully") - return nil -} - -// setProfileLevel 生成脚本内容 -func (s *SetProfiler) setProfileLevel() error { - s.runtime.Logger.Info("start to set profile level") - if err := common.SetProfilingLevel(s.OsUser, s.Mongo, s.ConfParams.IP, s.ConfParams.Port, s.ConfParams.AdminUsername, - s.ConfParams.AdminPassword, s.ConfParams.DbName, s.ConfParams.Level); err != nil { - s.runtime.Logger.Error("set profile level fail, error:%s", err) - return fmt.Errorf("set profile level fail, error:%s", err) - } - s.runtime.Logger.Info("set profile level successfully") - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go deleted file mode 100644 index 921822ffc8..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_install.go +++ /dev/null @@ -1,492 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "path/filepath" - "strconv" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -/* - -1.预检查 -检查输入的参数 检查端口是否合规 检查安装包 检查端口是否被使用(如果使用,则检查是否是mongodb服务) - -2.解压安装包 判断是否已经解压过,版本是否正确 -解压文件 做软链接 修改文件属主 - -3.安装 判断目录是否已被创建 -创建相关各级目录-判断目录是否已经创建过 修改目录属主 创建配置文件(noauth, auth) 创建dbtype文件 复制集创建key文件 - -4.启动服务 -以noauth启动服务 - -*/ - -// MongoDBPortMin MongoDB最小端口 -const MongoDBPortMin = 27000 - -// MongoDBPortMax MongoDB最大端口 -const MongoDBPortMax = 27230 - -// DefaultPerm 创建目录、文件的默认权限 -const DefaultPerm = 0755 - -// MongoDBConfParams 配置文件参数 -type MongoDBConfParams struct { - common.MediaPkg `json:"mediapkg"` - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - DbVersion string `json:"dbVersion" validate:"required"` - InstanceType string `json:"instanceType" validate:"required"` // mongos mongod - App string `json:"app" validate:"required"` - AreaId string `json:"areaId" validate:"required"` - SetId string `json:"setId" validate:"required"` - Auth bool `json:"auth"` // true:以验证方式启动mongod false:以非验证方式启动mongod - ClusterRole string `json:"clusterRole"` // 部署cluster时填写,shardsvr configsvr;部署复制集时为空 - DbConfig struct { - SlowOpThresholdMs int `json:"slowOpThresholdMs"` - CacheSizeGB int `json:"cacheSizeGB"` - OplogSizeMB int `json:"oplogSizeMB" validate:"required"` - Destination string `json:"destination"` - } `json:"dbConfig" validate:"required"` -} - -// MongoDBInstall MongoDB安装 -type MongoDBInstall struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - BackupDir string - DataDir string - OsUser string // MongoDB安装在哪个用户下 - OsGroup string - ConfParams *MongoDBConfParams - DbpathDir string - BackupPath string - AuthConfFilePath string - AuthConfFileContent []byte - NoAuthConfFilePath string - NoAuthConfFileContent []byte - DbTypeFilePath string - LogPath string - PidFilePath string - KeyFilePath string - InstallPackagePath string - LockFilePath string // 锁文件路径 -} - -// NewMongoDBInstall 实例化结构体 -func NewMongoDBInstall() jobruntime.JobRunner { - return &MongoDBInstall{} -} - -// Name 获取原子任务的名字 -func (m *MongoDBInstall) Name() string { - return "mongod_install" -} - -// Run 运行原子任务 -func (m *MongoDBInstall) Run() error { - // 进行校验 - status, err := m.checkParams() - if err != nil { - return err - } - if status { - return nil - } - - // 解压安装包并修改属主 - if err = m.unTarAndCreateSoftLink(); err != nil { - return err - } - - // 创建目录并修改属主 - if err = m.mkdir(); err != nil { - return err - } - - // 创建配置文件,key文件并修改属主 - if err = m.createConfFileAndKeyFileAndDbTypeFile(); err != nil { - return err - } - - // 启动服务 - if err = m.startup(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (m *MongoDBInstall) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (m *MongoDBInstall) Rollback() error { - return nil -} - -// Init 初始化 -func (m *MongoDBInstall) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - m.runtime = runtime - m.runtime.Logger.Info("start to init") - m.BinDir = consts.UsrLocal - m.BackupDir = consts.GetMongoBackupDir() - m.DataDir = consts.GetMongoDataDir() - m.OsUser = consts.GetProcessUser() - m.OsGroup = consts.GetProcessUserGroup() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(m.runtime.PayloadDecoded), &m.ConfParams); err != nil { - m.runtime.Logger.Error(fmt.Sprintf( - "get parameters of mongodb config file fail by json.Unmarshal, error:%s", err)) - return fmt.Errorf("get parameters of mongodb config file fail by json.Unmarshal, error:%s", err) - } - - // 获取信息 - m.InstallPackagePath = m.ConfParams.MediaPkg.GetAbsolutePath() - - // 设置各种路径 - strPort := strconv.Itoa(m.ConfParams.Port) - m.DbpathDir = filepath.Join(m.DataDir, "mongodata", strPort, "db") - m.BackupPath = filepath.Join(m.BackupDir, "dbbak") - m.AuthConfFilePath = filepath.Join(m.DataDir, "mongodata", strPort, "mongo.conf") - m.NoAuthConfFilePath = filepath.Join(m.DataDir, "mongodata", strPort, "noauth.conf") - m.LogPath = filepath.Join(m.BackupDir, "mongolog", strPort, "mongo.log") - PidFileName := fmt.Sprintf("pid.%s", strPort) - m.PidFilePath = filepath.Join(m.DataDir, "mongodata", strPort, PidFileName) - m.KeyFilePath = filepath.Join(m.DataDir, "mongodata", strPort, "key_of_mongo") - m.DbTypeFilePath = filepath.Join(m.DataDir, "mongodata", strPort, "dbtype") - m.LockFilePath = filepath.Join(m.DataDir, "mongoinstall.lock") - - m.runtime.Logger.Info("init successfully") - - // 生成配置文件内容 - if err := m.makeConfContent(); err != nil { - return err - } - - return nil -} - -// makeConfContent 生成配置文件内容 -func (m *MongoDBInstall) makeConfContent() error { - mainVersion, err := strconv.Atoi(strings.Split(m.ConfParams.DbVersion, ".")[0]) - if err != nil { - return err - } - - // mongodb 3.0及以上得到配置文件内容 - if mainVersion >= 3 { - m.runtime.Logger.Info("start to make mongodb config file content") - conf := common.NewYamlMongoDBConf() - conf.Storage.DbPath = m.DbpathDir - conf.Storage.Engine = "wiredTiger" - conf.Storage.WiredTiger.EngineConfig.CacheSizeGB = m.ConfParams.DbConfig.CacheSizeGB - conf.Replication.OplogSizeMB = m.ConfParams.DbConfig.OplogSizeMB - conf.Replication.ReplSetName = strings.Join([]string{m.ConfParams.App, m.ConfParams.AreaId, m.ConfParams.SetId}, - "-") - conf.SystemLog.LogAppend = true - conf.SystemLog.Path = m.LogPath - conf.SystemLog.Destination = m.ConfParams.DbConfig.Destination - conf.ProcessManagement.Fork = true - conf.ProcessManagement.PidFilePath = m.PidFilePath - conf.Net.Port = m.ConfParams.Port - conf.Net.BindIp = strings.Join([]string{"127.0.0.1", m.ConfParams.IP}, ",") - conf.Net.WireObjectCheck = false - conf.OperationProfiling.SlowOpThresholdMs = m.ConfParams.DbConfig.SlowOpThresholdMs - conf.Sharding.ClusterRole = m.ConfParams.ClusterRole - // 获取非验证配置文件内容 - m.NoAuthConfFileContent, err = conf.GetConfContent() - if err != nil { - m.runtime.Logger.Error(fmt.Sprintf( - "version:%s make mongodb no auth config file content fail, error:%s", m.ConfParams.DbVersion, err)) - return fmt.Errorf("version:%s make mongodb no auth config file content fail, error:%s", - m.ConfParams.DbVersion, err) - } - conf.Security.KeyFile = m.KeyFilePath - // 获取验证配置文件内容 - m.AuthConfFileContent, err = conf.GetConfContent() - if err != nil { - m.runtime.Logger.Error(fmt.Sprintf( - "version:%s make mongodb auth config file content fail, error:%s", - m.ConfParams.DbVersion, err)) - return fmt.Errorf("version:%s make mongodb auth config file content fail, error:%s", - m.ConfParams.DbVersion, err) - } - m.runtime.Logger.Info("make mongodb config file content successfully") - return nil - } - - // mongodb 3.0以下获取配置文件内容 - // 获取非验证配置文件内容 - m.runtime.Logger.Info("start to make mongodb config file content") - NoAuthConf := common.IniNoAuthMongoDBConf - AuthConf := common.IniAuthMongoDBConf - replSet := strings.Join([]string{m.ConfParams.App, m.ConfParams.AreaId, m.ConfParams.SetId}, - "-") - NoAuthConf = strings.Replace(NoAuthConf, "{{replSet}}", replSet, -1) - AuthConf = strings.Replace(AuthConf, "{{replSet}}", replSet, -1) - NoAuthConf = strings.Replace(NoAuthConf, "{{dbpath}}", m.DbpathDir, -1) - AuthConf = strings.Replace(AuthConf, "{{dbpath}}", m.DbpathDir, -1) - NoAuthConf = strings.Replace(NoAuthConf, "{{logpath}}", m.LogPath, -1) - AuthConf = strings.Replace(AuthConf, "{{logpath}}", m.LogPath, -1) - NoAuthConf = strings.Replace(NoAuthConf, "{{pidfilepath}}", m.PidFilePath, -1) - AuthConf = strings.Replace(AuthConf, "{{pidfilepath}}", m.PidFilePath, -1) - strPort := strconv.Itoa(m.ConfParams.Port) - NoAuthConf = strings.Replace(NoAuthConf, "{{port}}", strPort, -1) - AuthConf = strings.Replace(AuthConf, "{{port}}", strPort, -1) - bindIP := strings.Join([]string{"127.0.0.1", m.ConfParams.IP}, ",") - NoAuthConf = strings.Replace(NoAuthConf, "{{bind_ip}}", bindIP, -1) - AuthConf = strings.Replace(AuthConf, "{{bind_ip}}", bindIP, -1) - strOplogSize := strconv.Itoa(m.ConfParams.DbConfig.OplogSizeMB) - NoAuthConf = strings.Replace(NoAuthConf, "{{oplogSize}}", strOplogSize, -1) - AuthConf = strings.Replace(AuthConf, "{{oplogSize}}", strOplogSize, -1) - NoAuthConf = strings.Replace(NoAuthConf, "{{instanceRole}}", m.ConfParams.ClusterRole, -1) - AuthConf = strings.Replace(AuthConf, "{{instanceRole}}", m.ConfParams.ClusterRole, -1) - AuthConf = strings.Replace(AuthConf, "{{keyFile}}", m.KeyFilePath, -1) - m.NoAuthConfFileContent = []byte(NoAuthConf) - m.AuthConfFileContent = []byte(AuthConf) - m.runtime.Logger.Info("make mongodb config file content successfully") - - return nil -} - -// checkParams 校验参数 检查输入的参数 检查端口是否合规 检查安装包 检查端口是否被使用(如果使用,则检查是否是mongodb服务) -func (m *MongoDBInstall) checkParams() (bool, error) { - // 校验MongoDB配置文件 - m.runtime.Logger.Info("start to validate parameters") - validate := validator.New() - m.runtime.Logger.Info("start to validate parameters of mongodb config file") - if err := validate.Struct(m.ConfParams); err != nil { - m.runtime.Logger.Error(fmt.Sprintf("validate parameters of mongodb config file fail, error:%s", err)) - return false, fmt.Errorf("validate parameters of mongodb config file fail, error:%s", err) - } - // 校验port是否合规 - m.runtime.Logger.Info("start to validate port if it is correct") - if m.ConfParams.Port < MongoDBPortMin || m.ConfParams.Port > MongoDBPortMax { - m.runtime.Logger.Error(fmt.Sprintf( - "validate port if it is correct, port is not within defalut range [%d,%d]", - MongoDBPortMin, MongoDBPortMax)) - return false, fmt.Errorf("validate port if it is correct, port is not within defalut range [%d,%d]", - MongoDBPortMin, MongoDBPortMax) - } - - // 校验安装包是否存在,md5值是否一致 - m.runtime.Logger.Info("start to validate install package") - if flag := util.FileExists(m.InstallPackagePath); !flag { - m.runtime.Logger.Error(fmt.Sprintf("validate install package, %s is not existed", - m.InstallPackagePath)) - return false, fmt.Errorf("validate install file, %s is not existed", - m.InstallPackagePath) - } - md5, _ := util.GetFileMd5(m.InstallPackagePath) - if m.ConfParams.MediaPkg.PkgMd5 != md5 { - m.runtime.Logger.Error(fmt.Sprintf("validate install package md5 fail, md5 is incorrect")) - return false, fmt.Errorf("validate install package md5 fail, md5 is incorrect") - } - - // 校验端口是否使用 - m.runtime.Logger.Info("start to validate port if it has been used") - flag, _ := util.CheckPortIsInUse(m.ConfParams.IP, strconv.Itoa(m.ConfParams.Port)) - if flag { - // 校验端口是否是mongod进程 - cmd := fmt.Sprintf("netstat -ntpl |grep %d | awk '{print $7}' |head -1", m.ConfParams.Port) - result, _ := util.RunBashCmd(cmd, "", nil, 10*time.Second) - if strings.Contains(result, "mongod") { - // 检查配置文件是否一致,读取已有配置文件与新生成的配置文件内容对比 - content, _ := ioutil.ReadFile(m.AuthConfFilePath) - if strings.Compare(string(content), string(m.AuthConfFileContent)) == 0 { - // 检查mongod版本 - version, err := common.CheckMongoVersion(m.BinDir, "mongod") - if err != nil { - m.runtime.Logger.Error( - fmt.Sprintf("mongod has been installed, port:%d, check mongod version fail. error:%s", - m.ConfParams.Port, version)) - return false, fmt.Errorf("mongod has been installed, port:%d, check mongod version fail. error:%s", - m.ConfParams.Port, version) - } - if version == m.ConfParams.DbVersion { - m.runtime.Logger.Info(fmt.Sprintf("mongod has been installed, port:%d, version:%s", - m.ConfParams.Port, version)) - return true, nil - } - m.runtime.Logger.Error(fmt.Sprintf("other mongod has been installed, port:%d, version:%s", - m.ConfParams.Port, version)) - return false, fmt.Errorf("other mongod has been installed, port:%d, version:%s", - m.ConfParams.Port, version) - } - - } - m.runtime.Logger.Error( - fmt.Sprintf("validate port if it has been used, port:%d is used by other process", - m.ConfParams.Port)) - return false, fmt.Errorf("validate port if it has been used, port:%d is used by other process", - m.ConfParams.Port) - } - m.runtime.Logger.Info("validate parameters successfully") - return false, nil -} - -// unTarAndCreateSoftLink 解压安装包,创建软链接并给目录授权 -func (m *MongoDBInstall) unTarAndCreateSoftLink() error { - // 解压目录 - unTarPath := filepath.Join(m.BinDir, m.ConfParams.MediaPkg.GePkgBaseName()) - - // soft link目录 - installPath := filepath.Join(m.BinDir, "mongodb") - - // 解压安装包并授权 - // 安装多实例并发执行添加文件锁 - m.runtime.Logger.Info("start to get install file lock") - fileLock := common.NewFileLock(m.LockFilePath) - // 获取锁 - err := fileLock.Lock() - if err != nil { - for { - err = fileLock.Lock() - if err != nil { - time.Sleep(1 * time.Second) - continue - } - m.runtime.Logger.Info("get install file lock successfully") - break - } - } else { - m.runtime.Logger.Info("get install file lock successfully") - } - - if err = common.UnTarAndCreateSoftLinkAndChown(m.runtime, m.BinDir, - m.InstallPackagePath, unTarPath, installPath, m.OsUser, m.OsGroup); err != nil { - return err - } - // 释放锁 - _ = fileLock.UnLock() - m.runtime.Logger.Info("release install file lock successfully") - - // 检查mongod版本 - m.runtime.Logger.Info("start to check mongod version") - version, err := common.CheckMongoVersion(m.BinDir, "mongod") - if err != nil { - m.runtime.Logger.Error(fmt.Sprintf("%s has been existed, check mongodb version, error:%s", - installPath, err)) - return fmt.Errorf("%s has been existed, check mongodb version, error:%s", - installPath, err) - } - if version != m.ConfParams.DbVersion { - m.runtime.Logger.Error( - fmt.Sprintf("%s has been existed, check mongodb version, version:%s is incorrect", - installPath, version)) - return fmt.Errorf("%s has been existed, check mongodb version, version:%s is incorrect", - installPath, version) - } - m.runtime.Logger.Info("check mongod version successfully") - return nil -} - -// mkdir 创建相关目录并给目录授权 -func (m *MongoDBInstall) mkdir() error { - // 创建日志文件目录 - logPathDir, _ := filepath.Split(m.LogPath) - m.runtime.Logger.Info("start to create log directory") - if err := util.MkDirsIfNotExistsWithPerm([]string{logPathDir}, DefaultPerm); err != nil { - m.runtime.Logger.Error(fmt.Sprintf("create log directory fail, error:%s", err)) - return fmt.Errorf("create log directory fail, error:%s", err) - } - m.runtime.Logger.Info("create log directory successfully") - - // 创建数据文件目录 - m.runtime.Logger.Info("start to create data directory") - if err := util.MkDirsIfNotExistsWithPerm([]string{m.DbpathDir}, DefaultPerm); err != nil { - m.runtime.Logger.Error(fmt.Sprintf("create data directory fail, error:%s", err)) - return fmt.Errorf("create data directory fail, error:%s", err) - } - m.runtime.Logger.Info("create data directory successfully") - - // 创建备份文件目录 - m.runtime.Logger.Info("start to create backup directory") - if err := util.MkDirsIfNotExistsWithPerm([]string{m.BackupDir}, DefaultPerm); err != nil { - m.runtime.Logger.Error(fmt.Sprintf("create backup directory fail, error:%s", err)) - return fmt.Errorf("create backup directory fail, error:%s", err) - } - m.runtime.Logger.Info("create backup directory successfully") - - // 修改目录属主 - m.runtime.Logger.Info("start to execute chown command for dbPath, logPath and backupPath") - if _, err := util.RunBashCmd( - fmt.Sprintf("chown -R %s.%s %s", m.OsUser, m.OsGroup, filepath.Join(logPathDir, "../")), - "", nil, - 10*time.Second); err != nil { - m.runtime.Logger.Error(fmt.Sprintf("chown log directory fail, error:%s", err)) - return fmt.Errorf("chown log directory fail, error:%s", err) - } - if _, err := util.RunBashCmd( - fmt.Sprintf("chown -R %s.%s %s", m.OsUser, m.OsGroup, filepath.Join(m.DbpathDir, "../../")), - "", nil, - 10*time.Second); err != nil { - m.runtime.Logger.Error(fmt.Sprintf("chown data directory fail, error:%s", err)) - return fmt.Errorf("chown data directory fail, error:%s", err) - } - if _, err := util.RunBashCmd( - fmt.Sprintf("chown -R %s.%s %s", m.OsUser, m.OsGroup, m.BackupDir), - "", nil, - 10*time.Second); err != nil { - m.runtime.Logger.Error(fmt.Sprintf("chown backup directory fail, error:%s", err)) - return fmt.Errorf("chown backup directory fail, error:%s", err) - } - m.runtime.Logger.Info("execute chown command for dbPath, logPath and backupPath successfully") - return nil -} - -// createConfFileAndKeyFileAndDbTypeFile 创建配置文件以及key文件 -func (m *MongoDBInstall) createConfFileAndKeyFileAndDbTypeFile() error { - if err := common.CreateConfFileAndKeyFileAndDbTypeFileAndChown( - m.runtime, m.AuthConfFilePath, m.AuthConfFileContent, m.OsUser, m.OsGroup, m.NoAuthConfFilePath, - m.NoAuthConfFileContent, m.KeyFilePath, m.ConfParams.App, m.ConfParams.AreaId, m.DbTypeFilePath, - m.ConfParams.InstanceType, DefaultPerm); err != nil { - return err - } - return nil -} - -// startup 启动服务 -func (m *MongoDBInstall) startup() error { - // 声明mongod可执行文件路径,把路径写入/etc/profile - if err := common.AddPathToProfile(m.runtime, m.BinDir); err != nil { - return err - } - - // 启动服务 - m.runtime.Logger.Info("start to startup mongod") - if err := common.StartMongoProcess(m.BinDir, m.ConfParams.Port, - m.OsUser, m.ConfParams.Auth); err != nil { - m.runtime.Logger.Error("startup mongod fail, error:%s", err) - return fmt.Errorf("startup mongod fail, error:%s", err) - } - flag, service, err := common.CheckMongoService(m.ConfParams.Port) - if err != nil { - m.runtime.Logger.Error("check %s fail, error:%s", service, err) - return fmt.Errorf("check %s fail, error:%s", service, err) - } - if flag == false { - m.runtime.Logger.Error("startup %s fail", service) - return fmt.Errorf("startup %s fail", service) - } - m.runtime.Logger.Info("startup %s successfully", service) - - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go deleted file mode 100644 index be55ea2b01..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongod_replace.go +++ /dev/null @@ -1,356 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "path/filepath" - "strconv" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// MongoDReplaceConfParams 参数 // cluster 关闭stopBalancer -type MongoDReplaceConfParams struct { - IP string `json:"ip" validate:"required"` // 执行节点 - Port int `json:"port" validate:"required"` - SourceIP string `json:"sourceIP" validate:"required"` // 源节点 - SourcePort int `json:"sourcePort" validate:"required"` - SourceDown bool `json:"sourceDown"` // 源端已down机 true:已down false:未down - AdminUsername string `json:"adminUsername" validate:"required"` - AdminPassword string `json:"adminPassword" validate:"required"` - TargetIP string `json:"targetIP" validate:"required"` // 目标节点 - TargetPort int `json:"targetPort" validate:"required"` - TargetPriority string `json:"targetPriority"` // 可选,默认为null,如果为null,则使用source端的Priority,取值:0-正无穷 - TargetHidden string `json:"targetHidden"` // 可选,默认为null,如果为null,则使用source端的Hidden,取值:null,0,1,0:显现 1:隐藏 -} - -// MongoDReplace 添加分片到集群 -type MongoDReplace struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - Mongo string - OsUser string - DataDir string - DbpathDir string - PrimaryIP string - PrimaryPort int - AddTargetScript string - ConfParams *MongoDReplaceConfParams - TargetIPStatus int - TargetPriority int - TargetHidden bool - StatusCh chan int -} - -// NewMongoDReplace 实例化结构体 -func NewMongoDReplace() jobruntime.JobRunner { - return &MongoDReplace{} -} - -// Name 获取原子任务的名字 -func (r *MongoDReplace) Name() string { - return "mongod_replace" -} - -// Run 运行原子任务 -func (r *MongoDReplace) Run() error { - // 主节点进行切换 - if err := r.primaryStepDown(); err != nil { - return err - } - - // 生成添加新节点脚本 - if err := r.makeAddTargetScript(); err != nil { - return err - } - - // 生成添加新节点脚本 - if err := r.execAddTargetScript(); err != nil { - return err - } - - // 查看新节点状态 - go r.checkTargetStatus() - - // 执行删除老节点脚本 - if err := r.checkTargetStatusAndRemoveSource(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (r *MongoDReplace) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (r *MongoDReplace) Rollback() error { - return nil -} - -// Init 初始化 -func (r *MongoDReplace) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - r.runtime = runtime - r.runtime.Logger.Info("start to init") - r.BinDir = consts.UsrLocal - r.Mongo = filepath.Join(r.BinDir, "mongodb", "bin", "mongo") - r.OsUser = consts.GetProcessUser() - r.DataDir = consts.GetMongoDataDir() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(r.runtime.PayloadDecoded), &r.ConfParams); err != nil { - r.runtime.Logger.Error(fmt.Sprintf( - "get parameters of mongodReplace fail by json.Unmarshal, error:%s", err)) - return fmt.Errorf("get parameters of mongodReplace fail by json.Unmarshal, error:%s", err) - } - - r.DbpathDir = filepath.Join(r.DataDir, "mongodata", strconv.Itoa(r.ConfParams.Port), "db") - - // 获取primary信息 - info, err := common.AuthGetPrimaryInfo(r.OsUser, r.Mongo, r.ConfParams.AdminUsername, r.ConfParams.AdminPassword, - r.ConfParams.IP, r.ConfParams.Port) - if err != nil { - r.runtime.Logger.Error(fmt.Sprintf( - "get primary db info of mongodReplace fail, error:%s", err)) - return fmt.Errorf("get primary db info of mongodReplace fail, error:%s", err) - } - // 判断info是否为null - if info == "" { - r.runtime.Logger.Error(fmt.Sprintf( - "get primary db info of mongodReplace fail, error:%s", err)) - return fmt.Errorf("get primary db info of mongodReplace fail, error:%s", err) - } - getInfo := strings.Split(info, ":") - r.PrimaryIP = getInfo[0] - r.PrimaryPort, _ = strconv.Atoi(getInfo[1]) - r.StatusCh = make(chan int, 1) - - // 获取源端的配置信息 - _, _, _, hidden, priority, _, err := common.GetNodeInfo(r.OsUser, r.Mongo, r.PrimaryIP, r.PrimaryPort, - r.ConfParams.AdminUsername, r.ConfParams.AdminPassword, r.ConfParams.SourceIP, r.ConfParams.SourcePort) - if err != nil { - return err - } - r.TargetHidden = hidden - if r.ConfParams.TargetHidden == "0" { - r.TargetHidden = false - } else if r.ConfParams.TargetHidden == "1" { - r.TargetHidden = true - } - - r.TargetPriority = priority - if r.ConfParams.TargetPriority != "" { - r.TargetPriority, _ = strconv.Atoi(r.ConfParams.TargetPriority) - } - - r.runtime.Logger.Info("init successfully") - - // 进行校验 - if err = r.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (r *MongoDReplace) checkParams() error { - // 校验重启配置参数 - validate := validator.New() - r.runtime.Logger.Info("start to validate parameters of mongodReplace") - if err := validate.Struct(r.ConfParams); err != nil { - r.runtime.Logger.Error("validate parameters of mongodReplace fail, error:%s", err) - return fmt.Errorf("validate parameters of mongodReplace fail, error:%s", err) - } - r.runtime.Logger.Info("validate parameters of mongodReplace successfully") - return nil -} - -func (r *MongoDReplace) makeAddTargetScript() error { - // 生成脚本内容 - r.runtime.Logger.Info("start to make addTarget script content") - addMember := common.NewReplicasetMemberAdd() - addMember.Host = strings.Join([]string{r.ConfParams.TargetIP, strconv.Itoa(r.ConfParams.TargetPort)}, ":") - addMember.Priority = r.TargetPriority - addMember.Hidden = r.TargetHidden - addMemberJson, err := addMember.GetJson() - if err != nil { - r.runtime.Logger.Error("get addMemberJson info fail, error:%s", err) - return fmt.Errorf("get addMemberJson info fail, error:%s", err) - } - addMemberJson = strings.Replace(addMemberJson, "\"", "\\\"", -1) - addTargetConfScript := strings.Join([]string{"rs.add(", addMemberJson, ")"}, "") - r.AddTargetScript = addTargetConfScript - r.runtime.Logger.Info("make addTarget script content successfully") - return nil -} - -// execAddTargetScript 执行添加脚本 -func (r *MongoDReplace) execAddTargetScript() error { - // 检查target是否已经存在 - flag, _, _, _, _, _, _ := common.GetNodeInfo(r.OsUser, r.Mongo, r.PrimaryIP, r.PrimaryPort, - r.ConfParams.AdminUsername, r.ConfParams.AdminPassword, r.ConfParams.TargetIP, r.ConfParams.TargetPort) - if flag == true { - r.runtime.Logger.Info("target:%s has been existed", strings.Join( - []string{r.ConfParams.TargetIP, strconv.Itoa(r.ConfParams.TargetPort)}, ":")) - return nil - } - - r.runtime.Logger.Info("start to execute addTarget script") - cmd := fmt.Sprintf( - "su %s -c '%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet --eval \"%s\"'", - r.OsUser, r.Mongo, r.ConfParams.AdminUsername, r.ConfParams.AdminPassword, r.PrimaryIP, - r.PrimaryPort, r.AddTargetScript) - if _, err := util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - r.runtime.Logger.Error("execute addTarget script fail, error:%s", err) - return fmt.Errorf("execute addTarget script fail, error:%s", err) - } - r.runtime.Logger.Info("execute addTarget script successfully") - return nil -} - -// checkTargetStatus 检查target状态 -func (r *MongoDReplace) checkTargetStatus() { - // 超时时间 - timeout := time.After(40 * time.Second) - r.runtime.Logger.Info("start to check Target status") - for { - select { - case <-timeout: - r.runtime.Logger.Error("get target status timeout") - default: - _, _, status, _, _, _, err := common.GetNodeInfo(r.OsUser, r.Mongo, r.PrimaryIP, r.PrimaryPort, - r.ConfParams.AdminUsername, - r.ConfParams.AdminPassword, r.ConfParams.TargetIP, r.ConfParams.TargetPort) - if err != nil { - r.runtime.Logger.Error("get target status fail, error:%s", err) - } - if status == 2 { - r.StatusCh <- 2 - r.runtime.Logger.Info("target status is %d", status) - return - } - time.Sleep(5 * time.Second) - } - } -} - -// primaryStepDown 主库切换 -func (r *MongoDReplace) primaryStepDown() error { - if r.ConfParams.SourceIP == r.PrimaryIP && r.ConfParams.SourcePort == r.PrimaryPort { - r.runtime.Logger.Info("start to convert primary secondary db") - flag, err := common.AuthRsStepDown(r.OsUser, r.Mongo, r.PrimaryIP, r.PrimaryPort, r.ConfParams.AdminUsername, - r.ConfParams.AdminPassword) - if err != nil { - r.runtime.Logger.Error(fmt.Sprintf("convert primary secondary db fail, error:%s", err)) - return fmt.Errorf("convert primary secondary db fail, error:%s", err) - } - if flag == true { - info, err := common.AuthGetPrimaryInfo(r.OsUser, r.Mongo, r.ConfParams.AdminUsername, r.ConfParams.AdminPassword, - r.ConfParams.IP, r.ConfParams.Port) - if err != nil { - r.runtime.Logger.Error(fmt.Sprintf("get new primary info fail, error:%s", err)) - return fmt.Errorf("get new primary info fail, error:%s", err) - } - if info != fmt.Sprintf("%s:%d", r.ConfParams.IP, r.ConfParams.Port) { - r.runtime.Logger.Info("convert primary secondary db successfully") - infoSlice := strings.Split(info, ":") - r.PrimaryIP = infoSlice[0] - r.PrimaryPort, _ = strconv.Atoi(infoSlice[1]) - return nil - } - } - } - return nil -} - -// shutdownSourceProcess 关闭源端mongod进程 -func (r *MongoDReplace) shutdownSourceProcess() error { - flag, _, _ := common.CheckMongoService(r.ConfParams.Port) - if flag == false { - r.runtime.Logger.Info("source mongod process has been shut") - return nil - } - r.runtime.Logger.Info("start to shutdown source mongod process") - if err := common.ShutdownMongoProcess(r.OsUser, "mongod", r.BinDir, r.DbpathDir, r.ConfParams.Port); err != nil { - source := fmt.Sprintf("%s:%d", r.ConfParams.IP, r.ConfParams.Port) - r.runtime.Logger.Error(fmt.Sprintf("shutdown source:%s fail, error:%s", source, err)) - return fmt.Errorf("shutdown source:%s fail, error:%s", source, err) - } - r.runtime.Logger.Info("shutdown source mongod process successfully") - return nil -} - -// removeSource 复制集中移除source -func (r *MongoDReplace) removeSource() error { - // 检查source是否存在 - flag, _, _, _, _, _, _ := common.GetNodeInfo(r.OsUser, r.Mongo, r.PrimaryIP, r.PrimaryPort, - r.ConfParams.AdminUsername, r.ConfParams.AdminPassword, r.ConfParams.SourceIP, r.ConfParams.SourcePort) - if flag == false { - r.runtime.Logger.Info("source:%s has been remove", strings.Join( - []string{r.ConfParams.SourceIP, strconv.Itoa(r.ConfParams.SourcePort)}, ":")) - return nil - } - r.runtime.Logger.Info("start to make remove source script content") - removeSourceConfScript := strings.Join([]string{ - "rs.remove(", - fmt.Sprintf("\\\"%s:%d\\\"", r.ConfParams.SourceIP, r.ConfParams.SourcePort), - ")"}, "") - r.runtime.Logger.Info("make remove source script content successfully") - r.runtime.Logger.Info("start to execute remove source script") - cmd := fmt.Sprintf( - "su %s -c '%s -u %s -p %s --host %s --port %d --authenticationDatabase=admin --quiet --eval \"%s\"'", - r.OsUser, r.Mongo, r.ConfParams.AdminUsername, r.ConfParams.AdminPassword, r.PrimaryIP, - r.PrimaryPort, removeSourceConfScript) - if _, err := util.RunBashCmd( - cmd, - "", nil, - 10*time.Second); err != nil { - r.runtime.Logger.Error(fmt.Sprintf("execute remove source script fail, error:%s", err)) - return fmt.Errorf("execute remove source script fail, error:%s", err) - } - r.runtime.Logger.Info("execute remove source script successfully") - return nil -} - -// checkTargetStatusAndRemoveSource 监控状态并移除 -func (r *MongoDReplace) checkTargetStatusAndRemoveSource() error { - // 超时时间 - timeout := time.After(50 * time.Second) - for { - select { - case <-timeout: - return fmt.Errorf("check target status timeout") - case status := <-r.StatusCh: - if status == 2 && r.ConfParams.SourceDown == false { - if err := r.shutdownSourceProcess(); err != nil { - return err - } - if err := r.removeSource(); err != nil { - return err - } - return nil - } else if status == 2 && r.ConfParams.SourceDown == true { - if err := r.removeSource(); err != nil { - return err - } - return nil - } - default: - - } - } -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go deleted file mode 100644 index 4e295da24d..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/mongos_install.go +++ /dev/null @@ -1,440 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "path/filepath" - "strconv" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// MongoSConfParams 配置文件参数 -type MongoSConfParams struct { - common.MediaPkg `json:"mediapkg"` - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - InstanceType string `json:"instanceType" validate:"required"` // mongos mongod - App string `json:"app" validate:"required"` - AreaId string `json:"areaId" validate:"required"` - Auth bool `json:"auth"` // true:以验证方式启动mongos false:以非验证方式启动mongos - ConfigDB []string `json:"configDB" validate:"required"` // ip:port - DbConfig struct { - SlowOpThresholdMs int `json:"slowOpThresholdMs"` - Destination string `json:"destination"` - } `json:"dbConfig" validate:"required"` -} - -// MongoSInstall MongoS安装 -type MongoSInstall struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - DataDir string - OsUser string // MongoDB安装在哪个用户下 - OsGroup string - ConfParams *MongoSConfParams - DbVersion string - AuthConfFilePath string - AuthConfFileContent []byte - NoAuthConfFilePath string - NoAuthConfFileContent []byte - DbTypeFilePath string - LogPath string - PidFilePath string - KeyFilePath string - InstallPackagePath string - LockFilePath string // 锁文件路径 -} - -// NewMongoSInstall 实例化结构体 -func NewMongoSInstall() jobruntime.JobRunner { - return &MongoSInstall{} -} - -// Name 获取原子任务的名字 -func (s *MongoSInstall) Name() string { - return "mongos_install" -} - -// Run 运行原子任务 -func (s *MongoSInstall) Run() error { - // 进行校验 - status, err := s.checkParams() - if err != nil { - return err - } - if status { - return nil - } - - // 解压安装包并修改属主 - if err = s.unTarAndCreateSoftLink(); err != nil { - return err - } - - // 创建目录并修改属主 - if err = s.mkdir(); err != nil { - return err - } - - // 创建配置文件,key文件并修改属主 - if err = s.createConfFileAndKeyFileAndDbTypeFile(); err != nil { - return err - } - - // 启动服务 - if err = s.startup(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (s *MongoSInstall) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (s *MongoSInstall) Rollback() error { - return nil -} - -// Init 初始化 -func (s *MongoSInstall) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - s.runtime = runtime - s.runtime.Logger.Info("start to init") - s.BinDir = consts.UsrLocal - s.DataDir = consts.GetMongoDataDir() - s.OsUser = consts.GetProcessUser() - s.OsGroup = consts.GetProcessUserGroup() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(s.runtime.PayloadDecoded), &s.ConfParams); err != nil { - s.runtime.Logger.Error(fmt.Sprintf( - "get parameters of mongodb config file fail by json.Unmarshal, error:%s", err)) - return fmt.Errorf("get parameters of mongodb config file fail by json.Unmarshal, error:%s", err) - } - - // 获取信息 - s.InstallPackagePath = s.ConfParams.MediaPkg.GetAbsolutePath() - s.DbVersion = strings.Split(s.ConfParams.MediaPkg.GePkgBaseName(), "-")[3] - - // 设置各种路径 - strPort := strconv.Itoa(s.ConfParams.Port) - s.AuthConfFilePath = filepath.Join(s.DataDir, "mongodata", strPort, "mongo.conf") - s.NoAuthConfFilePath = filepath.Join(s.DataDir, "mongodata", strPort, "noauth.conf") - s.LogPath = filepath.Join(s.DataDir, "mongolog", strPort, "mongo.log") - PidFileName := fmt.Sprintf("pid.%s", strPort) - s.PidFilePath = filepath.Join(s.DataDir, "mongodata", strPort, PidFileName) - s.KeyFilePath = filepath.Join(s.DataDir, "mongodata", strPort, "key_of_mongo") - s.DbTypeFilePath = filepath.Join(s.DataDir, "mongodata", strPort, "dbtype") - s.LockFilePath = filepath.Join(s.DataDir, "mongoinstall.lock") - - // 生成配置文件内容 - s.runtime.Logger.Info("make mongos config file content") - if err := s.makeConfContent(); err != nil { - return err - } - - return nil -} - -// makeConfContent 生成配置文件内容 -func (s *MongoSInstall) makeConfContent() error { - // 只支持mongos 3.0及以上得到配置文件内容 - // 判断mongos版本 - s.runtime.Logger.Info("start to make config file content") - mainVersion, err := strconv.Atoi(strings.Split(s.DbVersion, ".")[0]) - if err != nil { - s.runtime.Logger.Error( - "get %s version fail, error:%s", s.ConfParams.InstanceType, err) - return fmt.Errorf("get %s version fail, error:%s", s.ConfParams.InstanceType, err) - } - clusterId := strings.Join([]string{s.ConfParams.App, s.ConfParams.AreaId, "conf"}, "-") - IpConfigDB := strings.Join(s.ConfParams.ConfigDB, ",") - configDB := strings.Join([]string{clusterId, IpConfigDB}, "/") - - // 生成mongos配置文件 - conf := common.NewYamlMongoSConf() - conf.Sharding.ConfigDB = configDB - conf.SystemLog.LogAppend = true - conf.SystemLog.Path = s.LogPath - conf.SystemLog.Destination = s.ConfParams.DbConfig.Destination - conf.ProcessManagement.Fork = true - conf.ProcessManagement.PidFilePath = s.PidFilePath - conf.Net.Port = s.ConfParams.Port - conf.Net.BindIp = strings.Join([]string{"127.0.0.1", s.ConfParams.IP}, ",") - conf.Net.WireObjectCheck = false - // mongos版本小于4获取配置文件内容 - if mainVersion < 4 { - s.NoAuthConfFileContent, err = conf.GetConfContent() - if err != nil { - s.runtime.Logger.Error( - "version:%s make mongos no auth config file content fail, error:%s", s.DbVersion, err) - return fmt.Errorf("version:%s make mongos no auth config file content fail, error:%s", - s.DbVersion, err) - } - conf.Security.KeyFile = s.KeyFilePath - // 获取验证配置文件内容 - s.AuthConfFileContent, err = conf.GetConfContent() - if err != nil { - s.runtime.Logger.Error(fmt.Sprintf( - "version:%s make mongos auth config file content fail, error:%s", - s.DbVersion, err)) - return fmt.Errorf("version:%s make mongos auth config file content fail, error:%s", - s.DbVersion, err) - } - s.runtime.Logger.Info("make config file content successfully") - return nil - } - - // mongos版本4及以上获取配置文件内容 - conf.OperationProfiling.SlowOpThresholdMs = s.ConfParams.DbConfig.SlowOpThresholdMs - conf.OperationProfiling.SlowOpThresholdMs = s.ConfParams.DbConfig.SlowOpThresholdMs - // 获取非验证配置文件内容 - s.NoAuthConfFileContent, err = conf.GetConfContent() - if err != nil { - s.runtime.Logger.Error( - "version:%s make mongos no auth config file content fail, error:%s", s.DbVersion, err) - return fmt.Errorf("version:%s make mongos no auth config file content fail, error:%s", - s.DbVersion, err) - } - conf.Security.KeyFile = s.KeyFilePath - // 获取验证配置文件内容 - s.AuthConfFileContent, err = conf.GetConfContent() - if err != nil { - s.runtime.Logger.Error(fmt.Sprintf( - "version:%s make mongos auth config file content fail, error:%s", - s.DbVersion, err)) - return fmt.Errorf("version:%s make mongos auth config file content fail, error:%s", - s.DbVersion, err) - } - s.runtime.Logger.Info("make config file content successfully") - return nil -} - -// checkParams 校验参数 检查输入的参数 检查端口是否合规 检查安装包 检查端口是否被使用(如果使用,则检查是否是mongodb服务) -func (s *MongoSInstall) checkParams() (bool, error) { - // 校验Mongo配置文件 - s.runtime.Logger.Info("start to validate parameters") - validate := validator.New() - s.runtime.Logger.Info("start to validate parameters of mongos config file") - if err := validate.Struct(s.ConfParams); err != nil { - s.runtime.Logger.Error(fmt.Sprintf("validate parameters of mongos config file fail, error:%s", err)) - return false, fmt.Errorf("validate parameters of mongos config file fail, error:%s", err) - } - s.runtime.Logger.Info("= validate parameters of mongos config file successfully") - - // 校验port是否合规 - s.runtime.Logger.Info("start to validate port if it is correct") - if s.ConfParams.Port < MongoDBPortMin || s.ConfParams.Port > MongoDBPortMax { - s.runtime.Logger.Error(fmt.Sprintf( - "validate port if it is correct, port is not within defalut range [%d,%d]", - MongoDBPortMin, MongoDBPortMax)) - return false, fmt.Errorf("validate port if it is correct, port is not within defalut range [%d,%d]", - MongoDBPortMin, MongoDBPortMax) - } - s.runtime.Logger.Info("validate port if it is correct successfully") - - // 校验安装包是否存在,md5值是否一致 - s.runtime.Logger.Info("start to validate install package") - if flag := util.FileExists(s.InstallPackagePath); !flag { - s.runtime.Logger.Error(fmt.Sprintf("validate install package, %s is not existed", - s.InstallPackagePath)) - return false, fmt.Errorf("validate install file, %s is not existed", - s.InstallPackagePath) - } - md5, _ := util.GetFileMd5(s.InstallPackagePath) - if s.ConfParams.MediaPkg.PkgMd5 != md5 { - s.runtime.Logger.Error(fmt.Sprintf("validate install package md5 fail, md5 is incorrect")) - return false, fmt.Errorf("validate install package md5 fail, md5 is incorrect") - } - s.runtime.Logger.Info("validate install package md5 successfully") - - // 校验端口是否使用 - s.runtime.Logger.Info("start to validate port if it has been used") - flag, _ := util.CheckPortIsInUse(s.ConfParams.IP, strconv.Itoa(s.ConfParams.Port)) - if flag { - // 校验端口是否是mongod进程 - cmd := fmt.Sprintf("netstat -ntpl |grep %d | awk '{print $7}' |head -1", s.ConfParams.Port) - result, _ := util.RunBashCmd(cmd, "", nil, 10*time.Second) - if strings.Contains(result, "mongos") { - // 检查配置文件是否一致,读取已有配置文件与新生成的配置文件内容对比 - content, _ := ioutil.ReadFile(s.AuthConfFilePath) - if strings.Compare(string(content), string(s.AuthConfFileContent)) == 0 { - // 检查mongodb版本 - version, err := common.CheckMongoVersion(s.BinDir, "mongos") - if err != nil { - s.runtime.Logger.Error( - fmt.Sprintf("mongos has been installed, port:%d, check mongos version fail. error:%s", - s.ConfParams.Port, version)) - return false, fmt.Errorf("mongos has been installed, port:%d, check mongos version fail. error:%s", - s.ConfParams.Port, version) - } - if version == s.DbVersion { - s.runtime.Logger.Info(fmt.Sprintf("mongos has been installed, port:%d, version:%s", - s.ConfParams.Port, version)) - return true, nil - } - s.runtime.Logger.Error(fmt.Sprintf("other mongos has been installed, port:%d, version:%s", - s.ConfParams.Port, version)) - return false, fmt.Errorf("other mongos has been installed, port:%d, version:%s", - s.ConfParams.Port, version) - } - - } - s.runtime.Logger.Error( - fmt.Sprintf("validate port if it has been used, port:%d is used by other process", - s.ConfParams.Port)) - return false, fmt.Errorf("validate port if it has been used, port:%d is used by other process", - s.ConfParams.Port) - } - s.runtime.Logger.Info("validate port if it has been used successfully") - s.runtime.Logger.Info("validate parameters successfully") - return false, nil -} - -// unTarAndCreateSoftLink 解压安装包,创建软链接并给目录授权 -func (s *MongoSInstall) unTarAndCreateSoftLink() error { - // 判断解压目录是否存在 - unTarPath := filepath.Join(s.BinDir, s.ConfParams.MediaPkg.GePkgBaseName()) - - // soft link目录 - installPath := filepath.Join(s.BinDir, "mongodb") - - // 解压安装包并授权 - // 安装多实例并发执行添加文件锁 - s.runtime.Logger.Info("start to get install file lock") - fileLock := common.NewFileLock(s.LockFilePath) - // 获取锁 - err := fileLock.Lock() - if err != nil { - for { - err = fileLock.Lock() - if err != nil { - time.Sleep(1 * time.Second) - continue - } - s.runtime.Logger.Info("get install file lock successfully") - break - } - } else { - s.runtime.Logger.Info("get install file lock successfully") - } - if err = common.UnTarAndCreateSoftLinkAndChown(s.runtime, s.BinDir, - s.InstallPackagePath, unTarPath, installPath, s.OsUser, s.OsGroup); err != nil { - return err - } - // 释放锁 - s.runtime.Logger.Info("release install file lock successfully") - _ = fileLock.UnLock() - - // 检查mongos版本 - s.runtime.Logger.Info("start to check mongos version") - version, err := common.CheckMongoVersion(s.BinDir, "mongos") - if err != nil { - s.runtime.Logger.Error(fmt.Sprintf("%s has been existed, check mongodb version, error:%s", - installPath, err)) - return fmt.Errorf("%s has been existed, check mongodb version, error:%s", - installPath, err) - } - if version != s.DbVersion { - s.runtime.Logger.Error( - fmt.Sprintf("%s has been existed, check mongodb version, version:%s is incorrect", - installPath, version)) - return fmt.Errorf("%s has been existed, check mongodb version, version:%s is incorrect", - installPath, version) - } - s.runtime.Logger.Info("check mongos version successfully") - return nil -} - -// mkdir 创建相关目录并给目录授权 -func (s *MongoSInstall) mkdir() error { - // 创建日志文件目录 - logPathDir, _ := filepath.Split(s.LogPath) - s.runtime.Logger.Info("start to create log directory") - if err := util.MkDirsIfNotExistsWithPerm([]string{logPathDir}, DefaultPerm); err != nil { - s.runtime.Logger.Error(fmt.Sprintf("create log directory fail, error:%s", err)) - return fmt.Errorf("create log directory fail, error:%s", err) - } - s.runtime.Logger.Info("create log directory successfully") - - // 创建配置文件目录 - confFilePathDir, _ := filepath.Split(s.AuthConfFilePath) - s.runtime.Logger.Info("start to create data directory") - if err := util.MkDirsIfNotExistsWithPerm([]string{confFilePathDir}, DefaultPerm); err != nil { - s.runtime.Logger.Error(fmt.Sprintf("create data directory fail, error:%s", err)) - return fmt.Errorf("create data directory fail, error:%s", err) - } - s.runtime.Logger.Info("create data directory successfully") - - // 修改目录属主 - s.runtime.Logger.Info("start to execute chown command for dbPath, logPath and backupPath") - if _, err := util.RunBashCmd( - fmt.Sprintf("chown -R %s.%s %s", s.OsUser, s.OsGroup, filepath.Join(logPathDir, "../")), - "", nil, - 10*time.Second); err != nil { - s.runtime.Logger.Error(fmt.Sprintf("chown log directory fail, error:%s", err)) - return fmt.Errorf("chown log directory fail, error:%s", err) - } - if _, err := util.RunBashCmd( - fmt.Sprintf("chown -R %s.%s %s", s.OsUser, s.OsGroup, filepath.Join(confFilePathDir, "../")), - "", nil, - 10*time.Second); err != nil { - s.runtime.Logger.Error(fmt.Sprintf("chown data directory fail, error:%s", err)) - return fmt.Errorf("chown data directory fail, error:%s", err) - } - s.runtime.Logger.Info("execute chown command for dbPath, logPath and backupPath successfully") - return nil -} - -// createConfFileAndKeyFileAndDbTypeFile 创建配置文件以及key文件 -func (s *MongoSInstall) createConfFileAndKeyFileAndDbTypeFile() error { - // 创建配置文件,key文件,dbType文件并授权 - if err := common.CreateConfFileAndKeyFileAndDbTypeFileAndChown( - s.runtime, s.AuthConfFilePath, s.AuthConfFileContent, s.OsUser, s.OsGroup, s.NoAuthConfFilePath, - s.NoAuthConfFileContent, s.KeyFilePath, s.ConfParams.App, s.ConfParams.AreaId, s.DbTypeFilePath, - s.ConfParams.InstanceType, DefaultPerm); err != nil { - return err - } - return nil -} - -// startup 启动服务 -func (s *MongoSInstall) startup() error { - // 申明mongos可执行文件路径,把路径写入/etc/profile - if err := common.AddPathToProfile(s.runtime, s.BinDir); err != nil { - return err - } - - // 启动服务 - s.runtime.Logger.Info("start to startup mongos") - if err := common.StartMongoProcess(s.BinDir, s.ConfParams.Port, - s.OsUser, s.ConfParams.Auth); err != nil { - s.runtime.Logger.Error(fmt.Sprintf("startup mongos fail, error:%s", err)) - return fmt.Errorf("shutdown mongos fail, error:%s", err) - } - flag, service, err := common.CheckMongoService(s.ConfParams.Port) - if err != nil { - s.runtime.Logger.Error("check %s fail, error:%s", service, err) - return fmt.Errorf("check %s fail, error:%s", service, err) - } - if flag == false { - s.runtime.Logger.Error("startup %s fail", service) - return fmt.Errorf("startup %s fail", service) - } - s.runtime.Logger.Info("startup %s successfully", service) - - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_install_test.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_install_test.go deleted file mode 100644 index dd6dd92085..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_install_test.go +++ /dev/null @@ -1,339 +0,0 @@ -package atommongodb - -import ( - "fmt" - "net" - "path" - "strings" - "testing" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomsys" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" -) - -// TestReplicaset 复制集安装及相关操作测试 -func TestReplicaset(t *testing.T) { - // 设置环境变量 - err := consts.SetMongoDataDir("") - if err != nil { - fmt.Println(fmt.Sprintf("replicate install SetMongoData fail, error:%s", err)) - t.Errorf("replicate install SetMongoData fail, error:%s", err) - return - } - err = consts.SetMongoBackupDir("") - if err != nil { - fmt.Println(fmt.Sprintf("replicate install SetMongoBackup fail, error:%s", err)) - t.Errorf("replicate install SetMongoBackup fail, error:%s", err) - return - } - - err = consts.SetProcessUser("") - if err != nil { - fmt.Println(fmt.Sprintf("replicate install SetProcessUser fail, error:%s", err)) - t.Errorf("replicate install SetProcessUser fail, error:%s", err) - return - } - err = consts.SetProcessUserGroup("") - if err != nil { - fmt.Println(fmt.Sprintf("replicate install SetProcessUserGroup fail, error:%s", err)) - t.Errorf("replicate install SetProcessUserGroup fail, error:%s", err) - return - } - // 初始化节点 - osSysInitParam := "{\n\"user\":\"mysql\",\n\"password\":\"Qwe123d\"\n}" - osSysInit := &atomsys.OsMongoInit{} - osSysInitRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: osSysInitParam, - } - osSysInitRuntime.SetLogger() - if err := osSysInit.Init(osSysInitRuntime); err != nil { - fmt.Println(fmt.Sprintf("replicate install osSysInit init fail, error:%s", err)) - t.Errorf("replicate install osSysInit init fail, error:%s", err) - return - } - if err := osSysInit.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install osSysInit run fail, error:%s", err)) - t.Errorf("replicate install osSysInit run fail, error:%s", err) - return - } - - // 获取本机IP地址 - var ip string - addrs, _ := net.InterfaceAddrs() - for _, addr := range addrs { - if !strings.Contains(addr.String(), "127.0.0.1") { - ip = strings.Split(addr.String(), "/")[0] - break - } - } - - // node1 - node1 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27001,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s1\",\n \"auth\": true,\n \"clusterRole\":\"\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node1 = strings.Replace(node1, "{{ip}}", ip, -1) - - // node2 - node2 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27002,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s1\",\n \"auth\": true,\n \"clusterRole\":\"\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node2 = strings.Replace(node2, "{{ip}}", ip, -1) - - // node3 - node3 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27003,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s1\",\n \"auth\": true,\n \"clusterRole\":\"\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node3 = strings.Replace(node3, "{{ip}}", ip, -1) - - // node4 - node4 := "{\n \"mediapkg\":{\n \"pkg\":\"mongodb-linux-x86_64-3.4.20.tar.gz\",\n \"pkg_md5\":\"e68d998d75df81b219e99795dec43ffb\"\n },\n \"ip\":\"{{ip}}\",\n \"port\":27004,\n \"dbVersion\":\"3.4.20\",\n \"instanceType\":\"mongod\",\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s1\",\n \"auth\": true,\n \"clusterRole\":\"\",\n \"dbConfig\":{\n \"slowOpThresholdMs\":200,\n \"cacheSizeGB\":1,\n \"oplogSizeMB\":500,\n \"destination\":\"file\"\n }\n}" - node4 = strings.Replace(node4, "{{ip}}", ip, -1) - - node1MongodInstall := NewMongoDBInstall() - node2MongodInstall := NewMongoDBInstall() - node3MongodInstall := NewMongoDBInstall() - node4MongodInstall := NewMongoDBInstall() - node1Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node1, - } - node1Runtime.SetLogger() - node2Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node2, - } - node2Runtime.SetLogger() - node3Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node3, - } - node3Runtime.SetLogger() - node4Runtime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: node4, - } - node4Runtime.SetLogger() - - // 安装节点 - if err := node1MongodInstall.Init(node1Runtime); err != nil { - fmt.Println(fmt.Sprintf("replicate install node1 init fail, error:%s", err)) - t.Errorf("replicate install node1 init fail, error:%s", err) - return - } - if err := node1MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install node1 run fail, error:%s", err)) - t.Errorf("replicate install node1 run fail, error:%s", err) - return - } - if err := node2MongodInstall.Init(node2Runtime); err != nil { - fmt.Println(fmt.Sprintf("replicate install node2 init fail, error:%s", err)) - t.Errorf("replicate install node2 init fail, error:%s", err) - return - } - if err := node2MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install node2 run fail, error:%s", err)) - t.Errorf("replicate install node2 run fail, error:%s", err) - return - } - if err := node3MongodInstall.Init(node3Runtime); err != nil { - fmt.Println(fmt.Sprintf("replicate install node3 init fail, error:%s", err)) - t.Errorf("replicate install node3 init fail, error:%s", err) - return - } - if err := node3MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install node3 run fail, error:%s", err)) - t.Errorf("replicate install node3 run fail, error:%s", err) - return - } - - if err := node4MongodInstall.Init(node4Runtime); err != nil { - fmt.Println(fmt.Sprintf("replicate install node3 init fail, error:%s", err)) - t.Errorf("replicate install node3 init fail, error:%s", err) - return - } - if err := node4MongodInstall.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install node3 run fail, error:%s", err)) - t.Errorf("replicate install node3 run fail, error:%s", err) - return - } - - // 复制集初始化 - initReplicasetParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27001,\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"setId\":\"s1\",\n \"configSvr\":false,\n \"ips\":[\n \"{{ip}}:27001\",\n \"{{ip}}:27002\",\n \"{{ip}}:27003\"\n ],\n \"priority\":{\n \"{{ip}}:27001\":1,\n \"{{ip}}:27002\":1,\n \"{{ip}}:27003\":0\n },\n \"hidden\":{\n \"{{ip}}:27001\":false,\n \"{{ip}}:27002\":false,\n \"{{ip}}:27003\":true\n }\n}" - initReplicasetParam = strings.Replace(initReplicasetParam, "{{ip}}", ip, -1) - initReplicasetRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: initReplicasetParam, - } - initReplicasetRuntime.SetLogger() - initReplicaset := NewInitiateReplicaset() - if err := initReplicaset.Init(initReplicasetRuntime); err != nil { - fmt.Println(fmt.Sprintf("replicate install initReplicaset init fail, error:%s", err)) - t.Errorf("replicate install initReplicaset init fail, error:%s", err) - return - } - if err := initReplicaset.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install initReplicaset run fail, error:%s", err)) - t.Errorf("replicate install initReplicaset run fail, error:%s", err) - return - } - time.Sleep(time.Second * 3) - // 创建管理员用户 - addAdminUserParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27001,\n \"instanceType\":\"mongod\",\n \"username\":\"dba\",\n \"password\":\"dba\",\n \"adminUsername\":\"\",\n \"adminPassword\":\"\",\n \"authDb\":\"admin\",\n \"dbs\":[\n\n ],\n \"privileges\":[\n \"root\"\n ]\n}" - addAdminUserParam = strings.Replace(addAdminUserParam, "{{ip}}", ip, -1) - addAdminUserRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: addAdminUserParam, - } - addAdminUserRuntime.SetLogger() - addAdminUser := NewAddUser() - if err := addAdminUser.Init(addAdminUserRuntime); err != nil { - fmt.Println(fmt.Sprintf("replicate install addAdminUser init fail, error:%s", err)) - t.Errorf("replicate install addAdminUser init fail, error:%s", err) - return - } - if err := addAdminUser.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install addAdminUser run fail, error:%s", err)) - t.Errorf("replicate install addAdminUser run fail, error:%s", err) - return - } - - // 创建业务用户 - addUserParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27001,\n \"instanceType\":\"mongod\",\n \"username\":\"test\",\n \"password\":\"test\",\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\",\n \"authDb\":\"admin\",\n \"dbs\":[\n\n ],\n \"privileges\":[\n \"readWriteAnyDatabase\"\n ]\n}" - addUserParam = strings.Replace(addUserParam, "{{ip}}", ip, -1) - addUserRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: addUserParam, - } - addUserRuntime.SetLogger() - addUser := NewAddUser() - if err := addUser.Init(addUserRuntime); err != nil { - fmt.Println(fmt.Sprintf("replicate install addUser init fail, error:%s", err)) - t.Errorf("replicate install addUser init fail, error:%s", err) - return - } - if err := addUser.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install addUser run fail, error:%s", err)) - t.Errorf("replicate install addUser run fail, error:%s", err) - return - } - - // 删除业务用户 - delUserParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27001,\n \"instanceType\":\"mongod\",\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\",\n \"username\":\"test\",\n \"authDb\":\"admin\"\n}" - delUserParam = strings.Replace(delUserParam, "{{ip}}", ip, -1) - delUserRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: delUserParam, - } - delUserRuntime.SetLogger() - delUser := NewDelUser() - if err := delUser.Init(delUserRuntime); err != nil { - fmt.Println(fmt.Sprintf("replicate install delUser init fail, error:%s", err)) - t.Errorf("replicate install delUser init fail, error:%s", err) - return - } - if err := delUser.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install delUser run fail, error:%s", err)) - t.Errorf("replicate install delUser run fail, error:%s", err) - return - } - - // 执行脚本 - execScriptParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27001,\n \"script\":\"var mongo = db;\\nmongo.getSisterDB('admin').runCommand({listDatabases:1}).databases.forEach (function (x) { print(x.name)});\\n\",\n \"type\":\"replicaset\",\n \"secondary\": false,\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\",\n \"repoUrl\":\"\",\n \"repoUsername\":\"\",\n \"repoToken\":\"\",\n \"repoProject\":\"\",\n \"repoRepo\":\"\",\n \"repoPath\":\"\"\n}" - execScriptParam = strings.Replace(execScriptParam, "{{ip}}", ip, -1) - execScriptRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: execScriptParam, - } - execScriptRuntime.SetLogger() - execScript := NewExecScript() - if err := execScript.Init(execScriptRuntime); err != nil { - fmt.Println(fmt.Sprintf("replicate install execScript init fail, error:%s", err)) - t.Errorf("replicate install execScript init fail, error:%s", err) - return - } - if err := execScript.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install execScript run fail, error:%s", err)) - t.Errorf("replicate install execScript run fail, error:%s", err) - return - } - - // 重启节点 - restartParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27002,\n \"instanceType\":\"mongod\",\n \"singleNodeInstallRestart\":false, \n \"auth\":true,\n \"cacheSizeGB\": 2,\n \"mongoSConfDbOld\":\"\",\n \"MongoSConfDbNew\":\"\",\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\"\n}" - restartParam = strings.Replace(restartParam, "{{ip}}", ip, -1) - restartRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: restartParam, - } - restartRuntime.SetLogger() - restart := NewMongoRestart() - if err := restart.Init(restartRuntime); err != nil { - fmt.Println(fmt.Sprintf("replicate install restart init fail, error:%s", err)) - t.Errorf("replicate install restart init fail, error:%s", err) - return - } - if err := restart.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install restart run fail, error:%s", err)) - t.Errorf("replicate install restart run fail, error:%s", err) - return - } - - time.Sleep(time.Second * 3) - // 替换节点 - replaceParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27001,\n \"sourceIP\":\"{{ip}}\",\n \"sourcePort\":27001,\n \"sourceDown\":false,\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\",\n \"targetIP\":\"{{ip}}\",\n \"targetPort\":27004,\n \"targetPriority\":\"\",\n \"targetHidden\":\"\"\n}" - replaceParam = strings.Replace(replaceParam, "{{ip}}", ip, -1) - replaceRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: replaceParam, - } - replaceRuntime.SetLogger() - replace := NewMongoDReplace() - if err := replace.Init(replaceRuntime); err != nil { - fmt.Println(fmt.Sprintf("replicate install replace init fail, error:%s", err)) - t.Errorf("replicate install replace init fail, error:%s", err) - return - } - if err := replace.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install replace run fail, error:%s", err)) - t.Errorf("replicate install replace run fail, error:%s", err) - return - } - - time.Sleep(time.Second * 3) - // 主从切换 - stepDownParam := "{\n \"ip\":\"{{ip}}\",\n \"port\":27002,\n \"adminUsername\":\"dba\",\n \"adminPassword\":\"dba\"\n}" - stepDownParam = strings.Replace(stepDownParam, "{{ip}}", ip, -1) - stepDownRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: stepDownParam, - } - stepDownRuntime.SetLogger() - stepDown := NewStepDown() - if err := stepDown.Init(stepDownRuntime); err != nil { - fmt.Println(fmt.Sprintf("replicate install stepDown init fail, error:%s", err)) - t.Errorf("replicate install stepDown init fail, error:%s", err) - return - } - if err := stepDown.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install stepDown run fail, error:%s", err)) - t.Errorf("replicate install stepDown run fail, error:%s", err) - return - } - - time.Sleep(time.Second * 3) - // 下架 - for _, i := range []int{27003, 27002, 27004} { - deinstallParam := fmt.Sprintf("{\n \"ip\":\"{{ip}}\",\n \"port\":%d,\n \"app\":\"test\",\n \"areaId\":\"test1\",\n \"nodeInfo\":[\n \"{{ip}}\"\n ],\n \"instanceType\":\"mongod\"\n}", i) - deinstallParam = strings.Replace(deinstallParam, "{{ip}}", ip, -1) - deinstallRuntime := &jobruntime.JobGenericRuntime{ - PayloadDecoded: deinstallParam, - } - deinstallRuntime.SetLogger() - deinstal := NewDeInstall() - if err := deinstal.Init(deinstallRuntime); err != nil { - fmt.Println(fmt.Sprintf("replicate install deinstal port:%d init fail, error:%s", i, err)) - t.Errorf("replicate install deinstal port:%d init fail, error:%s", i, err) - return - } - if err := deinstal.Run(); err != nil { - fmt.Println(fmt.Sprintf("replicate install deinstal port:%d run fail, error:%s", i, err)) - t.Errorf("replicate install deinstal port:%d run fail, error:%s", i, err) - return - } - } - - // 删除相关目录 - dbData := path.Join(consts.GetMongoDataDir(), "mongodata") - dbLog := path.Join(consts.GetMongoBackupDir(), "mongolog") - softInstall := path.Join(consts.UsrLocal, "mongodb") - cmd := fmt.Sprintf("rm -rf %s;rm -rf %s;rm -rf %s", dbData, dbLog, softInstall) - if _, err = util.RunBashCmd(cmd, "", nil, 10*time.Second); err != nil { - fmt.Println(fmt.Sprintf("delete directories fail, error:%s", err)) - t.Errorf("delete directories fail, error:%s", err) - } - -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go deleted file mode 100644 index 18761a2149..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb/replicaset_stepdown.go +++ /dev/null @@ -1,130 +0,0 @@ -package atommongodb - -import ( - "encoding/json" - "fmt" - "path/filepath" - "strconv" - "strings" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - - "github.com/go-playground/validator/v10" -) - -// StepDownConfParams 参数 -type StepDownConfParams struct { - IP string `json:"ip" validate:"required"` - Port int `json:"port" validate:"required"` - AdminUsername string `json:"adminUsername" validate:"required"` - AdminPassword string `json:"adminPassword" validate:"required"` -} - -// StepDown 添加分片到集群 -type StepDown struct { - runtime *jobruntime.JobGenericRuntime - BinDir string - Mongo string - OsUser string - PrimaryIP string - PrimaryPort int - ConfParams *StepDownConfParams -} - -// NewStepDown 实例化结构体 -func NewStepDown() jobruntime.JobRunner { - return &StepDown{} -} - -// Name 获取原子任务的名字 -func (s *StepDown) Name() string { - return "replicaset_stepdown" -} - -// Run 运行原子任务 -func (s *StepDown) Run() error { - // 执行主备切换 - if err := s.execStepDown(); err != nil { - return err - } - - return nil -} - -// Retry 重试 -func (s *StepDown) Retry() uint { - return 2 -} - -// Rollback 回滚 -func (s *StepDown) Rollback() error { - return nil -} - -// Init 初始化 -func (s *StepDown) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - s.runtime = runtime - s.runtime.Logger.Info("start to init") - s.BinDir = consts.UsrLocal - s.Mongo = filepath.Join(s.BinDir, "mongodb", "bin", "mongo") - s.OsUser = consts.GetProcessUser() - - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(s.runtime.PayloadDecoded), &s.ConfParams); err != nil { - s.runtime.Logger.Error(fmt.Sprintf( - "get parameters of stepDown fail by json.Unmarshal, error:%s", err)) - return fmt.Errorf("get parameters of stepDown fail by json.Unmarshal, error:%s", err) - } - - // 获取primary信息 - info, err := common.AuthGetPrimaryInfo(s.OsUser, s.Mongo, s.ConfParams.AdminUsername, s.ConfParams.AdminPassword, - s.ConfParams.IP, s.ConfParams.Port) - if err != nil { - s.runtime.Logger.Error(fmt.Sprintf( - "get primary db info of stepDown fail, error:%s", err)) - return fmt.Errorf("get primary db info of stepDown fail, error:%s", err) - } - getInfo := strings.Split(info, ":") - s.PrimaryIP = getInfo[0] - s.PrimaryPort, _ = strconv.Atoi(getInfo[1]) - - // 进行校验 - s.runtime.Logger.Info("start to validate parameters") - if err = s.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (s *StepDown) checkParams() error { - // 校验配置参数 - validate := validator.New() - s.runtime.Logger.Info("start to validate parameters of deleteUser") - if err := validate.Struct(s.ConfParams); err != nil { - s.runtime.Logger.Error(fmt.Sprintf("validate parameters of deleteUser fail, error:%s", err)) - return fmt.Errorf("validate parameters of deleteUser fail, error:%s", err) - } - return nil -} - -// execStepDown 执行切换 -func (s *StepDown) execStepDown() error { - s.runtime.Logger.Info("start to convert primary secondary db") - flag, err := common.AuthRsStepDown(s.OsUser, s.Mongo, s.PrimaryIP, s.PrimaryPort, s.ConfParams.AdminUsername, - s.ConfParams.AdminPassword) - if err != nil { - s.runtime.Logger.Error("convert primary secondary db fail, error:%s", err) - return fmt.Errorf("convert primary secondary db fail, error:%s", err) - } - if flag == true { - s.runtime.Logger.Info("convert primary secondary db successfully") - return nil - } - - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go deleted file mode 100644 index 907d39579a..0000000000 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomsys/os_mongo_init.go +++ /dev/null @@ -1,123 +0,0 @@ -package atomsys - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "strings" - "time" - - "dbm-services/redis/db-tools/dbactuator/pkg/common" - "dbm-services/redis/db-tools/dbactuator/pkg/consts" - "dbm-services/redis/db-tools/dbactuator/pkg/jobruntime" - "dbm-services/redis/db-tools/dbactuator/pkg/util" - - "github.com/go-playground/validator/v10" -) - -// OsMongoInitConfParams 系统初始化参数 -type OsMongoInitConfParams struct { - User string `json:"user" validate:"required"` - Password string `json:"password" validate:"required"` -} - -// OsMongoInit 系统初始化原子任务 -type OsMongoInit struct { - runtime *jobruntime.JobGenericRuntime - ConfParams *OsMongoInitConfParams - OsUser string - OsGroup string -} - -// NewOsMongoInit new -func NewOsMongoInit() jobruntime.JobRunner { - return &OsMongoInit{} -} - -// Init 初始化 -func (o *OsMongoInit) Init(runtime *jobruntime.JobGenericRuntime) error { - // 获取安装参数 - o.runtime = runtime - o.runtime.Logger.Info("start to init") - o.OsUser = consts.GetProcessUser() - o.OsGroup = consts.GetProcessUserGroup() - // 获取MongoDB配置文件参数 - if err := json.Unmarshal([]byte(o.runtime.PayloadDecoded), &o.ConfParams); err != nil { - o.runtime.Logger.Error( - "get parameters of mongoOsInit fail by json.Unmarshal, error:%s", err) - return fmt.Errorf("get parameters of mongoOsInit fail by json.Unmarshal, error:%s", err) - } - o.runtime.Logger.Info("init successfully") - - // 进行校验 - if err := o.checkParams(); err != nil { - return err - } - - return nil -} - -// checkParams 校验参数 -func (o *OsMongoInit) checkParams() error { - // 校验配置参数 - o.runtime.Logger.Info("start to validate parameters") - validate := validator.New() - o.runtime.Logger.Info("start to validate parameters of deInstall") - if err := validate.Struct(o.ConfParams); err != nil { - o.runtime.Logger.Error("validate parameters of mongoOsInit fail, error:%s", err) - return fmt.Errorf("validate parameters of mongoOsInit fail, error:%s", err) - } - o.runtime.Logger.Info("validate parameters successfully") - return nil -} - -// Name 名字 -func (o *OsMongoInit) Name() string { - return "os_mongo_init" -} - -// Run 执行函数 -func (o *OsMongoInit) Run() error { - // 获取初始化脚本 - o.runtime.Logger.Info("start to make init script content") - data := common.MongoShellInit - data = strings.Replace(data, "{{user}}", o.OsUser, -1) - data = strings.Replace(data, "{{group}}", o.OsGroup, -1) - o.runtime.Logger.Info("make init script content successfully") - - // 创建脚本文件 - o.runtime.Logger.Info("start to create init script file") - tmpScriptName := "/tmp/sysinit.sh" - if err := ioutil.WriteFile(tmpScriptName, []byte(data), 07555); err != nil { - o.runtime.Logger.Error("write tmp script failed %s", err.Error()) - return err - } - o.runtime.Logger.Info("create init script file successfully") - - // 执行脚本 - o.runtime.Logger.Info("start to execute init script") - _, err := util.RunBashCmd(tmpScriptName, "", nil, 30*time.Second) - if err != nil { - o.runtime.Logger.Error("execute init script fail, error:%s", err) - return fmt.Errorf("execute init script fail, error:%s", err) - } - o.runtime.Logger.Info("execute init script successfully") - // 设置用户名密码 - o.runtime.Logger.Info("start to set user:%s password", o.OsUser) - err = util.SetOSUserPassword(o.ConfParams.User, o.ConfParams.Password) - o.runtime.Logger.Info("set user:%s password successfully", o.OsUser) - if err != nil { - return err - } - return nil -} - -// Retry times -func (o *OsMongoInit) Retry() uint { - return 2 -} - -// Rollback rollback -func (o *OsMongoInit) Rollback() error { - return nil -} diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/jobmanager/jobmanager.go b/dbm-services/redis/db-tools/dbactuator/pkg/jobmanager/jobmanager.go index 51433b715e..9ee9f92e9c 100644 --- a/dbm-services/redis/db-tools/dbactuator/pkg/jobmanager/jobmanager.go +++ b/dbm-services/redis/db-tools/dbactuator/pkg/jobmanager/jobmanager.go @@ -12,7 +12,6 @@ import ( "sync" "time" - "dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atommongodb" "dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomproxy" "dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomredis" "dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomsys" @@ -213,21 +212,6 @@ func (m *JobGenericManager) atomjobsMapperLoading() { // 迁移 m.atomJobMapper[atomredis.NewRedisReuploadOldBackupRecords().Name()] = atomredis.NewRedisReuploadOldBackupRecords - // mongo atom jobs - m.atomJobMapper[atommongodb.NewMongoDBInstall().Name()] = atommongodb.NewMongoDBInstall - m.atomJobMapper[atommongodb.NewMongoSInstall().Name()] = atommongodb.NewMongoSInstall - m.atomJobMapper[atommongodb.NewInitiateReplicaset().Name()] = atommongodb.NewInitiateReplicaset - m.atomJobMapper[atommongodb.NewAddShardToCluster().Name()] = atommongodb.NewAddShardToCluster - m.atomJobMapper[atommongodb.NewAddUser().Name()] = atommongodb.NewAddUser - m.atomJobMapper[atommongodb.NewDelUser().Name()] = atommongodb.NewDelUser - m.atomJobMapper[atommongodb.NewMongoDReplace().Name()] = atommongodb.NewMongoDReplace - m.atomJobMapper[atommongodb.NewMongoRestart().Name()] = atommongodb.NewMongoRestart - m.atomJobMapper[atommongodb.NewStepDown().Name()] = atommongodb.NewStepDown - m.atomJobMapper[atommongodb.NewBalancer().Name()] = atommongodb.NewBalancer - m.atomJobMapper[atommongodb.NewDeInstall().Name()] = atommongodb.NewDeInstall - m.atomJobMapper[atommongodb.NewExecScript().Name()] = atommongodb.NewExecScript - m.atomJobMapper[atommongodb.NewSetProfiler().Name()] = atommongodb.NewSetProfiler - m.atomJobMapper[atomsys.NewOsMongoInit().Name()] = atomsys.NewOsMongoInit }) } diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_storage.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_storage.py new file mode 100644 index 0000000000..80b1655d31 --- /dev/null +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_storage.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" +import logging.config +from typing import Dict, Optional + +from backend.db_meta.enums.cluster_type import ClusterType +from backend.flow.engine.bamboo.scene.common.builder import Builder +from backend.flow.engine.bamboo.scene.mongodb.sub_task import cluster_scale, replicaset_scale +from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs + +logger = logging.getLogger("flow") + + +class MongoScaleFlow(object): + """MongoDB容量变更flow""" + + def __init__(self, root_id: str, data: Optional[Dict]): + """ + 传入参数 + @param root_id : 任务流程定义的root_id + @param data : 单据传递过来的参数列表,是dict格式 + """ + + self.root_id = root_id + self.data = data + self.get_kwargs = ActKwargs() + self.get_kwargs.payload = data + self.get_kwargs.get_file_path() + + def multi_cluster_scale_flow(self): + """ + multi cluster scale流程 + """ + + # 创建流程实例 + pipeline = Builder(root_id=self.root_id, data=self.data) + + # 复制集容量变更——子流程并行 + sub_pipelines = [] + if self.data["infos"][ClusterType.MongoReplicaSet.value]: + for replicaset in self.data["infos"][ClusterType.MongoReplicaSet.value]: + sub_pipline = replicaset_scale( + root_id=self.root_id, + ticket_data=self.data, + sub_kwargs=self.get_kwargs, + info=replicaset, + cluster_role="", + ) + sub_pipelines.append(sub_pipline) + + # cluster容量变更——子流程并行 + if self.data["infos"][ClusterType.MongoShardedCluster.value]: + for cluster in self.data["infos"][ClusterType.MongoShardedCluster.value]: + sub_pipline = cluster_scale( + root_id=self.root_id, ticket_data=self.data, sub_kwargs=self.get_kwargs, info=cluster + ) + sub_pipelines.append(sub_pipline) + pipeline.add_parallel_sub_pipeline(sub_flow_list=sub_pipelines) + + # 运行流程 + pipeline.run_pipeline() diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/__init__.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/__init__.py index e179d6f993..14f5e260d2 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/__init__.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/__init__.py @@ -11,6 +11,7 @@ from .cluster_replace import cluster_replace +from .cluster_scale import cluster_scale from .deinstall import deinstall from .exec_script import exec_script from .increase_mongos import increase_mongos @@ -21,4 +22,5 @@ from .reduce_mongos import reduce_mongos from .replicaset_install import replicaset_install from .replicaset_replace import replicaset_replace +from .replicaset_scale import replicaset_scale from .user import user diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_replace.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_replace.py index 3d8aa4069d..2ac4347acf 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_replace.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_replace.py @@ -55,7 +55,7 @@ def cluster_replace(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKw sub_get_kwargs.get_mongos_host_replace() # 介质下发 - kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="actuator") + kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") sub_pipeline.add_act( act_name=_("MongoDB-介质下发"), act_component_code=ExecSendMediaOperationComponent.code, kwargs=kwargs ) @@ -66,6 +66,12 @@ def cluster_replace(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKw act_name=_("MongoDB-创建原子任务执行目录"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs ) + # 机器初始化 + kwargs = sub_get_kwargs.get_os_init_kwargs() + sub_pipeline.add_act( + act_name=_("MongoDB-机器初始化"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs + ) + # 进行shard和config替换——并行 sub_sub_pipelines = [] # 替换config 以ip为维度 diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_scale.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_scale.py new file mode 100644 index 0000000000..1af28f6dd6 --- /dev/null +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_scale.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" + +from copy import deepcopy +from typing import Dict, Optional + +from django.utils.translation import ugettext as _ + +from backend.db_meta.enums.cluster_type import ClusterType +from backend.flow.consts import MongoDBClusterRole +from backend.flow.engine.bamboo.scene.common.builder import SubBuilder +from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent +from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent +from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs + +from .replicaset_scale import replicaset_scale + + +def cluster_scale(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKwargs, info: dict) -> SubBuilder: + """ + cluster 容量变更流程 + info 表示cluster信息 + """ + + # 获取变量 + sub_get_kwargs = deepcopy(sub_kwargs) + + # 创建子流程 + sub_pipeline = SubBuilder(root_id=root_id, data=ticket_data) + + # 获取集群信息并计算对应关系 + sub_get_kwargs.calc_scale(info=info) + + # 获取信息 + sub_get_kwargs.get_host_scale(mongodb_type=ClusterType.MongoShardedCluster.value, info=info) + + # 介质下发 + kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") + sub_pipeline.add_act( + act_name=_("MongoDB-介质下发"), act_component_code=ExecSendMediaOperationComponent.code, kwargs=kwargs + ) + + # 创建原子任务执行目录 + kwargs = sub_get_kwargs.get_create_dir_kwargs() + sub_pipeline.add_act( + act_name=_("MongoDB-创建原子任务执行目录"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs + ) + + # 机器初始化 + kwargs = sub_get_kwargs.get_os_init_kwargs() + sub_pipeline.add_act( + act_name=_("MongoDB-机器初始化"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs + ) + + # 进行shard——并行 + sub_sub_pipelines = [] + for shard_instance_relationships in sub_get_kwargs.payload["shards_instance_relationships"]: + sub_get_kwargs.payload["instance_relationships"] = shard_instance_relationships + sub_sub_pipeline = replicaset_scale( + root_id=root_id, + ticket_data=ticket_data, + sub_kwargs=sub_get_kwargs, + info=shard_instance_relationships, + cluster_role=MongoDBClusterRole.ShardSvr.value, + ) + sub_sub_pipelines.append(sub_sub_pipeline) + sub_pipeline.add_parallel_sub_pipeline(sub_sub_pipelines) + + return sub_pipeline.build_sub_process(sub_name=_("MongoDB--cluster:{}容量变更".format(info["cluster_id"]))) diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/increase_mongos.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/increase_mongos.py index 7651297085..08b310b5a8 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/increase_mongos.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/increase_mongos.py @@ -43,7 +43,7 @@ def increase_mongos(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKw sub_get_kwargs.get_host_scale_mongos(info=info, increase=True) # 介质下发 - kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="actuator") + kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") sub_pipeline.add_act( act_name=_("MongoDB-介质下发"), act_component_code=ExecSendMediaOperationComponent.code, kwargs=kwargs ) @@ -54,6 +54,12 @@ def increase_mongos(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKw act_name=_("MongoDB-创建原子任务执行目录"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs ) + # 机器初始化 + kwargs = sub_get_kwargs.get_os_init_kwargs() + sub_pipeline.add_act( + act_name=_("MongoDB-机器初始化"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs + ) + # 获取信息 sub_get_kwargs.get_cluster_info_deinstall(cluster_id=info["cluster_id"]) sub_get_kwargs.payload["cluster_id"] = info["cluster_id"] diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/mongod_replace.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/mongod_replace.py index 5fc7d9228b..b9bda3398f 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/mongod_replace.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/mongod_replace.py @@ -28,11 +28,17 @@ ExecDeletePasswordFromDBOperationComponent, ) from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent +from backend.flow.plugins.components.collections.mongodb.mongodb_cmr_4_meta import CMRMongoDBMetaComponent from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs def mongod_replace( - root_id: str, ticket_data: Optional[Dict], sub_sub_kwargs: ActKwargs, cluster_role: str, info: dict + root_id: str, + ticket_data: Optional[Dict], + sub_sub_kwargs: ActKwargs, + cluster_role: str, + info: dict, + mongod_scale: bool, ) -> SubBuilder: """ mongod替换流程 @@ -86,10 +92,8 @@ def mongod_replace( sub_sub_get_kwargs.cluster_type = ClusterType.MongoReplicaSet.value cluster_name = sub_sub_get_kwargs.db_instance["cluster_name"] sub_sub_get_kwargs.payload["cluster_type"] = ClusterType.MongoReplicaSet.value - sub_sub_get_kwargs.payload["set_id"] = sub_sub_get_kwargs.db_instance["cluster_name"] - sub_sub_get_kwargs.replicaset_info["key_file"] = sub_sub_get_kwargs.get_key_file( - cluster_name=sub_sub_get_kwargs.db_instance["cluster_name"] - ) + sub_sub_get_kwargs.payload["set_id"] = cluster_name + sub_sub_get_kwargs.replicaset_info["key_file"] = sub_sub_get_kwargs.get_key_file(cluster_name=cluster_name) sub_sub_get_kwargs.replicaset_info["set_id"] = cluster_name sub_sub_get_kwargs.replicaset_info["nodes"] = [ { @@ -170,6 +174,13 @@ def mongod_replace( kwargs=kwargs, ) + # 修改meta信息 + if mongod_scale: + kwargs = sub_sub_get_kwargs.get_change_meta_replace_kwargs(info=info, instance=sub_sub_get_kwargs.db_instance) + sub_sub_pipeline.add_act( + act_name=_("MongoDB-mongod修改meta"), act_component_code=CMRMongoDBMetaComponent.code, kwargs=kwargs + ) + # 下架老实例 kwargs = sub_sub_get_kwargs.get_mongo_deinstall_kwargs( node_info=sub_sub_get_kwargs.payload["nodes"][0], diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_replace.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_replace.py index db614b26ea..b0cbcbe3bc 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_replace.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_replace.py @@ -44,7 +44,7 @@ def replicaset_replace( sub_get_kwargs.get_host_replace(mongodb_type=ClusterType.MongoReplicaSet.value, info=info) # 介质下发 - kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="actuator") + kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") sub_pipeline.add_act( act_name=_("MongoDB-介质下发"), act_component_code=ExecSendMediaOperationComponent.code, kwargs=kwargs ) @@ -55,8 +55,14 @@ def replicaset_replace( act_name=_("MongoDB-创建原子任务执行目录"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs ) + # 机器初始化 + kwargs = sub_get_kwargs.get_os_init_kwargs() + sub_pipeline.add_act( + act_name=_("MongoDB-机器初始化"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs + ) + # 计算参数 - sub_get_kwargs.calc_param_replace(info=info) + sub_get_kwargs.calc_param_replace(info=info, instance_num=0) # 进行替换——并行 以ip为维度 sub_sub_pipelines = [] for mongodb_instance in info["instances"]: diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_scale.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_scale.py new file mode 100644 index 0000000000..eabf734c71 --- /dev/null +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_scale.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" + +from copy import deepcopy +from typing import Dict, Optional + +from django.utils.translation import ugettext as _ + +from backend.db_meta.enums.cluster_type import ClusterType +from backend.flow.consts import MongoDBClusterRole +from backend.flow.engine.bamboo.scene.common.builder import SubBuilder +from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent +from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent +from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs + +from .mongod_replace import mongod_replace + + +def replicaset_scale( + root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKwargs, info: dict, cluster_role: str +) -> SubBuilder: + """ + replicaset 容量变更流程 + info 表示replicaset信息 + """ + + # 获取变量 + sub_get_kwargs = deepcopy(sub_kwargs) + + # 创建子流程 + sub_pipeline = SubBuilder(root_id=root_id, data=ticket_data) + + if not cluster_role: + # 获取集群信息并计算对应关系 + sub_get_kwargs.calc_scale(info=info) + + # 获取主机信息 + sub_get_kwargs.get_host_scale(mongodb_type=ClusterType.MongoReplicaSet.value, info=info) + + # 介质下发 + kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") + sub_pipeline.add_act( + act_name=_("MongoDB-介质下发"), act_component_code=ExecSendMediaOperationComponent.code, kwargs=kwargs + ) + + # 创建原子任务执行目录 + kwargs = sub_get_kwargs.get_create_dir_kwargs() + sub_pipeline.add_act( + act_name=_("MongoDB-创建原子任务执行目录"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs + ) + + # 机器初始化 + kwargs = sub_get_kwargs.get_os_init_kwargs() + sub_pipeline.add_act( + act_name=_("MongoDB-机器初始化"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs + ) + + instance_relationships = sub_get_kwargs.payload["instance_relationships"] + sub_get_kwargs.calc_param_replace( + info=instance_relationships[0], instance_num=instance_relationships[0].get("node_replica_count", 0) + ) + + # 复制集进行替换——串行 + # backup节点优先替换 + instance_relationships.reverse() + for instance_relationship in instance_relationships: + sub_get_kwargs.db_instance = instance_relationship["instances"][0] + instance_relationship["db_type"] = "replicaset_mongodb" + sub_sub_pipeline = mongod_replace( + root_id=root_id, + ticket_data=ticket_data, + sub_sub_kwargs=sub_get_kwargs, + cluster_role=cluster_role, + info=instance_relationship, + mongod_scale=True, + ) + sub_pipeline.add_sub_pipeline(sub_sub_pipeline) + + if not cluster_role: + name = "replicaset" + else: + if cluster_role == MongoDBClusterRole.ShardSvr.value: + name = "shard" + return sub_pipeline.build_sub_process(sub_name=_("MongoDB--{}容量变更".format(name))) diff --git a/dbm-ui/backend/flow/engine/controller/mongodb.py b/dbm-ui/backend/flow/engine/controller/mongodb.py index 182c613b1d..7839639df8 100644 --- a/dbm-ui/backend/flow/engine/controller/mongodb.py +++ b/dbm-ui/backend/flow/engine/controller/mongodb.py @@ -18,6 +18,7 @@ from backend.flow.engine.bamboo.scene.mongodb.mongodb_remove_ns import MongoRemoveNsFlow from backend.flow.engine.bamboo.scene.mongodb.mongodb_replace import MongoReplaceFlow from backend.flow.engine.bamboo.scene.mongodb.mongodb_restore import MongoRestoreFlow +from backend.flow.engine.bamboo.scene.mongodb.mongodb_scale_storage import MongoScaleFlow from backend.flow.engine.bamboo.scene.mongodb.mongodb_user import MongoUserFlow from backend.flow.engine.controller.base import BaseController from backend.ticket.constants import TicketType @@ -135,3 +136,11 @@ def deinstall_cluster(self): flow = MongoDBDeInstallFlow(root_id=self.root_id, data=self.ticket_data) flow.multi_cluster_deinstall_flow() + + def scale_cluster(self): + """ + 集群容量变更 + """ + + flow = MongoScaleFlow(root_id=self.root_id, data=self.ticket_data) + flow.multi_cluster_scale_flow() diff --git a/dbm-ui/backend/flow/plugins/components/collections/mongodb/exec_actuator_job.py b/dbm-ui/backend/flow/plugins/components/collections/mongodb/exec_actuator_job.py index 72ea04e8ae..8118febffd 100644 --- a/dbm-ui/backend/flow/plugins/components/collections/mongodb/exec_actuator_job.py +++ b/dbm-ui/backend/flow/plugins/components/collections/mongodb/exec_actuator_job.py @@ -85,32 +85,28 @@ def _execute(self, data, parent_data) -> bool: # 创建额外管理员账号 if kwargs.get("create_extra_manager_user", False): + script = kwargs["db_act_template"]["payload"]["script"] if kwargs["set_name"]: kwargs["db_act_template"]["payload"]["adminPassword"] = trans_data[kwargs["set_name"]][ kwargs["db_act_template"]["payload"]["adminUsername"] ] - kwargs["db_act_template"]["payload"]["script"].replace( + script = script.replace( "{{appdba_pwd}}", trans_data[kwargs["set_name"]][MongoDBManagerUser.AppDbaUser] ) - kwargs["db_act_template"]["payload"]["script"].replace( + script = script.replace( "{{monitor_pwd}}", trans_data[kwargs["set_name"]][MongoDBManagerUser.MonitorUser] ) - kwargs["db_act_template"]["payload"]["script"].replace( + script = script.replace( "{{appmonitor_pwd}}", trans_data[kwargs["set_name"]][MongoDBManagerUser.AppMonitorUser] ) else: kwargs["db_act_template"]["payload"]["adminPassword"] = trans_data[ kwargs["db_act_template"]["payload"]["adminUsername"] ] - kwargs["db_act_template"]["payload"]["script"].replace( - "{{appdba_pwd}}", trans_data[MongoDBManagerUser.AppDbaUser] - ) - kwargs["db_act_template"]["payload"]["script"].replace( - "{{monitor_pwd}}", trans_data[MongoDBManagerUser.MonitorUser] - ) - kwargs["db_act_template"]["payload"]["script"].replace( - "{{appmonitor_pwd}}", trans_data[MongoDBManagerUser.AppMonitorUser] - ) + script = script.replace("{{appdba_pwd}}", trans_data[MongoDBManagerUser.AppDbaUser]) + script = script.replace("{{monitor_pwd}}", trans_data[MongoDBManagerUser.MonitorUser]) + script = script.replace("{{appmonitor_pwd}}", trans_data[MongoDBManagerUser.AppMonitorUser]) + kwargs["db_act_template"]["payload"]["script"] = script # 进行db初始设置获,从上游流程节点获取密码 if kwargs.get("db_init_set", False): diff --git a/dbm-ui/backend/flow/urls.py b/dbm-ui/backend/flow/urls.py index f48d8bff6a..a97c9fa3b4 100644 --- a/dbm-ui/backend/flow/urls.py +++ b/dbm-ui/backend/flow/urls.py @@ -74,6 +74,7 @@ MongoDBInstanceRestartView, MongoDBReduceMongoSView, MongoDBReplaceView, + MongoDBScaleSView, MongoFakeInstallApiView, MultiReplicasetInstallApiView, ) @@ -293,6 +294,7 @@ url(r"^scene/multi_cluster_increase_mongos$", MongoDBIncreaseMongoSView.as_view()), url(r"^scene/multi_cluster_reduce_mongos$", MongoDBReduceMongoSView.as_view()), url(r"^scene/cluster_deinstall$", MongoDBDeInstallSView.as_view()), + url(r"^scene/cluster_scale$", MongoDBScaleSView.as_view()), # mongodb end # mysql upgrade url(r"^scene/upgrade_mysql_proxy$", UpgradeMySQLProxySceneApiView.as_view()), diff --git a/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py b/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py index deee925b88..6ee9f0ea18 100644 --- a/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py +++ b/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py @@ -8,6 +8,7 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ + import os from dataclasses import dataclass from typing import Any, List, Optional @@ -40,7 +41,7 @@ ) from backend.flow.engine.bamboo.scene.common.get_file_list import GetFileList from backend.flow.utils.mongodb import mongodb_script_template -from backend.flow.utils.mongodb.calculate_cluster import get_cache_size, get_oplog_size +from backend.flow.utils.mongodb.calculate_cluster import get_cache_size, get_oplog_size, machine_order_by_tolerance from backend.flow.utils.mongodb.mongodb_password import MongoDBPassword @@ -819,18 +820,31 @@ def get_cluster_info_deinstall(self, cluster_id: int): cluster_info = MongoRepository().fetch_one_cluster(id=cluster_id) self.payload["cluster_type"] = cluster_info.cluster_type self.payload["set_id"] = cluster_info.name + self.payload["cluster_name"] = cluster_info.name self.payload["bk_cloud_id"] = cluster_info.bk_cloud_id nodes = [] if cluster_info.cluster_type == ClusterType.MongoReplicaSet.value: + backup_node = {} for member in cluster_info.get_shards()[0].members: + if member.role == InstanceRole.MONGO_BACKUP.value: + backup_node = { + "ip": member.ip, + "port": int(member.port), + "bk_cloud_id": member.bk_cloud_id, + "domain": member.domain, + "instance_role": member.role, + } + continue nodes.append( { "ip": member.ip, "port": int(member.port), "bk_cloud_id": member.bk_cloud_id, "domain": member.domain, + "instance_role": member.role, } ) + nodes.append(backup_node) self.payload["nodes"] = nodes elif cluster_info.cluster_type == ClusterType.MongoShardedCluster.value: mongos = cluster_info.get_mongos() @@ -846,12 +860,46 @@ def get_cluster_info_deinstall(self, cluster_id: int): for shard in shards: shard_info = {"shard": shard.set_name} nodes = [] + backup_node = {} for member in shard.members: - nodes.append({"ip": member.ip, "port": int(member.port), "bk_cloud_id": member.bk_cloud_id}) + if member.role == InstanceRole.MONGO_BACKUP.value: + backup_node = { + "ip": member.ip, + "port": int(member.port), + "bk_cloud_id": member.bk_cloud_id, + "instance_role": member.role, + } + continue + nodes.append( + { + "ip": member.ip, + "port": int(member.port), + "bk_cloud_id": member.bk_cloud_id, + "instance_role": member.role, + } + ) + nodes.append(backup_node) shard_info["nodes"] = nodes shards_nodes.append(shard_info) + backup_node = {} for member in config.members: - config_nodes.append({"ip": member.ip, "port": int(member.port), "bk_cloud_id": member.bk_cloud_id}) + if member.role == InstanceRole.MONGO_BACKUP.value: + backup_node = { + "ip": member.ip, + "port": int(member.port), + "bk_cloud_id": member.bk_cloud_id, + "instance_role": member.role, + } + continue + config_nodes.append( + { + "ip": member.ip, + "port": int(member.port), + "bk_cloud_id": member.bk_cloud_id, + "instance_role": member.role, + } + ) + config_nodes.append(backup_node) self.payload["mongos_nodes"] = mongos_nodes self.payload["shards_nodes"] = shards_nodes self.payload["config_nodes"] = config_nodes @@ -1015,7 +1063,7 @@ def get_instance_restart_kwargs( } def get_host_replace(self, mongodb_type: str, info: dict): - """替换获取信息""" + """替换获取host信息""" hosts = [] if mongodb_type == ClusterType.MongoReplicaSet.value: @@ -1060,12 +1108,15 @@ def get_mongos_host_replace(self): for mongos in self.payload["mongos_nodes"]: self.payload["hosts"].append({"ip": mongos["ip"], "bk_cloud_id": mongos["bk_cloud_id"]}) - def calc_param_replace(self, info: dict): + def calc_param_replace(self, info: dict, instance_num: int): """"计算参数""" self.replicaset_info = {} # 同机器的实例数 - instance_count = len(info["instances"]) + if instance_num: + instance_count = instance_num + else: + instance_count = len(info["instances"]) # 计算cacheSizeGB和oplogSizeMB self.replicaset_info["cacheSizeGB"] = get_cache_size( memory_size=info["target"]["bk_mem"], @@ -1218,6 +1269,133 @@ def get_change_meta_mongos_kwargs(self, increase: bool) -> dict: "mongos_del": mongos_del, } + def calc_scale(self, info: dict) -> dict: + """容量变更计算cluster对应关系""" + + # 获取副本集老实例信息 + cluster_id = info["cluster_id"] + self.get_cluster_info_deinstall(cluster_id=info["cluster_id"]) + if self.payload["cluster_type"] == ClusterType.MongoReplicaSet.value: + # 获取副本集新机器的顺序 副本集容量变更独占机器 + mongodb_host_order_by_tolerance = machine_order_by_tolerance( + disaster_tolerance_level=info["disaster_tolerance_level"], machine_set=info["mongodb"] + ) + instances = self.payload["nodes"] + instance_relationships = [] + for index, host in enumerate(mongodb_host_order_by_tolerance): + instance_relationships.append( + { + "created_by": self.payload["created_by"], + "bk_biz_id": self.payload["bk_biz_id"], + "ip": instances[index]["ip"], + "bk_cloud_id": instances[index]["bk_cloud_id"], + "spec_id": info["machine_specs"]["old_mongodb"]["spec_id"], + "spec_config": info["machine_specs"]["old_mongodb"]["spec_config"], + "target": { + "ip": host["ip"], + "bk_cloud_id": host["bk_cloud_id"], + "spec_id": info["machine_specs"]["mongodb"]["spec_id"], + "bk_cpu": host["bk_cpu"], + "bk_mem": host["bk_mem"], + "storage_device": host["storage_device"], + }, + "instances": [ + { + "cluster_id": cluster_id, + "cluster_name": self.payload["set_id"], + "db_version": info["db_version"], + "domain": instances[index]["domain"], + "port": instances[index]["port"], + } + ], + } + ) + self.payload["instance_relationships"] = instance_relationships + + elif self.payload["cluster_type"] == ClusterType.MongoShardedCluster.value: + # 获取新机器顺序 + mongodb_host_set = [] + for host_set in info["mongodb"]: + mongodb_host_order_by_tolerance = machine_order_by_tolerance( + disaster_tolerance_level=info["disaster_tolerance_level"], machine_set=host_set + ) + mongodb_host_set.append(mongodb_host_order_by_tolerance) + # 每台机器部署的实例数 + node_replica_count = int(info["shard_num"] / info["shard_machine_group"]) + # 所有shard的实例对应关系 + shards_instance_relationships = [] + # 分配机器 + for index, shard_host_set in enumerate(mongodb_host_set): + # 每组机器获取对应的shards + shards = self.payload["shards_nodes"][index * node_replica_count : (index + 1) * node_replica_count] + for shard in shards: + # 单个shard的实例对应关系 + shard_instance_relationships = [] + for node_index, node in enumerate(shard["nodes"]): + shard_instance_relationships.append( + { + "created_by": self.payload["created_by"], + "bk_biz_id": self.payload["bk_biz_id"], + "node_replica_count": node_replica_count, + "ip": node["ip"], + "bk_cloud_id": node["bk_cloud_id"], + "spec_id": info["machine_specs"]["old_mongodb"]["spec_id"], + "spec_config": info["machine_specs"]["old_mongodb"]["spec_config"], + "target": { + "ip": shard_host_set[node_index]["ip"], + "bk_cloud_id": shard_host_set[node_index]["bk_cloud_id"], + "spec_id": info["machine_specs"]["mongodb"]["spec_id"], + "bk_cpu": shard_host_set[node_index]["bk_cpu"], + "bk_mem": shard_host_set[node_index]["bk_mem"], + "storage_device": shard_host_set[node_index]["storage_device"], + }, + "instances": [ + { + "cluster_id": cluster_id, + "cluster_name": self.payload["cluster_name"], + "seg_range": shard["shard"], + "db_version": info["db_version"], + "domain": node.get("domain", ""), + "port": node["port"], + } + ], + } + ) + shards_instance_relationships.append(shard_instance_relationships) + self.payload["shards_instance_relationships"] = shards_instance_relationships + + def get_host_scale(self, mongodb_type: str, info: dict): + """容量变更获取host信息""" + + hosts = [] + if mongodb_type == ClusterType.MongoReplicaSet.value: + for instance_relationship in self.payload["instance_relationships"]: + # 源ip + hosts.append({"ip": instance_relationship["ip"], "bk_cloud_id": instance_relationship["bk_cloud_id"]}) + # 目标ip + hosts.append( + { + "ip": instance_relationship["target"]["ip"], + "bk_cloud_id": instance_relationship["target"]["bk_cloud_id"], + } + ) + # db版本 + self.payload["db_version"] = self.payload["instance_relationships"][0]["instances"][0]["db_version"] + self.db_main_version = self.payload["db_version"].split(".")[0] + + elif mongodb_type == ClusterType.MongoShardedCluster.value: + hosts_set = set() + bk_cloud_id = info["mongodb"][0][0]["bk_cloud_id"] + for shards_instance_relationships in self.payload["shards_instance_relationships"]: + for instance_relationship in shards_instance_relationships: + hosts_set.add(instance_relationship["ip"]) + hosts_set.add(instance_relationship["target"]["ip"]) + for host in hosts_set: + hosts.append({"ip": host, "bk_cloud_id": bk_cloud_id}) + self.payload["db_version"] = info["db_version"] + self.db_main_version = self.payload["db_version"].split(".")[0] + self.payload["hosts"] = hosts + @dataclass() class CommonContext: diff --git a/dbm-ui/backend/flow/views/mongodb_scene.py b/dbm-ui/backend/flow/views/mongodb_scene.py index 34140105da..e6a612393e 100644 --- a/dbm-ui/backend/flow/views/mongodb_scene.py +++ b/dbm-ui/backend/flow/views/mongodb_scene.py @@ -176,3 +176,15 @@ def post(request): root_id = uuid.uuid1().hex MongoDBController(root_id=root_id, ticket_data=request.data).deinstall_cluster() return Response({"root_id": root_id}) + + +class MongoDBScaleSView(FlowTestView): + """ + mongodb容量变更 + """ + + @staticmethod + def post(request): + root_id = uuid.uuid1().hex + MongoDBController(root_id=root_id, ticket_data=request.data).scale_cluster() + return Response({"root_id": root_id})