├── .codecov.yml ├── .github └── pull_request_template.md ├── .gitignore ├── .golangci.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── LICENSE ├── Makefile ├── Makefile.common ├── NOTICE ├── OWNERS ├── README.md ├── build_helper ├── DEPLOY_TIDB.md ├── GENERATE_CERTS.md ├── add_test_file.sh ├── ca-config.json ├── ca-csr.json ├── check-errdoc.sh ├── check-gogenerate.sh ├── check_testSuite.sh ├── go.mod ├── revive.toml └── server.json ├── common ├── client │ └── client.go ├── constants │ ├── changefeed.go │ ├── changefeed_test.go │ ├── check.go │ ├── cluster.go │ ├── cluster_test.go │ ├── common.go │ ├── datatransfer.go │ ├── metrics.go │ ├── parametergroup.go │ ├── platform.go │ ├── rbac.go │ ├── resource.go │ ├── resource_test.go │ ├── switchover.go │ ├── telemetry.go │ ├── tiup.go │ ├── upgrade.go │ ├── user.go │ └── workflow.go ├── errors │ ├── error.go │ ├── error_test.go │ ├── errorcode.go │ ├── optional.go │ └── optional_test.go └── structs │ ├── check.go │ ├── cluster.go │ ├── cluster_test.go │ ├── common.go │ ├── datatransfer.go │ ├── em.go │ ├── host_label.go │ ├── parametergroup.go │ ├── password.go │ ├── platform.go │ ├── rbac.go │ ├── rbac_test.go │ ├── resource.go │ ├── resource_test.go │ ├── telemetry.go │ ├── user.go │ └── workflow.go ├── deployment ├── attr_linux.go ├── attr_nonlinux.go ├── deploymentImpl.go ├── deploymentImpl_test.go ├── deploymentInterface.go ├── main_test.go ├── status.go └── status_test.go ├── docs ├── design │ ├── backuprestore.md │ ├── backuprestore_chinese.md │ ├── clone.md │ ├── clone_chinese.md │ ├── images │ │ ├── resource_manager │ │ │ ├── Resource_FT_cases.drawio.png │ │ │ ├── Resource_UML_Diagram.drawio.png │ │ │ └── chinese │ │ │ │ ├── allocation_workflow.png │ │ │ │ ├── auth_host_workflow.png │ │ │ │ ├── autofix_workflow.png │ │ │ │ ├── call_deployment_serv_error.jpeg │ │ │ │ ├── cluster_ports_workflow.png │ │ │ │ ├── delete_hosts_workflow.png │ │ │ │ ├── import_hosts_workflow.png │ │ │ │ ├── invalid_zone_error.jpeg │ │ │ │ ├── prepare_workflow.png │ │ │ │ ├── random_rack_workflow.png │ │ │ │ ├── recycle_holder_workflow.png │ │ │ │ ├── recycle_host_workflow.png │ │ │ │ ├── resource_manaager_uml.png │ │ │ │ ├── resource_pool_uml.png │ │ │ │ ├── skip_auth_workflow.png │ │ │ │ ├── user_specify_host_workflow.png │ │ │ │ ├── validate_host_status_error.jpeg │ │ │ │ └── verify_hosts_workflow.png │ │ └── switchover │ │ │ ├── master-slave-switchover-workflow-diagram-en.png │ │ │ ├── master-slave-switchover-workflow-diagram.png │ │ │ ├── switchover-demo.png │ │ │ ├── switchover-ft-en.png │ │ │ ├── switchover-ft.png │ │ │ └── switchover-rollback-successfully.png │ ├── importexport.md │ ├── importexport_chinese.md │ ├── product.md │ ├── resources.md │ ├── resources_chinese.md │ ├── scale.md │ ├── scale_chinese.md │ ├── switchover-zh.md │ ├── switchover.md │ ├── workflow.md │ └── workflow_chinese.md ├── docs.go ├── img │ ├── opentrace1.png │ ├── opentrace2.png │ └── tiunimanager.svg ├── openapi │ ├── backuprestore.md │ ├── changefeed.md │ ├── clone.md │ ├── cluster.md │ ├── clusterlog.md │ ├── clusterparameter.md │ ├── importexport.md │ ├── parametergroup.md │ ├── product.md │ ├── resourcemanager.md │ ├── scale.md │ ├── switchover.md │ ├── upgrade.md │ ├── user.md │ └── workflow.md ├── swagger.json ├── swagger.md └── swagger.yaml ├── file-server ├── common │ └── common.go ├── controller │ ├── common.go │ ├── file │ │ └── file_api.go │ └── httpresult.go ├── interceptor │ ├── access.go │ ├── audit.go │ ├── auth.go │ ├── opentracing.go │ ├── security.go │ └── trace-id.go ├── main.go ├── route │ └── router.go └── service │ ├── dir_manager.go │ └── file_manager.go ├── go.mod ├── go.sum ├── library ├── framework │ ├── args.go │ ├── args_test.go │ ├── assert.go │ ├── assert_test.go │ ├── certificate.go │ ├── certificate_test.go │ ├── configcenter.go │ ├── configcenter_test.go │ ├── elasticsearch.go │ ├── elasticsearch_test.go │ ├── etcd_client.go │ ├── framework.go │ ├── framework_test.go │ ├── log.go │ ├── log_test.go │ ├── meta.go │ ├── meta_test.go │ ├── newlog.go │ ├── tracer.go │ └── tracer_test.go ├── spec │ └── instance.go └── util │ ├── tiup.go │ └── tso │ └── tso.go ├── message ├── check.go ├── cluster │ ├── backuprestore.go │ ├── changefeed.go │ ├── changefeed_test.go │ ├── cluster.go │ └── upgrade.go ├── dataapps │ └── sqleditor │ │ └── sqleditor.go ├── datatransfer.go ├── log.go ├── parametergroup.go ├── platform.go ├── rbac.go ├── resource.go ├── user.go └── workflow.go ├── metrics ├── define.go ├── metrics.go └── metrics_test.go ├── micro-api ├── controller │ ├── cluster │ │ ├── alert │ │ │ └── alert_api.go │ │ ├── backuprestore │ │ │ └── backup_restore_api.go │ │ ├── changefeed │ │ │ └── changefeed_api.go │ │ ├── instance │ │ │ └── components_api.go │ │ ├── log │ │ │ └── log_api.go │ │ ├── management │ │ │ └── cluster_api.go │ │ ├── monitor │ │ │ └── monitor_api.go │ │ ├── parameter │ │ │ └── parameter_api.go │ │ ├── performance │ │ │ └── performance_api.go │ │ ├── switchover │ │ │ └── switchover_api.go │ │ └── upgrade │ │ │ └── upgrade_api.go │ ├── common.go │ ├── dataapps │ │ └── sqleditor │ │ │ └── sqleditor_api.go │ ├── datatransfer │ │ └── importexport │ │ │ └── import_export_api.go │ ├── httprequest.go │ ├── httpresult.go │ ├── invokerpc.go │ ├── parametergroup │ │ └── parametergroup_api.go │ ├── platform │ │ ├── check_api.go │ │ ├── config │ │ │ └── config_api.go │ │ ├── dignose │ │ │ ├── log_api.go │ │ │ └── monitor_api.go │ │ ├── product │ │ │ └── product_api.go │ │ └── system │ │ │ └── system_api.go │ ├── resource │ │ ├── hostresource │ │ │ ├── consts.go │ │ │ └── resource_api.go │ │ └── warehouse │ │ │ └── resource_stock_api.go │ ├── task │ │ ├── crontask │ │ │ └── crontask_api.go │ │ └── flowtask │ │ │ └── flowtask_api.go │ └── user │ │ ├── identification_api.go │ │ ├── rbac │ │ └── rbac_api.go │ │ ├── tenant_api.go │ │ └── user_api.go ├── interceptor │ ├── access.go │ ├── audit.go │ ├── auth.go │ ├── opentracing.go │ ├── security.go │ ├── system.go │ └── trace-id.go ├── main.go └── route │ └── router.go ├── micro-cluster ├── cluster │ ├── backuprestore │ │ ├── autobackup.go │ │ ├── autobackup_test.go │ │ ├── common.go │ │ ├── executor.go │ │ ├── executor_test.go │ │ ├── manager.go │ │ ├── manager_test.go │ │ └── service.go │ ├── changefeed │ │ ├── manager.go │ │ ├── manager_test.go │ │ ├── service.go │ │ └── service_test.go │ ├── log │ │ ├── common.go │ │ ├── executor.go │ │ ├── executor_test.go │ │ ├── main_test.go │ │ ├── manager.go │ │ └── manager_test.go │ ├── management │ │ ├── dashboard.go │ │ ├── dashboard_test.go │ │ ├── executor.go │ │ ├── executor_test.go │ │ ├── main_test.go │ │ ├── manager.go │ │ ├── manager_test.go │ │ ├── meta │ │ │ ├── common.go │ │ │ ├── common_test.go │ │ │ ├── main_test.go │ │ │ ├── meta.go │ │ │ ├── meta_test.go │ │ │ ├── metabuilder.go │ │ │ ├── metaconfig.go │ │ │ ├── metadisplay.go │ │ │ ├── metadisplay_test.go │ │ │ ├── metaoperation.go │ │ │ └── metaresource.go │ │ ├── validator.go │ │ └── validator_test.go │ ├── parameter │ │ ├── common.go │ │ ├── common_test.go │ │ ├── executor.go │ │ ├── executor_test.go │ │ ├── main_test.go │ │ ├── manager.go │ │ └── manager_test.go │ └── switchover │ │ ├── cdc_manager_api.go │ │ ├── check_db_writable.go │ │ ├── switchover.go │ │ ├── switchover_test.go │ │ ├── workflow.go │ │ └── workflow_test.go ├── dataapps │ └── sqleditor │ │ ├── main_test.go │ │ ├── manager.go │ │ └── manager_test.go ├── datatransfer │ └── importexport │ │ ├── common.go │ │ ├── excutor_test.go │ │ ├── executor.go │ │ ├── lightning.go │ │ ├── lightning_test.go │ │ ├── manager.go │ │ ├── manager_test.go │ │ └── service.go ├── main.go ├── parametergroup │ ├── common.go │ ├── manager.go │ └── manager_test.go ├── platform │ ├── check │ │ ├── autocheck.go │ │ ├── executor.go │ │ ├── executor_test.go │ │ ├── handler.go │ │ ├── handler_test.go │ │ ├── main_test.go │ │ ├── manager.go │ │ ├── manager_test.go │ │ └── service.go │ ├── config │ │ ├── manager.go │ │ └── manager_test.go │ ├── log │ │ ├── main_test.go │ │ ├── manager.go │ │ └── manager_test.go │ ├── product │ │ ├── main_test.go │ │ ├── manager.go │ │ └── manager_test.go │ ├── system │ │ ├── main_test.go │ │ ├── statemachine.go │ │ ├── statemachine_test.go │ │ ├── system.go │ │ └── system_test.go │ └── telemetry │ │ └── telemetry.go ├── registry │ ├── embed_etcd.go │ └── embed_etcd_test.go ├── resourcemanager │ ├── inspect │ │ ├── hostinspector.go │ │ ├── inspect.go │ │ └── inspect_test.go │ ├── main_test.go │ ├── management │ │ ├── allocator_recycler │ │ │ └── localhost_management.go │ │ ├── management.go │ │ └── structs │ │ │ ├── allocator_recycler.go │ │ │ ├── request.go │ │ │ └── response.go │ ├── manager_implement.go │ ├── manager_test.go │ └── resourcepool │ │ ├── constants │ │ └── const.go │ │ ├── executor.go │ │ ├── executor_test.go │ │ ├── hostinitiator │ │ ├── auth_host.go │ │ ├── auth_host_test.go │ │ ├── auto_fix.go │ │ ├── build_template.go │ │ ├── file_hostinitiator.go │ │ ├── file_hostinitiator_test.go │ │ └── hostinitiator.go │ │ ├── hostprovider │ │ ├── file_hostprovider.go │ │ ├── file_hostprovider_test.go │ │ └── hostprovider.go │ │ ├── resourcepool.go │ │ └── resourcepool_test.go ├── service │ ├── clusterservice.go │ └── clusterservice_test.go └── user │ ├── account │ ├── main_test.go │ ├── manager.go │ └── manager_test.go │ ├── identification │ ├── main_test.go │ ├── manager.go │ └── manager_test.go │ └── rbac │ ├── common.go │ ├── main_test.go │ ├── manager.go │ ├── manager_test.go │ └── service.go ├── models ├── cluster │ ├── alert │ │ └── readerwriter.go │ ├── backuprestore │ │ ├── backuprecord.go │ │ ├── backuprestore_readwrite.go │ │ ├── backuprestore_readwrite_test.go │ │ ├── backupstrategy.go │ │ ├── main_test.go │ │ └── readerwriter.go │ ├── changefeed │ │ ├── changefeedtask.go │ │ ├── changefeedtask_test.go │ │ ├── main_test.go │ │ ├── readerwriter.go │ │ └── readwriteimpl.go │ ├── log │ │ └── readerwriter.go │ ├── management │ │ ├── cluster.go │ │ ├── clusterinstance.go │ │ ├── clusterinstance_test.go │ │ ├── clusterrelation.go │ │ ├── clustertopologysnapshot.go │ │ ├── clusteruser.go │ │ ├── main_test.go │ │ ├── querymodel.go │ │ ├── readerwriter.go │ │ ├── readwriteimpl.go │ │ └── readwriteimpl_test.go │ ├── monitor │ │ └── readerwriter.go │ ├── parameter │ │ ├── clusterparameter_mapping.go │ │ ├── main_test.go │ │ ├── readerwriter.go │ │ ├── readwriteimpl.go │ │ └── readwriteimpl_test.go │ ├── performance │ │ └── readerwriter.go │ └── upgrade │ │ ├── main_test.go │ │ ├── product_upgrade_path.go │ │ ├── product_upgrade_path_test.go │ │ ├── readerwriter.go │ │ └── readwriteimpl.go ├── common │ ├── common.go │ └── common_test.go ├── dataapps │ └── sqleditor │ │ ├── dbagent │ │ ├── main_test.go │ │ ├── readerwriter.go │ │ ├── readwriteimpl.go │ │ ├── readwriteimpl_test.go │ │ ├── sessioncache.go │ │ └── sessioncache_test.go │ │ └── sqlfile │ │ ├── main_test.go │ │ ├── readerwriter.go │ │ ├── readwriteimpl.go │ │ ├── readwriteimpl_test.go │ │ └── sqleditorfile.go ├── database.go ├── database_test.go ├── datatransfer │ └── importexport │ │ ├── datatransportrecord.go │ │ ├── importexport_readwrite.go │ │ ├── importexport_readwrite_test.go │ │ ├── main_test.go │ │ └── readerwriter.go ├── initdata.go ├── initdata_test.go ├── parametergroup │ ├── main_test.go │ ├── parameter.go │ ├── parametergroup.go │ ├── parametergroup_mapping.go │ ├── readerwriter.go │ ├── readwriteimpl.go │ └── readwriteimpl_test.go ├── platform │ ├── check │ │ ├── main_test.go │ │ ├── report.go │ │ ├── report_read_writer.go │ │ └── report_read_writer_test.go │ ├── config │ │ ├── config_readwrite.go │ │ ├── config_readwrite_test.go │ │ ├── main_test.go │ │ ├── readerwriter.go │ │ └── systemconfig.go │ ├── dignose │ │ └── readerwriter.go │ ├── product │ │ ├── main_test.go │ │ ├── product.go │ │ ├── readerwriter.go │ │ ├── readwriteimpl.go │ │ ├── readwriteimpl_test.go │ │ └── vendor.go │ └── system │ │ ├── info.go │ │ ├── main_test.go │ │ ├── readerwriter.go │ │ ├── readwriteimpl.go │ │ ├── readwriteimpl_test.go │ │ └── version.go ├── resource │ ├── gormreadwrite │ │ ├── alloc_readwrite.go │ │ ├── allocrecycle_test.go │ │ ├── inspect_readwrite.go │ │ ├── inspect_test.go │ │ ├── main_test.go │ │ ├── recycle_readwrite.go │ │ └── resource_readewrite.go │ ├── management │ │ └── used_resource.go │ ├── readerwriter.go │ └── resourcepool │ │ ├── disk.go │ │ ├── disk_test.go │ │ ├── host.go │ │ ├── host_label.go │ │ └── host_test.go ├── tiup │ ├── main_test.go │ ├── readerwriter.go │ ├── readwriteimpl.go │ ├── tiup.go │ └── tiup_test.go ├── user │ ├── account │ │ ├── account.go │ │ ├── account_test.go │ │ ├── main_test.go │ │ ├── readerwriter.go │ │ ├── readwriteimpl.go │ │ └── readwriteimpl_test.go │ ├── identification │ │ ├── main_test.go │ │ ├── readerwriter.go │ │ ├── readwriteimpl.go │ │ ├── readwriteimpl_test.go │ │ └── token.go │ └── rbac │ │ ├── main_test.go │ │ ├── rbac.go │ │ ├── rbac_readwrite.go │ │ ├── rbac_readwrite_test.go │ │ └── readerwriter.go └── workflow │ ├── main_test.go │ ├── readerwriter.go │ ├── secondparty │ ├── main_test.go │ ├── readerwriter.go │ ├── readwriteimpl.go │ ├── second_party_operation.go │ └── second_party_operation_test.go │ ├── workflow.go │ ├── workflow_readwrite.go │ ├── workflow_readwrite_test.go │ ├── workflow_test.go │ └── workflownode.go ├── proto └── clusterservices.proto ├── quick_run.sh ├── resource ├── hostInfo_template.xlsx ├── prchecklist.md └── template │ ├── cluster_check.go │ ├── cluster_topology.go │ └── import_topology.go ├── scripts ├── parameters.sql ├── parameters_v1.0.0-beta.11.sql ├── parameters_v1.0.0-beta.13.sql ├── parameters_v1.0.1.sql ├── parameters_v1.0.2.sql ├── tiup_configs.sql └── upgrades.sql ├── util ├── api │ ├── cdc │ │ ├── changefeed.go │ │ ├── changefeed_test.go │ │ ├── clusterconfig.go │ │ └── clusterconfig_test.go │ ├── pd │ │ ├── clusterconfig.go │ │ └── clusterconfig_test.go │ ├── tidb │ │ ├── http │ │ │ ├── clusterconfig.go │ │ │ └── clusterconfig_test.go │ │ └── sql │ │ │ ├── backuprestore.go │ │ │ ├── clusterconfig.go │ │ │ ├── clusterconfig_test.go │ │ │ ├── clusteruser.go │ │ │ ├── clusteruser_test.go │ │ │ └── common.go │ └── tikv │ │ ├── clusterconfig.go │ │ └── clusterconfig_test.go ├── bitmap │ ├── concurrent.go │ ├── concurrent_test.go │ └── main_test.go ├── checksum │ ├── checksum.go │ ├── checksum_test.go │ └── main_test.go ├── convert │ ├── convert.go │ └── convert_test.go ├── disk │ ├── tempDir.go │ ├── tempDir_test.go │ ├── tempFile.go │ ├── tempFile_test.go │ └── tracker.go ├── encrypt │ ├── aes.go │ ├── aes_crypto.go │ ├── aes_crypto_test.go │ ├── aes_layer.go │ ├── aes_layer_test.go │ ├── aes_test.go │ ├── crypt.go │ └── crypt_test.go ├── fastrand │ ├── main_test.go │ ├── random.go │ └── random_test.go ├── format │ ├── format.go │ ├── format_test.go │ └── main_test.go ├── http │ ├── http.go │ └── http_test.go ├── israce │ ├── israce.go │ └── norace.go ├── kvcache │ ├── main_test.go │ ├── simple_lru.go │ └── simple_lru_test.go ├── math │ ├── main_test.go │ ├── math.go │ └── math_test.go ├── misc.go ├── misc_test.go ├── pdapi │ └── const.go ├── printer │ ├── main_test.go │ ├── printer.go │ └── printer_test.go ├── scp │ └── scp.go ├── signal │ ├── signal_posix.go │ └── signal_windows.go ├── slice │ ├── main_test.go │ ├── slice.go │ └── slice_test.go ├── ssh │ └── ssh_client.go ├── stringutil │ ├── main_test.go │ ├── string_util.go │ └── string_util_test.go ├── sys │ ├── linux │ │ ├── main_test.go │ │ ├── sys_linux.go │ │ ├── sys_other.go │ │ └── sys_test.go │ └── storage │ │ ├── main_test.go │ │ ├── sys_other.go │ │ ├── sys_posix.go │ │ ├── sys_test.go │ │ └── sys_windows.go ├── systimemon │ ├── systime_mon.go │ └── systime_mon_test.go ├── testbridge │ └── bridge.go ├── testkit │ └── fake.go ├── testleak │ ├── add-leaktest.sh │ ├── check-leaktest.sh │ └── leaktest.go ├── timeutil │ ├── time.go │ └── time_test.go ├── tracing │ ├── main_test.go │ ├── noop_bench_test.go │ ├── util.go │ └── util_test.go ├── uuidutil │ ├── idgenerator.go │ └── idgenerator_test.go └── versioninfo │ └── versioninfo.go ├── workflow ├── aggregation.go ├── common.go ├── definition.go ├── workflow.go └── workflow_test.go └── workflow2 ├── common.go ├── definition.go ├── meta.go ├── meta_test.go ├── service.go ├── workflow.go └── workflow_test.go /.codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | notify: 3 | require_ci_to_pass: yes 4 | 5 | coverage: 6 | precision: 4 7 | round: down 8 | 9 | status: 10 | project: 11 | default: 12 | threshold: 3 #Allow the coverage to drop by threshold%, and posting a success status. 13 | patch: 14 | default: 15 | target: 0% 16 | changes: no 17 | 18 | parsers: 19 | gcov: 20 | branch_detection: 21 | conditional: yes 22 | loop: yes 23 | method: no 24 | macro: no 25 | 26 | comment: 27 | layout: "header, diff" 28 | behavior: default 29 | require_changes: no 30 | 31 | ignore: 32 | - "LICENSES" 33 | - "*_test.go" 34 | - "*.pb.go" 35 | - ".git" 36 | - "*.yaml" 37 | - "*.toml" 38 | - "*.md" 39 | - "docs/.*" 40 | - "testing_utils/.*" 41 | - "micro-api/controller/.*" 42 | - "resource/template/.*" 43 | - "proto/.*" 44 | - "*.xlsx" 45 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## What have you changed? (mandatory) 2 | 3 | Please explain **IN DETAIL** what the changes are in this PR and why they are needed: 4 | 5 | - Summarize your change (mandatory) 6 | - How does this PR work? Need a brief introduction for the changed logic (optional) 7 | - Describe clearly one logical change and avoid lazy messages (optional) 8 | - Describe any limitations of the current code (optional) 9 | 10 | Please NOTE that: 11 | 12 | - Do not assume the code is self-evident 13 | - Do not assume reviewers understand the original issue 14 | 15 | ## What are the type of the changes? (mandatory) 16 | 17 | The currently defined types are listed below, please pick one of the types for this PR by removing the others: 18 | 19 | - New feature (non-breaking change which adds functionality) 20 | - Improvement (non-breaking change which is an improvement to an existing feature) 21 | - Bug fix (non-breaking change which fixes an issue) 22 | - Breaking change (fix or feature that would cause existing functionality to not work as expected) 23 | 24 | ## How has this PR been tested? (mandatory) 25 | 26 | Please describe the tests that you ran to verify your changes. Have you finished unit tests, integration tests, or manual tests? 27 | 28 | ## Does this PR affect documentation (docs/docs-cn) update? (mandatory) 29 | 30 | If there is document change, please file a PR in ([docs](https://github.com/pingcap/docs) and [docs-cn](https://github.com/pingcap/docs-cn)) and add the PR number here. 31 | 32 | ## Refer to a related PR or issue link (optional) 33 | 34 | ## Benchmark result if necessary (optional) 35 | 36 | ## Add a few positive/negative examples (optional) 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /tiunimanager.iml 2 | .DS_Store 3 | golangci-lint-report.xml 4 | results.xml 5 | .github/ISSUE_TEMPLATE 6 | .idea/ 7 | data.etcd1/ 8 | *.db 9 | /bin 10 | *.log 11 | /proto/clusterservices 12 | /micro-cluster/user/userinfo/testdata/ 13 | etcd/ 14 | /dbtest123.yaml 15 | library/client/cluster 16 | library/client/metadb 17 | library/framework/logs 18 | library/secondparty/logs 19 | test/ 20 | /template 21 | /nohup.out 22 | .vscode/ 23 | /log 24 | logs/ 25 | out.txt 26 | run.sh 27 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | # options for analysis running 2 | run: 3 | timeout: 10m 4 | skip-dirs: 5 | - test 6 | skip-files: 7 | - ".*_test\\.go$" 8 | 9 | linters: 10 | enable: 11 | #- misspell 12 | - ineffassign 13 | - typecheck 14 | - varcheck 15 | - unused 16 | - structcheck 17 | - deadcode 18 | - gosimple 19 | #- goimports 20 | - staticcheck 21 | #- stylecheck 22 | #- gosec 23 | disable: 24 | - errcheck 25 | - govet 26 | 27 | linters-settings: 28 | 29 | staticcheck: 30 | # Select the Go version to target. The default is '1.13'. 31 | go: "1.16" 32 | # https://staticcheck.io/docs/options#checks 33 | checks: [ "all" ] 34 | 35 | stylecheck: 36 | # Select the Go version to target. The default is '1.13'. 37 | go: "1.16" 38 | # https://staticcheck.io/docs/options#checks 39 | checks: [ "all"] 40 | 41 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | See the [Contributor Covenant Code of Conduct](https://github.com/pingcap/community/blob/master/CODE_OF_CONDUCT.md) -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guide 2 | 3 | See the [Contribution Guide](https://github.com/pingcap/community/blob/master/contributors/README.md) in the 4 | [community](https://github.com/pingcap/community) repo. -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | See [TiDB Contributors](https://contributor.tidb.io/people/contributor) -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | approvers: 3 | # - tiunimanager-maintainers 4 | - haiboumich 5 | - Yuiham 6 | # - tiunimanager-committers 7 | - cchenkey 8 | - zhangpeijin-milo 9 | reviewers: 10 | # - tiunimanager-reviewers 11 | - scsldb 12 | -------------------------------------------------------------------------------- /build_helper/GENERATE_CERTS.md: -------------------------------------------------------------------------------- 1 | ## 1. Make `cert` directory 2 | 3 | make sure that you are in the project's root path 4 | 5 | ```shell 6 | mkdir -p bin/cert 7 | cd bin/cert/ 8 | ``` 9 | 10 | ## 2. Generate server.crt, server.csr, server.key 11 | 12 | make sure that you are in the directory `/bin/cert` 13 | 14 | ```shell 15 | openssl genrsa -out rootCA.key 2048 16 | openssl req -x509 -new -nodes -key rootCA.key -days 1024 -out rootCA.pem -subj '/CN=em-server/O=PingCAP/C=CN' 17 | openssl genrsa -out server.key 2048 18 | openssl req -new -key server.key -out server.csr -subj '/CN=em-server/O=PingCAP/C=CN' 19 | openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 3650 20 | ``` 21 | 22 | ## 3. Generate aes.key 23 | 24 | make sure that you are in the directory `/bin/cert` 25 | 26 | ```shell 27 | echo $RANDOM | md5sum | head -c 32 > aes.key 28 | ``` 29 | 30 | ## 4. Generate etcd-ca.pem, etcd-server-key.pem, etcd-server.pem 31 | 32 | > You may need to generate executable `cfssl` and `cfssljson` by following [cfssl](https://github.com/cloudflare/cfssl/) before execute the commands below. 33 | 34 | make sure that you are in the directory `/bin/cert` 35 | 36 | ```shell 37 | cfsslBinPath= 38 | ${cfsslBinPath}/cfssl gencert -initca ../../build_helper/ca-csr.json | ${cfsslBinPath}/cfssljson -bare etcd-ca - 39 | ${cfsslBinPath}/cfssl gencert -ca=etcd-ca.pem -ca-key=etcd-ca-key.pem --config=../../build_helper/ca-config.json -profile=server ../../build_helper/server.json | ${cfsslBinPath}/cfssljson -bare etcd-server 40 | ``` -------------------------------------------------------------------------------- /build_helper/add_test_file.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2021 PingCAP 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # 16 | 17 | find . -name "*.go" | grep -vE "proto|docs|library/util" | while read fname; do 18 | fpath=`dirname $fname` 19 | firstline=$(sed -n -e '/^package/p' $fname) 20 | # if [ ! -f "$fpath/main_test.go" ]; then 21 | if ls $fpath/*_test.go 1> /dev/null 2>&1; then 22 | echo "no need to add main_test.go file in $fpath" 23 | else 24 | echo $firstline > $fpath/main_test.go 25 | echo "import \"testing\"" >> $fpath/main_test.go 26 | echo "func Test_Main(t *testing.T) {}" >> $fpath/main_test.go 27 | fi 28 | done -------------------------------------------------------------------------------- /build_helper/ca-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "signing": { 3 | "default": { 4 | "expiry": "1680000h" 5 | }, 6 | "profiles": { 7 | "server": { 8 | "expiry": "1680000h", 9 | "usages": [ 10 | "signing", 11 | "key encipherment", 12 | "server auth", 13 | "client auth" 14 | ] 15 | } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /build_helper/ca-csr.json: -------------------------------------------------------------------------------- 1 | { 2 | "CN": "etcd-root", 3 | "key": { 4 | "algo": "rsa", 5 | "size": 2048 6 | }, 7 | "names": [ 8 | { 9 | "C": "CN", 10 | "ST": "BeiJing", 11 | "L": "BeiJing", 12 | "O": "pingcap-tiem" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /build_helper/check-errdoc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright (c) 2021 PingCAP 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | set -euo pipefail 18 | 19 | cd -P . 20 | 21 | cp tiunimanager_errors.toml /tmp/tiunimanager_errors.toml.before 22 | bin/errdoc-gen --source . --module github.com/pingcap/tiunimanager --output tiunimanager_errors.toml 23 | diff -q errors.toml /tmp/errors.toml.before 24 | -------------------------------------------------------------------------------- /build_helper/check-gogenerate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright (c) 2021 PingCAP 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | 18 | set -euo pipefail 19 | 20 | go generate ./... 21 | set +e 22 | diffline=$(git status -s | awk '{print $2}' | xargs grep '^// Code generated .* DO NOT EDIT\.$' 2>/dev/null) 23 | set -e 24 | if [[ $diffline != "" ]] 25 | then 26 | echo "Your commit is changed after running go generate ./..., it should not happen." 27 | exit 1 28 | fi 29 | -------------------------------------------------------------------------------- /build_helper/check_testSuite.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright (c) 2021 PingCAP 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | 18 | set -euo pipefail 19 | 20 | exitCode=0 21 | 22 | list=$(find . -name "*_test.go" -not -path "./vendor/*" -print0 | xargs -0 grep -E "type test(.*)Suite" | awk -F ':| ' '{print $1" "$3}') 23 | while read -r file testSuite; do 24 | # TODO: ugly regex 25 | # TODO: check code comment 26 | dir=$(dirname "$file") 27 | if ! find "$dir" -name "*_test.go" -print0 | xargs -0 grep -E "_ = (check\.)?(Suite|SerialSuites)\((&?${testSuite}{|new\(${testSuite}\))" > /dev/null 28 | then 29 | if find "$dir" -name "*_test.go" -print0 | xargs -0 grep -E "func \((.* )?\*?${testSuite}\) Test" > /dev/null 30 | then 31 | echo "${testSuite} in ${dir} is not enabled" && exitCode=1 32 | fi 33 | fi 34 | done <<< "$list" 35 | exit ${exitCode} 36 | -------------------------------------------------------------------------------- /build_helper/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/pingcap/tidb/_tools 2 | 3 | go 1.16 4 | -------------------------------------------------------------------------------- /build_helper/revive.toml: -------------------------------------------------------------------------------- 1 | ignoreGeneratedHeader = false 2 | severity = "error" 3 | confidence = 0.8 4 | errorCode = -1 5 | warningCode = -1 6 | 7 | [rule.blank-imports] 8 | [rule.context-as-argument] 9 | [rule.dot-imports] 10 | [rule.error-return] 11 | [rule.error-strings] 12 | [rule.error-naming] 13 | [rule.exported] 14 | [rule.if-return] 15 | [rule.var-naming] 16 | [rule.package-comments] 17 | [rule.range] 18 | [rule.receiver-naming] 19 | [rule.indent-error-flow] 20 | [rule.superfluous-else] 21 | [rule.modifies-parameter] 22 | 23 | # This can be checked by other tools like megacheck 24 | [rule.unreachable-code] 25 | 26 | 27 | # Currently this makes too much noise, but should add it in 28 | # and perhaps ignore it in a few files 29 | #[rule.confusing-naming] 30 | # severity = "warning" 31 | #[rule.confusing-results] 32 | # severity = "warning" 33 | #[rule.unused-parameter] 34 | # severity = "warning" 35 | #[rule.deep-exit] 36 | # severity = "warning" 37 | #[rule.flag-parameter] 38 | # severity = "warning" 39 | 40 | 41 | 42 | # Adding these will slow down the linter 43 | # They are already provided by megacheck 44 | # [rule.unexported-return] 45 | # [rule.time-naming] 46 | # [rule.errorf] 47 | 48 | # Adding these will slow down the linter 49 | # Not sure if they are already provided by megacheck 50 | # [rule.var-declaration] 51 | # [rule.context-keys-type] 52 | -------------------------------------------------------------------------------- /build_helper/server.json: -------------------------------------------------------------------------------- 1 | { 2 | "CN": "etcd-server", 3 | "hosts":[""], 4 | "key": { 5 | "algo": "rsa", 6 | "size": 2048 7 | }, 8 | "names": [ 9 | { 10 | "C": "CN", 11 | "ST": "BeiJing", 12 | "L": "BeiJing", 13 | "O": "tiem-server" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /common/client/client.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package client 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/proto/clusterservices" 20 | ) 21 | 22 | var ClusterClient clusterservices.ClusterService 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/constants/changefeed_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package constants 17 | 18 | import ( 19 | "reflect" 20 | "testing" 21 | ) 22 | 23 | func TestUnfinishedChangeFeedStatus(t *testing.T) { 24 | tests := []struct { 25 | name string 26 | want []ChangeFeedStatus 27 | }{ 28 | {"normal", []ChangeFeedStatus{ 29 | ChangeFeedStatusInitial,ChangeFeedStatusNormal,ChangeFeedStatusStopped,ChangeFeedStatusError, 30 | }}, 31 | } 32 | for _, tt := range tests { 33 | t.Run(tt.name, func(t *testing.T) { 34 | if got := UnfinishedChangeFeedStatus(); !reflect.DeepEqual(got, tt.want) { 35 | t.Errorf("UnfinishedChangeFeedStatus() = %v, want %v", got, tt.want) 36 | } 37 | }) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /common/constants/check.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package constants 17 | 18 | const ( 19 | FlowCheckPlatform = "CheckPlatform" 20 | FlowCheckCluster = "CheckCluster" 21 | ) 22 | 23 | type CheckStatus string 24 | 25 | const ( 26 | CheckRunning CheckStatus = "Running" 27 | CheckFailure CheckStatus = "Failure" 28 | CheckCompleted CheckStatus = "Completed" 29 | ) 30 | 31 | type ReportType string 32 | 33 | const ( 34 | PlatformReport ReportType = "Platform" 35 | ClusterReport ReportType = "Cluster" 36 | ) 37 | -------------------------------------------------------------------------------- /common/constants/cluster_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | /******************************************************************************* 17 | * @File: cluster_test.go 18 | * @Description: 19 | * @Author: zhangpeijin@pingcap.com 20 | * @Version: 1.0.0 21 | * @Date: 2022/2/11 22 | *******************************************************************************/ 23 | 24 | package constants 25 | 26 | import ( 27 | "encoding/json" 28 | "github.com/stretchr/testify/assert" 29 | "testing" 30 | ) 31 | 32 | func Test_Config(t *testing.T) { 33 | ports := make([]int, 2) 34 | err := json.Unmarshal([]byte(DefaultRetainedPortRange), &ports) 35 | assert.NoError(t, err) 36 | assert.Equal(t, []int{11000, 12000}, ports) 37 | } -------------------------------------------------------------------------------- /common/constants/parametergroup.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | /******************************************************************************* 17 | * @File: parametergroup.go 18 | * @Description: 19 | * @Author: duanbing@pingcap.com 20 | * @Version: 1.0.0 21 | * @Date: 2021/12/4 22 | *******************************************************************************/ 23 | 24 | package constants 25 | -------------------------------------------------------------------------------- /common/constants/telemetry.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License * 14 | * * 15 | ******************************************************************************/ 16 | 17 | /******************************************************************************* 18 | * @File: telemetry.go 19 | * @Description: 20 | * @Author: duanbing@pingcap.com 21 | * @Version: 1.0.0 22 | * @Date: 2021/12/21 23 | *******************************************************************************/ 24 | 25 | package constants 26 | 27 | const ( 28 | // TelemetryAPIEndpoint Report address information to Telemetry, without username and password 29 | TelemetryAPIEndpoint string = "https://telemetry.pingcap.com/api/v1/em/report" 30 | 31 | // TelemetrySwitchEnable telemetry switch 32 | TelemetrySwitchEnable string = "enable" 33 | TelemetrySwitchDisable string = "disable" 34 | ) 35 | -------------------------------------------------------------------------------- /common/constants/tiup.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | /******************************************************************************* 17 | * @File: tiup.go 18 | * @Description: 19 | * @Author: shenhaibo@pingcap.com 20 | * @Version: 1.0.0 21 | * @Date: 2021/12/12 22 | *******************************************************************************/ 23 | 24 | package constants 25 | 26 | const ( 27 | TiUPBinPath = "tiup" 28 | TiUPTopologyTmpFilePrefix = "em-topology" 29 | TiUPCollectorTmpFilePrefix = "em-collector" 30 | 31 | DefaultTiUPHome string = "/home/tidb/.tiup" 32 | DefaultEMHome string = "/home/tidb/.em" 33 | ) 34 | 35 | type EMInstanceStatus string 36 | 37 | const ( 38 | EMInstanceUP EMInstanceStatus = "Up" 39 | EMInstanceDown EMInstanceStatus = "Down" 40 | ) 41 | 42 | const ( 43 | EMInstanceNameOfFileBeat string = "filebeat" 44 | ) 45 | -------------------------------------------------------------------------------- /common/constants/upgrade.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | /******************************************************************************* 18 | * @File: upgrade 19 | * @Description: 20 | * @Author: shenhaibo@pingcap.com 21 | * @Version: 1.0.0 22 | * @Date: 2021/12/14 23 | *******************************************************************************/ 24 | 25 | package constants 26 | 27 | type UpgradeType string 28 | 29 | type UpgradeWayStr string 30 | 31 | const ( 32 | UpgradeTypeInPlace UpgradeType = "in-place" 33 | UpgradeTypeMigration UpgradeType = "migration" 34 | UpgradeWayOffline UpgradeWayStr = "offline" 35 | UpgradeWayOnline UpgradeWayStr = "online" 36 | ) 37 | -------------------------------------------------------------------------------- /common/constants/workflow.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | /******************************************************************************* 17 | * @File: workflow.go 18 | * @Description: 19 | * @Author: duanbing@pingcap.com 20 | * @Version: 1.0.0 21 | * @Date: 2021/12/4 22 | *******************************************************************************/ 23 | 24 | package constants 25 | 26 | type WorkFlowStatus string 27 | 28 | //Definition workflow status information 29 | const ( 30 | WorkFlowStatusInitializing = "Initializing" 31 | WorkFlowStatusProcessing = "Processing" 32 | WorkFlowStatusCanceling = "Canceling" 33 | WorkFlowStatusFinished = "Finished" 34 | WorkFlowStatusError = "Error" 35 | WorkFlowStatusCanceled = "Canceled" 36 | WorkFlowStatusStopped = "Stopped" 37 | ) 38 | -------------------------------------------------------------------------------- /common/structs/password.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | /******************************************************************************* 17 | * @File: password.go 18 | * @Description: 19 | * @Author: zhangpeijin@pingcap.com 20 | * @Version: 1.0.0 21 | * @Date: 2022/3/30 22 | *******************************************************************************/ 23 | 24 | package structs 25 | 26 | import ( 27 | jsoniter "github.com/json-iterator/go" 28 | "unsafe" 29 | ) 30 | 31 | type SensitiveText string 32 | 33 | type SensitiveTextEncoder struct {} 34 | 35 | func (p SensitiveTextEncoder) IsEmpty(ptr unsafe.Pointer) bool { 36 | s := *((*string)(ptr)) 37 | return len(s) == 0 38 | } 39 | 40 | func (p SensitiveTextEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) { 41 | stream.WriteString("******") 42 | } 43 | -------------------------------------------------------------------------------- /common/structs/rbac.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package structs 17 | 18 | import "github.com/pingcap/tiunimanager/common/constants" 19 | 20 | type RbacPermission struct { 21 | Resource string `json:"resource"` 22 | Action string `json:"action"` 23 | } 24 | 25 | func (permission *RbacPermission) CheckInvalid() bool { 26 | _, resourceExist := constants.RbacResourceMap[permission.Resource] 27 | _, actionExist := constants.RbacActionMap[permission.Action] 28 | return resourceExist && actionExist 29 | } 30 | -------------------------------------------------------------------------------- /common/structs/rbac_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package structs 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/common/constants" 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestRbacPermission_CheckInvalid(t *testing.T) { 25 | permission := &RbacPermission{ 26 | Resource: string(constants.RbacResourceCluster), 27 | Action: string(constants.RbacActionAll), 28 | } 29 | assert.Equal(t, true, permission.CheckInvalid()) 30 | } 31 | -------------------------------------------------------------------------------- /deployment/attr_linux.go: -------------------------------------------------------------------------------- 1 | //go:build linux 2 | // +build linux 3 | 4 | /****************************************************************************** 5 | * Copyright (c) 2022 PingCAP * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); * 7 | * you may not use this file except in compliance with the License. * 8 | * You may obtain a copy of the License at * 9 | * * 10 | * http://www.apache.org/licenses/LICENSE-2.0 * 11 | * * 12 | * Unless required by applicable law or agreed to in writing, software * 13 | * distributed under the License is distributed on an "AS IS" BASIS, * 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 15 | * See the License for the specific language governing permissions and * 16 | * limitations under the License. * 17 | * * 18 | ******************************************************************************/ 19 | 20 | /******************************************************************************* 21 | * @File: attr_linux 22 | * @Description: 23 | * @Author: shenhaibo@pingcap.com 24 | * @Version: 1.0.0 25 | * @Date: 2022/1/11 26 | *******************************************************************************/ 27 | 28 | package deployment 29 | 30 | import "syscall" 31 | 32 | func genSysProcAttr() *syscall.SysProcAttr { 33 | return &syscall.SysProcAttr{ 34 | Pdeathsig: syscall.SIGTERM, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /deployment/attr_nonlinux.go: -------------------------------------------------------------------------------- 1 | //go:build !linux 2 | // +build !linux 3 | 4 | /****************************************************************************** 5 | * Copyright (c) 2022 PingCAP * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); * 7 | * you may not use this file except in compliance with the License. * 8 | * You may obtain a copy of the License at * 9 | * * 10 | * http://www.apache.org/licenses/LICENSE-2.0 * 11 | * * 12 | * Unless required by applicable law or agreed to in writing, software * 13 | * distributed under the License is distributed on an "AS IS" BASIS, * 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 15 | * See the License for the specific language governing permissions and * 16 | * limitations under the License. * 17 | * * 18 | ******************************************************************************/ 19 | 20 | /******************************************************************************* 21 | * @File: attr_nonlinux 22 | * @Description: 23 | * @Author: shenhaibo@pingcap.com 24 | * @Version: 1.0.0 25 | * @Date: 2022/1/11 26 | *******************************************************************************/ 27 | 28 | package deployment 29 | 30 | import "syscall" 31 | 32 | func genSysProcAttr() *syscall.SysProcAttr { 33 | return &syscall.SysProcAttr{} 34 | } 35 | -------------------------------------------------------------------------------- /docs/design/images/resource_manager/Resource_FT_cases.drawio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/Resource_FT_cases.drawio.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/Resource_UML_Diagram.drawio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/Resource_UML_Diagram.drawio.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/allocation_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/allocation_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/auth_host_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/auth_host_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/autofix_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/autofix_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/call_deployment_serv_error.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/call_deployment_serv_error.jpeg -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/cluster_ports_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/cluster_ports_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/delete_hosts_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/delete_hosts_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/import_hosts_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/import_hosts_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/invalid_zone_error.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/invalid_zone_error.jpeg -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/prepare_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/prepare_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/random_rack_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/random_rack_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/recycle_holder_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/recycle_holder_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/recycle_host_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/recycle_host_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/resource_manaager_uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/resource_manaager_uml.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/resource_pool_uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/resource_pool_uml.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/skip_auth_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/skip_auth_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/user_specify_host_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/user_specify_host_workflow.png -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/validate_host_status_error.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/validate_host_status_error.jpeg -------------------------------------------------------------------------------- /docs/design/images/resource_manager/chinese/verify_hosts_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/resource_manager/chinese/verify_hosts_workflow.png -------------------------------------------------------------------------------- /docs/design/images/switchover/master-slave-switchover-workflow-diagram-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/switchover/master-slave-switchover-workflow-diagram-en.png -------------------------------------------------------------------------------- /docs/design/images/switchover/master-slave-switchover-workflow-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/switchover/master-slave-switchover-workflow-diagram.png -------------------------------------------------------------------------------- /docs/design/images/switchover/switchover-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/switchover/switchover-demo.png -------------------------------------------------------------------------------- /docs/design/images/switchover/switchover-ft-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/switchover/switchover-ft-en.png -------------------------------------------------------------------------------- /docs/design/images/switchover/switchover-ft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/switchover/switchover-ft.png -------------------------------------------------------------------------------- /docs/design/images/switchover/switchover-rollback-successfully.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/images/switchover/switchover-rollback-successfully.png -------------------------------------------------------------------------------- /docs/design/product.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/design/product.md -------------------------------------------------------------------------------- /docs/img/opentrace1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/img/opentrace1.png -------------------------------------------------------------------------------- /docs/img/opentrace2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/docs/img/opentrace2.png -------------------------------------------------------------------------------- /file-server/common/common.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package common 17 | 18 | import "github.com/labstack/gommon/bytes" 19 | 20 | const MaxFileSize int64 = 2 * bytes.GB 21 | const MaxUploadNum int32 = 3 22 | const MaxDownloadNum int32 = 3 23 | -------------------------------------------------------------------------------- /file-server/controller/httpresult.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package controller 17 | 18 | type FileResultMark struct { 19 | Code int `json:"code"` 20 | Message string `json:"message"` 21 | } 22 | 23 | type CommonFileResult struct { 24 | FileResultMark 25 | Data interface{} `json:"data"` 26 | } 27 | 28 | func Success(data interface{}) *CommonFileResult { 29 | return &CommonFileResult{FileResultMark: FileResultMark{0, "OK"}, Data: data} 30 | } 31 | 32 | func Fail(code int, message string) *CommonFileResult { 33 | return &CommonFileResult{FileResultMark{code, message}, struct{}{}} 34 | } 35 | -------------------------------------------------------------------------------- /file-server/interceptor/security.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package interceptor 19 | 20 | import ( 21 | "net/http" 22 | 23 | "github.com/gin-gonic/gin" 24 | "github.com/unrolled/secure" 25 | ) 26 | 27 | func TlsHandler(addr string) gin.HandlerFunc { 28 | return func(c *gin.Context) { 29 | secureMiddleware := secure.New(secure.Options{ 30 | SSLRedirect: true, 31 | SSLHost: addr, 32 | }) 33 | err := secureMiddleware.Process(c.Writer, c.Request) 34 | 35 | // If there was an error, do not continue. 36 | if err != nil { 37 | c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error()) 38 | } 39 | 40 | c.Next() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /file-server/interceptor/trace-id.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package interceptor 18 | 19 | import ( 20 | "github.com/gin-gonic/gin" 21 | "github.com/pingcap/tiunimanager/library/framework" 22 | "github.com/pingcap/tiunimanager/util/uuidutil" 23 | ) 24 | 25 | // Em-X-Trace-ID 26 | func GinTraceIDHandler() gin.HandlerFunc { 27 | return func(c *gin.Context) { 28 | id := c.GetHeader(framework.TiUniManager_X_TRACE_ID_KEY) 29 | if len(id) <= 0 { 30 | id = uuidutil.GenerateID() 31 | } 32 | c.Set(framework.TiUniManager_X_TRACE_ID_KEY, id) 33 | c.Header(framework.TiUniManager_X_TRACE_ID_KEY, id) 34 | c.Next() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /library/framework/args_test.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package framework 19 | 20 | import ( 21 | "github.com/micro/cli/v2" 22 | "testing" 23 | ) 24 | 25 | func TestAllFlags(t *testing.T) { 26 | type args struct { 27 | receiver *ClientArgs 28 | } 29 | tests := []struct { 30 | name string 31 | args args 32 | asserts []func(receiver *ClientArgs, fs []cli.Flag) bool 33 | }{ 34 | {"normal", args{&ClientArgs{}}, []func(receiver *ClientArgs, fs []cli.Flag) bool{ 35 | func(receiver *ClientArgs, fs []cli.Flag) bool {return len(fs) > 4}, 36 | }}, 37 | } 38 | for _, tt := range tests { 39 | t.Run(tt.name, func(t *testing.T) { 40 | got := AllFlags(tt.args.receiver) 41 | for i,v := range tt.asserts { 42 | if !v(tt.args.receiver, got) { 43 | t.Errorf("AllFlags assert false, assert index = %v, got = %v", i, got) 44 | } 45 | } 46 | 47 | }) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /library/framework/assert.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package framework 19 | 20 | import "fmt" 21 | 22 | func AssertNoErr(err error) { 23 | if err == nil { 24 | } else { 25 | panic(err) 26 | } 27 | } 28 | 29 | func Assert(b bool) { 30 | if b { 31 | } else { 32 | panic("assert failed") 33 | } 34 | } 35 | 36 | func AssertWithInfo(b bool, info string) { 37 | if b { 38 | } else { 39 | panic(fmt.Sprintf("assert failed: %s", info)) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /library/framework/certificate.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package framework 18 | 19 | import ( 20 | "github.com/pingcap/tiunimanager/common/constants" 21 | ) 22 | 23 | type CertificateInfo struct { 24 | CertificateCrtFilePath string 25 | CertificateKeyFilePath string 26 | } 27 | 28 | func NewCertificateFromArgs(args *ClientArgs) *CertificateInfo { 29 | return &CertificateInfo{ 30 | CertificateCrtFilePath: args.DeployDir + constants.CertDirPrefix + constants.CertFileName, 31 | CertificateKeyFilePath: args.DeployDir + constants.CertDirPrefix + constants.KeyFileName, 32 | } 33 | } 34 | 35 | func NewAesKeyFilePathFromArgs(args *ClientArgs) string { 36 | return args.DeployDir + constants.CertDirPrefix + constants.AesKeyFileName 37 | } 38 | -------------------------------------------------------------------------------- /library/framework/elasticsearch_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package framework 17 | 18 | import ( 19 | "bytes" 20 | "github.com/stretchr/testify/assert" 21 | "net" 22 | "testing" 23 | ) 24 | 25 | func TestInitElasticsearch(t *testing.T) { 26 | InitElasticsearch("127.0.0.1") 27 | } 28 | 29 | func TestSearch(t *testing.T) { 30 | client := InitElasticsearch("127.0.0.1") 31 | _, e := client.Search("aaa", &bytes.Buffer{}, 1, 1) 32 | 33 | err, ok := e.(*net.OpError) 34 | assert.True(t, ok) 35 | assert.Error(t, err) 36 | } -------------------------------------------------------------------------------- /library/util/tso/tso.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 TiKV Project Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tso 16 | 17 | import ( 18 | "time" 19 | ) 20 | 21 | const ( 22 | physicalShiftBits = 18 23 | logicalBits = (1 << physicalShiftBits) - 1 24 | ) 25 | 26 | // ParseTS parses the ts to (physical,logical). 27 | func ParseTS(ts uint64) (time.Time, uint64) { 28 | logical := ts & logicalBits 29 | physical := ts >> physicalShiftBits 30 | physicalTime := time.Unix(int64(physical/1000), int64(physical)%1000*time.Millisecond.Nanoseconds()) 31 | return physicalTime, logical 32 | } 33 | 34 | // ComposeTS generate an `uint64` TS by passing the physical and logical parts. 35 | func ComposeTS(physical, logical int64) uint64 { 36 | return uint64(physical)<<18 | uint64(logical)&0x3FFFF 37 | } 38 | 39 | // GenerateTSO generate a TSO by passing `time.Time` and `uint64` 40 | func GenerateTSO(physical time.Time, logical uint64) uint64 { 41 | return ComposeTS(physical.UnixNano()/int64(time.Millisecond), int64(logical)) 42 | } 43 | -------------------------------------------------------------------------------- /message/check.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package message 17 | 18 | import "github.com/pingcap/tiunimanager/common/structs" 19 | 20 | type CheckPlatformReq struct { 21 | DisplayMode string `json:"displayMode" form:"displayMode"` 22 | } 23 | 24 | type CheckPlatformRsp struct { 25 | structs.AsyncTaskWorkFlowInfo 26 | CheckID string `json:"checkId"` 27 | } 28 | 29 | type CheckClusterReq struct { 30 | ClusterID string `json:"clusterId"` 31 | } 32 | 33 | type CheckClusterRsp struct { 34 | structs.AsyncTaskWorkFlowInfo 35 | CheckID string `json:"checkId"` 36 | } 37 | 38 | type QueryCheckReportsReq struct { 39 | structs.PageRequest 40 | } 41 | 42 | type QueryCheckReportsRsp struct { 43 | ReportMetas map[string]structs.CheckReportMeta `json:"reportMetas"` 44 | } 45 | 46 | type GetCheckReportReq struct { 47 | ID string `json:"id"` 48 | } 49 | 50 | type GetCheckReportRsp struct { 51 | ReportInfo interface{} `json:"reportInfo"` 52 | } 53 | -------------------------------------------------------------------------------- /micro-api/controller/cluster/alert/alert_api.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package alert 19 | -------------------------------------------------------------------------------- /micro-api/controller/cluster/instance/components_api.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package instance 19 | -------------------------------------------------------------------------------- /micro-api/controller/cluster/monitor/monitor_api.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package monitor 19 | -------------------------------------------------------------------------------- /micro-api/controller/cluster/performance/performance_api.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package performance 19 | -------------------------------------------------------------------------------- /micro-api/controller/platform/dignose/monitor_api.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package platformdignose 19 | -------------------------------------------------------------------------------- /micro-api/controller/resource/hostresource/consts.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package hostresource 18 | 19 | type ExcelField int 20 | 21 | const ( 22 | HOSTNAME_FIELD ExcelField = iota 23 | IP_FILED 24 | USERNAME_FIELD 25 | PASSWD_FIELD 26 | REGION_FIELD 27 | ZONE_FIELD 28 | RACK_FIELD 29 | ARCH_FIELD 30 | OS_FIELD 31 | KERNEL_FIELD 32 | CPU_FIELD 33 | MEM_FIELD 34 | NIC_FIELD 35 | CLUSTER_TYPE_FIELD 36 | PURPOSE_FIELD 37 | DISKTYPE_FIELD 38 | DISKS_FIELD 39 | ) 40 | 41 | //Constants for importing host information 42 | const ( 43 | ImportHostTemplateFileName string = "hostInfo_template.xlsx" 44 | ImportHostTemplateFilePath string = "./resource" 45 | ImportHostTemplateSheet string = "Host Information" 46 | ) 47 | -------------------------------------------------------------------------------- /micro-api/controller/task/crontask/crontask_api.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package crontask 19 | -------------------------------------------------------------------------------- /micro-api/interceptor/security.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package interceptor 19 | 20 | import ( 21 | "net/http" 22 | 23 | "github.com/gin-gonic/gin" 24 | "github.com/unrolled/secure" 25 | ) 26 | 27 | func TlsHandler(addr string) gin.HandlerFunc { 28 | return func(c *gin.Context) { 29 | secureMiddleware := secure.New(secure.Options{ 30 | SSLRedirect: true, 31 | SSLHost: addr, 32 | }) 33 | err := secureMiddleware.Process(c.Writer, c.Request) 34 | 35 | // If there was an error, do not continue. 36 | if err != nil { 37 | c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error()) 38 | } 39 | 40 | c.Next() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /micro-api/interceptor/trace-id.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package interceptor 18 | 19 | import ( 20 | "github.com/gin-gonic/gin" 21 | "github.com/pingcap/tiunimanager/library/framework" 22 | "github.com/pingcap/tiunimanager/util/uuidutil" 23 | ) 24 | 25 | // GinTraceIDHandler EM-X-Trace-ID 26 | func GinTraceIDHandler() gin.HandlerFunc { 27 | return func(c *gin.Context) { 28 | id := c.GetHeader(framework.TiUniManager_X_TRACE_ID_KEY) 29 | if len(id) <= 0 { 30 | id = uuidutil.GenerateID() 31 | } 32 | c.Set(framework.TiUniManager_X_TRACE_ID_KEY, id) 33 | c.Header(framework.TiUniManager_X_TRACE_ID_KEY, id) 34 | c.Next() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /micro-cluster/cluster/management/meta/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package meta 17 | 18 | import ( 19 | "os" 20 | "testing" 21 | 22 | "github.com/pingcap/tiunimanager/library/framework" 23 | "github.com/pingcap/tiunimanager/models" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | models.MockDB() 28 | framework.InitBaseFrameworkForUt(framework.ClusterService) 29 | os.Exit(m.Run()) 30 | } 31 | -------------------------------------------------------------------------------- /micro-cluster/dataapps/sqleditor/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2023 PingCAP, Inc. * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package sqleditor 17 | 18 | import ( 19 | "os" 20 | "testing" 21 | 22 | "github.com/pingcap/tiunimanager/library/framework" 23 | "github.com/pingcap/tiunimanager/models" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | var testFilePath string 28 | framework.InitBaseFrameworkForUt(framework.ClusterService, 29 | func(d *framework.BaseFramework) error { 30 | models.MockDB() 31 | testFilePath = d.GetDataDir() 32 | os.MkdirAll(testFilePath, 0755) 33 | models.MockDB() 34 | return models.Open(d) 35 | }, 36 | ) 37 | code := m.Run() 38 | os.RemoveAll(testFilePath) 39 | 40 | os.Exit(code) 41 | } 42 | -------------------------------------------------------------------------------- /micro-cluster/datatransfer/importexport/common.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package importexport 17 | 18 | const ( 19 | fileTypeCSV string = "csv" 20 | fileTypeSQL string = "sql" 21 | ) 22 | 23 | const ( 24 | lightningTimeout int = 60 * 60 * 24 * 30 //one month 25 | dumplingTimeout int = 60 * 60 * 24 * 30 //one month 26 | ) 27 | 28 | const ( 29 | contextClusterMetaKey string = "clusterMeta" 30 | contextDataTransportRecordKey string = "transportRecord" 31 | ) 32 | 33 | type importInfo struct { 34 | ClusterId string 35 | UserName string 36 | Password string 37 | FilePath string 38 | RecordId string 39 | StorageType string 40 | ConfigPath string 41 | } 42 | 43 | type exportInfo struct { 44 | ClusterId string 45 | UserName string 46 | Password string 47 | FileType string 48 | RecordId string 49 | FilePath string 50 | Filter string 51 | Sql string 52 | StorageType string 53 | ConfigPath string 54 | } 55 | -------------------------------------------------------------------------------- /micro-cluster/parametergroup/common.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | /******************************************************************************* 17 | * @File: common.go 18 | * @Description: define constants 19 | * @Author: jiangxunyu@pingcap.com 20 | * @Version: 1.0.0 21 | * @Date: 2022/3/18 10:19 22 | *******************************************************************************/ 23 | 24 | package parametergroup 25 | 26 | type DBType int 27 | 28 | const ( 29 | TiDB DBType = 1 30 | DM DBType = 2 31 | ) 32 | 33 | type ParamGroupCategory int 34 | 35 | const ( 36 | DEFAULT ParamGroupCategory = 1 37 | CUSTOM ParamGroupCategory = 2 38 | ) 39 | 40 | type GroupType int 41 | 42 | const ( 43 | Cluster GroupType = 1 44 | Instance GroupType = 2 45 | ) 46 | -------------------------------------------------------------------------------- /micro-cluster/platform/check/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | package check 16 | 17 | import ( 18 | "github.com/pingcap/tiunimanager/library/framework" 19 | "github.com/pingcap/tiunimanager/models" 20 | "os" 21 | "testing" 22 | ) 23 | 24 | func TestMain(m *testing.M) { 25 | var testFilePath string 26 | framework.InitBaseFrameworkForUt(framework.ClusterService, 27 | func(d *framework.BaseFramework) error { 28 | models.MockDB() 29 | testFilePath = d.GetDataDir() 30 | os.MkdirAll(testFilePath, 0755) 31 | models.MockDB() 32 | return models.Open(d) 33 | }, 34 | ) 35 | code := m.Run() 36 | os.RemoveAll(testFilePath) 37 | 38 | os.Exit(code) 39 | } 40 | 41 | -------------------------------------------------------------------------------- /micro-cluster/platform/product/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package product 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/library/framework" 20 | "github.com/pingcap/tiunimanager/models" 21 | "os" 22 | "testing" 23 | ) 24 | 25 | func TestMain(m *testing.M) { 26 | var testFilePath string 27 | framework.InitBaseFrameworkForUt(framework.ClusterService, 28 | func(d *framework.BaseFramework) error { 29 | models.MockDB() 30 | testFilePath = d.GetDataDir() 31 | os.MkdirAll(testFilePath, 0755) 32 | models.MockDB() 33 | return models.Open(d) 34 | }, 35 | ) 36 | code := m.Run() 37 | os.RemoveAll(testFilePath) 38 | 39 | os.Exit(code) 40 | } 41 | -------------------------------------------------------------------------------- /micro-cluster/platform/system/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package system 17 | 18 | import ( 19 | "context" 20 | "github.com/pingcap/tiunimanager/common/constants" 21 | "github.com/pingcap/tiunimanager/library/framework" 22 | "github.com/pingcap/tiunimanager/models" 23 | "os" 24 | "testing" 25 | ) 26 | 27 | func TestMain(m *testing.M) { 28 | var testFilePath string 29 | framework.InitBaseFrameworkForUt(framework.ClusterService, 30 | func(d *framework.BaseFramework) error { 31 | testFilePath = d.GetDataDir() 32 | os.MkdirAll(testFilePath, 0755) 33 | return models.Open(d) 34 | }, 35 | func(d *framework.BaseFramework) error { 36 | return GetSystemManager().AcceptSystemEvent(context.TODO(), constants.SystemProcessStarted) 37 | }, 38 | ) 39 | code := m.Run() 40 | models.MockDB() 41 | os.RemoveAll(testFilePath) 42 | 43 | os.Exit(code) 44 | } 45 | -------------------------------------------------------------------------------- /micro-cluster/resourcemanager/management/structs/allocator_recycler.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package structs 18 | 19 | import ( 20 | "context" 21 | ) 22 | 23 | type AllocatorRecycler interface { 24 | AllocResources(ctx context.Context, batchReq *BatchAllocRequest) (results *BatchAllocResponse, err error) 25 | RecycleResources(ctx context.Context, request *RecycleRequest) (err error) 26 | } 27 | -------------------------------------------------------------------------------- /micro-cluster/resourcemanager/resourcepool/hostinitiator/hostinitiator.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package hostinitiator 17 | 18 | import ( 19 | "context" 20 | 21 | "github.com/pingcap/tiunimanager/common/structs" 22 | ) 23 | 24 | type HostInitiator interface { 25 | AuthHost(ctx context.Context, deployUser, userGroup string, h *structs.HostInfo) (err error) 26 | Prepare(ctx context.Context, h *structs.HostInfo) (err error) 27 | Verify(ctx context.Context, h *structs.HostInfo) (err error) 28 | InstallSoftware(ctx context.Context, hosts []structs.HostInfo) (err error) 29 | PreCheckHostInstallFilebeat(ctx context.Context, hosts []structs.HostInfo) (installed bool, err error) 30 | JoinEMCluster(ctx context.Context, hosts []structs.HostInfo) (operationID string, err error) 31 | LeaveEMCluster(ctx context.Context, nodeId string) (operationID string, err error) 32 | } 33 | -------------------------------------------------------------------------------- /micro-cluster/user/account/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package account 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/models" 20 | "os" 21 | "testing" 22 | ) 23 | 24 | func TestMain(m *testing.M) { 25 | models.MockDB() 26 | 27 | os.Exit(m.Run()) 28 | } 29 | -------------------------------------------------------------------------------- /micro-cluster/user/identification/main_test.go: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * @File: main_test 3 | * @Description: 4 | * @Author: wangyaozheng@pingcap.com 5 | * @Version: 1.0.0 6 | * @Date: 2022/1/17 7 | *******************************************************************************/ 8 | 9 | package identification 10 | 11 | import ( 12 | "github.com/pingcap/tiunimanager/models" 13 | "os" 14 | "testing" 15 | ) 16 | 17 | func TestMain(m *testing.M) { 18 | models.MockDB() 19 | 20 | os.Exit(m.Run()) 21 | } 22 | -------------------------------------------------------------------------------- /micro-cluster/user/rbac/common.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package rbac 17 | 18 | const ( 19 | ObjectIndex int = 0 20 | ResourceIndex int = 1 21 | ActionIndex int = 2 22 | ) 23 | -------------------------------------------------------------------------------- /models/cluster/alert/readerwriter.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package alert 17 | -------------------------------------------------------------------------------- /models/cluster/backuprestore/backuprecord.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package backuprestore 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/models/common" 20 | "time" 21 | ) 22 | 23 | // BackupRecord backup record information 24 | type BackupRecord struct { 25 | common.Entity 26 | StorageType string `gorm:"not null"` 27 | ClusterID string `gorm:"not null;type:varchar(22);default:null"` 28 | BackupType string 29 | BackupMethod string 30 | BackupMode string 31 | FilePath string 32 | Size uint64 33 | BackupTso uint64 34 | StartTime time.Time 35 | EndTime time.Time 36 | } 37 | -------------------------------------------------------------------------------- /models/cluster/backuprestore/backupstrategy.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package backuprestore 17 | 18 | import "github.com/pingcap/tiunimanager/models/common" 19 | 20 | // BackupStrategy backup strategy information 21 | type BackupStrategy struct { 22 | common.Entity 23 | ClusterID string `gorm:"not null;"` 24 | BackupDate string `gorm:"default:null"` 25 | StartHour uint32 26 | EndHour uint32 27 | } 28 | -------------------------------------------------------------------------------- /models/cluster/log/readerwriter.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package log 17 | -------------------------------------------------------------------------------- /models/cluster/management/clusterrelation.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package management 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/common/constants" 20 | "gorm.io/gorm" 21 | ) 22 | 23 | // ClusterRelation Cluster relationship, the system will establish a master-slave relationship 24 | type ClusterRelation struct { 25 | gorm.Model 26 | RelationType constants.ClusterRelationType `gorm:"not null;size:32"` 27 | SubjectClusterID string `gorm:"not null;size:32"` 28 | ObjectClusterID string `gorm:"not null;size:32"` 29 | SyncChangeFeedTaskID string `gorm:"not null;size:32;default:''"` 30 | } 31 | -------------------------------------------------------------------------------- /models/cluster/management/clustertopologysnapshot.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package management 17 | 18 | type ClusterTopologySnapshot struct { 19 | ClusterID string `gorm:"primarykey;<-:create;size:64;comment:'cluster id';"` 20 | TenantID string `gorm:"not null;default:null;<-:create;size:64;comment:'tenant id';"` 21 | Config string `gorm:"type:text;comment:'yaml content of cluster topology';'"` 22 | PublicKey string `gorm:"not null;default:null;<-:create;type:text;comment:'connection public key';"` 23 | PrivateKey string `gorm:"not null;default:null;<-:create;type:text;comment:'Connection private key';"` 24 | } 25 | -------------------------------------------------------------------------------- /models/cluster/management/clusteruser.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package management 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/models/common" 20 | "gorm.io/gorm" 21 | ) 22 | 23 | type DBUser struct { 24 | gorm.Model 25 | ClusterID string `gorm:"not null;type:varchar(22);default:null"` 26 | Name string `gorm:"default:null;not null;comment:'name of the user'"` 27 | Password common.PasswordInExpired `gorm:"not null;size:256;comment:'password of the user'"` 28 | RoleType string `gorm:"not null;size:64;comment:'role type of the user'"` 29 | } 30 | -------------------------------------------------------------------------------- /models/cluster/management/querymodel.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package management 17 | 18 | import "github.com/pingcap/tiunimanager/common/constants" 19 | 20 | type Filters struct { 21 | ClusterIDs []string 22 | TenantId string 23 | NameLike string 24 | Type string 25 | StatusFilters []constants.ClusterRunningStatus 26 | Tag string 27 | } 28 | 29 | type Result struct { 30 | Cluster *Cluster 31 | Instances []*ClusterInstance 32 | DBUsers []*DBUser 33 | } 34 | -------------------------------------------------------------------------------- /models/cluster/monitor/readerwriter.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package monitor 17 | -------------------------------------------------------------------------------- /models/cluster/performance/readerwriter.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package performance 17 | -------------------------------------------------------------------------------- /models/dataapps/sqleditor/dbagent/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2023 PingCAP, Inc. * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package dbagent 17 | 18 | import ( 19 | "os" 20 | "testing" 21 | 22 | "github.com/pingcap/tiunimanager/library/framework" 23 | "github.com/pingcap/tiunimanager/models" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | var testFilePath string 28 | framework.InitBaseFrameworkForUt(framework.ClusterService, 29 | func(d *framework.BaseFramework) error { 30 | models.MockDB() 31 | testFilePath = d.GetDataDir() 32 | os.MkdirAll(testFilePath, 0755) 33 | models.MockDB() 34 | return models.Open(d) 35 | }, 36 | ) 37 | code := m.Run() 38 | os.RemoveAll(testFilePath) 39 | 40 | os.Exit(code) 41 | } 42 | -------------------------------------------------------------------------------- /models/dataapps/sqleditor/dbagent/readerwriter.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2023 PingCAP, Inc. * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package dbagent 17 | 18 | import ( 19 | "context" 20 | "database/sql" 21 | 22 | "github.com/pingcap/tiunimanager/message/dataapps/sqleditor" 23 | ) 24 | 25 | type ReaderWriter interface { 26 | GetTableMetaData(ctx context.Context, clusterID string, dbName string, tableName string) (metaRes *sqleditor.MetaRes, err error) 27 | GetClusterMetaData(ctx context.Context, isBrief bool, showSystemDBFlag bool) (dbmetaList []*sqleditor.DBMeta, err error) 28 | CreateSession(ctx context.Context, clusterID string, expireSec uint64, database string) (sessionID string, err error) 29 | CloseSession(ctx context.Context, sessionID string) error 30 | GetSession(ctx context.Context, sessionID string) (*sql.Conn, error) 31 | } 32 | -------------------------------------------------------------------------------- /models/dataapps/sqleditor/sqlfile/readerwriter.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2023 PingCAP, Inc. * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package sqleditorfile 17 | 18 | import ( 19 | "context" 20 | ) 21 | 22 | type ReaderWriter interface { 23 | Create(ctx context.Context, sqlEditorFile *SqlEditorFile, name string) (string, error) 24 | Update(ctx context.Context, sqlEditorFile *SqlEditorFile) error 25 | Delete(ctx context.Context, ID string, createBy string) error 26 | GetSqlFileByID(ctx context.Context, ID string, createdBy string) (sqlfile *SqlEditorFile, err error) 27 | GetSqlFileList(ctx context.Context, clusterID string, createdBy string, pageSize int, offset int) (sqlFileList []*SqlEditorFile, total int64, err error) 28 | } 29 | -------------------------------------------------------------------------------- /models/dataapps/sqleditor/sqlfile/sqleditorfile.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2023 PingCAP, Inc. * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package sqleditorfile 17 | 18 | import ( 19 | "time" 20 | 21 | "github.com/pingcap/tiunimanager/util/uuidutil" 22 | "gorm.io/gorm" 23 | ) 24 | 25 | type SqlEditorFile struct { 26 | ID string `gorm:"primarykey"` 27 | Name string `gorm:"default:null;not null;"` 28 | ClusterID string `gorm:"default:null;not null;"` 29 | Database string `gorm:"default:null"` 30 | Content string `gorm:"default:null;not null;"` 31 | IsDeleted int `gorm:"default:0;not null;"` 32 | CreatedBy string `gorm:"default:null;not null;"` 33 | UpdatedBy string `gorm:"default:null;not null;"` 34 | CreatedAt time.Time `gorm:"<-:create"` 35 | UpdatedAt time.Time 36 | } 37 | 38 | func (f *SqlEditorFile) BeforeCreate(tx *gorm.DB) (err error) { 39 | if len(f.ID) == 0 { 40 | f.ID = uuidutil.GenerateID() 41 | } 42 | 43 | return nil 44 | } 45 | -------------------------------------------------------------------------------- /models/datatransfer/importexport/datatransportrecord.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package importexport 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/models/common" 20 | "time" 21 | ) 22 | 23 | // DataTransportRecord import and export record information 24 | type DataTransportRecord struct { 25 | common.Entity 26 | ClusterID string `gorm:"index;"` 27 | TransportType string `gorm:"not null;"` 28 | FilePath string `gorm:"not null;"` 29 | ConfigPath string 30 | ZipName string 31 | StorageType string `gorm:"not null;"` 32 | Comment string 33 | ReImportSupport bool 34 | StartTime time.Time 35 | EndTime time.Time 36 | } 37 | -------------------------------------------------------------------------------- /models/platform/config/readerwriter.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package config 17 | 18 | import "context" 19 | 20 | type ReaderWriter interface { 21 | // CreateConfig 22 | // @Description: create system config 23 | // @Receiver m 24 | // @Parameter ctx 25 | // @Parameter cfg 26 | // @Return *SystemConfig 27 | // @Return error 28 | CreateConfig(ctx context.Context, cfg *SystemConfig) (*SystemConfig, error) 29 | 30 | // GetConfig 31 | // @Description: get system config by configKey 32 | // @Receiver m 33 | // @Parameter ctx 34 | // @Parameter configKey 35 | // @Return *SystemConfig 36 | // @Return error 37 | GetConfig(ctx context.Context, configKey string) (config *SystemConfig, err error) 38 | 39 | // UpdateConfig 40 | // @Description: update system config 41 | // @Receiver m 42 | // @Parameter ctx 43 | // @Parameter configKey 44 | // @Return *SystemConfig 45 | // @Return error 46 | UpdateConfig(ctx context.Context, config *SystemConfig) (err error) 47 | } 48 | -------------------------------------------------------------------------------- /models/platform/config/systemconfig.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package config 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/util/uuidutil" 20 | "gorm.io/gorm" 21 | "time" 22 | ) 23 | 24 | type SystemConfig struct { 25 | ID string `gorm:"primarykey"` 26 | CreatedAt time.Time `gorm:"<-:create"` 27 | UpdatedAt time.Time 28 | DeletedAt gorm.DeletedAt `gorm:"index"` 29 | ConfigKey string `gorm:"not null;uniqueIndex"` 30 | ConfigValue string `gorm:"not null;"` 31 | } 32 | 33 | func (e *SystemConfig) BeforeCreate(tx *gorm.DB) (err error) { 34 | e.ID = uuidutil.GenerateID() 35 | return nil 36 | } 37 | -------------------------------------------------------------------------------- /models/platform/dignose/readerwriter.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package dignose 17 | -------------------------------------------------------------------------------- /models/platform/system/version.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | /******************************************************************************* 17 | * @File: version.go 18 | * @Description: 19 | * @Author: zhangpeijin@pingcap.com 20 | * @Version: 1.0.0 21 | * @Date: 2022/2/16 22 | *******************************************************************************/ 23 | 24 | package system 25 | 26 | type VersionInfo struct { 27 | ID string `gorm:"primaryKey;"` 28 | Desc string 29 | ReleaseNote string 30 | } 31 | 32 | type VersionInitializer struct { 33 | VersionID string 34 | DataInitializer func() error 35 | } -------------------------------------------------------------------------------- /models/resource/resourcepool/host_label.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package resourcepool 17 | 18 | import ( 19 | "time" 20 | 21 | "github.com/pingcap/tiunimanager/common/structs" 22 | "gorm.io/gorm" 23 | ) 24 | 25 | type Label struct { 26 | Name string `gorm:"PrimaryKey"` 27 | Category int8 28 | Trait int64 29 | CreatedAt time.Time 30 | UpdatedAt time.Time 31 | DeletedAt gorm.DeletedAt 32 | } 33 | 34 | func (label *Label) ConstructLabelRecord(src *structs.Label) { 35 | label.Name = src.Name 36 | label.Category = src.Category 37 | label.Trait = src.Trait 38 | } 39 | -------------------------------------------------------------------------------- /models/user/account/account_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package account 17 | 18 | import ( 19 | "github.com/stretchr/testify/assert" 20 | "testing" 21 | ) 22 | 23 | func TestUser_GenSaltAndHash_CheckPassword(t *testing.T) { 24 | user := &User{ 25 | ID: "user01", 26 | Name: "user", 27 | } 28 | 29 | err := user.GenSaltAndHash("12345") 30 | assert.NoError(t, err) 31 | 32 | _, err = user.CheckPassword("") 33 | assert.Error(t, err) 34 | 35 | _, err = user.CheckPassword("123456789012345678901") 36 | assert.Error(t, err) 37 | 38 | got, err := user.CheckPassword("1234") 39 | assert.NoError(t, err) 40 | assert.False(t, got) 41 | 42 | got, err = user.CheckPassword("12345") 43 | assert.NoError(t, err) 44 | assert.True(t, got) 45 | } 46 | -------------------------------------------------------------------------------- /models/user/identification/readerwriter.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package identification 17 | 18 | import ( 19 | "context" 20 | "time" 21 | ) 22 | 23 | type ReaderWriter interface { 24 | CreateToken(ctx context.Context, tokenString, userID, tenantID string, expirationTime time.Time) (*Token, error) 25 | GetToken(ctx context.Context, tokenString string) (*Token, error) 26 | } 27 | -------------------------------------------------------------------------------- /models/user/identification/token.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package identification 17 | 18 | import ( 19 | "gorm.io/gorm" 20 | "time" 21 | ) 22 | 23 | type Token struct { 24 | gorm.Model 25 | 26 | TokenString string `gorm:"size:255"` 27 | UserID string `gorm:"size:255"` 28 | TenantID string `gorm:"size:255"` 29 | Status int8 `gorm:"size:255"` 30 | ExpirationTime time.Time `gorm:"size:255"` 31 | } 32 | 33 | func (token *Token) IsValid() bool { 34 | now := time.Now() 35 | return now.Before(token.ExpirationTime) 36 | } 37 | 38 | func (token *Token) Destroy() { 39 | token.ExpirationTime = time.Now() 40 | } 41 | -------------------------------------------------------------------------------- /models/user/rbac/main_test.go: -------------------------------------------------------------------------------- 1 | package rbac 2 | 3 | import ( 4 | "github.com/pingcap/tiunimanager/common/constants" 5 | "github.com/pingcap/tiunimanager/library/framework" 6 | "github.com/pingcap/tiunimanager/util/uuidutil" 7 | "gorm.io/driver/sqlite" 8 | "gorm.io/gorm" 9 | "log" 10 | "os" 11 | "testing" 12 | "time" 13 | ) 14 | 15 | var RW ReaderWriter 16 | 17 | func TestMain(m *testing.M) { 18 | testFilePath := "testdata/" + uuidutil.ShortId() 19 | os.MkdirAll(testFilePath, 0755) 20 | 21 | logins := framework.LogForkFile(constants.LogFileSystem) 22 | 23 | framework.InitBaseFrameworkForUt(framework.ClusterService, 24 | func(d *framework.BaseFramework) error { 25 | dbFile := testFilePath + constants.DBDirPrefix + constants.DatabaseFileName 26 | newLogger := framework.New( 27 | log.New(os.Stdout, "\r\n", log.LstdFlags), 28 | framework.Config{ 29 | SlowThreshold: time.Second, 30 | LogLevel: framework.Info, 31 | IgnoreRecordNotFoundError: true, 32 | }, 33 | ) 34 | db, err := gorm.Open(sqlite.Open(dbFile), &gorm.Config{ 35 | Logger: newLogger, 36 | //Logger: d.GetRootLogger(), 37 | }) 38 | if err != nil || db.Error != nil { 39 | logins.Fatalf("open database failed, filepath: %s database error: %s, meta database error: %v", dbFile, err, db.Error) 40 | } else { 41 | logins.Infof("open database successful, filepath: %s", dbFile) 42 | } 43 | 44 | RW = NewRBACReadWrite(db) 45 | return nil 46 | }, 47 | ) 48 | code := m.Run() 49 | os.RemoveAll("testdata/") 50 | os.RemoveAll("logs/") 51 | os.Exit(code) 52 | } 53 | -------------------------------------------------------------------------------- /models/user/rbac/rbac.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package rbac 17 | 18 | type RBAC struct { 19 | ID uint `gorm:"primaryKey;autoIncrement"` 20 | Ptype string `gorm:"size:128;uniqueIndex:unique_index"` 21 | V0 string `gorm:"size:128;uniqueIndex:unique_index"` 22 | V1 string `gorm:"size:128;uniqueIndex:unique_index"` 23 | V2 string `gorm:"size:128;uniqueIndex:unique_index"` 24 | V3 string `gorm:"size:128;uniqueIndex:unique_index"` 25 | V4 string `gorm:"size:128;uniqueIndex:unique_index"` 26 | V5 string `gorm:"size:128;uniqueIndex:unique_index"` 27 | } 28 | -------------------------------------------------------------------------------- /models/user/rbac/rbac_readwrite.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package rbac 17 | 18 | import ( 19 | "context" 20 | gormadapter "github.com/casbin/gorm-adapter/v3" 21 | dbCommon "github.com/pingcap/tiunimanager/models/common" 22 | "gorm.io/gorm" 23 | ) 24 | 25 | type RBACReadWrite struct { 26 | dbCommon.GormDB 27 | } 28 | 29 | func NewRBACReadWrite(db *gorm.DB) *RBACReadWrite { 30 | m := RBACReadWrite{ 31 | dbCommon.WrapDB(db), 32 | } 33 | return &m 34 | } 35 | 36 | func (m *RBACReadWrite) GetRBACAdapter(ctx context.Context) (*gormadapter.Adapter, error) { 37 | return gormadapter.NewAdapterByDBWithCustomTable(m.DB(ctx), &RBAC{}, "rbac") 38 | } 39 | -------------------------------------------------------------------------------- /models/user/rbac/rbac_readwrite_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package rbac 17 | 18 | import ( 19 | "context" 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestRBACReadWrite_GetRBACAdapter(t *testing.T) { 25 | adapter, err := RW.GetRBACAdapter(context.TODO()) 26 | assert.Nil(t, err) 27 | assert.NotNil(t, adapter) 28 | } 29 | -------------------------------------------------------------------------------- /models/user/rbac/readerwriter.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package rbac 17 | 18 | import ( 19 | "context" 20 | gormadapter "github.com/casbin/gorm-adapter/v3" 21 | ) 22 | 23 | type ReaderWriter interface { 24 | // GetRBACAdapter 25 | // @Description: get casbin gorm adapter 26 | // @Receiver m 27 | // @Parameter ctx 28 | // @Return *gormadapter.Adapter 29 | // @Return error 30 | GetRBACAdapter(ctx context.Context) (*gormadapter.Adapter, error) 31 | } 32 | -------------------------------------------------------------------------------- /models/workflow/workflow.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package workflow 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/common/constants" 20 | "github.com/pingcap/tiunimanager/models/common" 21 | ) 22 | 23 | // WorkFlow work flow infomation 24 | type WorkFlow struct { 25 | common.Entity 26 | Name string `gorm:"default:null;comment:'name of the workflow'"` 27 | BizID string `gorm:"default:null;<-:create"` 28 | BizType string `gorm:"default:null"` 29 | Context string `gorm:"default:null"` 30 | } 31 | 32 | func (flow *WorkFlow) Finished() bool { 33 | return constants.WorkFlowStatusFinished == flow.Status || constants.WorkFlowStatusError == flow.Status || constants.WorkFlowStatusCanceled == flow.Status 34 | } 35 | 36 | func (flow *WorkFlow) Stopped() bool { 37 | return constants.WorkFlowStatusStopped == flow.Status 38 | } 39 | -------------------------------------------------------------------------------- /models/workflow/workflow_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package workflow 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/common/constants" 20 | "github.com/pingcap/tiunimanager/models/common" 21 | "github.com/stretchr/testify/assert" 22 | "testing" 23 | ) 24 | 25 | func TestWorkFlow_Finished(t *testing.T) { 26 | f := &WorkFlow{ 27 | Entity: common.Entity{ 28 | Status: constants.WorkFlowStatusFinished, 29 | }, 30 | } 31 | assert.True(t, f.Finished()) 32 | } 33 | 34 | func TestResult(t *testing.T) { 35 | node := &WorkFlowNode{} 36 | node.Record("aaa", 2, true) 37 | assert.Equal(t, "aaa\n2\ntrue\n", node.Result) 38 | node.Record("ddd") 39 | assert.Equal(t, "aaa\n2\ntrue\nddd\n", node.Result) 40 | } -------------------------------------------------------------------------------- /quick_run.sh: -------------------------------------------------------------------------------- 1 | nohup ./bin/cluster-server --host=127.0.0.1 --port=4101 --tracer-address=127.0.0.1:6831 --metrics-port=4104 --registry-address=127.0.0.1:4106 --elasticsearch-address=127.0.0.1:9200 --skip-host-init=true --em-version=InTesting --deploy-user=tidb --deploy-group=tidb >> logs/system.log 2>&1 & 2 | sleep 3 3 | nohup ./bin/openapi-server --host=127.0.0.1 --port=4116 --tracer-address=127.0.0.1:6831 --metrics-port=4103 --registry-address=127.0.0.1:4106 >> system.log & 4 | sleep 3 5 | nohup ./bin/file-server --host=127.0.0.1 --port=4102 --tracer-address=127.0.0.1:6831 --metrics-port=4105 --registry-address=127.0.0.1:4106 >> system.log & 6 | -------------------------------------------------------------------------------- /resource/hostInfo_template.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingcap/tiunimanager/eedb752b3919b82d1c6cd6e6bd8972cd78d26fce/resource/hostInfo_template.xlsx -------------------------------------------------------------------------------- /resource/prchecklist.md: -------------------------------------------------------------------------------- 1 | # Following the checklist saves the reviewers' time and gets your PR reviewed faster. 2 | 3 | # Self Review 4 | Have you reviewed every line of your changes by yourself? 5 | 6 | # Test 7 | Have you added enough test cases to cover the new feature or bug fix? 8 | Also, add comments to describe your test cases. 9 | 10 | # Naming 11 | Do function names keep consistent with its behavior? 12 | Is it easy to infer the function's behavior by its name? 13 | 14 | # Comment 15 | Is there any code that confuses the reviewer? 16 | Add comments on them! You'll be asked to do so anyway. 17 | Make sure there is no syntax or spelling error in your comments. 18 | Some online syntax checking tools like Grammarly may be helpful. 19 | 20 | # Refactor 21 | Is there any way to refactor the code to make it more readable? 22 | If the refactoring touches a lot of existing code, send another PR to do it. 23 | 24 | # Single Purpose 25 | Make sure the PR does only one thing and nothing else. 26 | 27 | # Diff Size 28 | Make sure the diff size is no more than 500, split it into small PRs if it is too large. 29 | -------------------------------------------------------------------------------- /resource/template/import_topology.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package template 17 | 18 | var EMClusterScaleOut = ` 19 | filebeat_servers: 20 | {{ range .HostAddrs }} 21 | - host: {{ .HostIP }} 22 | ssh_port: {{ .SSHPort }} 23 | {{ end }} 24 | ` 25 | -------------------------------------------------------------------------------- /scripts/parameters_v1.0.0-beta.11.sql: -------------------------------------------------------------------------------- 1 | update parameters set unit = null, unit_options = '["MB", "GB"]' where id = '209'; 2 | update parameters set unit = null, unit_options = '["MB", "GB"]' where id = '240'; 3 | update parameters set unit = null, unit_options = '["MB", "GB"]' where id = '271'; 4 | update parameters set unit = null, unit_options = '["MB", "GB"]', range = '["1MB", "512GB"]' where id = '98'; 5 | update parameters set range = '["0", "102400"]' where id = '110'; 6 | update parameters set range = '["4", "256"]', range_type = 1 where id = '86'; 7 | update parameters set has_apply = 0, read_only = 1 where id = '62'; 8 | update parameters set has_apply = 0, read_only = 1 where id = '363'; 9 | update parameters set has_apply = 0, read_only = 1 where id = '364'; 10 | update parameters set read_only = 1 where id = '404'; -------------------------------------------------------------------------------- /scripts/parameters_v1.0.0-beta.13.sql: -------------------------------------------------------------------------------- 1 | update parameter_group_mappings set default_value = '' where default_value = ' '; 2 | update parameter_group_mappings set default_value = '' where parameter_id in ('62', '74', '86', '98', '110', '111', '117', '186', '209', '240', '271'); 3 | delete from parameter_group_mappings where parameter_group_id = 'II7PQbJWTHW2_VdlNRjtrQ' and parameter_id = '187'; 4 | delete from parameter_group_mappings where parameter_group_id = 'II7PQbJWTHW2_VdlNRjtrQ' and parameter_id = '190'; 5 | delete from parameter_group_mappings where parameter_group_id = 'SqsfgL4tQ7GaBGOxIK1c8A' and parameter_id = '187'; 6 | delete from parameter_group_mappings where parameter_group_id = 'SqsfgL4tQ7GaBGOxIK1c8A' and parameter_id = '188'; 7 | delete from parameter_group_mappings where parameter_group_id = 'SqsfgL4tQ7GaBGOxIK1c8A' and parameter_id = '189'; 8 | delete from parameter_group_mappings where parameter_group_id = 'SqsfgL4tQ7GaBGOxIK1c8A' and parameter_id = '190'; 9 | delete from parameter_group_mappings where parameter_group_id = 'SqsfgL4tQ7GaBGOxIK1c8A' and parameter_id = '191'; -------------------------------------------------------------------------------- /scripts/tiup_configs.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO system_configs (id, created_at, updated_at, config_key, config_value) 2 | VALUES ('default', datetime('now'), datetime('now'), 'default_tiup_home', '/home/tidb/.tiup'); 3 | INSERT INTO system_configs (id, created_at, updated_at, config_key, config_value) 4 | VALUES ('em', datetime('now'), datetime('now'), 'em_tiup_home', '/home/tidb/.em'); -------------------------------------------------------------------------------- /util/api/tidb/sql/common.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package sql 17 | 18 | type DbConnParam struct { 19 | Username string 20 | Password string 21 | IP string 22 | Port string 23 | } 24 | -------------------------------------------------------------------------------- /util/bitmap/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package bitmap 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "go.uber.org/goleak" 22 | "testing" 23 | ) 24 | 25 | func TestMain(m *testing.M) { 26 | testbridge2.WorkaroundGoCheckFlags() 27 | goleak.VerifyTestMain(m) 28 | } 29 | -------------------------------------------------------------------------------- /util/checksum/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package checksum 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "testing" 22 | 23 | "go.uber.org/goleak" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | testbridge2.WorkaroundGoCheckFlags() 28 | goleak.VerifyTestMain(m) 29 | } 30 | -------------------------------------------------------------------------------- /util/convert/convert.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | /******************************************************************************* 18 | * @File: convert.go 19 | * @Description: struct convert 20 | * @Author: jiangxunyu@pingcap.com 21 | * @Version: 1.0.0 22 | * @Date: 2021/11/26 17:59 23 | *******************************************************************************/ 24 | 25 | package convert 26 | 27 | import "encoding/json" 28 | 29 | func ConvertObj(src interface{}, dst interface{}) error { 30 | b, err := json.Marshal(src) 31 | if err != nil { 32 | return err 33 | } 34 | err = json.Unmarshal(b, dst) 35 | if err != nil { 36 | return err 37 | } 38 | return nil 39 | } 40 | -------------------------------------------------------------------------------- /util/disk/tempFile_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2022 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | /******************************************************************************* 18 | * @File: tempFile_test.go 19 | * @Description: 20 | * @Author: shenhaibo@pingcap.com 21 | * @Version: 1.0.0 22 | * @Date: 2022/3/30 23 | *******************************************************************************/ 24 | 25 | package disk 26 | 27 | import ( 28 | asserts "github.com/stretchr/testify/assert" 29 | "testing" 30 | ) 31 | 32 | func TestStatus(t *testing.T) { 33 | t.Run("normal", func(t *testing.T) { 34 | path, _ := CreateWithContent("", "test", "yaml", []byte("content")) 35 | content, err := ReadFileContent(path) 36 | asserts.NoError(t, err) 37 | asserts.Equal(t, "content", content) 38 | }) 39 | t.Run("err", func(t *testing.T) { 40 | _, err := ReadFileContent("/tmp/nosuchpath") 41 | asserts.Error(t, err) 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /util/disk/tracker.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | package disk 17 | // 18 | //import ( 19 | // "github.com/pingcap/tiunimanager/library/firstparty/util/memory" 20 | //) 21 | // 22 | //// Tracker is used to track the disk usage during query execution. 23 | //type Tracker = memory.Tracker 24 | // 25 | //// NewTracker creates a disk tracker. 26 | //// 1. "label" is the label used in the usage string. 27 | //// 2. "bytesLimit <= 0" means no limit. 28 | //var NewTracker = memory.NewTracker 29 | // 30 | //// NewGlobalTrcaker creates a global disk tracker. 31 | //var NewGlobalTrcaker = memory.NewGlobalTracker 32 | -------------------------------------------------------------------------------- /util/fastrand/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package fastrand 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "testing" 22 | 23 | "go.uber.org/goleak" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | testbridge2.WorkaroundGoCheckFlags() 28 | goleak.VerifyTestMain(m) 29 | } 30 | -------------------------------------------------------------------------------- /util/format/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package format 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "testing" 22 | 23 | "go.uber.org/goleak" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | testbridge2.WorkaroundGoCheckFlags() 28 | goleak.VerifyTestMain(m) 29 | } 30 | -------------------------------------------------------------------------------- /util/israce/israce.go: -------------------------------------------------------------------------------- 1 | // +build race 2 | 3 | /****************************************************************************** 4 | * Copyright (c) 2021 PingCAP * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); * 6 | * you may not use this file except in compliance with the License. * 7 | * You may obtain a copy of the License at * 8 | * * 9 | * http://www.apache.org/licenses/LICENSE-2.0 * 10 | * * 11 | * Unless required by applicable law or agreed to in writing, software * 12 | * distributed under the License is distributed on an "AS IS" BASIS, * 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 14 | * See the License for the specific language governing permissions and * 15 | * limitations under the License. * 16 | * * 17 | ******************************************************************************/ 18 | 19 | package israce 20 | 21 | // RaceEnabled checks if race is enabled. 22 | const RaceEnabled = true 23 | -------------------------------------------------------------------------------- /util/israce/norace.go: -------------------------------------------------------------------------------- 1 | // +build !race 2 | 3 | /****************************************************************************** 4 | * Copyright (c) 2021 PingCAP * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); * 6 | * you may not use this file except in compliance with the License. * 7 | * You may obtain a copy of the License at * 8 | * * 9 | * http://www.apache.org/licenses/LICENSE-2.0 * 10 | * * 11 | * Unless required by applicable law or agreed to in writing, software * 12 | * distributed under the License is distributed on an "AS IS" BASIS, * 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 14 | * See the License for the specific language governing permissions and * 15 | * limitations under the License. * 16 | * * 17 | ******************************************************************************/ 18 | 19 | package israce 20 | 21 | // RaceEnabled checks if race is enabled. 22 | const RaceEnabled = false 23 | -------------------------------------------------------------------------------- /util/kvcache/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | package kvcache 17 | // 18 | //import ( 19 | // "testing" 20 | // 21 | // "github.com/pingcap/tiunimanager/library/firstparty/util/testbridge" 22 | // "go.uber.org/goleak" 23 | //) 24 | // 25 | //func TestMain(m *testing.M) { 26 | // testbridge.WorkaroundGoCheckFlags() 27 | // goleak.VerifyTestMain(m) 28 | //} 29 | -------------------------------------------------------------------------------- /util/math/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package math 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "testing" 22 | 23 | "go.uber.org/goleak" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | testbridge2.WorkaroundGoCheckFlags() 28 | goleak.VerifyTestMain(m) 29 | } 30 | -------------------------------------------------------------------------------- /util/pdapi/const.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package pdapi 18 | 19 | // The following constants are the APIs of PD server. 20 | const ( 21 | HotRead = "/pd/api/v1/hotspot/regions/read" 22 | HotWrite = "/pd/api/v1/hotspot/regions/write" 23 | Regions = "/pd/api/v1/regions" 24 | RegionByID = "/pd/api/v1/region/id/" 25 | Stores = "/pd/api/v1/stores" 26 | ClusterVersion = "/pd/api/v1/config/cluster-version" 27 | Status = "/pd/api/v1/status" 28 | Config = "/pd/api/v1/config" 29 | ) 30 | -------------------------------------------------------------------------------- /util/printer/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package printer 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "testing" 22 | 23 | "go.uber.org/goleak" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | testbridge2.WorkaroundGoCheckFlags() 28 | goleak.VerifyTestMain(m) 29 | } 30 | -------------------------------------------------------------------------------- /util/signal/signal_windows.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package signal 18 | 19 | import ( 20 | "os" 21 | "os/signal" 22 | "syscall" 23 | ) 24 | 25 | // SetupSignalHandler setup signal handler for TiDB Server 26 | func SetupSignalHandler(shutdownFunc func(bool)) { 27 | //todo deal with dump goroutine stack on windows 28 | closeSignalChan := make(chan os.Signal, 1) 29 | signal.Notify(closeSignalChan, 30 | syscall.SIGHUP, 31 | syscall.SIGINT, 32 | syscall.SIGTERM, 33 | syscall.SIGQUIT) 34 | 35 | go func() { 36 | sig := <-closeSignalChan 37 | //logutil.BgLogger().Info("got signal to exit", zap.Stringer("signal", sig)) 38 | shutdownFunc(sig == syscall.SIGQUIT) 39 | }() 40 | } 41 | -------------------------------------------------------------------------------- /util/slice/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package slice 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "testing" 22 | 23 | "go.uber.org/goleak" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | testbridge2.WorkaroundGoCheckFlags() 28 | goleak.VerifyTestMain(m) 29 | } 30 | -------------------------------------------------------------------------------- /util/slice/slice.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package slice 18 | 19 | import "reflect" 20 | 21 | // AnyOf returns true if any element in the slice matches the predict func. 22 | func AnyOf(s interface{}, p func(int) bool) bool { 23 | l := reflect.ValueOf(s).Len() 24 | for i := 0; i < l; i++ { 25 | if p(i) { 26 | return true 27 | } 28 | } 29 | return false 30 | } 31 | 32 | // NoneOf returns true if no element in the slice matches the predict func. 33 | func NoneOf(s interface{}, p func(int) bool) bool { 34 | return !AnyOf(s, p) 35 | } 36 | 37 | // AllOf returns true if all elements in the slice match the predict func. 38 | func AllOf(s interface{}, p func(int) bool) bool { 39 | np := func(i int) bool { 40 | return !p(i) 41 | } 42 | return NoneOf(s, np) 43 | } 44 | -------------------------------------------------------------------------------- /util/slice/slice_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package slice 18 | 19 | import ( 20 | "fmt" 21 | "testing" 22 | 23 | "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestSlice(t *testing.T) { 27 | tests := []struct { 28 | a []int 29 | anyOf bool 30 | noneOf bool 31 | allOf bool 32 | }{ 33 | {[]int{}, false, true, true}, 34 | {[]int{1, 2, 3}, true, false, false}, 35 | {[]int{1, 3}, false, true, false}, 36 | {[]int{2, 2, 4}, true, false, true}, 37 | } 38 | 39 | for _, test := range tests { 40 | t.Run(fmt.Sprint(test.a), func(t *testing.T) { 41 | t.Parallel() 42 | even := func(i int) bool { return test.a[i]%2 == 0 } 43 | require.Equal(t, test.anyOf, AnyOf(test.a, even)) 44 | require.Equal(t, test.noneOf, NoneOf(test.a, even)) 45 | require.Equal(t, test.allOf, AllOf(test.a, even)) 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /util/stringutil/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package stringutil 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "testing" 22 | 23 | "go.uber.org/goleak" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | testbridge2.WorkaroundGoCheckFlags() 28 | goleak.VerifyTestMain(m) 29 | } 30 | -------------------------------------------------------------------------------- /util/sys/linux/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package linux_test 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "testing" 22 | 23 | "go.uber.org/goleak" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | testbridge2.WorkaroundGoCheckFlags() 28 | goleak.VerifyTestMain(m) 29 | } 30 | -------------------------------------------------------------------------------- /util/sys/linux/sys_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | package linux_test 17 | 18 | import ( 19 | "github.com/pingcap/tiunimanager/util/sys/linux" 20 | "testing" 21 | 22 | "github.com/stretchr/testify/require" 23 | ) 24 | 25 | func TestGetOSVersion(t *testing.T) { 26 | t.Parallel() 27 | 28 | osRelease, err := linux.OSVersion() 29 | require.NoError(t, err) 30 | require.NotEmpty(t, osRelease) 31 | } 32 | -------------------------------------------------------------------------------- /util/sys/storage/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package storage 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "testing" 22 | 23 | "go.uber.org/goleak" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | testbridge2.WorkaroundGoCheckFlags() 28 | goleak.VerifyTestMain(m) 29 | } 30 | -------------------------------------------------------------------------------- /util/sys/storage/sys_other.go: -------------------------------------------------------------------------------- 1 | // +build !linux,!windows,!darwin 2 | 3 | /****************************************************************************** 4 | * Copyright (c) 2021 PingCAP * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); * 6 | * you may not use this file except in compliance with the License. * 7 | * You may obtain a copy of the License at * 8 | * * 9 | * http://www.apache.org/licenses/LICENSE-2.0 * 10 | * * 11 | * Unless required by applicable law or agreed to in writing, software * 12 | * distributed under the License is distributed on an "AS IS" BASIS, * 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 14 | * See the License for the specific language governing permissions and * 15 | * limitations under the License. * 16 | * * 17 | ******************************************************************************/ 18 | 19 | package storage 20 | 21 | import "math" 22 | 23 | // GetTargetDirectoryCapacity get the capacity (bytes) of directory 24 | func GetTargetDirectoryCapacity(path string) (uint64, error) { 25 | return math.MaxInt64, nil 26 | } 27 | -------------------------------------------------------------------------------- /util/sys/storage/sys_posix.go: -------------------------------------------------------------------------------- 1 | // +build linux darwin 2 | 3 | /****************************************************************************** 4 | * Copyright (c) 2021 PingCAP * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); * 6 | * you may not use this file except in compliance with the License. * 7 | * You may obtain a copy of the License at * 8 | * * 9 | * http://www.apache.org/licenses/LICENSE-2.0 * 10 | * * 11 | * Unless required by applicable law or agreed to in writing, software * 12 | * distributed under the License is distributed on an "AS IS" BASIS, * 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 14 | * See the License for the specific language governing permissions and * 15 | * limitations under the License. * 16 | * * 17 | ******************************************************************************/ 18 | 19 | package storage 20 | 21 | import "syscall" 22 | 23 | // GetTargetDirectoryCapacity get the capacity (bytes) of directory 24 | func GetTargetDirectoryCapacity(path string) (uint64, error) { 25 | var stat syscall.Statfs_t 26 | err := syscall.Statfs(path, &stat) 27 | if err != nil { 28 | return 0, err 29 | } 30 | c := stat.Bavail * uint64(stat.Bsize) 31 | return c, nil 32 | } 33 | -------------------------------------------------------------------------------- /util/sys/storage/sys_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package storage_test 18 | 19 | import ( 20 | storage2 "github.com/pingcap/tiunimanager/util/sys/storage" 21 | "testing" 22 | 23 | "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestGetTargetDirectoryCapacity(t *testing.T) { 27 | t.Parallel() 28 | r, err := storage2.GetTargetDirectoryCapacity(".") 29 | require.NoError(t, err) 30 | require.GreaterOrEqual(t, r, uint64(1), "couldn't get capacity") 31 | 32 | //TODO: check the value of r with `df` in linux 33 | } 34 | -------------------------------------------------------------------------------- /util/sys/storage/sys_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | /****************************************************************************** 4 | * Copyright (c) 2021 PingCAP * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); * 6 | * you may not use this file except in compliance with the License. * 7 | * You may obtain a copy of the License at * 8 | * * 9 | * http://www.apache.org/licenses/LICENSE-2.0 * 10 | * * 11 | * Unless required by applicable law or agreed to in writing, software * 12 | * distributed under the License is distributed on an "AS IS" BASIS, * 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 14 | * See the License for the specific language governing permissions and * 15 | * limitations under the License. * 16 | * * 17 | ******************************************************************************/ 18 | 19 | package storage 20 | 21 | import ( 22 | "golang.org/x/sys/windows" 23 | ) 24 | 25 | // GetTargetDirectoryCapacity get the capacity (bytes) of directory 26 | func GetTargetDirectoryCapacity(path string) (uint64, error) { 27 | var freeBytes uint64 28 | err := windows.GetDiskFreeSpaceEx(windows.StringToUTF16Ptr(path), &freeBytes, nil, nil) 29 | if err != nil { 30 | return 0, err 31 | } 32 | return freeBytes, nil 33 | } 34 | -------------------------------------------------------------------------------- /util/systimemon/systime_mon.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package systimemon 18 | 19 | import ( 20 | "time" 21 | 22 | "github.com/pingcap/tiunimanager/library/framework" 23 | "go.uber.org/zap" 24 | ) 25 | 26 | // StartMonitor calls systimeErrHandler if system time jump backward. 27 | func StartMonitor(now func() time.Time, systimeErrHandler func(), successCallback func()) { 28 | framework.Log().Info("start system time monitor") 29 | tick := time.NewTicker(100 * time.Millisecond) 30 | defer tick.Stop() 31 | tickCount := 0 32 | for { 33 | last := now().UnixNano() 34 | <-tick.C 35 | if now().UnixNano() < last { 36 | framework.Log().Error("system time jump backward", zap.Int64("last", last)) 37 | systimeErrHandler() 38 | } 39 | // call successCallback per second. 40 | tickCount++ 41 | if tickCount >= 10 { 42 | tickCount = 0 43 | successCallback() 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /util/systimemon/systime_mon_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package systimemon 18 | 19 | import ( 20 | "testing" 21 | "time" 22 | 23 | "github.com/stretchr/testify/require" 24 | "go.uber.org/atomic" 25 | ) 26 | 27 | func TestSystimeMonitor(t *testing.T) { 28 | t.Parallel() 29 | 30 | errTriggered := atomic.NewBool(false) 31 | nowTriggered := atomic.NewBool(false) 32 | go StartMonitor( 33 | func() time.Time { 34 | if !nowTriggered.Load() { 35 | nowTriggered.Store(true) 36 | return time.Now() 37 | } 38 | 39 | return time.Now().Add(-2 * time.Second) 40 | }, func() { 41 | errTriggered.Store(true) 42 | }, func() {}) 43 | 44 | require.Eventually(t, errTriggered.Load, time.Second, 10*time.Millisecond) 45 | } 46 | -------------------------------------------------------------------------------- /util/testbridge/bridge.go: -------------------------------------------------------------------------------- 1 | // +build !codes 2 | 3 | /****************************************************************************** 4 | * Copyright (c) 2021 PingCAP * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); * 6 | * you may not use this file except in compliance with the License. * 7 | * You may obtain a copy of the License at * 8 | * * 9 | * http://www.apache.org/licenses/LICENSE-2.0 * 10 | * * 11 | * Unless required by applicable law or agreed to in writing, software * 12 | * distributed under the License is distributed on an "AS IS" BASIS, * 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 14 | * See the License for the specific language governing permissions and * 15 | * limitations under the License. * 16 | * * 17 | ******************************************************************************/ 18 | 19 | package testbridge 20 | 21 | import ( 22 | "flag" 23 | ) 24 | 25 | // WorkaroundGoCheckFlags registers flags of go-check for pkg does not import go-check 26 | // to workaround the go-check flags passed in Makefile. 27 | // 28 | // TODO: Remove this function when the migration from go-check to testify[1] is done. 29 | // [1] https://github.com/pingcap/tidb/issues/26022 30 | func WorkaroundGoCheckFlags() { 31 | if flag.Lookup("check.timeout") == nil { 32 | _ = flag.Duration("check.timeout", 0, "WorkaroundGoCheckFlags: check.timeout") 33 | } 34 | if flag.Lookup("check.p") == nil { 35 | _ = flag.Bool("check.p", false, "WorkaroundGoCheckFlags: check.p") 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /util/testkit/fake.go: -------------------------------------------------------------------------------- 1 | // +build codes 2 | 3 | /****************************************************************************** 4 | * Copyright (c) 2021 PingCAP * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); * 6 | * you may not use this file except in compliance with the License. * 7 | * You may obtain a copy of the License at * 8 | * * 9 | * http://www.apache.org/licenses/LICENSE-2.0 * 10 | * * 11 | * Unless required by applicable law or agreed to in writing, software * 12 | * distributed under the License is distributed on an "AS IS" BASIS, * 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 14 | * See the License for the specific language governing permissions and * 15 | * limitations under the License. * 16 | * * 17 | ******************************************************************************/ 18 | 19 | package testkit 20 | -------------------------------------------------------------------------------- /util/testleak/add-leaktest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2021 PingCAP 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | 18 | set -eu 19 | 20 | sed -i'~' -e ' 21 | /^func (s \*test.*Suite) Test.*(c \*C) {/ { 22 | n 23 | /testleak.AfterTest/! i\ 24 | defer testleak.AfterTest(c)() 25 | } 26 | ' $@ 27 | 28 | for i in $@; do 29 | if ! cmp -s $i $i~ ; then 30 | goimports -w $i 31 | fi 32 | echo $i 33 | rm -f $i~ 34 | done 35 | -------------------------------------------------------------------------------- /util/testleak/check-leaktest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2021 PingCAP 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | 18 | set -e 19 | 20 | pkgs=$(git grep 'Suite' |grep -vE "Godeps|tags" |awk -F: '{print $1}' | xargs -n1 dirname | sort |uniq) 21 | echo $pkgs 22 | for pkg in ${pkgs}; do 23 | if [ -z "$(ls ${pkg}/*_test.go 2>/dev/null)" ]; then 24 | continue 25 | fi 26 | awk -F'[(]' ' 27 | /func \(s .*Suite\) Test.*C\) {/ { 28 | test = $1"("$2 29 | next 30 | } 31 | 32 | /defer testleak.AfterTest/ { 33 | test = 0 34 | next 35 | } 36 | 37 | { 38 | if (test && (FILENAME != "./tidb_test.go")) { 39 | printf "%s: %s: missing defer testleak.AfterTest\n", FILENAME, test 40 | test = 0 41 | code = 1 42 | } 43 | } 44 | 45 | END { 46 | exit code 47 | } 48 | 49 | ' ${pkg}/*_test.go 50 | done 51 | -------------------------------------------------------------------------------- /util/tracing/main_test.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package tracing 18 | 19 | import ( 20 | testbridge2 "github.com/pingcap/tiunimanager/util/testbridge" 21 | "testing" 22 | 23 | "go.uber.org/goleak" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | testbridge2.WorkaroundGoCheckFlags() 28 | goleak.VerifyTestMain(m) 29 | } 30 | -------------------------------------------------------------------------------- /util/uuidutil/idgenerator.go: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * Copyright (c) 2021 PingCAP * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * 5 | * you may not use this file except in compliance with the License. * 6 | * You may obtain a copy of the License at * 7 | * * 8 | * http://www.apache.org/licenses/LICENSE-2.0 * 9 | * * 10 | * Unless required by applicable law or agreed to in writing, software * 11 | * distributed under the License is distributed on an "AS IS" BASIS, * 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 13 | * See the License for the specific language governing permissions and * 14 | * limitations under the License. * 15 | * * 16 | ******************************************************************************/ 17 | 18 | package uuidutil 19 | 20 | import ( 21 | "encoding/base64" 22 | "strings" 23 | 24 | "github.com/google/uuid" 25 | "github.com/lithammer/shortuuid" 26 | ) 27 | 28 | const ( 29 | ENTITY_UUID_LENGTH int = 22 30 | ) 31 | 32 | // GenerateID Encode with Base64 33 | // URLEncoding Set contains '-' and '_' 34 | func GenerateID() string { 35 | var encoded []byte = nil 36 | 37 | for encoded == nil || strings.HasPrefix(string(encoded), "-") || strings.HasPrefix(string(encoded), "_"){ 38 | uuid := uuid.New() 39 | 40 | encoded = make([]byte, ENTITY_UUID_LENGTH) 41 | base64.URLEncoding.WithPadding(base64.NoPadding).Encode(encoded, uuid[0:16]) 42 | } 43 | 44 | return string(encoded) 45 | } 46 | 47 | // ShortId Encode with Base57 48 | func ShortId() string { 49 | return shortuuid.New() 50 | } 51 | -------------------------------------------------------------------------------- /util/versioninfo/versioninfo.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | * * 15 | ******************************************************************************/ 16 | 17 | package versioninfo 18 | 19 | const ( 20 | // EnterpriseEdition is the default edition for building. 21 | EnterpriseEdition = "Enterprise" 22 | ) 23 | 24 | // Version information. 25 | var ( 26 | TiUniManagerReleaseVersion = "Non" 27 | TiUniManagerBuildTS = "None" 28 | TiUniManagerGitHash = "None" 29 | TiUniManagerGitBranch = "None" 30 | TiUniManagerEdition = EnterpriseEdition 31 | ) 32 | -------------------------------------------------------------------------------- /workflow/common.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package workflow 17 | 18 | /* 19 | type NodeReturnType string 20 | 21 | const ( 22 | SyncFuncNode NodeReturnType = "SyncFuncNode" 23 | PollingNode NodeReturnType = "PollingNode" 24 | ) 25 | 26 | const ( 27 | BizTypeCluster string = "cluster" 28 | BizTypeHost string = "host" 29 | BizTypeCheckReport string = "checkReport" 30 | ) 31 | 32 | const ( 33 | maxPollingSequence int32 = 10 * 24 * 3600 34 | ) 35 | */ 36 | -------------------------------------------------------------------------------- /workflow2/common.go: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021 PingCAP * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); * 4 | * you may not use this file except in compliance with the License. * 5 | * You may obtain a copy of the License at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * Unless required by applicable law or agreed to in writing, software * 10 | * distributed under the License is distributed on an "AS IS" BASIS, * 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 12 | * See the License for the specific language governing permissions and * 13 | * limitations under the License. * 14 | ******************************************************************************/ 15 | 16 | package workflow2 17 | 18 | type NodeReturnType string 19 | 20 | const ( 21 | SyncFuncNode NodeReturnType = "SyncFuncNode" 22 | PollingNode NodeReturnType = "PollingNode" 23 | ) 24 | 25 | const ( 26 | BizTypeCluster string = "cluster" 27 | BizTypeHost string = "host" 28 | BizTypePlatform string = "platform" 29 | ) 30 | 31 | const ( 32 | maxPollingSequence int32 = 10 * 24 * 3600 33 | defaultPageSize int = 10 34 | ) 35 | --------------------------------------------------------------------------------