From 494c982fe057e84292032e4814a890672b01adab Mon Sep 17 00:00:00 2001 From: Saurabh Ahuja <saurabh.ahuja@oracle.com> Date: Thu, 29 Aug 2024 04:02:38 +0000 Subject: [PATCH 1/3] add containerfiles folder --- container-based-sharding-deployment/README.md | 201 ++ .../containerfiles/19.3.0/19c_gsm_install.rsp | 35 + .../19.3.0/19c_gsm_install_sample.rsp | 35 + .../containerfiles/19.3.0/Checksum | 1 + .../containerfiles/19.3.0/Containerfile | 91 + .../containerfiles/19.3.0/Dockerfile_19c | 89 + .../containerfiles/19.3.0/checkLiveness.sh | 12 + .../containerfiles/19.3.0/checkSpace.sh | 16 + .../19.3.0/installGSMBinaries.sh | 37 + .../containerfiles/19.3.0/runOracle.sh | 36 + .../containerfiles/19.3.0/runOracle.sh_orig | 189 ++ .../containerfiles/19.3.0/runUserScripts.sh | 33 + .../containerfiles/19.3.0/scripts/cmdExec | 23 + .../containerfiles/19.3.0/scripts/demoapp.sql | 88 + .../containerfiles/19.3.0/scripts/main.py | 171 + .../19.3.0/scripts/oracommon.py | 886 +++++ .../containerfiles/19.3.0/scripts/oraenv.py | 139 + .../19.3.0/scripts/orafactory.py | 115 + .../containerfiles/19.3.0/scripts/oragsm.py | 2945 +++++++++++++++++ .../19.3.0/scripts/oralogger.py | 181 + .../19.3.0/scripts/oramachine.py | 45 + .../19.3.0/scripts/orapcatalog.py | 748 +++++ .../19.3.0/scripts/orapshard.py | 795 +++++ .../19.3.0/scripts/orascatalog.py | 9 + .../19.3.0/scripts/orasshard.py | 58 + .../19.3.0/scripts/runOraShardSetup.sh | 568 ++++ .../19.3.0/scripts/runOracle.sh | 78 + .../containerfiles/19.3.0/setupGSM.sh | 25 + .../containerfiles/19.3.0/setupLinuxEnv.sh | 11 + .../containerfiles/19.3.0/setupOshardEnv.sh | 963 ++++++ .../containerfiles/21.3.0/21c_gsm_install.rsp | 35 + .../21.3.0/21c_gsm_install_sample.rsp | 35 + .../containerfiles/21.3.0/Checksum | 1 + .../containerfiles/21.3.0/Containerfile | 144 + .../containerfiles/21.3.0/Dockerfile_21c | 85 + .../containerfiles/21.3.0/checkLiveness.sh | 22 + .../containerfiles/21.3.0/checkSpace.sh | 23 + .../21.3.0/installGSMBinaries.sh | 43 + .../containerfiles/21.3.0/runOracle.sh | 39 + .../containerfiles/21.3.0/runUserScripts.sh | 35 + .../containerfiles/21.3.0/scripts/cmdExec | 23 + .../containerfiles/21.3.0/scripts/demoapp.sql | 88 + .../containerfiles/21.3.0/scripts/main.py | 171 + .../21.3.0/scripts/oracommon.py | 886 +++++ .../containerfiles/21.3.0/scripts/oraenv.py | 139 + .../21.3.0/scripts/orafactory.py | 115 + .../containerfiles/21.3.0/scripts/oragsm.py | 2945 +++++++++++++++++ .../21.3.0/scripts/oralogger.py | 181 + .../21.3.0/scripts/oramachine.py | 45 + .../21.3.0/scripts/orapcatalog.py | 748 +++++ .../21.3.0/scripts/orapshard.py | 795 +++++ .../21.3.0/scripts/orascatalog.py | 9 + .../21.3.0/scripts/orasshard.py | 58 + .../21.3.0/scripts/runOraShardSetup.sh | 568 ++++ .../21.3.0/scripts/runOracle.sh | 78 + .../containerfiles/21.3.0/setupGSM.sh | 31 + .../containerfiles/21.3.0/setupLinuxEnv.sh | 14 + .../containerfiles/21.3.0/setupOshardEnv.sh | 970 ++++++ .../containerfiles/23.3.0/23c_gsm_install.rsp | 35 + .../23.3.0/23c_gsm_install_sample.rsp | 35 + .../containerfiles/23.3.0/Checksum | 1 + .../containerfiles/23.3.0/Containerfile | 143 + .../containerfiles/23.3.0/Dockerfile_21c | 85 + .../containerfiles/23.3.0/checkLiveness.sh | 22 + .../containerfiles/23.3.0/checkSpace.sh | 23 + .../23.3.0/installGSMBinaries.sh | 43 + .../containerfiles/23.3.0/runOracle.sh | 39 + .../containerfiles/23.3.0/runUserScripts.sh | 35 + .../containerfiles/23.3.0/scripts/cmdExec | 23 + .../containerfiles/23.3.0/scripts/demoapp.sql | 88 + .../containerfiles/23.3.0/scripts/main.py | 171 + .../23.3.0/scripts/oracommon.py | 886 +++++ .../containerfiles/23.3.0/scripts/oraenv.py | 139 + .../23.3.0/scripts/orafactory.py | 115 + .../containerfiles/23.3.0/scripts/oragsm.py | 2945 +++++++++++++++++ .../23.3.0/scripts/oralogger.py | 181 + .../23.3.0/scripts/oramachine.py | 45 + .../23.3.0/scripts/orapcatalog.py | 748 +++++ .../23.3.0/scripts/orapshard.py | 795 +++++ .../23.3.0/scripts/orascatalog.py | 9 + .../23.3.0/scripts/orasshard.py | 58 + .../23.3.0/scripts/runOraShardSetup.sh | 568 ++++ .../23.3.0/scripts/runOracle.sh | 78 + .../containerfiles/23.3.0/setupGSM.sh | 31 + .../containerfiles/23.3.0/setupLinuxEnv.sh | 14 + .../containerfiles/23.3.0/setupOshardEnv.sh | 970 ++++++ .../containerfiles/23.4.0/23c_gsm_install.rsp | 35 + .../23.4.0/23c_gsm_install_sample.rsp | 35 + .../containerfiles/23.4.0/Checksum | 1 + .../containerfiles/23.4.0/Containerfile | 232 ++ .../containerfiles/23.4.0/checkLiveness.sh | 22 + .../containerfiles/23.4.0/checkSpace.sh | 23 + .../23.4.0/installGSMBinaries.sh | 43 + .../containerfiles/23.4.0/runOracle.sh | 39 + .../containerfiles/23.4.0/runUserScripts.sh | 35 + .../containerfiles/23.4.0/scripts/cmdExec | 23 + .../containerfiles/23.4.0/scripts/demoapp.sql | 88 + .../containerfiles/23.4.0/scripts/main.py | 171 + .../23.4.0/scripts/oracommon.py | 966 ++++++ .../containerfiles/23.4.0/scripts/oraenv.py | 139 + .../23.4.0/scripts/orafactory.py | 115 + .../containerfiles/23.4.0/scripts/oragsm.py | 2945 +++++++++++++++++ .../23.4.0/scripts/oralogger.py | 181 + .../23.4.0/scripts/oramachine.py | 45 + .../23.4.0/scripts/orapcatalog.py | 790 +++++ .../23.4.0/scripts/orapshard.py | 838 +++++ .../23.4.0/scripts/orascatalog.py | 9 + .../23.4.0/scripts/orasshard.py | 58 + .../23.4.0/scripts/runOraShardSetup.sh | 568 ++++ .../23.4.0/scripts/runOracle.sh | 78 + .../containerfiles/23.4.0/setupGSM.sh | 31 + .../containerfiles/23.4.0/setupLinuxEnv.sh | 28 + .../containerfiles/23.4.0/setupOshardEnv.sh | 970 ++++++ .../containerfiles/23.5.0/23c_gsm_install.rsp | 35 + .../23.5.0/23c_gsm_install_sample.rsp | 35 + .../containerfiles/23.5.0/Checksum | 1 + .../containerfiles/23.5.0/Containerfile | 232 ++ .../containerfiles/23.5.0/checkLiveness.sh | 22 + .../containerfiles/23.5.0/checkSpace.sh | 23 + .../23.5.0/installGSMBinaries.sh | 43 + .../containerfiles/23.5.0/runOracle.sh | 39 + .../containerfiles/23.5.0/runUserScripts.sh | 35 + .../containerfiles/23.5.0/scripts/cmdExec | 23 + .../containerfiles/23.5.0/scripts/demoapp.sql | 88 + .../containerfiles/23.5.0/scripts/main.py | 171 + .../23.5.0/scripts/oracommon.py | 966 ++++++ .../containerfiles/23.5.0/scripts/oraenv.py | 139 + .../23.5.0/scripts/orafactory.py | 115 + .../containerfiles/23.5.0/scripts/oragsm.py | 2945 +++++++++++++++++ .../23.5.0/scripts/oralogger.py | 181 + .../23.5.0/scripts/oramachine.py | 45 + .../23.5.0/scripts/orapcatalog.py | 790 +++++ .../23.5.0/scripts/orapshard.py | 838 +++++ .../23.5.0/scripts/orascatalog.py | 9 + .../23.5.0/scripts/orasshard.py | 58 + .../23.5.0/scripts/runOraShardSetup.sh | 568 ++++ .../23.5.0/scripts/runOracle.sh | 78 + .../containerfiles/23.5.0/setupGSM.sh | 31 + .../containerfiles/23.5.0/setupLinuxEnv.sh | 28 + .../containerfiles/23.5.0/setupOshardEnv.sh | 970 ++++++ .../containerfiles/buildContainerImage.sh | 176 + .../containerfiles/setup_gdd_host.sh | 502 +++ .../containerfiles/shard-podman.te | 27 + .../docs/ENVVARIABLESCOMPOSE.md | 50 + .../docs/QUICKSTART.md | 226 ++ .../compose-files/docker-compose/README.md | 106 + .../docker-compose-prerequisites.sh | 130 + .../docker-compose/docker-compose.yml | 169 + .../compose-files/podman-compose/README.md | 137 + .../podman-compose/podman-compose-free.yml | 213 ++ .../podman-compose-prerequisites-free.sh | 139 + .../podman-compose-prerequisites.sh | 127 + .../podman-compose/podman-compose.yml | 202 ++ .../podman-compose/set-file-context.sh | 21 + .../docker-container-files/README.md | 136 + ...r-sharded-database-with-system-sharding.md | 579 ++++ ...ded-database-with-user-defined-sharding.md | 603 ++++ .../podman-container-files-free/README.md | 188 ++ ...h-system-sharding-with-snr-raft-enabled.md | 628 ++++ ...rded-database-free-with-system-sharding.md | 605 ++++ ...atabase-free-with-user-defined-sharding.md | 615 ++++ .../podman-container-files/README.md | 172 + ...h-system-sharding-with-snr-raft-enabled.md | 627 ++++ ...n-sharded-database-with-system-sharding.md | 598 ++++ ...ded-database-with-user-defined-sharding.md | 618 ++++ 165 files changed, 49884 insertions(+) create mode 100644 container-based-sharding-deployment/README.md create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/19c_gsm_install.rsp create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/19c_gsm_install_sample.rsp create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/Checksum create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/Containerfile create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/Dockerfile_19c create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/checkLiveness.sh create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/checkSpace.sh create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/installGSMBinaries.sh create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/runOracle.sh create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/runOracle.sh_orig create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/runUserScripts.sh create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/cmdExec create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/demoapp.sql create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/main.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/oracommon.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/oraenv.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/orafactory.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/oragsm.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/oralogger.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/oramachine.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/orapcatalog.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/orapshard.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/orascatalog.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/orasshard.py create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/runOraShardSetup.sh create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/scripts/runOracle.sh create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/setupGSM.sh create mode 100644 container-based-sharding-deployment/containerfiles/19.3.0/setupLinuxEnv.sh create mode 100755 container-based-sharding-deployment/containerfiles/19.3.0/setupOshardEnv.sh create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/21c_gsm_install.rsp create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/21c_gsm_install_sample.rsp create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/Checksum create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/Containerfile create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/Dockerfile_21c create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/checkLiveness.sh create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/checkSpace.sh create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/installGSMBinaries.sh create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/runOracle.sh create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/runUserScripts.sh create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/cmdExec create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/demoapp.sql create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/main.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/oracommon.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/oraenv.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/orafactory.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/oragsm.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/oralogger.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/oramachine.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/orapcatalog.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/orapshard.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/orascatalog.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/orasshard.py create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/runOraShardSetup.sh create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/scripts/runOracle.sh create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/setupGSM.sh create mode 100644 container-based-sharding-deployment/containerfiles/21.3.0/setupLinuxEnv.sh create mode 100755 container-based-sharding-deployment/containerfiles/21.3.0/setupOshardEnv.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install.rsp create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install_sample.rsp create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/Checksum create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/Containerfile create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/Dockerfile_21c create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/checkLiveness.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/checkSpace.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/installGSMBinaries.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/runOracle.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/runUserScripts.sh create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/cmdExec create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/demoapp.sql create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/main.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/oracommon.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/oraenv.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/orafactory.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/oragsm.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/oralogger.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/oramachine.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapcatalog.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapshard.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/orascatalog.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/orasshard.py create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOraShardSetup.sh create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOracle.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/setupGSM.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/setupLinuxEnv.sh create mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/setupOshardEnv.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install.rsp create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install_sample.rsp create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/Checksum create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/Containerfile create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/checkLiveness.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/checkSpace.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/installGSMBinaries.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/runOracle.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/runUserScripts.sh create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/cmdExec create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/demoapp.sql create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/main.py create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/oracommon.py create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/oraenv.py create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/orafactory.py create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/oragsm.py create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/oralogger.py create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/oramachine.py create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapcatalog.py create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapshard.py create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/orascatalog.py create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/orasshard.py create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOraShardSetup.sh create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOracle.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/setupGSM.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/setupLinuxEnv.sh create mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/setupOshardEnv.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/23c_gsm_install.rsp create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/23c_gsm_install_sample.rsp create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/Checksum create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/Containerfile create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/checkLiveness.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/checkSpace.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/installGSMBinaries.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/runOracle.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/runUserScripts.sh create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/cmdExec create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/demoapp.sql create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/main.py create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/oracommon.py create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/oraenv.py create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/orafactory.py create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/oragsm.py create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/oralogger.py create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/oramachine.py create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/orapcatalog.py create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/orapshard.py create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/orascatalog.py create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/orasshard.py create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/scripts/runOraShardSetup.sh create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/scripts/runOracle.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/setupGSM.sh create mode 100644 container-based-sharding-deployment/containerfiles/23.5.0/setupLinuxEnv.sh create mode 100755 container-based-sharding-deployment/containerfiles/23.5.0/setupOshardEnv.sh create mode 100755 container-based-sharding-deployment/containerfiles/buildContainerImage.sh create mode 100755 container-based-sharding-deployment/containerfiles/setup_gdd_host.sh create mode 100644 container-based-sharding-deployment/containerfiles/shard-podman.te create mode 100644 container-based-sharding-deployment/docs/ENVVARIABLESCOMPOSE.md create mode 100644 container-based-sharding-deployment/docs/QUICKSTART.md create mode 100644 container-based-sharding-deployment/samples/compose-files/docker-compose/README.md create mode 100644 container-based-sharding-deployment/samples/compose-files/docker-compose/docker-compose-prerequisites.sh create mode 100644 container-based-sharding-deployment/samples/compose-files/docker-compose/docker-compose.yml create mode 100644 container-based-sharding-deployment/samples/compose-files/podman-compose/README.md create mode 100644 container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-free.yml create mode 100644 container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-prerequisites-free.sh create mode 100644 container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-prerequisites.sh create mode 100644 container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose.yml create mode 100644 container-based-sharding-deployment/samples/compose-files/podman-compose/set-file-context.sh create mode 100644 container-based-sharding-deployment/samples/container-files/docker-container-files/README.md create mode 100644 container-based-sharding-deployment/samples/container-files/docker-container-files/docker-sharded-database-with-system-sharding.md create mode 100644 container-based-sharding-deployment/samples/container-files/docker-container-files/docker-sharded-database-with-user-defined-sharding.md create mode 100644 container-based-sharding-deployment/samples/container-files/podman-container-files-free/README.md create mode 100644 container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-system-sharding-with-snr-raft-enabled.md create mode 100644 container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-system-sharding.md create mode 100644 container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-user-defined-sharding.md create mode 100644 container-based-sharding-deployment/samples/container-files/podman-container-files/README.md create mode 100644 container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-system-sharding-with-snr-raft-enabled.md create mode 100644 container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-system-sharding.md create mode 100644 container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-user-defined-sharding.md diff --git a/container-based-sharding-deployment/README.md b/container-based-sharding-deployment/README.md new file mode 100644 index 0000000..23f0774 --- /dev/null +++ b/container-based-sharding-deployment/README.md @@ -0,0 +1,201 @@ +# Oracle Globally Distributed Database in Linux Containers + +Learn about container deployment options for Oracle Globally Distributed Database in Linux Containers Release 23ai (v23.5). + +## Overview of Oracle Globally Distributed Database in Linux Containers + +Oracle Globally Distributed Database is a scalability and availability feature for custom-designed OLTP applications that enables the distribution and replication of data across a pool of Oracle Databases that do not share hardware or software. The pool of databases is presented to the application as a single logical database. + +This project provides sample container files to facilitate installation, configuration, and environment setup for DevOps users. For more information about Oracle Database, see: [Oracle Globally Distributed Database Management Documentation](http://docs.oracle.com/en/database/). + +Review each of the sections of this README in the order given. After reviewing each section of the README, you can skip the image or container creation sections that do not apply to you. + +This project offers example container files for the following: + +* Oracle Database 23ai Global Service Manager (GSM/GDS) (23.5.0) for Linux x86-64 +* Older Releases: Oracle 19c (19.3) and Oracle 21c (21.3) for Linux x86-64 + + +## Using this Documentation +To create an Oracle Globally Distributed Database Container environment, follow these steps: + +- [Oracle Globally Distributed Database in Linux Containers](#oracle-globally-distributed-database-in-linux-containers) + - [Overview of Oracle Globally Distributed Database in Linux Containers](#overview-of-oracle-globally-distributed-database-in-linux-containers) + - [Using this Documentation](#using-this-documentation) + - [Preparation Steps for running Oracle Globally Distributed Database in Linux Containers](#preparation-steps-for-running-oracle-globally-distributed-database-in-linux-containers) + - [QuickStart](#quickstart) + - [Building Oracle Globally Distributed Database Container Images](#building-oracle-globally-distributed-database-container-images) + - [Building Oracle Global Service Manager Image](#building-oracle-global-service-manager-image) + - [Building Oracle Database Image](#building-oracle-database-image) + - [Building Extended Oracle Database Image with Oracle Globally Distributed Database Feature](#building-extended-oracle-database-image-with-globally-distributed-database-feature) + - [Oracle Globally Distributed Database in Containers Deployment Scenarios](#oracle-globally-distributed-database-in-containers-deployment-scenarios) + - [Deploy Oracle Globally Distributed Database Containers](#deploy-oracle-database-globally-distributed-database-containers) + - [Deploy Oracle Globally Distributed Database Containers on Podman](#deploy-oracle-globally-distributed-database-containers-on-podman) + - [Deploy Oracle Globally Distributed Database Containers on Docker](#deploy-oracle-globally-distributed-database-containers-on-docker) + - [Deploy Oracle Globally Distributed Database Containers on Podman using Oracle 23ai FREE Images](#deploy-oracle-globally-distributed-database-containers-on-podman-using-oracle-23ai-free-images) + - [Oracle Globally Distributed Database in Containers Deployment using docker-compose](#oracle-globally-distributed-database-in-containers-deployment-using-docker-compose) + - [Oracle Globally Distributed Database in Containers Deployment using podman-compose](#oracle-globally-distributed-database-in-containers-deployment-using-podman-compose) + - [Support](#support) + - [License](#license) + - [Copyright](#copyright) + +## Preparation Steps for running Oracle Globally Distributed Database in Linux Containers +**Note :** All Steps or Commands in this guide must be run as `root` or with a `sudo` user. +* Before you proceed, complete the following prerequisites for your platform: + * If you are using Oracle Linux 7, then install Docker. + * If you are using an Oracle Linux 7 system, then you must install [Docker Engine](https://docs.oracle.com/en/operating-systems/oracle-linux/docker/). + * Install `docker-engine` and `docker-cli` using yum command. + ```bash + yum-config-manager --enable ol7_addons + yum install docker-engine docker-cli + yum start docker + systemctl enable --now docker + ``` + * If you are using Oracle Linux 8, then Install Podman. + * You must install and configure [Podman release 4.6.1 or later](https://docs.oracle.com/en/learn/intro_podman/index.html#introduction) or later on Oracle Linux 8.9 or later to run Oracle Globally Distributed Database on Podman. + * You need to install `podman-docker` utility using dnf command. + ```bash + # Enable the Oracle Linux 8 AppStream repository + dnf config-manager --enable ol8_appstream + + # Install Podman and Podman-docker + dnf install -y podman podman-docker + ``` + * If SELinux is enabled on podman host, then install the following package as well: + ```bash + dnf install -y selinux-policy-devel + ``` + +## QuickStart +Oracle recommends that you start with the Quickstart to become familiar with Oracle Globally Distributed Database in Linux Containers. See: [QuickStart documentation](./docs/QUICKSTART.md). + +After you become familiar with Oracle Globally Distributed Database in Linux Containers, you can explore more advanced setups, deployments, features, and so on, as explained in detail in [Oracle Globally Distributed Database in Containers Deployment Scenarios](#oracle-globally-distributed-database-in-containers-deployment-scenarios). + +**Note:** +* Ensure that you have enough space in `/var/lib/containers` while building the Oracle Globally Distributed Database images. Also, if required use `export TMPDIR=</path/to/tmpdir>` for Podman to refer to any other folder as the temporary podman cache location instead of the default `/tmp` location. + +## Building Oracle Globally Distributed Database Container Images + +To assist with building the images, you can use the [buildContainerImage.sh](containerfiles/buildContainerImage.sh) script. + +**IMPORTANT:** Oracle Global Service Manager (GDS) container is useful when you want to configure the Global Data Service Framework. A Global Data Services framework consists of at least one global service manager, a Global Data Services catalog, and the GDS configuration databases. + +### Building Oracle Global Service Manager Image + +**IMPORTANT:** To create an Oracle Global Service Manager image (GSM image), you must provide the installation binaries of `Oracle Global Service Manager Oracle Database 23ai (23.4) for Linux x86-64` and put them into the `containerfiles/<version>` folder. You only need to provide the binaries for the edition you are going to install. The binaries can be downloaded from the [Oracle Technology Network](http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html). You must ensure that you have internet connectivity for the DNF package manager. + +**Note:** Do not uncompress the binaries. + +The `buildContainerImage.sh` script is just a utility shell script that performs MD5 checks. This script provides an easy way for beginners to get started. Expert users can directly call `podman build` with their preferred set of parameters. Before you build the image, ensure that you have provided the installation binaries and put them into the right folder. Go into the **containerfiles** folder and run the **buildContainerImage.sh** script as `root` or with `sudo` privileges: + +```bash +./buildContainerImage.sh -v (Software Version) +./buildContainerImage.sh -v 23.4.0 +``` + +For detailed usage information for `buildContainerImage.sh`, run the following command: + +```bash +./buildContainerImage.sh -h +Usage: buildContainerImage.sh -v [version] -t [image_name:tag] [-e | -s] [-i] [-o] [container build option] +It builds a container image for a DNS server + +Parameters: + -v: version to build + -i: ignores the MD5 checksums + -t: user defined image name and tag (e.g., image_name:ta + -o: passes on container build option (e.g., --build-arg SLIMMIMG=true for slim) + +LICENSE UPL 1.0 + +Copyright (c) 2014,2024 Oracle and/or its affiliates. +``` + +### Building Oracle Database Image + +To build Oracle Globally Distributed Database on a container, download and build an Oracle 23.4.0 Database Image. See the Oracle Database Single Instance [README.MD](https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md), which is available on the Oracle GitHub repository. + +**Note**: Use the [README.MD](https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md) to create the image, and do not use the container instructions. For the container, use the steps given in this document under the [Oracle Globally Distributed Database in Containers Deployment Scenarios](#oracle-globally-distributed-database-in-containers-deployment-scenarios) section. + +### Building Extended Oracle Database Image with Oracle Globally Distributed Database Feature + +After creating the base image using `buildContainerImage.sh` in the previous step, use the `buildExtensions.sh` script that is under the `extensions` folder to build an extended image. This extended image will include the Oracle Globally Distributed Database Feature. For more information, refer to the [README.MD](https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/extensions/README.md) in the `extensions` folder for the Oracle Single Instance Database, which is available on the Oracle GitHub repository. + +For example: + +```bash +./buildExtensions.sh -a -x sharding -b oracle/database:23.4.0-ee -t oracle/database-ext-sharding:23.4.0-ee -o "--build-arg BASE_IMAGE_VERSION=23.4.0" + +Where: +"-x sharding" is to specify to have sharding feature in the extended image +"-b oracle/database:23.4.0-ee" is to specify the Base image created in previous step +"oracle/database-ext-sharding:23.4.0-ee" is to specify the name:tag for the extended image with Sharding Feature +-o "--build-arg BASE_IMAGE_VERSION=23.4.0" is to specify the BASE_IMAGE_VERSION to clone from db-sharding git repo +``` + +To see more usage instructions for the `buildExtensions.sh` script, run the following command: +```bash +./buildExtensions.sh -h + +Usage: buildExtensions.sh -a -x [extensions] -b [base image] -t [image name] -v [version] [-o] [container build option] +Builds one of more Container Image Extensions. + +Parameters: + -a: Build all extensions + -x: Space separated extensions to build. Defaults to all + Choose from : k8s patching prebuiltdb sharding + -b: Base image to use + -v: Base version to extend (example 21.3.0) + -t: name:tag for the extended image + -o: passes on Container build option + +LICENSE UPL 1.0 + +Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. +``` + +## Oracle Globally Distributed Database in Containers Deployment Scenarios +### Deploy Oracle Globally Distributed Database Containers +If you want to manually deploy the Oracle Globally Distributed Database using Docker or Podman containers, then use the sections that follow to see the step by step procedure. + +#### Deploy Oracle Globally Distributed Database Containers on Podman + +To deploy an Oracle Globally Distributed Database on Podman, see: [Deploy Oracle Globally Distributed Database Containers on Podman](./samples/container-files/podman-container-files/README.md). This document provides the commands that you need to deploy an Oracle Globally Distributed Database using Podman with System-Managed Sharding or with System-Managed Sharding with RAFT replication or with User Defined Sharding. + +**NOTE:** If you want to use Oracle Database 21c or Oracle Database 23ai release-based container images with Podman, then you must deploy on an Oracle Linux 8 host. + +#### Deploy Oracle Globally Distributed Database Containers on Docker + +To deploy an Oracle Globally Distributed Database on Docker, see: [Deploy Oracle Globally Distributed Database Containers on Docker](./samples/container-files/docker-container-files/README.md). This document provides the commands that you need to deploy an Oracle Globally Distributed Database using Docker with either System-Managed Sharding or with User Defined Sharding. + +**NOTE:** If you want to use the Oracle Database 19c or Oracle Database 21c release-based container images with Docker, then you must deploy on an Oracle Linux 7 host. + +#### Deploy Oracle Globally Distributed Database Containers on Podman using Oracle 23ai FREE Images + +To deploy an Oracle Globally Distributed Database on Podman using Oracle 23ai FREE Images, see: [Deploy Oracle Globally Distributed Database Containers on Podman using Oracle 23ai FREE Images](./samples/container-files/podman-container-files-free/README.md). This document provides the commands that you need to deploy an Oracle Globally Distributed Database with Oracle 23ai FREE Images using Podman with System-Managed Sharding or with System-Managed Sharding with RAFT replication or with User Defined Sharding. + +## Oracle Globally Distributed Database in Containers Deployment using docker-compose + +To deploy an Oracle Globally Distributed Database in Containers using docker-compose, refer to [Deploying Oracle Globally Distributed Database Containers using docker-compose](./samples/compose-files/docker-compose/README.md) + +## Oracle Globally Distributed Database in Containers Deployment using podman-compose + +To deploy an Oracle Globally Distributed Database in Containers using podman-compose, refer to [Deploying Oracle Globally Distributed Database Containers using podman-compose](./samples/compose-files/podman-compose/README.md) + +## Support + +Oracle Global Service Manager (GSM) and Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Database 23ai GSM and Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + + +## License + +To download and run Oracle Global Service Manager (GSM) and Oracle Globally Distributed Database, either inside or outside a Container, you must download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/19c_gsm_install.rsp b/container-based-sharding-deployment/containerfiles/19.3.0/19c_gsm_install.rsp new file mode 100644 index 0000000..8465c12 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/19c_gsm_install.rsp @@ -0,0 +1,35 @@ + +############################################################################### +## Copyright(c) Oracle Corporation 1998,2019. All rights reserved. ## +## ## +## Specify values for the variables listed below to customize ## +## your installation. ## +## ## +## Each variable is associated with a comment. The comment ## +## can help to populate the variables with the appropriate ## +## values. ## +## ## +############################################################################### + +#------------------------------------------------------------------------------- +# Do not change the following system generated value. +#------------------------------------------------------------------------------- +oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v19.0.0 + +#------------------------------------------------------------------------------- +# Unix group to be set for the inventory directory. +#------------------------------------------------------------------------------- +UNIX_GROUP_NAME=oinstall +#------------------------------------------------------------------------------- +# Inventory location. +#------------------------------------------------------------------------------- +INVENTORY_LOCATION=###INVENTORY### +#------------------------------------------------------------------------------- +# Complete path of the Oracle Home +#------------------------------------------------------------------------------- +ORACLE_HOME=###ORACLE_HOME### + +#------------------------------------------------------------------------------- +# Complete path of the Oracle Base. +#------------------------------------------------------------------------------- +ORACLE_BASE=###ORACLE_BASE### diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/19c_gsm_install_sample.rsp b/container-based-sharding-deployment/containerfiles/19.3.0/19c_gsm_install_sample.rsp new file mode 100644 index 0000000..96cd388 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/19c_gsm_install_sample.rsp @@ -0,0 +1,35 @@ + +############################################################################### +## Copyright(c) Oracle Corporation 1998,2019. All rights reserved. ## +## ## +## Specify values for the variables listed below to customize ## +## your installation. ## +## ## +## Each variable is associated with a comment. The comment ## +## can help to populate the variables with the appropriate ## +## values. ## +## ## +############################################################################### + +#------------------------------------------------------------------------------- +# Do not change the following system generated value. +#------------------------------------------------------------------------------- +oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v19.0.0 + +#------------------------------------------------------------------------------- +# Unix group to be set for the inventory directory. +#------------------------------------------------------------------------------- +UNIX_GROUP_NAME= +#------------------------------------------------------------------------------- +# Inventory location. +#------------------------------------------------------------------------------- +INVENTORY_LOCATION= +#------------------------------------------------------------------------------- +# Complete path of the Oracle Home +#------------------------------------------------------------------------------- +ORACLE_HOME= + +#------------------------------------------------------------------------------- +# Complete path of the Oracle Base. +#------------------------------------------------------------------------------- +ORACLE_BASE= diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/Checksum b/container-based-sharding-deployment/containerfiles/19.3.0/Checksum new file mode 100644 index 0000000..01c9baf --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/Checksum @@ -0,0 +1 @@ +0edb0a62772436083ec102f351b4c772 LINUX.X64_193000_gsm.zip diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/Containerfile b/container-based-sharding-deployment/containerfiles/19.3.0/Containerfile new file mode 100644 index 0000000..33bbf41 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/Containerfile @@ -0,0 +1,91 @@ +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> +# +# This is the Dockerfile for Oracle Database 19c +# +# REQUIRED FILES TO BUILD THIS IMAGE +# ---------------------------------- +# (1) LINUX.X64_193000_gsm.zip +# Download Oracle Database 19c GSM Software +# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html +# +# HOW TO BUILD THIS IMAGE +# ----------------------- +# Put all downloaded files in the same directory as this Dockerfile +# Run: +# $ docker build -t oracle/gsm:19.3.0 . +# +# Pull base image +# --------------- +FROM oraclelinux:7-slim as base + +# Maintainer +# ---------- +MAINTAINER Paramdeep Saini <paramdeep.saini@oracle.com> + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +ENV GSM_BASE="/u01/app/oracle" \ + GSM_HOME="/u01/app/oracle/product/19c/gsmhome_1" \ + INVENTORY="/u01/app/oracle/oraInventory" \ + INSTALL_DIR="/opt/oracle/scripts" \ + INSTALL_FILE_1="LINUX.X64_193000_gsm.zip" \ + INSTALL_RSP="19c_gsm_install.rsp" \ + RUN_FILE="runOracle.sh" \ + SETUP_LINUX_FILE="setupLinuxEnv.sh" \ + CHECK_SPACE_FILE="checkSpace.sh" \ + USER_SCRIPTS_FILE="runUserScripts.sh" \ + INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ + GSM_SETUP_FILE="setupOshardEnv.sh" \ + GSM_ENV_SETUP_FILE="setupGSM.sh" \ + GSM_SCRIPTS="scripts" \ + MAINPY="main.py" \ + CHECKLIVENESS="checkLiveness.sh" +# Use second ENV so that variable get substituted +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/sharding \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH \ + GSM_PATH=$GSM_HOME/bin:/usr/sbin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib + + +# Copy files needed during both installation and runtime +# ------------ +COPY $INSTALL_FILE_1 $SETUP_LINUX_FILE $CHECK_SPACE_FILE $INSTALL_RSP $GSM_ENV_SETUP_FILE $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ +COPY $RUN_FILE $GSM_SETUP_FILE $CHECKLIVENESS $USER_SCRIPTS_FILE $SCRIPT_DIR/ +COPY $GSM_SCRIPTS $SCRIPT_DIR/scripts/ + +RUN chmod 755 $INSTALL_DIR/install/*.sh && \ + sync && \ + $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ + $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ + $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ + sed -e '/hard *memlock/s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-19c.conf && \ + su oracle -c "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ + $INVENTORY/orainstRoot.sh && \ + $GSM_HOME/root.sh && \ + rm -rf $INSTALL_DIR/install && \ + rm -f /etc/sysctl.d/99-oracle-database-preinstall-19c-sysctl.conf && \ + rm -f /etc/sysctl.d/99-sysctl.conf && \ + rm -f /etc/rc.d/init.d/oracle-database-preinstall-19c-firstboot && \ + rm -f /etc/security/limits.d/oracle-database-preinstall-19c.conf && \ + rm -f $INSTALL_DIR/install/* && \ + chown -R oracle:oinstall $SCRIPT_DIR && \ + chmod 755 $SCRIPT_DIR/*.sh && \ + chmod 755 $SCRIPT_DIR/scripts/*.py && \ + sync + +USER oracle +WORKDIR /home/oracle +EXPOSE 1521 + +VOLUME ["$GSM_BASE/oradata"] + +HEALTHCHECK --interval=2m --start-period=25m \ + CMD "$SCRIPT_DIR/scripts/$CHECKLIVENESS" >/dev/null || exit 1 + +# Define default command to start Oracle Database. +CMD exec $SCRIPT_DIR/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/Dockerfile_19c b/container-based-sharding-deployment/containerfiles/19.3.0/Dockerfile_19c new file mode 100644 index 0000000..49374fb --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/Dockerfile_19c @@ -0,0 +1,89 @@ +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> +# +# This is the Dockerfile for Oracle Database 19c +# +# REQUIRED FILES TO BUILD THIS IMAGE +# ---------------------------------- +# (1) LINUX.X64_193000_gsm.zip +# Download Oracle Database 19c GSM Software +# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html +# +# HOW TO BUILD THIS IMAGE +# ----------------------- +# Put all downloaded files in the same directory as this Dockerfile +# Run: +# $ docker build -t oracle/gsm:19.3.0 . +# +# Pull base image +# --------------- +FROM oraclelinux:7-slim as base + +# Maintainer +# ---------- +MAINTAINER Paramdeep Saini <paramdeep.saini@oracle.com> + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +ENV GSM_BASE="/u01/app/oracle" \ + GSM_HOME="/u01/app/oracle/product/19c/gsmhome_1" \ + INVENTORY="/u01/app/oracle/oraInventory" \ + INSTALL_DIR="/opt/oracle/scripts" \ + INSTALL_FILE_1="LINUX.X64_193000_gsm.zip" \ + INSTALL_RSP="19c_gsm_install.rsp" \ + RUN_FILE="runOracle.sh" \ + SETUP_LINUX_FILE="setupLinuxEnv.sh" \ + CHECK_SPACE_FILE="checkSpace.sh" \ + USER_SCRIPTS_FILE="runUserScripts.sh" \ + INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ + GSM_SETUP_FILE="setupOshardEnv.sh" \ + GSM_ENV_SETUP_FILE="setupGSM.sh" \ + GSM_SCRIPTS="scripts" + MAINPY="main.py" \ +# Use second ENV so that variable get substituted +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/startup \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH \ + GSM_PATH=$GSM_HOME/bin:/usr/sbin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib + + +# Copy files needed during both installation and runtime +# ------------ +COPY $INSTALL_FILE_1 $SETUP_LINUX_FILE $CHECK_SPACE_FILE $INSTALL_RSP $GSM_ENV_SETUP_FILE $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ +COPY $RUN_FILE $GSM_SETUP_FILE $USER_SCRIPTS_FILE $INSTALL_DIR/sharding +COPY $GSM_SCRIPTS $INSTALL_DIR/sharding/scripts + +RUN chmod 755 $INSTALL_DIR/install/*.sh && \ + sync && \ + $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ + $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ + $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ + sed -e '/hard *memlock/s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-19c.conf && \ + su oracle -c "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ + $INVENTORY/orainstRoot.sh && \ + $GSM_HOME/root.sh && \ + rm -rf $INSTALL_DIR/install && \ + rm -f /etc/sysctl.d/99-oracle-database-preinstall-19c-sysctl.conf && \ + rm -f /etc/sysctl.d/99-sysctl.conf && \ + rm -f /etc/rc.d/init.d/oracle-database-preinstall-19c-firstboot && \ + rm -f /etc/security/limits.d/oracle-database-preinstall-19c.conf && \ + rm -f $INSTALL_DIR/install/* && \ + chown -R oracle:oinstall $SCRIPT_DIR && \ + chmod 755 $SCRIPT_DIR/*.sh && \ + sync + +USER oracle +WORKDIR /home/oracle +EXPOSE 1521 + +VOLUME ["$GSM_BASE/oradata"] + +HEALTHCHECK --interval=1m --start-period=10m \ + CMD "$INSTALL_DIR/sharding/scripts/MAINPY" >/dev/null || exit 1 + +# Define default command to start Oracle Database. +CMD exec $INSTALL_DIR/startup/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/checkLiveness.sh b/container-based-sharding-deployment/containerfiles/19.3.0/checkLiveness.sh new file mode 100644 index 0000000..5092ca0 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/checkLiveness.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +export PYTHON="/bin/python" + +$PYTHON $SCRIPT_DIR/scripts/$MAINPY --checkliveness='true' +retcode=$? + + if [ ${retcode} -eq 0 ]; then + exit 0 + else + exit 1 + fi diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/checkSpace.sh b/container-based-sharding-deployment/containerfiles/19.3.0/checkSpace.sh new file mode 100644 index 0000000..1445fb7 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/checkSpace.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> + +REQUIRED_SPACE_GB=2 +AVAILABLE_SPACE_GB=`df -PB 1G / | tail -n 1 | awk '{ print $4 }'` + +if [ $AVAILABLE_SPACE_GB -lt $REQUIRED_SPACE_GB ]; then + script_name=`basename "$0"` + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "$script_name: ERROR - There is not enough space available in the docker container." + echo "$script_name: The container needs at least $REQUIRED_SPACE_GB GB, but only $AVAILABLE_SPACE_GB GB are available." + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + exit 1; +fi; diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/installGSMBinaries.sh b/container-based-sharding-deployment/containerfiles/19.3.0/installGSMBinaries.sh new file mode 100644 index 0000000..5739a5a --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/installGSMBinaries.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> + +export ORACLE_BASE=$GSM_BASE +export ORACLE_HOME=$GSM_HOME + +# Check whether ORACLE_BASE is set +if [ "$ORACLE_BASE" == "" ]; then + echo "ERROR: ORACLE_BASE has not been set!" + echo "You have to have the ORACLE_BASE environment variable set to a valid value!" + exit 1; +fi; + +# Check whether ORACLE_HOME is set +if [ "$ORACLE_HOME" == "" ]; then + echo "ERROR: ORACLE_HOME has not been set!" + echo "You have to have the ORACLE_HOME environment variable set to a valid value!" + exit 1; +fi; + + +# Replace place holders +# --------------------- + +sed -i -e "s|###INVENTORY###|$INVENTORY|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ +sed -i -e "s|###ORACLE_BASE###|$GSM_BASE|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ +sed -i -e "s|###ORACLE_HOME###|$GSM_HOME|g" $INSTALL_SCRIPTS/$INSTALL_RSP + +# Install Oracle binaries +cd $INSTALL_SCRIPTS && \ +unzip $INSTALL_FILE_1 && \ +rm $INSTALL_FILE_1 && \ +$INSTALL_SCRIPTS/gsm/runInstaller -silent -force -waitforcompletion -responsefile $INSTALL_SCRIPTS/$INSTALL_RSP -ignorePrereqFailure || true && \ +rm -rf gsm && \ +cd $HOME diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/runOracle.sh b/container-based-sharding-deployment/containerfiles/19.3.0/runOracle.sh new file mode 100644 index 0000000..346c117 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/runOracle.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +############################# +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# Author: paramdeep.saini@oracle.com +############################ + +#This is the main file which calls other file to setup the sharding. +if [ -z ${BASE_DIR} ]; then + BASE_DIR=$INSTALL_DIR/sharding/scripts +fi + +if [ -z ${MAIN_SCRIPT} ]; then + SCRIPT_NAME="main.py" +fi + +if [ -z ${EXECUTOR} ]; then + EXECUTOR="python" +fi + +cd $BASE_DIR +$EXECUTOR $SCRIPT_NAME + +# Tail on alert log and wait (otherwise container will exit) + +if [ -z ${DEV_MODE} ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/gsm/*/*/trace/alert*.log & +else + echo "The following output is now a tail of the /etc/passwd for dev mode" + tail -f /etc/passwd & +fi + +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/runOracle.sh_orig b/container-based-sharding-deployment/containerfiles/19.3.0/runOracle.sh_orig new file mode 100755 index 0000000..e1edb9a --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/runOracle.sh_orig @@ -0,0 +1,189 @@ +#!/bin/bash +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> + +export NOW=$(date +"%Y%m%d%H%M") +export LOGDIR="/tmp" +export LOGFILE="${LOGDIR}/runOracle_${NOW}.log" +export STD_OUT_FILE="/proc/1/fd/1" +export STD_ERR_FILE="/proc/1/fd/2" +export PDB_SQL_SCRIPT="/tmp/pdb.sql" +export TOP_PID=$$ +export GSM_HOST=$(hostname) +rm -f /tmp/sqllog.output +rm -f $PDB_SQL_SCRIPT +rm -f $LOGFILE + + +#################################### Print and Exit Functions Begin Here ####################### +error_exit() { +local NOW=$(date +"%m-%d-%Y %T %Z") + # Display error message and exit +# echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2 + echo "${NOW} : ${PROGNAME}: ${1:-"Unknown Error"}" | tee -a $LOGFILE > $STD_OUT_FILE + kill -s TERM $TOP_PID +} + +print_message () +{ + local NOW=$(date +"%m-%d-%Y %T %Z") + # Display message and return + echo "${NOW} : ${PROGNAME} : ${1:-"Unknown Message"}" | tee -a $LOGFILE > $STD_OUT_FILE + return $? +} +#################################### Print and Exit Functions End Here ####################### + + +########### Move DB files ############ +function moveFiles { + + if [ ! -d $ORACLE_BASE/gsmdata/gsmconfig ]; then + mkdir -p $ORACLE_BASE/gsmdata/gsmconfig + fi; + + mv $ORACLE_HOME/network/admin/tnsnames.ora $ORACLE_BASE/gsmdata/gsmconfig/ + mv $ORACLE_HOME/network/admin/gsm.ora $ORACLE_BASE/gsmdata/gsmconfig/ + + symLinkFiles; +} + +########### Symbolic link DB files ############ +function symLinkFiles { + + if [ ! -L $ORACLE_HOME/network/admin/tnsnames.ora ]; then + ln -s $ORACLE_BASE/gsmdata/gsmconfig/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi; + + if [ ! -L $ORACLE_HOME/network/admin/gsm.ora ]; then + ln -s $ORACLE_BASE/gsmdata/gsmconfig/gsm.ora $ORACLE_HOME/network/admin/gsm.ora + fi; + + +} + +########### SIGINT handler ############ +function _int() { + print_message "Stopping container." + print_message "SIGINT received, shutting down database!" + $ORACLE_HOME/bin/gdsctl <<EOF + stop gsm + exit; +EOF +} + +########### SIGTERM handler ############ +function _term() { + print_message "Stopping container." + print_message "SIGTERM received, shutting down database!" + $ORACLE_HOME/bin/gdsctl <<EOF + stop gsm + exit; +EOF +} + +########### SIGKILL handler ############ +function _kill() { + print_message "SIGKILL received, shutting down database!" + $ORACLE_HOME/bin/gdsctl <<EOF + stop gsm + exit; +EOF +} + +stopGSM() +{ + echo "Starting GSM" + $ORACLE_HOME/bin/gdsctl <<EOF + stop gsm + exit; +EOF +} + +startGSM() +{ + echo "Starting GSM" + $ORACLE_HOME/bin/gdsctl <<EOF + start gsm + exit; +EOF +} + +################################### +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +# Github issue #711 +if hostname | grep -q "_"; then + print_message "Error: The hostname must not container any '_'". + print_message "Your current hostname is '$(hostname)'" +fi; + +# Set SIGINT handler +trap _int SIGINT + +# Set SIGTERM handler +trap _term SIGTERM + +# Set SIGKILL handler +trap _kill SIGKILL + +# Check whether GSM config already exists +if [ -d $ORACLE_BASE/gsmdata/gsmconfig ]; then + symLinkFiles; + # Start gsm + startGSM +else + + if [ -z ${CUSTOM_SETUP_SCRIPT} ]; then + print_message "Calling GSM SETUP script $GSM_SETUP_FILE shipped with dockerimage as no previous configuration found" + $SCRIPT_DIR/$GSM_SETUP_FILE + else + print_message "Calling CUSTOM Script /opt/oracle/scripts/setup/$CUSTOM_SETUP_SCRIPT script to setup the GSM as no previous configuration found" + /opt/oracle/scripts/setup/$CUSTOM_SETUP_SCRIPT + fi + + if [ $? -eq 0 ]; then + print_message "#########################" + print_message "GSM IS READY TO USE!" + print_message "#########################" + # Move GSM operational files to gsmdata + stopGSM + moveFiles; + startGSM + else + print_message "#####################################" + print_message "########### E R R O R ###############" + print_message "GSM SETUP WAS NOT SUCCESSFUL!" + print_message "Please check output for further info!" + print_message "########### E R R O R ###############" + print_message "#####################################" + fi; +fi + +# Check whether GSM is up and running +#$ORACLE_BASE/$CHECK_GSM_FILE +#if [ $? -eq 0 ]; then +# echo "#########################" +# echo "GSM IS READY TO USE!" +# echo "#########################" + +# # Execute custom provided startup scripts +# $ORACLE_BASE/$USER_SCRIPTS_FILE $ORACLE_BASE/scripts/startup + +#else +# echo "#####################################" +# echo "########### E R R O R ###############" +# echo "GSM SETUP WAS NOT SUCCESSFUL!" +# echo "Please check output for further info!" +# echo "########### E R R O R ###############" +# echo "#####################################" +#fi; + +# Tail on alert log and wait (otherwise container will exit) +echo "The following output is now a tail of the alert.log:" +tail -f $ORACLE_BASE/diag/gsm/*/*/trace/alert*.log & +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/runUserScripts.sh b/container-based-sharding-deployment/containerfiles/19.3.0/runUserScripts.sh new file mode 100644 index 0000000..d9c0cca --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/runUserScripts.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> + +SCRIPTS_ROOT="$1"; + +# Check whether parameter has been passed on +if [ -z "$SCRIPTS_ROOT" ]; then + echo "$0: No SCRIPTS_ROOT passed on, no scripts will be run"; + exit 1; +fi; + +# Execute custom provided files (only if directory exists and has files in it) +if [ -d "$SCRIPTS_ROOT" ] && [ -n "$(ls -A $SCRIPTS_ROOT)" ]; then + + echo ""; + echo "Executing user defined scripts" + + for f in $SCRIPTS_ROOT/*; do + case "$f" in + *.sh) echo "$0: running $f"; . "$f" ;; + *.sql) echo "$0: running $f"; echo "exit" | $ORACLE_HOME/bin/sqlplus -s "/ as sysdba" @"$f"; echo ;; + *) echo "$0: ignoring $f" ;; + esac + echo ""; + done + + echo "DONE: Executing user defined scripts" + echo ""; + +fi; diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/cmdExec b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/cmdExec new file mode 100755 index 0000000..0e5ac30 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/cmdExec @@ -0,0 +1,23 @@ +#!/bin/bash + +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +TIMESTAMP=`date "+%Y-%m-%d"` +LOGFILE="/tmp/sharding_cmd_${TIMESTAMP}.log" + +echo $(date -u) " : " $@ >> $LOGFILE + +cmd=$@ + +$cmd + +if [ $? -eq 0 ]; then + exit 0 +else + exit 127 +fi diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/demoapp.sql b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/demoapp.sql new file mode 100755 index 0000000..3e96bfc --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/demoapp.sql @@ -0,0 +1,88 @@ + connect sys/'&1'@oshard-catalog-0:1521/CATCDB as sysdba + alter session set container=CAT1PDB; + alter session enable shard ddl; + create user app_schema identified by app_schema; + grant connect, resource, alter session to app_schema; + grant execute on dbms_crypto to app_schema; + grant create table, create procedure, create tablespace, create materialized view to app_schema; + grant unlimited tablespace to app_schema; + grant select_catalog_role to app_schema; + grant all privileges to app_schema; + grant gsmadmin_role to app_schema; + grant dba to app_schema; + conn app_schema/'&1'@oshard-catalog-0:1521/CAT1PDB + alter session enable shard ddl; + REM + REM Create a Sharded table for + REM + CREATE SHARDED TABLE Customers + ( + CustId VARCHAR2(60) NOT NULL, + FirstName VARCHAR2(60), + LastName VARCHAR2(60), + Class VARCHAR2(10), + Geo VARCHAR2(8), + CustProfile VARCHAR2(4000), + Passwd RAW(60), + CONSTRAINT pk_customers PRIMARY KEY (CustId), + CONSTRAINT json_customers CHECK (CustProfile IS JSON) + ) TABLESPACE SET TSP_SET_1 + PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO; + REM + REM Create a Sharded table for Orders + REM + CREATE SHARDED TABLE Orders + ( + OrderId INTEGER NOT NULL, + CustId VARCHAR2(60) NOT NULL, + OrderDate TIMESTAMP NOT NULL, + SumTotal NUMBER(19,4), + Status CHAR(4), + constraint pk_orders primary key (CustId, OrderId), + constraint fk_orders_parent foreign key (CustId) + references Customers on delete cascade + ) partition by reference (fk_orders_parent); + REM + REM Create the sequence used for the OrderId column + REM + CREATE SEQUENCE Orders_Seq; + REM + REM Create a Sharded table for LineItems + REM + CREATE SHARDED TABLE LineItems + ( + OrderId INTEGER NOT NULL, + CustId VARCHAR2(60) NOT NULL, + ProductId INTEGER NOT NULL, + Price NUMBER(19,4), + Qty NUMBER, + constraint pk_items primary key (CustId, OrderId, ProductId), + constraint fk_items_parent foreign key (CustId, OrderId) + references Orders on delete cascade + ) partition by reference (fk_items_parent); + REM + REM + CREATE DUPLICATED TABLE Products + ( + ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + Name VARCHAR2(128), + DescrUri VARCHAR2(128), + LastPrice NUMBER(19,4) + ) TABLESPACE products_tsp; + CREATE OR REPLACE FUNCTION PasswCreate(PASSW IN RAW) + RETURN RAW + IS + Salt RAW(8); + BEGIN + Salt := DBMS_CRYPTO.RANDOMBYTES(8); + RETURN UTL_RAW.CONCAT(Salt, DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(Salt,PASSW), DBMS_CRYPTO.HASH_SH256)); + END; + / + CREATE OR REPLACE FUNCTION PasswCheck(PASSW IN RAW, PHASH IN RAW) + RETURN INTEGER IS + BEGIN + RETURN UTL_RAW.COMPARE(DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(UTL_RAW.SUBSTR(PHASH, 1, 8), PASSW), DBMS_CRYPTO.HASH_SH256),UTL_RAW.SUBSTR(PHASH, 9)); + END; + / + REM + REM diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/main.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/main.py new file mode 100755 index 0000000..b7f0f17 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/main.py @@ -0,0 +1,171 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" +This is the main file which calls other file to setup the sharding. +""" + +from oralogger import * +from orafactory import * +from oraenv import * +from oracommon import * + + +def main(): + + # Checking Comand line Args + try: + opts, args = getopt.getopt(sys.argv[1:], '', ['addshard=','deleteshard=','validateshard=','checkliveness=','resetlistener=','restartdb=','createdir=','optype=','addshardgroup=','deployshard=','movechunks=','checkonlineshard=','cancelchunks=','checkchunks=','checkgsmshard=','checkreadyness=','validatenochunks=','invitednode=','resetpassword=','exporttdekey=','importtdekey=','help']) + except getopt.GetoptError: + pass + + # Initializing oraenv instance + oenv=OraEnv() + file_name = os.path.basename(__file__) + funcname = sys._getframe(1).f_code.co_name + + log_file_name = oenv.logfile_name("NONE") + + # Initialiing logger instance + oralogger = OraLogger(log_file_name) + console_handler = CHandler() + file_handler = FHandler() + stdout_handler = StdHandler() + # Setting next log handlers + stdout_handler.nextHandler = file_handler + file_handler.nextHandler = console_handler + console_handler.nextHandler = PassHandler() + + ocommon = OraCommon(oralogger,stdout_handler,oenv) + + for opt, arg in opts: + if opt in ('--help'): + oralogger.msg_ = '''{:^17}-{:^17} : You can pass parameter --addshard, --deleteshard, --validateshard, --checkliveness, --resetlistener, --restartdb, --createdir, --optype, --addshardgroup, --deployshard, '--checkonlineshard', '--cancelchunks', '--movechunks', '--checkchunks', '--checkgsmshard','--validatenochunks', '--checkreadyness','--invitednode', '--resetpassword','--exporttdekey','--importtdekey',or --help''' + stdout_handler.handle(oralogger) + elif opt in ('--addshard'): + file_name = oenv.logfile_name("ADD_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("ADD_SHARD",arg) + elif opt in ('--validateshard'): + file_name = oenv.logfile_name("VALIDATE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("VALIDATE_SHARD",arg) + elif opt in ('--deleteshard'): + file_name = oenv.logfile_name("REMOVE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("REMOVE_SHARD",arg) + elif opt in ('--checkliveness'): + oralogger.stdout_ = None + file_name = oenv.logfile_name("CHECK_LIVENESS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_LIVENESS",arg) + elif opt in ('--checkreadyness'): + oralogger.stdout_ = None + file_name = oenv.logfile_name("CHECK_READYNESS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_READYNESS",arg) + elif opt in ('--resetlistener'): + file_name = oenv.logfile_name("RESET_LISTENER") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESET_LISTENER",arg) + elif opt in ('--restartdb'): + file_name = oenv.logfile_name("RESTART_DB") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESTART_DB",arg) + elif opt in ('--createdir'): + file_name = oenv.logfile_name("CREATE_DIR") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CREATE_DIR",arg) + elif opt in ('--addshardgroup'): + file_name = oenv.logfile_name("ADD_SGROUP_PARAMS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("ADD_SGROUP_PARAMS",arg) + elif opt in ('--deployshard'): + file_name = oenv.logfile_name("DEPLOY_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("DEPLOY_SHARD",arg) + elif opt in ('--cancelchunks'): + file_name = oenv.logfile_name("CANCEL_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CANCEL_CHUNKS",arg) + elif opt in ('--movechunks'): + file_name = oenv.logfile_name("MOVE_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("MOVE_CHUNKS",arg) + elif opt in ('--checkchunks'): + file_name = oenv.logfile_name("CHECK_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_CHUNKS",arg) + elif opt in ('--validatenochunks'): + file_name = oenv.logfile_name("VALIDATE_NOCHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("VALIDATE_NOCHUNKS",arg) + elif opt in ('--checkonlineshard'): + file_name = oenv.logfile_name("CHECK_ONLINE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_ONLINE_SHARD",arg) + elif opt in ('--checkgsmshard'): + file_name = oenv.logfile_name("CHECK_GSM_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_GSM_SHARD",arg) + elif opt in ('--invitednode'): + file_name = oenv.logfile_name("INVITED_NODE_OP") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("INVITED_NODE_OP",arg) + elif opt in ('--resetpassword'): + file_name = oenv.logfile_name("RESET_PASSWD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESET_PASSWORD",arg) + elif opt in ('--exporttdekey'): + file_name = oenv.logfile_name("EXPORT_TDE_KEY") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("EXPORT_TDE_KEY",arg) + elif opt in ('--importtdekey'): + file_name = oenv.logfile_name("IMPORT_TDE_KEY") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("IMPORT_TDE_KEY",arg) + elif opt in ('--optype'): + oenv.add_custom_variable("OP_TYPE",arg) + else: + pass + + # Initializing orafactory instances + oralogger.msg_ = '''{:^17}-{:^17} : Calling OraFactory to start the setup'''.format(file_name,funcname) + stdout_handler.handle(oralogger) + orafactory = OraFactory(oralogger,stdout_handler,oenv,ocommon) + + # Get the ora objects + ofactory=orafactory.get_ora_objs() + + # Traverse through returned factory objects and execute the setup function + for obj in ofactory: + obj.setup() + +# Using the special variable +if __name__=="__main__": + main() diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oracommon.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oracommon.py new file mode 100755 index 0000000..634a9f1 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oracommon.py @@ -0,0 +1,886 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +from oralogger import * +from oraenv import * +import subprocess +import sys +import time +import datetime +import os +import getopt +import shlex +import json +import logging +import socket +import re +import os.path +import socket +import string +import random + +class OraCommon: + def __init__(self,oralogger,orahandler,oraenv): + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + + def run_sqlplus(self,cmd,sql_cmd,dbenv): + """ + This function execute the ran sqlplus or rman script and return the output + """ + try: + message="Received Command : {0}\n{1}".format(self.mask_str(cmd),self.mask_str(sql_cmd)) + self.log_info_message(message,self.file_name) + sql_cmd=self.unmask_str(sql_cmd) + cmd=self.unmask_str(cmd) +# message="Received Command : {0}\n{1}".format(cmd,sql_cmd) +# self.log_info_message(message,self.file_name) + p = subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,env=dbenv,shell=True,universal_newlines=True) + p.stdin.write(sql_cmd) + # (stdout,stderr), retcode = p.communicate(sqlplus_script.encode('utf-8')), p.returncode + (stdout,stderr),retcode = p.communicate(),p.returncode + # stdout_lines = stdout.decode('utf-8').split("\n") + except: + error_msg=sys.exc_info() + self.log_error_message(error_msg,self.file_name) + self.prog_exit(self) + + return stdout.replace("\n\n", "\n"),stderr,retcode + + def execute_cmd(self,cmd,env,dir): + """ + Execute the OS command on host + """ + try: + message="Received Command : {0}".format(self.mask_str(cmd)) + self.log_info_message(message,self.file_name) + cmd=self.unmask_str(cmd) + out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,universal_newlines=True) + (output,error),retcode = out.communicate(),out.returncode + except: + error_msg=sys.exc_info() + self.log_error_message(error_msg,self.file_name) + self.prog_exit(self) + + return output,error,retcode + + def mask_str(self,mstr): + """ + Function to mask the string. + """ + newstr=None + if self.oenv.encrypt_str__: + newstr=mstr.replace('HIDDEN_STRING','********') + # self.log_info_message(newstr,self.file_name) + if newstr: + # message = "Masked the string as encryption flag is set in the singleton class" + # self.log_info_message(message,self.file_name) + return newstr + else: + return mstr + + + def unmask_str(self,mstr): + """ + Function to unmask the string. + """ + newstr=None + if self.oenv.encrypt_str__: + newstr=mstr.replace('HIDDEN_STRING',self.oenv.original_str__.rstrip()) + # self.log_info_message(newstr,self.file_name) + if newstr: + # message = "Unmasked the encrypted string and returning original string from singleton class" + # self.log_info_message(message,self.file_name) + return newstr + else: + return mstr + + def set_mask_str(self,mstr): + """ + Function to unmask the string. + """ + if mstr: + # message = "Setting encrypted String flag to True and original string in singleton class" + # self.log_info_message(message,self.file_name) + self.oenv.encrypt_str__ = True + self.oenv.original_str__ = mstr + else: + message = "Masked String is empty so no change required in encrypted String Flag and original string in singleton class" + self.log_info_message(message,self.file_name) + + def unset_mask_str(self): + """ + Function to unmask the string. + """ + # message = "Un-setting encrypted String flag and original string to None in Singleton class" + # self.log_info_message(message,self.file_name) + self.oenv.encrypt_str__ = None + self.oenv.original_str__ = None + + def prog_exit(self,message): + """ + This function exit the program because of some error + """ + sys.exit(127) + + def log_info_message(self,lmessage,fname): + """ + Print the INFO message in the logger + """ + funcname = sys._getframe(1).f_code.co_name + message = '''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_ = message + self.ologger.logtype_ = "INFO" + self.ohandler.handle(self.ologger) + + def log_error_message(self,lmessage,fname): + """ + Print the Error message in the logger + """ + funcname=sys._getframe(1).f_code.co_name + message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_=message + self.ologger.logtype_="ERROR" + self.ohandler.handle(self.ologger) + + def log_warn_message(self,lmessage,fname): + """ + Print the Error message in the logger + """ + funcname=sys._getframe(1).f_code.co_name + message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_=message + self.ologger.logtype_="WARN" + self.ohandler.handle(self.ologger) + + def check_sql_err(self,output,err,retcode,status): + """ + Check if there are any error in sql command output + """ + match=None + msg2='''Sql command failed.Flag is set not to ignore this error.Please Check the logs,Exiting the Program!''' + msg3='''Sql command failed.Flag is set to ignore this error!''' + self.log_info_message("output : " + str(output or "no Output"),self.file_name) + # self.log_info_message("Error : " + str(err or "no Error"),self.file_name) + # self.log_info_message("Sqlplus return code : " + str(retcode),self.file_name) + # self.log_info_message("Command Check Status Set to :" + str(status),self.file_name) + + if status: + if (retcode!=0): + self.log_info_message("Error : " + str(err or "no Error"),self.file_name) + self.log_error_message("Sql Login Failed.Please Check the logs,Exiting the Program!",self.file_name) + self.prog_exit(self) + + match=re.search("(?i)(?m)error",output) + if status: + if (match): + self.log_error_message(msg2,self.file_name) + self.prog_exit("error") + else: + self.log_info_message("Sql command completed successfully",self.file_name) + else: + if (match): + self.log_warn_message("Sql command failed. Flag is set to ignore the error.",self.file_name) + else: + self.log_info_message("Sql command completed sucessfully.",self.file_name) + + def check_os_err(self,output,err,retcode,status): + """ + Check if there are any error in OS command execution + """ + msg1='''OS command returned code : {0} and returned output : {1}'''.format(str(retcode),str(output or "no Output")) + msg2='''OS command returned code : {0}, returned error : {1} and returned output : {2}'''.format(str(retcode),str(err or "no returned error"),str(output or "no retruned output")) + msg3='''OS command failed. Flag is set to ignore this error!''' + + if status: + if (retcode != 0): + self.log_error_message(msg2,self.file_name) + self.prog_exit(self) + else: + self.log_info_message(msg1,self.file_name) + else: + if (retcode != 0): + self.log_warn_message(msg2,self.file_name) + self.log_warn_message(msg3,self.file_name) + else: + self.log_info_message(msg1,self.file_name) + + def check_key(self,key,env_dict): + """ + Check the key if it exist in dictionary. + Attributes: + key (string): String to check if key exist in dictionary + env_dict (dict): Contains the env variable related to seup + """ + if key in env_dict: + return True + else: + return False + + def empty_key(self,key): + """ + key is empty and print failure message. + Attributes: + key (string): String is empty + """ + msg='''Variable {0} is not defilned. Exiting!'''.format(key) + self.log_error_message(msg,self.file_name) + self.prog_exit(self) + + def add_key(self,key,value,env_dict): + """ + Add the key in the dictionary. + Attributes: + key (string): key String to add in the dictionary + value (String): value String to add in dictionary + + Return: + dict + """ + if self.check_key(key,env_dict): + msg='''Variable {0} already exist in the env variables'''.format(key) + self.log_info_message(msg,self.file_name) + else: + if value: + env_dict[key] = value + self.oenv.update_env_vars(env_dict) + else: + msg='''Variable {0} value is not defilned to add in the env variables. Exiting!'''.format(value) + self.log_error_message(msg,self.file_name) + self.prog_exit(self) + + return env_dict + + def update_key(self,key,value,env_dict): + """ + update the key in the dictionary. + Attributes: + key (string): key String to update in the dictionary + value (String): value String to update in dictionary + + Return: + dict + """ + if self.check_key(key,env_dict): + if value: + env_dict[key] = value + self.oenv.update_env_vars(env_dict) + else: + msg='''Variable {0} value is not defilned to update in the env variables!'''.format(key) + self.log_warn_message(msg,self.file_name) + else: + msg='''Variable {0} already exist in the env variables'''.format(key) + self.log_info_message(msg,self.file_name) + + return env_dict + + def check_file(self,file,local,remote,user): + """ + check locally or remotely + Attributes: + file (string): file to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside check_file()",self.file_name) + if local: + if os.path.isfile(file): + return True + else: + return False + + + def read_file(self,fname): + """ + Read the contents of a file and returns the contents to end user + Attributes: + fname (string): file to be read + + Return: + file data (string) + """ + f1 = open(fname, 'r') + fdata = f1.read() + f1.close + return fdata + + def write_file(self,fname,fdata): + """ + write the contents to a file + Attributes: + fname (string): file to be written + fdata (string): COnetents to be written + + Return: + file data (string) + """ + f1 = open(fname, 'w') + f1.write(fdata) + f1.close + + def create_dir(self,dir,local,remote,user): + """ + Create dir locally or remotely + Attributes: + dir (string): dir to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside create_dir()",self.file_name) + if local: + if not os.path.isdir(dir): + cmd='''mkdir -p {0}'''.format(dir) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + else: + msg='''Dir {0} already exist'''.format(dir) + self.log_info_message(msg,self.file_name) + + if remote: + pass + + def create_file(self,file,local,remote,user): + """ + Create dir locally or remotely + Attributes: + file (string): file to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside create_file()",self.file_name) + if local: + if not os.path.isfile(file): + cmd='''touch {0}'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + if remote: + pass + + def shutdown_db(self,env_dict): + """ + Shutdown the database + """ + file="/home/oracle/shutDown.sh" + if not os.path.isfile(file): + self.log_info_message("Inside shutdown_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + shutdown immediate; + ''' + self.log_info_message("Running the sqlplus command to shutdown the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + else: + cmd='''sh {0} immediate'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + def mount_db(self,env_dict): + """ + Mount the database + """ + self.log_info_message("Inside mount_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup mount; + ''' + self.log_info_message("Running the sqlplus command to mount the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def start_db(self,env_dict): + """ + startup the database + """ + file="/home/oracle/startUp.sh" + if not os.path.isfile(file): + self.log_info_message("Inside start_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup; + ''' + self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + else: + cmd='''sh {0}'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + def nomount_db(self,env_dict): + """ + No mount the database + """ + self.log_info_message("Inside start_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup nomount; + ''' + self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def stop_gsm(self,env_dict): + """ + Stop the GSM + """ + self.log_info_message("Inside stop_gsm()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + gsmcmd=''' + stop gsm; + ''' + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + + def set_events(self,source): + """ + Seting events at DB level + """ + scope='' + accepted_scope = ['spfile', 'memory', 'both'] + + if self.check_key("DB_EVENTS",self.ora_env_dict): + events=str(self.ora_env_dict["DB_EVENTS"]).split(";") + + for event in events: + msg='''Setting up event {0}'''.format(event) + self.log_info_message(msg,self.file_name) + scope='' + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + source=event.split(":") + if len(source) > 1: + if source[1].split("=")[0] == "scope": + scope=source[1].split("=")[1] + + if scope not in accepted_scope: + sqlcmd=""" + alter system set events='{0}';""".format(source[0]) + else: + sqlcmd=""" + alter system set event='{0}' scope={1};""".format(source[0],scope) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def start_gsm(self,env_dict): + """ + Start the GSM + """ + self.log_info_message("Inside start_gsm()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + gsmcmd=''' + start gsm; + ''' + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + + def exec_gsm_cmd(self,gsmcmd,flag,env_dict): + """ + Get the GSM command output + """ + self.log_info_message("Inside exec_gsm_cmd()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + if gsmcmd: + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,flag) + else: + self.log_info_message("GSM Command was set to empty. Executing nothing and setting output to None",self.file_name) + output=None + + return output,error,retcode + + + def check_substr_match(self,source_str,sub_str): + """ + CHeck if substring exist + """ + self.log_info_message("Inside check_substr_match()",self.file_name) + if (source_str.find(sub_str) != -1): + return True + else: + return False + + def find_str_in_string(self,source_str,delimeter,search_str): + """AI is creating summary for find_str_in_string + + Args: + source_str ([string]): [string where you need to search] + delimeter ([character]): [string delimeter] + search_str ([string]): [string to be searched] + """ + if delimeter == 'comma': + new_str=source_str.split(',') + for str in new_str: + if str.lower() == search_str.lower(): + return True + return False + + return False + + def check_status_value(self,match): + """ + return completed or notcompleted + """ + self.log_info_message("Inside check_status_value()",self.file_name) + if match: + return 'completed' + else: + return 'notcompleted' + + def remove_file(self,fname): + """ + Remove if file exist + """ + self.log_info_message("Inside remove_file()",self.file_name) + if os.path.exists(fname): + os.remove(fname) + + def get_sid_desc(self,gdbname,ohome,sid,sflag): + """ + get the SID_LISTENER_DESCRIPTION + """ + self.log_info_message("Inside get_sid_desc()",self.file_name) + sid_desc = "" + if sflag == 'SID_DESC1': + sid_desc = ''' ) + (SID_DESC = + (GLOBAL_DBNAME = {0}) + (ORACLE_HOME = {1}) + (SID_NAME = {2}) + ) + ) + '''.format(gdbname,ohome,sid) + elif sflag == 'SID_DESC': + sid_desc = '''(SID_LIST = + (SID_DESC = + (GLOBAL_DBNAME = {0}) + (ORACLE_HOME = {1}) + (SID_NAME = {2}) + ) + ) + '''.format(gdbname,ohome,sid) + else: + pass + + return sid_desc + + def get_lisora(self,port): + """ + return listener.ora listener settings + """ + self.log_info_message("Inside get_lisora()",self.file_name) + listener='''LISTENER = + (DESCRIPTION_LIST = + (DESCRIPTION = + (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = {0})) + (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC{0})) + ) + ) + '''.format(port) + return listener + + def get_domain(self,ohost): + """ + get the domain name from hostname + """ + return ohost.partition('.')[2] + +######### Get the DOMAIN############## + def get_host_domain(self): + """ + Return Public Hostname + """ + domain=None + domain=socket.getfqdn().split('.',1)[1] + if domain is None: + domain="example.info" + + return domain + + ######### get the public IP ############## + def get_ip(self,hostname,domain): + """ + Return the Ip based on hostname + """ + if not domain: + domain=self.get_host_domain() + + return socket.gethostbyname(hostname) + + def get_global_dbdomain(self,ohost,gdbname): + """ + get the global dbname + """ + domain = self.get_domain(ohost) + if domain: + global_dbname = gdbname + domain + else: + global_dbname = gdbname + + return gdbname + +######### Sqlplus connect string ########### + def get_sqlplus_str(self,home,osid,dbuser,password,hostname,port,svc,osep,role,wallet): + """ + return the sqlplus connect string + """ + path='''/usr/bin:/bin:/sbin:/usr/local/sbin:{0}/bin'''.format(home) + ldpath='''{0}/lib:/lib:/usr/lib'''.format(home) + export_cmd='''export ORACLE_HOME={0};export PATH={1};export LD_LIBRARY_PATH={2};export ORACLE_SID={3}'''.format(home,path,ldpath,osid) + if dbuser == 'sys' and password and hostname and port and svc: + return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4} as sysdba'''.format(dbuser,password,hostname,port,svc,export_cmd,home) + elif dbuser != 'sys' and password and hostname and svc: + return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4}'''.format(dbuser,password,hostname,"1521",svc,export_cmd,home) + elif dbuser and osep: + return dbuser + elif dbuser == 'sys' and not password: + return '''{1};{0}/bin/sqlplus "/ as sysdba"'''.format(home,export_cmd) + elif dbuser == 'sys' and password: + return '''{1};{0}/bin/sqlplus {2}/{3} as sysdba'''.format(home,export_cmd,dbuser,password) + elif dbuser != 'sys' and password: + return '''{1};{0}/bin/sqlplus {2}/{3}'''.format(home,export_cmd,dbuser,password) + else: + self.log_info_message("Atleast specify db user and password for db connectivity. Exiting...",self.file_name) + self.prog_exit("127") + +######### Get Password ############## + def get_os_password(self): + """ + get the OS password + """ + ospasswd=self.get_password(None) + return ospasswd + + def get_asm_passwd(self): + """ + get the ASM password + """ + asmpasswd=self.get_password(None) + return asmpasswd + + def get_db_passwd(self): + """ + get the DB password + """ + dbpasswd=self.get_password(None) + return dbpasswd + + def get_sys_passwd(self): + """ + get the sys user password + """ + dbpasswd=self.get_password(None) + return dbpasswd + + def get_password(self,key): + """ + get the password + """ + passwd_file_flag=False + password=None + password_file=None + if self.check_key("SECRET_VOLUME",self.ora_env_dict): + self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["SECRET_VOLUME"]) + msg='''SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) + else: + self.ora_env_dict=self.add_key("SECRET_VOLUME","/run/secrets",self.ora_env_dict) + msg='''SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("KEY_SECRET_VOLUME",self.ora_env_dict): + self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["KEY_SECRET_VOLUME"]) + msg='''KEY_SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + else: + if self.check_key("SECRET_VOLUME",self.ora_env_dict): + self.ora_env_dict=self.add_key("KEY_SECRET_VOLUME",self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict) + msg='''KEY_SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict): + msg='''COMMON_OS_PWD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) + else: + self.ora_env_dict=self.add_key("COMMON_OS_PWD_FILE","common_os_pwdfile.enc",self.ora_env_dict) + msg='''COMMON_OS_PWD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("PWD_KEY",self.ora_env_dict): + msg='''PWD_KEY passed as an env variable and set to {0}'''.format(self.ora_env_dict["PWD_KEY"]) + else: + self.ora_env_dict=self.add_key("PWD_KEY","pwd.key",self.ora_env_dict) + msg='''PWD_KEY not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PWD_KEY"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("PASSWORD_FILE",self.ora_env_dict): + msg='''PASSWORD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) + else: + self.ora_env_dict=self.add_key("PASSWORD_FILE","dbpasswd.file",self.ora_env_dict) + msg='''PASSWORD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) + self.log_warn_message(msg,self.file_name) + + secret_volume = self.ora_env_dict["SECRET_VOLUME"] + key_secret_volume= self.ora_env_dict["KEY_SECRET_VOLUME"] + common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"] + pwd_volume=None + if self.check_key("PWD_VOLUME",self.ora_env_dict): + pwd_volume=self.ora_env_dict["PWD_VOLUME"] + else: + pwd_volume="/var/tmp" + pwd_key = self.ora_env_dict["PWD_KEY"] + passwd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) + dbpasswd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["PASSWORD_FILE"]) + key_file='''{0}/{1}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"],self.ora_env_dict["PWD_KEY"]) + key_secret_volume='''{0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + self.log_info_message("Password file set to : " + passwd_file,self.file_name) + self.log_info_message("key file set to : " + key_file,self.file_name) + self.log_info_message("dbpasswd file set to : " + dbpasswd_file,self.file_name) + self.log_info_message("key secret voluem set to file set to : " + key_secret_volume,self.file_name) + self.log_info_message("pwd volume set : " + pwd_volume,self.file_name) + #print(passwd_file) + if (os.path.isfile(passwd_file)) and (os.path.isfile(key_file)): + msg='''Passwd file {0} and key file {1} exist. Password file Check passed!'''.format(passwd_file,key_file) + self.log_info_message(msg,self.file_name) + msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file) + self.log_info_message(msg,self.file_name) + cmd=None + if self.check_key("ENCRYPTION_TYPE",self.ora_env_dict): + if self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "aes256": + cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out {2}/{1} -pass file:\"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + elif self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "rsautl": + cmd ='''openssl rsautl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + else: + pass + else: + cmd ='''openssl pkeyutl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + passwd_file_flag = True + password_file='''{0}/{1}'''.format(pwd_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) + elif os.path.isfile(dbpasswd_file): + msg='''Passwd file {0} exist. Password file Check passed!'''.format(dbpasswd_file) + self.log_info_message(msg,self.file_name) + msg='''Reading encrypted passwd from file {0}.'''.format(dbpasswd_file) + self.log_info_message(msg,self.file_name) + cmd='''openssl base64 -d -in \"{0}\" -out \"{2}/{1}\"'''.format(dbpasswd_file,self.ora_env_dict["PASSWORD_FILE"],pwd_volume) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + passwd_file_flag = True + password_file='''{1}/{0}'''.format(self.ora_env_dict["PASSWORD_FILE"],pwd_volume) + + if not passwd_file_flag: + # get random password pf length 8 with letters, digits, and symbols + characters1 = string.ascii_letters + string.digits + "_-%#" + str1 = ''.join(random.choice(string.ascii_uppercase) for i in range(4)) + str2 = ''.join(random.choice(characters1) for i in range(8)) + password=str1+str2 + else: + fname='''{0}'''.format(password_file) + fdata=self.read_file(fname) + password=fdata + self.remove_file(fname) + + if self.check_key("ORACLE_PWD",self.ora_env_dict): + msg="ORACLE_PWD is passed as an env variable. Check Passed!" + self.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.add_key("ORACLE_PWD",password,self.ora_env_dict) + msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file" + self.log_info_message(msg,self.file_name) + +######### Get oraversion ############## + def get_oraversion(self,home): + """ + get the software version + """ + cmd='''{0}/bin/oraversion -majorVersion'''.format(home) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + return output + +####### Get db lock file location ####### + def get_db_lock_location(self): + """ + get the db location + """ + if self.check_key("DB_LOCK_FILE_LOCATION",self.ora_env_dict): + return self.ora_env_dict["DB_LOCK_FILE_LOCATION"] + else: + ### Please note that you should not change following path as SIDB team is maintaining lock files under following location + return "/tmp/." + +####### Get the TDE Key ############### + def export_tde_key(self,filename): + """ + This function export the tde. + """ + self.log_info_message("Inside gettdekey()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + ALTER SESSION DISABLE SHARD DDL; + ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET {0} TO {1} IDENTIFIED BY {0}; + '''.format('HIDDEN_STRING',filename) + self.log_info_message("Running the sqlplus command to export the tde: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + +####### Get the TDE Key ############### + def import_tde_key(self,filename): + """ + This function import the TDE key. + """ + self.log_info_message("Inside importtdekey()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY {0}; + ADMINISTER KEY MANAGEMENT IMPORT ENCRYPTION KEYS WITH SECRET {0} FROM {1} IDENTIFIED BY {0} WITH BACKUP + '''.format('HIDDEN_STRING',filename) + self.log_info_message("Running the sqlplus command to import the tde key: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) +######## Reset the DB Password in database ######## + def reset_passwd(self): + """ + This function reset the password. + """ + password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh") + self.log_info_message("Executing password reset", self.file_name) + if self.check_key("ORACLE_PWD",self.ora_env_dict) and self.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script): + cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING') + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + self.unset_mask_str() + else: + msg='''Error Occurred! Either HOME DIR {0} does not exist, ORACLE_PWD {1} is not set or PASSWORD SCRIPT {2} does not exist'''.format(self.ora_env_dict["HOME"],self.ora_env_dict["ORACLE_PWD"],password_script) + self.log_error_message(msg,self.file_name) + self.oracommon.prog_exit() \ No newline at end of file diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oraenv.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oraenv.py new file mode 100755 index 0000000..dd96c48 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oraenv.py @@ -0,0 +1,139 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file read the env variables from a file or using env command and populate them in variable +""" + +import os + +class OraEnv: + __instance = None + __env_var_file = '/etc/rac_env_vars' + + __env_var_file_flag = None + __env_var_dict = {} + __ora_asm_diskgroup_name = '+DATA' + __ora_gimr_flag = 'false' + __ora_grid_user = 'grid' + __ora_db_user = 'oracle' + __ora_oinstall_group_name = 'oinstall' + encrypt_str__ = None + original_str__ = None + logdir__ = "/tmp/sharding" + + def __init__(self): + """ Virtually private constructor. """ + if OraEnv.__instance != None: + raise Exception("This class is a singleton!") + else: + OraEnv.__instance = self + OraEnv.read_variable() + OraEnv.add_variable() + try: + os.mkdir(OraEnv.logdir__) + except OSError as error: + pass + + @staticmethod + def get_instance(): + """ Static access method. """ + if OraEnv.__instance == None: + OraEnv() + return OraEnv.__instance + + @staticmethod + def read_variable(): + """ Read the variables from a file into dict """ + if OraEnv.__env_var_file_flag: + with open(OraEnv.__env_var_file) as envfile: + for line in envfile: + name, var = line.partition("=")[::2] + OraEnv.__env_var_dict[name.strip()] = var + else: + OraEnv.__env_var_dict = os.environ + + @staticmethod + def add_variable(): + """ Add more variable ased on enviornment with default values in __env_var_dict""" + OraEnv.__env_var_dict["GSM_LOCK_STATUS_FILE"] = "/tmp/.gsm_status_lock_file" + OraEnv.__env_var_dict["SHARD_LOCK_STATUS_FILE"] = "/tmp/.shard_status_lock_file" + if "ORA_ASM_DISKGROUP_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_ASM_DISKGROUP_NAME"] = "+DATA" + + if "ORA_GRID_USER" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_GRID_USER"] = "grid" + + if "ORA_DB_USER" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_DB_USER"] = "oracle" + + if "ORA_OINSTALL_GROUP_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_OINSTALL_GROUP_NAME"] = "oinstall" + + @staticmethod + def add_custom_variable(key,val): + """ Addcustom more variable passed from main.py values in __env_var_dict""" + if key not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict[key] = val + + @staticmethod + def get_env_vars(): + """ Static access method to get the env vars. """ + return OraEnv.__env_var_dict + + @staticmethod + def update_env_vars(env_dict): + """ Static access method to get the env vars. """ + OraEnv.__env_var_dict = env_dict + + @staticmethod + def logfile_name(file_type): + """ Static access method to return the logfile name. """ + if file_type == "NONE": + if "LOGFILE_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/oracle_sharding_setup.log" + elif file_type == "ADD_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_addition.log" + elif file_type == "VALIDATE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_validation.log" + elif file_type == "REMOVE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_remove.log" + elif file_type == "CHECK_LIVENESS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkliveness.log" + elif file_type == "CHECK_READYNESS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkreadyness.log" + elif file_type == "RESET_LISTENER": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_listener.log" + elif file_type == "RESTART_DB": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/restart_db.log" + elif file_type == "CREATE_DIR": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/create_dir.log" + elif file_type == "ADD_SGROUP_PARAMS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/add_sgroup.log" + elif file_type == "DEPLOY_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/deploy_shard.log" + elif file_type == "CANCEL_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/cancel_chunk.log" + elif file_type == "MOVE_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/move_chunks.log" + elif file_type == "CHECK_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_chunks.log" + elif file_type == "CHECK_ONLINE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_online_shard.log" + elif file_type == "CHECK_GSM_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_gsm_shard.log" + elif file_type == "INVITED_NODE_OP": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/node_invited_op.log" + elif file_type == "RESET_PASSWD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_passwd_file.log" + elif file_type == "TDE_KEY": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/tde_key.log" + else: + pass + + return OraEnv.__env_var_dict["LOG_FILE_NAME"] diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orafactory.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orafactory.py new file mode 100755 index 0000000..5ddb6e3 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orafactory.py @@ -0,0 +1,115 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file contains to the code call different classes objects based on setup type +""" + +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +from orapshard import * +from orasshard import * +from orapcatalog import * +from oragsm import * + +import os +import sys + +class OraFactory: + """ + This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def get_ora_objs(self): + ''' + Return the instance of a classes which will setup the enviornment. + + Returns: + ofactory_obj: List of objects + ''' + ofactory_obj = [] + + msg='''ora_env_dict set to : {0}'''.format(self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + msg="Checking the OP_TYPE and Version to begin the installation" + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the OP_TYPE + if self.ocommon.check_key("OP_TYPE",self.ora_env_dict): + msg='''OP_TYPE variable is set to {0}.'''.format(self.ora_env_dict["OP_TYPE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("OP_TYPE","nosetup",self.ora_env_dict) + msg="OP_TYPE variable is set to default nosetup. No value passed as an enviornment variable." + self.ocommon.log_info_message(msg,self.file_name) + + # Check the OP_TYPE value and call objects based on it value + if self.ora_env_dict["OP_TYPE"] == 'primaryshard': + msg="Creating and calling instance to setup primary shard" + opshard = OraPShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(opshard) + elif self.ora_env_dict["OP_TYPE"] == 'standbyshard': + msg="Creating and calling instance to setup standby shard" + osshard = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(osshard) + elif self.ora_env_dict["OP_TYPE"] == 'catalog': + msg="Creating and calling instance to setup Catalog DB" + opcat = OraPCatalog(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(opcat) + elif self.ora_env_dict["OP_TYPE"] == 'standbycatalog': + msg="Creating and calling instance to setup Catalog DB" + oscat = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(oscat) + elif self.ora_env_dict["OP_TYPE"] == 'gsm': + msg="Creating and calling instance to setup GSM" + ogsm = OraGSM(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(ogsm) + else: + msg="OP_TYPE must be set to {primaryshard|standbyshard|catalog|standbycatalog|gsm}" + self.ocommon.log_info_message(msg,self.file_name) + msg="Since OP_TYPE is set to nosetup, only compute env is being setup. Creating and calling instance to setup compute." + self.ocommon.log_info_message(msg,self.file_name) + omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + ofactory_obj.append(omachine) + + return ofactory_obj diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oragsm.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oragsm.py new file mode 100755 index 0000000..ef0bb06 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oragsm.py @@ -0,0 +1,2945 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +import os +import sys +import os.path +import re +import socket +import random +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +class OraGSM: + """ + This calss setup the Gsm after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraGsm class to setup the Gsm on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def setup(self): + """ + This function setup the Gsm on Primary DB. + """ + if self.ocommon.check_key("ADD_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.add_gsm_shard() + self.set_hostid_null() + self.add_invited_node("ADD_SHARD") + self.remove_invited_node("ADD_SHARD") + sys.exit(0) + if self.ocommon.check_key("DEPLOY_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.deploy_shard() + self.setup_gsm_service() + sys.exit(0) + elif self.ocommon.check_key("ADD_SGROUP_PARAMS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_gsm_shardg("ADD_SGROUP_PARAMS") + sys.exit(0) + elif self.ocommon.check_key("ADD_SSPACE_PARAMS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_gsm_sspace("ADD_SSPACE_PARAMS") + sys.exit(0) + elif self.ocommon.check_key("REMOVE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + status=self.remove_gsm_shard() + + if status: + sys.exit(0) + else: + sys.exit(1) + + elif self.ocommon.check_key("MOVE_CHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.move_shard_chunks() + sys.exit(0) + elif self.ocommon.check_key("TDE_KEY",self.ora_env_dict): + self.ocommon.get_tde_key() + sys.exit(0) + elif self.ocommon.check_key("CANCEL_CHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.cancel_move_chunks() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_NOCHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.validate_nochunks() + sys.exit(0) + elif self.ocommon.check_key("CHECK_ONLINE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.verify_online_shard() + sys.exit(0) + elif self.ocommon.check_key("CHECK_GSM_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.verify_gsm_shard() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.validate_gsm_shard() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_GSM",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + sys.exit(0) + elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + if os.path.exists(filename): + self.ocommon.log_info_message("provisioning is still in progress as file " + filename + " still exist!",self.file_name) + sys.exit(0) + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + status = self.check_gsm_director_status(None) + if not status: + self.ocommon.log_info_message("No GDS setup found on this system.",self.file_name) + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("GSM liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("INVITED_NODE_OP",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.invited_node_op() + sys.exit(0) + elif self.ocommon.check_key("CATALOG_SETUP",self.ora_env_dict): + # If user pass env avariable CATALOG_SETUP true then it will just create gsm director and add catalog but will not add any shard + # It will also add service + status = self.catalog_setup_checks() + if status == False: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.setup_machine() + self.catalog_checks() + self.reset_gsm_setup() + status1 = self.gsm_setup_check() + if status1: + self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) + self.start_gsm_director() + self.ocommon.log_info_message("Started GSM",self.file_name) + else: + # Perform Catalog setup after check GSM_MASTER FLAG. IF GSM MASTER FLAG is set then only catalog will be added. + self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) + master_flag=self.gsm_master_flag_check() + if master_flag: + self.setup_gsm_calog() + self.setup_gsm_director() + self.start_gsm_director() + self.status_gsm_director() + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': + self.setup_gsm_shardg("SHARD_GROUP") + else: + self.setup_gsm_shardg("SHARD_GROUP") + self.gsm_backup_file() + self.gsm_completion_message() + ### Running Custom Scripts + self.run_custom_scripts() + else: + self.add_gsm_director() + self.start_gsm_director() + self.gsm_backup_file() + self.gsm_completion_message() + else: + # This block run shard addition, catalog addition and service creation + # This block also verifies if master flag is not not GSM director then it will not create catalog but add GSM ony + self.setup_machine() + self.gsm_checks() + self.reset_gsm_setup() + status = self.gsm_setup_check() + if status: + self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) + self.start_gsm_director() + self.ocommon.log_info_message("Started GSM",self.file_name) + else: + # if the status = self.gsm_setup_check() return False then shard addition, catalog addition and service creation + master_flag=self.gsm_master_flag_check() + if master_flag: + self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) + self.setup_gsm_calog() + self.setup_gsm_director() + self.start_gsm_director() + self.status_gsm_director() + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': + self.setup_gsm_shardg("SHARD_GROUP") + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + self.setup_gsm_sspace("SHARD_SPACE") + else: + self.setup_gsm_shardg("SHARD_GROUP") + self.setup_gsm_shard() + self.set_hostid_null() + self.stop_gsm_director() + time.sleep(30) + self.start_gsm_director() + self.add_invited_node("SHARD") + self.remove_invited_node("SHARD") + self.stop_gsm_director() + time.sleep(30) + self.start_gsm_director() + self.deploy_shard() + self.setup_gsm_service() + self.setup_sample_schema() + self.gsm_backup_file() + self.gsm_completion_message() + ### Running Custom Scripts + self.run_custom_scripts() + else: + self.add_gsm_director() + self.start_gsm_director() + self.gsm_backup_file() + self.gsm_completion_message() + + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + filename = self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + touchfile = 'touch {0}'.format(filename) + if not os.path.isfile(filename): + self.ocommon.log_error_message("Setting file provisioning status file :" + filename ,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(touchfile,None,self.ora_env_dict) + if retcode == 1: + self.ocommon.log_error_message("error occurred while touching the file :" + filename + ". Exiting!",self.file_name) + self.ocommon.prog_exit("127") + + ########### ENDS here #################### + + def gsm_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.shard_user_check() + self.gsm_hostname_check() + self.director_params_checks() + self.catalog_params_check() + self.shard_params_check() + self.sgroup_params_check() + + + def catalog_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.shard_user_check() + self.gsm_hostname_check() + self.director_params_checks() + self.catalog_params_check() + self.sgroup_params_check() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit("127") + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def passwd_check(self): + """ + Set the password + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def shard_user_check(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def director_params_checks(self): + """ + This funnction check and set the shard director name + """ + status=False + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD Director PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + + def gsm_hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def catalog_params_check(self): + """ + This funnction check if CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''CATALOG PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + if stype: + if stype.lower() == 'user': + if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) + if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) + status=True + + if not status: + msg="CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is not set, exiting!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def shard_params_check(self): + """ + This funnction check if SHARD[1-9]_PARAMS such as SHARD1_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + + if not status: + msg="SHARD[1-9]_PARAMS such as SHARD1_PARAMS is not set, exiting!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def sgroup_params_check(self): + """ + This funnction check if SHARD[1-9]_GROUP_PARAMS such as SHARD1_GROUP_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD GROUP PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + def gsm_master_flag_check(self): + """ + This funnction check if MASTER_GSM is passed as an env variable or not. If not passed then exit. + """ + status=False + if self.ocommon.check_key("MASTER_GSM",self.ora_env_dict): + msg='''MASTER_GSM is set. This machine will be configured with as master GSM director.''' + self.ocommon.log_info_message(msg,self.file_name) + return True + else: + return False + + def catalog_setup_checks(self): + """ + This function checks if director and catalog is setup and connection is established. + """ + status = False + gsm_status = self.check_gsm_director(None) + #catalog_status = self.check_gsm_catalog() + + if gsm_status == 'completed': + status = True + else: + status = False + + #if catalog_status == 'completed': + # status = True + #else: + # status = False + + return status + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### + def reset_gsm_setup(self): + """ + This function delete the GSM files. + """ + self.ocommon.log_info_message("Inside reset_gsm_setup",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + cmd_list=[] + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + msg='''Deleteing files from {0}'''.format(gsmdata_loc) + self.ocommon.log_info_message(msg,self.file_name) + cmd_list[0]='''rm -f {0}/gsm.ora'''.format(gsmdata_loc) + cmd_list[1]='''rm -f {0}/tnsnames.ora'''.format(gsmdata_loc) + cmd_list[2]='''rm -rf {0}/wallets'''.format(gsmdata_loc) + for cmd in cmd_list: + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + def gsm_setup_check(self): + """ + This function check if GSM is already setup on this + """ + status=True + self.ocommon.log_info_message("Inside gsm_setup_check",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) + + gsmora='''{0}/gsm.ora'''.format(gsmdata_loc) + tnsnamesora='''{0}/tnsnames.ora'''.format(gsmdata_loc) + walletloc='''{0}/gsmwallet'''.format(gsmdata_loc) + + if os.path.isfile(gsmora): + cmd='''cp -r -v -f {0} {1}/'''.format(gsmora,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if os.path.isfile(tnsnamesora): + cmd='''cp -r -v -f {0} {1}/'''.format(tnsnamesora,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if os.path.isdir(walletloc): + cmd='''cp -r -v -f {0} {1}/'''.format(walletloc,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if status: + return True + else: + return False + + #################### Catalog related Functions BEGINS Here ########################### + def setup_gsm_calog(self): + """ + This function setup the GSM catalog. + """ + self.ocommon.log_info_message("Inside setup_gsm_calog()",self.file_name) + status=False + reg_exp= self.catalog_regex() + counter=1 + end_counter=60 + catalog_db_status=None + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + catalog_db_status=self.check_setup_status(catalog_host,catalog_db,catalog_pdb,catalog_port) + if catalog_db_status == 'completed': + self.configure_gsm_clog(catalog_host,catalog_db,catalog_pdb,catalog_port,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname) + break + else: + msg='''Catalog Status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + if catalog_db_status == 'completed': + break + else: + msg='''Catalog setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + def process_clog_vars(self,key): + """ + This function process catalog vars based on key and return values to configure the GSM + """ + catalog_db=None + catalog_pdb=None + catalog_port=None + catalog_region=None + catalog_host=None + catalog_name=None + catalog_chunks=None + repl_type=None + repl_factor=None + repl_unit=None + stype=None + sspace=None + cfname=None + + self.ocommon.log_info_message("Inside process_clog_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'catalog_db': + catalog_db = cvar_dict[ckey] + if ckey == 'catalog_pdb': + catalog_pdb = cvar_dict[ckey] + if ckey == 'catalog_port': + catalog_port = cvar_dict[ckey] + if ckey == 'catalog_region': + catalog_region = cvar_dict[ckey] + if ckey == 'catalog_host': + catalog_host = cvar_dict[ckey] + if ckey == 'catalog_name': + catalog_name = cvar_dict[ckey] + if ckey == 'catalog_chunks': + catalog_chunks = cvar_dict[ckey] + if ckey == 'repl_type': + repl_type = cvar_dict[ckey] + if ckey == 'repl_factor': + repl_factor = cvar_dict[ckey] + if ckey == 'repl_unit': + repl_unit = cvar_dict[ckey] + if ckey == 'sharding_type': + stype = cvar_dict[ckey] + if ckey == 'shard_space': + sspace = cvar_dict[ckey] + if ckey == 'shard_configname': + cfname = cvar_dict[ckey] + + ## Set the values if not set in above block + if not catalog_port: + catalog_port=1521 + if not catalog_region: + catalog_region="region1,region2" + if stype: + if not sspace: + sspace="shardspace1,shardspace2" + + ### Check values must be set + if catalog_host and catalog_db and catalog_pdb and catalog_port and catalog_region and catalog_name: + return catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname + else: + msg1='''catalog_db={0},catalog_pdb={1}'''.format((catalog_db or "Missing Value"),(catalog_pdb or "Missing Value")) + msg2='''catalog_port={0},catalog_host={1}'''.format((catalog_port or "Missing Value"),(catalog_host or "Missing Value")) + msg3='''catalog_region={0},catalog_name={1}'''.format((catalog_region or "Missing Value"),(catalog_name or "Missing Value")) + msg='''Catalog params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def check_gsm_catalog(self): + """ + This function check the catalog status in GSM + """ + self.ocommon.log_info_message("Inside check_gsm_catalog()",self.file_name) + #dtrname,dtrport,dtregion=self.process_director_vars() + gsmcmd=''' + config; + exit; + '''.format("test") + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + match=self.ocommon.check_substr_match(matched_output[0],"test") + except: + match=False + return(self.ocommon.check_status_value(match)) + + # output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + # new_output=output[0].replace(" ","") + # self.ocommon.log_info_message(new_output,self.file_name) + # match=self.ocommon.check_substr_match(new_output,"Catalogconnectionisestablished") + # return(self.ocommon.check_status_value(match)) + + def catalog_regex(self): + """ + This function return the rgex to search the CATALOG PARAMS + """ + self.ocommon.log_info_message("Inside catalog_regex()",self.file_name) + return re.compile('CATALOG_PARAMS') + + + def configure_gsm_clog(self,chost,ccdb,cpdb,cport,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname): + """ + This function configure the GSM catalog. + """ + self.ocommon.log_info_message("Inside configure_gsm_clog()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + replist=['native'] + + ### User Define Shardig Variables + shardingtype=None + shardspace=None + configname=None + + # if stype and sspace: + if stype: + if stype.lower() == 'user': + shardingtype="-sharding user" + #shardspace="" + shardspace=" -shardspace {0}".format(sspace) + if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) + if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) + else: + shardspace="" + shardingtype="" + else: + shardspace="" + shardingtype="" + + if cfname: + configname=" -configname {0}".format(cfname) + else: + configname="" + + ### SNR Sharding + chunks=None + repl=None + repfactor=None + repunits=None + + if catalog_chunks: + chunks="-chunks {0}".format(catalog_chunks) + else: + chunks="" + + if repl_type and repl_type.lower() in replist: + self.ocommon.log_info_message("Repl_Type value Set to in block1:" + repl_type,self.file_name) + repl=" -repl {0}".format(repl_type) + else: + repl="" + + if repl_factor: + repfactor=" -repfactor {0}".format(repl_factor) + else: + repfactor="" + + if repl_unit: + repunits=" -repunits {0}".format(repl_unit) + else: + repunits="" + + invited_subnet="" + add_invited_subnet="" + if self.ocommon.check_key("INVITED_NODE_SUBNET_FLAG",self.ora_env_dict): + if self.ocommon.check_key("INVITED_NODE_SUBNET",self.ora_env_dict): + invited_subnet=self.ora_env_dict["INVITED_NODE_SUBNET"] + else: + #self.ocommon.log_info_message("The catalog Host name is :" + chost,self.file_name) + chost_ip=self.ocommon.get_ip(chost,None) + ip_parts=chost_ip.split('.') + invited_subnet=ip_parts[0] + "." + ip_parts[1] + '.*' + '.*' + add_invited_subnet='''add invitedsubnet {0};'''.format(invited_subnet) + + cpasswd="HIDDEN_STRING" + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})))\" {7} -user {3}/{4} -sdb {5} -region {6} -agent_port 8080 -agent_password {4} {8} {9} {10} {11} {12} {13} -autovncr off; + add invitednode {0}; + {14} + exit; + '''.format(chost,cport,cpdb,cadmin,cpasswd,catalog_name,catalog_region,chunks,repl,repfactor,repunits,shardingtype,shardspace,configname,add_invited_subnet) + + counter=1 + while counter < 5: + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + if retcode != 0: + self.ocommon.log_info_message("Error occurred while creating the shard catalog, sleeping for 60 seconds",self.file_name) + counter = counter + 1 + time.sleep(60) + else: + break + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ######################################## GSM director Functions Begins Here ##################### + def process_director_vars(self,key): + """ + This function process GSM director vars based on key and return values to configure the GSM + """ + dtrname=None + dtrport=None + dtregion=None + + self.ocommon.log_info_message("Inside process_director_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'director_name': + dtrname = cvar_dict[ckey] + if ckey == 'director_port': + dtrport = cvar_dict[ckey] + if ckey == 'director_region': + dtregion = cvar_dict[ckey] + + ### Check values must be set + if dtrname and dtrport and dtregion: + return dtrname,dtrport,dtregion + else: + msg1='''director_name={0},director_port={1}'''.format((dtrname or "Missing Value"),(dtrport or "Missing Value")) + msg2='''director_region={0}'''.format((dtregion or "Missing Value")) + msg='''Director params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_gsm_director(self,dname): + """ + This function check the GSM director status + """ + self.ocommon.log_info_message("Inside check_gsm_director()",self.file_name) + status=False + if dname: + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(matched_output[0],dname): + status=True + except: + status=False + else: + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(matched_output[0],dname): + status=True + except: + status=False + + return(self.ocommon.check_status_value(status)) + + def check_gsm_region(self,region): + """ + This function check the GSM regions + """ + self.ocommon.log_info_message("Inside check_gsm_region()",self.file_name) + gsmcmd=self.get_gsm_config_cmd(None) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Regions\n)(?:.+\n)+",output) + status=False + try: + if self.ocommon.check_substr_match(matched_output[0],region): + status=True + except: + status=False + return(self.ocommon.check_status_value(status)) + + def check_gsm_shardspace(self,sspace): + """ + This function check the GSM shardspace + """ + self.ocommon.log_info_message("Inside check_gsm_shardspace()",self.file_name) + gsmcmd=self.get_gsm_config_cmd(None) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard spaces\n)(?:.+\n)+",output) + status=False + try: + if self.ocommon.check_substr_match(matched_output[0],sspace): + status=True + except: + status=False + return(self.ocommon.check_status_value(status)) + + def check_gsm_director_status(self,dname): + """ + This function check the GSM director status using 'gdsctl status' + """ + self.ocommon.log_info_message("Inside check_gsm_director_status()",self.file_name) + status=False + gsmcmd=''' + status; + exit; + ''' + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + if "Connected to GDS catalog Y".replace(" ","").lower() in output.replace(" ","").lower(): + return True + else: + return False + + def add_gsm_director(self): + """ + This function add the GSM + """ + status=False + counter=1 + end_counter=60 + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + reg_exp= self.director_regex() + + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_director_status=None + dtrname,dtrport,dtregion=self.process_director_vars(key) + shard_director_status=self.check_gsm_director(dtrname) + if shard_director_status != 'completed': + self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) + status = self.check_gsm_director(None) + if status == 'completed': + break + + if status == 'completed': + break + else: + msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + status = self.check_gsm_director(None) + if status == 'completed': + msg='''Shard director setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 60 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def setup_gsm_director(self): + """ + This function setup in GSM + """ + self.ocommon.log_info_message("Inside setup_gsm_director()",self.file_name) + status=False + reg_exp= self.director_regex() + counter=1 + end_counter=3 + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_director_status=None + dtrname,dtrport,dtregion=self.process_director_vars(key) + shard_director_status=self.check_gsm_director(dtrname) + if shard_director_status != 'completed': + self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) + status = self.check_gsm_director(None) + if status == 'completed': + break + else: + msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + time.sleep(60) + counter=counter+1 + + status = self.check_gsm_director(None) + if status == 'completed': + msg='''Shard director setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 3 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin): + """ + This function configure GSM director + """ + ## Getting the values of catalog_port,catalog_pdb,catalog_host + cpasswd="HIDDEN_STRING" + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sregionFlag=self.check_gsm_region(dtregion) + if sregionFlag != 'completed': + self.configure_gsm_region(dtregion) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + add gsm -gsm {0} -listener {1} -pwd {2} -catalog {3}:{4}/{5} -region {6}; + exit; + '''.format(dtrname,dtrport,cpasswd,catalog_host,catalog_port,catalog_pdb,dtregion,gsmhost) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def start_gsm_director(self): + """ + This function start the director in the GSM + """ + status='noval' + self.ocommon.log_info_message("Inside start_gsm_director() function",self.file_name) + reg_exp= self.director_regex() + counter=1 + end_counter=10 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=''' + start gsm -gsm {0}; + exit; + '''.format(dtrname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + status=self.check_gsm_director(dtrname) + if status == 'completed': + break; + if status == 'completed': + filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + remfile='''rm -f {0}'''.format(filename) + if os.path.isfile(filename): + output,error,retcode=self.ocommon.execute_cmd(remfile,None,self.ora_env_dict) + break + else: + msg='''GSM shard director failed to start.Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_error_message(msg,self.file_name) + time.sleep(30) + + counter=counter+1 + + + if status != 'completed': + msg='''GSM shard director failed to start.Exiting!''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def stop_gsm_director(self): + """ + This function stop the director in the GSM + """ + status=False + self.ocommon.log_info_message("Inside stop_gsm_director() function",self.file_name) + reg_exp= self.director_regex() + counter=1 + end_counter=2 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=''' + stop gsm -gsm {0}; + exit; + '''.format(dtrname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + counter=counter+1 + + def status_gsm_director(self): + """ + This function check the GSM director status + """ + gsm_status = self.check_gsm_director(None) + #catalog_status = self.check_gsm_catalog() + + if gsm_status == 'completed': + msg='''Director setup completed in GSM and catalog is connected''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard director in GSM did not complete or not connected to catalog. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + ######################################## Shard Group Setup Begins Here ############################ + def setup_gsm_shardg(self,restype): + """ + This function setup the shard group. + """ + self.ocommon.log_info_message("Inside setup_gsm_shardg()",self.file_name) + status=False + if restype == 'ADD_SGROUP_PARAMS': + reg_exp = self.add_shardg_regex() + elif restype == 'SHARD_GROUP': + reg_exp = self.shardg_regex() + else: + self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SGROUP_PARAMS or SHARD_GROUP key to create a shard group",self.file_name) + self.ocommon.log_warn_message("Since no key specified for ADD_SGROUP_PARAMS and SHARD_GROUP, shardgroup will be created during shard creation",self.file_name) + + sgListC=[] + sgListP=[] + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_group_status=None + self.ocommon.log_info_message("Key is set to : " + key,self.file_name) + group_name,deploy_as,group_region=self.process_shardg_vars(key) + self.ocommon.log_info_message("Name: " + group_name + "deploy_as" + deploy_as + "group_region" + group_region,self.file_name) + if group_name is not None: + if group_name not in sgListC: + dtrname=self.get_director_name(group_region) + shard_group_status=self.check_shardg_status(group_name,dtrname) + if shard_group_status != 'completed': + self.configure_gsm_shardg(group_name,deploy_as,group_region,'add') + shard_group_status = self.check_shardg_status(group_name,None) + if shard_group_status == 'completed': + sgListC.append(group_name) + if group_name in sgListP: + sgListP.remove(group_name) + else: + sgListP=sgListP.append(group_name) + time.sleep(30) + counter=counter + 1 + + if sgListP == []: + msg='''Shard group setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def get_director_name(self,region_name): + """ + This function get the director name based on the region + """ + self.ocommon.log_info_message("Inside get_director_name()",self.file_name) + status=False + director_name=None + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + director_name=dtrname + gsm_status = self.check_gsm_director(dtrname) + if gsm_status == 'completed': + status = True + else: + status = False + if dtregion == region_name: + break + if status: + if director_name: + return director_name + else: + self.ocommon.log_error_message("No director exist to match the region",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.log_error_message("Shard Director is not running!",self.file_name) + self.ocommon.prog_exit("127") + + def get_shardg_region_name(self,sgname): + """ + This function get the region name based on shard group name + """ + self.ocommon.log_info_message("Inside get_region_name()",self.file_name) + status=False + region_name=None + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + group_name,deploy_as,group_region=self.process_shardg_vars(key) + region_name=group_region + if sgname == group_name: + status=True + break + if status: + return region_name + else: + self.ocommon.log_error_message("No such shard group exist! exiting!",self.file_name) + self.ocommon.prog_exit("127") + + def process_shardg_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + group_name=None + deploy_as=None + group_region=None + + self.ocommon.log_info_message("Inside process_shardg_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'group_name': + group_name = cvar_dict[ckey] + if ckey == 'deploy_as': + deploy_as = cvar_dict[ckey] + if ckey == 'group_region': + group_region = cvar_dict[ckey] + + ### Check values must be set + if group_name and deploy_as and group_region: + return group_name,deploy_as,group_region + else: + msg1='''group_name={0},deploy_as={1}'''.format((group_name or "Missing Value"),(deploy_as or "Missing Value")) + msg2='''group_region={0}'''.format((group_region or "Missing Value")) + msg='''Shard group params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + + def check_shardg_status(self,group_name,dname): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_shardg_status()",self.file_name) + status=False + + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) + if self.ocommon.check_substr_match(matched_output[0],group_name): + status=True + else: + status=False + + ''' + else: + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + group_name,deploy_as,group_region=self.process_shardg_vars(key) + dname=self.get_director_name(group_region) + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) + # match=re.search("(?i)(?m)"+group_name,matched_output) + if self.ocommon.check_substr_match(matched_output[0],group_name): + status=True + else: + status=False + ''' + + return(self.ocommon.check_status_value(status)) + +############################################# Director Related Block ############ + def get_director_name(self,region_name): + """ + This function get the director name based on the region + """ + self.ocommon.log_info_message("Inside get_director_name()",self.file_name) + status=False + director_name=None + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + director_name=dtrname + gsm_status = self.check_gsm_director(dtrname) + if gsm_status == 'completed': + status = True + else: + status = False + if dtregion == region_name: + break + if status: + if director_name: + return director_name + else: + self.ocommon.log_error_message("No director exist to match the region",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.log_error_message("Shard Director is not running!",self.file_name) + self.ocommon.prog_exit("127") + +######## + + def get_gsm_config_cmd(self,dname): + """ + Get the GSM config command + """ + self.ocommon.log_info_message("Inside get_gsm_config_cmd()",self.file_name) + gsmcmd=''' + config; + exit; + '''.format("test") + return gsmcmd + + def director_regex(self): + """ + This function return the rgex to search the SHARD DIRECTOR PARAMS + """ + self.ocommon.log_info_message("Inside director_regex()",self.file_name) + return re.compile('SHARD_DIRECTOR_PARAMS') + + def shardg_regex(self): + """ + This function return the rgex to search the SHARD GROUP PARAMS + """ + self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) + return re.compile('SHARD[0-9]+_GROUP_PARAMS') + + def add_shardg_regex(self): + """ + This function return the rgex to search the SHARD GROUP PARAMS + """ + self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) + return re.compile('ADD_SGROUP_PARAMS') + + def configure_gsm_shardg(self,group_name,deploy_as,group_region,type): + """ + This function configure the Shard Group. + """ + self.ocommon.log_info_message("Inside configure_gsm_shardg()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + dtrname=self.get_director_name(group_region) + reg_exp= self.catalog_regex() + if type == 'modify': + cmd=''' modify shardgroup -shardgroup {0} '''.format(group_name) + else: + cmd=''' add shardgroup -shardgroup {0} '''.format(group_name) + + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + if repl_type: + cmd=cmd + " -region {0} ".format(group_region) + else: + cmd=cmd + " -deploy_as {0} -region {1} ".format(deploy_as,group_region) + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + exit; + '''.format("NA",cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + +############# Adding Shard Regions ############### + def configure_gsm_region(self,region): + """ + This function configure the Shard region. + """ + self.ocommon.log_info_message("Inside configure_gsm_region()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + add region -region {3}; + exit; + '''.format("NA",cadmin,cpasswd,region) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + +##################### Adding Shard Space ############### + def process_sspace_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + sspace=None + chunks=None + repfactor=None + repunits=None + protectedmode=None + self.ocommon.log_info_message("Inside process_sspace_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'sspace_name': + sspace = cvar_dict[ckey] + if ckey == 'chunks': + chunks = cvar_dict[ckey] + if ckey == 'repfactor': + repfactor = cvar_dict[ckey] + if ckey == 'repunits': + repunits = cvar_dict[ckey] + if ckey == 'protectedmode': + protectedmode = cvar_dict[ckey] + + ### Check values must be set + if sspace: + return sspace,chunks,repfactor,repunits,protectedmode + else: + msg1='''sspace={0}'''.format((sspace or "Missing Value")) + msg='''Shard space params {0} is not set correctly. One or more value is missing {1}'''.format(key,msg1) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def setup_gsm_sspace(self,restype): + """ + This function setup the shard sspace. + """ + self.ocommon.log_info_message("Inside setup_gsm_sspace()",self.file_name) + status=False + if restype == 'ADD_SSPACE_PARAMS': + reg_exp = self.add_shardg_regex() + elif restype == 'SHARD_SPACE': + reg_exp = self.shardg_regex() + else: + self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SSPACE_PARAMS or SHARD_SPACE key to create a shard space",self.file_name) + self.ocommon.log_warn_message("Since no ADD_SSPACE_PARAMS or SHARD_SPACE defined, shardspace will be created during shard creation",self.file_name) + counter=1 + ssListC=[] + ssListP=[] + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_space_status=None + sspace,chunks,repfactor,repuntis,protectedmode=self.process_sspace_vars(key) + if sspace is not None: + if sspace not in ssListC: + shard_sspace_status=self.check_gsm_shardspace(sspace) + if shard_sspace_status != 'completed': + self.configure_gsm_sspace(sspace,chunks,repfactor,repuntis,protectedmode,'add') + shard_space_status = self.check_gsm_shardspace(sspace) + if shard_sspace_status == 'completed': + ssListC.append(sspace) + if sspace in sgListP: + sgListP.remove(sspace) + else: + sgListP=sgListP.append(sspace) + time.sleep(30) + counter=counter + 1 + + if ssListP == []: + msg='''Shard space setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete shard space setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def configure_gsm_sspace(self,sspace,chunks,repfactor,repunits,protectedmode,type): + """ + This function configure the Shard Group. + """ + self.ocommon.log_info_message("Inside configure_gsm_sspace()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + if type == 'MODIFY': + cmd=''' modify shardspace -shardspace {0} '''.format(sspace) + else: + cmd=''' add shardspace -shardspace {0} '''.format(sspace) + if chunks is not None: + cmd = cmd + ''' -chunks {0}'''.format(chunks) + if repfactor: + cmd = cmd + ''' -repfactor {0}'''.format(repfactor) + if repunits is not None: + cmd = cmd + ''' -repunits {0}'''.format(repfactor) + if protectedmode is not None: + cmd = cmd + ''' -protectedmode {0}'''.format(protectedmode) + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + exit; + '''.format("NA",cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + #########################################Shard Function Begins Here ############################## + def setup_gsm_shard(self): + """ + This function setup and add shard in the GSM + """ + self.ocommon.log_info_message("Inside setup_gsm_shard()",self.file_name) + status=False + reg_exp= self.shard_regex() + counter=1 + end_counter=60 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,sregion,sspace=self.process_shard_vars(key) + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + if shard_db_status == 'completed': + self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,sregion,sspace) + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + status = self.check_shard_status(None) + if status == 'completed': + break + else: + msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + status = self.check_shard_status(None) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 60 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def add_gsm_shard(self): + """ + This function add the shard in the GSM + """ + self.ocommon.log_info_message("Inside add_gsm_shard()",self.file_name) + status=False + reg_exp= self.add_shard_regex() + counter=1 + end_counter=3 + shard_name="none" + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + self.ocommon.log_info_message("Shard Status : " + shard_db_status,self.file_name) + if shard_db_status == 'completed': + self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,shard_region,shard_space) + counter2=1 + end_counter2=5 + while counter2 < end_counter2: + status1 = self.check_shard_status(shard_name) + if status1 == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + break + else: + msg='''Shard DB is still not added in GSM. Sleeping for 60 seconds''' + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter2=counter2+1 + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + status = self.check_shard_status(None) + if status == 'completed': + break + else: + msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + status = self.check_shard_status(shard_name) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 3 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def remove_gsm_shard(self): + """ + This function remove the shard in the GSM + """ + self.ocommon.log_info_message("Inside remove_gsm_shard()",self.file_name) + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars("CATALOG_PARAMS") + numOfShards=self.count_online_shards() + status=False + reg_exp=self.remove_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shardname_to_delete=shard_db + "_" + shard_pdb + if repl_type is not None: + if(repl_type.upper() == 'NATIVE'): + self.move_shards_leader_rus(shardname_to_delete) + leaderCount=self.count_leader_shards(shardname_to_delete) + if(numOfShards < 4 or leaderCount > 0): + msg='''ruType=[{0}]. NumofShards=[{1}]. LeaderCount=[{2}]. Ignoring remove of shard [{3}]'''.format(repl_type,numOfShards,leaderCount,shardname_to_delete) + self.ocommon.log_info_message(msg,self.file_name) + break + + self.move_shard_rus(shardname_to_delete,None,None) + while self.count_shard_rus(shardname_to_delete) > 0: + self.ocommon.log_info_message("Waiting for all the shard chunks to be moved.",self.file_name) + time.sleep(15) + + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + if shard_db_status == 'completed': + self.delete_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group) + status=True + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + return status + + def move_shards_leader_rus(self,shardname_to_delete): + """ + This function move the shard leader RUs + """ + shards=self.get_online_shards() + leader_ru=self.get_rus(shardname_to_delete) + all_ru=self.get_rus(None) + count=0 + target_shards=[] + value=0 + + if len(shards) == 0: + msg="""No Shard is online so no RU is available to be moved""" + self.ocommon.log_info_message(msg,self.file_name) + else: + for line in leader_ru: + value=None + count += 1 + cols=line.split() + if len(cols) > 0: + if cols[0].lower() == shardname_to_delete.lower(): + if cols[1].isdigit: + value = int(cols[1]) + else: + continue + + target_shards.clear() + for line1 in all_ru: + cols1=line1.split() + print(cols1) + if len(cols1) > 5: + if cols1[0].lower() != shardname_to_delete.lower() and cols1[1].isdigit and cols1[2].lower() == 'follower': + if value is not None: + if int(cols1[1]) == value: + target_shards.append(cols1[0]) + break + + for shard in shards: + if shard.lower() != shardname_to_delete.lower(): + if shard in target_shards: + msg="Shard_name= " + shard + " Status=True" + " Value = " + str(value) + self.ocommon.log_info_message(msg,self.file_name) + self.move_shard_rus(shardname_to_delete,shard,value) + + def move_shard_chunks(self): + """ + This function move the shard chunks + """ + self.ocommon.log_info_message("Inside move_shard_chunks()",self.file_name) + status=False + reg_exp= self.move_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + shard_num = self.count_online_shards() + online_shard = self.check_online_shard(shard_name) + if shard_num > 1 and online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + MOVE CHUNK -CHUNK ALL -SOURCE {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def validate_nochunks(self): + """ + This function check the chnunks + """ + self.ocommon.log_info_message("Inside validate_nochunks()",self.file_name) + status=False + reg_exp= self.move_nochunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + shard_num = self.count_online_shards() + online_shard = self.check_online_shard(shard_name) + if shard_num > 1 and online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config chunks -shard {0} + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + matched_output=re.findall("(?:Chunks\n)(?:.+\n)+",output) + if self.ocommon.check_substr_match(matched_output[0].lower(),shard_name.lower()): + self.ocommon.prog_exit("127") + + def move_chunks_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside move_chnuks_regex()",self.file_name) + return re.compile('MOVE_CHUNKS') + + def move_nochunks_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside move_nochunks_regex()",self.file_name) + return re.compile('VALIDATE_NOCHUNKS') + + def check_shard_chunks(self): + """ + This function check the shard chunks + """ + self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) + status=False + reg_exp= self.check_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config chunks -shard {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + + def check_chunks_regex(self): + """ + This function return the rgex to search the chunks + """ + self.ocommon.log_info_message("Inside check_chunks_regex()",self.file_name) + return re.compile('CHECK_CHUNKS') + + def cancel_move_chunks(self): + """ + This function cancel the shard Chunks + """ + self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) + status=False + reg_exp= self.cancel_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 1: + self.ocommon.log_info_message("Shard is not online. Performing chunk cancellation in GSM to set the shard chunk status.",self.file_name) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + ALTER MOVE -cancel -SHARD {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + else: + self.ocommon.log_info_message("Shard " + shard_name + " is online. Unable to perform chunk cancellation.",self.file_name) + + def cancel_chunks_regex(self): + """ + This function return the cancel chunk movement + """ + self.ocommon.log_info_message("Inside cancel_chunks_regex()",self.file_name) + return re.compile('CANCEL_CHUNKS') + + def verify_online_shard(self): + """ + This function verify online shard + """ + self.ocommon.log_info_message("Inside verify_online_shard()",self.file_name) + status=False + reg_exp= self.online_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 0: + msg='''Shard {0} is online.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} is not online.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + + def online_shard_regex(self): + """ + This function return the rgex to search the ONLINE Shards + """ + self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) + return re.compile('CHECK_ONLINE_SHARD') + + def check_online_shard(self,shard_name): + """ + This function check the online shard + """ + self.ocommon.log_info_message("Inside check_online_shard()",self.file_name) + name_flag = False + availability_flag = False + state_flag = False + status_flag = False + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config shard -shard {0}; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + lines = output.split("\n") + for line in lines: + list1 = line.split(":") + if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): + name_flag = True + if list1[0].strip().lower() == 'Availability'.lower() and list1[1].strip().lower() == 'ONLINE'.lower(): + availability_flag = True + if list1[0].strip().lower() == 'STATUS'.lower() and list1[1].strip().lower() == 'OK'.lower(): + status_flag = True + if list1[0].strip().lower() == 'STATE'.lower() and list1[1].strip().lower() == 'DEPLOYED'.lower(): + state_flag = True + + del list1[:] + + if name_flag and availability_flag and state_flag and status_flag: + return 0 + else: + return 1 + + def verify_gsm_shard(self): + """ + This function verify GSM shard + """ + self.ocommon.log_info_message("Inside verify_gsm_shard()",self.file_name) + status=False + reg_exp= self.check_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + gsm_shard = self.check_gsm_shard(shard_name) + if gsm_shard == 0: + msg='''Shard {0} is present in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} is not present in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + def check_shard_regex(self): + """ + This function return the rgex to search the Shards in GSM + """ + self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) + return re.compile('CHECK_GSM_SHARD') + + def check_gsm_shard(self,shard_name): + """ + This function check the shard in gsm + """ + self.ocommon.log_info_message("Inside check_gsm_shard()",self.file_name) + name_flag = False + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config shard -shard {0}; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + lines = output.split("\n") + for line in lines: + list1 = line.split(":") + if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): + name_flag = True + + del list1[:] + + if name_flag: + return 0 + else: + return 1 + + def count_online_shards(self): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside count_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + config shard; + exit; + '''.format(cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + online_shard = 0 + lines = output.split("\n") + for line in lines: + if re.search('ok', line, re.IGNORECASE): + if re.search('deployed', line, re.IGNORECASE): + if re.search('online', line, re.IGNORECASE): + online_shard = online_shard + 1 + + return online_shard + + def get_online_shards(self): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + config shard; + exit; + '''.format(cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + shards=[] + online_shard = 0 + for line in output.split("\n"): + cols=line.split() + print(cols) + if len(cols) >= 5: + if cols[5].lower() == "online" and cols[2].lower() == "ok": + shards.append(cols[0]) + + return shards + + def get_rus(self,shardname_to_delete): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd=None + if shardname_to_delete is not None: + cmd='''status ru -leaders -shard {0}'''.format(shardname_to_delete) + else: + cmd='''status ru''' + + gsmcmd=''' + connect {0}/{1}; + {2}; + exit; + '''.format(cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + return output.split('\n') + + def move_shard_rus(self,sshard,tshard,runum): + """ + This function move the shard rus + """ + self.ocommon.log_info_message("Inside move_shard_rus()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd1="" + cmd2="" + shardname=sshard + if tshard is not None and runum is not None: + cmd1='''switchover ru -RU {0} -shard {1}'''.format(runum,tshard) + else: + cmd1='''MOVE RU -RU ALL -SOURCE {0}'''.format(shardname) + + gsmcmd=''' + connect {1}/{2}; + configure -verbose off -save_config; + {3}; + status RU -shard {0}; + exit; + '''.format(shardname,cadmin,cpasswd,cmd1,cmd2) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def count_shard_rus(self,shardname): + """ + This function return the returns the count of online shard chunks + """ + self.ocommon.log_info_message("Inside count_shard_chunks()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + status ru -shard {2}; + exit; + '''.format(cadmin,cpasswd,shardname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ru_count = 0 + lines = output.split("\n") + for line in lines: + if re.search(shardname, line, re.IGNORECASE): + ru_count = ru_count + 1 + + return ru_count + + def count_leader_shards(self,shardName): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside count_leader_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + status ru -shard {2} -leaders; + exit; + '''.format(cadmin,cpasswd,shardName) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + leader_shard = 0 + lines = output.split("\n") + for line in lines: + if re.search('ok', line, re.IGNORECASE): + if re.search('Leader', line, re.IGNORECASE): + leader_shard = leader_shard + 1 + + return leader_shard + + def validate_gsm_shard(self): + """ + This function validate the shard in the GSM + """ + self.ocommon.log_info_message("Inside validate_gsm_shard()",self.file_name) + status=False + reg_exp= self.validate_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + status = self.check_shard_status(shard_name) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} info does not exist in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + def process_shard_vars(self,key): + """ + This function process sgard vars based on key and return values to configure the GSM + """ + shard_db=None + shard_pdb=None + shard_port=None + shard_group=None + shard_host=None + shard_region=None + shard_space=None + shard_deploy_as=None + + self.ocommon.log_info_message("Inside process_shard_vars()",self.file_name) + # self.ocommon.log_info_message(key,self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_str=cvar_str.replace('"', '') + # self.ocommon.log_info_message(cvar_str,self.file_name) + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + # self.ocommon.log_info_message("key : " + ckey,self.file_name) + # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) + if ckey == 'shard_db': + shard_db = cvar_dict[ckey] + if ckey == 'shard_pdb': + shard_pdb = cvar_dict[ckey] + if ckey == 'shard_port': + shard_port = cvar_dict[ckey] + if ckey == 'shard_group': + shard_group = cvar_dict[ckey] + if ckey == 'shard_host': + shard_host = cvar_dict[ckey] + if ckey == 'shard_region': + #shard_region = self.validate_shard_param("region",cvar_dict[ckey]) + shard_region=cvar_dict[ckey] + if ckey == 'deploy_as': + shard_deploy_as=cvar_dict[ckey] + if ckey == 'shard_space': + #shard_space = self.validate_shard_param("shardspace",cvar_dict[ckey]) + shard_space=cvar_dict[ckey] + # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) + ## Set the values if not set in above block + if not shard_port: + shard_port=1521 + + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + shard_group="nogrp" + if not shard_deploy_as: + self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS","primary",self.ora_env_dict) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS",shard_deploy_as,self.ora_env_dict) + + ### Check values must be set + if shard_host and shard_db and shard_pdb and shard_port and shard_group: + return shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space + else: + msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) + msg2='''shard_port={0},shard_host={1}'''.format((shard_port or "Missing Value"),(shard_host or "Missing Value")) + msg3='''shard_group={0}'''.format((shard_group or "Missing Value")) + msg='''Shard DB params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def validate_shard_param(self,param_type,value): + """ + This function validaet the shard param such as region and shardspace + """ + status=False + reg_exp= self.catalog_regex() + stype=None + sspace=None + catalog_region=None + self.ocommon.log_info_message("Processing GSM params to verify the region and shardspace",self.file_name) + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + + if param_type == 'region': + if stype: + status=self.ocommon.find_str_in_string(catalog_region,'comma',value) + if status: + + return value + else: + return "" + + if param_type == 'shardspace': + if sspace: + status=self.ocommon.find_str_in_string(sspace,'comma',value) + if status: + return value + else: + return "" + + return False + + def process_chunks_vars(self,key): + """ + This function process the chunks vars + """ + shard_db=None + shard_pdb=None + self.ocommon.log_info_message("Inside process_chunks_vars()",self.file_name) + # self.ocommon.log_info_message(key,self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_str=cvar_str.replace('"', '') + # self.ocommon.log_info_message(cvar_str,self.file_name) + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + # self.ocommon.log_info_message("key : " + ckey,self.file_name) + # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) + if ckey == 'shard_db': + shard_db = cvar_dict[ckey] + if ckey == 'shard_pdb': + shard_pdb = cvar_dict[ckey] + # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) + ## Set the values if not set in above block + + ### Check values must be set + if shard_pdb and shard_db: + return shard_db,shard_pdb + else: + msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) + self.ocommon.log_info_message(msg1,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_shard_status(self,shard_name): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_shard_status()",self.file_name) + #gsmcmd=self.get_gsm_config_cmd(dname) + gsmcmd=''' + config; + exit; + ''' + counter=1 + end_counter=3 + status=False + while counter < end_counter: + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + error_check=re.findall("(?:GSM-45034\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(error_check[0],"GSM-45034"): + count = counter + 1 + self.ocommon.log_info_message("Issue in catalog connection, retrying to connect to catalog in 30 seconds!",self.file_name) + time.sleep(20) + status=False + continue + except: + status=False + matched_output=re.findall("(?:Databases\n)(?:.+\n)+",output) + if shard_name: + try: + if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): + status=True + break + else: + status=False + except: + status=False + else: + reg_exp= self.shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_region,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + try: + if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): + status=True + else: + status=False + except: + status=False + if status: + break; + counter = counter + 1 + + return(self.ocommon.check_status_value(status)) + + def shard_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside shard_regex()",self.file_name) + return re.compile('SHARD[0-9]+_PARAMS') + + def add_shard_regex(self): + """ + This function return the rgex to search the ADD_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside add_shard_regex()",self.file_name) + return re.compile('ADD_SHARD') + + def remove_shard_regex(self): + """ + This function return the rgex to search the REMOVE_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) + return re.compile('REMOVE_SHARD') + + def validate_shard_regex(self): + """ + This function return the rgex to search the VALIDATE_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) + return re.compile('VALIDATE_SHARD') + + def configure_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup,sregion,sspace): + """ + This function configure the shard db. + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + #dtrname,dtrport,dtregion=self.process_director_vars() + #group_region=self.get_shardg_region_name(sgroup) + #dtrname=self.get_director_name(group_region) + shard_name='''{0}_{1}'''.format(scdb,spdb) + shard_region=None + shard_space=None + shard_group=None + deploy_as=None + + if sregion: + regionFlag=self.check_gsm_region(sregion) + if regionFlag != 'completed': + self.configure_gsm_region(sregion) + shard_region=" -region {0}".format(sregion) + else: + shard_region="" + if sspace: + shard_space=" -shardspace {0}".format(sspace) + else: + shard_space="" + + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + sspaceFlag=self.check_gsm_shardspace(sspace) + if sspaceFlag != 'completed': + self.configure_gsm_sspace(sspace,None,None,None,None,'add') + shard_group="" + deploy_as,deploy_type=self.get_shard_deploy() + else: + shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) + shard_region="" + else: + shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) + shard_region="" + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + add cdb -connect {3}:{4}/{5} -pwd {2}; + add shard -cdb {5} -connect "(DESCRIPTION = (ADDRESS = (PROTOCOL = tcp)(HOST = {3})(PORT = {4})) (CONNECT_DATA = (SERVICE_NAME = {6}) (SERVER = DEDICATED)))" {7} -pwd {2} {9} {10} {11}; + config vncr; + exit; + '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,shard_group,shard_name,shard_region,shard_space,deploy_as) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def get_shard_deploy(self): + """ + get the shard deploy + """ + deploy_as=None + deploy_type=None + if self.ocommon.check_key("SHARD_DEPLOY_AS",self.ora_env_dict): + deploy_as="-deploy_as {0}".format(self.ora_env_dict["SHARD_DEPLOY_AS"]) + deploy_type=self.ora_env_dict["SHARD_DEPLOY_AS"] + else: + deploy_as="-deploy_as primary" + deploy_type='primary' + + return deploy_as,deploy_type + + def get_shardg_cmd(self,sgroup,sregion): + """ + Getting shard group cmd + """ + sgFlag=self.check_shardg_status(sgroup,None) + deploy_as,deploy_type=self.get_shard_deploy() + if sgFlag != 'completed': + self.configure_gsm_shardg(sgroup,deploy_type,sregion,'add') + else: + self.ocommon.log_info_message("Shardgroup exist " + sgroup, self.file_name) + + deploy_as="" + cmd=''' -shardgroup {0}'''.format(sgroup) + return cmd,deploy_as + + def delete_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup): + """ + This function delete the shard db. + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + shard_name='''{0}_{1}'''.format(scdb,spdb) + #group_region=self.get_shardg_region_name(sgroup) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + remove shard -shard {8}; + remove cdb -cdb {5}; + remove invitednode {3}; + config vncr; + exit; + '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,sgroup,shard_name) + + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_hostid_null(self): + """ + This function set the hostid to Null + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_pdb,admuser) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting host Id null in catalog as auto vncr is disabled''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set echo on + set termout on + set time on + update gsmadmin_internal.database set hostid=NULL; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + self.ocommon.unset_mask_str() + + def invited_node_op(self): + """ + This function perform the invitedaddition and deletion + """ + self.ocommon.log_info_message("Inside invited_node_op()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + shard_host=self.ora_env_dict["INVITED_NODE_OP"] + gsmcmd=''' + connect {1}/{2}; + remove invitednode {3}; + add invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,shard_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + def add_invited_node(self,op_str): + """ + This function add the invited in the GSM configuration + """ + self.ocommon.log_info_message("Inside add_invited_node()",self.file_name) + if op_str == "SHARD": + reg_exp = self.shard_regex() + else: + reg_exp = self.add_shard_regex() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + #group_region=self.get_shardg_region_name(shard_group) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + add invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,shard_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + def remove_invited_node(self,op_str): + """ + This function remove the invited in the GSM configuration + """ + self.ocommon.log_info_message("Inside remove_invited_node()",self.file_name) + if op_str == "SHARD": + reg_exp = self.shard_regex() + else: + reg_exp = self.add_shard_regex() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + temp_host= shard_host.split('.',1)[0] + #group_region=self.get_shardg_region_name(shard_group) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + remove invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,temp_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + else: + self.ocommon.log_info_message("KUBE_SVC is not set. No need to remove invited node!",self.file_name) + + + def deploy_shard(self): + """ + This function deploy shard + """ + self.ocommon.log_info_message("Inside deploy_shard()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + shrdg_sspace=None + #dtrname,dtrport,dtregion=self.process_director_vars() + #if op_str == "SHARD": + # reg_exp = self.shard_regex() + #else: + # reg_exp = self.add_shard_regex() + + #for key in self.ora_env_dict.keys(): + # if(reg_exp.match(key)): + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + shardg_shardspace="config shardspace" + else: + shardg_shardspace="config shardgroup" + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + config vncr; + deploy; + config shard; + exit; + '''.format("test",cadmin,cpasswd,shardg_shardspace) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def check_setup_status(self,host,ccdb,svc,port): + """ + This function check the shard status. + """ + systemStr='''{0}/bin/sqlplus "system/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,ccdb) + + fname='''/tmp/{0}'''.format("shard_setup.txt") + self.ocommon.remove_file(fname) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool {0} + select * from shardsetup WHERE ROWNUM = 1; + spool off + exit; + '''.format(fname) + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + if os.path.isfile(fname): + fdata=self.ocommon.read_file(fname) + else: + fdata='nosetup' + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + status = self.catalog_pdb_setup_check(host,ccdb,svc,port) + if status == 'completed': + return 'completed' + else: + return 'notcompleted' + else: + return 'notcompleted' + + + def catalog_pdb_setup_check(self,host,ccdb,svc,port): + """ + This function check the shard status. + """ + systemStr='''{0}/bin/sqlplus "pdbadmin/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,svc) + + fname='''/tmp/{0}'''.format("pdb_setup_check.txt") + self.ocommon.remove_file(fname) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Checking setup status in PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool {0} + select count(*) from dual; + spool off + exit; + '''.format(fname) + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + if os.path.isfile(fname): + fdata=self.ocommon.read_file(fname) + else: + fdata='nosetup' + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + if re.search('1',fdata): + return 'completed' + else: + return 'notcompleted' + + ############################# Setup GSM Service ############################################### + def setup_gsm_service(self): + """ + This function setup the shard service. + """ + self.ocommon.log_info_message("Inside setup_gsm_service()",self.file_name) + status=False + service_value="service_name=oltp_rw_svc;service_role=primary" + # self.ora_env_dict=self.ocommon.add_key("SERVICE1_PARAMS",service_value,self.ora_env_dict) + reg_exp= self.service_regex() + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_service_status=None + service_name,service_role=self.process_service_vars(key) + shard_service_status=self.check_service_status(service_name) + if shard_service_status != 'completed': + self.configure_gsm_service(service_name,service_role) + status = self.check_service_status(None) + if status == 'completed': + break + else: + msg='''GSM service setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + time.sleep(60) + counter=counter+1 + + status = self.check_service_status(None) + if status == 'completed': + msg='''Shard service setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def process_service_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + service_name=None + service_role=None + + self.ocommon.log_info_message("Inside process_service_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'service_name': + service_name = cvar_dict[ckey] + if ckey == 'service_role': + service_role = cvar_dict[ckey] + + ### Check values must be set + if service_name and service_role: + return service_name,service_role + else: + msg1='''service_name={0},service_role={1}'''.format((service_name or "Missing Value"),(service_role or "Missing Value")) + msg='''Shard service params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_service_status(self,service_name): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_service_status()",self.file_name) + #dtrname,dtrport,dtregion=self.process_director_vars() + gsmcmd=''' + config; + exit; + '''.format("test") + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Services\n)(?:.+\n)+",output) + status=False + if service_name: + try: + if self.ocommon.check_substr_match(matched_output[0],service_name): + status=True + else: + status=False + except: + status=False + else: + reg_exp= self.service_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + service_name,service_role=self.process_service_vars(key) + # match=re.search("(?i)(?m)"+service_name,matched_output) + try: + if self.ocommon.check_substr_match(matched_output[0],service_name): + status=True + else: + status=False + except: + status=False + + return(self.ocommon.check_status_value(status)) + + def service_regex(self): + """ + This function return the rgex to search the SERVICE[0-9]_PARAMS + """ + self.ocommon.log_info_message("Inside service_regex()",self.file_name) + return re.compile('SERVICE[0-9]+_PARAMS') + + def configure_gsm_service(self,service_name,service_role): + """ + This function configure the service creation. + """ + self.ocommon.log_info_message("Inside configure_gsm_service()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + add service -service {3} -role {4}; + start service -service {3}; + exit; + '''.format("test",cadmin,cpasswd,service_name,service_role) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ############################## GSM backup fIle function Begins Here ############################# + def gsm_backup_file(self): + """ + This function check the gsm setup status + """ + self.ocommon.log_info_message("Inside gsm_backup_file()",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) + + if os.path.isdir(gsmdata_loc): + msg='''Directory {0} exit'''.format(gsmdata_loc) + self.ocommon.log_info_message(msg,self.file_name) + + cmd='''cp -r -v {0}/* {1}/'''.format(gsmfile_loc,gsmdata_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############### Deploy Sample Function Begins Here ########################## + def setup_sample_schema(self): + """ + This function deploy the sample app + """ + s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?" + passlen = 8 + passwd = "".join(random.sample(s,passlen )) + self.ocommon.log_info_message("Inside deploy_sample_schema()",self.file_name) + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_db) + if self.ocommon.check_key("SAMPLE_SCHEMA",self.ora_env_dict): + if self.ora_env_dict["SAMPLE_SCHEMA"] == 'DEPLOY': + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Deploying sample schema''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set echo on + set termout on + set time on + spool /tmp/create_app_schema.lst + REM + REM Connect to the Shard Catalog and Create Schema + REM + alter session enable shard ddl; + alter session set container={2}; + alter session enable shard ddl; + create user app_schema identified by {3}; + grant connect, resource, alter session to app_schema; + grant execute on dbms_crypto to app_schema; + grant create table, create procedure, create tablespace, create materialized view to app_schema; + grant unlimited tablespace to app_schema; + grant select_catalog_role to app_schema; + grant all privileges to app_schema; + grant gsmadmin_role to app_schema; + grant dba to app_schema; + CREATE TABLESPACE SET tbsset1 IN SHARDSPACE shd1; + CREATE TABLESPACE SET tbsset2 IN SHARDSPACE shd2; + connect app_schema/{3}@{0}:{1}/{2} + alter session enable shard ddl; + + /* Customer shard table */ + + CREATE SHARDED TABLE customer + ( cust_id NUMBER NOT NULL, + cust_passwd VARCHAR2(20) NOT NULL, + cust_name VARCHAR2(60) NOT NULL, + cust_type VARCHAR2(10) NOT NULL, + cust_email VARCHAR2(100) NOT NULL) + partitionset by list (cust_type) + partition by consistent hash (cust_id) partitions auto + (partitionset individual values ('individual') tablespace set tbsset1, + partitionset business values ('business') tablespace set tbsset2 + ); + /* Invoice shard table */ + + CREATE SHARDED TABLE invoice + ( invoice_id NUMBER NOT NULL, + cust_id NUMBER NOT NULL, + cust_type VARCHAR2(10) NOT NULL, + vendor_name VARCHAR2(60) NOT NULL, + balance FLOAT(10) NOT NULL, + total FLOAT(10) NOT NULL, + status VARCHAR2(20), + CONSTRAINT InvoicePK PRIMARY KEY (cust_id, invoice_id)) + PARENT customer + partitionset by list (cust_type) + partition by consistent hash (cust_id) partitions auto + (partitionset individual values ('individual') tablespace set tbsset1, + partitionset business values ('business') tablespace set tbsset2 + ); + /* Data */ + insert into customer values (999, 'pass', 'Customer 999', 'individual', 'customer999@gmail.com'); + insert into customer values (250251, 'pass', 'Customer 250251', 'individual', 'customer250251@yahoo.com'); + insert into customer values (350351, 'pass', 'Customer 350351', 'individual', 'customer350351@gmail.com'); + insert into customer values (550551, 'pass', 'Customer 550551', 'business', 'customer550551@hotmail.com'); + insert into customer values (650651, 'pass', 'Customer 650651', 'business', 'customer650651@live.com'); + insert into invoice values (1001, 999, 'individual', 'VendorA', 10000, 20000, 'Due'); + insert into invoice values (1002, 999, 'individual', 'VendorB', 10000, 20000, 'Due'); + insert into invoice values (1001, 250251, 'individual', 'VendorA', 10000, 20000, 'Due'); + insert into invoice values (1002, 250251, 'individual', 'VendorB', 0, 10000, 'Paid'); + insert into invoice values (1003, 250251, 'individual', 'VendorC', 14000, 15000, 'Due'); + insert into invoice values (1001, 350351, 'individual', 'VendorD', 10000, 20000, 'Due'); + insert into invoice values (1002, 350351, 'individual', 'VendorE', 0, 10000, 'Paid'); + insert into invoice values (1003, 350351, 'individual', 'VendorF', 14000, 15000, 'Due'); + insert into invoice values (1004, 350351, 'individual', 'VendorG', 12000, 15000, 'Due'); + insert into invoice values (1001, 550551, 'business', 'VendorH', 10000, 20000, 'Due'); + insert into invoice values (1002, 550551, 'business', 'VendorI', 0, 10000, 'Paid'); + insert into invoice values (1003, 550551, 'business', 'VendorJ', 14000, 15000, 'Due'); + insert into invoice values (1004, 550551, 'business', 'VendorK', 10000, 20000, 'Due'); + insert into invoice values (1005, 550551, 'business', 'VendorL', 10000, 20000, 'Due'); + insert into invoice values (1006, 550551, 'business', 'VendorM', 0, 10000, 'Paid'); + insert into invoice values (1007, 550551, 'business', 'VendorN', 14000, 15000, 'Due'); + insert into invoice values (1008, 550551, 'business', 'VendorO', 10000, 20000, 'Due'); + insert into invoice values (1001, 650651, 'business', 'VendorT', 10000, 20000, 'Due'); + insert into invoice values (1002, 650651, 'business', 'VendorU', 0, 10000, 'Paid'); + insert into invoice values (1003, 650651, 'business', 'VendorV', 14000, 15000, 'Due'); + insert into invoice values (1004, 650651, 'business', 'VendorW', 10000, 20000, 'Due'); + insert into invoice values (1005, 650651, 'business', 'VendorX', 0, 20000, 'Paid'); + insert into invoice values (1006, 650651, 'business', 'VendorY', 0, 30000, 'Paid'); + insert into invoice values (1007, 650651, 'business', 'VendorZ', 0, 10000, 'Paid'); + commit; + select table_name from user_tables; + spool off + '''.format(catalog_host,catalog_port,catalog_pdb,passwd) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + show ddl; + exit; + '''.format("test",cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oralogger.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oralogger.py new file mode 100755 index 0000000..9a51b54 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oralogger.py @@ -0,0 +1,181 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file provides the functionality to log the event in console and file +""" + +import logging +import os + +class LoggingType(object): + CONSOLE = 1 + FILE = 2 + STDOUT = 3 + +class OraLogger(object): + """ + This is a class constructor which sets parameter for logger. + + Attributes: + filename_ (string): Filename which we need to set to store logs in a file. + """ + def __init__(self, filename_): + """ + This is a class constructor which sets parameter for logger. + + Attributes: + filename_ (string): Filename which we need to set to store logs in a file. + """ + self.filename_ = filename_ + # Set to default values can be changed later from other classes objects + self.console_ = LoggingType.CONSOLE + self.file_ = LoggingType.FILE + self.stdout_ = LoggingType.STDOUT + self.msg_ = None + self.functname_ = None + self.lineno_ = None + self.logtype_ = "INFO" + self.fmtstr_ = "%(asctime)s: %(levelname)s: %(message)s" + self.datestr_ = "%m/%d/%Y %I:%M:%S %p" + self.root = logging.getLogger() + self.root.setLevel(logging.DEBUG) + self.formatter = logging.Formatter('%(asctime)s %(levelname)8s:%(message)s', "%m/%d/%Y %I:%M:%S %p") + self.stdoutfile_ = "/proc/1/fd/1" + # self.stdoutfile_ = "/tmp/test.log" + + def getStdOutValue(self): + return self.stdout_ + +class Handler(object): + """ + This is a class which sets the handler for next logger. + """ + def __init__(self): + """ + This is a handler class constructor and nexthandler is set to None. + """ + self.nextHandler = None + + def handle(self, request): + ''' + This is a function which set the next handler. + + Attributes: + request (object): Object of the class oralogger. + ''' + self.nextHandler.handle(request) + + def print_message(self,request,lhandler): + """ + This function set the log type to INFO, WARN, DEBUG and CRITICAL. + + Attribute: + request (object): Object of the class oralogger. + lhandler: This parameter accept the loghandler. + """ + if request.logtype_ == "WARN": + request.root.warning(request.msg_) + elif request.logtype_ == "DEBUG": + request.root.debug(request.msg_) + elif request.logtype_ == "CRITICAL": + request.root.critical(request.msg_) + elif request.logtype_ == "ERROR": + request.root.error(request.msg_) + else: + request.root.info(request.msg_) + + request.root.removeHandler(lhandler) + +class FHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribut: + request: Object of OraLogger + """ + if request.file_ == LoggingType.FILE: + fh = logging.FileHandler(request.filename_) + request.root.addHandler(fh) + fh.setFormatter(request.formatter) + self.print_message(request,fh) + super(FHandler, self).handle(request) + else: + super(FHandler, self).handle(request) + + def print_message(self,request,fh): + """ + This function log the message to console/file/stdout. + """ + super(FHandler, self).print_message(request,fh) + +class CHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribute: + request: Object of OraLogger + """ + if request.console_ == LoggingType.CONSOLE: + # ch = logging.StreamHandler() + ch = logging.FileHandler("/tmp/test.log") + request.root.addHandler(ch) + ch.setFormatter(request.formatter) + self.print_message(request,ch) + super(CHandler, self).handle(request) + else: + super(CHandler, self).handle(request) + + def print_message(self,request,ch): + """ + This function log the message to console/file/stdout. + """ + super(CHandler, self).print_message(request,ch) + + +class StdHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribute: + request: Object of OraLogger + """ + request.stdout_ = request.getStdOutValue() + if request.stdout_ == LoggingType.STDOUT: + st = logging.FileHandler(request.stdoutfile_,mode="w") + request.root.addHandler(st) + st.setFormatter(request.formatter) + self.print_message(request,st) + super(StdHandler, self).handle(request) + else: + super(StdHandler, self).handle(request) + + def print_message(self,request,st): + """ + This function log the message to console/file/stdout. + """ + super(StdHandler, self).print_message(request,st) + +class PassHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self, request): + pass diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oramachine.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oramachine.py new file mode 100755 index 0000000..2d1431a --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/oramachine.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +import os +import sys + +class OraMachine: + """ + This calss setup the compute before starting the installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraMachine class to setup the compute + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + + def setup(self): + """ + This function setup the compute before starting the installation + """ + msg="Machine setup completed sucessfully!" + self.ocommon.log_info_message(msg,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orapcatalog.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orapcatalog.py new file mode 100755 index 0000000..6638860 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orapcatalog.py @@ -0,0 +1,748 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +class OraPCatalog: + """ + This calss setup the Catalog after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraCatalog class to setup the catalog on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def setup(self): + """ + This function setup the catalog on Primary DB. + """ + if self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) + self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) + if os.path.exists(create_db_file_lck): + self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) + sys.exit(127) + elif os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) + status = self.catalog_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) + sys.exit(0) + else: + status = self.catalog_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): + status = self.catalog_setup_check() + if not status: + self.ocommon.log_info_message("Catalog readyness check completed sucessfully!",self.file_name) + self.ocommon.prog_exit("127") + elif self.ocommon.check_key("RESET_PASSWORD",self.ora_env_dict): + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + if os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Catalog database up and running. Resetting password...",self.file_name) + else: + self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to reset password",self.file_name) + self.ocommon.prog_exit("127") + elif self.ocommon.check_key("EXPORT_TDE_KEY",self.ora_env_dict): + exist_db_file_lck=self.ocommon.get_db_lock_location()+ self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + if os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Catalog database up and running.",self.file_name) + self.ocommon.export_tde_key(self.ora_env_dict["EXPORT_TDE_KEY"]) + else: + self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to export the tde key",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_machine() + self.db_checks() + self.reset_catalog_setup() + status = self.catalog_setup_check() + if status: + self.ocommon.log_info_message("catalog Setup is already completed on this database",self.file_name) + else: + self.reset_passwd() + self.setup_cdb_catalog() + self.set_spfile_nonm_params() + self.ocommon.set_events("spfile") + self.set_dbparams_version() + self.restart_db() + self.alter_db() + self.setup_pdb_catalog() + self.set_primary_listener() + self.restart_listener() + self.register_services() + self.list_services() + self.backup_files() + self.update_catalog_setup() + self.gsm_completion_message() + self.run_custom_scripts() + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + + ########### SETUP_MACHINE ENDS here #################### + + ########### DB_CHECKS Related Functions Begin Here #################### + ## Function to perfom DB checks ###### + def db_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.set_user() + self.sid_check() + self.dbuinque_name_check() + self.hostname_check() + self.dbport_check() + self.dbr_dest_checks() + self.dpump_dir_checks() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit() + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def passwd_check(self): + """ + Function to set the password + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def set_user(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def sid_check(self): + """ + This funnction heck and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): + msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="ORACLE_SID is not set, existing!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def dbuinque_name_check(self): + """ + This funnction check and set the db unique name for standby + """ + if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" + self.ocommon.log_info_message(msg,self.file_name) + dbsid=self.ora_env_dict["ORACLE_SID"] + self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) + + + def hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + # hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def dbport_check(self): + """ + This funnction checks and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("DB_PORT",self.ora_env_dict): + msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) + msg="DB_PORT is not set, setting default to 1521" + self.ocommon.log_info_message(msg,self.file_name) + + def dbr_dest_checks(self): + """ + This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. + """ + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) + + # Checking the DB_RECOVERY_FILE_DEST_SIZE + + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the DB_CREATE_FILE_DEST + + if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): + msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) + + + def dpump_dir_checks(self): + """ + This funnction checks and set the DATA_PUMP dir and location. + """ + if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): + msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) + self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) + msg='''DATA_PUMP_DIR set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) + + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## RESET_PASSWORD function Begin here ############################# + ## Function to perform password reset + def reset_passwd(self): + """ + This function reset the password. + """ + self.ocommon.reset_passwd() + + ########## RESET_PASSWORD function ENDS here ############################# + + ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### + + def reset_catalog_setup(self): + """ + This function drop teh catalog setup table and reste the env to default values. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Inside reset_catalog_setup",self.file_name) + catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + if not os.path.isfile(catalog_reset_file): + msg='''Dropping catalogsetup table from CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + drop table system.shardsetup; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + else: + msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(catalog_reset_file) + self.ocommon.log_info_message(msg,self.file_name) + + + def catalog_setup_check(self): + """ + This function check the catalog status. + """ + #systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool /tmp/catalog_setup.txt + select * from system.shardsetup WHERE ROWNUM = 1; + spool off + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + fname='''/tmp/{0}'''.format("catalog_setup.txt") + fdata=self.ocommon.read_file(fname) + ### Unsetting the encrypt value to None + # self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + return True + else: + return False + + def setup_cdb_catalog(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + # Assigning variable + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] + dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] + host_name=self.ora_env_dict["ORACLE_HOSTNAME"] + dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] + db_port=self.ora_env_dict["DB_PORT"] + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting up catalog CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set db_create_file_dest=\"{0}\" scope=both; + alter system set db_recovery_file_dest_size={1} scope=both; + alter system set db_recovery_file_dest=\"{2}\" scope=both; + alter user gsmcatuser account unlock; + alter user gsmcatuser identified by HIDDEN_STRING; + alter system set local_listener='{4}:{5}' scope=both; + '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_spfile_nonm_params(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set open_links_per_instance=16 scope=spfile; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set standby_file_management='AUTO' scope=spfile; + alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; + alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + + def set_dbparams_version(self): + """ + This function setup the shard parameter based on db version. + """ + ohome1=self.ora_env_dict["ORACLE_HOME"] + version=self.ocommon.get_oraversion(ohome1).strip() + self.ocommon.log_info_message(version,self.file_name) + if int(version) > 21: + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set wallet_root=\"{1}/oradata/{2}/{3}\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_db(self): + """ + restarting the db + """ + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + #self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) + #sqlcmd=''' + # alter database archivelog; + # alter database open; + #''' + #output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + #self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + #self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + def setup_pdb_catalog(self): + """ + This function setup the catalog. + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + # Assigning variable + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter pluggable database {0} close immediate; + alter pluggable database {0} open services=All; + ALTER PLUGGABLE DATABASE {0} SAVE STATE; + alter system register; + alter session set container={0}; + create user {1} identified by HIDDEN_STRING; + alter user {1} account unlock; + grant connect, create session, gsmadmin_role to {1}; + grant inherit privileges on user SYS to GSMADMIN_INTERNAL; + execute dbms_xdb.sethttpport(8080); + exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('HIDDEN_STRING'); + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def update_catalog_setup(self): + """ + This function update the catalog setup on this DB. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") + # systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Updating shardsetup table''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + create table system.shardsetup (status varchar2(10)); + insert into system.shardsetup values('completed'); + commit; + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Reset File + catalog_reset_dir='''{0}/.catalog'''.format(self.ora_env_dict["HOME"]) + catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) + + self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) + if not os.path.isdir(catalog_reset_dir): + self.ocommon.create_dir(catalog_reset_dir,True,None,None) + + if not os.path.isfile(catalog_reset_file): + self.ocommon.create_file(catalog_reset_file,True,None,None) + +# self.ocommon.unset_mask_str() + + ########## SETUP_CDB_catalog FUNCTION ENDS HERE ############################### + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + def set_primary_listener(self): + """ + Function to set the primary listener + """ + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + + def set_db_listener(self,gdbname,sid): + """ + Funtion to reset the listener + """ + self.ocommon.log_info_message("Inside reset_listener()",self.file_name) + start = 'SID_LIST_LISTENER' + end = '^\)$' + oracle_home=self.ora_env_dict["ORACLE_HOME"] + lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) + buffer = "SID_LIST_LISTENER=" + '\n' + start_flag = False + try: + with open(lisora) as f: + for line1 in f: + if start_flag == False: + if (re.match(start, line1.strip())): + start_flag = True + elif (re.match(end, line1.strip())): + line2 = f.next() + if (re.match(end, line2.strip())): + break + else: + buffer += line1 + buffer += line2 + else: + if start_flag == True: + buffer += line1 + except: + pass + + if start_flag == True: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + else: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + + wr = open(lisora, 'w') + wr.write(listener) + + def restart_listener(self): + """ + restart listener + """ + self.ocommon.log_info_message("Stopping Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl stop'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + self.ocommon.log_info_message("Starting Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl start'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + + def register_services(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system register; + alter session set container={0}; + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def list_services(self): + """ + restart listener + """ + self.ocommon.log_info_message("Listing Services",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl services'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + + def backup_files(self): + """ + This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig + """ + self.ocommon.log_info_message("Inside backup_files()",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + dbsid=self.ora_env_dict["ORACLE_SID"] + + version=self.ocommon.get_oraversion(ohome).strip() + wallet_backup_cmd='''ls -ltr /bin''' + self.ocommon.log_info_message("Check Version " + version,self.file_name) + if int(version) >= 21: + obase1=self.ora_env_dict["ORACLE_BASE"] + wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) + cmd_names=''' + mkdir -p {0}/oradata/{1}/{2} + cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ + cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ + cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ + touch {0}/oradata/{1}/{2}/status_completed + '''.format(obase,"dbconfig",dbuname,ohome) + cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] + for cmd in cmd_list: + msg='''Executing cmd {0}'''.format(cmd) + self.ocommon.log_info_message(msg,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Catalog Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orapshard.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orapshard.py new file mode 100755 index 0000000..d1b1273 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orapshard.py @@ -0,0 +1,795 @@ +#!/usr/bin/python + +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +import traceback + +class OraPShard: + """ + This calss setup the primary shard after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraPShard class to setup the shard on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + try: + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + except BaseException as ex: + ex_type, ex_value, ex_traceback = sys.exc_info() + trace_back = traceback.extract_tb(ex_traceback) + stack_trace = list() + for trace in trace_back: + stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) + self.ocommon.log_info_message(ex_type.__name__,self.file_name) + self.ocommon.log_info_message(ex_value,self.file_name) + self.ocommon.log_info_message(stack_trace,self.file_name) + def setup(self): + """ + This function setup the shard on Primary DB. + """ + if self.ocommon.check_key("RESET_LISTENER",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) + self.ocommon.prog_exit("127") + self.reset_listener() + self.restart_listener() + if self.ocommon.check_key("RESTART_DB",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.start_db(self.ora_env_dict) + elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) + self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) + if os.path.exists(create_db_file_lck): + self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) + sys.exit(127) + elif os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) + status = self.shard_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) + sys.exit(0) + else: + status = self.shard_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Shard readyness check completed sucessfully!",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_machine() + self.db_checks() + self.reset_shard_setup() + status = self.shard_setup_check() + if status: + self.ocommon.log_info_message("Shard Setup is already completed on this database",self.file_name) + else: + self.reset_passwd() + self.setup_cdb_shard() + self.set_spfile_nonm_params() + self.ocommon.set_events("spfile") + self.set_dbparams_version() + self.restart_db() + self.alter_db() + self.setup_pdb_shard () + self.update_shard_setup() + self.set_primary_listener() + self.restart_listener() + self.register_services() + self.list_services() + self.backup_files() + self.gsm_completion_message() + self.run_custom_scripts() + + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + ########### SETUP_MACHINE ENDS here #################### + + ########### DB_CHECKS Related Functions Begin Here #################### + ## Function to perfom DB checks ###### + def db_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.set_user() + self.sid_check() + self.dbuinque_name_check() + self.hostname_check() + self.dbport_check() + self.dbr_dest_checks() + self.dpump_dir_checks() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit() + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def passwd_check(self): + """ + This funnction perform password related checks + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def set_user(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def sid_check(self): + """ + This funnction heck and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): + msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="ORACLE_SID is not set, existing!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def dbuinque_name_check(self): + """ + This funnction check and set the db unique name for standby + """ + if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" + self.ocommon.log_info_message(msg,self.file_name) + dbsid=self.ora_env_dict["ORACLE_SID"] + self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) + + def hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def dbport_check(self): + """ + This funnction checks and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("DB_PORT",self.ora_env_dict): + msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) + msg="DB_PORT is not set, setting default to 1521" + self.ocommon.log_info_message(msg,self.file_name) + + def dbr_dest_checks(self): + """ + This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. + """ + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) + + # Checking the DB_RECOVERY_FILE_DEST_SIZE + + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the DB_CREATE_FILE_DEST + + if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): + msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) + + + def dpump_dir_checks(self): + """ + This funnction checks and set the DATA_PUMP dir and location. + """ + if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): + msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) + self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) + msg='''DATA_PUMP_DIR set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) + + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## RESET_PASSWORD function Begin here ############################# + ## Function to perform password reset + def reset_passwd(self): + """ + This function reset the password. + """ + self.ocommon.reset_passwd() + + ########## RESET_PASSWORD function ENDS here ############################# + + ########## SETUP_CDB_SHARD FUNCTION BEGIN HERE ############################### + + def reset_shard_setup(self): + """ + This function drop teh shard setup table and reste the env to default values. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Inside reset_shard_setup",self.file_name) + shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + if not os.path.isfile(shard_reset_file): + msg='''Dropping shardsetup table from CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + drop table system.shardsetup; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + else: + msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(shard_reset_file) + self.ocommon.log_info_message(msg,self.file_name) + + + def shard_setup_check(self): + """ + This function check the shard status. + """ +# systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + # self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool /tmp/shard_setup.txt + select * from system.shardsetup WHERE ROWNUM = 1; + spool off + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + fname='''/tmp/{0}'''.format("shard_setup.txt") + fdata=self.ocommon.read_file(fname) + ### Unsetting the encrypt value to None + # self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + return True + else: + return False + + def setup_cdb_shard(self): + """ + This function setup the shard. + """ + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] + dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] + host_name=self.ora_env_dict["ORACLE_HOSTNAME"] + dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] + db_port=self.ora_env_dict["DB_PORT"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting up Shard CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set db_create_file_dest=\"{0}\" scope=both; + alter system set db_recovery_file_dest_size={1} scope=both; + alter system set db_recovery_file_dest=\"{2}\" scope=both; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set standby_file_management='AUTO' scope=spfile; + alter user gsmrootuser account unlock; + grant sysdg to gsmrootuser; + grant sysbackup to gsmrootuser; + alter user gsmrootuser identified by HIDDEN_STRING container=all; + alter user GSMUSER account unlock; + alter user GSMUSER identified by HIDDEN_STRING container=all; + grant sysdg to GSMUSER; + grant sysbackup to GSMUSER; + create or replace directory DATA_PUMP_DIR as '{3}'; + grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; + alter system set local_listener='{4}:{5}' scope=spfile; + '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_spfile_nonm_params(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set open_links_per_instance=16 scope=spfile; + alter system set open_links=16 scope=spfile; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; + alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def set_dbparams_version(self): + """ + This function setup the catalog parameter based on db version. + """ + ohome1=self.ora_env_dict["ORACLE_HOME"] + version=self.ocommon.get_oraversion(ohome1).strip() + self.ocommon.log_info_message(version,self.file_name) + if int(version) > 21: + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + + msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set wallet_root=\"{1}/oradata/{2}/{3}/\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_db(self): + + """ + restarting the db + """ + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + # self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) + # sqlcmd=''' + # alter database archivelog; + # alter database open; + # ''' + # output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + # self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + + def setup_pdb_shard(self): + """ + This function setup the shard. + """ + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up Shard PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter pluggable database {0} close immediate; + alter pluggable database {0} open services=All; + ALTER PLUGGABLE DATABASE {0} SAVE STATE; + alter system register; + alter session set container={0}; + grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; + grant sysdg to GSMUSER; + grant sysbackup to GSMUSER; + execute DBMS_GSM_FIX.validateShard; + alter system register; + '''.format(self.ora_env_dict["ORACLE_PDB"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + def update_shard_setup(self): + """ + This function update the shard setup on this DB. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") + systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + +# self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + + msg='''Updating shardsetup table''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + create table system.shardsetup (status varchar2(10)); + insert into system.shardsetup values('completed'); + commit; + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Reset File + shard_reset_dir='''{0}/.shard'''.format(self.ora_env_dict["HOME"]) + shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) + + self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) + if not os.path.isdir(shard_reset_dir): + self.ocommon.create_dir(shard_reset_dir,True,None,None) + + if not os.path.isfile(shard_reset_file): + self.ocommon.create_file(shard_reset_file,True,None,None) + +# self.ocommon.unset_mask_str() + + ########## SETUP_CDB_SHARD FUNCTION ENDS HERE ############################### + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Shard Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) + ################################ Reset and standby functions ################################################# + + def set_primary_listener(self): + """ + Function to set the primary listener + """ + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + + def set_db_listener(self,gdbname,sid): + """ + Funtion to reset the listener + """ + self.ocommon.log_info_message("Inside reset_listener()",self.file_name) + start = 'SID_LIST_LISTENER' + end = '^\)$' + oracle_home=self.ora_env_dict["ORACLE_HOME"] + lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) + buffer = "SID_LIST_LISTENER=" + '\n' + start_flag = False + try: + with open(lisora) as f: + for line1 in f: + if start_flag == False: + if (re.match(start, line1.strip())): + start_flag = True + elif (re.match(end, line1.strip())): + line2 = f.next() + if (re.match(end, line2.strip())): + break + else: + buffer += line1 + buffer += line2 + else: + if start_flag == True: + buffer += line1 + except: + pass + + if start_flag == True: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + else: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + + wr = open(lisora, 'w') + wr.write(listener) + + def restart_listener(self): + """ + restart listener + """ + self.ocommon.log_info_message("Stopping Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl stop'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + self.ocommon.log_info_message("Starting Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl start'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + def register_services(self): + """ + This function setup the catalog. + """ + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system register; + alter session set container={0}; + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def list_services(self): + """ + restart listener + """ + self.ocommon.log_info_message("Listing Services",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl services'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + def backup_files(self): + """ + This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig + """ + self.ocommon.log_info_message("Inside backup_files()",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + dbsid=self.ora_env_dict["ORACLE_SID"] + + version=self.ocommon.get_oraversion(ohome).strip() + wallet_backup_cmd='''ls -ltr /bin''' + self.ocommon.log_info_message("Check Version " + version,self.file_name) + if int(version) >= 21: + obase1=self.ora_env_dict["ORACLE_BASE"] + wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) + cmd_names=''' + mkdir -p {0}/oradata/{1}/{2} + cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ + cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ + cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ + {4} + touch {0}/oradata/{1}/{2}/status_completed + '''.format(obase,"dbconfig",dbuname,ohome,wallet_backup_cmd) + cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] + for cmd in cmd_list: + msg='''Executing cmd {0}'''.format(cmd) + self.ocommon.log_info_message(msg,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orascatalog.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orascatalog.py new file mode 100755 index 0000000..aa4ea65 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orascatalog.py @@ -0,0 +1,9 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orasshard.py b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orasshard.py new file mode 100755 index 0000000..58f168b --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/orasshard.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +import traceback + +class OraSShard: + """ + This calss setup the standby shard after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraSShard class to setup the shard on standby DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + try: + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + except BaseException as ex: + ex_type, ex_value, ex_traceback = sys.exc_info() + trace_back = traceback.extract_tb(ex_traceback) + stack_trace = list() + for trace in trace_back: + stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) + ocommon.log_info_message(ex_type.__name__,self.file_name) + ocommon.log_info_message(ex_value,self.file_name) + ocommon.log_info_message(stack_trace,self.file_name) + def setup(self): + """ + This function setup the shard on standby DB. + """ + pass diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/runOraShardSetup.sh b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/runOraShardSetup.sh new file mode 100755 index 0000000..c1b09b4 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/runOraShardSetup.sh @@ -0,0 +1,568 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +export CLONED_FILE="status_completed" +export STANDBY_STATUS="status_completed" + +########### Clone Files ##################### +function cloneDB { + +export NEW_ORACLE_SID=$ORACLE_SID +export ORACLE_SID=$OLD_ORACLE_SID +sqlplus / as sysdba << EOF + STARTUP mount; + exit; +EOF + +echo 'Y' | nid target=/ dbname="$NEW_ORACLE_SID" + +if [ $? -eq 0 ]; then + echo "DB name changed sucessfully" +else + echo "DB name change process failed" + exit 1; +fi + +if [ -z ${DB_RECOVERY_FILE_DEST} ]; then + export DB_RECOVERY_FILE_DEST=$ORACLE_BASE/oradata/fast_recovery_area/$NEW_ORACLE_SID +fi + +if [ -z ${DB_UNIQUE_NAME} ]; then + export DB_UNIQUE_NAME=$NEW_ORACLE_SID +fi + +export ORACLE_HOSTNAME=$( hostname -f ) + +echo "Changing DB name" +export ORACLE_SID=$NEW_ORACLE_SID +sqlplus / as sysdba << EOF + STARTUP nomount; + alter system set db_name=$ORACLE_SID scope=spfile; + alter system set open_links=16 scope=spfile; + alter system set open_links_per_instance=16 scope=spfile; + alter system set dg_broker_config_file1="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr2$DB_UNIQUE_NAME.dat" scope=spfile; + alter system set dg_broker_config_file2="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr1$DB_UNIQUE_NAME.dat" scope=spfile; + alter system set db_file_name_convert='*','$ORACLE_BASE/oradata/$DB_UNIQUE_NAME/' scope=spfile; + alter system set local_listener='$ORACLE_HOSTNAME' scope=spfile; + alter system set standby_file_management='auto' scope=spfile; + shutdown immediate + exit; +EOF + +## Get the version + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 21 ]; then + echo "Setting DB Parameter based on the vserion" + export ORACLE_SID=$NEW_ORACLE_SID + sqlplus / as sysdba << EOF + startup nomount + alter system set wallet_root="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME" scope=spfile; + shutdown immediate + exit; +EOF + fi + fi + +echo "Changing OLD SID string to new string" +sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_HOME/network/admin/tnsnames.ora +sed -i "s/$OLD_ORACLE_PDB/$ORACLE_PDB/g" $ORACLE_HOME/network/admin/tnsnames.ora + +echo "Starting Listener" + +$ORACLE_HOME/bin/lsnrctl start + +echo "Starting new cloned DB" + +sqlplus / as sysdba << EOF + STARTUP mount; + alter database archivelog; + alter database open resetlogs; + exit; +EOF + +echo "Renaming PDB" + +sqlplus / as sysdba << EOF + alter pluggable database $OLD_ORACLE_PDB open restricted; + alter session set container=$OLD_ORACLE_PDB; + alter pluggable database rename global_name to $ORACLE_PDB; + exit; +EOF + +echo " Closing and Opening PDB" + +sqlplus / as sysdba << EOF + alter pluggable database $ORACLE_PDB close immediate; + alter pluggable database $ORACLE_PDB open; + alter system register; + exit; +EOF + + +echo "Touching $CLONED_FILE as setup is completed" +touch $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE + +} + +############################################ +########### Symbolic link DB files ######### +############################################ +########### DB Version >= 23c ############## +############################################ +function symLinkFiles23c { + + if [ -z ${ORACLE_BASE_HOME} ]; then + # + export ORACLE_BASE_HOME=$ORACLE_HOME + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora + fi; + if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/listener.ora + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora + fi + if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then + unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + ## Link based on ORACLE_BASE +# ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/spfile$ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi + fi + fi; + + if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID + fi; + + if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID + fi; + + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then + ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB + fi; + # oracle user does not have permissions in /etc, hence cp and not ln + sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab + cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab + fi +fi + +} + + +############################################ +########### Symbolic link DB files ######### +############################################ +########### DB Version < 23c ############### +############################################ +function symLinkFiles { + + if [ -z ${ORACLE_BASE_HOME} ]; then + # + export ORACLE_BASE_HOME=$ORACLE_HOME + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora + fi; + if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/listener.ora + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora + fi + if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then + unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$OLD_ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi + fi + fi; + + if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID + fi; + + if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID + fi; + + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then + ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB + fi; + # oracle user does not have permissions in /etc, hence cp and not ln + sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab + cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab + fi +fi + +} + +################################### +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +# Check whether container has enough memory +# Github issue #219: Prevent integer overflow, +# only check if memory digits are less than 11 (single GB range and below) +if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes | wc -c` -lt 11 ]; then + if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` -lt 2147483648 ]; then + echo "Error: The container doesn't have enough memory allocated." + echo "A database container needs at least 2 GB of memory." + echo "You currently only have $((`cat /sys/fs/cgroup/memory/memory.limit_in_bytes`/1024/1024/1024)) GB allocated to the container." + exit 1; + fi; +fi; + + +# Check that hostname doesn't container any "_" +# Github issue #711 +if hostname | grep -q "_"; then + echo "Error: The hostname must not container any '_'". + echo "Your current hostname is '$(hostname)'" +fi; + +# Default for ORACLE SID +if [ "$OLD_ORACLE_SID" == "" ]; then + export OLD_ORACLE_SID=SEEDCDB +fi + +if [ ! -z ${ORACLE_SID} ]; then + # Make ORACLE_SID upper case + # Github issue # 984 + export ORACLE_SID=${ORACLE_SID^^} + + # Check whether SID is no longer than 12 bytes + # Github issue #246: Cannot start OracleDB image + if [ "${#ORACLE_SID}" -gt 12 ]; then + echo "Error: The ORACLE_SID must only be up to 12 characters long." + exit 1; + fi; + + # Check whether SID is alphanumeric + # Github issue #246: Cannot start OracleDB image + if [[ "$ORACLE_SID" =~ [^a-zA-Z0-9] ]]; then + echo "Error: The ORACLE_SID must be alphanumeric." + exit 1; + fi; +else + echo "Error: The ORACLE_SID must be defined." + exit 1; +fi; + + +if [ ! -z ${ORACLE_PDB} ]; then + export ORACLE_PDB=${ORACLE_PDB^^} + + if [ "${#ORACLE_PDB}" -gt 12 ]; then + echo "Error: The ORACLE_PDB must only be up to 12 characters long." + exit 1; + fi; +else + echo "Error: The ORACLE_PDB must be defined." + exit 1; +fi; + +if [ ! -z ${OLD_ORACLE_PDB} ]; then + export OLD_ORACLE_PDB=${OLD_ORACLE_PDB^^} +else + export OLD_ORACLE_PDB=SEEDPDB +fi; + + +# Default for ORACLE CHARACTERSET +export ORACLE_CHARACTERSET=${ORACLE_CHARACTERSET:-AL32UTF8} + +# Check whether database already exists +if [ ! -z ${CLONE_DB} ]; then +if [ ${CLONE_DB^^} == "TRUE" ]; then +echo "CLONE_DB is set to true, cloning DB from seed" +if [ -d $ORACLE_BASE/oradata/$OLD_ORACLE_SID ]; then + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 23 ]; then + symLinkFiles23c; + else + symLinkFiles; + fi; + else + echo "Unable to determine the Database Version, exiting.." + exit 1; + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE ]; + then + # Start database + echo "Starting Database as cloned status file exist" + $ORACLE_BASE/$START_FILE; + else + echo "Performing Cloning as cloned status file does not exist" + cloneDB; + $ORACLE_BASE/checkDBStatus.sh + if [ $? -eq 0 ]; then + echo "DB is in READ WRITE State" + touch "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" + $ORACLE_BASE/$LOCKING_SCRIPT --acquire --file "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" + else + echo "DB is not in READ WRITE state" + exit 1; + fi + fi +else + echo "Error: The $ORACLE_BASE/oradata/$OLD_ORACLE_SID (ORACLE_BASE/oradata/OLD_ORACLE_SID) dir does not exist. Error exiting ." + exit 1; +fi +fi +fi + +if [ ${OP_TYPE,,} == "standbyshard" ]; then + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 23 ]; then + symLinkFiles23c; + else + symLinkFiles; + fi; + else + echo "Unable to determine the Database Version, exiting.." + exit 1; + fi + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/$STANDBY_STATUS ]; + then + # Start database + echo "Starting Database as standby setup status file exist" + $ORACLE_BASE/$START_FILE; + fi +fi + +#This is the main file which calls other file to setup the sharding. +if [ -z ${BASE_DIR} ]; then + BASE_DIR=/opt/oracle/scripts/sharding +fi + +if [ -z ${MAIN_SCRIPT} ]; then + SCRIPT_NAME="main.py" +fi + +if [ -z ${EXECUTOR} ]; then + EXECUTOR="python" +fi + +cd $BASE_DIR +$EXECUTOR $SCRIPT_NAME diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/scripts/runOracle.sh b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/runOracle.sh new file mode 100755 index 0000000..2266e99 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/scripts/runOracle.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +########### SIGINT handler ############ +function _int() { + echo "Stopping container." + echo "SIGINT received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown immediate; + exit; +EOF + lsnrctl stop +} + +########### SIGTERM handler ############ +function _term() { + echo "Stopping container." + echo "SIGTERM received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown immediate; + exit; +EOF + lsnrctl stop +} + +########### SIGKILL handler ############ +function _kill() { + echo "SIGKILL received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown abort; + exit; +EOF + lsnrctl stop +} + + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +if [ ! -z ${SHARD_SETUP} ]; then + if [ ${SHARD_SETUP,,} == "true" ]; then + sh $ORACLE_BASE/scripts/sharding/runOraShardSetup.sh + fi +fi + +if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & + fi +fi + +if [ ! -z ${OP_TYPE} ]; then + if [ ${OP_TYPE,,} == "standbyshard" ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & + fi +fi + +# Set SIGINT handler +trap _int SIGINT + +# Set SIGTERM handler +trap _term SIGTERM + +# Set SIGKILL handler +trap _kill SIGKILL + + +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/setupGSM.sh b/container-based-sharding-deployment/containerfiles/19.3.0/setupGSM.sh new file mode 100644 index 0000000..b908c48 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/setupGSM.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> + +# Create Directories +mkdir -p $GSM_BASE +mkdir -p $GSM_HOME +mkdir -p $INVENTORY + +chown -R oracle:oinstall $INVENTORY +chown -R oracle:oinstall $GSM_BASE +chown -R oracle:oinstall $GSM_HOME +chown -R oracle:oinstall $INSTALL_SCRIPTS +chmod 775 $INSTALL_SCRIPTS + +chmod 666 /etc/sudoers +echo "oracle ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +chmod 440 /etc/sudoers + +echo "export ORACLE_HOME=$GSM_HOME" >> /home/oracle/.bashrc +echo "export PATH=$GSM_PATH" >> /home/oracle/.bashrc +echo "export LD_LIBRARY_PATH=$GSM_LD_LIBRARY_PATH" >> /home/oracle/.bashrc +echo "export SCRIPT_DIR=$SCRIPT_DIR" >> /home/oracle/.bashrc +echo "export GSM_HOME=$GSM_HOME" >> /home/oracle/.bashrc diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/setupLinuxEnv.sh b/container-based-sharding-deployment/containerfiles/19.3.0/setupLinuxEnv.sh new file mode 100644 index 0000000..f02a621 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/setupLinuxEnv.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# + +# ------------------------------------------------------------ +chmod ug+x $SCRIPT_DIR/*.sh && \ +yum -y install oracle-database-preinstall-19c net-tools which zip unzip tar openssl openssh-server openssh-client vim-minimal which vim-minimal passwd sudo && \ +yum clean all diff --git a/container-based-sharding-deployment/containerfiles/19.3.0/setupOshardEnv.sh b/container-based-sharding-deployment/containerfiles/19.3.0/setupOshardEnv.sh new file mode 100755 index 0000000..413148b --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/19.3.0/setupOshardEnv.sh @@ -0,0 +1,963 @@ +#!/bin/bash +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> + +export NOW=$(date +"%Y%m%d%H%M") +export LOGDIR="/tmp" +export LOGFILE="${LOGDIR}/oshard_${NOW}.log" +export STD_OUT_FILE="/proc/1/fd/1" +export STD_ERR_FILE="/proc/1/fd/2" +declare -x SECRET_VOLUME='/run/secrets/' ## Secret Volume +declare -x PWD_KEY='pwd.key' ## PWD Key File +declare -x COMMON_OS_PWD_FILE='common_os_pwdfile.enc' +declare -x DB_PWD_FILE +export PDB_SQL_SCRIPT="/tmp/pdb.sql" +export TOP_PID=$$ +rm -f /tmp/sqllog.output +rm -f $PDB_SQL_SCRIPT +rm -f $LOGFILE + +#################################### Print and Exit Functions Begin Here ####################### +error_exit() { +local NOW=$(date +"%m-%d-%Y %T %Z") + # Display error message and exit +# echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2 + echo "${NOW} : ${PROGNAME}: ${1:-"Unknown Error"}" | tee -a $LOGFILE > $STD_OUT_FILE + kill -s TERM $TOP_PID +} + +print_message () +{ + local NOW=$(date +"%m-%d-%Y %T %Z") + # Display message and return + echo "${NOW} : ${PROGNAME} : ${1:-"Unknown Message"}" | tee -a $LOGFILE > $STD_OUT_FILE + return $? +} +#################################### Print and Exit Functions End Here ####################### + + +####################################### Functions Related to checks #################### +dbChecks() +{ +if [ -z "$ORACLE_HOME" ] +then + error_exit "Set the ORACLE_HOME variable" +else + print_message "ORACLE_HOME set to $ORACLE_HOME" +fi + +# If ORACLE_HOME doesn't exist # +if [ ! -d "$ORACLE_HOME" ] +then + error_exit "The ORACLE_HOME $ORACLE_HOME does not exist" +else + print_message "ORACLE_HOME Directory Exist" +fi + +################## Checks for Password and Clustername and clustertype begins here ########### +if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then +cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' + +eval $cmd + +if [ $? -eq 0 ]; then +print_message "Password file generated" +else +error_exit "Error occurred during common os password file generation" +fi + +read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} +rm -f /tmp/${COMMON_OS_PWD_FILE} +else + print_message "Password is empty string" + export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 +fi + +if [ -z "${ORACLE_PWD}" ]; then + print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" + export ORACLE_PWD=${PASSWORD} +else + print_message "ORACLE_PWD is set to user specified password" +fi + +################################################################################################### + + +if [ -z "${SHARD_ADMIN_USER}" ] +then + print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + export SHARD_ADMIN_USER="mysdbadmin" +else + print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" +fi + + +if [ -z "${PDB_ADMIN_USER}" ] +then + print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" + export PDB_ADMIN_USER="pdbadmin" +else + print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" +fi + + +# Validate the value of ORACLE_SID # +if [ -z "${ORACLE_SID}" ] +then + error_exit "Set the ORACLE_SID variable" +else + print_message "ORACLE_SID is set to $ORACLE_SID" +fi + +if [ -z "${ORACLE_HOSTNAME}" ] +then + if [ -z "${KUBE_SVC}" ]; then + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname)" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + else + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + fi +else + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" +fi + + + +if [ -z "$DB_PORT" ] +then + print_message "Set the DB_PORT variable" + export DB_PORT=1521 +else + print_message "DB Port is set to $DB_PORT" +fi + +if [ -z "${DB_RECOVERY_FILE_DEST}" ]; then + print_message "Set the DB_RECOVERY_FILE_DEST is not set" + export DB_RECOVERY_FILE_DEST="${ORACLE_BASE}/oradata/fast_recovery_area/${ORACLE_SID}" +fi + +if [ -z "${DB_CREATE_FILE_DEST}" ]; then + print_message "Set the DB_CREATE_FILE_DEST is not set. Setting to ${ORACLE_BASE}/oradata/${ORACLE_SID}" + export DB_CREATE_FILE_DEST="${ORACLE_BASE}/oradata/${ORACLE_SID}" +fi + +if [ -z "${DATA_PUMP_DIR}" ]; then + print_message "DATA_PUMP_DIR is not set, it will se to ${ORACLE_BASE}/oradata/data_pump_dir" + export DATA_PUMP_DIR="${ORACLE_BASE}/oradata/data_pump_dir" +fi + +if [ ! -d "${DATA_PUMP_DIR}" ]; then + print_message "DATA_PUMP_DIR ${DATA_PUMP_DIR} directory does not exist" + mkdir -p "${DATA_PUMP_DIR}" +fi + +if [ ! -d "${DB_RECOVERY_FILE_DEST}" ]; then + print_message "DB_RECOVERY_FILE_DEST ${DB_RECOVERY_FILE_DEST} directory does not exist" + mkdir -p "${DB_RECOVERY_FILE_DEST}" +fi + +if [ -z "${DB_RECOVERY_FILE_DEST_SIZE}" ]; then + print_message "DB_RECOVERY_FILE_DEST_SIZE is not set" + export DB_RECOVERY_FILE_DEST_SIZE="40G" +else + print_message "DB_RECOVERY_FILE_DEST_SIZE is set to ${DB_RECOVERY_FILE_DEST_SIZE}" +fi + +} + +gsmChecks() +{ + print_message "Performing GSM related checks" + +if [ ! -z "${KUBE_SVC}" ]; then + lordinal=$( hostname | awk -F "-" '{ print $NF }' ) + print_message "lordinal is set to ${lordinal}" + region_num=$((lordinal+1)) + if [ -z "${REGION}" ]; then + print_message "REGION is not set. Setting to region$lordinal" + export REGION="region${region_num}" + fi +else + if [ -z "${REGION}" ]; then + error_exit "REGION Canot be set to empty" + fi +fi + +################## Checks for Password and Clustername and clustertype begins here ########### +if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then +cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' + +eval $cmd + +if [ $? -eq 0 ]; then +print_message "Password file generated" +else +error_exit "Error occurred during common os password file generation" +fi + +read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} +rm -f /tmp/${COMMON_OS_PWD_FILE} +else + print_message "Password is empty string" + export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 +fi + +if [ -z "${ORACLE_PWD}" ]; then + print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" + export ORACLE_PWD=${PASSWORD} +else + print_message "ORACLE_PWD is set to user specified password" +fi + +################################################################################################### + +if [ -z "$SHARD_ADMIN_USER" ] +then + print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + export SHARD_ADMIN_USER="mysdbadmin" +else + print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" +fi + + +if [ -z "$PDB_ADMIN_USER" ] +then + print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" + export PDB_ADMIN_USER="pdbadmin" +else + print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" +fi + + +if [ -z "${SHARD_GROUP_NAME}" ]; then + print_message "SHARD_GROUP_NAME is not set, it will be set to primary_shardgroup" + export SHARD_GROUP_NAME="primary_shardgroup" +fi + +if [ -z "${SHARD_DEPLOYMENT_TYPE}" ]; then + print_message "SHARD_DEPLOYMENT_TYPE is not set, it will set to primary" + export SHARD_DEPLOYMENT_TYPE="primary" +fi + +if [ -z "${SHARD_DIRECTOR_NAME}" ]; then + print_message "SHARD_DIRECTOR_NAME is not set, it will set to sharddirector${region_num}" + export SHARD_DIRECTOR_NAME="sharddirector${region_num}" +fi + +if [ -z "${ORACLE_HOSTNAME}" ] +then + if [ -z "${KUBE_SVC}" ]; then + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname)" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + else + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + fi +else + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" +fi + +} + +###################################### Function Related to Check end here ################### + +################################### Reset Password ########################################### +resetPassword() +{ +if [ -f "${HOME}/setPassword.sh" ]; then +if [ ! -z "${ORACLE_PWD}" ]; then +"${HOME}"/setPassword.sh "$ORACLE_PWD" +fi +fi +} + +############################################################################################### +setupCatalog() +{ + +localconnectStr="/ as sysdba" +systemStr="system/${ORACLE_PWD}" +sqlScript="/tmp/setapp.sql" +print_message "Setting up Paramteres in Spfile" + +cmd1="drop table shardsetup;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" +#cmd=$( eval echo "$cmd1" ) +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links_per_instance=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="@$ORACLE_HOME/rdbms/admin/setCatalogDBPrivs.sql;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" +print_message "cat /tmp/setup_grants_privs.lst" + +cmd1="alter user gsmcatuser account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmcatuser identified by $ORACLE_PWD;" +print_message "Sending query to sqlplus to execute alter user gsmcatuser identified by ORACLE_PWD;" +executeSQL "$cmd1" "$localconnectStr" + + +#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" +cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + + +cmd1="shutdown immediate;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="startup mount;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database archivelog;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database open;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database flashback on;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database force logging;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1", "$localconnectStr" + +cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +if [ ! -z "${ORACLE_PDB}" ]; then +setupCatalogPDB +fi + +cmd1="create table shardsetup (status varchar2(10));" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="insert into shardsetup values('completed');" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" +} + +configureSampleAppSchema() +{ +local sqlScript="/tmp/sqlScript.sql" +connectStr = "${SHARD_ADMIN_USER}/${ORACLE_PWD}" + +echo "alter session enable shard ddl;" > ${sqlScript} +echo "create user app_schema identified by ${ORACLE_PWD};" >> ${sqlScript} +echo "grant all privileges to app_schema;" >> ${sqlScript} +echo "grant gsmadmin_role to app_schema;" >> ${sqlScript} +echo "grant select_catalog_role to app_schema;" >> ${sqlScript} +echo "grant connect, resource to app_schema;" >> ${sqlScript} +echo "grant dba to app_schema;" >> ${sqlScript} +echo "grant execute on dbms_crypto to app_schema;" >> ${sqlScript} +echo "CREATE TABLESPACE SET TSP_SET_1 using template (datafile size 100m autoextend on next 10M maxsize unlimited extent management local segment space management auto);" >> ${sqlScript} +echo "CREATE TABLESPACE SET LOBTS1;" >> ${sqlScript} +echo "CREATE TABLESPACE products_tsp datafile size 100m autoextend on next 10M maxsize unlimited extent management local uniform size 1m; " >> ${sqlScript} +echo "CONNECT app_schema/app_schema_password;" >> ${sqlScript} +echo "ALTER SESSION ENABLE SHARD DDL;" >> ${sqlScript} +echo "CREATE SHARDED TABLE Customers (CustId VARCHAR2(60) NOT NULL, FirstName VARCHAR2(60), LastName VARCHAR2(60), Class VARCHAR2(10), Geo VARCHAR2(8),CustProfile VARCHAR2(4000),Passwd RAW(60),CONSTRAINT pk_customers PRIMARY KEY (CustId),CONSTRAINT json_customers CHECK (CustProfile IS JSON)) TABLESPACE SET TSP_SET_1 PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO;" >> ${sqlScript} +echo "CREATE SHARDED TABLE Orders (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL, OrderDate TIMESTAMP NOT NULL,SumTotal NUMBER(19,4),Status CHAR(4), CONSTRAINT pk_orders PRIMARY KEY (CustId, OrderId),CONSTRAINT fk_orders_parent FOREIGN KEY (CustId) REFERENCES Customers ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_orders_parent);" >> ${sqlScript} +echo "CREATE SEQUENCE Orders_Seq;" >> ${sqlScript} +echo "CREATE SHARDED TABLE LineItems (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL,ProductId INTEGER NOT NULL,Price NUMBER(19,4),Qty NUMBER,CONSTRAINT pk_items PRIMARY KEY (CustId, OrderId, ProductId),CONSTRAINT fk_items_parent FOREIGN KEY (CustId, OrderId) REFERENCES Orders ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_items_parent);" >> ${sqlScript} +echo "CREATE DUPLICATED TABLE Products (ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,Name VARCHAR2(128),DescrUri VARCHAR2(128),LastPrice NUMBER(19,4)) TABLESPACE products_tsp;" >> ${sqlScript} + +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "$connectStr" "sqlScript" "${sqlScript}" + +} + + +setupCatalogPDB() +{ +#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" +pdbConnStr=" /as sysdba" + +local sqlScript="/tmp/sqlScript.sql" + +print_message "Settup Sql Script to setup Catalog PDB" +echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" +echo "create user ${SHARD_ADMIN_USER} identified by ${ORACLE_PWD};" >> "${sqlScript}" +echo "grant connect, create session, gsmadmin_role to ${SHARD_ADMIN_USER} ;" >> "${sqlScript}" +echo "grant inherit privileges on user SYS to GSMADMIN_INTERNAL;" >> "${sqlScript}" +echo "execute dbms_xdb.sethttpport(8080);" >> ${sqlScript} +echo "exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('${ORACLE_PWD}');" >> "${sqlScript}" + +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" +} + +######################################################################## Catalog Setup task ends here ################################# + +######################################################################## Primary Shard Setup task ends here ################################# + +setupShardPDB() +{ + +#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" +pdbConnStr=" /as sysdba" + +local sqlScript="/tmp/sqlScript.sql" +print_message "Settup Sql Script to setup Catalog PDB" +echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" +echo "grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" >> "${sqlScript}" +echo "grant sysdg to GSMUSER;" >> "${sqlScript}" +echo "grant sysbackup to GSMUSER;" >> "${sqlScript}" +echo "execute DBMS_GSM_FIX.validateShard;" >> ${sqlScript} +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" + +} + +setupShardCDB() +{ +localconnectStr="/as sysdba" +systemStr="system/${ORACLE_PWD}" +print_message "Setting up Paramteres in Spfile" + +cmd1="drop table shardsetup;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links_per_instance=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmrootuser account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmrootuser identified by ${ORACLE_PWD} container=all;" +print_message "Sending query to sqlplus to execute alter user gsmrootuser identified by ORACLE_PWD container=all;" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysdg to gsmrootuser;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysbackup to gsmrootuser;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user GSMUSER account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user GSMUSER identified by ${ORACLE_PWD} container=all;" +print_message "Sending query to sqlplus to execute alter user GSMUSER identified by ORACLE_PWD container=all;" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysdg to GSMUSER;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysbackup to GSMUSER;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set dg_broker_start=true scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="create or replace directory DATA_PUMP_DIR as '${DATA_PUMP_DIR}';" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" +cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="shutdown immediate;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="startup mount;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database archivelog;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database open;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database flashback on;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database force logging;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +if [ ! -z "${ORACLE_PDB}" ]; then + +setupShardPDB + +fi + +cmd1="create table shardsetup (status varchar2(10));" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + + +cmd1="insert into shardsetup values('completed');" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +} + +######################################################################## Primary Shard Setup ends here ################################# + +######################################################################## GSM Setup Task Begin here ##################################### +setupGSM() +{ +local cstatus='false' +local sstatus='false' + +setupGSMCatalog +startGSM +addShardGroup +setupGSMShard + +} + +startGSM() +{ + +cmd1="start gsm" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +deployShard() +{ + +cmd1="deploy" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +stopGSM() +{ + +cmd1="stop gsm" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +addInvitedNode() +{ + +chost=$1 + +cmd1="add invitednode $chost" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + + +addShardGroup() +{ + +cmd1="add shardgroup -shardgroup ${shardGName} -deploy_as ${deployment_type} -region ${region}" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +checkStatus() +{ +host=$1 +port=1521 +cpdb=$3 +ccdb=$2 +uname="system" +cpasswd=${ORACLE_PWD} + +print_message "Connect String $uname/$cpasswd@//$host:$port/$ccdb" +output=$( "$ORACLE_HOME"/bin/sqlplus -s "$uname/$cpasswd@//$host:$port/$ccdb" <<EOF + set heading off feedback off verify off echo off PAGESIZE 0 + select status from shardsetup; + exit +EOF +) + + if [ "${output}" == 'completed' ];then + print_message "Returned status from catalog is $output" + else + print_message "Sleeping for 300 seconds as returned status is not $output " + sleep 300 + fi + + echo $output +} + +setupGSMCatalog() +{ +IFS='; ' read -r -a sarray <<< "$CATALOG_PARAMS" +for element in "${sarray[@]}" +do + print_message "1st String in Shard params $element" + type=$( echo $element | awk -F: '{print $NF }') + host=$( echo $element | awk -F: '{print $1 }') + db=$( echo $element | awk -F: '{print $2 }') + pdb=$( echo $element | awk -F: '{print $3 }') +done + +print_message "Set variables to host=${host} db=${db} pdb=${pdb}" +if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] +then +runtime="60 minute" +endtime=$(date -ud "$runtime" +%s) + +while [[ $(date -u +%s) -le $endtime ]] +do + + coutput=$( checkStatus $host $db $pdb ) + if [ "${coutput}" == 'completed' ] ;then + configureGSMCatalog $host $db $pdb + break + else + print_message "Catalog Status must return completed but returned value is $coutput" + fi + print_message "Catalog DB is still not ready. Sleeping for 60 seconds" + sleep 60 +done +fi + +if [ "${coutput}" != 'completed' ] ;then + error_exit "Shard Catalog is not setup, Unable to proceed futher" +fi + +} + +configureGSMCatalog() +{ +chost=$1 +cport=1521 +cpdb=$3 +ccdb=$2 +gsmhost=${ORACLE_HOSTNAME} +cadmin=${SHARD_ADMIN_USER} +cpasswd=${ORACLE_PWD} +########################## +region="${REGION}" +shardGName="${SHARD_GROUP_NAME}" +deployment_type="${SHARD_DEPLOYMENT_TYPE}" +local gdsScript="/tmp/gdsScript.sql" + +gsm_name="${SHARD_DIRECTOR_NAME}" +echo "create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=${chost})(PORT=${cport}))(CONNECT_DATA=(SERVICE_NAME=${cpdb})))\" -user ${cadmin}/${cpasswd} -sdb shardcatalog -region region1,region2 -agent_port 8080 -agent_password ${cpasswd} -autovncr off" > "${gdsScript}" +echo "add invitednode ${chost}" >> "${gdsScript}" +echo "add gsm -gsm ${gsm_name} -listener 1521 -pwd ${cpasswd} -catalog ${chost}:${cport}/${cpdb} -region region1 -endpoint '(ADDRESS=(PROTOCOL=tcp)(HOST=${gsmhost})(PORT=1521))'" >> "${gdsScript}" +echo "exit" >> "${gdsScript}" +print_message "Sending script to gsm to execute ${gdsScript}" +cat ${gdsScript} >> $LOGFILE +cp "${gdsScript}" "${gdsScript}.test" +executeGSM "$cmd1" "gdsScript" "${gdsScript}" +} + +setupGSMShard() +{ +IFS='; ' read -r -a sarray <<< "$PRIMARY_SHARD_PARAMS" +arrLen=$( echo "${#sarray[@]}" ) +count1=0 + +runtime="45 minute" +endtime=$(date -ud "$runtime" +%s) + +print_message "Set variables to host=${host} db=${db} pdb=${pdb}" +while [[ $(date -u +%s) -le $endtime ]] +do + for i in ${!sarray[@]}; do + print_message "1st String in Shard params $element" + host=$( echo ${sarray[i]} | awk -F: '{print $1 }') + db=$( echo ${sarray[i]} | awk -F: '{print $2 }') + pdb=$( echo ${sarray[i]} | awk -F: '{print $3 }') + print_message "shard env set to host=${host} db=${db} pdb=${pdb}" + if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] + then + coutput=$( checkStatus $host $db $pdb ) + if [ "${coutput}" == 'completed' ] ;then + configureGSMShard $host $db $pdb + unset sarray[i] + ((++count1)) + else + print_message "Catalog Status must return completed but returned value is $coutput" + fi + fi + done + if [ ${count1} -ge ${arrLen} ]; then + break; + fi + print_message "Shards are still not ready. Sleeping for 120 seconds" + sleep 120 +done +} + +configureGSMShard() +{ +chost=$1 +cport=1521 +cpdb=$3 +ccdb=$2 +cpasswd=${ORACLE_PWD} +region=${REGION} +shardGName="${SHARD_GROUP_NAME}" +deployment_type="${SHARD_DEPLOYMENT_TYPE}" +local gdsScript="/tmp/gdsScript.sql" +admuser="${PDB_ADMIN_USER}" + +echo "connect ${admuser}/${cpasswd}" > "${gdsScript}" +echo "add cdb -connect ${chost}:${cport}:${ccdb} -pwd ${cpasswd}" >> "${gdsScript}" +echo "add shard -cdb ${ccdb} -connect ${chost}:${cport}/${cpdb} -shardgroup ${shardGName} -pwd ${cpasswd}" >> "${gdsScript}" +echo "config vncr" >> "${gdsScript}" +echo "sql 'update gsmadmin_internal.database set hostid=NULL '" >> "${gdsScript}" +echo "exit" >> "${gdsScript}" +print_message "Sending script to gsm to execute ${gdsScript}" +cat ${gdsScript} >> $LOGFILE +executeGSM "$cmd1" "gdsScript" "${gdsScript}" +print_message " Calling Stop GSM function" +stopGSM +print_message "Stop GSM function completed, sleeping for 20 seconds" +sleep 20 +print_message " Calling Start GSM function" +startGSM +print_message "Start GSM function completed, sleeping for 30 seconds" +sleep 30 +print_message "Calling invitenode function to add the shard" +addInvitedNode $chost +deployShard +} + +####################################################################### GSM Setup Task Ends here ######################################### + + +######################################################################### Execute GSM Statements ######################################### +executeGSM() +{ +gsmQuery=$1 +type=$2 +gdsScript=$3 + +if [ -z "${gsmQuery}" ]; then + print_message "Empty gdsQuery passed to gds" +fi + +if [ -z "${type}" ]; then + type='notSet' +fi + +if [ -z "${gdsScript}" ]; then + gdsScript='notSet' +fi + +if [ "${type}" == "gdsScript" ]; then +print_message "Executing gds script " +"$ORACLE_HOME"/bin/gdsctl @${gdsScript} +else +print_message "Executing GSM query" +"$ORACLE_HOME"/bin/gdsctl << EOF >> $LOGFILE + $gsmQuery + exit +EOF +fi +} +######################################################################## Execute GSM Statements Ends here ################################ + +########################################################################## Execute SQL Function Begin here ############################## +executeSQL() +{ +sqlQuery=$1 +connectStr=$2 +type=$3 +sqlScript=$4 + +if [ -z "${sqlQuery}" ]; then + print_message "Empty sqlQuery passed to sqlplus. Operation Failed" +fi + +if [ -z "${connectStr}" ]; then + error_exit "Empty connectStr passed to sqlplus. Operation Failed" +fi + +if [ -z "${type}" ]; then + type='notSet' +fi + +if [ -z "${sqlScript}" ]; then + sqlScript='notSet' +fi + +if [ "${type}" == "sqlScript" ] && [ -f ${sqlScript} ]; then +print_message "Executing sql script using connect string" +"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE +@ ${sqlScript} +EOF +else +print_message "Executing sqlQuery using connect string" +"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE +$sqlQuery +EOF +fi +} + +############################################################################## Execute SQl Function ends here ################################# + +####################################### +################## MAIN ############### + +if [ "${OP_TYPE}" == "primaryshard" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + resetPassword + setupShardCDB +elif [ "${OP_TYPE}" == "standbyshard" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + setupShardStandby +elif [ "${OP_TYPE}" == "catalog" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + resetPassword + setupCatalog +elif [ "${OP_TYPE}" == "gsm" ]; then + print_message "Performing Checks before proceeding for setup" + gsmChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + setupGSM +else + print_message "OP_TYPE must be set to (gsm|catalog|primaryshard|standbyshard)" + exit 15 +fi diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/21c_gsm_install.rsp b/container-based-sharding-deployment/containerfiles/21.3.0/21c_gsm_install.rsp new file mode 100644 index 0000000..8051fd8 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/21c_gsm_install.rsp @@ -0,0 +1,35 @@ + +############################################################################### +## Copyright(c) Oracle Corporation 1998,2021. All rights reserved. ## +## ## +## Specify values for the variables listed below to customize ## +## your installation. ## +## ## +## Each variable is associated with a comment. The comment ## +## can help to populate the variables with the appropriate ## +## values. ## +## ## +############################################################################### + +#------------------------------------------------------------------------------- +# Do not change the following system generated value. +#------------------------------------------------------------------------------- +oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v21.0.0 + +#------------------------------------------------------------------------------- +# Unix group to be set for the inventory directory. +#------------------------------------------------------------------------------- +UNIX_GROUP_NAME=oinstall +#------------------------------------------------------------------------------- +# Inventory location. +#------------------------------------------------------------------------------- +INVENTORY_LOCATION=###INVENTORY### +#------------------------------------------------------------------------------- +# Complete path of the Oracle Home +#------------------------------------------------------------------------------- +ORACLE_HOME=###ORACLE_HOME### + +#------------------------------------------------------------------------------- +# Complete path of the Oracle Base. +#------------------------------------------------------------------------------- +ORACLE_BASE=###ORACLE_BASE### diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/21c_gsm_install_sample.rsp b/container-based-sharding-deployment/containerfiles/21.3.0/21c_gsm_install_sample.rsp new file mode 100644 index 0000000..00cbdfb --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/21c_gsm_install_sample.rsp @@ -0,0 +1,35 @@ + +############################################################################### +## Copyright(c) Oracle Corporation 1998,2021. All rights reserved. ## +## ## +## Specify values for the variables listed below to customize ## +## your installation. ## +## ## +## Each variable is associated with a comment. The comment ## +## can help to populate the variables with the appropriate ## +## values. ## +## ## +############################################################################### + +#------------------------------------------------------------------------------- +# Do not change the following system generated value. +#------------------------------------------------------------------------------- +oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v21.0.0 + +#------------------------------------------------------------------------------- +# Unix group to be set for the inventory directory. +#------------------------------------------------------------------------------- +UNIX_GROUP_NAME= +#------------------------------------------------------------------------------- +# Inventory location. +#------------------------------------------------------------------------------- +INVENTORY_LOCATION= +#------------------------------------------------------------------------------- +# Complete path of the Oracle Home +#------------------------------------------------------------------------------- +ORACLE_HOME= + +#------------------------------------------------------------------------------- +# Complete path of the Oracle Base. +#------------------------------------------------------------------------------- +ORACLE_BASE= diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/Checksum b/container-based-sharding-deployment/containerfiles/21.3.0/Checksum new file mode 100644 index 0000000..1fab7e9 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/Checksum @@ -0,0 +1 @@ +ba8e6b942ba8ff22d25dd3babc7b326c LINUX.X64_213000_gsm.zip diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/Containerfile b/container-based-sharding-deployment/containerfiles/21.3.0/Containerfile new file mode 100644 index 0000000..26a37e2 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/Containerfile @@ -0,0 +1,144 @@ +# LICENSE UPL 1.0 +# +# Copyright (c) 2018,2021 Oracle and/or its affiliates. +# +# ORACLE DOCKERFILES PROJECT +# -------------------------- +# This is the Dockerfile for Oracle GSM 21c Release 3 to build the container image +# MAINTAINER <paramdeep.saini@oracle.com> +# +# This is the Dockerfile for Oracle GSM 21c +# +# REQUIRED FILES TO BUILD THIS IMAGE +# ---------------------------------- +# (1) LINUX.X64_213000_gsm.zip +# Download Oracle Database 21c GSM Software +# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html +# +# HOW TO BUILD THIS IMAGE +# ----------------------- +# Put all downloaded files in the same directory as this Dockerfile +# Run: +# $ docker build -t oracle/gsm:21.3.0 . +# +# Pull base image +# --------------- +ARG BASE_OL_IMAGE=oraclelinux:7-slim + +# Pull base image +# --------------- +FROM $BASE_OL_IMAGE AS base + +# Labels +# ------ +LABEL "provider"="Oracle" \ + "issues"="https://github.com/oracle/db-sharding/issues" \ + "volume.setup.location1"="/opt/oracle/scripts" \ + "port.listener"="1522" + +# Argument to control removal of components not needed after db software installation +ARG SLIMMING=false +ARG INSTALL_FILE_1="LINUX.X64_213000_gsm.zip" + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +ENV GSM_BASE="/u01/app/oracle" \ + GSM_HOME="/u01/app/oracle/product/21c/gsmhome_1" \ + INVENTORY="/u01/app/oracle/oraInventory" \ + INSTALL_DIR="/opt/oracle/scripts" \ + INSTALL_FILE_1=$INSTALL_FILE_1 \ + INSTALL_RSP="21c_gsm_install.rsp" \ + RUN_FILE="runOracle.sh" \ + SETUP_LINUX_FILE="setupLinuxEnv.sh" \ + CHECK_SPACE_FILE="checkSpace.sh" \ + USER_SCRIPTS_FILE="runUserScripts.sh" \ + INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ + GSM_SETUP_FILE="setupOshardEnv.sh" \ + GSM_ENV_SETUP_FILE="setupGSM.sh" \ + GSM_SCRIPTS="scripts" \ + MAINPY="main.py" \ + PYTHON_FILE="/usr/bin/python" \ + PYTHON3_FILE="/usr/bin/python3" \ + CHECKLIVENESS="checkLiveness.sh" +# Use second ENV so that variable get substituted +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/sharding \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_PATH=$GSM_HOME/bin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib + + +# Copy files needed during both installation and runtime +# ------------ +COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $GSM_ENV_SETUP_FILE $INSTALL_DIR/install/ +COPY $RUN_FILE $GSM_SETUP_FILE $CHECKLIVENESS $USER_SCRIPTS_FILE $SCRIPT_DIR/ +COPY $GSM_SCRIPTS $SCRIPT_DIR/scripts/ + +RUN chmod 755 $INSTALL_DIR/install/*.sh && \ + sync && \ + $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ + $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ + $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ + sync + +############################################# +# ------------------------------------------- +# Start new stage for installing the GSM +# ------------------------------------------- +############################################# + +from base AS builder + +COPY $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ + +RUN chmod 755 $INSTALL_SCRIPTS/*.sh && \ + sync && \ + sed -e '/hard *memlock/s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-21c.conf && \ + sed -e '/ *nofile /s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-21c.conf && \ + su oracle -c "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ + $INVENTORY/orainstRoot.sh && \ + $GSM_HOME/root.sh && \ + rm -rf $INSTALL_DIR/install && \ + rm -f /etc/sysctl.d/99-oracle-database-preinstall-21c-sysctl.conf && \ + rm -f /etc/sysctl.d/99-sysctl.conf && \ + rm -f /etc/rc.d/init.d/oracle-database-preinstall-21c-firstboot && \ + rm -f /etc/security/limits.d/oracle-database-preinstall-21c.conf && \ + sync + +############################################# +# ------------------------------------------- +# Start new layer for GSM runtime +# ------------------------------------------- +############################################# + +FROM base + +COPY --from=builder /u01 /u01 + +RUN if [ ! -f $PYTHON_FILE ]; then \ + ln -s $PYTHON3_FILE $PYTHON_FILE && \ + :; \ + fi && \ + rm -f $INSTALL_DIR/install/* && \ + cp $SCRIPT_DIR/scripts/cmdExec $SCRIPT_DIR/ && \ + chown -R oracle:oinstall $SCRIPT_DIR && \ + chmod 755 $SCRIPT_DIR/*.sh && \ + chmod 755 $SCRIPT_DIR/scripts/*.py && \ + chmod 755 $SCRIPT_DIR/scripts/*.sh && \ + chmod 755 $SCRIPT_DIR/scripts/cmdExec && \ + chmod 755 $SCRIPT_DIR/cmdExec && \ + sync + +USER oracle +WORKDIR /home/oracle +EXPOSE 1521 + +VOLUME ["$GSM_BASE/oradata"] + +HEALTHCHECK --interval=2m --start-period=25m \ + CMD "$SCRIPT_DIR/scripts/$CHECKLIVENESS" >/dev/null || exit 1 + +# Define default command to start Oracle Database. +CMD exec $SCRIPT_DIR/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/Dockerfile_21c b/container-based-sharding-deployment/containerfiles/21.3.0/Dockerfile_21c new file mode 100644 index 0000000..37f8fba --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/Dockerfile_21c @@ -0,0 +1,85 @@ +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> +# +# This is the Dockerfile for Oracle Database 21 +# +# REQUIRED FILES TO BUILD THIS IMAGE +# ---------------------------------- +# (1) LINUX.X64_213000_gsm.zip +# Download Oracle Database 21c GSM Software +# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html +# +# HOW TO BUILD THIS IMAGE +# ----------------------- +# Put all downloaded files in the same directory as this Dockerfile +# Run: +# $ docker build -t oracle/gsm:21.3.0 . +# +# Pull base image +# --------------- +FROM oraclelinux:7-slim as base + +# Maintainer +# ---------- +MAINTAINER Paramdeep Saini <paramdeep.saini@oracle.com> + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +ENV GSM_BASE="/u01/app/oracle" \ + GSM_HOME="/u01/app/oracle/product/21c/gsmhome_1" \ + INVENTORY="/u01/app/oraInventory" \ + INSTALL_DIR="/opt/scripts" \ + INSTALL_FILE_1="LINUX.X64_213000_gsm.zip" \ + INSTALL_RSP="21c_gsm_install.rsp" \ + RUN_FILE="runOracle.sh" \ + SETUP_LINUX_FILE="setupLinuxEnv.sh" \ + CHECK_SPACE_FILE="checkSpace.sh" \ + USER_SCRIPTS_FILE="runUserScripts.sh" \ + INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ + GSM_SETUP_FILE="setupOshardEnv.sh" \ + GSM_ENV_SETUP_FILE="setupGSM.sh" \ + GSM_SCRIPTS="scripts" +# Use second ENV so that variable get substituted +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/startup \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH \ + GSM_PATH=$GSM_HOME/bin:/usr/sbin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib + + +# Copy files needed during both installation and runtime +# ------------ +COPY $INSTALL_FILE_1 $SETUP_LINUX_FILE $CHECK_SPACE_FILE $INSTALL_RSP $GSM_ENV_SETUP_FILE $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ +COPY $RUN_FILE $GSM_SETUP_FILE $USER_SCRIPTS_FILE $INSTALL_DIR/startup/ +COPY $GSM_SCRIPTS $INSTALL_DIR/startup/scripts + +RUN chmod 755 $INSTALL_DIR/install/*.sh && \ + sync && \ + $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ + $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ + $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ + sed -e '/hard *memlock/s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-19c.conf && \ + su oracle -c "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ + $INVENTORY/orainstRoot.sh && \ + $GSM_HOME/root.sh && \ + rm -rf $INSTALL_DIR/install && \ + rm -f /etc/sysctl.d/99-oracle-database-preinstall-19c-sysctl.conf && \ + rm -f /etc/sysctl.d/99-sysctl.conf && \ + rm -f /etc/rc.d/init.d/oracle-database-preinstall-19c-firstboot && \ + rm -f /etc/security/limits.d/oracle-database-preinstall-19c.conf && \ + rm -f $INSTALL_DIR/install/* && \ + chown -R oracle:oinstall $SCRIPT_DIR && \ + chmod 755 $SCRIPT_DIR/*.sh && \ + sync + +USER oracle +WORKDIR /home/oracle +EXPOSE 1521 + +VOLUME ["$GSM_BASE/oradata"] + +# Define default command to start Oracle Database. +CMD exec $INSTALL_DIR/startup/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/checkLiveness.sh b/container-based-sharding-deployment/containerfiles/21.3.0/checkLiveness.sh new file mode 100644 index 0000000..e4d3563 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/checkLiveness.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +export PYTHON="/bin/python" + +$PYTHON $SCRIPT_DIR/scripts/$MAINPY --checkliveness='true' +retcode=$? + + if [ ${retcode} -eq 0 ]; then + exit 0 + else + exit 1 + fi diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/checkSpace.sh b/container-based-sharding-deployment/containerfiles/21.3.0/checkSpace.sh new file mode 100644 index 0000000..5d4b8d9 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/checkSpace.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +REQUIRED_SPACE_GB=2 +AVAILABLE_SPACE_GB=`df -PB 1G / | tail -n 1 | awk '{ print $4 }'` + +if [ $AVAILABLE_SPACE_GB -lt $REQUIRED_SPACE_GB ]; then + script_name=`basename "$0"` + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "$script_name: ERROR - There is not enough space available in the docker container." + echo "$script_name: The container needs at least $REQUIRED_SPACE_GB GB, but only $AVAILABLE_SPACE_GB GB are available." + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + exit 1; +fi; diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/installGSMBinaries.sh b/container-based-sharding-deployment/containerfiles/21.3.0/installGSMBinaries.sh new file mode 100644 index 0000000..adf6547 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/installGSMBinaries.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +export ORACLE_BASE=$GSM_BASE +export ORACLE_HOME=$GSM_HOME + +# Check whether ORACLE_BASE is set +if [ "$ORACLE_BASE" == "" ]; then + echo "ERROR: ORACLE_BASE has not been set!" + echo "You have to have the ORACLE_BASE environment variable set to a valid value!" + exit 1; +fi; + +# Check whether ORACLE_HOME is set +if [ "$ORACLE_HOME" == "" ]; then + echo "ERROR: ORACLE_HOME has not been set!" + echo "You have to have the ORACLE_HOME environment variable set to a valid value!" + exit 1; +fi; + + +# Replace place holders +# --------------------- + +sed -i -e "s|###INVENTORY###|$INVENTORY|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ +sed -i -e "s|###ORACLE_BASE###|$GSM_BASE|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ +sed -i -e "s|###ORACLE_HOME###|$GSM_HOME|g" $INSTALL_SCRIPTS/$INSTALL_RSP + +# Install Oracle binaries +cd $INSTALL_SCRIPTS && \ +unzip $INSTALL_FILE_1 && \ +rm $INSTALL_FILE_1 && \ +$INSTALL_SCRIPTS/gsm/runInstaller -silent -force -waitforcompletion -responsefile $INSTALL_SCRIPTS/$INSTALL_RSP -ignorePrereqFailure || true && \ +rm -rf gsm && \ +cd $HOME diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/runOracle.sh b/container-based-sharding-deployment/containerfiles/21.3.0/runOracle.sh new file mode 100644 index 0000000..edb50f7 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/runOracle.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +#This is the main file which calls other file to setup the sharding. +if [ -z ${BASE_DIR} ]; then + BASE_DIR=$INSTALL_DIR/sharding/scripts +fi + +if [ -z ${MAIN_SCRIPT} ]; then + SCRIPT_NAME="main.py" +fi + +if [ -z ${EXECUTOR} ]; then + EXECUTOR="python" +fi + +cd $BASE_DIR +$EXECUTOR $SCRIPT_NAME + +# Tail on alert log and wait (otherwise container will exit) + +if [ -z ${DEV_MODE} ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/gsm/*/*/trace/alert*.log & +else + echo "The following output is now a tail of the /etc/passwd for dev mode" + tail -f /etc/passwd & +fi + +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/runUserScripts.sh b/container-based-sharding-deployment/containerfiles/21.3.0/runUserScripts.sh new file mode 100644 index 0000000..c1d1c44 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/runUserScripts.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +SCRIPTS_ROOT="$1"; + +# Check whether parameter has been passed on +if [ -z "$SCRIPTS_ROOT" ]; then + echo "$0: No SCRIPTS_ROOT passed on, no scripts will be run"; + exit 1; +fi; + +# Execute custom provided files (only if directory exists and has files in it) +if [ -d "$SCRIPTS_ROOT" ] && [ -n "$(ls -A $SCRIPTS_ROOT)" ]; then + + echo ""; + echo "Executing user defined scripts" + + for f in $SCRIPTS_ROOT/*; do + case "$f" in + *.sh) echo "$0: running $f"; . "$f" ;; + *.sql) echo "$0: running $f"; echo "exit" | $ORACLE_HOME/bin/sqlplus -s "/ as sysdba" @"$f"; echo ;; + *) echo "$0: ignoring $f" ;; + esac + echo ""; + done + + echo "DONE: Executing user defined scripts" + echo ""; + +fi; diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/cmdExec b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/cmdExec new file mode 100755 index 0000000..0e5ac30 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/cmdExec @@ -0,0 +1,23 @@ +#!/bin/bash + +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +TIMESTAMP=`date "+%Y-%m-%d"` +LOGFILE="/tmp/sharding_cmd_${TIMESTAMP}.log" + +echo $(date -u) " : " $@ >> $LOGFILE + +cmd=$@ + +$cmd + +if [ $? -eq 0 ]; then + exit 0 +else + exit 127 +fi diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/demoapp.sql b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/demoapp.sql new file mode 100755 index 0000000..3e96bfc --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/demoapp.sql @@ -0,0 +1,88 @@ + connect sys/'&1'@oshard-catalog-0:1521/CATCDB as sysdba + alter session set container=CAT1PDB; + alter session enable shard ddl; + create user app_schema identified by app_schema; + grant connect, resource, alter session to app_schema; + grant execute on dbms_crypto to app_schema; + grant create table, create procedure, create tablespace, create materialized view to app_schema; + grant unlimited tablespace to app_schema; + grant select_catalog_role to app_schema; + grant all privileges to app_schema; + grant gsmadmin_role to app_schema; + grant dba to app_schema; + conn app_schema/'&1'@oshard-catalog-0:1521/CAT1PDB + alter session enable shard ddl; + REM + REM Create a Sharded table for + REM + CREATE SHARDED TABLE Customers + ( + CustId VARCHAR2(60) NOT NULL, + FirstName VARCHAR2(60), + LastName VARCHAR2(60), + Class VARCHAR2(10), + Geo VARCHAR2(8), + CustProfile VARCHAR2(4000), + Passwd RAW(60), + CONSTRAINT pk_customers PRIMARY KEY (CustId), + CONSTRAINT json_customers CHECK (CustProfile IS JSON) + ) TABLESPACE SET TSP_SET_1 + PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO; + REM + REM Create a Sharded table for Orders + REM + CREATE SHARDED TABLE Orders + ( + OrderId INTEGER NOT NULL, + CustId VARCHAR2(60) NOT NULL, + OrderDate TIMESTAMP NOT NULL, + SumTotal NUMBER(19,4), + Status CHAR(4), + constraint pk_orders primary key (CustId, OrderId), + constraint fk_orders_parent foreign key (CustId) + references Customers on delete cascade + ) partition by reference (fk_orders_parent); + REM + REM Create the sequence used for the OrderId column + REM + CREATE SEQUENCE Orders_Seq; + REM + REM Create a Sharded table for LineItems + REM + CREATE SHARDED TABLE LineItems + ( + OrderId INTEGER NOT NULL, + CustId VARCHAR2(60) NOT NULL, + ProductId INTEGER NOT NULL, + Price NUMBER(19,4), + Qty NUMBER, + constraint pk_items primary key (CustId, OrderId, ProductId), + constraint fk_items_parent foreign key (CustId, OrderId) + references Orders on delete cascade + ) partition by reference (fk_items_parent); + REM + REM + CREATE DUPLICATED TABLE Products + ( + ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + Name VARCHAR2(128), + DescrUri VARCHAR2(128), + LastPrice NUMBER(19,4) + ) TABLESPACE products_tsp; + CREATE OR REPLACE FUNCTION PasswCreate(PASSW IN RAW) + RETURN RAW + IS + Salt RAW(8); + BEGIN + Salt := DBMS_CRYPTO.RANDOMBYTES(8); + RETURN UTL_RAW.CONCAT(Salt, DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(Salt,PASSW), DBMS_CRYPTO.HASH_SH256)); + END; + / + CREATE OR REPLACE FUNCTION PasswCheck(PASSW IN RAW, PHASH IN RAW) + RETURN INTEGER IS + BEGIN + RETURN UTL_RAW.COMPARE(DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(UTL_RAW.SUBSTR(PHASH, 1, 8), PASSW), DBMS_CRYPTO.HASH_SH256),UTL_RAW.SUBSTR(PHASH, 9)); + END; + / + REM + REM diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/main.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/main.py new file mode 100755 index 0000000..b7f0f17 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/main.py @@ -0,0 +1,171 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" +This is the main file which calls other file to setup the sharding. +""" + +from oralogger import * +from orafactory import * +from oraenv import * +from oracommon import * + + +def main(): + + # Checking Comand line Args + try: + opts, args = getopt.getopt(sys.argv[1:], '', ['addshard=','deleteshard=','validateshard=','checkliveness=','resetlistener=','restartdb=','createdir=','optype=','addshardgroup=','deployshard=','movechunks=','checkonlineshard=','cancelchunks=','checkchunks=','checkgsmshard=','checkreadyness=','validatenochunks=','invitednode=','resetpassword=','exporttdekey=','importtdekey=','help']) + except getopt.GetoptError: + pass + + # Initializing oraenv instance + oenv=OraEnv() + file_name = os.path.basename(__file__) + funcname = sys._getframe(1).f_code.co_name + + log_file_name = oenv.logfile_name("NONE") + + # Initialiing logger instance + oralogger = OraLogger(log_file_name) + console_handler = CHandler() + file_handler = FHandler() + stdout_handler = StdHandler() + # Setting next log handlers + stdout_handler.nextHandler = file_handler + file_handler.nextHandler = console_handler + console_handler.nextHandler = PassHandler() + + ocommon = OraCommon(oralogger,stdout_handler,oenv) + + for opt, arg in opts: + if opt in ('--help'): + oralogger.msg_ = '''{:^17}-{:^17} : You can pass parameter --addshard, --deleteshard, --validateshard, --checkliveness, --resetlistener, --restartdb, --createdir, --optype, --addshardgroup, --deployshard, '--checkonlineshard', '--cancelchunks', '--movechunks', '--checkchunks', '--checkgsmshard','--validatenochunks', '--checkreadyness','--invitednode', '--resetpassword','--exporttdekey','--importtdekey',or --help''' + stdout_handler.handle(oralogger) + elif opt in ('--addshard'): + file_name = oenv.logfile_name("ADD_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("ADD_SHARD",arg) + elif opt in ('--validateshard'): + file_name = oenv.logfile_name("VALIDATE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("VALIDATE_SHARD",arg) + elif opt in ('--deleteshard'): + file_name = oenv.logfile_name("REMOVE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("REMOVE_SHARD",arg) + elif opt in ('--checkliveness'): + oralogger.stdout_ = None + file_name = oenv.logfile_name("CHECK_LIVENESS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_LIVENESS",arg) + elif opt in ('--checkreadyness'): + oralogger.stdout_ = None + file_name = oenv.logfile_name("CHECK_READYNESS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_READYNESS",arg) + elif opt in ('--resetlistener'): + file_name = oenv.logfile_name("RESET_LISTENER") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESET_LISTENER",arg) + elif opt in ('--restartdb'): + file_name = oenv.logfile_name("RESTART_DB") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESTART_DB",arg) + elif opt in ('--createdir'): + file_name = oenv.logfile_name("CREATE_DIR") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CREATE_DIR",arg) + elif opt in ('--addshardgroup'): + file_name = oenv.logfile_name("ADD_SGROUP_PARAMS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("ADD_SGROUP_PARAMS",arg) + elif opt in ('--deployshard'): + file_name = oenv.logfile_name("DEPLOY_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("DEPLOY_SHARD",arg) + elif opt in ('--cancelchunks'): + file_name = oenv.logfile_name("CANCEL_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CANCEL_CHUNKS",arg) + elif opt in ('--movechunks'): + file_name = oenv.logfile_name("MOVE_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("MOVE_CHUNKS",arg) + elif opt in ('--checkchunks'): + file_name = oenv.logfile_name("CHECK_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_CHUNKS",arg) + elif opt in ('--validatenochunks'): + file_name = oenv.logfile_name("VALIDATE_NOCHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("VALIDATE_NOCHUNKS",arg) + elif opt in ('--checkonlineshard'): + file_name = oenv.logfile_name("CHECK_ONLINE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_ONLINE_SHARD",arg) + elif opt in ('--checkgsmshard'): + file_name = oenv.logfile_name("CHECK_GSM_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_GSM_SHARD",arg) + elif opt in ('--invitednode'): + file_name = oenv.logfile_name("INVITED_NODE_OP") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("INVITED_NODE_OP",arg) + elif opt in ('--resetpassword'): + file_name = oenv.logfile_name("RESET_PASSWD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESET_PASSWORD",arg) + elif opt in ('--exporttdekey'): + file_name = oenv.logfile_name("EXPORT_TDE_KEY") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("EXPORT_TDE_KEY",arg) + elif opt in ('--importtdekey'): + file_name = oenv.logfile_name("IMPORT_TDE_KEY") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("IMPORT_TDE_KEY",arg) + elif opt in ('--optype'): + oenv.add_custom_variable("OP_TYPE",arg) + else: + pass + + # Initializing orafactory instances + oralogger.msg_ = '''{:^17}-{:^17} : Calling OraFactory to start the setup'''.format(file_name,funcname) + stdout_handler.handle(oralogger) + orafactory = OraFactory(oralogger,stdout_handler,oenv,ocommon) + + # Get the ora objects + ofactory=orafactory.get_ora_objs() + + # Traverse through returned factory objects and execute the setup function + for obj in ofactory: + obj.setup() + +# Using the special variable +if __name__=="__main__": + main() diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oracommon.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oracommon.py new file mode 100755 index 0000000..634a9f1 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oracommon.py @@ -0,0 +1,886 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +from oralogger import * +from oraenv import * +import subprocess +import sys +import time +import datetime +import os +import getopt +import shlex +import json +import logging +import socket +import re +import os.path +import socket +import string +import random + +class OraCommon: + def __init__(self,oralogger,orahandler,oraenv): + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + + def run_sqlplus(self,cmd,sql_cmd,dbenv): + """ + This function execute the ran sqlplus or rman script and return the output + """ + try: + message="Received Command : {0}\n{1}".format(self.mask_str(cmd),self.mask_str(sql_cmd)) + self.log_info_message(message,self.file_name) + sql_cmd=self.unmask_str(sql_cmd) + cmd=self.unmask_str(cmd) +# message="Received Command : {0}\n{1}".format(cmd,sql_cmd) +# self.log_info_message(message,self.file_name) + p = subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,env=dbenv,shell=True,universal_newlines=True) + p.stdin.write(sql_cmd) + # (stdout,stderr), retcode = p.communicate(sqlplus_script.encode('utf-8')), p.returncode + (stdout,stderr),retcode = p.communicate(),p.returncode + # stdout_lines = stdout.decode('utf-8').split("\n") + except: + error_msg=sys.exc_info() + self.log_error_message(error_msg,self.file_name) + self.prog_exit(self) + + return stdout.replace("\n\n", "\n"),stderr,retcode + + def execute_cmd(self,cmd,env,dir): + """ + Execute the OS command on host + """ + try: + message="Received Command : {0}".format(self.mask_str(cmd)) + self.log_info_message(message,self.file_name) + cmd=self.unmask_str(cmd) + out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,universal_newlines=True) + (output,error),retcode = out.communicate(),out.returncode + except: + error_msg=sys.exc_info() + self.log_error_message(error_msg,self.file_name) + self.prog_exit(self) + + return output,error,retcode + + def mask_str(self,mstr): + """ + Function to mask the string. + """ + newstr=None + if self.oenv.encrypt_str__: + newstr=mstr.replace('HIDDEN_STRING','********') + # self.log_info_message(newstr,self.file_name) + if newstr: + # message = "Masked the string as encryption flag is set in the singleton class" + # self.log_info_message(message,self.file_name) + return newstr + else: + return mstr + + + def unmask_str(self,mstr): + """ + Function to unmask the string. + """ + newstr=None + if self.oenv.encrypt_str__: + newstr=mstr.replace('HIDDEN_STRING',self.oenv.original_str__.rstrip()) + # self.log_info_message(newstr,self.file_name) + if newstr: + # message = "Unmasked the encrypted string and returning original string from singleton class" + # self.log_info_message(message,self.file_name) + return newstr + else: + return mstr + + def set_mask_str(self,mstr): + """ + Function to unmask the string. + """ + if mstr: + # message = "Setting encrypted String flag to True and original string in singleton class" + # self.log_info_message(message,self.file_name) + self.oenv.encrypt_str__ = True + self.oenv.original_str__ = mstr + else: + message = "Masked String is empty so no change required in encrypted String Flag and original string in singleton class" + self.log_info_message(message,self.file_name) + + def unset_mask_str(self): + """ + Function to unmask the string. + """ + # message = "Un-setting encrypted String flag and original string to None in Singleton class" + # self.log_info_message(message,self.file_name) + self.oenv.encrypt_str__ = None + self.oenv.original_str__ = None + + def prog_exit(self,message): + """ + This function exit the program because of some error + """ + sys.exit(127) + + def log_info_message(self,lmessage,fname): + """ + Print the INFO message in the logger + """ + funcname = sys._getframe(1).f_code.co_name + message = '''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_ = message + self.ologger.logtype_ = "INFO" + self.ohandler.handle(self.ologger) + + def log_error_message(self,lmessage,fname): + """ + Print the Error message in the logger + """ + funcname=sys._getframe(1).f_code.co_name + message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_=message + self.ologger.logtype_="ERROR" + self.ohandler.handle(self.ologger) + + def log_warn_message(self,lmessage,fname): + """ + Print the Error message in the logger + """ + funcname=sys._getframe(1).f_code.co_name + message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_=message + self.ologger.logtype_="WARN" + self.ohandler.handle(self.ologger) + + def check_sql_err(self,output,err,retcode,status): + """ + Check if there are any error in sql command output + """ + match=None + msg2='''Sql command failed.Flag is set not to ignore this error.Please Check the logs,Exiting the Program!''' + msg3='''Sql command failed.Flag is set to ignore this error!''' + self.log_info_message("output : " + str(output or "no Output"),self.file_name) + # self.log_info_message("Error : " + str(err or "no Error"),self.file_name) + # self.log_info_message("Sqlplus return code : " + str(retcode),self.file_name) + # self.log_info_message("Command Check Status Set to :" + str(status),self.file_name) + + if status: + if (retcode!=0): + self.log_info_message("Error : " + str(err or "no Error"),self.file_name) + self.log_error_message("Sql Login Failed.Please Check the logs,Exiting the Program!",self.file_name) + self.prog_exit(self) + + match=re.search("(?i)(?m)error",output) + if status: + if (match): + self.log_error_message(msg2,self.file_name) + self.prog_exit("error") + else: + self.log_info_message("Sql command completed successfully",self.file_name) + else: + if (match): + self.log_warn_message("Sql command failed. Flag is set to ignore the error.",self.file_name) + else: + self.log_info_message("Sql command completed sucessfully.",self.file_name) + + def check_os_err(self,output,err,retcode,status): + """ + Check if there are any error in OS command execution + """ + msg1='''OS command returned code : {0} and returned output : {1}'''.format(str(retcode),str(output or "no Output")) + msg2='''OS command returned code : {0}, returned error : {1} and returned output : {2}'''.format(str(retcode),str(err or "no returned error"),str(output or "no retruned output")) + msg3='''OS command failed. Flag is set to ignore this error!''' + + if status: + if (retcode != 0): + self.log_error_message(msg2,self.file_name) + self.prog_exit(self) + else: + self.log_info_message(msg1,self.file_name) + else: + if (retcode != 0): + self.log_warn_message(msg2,self.file_name) + self.log_warn_message(msg3,self.file_name) + else: + self.log_info_message(msg1,self.file_name) + + def check_key(self,key,env_dict): + """ + Check the key if it exist in dictionary. + Attributes: + key (string): String to check if key exist in dictionary + env_dict (dict): Contains the env variable related to seup + """ + if key in env_dict: + return True + else: + return False + + def empty_key(self,key): + """ + key is empty and print failure message. + Attributes: + key (string): String is empty + """ + msg='''Variable {0} is not defilned. Exiting!'''.format(key) + self.log_error_message(msg,self.file_name) + self.prog_exit(self) + + def add_key(self,key,value,env_dict): + """ + Add the key in the dictionary. + Attributes: + key (string): key String to add in the dictionary + value (String): value String to add in dictionary + + Return: + dict + """ + if self.check_key(key,env_dict): + msg='''Variable {0} already exist in the env variables'''.format(key) + self.log_info_message(msg,self.file_name) + else: + if value: + env_dict[key] = value + self.oenv.update_env_vars(env_dict) + else: + msg='''Variable {0} value is not defilned to add in the env variables. Exiting!'''.format(value) + self.log_error_message(msg,self.file_name) + self.prog_exit(self) + + return env_dict + + def update_key(self,key,value,env_dict): + """ + update the key in the dictionary. + Attributes: + key (string): key String to update in the dictionary + value (String): value String to update in dictionary + + Return: + dict + """ + if self.check_key(key,env_dict): + if value: + env_dict[key] = value + self.oenv.update_env_vars(env_dict) + else: + msg='''Variable {0} value is not defilned to update in the env variables!'''.format(key) + self.log_warn_message(msg,self.file_name) + else: + msg='''Variable {0} already exist in the env variables'''.format(key) + self.log_info_message(msg,self.file_name) + + return env_dict + + def check_file(self,file,local,remote,user): + """ + check locally or remotely + Attributes: + file (string): file to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside check_file()",self.file_name) + if local: + if os.path.isfile(file): + return True + else: + return False + + + def read_file(self,fname): + """ + Read the contents of a file and returns the contents to end user + Attributes: + fname (string): file to be read + + Return: + file data (string) + """ + f1 = open(fname, 'r') + fdata = f1.read() + f1.close + return fdata + + def write_file(self,fname,fdata): + """ + write the contents to a file + Attributes: + fname (string): file to be written + fdata (string): COnetents to be written + + Return: + file data (string) + """ + f1 = open(fname, 'w') + f1.write(fdata) + f1.close + + def create_dir(self,dir,local,remote,user): + """ + Create dir locally or remotely + Attributes: + dir (string): dir to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside create_dir()",self.file_name) + if local: + if not os.path.isdir(dir): + cmd='''mkdir -p {0}'''.format(dir) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + else: + msg='''Dir {0} already exist'''.format(dir) + self.log_info_message(msg,self.file_name) + + if remote: + pass + + def create_file(self,file,local,remote,user): + """ + Create dir locally or remotely + Attributes: + file (string): file to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside create_file()",self.file_name) + if local: + if not os.path.isfile(file): + cmd='''touch {0}'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + if remote: + pass + + def shutdown_db(self,env_dict): + """ + Shutdown the database + """ + file="/home/oracle/shutDown.sh" + if not os.path.isfile(file): + self.log_info_message("Inside shutdown_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + shutdown immediate; + ''' + self.log_info_message("Running the sqlplus command to shutdown the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + else: + cmd='''sh {0} immediate'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + def mount_db(self,env_dict): + """ + Mount the database + """ + self.log_info_message("Inside mount_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup mount; + ''' + self.log_info_message("Running the sqlplus command to mount the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def start_db(self,env_dict): + """ + startup the database + """ + file="/home/oracle/startUp.sh" + if not os.path.isfile(file): + self.log_info_message("Inside start_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup; + ''' + self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + else: + cmd='''sh {0}'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + def nomount_db(self,env_dict): + """ + No mount the database + """ + self.log_info_message("Inside start_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup nomount; + ''' + self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def stop_gsm(self,env_dict): + """ + Stop the GSM + """ + self.log_info_message("Inside stop_gsm()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + gsmcmd=''' + stop gsm; + ''' + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + + def set_events(self,source): + """ + Seting events at DB level + """ + scope='' + accepted_scope = ['spfile', 'memory', 'both'] + + if self.check_key("DB_EVENTS",self.ora_env_dict): + events=str(self.ora_env_dict["DB_EVENTS"]).split(";") + + for event in events: + msg='''Setting up event {0}'''.format(event) + self.log_info_message(msg,self.file_name) + scope='' + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + source=event.split(":") + if len(source) > 1: + if source[1].split("=")[0] == "scope": + scope=source[1].split("=")[1] + + if scope not in accepted_scope: + sqlcmd=""" + alter system set events='{0}';""".format(source[0]) + else: + sqlcmd=""" + alter system set event='{0}' scope={1};""".format(source[0],scope) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def start_gsm(self,env_dict): + """ + Start the GSM + """ + self.log_info_message("Inside start_gsm()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + gsmcmd=''' + start gsm; + ''' + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + + def exec_gsm_cmd(self,gsmcmd,flag,env_dict): + """ + Get the GSM command output + """ + self.log_info_message("Inside exec_gsm_cmd()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + if gsmcmd: + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,flag) + else: + self.log_info_message("GSM Command was set to empty. Executing nothing and setting output to None",self.file_name) + output=None + + return output,error,retcode + + + def check_substr_match(self,source_str,sub_str): + """ + CHeck if substring exist + """ + self.log_info_message("Inside check_substr_match()",self.file_name) + if (source_str.find(sub_str) != -1): + return True + else: + return False + + def find_str_in_string(self,source_str,delimeter,search_str): + """AI is creating summary for find_str_in_string + + Args: + source_str ([string]): [string where you need to search] + delimeter ([character]): [string delimeter] + search_str ([string]): [string to be searched] + """ + if delimeter == 'comma': + new_str=source_str.split(',') + for str in new_str: + if str.lower() == search_str.lower(): + return True + return False + + return False + + def check_status_value(self,match): + """ + return completed or notcompleted + """ + self.log_info_message("Inside check_status_value()",self.file_name) + if match: + return 'completed' + else: + return 'notcompleted' + + def remove_file(self,fname): + """ + Remove if file exist + """ + self.log_info_message("Inside remove_file()",self.file_name) + if os.path.exists(fname): + os.remove(fname) + + def get_sid_desc(self,gdbname,ohome,sid,sflag): + """ + get the SID_LISTENER_DESCRIPTION + """ + self.log_info_message("Inside get_sid_desc()",self.file_name) + sid_desc = "" + if sflag == 'SID_DESC1': + sid_desc = ''' ) + (SID_DESC = + (GLOBAL_DBNAME = {0}) + (ORACLE_HOME = {1}) + (SID_NAME = {2}) + ) + ) + '''.format(gdbname,ohome,sid) + elif sflag == 'SID_DESC': + sid_desc = '''(SID_LIST = + (SID_DESC = + (GLOBAL_DBNAME = {0}) + (ORACLE_HOME = {1}) + (SID_NAME = {2}) + ) + ) + '''.format(gdbname,ohome,sid) + else: + pass + + return sid_desc + + def get_lisora(self,port): + """ + return listener.ora listener settings + """ + self.log_info_message("Inside get_lisora()",self.file_name) + listener='''LISTENER = + (DESCRIPTION_LIST = + (DESCRIPTION = + (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = {0})) + (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC{0})) + ) + ) + '''.format(port) + return listener + + def get_domain(self,ohost): + """ + get the domain name from hostname + """ + return ohost.partition('.')[2] + +######### Get the DOMAIN############## + def get_host_domain(self): + """ + Return Public Hostname + """ + domain=None + domain=socket.getfqdn().split('.',1)[1] + if domain is None: + domain="example.info" + + return domain + + ######### get the public IP ############## + def get_ip(self,hostname,domain): + """ + Return the Ip based on hostname + """ + if not domain: + domain=self.get_host_domain() + + return socket.gethostbyname(hostname) + + def get_global_dbdomain(self,ohost,gdbname): + """ + get the global dbname + """ + domain = self.get_domain(ohost) + if domain: + global_dbname = gdbname + domain + else: + global_dbname = gdbname + + return gdbname + +######### Sqlplus connect string ########### + def get_sqlplus_str(self,home,osid,dbuser,password,hostname,port,svc,osep,role,wallet): + """ + return the sqlplus connect string + """ + path='''/usr/bin:/bin:/sbin:/usr/local/sbin:{0}/bin'''.format(home) + ldpath='''{0}/lib:/lib:/usr/lib'''.format(home) + export_cmd='''export ORACLE_HOME={0};export PATH={1};export LD_LIBRARY_PATH={2};export ORACLE_SID={3}'''.format(home,path,ldpath,osid) + if dbuser == 'sys' and password and hostname and port and svc: + return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4} as sysdba'''.format(dbuser,password,hostname,port,svc,export_cmd,home) + elif dbuser != 'sys' and password and hostname and svc: + return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4}'''.format(dbuser,password,hostname,"1521",svc,export_cmd,home) + elif dbuser and osep: + return dbuser + elif dbuser == 'sys' and not password: + return '''{1};{0}/bin/sqlplus "/ as sysdba"'''.format(home,export_cmd) + elif dbuser == 'sys' and password: + return '''{1};{0}/bin/sqlplus {2}/{3} as sysdba'''.format(home,export_cmd,dbuser,password) + elif dbuser != 'sys' and password: + return '''{1};{0}/bin/sqlplus {2}/{3}'''.format(home,export_cmd,dbuser,password) + else: + self.log_info_message("Atleast specify db user and password for db connectivity. Exiting...",self.file_name) + self.prog_exit("127") + +######### Get Password ############## + def get_os_password(self): + """ + get the OS password + """ + ospasswd=self.get_password(None) + return ospasswd + + def get_asm_passwd(self): + """ + get the ASM password + """ + asmpasswd=self.get_password(None) + return asmpasswd + + def get_db_passwd(self): + """ + get the DB password + """ + dbpasswd=self.get_password(None) + return dbpasswd + + def get_sys_passwd(self): + """ + get the sys user password + """ + dbpasswd=self.get_password(None) + return dbpasswd + + def get_password(self,key): + """ + get the password + """ + passwd_file_flag=False + password=None + password_file=None + if self.check_key("SECRET_VOLUME",self.ora_env_dict): + self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["SECRET_VOLUME"]) + msg='''SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) + else: + self.ora_env_dict=self.add_key("SECRET_VOLUME","/run/secrets",self.ora_env_dict) + msg='''SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("KEY_SECRET_VOLUME",self.ora_env_dict): + self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["KEY_SECRET_VOLUME"]) + msg='''KEY_SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + else: + if self.check_key("SECRET_VOLUME",self.ora_env_dict): + self.ora_env_dict=self.add_key("KEY_SECRET_VOLUME",self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict) + msg='''KEY_SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict): + msg='''COMMON_OS_PWD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) + else: + self.ora_env_dict=self.add_key("COMMON_OS_PWD_FILE","common_os_pwdfile.enc",self.ora_env_dict) + msg='''COMMON_OS_PWD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("PWD_KEY",self.ora_env_dict): + msg='''PWD_KEY passed as an env variable and set to {0}'''.format(self.ora_env_dict["PWD_KEY"]) + else: + self.ora_env_dict=self.add_key("PWD_KEY","pwd.key",self.ora_env_dict) + msg='''PWD_KEY not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PWD_KEY"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("PASSWORD_FILE",self.ora_env_dict): + msg='''PASSWORD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) + else: + self.ora_env_dict=self.add_key("PASSWORD_FILE","dbpasswd.file",self.ora_env_dict) + msg='''PASSWORD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) + self.log_warn_message(msg,self.file_name) + + secret_volume = self.ora_env_dict["SECRET_VOLUME"] + key_secret_volume= self.ora_env_dict["KEY_SECRET_VOLUME"] + common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"] + pwd_volume=None + if self.check_key("PWD_VOLUME",self.ora_env_dict): + pwd_volume=self.ora_env_dict["PWD_VOLUME"] + else: + pwd_volume="/var/tmp" + pwd_key = self.ora_env_dict["PWD_KEY"] + passwd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) + dbpasswd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["PASSWORD_FILE"]) + key_file='''{0}/{1}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"],self.ora_env_dict["PWD_KEY"]) + key_secret_volume='''{0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + self.log_info_message("Password file set to : " + passwd_file,self.file_name) + self.log_info_message("key file set to : " + key_file,self.file_name) + self.log_info_message("dbpasswd file set to : " + dbpasswd_file,self.file_name) + self.log_info_message("key secret voluem set to file set to : " + key_secret_volume,self.file_name) + self.log_info_message("pwd volume set : " + pwd_volume,self.file_name) + #print(passwd_file) + if (os.path.isfile(passwd_file)) and (os.path.isfile(key_file)): + msg='''Passwd file {0} and key file {1} exist. Password file Check passed!'''.format(passwd_file,key_file) + self.log_info_message(msg,self.file_name) + msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file) + self.log_info_message(msg,self.file_name) + cmd=None + if self.check_key("ENCRYPTION_TYPE",self.ora_env_dict): + if self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "aes256": + cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out {2}/{1} -pass file:\"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + elif self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "rsautl": + cmd ='''openssl rsautl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + else: + pass + else: + cmd ='''openssl pkeyutl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + passwd_file_flag = True + password_file='''{0}/{1}'''.format(pwd_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) + elif os.path.isfile(dbpasswd_file): + msg='''Passwd file {0} exist. Password file Check passed!'''.format(dbpasswd_file) + self.log_info_message(msg,self.file_name) + msg='''Reading encrypted passwd from file {0}.'''.format(dbpasswd_file) + self.log_info_message(msg,self.file_name) + cmd='''openssl base64 -d -in \"{0}\" -out \"{2}/{1}\"'''.format(dbpasswd_file,self.ora_env_dict["PASSWORD_FILE"],pwd_volume) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + passwd_file_flag = True + password_file='''{1}/{0}'''.format(self.ora_env_dict["PASSWORD_FILE"],pwd_volume) + + if not passwd_file_flag: + # get random password pf length 8 with letters, digits, and symbols + characters1 = string.ascii_letters + string.digits + "_-%#" + str1 = ''.join(random.choice(string.ascii_uppercase) for i in range(4)) + str2 = ''.join(random.choice(characters1) for i in range(8)) + password=str1+str2 + else: + fname='''{0}'''.format(password_file) + fdata=self.read_file(fname) + password=fdata + self.remove_file(fname) + + if self.check_key("ORACLE_PWD",self.ora_env_dict): + msg="ORACLE_PWD is passed as an env variable. Check Passed!" + self.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.add_key("ORACLE_PWD",password,self.ora_env_dict) + msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file" + self.log_info_message(msg,self.file_name) + +######### Get oraversion ############## + def get_oraversion(self,home): + """ + get the software version + """ + cmd='''{0}/bin/oraversion -majorVersion'''.format(home) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + return output + +####### Get db lock file location ####### + def get_db_lock_location(self): + """ + get the db location + """ + if self.check_key("DB_LOCK_FILE_LOCATION",self.ora_env_dict): + return self.ora_env_dict["DB_LOCK_FILE_LOCATION"] + else: + ### Please note that you should not change following path as SIDB team is maintaining lock files under following location + return "/tmp/." + +####### Get the TDE Key ############### + def export_tde_key(self,filename): + """ + This function export the tde. + """ + self.log_info_message("Inside gettdekey()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + ALTER SESSION DISABLE SHARD DDL; + ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET {0} TO {1} IDENTIFIED BY {0}; + '''.format('HIDDEN_STRING',filename) + self.log_info_message("Running the sqlplus command to export the tde: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + +####### Get the TDE Key ############### + def import_tde_key(self,filename): + """ + This function import the TDE key. + """ + self.log_info_message("Inside importtdekey()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY {0}; + ADMINISTER KEY MANAGEMENT IMPORT ENCRYPTION KEYS WITH SECRET {0} FROM {1} IDENTIFIED BY {0} WITH BACKUP + '''.format('HIDDEN_STRING',filename) + self.log_info_message("Running the sqlplus command to import the tde key: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) +######## Reset the DB Password in database ######## + def reset_passwd(self): + """ + This function reset the password. + """ + password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh") + self.log_info_message("Executing password reset", self.file_name) + if self.check_key("ORACLE_PWD",self.ora_env_dict) and self.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script): + cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING') + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + self.unset_mask_str() + else: + msg='''Error Occurred! Either HOME DIR {0} does not exist, ORACLE_PWD {1} is not set or PASSWORD SCRIPT {2} does not exist'''.format(self.ora_env_dict["HOME"],self.ora_env_dict["ORACLE_PWD"],password_script) + self.log_error_message(msg,self.file_name) + self.oracommon.prog_exit() \ No newline at end of file diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oraenv.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oraenv.py new file mode 100755 index 0000000..dd96c48 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oraenv.py @@ -0,0 +1,139 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file read the env variables from a file or using env command and populate them in variable +""" + +import os + +class OraEnv: + __instance = None + __env_var_file = '/etc/rac_env_vars' + + __env_var_file_flag = None + __env_var_dict = {} + __ora_asm_diskgroup_name = '+DATA' + __ora_gimr_flag = 'false' + __ora_grid_user = 'grid' + __ora_db_user = 'oracle' + __ora_oinstall_group_name = 'oinstall' + encrypt_str__ = None + original_str__ = None + logdir__ = "/tmp/sharding" + + def __init__(self): + """ Virtually private constructor. """ + if OraEnv.__instance != None: + raise Exception("This class is a singleton!") + else: + OraEnv.__instance = self + OraEnv.read_variable() + OraEnv.add_variable() + try: + os.mkdir(OraEnv.logdir__) + except OSError as error: + pass + + @staticmethod + def get_instance(): + """ Static access method. """ + if OraEnv.__instance == None: + OraEnv() + return OraEnv.__instance + + @staticmethod + def read_variable(): + """ Read the variables from a file into dict """ + if OraEnv.__env_var_file_flag: + with open(OraEnv.__env_var_file) as envfile: + for line in envfile: + name, var = line.partition("=")[::2] + OraEnv.__env_var_dict[name.strip()] = var + else: + OraEnv.__env_var_dict = os.environ + + @staticmethod + def add_variable(): + """ Add more variable ased on enviornment with default values in __env_var_dict""" + OraEnv.__env_var_dict["GSM_LOCK_STATUS_FILE"] = "/tmp/.gsm_status_lock_file" + OraEnv.__env_var_dict["SHARD_LOCK_STATUS_FILE"] = "/tmp/.shard_status_lock_file" + if "ORA_ASM_DISKGROUP_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_ASM_DISKGROUP_NAME"] = "+DATA" + + if "ORA_GRID_USER" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_GRID_USER"] = "grid" + + if "ORA_DB_USER" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_DB_USER"] = "oracle" + + if "ORA_OINSTALL_GROUP_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_OINSTALL_GROUP_NAME"] = "oinstall" + + @staticmethod + def add_custom_variable(key,val): + """ Addcustom more variable passed from main.py values in __env_var_dict""" + if key not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict[key] = val + + @staticmethod + def get_env_vars(): + """ Static access method to get the env vars. """ + return OraEnv.__env_var_dict + + @staticmethod + def update_env_vars(env_dict): + """ Static access method to get the env vars. """ + OraEnv.__env_var_dict = env_dict + + @staticmethod + def logfile_name(file_type): + """ Static access method to return the logfile name. """ + if file_type == "NONE": + if "LOGFILE_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/oracle_sharding_setup.log" + elif file_type == "ADD_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_addition.log" + elif file_type == "VALIDATE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_validation.log" + elif file_type == "REMOVE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_remove.log" + elif file_type == "CHECK_LIVENESS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkliveness.log" + elif file_type == "CHECK_READYNESS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkreadyness.log" + elif file_type == "RESET_LISTENER": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_listener.log" + elif file_type == "RESTART_DB": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/restart_db.log" + elif file_type == "CREATE_DIR": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/create_dir.log" + elif file_type == "ADD_SGROUP_PARAMS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/add_sgroup.log" + elif file_type == "DEPLOY_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/deploy_shard.log" + elif file_type == "CANCEL_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/cancel_chunk.log" + elif file_type == "MOVE_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/move_chunks.log" + elif file_type == "CHECK_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_chunks.log" + elif file_type == "CHECK_ONLINE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_online_shard.log" + elif file_type == "CHECK_GSM_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_gsm_shard.log" + elif file_type == "INVITED_NODE_OP": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/node_invited_op.log" + elif file_type == "RESET_PASSWD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_passwd_file.log" + elif file_type == "TDE_KEY": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/tde_key.log" + else: + pass + + return OraEnv.__env_var_dict["LOG_FILE_NAME"] diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orafactory.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orafactory.py new file mode 100755 index 0000000..5ddb6e3 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orafactory.py @@ -0,0 +1,115 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file contains to the code call different classes objects based on setup type +""" + +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +from orapshard import * +from orasshard import * +from orapcatalog import * +from oragsm import * + +import os +import sys + +class OraFactory: + """ + This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def get_ora_objs(self): + ''' + Return the instance of a classes which will setup the enviornment. + + Returns: + ofactory_obj: List of objects + ''' + ofactory_obj = [] + + msg='''ora_env_dict set to : {0}'''.format(self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + msg="Checking the OP_TYPE and Version to begin the installation" + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the OP_TYPE + if self.ocommon.check_key("OP_TYPE",self.ora_env_dict): + msg='''OP_TYPE variable is set to {0}.'''.format(self.ora_env_dict["OP_TYPE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("OP_TYPE","nosetup",self.ora_env_dict) + msg="OP_TYPE variable is set to default nosetup. No value passed as an enviornment variable." + self.ocommon.log_info_message(msg,self.file_name) + + # Check the OP_TYPE value and call objects based on it value + if self.ora_env_dict["OP_TYPE"] == 'primaryshard': + msg="Creating and calling instance to setup primary shard" + opshard = OraPShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(opshard) + elif self.ora_env_dict["OP_TYPE"] == 'standbyshard': + msg="Creating and calling instance to setup standby shard" + osshard = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(osshard) + elif self.ora_env_dict["OP_TYPE"] == 'catalog': + msg="Creating and calling instance to setup Catalog DB" + opcat = OraPCatalog(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(opcat) + elif self.ora_env_dict["OP_TYPE"] == 'standbycatalog': + msg="Creating and calling instance to setup Catalog DB" + oscat = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(oscat) + elif self.ora_env_dict["OP_TYPE"] == 'gsm': + msg="Creating and calling instance to setup GSM" + ogsm = OraGSM(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(ogsm) + else: + msg="OP_TYPE must be set to {primaryshard|standbyshard|catalog|standbycatalog|gsm}" + self.ocommon.log_info_message(msg,self.file_name) + msg="Since OP_TYPE is set to nosetup, only compute env is being setup. Creating and calling instance to setup compute." + self.ocommon.log_info_message(msg,self.file_name) + omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + ofactory_obj.append(omachine) + + return ofactory_obj diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oragsm.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oragsm.py new file mode 100755 index 0000000..ef0bb06 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oragsm.py @@ -0,0 +1,2945 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +import os +import sys +import os.path +import re +import socket +import random +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +class OraGSM: + """ + This calss setup the Gsm after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraGsm class to setup the Gsm on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def setup(self): + """ + This function setup the Gsm on Primary DB. + """ + if self.ocommon.check_key("ADD_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.add_gsm_shard() + self.set_hostid_null() + self.add_invited_node("ADD_SHARD") + self.remove_invited_node("ADD_SHARD") + sys.exit(0) + if self.ocommon.check_key("DEPLOY_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.deploy_shard() + self.setup_gsm_service() + sys.exit(0) + elif self.ocommon.check_key("ADD_SGROUP_PARAMS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_gsm_shardg("ADD_SGROUP_PARAMS") + sys.exit(0) + elif self.ocommon.check_key("ADD_SSPACE_PARAMS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_gsm_sspace("ADD_SSPACE_PARAMS") + sys.exit(0) + elif self.ocommon.check_key("REMOVE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + status=self.remove_gsm_shard() + + if status: + sys.exit(0) + else: + sys.exit(1) + + elif self.ocommon.check_key("MOVE_CHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.move_shard_chunks() + sys.exit(0) + elif self.ocommon.check_key("TDE_KEY",self.ora_env_dict): + self.ocommon.get_tde_key() + sys.exit(0) + elif self.ocommon.check_key("CANCEL_CHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.cancel_move_chunks() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_NOCHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.validate_nochunks() + sys.exit(0) + elif self.ocommon.check_key("CHECK_ONLINE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.verify_online_shard() + sys.exit(0) + elif self.ocommon.check_key("CHECK_GSM_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.verify_gsm_shard() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.validate_gsm_shard() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_GSM",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + sys.exit(0) + elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + if os.path.exists(filename): + self.ocommon.log_info_message("provisioning is still in progress as file " + filename + " still exist!",self.file_name) + sys.exit(0) + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + status = self.check_gsm_director_status(None) + if not status: + self.ocommon.log_info_message("No GDS setup found on this system.",self.file_name) + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("GSM liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("INVITED_NODE_OP",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.invited_node_op() + sys.exit(0) + elif self.ocommon.check_key("CATALOG_SETUP",self.ora_env_dict): + # If user pass env avariable CATALOG_SETUP true then it will just create gsm director and add catalog but will not add any shard + # It will also add service + status = self.catalog_setup_checks() + if status == False: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.setup_machine() + self.catalog_checks() + self.reset_gsm_setup() + status1 = self.gsm_setup_check() + if status1: + self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) + self.start_gsm_director() + self.ocommon.log_info_message("Started GSM",self.file_name) + else: + # Perform Catalog setup after check GSM_MASTER FLAG. IF GSM MASTER FLAG is set then only catalog will be added. + self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) + master_flag=self.gsm_master_flag_check() + if master_flag: + self.setup_gsm_calog() + self.setup_gsm_director() + self.start_gsm_director() + self.status_gsm_director() + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': + self.setup_gsm_shardg("SHARD_GROUP") + else: + self.setup_gsm_shardg("SHARD_GROUP") + self.gsm_backup_file() + self.gsm_completion_message() + ### Running Custom Scripts + self.run_custom_scripts() + else: + self.add_gsm_director() + self.start_gsm_director() + self.gsm_backup_file() + self.gsm_completion_message() + else: + # This block run shard addition, catalog addition and service creation + # This block also verifies if master flag is not not GSM director then it will not create catalog but add GSM ony + self.setup_machine() + self.gsm_checks() + self.reset_gsm_setup() + status = self.gsm_setup_check() + if status: + self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) + self.start_gsm_director() + self.ocommon.log_info_message("Started GSM",self.file_name) + else: + # if the status = self.gsm_setup_check() return False then shard addition, catalog addition and service creation + master_flag=self.gsm_master_flag_check() + if master_flag: + self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) + self.setup_gsm_calog() + self.setup_gsm_director() + self.start_gsm_director() + self.status_gsm_director() + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': + self.setup_gsm_shardg("SHARD_GROUP") + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + self.setup_gsm_sspace("SHARD_SPACE") + else: + self.setup_gsm_shardg("SHARD_GROUP") + self.setup_gsm_shard() + self.set_hostid_null() + self.stop_gsm_director() + time.sleep(30) + self.start_gsm_director() + self.add_invited_node("SHARD") + self.remove_invited_node("SHARD") + self.stop_gsm_director() + time.sleep(30) + self.start_gsm_director() + self.deploy_shard() + self.setup_gsm_service() + self.setup_sample_schema() + self.gsm_backup_file() + self.gsm_completion_message() + ### Running Custom Scripts + self.run_custom_scripts() + else: + self.add_gsm_director() + self.start_gsm_director() + self.gsm_backup_file() + self.gsm_completion_message() + + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + filename = self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + touchfile = 'touch {0}'.format(filename) + if not os.path.isfile(filename): + self.ocommon.log_error_message("Setting file provisioning status file :" + filename ,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(touchfile,None,self.ora_env_dict) + if retcode == 1: + self.ocommon.log_error_message("error occurred while touching the file :" + filename + ". Exiting!",self.file_name) + self.ocommon.prog_exit("127") + + ########### ENDS here #################### + + def gsm_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.shard_user_check() + self.gsm_hostname_check() + self.director_params_checks() + self.catalog_params_check() + self.shard_params_check() + self.sgroup_params_check() + + + def catalog_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.shard_user_check() + self.gsm_hostname_check() + self.director_params_checks() + self.catalog_params_check() + self.sgroup_params_check() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit("127") + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def passwd_check(self): + """ + Set the password + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def shard_user_check(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def director_params_checks(self): + """ + This funnction check and set the shard director name + """ + status=False + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD Director PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + + def gsm_hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def catalog_params_check(self): + """ + This funnction check if CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''CATALOG PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + if stype: + if stype.lower() == 'user': + if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) + if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) + status=True + + if not status: + msg="CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is not set, exiting!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def shard_params_check(self): + """ + This funnction check if SHARD[1-9]_PARAMS such as SHARD1_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + + if not status: + msg="SHARD[1-9]_PARAMS such as SHARD1_PARAMS is not set, exiting!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def sgroup_params_check(self): + """ + This funnction check if SHARD[1-9]_GROUP_PARAMS such as SHARD1_GROUP_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD GROUP PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + def gsm_master_flag_check(self): + """ + This funnction check if MASTER_GSM is passed as an env variable or not. If not passed then exit. + """ + status=False + if self.ocommon.check_key("MASTER_GSM",self.ora_env_dict): + msg='''MASTER_GSM is set. This machine will be configured with as master GSM director.''' + self.ocommon.log_info_message(msg,self.file_name) + return True + else: + return False + + def catalog_setup_checks(self): + """ + This function checks if director and catalog is setup and connection is established. + """ + status = False + gsm_status = self.check_gsm_director(None) + #catalog_status = self.check_gsm_catalog() + + if gsm_status == 'completed': + status = True + else: + status = False + + #if catalog_status == 'completed': + # status = True + #else: + # status = False + + return status + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### + def reset_gsm_setup(self): + """ + This function delete the GSM files. + """ + self.ocommon.log_info_message("Inside reset_gsm_setup",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + cmd_list=[] + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + msg='''Deleteing files from {0}'''.format(gsmdata_loc) + self.ocommon.log_info_message(msg,self.file_name) + cmd_list[0]='''rm -f {0}/gsm.ora'''.format(gsmdata_loc) + cmd_list[1]='''rm -f {0}/tnsnames.ora'''.format(gsmdata_loc) + cmd_list[2]='''rm -rf {0}/wallets'''.format(gsmdata_loc) + for cmd in cmd_list: + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + def gsm_setup_check(self): + """ + This function check if GSM is already setup on this + """ + status=True + self.ocommon.log_info_message("Inside gsm_setup_check",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) + + gsmora='''{0}/gsm.ora'''.format(gsmdata_loc) + tnsnamesora='''{0}/tnsnames.ora'''.format(gsmdata_loc) + walletloc='''{0}/gsmwallet'''.format(gsmdata_loc) + + if os.path.isfile(gsmora): + cmd='''cp -r -v -f {0} {1}/'''.format(gsmora,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if os.path.isfile(tnsnamesora): + cmd='''cp -r -v -f {0} {1}/'''.format(tnsnamesora,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if os.path.isdir(walletloc): + cmd='''cp -r -v -f {0} {1}/'''.format(walletloc,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if status: + return True + else: + return False + + #################### Catalog related Functions BEGINS Here ########################### + def setup_gsm_calog(self): + """ + This function setup the GSM catalog. + """ + self.ocommon.log_info_message("Inside setup_gsm_calog()",self.file_name) + status=False + reg_exp= self.catalog_regex() + counter=1 + end_counter=60 + catalog_db_status=None + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + catalog_db_status=self.check_setup_status(catalog_host,catalog_db,catalog_pdb,catalog_port) + if catalog_db_status == 'completed': + self.configure_gsm_clog(catalog_host,catalog_db,catalog_pdb,catalog_port,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname) + break + else: + msg='''Catalog Status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + if catalog_db_status == 'completed': + break + else: + msg='''Catalog setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + def process_clog_vars(self,key): + """ + This function process catalog vars based on key and return values to configure the GSM + """ + catalog_db=None + catalog_pdb=None + catalog_port=None + catalog_region=None + catalog_host=None + catalog_name=None + catalog_chunks=None + repl_type=None + repl_factor=None + repl_unit=None + stype=None + sspace=None + cfname=None + + self.ocommon.log_info_message("Inside process_clog_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'catalog_db': + catalog_db = cvar_dict[ckey] + if ckey == 'catalog_pdb': + catalog_pdb = cvar_dict[ckey] + if ckey == 'catalog_port': + catalog_port = cvar_dict[ckey] + if ckey == 'catalog_region': + catalog_region = cvar_dict[ckey] + if ckey == 'catalog_host': + catalog_host = cvar_dict[ckey] + if ckey == 'catalog_name': + catalog_name = cvar_dict[ckey] + if ckey == 'catalog_chunks': + catalog_chunks = cvar_dict[ckey] + if ckey == 'repl_type': + repl_type = cvar_dict[ckey] + if ckey == 'repl_factor': + repl_factor = cvar_dict[ckey] + if ckey == 'repl_unit': + repl_unit = cvar_dict[ckey] + if ckey == 'sharding_type': + stype = cvar_dict[ckey] + if ckey == 'shard_space': + sspace = cvar_dict[ckey] + if ckey == 'shard_configname': + cfname = cvar_dict[ckey] + + ## Set the values if not set in above block + if not catalog_port: + catalog_port=1521 + if not catalog_region: + catalog_region="region1,region2" + if stype: + if not sspace: + sspace="shardspace1,shardspace2" + + ### Check values must be set + if catalog_host and catalog_db and catalog_pdb and catalog_port and catalog_region and catalog_name: + return catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname + else: + msg1='''catalog_db={0},catalog_pdb={1}'''.format((catalog_db or "Missing Value"),(catalog_pdb or "Missing Value")) + msg2='''catalog_port={0},catalog_host={1}'''.format((catalog_port or "Missing Value"),(catalog_host or "Missing Value")) + msg3='''catalog_region={0},catalog_name={1}'''.format((catalog_region or "Missing Value"),(catalog_name or "Missing Value")) + msg='''Catalog params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def check_gsm_catalog(self): + """ + This function check the catalog status in GSM + """ + self.ocommon.log_info_message("Inside check_gsm_catalog()",self.file_name) + #dtrname,dtrport,dtregion=self.process_director_vars() + gsmcmd=''' + config; + exit; + '''.format("test") + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + match=self.ocommon.check_substr_match(matched_output[0],"test") + except: + match=False + return(self.ocommon.check_status_value(match)) + + # output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + # new_output=output[0].replace(" ","") + # self.ocommon.log_info_message(new_output,self.file_name) + # match=self.ocommon.check_substr_match(new_output,"Catalogconnectionisestablished") + # return(self.ocommon.check_status_value(match)) + + def catalog_regex(self): + """ + This function return the rgex to search the CATALOG PARAMS + """ + self.ocommon.log_info_message("Inside catalog_regex()",self.file_name) + return re.compile('CATALOG_PARAMS') + + + def configure_gsm_clog(self,chost,ccdb,cpdb,cport,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname): + """ + This function configure the GSM catalog. + """ + self.ocommon.log_info_message("Inside configure_gsm_clog()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + replist=['native'] + + ### User Define Shardig Variables + shardingtype=None + shardspace=None + configname=None + + # if stype and sspace: + if stype: + if stype.lower() == 'user': + shardingtype="-sharding user" + #shardspace="" + shardspace=" -shardspace {0}".format(sspace) + if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) + if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) + else: + shardspace="" + shardingtype="" + else: + shardspace="" + shardingtype="" + + if cfname: + configname=" -configname {0}".format(cfname) + else: + configname="" + + ### SNR Sharding + chunks=None + repl=None + repfactor=None + repunits=None + + if catalog_chunks: + chunks="-chunks {0}".format(catalog_chunks) + else: + chunks="" + + if repl_type and repl_type.lower() in replist: + self.ocommon.log_info_message("Repl_Type value Set to in block1:" + repl_type,self.file_name) + repl=" -repl {0}".format(repl_type) + else: + repl="" + + if repl_factor: + repfactor=" -repfactor {0}".format(repl_factor) + else: + repfactor="" + + if repl_unit: + repunits=" -repunits {0}".format(repl_unit) + else: + repunits="" + + invited_subnet="" + add_invited_subnet="" + if self.ocommon.check_key("INVITED_NODE_SUBNET_FLAG",self.ora_env_dict): + if self.ocommon.check_key("INVITED_NODE_SUBNET",self.ora_env_dict): + invited_subnet=self.ora_env_dict["INVITED_NODE_SUBNET"] + else: + #self.ocommon.log_info_message("The catalog Host name is :" + chost,self.file_name) + chost_ip=self.ocommon.get_ip(chost,None) + ip_parts=chost_ip.split('.') + invited_subnet=ip_parts[0] + "." + ip_parts[1] + '.*' + '.*' + add_invited_subnet='''add invitedsubnet {0};'''.format(invited_subnet) + + cpasswd="HIDDEN_STRING" + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})))\" {7} -user {3}/{4} -sdb {5} -region {6} -agent_port 8080 -agent_password {4} {8} {9} {10} {11} {12} {13} -autovncr off; + add invitednode {0}; + {14} + exit; + '''.format(chost,cport,cpdb,cadmin,cpasswd,catalog_name,catalog_region,chunks,repl,repfactor,repunits,shardingtype,shardspace,configname,add_invited_subnet) + + counter=1 + while counter < 5: + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + if retcode != 0: + self.ocommon.log_info_message("Error occurred while creating the shard catalog, sleeping for 60 seconds",self.file_name) + counter = counter + 1 + time.sleep(60) + else: + break + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ######################################## GSM director Functions Begins Here ##################### + def process_director_vars(self,key): + """ + This function process GSM director vars based on key and return values to configure the GSM + """ + dtrname=None + dtrport=None + dtregion=None + + self.ocommon.log_info_message("Inside process_director_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'director_name': + dtrname = cvar_dict[ckey] + if ckey == 'director_port': + dtrport = cvar_dict[ckey] + if ckey == 'director_region': + dtregion = cvar_dict[ckey] + + ### Check values must be set + if dtrname and dtrport and dtregion: + return dtrname,dtrport,dtregion + else: + msg1='''director_name={0},director_port={1}'''.format((dtrname or "Missing Value"),(dtrport or "Missing Value")) + msg2='''director_region={0}'''.format((dtregion or "Missing Value")) + msg='''Director params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_gsm_director(self,dname): + """ + This function check the GSM director status + """ + self.ocommon.log_info_message("Inside check_gsm_director()",self.file_name) + status=False + if dname: + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(matched_output[0],dname): + status=True + except: + status=False + else: + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(matched_output[0],dname): + status=True + except: + status=False + + return(self.ocommon.check_status_value(status)) + + def check_gsm_region(self,region): + """ + This function check the GSM regions + """ + self.ocommon.log_info_message("Inside check_gsm_region()",self.file_name) + gsmcmd=self.get_gsm_config_cmd(None) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Regions\n)(?:.+\n)+",output) + status=False + try: + if self.ocommon.check_substr_match(matched_output[0],region): + status=True + except: + status=False + return(self.ocommon.check_status_value(status)) + + def check_gsm_shardspace(self,sspace): + """ + This function check the GSM shardspace + """ + self.ocommon.log_info_message("Inside check_gsm_shardspace()",self.file_name) + gsmcmd=self.get_gsm_config_cmd(None) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard spaces\n)(?:.+\n)+",output) + status=False + try: + if self.ocommon.check_substr_match(matched_output[0],sspace): + status=True + except: + status=False + return(self.ocommon.check_status_value(status)) + + def check_gsm_director_status(self,dname): + """ + This function check the GSM director status using 'gdsctl status' + """ + self.ocommon.log_info_message("Inside check_gsm_director_status()",self.file_name) + status=False + gsmcmd=''' + status; + exit; + ''' + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + if "Connected to GDS catalog Y".replace(" ","").lower() in output.replace(" ","").lower(): + return True + else: + return False + + def add_gsm_director(self): + """ + This function add the GSM + """ + status=False + counter=1 + end_counter=60 + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + reg_exp= self.director_regex() + + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_director_status=None + dtrname,dtrport,dtregion=self.process_director_vars(key) + shard_director_status=self.check_gsm_director(dtrname) + if shard_director_status != 'completed': + self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) + status = self.check_gsm_director(None) + if status == 'completed': + break + + if status == 'completed': + break + else: + msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + status = self.check_gsm_director(None) + if status == 'completed': + msg='''Shard director setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 60 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def setup_gsm_director(self): + """ + This function setup in GSM + """ + self.ocommon.log_info_message("Inside setup_gsm_director()",self.file_name) + status=False + reg_exp= self.director_regex() + counter=1 + end_counter=3 + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_director_status=None + dtrname,dtrport,dtregion=self.process_director_vars(key) + shard_director_status=self.check_gsm_director(dtrname) + if shard_director_status != 'completed': + self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) + status = self.check_gsm_director(None) + if status == 'completed': + break + else: + msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + time.sleep(60) + counter=counter+1 + + status = self.check_gsm_director(None) + if status == 'completed': + msg='''Shard director setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 3 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin): + """ + This function configure GSM director + """ + ## Getting the values of catalog_port,catalog_pdb,catalog_host + cpasswd="HIDDEN_STRING" + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sregionFlag=self.check_gsm_region(dtregion) + if sregionFlag != 'completed': + self.configure_gsm_region(dtregion) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + add gsm -gsm {0} -listener {1} -pwd {2} -catalog {3}:{4}/{5} -region {6}; + exit; + '''.format(dtrname,dtrport,cpasswd,catalog_host,catalog_port,catalog_pdb,dtregion,gsmhost) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def start_gsm_director(self): + """ + This function start the director in the GSM + """ + status='noval' + self.ocommon.log_info_message("Inside start_gsm_director() function",self.file_name) + reg_exp= self.director_regex() + counter=1 + end_counter=10 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=''' + start gsm -gsm {0}; + exit; + '''.format(dtrname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + status=self.check_gsm_director(dtrname) + if status == 'completed': + break; + if status == 'completed': + filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + remfile='''rm -f {0}'''.format(filename) + if os.path.isfile(filename): + output,error,retcode=self.ocommon.execute_cmd(remfile,None,self.ora_env_dict) + break + else: + msg='''GSM shard director failed to start.Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_error_message(msg,self.file_name) + time.sleep(30) + + counter=counter+1 + + + if status != 'completed': + msg='''GSM shard director failed to start.Exiting!''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def stop_gsm_director(self): + """ + This function stop the director in the GSM + """ + status=False + self.ocommon.log_info_message("Inside stop_gsm_director() function",self.file_name) + reg_exp= self.director_regex() + counter=1 + end_counter=2 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=''' + stop gsm -gsm {0}; + exit; + '''.format(dtrname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + counter=counter+1 + + def status_gsm_director(self): + """ + This function check the GSM director status + """ + gsm_status = self.check_gsm_director(None) + #catalog_status = self.check_gsm_catalog() + + if gsm_status == 'completed': + msg='''Director setup completed in GSM and catalog is connected''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard director in GSM did not complete or not connected to catalog. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + ######################################## Shard Group Setup Begins Here ############################ + def setup_gsm_shardg(self,restype): + """ + This function setup the shard group. + """ + self.ocommon.log_info_message("Inside setup_gsm_shardg()",self.file_name) + status=False + if restype == 'ADD_SGROUP_PARAMS': + reg_exp = self.add_shardg_regex() + elif restype == 'SHARD_GROUP': + reg_exp = self.shardg_regex() + else: + self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SGROUP_PARAMS or SHARD_GROUP key to create a shard group",self.file_name) + self.ocommon.log_warn_message("Since no key specified for ADD_SGROUP_PARAMS and SHARD_GROUP, shardgroup will be created during shard creation",self.file_name) + + sgListC=[] + sgListP=[] + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_group_status=None + self.ocommon.log_info_message("Key is set to : " + key,self.file_name) + group_name,deploy_as,group_region=self.process_shardg_vars(key) + self.ocommon.log_info_message("Name: " + group_name + "deploy_as" + deploy_as + "group_region" + group_region,self.file_name) + if group_name is not None: + if group_name not in sgListC: + dtrname=self.get_director_name(group_region) + shard_group_status=self.check_shardg_status(group_name,dtrname) + if shard_group_status != 'completed': + self.configure_gsm_shardg(group_name,deploy_as,group_region,'add') + shard_group_status = self.check_shardg_status(group_name,None) + if shard_group_status == 'completed': + sgListC.append(group_name) + if group_name in sgListP: + sgListP.remove(group_name) + else: + sgListP=sgListP.append(group_name) + time.sleep(30) + counter=counter + 1 + + if sgListP == []: + msg='''Shard group setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def get_director_name(self,region_name): + """ + This function get the director name based on the region + """ + self.ocommon.log_info_message("Inside get_director_name()",self.file_name) + status=False + director_name=None + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + director_name=dtrname + gsm_status = self.check_gsm_director(dtrname) + if gsm_status == 'completed': + status = True + else: + status = False + if dtregion == region_name: + break + if status: + if director_name: + return director_name + else: + self.ocommon.log_error_message("No director exist to match the region",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.log_error_message("Shard Director is not running!",self.file_name) + self.ocommon.prog_exit("127") + + def get_shardg_region_name(self,sgname): + """ + This function get the region name based on shard group name + """ + self.ocommon.log_info_message("Inside get_region_name()",self.file_name) + status=False + region_name=None + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + group_name,deploy_as,group_region=self.process_shardg_vars(key) + region_name=group_region + if sgname == group_name: + status=True + break + if status: + return region_name + else: + self.ocommon.log_error_message("No such shard group exist! exiting!",self.file_name) + self.ocommon.prog_exit("127") + + def process_shardg_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + group_name=None + deploy_as=None + group_region=None + + self.ocommon.log_info_message("Inside process_shardg_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'group_name': + group_name = cvar_dict[ckey] + if ckey == 'deploy_as': + deploy_as = cvar_dict[ckey] + if ckey == 'group_region': + group_region = cvar_dict[ckey] + + ### Check values must be set + if group_name and deploy_as and group_region: + return group_name,deploy_as,group_region + else: + msg1='''group_name={0},deploy_as={1}'''.format((group_name or "Missing Value"),(deploy_as or "Missing Value")) + msg2='''group_region={0}'''.format((group_region or "Missing Value")) + msg='''Shard group params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + + def check_shardg_status(self,group_name,dname): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_shardg_status()",self.file_name) + status=False + + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) + if self.ocommon.check_substr_match(matched_output[0],group_name): + status=True + else: + status=False + + ''' + else: + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + group_name,deploy_as,group_region=self.process_shardg_vars(key) + dname=self.get_director_name(group_region) + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) + # match=re.search("(?i)(?m)"+group_name,matched_output) + if self.ocommon.check_substr_match(matched_output[0],group_name): + status=True + else: + status=False + ''' + + return(self.ocommon.check_status_value(status)) + +############################################# Director Related Block ############ + def get_director_name(self,region_name): + """ + This function get the director name based on the region + """ + self.ocommon.log_info_message("Inside get_director_name()",self.file_name) + status=False + director_name=None + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + director_name=dtrname + gsm_status = self.check_gsm_director(dtrname) + if gsm_status == 'completed': + status = True + else: + status = False + if dtregion == region_name: + break + if status: + if director_name: + return director_name + else: + self.ocommon.log_error_message("No director exist to match the region",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.log_error_message("Shard Director is not running!",self.file_name) + self.ocommon.prog_exit("127") + +######## + + def get_gsm_config_cmd(self,dname): + """ + Get the GSM config command + """ + self.ocommon.log_info_message("Inside get_gsm_config_cmd()",self.file_name) + gsmcmd=''' + config; + exit; + '''.format("test") + return gsmcmd + + def director_regex(self): + """ + This function return the rgex to search the SHARD DIRECTOR PARAMS + """ + self.ocommon.log_info_message("Inside director_regex()",self.file_name) + return re.compile('SHARD_DIRECTOR_PARAMS') + + def shardg_regex(self): + """ + This function return the rgex to search the SHARD GROUP PARAMS + """ + self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) + return re.compile('SHARD[0-9]+_GROUP_PARAMS') + + def add_shardg_regex(self): + """ + This function return the rgex to search the SHARD GROUP PARAMS + """ + self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) + return re.compile('ADD_SGROUP_PARAMS') + + def configure_gsm_shardg(self,group_name,deploy_as,group_region,type): + """ + This function configure the Shard Group. + """ + self.ocommon.log_info_message("Inside configure_gsm_shardg()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + dtrname=self.get_director_name(group_region) + reg_exp= self.catalog_regex() + if type == 'modify': + cmd=''' modify shardgroup -shardgroup {0} '''.format(group_name) + else: + cmd=''' add shardgroup -shardgroup {0} '''.format(group_name) + + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + if repl_type: + cmd=cmd + " -region {0} ".format(group_region) + else: + cmd=cmd + " -deploy_as {0} -region {1} ".format(deploy_as,group_region) + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + exit; + '''.format("NA",cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + +############# Adding Shard Regions ############### + def configure_gsm_region(self,region): + """ + This function configure the Shard region. + """ + self.ocommon.log_info_message("Inside configure_gsm_region()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + add region -region {3}; + exit; + '''.format("NA",cadmin,cpasswd,region) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + +##################### Adding Shard Space ############### + def process_sspace_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + sspace=None + chunks=None + repfactor=None + repunits=None + protectedmode=None + self.ocommon.log_info_message("Inside process_sspace_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'sspace_name': + sspace = cvar_dict[ckey] + if ckey == 'chunks': + chunks = cvar_dict[ckey] + if ckey == 'repfactor': + repfactor = cvar_dict[ckey] + if ckey == 'repunits': + repunits = cvar_dict[ckey] + if ckey == 'protectedmode': + protectedmode = cvar_dict[ckey] + + ### Check values must be set + if sspace: + return sspace,chunks,repfactor,repunits,protectedmode + else: + msg1='''sspace={0}'''.format((sspace or "Missing Value")) + msg='''Shard space params {0} is not set correctly. One or more value is missing {1}'''.format(key,msg1) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def setup_gsm_sspace(self,restype): + """ + This function setup the shard sspace. + """ + self.ocommon.log_info_message("Inside setup_gsm_sspace()",self.file_name) + status=False + if restype == 'ADD_SSPACE_PARAMS': + reg_exp = self.add_shardg_regex() + elif restype == 'SHARD_SPACE': + reg_exp = self.shardg_regex() + else: + self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SSPACE_PARAMS or SHARD_SPACE key to create a shard space",self.file_name) + self.ocommon.log_warn_message("Since no ADD_SSPACE_PARAMS or SHARD_SPACE defined, shardspace will be created during shard creation",self.file_name) + counter=1 + ssListC=[] + ssListP=[] + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_space_status=None + sspace,chunks,repfactor,repuntis,protectedmode=self.process_sspace_vars(key) + if sspace is not None: + if sspace not in ssListC: + shard_sspace_status=self.check_gsm_shardspace(sspace) + if shard_sspace_status != 'completed': + self.configure_gsm_sspace(sspace,chunks,repfactor,repuntis,protectedmode,'add') + shard_space_status = self.check_gsm_shardspace(sspace) + if shard_sspace_status == 'completed': + ssListC.append(sspace) + if sspace in sgListP: + sgListP.remove(sspace) + else: + sgListP=sgListP.append(sspace) + time.sleep(30) + counter=counter + 1 + + if ssListP == []: + msg='''Shard space setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete shard space setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def configure_gsm_sspace(self,sspace,chunks,repfactor,repunits,protectedmode,type): + """ + This function configure the Shard Group. + """ + self.ocommon.log_info_message("Inside configure_gsm_sspace()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + if type == 'MODIFY': + cmd=''' modify shardspace -shardspace {0} '''.format(sspace) + else: + cmd=''' add shardspace -shardspace {0} '''.format(sspace) + if chunks is not None: + cmd = cmd + ''' -chunks {0}'''.format(chunks) + if repfactor: + cmd = cmd + ''' -repfactor {0}'''.format(repfactor) + if repunits is not None: + cmd = cmd + ''' -repunits {0}'''.format(repfactor) + if protectedmode is not None: + cmd = cmd + ''' -protectedmode {0}'''.format(protectedmode) + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + exit; + '''.format("NA",cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + #########################################Shard Function Begins Here ############################## + def setup_gsm_shard(self): + """ + This function setup and add shard in the GSM + """ + self.ocommon.log_info_message("Inside setup_gsm_shard()",self.file_name) + status=False + reg_exp= self.shard_regex() + counter=1 + end_counter=60 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,sregion,sspace=self.process_shard_vars(key) + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + if shard_db_status == 'completed': + self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,sregion,sspace) + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + status = self.check_shard_status(None) + if status == 'completed': + break + else: + msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + status = self.check_shard_status(None) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 60 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def add_gsm_shard(self): + """ + This function add the shard in the GSM + """ + self.ocommon.log_info_message("Inside add_gsm_shard()",self.file_name) + status=False + reg_exp= self.add_shard_regex() + counter=1 + end_counter=3 + shard_name="none" + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + self.ocommon.log_info_message("Shard Status : " + shard_db_status,self.file_name) + if shard_db_status == 'completed': + self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,shard_region,shard_space) + counter2=1 + end_counter2=5 + while counter2 < end_counter2: + status1 = self.check_shard_status(shard_name) + if status1 == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + break + else: + msg='''Shard DB is still not added in GSM. Sleeping for 60 seconds''' + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter2=counter2+1 + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + status = self.check_shard_status(None) + if status == 'completed': + break + else: + msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + status = self.check_shard_status(shard_name) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 3 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def remove_gsm_shard(self): + """ + This function remove the shard in the GSM + """ + self.ocommon.log_info_message("Inside remove_gsm_shard()",self.file_name) + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars("CATALOG_PARAMS") + numOfShards=self.count_online_shards() + status=False + reg_exp=self.remove_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shardname_to_delete=shard_db + "_" + shard_pdb + if repl_type is not None: + if(repl_type.upper() == 'NATIVE'): + self.move_shards_leader_rus(shardname_to_delete) + leaderCount=self.count_leader_shards(shardname_to_delete) + if(numOfShards < 4 or leaderCount > 0): + msg='''ruType=[{0}]. NumofShards=[{1}]. LeaderCount=[{2}]. Ignoring remove of shard [{3}]'''.format(repl_type,numOfShards,leaderCount,shardname_to_delete) + self.ocommon.log_info_message(msg,self.file_name) + break + + self.move_shard_rus(shardname_to_delete,None,None) + while self.count_shard_rus(shardname_to_delete) > 0: + self.ocommon.log_info_message("Waiting for all the shard chunks to be moved.",self.file_name) + time.sleep(15) + + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + if shard_db_status == 'completed': + self.delete_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group) + status=True + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + return status + + def move_shards_leader_rus(self,shardname_to_delete): + """ + This function move the shard leader RUs + """ + shards=self.get_online_shards() + leader_ru=self.get_rus(shardname_to_delete) + all_ru=self.get_rus(None) + count=0 + target_shards=[] + value=0 + + if len(shards) == 0: + msg="""No Shard is online so no RU is available to be moved""" + self.ocommon.log_info_message(msg,self.file_name) + else: + for line in leader_ru: + value=None + count += 1 + cols=line.split() + if len(cols) > 0: + if cols[0].lower() == shardname_to_delete.lower(): + if cols[1].isdigit: + value = int(cols[1]) + else: + continue + + target_shards.clear() + for line1 in all_ru: + cols1=line1.split() + print(cols1) + if len(cols1) > 5: + if cols1[0].lower() != shardname_to_delete.lower() and cols1[1].isdigit and cols1[2].lower() == 'follower': + if value is not None: + if int(cols1[1]) == value: + target_shards.append(cols1[0]) + break + + for shard in shards: + if shard.lower() != shardname_to_delete.lower(): + if shard in target_shards: + msg="Shard_name= " + shard + " Status=True" + " Value = " + str(value) + self.ocommon.log_info_message(msg,self.file_name) + self.move_shard_rus(shardname_to_delete,shard,value) + + def move_shard_chunks(self): + """ + This function move the shard chunks + """ + self.ocommon.log_info_message("Inside move_shard_chunks()",self.file_name) + status=False + reg_exp= self.move_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + shard_num = self.count_online_shards() + online_shard = self.check_online_shard(shard_name) + if shard_num > 1 and online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + MOVE CHUNK -CHUNK ALL -SOURCE {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def validate_nochunks(self): + """ + This function check the chnunks + """ + self.ocommon.log_info_message("Inside validate_nochunks()",self.file_name) + status=False + reg_exp= self.move_nochunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + shard_num = self.count_online_shards() + online_shard = self.check_online_shard(shard_name) + if shard_num > 1 and online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config chunks -shard {0} + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + matched_output=re.findall("(?:Chunks\n)(?:.+\n)+",output) + if self.ocommon.check_substr_match(matched_output[0].lower(),shard_name.lower()): + self.ocommon.prog_exit("127") + + def move_chunks_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside move_chnuks_regex()",self.file_name) + return re.compile('MOVE_CHUNKS') + + def move_nochunks_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside move_nochunks_regex()",self.file_name) + return re.compile('VALIDATE_NOCHUNKS') + + def check_shard_chunks(self): + """ + This function check the shard chunks + """ + self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) + status=False + reg_exp= self.check_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config chunks -shard {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + + def check_chunks_regex(self): + """ + This function return the rgex to search the chunks + """ + self.ocommon.log_info_message("Inside check_chunks_regex()",self.file_name) + return re.compile('CHECK_CHUNKS') + + def cancel_move_chunks(self): + """ + This function cancel the shard Chunks + """ + self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) + status=False + reg_exp= self.cancel_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 1: + self.ocommon.log_info_message("Shard is not online. Performing chunk cancellation in GSM to set the shard chunk status.",self.file_name) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + ALTER MOVE -cancel -SHARD {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + else: + self.ocommon.log_info_message("Shard " + shard_name + " is online. Unable to perform chunk cancellation.",self.file_name) + + def cancel_chunks_regex(self): + """ + This function return the cancel chunk movement + """ + self.ocommon.log_info_message("Inside cancel_chunks_regex()",self.file_name) + return re.compile('CANCEL_CHUNKS') + + def verify_online_shard(self): + """ + This function verify online shard + """ + self.ocommon.log_info_message("Inside verify_online_shard()",self.file_name) + status=False + reg_exp= self.online_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 0: + msg='''Shard {0} is online.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} is not online.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + + def online_shard_regex(self): + """ + This function return the rgex to search the ONLINE Shards + """ + self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) + return re.compile('CHECK_ONLINE_SHARD') + + def check_online_shard(self,shard_name): + """ + This function check the online shard + """ + self.ocommon.log_info_message("Inside check_online_shard()",self.file_name) + name_flag = False + availability_flag = False + state_flag = False + status_flag = False + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config shard -shard {0}; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + lines = output.split("\n") + for line in lines: + list1 = line.split(":") + if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): + name_flag = True + if list1[0].strip().lower() == 'Availability'.lower() and list1[1].strip().lower() == 'ONLINE'.lower(): + availability_flag = True + if list1[0].strip().lower() == 'STATUS'.lower() and list1[1].strip().lower() == 'OK'.lower(): + status_flag = True + if list1[0].strip().lower() == 'STATE'.lower() and list1[1].strip().lower() == 'DEPLOYED'.lower(): + state_flag = True + + del list1[:] + + if name_flag and availability_flag and state_flag and status_flag: + return 0 + else: + return 1 + + def verify_gsm_shard(self): + """ + This function verify GSM shard + """ + self.ocommon.log_info_message("Inside verify_gsm_shard()",self.file_name) + status=False + reg_exp= self.check_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + gsm_shard = self.check_gsm_shard(shard_name) + if gsm_shard == 0: + msg='''Shard {0} is present in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} is not present in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + def check_shard_regex(self): + """ + This function return the rgex to search the Shards in GSM + """ + self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) + return re.compile('CHECK_GSM_SHARD') + + def check_gsm_shard(self,shard_name): + """ + This function check the shard in gsm + """ + self.ocommon.log_info_message("Inside check_gsm_shard()",self.file_name) + name_flag = False + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config shard -shard {0}; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + lines = output.split("\n") + for line in lines: + list1 = line.split(":") + if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): + name_flag = True + + del list1[:] + + if name_flag: + return 0 + else: + return 1 + + def count_online_shards(self): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside count_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + config shard; + exit; + '''.format(cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + online_shard = 0 + lines = output.split("\n") + for line in lines: + if re.search('ok', line, re.IGNORECASE): + if re.search('deployed', line, re.IGNORECASE): + if re.search('online', line, re.IGNORECASE): + online_shard = online_shard + 1 + + return online_shard + + def get_online_shards(self): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + config shard; + exit; + '''.format(cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + shards=[] + online_shard = 0 + for line in output.split("\n"): + cols=line.split() + print(cols) + if len(cols) >= 5: + if cols[5].lower() == "online" and cols[2].lower() == "ok": + shards.append(cols[0]) + + return shards + + def get_rus(self,shardname_to_delete): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd=None + if shardname_to_delete is not None: + cmd='''status ru -leaders -shard {0}'''.format(shardname_to_delete) + else: + cmd='''status ru''' + + gsmcmd=''' + connect {0}/{1}; + {2}; + exit; + '''.format(cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + return output.split('\n') + + def move_shard_rus(self,sshard,tshard,runum): + """ + This function move the shard rus + """ + self.ocommon.log_info_message("Inside move_shard_rus()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd1="" + cmd2="" + shardname=sshard + if tshard is not None and runum is not None: + cmd1='''switchover ru -RU {0} -shard {1}'''.format(runum,tshard) + else: + cmd1='''MOVE RU -RU ALL -SOURCE {0}'''.format(shardname) + + gsmcmd=''' + connect {1}/{2}; + configure -verbose off -save_config; + {3}; + status RU -shard {0}; + exit; + '''.format(shardname,cadmin,cpasswd,cmd1,cmd2) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def count_shard_rus(self,shardname): + """ + This function return the returns the count of online shard chunks + """ + self.ocommon.log_info_message("Inside count_shard_chunks()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + status ru -shard {2}; + exit; + '''.format(cadmin,cpasswd,shardname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ru_count = 0 + lines = output.split("\n") + for line in lines: + if re.search(shardname, line, re.IGNORECASE): + ru_count = ru_count + 1 + + return ru_count + + def count_leader_shards(self,shardName): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside count_leader_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + status ru -shard {2} -leaders; + exit; + '''.format(cadmin,cpasswd,shardName) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + leader_shard = 0 + lines = output.split("\n") + for line in lines: + if re.search('ok', line, re.IGNORECASE): + if re.search('Leader', line, re.IGNORECASE): + leader_shard = leader_shard + 1 + + return leader_shard + + def validate_gsm_shard(self): + """ + This function validate the shard in the GSM + """ + self.ocommon.log_info_message("Inside validate_gsm_shard()",self.file_name) + status=False + reg_exp= self.validate_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + status = self.check_shard_status(shard_name) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} info does not exist in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + def process_shard_vars(self,key): + """ + This function process sgard vars based on key and return values to configure the GSM + """ + shard_db=None + shard_pdb=None + shard_port=None + shard_group=None + shard_host=None + shard_region=None + shard_space=None + shard_deploy_as=None + + self.ocommon.log_info_message("Inside process_shard_vars()",self.file_name) + # self.ocommon.log_info_message(key,self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_str=cvar_str.replace('"', '') + # self.ocommon.log_info_message(cvar_str,self.file_name) + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + # self.ocommon.log_info_message("key : " + ckey,self.file_name) + # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) + if ckey == 'shard_db': + shard_db = cvar_dict[ckey] + if ckey == 'shard_pdb': + shard_pdb = cvar_dict[ckey] + if ckey == 'shard_port': + shard_port = cvar_dict[ckey] + if ckey == 'shard_group': + shard_group = cvar_dict[ckey] + if ckey == 'shard_host': + shard_host = cvar_dict[ckey] + if ckey == 'shard_region': + #shard_region = self.validate_shard_param("region",cvar_dict[ckey]) + shard_region=cvar_dict[ckey] + if ckey == 'deploy_as': + shard_deploy_as=cvar_dict[ckey] + if ckey == 'shard_space': + #shard_space = self.validate_shard_param("shardspace",cvar_dict[ckey]) + shard_space=cvar_dict[ckey] + # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) + ## Set the values if not set in above block + if not shard_port: + shard_port=1521 + + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + shard_group="nogrp" + if not shard_deploy_as: + self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS","primary",self.ora_env_dict) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS",shard_deploy_as,self.ora_env_dict) + + ### Check values must be set + if shard_host and shard_db and shard_pdb and shard_port and shard_group: + return shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space + else: + msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) + msg2='''shard_port={0},shard_host={1}'''.format((shard_port or "Missing Value"),(shard_host or "Missing Value")) + msg3='''shard_group={0}'''.format((shard_group or "Missing Value")) + msg='''Shard DB params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def validate_shard_param(self,param_type,value): + """ + This function validaet the shard param such as region and shardspace + """ + status=False + reg_exp= self.catalog_regex() + stype=None + sspace=None + catalog_region=None + self.ocommon.log_info_message("Processing GSM params to verify the region and shardspace",self.file_name) + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + + if param_type == 'region': + if stype: + status=self.ocommon.find_str_in_string(catalog_region,'comma',value) + if status: + + return value + else: + return "" + + if param_type == 'shardspace': + if sspace: + status=self.ocommon.find_str_in_string(sspace,'comma',value) + if status: + return value + else: + return "" + + return False + + def process_chunks_vars(self,key): + """ + This function process the chunks vars + """ + shard_db=None + shard_pdb=None + self.ocommon.log_info_message("Inside process_chunks_vars()",self.file_name) + # self.ocommon.log_info_message(key,self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_str=cvar_str.replace('"', '') + # self.ocommon.log_info_message(cvar_str,self.file_name) + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + # self.ocommon.log_info_message("key : " + ckey,self.file_name) + # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) + if ckey == 'shard_db': + shard_db = cvar_dict[ckey] + if ckey == 'shard_pdb': + shard_pdb = cvar_dict[ckey] + # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) + ## Set the values if not set in above block + + ### Check values must be set + if shard_pdb and shard_db: + return shard_db,shard_pdb + else: + msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) + self.ocommon.log_info_message(msg1,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_shard_status(self,shard_name): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_shard_status()",self.file_name) + #gsmcmd=self.get_gsm_config_cmd(dname) + gsmcmd=''' + config; + exit; + ''' + counter=1 + end_counter=3 + status=False + while counter < end_counter: + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + error_check=re.findall("(?:GSM-45034\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(error_check[0],"GSM-45034"): + count = counter + 1 + self.ocommon.log_info_message("Issue in catalog connection, retrying to connect to catalog in 30 seconds!",self.file_name) + time.sleep(20) + status=False + continue + except: + status=False + matched_output=re.findall("(?:Databases\n)(?:.+\n)+",output) + if shard_name: + try: + if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): + status=True + break + else: + status=False + except: + status=False + else: + reg_exp= self.shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_region,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + try: + if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): + status=True + else: + status=False + except: + status=False + if status: + break; + counter = counter + 1 + + return(self.ocommon.check_status_value(status)) + + def shard_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside shard_regex()",self.file_name) + return re.compile('SHARD[0-9]+_PARAMS') + + def add_shard_regex(self): + """ + This function return the rgex to search the ADD_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside add_shard_regex()",self.file_name) + return re.compile('ADD_SHARD') + + def remove_shard_regex(self): + """ + This function return the rgex to search the REMOVE_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) + return re.compile('REMOVE_SHARD') + + def validate_shard_regex(self): + """ + This function return the rgex to search the VALIDATE_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) + return re.compile('VALIDATE_SHARD') + + def configure_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup,sregion,sspace): + """ + This function configure the shard db. + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + #dtrname,dtrport,dtregion=self.process_director_vars() + #group_region=self.get_shardg_region_name(sgroup) + #dtrname=self.get_director_name(group_region) + shard_name='''{0}_{1}'''.format(scdb,spdb) + shard_region=None + shard_space=None + shard_group=None + deploy_as=None + + if sregion: + regionFlag=self.check_gsm_region(sregion) + if regionFlag != 'completed': + self.configure_gsm_region(sregion) + shard_region=" -region {0}".format(sregion) + else: + shard_region="" + if sspace: + shard_space=" -shardspace {0}".format(sspace) + else: + shard_space="" + + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + sspaceFlag=self.check_gsm_shardspace(sspace) + if sspaceFlag != 'completed': + self.configure_gsm_sspace(sspace,None,None,None,None,'add') + shard_group="" + deploy_as,deploy_type=self.get_shard_deploy() + else: + shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) + shard_region="" + else: + shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) + shard_region="" + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + add cdb -connect {3}:{4}/{5} -pwd {2}; + add shard -cdb {5} -connect "(DESCRIPTION = (ADDRESS = (PROTOCOL = tcp)(HOST = {3})(PORT = {4})) (CONNECT_DATA = (SERVICE_NAME = {6}) (SERVER = DEDICATED)))" {7} -pwd {2} {9} {10} {11}; + config vncr; + exit; + '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,shard_group,shard_name,shard_region,shard_space,deploy_as) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def get_shard_deploy(self): + """ + get the shard deploy + """ + deploy_as=None + deploy_type=None + if self.ocommon.check_key("SHARD_DEPLOY_AS",self.ora_env_dict): + deploy_as="-deploy_as {0}".format(self.ora_env_dict["SHARD_DEPLOY_AS"]) + deploy_type=self.ora_env_dict["SHARD_DEPLOY_AS"] + else: + deploy_as="-deploy_as primary" + deploy_type='primary' + + return deploy_as,deploy_type + + def get_shardg_cmd(self,sgroup,sregion): + """ + Getting shard group cmd + """ + sgFlag=self.check_shardg_status(sgroup,None) + deploy_as,deploy_type=self.get_shard_deploy() + if sgFlag != 'completed': + self.configure_gsm_shardg(sgroup,deploy_type,sregion,'add') + else: + self.ocommon.log_info_message("Shardgroup exist " + sgroup, self.file_name) + + deploy_as="" + cmd=''' -shardgroup {0}'''.format(sgroup) + return cmd,deploy_as + + def delete_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup): + """ + This function delete the shard db. + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + shard_name='''{0}_{1}'''.format(scdb,spdb) + #group_region=self.get_shardg_region_name(sgroup) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + remove shard -shard {8}; + remove cdb -cdb {5}; + remove invitednode {3}; + config vncr; + exit; + '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,sgroup,shard_name) + + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_hostid_null(self): + """ + This function set the hostid to Null + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_pdb,admuser) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting host Id null in catalog as auto vncr is disabled''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set echo on + set termout on + set time on + update gsmadmin_internal.database set hostid=NULL; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + self.ocommon.unset_mask_str() + + def invited_node_op(self): + """ + This function perform the invitedaddition and deletion + """ + self.ocommon.log_info_message("Inside invited_node_op()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + shard_host=self.ora_env_dict["INVITED_NODE_OP"] + gsmcmd=''' + connect {1}/{2}; + remove invitednode {3}; + add invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,shard_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + def add_invited_node(self,op_str): + """ + This function add the invited in the GSM configuration + """ + self.ocommon.log_info_message("Inside add_invited_node()",self.file_name) + if op_str == "SHARD": + reg_exp = self.shard_regex() + else: + reg_exp = self.add_shard_regex() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + #group_region=self.get_shardg_region_name(shard_group) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + add invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,shard_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + def remove_invited_node(self,op_str): + """ + This function remove the invited in the GSM configuration + """ + self.ocommon.log_info_message("Inside remove_invited_node()",self.file_name) + if op_str == "SHARD": + reg_exp = self.shard_regex() + else: + reg_exp = self.add_shard_regex() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + temp_host= shard_host.split('.',1)[0] + #group_region=self.get_shardg_region_name(shard_group) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + remove invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,temp_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + else: + self.ocommon.log_info_message("KUBE_SVC is not set. No need to remove invited node!",self.file_name) + + + def deploy_shard(self): + """ + This function deploy shard + """ + self.ocommon.log_info_message("Inside deploy_shard()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + shrdg_sspace=None + #dtrname,dtrport,dtregion=self.process_director_vars() + #if op_str == "SHARD": + # reg_exp = self.shard_regex() + #else: + # reg_exp = self.add_shard_regex() + + #for key in self.ora_env_dict.keys(): + # if(reg_exp.match(key)): + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + shardg_shardspace="config shardspace" + else: + shardg_shardspace="config shardgroup" + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + config vncr; + deploy; + config shard; + exit; + '''.format("test",cadmin,cpasswd,shardg_shardspace) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def check_setup_status(self,host,ccdb,svc,port): + """ + This function check the shard status. + """ + systemStr='''{0}/bin/sqlplus "system/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,ccdb) + + fname='''/tmp/{0}'''.format("shard_setup.txt") + self.ocommon.remove_file(fname) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool {0} + select * from shardsetup WHERE ROWNUM = 1; + spool off + exit; + '''.format(fname) + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + if os.path.isfile(fname): + fdata=self.ocommon.read_file(fname) + else: + fdata='nosetup' + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + status = self.catalog_pdb_setup_check(host,ccdb,svc,port) + if status == 'completed': + return 'completed' + else: + return 'notcompleted' + else: + return 'notcompleted' + + + def catalog_pdb_setup_check(self,host,ccdb,svc,port): + """ + This function check the shard status. + """ + systemStr='''{0}/bin/sqlplus "pdbadmin/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,svc) + + fname='''/tmp/{0}'''.format("pdb_setup_check.txt") + self.ocommon.remove_file(fname) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Checking setup status in PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool {0} + select count(*) from dual; + spool off + exit; + '''.format(fname) + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + if os.path.isfile(fname): + fdata=self.ocommon.read_file(fname) + else: + fdata='nosetup' + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + if re.search('1',fdata): + return 'completed' + else: + return 'notcompleted' + + ############################# Setup GSM Service ############################################### + def setup_gsm_service(self): + """ + This function setup the shard service. + """ + self.ocommon.log_info_message("Inside setup_gsm_service()",self.file_name) + status=False + service_value="service_name=oltp_rw_svc;service_role=primary" + # self.ora_env_dict=self.ocommon.add_key("SERVICE1_PARAMS",service_value,self.ora_env_dict) + reg_exp= self.service_regex() + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_service_status=None + service_name,service_role=self.process_service_vars(key) + shard_service_status=self.check_service_status(service_name) + if shard_service_status != 'completed': + self.configure_gsm_service(service_name,service_role) + status = self.check_service_status(None) + if status == 'completed': + break + else: + msg='''GSM service setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + time.sleep(60) + counter=counter+1 + + status = self.check_service_status(None) + if status == 'completed': + msg='''Shard service setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def process_service_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + service_name=None + service_role=None + + self.ocommon.log_info_message("Inside process_service_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'service_name': + service_name = cvar_dict[ckey] + if ckey == 'service_role': + service_role = cvar_dict[ckey] + + ### Check values must be set + if service_name and service_role: + return service_name,service_role + else: + msg1='''service_name={0},service_role={1}'''.format((service_name or "Missing Value"),(service_role or "Missing Value")) + msg='''Shard service params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_service_status(self,service_name): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_service_status()",self.file_name) + #dtrname,dtrport,dtregion=self.process_director_vars() + gsmcmd=''' + config; + exit; + '''.format("test") + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Services\n)(?:.+\n)+",output) + status=False + if service_name: + try: + if self.ocommon.check_substr_match(matched_output[0],service_name): + status=True + else: + status=False + except: + status=False + else: + reg_exp= self.service_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + service_name,service_role=self.process_service_vars(key) + # match=re.search("(?i)(?m)"+service_name,matched_output) + try: + if self.ocommon.check_substr_match(matched_output[0],service_name): + status=True + else: + status=False + except: + status=False + + return(self.ocommon.check_status_value(status)) + + def service_regex(self): + """ + This function return the rgex to search the SERVICE[0-9]_PARAMS + """ + self.ocommon.log_info_message("Inside service_regex()",self.file_name) + return re.compile('SERVICE[0-9]+_PARAMS') + + def configure_gsm_service(self,service_name,service_role): + """ + This function configure the service creation. + """ + self.ocommon.log_info_message("Inside configure_gsm_service()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + add service -service {3} -role {4}; + start service -service {3}; + exit; + '''.format("test",cadmin,cpasswd,service_name,service_role) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ############################## GSM backup fIle function Begins Here ############################# + def gsm_backup_file(self): + """ + This function check the gsm setup status + """ + self.ocommon.log_info_message("Inside gsm_backup_file()",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) + + if os.path.isdir(gsmdata_loc): + msg='''Directory {0} exit'''.format(gsmdata_loc) + self.ocommon.log_info_message(msg,self.file_name) + + cmd='''cp -r -v {0}/* {1}/'''.format(gsmfile_loc,gsmdata_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############### Deploy Sample Function Begins Here ########################## + def setup_sample_schema(self): + """ + This function deploy the sample app + """ + s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?" + passlen = 8 + passwd = "".join(random.sample(s,passlen )) + self.ocommon.log_info_message("Inside deploy_sample_schema()",self.file_name) + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_db) + if self.ocommon.check_key("SAMPLE_SCHEMA",self.ora_env_dict): + if self.ora_env_dict["SAMPLE_SCHEMA"] == 'DEPLOY': + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Deploying sample schema''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set echo on + set termout on + set time on + spool /tmp/create_app_schema.lst + REM + REM Connect to the Shard Catalog and Create Schema + REM + alter session enable shard ddl; + alter session set container={2}; + alter session enable shard ddl; + create user app_schema identified by {3}; + grant connect, resource, alter session to app_schema; + grant execute on dbms_crypto to app_schema; + grant create table, create procedure, create tablespace, create materialized view to app_schema; + grant unlimited tablespace to app_schema; + grant select_catalog_role to app_schema; + grant all privileges to app_schema; + grant gsmadmin_role to app_schema; + grant dba to app_schema; + CREATE TABLESPACE SET tbsset1 IN SHARDSPACE shd1; + CREATE TABLESPACE SET tbsset2 IN SHARDSPACE shd2; + connect app_schema/{3}@{0}:{1}/{2} + alter session enable shard ddl; + + /* Customer shard table */ + + CREATE SHARDED TABLE customer + ( cust_id NUMBER NOT NULL, + cust_passwd VARCHAR2(20) NOT NULL, + cust_name VARCHAR2(60) NOT NULL, + cust_type VARCHAR2(10) NOT NULL, + cust_email VARCHAR2(100) NOT NULL) + partitionset by list (cust_type) + partition by consistent hash (cust_id) partitions auto + (partitionset individual values ('individual') tablespace set tbsset1, + partitionset business values ('business') tablespace set tbsset2 + ); + /* Invoice shard table */ + + CREATE SHARDED TABLE invoice + ( invoice_id NUMBER NOT NULL, + cust_id NUMBER NOT NULL, + cust_type VARCHAR2(10) NOT NULL, + vendor_name VARCHAR2(60) NOT NULL, + balance FLOAT(10) NOT NULL, + total FLOAT(10) NOT NULL, + status VARCHAR2(20), + CONSTRAINT InvoicePK PRIMARY KEY (cust_id, invoice_id)) + PARENT customer + partitionset by list (cust_type) + partition by consistent hash (cust_id) partitions auto + (partitionset individual values ('individual') tablespace set tbsset1, + partitionset business values ('business') tablespace set tbsset2 + ); + /* Data */ + insert into customer values (999, 'pass', 'Customer 999', 'individual', 'customer999@gmail.com'); + insert into customer values (250251, 'pass', 'Customer 250251', 'individual', 'customer250251@yahoo.com'); + insert into customer values (350351, 'pass', 'Customer 350351', 'individual', 'customer350351@gmail.com'); + insert into customer values (550551, 'pass', 'Customer 550551', 'business', 'customer550551@hotmail.com'); + insert into customer values (650651, 'pass', 'Customer 650651', 'business', 'customer650651@live.com'); + insert into invoice values (1001, 999, 'individual', 'VendorA', 10000, 20000, 'Due'); + insert into invoice values (1002, 999, 'individual', 'VendorB', 10000, 20000, 'Due'); + insert into invoice values (1001, 250251, 'individual', 'VendorA', 10000, 20000, 'Due'); + insert into invoice values (1002, 250251, 'individual', 'VendorB', 0, 10000, 'Paid'); + insert into invoice values (1003, 250251, 'individual', 'VendorC', 14000, 15000, 'Due'); + insert into invoice values (1001, 350351, 'individual', 'VendorD', 10000, 20000, 'Due'); + insert into invoice values (1002, 350351, 'individual', 'VendorE', 0, 10000, 'Paid'); + insert into invoice values (1003, 350351, 'individual', 'VendorF', 14000, 15000, 'Due'); + insert into invoice values (1004, 350351, 'individual', 'VendorG', 12000, 15000, 'Due'); + insert into invoice values (1001, 550551, 'business', 'VendorH', 10000, 20000, 'Due'); + insert into invoice values (1002, 550551, 'business', 'VendorI', 0, 10000, 'Paid'); + insert into invoice values (1003, 550551, 'business', 'VendorJ', 14000, 15000, 'Due'); + insert into invoice values (1004, 550551, 'business', 'VendorK', 10000, 20000, 'Due'); + insert into invoice values (1005, 550551, 'business', 'VendorL', 10000, 20000, 'Due'); + insert into invoice values (1006, 550551, 'business', 'VendorM', 0, 10000, 'Paid'); + insert into invoice values (1007, 550551, 'business', 'VendorN', 14000, 15000, 'Due'); + insert into invoice values (1008, 550551, 'business', 'VendorO', 10000, 20000, 'Due'); + insert into invoice values (1001, 650651, 'business', 'VendorT', 10000, 20000, 'Due'); + insert into invoice values (1002, 650651, 'business', 'VendorU', 0, 10000, 'Paid'); + insert into invoice values (1003, 650651, 'business', 'VendorV', 14000, 15000, 'Due'); + insert into invoice values (1004, 650651, 'business', 'VendorW', 10000, 20000, 'Due'); + insert into invoice values (1005, 650651, 'business', 'VendorX', 0, 20000, 'Paid'); + insert into invoice values (1006, 650651, 'business', 'VendorY', 0, 30000, 'Paid'); + insert into invoice values (1007, 650651, 'business', 'VendorZ', 0, 10000, 'Paid'); + commit; + select table_name from user_tables; + spool off + '''.format(catalog_host,catalog_port,catalog_pdb,passwd) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + show ddl; + exit; + '''.format("test",cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oralogger.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oralogger.py new file mode 100755 index 0000000..9a51b54 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oralogger.py @@ -0,0 +1,181 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file provides the functionality to log the event in console and file +""" + +import logging +import os + +class LoggingType(object): + CONSOLE = 1 + FILE = 2 + STDOUT = 3 + +class OraLogger(object): + """ + This is a class constructor which sets parameter for logger. + + Attributes: + filename_ (string): Filename which we need to set to store logs in a file. + """ + def __init__(self, filename_): + """ + This is a class constructor which sets parameter for logger. + + Attributes: + filename_ (string): Filename which we need to set to store logs in a file. + """ + self.filename_ = filename_ + # Set to default values can be changed later from other classes objects + self.console_ = LoggingType.CONSOLE + self.file_ = LoggingType.FILE + self.stdout_ = LoggingType.STDOUT + self.msg_ = None + self.functname_ = None + self.lineno_ = None + self.logtype_ = "INFO" + self.fmtstr_ = "%(asctime)s: %(levelname)s: %(message)s" + self.datestr_ = "%m/%d/%Y %I:%M:%S %p" + self.root = logging.getLogger() + self.root.setLevel(logging.DEBUG) + self.formatter = logging.Formatter('%(asctime)s %(levelname)8s:%(message)s', "%m/%d/%Y %I:%M:%S %p") + self.stdoutfile_ = "/proc/1/fd/1" + # self.stdoutfile_ = "/tmp/test.log" + + def getStdOutValue(self): + return self.stdout_ + +class Handler(object): + """ + This is a class which sets the handler for next logger. + """ + def __init__(self): + """ + This is a handler class constructor and nexthandler is set to None. + """ + self.nextHandler = None + + def handle(self, request): + ''' + This is a function which set the next handler. + + Attributes: + request (object): Object of the class oralogger. + ''' + self.nextHandler.handle(request) + + def print_message(self,request,lhandler): + """ + This function set the log type to INFO, WARN, DEBUG and CRITICAL. + + Attribute: + request (object): Object of the class oralogger. + lhandler: This parameter accept the loghandler. + """ + if request.logtype_ == "WARN": + request.root.warning(request.msg_) + elif request.logtype_ == "DEBUG": + request.root.debug(request.msg_) + elif request.logtype_ == "CRITICAL": + request.root.critical(request.msg_) + elif request.logtype_ == "ERROR": + request.root.error(request.msg_) + else: + request.root.info(request.msg_) + + request.root.removeHandler(lhandler) + +class FHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribut: + request: Object of OraLogger + """ + if request.file_ == LoggingType.FILE: + fh = logging.FileHandler(request.filename_) + request.root.addHandler(fh) + fh.setFormatter(request.formatter) + self.print_message(request,fh) + super(FHandler, self).handle(request) + else: + super(FHandler, self).handle(request) + + def print_message(self,request,fh): + """ + This function log the message to console/file/stdout. + """ + super(FHandler, self).print_message(request,fh) + +class CHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribute: + request: Object of OraLogger + """ + if request.console_ == LoggingType.CONSOLE: + # ch = logging.StreamHandler() + ch = logging.FileHandler("/tmp/test.log") + request.root.addHandler(ch) + ch.setFormatter(request.formatter) + self.print_message(request,ch) + super(CHandler, self).handle(request) + else: + super(CHandler, self).handle(request) + + def print_message(self,request,ch): + """ + This function log the message to console/file/stdout. + """ + super(CHandler, self).print_message(request,ch) + + +class StdHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribute: + request: Object of OraLogger + """ + request.stdout_ = request.getStdOutValue() + if request.stdout_ == LoggingType.STDOUT: + st = logging.FileHandler(request.stdoutfile_,mode="w") + request.root.addHandler(st) + st.setFormatter(request.formatter) + self.print_message(request,st) + super(StdHandler, self).handle(request) + else: + super(StdHandler, self).handle(request) + + def print_message(self,request,st): + """ + This function log the message to console/file/stdout. + """ + super(StdHandler, self).print_message(request,st) + +class PassHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self, request): + pass diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oramachine.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oramachine.py new file mode 100755 index 0000000..2d1431a --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/oramachine.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +import os +import sys + +class OraMachine: + """ + This calss setup the compute before starting the installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraMachine class to setup the compute + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + + def setup(self): + """ + This function setup the compute before starting the installation + """ + msg="Machine setup completed sucessfully!" + self.ocommon.log_info_message(msg,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orapcatalog.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orapcatalog.py new file mode 100755 index 0000000..6638860 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orapcatalog.py @@ -0,0 +1,748 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +class OraPCatalog: + """ + This calss setup the Catalog after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraCatalog class to setup the catalog on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def setup(self): + """ + This function setup the catalog on Primary DB. + """ + if self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) + self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) + if os.path.exists(create_db_file_lck): + self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) + sys.exit(127) + elif os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) + status = self.catalog_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) + sys.exit(0) + else: + status = self.catalog_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): + status = self.catalog_setup_check() + if not status: + self.ocommon.log_info_message("Catalog readyness check completed sucessfully!",self.file_name) + self.ocommon.prog_exit("127") + elif self.ocommon.check_key("RESET_PASSWORD",self.ora_env_dict): + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + if os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Catalog database up and running. Resetting password...",self.file_name) + else: + self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to reset password",self.file_name) + self.ocommon.prog_exit("127") + elif self.ocommon.check_key("EXPORT_TDE_KEY",self.ora_env_dict): + exist_db_file_lck=self.ocommon.get_db_lock_location()+ self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + if os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Catalog database up and running.",self.file_name) + self.ocommon.export_tde_key(self.ora_env_dict["EXPORT_TDE_KEY"]) + else: + self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to export the tde key",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_machine() + self.db_checks() + self.reset_catalog_setup() + status = self.catalog_setup_check() + if status: + self.ocommon.log_info_message("catalog Setup is already completed on this database",self.file_name) + else: + self.reset_passwd() + self.setup_cdb_catalog() + self.set_spfile_nonm_params() + self.ocommon.set_events("spfile") + self.set_dbparams_version() + self.restart_db() + self.alter_db() + self.setup_pdb_catalog() + self.set_primary_listener() + self.restart_listener() + self.register_services() + self.list_services() + self.backup_files() + self.update_catalog_setup() + self.gsm_completion_message() + self.run_custom_scripts() + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + + ########### SETUP_MACHINE ENDS here #################### + + ########### DB_CHECKS Related Functions Begin Here #################### + ## Function to perfom DB checks ###### + def db_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.set_user() + self.sid_check() + self.dbuinque_name_check() + self.hostname_check() + self.dbport_check() + self.dbr_dest_checks() + self.dpump_dir_checks() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit() + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def passwd_check(self): + """ + Function to set the password + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def set_user(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def sid_check(self): + """ + This funnction heck and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): + msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="ORACLE_SID is not set, existing!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def dbuinque_name_check(self): + """ + This funnction check and set the db unique name for standby + """ + if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" + self.ocommon.log_info_message(msg,self.file_name) + dbsid=self.ora_env_dict["ORACLE_SID"] + self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) + + + def hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + # hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def dbport_check(self): + """ + This funnction checks and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("DB_PORT",self.ora_env_dict): + msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) + msg="DB_PORT is not set, setting default to 1521" + self.ocommon.log_info_message(msg,self.file_name) + + def dbr_dest_checks(self): + """ + This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. + """ + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) + + # Checking the DB_RECOVERY_FILE_DEST_SIZE + + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the DB_CREATE_FILE_DEST + + if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): + msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) + + + def dpump_dir_checks(self): + """ + This funnction checks and set the DATA_PUMP dir and location. + """ + if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): + msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) + self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) + msg='''DATA_PUMP_DIR set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) + + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## RESET_PASSWORD function Begin here ############################# + ## Function to perform password reset + def reset_passwd(self): + """ + This function reset the password. + """ + self.ocommon.reset_passwd() + + ########## RESET_PASSWORD function ENDS here ############################# + + ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### + + def reset_catalog_setup(self): + """ + This function drop teh catalog setup table and reste the env to default values. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Inside reset_catalog_setup",self.file_name) + catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + if not os.path.isfile(catalog_reset_file): + msg='''Dropping catalogsetup table from CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + drop table system.shardsetup; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + else: + msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(catalog_reset_file) + self.ocommon.log_info_message(msg,self.file_name) + + + def catalog_setup_check(self): + """ + This function check the catalog status. + """ + #systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool /tmp/catalog_setup.txt + select * from system.shardsetup WHERE ROWNUM = 1; + spool off + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + fname='''/tmp/{0}'''.format("catalog_setup.txt") + fdata=self.ocommon.read_file(fname) + ### Unsetting the encrypt value to None + # self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + return True + else: + return False + + def setup_cdb_catalog(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + # Assigning variable + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] + dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] + host_name=self.ora_env_dict["ORACLE_HOSTNAME"] + dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] + db_port=self.ora_env_dict["DB_PORT"] + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting up catalog CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set db_create_file_dest=\"{0}\" scope=both; + alter system set db_recovery_file_dest_size={1} scope=both; + alter system set db_recovery_file_dest=\"{2}\" scope=both; + alter user gsmcatuser account unlock; + alter user gsmcatuser identified by HIDDEN_STRING; + alter system set local_listener='{4}:{5}' scope=both; + '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_spfile_nonm_params(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set open_links_per_instance=16 scope=spfile; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set standby_file_management='AUTO' scope=spfile; + alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; + alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + + def set_dbparams_version(self): + """ + This function setup the shard parameter based on db version. + """ + ohome1=self.ora_env_dict["ORACLE_HOME"] + version=self.ocommon.get_oraversion(ohome1).strip() + self.ocommon.log_info_message(version,self.file_name) + if int(version) > 21: + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set wallet_root=\"{1}/oradata/{2}/{3}\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_db(self): + """ + restarting the db + """ + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + #self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) + #sqlcmd=''' + # alter database archivelog; + # alter database open; + #''' + #output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + #self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + #self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + def setup_pdb_catalog(self): + """ + This function setup the catalog. + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + # Assigning variable + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter pluggable database {0} close immediate; + alter pluggable database {0} open services=All; + ALTER PLUGGABLE DATABASE {0} SAVE STATE; + alter system register; + alter session set container={0}; + create user {1} identified by HIDDEN_STRING; + alter user {1} account unlock; + grant connect, create session, gsmadmin_role to {1}; + grant inherit privileges on user SYS to GSMADMIN_INTERNAL; + execute dbms_xdb.sethttpport(8080); + exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('HIDDEN_STRING'); + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def update_catalog_setup(self): + """ + This function update the catalog setup on this DB. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") + # systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Updating shardsetup table''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + create table system.shardsetup (status varchar2(10)); + insert into system.shardsetup values('completed'); + commit; + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Reset File + catalog_reset_dir='''{0}/.catalog'''.format(self.ora_env_dict["HOME"]) + catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) + + self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) + if not os.path.isdir(catalog_reset_dir): + self.ocommon.create_dir(catalog_reset_dir,True,None,None) + + if not os.path.isfile(catalog_reset_file): + self.ocommon.create_file(catalog_reset_file,True,None,None) + +# self.ocommon.unset_mask_str() + + ########## SETUP_CDB_catalog FUNCTION ENDS HERE ############################### + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + def set_primary_listener(self): + """ + Function to set the primary listener + """ + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + + def set_db_listener(self,gdbname,sid): + """ + Funtion to reset the listener + """ + self.ocommon.log_info_message("Inside reset_listener()",self.file_name) + start = 'SID_LIST_LISTENER' + end = '^\)$' + oracle_home=self.ora_env_dict["ORACLE_HOME"] + lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) + buffer = "SID_LIST_LISTENER=" + '\n' + start_flag = False + try: + with open(lisora) as f: + for line1 in f: + if start_flag == False: + if (re.match(start, line1.strip())): + start_flag = True + elif (re.match(end, line1.strip())): + line2 = f.next() + if (re.match(end, line2.strip())): + break + else: + buffer += line1 + buffer += line2 + else: + if start_flag == True: + buffer += line1 + except: + pass + + if start_flag == True: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + else: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + + wr = open(lisora, 'w') + wr.write(listener) + + def restart_listener(self): + """ + restart listener + """ + self.ocommon.log_info_message("Stopping Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl stop'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + self.ocommon.log_info_message("Starting Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl start'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + + def register_services(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system register; + alter session set container={0}; + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def list_services(self): + """ + restart listener + """ + self.ocommon.log_info_message("Listing Services",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl services'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + + def backup_files(self): + """ + This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig + """ + self.ocommon.log_info_message("Inside backup_files()",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + dbsid=self.ora_env_dict["ORACLE_SID"] + + version=self.ocommon.get_oraversion(ohome).strip() + wallet_backup_cmd='''ls -ltr /bin''' + self.ocommon.log_info_message("Check Version " + version,self.file_name) + if int(version) >= 21: + obase1=self.ora_env_dict["ORACLE_BASE"] + wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) + cmd_names=''' + mkdir -p {0}/oradata/{1}/{2} + cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ + cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ + cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ + touch {0}/oradata/{1}/{2}/status_completed + '''.format(obase,"dbconfig",dbuname,ohome) + cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] + for cmd in cmd_list: + msg='''Executing cmd {0}'''.format(cmd) + self.ocommon.log_info_message(msg,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Catalog Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orapshard.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orapshard.py new file mode 100755 index 0000000..d1b1273 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orapshard.py @@ -0,0 +1,795 @@ +#!/usr/bin/python + +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +import traceback + +class OraPShard: + """ + This calss setup the primary shard after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraPShard class to setup the shard on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + try: + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + except BaseException as ex: + ex_type, ex_value, ex_traceback = sys.exc_info() + trace_back = traceback.extract_tb(ex_traceback) + stack_trace = list() + for trace in trace_back: + stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) + self.ocommon.log_info_message(ex_type.__name__,self.file_name) + self.ocommon.log_info_message(ex_value,self.file_name) + self.ocommon.log_info_message(stack_trace,self.file_name) + def setup(self): + """ + This function setup the shard on Primary DB. + """ + if self.ocommon.check_key("RESET_LISTENER",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) + self.ocommon.prog_exit("127") + self.reset_listener() + self.restart_listener() + if self.ocommon.check_key("RESTART_DB",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.start_db(self.ora_env_dict) + elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) + self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) + if os.path.exists(create_db_file_lck): + self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) + sys.exit(127) + elif os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) + status = self.shard_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) + sys.exit(0) + else: + status = self.shard_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Shard readyness check completed sucessfully!",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_machine() + self.db_checks() + self.reset_shard_setup() + status = self.shard_setup_check() + if status: + self.ocommon.log_info_message("Shard Setup is already completed on this database",self.file_name) + else: + self.reset_passwd() + self.setup_cdb_shard() + self.set_spfile_nonm_params() + self.ocommon.set_events("spfile") + self.set_dbparams_version() + self.restart_db() + self.alter_db() + self.setup_pdb_shard () + self.update_shard_setup() + self.set_primary_listener() + self.restart_listener() + self.register_services() + self.list_services() + self.backup_files() + self.gsm_completion_message() + self.run_custom_scripts() + + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + ########### SETUP_MACHINE ENDS here #################### + + ########### DB_CHECKS Related Functions Begin Here #################### + ## Function to perfom DB checks ###### + def db_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.set_user() + self.sid_check() + self.dbuinque_name_check() + self.hostname_check() + self.dbport_check() + self.dbr_dest_checks() + self.dpump_dir_checks() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit() + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def passwd_check(self): + """ + This funnction perform password related checks + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def set_user(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def sid_check(self): + """ + This funnction heck and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): + msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="ORACLE_SID is not set, existing!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def dbuinque_name_check(self): + """ + This funnction check and set the db unique name for standby + """ + if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" + self.ocommon.log_info_message(msg,self.file_name) + dbsid=self.ora_env_dict["ORACLE_SID"] + self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) + + def hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def dbport_check(self): + """ + This funnction checks and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("DB_PORT",self.ora_env_dict): + msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) + msg="DB_PORT is not set, setting default to 1521" + self.ocommon.log_info_message(msg,self.file_name) + + def dbr_dest_checks(self): + """ + This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. + """ + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) + + # Checking the DB_RECOVERY_FILE_DEST_SIZE + + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the DB_CREATE_FILE_DEST + + if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): + msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) + + + def dpump_dir_checks(self): + """ + This funnction checks and set the DATA_PUMP dir and location. + """ + if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): + msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) + self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) + msg='''DATA_PUMP_DIR set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) + + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## RESET_PASSWORD function Begin here ############################# + ## Function to perform password reset + def reset_passwd(self): + """ + This function reset the password. + """ + self.ocommon.reset_passwd() + + ########## RESET_PASSWORD function ENDS here ############################# + + ########## SETUP_CDB_SHARD FUNCTION BEGIN HERE ############################### + + def reset_shard_setup(self): + """ + This function drop teh shard setup table and reste the env to default values. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Inside reset_shard_setup",self.file_name) + shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + if not os.path.isfile(shard_reset_file): + msg='''Dropping shardsetup table from CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + drop table system.shardsetup; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + else: + msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(shard_reset_file) + self.ocommon.log_info_message(msg,self.file_name) + + + def shard_setup_check(self): + """ + This function check the shard status. + """ +# systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + # self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool /tmp/shard_setup.txt + select * from system.shardsetup WHERE ROWNUM = 1; + spool off + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + fname='''/tmp/{0}'''.format("shard_setup.txt") + fdata=self.ocommon.read_file(fname) + ### Unsetting the encrypt value to None + # self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + return True + else: + return False + + def setup_cdb_shard(self): + """ + This function setup the shard. + """ + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] + dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] + host_name=self.ora_env_dict["ORACLE_HOSTNAME"] + dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] + db_port=self.ora_env_dict["DB_PORT"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting up Shard CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set db_create_file_dest=\"{0}\" scope=both; + alter system set db_recovery_file_dest_size={1} scope=both; + alter system set db_recovery_file_dest=\"{2}\" scope=both; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set standby_file_management='AUTO' scope=spfile; + alter user gsmrootuser account unlock; + grant sysdg to gsmrootuser; + grant sysbackup to gsmrootuser; + alter user gsmrootuser identified by HIDDEN_STRING container=all; + alter user GSMUSER account unlock; + alter user GSMUSER identified by HIDDEN_STRING container=all; + grant sysdg to GSMUSER; + grant sysbackup to GSMUSER; + create or replace directory DATA_PUMP_DIR as '{3}'; + grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; + alter system set local_listener='{4}:{5}' scope=spfile; + '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_spfile_nonm_params(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set open_links_per_instance=16 scope=spfile; + alter system set open_links=16 scope=spfile; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; + alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def set_dbparams_version(self): + """ + This function setup the catalog parameter based on db version. + """ + ohome1=self.ora_env_dict["ORACLE_HOME"] + version=self.ocommon.get_oraversion(ohome1).strip() + self.ocommon.log_info_message(version,self.file_name) + if int(version) > 21: + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + + msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set wallet_root=\"{1}/oradata/{2}/{3}/\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_db(self): + + """ + restarting the db + """ + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + # self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) + # sqlcmd=''' + # alter database archivelog; + # alter database open; + # ''' + # output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + # self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + + def setup_pdb_shard(self): + """ + This function setup the shard. + """ + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up Shard PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter pluggable database {0} close immediate; + alter pluggable database {0} open services=All; + ALTER PLUGGABLE DATABASE {0} SAVE STATE; + alter system register; + alter session set container={0}; + grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; + grant sysdg to GSMUSER; + grant sysbackup to GSMUSER; + execute DBMS_GSM_FIX.validateShard; + alter system register; + '''.format(self.ora_env_dict["ORACLE_PDB"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + def update_shard_setup(self): + """ + This function update the shard setup on this DB. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") + systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + +# self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + + msg='''Updating shardsetup table''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + create table system.shardsetup (status varchar2(10)); + insert into system.shardsetup values('completed'); + commit; + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Reset File + shard_reset_dir='''{0}/.shard'''.format(self.ora_env_dict["HOME"]) + shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) + + self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) + if not os.path.isdir(shard_reset_dir): + self.ocommon.create_dir(shard_reset_dir,True,None,None) + + if not os.path.isfile(shard_reset_file): + self.ocommon.create_file(shard_reset_file,True,None,None) + +# self.ocommon.unset_mask_str() + + ########## SETUP_CDB_SHARD FUNCTION ENDS HERE ############################### + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Shard Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) + ################################ Reset and standby functions ################################################# + + def set_primary_listener(self): + """ + Function to set the primary listener + """ + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + + def set_db_listener(self,gdbname,sid): + """ + Funtion to reset the listener + """ + self.ocommon.log_info_message("Inside reset_listener()",self.file_name) + start = 'SID_LIST_LISTENER' + end = '^\)$' + oracle_home=self.ora_env_dict["ORACLE_HOME"] + lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) + buffer = "SID_LIST_LISTENER=" + '\n' + start_flag = False + try: + with open(lisora) as f: + for line1 in f: + if start_flag == False: + if (re.match(start, line1.strip())): + start_flag = True + elif (re.match(end, line1.strip())): + line2 = f.next() + if (re.match(end, line2.strip())): + break + else: + buffer += line1 + buffer += line2 + else: + if start_flag == True: + buffer += line1 + except: + pass + + if start_flag == True: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + else: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + + wr = open(lisora, 'w') + wr.write(listener) + + def restart_listener(self): + """ + restart listener + """ + self.ocommon.log_info_message("Stopping Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl stop'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + self.ocommon.log_info_message("Starting Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl start'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + def register_services(self): + """ + This function setup the catalog. + """ + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system register; + alter session set container={0}; + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def list_services(self): + """ + restart listener + """ + self.ocommon.log_info_message("Listing Services",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl services'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + def backup_files(self): + """ + This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig + """ + self.ocommon.log_info_message("Inside backup_files()",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + dbsid=self.ora_env_dict["ORACLE_SID"] + + version=self.ocommon.get_oraversion(ohome).strip() + wallet_backup_cmd='''ls -ltr /bin''' + self.ocommon.log_info_message("Check Version " + version,self.file_name) + if int(version) >= 21: + obase1=self.ora_env_dict["ORACLE_BASE"] + wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) + cmd_names=''' + mkdir -p {0}/oradata/{1}/{2} + cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ + cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ + cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ + {4} + touch {0}/oradata/{1}/{2}/status_completed + '''.format(obase,"dbconfig",dbuname,ohome,wallet_backup_cmd) + cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] + for cmd in cmd_list: + msg='''Executing cmd {0}'''.format(cmd) + self.ocommon.log_info_message(msg,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orascatalog.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orascatalog.py new file mode 100755 index 0000000..aa4ea65 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orascatalog.py @@ -0,0 +1,9 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orasshard.py b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orasshard.py new file mode 100755 index 0000000..58f168b --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/orasshard.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +import traceback + +class OraSShard: + """ + This calss setup the standby shard after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraSShard class to setup the shard on standby DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + try: + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + except BaseException as ex: + ex_type, ex_value, ex_traceback = sys.exc_info() + trace_back = traceback.extract_tb(ex_traceback) + stack_trace = list() + for trace in trace_back: + stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) + ocommon.log_info_message(ex_type.__name__,self.file_name) + ocommon.log_info_message(ex_value,self.file_name) + ocommon.log_info_message(stack_trace,self.file_name) + def setup(self): + """ + This function setup the shard on standby DB. + """ + pass diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/runOraShardSetup.sh b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/runOraShardSetup.sh new file mode 100755 index 0000000..c1b09b4 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/runOraShardSetup.sh @@ -0,0 +1,568 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +export CLONED_FILE="status_completed" +export STANDBY_STATUS="status_completed" + +########### Clone Files ##################### +function cloneDB { + +export NEW_ORACLE_SID=$ORACLE_SID +export ORACLE_SID=$OLD_ORACLE_SID +sqlplus / as sysdba << EOF + STARTUP mount; + exit; +EOF + +echo 'Y' | nid target=/ dbname="$NEW_ORACLE_SID" + +if [ $? -eq 0 ]; then + echo "DB name changed sucessfully" +else + echo "DB name change process failed" + exit 1; +fi + +if [ -z ${DB_RECOVERY_FILE_DEST} ]; then + export DB_RECOVERY_FILE_DEST=$ORACLE_BASE/oradata/fast_recovery_area/$NEW_ORACLE_SID +fi + +if [ -z ${DB_UNIQUE_NAME} ]; then + export DB_UNIQUE_NAME=$NEW_ORACLE_SID +fi + +export ORACLE_HOSTNAME=$( hostname -f ) + +echo "Changing DB name" +export ORACLE_SID=$NEW_ORACLE_SID +sqlplus / as sysdba << EOF + STARTUP nomount; + alter system set db_name=$ORACLE_SID scope=spfile; + alter system set open_links=16 scope=spfile; + alter system set open_links_per_instance=16 scope=spfile; + alter system set dg_broker_config_file1="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr2$DB_UNIQUE_NAME.dat" scope=spfile; + alter system set dg_broker_config_file2="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr1$DB_UNIQUE_NAME.dat" scope=spfile; + alter system set db_file_name_convert='*','$ORACLE_BASE/oradata/$DB_UNIQUE_NAME/' scope=spfile; + alter system set local_listener='$ORACLE_HOSTNAME' scope=spfile; + alter system set standby_file_management='auto' scope=spfile; + shutdown immediate + exit; +EOF + +## Get the version + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 21 ]; then + echo "Setting DB Parameter based on the vserion" + export ORACLE_SID=$NEW_ORACLE_SID + sqlplus / as sysdba << EOF + startup nomount + alter system set wallet_root="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME" scope=spfile; + shutdown immediate + exit; +EOF + fi + fi + +echo "Changing OLD SID string to new string" +sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_HOME/network/admin/tnsnames.ora +sed -i "s/$OLD_ORACLE_PDB/$ORACLE_PDB/g" $ORACLE_HOME/network/admin/tnsnames.ora + +echo "Starting Listener" + +$ORACLE_HOME/bin/lsnrctl start + +echo "Starting new cloned DB" + +sqlplus / as sysdba << EOF + STARTUP mount; + alter database archivelog; + alter database open resetlogs; + exit; +EOF + +echo "Renaming PDB" + +sqlplus / as sysdba << EOF + alter pluggable database $OLD_ORACLE_PDB open restricted; + alter session set container=$OLD_ORACLE_PDB; + alter pluggable database rename global_name to $ORACLE_PDB; + exit; +EOF + +echo " Closing and Opening PDB" + +sqlplus / as sysdba << EOF + alter pluggable database $ORACLE_PDB close immediate; + alter pluggable database $ORACLE_PDB open; + alter system register; + exit; +EOF + + +echo "Touching $CLONED_FILE as setup is completed" +touch $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE + +} + +############################################ +########### Symbolic link DB files ######### +############################################ +########### DB Version >= 23c ############## +############################################ +function symLinkFiles23c { + + if [ -z ${ORACLE_BASE_HOME} ]; then + # + export ORACLE_BASE_HOME=$ORACLE_HOME + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora + fi; + if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/listener.ora + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora + fi + if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then + unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + ## Link based on ORACLE_BASE +# ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/spfile$ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi + fi + fi; + + if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID + fi; + + if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID + fi; + + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then + ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB + fi; + # oracle user does not have permissions in /etc, hence cp and not ln + sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab + cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab + fi +fi + +} + + +############################################ +########### Symbolic link DB files ######### +############################################ +########### DB Version < 23c ############### +############################################ +function symLinkFiles { + + if [ -z ${ORACLE_BASE_HOME} ]; then + # + export ORACLE_BASE_HOME=$ORACLE_HOME + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora + fi; + if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/listener.ora + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora + fi + if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then + unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$OLD_ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi + fi + fi; + + if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID + fi; + + if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID + fi; + + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then + ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB + fi; + # oracle user does not have permissions in /etc, hence cp and not ln + sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab + cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab + fi +fi + +} + +################################### +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +# Check whether container has enough memory +# Github issue #219: Prevent integer overflow, +# only check if memory digits are less than 11 (single GB range and below) +if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes | wc -c` -lt 11 ]; then + if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` -lt 2147483648 ]; then + echo "Error: The container doesn't have enough memory allocated." + echo "A database container needs at least 2 GB of memory." + echo "You currently only have $((`cat /sys/fs/cgroup/memory/memory.limit_in_bytes`/1024/1024/1024)) GB allocated to the container." + exit 1; + fi; +fi; + + +# Check that hostname doesn't container any "_" +# Github issue #711 +if hostname | grep -q "_"; then + echo "Error: The hostname must not container any '_'". + echo "Your current hostname is '$(hostname)'" +fi; + +# Default for ORACLE SID +if [ "$OLD_ORACLE_SID" == "" ]; then + export OLD_ORACLE_SID=SEEDCDB +fi + +if [ ! -z ${ORACLE_SID} ]; then + # Make ORACLE_SID upper case + # Github issue # 984 + export ORACLE_SID=${ORACLE_SID^^} + + # Check whether SID is no longer than 12 bytes + # Github issue #246: Cannot start OracleDB image + if [ "${#ORACLE_SID}" -gt 12 ]; then + echo "Error: The ORACLE_SID must only be up to 12 characters long." + exit 1; + fi; + + # Check whether SID is alphanumeric + # Github issue #246: Cannot start OracleDB image + if [[ "$ORACLE_SID" =~ [^a-zA-Z0-9] ]]; then + echo "Error: The ORACLE_SID must be alphanumeric." + exit 1; + fi; +else + echo "Error: The ORACLE_SID must be defined." + exit 1; +fi; + + +if [ ! -z ${ORACLE_PDB} ]; then + export ORACLE_PDB=${ORACLE_PDB^^} + + if [ "${#ORACLE_PDB}" -gt 12 ]; then + echo "Error: The ORACLE_PDB must only be up to 12 characters long." + exit 1; + fi; +else + echo "Error: The ORACLE_PDB must be defined." + exit 1; +fi; + +if [ ! -z ${OLD_ORACLE_PDB} ]; then + export OLD_ORACLE_PDB=${OLD_ORACLE_PDB^^} +else + export OLD_ORACLE_PDB=SEEDPDB +fi; + + +# Default for ORACLE CHARACTERSET +export ORACLE_CHARACTERSET=${ORACLE_CHARACTERSET:-AL32UTF8} + +# Check whether database already exists +if [ ! -z ${CLONE_DB} ]; then +if [ ${CLONE_DB^^} == "TRUE" ]; then +echo "CLONE_DB is set to true, cloning DB from seed" +if [ -d $ORACLE_BASE/oradata/$OLD_ORACLE_SID ]; then + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 23 ]; then + symLinkFiles23c; + else + symLinkFiles; + fi; + else + echo "Unable to determine the Database Version, exiting.." + exit 1; + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE ]; + then + # Start database + echo "Starting Database as cloned status file exist" + $ORACLE_BASE/$START_FILE; + else + echo "Performing Cloning as cloned status file does not exist" + cloneDB; + $ORACLE_BASE/checkDBStatus.sh + if [ $? -eq 0 ]; then + echo "DB is in READ WRITE State" + touch "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" + $ORACLE_BASE/$LOCKING_SCRIPT --acquire --file "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" + else + echo "DB is not in READ WRITE state" + exit 1; + fi + fi +else + echo "Error: The $ORACLE_BASE/oradata/$OLD_ORACLE_SID (ORACLE_BASE/oradata/OLD_ORACLE_SID) dir does not exist. Error exiting ." + exit 1; +fi +fi +fi + +if [ ${OP_TYPE,,} == "standbyshard" ]; then + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 23 ]; then + symLinkFiles23c; + else + symLinkFiles; + fi; + else + echo "Unable to determine the Database Version, exiting.." + exit 1; + fi + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/$STANDBY_STATUS ]; + then + # Start database + echo "Starting Database as standby setup status file exist" + $ORACLE_BASE/$START_FILE; + fi +fi + +#This is the main file which calls other file to setup the sharding. +if [ -z ${BASE_DIR} ]; then + BASE_DIR=/opt/oracle/scripts/sharding +fi + +if [ -z ${MAIN_SCRIPT} ]; then + SCRIPT_NAME="main.py" +fi + +if [ -z ${EXECUTOR} ]; then + EXECUTOR="python" +fi + +cd $BASE_DIR +$EXECUTOR $SCRIPT_NAME diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/scripts/runOracle.sh b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/runOracle.sh new file mode 100755 index 0000000..2266e99 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/scripts/runOracle.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +########### SIGINT handler ############ +function _int() { + echo "Stopping container." + echo "SIGINT received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown immediate; + exit; +EOF + lsnrctl stop +} + +########### SIGTERM handler ############ +function _term() { + echo "Stopping container." + echo "SIGTERM received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown immediate; + exit; +EOF + lsnrctl stop +} + +########### SIGKILL handler ############ +function _kill() { + echo "SIGKILL received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown abort; + exit; +EOF + lsnrctl stop +} + + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +if [ ! -z ${SHARD_SETUP} ]; then + if [ ${SHARD_SETUP,,} == "true" ]; then + sh $ORACLE_BASE/scripts/sharding/runOraShardSetup.sh + fi +fi + +if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & + fi +fi + +if [ ! -z ${OP_TYPE} ]; then + if [ ${OP_TYPE,,} == "standbyshard" ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & + fi +fi + +# Set SIGINT handler +trap _int SIGINT + +# Set SIGTERM handler +trap _term SIGTERM + +# Set SIGKILL handler +trap _kill SIGKILL + + +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/setupGSM.sh b/container-based-sharding-deployment/containerfiles/21.3.0/setupGSM.sh new file mode 100644 index 0000000..4a6a6ca --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/setupGSM.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +# Create Directories +mkdir -p $GSM_BASE +mkdir -p $GSM_HOME +mkdir -p $INVENTORY + +chown -R oracle:oinstall $INVENTORY +chown -R oracle:oinstall $GSM_BASE +chown -R oracle:oinstall $GSM_HOME +chown -R oracle:oinstall $INSTALL_SCRIPTS +chmod 775 $INSTALL_SCRIPTS + +chmod 666 /etc/sudoers +echo "oracle ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +chmod 440 /etc/sudoers + +echo "export ORACLE_HOME=$GSM_HOME" >> /home/oracle/.bashrc +echo "export PATH=$GSM_PATH" >> /home/oracle/.bashrc +echo "export LD_LIBRARY_PATH=$GSM_LD_LIBRARY_PATH" >> /home/oracle/.bashrc +echo "export SCRIPT_DIR=$SCRIPT_DIR" >> /home/oracle/.bashrc +echo "export GSM_HOME=$GSM_HOME" >> /home/oracle/.bashrc diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/setupLinuxEnv.sh b/container-based-sharding-deployment/containerfiles/21.3.0/setupLinuxEnv.sh new file mode 100644 index 0000000..17db98f --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/setupLinuxEnv.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +chmod ug+x $SCRIPT_DIR/*.sh && \ +yum -y install oracle-database-preinstall-21c net-tools which zip unzip tar openssl openssh-server openssh-client vim-minimal which vim-minimal passwd sudo && \ +yum clean all diff --git a/container-based-sharding-deployment/containerfiles/21.3.0/setupOshardEnv.sh b/container-based-sharding-deployment/containerfiles/21.3.0/setupOshardEnv.sh new file mode 100755 index 0000000..5ae2692 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/21.3.0/setupOshardEnv.sh @@ -0,0 +1,970 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +export NOW=$(date +"%Y%m%d%H%M") +export LOGDIR="/tmp" +export LOGFILE="${LOGDIR}/oshard_${NOW}.log" +export STD_OUT_FILE="/proc/1/fd/1" +export STD_ERR_FILE="/proc/1/fd/2" +declare -x SECRET_VOLUME='/run/secrets/' ## Secret Volume +declare -x PWD_KEY='pwd.key' ## PWD Key File +declare -x COMMON_OS_PWD_FILE='common_os_pwdfile.enc' +declare -x DB_PWD_FILE +export PDB_SQL_SCRIPT="/tmp/pdb.sql" +export TOP_PID=$$ +rm -f /tmp/sqllog.output +rm -f $PDB_SQL_SCRIPT +rm -f $LOGFILE + +#################################### Print and Exit Functions Begin Here ####################### +error_exit() { +local NOW=$(date +"%m-%d-%Y %T %Z") + # Display error message and exit +# echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2 + echo "${NOW} : ${PROGNAME}: ${1:-"Unknown Error"}" | tee -a $LOGFILE > $STD_OUT_FILE + kill -s TERM $TOP_PID +} + +print_message () +{ + local NOW=$(date +"%m-%d-%Y %T %Z") + # Display message and return + echo "${NOW} : ${PROGNAME} : ${1:-"Unknown Message"}" | tee -a $LOGFILE > $STD_OUT_FILE + return $? +} +#################################### Print and Exit Functions End Here ####################### + + +####################################### Functions Related to checks #################### +dbChecks() +{ +if [ -z "$ORACLE_HOME" ] +then + error_exit "Set the ORACLE_HOME variable" +else + print_message "ORACLE_HOME set to $ORACLE_HOME" +fi + +# If ORACLE_HOME doesn't exist # +if [ ! -d "$ORACLE_HOME" ] +then + error_exit "The ORACLE_HOME $ORACLE_HOME does not exist" +else + print_message "ORACLE_HOME Directory Exist" +fi + +################## Checks for Password and Clustername and clustertype begins here ########### +if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then +cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' + +eval $cmd + +if [ $? -eq 0 ]; then +print_message "Password file generated" +else +error_exit "Error occurred during common os password file generation" +fi + +read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} +rm -f /tmp/${COMMON_OS_PWD_FILE} +else + print_message "Password is empty string" + export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 +fi + +if [ -z "${ORACLE_PWD}" ]; then + print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" + export ORACLE_PWD=${PASSWORD} +else + print_message "ORACLE_PWD is set to user specified password" +fi + +################################################################################################### + + +if [ -z "${SHARD_ADMIN_USER}" ] +then + print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + export SHARD_ADMIN_USER="mysdbadmin" +else + print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" +fi + + +if [ -z "${PDB_ADMIN_USER}" ] +then + print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" + export PDB_ADMIN_USER="pdbadmin" +else + print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" +fi + + +# Validate the value of ORACLE_SID # +if [ -z "${ORACLE_SID}" ] +then + error_exit "Set the ORACLE_SID variable" +else + print_message "ORACLE_SID is set to $ORACLE_SID" +fi + +if [ -z "${ORACLE_HOSTNAME}" ] +then + if [ -z "${KUBE_SVC}" ]; then + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname)" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + else + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + fi +else + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" +fi + + + +if [ -z "$DB_PORT" ] +then + print_message "Set the DB_PORT variable" + export DB_PORT=1521 +else + print_message "DB Port is set to $DB_PORT" +fi + +if [ -z "${DB_RECOVERY_FILE_DEST}" ]; then + print_message "Set the DB_RECOVERY_FILE_DEST is not set" + export DB_RECOVERY_FILE_DEST="${ORACLE_BASE}/oradata/fast_recovery_area/${ORACLE_SID}" +fi + +if [ -z "${DB_CREATE_FILE_DEST}" ]; then + print_message "Set the DB_CREATE_FILE_DEST is not set. Setting to ${ORACLE_BASE}/oradata/${ORACLE_SID}" + export DB_CREATE_FILE_DEST="${ORACLE_BASE}/oradata/${ORACLE_SID}" +fi + +if [ -z "${DATA_PUMP_DIR}" ]; then + print_message "DATA_PUMP_DIR is not set, it will se to ${ORACLE_BASE}/oradata/data_pump_dir" + export DATA_PUMP_DIR="${ORACLE_BASE}/oradata/data_pump_dir" +fi + +if [ ! -d "${DATA_PUMP_DIR}" ]; then + print_message "DATA_PUMP_DIR ${DATA_PUMP_DIR} directory does not exist" + mkdir -p "${DATA_PUMP_DIR}" +fi + +if [ ! -d "${DB_RECOVERY_FILE_DEST}" ]; then + print_message "DB_RECOVERY_FILE_DEST ${DB_RECOVERY_FILE_DEST} directory does not exist" + mkdir -p "${DB_RECOVERY_FILE_DEST}" +fi + +if [ -z "${DB_RECOVERY_FILE_DEST_SIZE}" ]; then + print_message "DB_RECOVERY_FILE_DEST_SIZE is not set" + export DB_RECOVERY_FILE_DEST_SIZE="40G" +else + print_message "DB_RECOVERY_FILE_DEST_SIZE is set to ${DB_RECOVERY_FILE_DEST_SIZE}" +fi + +} + +gsmChecks() +{ + print_message "Performing GSM related checks" + +if [ ! -z "${KUBE_SVC}" ]; then + lordinal=$( hostname | awk -F "-" '{ print $NF }' ) + print_message "lordinal is set to ${lordinal}" + region_num=$((lordinal+1)) + if [ -z "${REGION}" ]; then + print_message "REGION is not set. Setting to region$lordinal" + export REGION="region${region_num}" + fi +else + if [ -z "${REGION}" ]; then + error_exit "REGION Canot be set to empty" + fi +fi + +################## Checks for Password and Clustername and clustertype begins here ########### +if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then +cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' + +eval $cmd + +if [ $? -eq 0 ]; then +print_message "Password file generated" +else +error_exit "Error occurred during common os password file generation" +fi + +read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} +rm -f /tmp/${COMMON_OS_PWD_FILE} +else + print_message "Password is empty string" + export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 +fi + +if [ -z "${ORACLE_PWD}" ]; then + print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" + export ORACLE_PWD=${PASSWORD} +else + print_message "ORACLE_PWD is set to user specified password" +fi + +################################################################################################### + +if [ -z "$SHARD_ADMIN_USER" ] +then + print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + export SHARD_ADMIN_USER="mysdbadmin" +else + print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" +fi + + +if [ -z "$PDB_ADMIN_USER" ] +then + print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" + export PDB_ADMIN_USER="pdbadmin" +else + print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" +fi + + +if [ -z "${SHARD_GROUP_NAME}" ]; then + print_message "SHARD_GROUP_NAME is not set, it will be set to primary_shardgroup" + export SHARD_GROUP_NAME="primary_shardgroup" +fi + +if [ -z "${SHARD_DEPLOYMENT_TYPE}" ]; then + print_message "SHARD_DEPLOYMENT_TYPE is not set, it will set to primary" + export SHARD_DEPLOYMENT_TYPE="primary" +fi + +if [ -z "${SHARD_DIRECTOR_NAME}" ]; then + print_message "SHARD_DIRECTOR_NAME is not set, it will set to sharddirector${region_num}" + export SHARD_DIRECTOR_NAME="sharddirector${region_num}" +fi + +if [ -z "${ORACLE_HOSTNAME}" ] +then + if [ -z "${KUBE_SVC}" ]; then + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname)" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + else + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + fi +else + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" +fi + +} + +###################################### Function Related to Check end here ################### + +################################### Reset Password ########################################### +resetPassword() +{ +if [ -f "${HOME}/setPassword.sh" ]; then +if [ ! -z "${ORACLE_PWD}" ]; then +"${HOME}"/setPassword.sh "$ORACLE_PWD" +fi +fi +} + +############################################################################################### +setupCatalog() +{ + +localconnectStr="/ as sysdba" +systemStr="system/${ORACLE_PWD}" +sqlScript="/tmp/setapp.sql" +print_message "Setting up Paramteres in Spfile" + +cmd1="drop table shardsetup;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" +#cmd=$( eval echo "$cmd1" ) +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links_per_instance=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="@$ORACLE_HOME/rdbms/admin/setCatalogDBPrivs.sql;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" +print_message "cat /tmp/setup_grants_privs.lst" + +cmd1="alter user gsmcatuser account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmcatuser identified by $ORACLE_PWD;" +print_message "Sending query to sqlplus to execute alter user gsmcatuser identified by ORACLE_PWD;" +executeSQL "$cmd1" "$localconnectStr" + + +#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" +cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + + +cmd1="shutdown immediate;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="startup mount;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database archivelog;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database open;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database flashback on;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database force logging;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1", "$localconnectStr" + +cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +if [ ! -z "${ORACLE_PDB}" ]; then +setupCatalogPDB +fi + +cmd1="create table shardsetup (status varchar2(10));" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="insert into shardsetup values('completed');" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" +} + +configureSampleAppSchema() +{ +local sqlScript="/tmp/sqlScript.sql" +connectStr = "${SHARD_ADMIN_USER}/${ORACLE_PWD}" + +echo "alter session enable shard ddl;" > ${sqlScript} +echo "create user app_schema identified by '&1';" >> ${sqlScript} +echo "grant all privileges to app_schema;" >> ${sqlScript} +echo "grant gsmadmin_role to app_schema;" >> ${sqlScript} +echo "grant select_catalog_role to app_schema;" >> ${sqlScript} +echo "grant connect, resource to app_schema;" >> ${sqlScript} +echo "grant dba to app_schema;" >> ${sqlScript} +echo "grant execute on dbms_crypto to app_schema;" >> ${sqlScript} +echo "CREATE TABLESPACE SET TSP_SET_1 using template (datafile size 100m autoextend on next 10M maxsize unlimited extent management local segment space management auto);" >> ${sqlScript} +echo "CREATE TABLESPACE SET LOBTS1;" >> ${sqlScript} +echo "CREATE TABLESPACE products_tsp datafile size 100m autoextend on next 10M maxsize unlimited extent management local uniform size 1m; " >> ${sqlScript} +echo "CONNECT app_schema/'&1';" >> ${sqlScript} +echo "ALTER SESSION ENABLE SHARD DDL;" >> ${sqlScript} +echo "CREATE SHARDED TABLE Customers (CustId VARCHAR2(60) NOT NULL, FirstName VARCHAR2(60), LastName VARCHAR2(60), Class VARCHAR2(10), Geo VARCHAR2(8),CustProfile VARCHAR2(4000),Passwd RAW(60),CONSTRAINT pk_customers PRIMARY KEY (CustId),CONSTRAINT json_customers CHECK (CustProfile IS JSON)) TABLESPACE SET TSP_SET_1 PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO;" >> ${sqlScript} +echo "CREATE SHARDED TABLE Orders (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL, OrderDate TIMESTAMP NOT NULL,SumTotal NUMBER(19,4),Status CHAR(4), CONSTRAINT pk_orders PRIMARY KEY (CustId, OrderId),CONSTRAINT fk_orders_parent FOREIGN KEY (CustId) REFERENCES Customers ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_orders_parent);" >> ${sqlScript} +echo "CREATE SEQUENCE Orders_Seq;" >> ${sqlScript} +echo "CREATE SHARDED TABLE LineItems (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL,ProductId INTEGER NOT NULL,Price NUMBER(19,4),Qty NUMBER,CONSTRAINT pk_items PRIMARY KEY (CustId, OrderId, ProductId),CONSTRAINT fk_items_parent FOREIGN KEY (CustId, OrderId) REFERENCES Orders ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_items_parent);" >> ${sqlScript} +echo "CREATE DUPLICATED TABLE Products (ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,Name VARCHAR2(128),DescrUri VARCHAR2(128),LastPrice NUMBER(19,4)) TABLESPACE products_tsp;" >> ${sqlScript} + +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "$connectStr" "sqlScript" "${sqlScript}" + +} + + +setupCatalogPDB() +{ +#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" +pdbConnStr=" /as sysdba" + +local sqlScript="/tmp/sqlScript.sql" + +print_message "Settup Sql Script to setup Catalog PDB" +echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" +echo "create user ${SHARD_ADMIN_USER} identified by ${ORACLE_PWD};" >> "${sqlScript}" +echo "grant connect, create session, gsmadmin_role to ${SHARD_ADMIN_USER} ;" >> "${sqlScript}" +echo "grant inherit privileges on user SYS to GSMADMIN_INTERNAL;" >> "${sqlScript}" +echo "execute dbms_xdb.sethttpport(8080);" >> ${sqlScript} +echo "exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('${ORACLE_PWD}');" >> "${sqlScript}" + +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" +} + +######################################################################## Catalog Setup task ends here ################################# + +######################################################################## Primary Shard Setup task ends here ################################# + +setupShardPDB() +{ + +#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" +pdbConnStr=" /as sysdba" + +local sqlScript="/tmp/sqlScript.sql" +print_message "Settup Sql Script to setup Catalog PDB" +echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" +echo "grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" >> "${sqlScript}" +echo "grant sysdg to GSMUSER;" >> "${sqlScript}" +echo "grant sysbackup to GSMUSER;" >> "${sqlScript}" +echo "execute DBMS_GSM_FIX.validateShard;" >> ${sqlScript} +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" + +} + +setupShardCDB() +{ +localconnectStr="/as sysdba" +systemStr="system/${ORACLE_PWD}" +print_message "Setting up Paramteres in Spfile" + +cmd1="drop table shardsetup;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links_per_instance=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmrootuser account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmrootuser identified by ${ORACLE_PWD} container=all;" +print_message "Sending query to sqlplus to execute alter user gsmrootuser identified by ORACLE_PWD container=all;" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysdg to gsmrootuser;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysbackup to gsmrootuser;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user GSMUSER account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user GSMUSER identified by ${ORACLE_PWD} container=all;" +print_message "Sending query to sqlplus to execute alter user GSMUSER identified by ORACLE_PWD container=all;" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysdg to GSMUSER;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysbackup to GSMUSER;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set dg_broker_start=true scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="create or replace directory DATA_PUMP_DIR as '${DATA_PUMP_DIR}';" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" +cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="shutdown immediate;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="startup mount;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database archivelog;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database open;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database flashback on;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database force logging;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +if [ ! -z "${ORACLE_PDB}" ]; then + +setupShardPDB + +fi + +cmd1="create table shardsetup (status varchar2(10));" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + + +cmd1="insert into shardsetup values('completed');" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +} + +######################################################################## Primary Shard Setup ends here ################################# + +######################################################################## GSM Setup Task Begin here ##################################### +setupGSM() +{ +local cstatus='false' +local sstatus='false' + +setupGSMCatalog +startGSM +addShardGroup +setupGSMShard + +} + +startGSM() +{ + +cmd1="start gsm" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +deployShard() +{ + +cmd1="deploy" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +stopGSM() +{ + +cmd1="stop gsm" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +addInvitedNode() +{ + +chost=$1 + +cmd1="add invitednode $chost" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + + +addShardGroup() +{ + +cmd1="add shardgroup -shardgroup ${shardGName} -deploy_as ${deployment_type} -region ${region}" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +checkStatus() +{ +host=$1 +port=1521 +cpdb=$3 +ccdb=$2 +uname="system" +cpasswd=${ORACLE_PWD} + +print_message "Connect String $uname/$cpasswd@//$host:$port/$ccdb" +output=$( "$ORACLE_HOME"/bin/sqlplus -s "$uname/$cpasswd@//$host:$port/$ccdb" <<EOF + set heading off feedback off verify off echo off PAGESIZE 0 + select status from shardsetup; + exit +EOF +) + + if [ "${output}" == 'completed' ];then + print_message "Returned status from catalog is $output" + else + print_message "Sleeping for 300 seconds as returned status is not $output " + sleep 300 + fi + + echo $output +} + +setupGSMCatalog() +{ +IFS='; ' read -r -a sarray <<< "$CATALOG_PARAMS" +for element in "${sarray[@]}" +do + print_message "1st String in Shard params $element" + type=$( echo $element | awk -F: '{print $NF }') + host=$( echo $element | awk -F: '{print $1 }') + db=$( echo $element | awk -F: '{print $2 }') + pdb=$( echo $element | awk -F: '{print $3 }') +done + +print_message "Set variables to host=${host} db=${db} pdb=${pdb}" +if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] +then +runtime="60 minute" +endtime=$(date -ud "$runtime" +%s) + +while [[ $(date -u +%s) -le $endtime ]] +do + + coutput=$( checkStatus $host $db $pdb ) + if [ "${coutput}" == 'completed' ] ;then + configureGSMCatalog $host $db $pdb + break + else + print_message "Catalog Status must return completed but returned value is $coutput" + fi + print_message "Catalog DB is still not ready. Sleeping for 60 seconds" + sleep 60 +done +fi + +if [ "${coutput}" != 'completed' ] ;then + error_exit "Shard Catalog is not setup, Unable to proceed futher" +fi + +} + +configureGSMCatalog() +{ +chost=$1 +cport=1521 +cpdb=$3 +ccdb=$2 +gsmhost=${ORACLE_HOSTNAME} +cadmin=${SHARD_ADMIN_USER} +cpasswd=${ORACLE_PWD} +########################## +region="${REGION}" +shardGName="${SHARD_GROUP_NAME}" +deployment_type="${SHARD_DEPLOYMENT_TYPE}" +local gdsScript="/tmp/gdsScript.sql" + +gsm_name="${SHARD_DIRECTOR_NAME}" +echo "create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=${chost})(PORT=${cport}))(CONNECT_DATA=(SERVICE_NAME=${cpdb})))\" -user ${cadmin}/${cpasswd} -sdb shardcatalog -region region1,region2 -agent_port 8080 -agent_password ${cpasswd} -autovncr off" > "${gdsScript}" +echo "add invitednode ${chost}" >> "${gdsScript}" +echo "add gsm -gsm ${gsm_name} -listener 1521 -pwd ${cpasswd} -catalog ${chost}:${cport}/${cpdb} -region region1 -endpoint '(ADDRESS=(PROTOCOL=tcp)(HOST=${gsmhost})(PORT=1521))'" >> "${gdsScript}" +echo "exit" >> "${gdsScript}" +print_message "Sending script to gsm to execute ${gdsScript}" +cat ${gdsScript} >> $LOGFILE +cp "${gdsScript}" "${gdsScript}.test" +executeGSM "$cmd1" "gdsScript" "${gdsScript}" +} + +setupGSMShard() +{ +IFS='; ' read -r -a sarray <<< "$PRIMARY_SHARD_PARAMS" +arrLen=$( echo "${#sarray[@]}" ) +count1=0 + +runtime="45 minute" +endtime=$(date -ud "$runtime" +%s) + +print_message "Set variables to host=${host} db=${db} pdb=${pdb}" +while [[ $(date -u +%s) -le $endtime ]] +do + for i in ${!sarray[@]}; do + print_message "1st String in Shard params $element" + host=$( echo ${sarray[i]} | awk -F: '{print $1 }') + db=$( echo ${sarray[i]} | awk -F: '{print $2 }') + pdb=$( echo ${sarray[i]} | awk -F: '{print $3 }') + print_message "shard env set to host=${host} db=${db} pdb=${pdb}" + if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] + then + coutput=$( checkStatus $host $db $pdb ) + if [ "${coutput}" == 'completed' ] ;then + configureGSMShard $host $db $pdb + unset sarray[i] + ((++count1)) + else + print_message "Catalog Status must return completed but returned value is $coutput" + fi + fi + done + if [ ${count1} -ge ${arrLen} ]; then + break; + fi + print_message "Shards are still not ready. Sleeping for 120 seconds" + sleep 120 +done +} + +configureGSMShard() +{ +chost=$1 +cport=1521 +cpdb=$3 +ccdb=$2 +cpasswd=${ORACLE_PWD} +region=${REGION} +shardGName="${SHARD_GROUP_NAME}" +deployment_type="${SHARD_DEPLOYMENT_TYPE}" +local gdsScript="/tmp/gdsScript.sql" +admuser="${PDB_ADMIN_USER}" + +echo "connect ${admuser}/${cpasswd}" > "${gdsScript}" +echo "add cdb -connect ${chost}:${cport}:${ccdb} -pwd ${cpasswd}" >> "${gdsScript}" +echo "add shard -cdb ${ccdb} -connect ${chost}:${cport}/${cpdb} -shardgroup ${shardGName} -pwd ${cpasswd}" >> "${gdsScript}" +echo "config vncr" >> "${gdsScript}" +echo "sql 'update gsmadmin_internal.database set hostid=NULL '" >> "${gdsScript}" +echo "exit" >> "${gdsScript}" +print_message "Sending script to gsm to execute ${gdsScript}" +cat ${gdsScript} >> $LOGFILE +executeGSM "$cmd1" "gdsScript" "${gdsScript}" +print_message " Calling Stop GSM function" +stopGSM +print_message "Stop GSM function completed, sleeping for 20 seconds" +sleep 20 +print_message " Calling Start GSM function" +startGSM +print_message "Start GSM function completed, sleeping for 30 seconds" +sleep 30 +print_message "Calling invitenode function to add the shard" +addInvitedNode $chost +deployShard +} + +####################################################################### GSM Setup Task Ends here ######################################### + + +######################################################################### Execute GSM Statements ######################################### +executeGSM() +{ +gsmQuery=$1 +type=$2 +gdsScript=$3 + +if [ -z "${gsmQuery}" ]; then + print_message "Empty gdsQuery passed to gds" +fi + +if [ -z "${type}" ]; then + type='notSet' +fi + +if [ -z "${gdsScript}" ]; then + gdsScript='notSet' +fi + +if [ "${type}" == "gdsScript" ]; then +print_message "Executing gds script " +"$ORACLE_HOME"/bin/gdsctl @${gdsScript} +else +print_message "Executing GSM query" +"$ORACLE_HOME"/bin/gdsctl << EOF >> $LOGFILE + $gsmQuery + exit +EOF +fi +} +######################################################################## Execute GSM Statements Ends here ################################ + +########################################################################## Execute SQL Function Begin here ############################## +executeSQL() +{ +sqlQuery=$1 +connectStr=$2 +type=$3 +sqlScript=$4 + +if [ -z "${sqlQuery}" ]; then + print_message "Empty sqlQuery passed to sqlplus. Operation Failed" +fi + +if [ -z "${connectStr}" ]; then + error_exit "Empty connectStr passed to sqlplus. Operation Failed" +fi + +if [ -z "${type}" ]; then + type='notSet' +fi + +if [ -z "${sqlScript}" ]; then + sqlScript='notSet' +fi + +if [ "${type}" == "sqlScript" ] && [ -f ${sqlScript} ]; then +print_message "Executing sql script using connect string" +"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE +@ ${sqlScript} +EOF +else +print_message "Executing sqlQuery using connect string" +"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE +$sqlQuery +EOF +fi +} + +############################################################################## Execute SQl Function ends here ################################# + +####################################### +################## MAIN ############### + +if [ "${OP_TYPE}" == "primaryshard" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + resetPassword + setupShardCDB +elif [ "${OP_TYPE}" == "standbyshard" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + setupShardStandby +elif [ "${OP_TYPE}" == "catalog" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + resetPassword + setupCatalog +elif [ "${OP_TYPE}" == "gsm" ]; then + print_message "Performing Checks before proceeding for setup" + gsmChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + setupGSM +else + print_message "OP_TYPE must be set to (gsm|catalog|primaryshard|standbyshard)" + exit 15 +fi diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install.rsp b/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install.rsp new file mode 100644 index 0000000..102854f --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install.rsp @@ -0,0 +1,35 @@ + +############################################################################### +## Copyright(c) Oracle Corporation 1998,2022. All rights reserved. ## +## ## +## Specify values for the variables listed below to customize ## +## your installation. ## +## ## +## Each variable is associated with a comment. The comment ## +## can help to populate the variables with the appropriate ## +## values. ## +## ## +############################################################################### + +#------------------------------------------------------------------------------- +# Do not change the following system generated value. +#------------------------------------------------------------------------------- +oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v23.0.0 + +#------------------------------------------------------------------------------- +# Unix group to be set for the inventory directory. +#------------------------------------------------------------------------------- +UNIX_GROUP_NAME=oinstall +#------------------------------------------------------------------------------- +# Inventory location. +#------------------------------------------------------------------------------- +INVENTORY_LOCATION=###INVENTORY### +#------------------------------------------------------------------------------- +# Complete path of the Oracle Home +#------------------------------------------------------------------------------- +ORACLE_HOME=###ORACLE_HOME### + +#------------------------------------------------------------------------------- +# Complete path of the Oracle Base. +#------------------------------------------------------------------------------- +ORACLE_BASE=###ORACLE_BASE### diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install_sample.rsp b/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install_sample.rsp new file mode 100644 index 0000000..fce54e3 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install_sample.rsp @@ -0,0 +1,35 @@ + +############################################################################### +## Copyright(c) Oracle Corporation 1998,2022. All rights reserved. ## +## ## +## Specify values for the variables listed below to customize ## +## your installation. ## +## ## +## Each variable is associated with a comment. The comment ## +## can help to populate the variables with the appropriate ## +## values. ## +## ## +############################################################################### + +#------------------------------------------------------------------------------- +# Do not change the following system generated value. +#------------------------------------------------------------------------------- +oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v23.0.0 + +#------------------------------------------------------------------------------- +# Unix group to be set for the inventory directory. +#------------------------------------------------------------------------------- +UNIX_GROUP_NAME= +#------------------------------------------------------------------------------- +# Inventory location. +#------------------------------------------------------------------------------- +INVENTORY_LOCATION= +#------------------------------------------------------------------------------- +# Complete path of the Oracle Home +#------------------------------------------------------------------------------- +ORACLE_HOME= + +#------------------------------------------------------------------------------- +# Complete path of the Oracle Base. +#------------------------------------------------------------------------------- +ORACLE_BASE= diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/Checksum b/container-based-sharding-deployment/containerfiles/23.3.0/Checksum new file mode 100644 index 0000000..5cd5a7a --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/Checksum @@ -0,0 +1 @@ +ba8e6b942ba8ff22d25dd3babc7b326c LINUX.X64_233000_gsm.zip diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/Containerfile b/container-based-sharding-deployment/containerfiles/23.3.0/Containerfile new file mode 100644 index 0000000..2ba24c1 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/Containerfile @@ -0,0 +1,143 @@ +# LICENSE UPL 1.0 +# +# Copyright (c) 2018,2022 Oracle and/or its affiliates. +# +# ORACLE DOCKERFILES PROJECT +# -------------------------- +# This is the Dockerfile for Oracle GSM 23c Release 3 to build the container image +# MAINTAINER <paramdeep.saini@oracle.com> +# +# This is the Dockerfile for Oracle GSM 23c +# +# REQUIRED FILES TO BUILD THIS IMAGE +# ---------------------------------- +# (1) LINUX.X64_233000_gsm.zip +# Download Oracle Database 23c GSM Software +# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html +# +# HOW TO BUILD THIS IMAGE +# ----------------------- +# Put all downloaded files in the same directory as this Dockerfile +# Run: +# $ docker build -t oracle/gsm:23.3.0 . +# + +ARG BASE_OL_IMAGE=oraclelinux:8 + +# Pull base image +# --------------- +FROM $BASE_OL_IMAGE AS base + +# Labels +# ------ +LABEL "provider"="Oracle" \ + "issues"="https://github.com/oracle/db-sharding/issues" \ + "volume.setup.location1"="/opt/oracle/scripts" \ + "port.listener"="1522" + +# Argument to control removal of components not needed after db software installation +ARG SLIMMING=false +ARG INSTALL_FILE_1="LINUX.X64_233000_gsm.zip" + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +ENV GSM_BASE="/u01/app/oracle" \ + GSM_HOME="/u01/app/oracle/product/23c/gsmhome_1" \ + INVENTORY="/u01/app/oracle/oraInventory" \ + INSTALL_DIR="/opt/oracle/scripts" \ + INSTALL_FILE_1=$INSTALL_FILE_1 \ + INSTALL_RSP="23c_gsm_install.rsp" \ + RUN_FILE="runOracle.sh" \ + SETUP_LINUX_FILE="setupLinuxEnv.sh" \ + CHECK_SPACE_FILE="checkSpace.sh" \ + USER_SCRIPTS_FILE="runUserScripts.sh" \ + INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ + GSM_SETUP_FILE="setupOshardEnv.sh" \ + GSM_ENV_SETUP_FILE="setupGSM.sh" \ + GSM_SCRIPTS="scripts" \ + MAINPY="main.py" \ + PYTHON_FILE="/usr/bin/python" \ + PYTHON3_FILE="/usr/bin/python3" \ + CHECKLIVENESS="checkLiveness.sh" +# Use second ENV so that variable get substituted +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/sharding \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_PATH=$GSM_HOME/bin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib + + +# Copy files needed during both installation and runtime +# ------------ +COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $GSM_ENV_SETUP_FILE $INSTALL_DIR/install/ +COPY $RUN_FILE $GSM_SETUP_FILE $CHECKLIVENESS $USER_SCRIPTS_FILE $SCRIPT_DIR/ +COPY $GSM_SCRIPTS $SCRIPT_DIR/scripts/ + +RUN chmod 755 $INSTALL_DIR/install/*.sh && \ + sync && \ + $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ + $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ + $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ + sync + +############################################# +# ------------------------------------------- +# Start new stage for installing the GSM +# ------------------------------------------- +############################################# + +from base AS builder + +COPY $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ + +RUN chmod 755 $INSTALL_SCRIPTS/*.sh && \ + sync && \ + sed -e '/hard *memlock/s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-21c.conf && \ + sed -e '/ *nofile /s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-21c.conf && \ + su oracle -c "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ + $INVENTORY/orainstRoot.sh && \ + $GSM_HOME/root.sh && \ + rm -rf $INSTALL_DIR/install && \ + rm -f /etc/sysctl.d/99-oracle-database-preinstall-21c-sysctl.conf && \ + rm -f /etc/sysctl.d/99-sysctl.conf && \ + rm -f /etc/rc.d/init.d/oracle-database-preinstall-21c-firstboot && \ + rm -f /etc/security/limits.d/oracle-database-preinstall-21c.conf && \ + sync + +############################################# +# ------------------------------------------- +# Start new layer for GSM runtime +# ------------------------------------------- +############################################# + +FROM base + +COPY --from=builder /u01 /u01 + +RUN if [ ! -f $PYTHON_FILE ]; then \ + ln -s $PYTHON3_FILE $PYTHON_FILE && \ + :; \ + fi && \ + rm -f $INSTALL_DIR/install/* && \ + cp $SCRIPT_DIR/scripts/cmdExec $SCRIPT_DIR/ && \ + chown -R oracle:oinstall $SCRIPT_DIR && \ + chmod 755 $SCRIPT_DIR/*.sh && \ + chmod 755 $SCRIPT_DIR/scripts/*.py && \ + chmod 755 $SCRIPT_DIR/scripts/*.sh && \ + chmod 755 $SCRIPT_DIR/scripts/cmdExec && \ + chmod 755 $SCRIPT_DIR/cmdExec && \ + sync + +USER oracle +WORKDIR /home/oracle +EXPOSE 1522 + +VOLUME ["$GSM_BASE/oradata"] + +HEALTHCHECK --interval=2m --start-period=25m \ + CMD "$SCRIPT_DIR/$CHECKLIVENESS" >/dev/null || exit 1 + +# Define default command to start Oracle Database. +CMD exec $SCRIPT_DIR/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/Dockerfile_21c b/container-based-sharding-deployment/containerfiles/23.3.0/Dockerfile_21c new file mode 100644 index 0000000..37f8fba --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/Dockerfile_21c @@ -0,0 +1,85 @@ +# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl +# MAINTAINER <paramdeep.saini@oracle.com> +# +# This is the Dockerfile for Oracle Database 21 +# +# REQUIRED FILES TO BUILD THIS IMAGE +# ---------------------------------- +# (1) LINUX.X64_213000_gsm.zip +# Download Oracle Database 21c GSM Software +# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html +# +# HOW TO BUILD THIS IMAGE +# ----------------------- +# Put all downloaded files in the same directory as this Dockerfile +# Run: +# $ docker build -t oracle/gsm:21.3.0 . +# +# Pull base image +# --------------- +FROM oraclelinux:7-slim as base + +# Maintainer +# ---------- +MAINTAINER Paramdeep Saini <paramdeep.saini@oracle.com> + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +ENV GSM_BASE="/u01/app/oracle" \ + GSM_HOME="/u01/app/oracle/product/21c/gsmhome_1" \ + INVENTORY="/u01/app/oraInventory" \ + INSTALL_DIR="/opt/scripts" \ + INSTALL_FILE_1="LINUX.X64_213000_gsm.zip" \ + INSTALL_RSP="21c_gsm_install.rsp" \ + RUN_FILE="runOracle.sh" \ + SETUP_LINUX_FILE="setupLinuxEnv.sh" \ + CHECK_SPACE_FILE="checkSpace.sh" \ + USER_SCRIPTS_FILE="runUserScripts.sh" \ + INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ + GSM_SETUP_FILE="setupOshardEnv.sh" \ + GSM_ENV_SETUP_FILE="setupGSM.sh" \ + GSM_SCRIPTS="scripts" +# Use second ENV so that variable get substituted +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/startup \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH \ + GSM_PATH=$GSM_HOME/bin:/usr/sbin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib + + +# Copy files needed during both installation and runtime +# ------------ +COPY $INSTALL_FILE_1 $SETUP_LINUX_FILE $CHECK_SPACE_FILE $INSTALL_RSP $GSM_ENV_SETUP_FILE $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ +COPY $RUN_FILE $GSM_SETUP_FILE $USER_SCRIPTS_FILE $INSTALL_DIR/startup/ +COPY $GSM_SCRIPTS $INSTALL_DIR/startup/scripts + +RUN chmod 755 $INSTALL_DIR/install/*.sh && \ + sync && \ + $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ + $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ + $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ + sed -e '/hard *memlock/s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-19c.conf && \ + su oracle -c "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ + $INVENTORY/orainstRoot.sh && \ + $GSM_HOME/root.sh && \ + rm -rf $INSTALL_DIR/install && \ + rm -f /etc/sysctl.d/99-oracle-database-preinstall-19c-sysctl.conf && \ + rm -f /etc/sysctl.d/99-sysctl.conf && \ + rm -f /etc/rc.d/init.d/oracle-database-preinstall-19c-firstboot && \ + rm -f /etc/security/limits.d/oracle-database-preinstall-19c.conf && \ + rm -f $INSTALL_DIR/install/* && \ + chown -R oracle:oinstall $SCRIPT_DIR && \ + chmod 755 $SCRIPT_DIR/*.sh && \ + sync + +USER oracle +WORKDIR /home/oracle +EXPOSE 1521 + +VOLUME ["$GSM_BASE/oradata"] + +# Define default command to start Oracle Database. +CMD exec $INSTALL_DIR/startup/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/checkLiveness.sh b/container-based-sharding-deployment/containerfiles/23.3.0/checkLiveness.sh new file mode 100644 index 0000000..32a9fe3 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/checkLiveness.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +export PYTHON="/bin/python3" + +$PYTHON $SCRIPT_DIR/$MAINPY --checkliveness='true' +retcode=$? + + if [ ${retcode} -eq 0 ]; then + exit 0 + else + exit 1 + fi diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/checkSpace.sh b/container-based-sharding-deployment/containerfiles/23.3.0/checkSpace.sh new file mode 100644 index 0000000..5d4b8d9 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/checkSpace.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +REQUIRED_SPACE_GB=2 +AVAILABLE_SPACE_GB=`df -PB 1G / | tail -n 1 | awk '{ print $4 }'` + +if [ $AVAILABLE_SPACE_GB -lt $REQUIRED_SPACE_GB ]; then + script_name=`basename "$0"` + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "$script_name: ERROR - There is not enough space available in the docker container." + echo "$script_name: The container needs at least $REQUIRED_SPACE_GB GB, but only $AVAILABLE_SPACE_GB GB are available." + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + exit 1; +fi; diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/installGSMBinaries.sh b/container-based-sharding-deployment/containerfiles/23.3.0/installGSMBinaries.sh new file mode 100644 index 0000000..adf6547 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/installGSMBinaries.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +export ORACLE_BASE=$GSM_BASE +export ORACLE_HOME=$GSM_HOME + +# Check whether ORACLE_BASE is set +if [ "$ORACLE_BASE" == "" ]; then + echo "ERROR: ORACLE_BASE has not been set!" + echo "You have to have the ORACLE_BASE environment variable set to a valid value!" + exit 1; +fi; + +# Check whether ORACLE_HOME is set +if [ "$ORACLE_HOME" == "" ]; then + echo "ERROR: ORACLE_HOME has not been set!" + echo "You have to have the ORACLE_HOME environment variable set to a valid value!" + exit 1; +fi; + + +# Replace place holders +# --------------------- + +sed -i -e "s|###INVENTORY###|$INVENTORY|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ +sed -i -e "s|###ORACLE_BASE###|$GSM_BASE|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ +sed -i -e "s|###ORACLE_HOME###|$GSM_HOME|g" $INSTALL_SCRIPTS/$INSTALL_RSP + +# Install Oracle binaries +cd $INSTALL_SCRIPTS && \ +unzip $INSTALL_FILE_1 && \ +rm $INSTALL_FILE_1 && \ +$INSTALL_SCRIPTS/gsm/runInstaller -silent -force -waitforcompletion -responsefile $INSTALL_SCRIPTS/$INSTALL_RSP -ignorePrereqFailure || true && \ +rm -rf gsm && \ +cd $HOME diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/runOracle.sh b/container-based-sharding-deployment/containerfiles/23.3.0/runOracle.sh new file mode 100644 index 0000000..473de50 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/runOracle.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +#This is the main file which calls other file to setup the sharding. +if [ -z ${BASE_DIR} ]; then + BASE_DIR=$INSTALL_DIR/sharding/scripts +fi + +if [ -z ${MAIN_SCRIPT} ]; then + SCRIPT_NAME="main.py" +fi + +if [ -z ${EXECUTOR} ]; then + EXECUTOR="python3" +fi + +cd $BASE_DIR +$EXECUTOR $SCRIPT_NAME + +# Tail on alert log and wait (otherwise container will exit) + +if [ -z ${DEV_MODE} ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/gsm/*/*/trace/alert*.log & +else + echo "The following output is now a tail of the /etc/passwd for dev mode" + tail -f /etc/passwd & +fi + +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/runUserScripts.sh b/container-based-sharding-deployment/containerfiles/23.3.0/runUserScripts.sh new file mode 100644 index 0000000..c1d1c44 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/runUserScripts.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +SCRIPTS_ROOT="$1"; + +# Check whether parameter has been passed on +if [ -z "$SCRIPTS_ROOT" ]; then + echo "$0: No SCRIPTS_ROOT passed on, no scripts will be run"; + exit 1; +fi; + +# Execute custom provided files (only if directory exists and has files in it) +if [ -d "$SCRIPTS_ROOT" ] && [ -n "$(ls -A $SCRIPTS_ROOT)" ]; then + + echo ""; + echo "Executing user defined scripts" + + for f in $SCRIPTS_ROOT/*; do + case "$f" in + *.sh) echo "$0: running $f"; . "$f" ;; + *.sql) echo "$0: running $f"; echo "exit" | $ORACLE_HOME/bin/sqlplus -s "/ as sysdba" @"$f"; echo ;; + *) echo "$0: ignoring $f" ;; + esac + echo ""; + done + + echo "DONE: Executing user defined scripts" + echo ""; + +fi; diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/cmdExec b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/cmdExec new file mode 100755 index 0000000..0e5ac30 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/cmdExec @@ -0,0 +1,23 @@ +#!/bin/bash + +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +TIMESTAMP=`date "+%Y-%m-%d"` +LOGFILE="/tmp/sharding_cmd_${TIMESTAMP}.log" + +echo $(date -u) " : " $@ >> $LOGFILE + +cmd=$@ + +$cmd + +if [ $? -eq 0 ]; then + exit 0 +else + exit 127 +fi diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/demoapp.sql b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/demoapp.sql new file mode 100755 index 0000000..3e96bfc --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/demoapp.sql @@ -0,0 +1,88 @@ + connect sys/'&1'@oshard-catalog-0:1521/CATCDB as sysdba + alter session set container=CAT1PDB; + alter session enable shard ddl; + create user app_schema identified by app_schema; + grant connect, resource, alter session to app_schema; + grant execute on dbms_crypto to app_schema; + grant create table, create procedure, create tablespace, create materialized view to app_schema; + grant unlimited tablespace to app_schema; + grant select_catalog_role to app_schema; + grant all privileges to app_schema; + grant gsmadmin_role to app_schema; + grant dba to app_schema; + conn app_schema/'&1'@oshard-catalog-0:1521/CAT1PDB + alter session enable shard ddl; + REM + REM Create a Sharded table for + REM + CREATE SHARDED TABLE Customers + ( + CustId VARCHAR2(60) NOT NULL, + FirstName VARCHAR2(60), + LastName VARCHAR2(60), + Class VARCHAR2(10), + Geo VARCHAR2(8), + CustProfile VARCHAR2(4000), + Passwd RAW(60), + CONSTRAINT pk_customers PRIMARY KEY (CustId), + CONSTRAINT json_customers CHECK (CustProfile IS JSON) + ) TABLESPACE SET TSP_SET_1 + PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO; + REM + REM Create a Sharded table for Orders + REM + CREATE SHARDED TABLE Orders + ( + OrderId INTEGER NOT NULL, + CustId VARCHAR2(60) NOT NULL, + OrderDate TIMESTAMP NOT NULL, + SumTotal NUMBER(19,4), + Status CHAR(4), + constraint pk_orders primary key (CustId, OrderId), + constraint fk_orders_parent foreign key (CustId) + references Customers on delete cascade + ) partition by reference (fk_orders_parent); + REM + REM Create the sequence used for the OrderId column + REM + CREATE SEQUENCE Orders_Seq; + REM + REM Create a Sharded table for LineItems + REM + CREATE SHARDED TABLE LineItems + ( + OrderId INTEGER NOT NULL, + CustId VARCHAR2(60) NOT NULL, + ProductId INTEGER NOT NULL, + Price NUMBER(19,4), + Qty NUMBER, + constraint pk_items primary key (CustId, OrderId, ProductId), + constraint fk_items_parent foreign key (CustId, OrderId) + references Orders on delete cascade + ) partition by reference (fk_items_parent); + REM + REM + CREATE DUPLICATED TABLE Products + ( + ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + Name VARCHAR2(128), + DescrUri VARCHAR2(128), + LastPrice NUMBER(19,4) + ) TABLESPACE products_tsp; + CREATE OR REPLACE FUNCTION PasswCreate(PASSW IN RAW) + RETURN RAW + IS + Salt RAW(8); + BEGIN + Salt := DBMS_CRYPTO.RANDOMBYTES(8); + RETURN UTL_RAW.CONCAT(Salt, DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(Salt,PASSW), DBMS_CRYPTO.HASH_SH256)); + END; + / + CREATE OR REPLACE FUNCTION PasswCheck(PASSW IN RAW, PHASH IN RAW) + RETURN INTEGER IS + BEGIN + RETURN UTL_RAW.COMPARE(DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(UTL_RAW.SUBSTR(PHASH, 1, 8), PASSW), DBMS_CRYPTO.HASH_SH256),UTL_RAW.SUBSTR(PHASH, 9)); + END; + / + REM + REM diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/main.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/main.py new file mode 100755 index 0000000..b7f0f17 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/main.py @@ -0,0 +1,171 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" +This is the main file which calls other file to setup the sharding. +""" + +from oralogger import * +from orafactory import * +from oraenv import * +from oracommon import * + + +def main(): + + # Checking Comand line Args + try: + opts, args = getopt.getopt(sys.argv[1:], '', ['addshard=','deleteshard=','validateshard=','checkliveness=','resetlistener=','restartdb=','createdir=','optype=','addshardgroup=','deployshard=','movechunks=','checkonlineshard=','cancelchunks=','checkchunks=','checkgsmshard=','checkreadyness=','validatenochunks=','invitednode=','resetpassword=','exporttdekey=','importtdekey=','help']) + except getopt.GetoptError: + pass + + # Initializing oraenv instance + oenv=OraEnv() + file_name = os.path.basename(__file__) + funcname = sys._getframe(1).f_code.co_name + + log_file_name = oenv.logfile_name("NONE") + + # Initialiing logger instance + oralogger = OraLogger(log_file_name) + console_handler = CHandler() + file_handler = FHandler() + stdout_handler = StdHandler() + # Setting next log handlers + stdout_handler.nextHandler = file_handler + file_handler.nextHandler = console_handler + console_handler.nextHandler = PassHandler() + + ocommon = OraCommon(oralogger,stdout_handler,oenv) + + for opt, arg in opts: + if opt in ('--help'): + oralogger.msg_ = '''{:^17}-{:^17} : You can pass parameter --addshard, --deleteshard, --validateshard, --checkliveness, --resetlistener, --restartdb, --createdir, --optype, --addshardgroup, --deployshard, '--checkonlineshard', '--cancelchunks', '--movechunks', '--checkchunks', '--checkgsmshard','--validatenochunks', '--checkreadyness','--invitednode', '--resetpassword','--exporttdekey','--importtdekey',or --help''' + stdout_handler.handle(oralogger) + elif opt in ('--addshard'): + file_name = oenv.logfile_name("ADD_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("ADD_SHARD",arg) + elif opt in ('--validateshard'): + file_name = oenv.logfile_name("VALIDATE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("VALIDATE_SHARD",arg) + elif opt in ('--deleteshard'): + file_name = oenv.logfile_name("REMOVE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("REMOVE_SHARD",arg) + elif opt in ('--checkliveness'): + oralogger.stdout_ = None + file_name = oenv.logfile_name("CHECK_LIVENESS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_LIVENESS",arg) + elif opt in ('--checkreadyness'): + oralogger.stdout_ = None + file_name = oenv.logfile_name("CHECK_READYNESS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_READYNESS",arg) + elif opt in ('--resetlistener'): + file_name = oenv.logfile_name("RESET_LISTENER") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESET_LISTENER",arg) + elif opt in ('--restartdb'): + file_name = oenv.logfile_name("RESTART_DB") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESTART_DB",arg) + elif opt in ('--createdir'): + file_name = oenv.logfile_name("CREATE_DIR") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CREATE_DIR",arg) + elif opt in ('--addshardgroup'): + file_name = oenv.logfile_name("ADD_SGROUP_PARAMS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("ADD_SGROUP_PARAMS",arg) + elif opt in ('--deployshard'): + file_name = oenv.logfile_name("DEPLOY_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("DEPLOY_SHARD",arg) + elif opt in ('--cancelchunks'): + file_name = oenv.logfile_name("CANCEL_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CANCEL_CHUNKS",arg) + elif opt in ('--movechunks'): + file_name = oenv.logfile_name("MOVE_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("MOVE_CHUNKS",arg) + elif opt in ('--checkchunks'): + file_name = oenv.logfile_name("CHECK_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_CHUNKS",arg) + elif opt in ('--validatenochunks'): + file_name = oenv.logfile_name("VALIDATE_NOCHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("VALIDATE_NOCHUNKS",arg) + elif opt in ('--checkonlineshard'): + file_name = oenv.logfile_name("CHECK_ONLINE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_ONLINE_SHARD",arg) + elif opt in ('--checkgsmshard'): + file_name = oenv.logfile_name("CHECK_GSM_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_GSM_SHARD",arg) + elif opt in ('--invitednode'): + file_name = oenv.logfile_name("INVITED_NODE_OP") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("INVITED_NODE_OP",arg) + elif opt in ('--resetpassword'): + file_name = oenv.logfile_name("RESET_PASSWD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESET_PASSWORD",arg) + elif opt in ('--exporttdekey'): + file_name = oenv.logfile_name("EXPORT_TDE_KEY") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("EXPORT_TDE_KEY",arg) + elif opt in ('--importtdekey'): + file_name = oenv.logfile_name("IMPORT_TDE_KEY") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("IMPORT_TDE_KEY",arg) + elif opt in ('--optype'): + oenv.add_custom_variable("OP_TYPE",arg) + else: + pass + + # Initializing orafactory instances + oralogger.msg_ = '''{:^17}-{:^17} : Calling OraFactory to start the setup'''.format(file_name,funcname) + stdout_handler.handle(oralogger) + orafactory = OraFactory(oralogger,stdout_handler,oenv,ocommon) + + # Get the ora objects + ofactory=orafactory.get_ora_objs() + + # Traverse through returned factory objects and execute the setup function + for obj in ofactory: + obj.setup() + +# Using the special variable +if __name__=="__main__": + main() diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oracommon.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oracommon.py new file mode 100755 index 0000000..634a9f1 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oracommon.py @@ -0,0 +1,886 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +from oralogger import * +from oraenv import * +import subprocess +import sys +import time +import datetime +import os +import getopt +import shlex +import json +import logging +import socket +import re +import os.path +import socket +import string +import random + +class OraCommon: + def __init__(self,oralogger,orahandler,oraenv): + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + + def run_sqlplus(self,cmd,sql_cmd,dbenv): + """ + This function execute the ran sqlplus or rman script and return the output + """ + try: + message="Received Command : {0}\n{1}".format(self.mask_str(cmd),self.mask_str(sql_cmd)) + self.log_info_message(message,self.file_name) + sql_cmd=self.unmask_str(sql_cmd) + cmd=self.unmask_str(cmd) +# message="Received Command : {0}\n{1}".format(cmd,sql_cmd) +# self.log_info_message(message,self.file_name) + p = subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,env=dbenv,shell=True,universal_newlines=True) + p.stdin.write(sql_cmd) + # (stdout,stderr), retcode = p.communicate(sqlplus_script.encode('utf-8')), p.returncode + (stdout,stderr),retcode = p.communicate(),p.returncode + # stdout_lines = stdout.decode('utf-8').split("\n") + except: + error_msg=sys.exc_info() + self.log_error_message(error_msg,self.file_name) + self.prog_exit(self) + + return stdout.replace("\n\n", "\n"),stderr,retcode + + def execute_cmd(self,cmd,env,dir): + """ + Execute the OS command on host + """ + try: + message="Received Command : {0}".format(self.mask_str(cmd)) + self.log_info_message(message,self.file_name) + cmd=self.unmask_str(cmd) + out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,universal_newlines=True) + (output,error),retcode = out.communicate(),out.returncode + except: + error_msg=sys.exc_info() + self.log_error_message(error_msg,self.file_name) + self.prog_exit(self) + + return output,error,retcode + + def mask_str(self,mstr): + """ + Function to mask the string. + """ + newstr=None + if self.oenv.encrypt_str__: + newstr=mstr.replace('HIDDEN_STRING','********') + # self.log_info_message(newstr,self.file_name) + if newstr: + # message = "Masked the string as encryption flag is set in the singleton class" + # self.log_info_message(message,self.file_name) + return newstr + else: + return mstr + + + def unmask_str(self,mstr): + """ + Function to unmask the string. + """ + newstr=None + if self.oenv.encrypt_str__: + newstr=mstr.replace('HIDDEN_STRING',self.oenv.original_str__.rstrip()) + # self.log_info_message(newstr,self.file_name) + if newstr: + # message = "Unmasked the encrypted string and returning original string from singleton class" + # self.log_info_message(message,self.file_name) + return newstr + else: + return mstr + + def set_mask_str(self,mstr): + """ + Function to unmask the string. + """ + if mstr: + # message = "Setting encrypted String flag to True and original string in singleton class" + # self.log_info_message(message,self.file_name) + self.oenv.encrypt_str__ = True + self.oenv.original_str__ = mstr + else: + message = "Masked String is empty so no change required in encrypted String Flag and original string in singleton class" + self.log_info_message(message,self.file_name) + + def unset_mask_str(self): + """ + Function to unmask the string. + """ + # message = "Un-setting encrypted String flag and original string to None in Singleton class" + # self.log_info_message(message,self.file_name) + self.oenv.encrypt_str__ = None + self.oenv.original_str__ = None + + def prog_exit(self,message): + """ + This function exit the program because of some error + """ + sys.exit(127) + + def log_info_message(self,lmessage,fname): + """ + Print the INFO message in the logger + """ + funcname = sys._getframe(1).f_code.co_name + message = '''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_ = message + self.ologger.logtype_ = "INFO" + self.ohandler.handle(self.ologger) + + def log_error_message(self,lmessage,fname): + """ + Print the Error message in the logger + """ + funcname=sys._getframe(1).f_code.co_name + message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_=message + self.ologger.logtype_="ERROR" + self.ohandler.handle(self.ologger) + + def log_warn_message(self,lmessage,fname): + """ + Print the Error message in the logger + """ + funcname=sys._getframe(1).f_code.co_name + message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_=message + self.ologger.logtype_="WARN" + self.ohandler.handle(self.ologger) + + def check_sql_err(self,output,err,retcode,status): + """ + Check if there are any error in sql command output + """ + match=None + msg2='''Sql command failed.Flag is set not to ignore this error.Please Check the logs,Exiting the Program!''' + msg3='''Sql command failed.Flag is set to ignore this error!''' + self.log_info_message("output : " + str(output or "no Output"),self.file_name) + # self.log_info_message("Error : " + str(err or "no Error"),self.file_name) + # self.log_info_message("Sqlplus return code : " + str(retcode),self.file_name) + # self.log_info_message("Command Check Status Set to :" + str(status),self.file_name) + + if status: + if (retcode!=0): + self.log_info_message("Error : " + str(err or "no Error"),self.file_name) + self.log_error_message("Sql Login Failed.Please Check the logs,Exiting the Program!",self.file_name) + self.prog_exit(self) + + match=re.search("(?i)(?m)error",output) + if status: + if (match): + self.log_error_message(msg2,self.file_name) + self.prog_exit("error") + else: + self.log_info_message("Sql command completed successfully",self.file_name) + else: + if (match): + self.log_warn_message("Sql command failed. Flag is set to ignore the error.",self.file_name) + else: + self.log_info_message("Sql command completed sucessfully.",self.file_name) + + def check_os_err(self,output,err,retcode,status): + """ + Check if there are any error in OS command execution + """ + msg1='''OS command returned code : {0} and returned output : {1}'''.format(str(retcode),str(output or "no Output")) + msg2='''OS command returned code : {0}, returned error : {1} and returned output : {2}'''.format(str(retcode),str(err or "no returned error"),str(output or "no retruned output")) + msg3='''OS command failed. Flag is set to ignore this error!''' + + if status: + if (retcode != 0): + self.log_error_message(msg2,self.file_name) + self.prog_exit(self) + else: + self.log_info_message(msg1,self.file_name) + else: + if (retcode != 0): + self.log_warn_message(msg2,self.file_name) + self.log_warn_message(msg3,self.file_name) + else: + self.log_info_message(msg1,self.file_name) + + def check_key(self,key,env_dict): + """ + Check the key if it exist in dictionary. + Attributes: + key (string): String to check if key exist in dictionary + env_dict (dict): Contains the env variable related to seup + """ + if key in env_dict: + return True + else: + return False + + def empty_key(self,key): + """ + key is empty and print failure message. + Attributes: + key (string): String is empty + """ + msg='''Variable {0} is not defilned. Exiting!'''.format(key) + self.log_error_message(msg,self.file_name) + self.prog_exit(self) + + def add_key(self,key,value,env_dict): + """ + Add the key in the dictionary. + Attributes: + key (string): key String to add in the dictionary + value (String): value String to add in dictionary + + Return: + dict + """ + if self.check_key(key,env_dict): + msg='''Variable {0} already exist in the env variables'''.format(key) + self.log_info_message(msg,self.file_name) + else: + if value: + env_dict[key] = value + self.oenv.update_env_vars(env_dict) + else: + msg='''Variable {0} value is not defilned to add in the env variables. Exiting!'''.format(value) + self.log_error_message(msg,self.file_name) + self.prog_exit(self) + + return env_dict + + def update_key(self,key,value,env_dict): + """ + update the key in the dictionary. + Attributes: + key (string): key String to update in the dictionary + value (String): value String to update in dictionary + + Return: + dict + """ + if self.check_key(key,env_dict): + if value: + env_dict[key] = value + self.oenv.update_env_vars(env_dict) + else: + msg='''Variable {0} value is not defilned to update in the env variables!'''.format(key) + self.log_warn_message(msg,self.file_name) + else: + msg='''Variable {0} already exist in the env variables'''.format(key) + self.log_info_message(msg,self.file_name) + + return env_dict + + def check_file(self,file,local,remote,user): + """ + check locally or remotely + Attributes: + file (string): file to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside check_file()",self.file_name) + if local: + if os.path.isfile(file): + return True + else: + return False + + + def read_file(self,fname): + """ + Read the contents of a file and returns the contents to end user + Attributes: + fname (string): file to be read + + Return: + file data (string) + """ + f1 = open(fname, 'r') + fdata = f1.read() + f1.close + return fdata + + def write_file(self,fname,fdata): + """ + write the contents to a file + Attributes: + fname (string): file to be written + fdata (string): COnetents to be written + + Return: + file data (string) + """ + f1 = open(fname, 'w') + f1.write(fdata) + f1.close + + def create_dir(self,dir,local,remote,user): + """ + Create dir locally or remotely + Attributes: + dir (string): dir to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside create_dir()",self.file_name) + if local: + if not os.path.isdir(dir): + cmd='''mkdir -p {0}'''.format(dir) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + else: + msg='''Dir {0} already exist'''.format(dir) + self.log_info_message(msg,self.file_name) + + if remote: + pass + + def create_file(self,file,local,remote,user): + """ + Create dir locally or remotely + Attributes: + file (string): file to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside create_file()",self.file_name) + if local: + if not os.path.isfile(file): + cmd='''touch {0}'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + if remote: + pass + + def shutdown_db(self,env_dict): + """ + Shutdown the database + """ + file="/home/oracle/shutDown.sh" + if not os.path.isfile(file): + self.log_info_message("Inside shutdown_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + shutdown immediate; + ''' + self.log_info_message("Running the sqlplus command to shutdown the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + else: + cmd='''sh {0} immediate'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + def mount_db(self,env_dict): + """ + Mount the database + """ + self.log_info_message("Inside mount_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup mount; + ''' + self.log_info_message("Running the sqlplus command to mount the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def start_db(self,env_dict): + """ + startup the database + """ + file="/home/oracle/startUp.sh" + if not os.path.isfile(file): + self.log_info_message("Inside start_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup; + ''' + self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + else: + cmd='''sh {0}'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + def nomount_db(self,env_dict): + """ + No mount the database + """ + self.log_info_message("Inside start_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup nomount; + ''' + self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def stop_gsm(self,env_dict): + """ + Stop the GSM + """ + self.log_info_message("Inside stop_gsm()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + gsmcmd=''' + stop gsm; + ''' + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + + def set_events(self,source): + """ + Seting events at DB level + """ + scope='' + accepted_scope = ['spfile', 'memory', 'both'] + + if self.check_key("DB_EVENTS",self.ora_env_dict): + events=str(self.ora_env_dict["DB_EVENTS"]).split(";") + + for event in events: + msg='''Setting up event {0}'''.format(event) + self.log_info_message(msg,self.file_name) + scope='' + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + source=event.split(":") + if len(source) > 1: + if source[1].split("=")[0] == "scope": + scope=source[1].split("=")[1] + + if scope not in accepted_scope: + sqlcmd=""" + alter system set events='{0}';""".format(source[0]) + else: + sqlcmd=""" + alter system set event='{0}' scope={1};""".format(source[0],scope) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def start_gsm(self,env_dict): + """ + Start the GSM + """ + self.log_info_message("Inside start_gsm()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + gsmcmd=''' + start gsm; + ''' + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + + def exec_gsm_cmd(self,gsmcmd,flag,env_dict): + """ + Get the GSM command output + """ + self.log_info_message("Inside exec_gsm_cmd()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + if gsmcmd: + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,flag) + else: + self.log_info_message("GSM Command was set to empty. Executing nothing and setting output to None",self.file_name) + output=None + + return output,error,retcode + + + def check_substr_match(self,source_str,sub_str): + """ + CHeck if substring exist + """ + self.log_info_message("Inside check_substr_match()",self.file_name) + if (source_str.find(sub_str) != -1): + return True + else: + return False + + def find_str_in_string(self,source_str,delimeter,search_str): + """AI is creating summary for find_str_in_string + + Args: + source_str ([string]): [string where you need to search] + delimeter ([character]): [string delimeter] + search_str ([string]): [string to be searched] + """ + if delimeter == 'comma': + new_str=source_str.split(',') + for str in new_str: + if str.lower() == search_str.lower(): + return True + return False + + return False + + def check_status_value(self,match): + """ + return completed or notcompleted + """ + self.log_info_message("Inside check_status_value()",self.file_name) + if match: + return 'completed' + else: + return 'notcompleted' + + def remove_file(self,fname): + """ + Remove if file exist + """ + self.log_info_message("Inside remove_file()",self.file_name) + if os.path.exists(fname): + os.remove(fname) + + def get_sid_desc(self,gdbname,ohome,sid,sflag): + """ + get the SID_LISTENER_DESCRIPTION + """ + self.log_info_message("Inside get_sid_desc()",self.file_name) + sid_desc = "" + if sflag == 'SID_DESC1': + sid_desc = ''' ) + (SID_DESC = + (GLOBAL_DBNAME = {0}) + (ORACLE_HOME = {1}) + (SID_NAME = {2}) + ) + ) + '''.format(gdbname,ohome,sid) + elif sflag == 'SID_DESC': + sid_desc = '''(SID_LIST = + (SID_DESC = + (GLOBAL_DBNAME = {0}) + (ORACLE_HOME = {1}) + (SID_NAME = {2}) + ) + ) + '''.format(gdbname,ohome,sid) + else: + pass + + return sid_desc + + def get_lisora(self,port): + """ + return listener.ora listener settings + """ + self.log_info_message("Inside get_lisora()",self.file_name) + listener='''LISTENER = + (DESCRIPTION_LIST = + (DESCRIPTION = + (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = {0})) + (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC{0})) + ) + ) + '''.format(port) + return listener + + def get_domain(self,ohost): + """ + get the domain name from hostname + """ + return ohost.partition('.')[2] + +######### Get the DOMAIN############## + def get_host_domain(self): + """ + Return Public Hostname + """ + domain=None + domain=socket.getfqdn().split('.',1)[1] + if domain is None: + domain="example.info" + + return domain + + ######### get the public IP ############## + def get_ip(self,hostname,domain): + """ + Return the Ip based on hostname + """ + if not domain: + domain=self.get_host_domain() + + return socket.gethostbyname(hostname) + + def get_global_dbdomain(self,ohost,gdbname): + """ + get the global dbname + """ + domain = self.get_domain(ohost) + if domain: + global_dbname = gdbname + domain + else: + global_dbname = gdbname + + return gdbname + +######### Sqlplus connect string ########### + def get_sqlplus_str(self,home,osid,dbuser,password,hostname,port,svc,osep,role,wallet): + """ + return the sqlplus connect string + """ + path='''/usr/bin:/bin:/sbin:/usr/local/sbin:{0}/bin'''.format(home) + ldpath='''{0}/lib:/lib:/usr/lib'''.format(home) + export_cmd='''export ORACLE_HOME={0};export PATH={1};export LD_LIBRARY_PATH={2};export ORACLE_SID={3}'''.format(home,path,ldpath,osid) + if dbuser == 'sys' and password and hostname and port and svc: + return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4} as sysdba'''.format(dbuser,password,hostname,port,svc,export_cmd,home) + elif dbuser != 'sys' and password and hostname and svc: + return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4}'''.format(dbuser,password,hostname,"1521",svc,export_cmd,home) + elif dbuser and osep: + return dbuser + elif dbuser == 'sys' and not password: + return '''{1};{0}/bin/sqlplus "/ as sysdba"'''.format(home,export_cmd) + elif dbuser == 'sys' and password: + return '''{1};{0}/bin/sqlplus {2}/{3} as sysdba'''.format(home,export_cmd,dbuser,password) + elif dbuser != 'sys' and password: + return '''{1};{0}/bin/sqlplus {2}/{3}'''.format(home,export_cmd,dbuser,password) + else: + self.log_info_message("Atleast specify db user and password for db connectivity. Exiting...",self.file_name) + self.prog_exit("127") + +######### Get Password ############## + def get_os_password(self): + """ + get the OS password + """ + ospasswd=self.get_password(None) + return ospasswd + + def get_asm_passwd(self): + """ + get the ASM password + """ + asmpasswd=self.get_password(None) + return asmpasswd + + def get_db_passwd(self): + """ + get the DB password + """ + dbpasswd=self.get_password(None) + return dbpasswd + + def get_sys_passwd(self): + """ + get the sys user password + """ + dbpasswd=self.get_password(None) + return dbpasswd + + def get_password(self,key): + """ + get the password + """ + passwd_file_flag=False + password=None + password_file=None + if self.check_key("SECRET_VOLUME",self.ora_env_dict): + self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["SECRET_VOLUME"]) + msg='''SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) + else: + self.ora_env_dict=self.add_key("SECRET_VOLUME","/run/secrets",self.ora_env_dict) + msg='''SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("KEY_SECRET_VOLUME",self.ora_env_dict): + self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["KEY_SECRET_VOLUME"]) + msg='''KEY_SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + else: + if self.check_key("SECRET_VOLUME",self.ora_env_dict): + self.ora_env_dict=self.add_key("KEY_SECRET_VOLUME",self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict) + msg='''KEY_SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict): + msg='''COMMON_OS_PWD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) + else: + self.ora_env_dict=self.add_key("COMMON_OS_PWD_FILE","common_os_pwdfile.enc",self.ora_env_dict) + msg='''COMMON_OS_PWD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("PWD_KEY",self.ora_env_dict): + msg='''PWD_KEY passed as an env variable and set to {0}'''.format(self.ora_env_dict["PWD_KEY"]) + else: + self.ora_env_dict=self.add_key("PWD_KEY","pwd.key",self.ora_env_dict) + msg='''PWD_KEY not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PWD_KEY"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("PASSWORD_FILE",self.ora_env_dict): + msg='''PASSWORD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) + else: + self.ora_env_dict=self.add_key("PASSWORD_FILE","dbpasswd.file",self.ora_env_dict) + msg='''PASSWORD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) + self.log_warn_message(msg,self.file_name) + + secret_volume = self.ora_env_dict["SECRET_VOLUME"] + key_secret_volume= self.ora_env_dict["KEY_SECRET_VOLUME"] + common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"] + pwd_volume=None + if self.check_key("PWD_VOLUME",self.ora_env_dict): + pwd_volume=self.ora_env_dict["PWD_VOLUME"] + else: + pwd_volume="/var/tmp" + pwd_key = self.ora_env_dict["PWD_KEY"] + passwd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) + dbpasswd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["PASSWORD_FILE"]) + key_file='''{0}/{1}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"],self.ora_env_dict["PWD_KEY"]) + key_secret_volume='''{0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + self.log_info_message("Password file set to : " + passwd_file,self.file_name) + self.log_info_message("key file set to : " + key_file,self.file_name) + self.log_info_message("dbpasswd file set to : " + dbpasswd_file,self.file_name) + self.log_info_message("key secret voluem set to file set to : " + key_secret_volume,self.file_name) + self.log_info_message("pwd volume set : " + pwd_volume,self.file_name) + #print(passwd_file) + if (os.path.isfile(passwd_file)) and (os.path.isfile(key_file)): + msg='''Passwd file {0} and key file {1} exist. Password file Check passed!'''.format(passwd_file,key_file) + self.log_info_message(msg,self.file_name) + msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file) + self.log_info_message(msg,self.file_name) + cmd=None + if self.check_key("ENCRYPTION_TYPE",self.ora_env_dict): + if self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "aes256": + cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out {2}/{1} -pass file:\"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + elif self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "rsautl": + cmd ='''openssl rsautl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + else: + pass + else: + cmd ='''openssl pkeyutl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + passwd_file_flag = True + password_file='''{0}/{1}'''.format(pwd_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) + elif os.path.isfile(dbpasswd_file): + msg='''Passwd file {0} exist. Password file Check passed!'''.format(dbpasswd_file) + self.log_info_message(msg,self.file_name) + msg='''Reading encrypted passwd from file {0}.'''.format(dbpasswd_file) + self.log_info_message(msg,self.file_name) + cmd='''openssl base64 -d -in \"{0}\" -out \"{2}/{1}\"'''.format(dbpasswd_file,self.ora_env_dict["PASSWORD_FILE"],pwd_volume) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + passwd_file_flag = True + password_file='''{1}/{0}'''.format(self.ora_env_dict["PASSWORD_FILE"],pwd_volume) + + if not passwd_file_flag: + # get random password pf length 8 with letters, digits, and symbols + characters1 = string.ascii_letters + string.digits + "_-%#" + str1 = ''.join(random.choice(string.ascii_uppercase) for i in range(4)) + str2 = ''.join(random.choice(characters1) for i in range(8)) + password=str1+str2 + else: + fname='''{0}'''.format(password_file) + fdata=self.read_file(fname) + password=fdata + self.remove_file(fname) + + if self.check_key("ORACLE_PWD",self.ora_env_dict): + msg="ORACLE_PWD is passed as an env variable. Check Passed!" + self.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.add_key("ORACLE_PWD",password,self.ora_env_dict) + msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file" + self.log_info_message(msg,self.file_name) + +######### Get oraversion ############## + def get_oraversion(self,home): + """ + get the software version + """ + cmd='''{0}/bin/oraversion -majorVersion'''.format(home) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + return output + +####### Get db lock file location ####### + def get_db_lock_location(self): + """ + get the db location + """ + if self.check_key("DB_LOCK_FILE_LOCATION",self.ora_env_dict): + return self.ora_env_dict["DB_LOCK_FILE_LOCATION"] + else: + ### Please note that you should not change following path as SIDB team is maintaining lock files under following location + return "/tmp/." + +####### Get the TDE Key ############### + def export_tde_key(self,filename): + """ + This function export the tde. + """ + self.log_info_message("Inside gettdekey()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + ALTER SESSION DISABLE SHARD DDL; + ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET {0} TO {1} IDENTIFIED BY {0}; + '''.format('HIDDEN_STRING',filename) + self.log_info_message("Running the sqlplus command to export the tde: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + +####### Get the TDE Key ############### + def import_tde_key(self,filename): + """ + This function import the TDE key. + """ + self.log_info_message("Inside importtdekey()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY {0}; + ADMINISTER KEY MANAGEMENT IMPORT ENCRYPTION KEYS WITH SECRET {0} FROM {1} IDENTIFIED BY {0} WITH BACKUP + '''.format('HIDDEN_STRING',filename) + self.log_info_message("Running the sqlplus command to import the tde key: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) +######## Reset the DB Password in database ######## + def reset_passwd(self): + """ + This function reset the password. + """ + password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh") + self.log_info_message("Executing password reset", self.file_name) + if self.check_key("ORACLE_PWD",self.ora_env_dict) and self.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script): + cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING') + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + self.unset_mask_str() + else: + msg='''Error Occurred! Either HOME DIR {0} does not exist, ORACLE_PWD {1} is not set or PASSWORD SCRIPT {2} does not exist'''.format(self.ora_env_dict["HOME"],self.ora_env_dict["ORACLE_PWD"],password_script) + self.log_error_message(msg,self.file_name) + self.oracommon.prog_exit() \ No newline at end of file diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oraenv.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oraenv.py new file mode 100755 index 0000000..dd96c48 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oraenv.py @@ -0,0 +1,139 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file read the env variables from a file or using env command and populate them in variable +""" + +import os + +class OraEnv: + __instance = None + __env_var_file = '/etc/rac_env_vars' + + __env_var_file_flag = None + __env_var_dict = {} + __ora_asm_diskgroup_name = '+DATA' + __ora_gimr_flag = 'false' + __ora_grid_user = 'grid' + __ora_db_user = 'oracle' + __ora_oinstall_group_name = 'oinstall' + encrypt_str__ = None + original_str__ = None + logdir__ = "/tmp/sharding" + + def __init__(self): + """ Virtually private constructor. """ + if OraEnv.__instance != None: + raise Exception("This class is a singleton!") + else: + OraEnv.__instance = self + OraEnv.read_variable() + OraEnv.add_variable() + try: + os.mkdir(OraEnv.logdir__) + except OSError as error: + pass + + @staticmethod + def get_instance(): + """ Static access method. """ + if OraEnv.__instance == None: + OraEnv() + return OraEnv.__instance + + @staticmethod + def read_variable(): + """ Read the variables from a file into dict """ + if OraEnv.__env_var_file_flag: + with open(OraEnv.__env_var_file) as envfile: + for line in envfile: + name, var = line.partition("=")[::2] + OraEnv.__env_var_dict[name.strip()] = var + else: + OraEnv.__env_var_dict = os.environ + + @staticmethod + def add_variable(): + """ Add more variable ased on enviornment with default values in __env_var_dict""" + OraEnv.__env_var_dict["GSM_LOCK_STATUS_FILE"] = "/tmp/.gsm_status_lock_file" + OraEnv.__env_var_dict["SHARD_LOCK_STATUS_FILE"] = "/tmp/.shard_status_lock_file" + if "ORA_ASM_DISKGROUP_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_ASM_DISKGROUP_NAME"] = "+DATA" + + if "ORA_GRID_USER" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_GRID_USER"] = "grid" + + if "ORA_DB_USER" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_DB_USER"] = "oracle" + + if "ORA_OINSTALL_GROUP_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_OINSTALL_GROUP_NAME"] = "oinstall" + + @staticmethod + def add_custom_variable(key,val): + """ Addcustom more variable passed from main.py values in __env_var_dict""" + if key not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict[key] = val + + @staticmethod + def get_env_vars(): + """ Static access method to get the env vars. """ + return OraEnv.__env_var_dict + + @staticmethod + def update_env_vars(env_dict): + """ Static access method to get the env vars. """ + OraEnv.__env_var_dict = env_dict + + @staticmethod + def logfile_name(file_type): + """ Static access method to return the logfile name. """ + if file_type == "NONE": + if "LOGFILE_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/oracle_sharding_setup.log" + elif file_type == "ADD_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_addition.log" + elif file_type == "VALIDATE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_validation.log" + elif file_type == "REMOVE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_remove.log" + elif file_type == "CHECK_LIVENESS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkliveness.log" + elif file_type == "CHECK_READYNESS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkreadyness.log" + elif file_type == "RESET_LISTENER": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_listener.log" + elif file_type == "RESTART_DB": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/restart_db.log" + elif file_type == "CREATE_DIR": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/create_dir.log" + elif file_type == "ADD_SGROUP_PARAMS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/add_sgroup.log" + elif file_type == "DEPLOY_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/deploy_shard.log" + elif file_type == "CANCEL_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/cancel_chunk.log" + elif file_type == "MOVE_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/move_chunks.log" + elif file_type == "CHECK_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_chunks.log" + elif file_type == "CHECK_ONLINE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_online_shard.log" + elif file_type == "CHECK_GSM_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_gsm_shard.log" + elif file_type == "INVITED_NODE_OP": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/node_invited_op.log" + elif file_type == "RESET_PASSWD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_passwd_file.log" + elif file_type == "TDE_KEY": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/tde_key.log" + else: + pass + + return OraEnv.__env_var_dict["LOG_FILE_NAME"] diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orafactory.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orafactory.py new file mode 100755 index 0000000..5ddb6e3 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orafactory.py @@ -0,0 +1,115 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file contains to the code call different classes objects based on setup type +""" + +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +from orapshard import * +from orasshard import * +from orapcatalog import * +from oragsm import * + +import os +import sys + +class OraFactory: + """ + This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def get_ora_objs(self): + ''' + Return the instance of a classes which will setup the enviornment. + + Returns: + ofactory_obj: List of objects + ''' + ofactory_obj = [] + + msg='''ora_env_dict set to : {0}'''.format(self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + msg="Checking the OP_TYPE and Version to begin the installation" + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the OP_TYPE + if self.ocommon.check_key("OP_TYPE",self.ora_env_dict): + msg='''OP_TYPE variable is set to {0}.'''.format(self.ora_env_dict["OP_TYPE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("OP_TYPE","nosetup",self.ora_env_dict) + msg="OP_TYPE variable is set to default nosetup. No value passed as an enviornment variable." + self.ocommon.log_info_message(msg,self.file_name) + + # Check the OP_TYPE value and call objects based on it value + if self.ora_env_dict["OP_TYPE"] == 'primaryshard': + msg="Creating and calling instance to setup primary shard" + opshard = OraPShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(opshard) + elif self.ora_env_dict["OP_TYPE"] == 'standbyshard': + msg="Creating and calling instance to setup standby shard" + osshard = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(osshard) + elif self.ora_env_dict["OP_TYPE"] == 'catalog': + msg="Creating and calling instance to setup Catalog DB" + opcat = OraPCatalog(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(opcat) + elif self.ora_env_dict["OP_TYPE"] == 'standbycatalog': + msg="Creating and calling instance to setup Catalog DB" + oscat = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(oscat) + elif self.ora_env_dict["OP_TYPE"] == 'gsm': + msg="Creating and calling instance to setup GSM" + ogsm = OraGSM(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(ogsm) + else: + msg="OP_TYPE must be set to {primaryshard|standbyshard|catalog|standbycatalog|gsm}" + self.ocommon.log_info_message(msg,self.file_name) + msg="Since OP_TYPE is set to nosetup, only compute env is being setup. Creating and calling instance to setup compute." + self.ocommon.log_info_message(msg,self.file_name) + omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + ofactory_obj.append(omachine) + + return ofactory_obj diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oragsm.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oragsm.py new file mode 100755 index 0000000..ef0bb06 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oragsm.py @@ -0,0 +1,2945 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +import os +import sys +import os.path +import re +import socket +import random +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +class OraGSM: + """ + This calss setup the Gsm after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraGsm class to setup the Gsm on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def setup(self): + """ + This function setup the Gsm on Primary DB. + """ + if self.ocommon.check_key("ADD_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.add_gsm_shard() + self.set_hostid_null() + self.add_invited_node("ADD_SHARD") + self.remove_invited_node("ADD_SHARD") + sys.exit(0) + if self.ocommon.check_key("DEPLOY_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.deploy_shard() + self.setup_gsm_service() + sys.exit(0) + elif self.ocommon.check_key("ADD_SGROUP_PARAMS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_gsm_shardg("ADD_SGROUP_PARAMS") + sys.exit(0) + elif self.ocommon.check_key("ADD_SSPACE_PARAMS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_gsm_sspace("ADD_SSPACE_PARAMS") + sys.exit(0) + elif self.ocommon.check_key("REMOVE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + status=self.remove_gsm_shard() + + if status: + sys.exit(0) + else: + sys.exit(1) + + elif self.ocommon.check_key("MOVE_CHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.move_shard_chunks() + sys.exit(0) + elif self.ocommon.check_key("TDE_KEY",self.ora_env_dict): + self.ocommon.get_tde_key() + sys.exit(0) + elif self.ocommon.check_key("CANCEL_CHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.cancel_move_chunks() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_NOCHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.validate_nochunks() + sys.exit(0) + elif self.ocommon.check_key("CHECK_ONLINE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.verify_online_shard() + sys.exit(0) + elif self.ocommon.check_key("CHECK_GSM_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.verify_gsm_shard() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.validate_gsm_shard() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_GSM",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + sys.exit(0) + elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + if os.path.exists(filename): + self.ocommon.log_info_message("provisioning is still in progress as file " + filename + " still exist!",self.file_name) + sys.exit(0) + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + status = self.check_gsm_director_status(None) + if not status: + self.ocommon.log_info_message("No GDS setup found on this system.",self.file_name) + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("GSM liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("INVITED_NODE_OP",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.invited_node_op() + sys.exit(0) + elif self.ocommon.check_key("CATALOG_SETUP",self.ora_env_dict): + # If user pass env avariable CATALOG_SETUP true then it will just create gsm director and add catalog but will not add any shard + # It will also add service + status = self.catalog_setup_checks() + if status == False: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.setup_machine() + self.catalog_checks() + self.reset_gsm_setup() + status1 = self.gsm_setup_check() + if status1: + self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) + self.start_gsm_director() + self.ocommon.log_info_message("Started GSM",self.file_name) + else: + # Perform Catalog setup after check GSM_MASTER FLAG. IF GSM MASTER FLAG is set then only catalog will be added. + self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) + master_flag=self.gsm_master_flag_check() + if master_flag: + self.setup_gsm_calog() + self.setup_gsm_director() + self.start_gsm_director() + self.status_gsm_director() + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': + self.setup_gsm_shardg("SHARD_GROUP") + else: + self.setup_gsm_shardg("SHARD_GROUP") + self.gsm_backup_file() + self.gsm_completion_message() + ### Running Custom Scripts + self.run_custom_scripts() + else: + self.add_gsm_director() + self.start_gsm_director() + self.gsm_backup_file() + self.gsm_completion_message() + else: + # This block run shard addition, catalog addition and service creation + # This block also verifies if master flag is not not GSM director then it will not create catalog but add GSM ony + self.setup_machine() + self.gsm_checks() + self.reset_gsm_setup() + status = self.gsm_setup_check() + if status: + self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) + self.start_gsm_director() + self.ocommon.log_info_message("Started GSM",self.file_name) + else: + # if the status = self.gsm_setup_check() return False then shard addition, catalog addition and service creation + master_flag=self.gsm_master_flag_check() + if master_flag: + self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) + self.setup_gsm_calog() + self.setup_gsm_director() + self.start_gsm_director() + self.status_gsm_director() + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': + self.setup_gsm_shardg("SHARD_GROUP") + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + self.setup_gsm_sspace("SHARD_SPACE") + else: + self.setup_gsm_shardg("SHARD_GROUP") + self.setup_gsm_shard() + self.set_hostid_null() + self.stop_gsm_director() + time.sleep(30) + self.start_gsm_director() + self.add_invited_node("SHARD") + self.remove_invited_node("SHARD") + self.stop_gsm_director() + time.sleep(30) + self.start_gsm_director() + self.deploy_shard() + self.setup_gsm_service() + self.setup_sample_schema() + self.gsm_backup_file() + self.gsm_completion_message() + ### Running Custom Scripts + self.run_custom_scripts() + else: + self.add_gsm_director() + self.start_gsm_director() + self.gsm_backup_file() + self.gsm_completion_message() + + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + filename = self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + touchfile = 'touch {0}'.format(filename) + if not os.path.isfile(filename): + self.ocommon.log_error_message("Setting file provisioning status file :" + filename ,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(touchfile,None,self.ora_env_dict) + if retcode == 1: + self.ocommon.log_error_message("error occurred while touching the file :" + filename + ". Exiting!",self.file_name) + self.ocommon.prog_exit("127") + + ########### ENDS here #################### + + def gsm_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.shard_user_check() + self.gsm_hostname_check() + self.director_params_checks() + self.catalog_params_check() + self.shard_params_check() + self.sgroup_params_check() + + + def catalog_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.shard_user_check() + self.gsm_hostname_check() + self.director_params_checks() + self.catalog_params_check() + self.sgroup_params_check() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit("127") + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def passwd_check(self): + """ + Set the password + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def shard_user_check(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def director_params_checks(self): + """ + This funnction check and set the shard director name + """ + status=False + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD Director PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + + def gsm_hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def catalog_params_check(self): + """ + This funnction check if CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''CATALOG PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + if stype: + if stype.lower() == 'user': + if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) + if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) + status=True + + if not status: + msg="CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is not set, exiting!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def shard_params_check(self): + """ + This funnction check if SHARD[1-9]_PARAMS such as SHARD1_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + + if not status: + msg="SHARD[1-9]_PARAMS such as SHARD1_PARAMS is not set, exiting!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def sgroup_params_check(self): + """ + This funnction check if SHARD[1-9]_GROUP_PARAMS such as SHARD1_GROUP_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD GROUP PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + def gsm_master_flag_check(self): + """ + This funnction check if MASTER_GSM is passed as an env variable or not. If not passed then exit. + """ + status=False + if self.ocommon.check_key("MASTER_GSM",self.ora_env_dict): + msg='''MASTER_GSM is set. This machine will be configured with as master GSM director.''' + self.ocommon.log_info_message(msg,self.file_name) + return True + else: + return False + + def catalog_setup_checks(self): + """ + This function checks if director and catalog is setup and connection is established. + """ + status = False + gsm_status = self.check_gsm_director(None) + #catalog_status = self.check_gsm_catalog() + + if gsm_status == 'completed': + status = True + else: + status = False + + #if catalog_status == 'completed': + # status = True + #else: + # status = False + + return status + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### + def reset_gsm_setup(self): + """ + This function delete the GSM files. + """ + self.ocommon.log_info_message("Inside reset_gsm_setup",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + cmd_list=[] + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + msg='''Deleteing files from {0}'''.format(gsmdata_loc) + self.ocommon.log_info_message(msg,self.file_name) + cmd_list[0]='''rm -f {0}/gsm.ora'''.format(gsmdata_loc) + cmd_list[1]='''rm -f {0}/tnsnames.ora'''.format(gsmdata_loc) + cmd_list[2]='''rm -rf {0}/wallets'''.format(gsmdata_loc) + for cmd in cmd_list: + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + def gsm_setup_check(self): + """ + This function check if GSM is already setup on this + """ + status=True + self.ocommon.log_info_message("Inside gsm_setup_check",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) + + gsmora='''{0}/gsm.ora'''.format(gsmdata_loc) + tnsnamesora='''{0}/tnsnames.ora'''.format(gsmdata_loc) + walletloc='''{0}/gsmwallet'''.format(gsmdata_loc) + + if os.path.isfile(gsmora): + cmd='''cp -r -v -f {0} {1}/'''.format(gsmora,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if os.path.isfile(tnsnamesora): + cmd='''cp -r -v -f {0} {1}/'''.format(tnsnamesora,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if os.path.isdir(walletloc): + cmd='''cp -r -v -f {0} {1}/'''.format(walletloc,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if status: + return True + else: + return False + + #################### Catalog related Functions BEGINS Here ########################### + def setup_gsm_calog(self): + """ + This function setup the GSM catalog. + """ + self.ocommon.log_info_message("Inside setup_gsm_calog()",self.file_name) + status=False + reg_exp= self.catalog_regex() + counter=1 + end_counter=60 + catalog_db_status=None + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + catalog_db_status=self.check_setup_status(catalog_host,catalog_db,catalog_pdb,catalog_port) + if catalog_db_status == 'completed': + self.configure_gsm_clog(catalog_host,catalog_db,catalog_pdb,catalog_port,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname) + break + else: + msg='''Catalog Status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + if catalog_db_status == 'completed': + break + else: + msg='''Catalog setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + def process_clog_vars(self,key): + """ + This function process catalog vars based on key and return values to configure the GSM + """ + catalog_db=None + catalog_pdb=None + catalog_port=None + catalog_region=None + catalog_host=None + catalog_name=None + catalog_chunks=None + repl_type=None + repl_factor=None + repl_unit=None + stype=None + sspace=None + cfname=None + + self.ocommon.log_info_message("Inside process_clog_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'catalog_db': + catalog_db = cvar_dict[ckey] + if ckey == 'catalog_pdb': + catalog_pdb = cvar_dict[ckey] + if ckey == 'catalog_port': + catalog_port = cvar_dict[ckey] + if ckey == 'catalog_region': + catalog_region = cvar_dict[ckey] + if ckey == 'catalog_host': + catalog_host = cvar_dict[ckey] + if ckey == 'catalog_name': + catalog_name = cvar_dict[ckey] + if ckey == 'catalog_chunks': + catalog_chunks = cvar_dict[ckey] + if ckey == 'repl_type': + repl_type = cvar_dict[ckey] + if ckey == 'repl_factor': + repl_factor = cvar_dict[ckey] + if ckey == 'repl_unit': + repl_unit = cvar_dict[ckey] + if ckey == 'sharding_type': + stype = cvar_dict[ckey] + if ckey == 'shard_space': + sspace = cvar_dict[ckey] + if ckey == 'shard_configname': + cfname = cvar_dict[ckey] + + ## Set the values if not set in above block + if not catalog_port: + catalog_port=1521 + if not catalog_region: + catalog_region="region1,region2" + if stype: + if not sspace: + sspace="shardspace1,shardspace2" + + ### Check values must be set + if catalog_host and catalog_db and catalog_pdb and catalog_port and catalog_region and catalog_name: + return catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname + else: + msg1='''catalog_db={0},catalog_pdb={1}'''.format((catalog_db or "Missing Value"),(catalog_pdb or "Missing Value")) + msg2='''catalog_port={0},catalog_host={1}'''.format((catalog_port or "Missing Value"),(catalog_host or "Missing Value")) + msg3='''catalog_region={0},catalog_name={1}'''.format((catalog_region or "Missing Value"),(catalog_name or "Missing Value")) + msg='''Catalog params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def check_gsm_catalog(self): + """ + This function check the catalog status in GSM + """ + self.ocommon.log_info_message("Inside check_gsm_catalog()",self.file_name) + #dtrname,dtrport,dtregion=self.process_director_vars() + gsmcmd=''' + config; + exit; + '''.format("test") + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + match=self.ocommon.check_substr_match(matched_output[0],"test") + except: + match=False + return(self.ocommon.check_status_value(match)) + + # output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + # new_output=output[0].replace(" ","") + # self.ocommon.log_info_message(new_output,self.file_name) + # match=self.ocommon.check_substr_match(new_output,"Catalogconnectionisestablished") + # return(self.ocommon.check_status_value(match)) + + def catalog_regex(self): + """ + This function return the rgex to search the CATALOG PARAMS + """ + self.ocommon.log_info_message("Inside catalog_regex()",self.file_name) + return re.compile('CATALOG_PARAMS') + + + def configure_gsm_clog(self,chost,ccdb,cpdb,cport,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname): + """ + This function configure the GSM catalog. + """ + self.ocommon.log_info_message("Inside configure_gsm_clog()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + replist=['native'] + + ### User Define Shardig Variables + shardingtype=None + shardspace=None + configname=None + + # if stype and sspace: + if stype: + if stype.lower() == 'user': + shardingtype="-sharding user" + #shardspace="" + shardspace=" -shardspace {0}".format(sspace) + if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) + if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) + else: + shardspace="" + shardingtype="" + else: + shardspace="" + shardingtype="" + + if cfname: + configname=" -configname {0}".format(cfname) + else: + configname="" + + ### SNR Sharding + chunks=None + repl=None + repfactor=None + repunits=None + + if catalog_chunks: + chunks="-chunks {0}".format(catalog_chunks) + else: + chunks="" + + if repl_type and repl_type.lower() in replist: + self.ocommon.log_info_message("Repl_Type value Set to in block1:" + repl_type,self.file_name) + repl=" -repl {0}".format(repl_type) + else: + repl="" + + if repl_factor: + repfactor=" -repfactor {0}".format(repl_factor) + else: + repfactor="" + + if repl_unit: + repunits=" -repunits {0}".format(repl_unit) + else: + repunits="" + + invited_subnet="" + add_invited_subnet="" + if self.ocommon.check_key("INVITED_NODE_SUBNET_FLAG",self.ora_env_dict): + if self.ocommon.check_key("INVITED_NODE_SUBNET",self.ora_env_dict): + invited_subnet=self.ora_env_dict["INVITED_NODE_SUBNET"] + else: + #self.ocommon.log_info_message("The catalog Host name is :" + chost,self.file_name) + chost_ip=self.ocommon.get_ip(chost,None) + ip_parts=chost_ip.split('.') + invited_subnet=ip_parts[0] + "." + ip_parts[1] + '.*' + '.*' + add_invited_subnet='''add invitedsubnet {0};'''.format(invited_subnet) + + cpasswd="HIDDEN_STRING" + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})))\" {7} -user {3}/{4} -sdb {5} -region {6} -agent_port 8080 -agent_password {4} {8} {9} {10} {11} {12} {13} -autovncr off; + add invitednode {0}; + {14} + exit; + '''.format(chost,cport,cpdb,cadmin,cpasswd,catalog_name,catalog_region,chunks,repl,repfactor,repunits,shardingtype,shardspace,configname,add_invited_subnet) + + counter=1 + while counter < 5: + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + if retcode != 0: + self.ocommon.log_info_message("Error occurred while creating the shard catalog, sleeping for 60 seconds",self.file_name) + counter = counter + 1 + time.sleep(60) + else: + break + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ######################################## GSM director Functions Begins Here ##################### + def process_director_vars(self,key): + """ + This function process GSM director vars based on key and return values to configure the GSM + """ + dtrname=None + dtrport=None + dtregion=None + + self.ocommon.log_info_message("Inside process_director_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'director_name': + dtrname = cvar_dict[ckey] + if ckey == 'director_port': + dtrport = cvar_dict[ckey] + if ckey == 'director_region': + dtregion = cvar_dict[ckey] + + ### Check values must be set + if dtrname and dtrport and dtregion: + return dtrname,dtrport,dtregion + else: + msg1='''director_name={0},director_port={1}'''.format((dtrname or "Missing Value"),(dtrport or "Missing Value")) + msg2='''director_region={0}'''.format((dtregion or "Missing Value")) + msg='''Director params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_gsm_director(self,dname): + """ + This function check the GSM director status + """ + self.ocommon.log_info_message("Inside check_gsm_director()",self.file_name) + status=False + if dname: + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(matched_output[0],dname): + status=True + except: + status=False + else: + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(matched_output[0],dname): + status=True + except: + status=False + + return(self.ocommon.check_status_value(status)) + + def check_gsm_region(self,region): + """ + This function check the GSM regions + """ + self.ocommon.log_info_message("Inside check_gsm_region()",self.file_name) + gsmcmd=self.get_gsm_config_cmd(None) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Regions\n)(?:.+\n)+",output) + status=False + try: + if self.ocommon.check_substr_match(matched_output[0],region): + status=True + except: + status=False + return(self.ocommon.check_status_value(status)) + + def check_gsm_shardspace(self,sspace): + """ + This function check the GSM shardspace + """ + self.ocommon.log_info_message("Inside check_gsm_shardspace()",self.file_name) + gsmcmd=self.get_gsm_config_cmd(None) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard spaces\n)(?:.+\n)+",output) + status=False + try: + if self.ocommon.check_substr_match(matched_output[0],sspace): + status=True + except: + status=False + return(self.ocommon.check_status_value(status)) + + def check_gsm_director_status(self,dname): + """ + This function check the GSM director status using 'gdsctl status' + """ + self.ocommon.log_info_message("Inside check_gsm_director_status()",self.file_name) + status=False + gsmcmd=''' + status; + exit; + ''' + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + if "Connected to GDS catalog Y".replace(" ","").lower() in output.replace(" ","").lower(): + return True + else: + return False + + def add_gsm_director(self): + """ + This function add the GSM + """ + status=False + counter=1 + end_counter=60 + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + reg_exp= self.director_regex() + + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_director_status=None + dtrname,dtrport,dtregion=self.process_director_vars(key) + shard_director_status=self.check_gsm_director(dtrname) + if shard_director_status != 'completed': + self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) + status = self.check_gsm_director(None) + if status == 'completed': + break + + if status == 'completed': + break + else: + msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + status = self.check_gsm_director(None) + if status == 'completed': + msg='''Shard director setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 60 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def setup_gsm_director(self): + """ + This function setup in GSM + """ + self.ocommon.log_info_message("Inside setup_gsm_director()",self.file_name) + status=False + reg_exp= self.director_regex() + counter=1 + end_counter=3 + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_director_status=None + dtrname,dtrport,dtregion=self.process_director_vars(key) + shard_director_status=self.check_gsm_director(dtrname) + if shard_director_status != 'completed': + self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) + status = self.check_gsm_director(None) + if status == 'completed': + break + else: + msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + time.sleep(60) + counter=counter+1 + + status = self.check_gsm_director(None) + if status == 'completed': + msg='''Shard director setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 3 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin): + """ + This function configure GSM director + """ + ## Getting the values of catalog_port,catalog_pdb,catalog_host + cpasswd="HIDDEN_STRING" + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sregionFlag=self.check_gsm_region(dtregion) + if sregionFlag != 'completed': + self.configure_gsm_region(dtregion) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + add gsm -gsm {0} -listener {1} -pwd {2} -catalog {3}:{4}/{5} -region {6}; + exit; + '''.format(dtrname,dtrport,cpasswd,catalog_host,catalog_port,catalog_pdb,dtregion,gsmhost) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def start_gsm_director(self): + """ + This function start the director in the GSM + """ + status='noval' + self.ocommon.log_info_message("Inside start_gsm_director() function",self.file_name) + reg_exp= self.director_regex() + counter=1 + end_counter=10 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=''' + start gsm -gsm {0}; + exit; + '''.format(dtrname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + status=self.check_gsm_director(dtrname) + if status == 'completed': + break; + if status == 'completed': + filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + remfile='''rm -f {0}'''.format(filename) + if os.path.isfile(filename): + output,error,retcode=self.ocommon.execute_cmd(remfile,None,self.ora_env_dict) + break + else: + msg='''GSM shard director failed to start.Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_error_message(msg,self.file_name) + time.sleep(30) + + counter=counter+1 + + + if status != 'completed': + msg='''GSM shard director failed to start.Exiting!''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def stop_gsm_director(self): + """ + This function stop the director in the GSM + """ + status=False + self.ocommon.log_info_message("Inside stop_gsm_director() function",self.file_name) + reg_exp= self.director_regex() + counter=1 + end_counter=2 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=''' + stop gsm -gsm {0}; + exit; + '''.format(dtrname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + counter=counter+1 + + def status_gsm_director(self): + """ + This function check the GSM director status + """ + gsm_status = self.check_gsm_director(None) + #catalog_status = self.check_gsm_catalog() + + if gsm_status == 'completed': + msg='''Director setup completed in GSM and catalog is connected''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard director in GSM did not complete or not connected to catalog. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + ######################################## Shard Group Setup Begins Here ############################ + def setup_gsm_shardg(self,restype): + """ + This function setup the shard group. + """ + self.ocommon.log_info_message("Inside setup_gsm_shardg()",self.file_name) + status=False + if restype == 'ADD_SGROUP_PARAMS': + reg_exp = self.add_shardg_regex() + elif restype == 'SHARD_GROUP': + reg_exp = self.shardg_regex() + else: + self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SGROUP_PARAMS or SHARD_GROUP key to create a shard group",self.file_name) + self.ocommon.log_warn_message("Since no key specified for ADD_SGROUP_PARAMS and SHARD_GROUP, shardgroup will be created during shard creation",self.file_name) + + sgListC=[] + sgListP=[] + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_group_status=None + self.ocommon.log_info_message("Key is set to : " + key,self.file_name) + group_name,deploy_as,group_region=self.process_shardg_vars(key) + self.ocommon.log_info_message("Name: " + group_name + "deploy_as" + deploy_as + "group_region" + group_region,self.file_name) + if group_name is not None: + if group_name not in sgListC: + dtrname=self.get_director_name(group_region) + shard_group_status=self.check_shardg_status(group_name,dtrname) + if shard_group_status != 'completed': + self.configure_gsm_shardg(group_name,deploy_as,group_region,'add') + shard_group_status = self.check_shardg_status(group_name,None) + if shard_group_status == 'completed': + sgListC.append(group_name) + if group_name in sgListP: + sgListP.remove(group_name) + else: + sgListP=sgListP.append(group_name) + time.sleep(30) + counter=counter + 1 + + if sgListP == []: + msg='''Shard group setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def get_director_name(self,region_name): + """ + This function get the director name based on the region + """ + self.ocommon.log_info_message("Inside get_director_name()",self.file_name) + status=False + director_name=None + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + director_name=dtrname + gsm_status = self.check_gsm_director(dtrname) + if gsm_status == 'completed': + status = True + else: + status = False + if dtregion == region_name: + break + if status: + if director_name: + return director_name + else: + self.ocommon.log_error_message("No director exist to match the region",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.log_error_message("Shard Director is not running!",self.file_name) + self.ocommon.prog_exit("127") + + def get_shardg_region_name(self,sgname): + """ + This function get the region name based on shard group name + """ + self.ocommon.log_info_message("Inside get_region_name()",self.file_name) + status=False + region_name=None + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + group_name,deploy_as,group_region=self.process_shardg_vars(key) + region_name=group_region + if sgname == group_name: + status=True + break + if status: + return region_name + else: + self.ocommon.log_error_message("No such shard group exist! exiting!",self.file_name) + self.ocommon.prog_exit("127") + + def process_shardg_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + group_name=None + deploy_as=None + group_region=None + + self.ocommon.log_info_message("Inside process_shardg_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'group_name': + group_name = cvar_dict[ckey] + if ckey == 'deploy_as': + deploy_as = cvar_dict[ckey] + if ckey == 'group_region': + group_region = cvar_dict[ckey] + + ### Check values must be set + if group_name and deploy_as and group_region: + return group_name,deploy_as,group_region + else: + msg1='''group_name={0},deploy_as={1}'''.format((group_name or "Missing Value"),(deploy_as or "Missing Value")) + msg2='''group_region={0}'''.format((group_region or "Missing Value")) + msg='''Shard group params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + + def check_shardg_status(self,group_name,dname): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_shardg_status()",self.file_name) + status=False + + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) + if self.ocommon.check_substr_match(matched_output[0],group_name): + status=True + else: + status=False + + ''' + else: + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + group_name,deploy_as,group_region=self.process_shardg_vars(key) + dname=self.get_director_name(group_region) + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) + # match=re.search("(?i)(?m)"+group_name,matched_output) + if self.ocommon.check_substr_match(matched_output[0],group_name): + status=True + else: + status=False + ''' + + return(self.ocommon.check_status_value(status)) + +############################################# Director Related Block ############ + def get_director_name(self,region_name): + """ + This function get the director name based on the region + """ + self.ocommon.log_info_message("Inside get_director_name()",self.file_name) + status=False + director_name=None + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + director_name=dtrname + gsm_status = self.check_gsm_director(dtrname) + if gsm_status == 'completed': + status = True + else: + status = False + if dtregion == region_name: + break + if status: + if director_name: + return director_name + else: + self.ocommon.log_error_message("No director exist to match the region",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.log_error_message("Shard Director is not running!",self.file_name) + self.ocommon.prog_exit("127") + +######## + + def get_gsm_config_cmd(self,dname): + """ + Get the GSM config command + """ + self.ocommon.log_info_message("Inside get_gsm_config_cmd()",self.file_name) + gsmcmd=''' + config; + exit; + '''.format("test") + return gsmcmd + + def director_regex(self): + """ + This function return the rgex to search the SHARD DIRECTOR PARAMS + """ + self.ocommon.log_info_message("Inside director_regex()",self.file_name) + return re.compile('SHARD_DIRECTOR_PARAMS') + + def shardg_regex(self): + """ + This function return the rgex to search the SHARD GROUP PARAMS + """ + self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) + return re.compile('SHARD[0-9]+_GROUP_PARAMS') + + def add_shardg_regex(self): + """ + This function return the rgex to search the SHARD GROUP PARAMS + """ + self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) + return re.compile('ADD_SGROUP_PARAMS') + + def configure_gsm_shardg(self,group_name,deploy_as,group_region,type): + """ + This function configure the Shard Group. + """ + self.ocommon.log_info_message("Inside configure_gsm_shardg()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + dtrname=self.get_director_name(group_region) + reg_exp= self.catalog_regex() + if type == 'modify': + cmd=''' modify shardgroup -shardgroup {0} '''.format(group_name) + else: + cmd=''' add shardgroup -shardgroup {0} '''.format(group_name) + + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + if repl_type: + cmd=cmd + " -region {0} ".format(group_region) + else: + cmd=cmd + " -deploy_as {0} -region {1} ".format(deploy_as,group_region) + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + exit; + '''.format("NA",cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + +############# Adding Shard Regions ############### + def configure_gsm_region(self,region): + """ + This function configure the Shard region. + """ + self.ocommon.log_info_message("Inside configure_gsm_region()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + add region -region {3}; + exit; + '''.format("NA",cadmin,cpasswd,region) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + +##################### Adding Shard Space ############### + def process_sspace_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + sspace=None + chunks=None + repfactor=None + repunits=None + protectedmode=None + self.ocommon.log_info_message("Inside process_sspace_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'sspace_name': + sspace = cvar_dict[ckey] + if ckey == 'chunks': + chunks = cvar_dict[ckey] + if ckey == 'repfactor': + repfactor = cvar_dict[ckey] + if ckey == 'repunits': + repunits = cvar_dict[ckey] + if ckey == 'protectedmode': + protectedmode = cvar_dict[ckey] + + ### Check values must be set + if sspace: + return sspace,chunks,repfactor,repunits,protectedmode + else: + msg1='''sspace={0}'''.format((sspace or "Missing Value")) + msg='''Shard space params {0} is not set correctly. One or more value is missing {1}'''.format(key,msg1) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def setup_gsm_sspace(self,restype): + """ + This function setup the shard sspace. + """ + self.ocommon.log_info_message("Inside setup_gsm_sspace()",self.file_name) + status=False + if restype == 'ADD_SSPACE_PARAMS': + reg_exp = self.add_shardg_regex() + elif restype == 'SHARD_SPACE': + reg_exp = self.shardg_regex() + else: + self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SSPACE_PARAMS or SHARD_SPACE key to create a shard space",self.file_name) + self.ocommon.log_warn_message("Since no ADD_SSPACE_PARAMS or SHARD_SPACE defined, shardspace will be created during shard creation",self.file_name) + counter=1 + ssListC=[] + ssListP=[] + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_space_status=None + sspace,chunks,repfactor,repuntis,protectedmode=self.process_sspace_vars(key) + if sspace is not None: + if sspace not in ssListC: + shard_sspace_status=self.check_gsm_shardspace(sspace) + if shard_sspace_status != 'completed': + self.configure_gsm_sspace(sspace,chunks,repfactor,repuntis,protectedmode,'add') + shard_space_status = self.check_gsm_shardspace(sspace) + if shard_sspace_status == 'completed': + ssListC.append(sspace) + if sspace in sgListP: + sgListP.remove(sspace) + else: + sgListP=sgListP.append(sspace) + time.sleep(30) + counter=counter + 1 + + if ssListP == []: + msg='''Shard space setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete shard space setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def configure_gsm_sspace(self,sspace,chunks,repfactor,repunits,protectedmode,type): + """ + This function configure the Shard Group. + """ + self.ocommon.log_info_message("Inside configure_gsm_sspace()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + if type == 'MODIFY': + cmd=''' modify shardspace -shardspace {0} '''.format(sspace) + else: + cmd=''' add shardspace -shardspace {0} '''.format(sspace) + if chunks is not None: + cmd = cmd + ''' -chunks {0}'''.format(chunks) + if repfactor: + cmd = cmd + ''' -repfactor {0}'''.format(repfactor) + if repunits is not None: + cmd = cmd + ''' -repunits {0}'''.format(repfactor) + if protectedmode is not None: + cmd = cmd + ''' -protectedmode {0}'''.format(protectedmode) + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + exit; + '''.format("NA",cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + #########################################Shard Function Begins Here ############################## + def setup_gsm_shard(self): + """ + This function setup and add shard in the GSM + """ + self.ocommon.log_info_message("Inside setup_gsm_shard()",self.file_name) + status=False + reg_exp= self.shard_regex() + counter=1 + end_counter=60 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,sregion,sspace=self.process_shard_vars(key) + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + if shard_db_status == 'completed': + self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,sregion,sspace) + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + status = self.check_shard_status(None) + if status == 'completed': + break + else: + msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + status = self.check_shard_status(None) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 60 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def add_gsm_shard(self): + """ + This function add the shard in the GSM + """ + self.ocommon.log_info_message("Inside add_gsm_shard()",self.file_name) + status=False + reg_exp= self.add_shard_regex() + counter=1 + end_counter=3 + shard_name="none" + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + self.ocommon.log_info_message("Shard Status : " + shard_db_status,self.file_name) + if shard_db_status == 'completed': + self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,shard_region,shard_space) + counter2=1 + end_counter2=5 + while counter2 < end_counter2: + status1 = self.check_shard_status(shard_name) + if status1 == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + break + else: + msg='''Shard DB is still not added in GSM. Sleeping for 60 seconds''' + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter2=counter2+1 + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + status = self.check_shard_status(None) + if status == 'completed': + break + else: + msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + status = self.check_shard_status(shard_name) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 3 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def remove_gsm_shard(self): + """ + This function remove the shard in the GSM + """ + self.ocommon.log_info_message("Inside remove_gsm_shard()",self.file_name) + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars("CATALOG_PARAMS") + numOfShards=self.count_online_shards() + status=False + reg_exp=self.remove_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shardname_to_delete=shard_db + "_" + shard_pdb + if repl_type is not None: + if(repl_type.upper() == 'NATIVE'): + self.move_shards_leader_rus(shardname_to_delete) + leaderCount=self.count_leader_shards(shardname_to_delete) + if(numOfShards < 4 or leaderCount > 0): + msg='''ruType=[{0}]. NumofShards=[{1}]. LeaderCount=[{2}]. Ignoring remove of shard [{3}]'''.format(repl_type,numOfShards,leaderCount,shardname_to_delete) + self.ocommon.log_info_message(msg,self.file_name) + break + + self.move_shard_rus(shardname_to_delete,None,None) + while self.count_shard_rus(shardname_to_delete) > 0: + self.ocommon.log_info_message("Waiting for all the shard chunks to be moved.",self.file_name) + time.sleep(15) + + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + if shard_db_status == 'completed': + self.delete_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group) + status=True + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + return status + + def move_shards_leader_rus(self,shardname_to_delete): + """ + This function move the shard leader RUs + """ + shards=self.get_online_shards() + leader_ru=self.get_rus(shardname_to_delete) + all_ru=self.get_rus(None) + count=0 + target_shards=[] + value=0 + + if len(shards) == 0: + msg="""No Shard is online so no RU is available to be moved""" + self.ocommon.log_info_message(msg,self.file_name) + else: + for line in leader_ru: + value=None + count += 1 + cols=line.split() + if len(cols) > 0: + if cols[0].lower() == shardname_to_delete.lower(): + if cols[1].isdigit: + value = int(cols[1]) + else: + continue + + target_shards.clear() + for line1 in all_ru: + cols1=line1.split() + print(cols1) + if len(cols1) > 5: + if cols1[0].lower() != shardname_to_delete.lower() and cols1[1].isdigit and cols1[2].lower() == 'follower': + if value is not None: + if int(cols1[1]) == value: + target_shards.append(cols1[0]) + break + + for shard in shards: + if shard.lower() != shardname_to_delete.lower(): + if shard in target_shards: + msg="Shard_name= " + shard + " Status=True" + " Value = " + str(value) + self.ocommon.log_info_message(msg,self.file_name) + self.move_shard_rus(shardname_to_delete,shard,value) + + def move_shard_chunks(self): + """ + This function move the shard chunks + """ + self.ocommon.log_info_message("Inside move_shard_chunks()",self.file_name) + status=False + reg_exp= self.move_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + shard_num = self.count_online_shards() + online_shard = self.check_online_shard(shard_name) + if shard_num > 1 and online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + MOVE CHUNK -CHUNK ALL -SOURCE {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def validate_nochunks(self): + """ + This function check the chnunks + """ + self.ocommon.log_info_message("Inside validate_nochunks()",self.file_name) + status=False + reg_exp= self.move_nochunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + shard_num = self.count_online_shards() + online_shard = self.check_online_shard(shard_name) + if shard_num > 1 and online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config chunks -shard {0} + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + matched_output=re.findall("(?:Chunks\n)(?:.+\n)+",output) + if self.ocommon.check_substr_match(matched_output[0].lower(),shard_name.lower()): + self.ocommon.prog_exit("127") + + def move_chunks_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside move_chnuks_regex()",self.file_name) + return re.compile('MOVE_CHUNKS') + + def move_nochunks_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside move_nochunks_regex()",self.file_name) + return re.compile('VALIDATE_NOCHUNKS') + + def check_shard_chunks(self): + """ + This function check the shard chunks + """ + self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) + status=False + reg_exp= self.check_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config chunks -shard {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + + def check_chunks_regex(self): + """ + This function return the rgex to search the chunks + """ + self.ocommon.log_info_message("Inside check_chunks_regex()",self.file_name) + return re.compile('CHECK_CHUNKS') + + def cancel_move_chunks(self): + """ + This function cancel the shard Chunks + """ + self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) + status=False + reg_exp= self.cancel_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 1: + self.ocommon.log_info_message("Shard is not online. Performing chunk cancellation in GSM to set the shard chunk status.",self.file_name) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + ALTER MOVE -cancel -SHARD {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + else: + self.ocommon.log_info_message("Shard " + shard_name + " is online. Unable to perform chunk cancellation.",self.file_name) + + def cancel_chunks_regex(self): + """ + This function return the cancel chunk movement + """ + self.ocommon.log_info_message("Inside cancel_chunks_regex()",self.file_name) + return re.compile('CANCEL_CHUNKS') + + def verify_online_shard(self): + """ + This function verify online shard + """ + self.ocommon.log_info_message("Inside verify_online_shard()",self.file_name) + status=False + reg_exp= self.online_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 0: + msg='''Shard {0} is online.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} is not online.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + + def online_shard_regex(self): + """ + This function return the rgex to search the ONLINE Shards + """ + self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) + return re.compile('CHECK_ONLINE_SHARD') + + def check_online_shard(self,shard_name): + """ + This function check the online shard + """ + self.ocommon.log_info_message("Inside check_online_shard()",self.file_name) + name_flag = False + availability_flag = False + state_flag = False + status_flag = False + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config shard -shard {0}; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + lines = output.split("\n") + for line in lines: + list1 = line.split(":") + if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): + name_flag = True + if list1[0].strip().lower() == 'Availability'.lower() and list1[1].strip().lower() == 'ONLINE'.lower(): + availability_flag = True + if list1[0].strip().lower() == 'STATUS'.lower() and list1[1].strip().lower() == 'OK'.lower(): + status_flag = True + if list1[0].strip().lower() == 'STATE'.lower() and list1[1].strip().lower() == 'DEPLOYED'.lower(): + state_flag = True + + del list1[:] + + if name_flag and availability_flag and state_flag and status_flag: + return 0 + else: + return 1 + + def verify_gsm_shard(self): + """ + This function verify GSM shard + """ + self.ocommon.log_info_message("Inside verify_gsm_shard()",self.file_name) + status=False + reg_exp= self.check_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + gsm_shard = self.check_gsm_shard(shard_name) + if gsm_shard == 0: + msg='''Shard {0} is present in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} is not present in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + def check_shard_regex(self): + """ + This function return the rgex to search the Shards in GSM + """ + self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) + return re.compile('CHECK_GSM_SHARD') + + def check_gsm_shard(self,shard_name): + """ + This function check the shard in gsm + """ + self.ocommon.log_info_message("Inside check_gsm_shard()",self.file_name) + name_flag = False + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config shard -shard {0}; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + lines = output.split("\n") + for line in lines: + list1 = line.split(":") + if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): + name_flag = True + + del list1[:] + + if name_flag: + return 0 + else: + return 1 + + def count_online_shards(self): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside count_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + config shard; + exit; + '''.format(cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + online_shard = 0 + lines = output.split("\n") + for line in lines: + if re.search('ok', line, re.IGNORECASE): + if re.search('deployed', line, re.IGNORECASE): + if re.search('online', line, re.IGNORECASE): + online_shard = online_shard + 1 + + return online_shard + + def get_online_shards(self): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + config shard; + exit; + '''.format(cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + shards=[] + online_shard = 0 + for line in output.split("\n"): + cols=line.split() + print(cols) + if len(cols) >= 5: + if cols[5].lower() == "online" and cols[2].lower() == "ok": + shards.append(cols[0]) + + return shards + + def get_rus(self,shardname_to_delete): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd=None + if shardname_to_delete is not None: + cmd='''status ru -leaders -shard {0}'''.format(shardname_to_delete) + else: + cmd='''status ru''' + + gsmcmd=''' + connect {0}/{1}; + {2}; + exit; + '''.format(cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + return output.split('\n') + + def move_shard_rus(self,sshard,tshard,runum): + """ + This function move the shard rus + """ + self.ocommon.log_info_message("Inside move_shard_rus()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd1="" + cmd2="" + shardname=sshard + if tshard is not None and runum is not None: + cmd1='''switchover ru -RU {0} -shard {1}'''.format(runum,tshard) + else: + cmd1='''MOVE RU -RU ALL -SOURCE {0}'''.format(shardname) + + gsmcmd=''' + connect {1}/{2}; + configure -verbose off -save_config; + {3}; + status RU -shard {0}; + exit; + '''.format(shardname,cadmin,cpasswd,cmd1,cmd2) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def count_shard_rus(self,shardname): + """ + This function return the returns the count of online shard chunks + """ + self.ocommon.log_info_message("Inside count_shard_chunks()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + status ru -shard {2}; + exit; + '''.format(cadmin,cpasswd,shardname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ru_count = 0 + lines = output.split("\n") + for line in lines: + if re.search(shardname, line, re.IGNORECASE): + ru_count = ru_count + 1 + + return ru_count + + def count_leader_shards(self,shardName): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside count_leader_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + status ru -shard {2} -leaders; + exit; + '''.format(cadmin,cpasswd,shardName) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + leader_shard = 0 + lines = output.split("\n") + for line in lines: + if re.search('ok', line, re.IGNORECASE): + if re.search('Leader', line, re.IGNORECASE): + leader_shard = leader_shard + 1 + + return leader_shard + + def validate_gsm_shard(self): + """ + This function validate the shard in the GSM + """ + self.ocommon.log_info_message("Inside validate_gsm_shard()",self.file_name) + status=False + reg_exp= self.validate_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + status = self.check_shard_status(shard_name) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} info does not exist in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + def process_shard_vars(self,key): + """ + This function process sgard vars based on key and return values to configure the GSM + """ + shard_db=None + shard_pdb=None + shard_port=None + shard_group=None + shard_host=None + shard_region=None + shard_space=None + shard_deploy_as=None + + self.ocommon.log_info_message("Inside process_shard_vars()",self.file_name) + # self.ocommon.log_info_message(key,self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_str=cvar_str.replace('"', '') + # self.ocommon.log_info_message(cvar_str,self.file_name) + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + # self.ocommon.log_info_message("key : " + ckey,self.file_name) + # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) + if ckey == 'shard_db': + shard_db = cvar_dict[ckey] + if ckey == 'shard_pdb': + shard_pdb = cvar_dict[ckey] + if ckey == 'shard_port': + shard_port = cvar_dict[ckey] + if ckey == 'shard_group': + shard_group = cvar_dict[ckey] + if ckey == 'shard_host': + shard_host = cvar_dict[ckey] + if ckey == 'shard_region': + #shard_region = self.validate_shard_param("region",cvar_dict[ckey]) + shard_region=cvar_dict[ckey] + if ckey == 'deploy_as': + shard_deploy_as=cvar_dict[ckey] + if ckey == 'shard_space': + #shard_space = self.validate_shard_param("shardspace",cvar_dict[ckey]) + shard_space=cvar_dict[ckey] + # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) + ## Set the values if not set in above block + if not shard_port: + shard_port=1521 + + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + shard_group="nogrp" + if not shard_deploy_as: + self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS","primary",self.ora_env_dict) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS",shard_deploy_as,self.ora_env_dict) + + ### Check values must be set + if shard_host and shard_db and shard_pdb and shard_port and shard_group: + return shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space + else: + msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) + msg2='''shard_port={0},shard_host={1}'''.format((shard_port or "Missing Value"),(shard_host or "Missing Value")) + msg3='''shard_group={0}'''.format((shard_group or "Missing Value")) + msg='''Shard DB params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def validate_shard_param(self,param_type,value): + """ + This function validaet the shard param such as region and shardspace + """ + status=False + reg_exp= self.catalog_regex() + stype=None + sspace=None + catalog_region=None + self.ocommon.log_info_message("Processing GSM params to verify the region and shardspace",self.file_name) + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + + if param_type == 'region': + if stype: + status=self.ocommon.find_str_in_string(catalog_region,'comma',value) + if status: + + return value + else: + return "" + + if param_type == 'shardspace': + if sspace: + status=self.ocommon.find_str_in_string(sspace,'comma',value) + if status: + return value + else: + return "" + + return False + + def process_chunks_vars(self,key): + """ + This function process the chunks vars + """ + shard_db=None + shard_pdb=None + self.ocommon.log_info_message("Inside process_chunks_vars()",self.file_name) + # self.ocommon.log_info_message(key,self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_str=cvar_str.replace('"', '') + # self.ocommon.log_info_message(cvar_str,self.file_name) + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + # self.ocommon.log_info_message("key : " + ckey,self.file_name) + # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) + if ckey == 'shard_db': + shard_db = cvar_dict[ckey] + if ckey == 'shard_pdb': + shard_pdb = cvar_dict[ckey] + # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) + ## Set the values if not set in above block + + ### Check values must be set + if shard_pdb and shard_db: + return shard_db,shard_pdb + else: + msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) + self.ocommon.log_info_message(msg1,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_shard_status(self,shard_name): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_shard_status()",self.file_name) + #gsmcmd=self.get_gsm_config_cmd(dname) + gsmcmd=''' + config; + exit; + ''' + counter=1 + end_counter=3 + status=False + while counter < end_counter: + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + error_check=re.findall("(?:GSM-45034\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(error_check[0],"GSM-45034"): + count = counter + 1 + self.ocommon.log_info_message("Issue in catalog connection, retrying to connect to catalog in 30 seconds!",self.file_name) + time.sleep(20) + status=False + continue + except: + status=False + matched_output=re.findall("(?:Databases\n)(?:.+\n)+",output) + if shard_name: + try: + if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): + status=True + break + else: + status=False + except: + status=False + else: + reg_exp= self.shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_region,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + try: + if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): + status=True + else: + status=False + except: + status=False + if status: + break; + counter = counter + 1 + + return(self.ocommon.check_status_value(status)) + + def shard_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside shard_regex()",self.file_name) + return re.compile('SHARD[0-9]+_PARAMS') + + def add_shard_regex(self): + """ + This function return the rgex to search the ADD_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside add_shard_regex()",self.file_name) + return re.compile('ADD_SHARD') + + def remove_shard_regex(self): + """ + This function return the rgex to search the REMOVE_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) + return re.compile('REMOVE_SHARD') + + def validate_shard_regex(self): + """ + This function return the rgex to search the VALIDATE_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) + return re.compile('VALIDATE_SHARD') + + def configure_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup,sregion,sspace): + """ + This function configure the shard db. + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + #dtrname,dtrport,dtregion=self.process_director_vars() + #group_region=self.get_shardg_region_name(sgroup) + #dtrname=self.get_director_name(group_region) + shard_name='''{0}_{1}'''.format(scdb,spdb) + shard_region=None + shard_space=None + shard_group=None + deploy_as=None + + if sregion: + regionFlag=self.check_gsm_region(sregion) + if regionFlag != 'completed': + self.configure_gsm_region(sregion) + shard_region=" -region {0}".format(sregion) + else: + shard_region="" + if sspace: + shard_space=" -shardspace {0}".format(sspace) + else: + shard_space="" + + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + sspaceFlag=self.check_gsm_shardspace(sspace) + if sspaceFlag != 'completed': + self.configure_gsm_sspace(sspace,None,None,None,None,'add') + shard_group="" + deploy_as,deploy_type=self.get_shard_deploy() + else: + shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) + shard_region="" + else: + shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) + shard_region="" + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + add cdb -connect {3}:{4}/{5} -pwd {2}; + add shard -cdb {5} -connect "(DESCRIPTION = (ADDRESS = (PROTOCOL = tcp)(HOST = {3})(PORT = {4})) (CONNECT_DATA = (SERVICE_NAME = {6}) (SERVER = DEDICATED)))" {7} -pwd {2} {9} {10} {11}; + config vncr; + exit; + '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,shard_group,shard_name,shard_region,shard_space,deploy_as) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def get_shard_deploy(self): + """ + get the shard deploy + """ + deploy_as=None + deploy_type=None + if self.ocommon.check_key("SHARD_DEPLOY_AS",self.ora_env_dict): + deploy_as="-deploy_as {0}".format(self.ora_env_dict["SHARD_DEPLOY_AS"]) + deploy_type=self.ora_env_dict["SHARD_DEPLOY_AS"] + else: + deploy_as="-deploy_as primary" + deploy_type='primary' + + return deploy_as,deploy_type + + def get_shardg_cmd(self,sgroup,sregion): + """ + Getting shard group cmd + """ + sgFlag=self.check_shardg_status(sgroup,None) + deploy_as,deploy_type=self.get_shard_deploy() + if sgFlag != 'completed': + self.configure_gsm_shardg(sgroup,deploy_type,sregion,'add') + else: + self.ocommon.log_info_message("Shardgroup exist " + sgroup, self.file_name) + + deploy_as="" + cmd=''' -shardgroup {0}'''.format(sgroup) + return cmd,deploy_as + + def delete_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup): + """ + This function delete the shard db. + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + shard_name='''{0}_{1}'''.format(scdb,spdb) + #group_region=self.get_shardg_region_name(sgroup) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + remove shard -shard {8}; + remove cdb -cdb {5}; + remove invitednode {3}; + config vncr; + exit; + '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,sgroup,shard_name) + + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_hostid_null(self): + """ + This function set the hostid to Null + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_pdb,admuser) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting host Id null in catalog as auto vncr is disabled''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set echo on + set termout on + set time on + update gsmadmin_internal.database set hostid=NULL; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + self.ocommon.unset_mask_str() + + def invited_node_op(self): + """ + This function perform the invitedaddition and deletion + """ + self.ocommon.log_info_message("Inside invited_node_op()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + shard_host=self.ora_env_dict["INVITED_NODE_OP"] + gsmcmd=''' + connect {1}/{2}; + remove invitednode {3}; + add invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,shard_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + def add_invited_node(self,op_str): + """ + This function add the invited in the GSM configuration + """ + self.ocommon.log_info_message("Inside add_invited_node()",self.file_name) + if op_str == "SHARD": + reg_exp = self.shard_regex() + else: + reg_exp = self.add_shard_regex() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + #group_region=self.get_shardg_region_name(shard_group) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + add invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,shard_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + def remove_invited_node(self,op_str): + """ + This function remove the invited in the GSM configuration + """ + self.ocommon.log_info_message("Inside remove_invited_node()",self.file_name) + if op_str == "SHARD": + reg_exp = self.shard_regex() + else: + reg_exp = self.add_shard_regex() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + temp_host= shard_host.split('.',1)[0] + #group_region=self.get_shardg_region_name(shard_group) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + remove invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,temp_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + else: + self.ocommon.log_info_message("KUBE_SVC is not set. No need to remove invited node!",self.file_name) + + + def deploy_shard(self): + """ + This function deploy shard + """ + self.ocommon.log_info_message("Inside deploy_shard()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + shrdg_sspace=None + #dtrname,dtrport,dtregion=self.process_director_vars() + #if op_str == "SHARD": + # reg_exp = self.shard_regex() + #else: + # reg_exp = self.add_shard_regex() + + #for key in self.ora_env_dict.keys(): + # if(reg_exp.match(key)): + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + shardg_shardspace="config shardspace" + else: + shardg_shardspace="config shardgroup" + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + config vncr; + deploy; + config shard; + exit; + '''.format("test",cadmin,cpasswd,shardg_shardspace) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def check_setup_status(self,host,ccdb,svc,port): + """ + This function check the shard status. + """ + systemStr='''{0}/bin/sqlplus "system/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,ccdb) + + fname='''/tmp/{0}'''.format("shard_setup.txt") + self.ocommon.remove_file(fname) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool {0} + select * from shardsetup WHERE ROWNUM = 1; + spool off + exit; + '''.format(fname) + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + if os.path.isfile(fname): + fdata=self.ocommon.read_file(fname) + else: + fdata='nosetup' + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + status = self.catalog_pdb_setup_check(host,ccdb,svc,port) + if status == 'completed': + return 'completed' + else: + return 'notcompleted' + else: + return 'notcompleted' + + + def catalog_pdb_setup_check(self,host,ccdb,svc,port): + """ + This function check the shard status. + """ + systemStr='''{0}/bin/sqlplus "pdbadmin/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,svc) + + fname='''/tmp/{0}'''.format("pdb_setup_check.txt") + self.ocommon.remove_file(fname) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Checking setup status in PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool {0} + select count(*) from dual; + spool off + exit; + '''.format(fname) + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + if os.path.isfile(fname): + fdata=self.ocommon.read_file(fname) + else: + fdata='nosetup' + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + if re.search('1',fdata): + return 'completed' + else: + return 'notcompleted' + + ############################# Setup GSM Service ############################################### + def setup_gsm_service(self): + """ + This function setup the shard service. + """ + self.ocommon.log_info_message("Inside setup_gsm_service()",self.file_name) + status=False + service_value="service_name=oltp_rw_svc;service_role=primary" + # self.ora_env_dict=self.ocommon.add_key("SERVICE1_PARAMS",service_value,self.ora_env_dict) + reg_exp= self.service_regex() + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_service_status=None + service_name,service_role=self.process_service_vars(key) + shard_service_status=self.check_service_status(service_name) + if shard_service_status != 'completed': + self.configure_gsm_service(service_name,service_role) + status = self.check_service_status(None) + if status == 'completed': + break + else: + msg='''GSM service setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + time.sleep(60) + counter=counter+1 + + status = self.check_service_status(None) + if status == 'completed': + msg='''Shard service setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def process_service_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + service_name=None + service_role=None + + self.ocommon.log_info_message("Inside process_service_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'service_name': + service_name = cvar_dict[ckey] + if ckey == 'service_role': + service_role = cvar_dict[ckey] + + ### Check values must be set + if service_name and service_role: + return service_name,service_role + else: + msg1='''service_name={0},service_role={1}'''.format((service_name or "Missing Value"),(service_role or "Missing Value")) + msg='''Shard service params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_service_status(self,service_name): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_service_status()",self.file_name) + #dtrname,dtrport,dtregion=self.process_director_vars() + gsmcmd=''' + config; + exit; + '''.format("test") + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Services\n)(?:.+\n)+",output) + status=False + if service_name: + try: + if self.ocommon.check_substr_match(matched_output[0],service_name): + status=True + else: + status=False + except: + status=False + else: + reg_exp= self.service_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + service_name,service_role=self.process_service_vars(key) + # match=re.search("(?i)(?m)"+service_name,matched_output) + try: + if self.ocommon.check_substr_match(matched_output[0],service_name): + status=True + else: + status=False + except: + status=False + + return(self.ocommon.check_status_value(status)) + + def service_regex(self): + """ + This function return the rgex to search the SERVICE[0-9]_PARAMS + """ + self.ocommon.log_info_message("Inside service_regex()",self.file_name) + return re.compile('SERVICE[0-9]+_PARAMS') + + def configure_gsm_service(self,service_name,service_role): + """ + This function configure the service creation. + """ + self.ocommon.log_info_message("Inside configure_gsm_service()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + add service -service {3} -role {4}; + start service -service {3}; + exit; + '''.format("test",cadmin,cpasswd,service_name,service_role) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ############################## GSM backup fIle function Begins Here ############################# + def gsm_backup_file(self): + """ + This function check the gsm setup status + """ + self.ocommon.log_info_message("Inside gsm_backup_file()",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) + + if os.path.isdir(gsmdata_loc): + msg='''Directory {0} exit'''.format(gsmdata_loc) + self.ocommon.log_info_message(msg,self.file_name) + + cmd='''cp -r -v {0}/* {1}/'''.format(gsmfile_loc,gsmdata_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############### Deploy Sample Function Begins Here ########################## + def setup_sample_schema(self): + """ + This function deploy the sample app + """ + s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?" + passlen = 8 + passwd = "".join(random.sample(s,passlen )) + self.ocommon.log_info_message("Inside deploy_sample_schema()",self.file_name) + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_db) + if self.ocommon.check_key("SAMPLE_SCHEMA",self.ora_env_dict): + if self.ora_env_dict["SAMPLE_SCHEMA"] == 'DEPLOY': + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Deploying sample schema''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set echo on + set termout on + set time on + spool /tmp/create_app_schema.lst + REM + REM Connect to the Shard Catalog and Create Schema + REM + alter session enable shard ddl; + alter session set container={2}; + alter session enable shard ddl; + create user app_schema identified by {3}; + grant connect, resource, alter session to app_schema; + grant execute on dbms_crypto to app_schema; + grant create table, create procedure, create tablespace, create materialized view to app_schema; + grant unlimited tablespace to app_schema; + grant select_catalog_role to app_schema; + grant all privileges to app_schema; + grant gsmadmin_role to app_schema; + grant dba to app_schema; + CREATE TABLESPACE SET tbsset1 IN SHARDSPACE shd1; + CREATE TABLESPACE SET tbsset2 IN SHARDSPACE shd2; + connect app_schema/{3}@{0}:{1}/{2} + alter session enable shard ddl; + + /* Customer shard table */ + + CREATE SHARDED TABLE customer + ( cust_id NUMBER NOT NULL, + cust_passwd VARCHAR2(20) NOT NULL, + cust_name VARCHAR2(60) NOT NULL, + cust_type VARCHAR2(10) NOT NULL, + cust_email VARCHAR2(100) NOT NULL) + partitionset by list (cust_type) + partition by consistent hash (cust_id) partitions auto + (partitionset individual values ('individual') tablespace set tbsset1, + partitionset business values ('business') tablespace set tbsset2 + ); + /* Invoice shard table */ + + CREATE SHARDED TABLE invoice + ( invoice_id NUMBER NOT NULL, + cust_id NUMBER NOT NULL, + cust_type VARCHAR2(10) NOT NULL, + vendor_name VARCHAR2(60) NOT NULL, + balance FLOAT(10) NOT NULL, + total FLOAT(10) NOT NULL, + status VARCHAR2(20), + CONSTRAINT InvoicePK PRIMARY KEY (cust_id, invoice_id)) + PARENT customer + partitionset by list (cust_type) + partition by consistent hash (cust_id) partitions auto + (partitionset individual values ('individual') tablespace set tbsset1, + partitionset business values ('business') tablespace set tbsset2 + ); + /* Data */ + insert into customer values (999, 'pass', 'Customer 999', 'individual', 'customer999@gmail.com'); + insert into customer values (250251, 'pass', 'Customer 250251', 'individual', 'customer250251@yahoo.com'); + insert into customer values (350351, 'pass', 'Customer 350351', 'individual', 'customer350351@gmail.com'); + insert into customer values (550551, 'pass', 'Customer 550551', 'business', 'customer550551@hotmail.com'); + insert into customer values (650651, 'pass', 'Customer 650651', 'business', 'customer650651@live.com'); + insert into invoice values (1001, 999, 'individual', 'VendorA', 10000, 20000, 'Due'); + insert into invoice values (1002, 999, 'individual', 'VendorB', 10000, 20000, 'Due'); + insert into invoice values (1001, 250251, 'individual', 'VendorA', 10000, 20000, 'Due'); + insert into invoice values (1002, 250251, 'individual', 'VendorB', 0, 10000, 'Paid'); + insert into invoice values (1003, 250251, 'individual', 'VendorC', 14000, 15000, 'Due'); + insert into invoice values (1001, 350351, 'individual', 'VendorD', 10000, 20000, 'Due'); + insert into invoice values (1002, 350351, 'individual', 'VendorE', 0, 10000, 'Paid'); + insert into invoice values (1003, 350351, 'individual', 'VendorF', 14000, 15000, 'Due'); + insert into invoice values (1004, 350351, 'individual', 'VendorG', 12000, 15000, 'Due'); + insert into invoice values (1001, 550551, 'business', 'VendorH', 10000, 20000, 'Due'); + insert into invoice values (1002, 550551, 'business', 'VendorI', 0, 10000, 'Paid'); + insert into invoice values (1003, 550551, 'business', 'VendorJ', 14000, 15000, 'Due'); + insert into invoice values (1004, 550551, 'business', 'VendorK', 10000, 20000, 'Due'); + insert into invoice values (1005, 550551, 'business', 'VendorL', 10000, 20000, 'Due'); + insert into invoice values (1006, 550551, 'business', 'VendorM', 0, 10000, 'Paid'); + insert into invoice values (1007, 550551, 'business', 'VendorN', 14000, 15000, 'Due'); + insert into invoice values (1008, 550551, 'business', 'VendorO', 10000, 20000, 'Due'); + insert into invoice values (1001, 650651, 'business', 'VendorT', 10000, 20000, 'Due'); + insert into invoice values (1002, 650651, 'business', 'VendorU', 0, 10000, 'Paid'); + insert into invoice values (1003, 650651, 'business', 'VendorV', 14000, 15000, 'Due'); + insert into invoice values (1004, 650651, 'business', 'VendorW', 10000, 20000, 'Due'); + insert into invoice values (1005, 650651, 'business', 'VendorX', 0, 20000, 'Paid'); + insert into invoice values (1006, 650651, 'business', 'VendorY', 0, 30000, 'Paid'); + insert into invoice values (1007, 650651, 'business', 'VendorZ', 0, 10000, 'Paid'); + commit; + select table_name from user_tables; + spool off + '''.format(catalog_host,catalog_port,catalog_pdb,passwd) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + show ddl; + exit; + '''.format("test",cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oralogger.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oralogger.py new file mode 100755 index 0000000..9a51b54 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oralogger.py @@ -0,0 +1,181 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file provides the functionality to log the event in console and file +""" + +import logging +import os + +class LoggingType(object): + CONSOLE = 1 + FILE = 2 + STDOUT = 3 + +class OraLogger(object): + """ + This is a class constructor which sets parameter for logger. + + Attributes: + filename_ (string): Filename which we need to set to store logs in a file. + """ + def __init__(self, filename_): + """ + This is a class constructor which sets parameter for logger. + + Attributes: + filename_ (string): Filename which we need to set to store logs in a file. + """ + self.filename_ = filename_ + # Set to default values can be changed later from other classes objects + self.console_ = LoggingType.CONSOLE + self.file_ = LoggingType.FILE + self.stdout_ = LoggingType.STDOUT + self.msg_ = None + self.functname_ = None + self.lineno_ = None + self.logtype_ = "INFO" + self.fmtstr_ = "%(asctime)s: %(levelname)s: %(message)s" + self.datestr_ = "%m/%d/%Y %I:%M:%S %p" + self.root = logging.getLogger() + self.root.setLevel(logging.DEBUG) + self.formatter = logging.Formatter('%(asctime)s %(levelname)8s:%(message)s', "%m/%d/%Y %I:%M:%S %p") + self.stdoutfile_ = "/proc/1/fd/1" + # self.stdoutfile_ = "/tmp/test.log" + + def getStdOutValue(self): + return self.stdout_ + +class Handler(object): + """ + This is a class which sets the handler for next logger. + """ + def __init__(self): + """ + This is a handler class constructor and nexthandler is set to None. + """ + self.nextHandler = None + + def handle(self, request): + ''' + This is a function which set the next handler. + + Attributes: + request (object): Object of the class oralogger. + ''' + self.nextHandler.handle(request) + + def print_message(self,request,lhandler): + """ + This function set the log type to INFO, WARN, DEBUG and CRITICAL. + + Attribute: + request (object): Object of the class oralogger. + lhandler: This parameter accept the loghandler. + """ + if request.logtype_ == "WARN": + request.root.warning(request.msg_) + elif request.logtype_ == "DEBUG": + request.root.debug(request.msg_) + elif request.logtype_ == "CRITICAL": + request.root.critical(request.msg_) + elif request.logtype_ == "ERROR": + request.root.error(request.msg_) + else: + request.root.info(request.msg_) + + request.root.removeHandler(lhandler) + +class FHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribut: + request: Object of OraLogger + """ + if request.file_ == LoggingType.FILE: + fh = logging.FileHandler(request.filename_) + request.root.addHandler(fh) + fh.setFormatter(request.formatter) + self.print_message(request,fh) + super(FHandler, self).handle(request) + else: + super(FHandler, self).handle(request) + + def print_message(self,request,fh): + """ + This function log the message to console/file/stdout. + """ + super(FHandler, self).print_message(request,fh) + +class CHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribute: + request: Object of OraLogger + """ + if request.console_ == LoggingType.CONSOLE: + # ch = logging.StreamHandler() + ch = logging.FileHandler("/tmp/test.log") + request.root.addHandler(ch) + ch.setFormatter(request.formatter) + self.print_message(request,ch) + super(CHandler, self).handle(request) + else: + super(CHandler, self).handle(request) + + def print_message(self,request,ch): + """ + This function log the message to console/file/stdout. + """ + super(CHandler, self).print_message(request,ch) + + +class StdHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribute: + request: Object of OraLogger + """ + request.stdout_ = request.getStdOutValue() + if request.stdout_ == LoggingType.STDOUT: + st = logging.FileHandler(request.stdoutfile_,mode="w") + request.root.addHandler(st) + st.setFormatter(request.formatter) + self.print_message(request,st) + super(StdHandler, self).handle(request) + else: + super(StdHandler, self).handle(request) + + def print_message(self,request,st): + """ + This function log the message to console/file/stdout. + """ + super(StdHandler, self).print_message(request,st) + +class PassHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self, request): + pass diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oramachine.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oramachine.py new file mode 100755 index 0000000..2d1431a --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oramachine.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +import os +import sys + +class OraMachine: + """ + This calss setup the compute before starting the installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraMachine class to setup the compute + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + + def setup(self): + """ + This function setup the compute before starting the installation + """ + msg="Machine setup completed sucessfully!" + self.ocommon.log_info_message(msg,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapcatalog.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapcatalog.py new file mode 100755 index 0000000..6638860 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapcatalog.py @@ -0,0 +1,748 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +class OraPCatalog: + """ + This calss setup the Catalog after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraCatalog class to setup the catalog on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def setup(self): + """ + This function setup the catalog on Primary DB. + """ + if self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) + self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) + if os.path.exists(create_db_file_lck): + self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) + sys.exit(127) + elif os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) + status = self.catalog_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) + sys.exit(0) + else: + status = self.catalog_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): + status = self.catalog_setup_check() + if not status: + self.ocommon.log_info_message("Catalog readyness check completed sucessfully!",self.file_name) + self.ocommon.prog_exit("127") + elif self.ocommon.check_key("RESET_PASSWORD",self.ora_env_dict): + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + if os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Catalog database up and running. Resetting password...",self.file_name) + else: + self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to reset password",self.file_name) + self.ocommon.prog_exit("127") + elif self.ocommon.check_key("EXPORT_TDE_KEY",self.ora_env_dict): + exist_db_file_lck=self.ocommon.get_db_lock_location()+ self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + if os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Catalog database up and running.",self.file_name) + self.ocommon.export_tde_key(self.ora_env_dict["EXPORT_TDE_KEY"]) + else: + self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to export the tde key",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_machine() + self.db_checks() + self.reset_catalog_setup() + status = self.catalog_setup_check() + if status: + self.ocommon.log_info_message("catalog Setup is already completed on this database",self.file_name) + else: + self.reset_passwd() + self.setup_cdb_catalog() + self.set_spfile_nonm_params() + self.ocommon.set_events("spfile") + self.set_dbparams_version() + self.restart_db() + self.alter_db() + self.setup_pdb_catalog() + self.set_primary_listener() + self.restart_listener() + self.register_services() + self.list_services() + self.backup_files() + self.update_catalog_setup() + self.gsm_completion_message() + self.run_custom_scripts() + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + + ########### SETUP_MACHINE ENDS here #################### + + ########### DB_CHECKS Related Functions Begin Here #################### + ## Function to perfom DB checks ###### + def db_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.set_user() + self.sid_check() + self.dbuinque_name_check() + self.hostname_check() + self.dbport_check() + self.dbr_dest_checks() + self.dpump_dir_checks() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit() + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def passwd_check(self): + """ + Function to set the password + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def set_user(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def sid_check(self): + """ + This funnction heck and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): + msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="ORACLE_SID is not set, existing!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def dbuinque_name_check(self): + """ + This funnction check and set the db unique name for standby + """ + if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" + self.ocommon.log_info_message(msg,self.file_name) + dbsid=self.ora_env_dict["ORACLE_SID"] + self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) + + + def hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + # hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def dbport_check(self): + """ + This funnction checks and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("DB_PORT",self.ora_env_dict): + msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) + msg="DB_PORT is not set, setting default to 1521" + self.ocommon.log_info_message(msg,self.file_name) + + def dbr_dest_checks(self): + """ + This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. + """ + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) + + # Checking the DB_RECOVERY_FILE_DEST_SIZE + + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the DB_CREATE_FILE_DEST + + if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): + msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) + + + def dpump_dir_checks(self): + """ + This funnction checks and set the DATA_PUMP dir and location. + """ + if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): + msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) + self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) + msg='''DATA_PUMP_DIR set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) + + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## RESET_PASSWORD function Begin here ############################# + ## Function to perform password reset + def reset_passwd(self): + """ + This function reset the password. + """ + self.ocommon.reset_passwd() + + ########## RESET_PASSWORD function ENDS here ############################# + + ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### + + def reset_catalog_setup(self): + """ + This function drop teh catalog setup table and reste the env to default values. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Inside reset_catalog_setup",self.file_name) + catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + if not os.path.isfile(catalog_reset_file): + msg='''Dropping catalogsetup table from CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + drop table system.shardsetup; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + else: + msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(catalog_reset_file) + self.ocommon.log_info_message(msg,self.file_name) + + + def catalog_setup_check(self): + """ + This function check the catalog status. + """ + #systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool /tmp/catalog_setup.txt + select * from system.shardsetup WHERE ROWNUM = 1; + spool off + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + fname='''/tmp/{0}'''.format("catalog_setup.txt") + fdata=self.ocommon.read_file(fname) + ### Unsetting the encrypt value to None + # self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + return True + else: + return False + + def setup_cdb_catalog(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + # Assigning variable + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] + dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] + host_name=self.ora_env_dict["ORACLE_HOSTNAME"] + dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] + db_port=self.ora_env_dict["DB_PORT"] + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting up catalog CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set db_create_file_dest=\"{0}\" scope=both; + alter system set db_recovery_file_dest_size={1} scope=both; + alter system set db_recovery_file_dest=\"{2}\" scope=both; + alter user gsmcatuser account unlock; + alter user gsmcatuser identified by HIDDEN_STRING; + alter system set local_listener='{4}:{5}' scope=both; + '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_spfile_nonm_params(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set open_links_per_instance=16 scope=spfile; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set standby_file_management='AUTO' scope=spfile; + alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; + alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + + def set_dbparams_version(self): + """ + This function setup the shard parameter based on db version. + """ + ohome1=self.ora_env_dict["ORACLE_HOME"] + version=self.ocommon.get_oraversion(ohome1).strip() + self.ocommon.log_info_message(version,self.file_name) + if int(version) > 21: + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set wallet_root=\"{1}/oradata/{2}/{3}\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_db(self): + """ + restarting the db + """ + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + #self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) + #sqlcmd=''' + # alter database archivelog; + # alter database open; + #''' + #output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + #self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + #self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + def setup_pdb_catalog(self): + """ + This function setup the catalog. + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + # Assigning variable + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter pluggable database {0} close immediate; + alter pluggable database {0} open services=All; + ALTER PLUGGABLE DATABASE {0} SAVE STATE; + alter system register; + alter session set container={0}; + create user {1} identified by HIDDEN_STRING; + alter user {1} account unlock; + grant connect, create session, gsmadmin_role to {1}; + grant inherit privileges on user SYS to GSMADMIN_INTERNAL; + execute dbms_xdb.sethttpport(8080); + exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('HIDDEN_STRING'); + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def update_catalog_setup(self): + """ + This function update the catalog setup on this DB. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") + # systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Updating shardsetup table''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + create table system.shardsetup (status varchar2(10)); + insert into system.shardsetup values('completed'); + commit; + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Reset File + catalog_reset_dir='''{0}/.catalog'''.format(self.ora_env_dict["HOME"]) + catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) + + self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) + if not os.path.isdir(catalog_reset_dir): + self.ocommon.create_dir(catalog_reset_dir,True,None,None) + + if not os.path.isfile(catalog_reset_file): + self.ocommon.create_file(catalog_reset_file,True,None,None) + +# self.ocommon.unset_mask_str() + + ########## SETUP_CDB_catalog FUNCTION ENDS HERE ############################### + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + def set_primary_listener(self): + """ + Function to set the primary listener + """ + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + + def set_db_listener(self,gdbname,sid): + """ + Funtion to reset the listener + """ + self.ocommon.log_info_message("Inside reset_listener()",self.file_name) + start = 'SID_LIST_LISTENER' + end = '^\)$' + oracle_home=self.ora_env_dict["ORACLE_HOME"] + lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) + buffer = "SID_LIST_LISTENER=" + '\n' + start_flag = False + try: + with open(lisora) as f: + for line1 in f: + if start_flag == False: + if (re.match(start, line1.strip())): + start_flag = True + elif (re.match(end, line1.strip())): + line2 = f.next() + if (re.match(end, line2.strip())): + break + else: + buffer += line1 + buffer += line2 + else: + if start_flag == True: + buffer += line1 + except: + pass + + if start_flag == True: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + else: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + + wr = open(lisora, 'w') + wr.write(listener) + + def restart_listener(self): + """ + restart listener + """ + self.ocommon.log_info_message("Stopping Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl stop'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + self.ocommon.log_info_message("Starting Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl start'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + + def register_services(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system register; + alter session set container={0}; + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def list_services(self): + """ + restart listener + """ + self.ocommon.log_info_message("Listing Services",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl services'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + + def backup_files(self): + """ + This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig + """ + self.ocommon.log_info_message("Inside backup_files()",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + dbsid=self.ora_env_dict["ORACLE_SID"] + + version=self.ocommon.get_oraversion(ohome).strip() + wallet_backup_cmd='''ls -ltr /bin''' + self.ocommon.log_info_message("Check Version " + version,self.file_name) + if int(version) >= 21: + obase1=self.ora_env_dict["ORACLE_BASE"] + wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) + cmd_names=''' + mkdir -p {0}/oradata/{1}/{2} + cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ + cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ + cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ + touch {0}/oradata/{1}/{2}/status_completed + '''.format(obase,"dbconfig",dbuname,ohome) + cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] + for cmd in cmd_list: + msg='''Executing cmd {0}'''.format(cmd) + self.ocommon.log_info_message(msg,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Catalog Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapshard.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapshard.py new file mode 100755 index 0000000..d1b1273 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapshard.py @@ -0,0 +1,795 @@ +#!/usr/bin/python + +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +import traceback + +class OraPShard: + """ + This calss setup the primary shard after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraPShard class to setup the shard on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + try: + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + except BaseException as ex: + ex_type, ex_value, ex_traceback = sys.exc_info() + trace_back = traceback.extract_tb(ex_traceback) + stack_trace = list() + for trace in trace_back: + stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) + self.ocommon.log_info_message(ex_type.__name__,self.file_name) + self.ocommon.log_info_message(ex_value,self.file_name) + self.ocommon.log_info_message(stack_trace,self.file_name) + def setup(self): + """ + This function setup the shard on Primary DB. + """ + if self.ocommon.check_key("RESET_LISTENER",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) + self.ocommon.prog_exit("127") + self.reset_listener() + self.restart_listener() + if self.ocommon.check_key("RESTART_DB",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.start_db(self.ora_env_dict) + elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) + self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) + if os.path.exists(create_db_file_lck): + self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) + sys.exit(127) + elif os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) + status = self.shard_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) + sys.exit(0) + else: + status = self.shard_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Shard readyness check completed sucessfully!",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_machine() + self.db_checks() + self.reset_shard_setup() + status = self.shard_setup_check() + if status: + self.ocommon.log_info_message("Shard Setup is already completed on this database",self.file_name) + else: + self.reset_passwd() + self.setup_cdb_shard() + self.set_spfile_nonm_params() + self.ocommon.set_events("spfile") + self.set_dbparams_version() + self.restart_db() + self.alter_db() + self.setup_pdb_shard () + self.update_shard_setup() + self.set_primary_listener() + self.restart_listener() + self.register_services() + self.list_services() + self.backup_files() + self.gsm_completion_message() + self.run_custom_scripts() + + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + ########### SETUP_MACHINE ENDS here #################### + + ########### DB_CHECKS Related Functions Begin Here #################### + ## Function to perfom DB checks ###### + def db_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.set_user() + self.sid_check() + self.dbuinque_name_check() + self.hostname_check() + self.dbport_check() + self.dbr_dest_checks() + self.dpump_dir_checks() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit() + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def passwd_check(self): + """ + This funnction perform password related checks + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def set_user(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def sid_check(self): + """ + This funnction heck and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): + msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="ORACLE_SID is not set, existing!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def dbuinque_name_check(self): + """ + This funnction check and set the db unique name for standby + """ + if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" + self.ocommon.log_info_message(msg,self.file_name) + dbsid=self.ora_env_dict["ORACLE_SID"] + self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) + + def hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def dbport_check(self): + """ + This funnction checks and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("DB_PORT",self.ora_env_dict): + msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) + msg="DB_PORT is not set, setting default to 1521" + self.ocommon.log_info_message(msg,self.file_name) + + def dbr_dest_checks(self): + """ + This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. + """ + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) + + # Checking the DB_RECOVERY_FILE_DEST_SIZE + + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the DB_CREATE_FILE_DEST + + if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): + msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) + + + def dpump_dir_checks(self): + """ + This funnction checks and set the DATA_PUMP dir and location. + """ + if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): + msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) + self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) + msg='''DATA_PUMP_DIR set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) + + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## RESET_PASSWORD function Begin here ############################# + ## Function to perform password reset + def reset_passwd(self): + """ + This function reset the password. + """ + self.ocommon.reset_passwd() + + ########## RESET_PASSWORD function ENDS here ############################# + + ########## SETUP_CDB_SHARD FUNCTION BEGIN HERE ############################### + + def reset_shard_setup(self): + """ + This function drop teh shard setup table and reste the env to default values. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Inside reset_shard_setup",self.file_name) + shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + if not os.path.isfile(shard_reset_file): + msg='''Dropping shardsetup table from CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + drop table system.shardsetup; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + else: + msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(shard_reset_file) + self.ocommon.log_info_message(msg,self.file_name) + + + def shard_setup_check(self): + """ + This function check the shard status. + """ +# systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + # self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool /tmp/shard_setup.txt + select * from system.shardsetup WHERE ROWNUM = 1; + spool off + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + fname='''/tmp/{0}'''.format("shard_setup.txt") + fdata=self.ocommon.read_file(fname) + ### Unsetting the encrypt value to None + # self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + return True + else: + return False + + def setup_cdb_shard(self): + """ + This function setup the shard. + """ + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] + dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] + host_name=self.ora_env_dict["ORACLE_HOSTNAME"] + dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] + db_port=self.ora_env_dict["DB_PORT"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting up Shard CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set db_create_file_dest=\"{0}\" scope=both; + alter system set db_recovery_file_dest_size={1} scope=both; + alter system set db_recovery_file_dest=\"{2}\" scope=both; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set standby_file_management='AUTO' scope=spfile; + alter user gsmrootuser account unlock; + grant sysdg to gsmrootuser; + grant sysbackup to gsmrootuser; + alter user gsmrootuser identified by HIDDEN_STRING container=all; + alter user GSMUSER account unlock; + alter user GSMUSER identified by HIDDEN_STRING container=all; + grant sysdg to GSMUSER; + grant sysbackup to GSMUSER; + create or replace directory DATA_PUMP_DIR as '{3}'; + grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; + alter system set local_listener='{4}:{5}' scope=spfile; + '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_spfile_nonm_params(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set open_links_per_instance=16 scope=spfile; + alter system set open_links=16 scope=spfile; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; + alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def set_dbparams_version(self): + """ + This function setup the catalog parameter based on db version. + """ + ohome1=self.ora_env_dict["ORACLE_HOME"] + version=self.ocommon.get_oraversion(ohome1).strip() + self.ocommon.log_info_message(version,self.file_name) + if int(version) > 21: + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + + msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set wallet_root=\"{1}/oradata/{2}/{3}/\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_db(self): + + """ + restarting the db + """ + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + # self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) + # sqlcmd=''' + # alter database archivelog; + # alter database open; + # ''' + # output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + # self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + + def setup_pdb_shard(self): + """ + This function setup the shard. + """ + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up Shard PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter pluggable database {0} close immediate; + alter pluggable database {0} open services=All; + ALTER PLUGGABLE DATABASE {0} SAVE STATE; + alter system register; + alter session set container={0}; + grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; + grant sysdg to GSMUSER; + grant sysbackup to GSMUSER; + execute DBMS_GSM_FIX.validateShard; + alter system register; + '''.format(self.ora_env_dict["ORACLE_PDB"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + def update_shard_setup(self): + """ + This function update the shard setup on this DB. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") + systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + +# self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + + msg='''Updating shardsetup table''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + create table system.shardsetup (status varchar2(10)); + insert into system.shardsetup values('completed'); + commit; + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Reset File + shard_reset_dir='''{0}/.shard'''.format(self.ora_env_dict["HOME"]) + shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) + + self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) + if not os.path.isdir(shard_reset_dir): + self.ocommon.create_dir(shard_reset_dir,True,None,None) + + if not os.path.isfile(shard_reset_file): + self.ocommon.create_file(shard_reset_file,True,None,None) + +# self.ocommon.unset_mask_str() + + ########## SETUP_CDB_SHARD FUNCTION ENDS HERE ############################### + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Shard Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) + ################################ Reset and standby functions ################################################# + + def set_primary_listener(self): + """ + Function to set the primary listener + """ + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + + def set_db_listener(self,gdbname,sid): + """ + Funtion to reset the listener + """ + self.ocommon.log_info_message("Inside reset_listener()",self.file_name) + start = 'SID_LIST_LISTENER' + end = '^\)$' + oracle_home=self.ora_env_dict["ORACLE_HOME"] + lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) + buffer = "SID_LIST_LISTENER=" + '\n' + start_flag = False + try: + with open(lisora) as f: + for line1 in f: + if start_flag == False: + if (re.match(start, line1.strip())): + start_flag = True + elif (re.match(end, line1.strip())): + line2 = f.next() + if (re.match(end, line2.strip())): + break + else: + buffer += line1 + buffer += line2 + else: + if start_flag == True: + buffer += line1 + except: + pass + + if start_flag == True: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + else: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + + wr = open(lisora, 'w') + wr.write(listener) + + def restart_listener(self): + """ + restart listener + """ + self.ocommon.log_info_message("Stopping Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl stop'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + self.ocommon.log_info_message("Starting Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl start'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + def register_services(self): + """ + This function setup the catalog. + """ + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system register; + alter session set container={0}; + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def list_services(self): + """ + restart listener + """ + self.ocommon.log_info_message("Listing Services",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl services'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + def backup_files(self): + """ + This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig + """ + self.ocommon.log_info_message("Inside backup_files()",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + dbsid=self.ora_env_dict["ORACLE_SID"] + + version=self.ocommon.get_oraversion(ohome).strip() + wallet_backup_cmd='''ls -ltr /bin''' + self.ocommon.log_info_message("Check Version " + version,self.file_name) + if int(version) >= 21: + obase1=self.ora_env_dict["ORACLE_BASE"] + wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) + cmd_names=''' + mkdir -p {0}/oradata/{1}/{2} + cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ + cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ + cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ + {4} + touch {0}/oradata/{1}/{2}/status_completed + '''.format(obase,"dbconfig",dbuname,ohome,wallet_backup_cmd) + cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] + for cmd in cmd_list: + msg='''Executing cmd {0}'''.format(cmd) + self.ocommon.log_info_message(msg,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orascatalog.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orascatalog.py new file mode 100755 index 0000000..aa4ea65 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orascatalog.py @@ -0,0 +1,9 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orasshard.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orasshard.py new file mode 100755 index 0000000..58f168b --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orasshard.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +import traceback + +class OraSShard: + """ + This calss setup the standby shard after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraSShard class to setup the shard on standby DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + try: + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + except BaseException as ex: + ex_type, ex_value, ex_traceback = sys.exc_info() + trace_back = traceback.extract_tb(ex_traceback) + stack_trace = list() + for trace in trace_back: + stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) + ocommon.log_info_message(ex_type.__name__,self.file_name) + ocommon.log_info_message(ex_value,self.file_name) + ocommon.log_info_message(stack_trace,self.file_name) + def setup(self): + """ + This function setup the shard on standby DB. + """ + pass diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOraShardSetup.sh b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOraShardSetup.sh new file mode 100755 index 0000000..c1b09b4 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOraShardSetup.sh @@ -0,0 +1,568 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +export CLONED_FILE="status_completed" +export STANDBY_STATUS="status_completed" + +########### Clone Files ##################### +function cloneDB { + +export NEW_ORACLE_SID=$ORACLE_SID +export ORACLE_SID=$OLD_ORACLE_SID +sqlplus / as sysdba << EOF + STARTUP mount; + exit; +EOF + +echo 'Y' | nid target=/ dbname="$NEW_ORACLE_SID" + +if [ $? -eq 0 ]; then + echo "DB name changed sucessfully" +else + echo "DB name change process failed" + exit 1; +fi + +if [ -z ${DB_RECOVERY_FILE_DEST} ]; then + export DB_RECOVERY_FILE_DEST=$ORACLE_BASE/oradata/fast_recovery_area/$NEW_ORACLE_SID +fi + +if [ -z ${DB_UNIQUE_NAME} ]; then + export DB_UNIQUE_NAME=$NEW_ORACLE_SID +fi + +export ORACLE_HOSTNAME=$( hostname -f ) + +echo "Changing DB name" +export ORACLE_SID=$NEW_ORACLE_SID +sqlplus / as sysdba << EOF + STARTUP nomount; + alter system set db_name=$ORACLE_SID scope=spfile; + alter system set open_links=16 scope=spfile; + alter system set open_links_per_instance=16 scope=spfile; + alter system set dg_broker_config_file1="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr2$DB_UNIQUE_NAME.dat" scope=spfile; + alter system set dg_broker_config_file2="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr1$DB_UNIQUE_NAME.dat" scope=spfile; + alter system set db_file_name_convert='*','$ORACLE_BASE/oradata/$DB_UNIQUE_NAME/' scope=spfile; + alter system set local_listener='$ORACLE_HOSTNAME' scope=spfile; + alter system set standby_file_management='auto' scope=spfile; + shutdown immediate + exit; +EOF + +## Get the version + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 21 ]; then + echo "Setting DB Parameter based on the vserion" + export ORACLE_SID=$NEW_ORACLE_SID + sqlplus / as sysdba << EOF + startup nomount + alter system set wallet_root="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME" scope=spfile; + shutdown immediate + exit; +EOF + fi + fi + +echo "Changing OLD SID string to new string" +sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_HOME/network/admin/tnsnames.ora +sed -i "s/$OLD_ORACLE_PDB/$ORACLE_PDB/g" $ORACLE_HOME/network/admin/tnsnames.ora + +echo "Starting Listener" + +$ORACLE_HOME/bin/lsnrctl start + +echo "Starting new cloned DB" + +sqlplus / as sysdba << EOF + STARTUP mount; + alter database archivelog; + alter database open resetlogs; + exit; +EOF + +echo "Renaming PDB" + +sqlplus / as sysdba << EOF + alter pluggable database $OLD_ORACLE_PDB open restricted; + alter session set container=$OLD_ORACLE_PDB; + alter pluggable database rename global_name to $ORACLE_PDB; + exit; +EOF + +echo " Closing and Opening PDB" + +sqlplus / as sysdba << EOF + alter pluggable database $ORACLE_PDB close immediate; + alter pluggable database $ORACLE_PDB open; + alter system register; + exit; +EOF + + +echo "Touching $CLONED_FILE as setup is completed" +touch $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE + +} + +############################################ +########### Symbolic link DB files ######### +############################################ +########### DB Version >= 23c ############## +############################################ +function symLinkFiles23c { + + if [ -z ${ORACLE_BASE_HOME} ]; then + # + export ORACLE_BASE_HOME=$ORACLE_HOME + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora + fi; + if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/listener.ora + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora + fi + if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then + unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + ## Link based on ORACLE_BASE +# ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/spfile$ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi + fi + fi; + + if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID + fi; + + if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID + fi; + + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then + ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB + fi; + # oracle user does not have permissions in /etc, hence cp and not ln + sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab + cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab + fi +fi + +} + + +############################################ +########### Symbolic link DB files ######### +############################################ +########### DB Version < 23c ############### +############################################ +function symLinkFiles { + + if [ -z ${ORACLE_BASE_HOME} ]; then + # + export ORACLE_BASE_HOME=$ORACLE_HOME + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora + fi; + if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/listener.ora + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora + fi + if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then + unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$OLD_ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi + fi + fi; + + if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID + fi; + + if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID + fi; + + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then + ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB + fi; + # oracle user does not have permissions in /etc, hence cp and not ln + sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab + cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab + fi +fi + +} + +################################### +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +# Check whether container has enough memory +# Github issue #219: Prevent integer overflow, +# only check if memory digits are less than 11 (single GB range and below) +if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes | wc -c` -lt 11 ]; then + if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` -lt 2147483648 ]; then + echo "Error: The container doesn't have enough memory allocated." + echo "A database container needs at least 2 GB of memory." + echo "You currently only have $((`cat /sys/fs/cgroup/memory/memory.limit_in_bytes`/1024/1024/1024)) GB allocated to the container." + exit 1; + fi; +fi; + + +# Check that hostname doesn't container any "_" +# Github issue #711 +if hostname | grep -q "_"; then + echo "Error: The hostname must not container any '_'". + echo "Your current hostname is '$(hostname)'" +fi; + +# Default for ORACLE SID +if [ "$OLD_ORACLE_SID" == "" ]; then + export OLD_ORACLE_SID=SEEDCDB +fi + +if [ ! -z ${ORACLE_SID} ]; then + # Make ORACLE_SID upper case + # Github issue # 984 + export ORACLE_SID=${ORACLE_SID^^} + + # Check whether SID is no longer than 12 bytes + # Github issue #246: Cannot start OracleDB image + if [ "${#ORACLE_SID}" -gt 12 ]; then + echo "Error: The ORACLE_SID must only be up to 12 characters long." + exit 1; + fi; + + # Check whether SID is alphanumeric + # Github issue #246: Cannot start OracleDB image + if [[ "$ORACLE_SID" =~ [^a-zA-Z0-9] ]]; then + echo "Error: The ORACLE_SID must be alphanumeric." + exit 1; + fi; +else + echo "Error: The ORACLE_SID must be defined." + exit 1; +fi; + + +if [ ! -z ${ORACLE_PDB} ]; then + export ORACLE_PDB=${ORACLE_PDB^^} + + if [ "${#ORACLE_PDB}" -gt 12 ]; then + echo "Error: The ORACLE_PDB must only be up to 12 characters long." + exit 1; + fi; +else + echo "Error: The ORACLE_PDB must be defined." + exit 1; +fi; + +if [ ! -z ${OLD_ORACLE_PDB} ]; then + export OLD_ORACLE_PDB=${OLD_ORACLE_PDB^^} +else + export OLD_ORACLE_PDB=SEEDPDB +fi; + + +# Default for ORACLE CHARACTERSET +export ORACLE_CHARACTERSET=${ORACLE_CHARACTERSET:-AL32UTF8} + +# Check whether database already exists +if [ ! -z ${CLONE_DB} ]; then +if [ ${CLONE_DB^^} == "TRUE" ]; then +echo "CLONE_DB is set to true, cloning DB from seed" +if [ -d $ORACLE_BASE/oradata/$OLD_ORACLE_SID ]; then + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 23 ]; then + symLinkFiles23c; + else + symLinkFiles; + fi; + else + echo "Unable to determine the Database Version, exiting.." + exit 1; + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE ]; + then + # Start database + echo "Starting Database as cloned status file exist" + $ORACLE_BASE/$START_FILE; + else + echo "Performing Cloning as cloned status file does not exist" + cloneDB; + $ORACLE_BASE/checkDBStatus.sh + if [ $? -eq 0 ]; then + echo "DB is in READ WRITE State" + touch "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" + $ORACLE_BASE/$LOCKING_SCRIPT --acquire --file "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" + else + echo "DB is not in READ WRITE state" + exit 1; + fi + fi +else + echo "Error: The $ORACLE_BASE/oradata/$OLD_ORACLE_SID (ORACLE_BASE/oradata/OLD_ORACLE_SID) dir does not exist. Error exiting ." + exit 1; +fi +fi +fi + +if [ ${OP_TYPE,,} == "standbyshard" ]; then + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 23 ]; then + symLinkFiles23c; + else + symLinkFiles; + fi; + else + echo "Unable to determine the Database Version, exiting.." + exit 1; + fi + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/$STANDBY_STATUS ]; + then + # Start database + echo "Starting Database as standby setup status file exist" + $ORACLE_BASE/$START_FILE; + fi +fi + +#This is the main file which calls other file to setup the sharding. +if [ -z ${BASE_DIR} ]; then + BASE_DIR=/opt/oracle/scripts/sharding +fi + +if [ -z ${MAIN_SCRIPT} ]; then + SCRIPT_NAME="main.py" +fi + +if [ -z ${EXECUTOR} ]; then + EXECUTOR="python" +fi + +cd $BASE_DIR +$EXECUTOR $SCRIPT_NAME diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOracle.sh b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOracle.sh new file mode 100755 index 0000000..2266e99 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOracle.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +########### SIGINT handler ############ +function _int() { + echo "Stopping container." + echo "SIGINT received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown immediate; + exit; +EOF + lsnrctl stop +} + +########### SIGTERM handler ############ +function _term() { + echo "Stopping container." + echo "SIGTERM received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown immediate; + exit; +EOF + lsnrctl stop +} + +########### SIGKILL handler ############ +function _kill() { + echo "SIGKILL received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown abort; + exit; +EOF + lsnrctl stop +} + + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +if [ ! -z ${SHARD_SETUP} ]; then + if [ ${SHARD_SETUP,,} == "true" ]; then + sh $ORACLE_BASE/scripts/sharding/runOraShardSetup.sh + fi +fi + +if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & + fi +fi + +if [ ! -z ${OP_TYPE} ]; then + if [ ${OP_TYPE,,} == "standbyshard" ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & + fi +fi + +# Set SIGINT handler +trap _int SIGINT + +# Set SIGTERM handler +trap _term SIGTERM + +# Set SIGKILL handler +trap _kill SIGKILL + + +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/setupGSM.sh b/container-based-sharding-deployment/containerfiles/23.3.0/setupGSM.sh new file mode 100644 index 0000000..4a6a6ca --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/setupGSM.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +# Create Directories +mkdir -p $GSM_BASE +mkdir -p $GSM_HOME +mkdir -p $INVENTORY + +chown -R oracle:oinstall $INVENTORY +chown -R oracle:oinstall $GSM_BASE +chown -R oracle:oinstall $GSM_HOME +chown -R oracle:oinstall $INSTALL_SCRIPTS +chmod 775 $INSTALL_SCRIPTS + +chmod 666 /etc/sudoers +echo "oracle ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +chmod 440 /etc/sudoers + +echo "export ORACLE_HOME=$GSM_HOME" >> /home/oracle/.bashrc +echo "export PATH=$GSM_PATH" >> /home/oracle/.bashrc +echo "export LD_LIBRARY_PATH=$GSM_LD_LIBRARY_PATH" >> /home/oracle/.bashrc +echo "export SCRIPT_DIR=$SCRIPT_DIR" >> /home/oracle/.bashrc +echo "export GSM_HOME=$GSM_HOME" >> /home/oracle/.bashrc diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/setupLinuxEnv.sh b/container-based-sharding-deployment/containerfiles/23.3.0/setupLinuxEnv.sh new file mode 100644 index 0000000..29c3339 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/setupLinuxEnv.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +chmod ug+x $SCRIPT_DIR/*.sh && \ +yum -y install oracle-database-preinstall-21c net-tools zip unzip tar openssl openssh-server vim-minimal which passwd sudo python3 hostname && \ +yum clean all diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/setupOshardEnv.sh b/container-based-sharding-deployment/containerfiles/23.3.0/setupOshardEnv.sh new file mode 100755 index 0000000..5ae2692 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.3.0/setupOshardEnv.sh @@ -0,0 +1,970 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +export NOW=$(date +"%Y%m%d%H%M") +export LOGDIR="/tmp" +export LOGFILE="${LOGDIR}/oshard_${NOW}.log" +export STD_OUT_FILE="/proc/1/fd/1" +export STD_ERR_FILE="/proc/1/fd/2" +declare -x SECRET_VOLUME='/run/secrets/' ## Secret Volume +declare -x PWD_KEY='pwd.key' ## PWD Key File +declare -x COMMON_OS_PWD_FILE='common_os_pwdfile.enc' +declare -x DB_PWD_FILE +export PDB_SQL_SCRIPT="/tmp/pdb.sql" +export TOP_PID=$$ +rm -f /tmp/sqllog.output +rm -f $PDB_SQL_SCRIPT +rm -f $LOGFILE + +#################################### Print and Exit Functions Begin Here ####################### +error_exit() { +local NOW=$(date +"%m-%d-%Y %T %Z") + # Display error message and exit +# echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2 + echo "${NOW} : ${PROGNAME}: ${1:-"Unknown Error"}" | tee -a $LOGFILE > $STD_OUT_FILE + kill -s TERM $TOP_PID +} + +print_message () +{ + local NOW=$(date +"%m-%d-%Y %T %Z") + # Display message and return + echo "${NOW} : ${PROGNAME} : ${1:-"Unknown Message"}" | tee -a $LOGFILE > $STD_OUT_FILE + return $? +} +#################################### Print and Exit Functions End Here ####################### + + +####################################### Functions Related to checks #################### +dbChecks() +{ +if [ -z "$ORACLE_HOME" ] +then + error_exit "Set the ORACLE_HOME variable" +else + print_message "ORACLE_HOME set to $ORACLE_HOME" +fi + +# If ORACLE_HOME doesn't exist # +if [ ! -d "$ORACLE_HOME" ] +then + error_exit "The ORACLE_HOME $ORACLE_HOME does not exist" +else + print_message "ORACLE_HOME Directory Exist" +fi + +################## Checks for Password and Clustername and clustertype begins here ########### +if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then +cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' + +eval $cmd + +if [ $? -eq 0 ]; then +print_message "Password file generated" +else +error_exit "Error occurred during common os password file generation" +fi + +read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} +rm -f /tmp/${COMMON_OS_PWD_FILE} +else + print_message "Password is empty string" + export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 +fi + +if [ -z "${ORACLE_PWD}" ]; then + print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" + export ORACLE_PWD=${PASSWORD} +else + print_message "ORACLE_PWD is set to user specified password" +fi + +################################################################################################### + + +if [ -z "${SHARD_ADMIN_USER}" ] +then + print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + export SHARD_ADMIN_USER="mysdbadmin" +else + print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" +fi + + +if [ -z "${PDB_ADMIN_USER}" ] +then + print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" + export PDB_ADMIN_USER="pdbadmin" +else + print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" +fi + + +# Validate the value of ORACLE_SID # +if [ -z "${ORACLE_SID}" ] +then + error_exit "Set the ORACLE_SID variable" +else + print_message "ORACLE_SID is set to $ORACLE_SID" +fi + +if [ -z "${ORACLE_HOSTNAME}" ] +then + if [ -z "${KUBE_SVC}" ]; then + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname)" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + else + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + fi +else + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" +fi + + + +if [ -z "$DB_PORT" ] +then + print_message "Set the DB_PORT variable" + export DB_PORT=1521 +else + print_message "DB Port is set to $DB_PORT" +fi + +if [ -z "${DB_RECOVERY_FILE_DEST}" ]; then + print_message "Set the DB_RECOVERY_FILE_DEST is not set" + export DB_RECOVERY_FILE_DEST="${ORACLE_BASE}/oradata/fast_recovery_area/${ORACLE_SID}" +fi + +if [ -z "${DB_CREATE_FILE_DEST}" ]; then + print_message "Set the DB_CREATE_FILE_DEST is not set. Setting to ${ORACLE_BASE}/oradata/${ORACLE_SID}" + export DB_CREATE_FILE_DEST="${ORACLE_BASE}/oradata/${ORACLE_SID}" +fi + +if [ -z "${DATA_PUMP_DIR}" ]; then + print_message "DATA_PUMP_DIR is not set, it will se to ${ORACLE_BASE}/oradata/data_pump_dir" + export DATA_PUMP_DIR="${ORACLE_BASE}/oradata/data_pump_dir" +fi + +if [ ! -d "${DATA_PUMP_DIR}" ]; then + print_message "DATA_PUMP_DIR ${DATA_PUMP_DIR} directory does not exist" + mkdir -p "${DATA_PUMP_DIR}" +fi + +if [ ! -d "${DB_RECOVERY_FILE_DEST}" ]; then + print_message "DB_RECOVERY_FILE_DEST ${DB_RECOVERY_FILE_DEST} directory does not exist" + mkdir -p "${DB_RECOVERY_FILE_DEST}" +fi + +if [ -z "${DB_RECOVERY_FILE_DEST_SIZE}" ]; then + print_message "DB_RECOVERY_FILE_DEST_SIZE is not set" + export DB_RECOVERY_FILE_DEST_SIZE="40G" +else + print_message "DB_RECOVERY_FILE_DEST_SIZE is set to ${DB_RECOVERY_FILE_DEST_SIZE}" +fi + +} + +gsmChecks() +{ + print_message "Performing GSM related checks" + +if [ ! -z "${KUBE_SVC}" ]; then + lordinal=$( hostname | awk -F "-" '{ print $NF }' ) + print_message "lordinal is set to ${lordinal}" + region_num=$((lordinal+1)) + if [ -z "${REGION}" ]; then + print_message "REGION is not set. Setting to region$lordinal" + export REGION="region${region_num}" + fi +else + if [ -z "${REGION}" ]; then + error_exit "REGION Canot be set to empty" + fi +fi + +################## Checks for Password and Clustername and clustertype begins here ########### +if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then +cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' + +eval $cmd + +if [ $? -eq 0 ]; then +print_message "Password file generated" +else +error_exit "Error occurred during common os password file generation" +fi + +read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} +rm -f /tmp/${COMMON_OS_PWD_FILE} +else + print_message "Password is empty string" + export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 +fi + +if [ -z "${ORACLE_PWD}" ]; then + print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" + export ORACLE_PWD=${PASSWORD} +else + print_message "ORACLE_PWD is set to user specified password" +fi + +################################################################################################### + +if [ -z "$SHARD_ADMIN_USER" ] +then + print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + export SHARD_ADMIN_USER="mysdbadmin" +else + print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" +fi + + +if [ -z "$PDB_ADMIN_USER" ] +then + print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" + export PDB_ADMIN_USER="pdbadmin" +else + print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" +fi + + +if [ -z "${SHARD_GROUP_NAME}" ]; then + print_message "SHARD_GROUP_NAME is not set, it will be set to primary_shardgroup" + export SHARD_GROUP_NAME="primary_shardgroup" +fi + +if [ -z "${SHARD_DEPLOYMENT_TYPE}" ]; then + print_message "SHARD_DEPLOYMENT_TYPE is not set, it will set to primary" + export SHARD_DEPLOYMENT_TYPE="primary" +fi + +if [ -z "${SHARD_DIRECTOR_NAME}" ]; then + print_message "SHARD_DIRECTOR_NAME is not set, it will set to sharddirector${region_num}" + export SHARD_DIRECTOR_NAME="sharddirector${region_num}" +fi + +if [ -z "${ORACLE_HOSTNAME}" ] +then + if [ -z "${KUBE_SVC}" ]; then + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname)" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + else + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + fi +else + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" +fi + +} + +###################################### Function Related to Check end here ################### + +################################### Reset Password ########################################### +resetPassword() +{ +if [ -f "${HOME}/setPassword.sh" ]; then +if [ ! -z "${ORACLE_PWD}" ]; then +"${HOME}"/setPassword.sh "$ORACLE_PWD" +fi +fi +} + +############################################################################################### +setupCatalog() +{ + +localconnectStr="/ as sysdba" +systemStr="system/${ORACLE_PWD}" +sqlScript="/tmp/setapp.sql" +print_message "Setting up Paramteres in Spfile" + +cmd1="drop table shardsetup;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" +#cmd=$( eval echo "$cmd1" ) +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links_per_instance=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="@$ORACLE_HOME/rdbms/admin/setCatalogDBPrivs.sql;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" +print_message "cat /tmp/setup_grants_privs.lst" + +cmd1="alter user gsmcatuser account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmcatuser identified by $ORACLE_PWD;" +print_message "Sending query to sqlplus to execute alter user gsmcatuser identified by ORACLE_PWD;" +executeSQL "$cmd1" "$localconnectStr" + + +#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" +cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + + +cmd1="shutdown immediate;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="startup mount;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database archivelog;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database open;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database flashback on;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database force logging;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1", "$localconnectStr" + +cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +if [ ! -z "${ORACLE_PDB}" ]; then +setupCatalogPDB +fi + +cmd1="create table shardsetup (status varchar2(10));" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="insert into shardsetup values('completed');" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" +} + +configureSampleAppSchema() +{ +local sqlScript="/tmp/sqlScript.sql" +connectStr = "${SHARD_ADMIN_USER}/${ORACLE_PWD}" + +echo "alter session enable shard ddl;" > ${sqlScript} +echo "create user app_schema identified by '&1';" >> ${sqlScript} +echo "grant all privileges to app_schema;" >> ${sqlScript} +echo "grant gsmadmin_role to app_schema;" >> ${sqlScript} +echo "grant select_catalog_role to app_schema;" >> ${sqlScript} +echo "grant connect, resource to app_schema;" >> ${sqlScript} +echo "grant dba to app_schema;" >> ${sqlScript} +echo "grant execute on dbms_crypto to app_schema;" >> ${sqlScript} +echo "CREATE TABLESPACE SET TSP_SET_1 using template (datafile size 100m autoextend on next 10M maxsize unlimited extent management local segment space management auto);" >> ${sqlScript} +echo "CREATE TABLESPACE SET LOBTS1;" >> ${sqlScript} +echo "CREATE TABLESPACE products_tsp datafile size 100m autoextend on next 10M maxsize unlimited extent management local uniform size 1m; " >> ${sqlScript} +echo "CONNECT app_schema/'&1';" >> ${sqlScript} +echo "ALTER SESSION ENABLE SHARD DDL;" >> ${sqlScript} +echo "CREATE SHARDED TABLE Customers (CustId VARCHAR2(60) NOT NULL, FirstName VARCHAR2(60), LastName VARCHAR2(60), Class VARCHAR2(10), Geo VARCHAR2(8),CustProfile VARCHAR2(4000),Passwd RAW(60),CONSTRAINT pk_customers PRIMARY KEY (CustId),CONSTRAINT json_customers CHECK (CustProfile IS JSON)) TABLESPACE SET TSP_SET_1 PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO;" >> ${sqlScript} +echo "CREATE SHARDED TABLE Orders (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL, OrderDate TIMESTAMP NOT NULL,SumTotal NUMBER(19,4),Status CHAR(4), CONSTRAINT pk_orders PRIMARY KEY (CustId, OrderId),CONSTRAINT fk_orders_parent FOREIGN KEY (CustId) REFERENCES Customers ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_orders_parent);" >> ${sqlScript} +echo "CREATE SEQUENCE Orders_Seq;" >> ${sqlScript} +echo "CREATE SHARDED TABLE LineItems (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL,ProductId INTEGER NOT NULL,Price NUMBER(19,4),Qty NUMBER,CONSTRAINT pk_items PRIMARY KEY (CustId, OrderId, ProductId),CONSTRAINT fk_items_parent FOREIGN KEY (CustId, OrderId) REFERENCES Orders ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_items_parent);" >> ${sqlScript} +echo "CREATE DUPLICATED TABLE Products (ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,Name VARCHAR2(128),DescrUri VARCHAR2(128),LastPrice NUMBER(19,4)) TABLESPACE products_tsp;" >> ${sqlScript} + +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "$connectStr" "sqlScript" "${sqlScript}" + +} + + +setupCatalogPDB() +{ +#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" +pdbConnStr=" /as sysdba" + +local sqlScript="/tmp/sqlScript.sql" + +print_message "Settup Sql Script to setup Catalog PDB" +echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" +echo "create user ${SHARD_ADMIN_USER} identified by ${ORACLE_PWD};" >> "${sqlScript}" +echo "grant connect, create session, gsmadmin_role to ${SHARD_ADMIN_USER} ;" >> "${sqlScript}" +echo "grant inherit privileges on user SYS to GSMADMIN_INTERNAL;" >> "${sqlScript}" +echo "execute dbms_xdb.sethttpport(8080);" >> ${sqlScript} +echo "exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('${ORACLE_PWD}');" >> "${sqlScript}" + +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" +} + +######################################################################## Catalog Setup task ends here ################################# + +######################################################################## Primary Shard Setup task ends here ################################# + +setupShardPDB() +{ + +#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" +pdbConnStr=" /as sysdba" + +local sqlScript="/tmp/sqlScript.sql" +print_message "Settup Sql Script to setup Catalog PDB" +echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" +echo "grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" >> "${sqlScript}" +echo "grant sysdg to GSMUSER;" >> "${sqlScript}" +echo "grant sysbackup to GSMUSER;" >> "${sqlScript}" +echo "execute DBMS_GSM_FIX.validateShard;" >> ${sqlScript} +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" + +} + +setupShardCDB() +{ +localconnectStr="/as sysdba" +systemStr="system/${ORACLE_PWD}" +print_message "Setting up Paramteres in Spfile" + +cmd1="drop table shardsetup;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links_per_instance=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmrootuser account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmrootuser identified by ${ORACLE_PWD} container=all;" +print_message "Sending query to sqlplus to execute alter user gsmrootuser identified by ORACLE_PWD container=all;" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysdg to gsmrootuser;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysbackup to gsmrootuser;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user GSMUSER account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user GSMUSER identified by ${ORACLE_PWD} container=all;" +print_message "Sending query to sqlplus to execute alter user GSMUSER identified by ORACLE_PWD container=all;" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysdg to GSMUSER;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysbackup to GSMUSER;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set dg_broker_start=true scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="create or replace directory DATA_PUMP_DIR as '${DATA_PUMP_DIR}';" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" +cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="shutdown immediate;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="startup mount;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database archivelog;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database open;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database flashback on;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database force logging;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +if [ ! -z "${ORACLE_PDB}" ]; then + +setupShardPDB + +fi + +cmd1="create table shardsetup (status varchar2(10));" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + + +cmd1="insert into shardsetup values('completed');" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +} + +######################################################################## Primary Shard Setup ends here ################################# + +######################################################################## GSM Setup Task Begin here ##################################### +setupGSM() +{ +local cstatus='false' +local sstatus='false' + +setupGSMCatalog +startGSM +addShardGroup +setupGSMShard + +} + +startGSM() +{ + +cmd1="start gsm" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +deployShard() +{ + +cmd1="deploy" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +stopGSM() +{ + +cmd1="stop gsm" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +addInvitedNode() +{ + +chost=$1 + +cmd1="add invitednode $chost" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + + +addShardGroup() +{ + +cmd1="add shardgroup -shardgroup ${shardGName} -deploy_as ${deployment_type} -region ${region}" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +checkStatus() +{ +host=$1 +port=1521 +cpdb=$3 +ccdb=$2 +uname="system" +cpasswd=${ORACLE_PWD} + +print_message "Connect String $uname/$cpasswd@//$host:$port/$ccdb" +output=$( "$ORACLE_HOME"/bin/sqlplus -s "$uname/$cpasswd@//$host:$port/$ccdb" <<EOF + set heading off feedback off verify off echo off PAGESIZE 0 + select status from shardsetup; + exit +EOF +) + + if [ "${output}" == 'completed' ];then + print_message "Returned status from catalog is $output" + else + print_message "Sleeping for 300 seconds as returned status is not $output " + sleep 300 + fi + + echo $output +} + +setupGSMCatalog() +{ +IFS='; ' read -r -a sarray <<< "$CATALOG_PARAMS" +for element in "${sarray[@]}" +do + print_message "1st String in Shard params $element" + type=$( echo $element | awk -F: '{print $NF }') + host=$( echo $element | awk -F: '{print $1 }') + db=$( echo $element | awk -F: '{print $2 }') + pdb=$( echo $element | awk -F: '{print $3 }') +done + +print_message "Set variables to host=${host} db=${db} pdb=${pdb}" +if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] +then +runtime="60 minute" +endtime=$(date -ud "$runtime" +%s) + +while [[ $(date -u +%s) -le $endtime ]] +do + + coutput=$( checkStatus $host $db $pdb ) + if [ "${coutput}" == 'completed' ] ;then + configureGSMCatalog $host $db $pdb + break + else + print_message "Catalog Status must return completed but returned value is $coutput" + fi + print_message "Catalog DB is still not ready. Sleeping for 60 seconds" + sleep 60 +done +fi + +if [ "${coutput}" != 'completed' ] ;then + error_exit "Shard Catalog is not setup, Unable to proceed futher" +fi + +} + +configureGSMCatalog() +{ +chost=$1 +cport=1521 +cpdb=$3 +ccdb=$2 +gsmhost=${ORACLE_HOSTNAME} +cadmin=${SHARD_ADMIN_USER} +cpasswd=${ORACLE_PWD} +########################## +region="${REGION}" +shardGName="${SHARD_GROUP_NAME}" +deployment_type="${SHARD_DEPLOYMENT_TYPE}" +local gdsScript="/tmp/gdsScript.sql" + +gsm_name="${SHARD_DIRECTOR_NAME}" +echo "create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=${chost})(PORT=${cport}))(CONNECT_DATA=(SERVICE_NAME=${cpdb})))\" -user ${cadmin}/${cpasswd} -sdb shardcatalog -region region1,region2 -agent_port 8080 -agent_password ${cpasswd} -autovncr off" > "${gdsScript}" +echo "add invitednode ${chost}" >> "${gdsScript}" +echo "add gsm -gsm ${gsm_name} -listener 1521 -pwd ${cpasswd} -catalog ${chost}:${cport}/${cpdb} -region region1 -endpoint '(ADDRESS=(PROTOCOL=tcp)(HOST=${gsmhost})(PORT=1521))'" >> "${gdsScript}" +echo "exit" >> "${gdsScript}" +print_message "Sending script to gsm to execute ${gdsScript}" +cat ${gdsScript} >> $LOGFILE +cp "${gdsScript}" "${gdsScript}.test" +executeGSM "$cmd1" "gdsScript" "${gdsScript}" +} + +setupGSMShard() +{ +IFS='; ' read -r -a sarray <<< "$PRIMARY_SHARD_PARAMS" +arrLen=$( echo "${#sarray[@]}" ) +count1=0 + +runtime="45 minute" +endtime=$(date -ud "$runtime" +%s) + +print_message "Set variables to host=${host} db=${db} pdb=${pdb}" +while [[ $(date -u +%s) -le $endtime ]] +do + for i in ${!sarray[@]}; do + print_message "1st String in Shard params $element" + host=$( echo ${sarray[i]} | awk -F: '{print $1 }') + db=$( echo ${sarray[i]} | awk -F: '{print $2 }') + pdb=$( echo ${sarray[i]} | awk -F: '{print $3 }') + print_message "shard env set to host=${host} db=${db} pdb=${pdb}" + if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] + then + coutput=$( checkStatus $host $db $pdb ) + if [ "${coutput}" == 'completed' ] ;then + configureGSMShard $host $db $pdb + unset sarray[i] + ((++count1)) + else + print_message "Catalog Status must return completed but returned value is $coutput" + fi + fi + done + if [ ${count1} -ge ${arrLen} ]; then + break; + fi + print_message "Shards are still not ready. Sleeping for 120 seconds" + sleep 120 +done +} + +configureGSMShard() +{ +chost=$1 +cport=1521 +cpdb=$3 +ccdb=$2 +cpasswd=${ORACLE_PWD} +region=${REGION} +shardGName="${SHARD_GROUP_NAME}" +deployment_type="${SHARD_DEPLOYMENT_TYPE}" +local gdsScript="/tmp/gdsScript.sql" +admuser="${PDB_ADMIN_USER}" + +echo "connect ${admuser}/${cpasswd}" > "${gdsScript}" +echo "add cdb -connect ${chost}:${cport}:${ccdb} -pwd ${cpasswd}" >> "${gdsScript}" +echo "add shard -cdb ${ccdb} -connect ${chost}:${cport}/${cpdb} -shardgroup ${shardGName} -pwd ${cpasswd}" >> "${gdsScript}" +echo "config vncr" >> "${gdsScript}" +echo "sql 'update gsmadmin_internal.database set hostid=NULL '" >> "${gdsScript}" +echo "exit" >> "${gdsScript}" +print_message "Sending script to gsm to execute ${gdsScript}" +cat ${gdsScript} >> $LOGFILE +executeGSM "$cmd1" "gdsScript" "${gdsScript}" +print_message " Calling Stop GSM function" +stopGSM +print_message "Stop GSM function completed, sleeping for 20 seconds" +sleep 20 +print_message " Calling Start GSM function" +startGSM +print_message "Start GSM function completed, sleeping for 30 seconds" +sleep 30 +print_message "Calling invitenode function to add the shard" +addInvitedNode $chost +deployShard +} + +####################################################################### GSM Setup Task Ends here ######################################### + + +######################################################################### Execute GSM Statements ######################################### +executeGSM() +{ +gsmQuery=$1 +type=$2 +gdsScript=$3 + +if [ -z "${gsmQuery}" ]; then + print_message "Empty gdsQuery passed to gds" +fi + +if [ -z "${type}" ]; then + type='notSet' +fi + +if [ -z "${gdsScript}" ]; then + gdsScript='notSet' +fi + +if [ "${type}" == "gdsScript" ]; then +print_message "Executing gds script " +"$ORACLE_HOME"/bin/gdsctl @${gdsScript} +else +print_message "Executing GSM query" +"$ORACLE_HOME"/bin/gdsctl << EOF >> $LOGFILE + $gsmQuery + exit +EOF +fi +} +######################################################################## Execute GSM Statements Ends here ################################ + +########################################################################## Execute SQL Function Begin here ############################## +executeSQL() +{ +sqlQuery=$1 +connectStr=$2 +type=$3 +sqlScript=$4 + +if [ -z "${sqlQuery}" ]; then + print_message "Empty sqlQuery passed to sqlplus. Operation Failed" +fi + +if [ -z "${connectStr}" ]; then + error_exit "Empty connectStr passed to sqlplus. Operation Failed" +fi + +if [ -z "${type}" ]; then + type='notSet' +fi + +if [ -z "${sqlScript}" ]; then + sqlScript='notSet' +fi + +if [ "${type}" == "sqlScript" ] && [ -f ${sqlScript} ]; then +print_message "Executing sql script using connect string" +"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE +@ ${sqlScript} +EOF +else +print_message "Executing sqlQuery using connect string" +"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE +$sqlQuery +EOF +fi +} + +############################################################################## Execute SQl Function ends here ################################# + +####################################### +################## MAIN ############### + +if [ "${OP_TYPE}" == "primaryshard" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + resetPassword + setupShardCDB +elif [ "${OP_TYPE}" == "standbyshard" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + setupShardStandby +elif [ "${OP_TYPE}" == "catalog" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + resetPassword + setupCatalog +elif [ "${OP_TYPE}" == "gsm" ]; then + print_message "Performing Checks before proceeding for setup" + gsmChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + setupGSM +else + print_message "OP_TYPE must be set to (gsm|catalog|primaryshard|standbyshard)" + exit 15 +fi diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install.rsp b/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install.rsp new file mode 100644 index 0000000..102854f --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install.rsp @@ -0,0 +1,35 @@ + +############################################################################### +## Copyright(c) Oracle Corporation 1998,2022. All rights reserved. ## +## ## +## Specify values for the variables listed below to customize ## +## your installation. ## +## ## +## Each variable is associated with a comment. The comment ## +## can help to populate the variables with the appropriate ## +## values. ## +## ## +############################################################################### + +#------------------------------------------------------------------------------- +# Do not change the following system generated value. +#------------------------------------------------------------------------------- +oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v23.0.0 + +#------------------------------------------------------------------------------- +# Unix group to be set for the inventory directory. +#------------------------------------------------------------------------------- +UNIX_GROUP_NAME=oinstall +#------------------------------------------------------------------------------- +# Inventory location. +#------------------------------------------------------------------------------- +INVENTORY_LOCATION=###INVENTORY### +#------------------------------------------------------------------------------- +# Complete path of the Oracle Home +#------------------------------------------------------------------------------- +ORACLE_HOME=###ORACLE_HOME### + +#------------------------------------------------------------------------------- +# Complete path of the Oracle Base. +#------------------------------------------------------------------------------- +ORACLE_BASE=###ORACLE_BASE### diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install_sample.rsp b/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install_sample.rsp new file mode 100644 index 0000000..fce54e3 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install_sample.rsp @@ -0,0 +1,35 @@ + +############################################################################### +## Copyright(c) Oracle Corporation 1998,2022. All rights reserved. ## +## ## +## Specify values for the variables listed below to customize ## +## your installation. ## +## ## +## Each variable is associated with a comment. The comment ## +## can help to populate the variables with the appropriate ## +## values. ## +## ## +############################################################################### + +#------------------------------------------------------------------------------- +# Do not change the following system generated value. +#------------------------------------------------------------------------------- +oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v23.0.0 + +#------------------------------------------------------------------------------- +# Unix group to be set for the inventory directory. +#------------------------------------------------------------------------------- +UNIX_GROUP_NAME= +#------------------------------------------------------------------------------- +# Inventory location. +#------------------------------------------------------------------------------- +INVENTORY_LOCATION= +#------------------------------------------------------------------------------- +# Complete path of the Oracle Home +#------------------------------------------------------------------------------- +ORACLE_HOME= + +#------------------------------------------------------------------------------- +# Complete path of the Oracle Base. +#------------------------------------------------------------------------------- +ORACLE_BASE= diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/Checksum b/container-based-sharding-deployment/containerfiles/23.4.0/Checksum new file mode 100644 index 0000000..faf7c8c --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/Checksum @@ -0,0 +1 @@ +ba8e6b942ba8ff22d25dd3babc7b326c LINUX.X64_234000_gsm.zip diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/Containerfile b/container-based-sharding-deployment/containerfiles/23.4.0/Containerfile new file mode 100644 index 0000000..9d734f5 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/Containerfile @@ -0,0 +1,232 @@ +# LICENSE UPL 1.0 +# +# Copyright (c) 2018,2022 Oracle and/or its affiliates. +# +# ORACLE DOCKERFILES PROJECT +# -------------------------- +# This is the Dockerfile for Oracle GSM 23ai Release 4 to build the container image +# MAINTAINER <paramdeep.saini@oracle.com> +# +# This is the Dockerfile for Oracle GSM 23ai +# +# REQUIRED FILES TO BUILD THIS IMAGE +# ---------------------------------- +# (1) LINUX.X64_234000_gsm.zip +# Download Oracle Database 23ai GSM Software +# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html +# +# HOW TO BUILD THIS IMAGE +# ----------------------- +# Put all downloaded files in the same directory as this Dockerfile +# Run: +# $ docker build -t oracle/gsm:23.3.0 . +# + +ARG BASE_OL_IMAGE=oraclelinux:8 + +# Pull base image +# --------------- +FROM $BASE_OL_IMAGE AS base +ARG SLIMMING=false + +# Labels +# ------ +LABEL "provider"="Oracle" \ + "issues"="https://github.com/oracle/db-sharding/issues" \ + "volume.setup.location1"="/opt/oracle/scripts" \ + "port.listener"="1522" + +# Argument to control removal of components not needed after db software installation + +ARG INSTALL_FILE_1="LINUX.X64_234000_gsm.zip" +ARG USER="root" + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +ENV GSM_BASE="/u01/app/oracle" \ + GSM_USER="oracle" \ + GSM_HOME="/u01/app/oracle/product/23ai/gsmhome_1" \ + INVENTORY="/u01/app/oracle/oraInventory" \ + INSTALL_DIR="/opt/oracle/scripts" \ + INSTALL_FILE_1=$INSTALL_FILE_1 \ + INSTALL_RSP="23c_gsm_install.rsp" \ + RUN_FILE="runOracle.sh" \ + SETUP_LINUX_FILE="setupLinuxEnv.sh" \ + CHECK_SPACE_FILE="checkSpace.sh" \ + USER_SCRIPTS_FILE="runUserScripts.sh" \ + INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ + GSM_SETUP_FILE="setupOshardEnv.sh" \ + GSM_ENV_SETUP_FILE="setupGSM.sh" \ + GSM_SCRIPTS="scripts" \ + MAINPY="main.py" \ + PYTHON_FILE="/usr/bin/python" \ + PYTHON3_FILE="/usr/bin/python3" \ + ORAPCATALOG="orapcatalog.py" \ + CMDEXEC="cmdExec" \ + ORAMACHINE="oramachine.py" \ + ORALOGGER="oralogger.py" \ + ORAFACTORY="orafactory.py" \ + ORAGSM="oragsm.py" \ + ORASSHARD="orasshard.py" \ + ORAENV="oraenv.py" \ + ORAPSHARD="orapshard.py" \ + MAINPY="main.py" \ + ORASCATALOG="orascatalog.py" \ + ORACOMMON="oracommon.py" \ + DEMOAPPSQL="demoapp.sql" \ + RUNORASHARD="runOraShardSetup.sh" \ + CHECKLIVENESS="checkLiveness.sh" +# Use second ENV so that variable get substituted +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/sharding \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_PATH=$GSM_HOME/bin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib + +############################################# +# ------------------------------------------- +# Start new stage for slim image +# ------------------------------------------- +############################################# +FROM base AS gsm-image-slim-false +ARG SLIMMING + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +# Linux Env Variable +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/sharding \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_PATH=$GSM_HOME/bin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib \ + INSTALL_SCRIPTS=$INSTALL_DIR/install \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_SCRIPTS="scripts" + +# Copy binaries +# ------------- +# COPY Binaries +COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $GSM_ENV_SETUP_FILE $INSTALL_SCRIPTS/ +COPY $RUN_FILE $GSM_SETUP_FILE $CHECKLIVENESS $USER_SCRIPTS_FILE $SCRIPT_DIR/ +COPY $GSM_SCRIPTS/$ORAPCATALOG $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$ORAPSHARD $GSM_SCRIPTS/$MAINPY $GSM_SCRIPTS/$ORASCATALOG $GSM_SCRIPTS/$ORACOMMON $GSM_SCRIPTS/$DEMOAPPSQL $GSM_SCRIPTS/$RUNORASHARD $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$ORAMACHINE $GSM_SCRIPTS/$ORALOGGER $GSM_SCRIPTS/$ORAFACTORY $GSM_SCRIPTS/$ORAGSM $GSM_SCRIPTS/$ORASSHARD $GSM_SCRIPTS/$ORAENV $SCRIPT_DIR/scripts/ + +RUN chmod 755 $INSTALL_DIR/install/*.sh && \ + sync && \ + $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ + $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ + $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ + sync + +############################################# +# ------------------------------------------- +# Start new stage for slim image true +# ------------------------------------------- +############################################# +FROM base AS gsm-image-slim-true +ARG SLIMMING + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +# Linux Env Variable +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/sharding \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_PATH=$GSM_HOME/bin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib \ + INSTALL_SCRIPTS=$INSTALL_DIR/install \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_SCRIPTS="scripts" + +# Copy binaries +# ------------- +# COPY Binaries +COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $GSM_ENV_SETUP_FILE $INSTALL_SCRIPTS/ +COPY $RUN_FILE $GSM_SETUP_FILE $CHECKLIVENESS $USER_SCRIPTS_FILE $SCRIPT_DIR/ +COPY $GSM_SCRIPTS/$ORAPCATALOG $GSM_SCRIPTS/$ORAPSHARD $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$MAINPY $GSM_SCRIPTS/$ORASCATALOG $GSM_SCRIPTS/$ORACOMMON $GSM_SCRIPTS/$DEMOAPPSQL $GSM_SCRIPTS/$RUNORASHARD $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$ORAMACHINE $GSM_SCRIPTS/$ORALOGGER $GSM_SCRIPTS/$ORAFACTORY $GSM_SCRIPTS/$ORAGSM $GSM_SCRIPTS/$ORASSHARD $GSM_SCRIPTS/$ORAENV $SCRIPT_DIR/scripts/ + +RUN chmod 755 $INSTALL_DIR/install/*.sh && \ + sync && \ + $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ + $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ + $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ + sync + +############################################# +# ------------------------------------------- +# Start new stage for installing the grid and DB +# ------------------------------------------- +############################################# + +FROM gsm-image-slim-${SLIMMING} AS builder +ARG SLIMMING + +COPY $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ + +USER ${USER} +RUN if [ "${SLIMMING}x" != 'truex' ]; then \ + chmod 755 $INSTALL_SCRIPTS/*.sh && \ + :;\ + fi +USER ${GSM_USER} +RUN if [ "${SLIMMING}x" != 'truex' ]; then \ + "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ + :;\ +fi + +USER ${USER} +RUN if [ "${SLIMMING}x" != 'truex' ]; then \ + $INVENTORY/orainstRoot.sh && \ + $GSM_HOME/root.sh && \ + rm -rf $INSTALL_DIR/install && \ + :;\ + fi + +#RUN if [ "${SLIMMING}x" == 'truex' ]; then \ +# mkdir /u01 && \ +# :; \ +#fi + +RUN rm -f $INSTALL_DIR/install/* && \ + sync + +############################################# +# ------------------------------------------- +# Start new layer for GSM runtime +# ------------------------------------------- +############################################# + +FROM gsm-image-slim-${SLIMMING} AS final + +COPY --from=builder /u01 /u01 + +RUN if [ ! -f $PYTHON_FILE ]; then \ + ln -s $PYTHON3_FILE $PYTHON_FILE && \ + :; \ + fi && \ + rm -f $INSTALL_DIR/install/* && \ + cp $SCRIPT_DIR/scripts/cmdExec $SCRIPT_DIR/ && \ + chown -R oracle:oinstall $SCRIPT_DIR && \ + chmod 755 $SCRIPT_DIR/*.sh && \ + chmod 755 $SCRIPT_DIR/scripts/*.py && \ + chmod 755 $SCRIPT_DIR/scripts/*.sh && \ + chmod 755 $SCRIPT_DIR/scripts/cmdExec && \ + chmod 755 $SCRIPT_DIR/cmdExec && \ + sync + +USER ${GSM_USER} +WORKDIR /home/${GSM_USER} +EXPOSE 1522 + +VOLUME ["$GSM_BASE/oradata"] + +HEALTHCHECK --interval=2m --start-period=25m \ + CMD "$SCRIPT_DIR/$CHECKLIVENESS" >/dev/null || exit 1 + +# Define default command to start Oracle Database. +CMD exec $SCRIPT_DIR/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/checkLiveness.sh b/container-based-sharding-deployment/containerfiles/23.4.0/checkLiveness.sh new file mode 100644 index 0000000..e917502 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/checkLiveness.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +export PYTHON="/bin/python3" + +$PYTHON $SCRIPT_DIR/scripts/$MAINPY --checkliveness='true' +retcode=$? + + if [ ${retcode} -eq 0 ]; then + exit 0 + else + exit 1 + fi diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/checkSpace.sh b/container-based-sharding-deployment/containerfiles/23.4.0/checkSpace.sh new file mode 100644 index 0000000..5d4b8d9 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/checkSpace.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +REQUIRED_SPACE_GB=2 +AVAILABLE_SPACE_GB=`df -PB 1G / | tail -n 1 | awk '{ print $4 }'` + +if [ $AVAILABLE_SPACE_GB -lt $REQUIRED_SPACE_GB ]; then + script_name=`basename "$0"` + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "$script_name: ERROR - There is not enough space available in the docker container." + echo "$script_name: The container needs at least $REQUIRED_SPACE_GB GB, but only $AVAILABLE_SPACE_GB GB are available." + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + exit 1; +fi; diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/installGSMBinaries.sh b/container-based-sharding-deployment/containerfiles/23.4.0/installGSMBinaries.sh new file mode 100644 index 0000000..adf6547 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/installGSMBinaries.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +export ORACLE_BASE=$GSM_BASE +export ORACLE_HOME=$GSM_HOME + +# Check whether ORACLE_BASE is set +if [ "$ORACLE_BASE" == "" ]; then + echo "ERROR: ORACLE_BASE has not been set!" + echo "You have to have the ORACLE_BASE environment variable set to a valid value!" + exit 1; +fi; + +# Check whether ORACLE_HOME is set +if [ "$ORACLE_HOME" == "" ]; then + echo "ERROR: ORACLE_HOME has not been set!" + echo "You have to have the ORACLE_HOME environment variable set to a valid value!" + exit 1; +fi; + + +# Replace place holders +# --------------------- + +sed -i -e "s|###INVENTORY###|$INVENTORY|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ +sed -i -e "s|###ORACLE_BASE###|$GSM_BASE|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ +sed -i -e "s|###ORACLE_HOME###|$GSM_HOME|g" $INSTALL_SCRIPTS/$INSTALL_RSP + +# Install Oracle binaries +cd $INSTALL_SCRIPTS && \ +unzip $INSTALL_FILE_1 && \ +rm $INSTALL_FILE_1 && \ +$INSTALL_SCRIPTS/gsm/runInstaller -silent -force -waitforcompletion -responsefile $INSTALL_SCRIPTS/$INSTALL_RSP -ignorePrereqFailure || true && \ +rm -rf gsm && \ +cd $HOME diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/runOracle.sh b/container-based-sharding-deployment/containerfiles/23.4.0/runOracle.sh new file mode 100644 index 0000000..473de50 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/runOracle.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +#This is the main file which calls other file to setup the sharding. +if [ -z ${BASE_DIR} ]; then + BASE_DIR=$INSTALL_DIR/sharding/scripts +fi + +if [ -z ${MAIN_SCRIPT} ]; then + SCRIPT_NAME="main.py" +fi + +if [ -z ${EXECUTOR} ]; then + EXECUTOR="python3" +fi + +cd $BASE_DIR +$EXECUTOR $SCRIPT_NAME + +# Tail on alert log and wait (otherwise container will exit) + +if [ -z ${DEV_MODE} ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/gsm/*/*/trace/alert*.log & +else + echo "The following output is now a tail of the /etc/passwd for dev mode" + tail -f /etc/passwd & +fi + +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/runUserScripts.sh b/container-based-sharding-deployment/containerfiles/23.4.0/runUserScripts.sh new file mode 100644 index 0000000..c1d1c44 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/runUserScripts.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +SCRIPTS_ROOT="$1"; + +# Check whether parameter has been passed on +if [ -z "$SCRIPTS_ROOT" ]; then + echo "$0: No SCRIPTS_ROOT passed on, no scripts will be run"; + exit 1; +fi; + +# Execute custom provided files (only if directory exists and has files in it) +if [ -d "$SCRIPTS_ROOT" ] && [ -n "$(ls -A $SCRIPTS_ROOT)" ]; then + + echo ""; + echo "Executing user defined scripts" + + for f in $SCRIPTS_ROOT/*; do + case "$f" in + *.sh) echo "$0: running $f"; . "$f" ;; + *.sql) echo "$0: running $f"; echo "exit" | $ORACLE_HOME/bin/sqlplus -s "/ as sysdba" @"$f"; echo ;; + *) echo "$0: ignoring $f" ;; + esac + echo ""; + done + + echo "DONE: Executing user defined scripts" + echo ""; + +fi; diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/cmdExec b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/cmdExec new file mode 100755 index 0000000..0e5ac30 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/cmdExec @@ -0,0 +1,23 @@ +#!/bin/bash + +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +TIMESTAMP=`date "+%Y-%m-%d"` +LOGFILE="/tmp/sharding_cmd_${TIMESTAMP}.log" + +echo $(date -u) " : " $@ >> $LOGFILE + +cmd=$@ + +$cmd + +if [ $? -eq 0 ]; then + exit 0 +else + exit 127 +fi diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/demoapp.sql b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/demoapp.sql new file mode 100755 index 0000000..3e96bfc --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/demoapp.sql @@ -0,0 +1,88 @@ + connect sys/'&1'@oshard-catalog-0:1521/CATCDB as sysdba + alter session set container=CAT1PDB; + alter session enable shard ddl; + create user app_schema identified by app_schema; + grant connect, resource, alter session to app_schema; + grant execute on dbms_crypto to app_schema; + grant create table, create procedure, create tablespace, create materialized view to app_schema; + grant unlimited tablespace to app_schema; + grant select_catalog_role to app_schema; + grant all privileges to app_schema; + grant gsmadmin_role to app_schema; + grant dba to app_schema; + conn app_schema/'&1'@oshard-catalog-0:1521/CAT1PDB + alter session enable shard ddl; + REM + REM Create a Sharded table for + REM + CREATE SHARDED TABLE Customers + ( + CustId VARCHAR2(60) NOT NULL, + FirstName VARCHAR2(60), + LastName VARCHAR2(60), + Class VARCHAR2(10), + Geo VARCHAR2(8), + CustProfile VARCHAR2(4000), + Passwd RAW(60), + CONSTRAINT pk_customers PRIMARY KEY (CustId), + CONSTRAINT json_customers CHECK (CustProfile IS JSON) + ) TABLESPACE SET TSP_SET_1 + PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO; + REM + REM Create a Sharded table for Orders + REM + CREATE SHARDED TABLE Orders + ( + OrderId INTEGER NOT NULL, + CustId VARCHAR2(60) NOT NULL, + OrderDate TIMESTAMP NOT NULL, + SumTotal NUMBER(19,4), + Status CHAR(4), + constraint pk_orders primary key (CustId, OrderId), + constraint fk_orders_parent foreign key (CustId) + references Customers on delete cascade + ) partition by reference (fk_orders_parent); + REM + REM Create the sequence used for the OrderId column + REM + CREATE SEQUENCE Orders_Seq; + REM + REM Create a Sharded table for LineItems + REM + CREATE SHARDED TABLE LineItems + ( + OrderId INTEGER NOT NULL, + CustId VARCHAR2(60) NOT NULL, + ProductId INTEGER NOT NULL, + Price NUMBER(19,4), + Qty NUMBER, + constraint pk_items primary key (CustId, OrderId, ProductId), + constraint fk_items_parent foreign key (CustId, OrderId) + references Orders on delete cascade + ) partition by reference (fk_items_parent); + REM + REM + CREATE DUPLICATED TABLE Products + ( + ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + Name VARCHAR2(128), + DescrUri VARCHAR2(128), + LastPrice NUMBER(19,4) + ) TABLESPACE products_tsp; + CREATE OR REPLACE FUNCTION PasswCreate(PASSW IN RAW) + RETURN RAW + IS + Salt RAW(8); + BEGIN + Salt := DBMS_CRYPTO.RANDOMBYTES(8); + RETURN UTL_RAW.CONCAT(Salt, DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(Salt,PASSW), DBMS_CRYPTO.HASH_SH256)); + END; + / + CREATE OR REPLACE FUNCTION PasswCheck(PASSW IN RAW, PHASH IN RAW) + RETURN INTEGER IS + BEGIN + RETURN UTL_RAW.COMPARE(DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(UTL_RAW.SUBSTR(PHASH, 1, 8), PASSW), DBMS_CRYPTO.HASH_SH256),UTL_RAW.SUBSTR(PHASH, 9)); + END; + / + REM + REM diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/main.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/main.py new file mode 100755 index 0000000..b7f0f17 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/main.py @@ -0,0 +1,171 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" +This is the main file which calls other file to setup the sharding. +""" + +from oralogger import * +from orafactory import * +from oraenv import * +from oracommon import * + + +def main(): + + # Checking Comand line Args + try: + opts, args = getopt.getopt(sys.argv[1:], '', ['addshard=','deleteshard=','validateshard=','checkliveness=','resetlistener=','restartdb=','createdir=','optype=','addshardgroup=','deployshard=','movechunks=','checkonlineshard=','cancelchunks=','checkchunks=','checkgsmshard=','checkreadyness=','validatenochunks=','invitednode=','resetpassword=','exporttdekey=','importtdekey=','help']) + except getopt.GetoptError: + pass + + # Initializing oraenv instance + oenv=OraEnv() + file_name = os.path.basename(__file__) + funcname = sys._getframe(1).f_code.co_name + + log_file_name = oenv.logfile_name("NONE") + + # Initialiing logger instance + oralogger = OraLogger(log_file_name) + console_handler = CHandler() + file_handler = FHandler() + stdout_handler = StdHandler() + # Setting next log handlers + stdout_handler.nextHandler = file_handler + file_handler.nextHandler = console_handler + console_handler.nextHandler = PassHandler() + + ocommon = OraCommon(oralogger,stdout_handler,oenv) + + for opt, arg in opts: + if opt in ('--help'): + oralogger.msg_ = '''{:^17}-{:^17} : You can pass parameter --addshard, --deleteshard, --validateshard, --checkliveness, --resetlistener, --restartdb, --createdir, --optype, --addshardgroup, --deployshard, '--checkonlineshard', '--cancelchunks', '--movechunks', '--checkchunks', '--checkgsmshard','--validatenochunks', '--checkreadyness','--invitednode', '--resetpassword','--exporttdekey','--importtdekey',or --help''' + stdout_handler.handle(oralogger) + elif opt in ('--addshard'): + file_name = oenv.logfile_name("ADD_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("ADD_SHARD",arg) + elif opt in ('--validateshard'): + file_name = oenv.logfile_name("VALIDATE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("VALIDATE_SHARD",arg) + elif opt in ('--deleteshard'): + file_name = oenv.logfile_name("REMOVE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("REMOVE_SHARD",arg) + elif opt in ('--checkliveness'): + oralogger.stdout_ = None + file_name = oenv.logfile_name("CHECK_LIVENESS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_LIVENESS",arg) + elif opt in ('--checkreadyness'): + oralogger.stdout_ = None + file_name = oenv.logfile_name("CHECK_READYNESS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_READYNESS",arg) + elif opt in ('--resetlistener'): + file_name = oenv.logfile_name("RESET_LISTENER") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESET_LISTENER",arg) + elif opt in ('--restartdb'): + file_name = oenv.logfile_name("RESTART_DB") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESTART_DB",arg) + elif opt in ('--createdir'): + file_name = oenv.logfile_name("CREATE_DIR") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CREATE_DIR",arg) + elif opt in ('--addshardgroup'): + file_name = oenv.logfile_name("ADD_SGROUP_PARAMS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("ADD_SGROUP_PARAMS",arg) + elif opt in ('--deployshard'): + file_name = oenv.logfile_name("DEPLOY_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("DEPLOY_SHARD",arg) + elif opt in ('--cancelchunks'): + file_name = oenv.logfile_name("CANCEL_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CANCEL_CHUNKS",arg) + elif opt in ('--movechunks'): + file_name = oenv.logfile_name("MOVE_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("MOVE_CHUNKS",arg) + elif opt in ('--checkchunks'): + file_name = oenv.logfile_name("CHECK_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_CHUNKS",arg) + elif opt in ('--validatenochunks'): + file_name = oenv.logfile_name("VALIDATE_NOCHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("VALIDATE_NOCHUNKS",arg) + elif opt in ('--checkonlineshard'): + file_name = oenv.logfile_name("CHECK_ONLINE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_ONLINE_SHARD",arg) + elif opt in ('--checkgsmshard'): + file_name = oenv.logfile_name("CHECK_GSM_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_GSM_SHARD",arg) + elif opt in ('--invitednode'): + file_name = oenv.logfile_name("INVITED_NODE_OP") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("INVITED_NODE_OP",arg) + elif opt in ('--resetpassword'): + file_name = oenv.logfile_name("RESET_PASSWD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESET_PASSWORD",arg) + elif opt in ('--exporttdekey'): + file_name = oenv.logfile_name("EXPORT_TDE_KEY") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("EXPORT_TDE_KEY",arg) + elif opt in ('--importtdekey'): + file_name = oenv.logfile_name("IMPORT_TDE_KEY") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("IMPORT_TDE_KEY",arg) + elif opt in ('--optype'): + oenv.add_custom_variable("OP_TYPE",arg) + else: + pass + + # Initializing orafactory instances + oralogger.msg_ = '''{:^17}-{:^17} : Calling OraFactory to start the setup'''.format(file_name,funcname) + stdout_handler.handle(oralogger) + orafactory = OraFactory(oralogger,stdout_handler,oenv,ocommon) + + # Get the ora objects + ofactory=orafactory.get_ora_objs() + + # Traverse through returned factory objects and execute the setup function + for obj in ofactory: + obj.setup() + +# Using the special variable +if __name__=="__main__": + main() diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oracommon.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oracommon.py new file mode 100755 index 0000000..42a319b --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oracommon.py @@ -0,0 +1,966 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +from oralogger import * +from oraenv import * +import subprocess +import sys +import time +import datetime +import os +import getopt +import shlex +import json +import logging +import socket +import re +import os.path +import socket +import string +import random + +class OraCommon: + def __init__(self,oralogger,orahandler,oraenv): + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + + def run_sqlplus(self,cmd,sql_cmd,dbenv): + """ + This function execute the ran sqlplus or rman script and return the output + """ + try: + message="Received Command : {0}\n{1}".format(self.mask_str(cmd),self.mask_str(sql_cmd)) + self.log_info_message(message,self.file_name) + sql_cmd=self.unmask_str(sql_cmd) + cmd=self.unmask_str(cmd) +# message="Received Command : {0}\n{1}".format(cmd,sql_cmd) +# self.log_info_message(message,self.file_name) + p = subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,env=dbenv,shell=True,universal_newlines=True) + p.stdin.write(sql_cmd) + # (stdout,stderr), retcode = p.communicate(sqlplus_script.encode('utf-8')), p.returncode + (stdout,stderr),retcode = p.communicate(),p.returncode + # stdout_lines = stdout.decode('utf-8').split("\n") + except: + error_msg=sys.exc_info() + self.log_error_message(error_msg,self.file_name) + self.prog_exit(self) + + return stdout.replace("\n\n", "\n"),stderr,retcode + + def execute_cmd(self,cmd,env,dir): + """ + Execute the OS command on host + """ + try: + message="Received Command : {0}".format(self.mask_str(cmd)) + self.log_info_message(message,self.file_name) + cmd=self.unmask_str(cmd) + out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,universal_newlines=True) + (output,error),retcode = out.communicate(),out.returncode + except: + error_msg=sys.exc_info() + self.log_error_message(error_msg,self.file_name) + self.prog_exit(self) + + return output,error,retcode + + def mask_str(self,mstr): + """ + Function to mask the string. + """ + newstr=None + if self.oenv.encrypt_str__: + newstr=mstr.replace('HIDDEN_STRING','********') + # self.log_info_message(newstr,self.file_name) + if newstr: + # message = "Masked the string as encryption flag is set in the singleton class" + # self.log_info_message(message,self.file_name) + return newstr + else: + return mstr + + + def unmask_str(self,mstr): + """ + Function to unmask the string. + """ + newstr=None + if self.oenv.encrypt_str__: + newstr=mstr.replace('HIDDEN_STRING',self.oenv.original_str__.rstrip()) + # self.log_info_message(newstr,self.file_name) + if newstr: + # message = "Unmasked the encrypted string and returning original string from singleton class" + # self.log_info_message(message,self.file_name) + return newstr + else: + return mstr + + def set_mask_str(self,mstr): + """ + Function to unmask the string. + """ + if mstr: + # message = "Setting encrypted String flag to True and original string in singleton class" + # self.log_info_message(message,self.file_name) + self.oenv.encrypt_str__ = True + self.oenv.original_str__ = mstr + else: + message = "Masked String is empty so no change required in encrypted String Flag and original string in singleton class" + self.log_info_message(message,self.file_name) + + def unset_mask_str(self): + """ + Function to unmask the string. + """ + # message = "Un-setting encrypted String flag and original string to None in Singleton class" + # self.log_info_message(message,self.file_name) + self.oenv.encrypt_str__ = None + self.oenv.original_str__ = None + + def prog_exit(self,message): + """ + This function exit the program because of some error + """ + sys.exit(127) + + def log_info_message(self,lmessage,fname): + """ + Print the INFO message in the logger + """ + funcname = sys._getframe(1).f_code.co_name + message = '''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_ = message + self.ologger.logtype_ = "INFO" + self.ohandler.handle(self.ologger) + + def log_error_message(self,lmessage,fname): + """ + Print the Error message in the logger + """ + funcname=sys._getframe(1).f_code.co_name + message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_=message + self.ologger.logtype_="ERROR" + self.ohandler.handle(self.ologger) + + def log_warn_message(self,lmessage,fname): + """ + Print the Error message in the logger + """ + funcname=sys._getframe(1).f_code.co_name + message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_=message + self.ologger.logtype_="WARN" + self.ohandler.handle(self.ologger) + + def check_sql_err(self,output,err,retcode,status): + """ + Check if there are any error in sql command output + """ + match=None + msg2='''Sql command failed.Flag is set not to ignore this error.Please Check the logs,Exiting the Program!''' + msg3='''Sql command failed.Flag is set to ignore this error!''' + self.log_info_message("output : " + str(output or "no Output"),self.file_name) + # self.log_info_message("Error : " + str(err or "no Error"),self.file_name) + # self.log_info_message("Sqlplus return code : " + str(retcode),self.file_name) + # self.log_info_message("Command Check Status Set to :" + str(status),self.file_name) + + if status: + if (retcode!=0): + self.log_info_message("Error : " + str(err or "no Error"),self.file_name) + self.log_error_message("Sql Login Failed.Please Check the logs,Exiting the Program!",self.file_name) + self.prog_exit(self) + + match=re.search("(?i)(?m)error",output) + if status: + if (match): + self.log_error_message(msg2,self.file_name) + self.prog_exit("error") + else: + self.log_info_message("Sql command completed successfully",self.file_name) + else: + if (match): + self.log_warn_message("Sql command failed. Flag is set to ignore the error.",self.file_name) + else: + self.log_info_message("Sql command completed sucessfully.",self.file_name) + + def check_os_err(self,output,err,retcode,status): + """ + Check if there are any error in OS command execution + """ + msg1='''OS command returned code : {0} and returned output : {1}'''.format(str(retcode),str(output or "no Output")) + msg2='''OS command returned code : {0}, returned error : {1} and returned output : {2}'''.format(str(retcode),str(err or "no returned error"),str(output or "no retruned output")) + msg3='''OS command failed. Flag is set to ignore this error!''' + + if status: + if (retcode != 0): + self.log_error_message(msg2,self.file_name) + self.prog_exit(self) + else: + self.log_info_message(msg1,self.file_name) + else: + if (retcode != 0): + self.log_warn_message(msg2,self.file_name) + self.log_warn_message(msg3,self.file_name) + else: + self.log_info_message(msg1,self.file_name) + + def check_key(self,key,env_dict): + """ + Check the key if it exist in dictionary. + Attributes: + key (string): String to check if key exist in dictionary + env_dict (dict): Contains the env variable related to seup + """ + if key in env_dict: + return True + else: + return False + + def empty_key(self,key): + """ + key is empty and print failure message. + Attributes: + key (string): String is empty + """ + msg='''Variable {0} is not defilned. Exiting!'''.format(key) + self.log_error_message(msg,self.file_name) + self.prog_exit(self) + + def add_key(self,key,value,env_dict): + """ + Add the key in the dictionary. + Attributes: + key (string): key String to add in the dictionary + value (String): value String to add in dictionary + + Return: + dict + """ + if self.check_key(key,env_dict): + msg='''Variable {0} already exist in the env variables'''.format(key) + self.log_info_message(msg,self.file_name) + else: + if value: + env_dict[key] = value + self.oenv.update_env_vars(env_dict) + else: + msg='''Variable {0} value is not defilned to add in the env variables. Exiting!'''.format(value) + self.log_error_message(msg,self.file_name) + self.prog_exit(self) + + return env_dict + + def update_key(self,key,value,env_dict): + """ + update the key in the dictionary. + Attributes: + key (string): key String to update in the dictionary + value (String): value String to update in dictionary + + Return: + dict + """ + if self.check_key(key,env_dict): + if value: + env_dict[key] = value + self.oenv.update_env_vars(env_dict) + else: + msg='''Variable {0} value is not defilned to update in the env variables!'''.format(key) + self.log_warn_message(msg,self.file_name) + else: + msg='''Variable {0} already exist in the env variables'''.format(key) + self.log_info_message(msg,self.file_name) + + return env_dict + + def check_file(self,file,local,remote,user): + """ + check locally or remotely + Attributes: + file (string): file to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside check_file()",self.file_name) + if local: + if os.path.isfile(file): + return True + else: + return False + + + def read_file(self,fname): + """ + Read the contents of a file and returns the contents to end user + Attributes: + fname (string): file to be read + + Return: + file data (string) + """ + f1 = open(fname, 'r') + fdata = f1.read() + f1.close + return fdata + + def write_file(self,fname,fdata): + """ + write the contents to a file + Attributes: + fname (string): file to be written + fdata (string): COnetents to be written + + Return: + file data (string) + """ + f1 = open(fname, 'w') + f1.write(fdata) + f1.close + + def append_file(self,fname,fdata): + """ + append the contents to a file + Attributes: + fname (string): file to be appended + fdata (string): COnetents to be appended + + Return: + file data (string) + """ + f1 = open(fname, 'a') + f1.write(fdata) + f1.close + + def create_dir(self,dir,local,remote,user): + """ + Create dir locally or remotely + Attributes: + dir (string): dir to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside create_dir()",self.file_name) + if local: + if not os.path.isdir(dir): + cmd='''mkdir -p {0}'''.format(dir) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + else: + msg='''Dir {0} already exist'''.format(dir) + self.log_info_message(msg,self.file_name) + + if remote: + pass + + def create_file(self,file,local,remote,user): + """ + Create dir locally or remotely + Attributes: + file (string): file to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside create_file()",self.file_name) + if local: + if not os.path.isfile(file): + cmd='''touch {0}'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + if remote: + pass + + def shutdown_db(self,env_dict): + """ + Shutdown the database + """ + file="/home/oracle/shutDown.sh" + if not os.path.isfile(file): + self.log_info_message("Inside shutdown_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + shutdown immediate; + ''' + self.log_info_message("Running the sqlplus command to shutdown the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + else: + cmd='''sh {0} immediate'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + def mount_db(self,env_dict): + """ + Mount the database + """ + self.log_info_message("Inside mount_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup mount; + ''' + self.log_info_message("Running the sqlplus command to mount the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def start_db(self,env_dict): + """ + startup the database + """ + file="/home/oracle/startUp.sh" + if not os.path.isfile(file): + self.log_info_message("Inside start_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup; + ''' + self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + else: + cmd='''sh {0}'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + def nomount_db(self,env_dict): + """ + No mount the database + """ + self.log_info_message("Inside start_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup nomount; + ''' + self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def stop_gsm(self,env_dict): + """ + Stop the GSM + """ + self.log_info_message("Inside stop_gsm()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + gsmcmd=''' + stop gsm; + ''' + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + + def set_events(self,source): + """ + Seting events at DB level + """ + scope='' + accepted_scope = ['spfile', 'memory', 'both'] + + if self.check_key("DB_EVENTS",self.ora_env_dict): + events=str(self.ora_env_dict["DB_EVENTS"]).split(";") + + for event in events: + msg='''Setting up event {0}'''.format(event) + self.log_info_message(msg,self.file_name) + scope='' + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + source=event.split(":") + if len(source) > 1: + if source[1].split("=")[0] == "scope": + scope=source[1].split("=")[1] + + if scope not in accepted_scope: + sqlcmd=""" + alter system set events='{0}';""".format(source[0]) + else: + sqlcmd=""" + alter system set event='{0}' scope={1};""".format(source[0],scope) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def start_gsm(self,env_dict): + """ + Start the GSM + """ + self.log_info_message("Inside start_gsm()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + gsmcmd=''' + start gsm; + ''' + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + + def exec_gsm_cmd(self,gsmcmd,flag,env_dict): + """ + Get the GSM command output + """ + self.log_info_message("Inside exec_gsm_cmd()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + if gsmcmd: + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,flag) + else: + self.log_info_message("GSM Command was set to empty. Executing nothing and setting output to None",self.file_name) + output=None + + return output,error,retcode + + + def check_substr_match(self,source_str,sub_str): + """ + CHeck if substring exist + """ + self.log_info_message("Inside check_substr_match()",self.file_name) + if (source_str.find(sub_str) != -1): + return True + else: + return False + + def find_str_in_string(self,source_str,delimeter,search_str): + """AI is creating summary for find_str_in_string + + Args: + source_str ([string]): [string where you need to search] + delimeter ([character]): [string delimeter] + search_str ([string]): [string to be searched] + """ + if delimeter == 'comma': + new_str=source_str.split(',') + for str in new_str: + if str.lower() == search_str.lower(): + return True + return False + + return False + + def check_status_value(self,match): + """ + return completed or notcompleted + """ + self.log_info_message("Inside check_status_value()",self.file_name) + if match: + return 'completed' + else: + return 'notcompleted' + + def remove_file(self,fname): + """ + Remove if file exist + """ + self.log_info_message("Inside remove_file()",self.file_name) + if os.path.exists(fname): + os.remove(fname) + + def get_sid_desc(self,gdbname,ohome,sid,sflag): + """ + get the SID_LISTENER_DESCRIPTION + """ + self.log_info_message("Inside get_sid_desc()",self.file_name) + sid_desc = "" + if sflag == 'SID_DESC1': + sid_desc = ''' ) + (SID_DESC = + (GLOBAL_DBNAME = {0}) + (ORACLE_HOME = {1}) + (SID_NAME = {2}) + ) + ) + '''.format(gdbname,ohome,sid) + elif sflag == 'SID_DESC': + sid_desc = '''(SID_LIST = + (SID_DESC = + (GLOBAL_DBNAME = {0}) + (ORACLE_HOME = {1}) + (SID_NAME = {2}) + ) + ) + '''.format(gdbname,ohome,sid) + else: + pass + + return sid_desc + + def get_lisora(self,port): + """ + return listener.ora listener settings + """ + self.log_info_message("Inside get_lisora()",self.file_name) + listener='''LISTENER = + (DESCRIPTION_LIST = + (DESCRIPTION = + (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = {0})) + (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC{0})) + ) + ) + '''.format(port) + return listener + + def get_domain(self,ohost): + """ + get the domain name from hostname + """ + return ohost.partition('.')[2] + +######### Get the DOMAIN############## + def get_host_domain(self): + """ + Return Public Hostname + """ + domain=None + domain=socket.getfqdn().split('.',1)[1] + if domain is None: + domain="example.info" + + return domain + + ######### get the public IP ############## + def get_ip(self,hostname,domain): + """ + Return the Ip based on hostname + """ + if not domain: + domain=self.get_host_domain() + + return socket.gethostbyname(hostname) + + def get_global_dbdomain(self,ohost,gdbname): + """ + get the global dbname + """ + domain = self.get_domain(ohost) + if domain: + global_dbname = gdbname + domain + else: + global_dbname = gdbname + + return gdbname + +######### Sqlplus connect string ########### + def get_sqlplus_str(self,home,osid,dbuser,password,hostname,port,svc,osep,role,wallet): + """ + return the sqlplus connect string + """ + path='''/usr/bin:/bin:/sbin:/usr/local/sbin:{0}/bin'''.format(home) + ldpath='''{0}/lib:/lib:/usr/lib'''.format(home) + export_cmd='''export ORACLE_HOME={0};export PATH={1};export LD_LIBRARY_PATH={2};export ORACLE_SID={3}'''.format(home,path,ldpath,osid) + if dbuser == 'sys' and password and hostname and port and svc: + return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4} as sysdba'''.format(dbuser,password,hostname,port,svc,export_cmd,home) + elif dbuser != 'sys' and password and hostname and svc: + return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4}'''.format(dbuser,password,hostname,"1521",svc,export_cmd,home) + elif dbuser and osep: + return dbuser + elif dbuser == 'sys' and not password: + return '''{1};{0}/bin/sqlplus "/ as sysdba"'''.format(home,export_cmd) + elif dbuser == 'sys' and password: + return '''{1};{0}/bin/sqlplus {2}/{3} as sysdba'''.format(home,export_cmd,dbuser,password) + elif dbuser != 'sys' and password: + return '''{1};{0}/bin/sqlplus {2}/{3}'''.format(home,export_cmd,dbuser,password) + else: + self.log_info_message("Atleast specify db user and password for db connectivity. Exiting...",self.file_name) + self.prog_exit("127") + +######### Get Password ############## + def get_os_password(self): + """ + get the OS password + """ + ospasswd=self.get_password(None) + return ospasswd + + def get_asm_passwd(self): + """ + get the ASM password + """ + asmpasswd=self.get_password(None) + return asmpasswd + + def get_db_passwd(self): + """ + get the DB password + """ + dbpasswd=self.get_password(None) + return dbpasswd + + def get_sys_passwd(self): + """ + get the sys user password + """ + dbpasswd=self.get_password(None) + return dbpasswd + + def get_password(self,key): + """ + get the password + """ + passwd_file_flag=False + password=None + password_file=None + if self.check_key("SECRET_VOLUME",self.ora_env_dict): + self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["SECRET_VOLUME"]) + msg='''SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) + else: + self.ora_env_dict=self.add_key("SECRET_VOLUME","/run/secrets",self.ora_env_dict) + msg='''SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("KEY_SECRET_VOLUME",self.ora_env_dict): + self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["KEY_SECRET_VOLUME"]) + msg='''KEY_SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + else: + if self.check_key("SECRET_VOLUME",self.ora_env_dict): + self.ora_env_dict=self.add_key("KEY_SECRET_VOLUME",self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict) + msg='''KEY_SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict): + msg='''COMMON_OS_PWD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) + else: + self.ora_env_dict=self.add_key("COMMON_OS_PWD_FILE","common_os_pwdfile.enc",self.ora_env_dict) + msg='''COMMON_OS_PWD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("PWD_KEY",self.ora_env_dict): + msg='''PWD_KEY passed as an env variable and set to {0}'''.format(self.ora_env_dict["PWD_KEY"]) + else: + self.ora_env_dict=self.add_key("PWD_KEY","pwd.key",self.ora_env_dict) + msg='''PWD_KEY not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PWD_KEY"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("PASSWORD_FILE",self.ora_env_dict): + msg='''PASSWORD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) + else: + self.ora_env_dict=self.add_key("PASSWORD_FILE","dbpasswd.file",self.ora_env_dict) + msg='''PASSWORD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) + self.log_warn_message(msg,self.file_name) + + secret_volume = self.ora_env_dict["SECRET_VOLUME"] + key_secret_volume= self.ora_env_dict["KEY_SECRET_VOLUME"] + common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"] + pwd_volume=None + if self.check_key("PWD_VOLUME",self.ora_env_dict): + pwd_volume=self.ora_env_dict["PWD_VOLUME"] + else: + pwd_volume="/var/tmp" + pwd_key = self.ora_env_dict["PWD_KEY"] + passwd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) + dbpasswd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["PASSWORD_FILE"]) + key_file='''{0}/{1}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"],self.ora_env_dict["PWD_KEY"]) + key_secret_volume='''{0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + self.log_info_message("Password file set to : " + passwd_file,self.file_name) + self.log_info_message("key file set to : " + key_file,self.file_name) + self.log_info_message("dbpasswd file set to : " + dbpasswd_file,self.file_name) + self.log_info_message("key secret voluem set to file set to : " + key_secret_volume,self.file_name) + self.log_info_message("pwd volume set : " + pwd_volume,self.file_name) + #print(passwd_file) + if (os.path.isfile(passwd_file)) and (os.path.isfile(key_file)): + msg='''Passwd file {0} and key file {1} exist. Password file Check passed!'''.format(passwd_file,key_file) + self.log_info_message(msg,self.file_name) + msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file) + self.log_info_message(msg,self.file_name) + cmd=None + if self.check_key("ENCRYPTION_TYPE",self.ora_env_dict): + if self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "aes256": + cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out {2}/{1} -pass file:\"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + elif self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "rsautl": + cmd ='''openssl rsautl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + else: + pass + else: + cmd ='''openssl pkeyutl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + passwd_file_flag = True + password_file='''{0}/{1}'''.format(pwd_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) + elif os.path.isfile(dbpasswd_file): + msg='''Passwd file {0} exist. Password file Check passed!'''.format(dbpasswd_file) + self.log_info_message(msg,self.file_name) + msg='''Reading encrypted passwd from file {0}.'''.format(dbpasswd_file) + self.log_info_message(msg,self.file_name) + cmd='''openssl base64 -d -in \"{0}\" -out \"{2}/{1}\"'''.format(dbpasswd_file,self.ora_env_dict["PASSWORD_FILE"],pwd_volume) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + passwd_file_flag = True + password_file='''{1}/{0}'''.format(self.ora_env_dict["PASSWORD_FILE"],pwd_volume) + + if not passwd_file_flag: + # get random password pf length 8 with letters, digits, and symbols + characters1 = string.ascii_letters + string.digits + "_-%#" + str1 = ''.join(random.choice(string.ascii_uppercase) for i in range(4)) + str2 = ''.join(random.choice(characters1) for i in range(8)) + password=str1+str2 + else: + fname='''{0}'''.format(password_file) + fdata=self.read_file(fname) + password=fdata + self.remove_file(fname) + + if self.check_key("ORACLE_PWD",self.ora_env_dict): + if len(self.ora_env_dict["ORACLE_PWD"]) > 0: + msg="ORACLE_PWD is passed as an env variable. Check Passed!" + self.log_info_message(msg,self.file_name) + else: + msg="ORACLE_PWD passed as 0 length string" + self.log_info_message(msg,self.file_name) + self.ora_env_dict=self.update_key("ORACLE_PWD",password,self.ora_env_dict) + msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file" + self.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.add_key("ORACLE_PWD",password,self.ora_env_dict) + msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file" + self.log_info_message(msg,self.file_name) + +######### Get oraversion ############## + def get_oraversion(self,home): + """ + get the software version + """ + cmd='''{0}/bin/oraversion -majorVersion'''.format(home) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + return output + +####### Get db lock file location ####### + def get_db_lock_location(self): + """ + get the db location + """ + if self.check_key("DB_LOCK_FILE_LOCATION",self.ora_env_dict): + return self.ora_env_dict["DB_LOCK_FILE_LOCATION"] + else: + ### Please note that you should not change following path as SIDB team is maintaining lock files under following location + return "/tmp/." + +####### Get the TDE Key ############### + def export_tde_key(self,filename): + """ + This function export the tde. + """ + self.log_info_message("Inside gettdekey()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + ALTER SESSION DISABLE SHARD DDL; + ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET {0} TO {1} IDENTIFIED BY {0}; + '''.format('HIDDEN_STRING',filename) + self.log_info_message("Running the sqlplus command to export the tde: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + +####### Get the TDE Key ############### + def import_tde_key(self,filename): + """ + This function import the TDE key. + """ + self.log_info_message("Inside importtdekey()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY {0}; + ADMINISTER KEY MANAGEMENT IMPORT ENCRYPTION KEYS WITH SECRET {0} FROM {1} IDENTIFIED BY {0} WITH BACKUP + '''.format('HIDDEN_STRING',filename) + self.log_info_message("Running the sqlplus command to import the tde key: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + +####### Check PDB if it exist ############### + def check_pdb(self,pdbname): + """ + This function check the PDB. + """ + self.log_info_message("Inside check_pdb()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + set heading off + set feedback off + select NAME from gv$pdbs; + ''' + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + pdblist=output.splitlines() + self.log_info_message("Checking pdb " + pdbname, self.file_name) + if pdbname in pdblist: + return True + else: + return False + +####### Create PDB if it does not exist ############### + def create_pdb(self,ohome,opdb,inst_sid): + """ + This function create the PDB. + """ + self.log_info_message("Inside create_pdb()",self.file_name) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd='''{0}/bin/dbca -silent -createPluggableDatabase -pdbName {1} -sourceDB {2} <<< HIDDEN_STRING'''.format(ohome,opdb,inst_sid) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.unset_mask_str() + self.check_os_err(output,error,retcode,True) + + + +####### Create PDB tnsnames.ora entry ############### + def create_pdb_tns_entry(self,ohome,opdb): + """ + This function create the PDB tnsnames.ora entry. + """ + self.log_info_message("Inside create_pdb_tns_entry()",self.file_name) + tns_entry_string=""" +{0} = + (DESCRIPTION = + (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521)) + (CONNECT_DATA = + (SERVER = DEDICATED) + (SERVICE_NAME = {0}) + ) + ) + +""".format(opdb) + + tns_file='''{0}/network/admin/tnsnames.ora'''.format(ohome) + self.append_file(tns_file,tns_entry_string) + +######## Reset the DB Password in database ######## + def reset_passwd(self): + """ + This function reset the password. + """ + password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh") + self.log_info_message("Executing password reset", self.file_name) + if self.check_key("ORACLE_PWD",self.ora_env_dict) and self.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script): + cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING') + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + self.unset_mask_str() + else: + msg='''Error Occurred! Either HOME DIR {0} does not exist, ORACLE_PWD {1} is not set or PASSWORD SCRIPT {2} does not exist'''.format(self.ora_env_dict["HOME"],self.ora_env_dict["ORACLE_PWD"],password_script) + self.log_error_message(msg,self.file_name) + self.oracommon.prog_exit() diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oraenv.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oraenv.py new file mode 100755 index 0000000..dd96c48 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oraenv.py @@ -0,0 +1,139 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file read the env variables from a file or using env command and populate them in variable +""" + +import os + +class OraEnv: + __instance = None + __env_var_file = '/etc/rac_env_vars' + + __env_var_file_flag = None + __env_var_dict = {} + __ora_asm_diskgroup_name = '+DATA' + __ora_gimr_flag = 'false' + __ora_grid_user = 'grid' + __ora_db_user = 'oracle' + __ora_oinstall_group_name = 'oinstall' + encrypt_str__ = None + original_str__ = None + logdir__ = "/tmp/sharding" + + def __init__(self): + """ Virtually private constructor. """ + if OraEnv.__instance != None: + raise Exception("This class is a singleton!") + else: + OraEnv.__instance = self + OraEnv.read_variable() + OraEnv.add_variable() + try: + os.mkdir(OraEnv.logdir__) + except OSError as error: + pass + + @staticmethod + def get_instance(): + """ Static access method. """ + if OraEnv.__instance == None: + OraEnv() + return OraEnv.__instance + + @staticmethod + def read_variable(): + """ Read the variables from a file into dict """ + if OraEnv.__env_var_file_flag: + with open(OraEnv.__env_var_file) as envfile: + for line in envfile: + name, var = line.partition("=")[::2] + OraEnv.__env_var_dict[name.strip()] = var + else: + OraEnv.__env_var_dict = os.environ + + @staticmethod + def add_variable(): + """ Add more variable ased on enviornment with default values in __env_var_dict""" + OraEnv.__env_var_dict["GSM_LOCK_STATUS_FILE"] = "/tmp/.gsm_status_lock_file" + OraEnv.__env_var_dict["SHARD_LOCK_STATUS_FILE"] = "/tmp/.shard_status_lock_file" + if "ORA_ASM_DISKGROUP_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_ASM_DISKGROUP_NAME"] = "+DATA" + + if "ORA_GRID_USER" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_GRID_USER"] = "grid" + + if "ORA_DB_USER" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_DB_USER"] = "oracle" + + if "ORA_OINSTALL_GROUP_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_OINSTALL_GROUP_NAME"] = "oinstall" + + @staticmethod + def add_custom_variable(key,val): + """ Addcustom more variable passed from main.py values in __env_var_dict""" + if key not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict[key] = val + + @staticmethod + def get_env_vars(): + """ Static access method to get the env vars. """ + return OraEnv.__env_var_dict + + @staticmethod + def update_env_vars(env_dict): + """ Static access method to get the env vars. """ + OraEnv.__env_var_dict = env_dict + + @staticmethod + def logfile_name(file_type): + """ Static access method to return the logfile name. """ + if file_type == "NONE": + if "LOGFILE_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/oracle_sharding_setup.log" + elif file_type == "ADD_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_addition.log" + elif file_type == "VALIDATE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_validation.log" + elif file_type == "REMOVE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_remove.log" + elif file_type == "CHECK_LIVENESS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkliveness.log" + elif file_type == "CHECK_READYNESS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkreadyness.log" + elif file_type == "RESET_LISTENER": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_listener.log" + elif file_type == "RESTART_DB": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/restart_db.log" + elif file_type == "CREATE_DIR": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/create_dir.log" + elif file_type == "ADD_SGROUP_PARAMS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/add_sgroup.log" + elif file_type == "DEPLOY_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/deploy_shard.log" + elif file_type == "CANCEL_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/cancel_chunk.log" + elif file_type == "MOVE_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/move_chunks.log" + elif file_type == "CHECK_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_chunks.log" + elif file_type == "CHECK_ONLINE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_online_shard.log" + elif file_type == "CHECK_GSM_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_gsm_shard.log" + elif file_type == "INVITED_NODE_OP": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/node_invited_op.log" + elif file_type == "RESET_PASSWD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_passwd_file.log" + elif file_type == "TDE_KEY": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/tde_key.log" + else: + pass + + return OraEnv.__env_var_dict["LOG_FILE_NAME"] diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orafactory.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orafactory.py new file mode 100755 index 0000000..5ddb6e3 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orafactory.py @@ -0,0 +1,115 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file contains to the code call different classes objects based on setup type +""" + +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +from orapshard import * +from orasshard import * +from orapcatalog import * +from oragsm import * + +import os +import sys + +class OraFactory: + """ + This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def get_ora_objs(self): + ''' + Return the instance of a classes which will setup the enviornment. + + Returns: + ofactory_obj: List of objects + ''' + ofactory_obj = [] + + msg='''ora_env_dict set to : {0}'''.format(self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + msg="Checking the OP_TYPE and Version to begin the installation" + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the OP_TYPE + if self.ocommon.check_key("OP_TYPE",self.ora_env_dict): + msg='''OP_TYPE variable is set to {0}.'''.format(self.ora_env_dict["OP_TYPE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("OP_TYPE","nosetup",self.ora_env_dict) + msg="OP_TYPE variable is set to default nosetup. No value passed as an enviornment variable." + self.ocommon.log_info_message(msg,self.file_name) + + # Check the OP_TYPE value and call objects based on it value + if self.ora_env_dict["OP_TYPE"] == 'primaryshard': + msg="Creating and calling instance to setup primary shard" + opshard = OraPShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(opshard) + elif self.ora_env_dict["OP_TYPE"] == 'standbyshard': + msg="Creating and calling instance to setup standby shard" + osshard = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(osshard) + elif self.ora_env_dict["OP_TYPE"] == 'catalog': + msg="Creating and calling instance to setup Catalog DB" + opcat = OraPCatalog(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(opcat) + elif self.ora_env_dict["OP_TYPE"] == 'standbycatalog': + msg="Creating and calling instance to setup Catalog DB" + oscat = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(oscat) + elif self.ora_env_dict["OP_TYPE"] == 'gsm': + msg="Creating and calling instance to setup GSM" + ogsm = OraGSM(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(ogsm) + else: + msg="OP_TYPE must be set to {primaryshard|standbyshard|catalog|standbycatalog|gsm}" + self.ocommon.log_info_message(msg,self.file_name) + msg="Since OP_TYPE is set to nosetup, only compute env is being setup. Creating and calling instance to setup compute." + self.ocommon.log_info_message(msg,self.file_name) + omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + ofactory_obj.append(omachine) + + return ofactory_obj diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oragsm.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oragsm.py new file mode 100755 index 0000000..ef0bb06 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oragsm.py @@ -0,0 +1,2945 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +import os +import sys +import os.path +import re +import socket +import random +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +class OraGSM: + """ + This calss setup the Gsm after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraGsm class to setup the Gsm on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def setup(self): + """ + This function setup the Gsm on Primary DB. + """ + if self.ocommon.check_key("ADD_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.add_gsm_shard() + self.set_hostid_null() + self.add_invited_node("ADD_SHARD") + self.remove_invited_node("ADD_SHARD") + sys.exit(0) + if self.ocommon.check_key("DEPLOY_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.deploy_shard() + self.setup_gsm_service() + sys.exit(0) + elif self.ocommon.check_key("ADD_SGROUP_PARAMS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_gsm_shardg("ADD_SGROUP_PARAMS") + sys.exit(0) + elif self.ocommon.check_key("ADD_SSPACE_PARAMS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_gsm_sspace("ADD_SSPACE_PARAMS") + sys.exit(0) + elif self.ocommon.check_key("REMOVE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + status=self.remove_gsm_shard() + + if status: + sys.exit(0) + else: + sys.exit(1) + + elif self.ocommon.check_key("MOVE_CHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.move_shard_chunks() + sys.exit(0) + elif self.ocommon.check_key("TDE_KEY",self.ora_env_dict): + self.ocommon.get_tde_key() + sys.exit(0) + elif self.ocommon.check_key("CANCEL_CHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.cancel_move_chunks() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_NOCHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.validate_nochunks() + sys.exit(0) + elif self.ocommon.check_key("CHECK_ONLINE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.verify_online_shard() + sys.exit(0) + elif self.ocommon.check_key("CHECK_GSM_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.verify_gsm_shard() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.validate_gsm_shard() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_GSM",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + sys.exit(0) + elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + if os.path.exists(filename): + self.ocommon.log_info_message("provisioning is still in progress as file " + filename + " still exist!",self.file_name) + sys.exit(0) + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + status = self.check_gsm_director_status(None) + if not status: + self.ocommon.log_info_message("No GDS setup found on this system.",self.file_name) + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("GSM liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("INVITED_NODE_OP",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.invited_node_op() + sys.exit(0) + elif self.ocommon.check_key("CATALOG_SETUP",self.ora_env_dict): + # If user pass env avariable CATALOG_SETUP true then it will just create gsm director and add catalog but will not add any shard + # It will also add service + status = self.catalog_setup_checks() + if status == False: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.setup_machine() + self.catalog_checks() + self.reset_gsm_setup() + status1 = self.gsm_setup_check() + if status1: + self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) + self.start_gsm_director() + self.ocommon.log_info_message("Started GSM",self.file_name) + else: + # Perform Catalog setup after check GSM_MASTER FLAG. IF GSM MASTER FLAG is set then only catalog will be added. + self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) + master_flag=self.gsm_master_flag_check() + if master_flag: + self.setup_gsm_calog() + self.setup_gsm_director() + self.start_gsm_director() + self.status_gsm_director() + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': + self.setup_gsm_shardg("SHARD_GROUP") + else: + self.setup_gsm_shardg("SHARD_GROUP") + self.gsm_backup_file() + self.gsm_completion_message() + ### Running Custom Scripts + self.run_custom_scripts() + else: + self.add_gsm_director() + self.start_gsm_director() + self.gsm_backup_file() + self.gsm_completion_message() + else: + # This block run shard addition, catalog addition and service creation + # This block also verifies if master flag is not not GSM director then it will not create catalog but add GSM ony + self.setup_machine() + self.gsm_checks() + self.reset_gsm_setup() + status = self.gsm_setup_check() + if status: + self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) + self.start_gsm_director() + self.ocommon.log_info_message("Started GSM",self.file_name) + else: + # if the status = self.gsm_setup_check() return False then shard addition, catalog addition and service creation + master_flag=self.gsm_master_flag_check() + if master_flag: + self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) + self.setup_gsm_calog() + self.setup_gsm_director() + self.start_gsm_director() + self.status_gsm_director() + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': + self.setup_gsm_shardg("SHARD_GROUP") + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + self.setup_gsm_sspace("SHARD_SPACE") + else: + self.setup_gsm_shardg("SHARD_GROUP") + self.setup_gsm_shard() + self.set_hostid_null() + self.stop_gsm_director() + time.sleep(30) + self.start_gsm_director() + self.add_invited_node("SHARD") + self.remove_invited_node("SHARD") + self.stop_gsm_director() + time.sleep(30) + self.start_gsm_director() + self.deploy_shard() + self.setup_gsm_service() + self.setup_sample_schema() + self.gsm_backup_file() + self.gsm_completion_message() + ### Running Custom Scripts + self.run_custom_scripts() + else: + self.add_gsm_director() + self.start_gsm_director() + self.gsm_backup_file() + self.gsm_completion_message() + + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + filename = self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + touchfile = 'touch {0}'.format(filename) + if not os.path.isfile(filename): + self.ocommon.log_error_message("Setting file provisioning status file :" + filename ,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(touchfile,None,self.ora_env_dict) + if retcode == 1: + self.ocommon.log_error_message("error occurred while touching the file :" + filename + ". Exiting!",self.file_name) + self.ocommon.prog_exit("127") + + ########### ENDS here #################### + + def gsm_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.shard_user_check() + self.gsm_hostname_check() + self.director_params_checks() + self.catalog_params_check() + self.shard_params_check() + self.sgroup_params_check() + + + def catalog_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.shard_user_check() + self.gsm_hostname_check() + self.director_params_checks() + self.catalog_params_check() + self.sgroup_params_check() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit("127") + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def passwd_check(self): + """ + Set the password + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def shard_user_check(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def director_params_checks(self): + """ + This funnction check and set the shard director name + """ + status=False + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD Director PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + + def gsm_hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def catalog_params_check(self): + """ + This funnction check if CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''CATALOG PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + if stype: + if stype.lower() == 'user': + if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) + if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) + status=True + + if not status: + msg="CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is not set, exiting!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def shard_params_check(self): + """ + This funnction check if SHARD[1-9]_PARAMS such as SHARD1_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + + if not status: + msg="SHARD[1-9]_PARAMS such as SHARD1_PARAMS is not set, exiting!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def sgroup_params_check(self): + """ + This funnction check if SHARD[1-9]_GROUP_PARAMS such as SHARD1_GROUP_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD GROUP PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + def gsm_master_flag_check(self): + """ + This funnction check if MASTER_GSM is passed as an env variable or not. If not passed then exit. + """ + status=False + if self.ocommon.check_key("MASTER_GSM",self.ora_env_dict): + msg='''MASTER_GSM is set. This machine will be configured with as master GSM director.''' + self.ocommon.log_info_message(msg,self.file_name) + return True + else: + return False + + def catalog_setup_checks(self): + """ + This function checks if director and catalog is setup and connection is established. + """ + status = False + gsm_status = self.check_gsm_director(None) + #catalog_status = self.check_gsm_catalog() + + if gsm_status == 'completed': + status = True + else: + status = False + + #if catalog_status == 'completed': + # status = True + #else: + # status = False + + return status + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### + def reset_gsm_setup(self): + """ + This function delete the GSM files. + """ + self.ocommon.log_info_message("Inside reset_gsm_setup",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + cmd_list=[] + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + msg='''Deleteing files from {0}'''.format(gsmdata_loc) + self.ocommon.log_info_message(msg,self.file_name) + cmd_list[0]='''rm -f {0}/gsm.ora'''.format(gsmdata_loc) + cmd_list[1]='''rm -f {0}/tnsnames.ora'''.format(gsmdata_loc) + cmd_list[2]='''rm -rf {0}/wallets'''.format(gsmdata_loc) + for cmd in cmd_list: + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + def gsm_setup_check(self): + """ + This function check if GSM is already setup on this + """ + status=True + self.ocommon.log_info_message("Inside gsm_setup_check",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) + + gsmora='''{0}/gsm.ora'''.format(gsmdata_loc) + tnsnamesora='''{0}/tnsnames.ora'''.format(gsmdata_loc) + walletloc='''{0}/gsmwallet'''.format(gsmdata_loc) + + if os.path.isfile(gsmora): + cmd='''cp -r -v -f {0} {1}/'''.format(gsmora,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if os.path.isfile(tnsnamesora): + cmd='''cp -r -v -f {0} {1}/'''.format(tnsnamesora,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if os.path.isdir(walletloc): + cmd='''cp -r -v -f {0} {1}/'''.format(walletloc,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if status: + return True + else: + return False + + #################### Catalog related Functions BEGINS Here ########################### + def setup_gsm_calog(self): + """ + This function setup the GSM catalog. + """ + self.ocommon.log_info_message("Inside setup_gsm_calog()",self.file_name) + status=False + reg_exp= self.catalog_regex() + counter=1 + end_counter=60 + catalog_db_status=None + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + catalog_db_status=self.check_setup_status(catalog_host,catalog_db,catalog_pdb,catalog_port) + if catalog_db_status == 'completed': + self.configure_gsm_clog(catalog_host,catalog_db,catalog_pdb,catalog_port,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname) + break + else: + msg='''Catalog Status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + if catalog_db_status == 'completed': + break + else: + msg='''Catalog setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + def process_clog_vars(self,key): + """ + This function process catalog vars based on key and return values to configure the GSM + """ + catalog_db=None + catalog_pdb=None + catalog_port=None + catalog_region=None + catalog_host=None + catalog_name=None + catalog_chunks=None + repl_type=None + repl_factor=None + repl_unit=None + stype=None + sspace=None + cfname=None + + self.ocommon.log_info_message("Inside process_clog_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'catalog_db': + catalog_db = cvar_dict[ckey] + if ckey == 'catalog_pdb': + catalog_pdb = cvar_dict[ckey] + if ckey == 'catalog_port': + catalog_port = cvar_dict[ckey] + if ckey == 'catalog_region': + catalog_region = cvar_dict[ckey] + if ckey == 'catalog_host': + catalog_host = cvar_dict[ckey] + if ckey == 'catalog_name': + catalog_name = cvar_dict[ckey] + if ckey == 'catalog_chunks': + catalog_chunks = cvar_dict[ckey] + if ckey == 'repl_type': + repl_type = cvar_dict[ckey] + if ckey == 'repl_factor': + repl_factor = cvar_dict[ckey] + if ckey == 'repl_unit': + repl_unit = cvar_dict[ckey] + if ckey == 'sharding_type': + stype = cvar_dict[ckey] + if ckey == 'shard_space': + sspace = cvar_dict[ckey] + if ckey == 'shard_configname': + cfname = cvar_dict[ckey] + + ## Set the values if not set in above block + if not catalog_port: + catalog_port=1521 + if not catalog_region: + catalog_region="region1,region2" + if stype: + if not sspace: + sspace="shardspace1,shardspace2" + + ### Check values must be set + if catalog_host and catalog_db and catalog_pdb and catalog_port and catalog_region and catalog_name: + return catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname + else: + msg1='''catalog_db={0},catalog_pdb={1}'''.format((catalog_db or "Missing Value"),(catalog_pdb or "Missing Value")) + msg2='''catalog_port={0},catalog_host={1}'''.format((catalog_port or "Missing Value"),(catalog_host or "Missing Value")) + msg3='''catalog_region={0},catalog_name={1}'''.format((catalog_region or "Missing Value"),(catalog_name or "Missing Value")) + msg='''Catalog params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def check_gsm_catalog(self): + """ + This function check the catalog status in GSM + """ + self.ocommon.log_info_message("Inside check_gsm_catalog()",self.file_name) + #dtrname,dtrport,dtregion=self.process_director_vars() + gsmcmd=''' + config; + exit; + '''.format("test") + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + match=self.ocommon.check_substr_match(matched_output[0],"test") + except: + match=False + return(self.ocommon.check_status_value(match)) + + # output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + # new_output=output[0].replace(" ","") + # self.ocommon.log_info_message(new_output,self.file_name) + # match=self.ocommon.check_substr_match(new_output,"Catalogconnectionisestablished") + # return(self.ocommon.check_status_value(match)) + + def catalog_regex(self): + """ + This function return the rgex to search the CATALOG PARAMS + """ + self.ocommon.log_info_message("Inside catalog_regex()",self.file_name) + return re.compile('CATALOG_PARAMS') + + + def configure_gsm_clog(self,chost,ccdb,cpdb,cport,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname): + """ + This function configure the GSM catalog. + """ + self.ocommon.log_info_message("Inside configure_gsm_clog()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + replist=['native'] + + ### User Define Shardig Variables + shardingtype=None + shardspace=None + configname=None + + # if stype and sspace: + if stype: + if stype.lower() == 'user': + shardingtype="-sharding user" + #shardspace="" + shardspace=" -shardspace {0}".format(sspace) + if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) + if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) + else: + shardspace="" + shardingtype="" + else: + shardspace="" + shardingtype="" + + if cfname: + configname=" -configname {0}".format(cfname) + else: + configname="" + + ### SNR Sharding + chunks=None + repl=None + repfactor=None + repunits=None + + if catalog_chunks: + chunks="-chunks {0}".format(catalog_chunks) + else: + chunks="" + + if repl_type and repl_type.lower() in replist: + self.ocommon.log_info_message("Repl_Type value Set to in block1:" + repl_type,self.file_name) + repl=" -repl {0}".format(repl_type) + else: + repl="" + + if repl_factor: + repfactor=" -repfactor {0}".format(repl_factor) + else: + repfactor="" + + if repl_unit: + repunits=" -repunits {0}".format(repl_unit) + else: + repunits="" + + invited_subnet="" + add_invited_subnet="" + if self.ocommon.check_key("INVITED_NODE_SUBNET_FLAG",self.ora_env_dict): + if self.ocommon.check_key("INVITED_NODE_SUBNET",self.ora_env_dict): + invited_subnet=self.ora_env_dict["INVITED_NODE_SUBNET"] + else: + #self.ocommon.log_info_message("The catalog Host name is :" + chost,self.file_name) + chost_ip=self.ocommon.get_ip(chost,None) + ip_parts=chost_ip.split('.') + invited_subnet=ip_parts[0] + "." + ip_parts[1] + '.*' + '.*' + add_invited_subnet='''add invitedsubnet {0};'''.format(invited_subnet) + + cpasswd="HIDDEN_STRING" + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})))\" {7} -user {3}/{4} -sdb {5} -region {6} -agent_port 8080 -agent_password {4} {8} {9} {10} {11} {12} {13} -autovncr off; + add invitednode {0}; + {14} + exit; + '''.format(chost,cport,cpdb,cadmin,cpasswd,catalog_name,catalog_region,chunks,repl,repfactor,repunits,shardingtype,shardspace,configname,add_invited_subnet) + + counter=1 + while counter < 5: + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + if retcode != 0: + self.ocommon.log_info_message("Error occurred while creating the shard catalog, sleeping for 60 seconds",self.file_name) + counter = counter + 1 + time.sleep(60) + else: + break + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ######################################## GSM director Functions Begins Here ##################### + def process_director_vars(self,key): + """ + This function process GSM director vars based on key and return values to configure the GSM + """ + dtrname=None + dtrport=None + dtregion=None + + self.ocommon.log_info_message("Inside process_director_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'director_name': + dtrname = cvar_dict[ckey] + if ckey == 'director_port': + dtrport = cvar_dict[ckey] + if ckey == 'director_region': + dtregion = cvar_dict[ckey] + + ### Check values must be set + if dtrname and dtrport and dtregion: + return dtrname,dtrport,dtregion + else: + msg1='''director_name={0},director_port={1}'''.format((dtrname or "Missing Value"),(dtrport or "Missing Value")) + msg2='''director_region={0}'''.format((dtregion or "Missing Value")) + msg='''Director params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_gsm_director(self,dname): + """ + This function check the GSM director status + """ + self.ocommon.log_info_message("Inside check_gsm_director()",self.file_name) + status=False + if dname: + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(matched_output[0],dname): + status=True + except: + status=False + else: + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(matched_output[0],dname): + status=True + except: + status=False + + return(self.ocommon.check_status_value(status)) + + def check_gsm_region(self,region): + """ + This function check the GSM regions + """ + self.ocommon.log_info_message("Inside check_gsm_region()",self.file_name) + gsmcmd=self.get_gsm_config_cmd(None) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Regions\n)(?:.+\n)+",output) + status=False + try: + if self.ocommon.check_substr_match(matched_output[0],region): + status=True + except: + status=False + return(self.ocommon.check_status_value(status)) + + def check_gsm_shardspace(self,sspace): + """ + This function check the GSM shardspace + """ + self.ocommon.log_info_message("Inside check_gsm_shardspace()",self.file_name) + gsmcmd=self.get_gsm_config_cmd(None) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard spaces\n)(?:.+\n)+",output) + status=False + try: + if self.ocommon.check_substr_match(matched_output[0],sspace): + status=True + except: + status=False + return(self.ocommon.check_status_value(status)) + + def check_gsm_director_status(self,dname): + """ + This function check the GSM director status using 'gdsctl status' + """ + self.ocommon.log_info_message("Inside check_gsm_director_status()",self.file_name) + status=False + gsmcmd=''' + status; + exit; + ''' + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + if "Connected to GDS catalog Y".replace(" ","").lower() in output.replace(" ","").lower(): + return True + else: + return False + + def add_gsm_director(self): + """ + This function add the GSM + """ + status=False + counter=1 + end_counter=60 + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + reg_exp= self.director_regex() + + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_director_status=None + dtrname,dtrport,dtregion=self.process_director_vars(key) + shard_director_status=self.check_gsm_director(dtrname) + if shard_director_status != 'completed': + self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) + status = self.check_gsm_director(None) + if status == 'completed': + break + + if status == 'completed': + break + else: + msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + status = self.check_gsm_director(None) + if status == 'completed': + msg='''Shard director setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 60 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def setup_gsm_director(self): + """ + This function setup in GSM + """ + self.ocommon.log_info_message("Inside setup_gsm_director()",self.file_name) + status=False + reg_exp= self.director_regex() + counter=1 + end_counter=3 + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_director_status=None + dtrname,dtrport,dtregion=self.process_director_vars(key) + shard_director_status=self.check_gsm_director(dtrname) + if shard_director_status != 'completed': + self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) + status = self.check_gsm_director(None) + if status == 'completed': + break + else: + msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + time.sleep(60) + counter=counter+1 + + status = self.check_gsm_director(None) + if status == 'completed': + msg='''Shard director setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 3 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin): + """ + This function configure GSM director + """ + ## Getting the values of catalog_port,catalog_pdb,catalog_host + cpasswd="HIDDEN_STRING" + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sregionFlag=self.check_gsm_region(dtregion) + if sregionFlag != 'completed': + self.configure_gsm_region(dtregion) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + add gsm -gsm {0} -listener {1} -pwd {2} -catalog {3}:{4}/{5} -region {6}; + exit; + '''.format(dtrname,dtrport,cpasswd,catalog_host,catalog_port,catalog_pdb,dtregion,gsmhost) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def start_gsm_director(self): + """ + This function start the director in the GSM + """ + status='noval' + self.ocommon.log_info_message("Inside start_gsm_director() function",self.file_name) + reg_exp= self.director_regex() + counter=1 + end_counter=10 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=''' + start gsm -gsm {0}; + exit; + '''.format(dtrname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + status=self.check_gsm_director(dtrname) + if status == 'completed': + break; + if status == 'completed': + filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + remfile='''rm -f {0}'''.format(filename) + if os.path.isfile(filename): + output,error,retcode=self.ocommon.execute_cmd(remfile,None,self.ora_env_dict) + break + else: + msg='''GSM shard director failed to start.Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_error_message(msg,self.file_name) + time.sleep(30) + + counter=counter+1 + + + if status != 'completed': + msg='''GSM shard director failed to start.Exiting!''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def stop_gsm_director(self): + """ + This function stop the director in the GSM + """ + status=False + self.ocommon.log_info_message("Inside stop_gsm_director() function",self.file_name) + reg_exp= self.director_regex() + counter=1 + end_counter=2 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=''' + stop gsm -gsm {0}; + exit; + '''.format(dtrname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + counter=counter+1 + + def status_gsm_director(self): + """ + This function check the GSM director status + """ + gsm_status = self.check_gsm_director(None) + #catalog_status = self.check_gsm_catalog() + + if gsm_status == 'completed': + msg='''Director setup completed in GSM and catalog is connected''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard director in GSM did not complete or not connected to catalog. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + ######################################## Shard Group Setup Begins Here ############################ + def setup_gsm_shardg(self,restype): + """ + This function setup the shard group. + """ + self.ocommon.log_info_message("Inside setup_gsm_shardg()",self.file_name) + status=False + if restype == 'ADD_SGROUP_PARAMS': + reg_exp = self.add_shardg_regex() + elif restype == 'SHARD_GROUP': + reg_exp = self.shardg_regex() + else: + self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SGROUP_PARAMS or SHARD_GROUP key to create a shard group",self.file_name) + self.ocommon.log_warn_message("Since no key specified for ADD_SGROUP_PARAMS and SHARD_GROUP, shardgroup will be created during shard creation",self.file_name) + + sgListC=[] + sgListP=[] + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_group_status=None + self.ocommon.log_info_message("Key is set to : " + key,self.file_name) + group_name,deploy_as,group_region=self.process_shardg_vars(key) + self.ocommon.log_info_message("Name: " + group_name + "deploy_as" + deploy_as + "group_region" + group_region,self.file_name) + if group_name is not None: + if group_name not in sgListC: + dtrname=self.get_director_name(group_region) + shard_group_status=self.check_shardg_status(group_name,dtrname) + if shard_group_status != 'completed': + self.configure_gsm_shardg(group_name,deploy_as,group_region,'add') + shard_group_status = self.check_shardg_status(group_name,None) + if shard_group_status == 'completed': + sgListC.append(group_name) + if group_name in sgListP: + sgListP.remove(group_name) + else: + sgListP=sgListP.append(group_name) + time.sleep(30) + counter=counter + 1 + + if sgListP == []: + msg='''Shard group setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def get_director_name(self,region_name): + """ + This function get the director name based on the region + """ + self.ocommon.log_info_message("Inside get_director_name()",self.file_name) + status=False + director_name=None + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + director_name=dtrname + gsm_status = self.check_gsm_director(dtrname) + if gsm_status == 'completed': + status = True + else: + status = False + if dtregion == region_name: + break + if status: + if director_name: + return director_name + else: + self.ocommon.log_error_message("No director exist to match the region",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.log_error_message("Shard Director is not running!",self.file_name) + self.ocommon.prog_exit("127") + + def get_shardg_region_name(self,sgname): + """ + This function get the region name based on shard group name + """ + self.ocommon.log_info_message("Inside get_region_name()",self.file_name) + status=False + region_name=None + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + group_name,deploy_as,group_region=self.process_shardg_vars(key) + region_name=group_region + if sgname == group_name: + status=True + break + if status: + return region_name + else: + self.ocommon.log_error_message("No such shard group exist! exiting!",self.file_name) + self.ocommon.prog_exit("127") + + def process_shardg_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + group_name=None + deploy_as=None + group_region=None + + self.ocommon.log_info_message("Inside process_shardg_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'group_name': + group_name = cvar_dict[ckey] + if ckey == 'deploy_as': + deploy_as = cvar_dict[ckey] + if ckey == 'group_region': + group_region = cvar_dict[ckey] + + ### Check values must be set + if group_name and deploy_as and group_region: + return group_name,deploy_as,group_region + else: + msg1='''group_name={0},deploy_as={1}'''.format((group_name or "Missing Value"),(deploy_as or "Missing Value")) + msg2='''group_region={0}'''.format((group_region or "Missing Value")) + msg='''Shard group params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + + def check_shardg_status(self,group_name,dname): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_shardg_status()",self.file_name) + status=False + + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) + if self.ocommon.check_substr_match(matched_output[0],group_name): + status=True + else: + status=False + + ''' + else: + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + group_name,deploy_as,group_region=self.process_shardg_vars(key) + dname=self.get_director_name(group_region) + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) + # match=re.search("(?i)(?m)"+group_name,matched_output) + if self.ocommon.check_substr_match(matched_output[0],group_name): + status=True + else: + status=False + ''' + + return(self.ocommon.check_status_value(status)) + +############################################# Director Related Block ############ + def get_director_name(self,region_name): + """ + This function get the director name based on the region + """ + self.ocommon.log_info_message("Inside get_director_name()",self.file_name) + status=False + director_name=None + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + director_name=dtrname + gsm_status = self.check_gsm_director(dtrname) + if gsm_status == 'completed': + status = True + else: + status = False + if dtregion == region_name: + break + if status: + if director_name: + return director_name + else: + self.ocommon.log_error_message("No director exist to match the region",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.log_error_message("Shard Director is not running!",self.file_name) + self.ocommon.prog_exit("127") + +######## + + def get_gsm_config_cmd(self,dname): + """ + Get the GSM config command + """ + self.ocommon.log_info_message("Inside get_gsm_config_cmd()",self.file_name) + gsmcmd=''' + config; + exit; + '''.format("test") + return gsmcmd + + def director_regex(self): + """ + This function return the rgex to search the SHARD DIRECTOR PARAMS + """ + self.ocommon.log_info_message("Inside director_regex()",self.file_name) + return re.compile('SHARD_DIRECTOR_PARAMS') + + def shardg_regex(self): + """ + This function return the rgex to search the SHARD GROUP PARAMS + """ + self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) + return re.compile('SHARD[0-9]+_GROUP_PARAMS') + + def add_shardg_regex(self): + """ + This function return the rgex to search the SHARD GROUP PARAMS + """ + self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) + return re.compile('ADD_SGROUP_PARAMS') + + def configure_gsm_shardg(self,group_name,deploy_as,group_region,type): + """ + This function configure the Shard Group. + """ + self.ocommon.log_info_message("Inside configure_gsm_shardg()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + dtrname=self.get_director_name(group_region) + reg_exp= self.catalog_regex() + if type == 'modify': + cmd=''' modify shardgroup -shardgroup {0} '''.format(group_name) + else: + cmd=''' add shardgroup -shardgroup {0} '''.format(group_name) + + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + if repl_type: + cmd=cmd + " -region {0} ".format(group_region) + else: + cmd=cmd + " -deploy_as {0} -region {1} ".format(deploy_as,group_region) + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + exit; + '''.format("NA",cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + +############# Adding Shard Regions ############### + def configure_gsm_region(self,region): + """ + This function configure the Shard region. + """ + self.ocommon.log_info_message("Inside configure_gsm_region()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + add region -region {3}; + exit; + '''.format("NA",cadmin,cpasswd,region) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + +##################### Adding Shard Space ############### + def process_sspace_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + sspace=None + chunks=None + repfactor=None + repunits=None + protectedmode=None + self.ocommon.log_info_message("Inside process_sspace_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'sspace_name': + sspace = cvar_dict[ckey] + if ckey == 'chunks': + chunks = cvar_dict[ckey] + if ckey == 'repfactor': + repfactor = cvar_dict[ckey] + if ckey == 'repunits': + repunits = cvar_dict[ckey] + if ckey == 'protectedmode': + protectedmode = cvar_dict[ckey] + + ### Check values must be set + if sspace: + return sspace,chunks,repfactor,repunits,protectedmode + else: + msg1='''sspace={0}'''.format((sspace or "Missing Value")) + msg='''Shard space params {0} is not set correctly. One or more value is missing {1}'''.format(key,msg1) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def setup_gsm_sspace(self,restype): + """ + This function setup the shard sspace. + """ + self.ocommon.log_info_message("Inside setup_gsm_sspace()",self.file_name) + status=False + if restype == 'ADD_SSPACE_PARAMS': + reg_exp = self.add_shardg_regex() + elif restype == 'SHARD_SPACE': + reg_exp = self.shardg_regex() + else: + self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SSPACE_PARAMS or SHARD_SPACE key to create a shard space",self.file_name) + self.ocommon.log_warn_message("Since no ADD_SSPACE_PARAMS or SHARD_SPACE defined, shardspace will be created during shard creation",self.file_name) + counter=1 + ssListC=[] + ssListP=[] + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_space_status=None + sspace,chunks,repfactor,repuntis,protectedmode=self.process_sspace_vars(key) + if sspace is not None: + if sspace not in ssListC: + shard_sspace_status=self.check_gsm_shardspace(sspace) + if shard_sspace_status != 'completed': + self.configure_gsm_sspace(sspace,chunks,repfactor,repuntis,protectedmode,'add') + shard_space_status = self.check_gsm_shardspace(sspace) + if shard_sspace_status == 'completed': + ssListC.append(sspace) + if sspace in sgListP: + sgListP.remove(sspace) + else: + sgListP=sgListP.append(sspace) + time.sleep(30) + counter=counter + 1 + + if ssListP == []: + msg='''Shard space setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete shard space setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def configure_gsm_sspace(self,sspace,chunks,repfactor,repunits,protectedmode,type): + """ + This function configure the Shard Group. + """ + self.ocommon.log_info_message("Inside configure_gsm_sspace()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + if type == 'MODIFY': + cmd=''' modify shardspace -shardspace {0} '''.format(sspace) + else: + cmd=''' add shardspace -shardspace {0} '''.format(sspace) + if chunks is not None: + cmd = cmd + ''' -chunks {0}'''.format(chunks) + if repfactor: + cmd = cmd + ''' -repfactor {0}'''.format(repfactor) + if repunits is not None: + cmd = cmd + ''' -repunits {0}'''.format(repfactor) + if protectedmode is not None: + cmd = cmd + ''' -protectedmode {0}'''.format(protectedmode) + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + exit; + '''.format("NA",cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + #########################################Shard Function Begins Here ############################## + def setup_gsm_shard(self): + """ + This function setup and add shard in the GSM + """ + self.ocommon.log_info_message("Inside setup_gsm_shard()",self.file_name) + status=False + reg_exp= self.shard_regex() + counter=1 + end_counter=60 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,sregion,sspace=self.process_shard_vars(key) + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + if shard_db_status == 'completed': + self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,sregion,sspace) + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + status = self.check_shard_status(None) + if status == 'completed': + break + else: + msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + status = self.check_shard_status(None) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 60 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def add_gsm_shard(self): + """ + This function add the shard in the GSM + """ + self.ocommon.log_info_message("Inside add_gsm_shard()",self.file_name) + status=False + reg_exp= self.add_shard_regex() + counter=1 + end_counter=3 + shard_name="none" + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + self.ocommon.log_info_message("Shard Status : " + shard_db_status,self.file_name) + if shard_db_status == 'completed': + self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,shard_region,shard_space) + counter2=1 + end_counter2=5 + while counter2 < end_counter2: + status1 = self.check_shard_status(shard_name) + if status1 == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + break + else: + msg='''Shard DB is still not added in GSM. Sleeping for 60 seconds''' + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter2=counter2+1 + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + status = self.check_shard_status(None) + if status == 'completed': + break + else: + msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + status = self.check_shard_status(shard_name) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 3 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def remove_gsm_shard(self): + """ + This function remove the shard in the GSM + """ + self.ocommon.log_info_message("Inside remove_gsm_shard()",self.file_name) + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars("CATALOG_PARAMS") + numOfShards=self.count_online_shards() + status=False + reg_exp=self.remove_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shardname_to_delete=shard_db + "_" + shard_pdb + if repl_type is not None: + if(repl_type.upper() == 'NATIVE'): + self.move_shards_leader_rus(shardname_to_delete) + leaderCount=self.count_leader_shards(shardname_to_delete) + if(numOfShards < 4 or leaderCount > 0): + msg='''ruType=[{0}]. NumofShards=[{1}]. LeaderCount=[{2}]. Ignoring remove of shard [{3}]'''.format(repl_type,numOfShards,leaderCount,shardname_to_delete) + self.ocommon.log_info_message(msg,self.file_name) + break + + self.move_shard_rus(shardname_to_delete,None,None) + while self.count_shard_rus(shardname_to_delete) > 0: + self.ocommon.log_info_message("Waiting for all the shard chunks to be moved.",self.file_name) + time.sleep(15) + + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + if shard_db_status == 'completed': + self.delete_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group) + status=True + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + return status + + def move_shards_leader_rus(self,shardname_to_delete): + """ + This function move the shard leader RUs + """ + shards=self.get_online_shards() + leader_ru=self.get_rus(shardname_to_delete) + all_ru=self.get_rus(None) + count=0 + target_shards=[] + value=0 + + if len(shards) == 0: + msg="""No Shard is online so no RU is available to be moved""" + self.ocommon.log_info_message(msg,self.file_name) + else: + for line in leader_ru: + value=None + count += 1 + cols=line.split() + if len(cols) > 0: + if cols[0].lower() == shardname_to_delete.lower(): + if cols[1].isdigit: + value = int(cols[1]) + else: + continue + + target_shards.clear() + for line1 in all_ru: + cols1=line1.split() + print(cols1) + if len(cols1) > 5: + if cols1[0].lower() != shardname_to_delete.lower() and cols1[1].isdigit and cols1[2].lower() == 'follower': + if value is not None: + if int(cols1[1]) == value: + target_shards.append(cols1[0]) + break + + for shard in shards: + if shard.lower() != shardname_to_delete.lower(): + if shard in target_shards: + msg="Shard_name= " + shard + " Status=True" + " Value = " + str(value) + self.ocommon.log_info_message(msg,self.file_name) + self.move_shard_rus(shardname_to_delete,shard,value) + + def move_shard_chunks(self): + """ + This function move the shard chunks + """ + self.ocommon.log_info_message("Inside move_shard_chunks()",self.file_name) + status=False + reg_exp= self.move_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + shard_num = self.count_online_shards() + online_shard = self.check_online_shard(shard_name) + if shard_num > 1 and online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + MOVE CHUNK -CHUNK ALL -SOURCE {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def validate_nochunks(self): + """ + This function check the chnunks + """ + self.ocommon.log_info_message("Inside validate_nochunks()",self.file_name) + status=False + reg_exp= self.move_nochunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + shard_num = self.count_online_shards() + online_shard = self.check_online_shard(shard_name) + if shard_num > 1 and online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config chunks -shard {0} + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + matched_output=re.findall("(?:Chunks\n)(?:.+\n)+",output) + if self.ocommon.check_substr_match(matched_output[0].lower(),shard_name.lower()): + self.ocommon.prog_exit("127") + + def move_chunks_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside move_chnuks_regex()",self.file_name) + return re.compile('MOVE_CHUNKS') + + def move_nochunks_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside move_nochunks_regex()",self.file_name) + return re.compile('VALIDATE_NOCHUNKS') + + def check_shard_chunks(self): + """ + This function check the shard chunks + """ + self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) + status=False + reg_exp= self.check_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config chunks -shard {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + + def check_chunks_regex(self): + """ + This function return the rgex to search the chunks + """ + self.ocommon.log_info_message("Inside check_chunks_regex()",self.file_name) + return re.compile('CHECK_CHUNKS') + + def cancel_move_chunks(self): + """ + This function cancel the shard Chunks + """ + self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) + status=False + reg_exp= self.cancel_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 1: + self.ocommon.log_info_message("Shard is not online. Performing chunk cancellation in GSM to set the shard chunk status.",self.file_name) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + ALTER MOVE -cancel -SHARD {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + else: + self.ocommon.log_info_message("Shard " + shard_name + " is online. Unable to perform chunk cancellation.",self.file_name) + + def cancel_chunks_regex(self): + """ + This function return the cancel chunk movement + """ + self.ocommon.log_info_message("Inside cancel_chunks_regex()",self.file_name) + return re.compile('CANCEL_CHUNKS') + + def verify_online_shard(self): + """ + This function verify online shard + """ + self.ocommon.log_info_message("Inside verify_online_shard()",self.file_name) + status=False + reg_exp= self.online_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 0: + msg='''Shard {0} is online.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} is not online.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + + def online_shard_regex(self): + """ + This function return the rgex to search the ONLINE Shards + """ + self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) + return re.compile('CHECK_ONLINE_SHARD') + + def check_online_shard(self,shard_name): + """ + This function check the online shard + """ + self.ocommon.log_info_message("Inside check_online_shard()",self.file_name) + name_flag = False + availability_flag = False + state_flag = False + status_flag = False + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config shard -shard {0}; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + lines = output.split("\n") + for line in lines: + list1 = line.split(":") + if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): + name_flag = True + if list1[0].strip().lower() == 'Availability'.lower() and list1[1].strip().lower() == 'ONLINE'.lower(): + availability_flag = True + if list1[0].strip().lower() == 'STATUS'.lower() and list1[1].strip().lower() == 'OK'.lower(): + status_flag = True + if list1[0].strip().lower() == 'STATE'.lower() and list1[1].strip().lower() == 'DEPLOYED'.lower(): + state_flag = True + + del list1[:] + + if name_flag and availability_flag and state_flag and status_flag: + return 0 + else: + return 1 + + def verify_gsm_shard(self): + """ + This function verify GSM shard + """ + self.ocommon.log_info_message("Inside verify_gsm_shard()",self.file_name) + status=False + reg_exp= self.check_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + gsm_shard = self.check_gsm_shard(shard_name) + if gsm_shard == 0: + msg='''Shard {0} is present in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} is not present in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + def check_shard_regex(self): + """ + This function return the rgex to search the Shards in GSM + """ + self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) + return re.compile('CHECK_GSM_SHARD') + + def check_gsm_shard(self,shard_name): + """ + This function check the shard in gsm + """ + self.ocommon.log_info_message("Inside check_gsm_shard()",self.file_name) + name_flag = False + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config shard -shard {0}; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + lines = output.split("\n") + for line in lines: + list1 = line.split(":") + if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): + name_flag = True + + del list1[:] + + if name_flag: + return 0 + else: + return 1 + + def count_online_shards(self): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside count_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + config shard; + exit; + '''.format(cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + online_shard = 0 + lines = output.split("\n") + for line in lines: + if re.search('ok', line, re.IGNORECASE): + if re.search('deployed', line, re.IGNORECASE): + if re.search('online', line, re.IGNORECASE): + online_shard = online_shard + 1 + + return online_shard + + def get_online_shards(self): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + config shard; + exit; + '''.format(cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + shards=[] + online_shard = 0 + for line in output.split("\n"): + cols=line.split() + print(cols) + if len(cols) >= 5: + if cols[5].lower() == "online" and cols[2].lower() == "ok": + shards.append(cols[0]) + + return shards + + def get_rus(self,shardname_to_delete): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd=None + if shardname_to_delete is not None: + cmd='''status ru -leaders -shard {0}'''.format(shardname_to_delete) + else: + cmd='''status ru''' + + gsmcmd=''' + connect {0}/{1}; + {2}; + exit; + '''.format(cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + return output.split('\n') + + def move_shard_rus(self,sshard,tshard,runum): + """ + This function move the shard rus + """ + self.ocommon.log_info_message("Inside move_shard_rus()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd1="" + cmd2="" + shardname=sshard + if tshard is not None and runum is not None: + cmd1='''switchover ru -RU {0} -shard {1}'''.format(runum,tshard) + else: + cmd1='''MOVE RU -RU ALL -SOURCE {0}'''.format(shardname) + + gsmcmd=''' + connect {1}/{2}; + configure -verbose off -save_config; + {3}; + status RU -shard {0}; + exit; + '''.format(shardname,cadmin,cpasswd,cmd1,cmd2) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def count_shard_rus(self,shardname): + """ + This function return the returns the count of online shard chunks + """ + self.ocommon.log_info_message("Inside count_shard_chunks()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + status ru -shard {2}; + exit; + '''.format(cadmin,cpasswd,shardname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ru_count = 0 + lines = output.split("\n") + for line in lines: + if re.search(shardname, line, re.IGNORECASE): + ru_count = ru_count + 1 + + return ru_count + + def count_leader_shards(self,shardName): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside count_leader_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + status ru -shard {2} -leaders; + exit; + '''.format(cadmin,cpasswd,shardName) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + leader_shard = 0 + lines = output.split("\n") + for line in lines: + if re.search('ok', line, re.IGNORECASE): + if re.search('Leader', line, re.IGNORECASE): + leader_shard = leader_shard + 1 + + return leader_shard + + def validate_gsm_shard(self): + """ + This function validate the shard in the GSM + """ + self.ocommon.log_info_message("Inside validate_gsm_shard()",self.file_name) + status=False + reg_exp= self.validate_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + status = self.check_shard_status(shard_name) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} info does not exist in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + def process_shard_vars(self,key): + """ + This function process sgard vars based on key and return values to configure the GSM + """ + shard_db=None + shard_pdb=None + shard_port=None + shard_group=None + shard_host=None + shard_region=None + shard_space=None + shard_deploy_as=None + + self.ocommon.log_info_message("Inside process_shard_vars()",self.file_name) + # self.ocommon.log_info_message(key,self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_str=cvar_str.replace('"', '') + # self.ocommon.log_info_message(cvar_str,self.file_name) + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + # self.ocommon.log_info_message("key : " + ckey,self.file_name) + # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) + if ckey == 'shard_db': + shard_db = cvar_dict[ckey] + if ckey == 'shard_pdb': + shard_pdb = cvar_dict[ckey] + if ckey == 'shard_port': + shard_port = cvar_dict[ckey] + if ckey == 'shard_group': + shard_group = cvar_dict[ckey] + if ckey == 'shard_host': + shard_host = cvar_dict[ckey] + if ckey == 'shard_region': + #shard_region = self.validate_shard_param("region",cvar_dict[ckey]) + shard_region=cvar_dict[ckey] + if ckey == 'deploy_as': + shard_deploy_as=cvar_dict[ckey] + if ckey == 'shard_space': + #shard_space = self.validate_shard_param("shardspace",cvar_dict[ckey]) + shard_space=cvar_dict[ckey] + # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) + ## Set the values if not set in above block + if not shard_port: + shard_port=1521 + + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + shard_group="nogrp" + if not shard_deploy_as: + self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS","primary",self.ora_env_dict) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS",shard_deploy_as,self.ora_env_dict) + + ### Check values must be set + if shard_host and shard_db and shard_pdb and shard_port and shard_group: + return shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space + else: + msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) + msg2='''shard_port={0},shard_host={1}'''.format((shard_port or "Missing Value"),(shard_host or "Missing Value")) + msg3='''shard_group={0}'''.format((shard_group or "Missing Value")) + msg='''Shard DB params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def validate_shard_param(self,param_type,value): + """ + This function validaet the shard param such as region and shardspace + """ + status=False + reg_exp= self.catalog_regex() + stype=None + sspace=None + catalog_region=None + self.ocommon.log_info_message("Processing GSM params to verify the region and shardspace",self.file_name) + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + + if param_type == 'region': + if stype: + status=self.ocommon.find_str_in_string(catalog_region,'comma',value) + if status: + + return value + else: + return "" + + if param_type == 'shardspace': + if sspace: + status=self.ocommon.find_str_in_string(sspace,'comma',value) + if status: + return value + else: + return "" + + return False + + def process_chunks_vars(self,key): + """ + This function process the chunks vars + """ + shard_db=None + shard_pdb=None + self.ocommon.log_info_message("Inside process_chunks_vars()",self.file_name) + # self.ocommon.log_info_message(key,self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_str=cvar_str.replace('"', '') + # self.ocommon.log_info_message(cvar_str,self.file_name) + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + # self.ocommon.log_info_message("key : " + ckey,self.file_name) + # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) + if ckey == 'shard_db': + shard_db = cvar_dict[ckey] + if ckey == 'shard_pdb': + shard_pdb = cvar_dict[ckey] + # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) + ## Set the values if not set in above block + + ### Check values must be set + if shard_pdb and shard_db: + return shard_db,shard_pdb + else: + msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) + self.ocommon.log_info_message(msg1,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_shard_status(self,shard_name): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_shard_status()",self.file_name) + #gsmcmd=self.get_gsm_config_cmd(dname) + gsmcmd=''' + config; + exit; + ''' + counter=1 + end_counter=3 + status=False + while counter < end_counter: + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + error_check=re.findall("(?:GSM-45034\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(error_check[0],"GSM-45034"): + count = counter + 1 + self.ocommon.log_info_message("Issue in catalog connection, retrying to connect to catalog in 30 seconds!",self.file_name) + time.sleep(20) + status=False + continue + except: + status=False + matched_output=re.findall("(?:Databases\n)(?:.+\n)+",output) + if shard_name: + try: + if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): + status=True + break + else: + status=False + except: + status=False + else: + reg_exp= self.shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_region,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + try: + if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): + status=True + else: + status=False + except: + status=False + if status: + break; + counter = counter + 1 + + return(self.ocommon.check_status_value(status)) + + def shard_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside shard_regex()",self.file_name) + return re.compile('SHARD[0-9]+_PARAMS') + + def add_shard_regex(self): + """ + This function return the rgex to search the ADD_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside add_shard_regex()",self.file_name) + return re.compile('ADD_SHARD') + + def remove_shard_regex(self): + """ + This function return the rgex to search the REMOVE_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) + return re.compile('REMOVE_SHARD') + + def validate_shard_regex(self): + """ + This function return the rgex to search the VALIDATE_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) + return re.compile('VALIDATE_SHARD') + + def configure_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup,sregion,sspace): + """ + This function configure the shard db. + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + #dtrname,dtrport,dtregion=self.process_director_vars() + #group_region=self.get_shardg_region_name(sgroup) + #dtrname=self.get_director_name(group_region) + shard_name='''{0}_{1}'''.format(scdb,spdb) + shard_region=None + shard_space=None + shard_group=None + deploy_as=None + + if sregion: + regionFlag=self.check_gsm_region(sregion) + if regionFlag != 'completed': + self.configure_gsm_region(sregion) + shard_region=" -region {0}".format(sregion) + else: + shard_region="" + if sspace: + shard_space=" -shardspace {0}".format(sspace) + else: + shard_space="" + + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + sspaceFlag=self.check_gsm_shardspace(sspace) + if sspaceFlag != 'completed': + self.configure_gsm_sspace(sspace,None,None,None,None,'add') + shard_group="" + deploy_as,deploy_type=self.get_shard_deploy() + else: + shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) + shard_region="" + else: + shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) + shard_region="" + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + add cdb -connect {3}:{4}/{5} -pwd {2}; + add shard -cdb {5} -connect "(DESCRIPTION = (ADDRESS = (PROTOCOL = tcp)(HOST = {3})(PORT = {4})) (CONNECT_DATA = (SERVICE_NAME = {6}) (SERVER = DEDICATED)))" {7} -pwd {2} {9} {10} {11}; + config vncr; + exit; + '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,shard_group,shard_name,shard_region,shard_space,deploy_as) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def get_shard_deploy(self): + """ + get the shard deploy + """ + deploy_as=None + deploy_type=None + if self.ocommon.check_key("SHARD_DEPLOY_AS",self.ora_env_dict): + deploy_as="-deploy_as {0}".format(self.ora_env_dict["SHARD_DEPLOY_AS"]) + deploy_type=self.ora_env_dict["SHARD_DEPLOY_AS"] + else: + deploy_as="-deploy_as primary" + deploy_type='primary' + + return deploy_as,deploy_type + + def get_shardg_cmd(self,sgroup,sregion): + """ + Getting shard group cmd + """ + sgFlag=self.check_shardg_status(sgroup,None) + deploy_as,deploy_type=self.get_shard_deploy() + if sgFlag != 'completed': + self.configure_gsm_shardg(sgroup,deploy_type,sregion,'add') + else: + self.ocommon.log_info_message("Shardgroup exist " + sgroup, self.file_name) + + deploy_as="" + cmd=''' -shardgroup {0}'''.format(sgroup) + return cmd,deploy_as + + def delete_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup): + """ + This function delete the shard db. + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + shard_name='''{0}_{1}'''.format(scdb,spdb) + #group_region=self.get_shardg_region_name(sgroup) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + remove shard -shard {8}; + remove cdb -cdb {5}; + remove invitednode {3}; + config vncr; + exit; + '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,sgroup,shard_name) + + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_hostid_null(self): + """ + This function set the hostid to Null + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_pdb,admuser) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting host Id null in catalog as auto vncr is disabled''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set echo on + set termout on + set time on + update gsmadmin_internal.database set hostid=NULL; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + self.ocommon.unset_mask_str() + + def invited_node_op(self): + """ + This function perform the invitedaddition and deletion + """ + self.ocommon.log_info_message("Inside invited_node_op()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + shard_host=self.ora_env_dict["INVITED_NODE_OP"] + gsmcmd=''' + connect {1}/{2}; + remove invitednode {3}; + add invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,shard_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + def add_invited_node(self,op_str): + """ + This function add the invited in the GSM configuration + """ + self.ocommon.log_info_message("Inside add_invited_node()",self.file_name) + if op_str == "SHARD": + reg_exp = self.shard_regex() + else: + reg_exp = self.add_shard_regex() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + #group_region=self.get_shardg_region_name(shard_group) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + add invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,shard_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + def remove_invited_node(self,op_str): + """ + This function remove the invited in the GSM configuration + """ + self.ocommon.log_info_message("Inside remove_invited_node()",self.file_name) + if op_str == "SHARD": + reg_exp = self.shard_regex() + else: + reg_exp = self.add_shard_regex() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + temp_host= shard_host.split('.',1)[0] + #group_region=self.get_shardg_region_name(shard_group) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + remove invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,temp_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + else: + self.ocommon.log_info_message("KUBE_SVC is not set. No need to remove invited node!",self.file_name) + + + def deploy_shard(self): + """ + This function deploy shard + """ + self.ocommon.log_info_message("Inside deploy_shard()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + shrdg_sspace=None + #dtrname,dtrport,dtregion=self.process_director_vars() + #if op_str == "SHARD": + # reg_exp = self.shard_regex() + #else: + # reg_exp = self.add_shard_regex() + + #for key in self.ora_env_dict.keys(): + # if(reg_exp.match(key)): + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + shardg_shardspace="config shardspace" + else: + shardg_shardspace="config shardgroup" + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + config vncr; + deploy; + config shard; + exit; + '''.format("test",cadmin,cpasswd,shardg_shardspace) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def check_setup_status(self,host,ccdb,svc,port): + """ + This function check the shard status. + """ + systemStr='''{0}/bin/sqlplus "system/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,ccdb) + + fname='''/tmp/{0}'''.format("shard_setup.txt") + self.ocommon.remove_file(fname) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool {0} + select * from shardsetup WHERE ROWNUM = 1; + spool off + exit; + '''.format(fname) + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + if os.path.isfile(fname): + fdata=self.ocommon.read_file(fname) + else: + fdata='nosetup' + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + status = self.catalog_pdb_setup_check(host,ccdb,svc,port) + if status == 'completed': + return 'completed' + else: + return 'notcompleted' + else: + return 'notcompleted' + + + def catalog_pdb_setup_check(self,host,ccdb,svc,port): + """ + This function check the shard status. + """ + systemStr='''{0}/bin/sqlplus "pdbadmin/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,svc) + + fname='''/tmp/{0}'''.format("pdb_setup_check.txt") + self.ocommon.remove_file(fname) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Checking setup status in PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool {0} + select count(*) from dual; + spool off + exit; + '''.format(fname) + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + if os.path.isfile(fname): + fdata=self.ocommon.read_file(fname) + else: + fdata='nosetup' + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + if re.search('1',fdata): + return 'completed' + else: + return 'notcompleted' + + ############################# Setup GSM Service ############################################### + def setup_gsm_service(self): + """ + This function setup the shard service. + """ + self.ocommon.log_info_message("Inside setup_gsm_service()",self.file_name) + status=False + service_value="service_name=oltp_rw_svc;service_role=primary" + # self.ora_env_dict=self.ocommon.add_key("SERVICE1_PARAMS",service_value,self.ora_env_dict) + reg_exp= self.service_regex() + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_service_status=None + service_name,service_role=self.process_service_vars(key) + shard_service_status=self.check_service_status(service_name) + if shard_service_status != 'completed': + self.configure_gsm_service(service_name,service_role) + status = self.check_service_status(None) + if status == 'completed': + break + else: + msg='''GSM service setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + time.sleep(60) + counter=counter+1 + + status = self.check_service_status(None) + if status == 'completed': + msg='''Shard service setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def process_service_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + service_name=None + service_role=None + + self.ocommon.log_info_message("Inside process_service_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'service_name': + service_name = cvar_dict[ckey] + if ckey == 'service_role': + service_role = cvar_dict[ckey] + + ### Check values must be set + if service_name and service_role: + return service_name,service_role + else: + msg1='''service_name={0},service_role={1}'''.format((service_name or "Missing Value"),(service_role or "Missing Value")) + msg='''Shard service params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_service_status(self,service_name): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_service_status()",self.file_name) + #dtrname,dtrport,dtregion=self.process_director_vars() + gsmcmd=''' + config; + exit; + '''.format("test") + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Services\n)(?:.+\n)+",output) + status=False + if service_name: + try: + if self.ocommon.check_substr_match(matched_output[0],service_name): + status=True + else: + status=False + except: + status=False + else: + reg_exp= self.service_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + service_name,service_role=self.process_service_vars(key) + # match=re.search("(?i)(?m)"+service_name,matched_output) + try: + if self.ocommon.check_substr_match(matched_output[0],service_name): + status=True + else: + status=False + except: + status=False + + return(self.ocommon.check_status_value(status)) + + def service_regex(self): + """ + This function return the rgex to search the SERVICE[0-9]_PARAMS + """ + self.ocommon.log_info_message("Inside service_regex()",self.file_name) + return re.compile('SERVICE[0-9]+_PARAMS') + + def configure_gsm_service(self,service_name,service_role): + """ + This function configure the service creation. + """ + self.ocommon.log_info_message("Inside configure_gsm_service()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + add service -service {3} -role {4}; + start service -service {3}; + exit; + '''.format("test",cadmin,cpasswd,service_name,service_role) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ############################## GSM backup fIle function Begins Here ############################# + def gsm_backup_file(self): + """ + This function check the gsm setup status + """ + self.ocommon.log_info_message("Inside gsm_backup_file()",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) + + if os.path.isdir(gsmdata_loc): + msg='''Directory {0} exit'''.format(gsmdata_loc) + self.ocommon.log_info_message(msg,self.file_name) + + cmd='''cp -r -v {0}/* {1}/'''.format(gsmfile_loc,gsmdata_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############### Deploy Sample Function Begins Here ########################## + def setup_sample_schema(self): + """ + This function deploy the sample app + """ + s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?" + passlen = 8 + passwd = "".join(random.sample(s,passlen )) + self.ocommon.log_info_message("Inside deploy_sample_schema()",self.file_name) + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_db) + if self.ocommon.check_key("SAMPLE_SCHEMA",self.ora_env_dict): + if self.ora_env_dict["SAMPLE_SCHEMA"] == 'DEPLOY': + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Deploying sample schema''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set echo on + set termout on + set time on + spool /tmp/create_app_schema.lst + REM + REM Connect to the Shard Catalog and Create Schema + REM + alter session enable shard ddl; + alter session set container={2}; + alter session enable shard ddl; + create user app_schema identified by {3}; + grant connect, resource, alter session to app_schema; + grant execute on dbms_crypto to app_schema; + grant create table, create procedure, create tablespace, create materialized view to app_schema; + grant unlimited tablespace to app_schema; + grant select_catalog_role to app_schema; + grant all privileges to app_schema; + grant gsmadmin_role to app_schema; + grant dba to app_schema; + CREATE TABLESPACE SET tbsset1 IN SHARDSPACE shd1; + CREATE TABLESPACE SET tbsset2 IN SHARDSPACE shd2; + connect app_schema/{3}@{0}:{1}/{2} + alter session enable shard ddl; + + /* Customer shard table */ + + CREATE SHARDED TABLE customer + ( cust_id NUMBER NOT NULL, + cust_passwd VARCHAR2(20) NOT NULL, + cust_name VARCHAR2(60) NOT NULL, + cust_type VARCHAR2(10) NOT NULL, + cust_email VARCHAR2(100) NOT NULL) + partitionset by list (cust_type) + partition by consistent hash (cust_id) partitions auto + (partitionset individual values ('individual') tablespace set tbsset1, + partitionset business values ('business') tablespace set tbsset2 + ); + /* Invoice shard table */ + + CREATE SHARDED TABLE invoice + ( invoice_id NUMBER NOT NULL, + cust_id NUMBER NOT NULL, + cust_type VARCHAR2(10) NOT NULL, + vendor_name VARCHAR2(60) NOT NULL, + balance FLOAT(10) NOT NULL, + total FLOAT(10) NOT NULL, + status VARCHAR2(20), + CONSTRAINT InvoicePK PRIMARY KEY (cust_id, invoice_id)) + PARENT customer + partitionset by list (cust_type) + partition by consistent hash (cust_id) partitions auto + (partitionset individual values ('individual') tablespace set tbsset1, + partitionset business values ('business') tablespace set tbsset2 + ); + /* Data */ + insert into customer values (999, 'pass', 'Customer 999', 'individual', 'customer999@gmail.com'); + insert into customer values (250251, 'pass', 'Customer 250251', 'individual', 'customer250251@yahoo.com'); + insert into customer values (350351, 'pass', 'Customer 350351', 'individual', 'customer350351@gmail.com'); + insert into customer values (550551, 'pass', 'Customer 550551', 'business', 'customer550551@hotmail.com'); + insert into customer values (650651, 'pass', 'Customer 650651', 'business', 'customer650651@live.com'); + insert into invoice values (1001, 999, 'individual', 'VendorA', 10000, 20000, 'Due'); + insert into invoice values (1002, 999, 'individual', 'VendorB', 10000, 20000, 'Due'); + insert into invoice values (1001, 250251, 'individual', 'VendorA', 10000, 20000, 'Due'); + insert into invoice values (1002, 250251, 'individual', 'VendorB', 0, 10000, 'Paid'); + insert into invoice values (1003, 250251, 'individual', 'VendorC', 14000, 15000, 'Due'); + insert into invoice values (1001, 350351, 'individual', 'VendorD', 10000, 20000, 'Due'); + insert into invoice values (1002, 350351, 'individual', 'VendorE', 0, 10000, 'Paid'); + insert into invoice values (1003, 350351, 'individual', 'VendorF', 14000, 15000, 'Due'); + insert into invoice values (1004, 350351, 'individual', 'VendorG', 12000, 15000, 'Due'); + insert into invoice values (1001, 550551, 'business', 'VendorH', 10000, 20000, 'Due'); + insert into invoice values (1002, 550551, 'business', 'VendorI', 0, 10000, 'Paid'); + insert into invoice values (1003, 550551, 'business', 'VendorJ', 14000, 15000, 'Due'); + insert into invoice values (1004, 550551, 'business', 'VendorK', 10000, 20000, 'Due'); + insert into invoice values (1005, 550551, 'business', 'VendorL', 10000, 20000, 'Due'); + insert into invoice values (1006, 550551, 'business', 'VendorM', 0, 10000, 'Paid'); + insert into invoice values (1007, 550551, 'business', 'VendorN', 14000, 15000, 'Due'); + insert into invoice values (1008, 550551, 'business', 'VendorO', 10000, 20000, 'Due'); + insert into invoice values (1001, 650651, 'business', 'VendorT', 10000, 20000, 'Due'); + insert into invoice values (1002, 650651, 'business', 'VendorU', 0, 10000, 'Paid'); + insert into invoice values (1003, 650651, 'business', 'VendorV', 14000, 15000, 'Due'); + insert into invoice values (1004, 650651, 'business', 'VendorW', 10000, 20000, 'Due'); + insert into invoice values (1005, 650651, 'business', 'VendorX', 0, 20000, 'Paid'); + insert into invoice values (1006, 650651, 'business', 'VendorY', 0, 30000, 'Paid'); + insert into invoice values (1007, 650651, 'business', 'VendorZ', 0, 10000, 'Paid'); + commit; + select table_name from user_tables; + spool off + '''.format(catalog_host,catalog_port,catalog_pdb,passwd) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + show ddl; + exit; + '''.format("test",cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oralogger.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oralogger.py new file mode 100755 index 0000000..9a51b54 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oralogger.py @@ -0,0 +1,181 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file provides the functionality to log the event in console and file +""" + +import logging +import os + +class LoggingType(object): + CONSOLE = 1 + FILE = 2 + STDOUT = 3 + +class OraLogger(object): + """ + This is a class constructor which sets parameter for logger. + + Attributes: + filename_ (string): Filename which we need to set to store logs in a file. + """ + def __init__(self, filename_): + """ + This is a class constructor which sets parameter for logger. + + Attributes: + filename_ (string): Filename which we need to set to store logs in a file. + """ + self.filename_ = filename_ + # Set to default values can be changed later from other classes objects + self.console_ = LoggingType.CONSOLE + self.file_ = LoggingType.FILE + self.stdout_ = LoggingType.STDOUT + self.msg_ = None + self.functname_ = None + self.lineno_ = None + self.logtype_ = "INFO" + self.fmtstr_ = "%(asctime)s: %(levelname)s: %(message)s" + self.datestr_ = "%m/%d/%Y %I:%M:%S %p" + self.root = logging.getLogger() + self.root.setLevel(logging.DEBUG) + self.formatter = logging.Formatter('%(asctime)s %(levelname)8s:%(message)s', "%m/%d/%Y %I:%M:%S %p") + self.stdoutfile_ = "/proc/1/fd/1" + # self.stdoutfile_ = "/tmp/test.log" + + def getStdOutValue(self): + return self.stdout_ + +class Handler(object): + """ + This is a class which sets the handler for next logger. + """ + def __init__(self): + """ + This is a handler class constructor and nexthandler is set to None. + """ + self.nextHandler = None + + def handle(self, request): + ''' + This is a function which set the next handler. + + Attributes: + request (object): Object of the class oralogger. + ''' + self.nextHandler.handle(request) + + def print_message(self,request,lhandler): + """ + This function set the log type to INFO, WARN, DEBUG and CRITICAL. + + Attribute: + request (object): Object of the class oralogger. + lhandler: This parameter accept the loghandler. + """ + if request.logtype_ == "WARN": + request.root.warning(request.msg_) + elif request.logtype_ == "DEBUG": + request.root.debug(request.msg_) + elif request.logtype_ == "CRITICAL": + request.root.critical(request.msg_) + elif request.logtype_ == "ERROR": + request.root.error(request.msg_) + else: + request.root.info(request.msg_) + + request.root.removeHandler(lhandler) + +class FHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribut: + request: Object of OraLogger + """ + if request.file_ == LoggingType.FILE: + fh = logging.FileHandler(request.filename_) + request.root.addHandler(fh) + fh.setFormatter(request.formatter) + self.print_message(request,fh) + super(FHandler, self).handle(request) + else: + super(FHandler, self).handle(request) + + def print_message(self,request,fh): + """ + This function log the message to console/file/stdout. + """ + super(FHandler, self).print_message(request,fh) + +class CHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribute: + request: Object of OraLogger + """ + if request.console_ == LoggingType.CONSOLE: + # ch = logging.StreamHandler() + ch = logging.FileHandler("/tmp/test.log") + request.root.addHandler(ch) + ch.setFormatter(request.formatter) + self.print_message(request,ch) + super(CHandler, self).handle(request) + else: + super(CHandler, self).handle(request) + + def print_message(self,request,ch): + """ + This function log the message to console/file/stdout. + """ + super(CHandler, self).print_message(request,ch) + + +class StdHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribute: + request: Object of OraLogger + """ + request.stdout_ = request.getStdOutValue() + if request.stdout_ == LoggingType.STDOUT: + st = logging.FileHandler(request.stdoutfile_,mode="w") + request.root.addHandler(st) + st.setFormatter(request.formatter) + self.print_message(request,st) + super(StdHandler, self).handle(request) + else: + super(StdHandler, self).handle(request) + + def print_message(self,request,st): + """ + This function log the message to console/file/stdout. + """ + super(StdHandler, self).print_message(request,st) + +class PassHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self, request): + pass diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oramachine.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oramachine.py new file mode 100755 index 0000000..2d1431a --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oramachine.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +import os +import sys + +class OraMachine: + """ + This calss setup the compute before starting the installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraMachine class to setup the compute + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + + def setup(self): + """ + This function setup the compute before starting the installation + """ + msg="Machine setup completed sucessfully!" + self.ocommon.log_info_message(msg,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapcatalog.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapcatalog.py new file mode 100755 index 0000000..112f309 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapcatalog.py @@ -0,0 +1,790 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +class OraPCatalog: + """ + This calss setup the Catalog after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraCatalog class to setup the catalog on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def setup(self): + """ + This function setup the catalog on Primary DB. + """ + if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): + self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) + if self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) + self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) + if os.path.exists(create_db_file_lck): + self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) + sys.exit(127) + elif os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) + status = self.catalog_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) + sys.exit(0) + else: + status = self.catalog_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): + status = self.catalog_setup_check() + if not status: + self.ocommon.log_info_message("Catalog readyness check completed sucessfully!",self.file_name) + self.ocommon.prog_exit("127") + elif self.ocommon.check_key("RESET_PASSWORD",self.ora_env_dict): + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + if os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Catalog database up and running. Resetting password...",self.file_name) + else: + self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to reset password",self.file_name) + self.ocommon.prog_exit("127") + elif self.ocommon.check_key("EXPORT_TDE_KEY",self.ora_env_dict): + exist_db_file_lck=self.ocommon.get_db_lock_location()+ self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + if os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Catalog database up and running.",self.file_name) + self.ocommon.export_tde_key(self.ora_env_dict["EXPORT_TDE_KEY"]) + else: + self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to export the tde key",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_machine() + self.db_checks() + self.reset_catalog_setup() + status = self.catalog_setup_check() + if status: + self.ocommon.log_info_message("catalog Setup is already completed on this database",self.file_name) + else: + self.reset_passwd() + self.setup_cdb_catalog() + self.set_spfile_nonm_params() + self.ocommon.set_events("spfile") + self.set_dbparams_version() + self.restart_db() + self.restart_for_db_unique_name() + self.create_pdb() + self.alter_db() + self.setup_pdb_catalog() + self.set_primary_listener() + self.restart_listener() + self.register_services() + self.list_services() + self.backup_files() + self.update_catalog_setup() + self.gsm_completion_message() + self.run_custom_scripts() + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + + ########### SETUP_MACHINE ENDS here #################### + + ########### DB_CHECKS Related Functions Begin Here #################### + ## Function to perfom DB checks ###### + def db_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.set_user() + self.sid_check() + self.dbunique_name_check() + self.hostname_check() + self.dbport_check() + self.dbr_dest_checks() + self.dpump_dir_checks() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit() + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def passwd_check(self): + """ + Function to set the password + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def set_user(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def sid_check(self): + """ + This funnction heck and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): + msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="ORACLE_SID is not set, existing!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def dbunique_name_check(self): + """ + This funnction check and set the db unique name for standby + """ + if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + + msg='''Setting the Flag to restart the DB to set DB_UNIQUE_NAME to {0}! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + restart_db_to_set_db_unique_name='true' + self.ora_env_dict=self.ocommon.add_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",restart_db_to_set_db_unique_name,self.ora_env_dict) + else: + msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" + self.ocommon.log_info_message(msg,self.file_name) + dbsid=self.ora_env_dict["ORACLE_SID"] + self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) + + + def hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + # hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def dbport_check(self): + """ + This funnction checks and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("DB_PORT",self.ora_env_dict): + msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) + msg="DB_PORT is not set, setting default to 1521" + self.ocommon.log_info_message(msg,self.file_name) + + def dbr_dest_checks(self): + """ + This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. + """ + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) + + # Checking the DB_RECOVERY_FILE_DEST_SIZE + + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the DB_CREATE_FILE_DEST + + if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): + msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) + + + def dpump_dir_checks(self): + """ + This funnction checks and set the DATA_PUMP dir and location. + """ + if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): + msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) + self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) + msg='''DATA_PUMP_DIR set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) + + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## RESET_PASSWORD function Begin here ############################# + ## Function to perform password reset + def reset_passwd(self): + """ + This function reset the password. + """ + self.ocommon.reset_passwd() + + ########## RESET_PASSWORD function ENDS here ############################# + + ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### + + def reset_catalog_setup(self): + """ + This function drop teh catalog setup table and reste the env to default values. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Inside reset_catalog_setup",self.file_name) + catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + if not os.path.isfile(catalog_reset_file): + msg='''Dropping catalogsetup table from CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + drop table system.shardsetup; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + else: + msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(catalog_reset_file) + self.ocommon.log_info_message(msg,self.file_name) + + + def catalog_setup_check(self): + """ + This function check the catalog status. + """ + #systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool /tmp/catalog_setup.txt + select * from system.shardsetup WHERE ROWNUM = 1; + spool off + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + fname='''/tmp/{0}'''.format("catalog_setup.txt") + fdata=self.ocommon.read_file(fname) + ### Unsetting the encrypt value to None + # self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + return True + else: + return False + + def setup_cdb_catalog(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + # Assigning variable + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] + dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] + host_name=self.ora_env_dict["ORACLE_HOSTNAME"] + dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] + db_port=self.ora_env_dict["DB_PORT"] + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting up catalog CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set db_create_file_dest=\"{0}\" scope=both; + alter system set db_recovery_file_dest_size={1} scope=both; + alter system set db_recovery_file_dest=\"{2}\" scope=both; + alter user gsmcatuser account unlock; + alter user gsmcatuser identified by HIDDEN_STRING; + alter system set local_listener='{4}:{5}' scope=both; + alter system set db_unique_name='{8}' scope=spfile; + '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_spfile_nonm_params(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set open_links_per_instance=16 scope=spfile; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set standby_file_management='AUTO' scope=spfile; + alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; + alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + + def set_dbparams_version(self): + """ + This function setup the shard parameter based on db version. + """ + ohome1=self.ora_env_dict["ORACLE_HOME"] + version=self.ocommon.get_oraversion(ohome1).strip() + self.ocommon.log_info_message(version,self.file_name) + if int(version) > 21: + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set wallet_root=\"{1}/oradata/{2}/{3}\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_db(self): + """ + restarting the db + """ + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + #self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) + #sqlcmd=''' + # alter database archivelog; + # alter database open; + #''' + #output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + #self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + #self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_for_db_unique_name(self): + """ + restarting the db, when db_unique_name is passed explicitly + """ + if self.ocommon.check_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",self.ora_env_dict): + if self.ora_env_dict["RESTART_DB_TO_SET_DB_UNIQUE_NAME"] == 'true': + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Restarting the Database to set the DB_UNIQUE_NAME! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + + def create_pdb(self): + """ + This function creates the PDB + """ + inst_sid=self.ora_env_dict["ORACLE_SID"] + ohome=self.ora_env_dict["ORACLE_HOME"] + if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): + self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) + opdb=self.ora_env_dict["ORACLE_PDB"] + status=self.ocommon.check_pdb(opdb) + if not status: + self.ocommon.create_pdb(ohome,opdb,inst_sid) + self.ocommon.create_pdb_tns_entry(ohome,opdb) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + def setup_pdb_catalog(self): + """ + This function setup the catalog. + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + # Assigning variable + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter pluggable database {0} close immediate; + alter pluggable database {0} open services=All; + ALTER PLUGGABLE DATABASE {0} SAVE STATE; + alter system register; + alter session set container={0}; + create user {1} identified by HIDDEN_STRING; + alter user {1} account unlock; + grant connect, create session, gsmadmin_role to {1}; + grant inherit privileges on user SYS to GSMADMIN_INTERNAL; + execute dbms_xdb.sethttpport(8080); + exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('HIDDEN_STRING'); + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def update_catalog_setup(self): + """ + This function update the catalog setup on this DB. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") + # systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Updating shardsetup table''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + create table system.shardsetup (status varchar2(10)); + insert into system.shardsetup values('completed'); + commit; + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Reset File + catalog_reset_dir='''{0}/.catalog'''.format(self.ora_env_dict["HOME"]) + catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) + + self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) + if not os.path.isdir(catalog_reset_dir): + self.ocommon.create_dir(catalog_reset_dir,True,None,None) + + if not os.path.isfile(catalog_reset_file): + self.ocommon.create_file(catalog_reset_file,True,None,None) + +# self.ocommon.unset_mask_str() + + ########## SETUP_CDB_catalog FUNCTION ENDS HERE ############################### + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + def set_primary_listener(self): + """ + Function to set the primary listener + """ + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + + def set_db_listener(self,gdbname,sid): + """ + Funtion to reset the listener + """ + self.ocommon.log_info_message("Inside reset_listener()",self.file_name) + start = 'SID_LIST_LISTENER' + end = '^\)$' + oracle_home=self.ora_env_dict["ORACLE_HOME"] + lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) + buffer = "SID_LIST_LISTENER=" + '\n' + start_flag = False + try: + with open(lisora) as f: + for line1 in f: + if start_flag == False: + if (re.match(start, line1.strip())): + start_flag = True + elif (re.match(end, line1.strip())): + line2 = f.next() + if (re.match(end, line2.strip())): + break + else: + buffer += line1 + buffer += line2 + else: + if start_flag == True: + buffer += line1 + except: + pass + + if start_flag == True: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + else: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + + wr = open(lisora, 'w') + wr.write(listener) + + def restart_listener(self): + """ + restart listener + """ + self.ocommon.log_info_message("Stopping Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl stop'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + self.ocommon.log_info_message("Starting Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl start'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + + def register_services(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system register; + alter session set container={0}; + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def list_services(self): + """ + restart listener + """ + self.ocommon.log_info_message("Listing Services",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl services'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + + def backup_files(self): + """ + This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig + """ + self.ocommon.log_info_message("Inside backup_files()",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + dbsid=self.ora_env_dict["ORACLE_SID"] + + version=self.ocommon.get_oraversion(ohome).strip() + wallet_backup_cmd='''ls -ltr /bin''' + self.ocommon.log_info_message("Check Version " + version,self.file_name) + if int(version) >= 21: + obase1=self.ora_env_dict["ORACLE_BASE"] + wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) + cmd_names=''' + mkdir -p {0}/oradata/{1}/{2} + cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ + cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ + cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ + touch {0}/oradata/{1}/{2}/status_completed + '''.format(obase,"dbconfig",dbuname,ohome) + cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] + for cmd in cmd_list: + msg='''Executing cmd {0}'''.format(cmd) + self.ocommon.log_info_message(msg,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Catalog Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapshard.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapshard.py new file mode 100755 index 0000000..e4be415 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapshard.py @@ -0,0 +1,838 @@ +#!/usr/bin/python + +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +import traceback + +class OraPShard: + """ + This calss setup the primary shard after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraPShard class to setup the shard on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + try: + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + except BaseException as ex: + ex_type, ex_value, ex_traceback = sys.exc_info() + trace_back = traceback.extract_tb(ex_traceback) + stack_trace = list() + for trace in trace_back: + stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) + self.ocommon.log_info_message(ex_type.__name__,self.file_name) + self.ocommon.log_info_message(ex_value,self.file_name) + self.ocommon.log_info_message(stack_trace,self.file_name) + def setup(self): + """ + This function setup the shard on Primary DB. + """ + if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): + self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) + if self.ocommon.check_key("RESET_LISTENER",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) + self.ocommon.prog_exit("127") + self.reset_listener() + self.restart_listener() + if self.ocommon.check_key("RESTART_DB",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.start_db(self.ora_env_dict) + elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) + self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) + if os.path.exists(create_db_file_lck): + self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) + sys.exit(127) + elif os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) + status = self.shard_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) + sys.exit(0) + else: + status = self.shard_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Shard readyness check completed sucessfully!",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_machine() + self.db_checks() + self.reset_shard_setup() + status = self.shard_setup_check() + if status: + self.ocommon.log_info_message("Shard Setup is already completed on this database",self.file_name) + else: + self.reset_passwd() + self.setup_cdb_shard() + self.set_spfile_nonm_params() + self.ocommon.set_events("spfile") + self.set_dbparams_version() + self.restart_db() + self.restart_for_db_unique_name() + self.create_pdb() + self.alter_db() + self.setup_pdb_shard () + self.update_shard_setup() + self.set_primary_listener() + self.restart_listener() + self.register_services() + self.list_services() + self.backup_files() + self.gsm_completion_message() + self.run_custom_scripts() + + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + ########### SETUP_MACHINE ENDS here #################### + + ########### DB_CHECKS Related Functions Begin Here #################### + ## Function to perfom DB checks ###### + def db_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.set_user() + self.sid_check() + self.dbunique_name_check() + self.hostname_check() + self.dbport_check() + self.dbr_dest_checks() + self.dpump_dir_checks() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit() + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def passwd_check(self): + """ + This funnction perform password related checks + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def set_user(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def sid_check(self): + """ + This funnction heck and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): + msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="ORACLE_SID is not set, existing!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def dbunique_name_check(self): + """ + This funnction check and set the db unique name for standby + """ + if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + + msg='''Setting the Flag to restart the DB to set DB_UNIQUE_NAME to {0}! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + restart_db_to_set_db_unique_name='true' + self.ora_env_dict=self.ocommon.add_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",restart_db_to_set_db_unique_name,self.ora_env_dict) + else: + msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" + self.ocommon.log_info_message(msg,self.file_name) + dbsid=self.ora_env_dict["ORACLE_SID"] + self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) + + def hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def dbport_check(self): + """ + This funnction checks and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("DB_PORT",self.ora_env_dict): + msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) + msg="DB_PORT is not set, setting default to 1521" + self.ocommon.log_info_message(msg,self.file_name) + + def dbr_dest_checks(self): + """ + This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. + """ + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) + + # Checking the DB_RECOVERY_FILE_DEST_SIZE + + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the DB_CREATE_FILE_DEST + + if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): + msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) + + + def dpump_dir_checks(self): + """ + This funnction checks and set the DATA_PUMP dir and location. + """ + if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): + msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) + self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) + msg='''DATA_PUMP_DIR set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) + + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## RESET_PASSWORD function Begin here ############################# + ## Function to perform password reset + def reset_passwd(self): + """ + This function reset the password. + """ + self.ocommon.reset_passwd() + + ########## RESET_PASSWORD function ENDS here ############################# + + ########## SETUP_CDB_SHARD FUNCTION BEGIN HERE ############################### + + def reset_shard_setup(self): + """ + This function drop teh shard setup table and reste the env to default values. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Inside reset_shard_setup",self.file_name) + shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + if not os.path.isfile(shard_reset_file): + msg='''Dropping shardsetup table from CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + drop table system.shardsetup; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + else: + msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(shard_reset_file) + self.ocommon.log_info_message(msg,self.file_name) + + + def shard_setup_check(self): + """ + This function check the shard status. + """ +# systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + # self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool /tmp/shard_setup.txt + select * from system.shardsetup WHERE ROWNUM = 1; + spool off + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + fname='''/tmp/{0}'''.format("shard_setup.txt") + fdata=self.ocommon.read_file(fname) + ### Unsetting the encrypt value to None + # self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + return True + else: + return False + + def setup_cdb_shard(self): + """ + This function setup the shard. + """ + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] + dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] + host_name=self.ora_env_dict["ORACLE_HOSTNAME"] + dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] + db_port=self.ora_env_dict["DB_PORT"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting up Shard CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set db_create_file_dest=\"{0}\" scope=both; + alter system set db_recovery_file_dest_size={1} scope=both; + alter system set db_recovery_file_dest=\"{2}\" scope=both; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set standby_file_management='AUTO' scope=spfile; + alter user gsmrootuser account unlock; + grant sysdg to gsmrootuser; + grant sysbackup to gsmrootuser; + alter user gsmrootuser identified by HIDDEN_STRING container=all; + alter user GSMUSER account unlock; + alter user GSMUSER identified by HIDDEN_STRING container=all; + grant sysdg to GSMUSER; + grant sysbackup to GSMUSER; + create or replace directory DATA_PUMP_DIR as '{3}'; + grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; + alter system set local_listener='{4}:{5}' scope=spfile; + alter system set db_unique_name='{8}' scope=spfile; + '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_spfile_nonm_params(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set open_links_per_instance=16 scope=spfile; + alter system set open_links=16 scope=spfile; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; + alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def set_dbparams_version(self): + """ + This function setup the catalog parameter based on db version. + """ + ohome1=self.ora_env_dict["ORACLE_HOME"] + version=self.ocommon.get_oraversion(ohome1).strip() + self.ocommon.log_info_message(version,self.file_name) + if int(version) > 21: + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + + msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set wallet_root=\"{1}/oradata/{2}/{3}/\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_db(self): + + """ + restarting the db + """ + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + # self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) + # sqlcmd=''' + # alter database archivelog; + # alter database open; + # ''' + # output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + # self.ocommon.check_sql_err(output,error,retcode,True) + + + def restart_for_db_unique_name(self): + """ + restarting the db, when db_unique_name is passed explicitly + """ + if self.ocommon.check_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",self.ora_env_dict): + if self.ora_env_dict["RESTART_DB_TO_SET_DB_UNIQUE_NAME"] == 'true': + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Restarting the Database to set the DB_UNIQUE_NAME! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + + def create_pdb(self): + """ + This function creates the PDB + """ + inst_sid=self.ora_env_dict["ORACLE_SID"] + ohome=self.ora_env_dict["ORACLE_HOME"] + if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): + self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) + opdb=self.ora_env_dict["ORACLE_PDB"] + status=self.ocommon.check_pdb(opdb) + if not status: + self.ocommon.create_pdb(ohome,opdb,inst_sid) + self.ocommon.create_pdb_tns_entry(ohome,opdb) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + + def setup_pdb_shard(self): + """ + This function setup the shard. + """ + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up Shard PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter pluggable database {0} close immediate; + alter pluggable database {0} open services=All; + ALTER PLUGGABLE DATABASE {0} SAVE STATE; + alter system register; + alter session set container={0}; + grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; + grant sysdg to GSMUSER; + grant sysbackup to GSMUSER; + execute DBMS_GSM_FIX.validateShard; + alter system register; + '''.format(self.ora_env_dict["ORACLE_PDB"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + def update_shard_setup(self): + """ + This function update the shard setup on this DB. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") + systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + +# self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + + msg='''Updating shardsetup table''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + create table system.shardsetup (status varchar2(10)); + insert into system.shardsetup values('completed'); + commit; + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Reset File + shard_reset_dir='''{0}/.shard'''.format(self.ora_env_dict["HOME"]) + shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) + + self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) + if not os.path.isdir(shard_reset_dir): + self.ocommon.create_dir(shard_reset_dir,True,None,None) + + if not os.path.isfile(shard_reset_file): + self.ocommon.create_file(shard_reset_file,True,None,None) + +# self.ocommon.unset_mask_str() + + ########## SETUP_CDB_SHARD FUNCTION ENDS HERE ############################### + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Shard Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) + ################################ Reset and standby functions ################################################# + + def set_primary_listener(self): + """ + Function to set the primary listener + """ + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + + def set_db_listener(self,gdbname,sid): + """ + Funtion to reset the listener + """ + self.ocommon.log_info_message("Inside reset_listener()",self.file_name) + start = 'SID_LIST_LISTENER' + end = '^\)$' + oracle_home=self.ora_env_dict["ORACLE_HOME"] + lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) + buffer = "SID_LIST_LISTENER=" + '\n' + start_flag = False + try: + with open(lisora) as f: + for line1 in f: + if start_flag == False: + if (re.match(start, line1.strip())): + start_flag = True + elif (re.match(end, line1.strip())): + line2 = f.next() + if (re.match(end, line2.strip())): + break + else: + buffer += line1 + buffer += line2 + else: + if start_flag == True: + buffer += line1 + except: + pass + + if start_flag == True: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + else: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + + wr = open(lisora, 'w') + wr.write(listener) + + def restart_listener(self): + """ + restart listener + """ + self.ocommon.log_info_message("Stopping Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl stop'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + self.ocommon.log_info_message("Starting Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl start'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + def register_services(self): + """ + This function setup the catalog. + """ + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system register; + alter session set container={0}; + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def list_services(self): + """ + restart listener + """ + self.ocommon.log_info_message("Listing Services",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl services'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + def backup_files(self): + """ + This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig + """ + self.ocommon.log_info_message("Inside backup_files()",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + dbsid=self.ora_env_dict["ORACLE_SID"] + + version=self.ocommon.get_oraversion(ohome).strip() + wallet_backup_cmd='''ls -ltr /bin''' + self.ocommon.log_info_message("Check Version " + version,self.file_name) + if int(version) >= 21: + obase1=self.ora_env_dict["ORACLE_BASE"] + wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) + cmd_names=''' + mkdir -p {0}/oradata/{1}/{2} + cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ + cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ + cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ + {4} + touch {0}/oradata/{1}/{2}/status_completed + '''.format(obase,"dbconfig",dbuname,ohome,wallet_backup_cmd) + cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] + for cmd in cmd_list: + msg='''Executing cmd {0}'''.format(cmd) + self.ocommon.log_info_message(msg,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orascatalog.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orascatalog.py new file mode 100755 index 0000000..aa4ea65 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orascatalog.py @@ -0,0 +1,9 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orasshard.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orasshard.py new file mode 100755 index 0000000..58f168b --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orasshard.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +import traceback + +class OraSShard: + """ + This calss setup the standby shard after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraSShard class to setup the shard on standby DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + try: + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + except BaseException as ex: + ex_type, ex_value, ex_traceback = sys.exc_info() + trace_back = traceback.extract_tb(ex_traceback) + stack_trace = list() + for trace in trace_back: + stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) + ocommon.log_info_message(ex_type.__name__,self.file_name) + ocommon.log_info_message(ex_value,self.file_name) + ocommon.log_info_message(stack_trace,self.file_name) + def setup(self): + """ + This function setup the shard on standby DB. + """ + pass diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOraShardSetup.sh b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOraShardSetup.sh new file mode 100644 index 0000000..c1b09b4 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOraShardSetup.sh @@ -0,0 +1,568 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +export CLONED_FILE="status_completed" +export STANDBY_STATUS="status_completed" + +########### Clone Files ##################### +function cloneDB { + +export NEW_ORACLE_SID=$ORACLE_SID +export ORACLE_SID=$OLD_ORACLE_SID +sqlplus / as sysdba << EOF + STARTUP mount; + exit; +EOF + +echo 'Y' | nid target=/ dbname="$NEW_ORACLE_SID" + +if [ $? -eq 0 ]; then + echo "DB name changed sucessfully" +else + echo "DB name change process failed" + exit 1; +fi + +if [ -z ${DB_RECOVERY_FILE_DEST} ]; then + export DB_RECOVERY_FILE_DEST=$ORACLE_BASE/oradata/fast_recovery_area/$NEW_ORACLE_SID +fi + +if [ -z ${DB_UNIQUE_NAME} ]; then + export DB_UNIQUE_NAME=$NEW_ORACLE_SID +fi + +export ORACLE_HOSTNAME=$( hostname -f ) + +echo "Changing DB name" +export ORACLE_SID=$NEW_ORACLE_SID +sqlplus / as sysdba << EOF + STARTUP nomount; + alter system set db_name=$ORACLE_SID scope=spfile; + alter system set open_links=16 scope=spfile; + alter system set open_links_per_instance=16 scope=spfile; + alter system set dg_broker_config_file1="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr2$DB_UNIQUE_NAME.dat" scope=spfile; + alter system set dg_broker_config_file2="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr1$DB_UNIQUE_NAME.dat" scope=spfile; + alter system set db_file_name_convert='*','$ORACLE_BASE/oradata/$DB_UNIQUE_NAME/' scope=spfile; + alter system set local_listener='$ORACLE_HOSTNAME' scope=spfile; + alter system set standby_file_management='auto' scope=spfile; + shutdown immediate + exit; +EOF + +## Get the version + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 21 ]; then + echo "Setting DB Parameter based on the vserion" + export ORACLE_SID=$NEW_ORACLE_SID + sqlplus / as sysdba << EOF + startup nomount + alter system set wallet_root="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME" scope=spfile; + shutdown immediate + exit; +EOF + fi + fi + +echo "Changing OLD SID string to new string" +sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_HOME/network/admin/tnsnames.ora +sed -i "s/$OLD_ORACLE_PDB/$ORACLE_PDB/g" $ORACLE_HOME/network/admin/tnsnames.ora + +echo "Starting Listener" + +$ORACLE_HOME/bin/lsnrctl start + +echo "Starting new cloned DB" + +sqlplus / as sysdba << EOF + STARTUP mount; + alter database archivelog; + alter database open resetlogs; + exit; +EOF + +echo "Renaming PDB" + +sqlplus / as sysdba << EOF + alter pluggable database $OLD_ORACLE_PDB open restricted; + alter session set container=$OLD_ORACLE_PDB; + alter pluggable database rename global_name to $ORACLE_PDB; + exit; +EOF + +echo " Closing and Opening PDB" + +sqlplus / as sysdba << EOF + alter pluggable database $ORACLE_PDB close immediate; + alter pluggable database $ORACLE_PDB open; + alter system register; + exit; +EOF + + +echo "Touching $CLONED_FILE as setup is completed" +touch $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE + +} + +############################################ +########### Symbolic link DB files ######### +############################################ +########### DB Version >= 23c ############## +############################################ +function symLinkFiles23c { + + if [ -z ${ORACLE_BASE_HOME} ]; then + # + export ORACLE_BASE_HOME=$ORACLE_HOME + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora + fi; + if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/listener.ora + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora + fi + if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then + unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + ## Link based on ORACLE_BASE +# ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/spfile$ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi + fi + fi; + + if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID + fi; + + if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID + fi; + + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then + ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB + fi; + # oracle user does not have permissions in /etc, hence cp and not ln + sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab + cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab + fi +fi + +} + + +############################################ +########### Symbolic link DB files ######### +############################################ +########### DB Version < 23c ############### +############################################ +function symLinkFiles { + + if [ -z ${ORACLE_BASE_HOME} ]; then + # + export ORACLE_BASE_HOME=$ORACLE_HOME + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora + fi; + if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/listener.ora + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora + fi + if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then + unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$OLD_ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi + fi + fi; + + if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID + fi; + + if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID + fi; + + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then + ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB + fi; + # oracle user does not have permissions in /etc, hence cp and not ln + sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab + cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab + fi +fi + +} + +################################### +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +# Check whether container has enough memory +# Github issue #219: Prevent integer overflow, +# only check if memory digits are less than 11 (single GB range and below) +if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes | wc -c` -lt 11 ]; then + if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` -lt 2147483648 ]; then + echo "Error: The container doesn't have enough memory allocated." + echo "A database container needs at least 2 GB of memory." + echo "You currently only have $((`cat /sys/fs/cgroup/memory/memory.limit_in_bytes`/1024/1024/1024)) GB allocated to the container." + exit 1; + fi; +fi; + + +# Check that hostname doesn't container any "_" +# Github issue #711 +if hostname | grep -q "_"; then + echo "Error: The hostname must not container any '_'". + echo "Your current hostname is '$(hostname)'" +fi; + +# Default for ORACLE SID +if [ "$OLD_ORACLE_SID" == "" ]; then + export OLD_ORACLE_SID=SEEDCDB +fi + +if [ ! -z ${ORACLE_SID} ]; then + # Make ORACLE_SID upper case + # Github issue # 984 + export ORACLE_SID=${ORACLE_SID^^} + + # Check whether SID is no longer than 12 bytes + # Github issue #246: Cannot start OracleDB image + if [ "${#ORACLE_SID}" -gt 12 ]; then + echo "Error: The ORACLE_SID must only be up to 12 characters long." + exit 1; + fi; + + # Check whether SID is alphanumeric + # Github issue #246: Cannot start OracleDB image + if [[ "$ORACLE_SID" =~ [^a-zA-Z0-9] ]]; then + echo "Error: The ORACLE_SID must be alphanumeric." + exit 1; + fi; +else + echo "Error: The ORACLE_SID must be defined." + exit 1; +fi; + + +if [ ! -z ${ORACLE_PDB} ]; then + export ORACLE_PDB=${ORACLE_PDB^^} + + if [ "${#ORACLE_PDB}" -gt 12 ]; then + echo "Error: The ORACLE_PDB must only be up to 12 characters long." + exit 1; + fi; +else + echo "Error: The ORACLE_PDB must be defined." + exit 1; +fi; + +if [ ! -z ${OLD_ORACLE_PDB} ]; then + export OLD_ORACLE_PDB=${OLD_ORACLE_PDB^^} +else + export OLD_ORACLE_PDB=SEEDPDB +fi; + + +# Default for ORACLE CHARACTERSET +export ORACLE_CHARACTERSET=${ORACLE_CHARACTERSET:-AL32UTF8} + +# Check whether database already exists +if [ ! -z ${CLONE_DB} ]; then +if [ ${CLONE_DB^^} == "TRUE" ]; then +echo "CLONE_DB is set to true, cloning DB from seed" +if [ -d $ORACLE_BASE/oradata/$OLD_ORACLE_SID ]; then + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 23 ]; then + symLinkFiles23c; + else + symLinkFiles; + fi; + else + echo "Unable to determine the Database Version, exiting.." + exit 1; + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE ]; + then + # Start database + echo "Starting Database as cloned status file exist" + $ORACLE_BASE/$START_FILE; + else + echo "Performing Cloning as cloned status file does not exist" + cloneDB; + $ORACLE_BASE/checkDBStatus.sh + if [ $? -eq 0 ]; then + echo "DB is in READ WRITE State" + touch "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" + $ORACLE_BASE/$LOCKING_SCRIPT --acquire --file "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" + else + echo "DB is not in READ WRITE state" + exit 1; + fi + fi +else + echo "Error: The $ORACLE_BASE/oradata/$OLD_ORACLE_SID (ORACLE_BASE/oradata/OLD_ORACLE_SID) dir does not exist. Error exiting ." + exit 1; +fi +fi +fi + +if [ ${OP_TYPE,,} == "standbyshard" ]; then + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 23 ]; then + symLinkFiles23c; + else + symLinkFiles; + fi; + else + echo "Unable to determine the Database Version, exiting.." + exit 1; + fi + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/$STANDBY_STATUS ]; + then + # Start database + echo "Starting Database as standby setup status file exist" + $ORACLE_BASE/$START_FILE; + fi +fi + +#This is the main file which calls other file to setup the sharding. +if [ -z ${BASE_DIR} ]; then + BASE_DIR=/opt/oracle/scripts/sharding +fi + +if [ -z ${MAIN_SCRIPT} ]; then + SCRIPT_NAME="main.py" +fi + +if [ -z ${EXECUTOR} ]; then + EXECUTOR="python" +fi + +cd $BASE_DIR +$EXECUTOR $SCRIPT_NAME diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOracle.sh b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOracle.sh new file mode 100755 index 0000000..2266e99 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOracle.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +########### SIGINT handler ############ +function _int() { + echo "Stopping container." + echo "SIGINT received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown immediate; + exit; +EOF + lsnrctl stop +} + +########### SIGTERM handler ############ +function _term() { + echo "Stopping container." + echo "SIGTERM received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown immediate; + exit; +EOF + lsnrctl stop +} + +########### SIGKILL handler ############ +function _kill() { + echo "SIGKILL received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown abort; + exit; +EOF + lsnrctl stop +} + + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +if [ ! -z ${SHARD_SETUP} ]; then + if [ ${SHARD_SETUP,,} == "true" ]; then + sh $ORACLE_BASE/scripts/sharding/runOraShardSetup.sh + fi +fi + +if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & + fi +fi + +if [ ! -z ${OP_TYPE} ]; then + if [ ${OP_TYPE,,} == "standbyshard" ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & + fi +fi + +# Set SIGINT handler +trap _int SIGINT + +# Set SIGTERM handler +trap _term SIGTERM + +# Set SIGKILL handler +trap _kill SIGKILL + + +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/setupGSM.sh b/container-based-sharding-deployment/containerfiles/23.4.0/setupGSM.sh new file mode 100644 index 0000000..4a6a6ca --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/setupGSM.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +# Create Directories +mkdir -p $GSM_BASE +mkdir -p $GSM_HOME +mkdir -p $INVENTORY + +chown -R oracle:oinstall $INVENTORY +chown -R oracle:oinstall $GSM_BASE +chown -R oracle:oinstall $GSM_HOME +chown -R oracle:oinstall $INSTALL_SCRIPTS +chmod 775 $INSTALL_SCRIPTS + +chmod 666 /etc/sudoers +echo "oracle ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +chmod 440 /etc/sudoers + +echo "export ORACLE_HOME=$GSM_HOME" >> /home/oracle/.bashrc +echo "export PATH=$GSM_PATH" >> /home/oracle/.bashrc +echo "export LD_LIBRARY_PATH=$GSM_LD_LIBRARY_PATH" >> /home/oracle/.bashrc +echo "export SCRIPT_DIR=$SCRIPT_DIR" >> /home/oracle/.bashrc +echo "export GSM_HOME=$GSM_HOME" >> /home/oracle/.bashrc diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/setupLinuxEnv.sh b/container-based-sharding-deployment/containerfiles/23.4.0/setupLinuxEnv.sh new file mode 100644 index 0000000..c652b9b --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/setupLinuxEnv.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +if grep -q "Oracle Linux Server release 9" /etc/oracle-release; then \ + curl --noproxy '*' https://ca-artifacts.oraclecorp.com/auto-build/x86_64-build-output-9-dev/oracle-database-preinstall-23ai-1.0-1.4.el9.x86_64.rpm --output oracle-database-preinstall-23ai-1.0-1.4.el9.x86_64.rpm && \ + dnf install -y oracle-database-preinstall-23ai-1.0-1.4.el9.x86_64.rpm && \ + rm -f /etc/systemd/system/oracle-database-preinstall-23ai-firstboot.service && \ + dnf clean all; \ +else \ + dnf -y install oraclelinux-developer-release-el8 && \ + dnf -y install oracle-database-preinstall-23c && \ + rm -f /etc/rc.d/init.d/oracle-database-preinstall-23c-firstboot && \ + dnf clean all; \ +fi && \ +dnf -y install net-tools zip unzip tar openssl openssh-server vim-minimal which passwd sudo python3 hostname fontconfig lsof && \ +dnf clean all && \ +chmod ug+x $SCRIPT_DIR/*.sh && \ +rm -f /etc/sysctl.conf && \ +rm -f /usr/lib/systemd/system/dnf-makecache.service \ No newline at end of file diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/setupOshardEnv.sh b/container-based-sharding-deployment/containerfiles/23.4.0/setupOshardEnv.sh new file mode 100755 index 0000000..5ae2692 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.4.0/setupOshardEnv.sh @@ -0,0 +1,970 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +export NOW=$(date +"%Y%m%d%H%M") +export LOGDIR="/tmp" +export LOGFILE="${LOGDIR}/oshard_${NOW}.log" +export STD_OUT_FILE="/proc/1/fd/1" +export STD_ERR_FILE="/proc/1/fd/2" +declare -x SECRET_VOLUME='/run/secrets/' ## Secret Volume +declare -x PWD_KEY='pwd.key' ## PWD Key File +declare -x COMMON_OS_PWD_FILE='common_os_pwdfile.enc' +declare -x DB_PWD_FILE +export PDB_SQL_SCRIPT="/tmp/pdb.sql" +export TOP_PID=$$ +rm -f /tmp/sqllog.output +rm -f $PDB_SQL_SCRIPT +rm -f $LOGFILE + +#################################### Print and Exit Functions Begin Here ####################### +error_exit() { +local NOW=$(date +"%m-%d-%Y %T %Z") + # Display error message and exit +# echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2 + echo "${NOW} : ${PROGNAME}: ${1:-"Unknown Error"}" | tee -a $LOGFILE > $STD_OUT_FILE + kill -s TERM $TOP_PID +} + +print_message () +{ + local NOW=$(date +"%m-%d-%Y %T %Z") + # Display message and return + echo "${NOW} : ${PROGNAME} : ${1:-"Unknown Message"}" | tee -a $LOGFILE > $STD_OUT_FILE + return $? +} +#################################### Print and Exit Functions End Here ####################### + + +####################################### Functions Related to checks #################### +dbChecks() +{ +if [ -z "$ORACLE_HOME" ] +then + error_exit "Set the ORACLE_HOME variable" +else + print_message "ORACLE_HOME set to $ORACLE_HOME" +fi + +# If ORACLE_HOME doesn't exist # +if [ ! -d "$ORACLE_HOME" ] +then + error_exit "The ORACLE_HOME $ORACLE_HOME does not exist" +else + print_message "ORACLE_HOME Directory Exist" +fi + +################## Checks for Password and Clustername and clustertype begins here ########### +if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then +cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' + +eval $cmd + +if [ $? -eq 0 ]; then +print_message "Password file generated" +else +error_exit "Error occurred during common os password file generation" +fi + +read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} +rm -f /tmp/${COMMON_OS_PWD_FILE} +else + print_message "Password is empty string" + export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 +fi + +if [ -z "${ORACLE_PWD}" ]; then + print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" + export ORACLE_PWD=${PASSWORD} +else + print_message "ORACLE_PWD is set to user specified password" +fi + +################################################################################################### + + +if [ -z "${SHARD_ADMIN_USER}" ] +then + print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + export SHARD_ADMIN_USER="mysdbadmin" +else + print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" +fi + + +if [ -z "${PDB_ADMIN_USER}" ] +then + print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" + export PDB_ADMIN_USER="pdbadmin" +else + print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" +fi + + +# Validate the value of ORACLE_SID # +if [ -z "${ORACLE_SID}" ] +then + error_exit "Set the ORACLE_SID variable" +else + print_message "ORACLE_SID is set to $ORACLE_SID" +fi + +if [ -z "${ORACLE_HOSTNAME}" ] +then + if [ -z "${KUBE_SVC}" ]; then + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname)" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + else + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + fi +else + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" +fi + + + +if [ -z "$DB_PORT" ] +then + print_message "Set the DB_PORT variable" + export DB_PORT=1521 +else + print_message "DB Port is set to $DB_PORT" +fi + +if [ -z "${DB_RECOVERY_FILE_DEST}" ]; then + print_message "Set the DB_RECOVERY_FILE_DEST is not set" + export DB_RECOVERY_FILE_DEST="${ORACLE_BASE}/oradata/fast_recovery_area/${ORACLE_SID}" +fi + +if [ -z "${DB_CREATE_FILE_DEST}" ]; then + print_message "Set the DB_CREATE_FILE_DEST is not set. Setting to ${ORACLE_BASE}/oradata/${ORACLE_SID}" + export DB_CREATE_FILE_DEST="${ORACLE_BASE}/oradata/${ORACLE_SID}" +fi + +if [ -z "${DATA_PUMP_DIR}" ]; then + print_message "DATA_PUMP_DIR is not set, it will se to ${ORACLE_BASE}/oradata/data_pump_dir" + export DATA_PUMP_DIR="${ORACLE_BASE}/oradata/data_pump_dir" +fi + +if [ ! -d "${DATA_PUMP_DIR}" ]; then + print_message "DATA_PUMP_DIR ${DATA_PUMP_DIR} directory does not exist" + mkdir -p "${DATA_PUMP_DIR}" +fi + +if [ ! -d "${DB_RECOVERY_FILE_DEST}" ]; then + print_message "DB_RECOVERY_FILE_DEST ${DB_RECOVERY_FILE_DEST} directory does not exist" + mkdir -p "${DB_RECOVERY_FILE_DEST}" +fi + +if [ -z "${DB_RECOVERY_FILE_DEST_SIZE}" ]; then + print_message "DB_RECOVERY_FILE_DEST_SIZE is not set" + export DB_RECOVERY_FILE_DEST_SIZE="40G" +else + print_message "DB_RECOVERY_FILE_DEST_SIZE is set to ${DB_RECOVERY_FILE_DEST_SIZE}" +fi + +} + +gsmChecks() +{ + print_message "Performing GSM related checks" + +if [ ! -z "${KUBE_SVC}" ]; then + lordinal=$( hostname | awk -F "-" '{ print $NF }' ) + print_message "lordinal is set to ${lordinal}" + region_num=$((lordinal+1)) + if [ -z "${REGION}" ]; then + print_message "REGION is not set. Setting to region$lordinal" + export REGION="region${region_num}" + fi +else + if [ -z "${REGION}" ]; then + error_exit "REGION Canot be set to empty" + fi +fi + +################## Checks for Password and Clustername and clustertype begins here ########### +if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then +cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' + +eval $cmd + +if [ $? -eq 0 ]; then +print_message "Password file generated" +else +error_exit "Error occurred during common os password file generation" +fi + +read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} +rm -f /tmp/${COMMON_OS_PWD_FILE} +else + print_message "Password is empty string" + export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 +fi + +if [ -z "${ORACLE_PWD}" ]; then + print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" + export ORACLE_PWD=${PASSWORD} +else + print_message "ORACLE_PWD is set to user specified password" +fi + +################################################################################################### + +if [ -z "$SHARD_ADMIN_USER" ] +then + print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + export SHARD_ADMIN_USER="mysdbadmin" +else + print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" +fi + + +if [ -z "$PDB_ADMIN_USER" ] +then + print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" + export PDB_ADMIN_USER="pdbadmin" +else + print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" +fi + + +if [ -z "${SHARD_GROUP_NAME}" ]; then + print_message "SHARD_GROUP_NAME is not set, it will be set to primary_shardgroup" + export SHARD_GROUP_NAME="primary_shardgroup" +fi + +if [ -z "${SHARD_DEPLOYMENT_TYPE}" ]; then + print_message "SHARD_DEPLOYMENT_TYPE is not set, it will set to primary" + export SHARD_DEPLOYMENT_TYPE="primary" +fi + +if [ -z "${SHARD_DIRECTOR_NAME}" ]; then + print_message "SHARD_DIRECTOR_NAME is not set, it will set to sharddirector${region_num}" + export SHARD_DIRECTOR_NAME="sharddirector${region_num}" +fi + +if [ -z "${ORACLE_HOSTNAME}" ] +then + if [ -z "${KUBE_SVC}" ]; then + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname)" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + else + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + fi +else + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" +fi + +} + +###################################### Function Related to Check end here ################### + +################################### Reset Password ########################################### +resetPassword() +{ +if [ -f "${HOME}/setPassword.sh" ]; then +if [ ! -z "${ORACLE_PWD}" ]; then +"${HOME}"/setPassword.sh "$ORACLE_PWD" +fi +fi +} + +############################################################################################### +setupCatalog() +{ + +localconnectStr="/ as sysdba" +systemStr="system/${ORACLE_PWD}" +sqlScript="/tmp/setapp.sql" +print_message "Setting up Paramteres in Spfile" + +cmd1="drop table shardsetup;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" +#cmd=$( eval echo "$cmd1" ) +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links_per_instance=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="@$ORACLE_HOME/rdbms/admin/setCatalogDBPrivs.sql;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" +print_message "cat /tmp/setup_grants_privs.lst" + +cmd1="alter user gsmcatuser account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmcatuser identified by $ORACLE_PWD;" +print_message "Sending query to sqlplus to execute alter user gsmcatuser identified by ORACLE_PWD;" +executeSQL "$cmd1" "$localconnectStr" + + +#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" +cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + + +cmd1="shutdown immediate;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="startup mount;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database archivelog;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database open;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database flashback on;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database force logging;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1", "$localconnectStr" + +cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +if [ ! -z "${ORACLE_PDB}" ]; then +setupCatalogPDB +fi + +cmd1="create table shardsetup (status varchar2(10));" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="insert into shardsetup values('completed');" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" +} + +configureSampleAppSchema() +{ +local sqlScript="/tmp/sqlScript.sql" +connectStr = "${SHARD_ADMIN_USER}/${ORACLE_PWD}" + +echo "alter session enable shard ddl;" > ${sqlScript} +echo "create user app_schema identified by '&1';" >> ${sqlScript} +echo "grant all privileges to app_schema;" >> ${sqlScript} +echo "grant gsmadmin_role to app_schema;" >> ${sqlScript} +echo "grant select_catalog_role to app_schema;" >> ${sqlScript} +echo "grant connect, resource to app_schema;" >> ${sqlScript} +echo "grant dba to app_schema;" >> ${sqlScript} +echo "grant execute on dbms_crypto to app_schema;" >> ${sqlScript} +echo "CREATE TABLESPACE SET TSP_SET_1 using template (datafile size 100m autoextend on next 10M maxsize unlimited extent management local segment space management auto);" >> ${sqlScript} +echo "CREATE TABLESPACE SET LOBTS1;" >> ${sqlScript} +echo "CREATE TABLESPACE products_tsp datafile size 100m autoextend on next 10M maxsize unlimited extent management local uniform size 1m; " >> ${sqlScript} +echo "CONNECT app_schema/'&1';" >> ${sqlScript} +echo "ALTER SESSION ENABLE SHARD DDL;" >> ${sqlScript} +echo "CREATE SHARDED TABLE Customers (CustId VARCHAR2(60) NOT NULL, FirstName VARCHAR2(60), LastName VARCHAR2(60), Class VARCHAR2(10), Geo VARCHAR2(8),CustProfile VARCHAR2(4000),Passwd RAW(60),CONSTRAINT pk_customers PRIMARY KEY (CustId),CONSTRAINT json_customers CHECK (CustProfile IS JSON)) TABLESPACE SET TSP_SET_1 PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO;" >> ${sqlScript} +echo "CREATE SHARDED TABLE Orders (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL, OrderDate TIMESTAMP NOT NULL,SumTotal NUMBER(19,4),Status CHAR(4), CONSTRAINT pk_orders PRIMARY KEY (CustId, OrderId),CONSTRAINT fk_orders_parent FOREIGN KEY (CustId) REFERENCES Customers ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_orders_parent);" >> ${sqlScript} +echo "CREATE SEQUENCE Orders_Seq;" >> ${sqlScript} +echo "CREATE SHARDED TABLE LineItems (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL,ProductId INTEGER NOT NULL,Price NUMBER(19,4),Qty NUMBER,CONSTRAINT pk_items PRIMARY KEY (CustId, OrderId, ProductId),CONSTRAINT fk_items_parent FOREIGN KEY (CustId, OrderId) REFERENCES Orders ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_items_parent);" >> ${sqlScript} +echo "CREATE DUPLICATED TABLE Products (ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,Name VARCHAR2(128),DescrUri VARCHAR2(128),LastPrice NUMBER(19,4)) TABLESPACE products_tsp;" >> ${sqlScript} + +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "$connectStr" "sqlScript" "${sqlScript}" + +} + + +setupCatalogPDB() +{ +#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" +pdbConnStr=" /as sysdba" + +local sqlScript="/tmp/sqlScript.sql" + +print_message "Settup Sql Script to setup Catalog PDB" +echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" +echo "create user ${SHARD_ADMIN_USER} identified by ${ORACLE_PWD};" >> "${sqlScript}" +echo "grant connect, create session, gsmadmin_role to ${SHARD_ADMIN_USER} ;" >> "${sqlScript}" +echo "grant inherit privileges on user SYS to GSMADMIN_INTERNAL;" >> "${sqlScript}" +echo "execute dbms_xdb.sethttpport(8080);" >> ${sqlScript} +echo "exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('${ORACLE_PWD}');" >> "${sqlScript}" + +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" +} + +######################################################################## Catalog Setup task ends here ################################# + +######################################################################## Primary Shard Setup task ends here ################################# + +setupShardPDB() +{ + +#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" +pdbConnStr=" /as sysdba" + +local sqlScript="/tmp/sqlScript.sql" +print_message "Settup Sql Script to setup Catalog PDB" +echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" +echo "grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" >> "${sqlScript}" +echo "grant sysdg to GSMUSER;" >> "${sqlScript}" +echo "grant sysbackup to GSMUSER;" >> "${sqlScript}" +echo "execute DBMS_GSM_FIX.validateShard;" >> ${sqlScript} +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" + +} + +setupShardCDB() +{ +localconnectStr="/as sysdba" +systemStr="system/${ORACLE_PWD}" +print_message "Setting up Paramteres in Spfile" + +cmd1="drop table shardsetup;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links_per_instance=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmrootuser account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmrootuser identified by ${ORACLE_PWD} container=all;" +print_message "Sending query to sqlplus to execute alter user gsmrootuser identified by ORACLE_PWD container=all;" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysdg to gsmrootuser;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysbackup to gsmrootuser;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user GSMUSER account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user GSMUSER identified by ${ORACLE_PWD} container=all;" +print_message "Sending query to sqlplus to execute alter user GSMUSER identified by ORACLE_PWD container=all;" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysdg to GSMUSER;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysbackup to GSMUSER;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set dg_broker_start=true scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="create or replace directory DATA_PUMP_DIR as '${DATA_PUMP_DIR}';" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" +cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="shutdown immediate;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="startup mount;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database archivelog;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database open;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database flashback on;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database force logging;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +if [ ! -z "${ORACLE_PDB}" ]; then + +setupShardPDB + +fi + +cmd1="create table shardsetup (status varchar2(10));" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + + +cmd1="insert into shardsetup values('completed');" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +} + +######################################################################## Primary Shard Setup ends here ################################# + +######################################################################## GSM Setup Task Begin here ##################################### +setupGSM() +{ +local cstatus='false' +local sstatus='false' + +setupGSMCatalog +startGSM +addShardGroup +setupGSMShard + +} + +startGSM() +{ + +cmd1="start gsm" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +deployShard() +{ + +cmd1="deploy" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +stopGSM() +{ + +cmd1="stop gsm" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +addInvitedNode() +{ + +chost=$1 + +cmd1="add invitednode $chost" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + + +addShardGroup() +{ + +cmd1="add shardgroup -shardgroup ${shardGName} -deploy_as ${deployment_type} -region ${region}" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +checkStatus() +{ +host=$1 +port=1521 +cpdb=$3 +ccdb=$2 +uname="system" +cpasswd=${ORACLE_PWD} + +print_message "Connect String $uname/$cpasswd@//$host:$port/$ccdb" +output=$( "$ORACLE_HOME"/bin/sqlplus -s "$uname/$cpasswd@//$host:$port/$ccdb" <<EOF + set heading off feedback off verify off echo off PAGESIZE 0 + select status from shardsetup; + exit +EOF +) + + if [ "${output}" == 'completed' ];then + print_message "Returned status from catalog is $output" + else + print_message "Sleeping for 300 seconds as returned status is not $output " + sleep 300 + fi + + echo $output +} + +setupGSMCatalog() +{ +IFS='; ' read -r -a sarray <<< "$CATALOG_PARAMS" +for element in "${sarray[@]}" +do + print_message "1st String in Shard params $element" + type=$( echo $element | awk -F: '{print $NF }') + host=$( echo $element | awk -F: '{print $1 }') + db=$( echo $element | awk -F: '{print $2 }') + pdb=$( echo $element | awk -F: '{print $3 }') +done + +print_message "Set variables to host=${host} db=${db} pdb=${pdb}" +if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] +then +runtime="60 minute" +endtime=$(date -ud "$runtime" +%s) + +while [[ $(date -u +%s) -le $endtime ]] +do + + coutput=$( checkStatus $host $db $pdb ) + if [ "${coutput}" == 'completed' ] ;then + configureGSMCatalog $host $db $pdb + break + else + print_message "Catalog Status must return completed but returned value is $coutput" + fi + print_message "Catalog DB is still not ready. Sleeping for 60 seconds" + sleep 60 +done +fi + +if [ "${coutput}" != 'completed' ] ;then + error_exit "Shard Catalog is not setup, Unable to proceed futher" +fi + +} + +configureGSMCatalog() +{ +chost=$1 +cport=1521 +cpdb=$3 +ccdb=$2 +gsmhost=${ORACLE_HOSTNAME} +cadmin=${SHARD_ADMIN_USER} +cpasswd=${ORACLE_PWD} +########################## +region="${REGION}" +shardGName="${SHARD_GROUP_NAME}" +deployment_type="${SHARD_DEPLOYMENT_TYPE}" +local gdsScript="/tmp/gdsScript.sql" + +gsm_name="${SHARD_DIRECTOR_NAME}" +echo "create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=${chost})(PORT=${cport}))(CONNECT_DATA=(SERVICE_NAME=${cpdb})))\" -user ${cadmin}/${cpasswd} -sdb shardcatalog -region region1,region2 -agent_port 8080 -agent_password ${cpasswd} -autovncr off" > "${gdsScript}" +echo "add invitednode ${chost}" >> "${gdsScript}" +echo "add gsm -gsm ${gsm_name} -listener 1521 -pwd ${cpasswd} -catalog ${chost}:${cport}/${cpdb} -region region1 -endpoint '(ADDRESS=(PROTOCOL=tcp)(HOST=${gsmhost})(PORT=1521))'" >> "${gdsScript}" +echo "exit" >> "${gdsScript}" +print_message "Sending script to gsm to execute ${gdsScript}" +cat ${gdsScript} >> $LOGFILE +cp "${gdsScript}" "${gdsScript}.test" +executeGSM "$cmd1" "gdsScript" "${gdsScript}" +} + +setupGSMShard() +{ +IFS='; ' read -r -a sarray <<< "$PRIMARY_SHARD_PARAMS" +arrLen=$( echo "${#sarray[@]}" ) +count1=0 + +runtime="45 minute" +endtime=$(date -ud "$runtime" +%s) + +print_message "Set variables to host=${host} db=${db} pdb=${pdb}" +while [[ $(date -u +%s) -le $endtime ]] +do + for i in ${!sarray[@]}; do + print_message "1st String in Shard params $element" + host=$( echo ${sarray[i]} | awk -F: '{print $1 }') + db=$( echo ${sarray[i]} | awk -F: '{print $2 }') + pdb=$( echo ${sarray[i]} | awk -F: '{print $3 }') + print_message "shard env set to host=${host} db=${db} pdb=${pdb}" + if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] + then + coutput=$( checkStatus $host $db $pdb ) + if [ "${coutput}" == 'completed' ] ;then + configureGSMShard $host $db $pdb + unset sarray[i] + ((++count1)) + else + print_message "Catalog Status must return completed but returned value is $coutput" + fi + fi + done + if [ ${count1} -ge ${arrLen} ]; then + break; + fi + print_message "Shards are still not ready. Sleeping for 120 seconds" + sleep 120 +done +} + +configureGSMShard() +{ +chost=$1 +cport=1521 +cpdb=$3 +ccdb=$2 +cpasswd=${ORACLE_PWD} +region=${REGION} +shardGName="${SHARD_GROUP_NAME}" +deployment_type="${SHARD_DEPLOYMENT_TYPE}" +local gdsScript="/tmp/gdsScript.sql" +admuser="${PDB_ADMIN_USER}" + +echo "connect ${admuser}/${cpasswd}" > "${gdsScript}" +echo "add cdb -connect ${chost}:${cport}:${ccdb} -pwd ${cpasswd}" >> "${gdsScript}" +echo "add shard -cdb ${ccdb} -connect ${chost}:${cport}/${cpdb} -shardgroup ${shardGName} -pwd ${cpasswd}" >> "${gdsScript}" +echo "config vncr" >> "${gdsScript}" +echo "sql 'update gsmadmin_internal.database set hostid=NULL '" >> "${gdsScript}" +echo "exit" >> "${gdsScript}" +print_message "Sending script to gsm to execute ${gdsScript}" +cat ${gdsScript} >> $LOGFILE +executeGSM "$cmd1" "gdsScript" "${gdsScript}" +print_message " Calling Stop GSM function" +stopGSM +print_message "Stop GSM function completed, sleeping for 20 seconds" +sleep 20 +print_message " Calling Start GSM function" +startGSM +print_message "Start GSM function completed, sleeping for 30 seconds" +sleep 30 +print_message "Calling invitenode function to add the shard" +addInvitedNode $chost +deployShard +} + +####################################################################### GSM Setup Task Ends here ######################################### + + +######################################################################### Execute GSM Statements ######################################### +executeGSM() +{ +gsmQuery=$1 +type=$2 +gdsScript=$3 + +if [ -z "${gsmQuery}" ]; then + print_message "Empty gdsQuery passed to gds" +fi + +if [ -z "${type}" ]; then + type='notSet' +fi + +if [ -z "${gdsScript}" ]; then + gdsScript='notSet' +fi + +if [ "${type}" == "gdsScript" ]; then +print_message "Executing gds script " +"$ORACLE_HOME"/bin/gdsctl @${gdsScript} +else +print_message "Executing GSM query" +"$ORACLE_HOME"/bin/gdsctl << EOF >> $LOGFILE + $gsmQuery + exit +EOF +fi +} +######################################################################## Execute GSM Statements Ends here ################################ + +########################################################################## Execute SQL Function Begin here ############################## +executeSQL() +{ +sqlQuery=$1 +connectStr=$2 +type=$3 +sqlScript=$4 + +if [ -z "${sqlQuery}" ]; then + print_message "Empty sqlQuery passed to sqlplus. Operation Failed" +fi + +if [ -z "${connectStr}" ]; then + error_exit "Empty connectStr passed to sqlplus. Operation Failed" +fi + +if [ -z "${type}" ]; then + type='notSet' +fi + +if [ -z "${sqlScript}" ]; then + sqlScript='notSet' +fi + +if [ "${type}" == "sqlScript" ] && [ -f ${sqlScript} ]; then +print_message "Executing sql script using connect string" +"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE +@ ${sqlScript} +EOF +else +print_message "Executing sqlQuery using connect string" +"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE +$sqlQuery +EOF +fi +} + +############################################################################## Execute SQl Function ends here ################################# + +####################################### +################## MAIN ############### + +if [ "${OP_TYPE}" == "primaryshard" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + resetPassword + setupShardCDB +elif [ "${OP_TYPE}" == "standbyshard" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + setupShardStandby +elif [ "${OP_TYPE}" == "catalog" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + resetPassword + setupCatalog +elif [ "${OP_TYPE}" == "gsm" ]; then + print_message "Performing Checks before proceeding for setup" + gsmChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + setupGSM +else + print_message "OP_TYPE must be set to (gsm|catalog|primaryshard|standbyshard)" + exit 15 +fi diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/23c_gsm_install.rsp b/container-based-sharding-deployment/containerfiles/23.5.0/23c_gsm_install.rsp new file mode 100644 index 0000000..102854f --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/23c_gsm_install.rsp @@ -0,0 +1,35 @@ + +############################################################################### +## Copyright(c) Oracle Corporation 1998,2022. All rights reserved. ## +## ## +## Specify values for the variables listed below to customize ## +## your installation. ## +## ## +## Each variable is associated with a comment. The comment ## +## can help to populate the variables with the appropriate ## +## values. ## +## ## +############################################################################### + +#------------------------------------------------------------------------------- +# Do not change the following system generated value. +#------------------------------------------------------------------------------- +oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v23.0.0 + +#------------------------------------------------------------------------------- +# Unix group to be set for the inventory directory. +#------------------------------------------------------------------------------- +UNIX_GROUP_NAME=oinstall +#------------------------------------------------------------------------------- +# Inventory location. +#------------------------------------------------------------------------------- +INVENTORY_LOCATION=###INVENTORY### +#------------------------------------------------------------------------------- +# Complete path of the Oracle Home +#------------------------------------------------------------------------------- +ORACLE_HOME=###ORACLE_HOME### + +#------------------------------------------------------------------------------- +# Complete path of the Oracle Base. +#------------------------------------------------------------------------------- +ORACLE_BASE=###ORACLE_BASE### diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/23c_gsm_install_sample.rsp b/container-based-sharding-deployment/containerfiles/23.5.0/23c_gsm_install_sample.rsp new file mode 100644 index 0000000..fce54e3 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/23c_gsm_install_sample.rsp @@ -0,0 +1,35 @@ + +############################################################################### +## Copyright(c) Oracle Corporation 1998,2022. All rights reserved. ## +## ## +## Specify values for the variables listed below to customize ## +## your installation. ## +## ## +## Each variable is associated with a comment. The comment ## +## can help to populate the variables with the appropriate ## +## values. ## +## ## +############################################################################### + +#------------------------------------------------------------------------------- +# Do not change the following system generated value. +#------------------------------------------------------------------------------- +oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v23.0.0 + +#------------------------------------------------------------------------------- +# Unix group to be set for the inventory directory. +#------------------------------------------------------------------------------- +UNIX_GROUP_NAME= +#------------------------------------------------------------------------------- +# Inventory location. +#------------------------------------------------------------------------------- +INVENTORY_LOCATION= +#------------------------------------------------------------------------------- +# Complete path of the Oracle Home +#------------------------------------------------------------------------------- +ORACLE_HOME= + +#------------------------------------------------------------------------------- +# Complete path of the Oracle Base. +#------------------------------------------------------------------------------- +ORACLE_BASE= diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/Checksum b/container-based-sharding-deployment/containerfiles/23.5.0/Checksum new file mode 100644 index 0000000..faf7c8c --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/Checksum @@ -0,0 +1 @@ +ba8e6b942ba8ff22d25dd3babc7b326c LINUX.X64_234000_gsm.zip diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/Containerfile b/container-based-sharding-deployment/containerfiles/23.5.0/Containerfile new file mode 100644 index 0000000..9d734f5 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/Containerfile @@ -0,0 +1,232 @@ +# LICENSE UPL 1.0 +# +# Copyright (c) 2018,2022 Oracle and/or its affiliates. +# +# ORACLE DOCKERFILES PROJECT +# -------------------------- +# This is the Dockerfile for Oracle GSM 23ai Release 4 to build the container image +# MAINTAINER <paramdeep.saini@oracle.com> +# +# This is the Dockerfile for Oracle GSM 23ai +# +# REQUIRED FILES TO BUILD THIS IMAGE +# ---------------------------------- +# (1) LINUX.X64_234000_gsm.zip +# Download Oracle Database 23ai GSM Software +# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html +# +# HOW TO BUILD THIS IMAGE +# ----------------------- +# Put all downloaded files in the same directory as this Dockerfile +# Run: +# $ docker build -t oracle/gsm:23.3.0 . +# + +ARG BASE_OL_IMAGE=oraclelinux:8 + +# Pull base image +# --------------- +FROM $BASE_OL_IMAGE AS base +ARG SLIMMING=false + +# Labels +# ------ +LABEL "provider"="Oracle" \ + "issues"="https://github.com/oracle/db-sharding/issues" \ + "volume.setup.location1"="/opt/oracle/scripts" \ + "port.listener"="1522" + +# Argument to control removal of components not needed after db software installation + +ARG INSTALL_FILE_1="LINUX.X64_234000_gsm.zip" +ARG USER="root" + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +ENV GSM_BASE="/u01/app/oracle" \ + GSM_USER="oracle" \ + GSM_HOME="/u01/app/oracle/product/23ai/gsmhome_1" \ + INVENTORY="/u01/app/oracle/oraInventory" \ + INSTALL_DIR="/opt/oracle/scripts" \ + INSTALL_FILE_1=$INSTALL_FILE_1 \ + INSTALL_RSP="23c_gsm_install.rsp" \ + RUN_FILE="runOracle.sh" \ + SETUP_LINUX_FILE="setupLinuxEnv.sh" \ + CHECK_SPACE_FILE="checkSpace.sh" \ + USER_SCRIPTS_FILE="runUserScripts.sh" \ + INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ + GSM_SETUP_FILE="setupOshardEnv.sh" \ + GSM_ENV_SETUP_FILE="setupGSM.sh" \ + GSM_SCRIPTS="scripts" \ + MAINPY="main.py" \ + PYTHON_FILE="/usr/bin/python" \ + PYTHON3_FILE="/usr/bin/python3" \ + ORAPCATALOG="orapcatalog.py" \ + CMDEXEC="cmdExec" \ + ORAMACHINE="oramachine.py" \ + ORALOGGER="oralogger.py" \ + ORAFACTORY="orafactory.py" \ + ORAGSM="oragsm.py" \ + ORASSHARD="orasshard.py" \ + ORAENV="oraenv.py" \ + ORAPSHARD="orapshard.py" \ + MAINPY="main.py" \ + ORASCATALOG="orascatalog.py" \ + ORACOMMON="oracommon.py" \ + DEMOAPPSQL="demoapp.sql" \ + RUNORASHARD="runOraShardSetup.sh" \ + CHECKLIVENESS="checkLiveness.sh" +# Use second ENV so that variable get substituted +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/sharding \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_PATH=$GSM_HOME/bin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib + +############################################# +# ------------------------------------------- +# Start new stage for slim image +# ------------------------------------------- +############################################# +FROM base AS gsm-image-slim-false +ARG SLIMMING + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +# Linux Env Variable +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/sharding \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_PATH=$GSM_HOME/bin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib \ + INSTALL_SCRIPTS=$INSTALL_DIR/install \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_SCRIPTS="scripts" + +# Copy binaries +# ------------- +# COPY Binaries +COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $GSM_ENV_SETUP_FILE $INSTALL_SCRIPTS/ +COPY $RUN_FILE $GSM_SETUP_FILE $CHECKLIVENESS $USER_SCRIPTS_FILE $SCRIPT_DIR/ +COPY $GSM_SCRIPTS/$ORAPCATALOG $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$ORAPSHARD $GSM_SCRIPTS/$MAINPY $GSM_SCRIPTS/$ORASCATALOG $GSM_SCRIPTS/$ORACOMMON $GSM_SCRIPTS/$DEMOAPPSQL $GSM_SCRIPTS/$RUNORASHARD $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$ORAMACHINE $GSM_SCRIPTS/$ORALOGGER $GSM_SCRIPTS/$ORAFACTORY $GSM_SCRIPTS/$ORAGSM $GSM_SCRIPTS/$ORASSHARD $GSM_SCRIPTS/$ORAENV $SCRIPT_DIR/scripts/ + +RUN chmod 755 $INSTALL_DIR/install/*.sh && \ + sync && \ + $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ + $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ + $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ + sync + +############################################# +# ------------------------------------------- +# Start new stage for slim image true +# ------------------------------------------- +############################################# +FROM base AS gsm-image-slim-true +ARG SLIMMING + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +# Linux Env Variable +ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ + ORACLE_HOME=$GSM_HOME \ + ORACLE_BASE=$GSM_BASE \ + SCRIPT_DIR=$INSTALL_DIR/sharding \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_PATH=$GSM_HOME/bin:$PATH \ + GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib \ + INSTALL_SCRIPTS=$INSTALL_DIR/install \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + GSM_SCRIPTS="scripts" + +# Copy binaries +# ------------- +# COPY Binaries +COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $GSM_ENV_SETUP_FILE $INSTALL_SCRIPTS/ +COPY $RUN_FILE $GSM_SETUP_FILE $CHECKLIVENESS $USER_SCRIPTS_FILE $SCRIPT_DIR/ +COPY $GSM_SCRIPTS/$ORAPCATALOG $GSM_SCRIPTS/$ORAPSHARD $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$MAINPY $GSM_SCRIPTS/$ORASCATALOG $GSM_SCRIPTS/$ORACOMMON $GSM_SCRIPTS/$DEMOAPPSQL $GSM_SCRIPTS/$RUNORASHARD $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$ORAMACHINE $GSM_SCRIPTS/$ORALOGGER $GSM_SCRIPTS/$ORAFACTORY $GSM_SCRIPTS/$ORAGSM $GSM_SCRIPTS/$ORASSHARD $GSM_SCRIPTS/$ORAENV $SCRIPT_DIR/scripts/ + +RUN chmod 755 $INSTALL_DIR/install/*.sh && \ + sync && \ + $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ + $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ + $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ + sync + +############################################# +# ------------------------------------------- +# Start new stage for installing the grid and DB +# ------------------------------------------- +############################################# + +FROM gsm-image-slim-${SLIMMING} AS builder +ARG SLIMMING + +COPY $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ + +USER ${USER} +RUN if [ "${SLIMMING}x" != 'truex' ]; then \ + chmod 755 $INSTALL_SCRIPTS/*.sh && \ + :;\ + fi +USER ${GSM_USER} +RUN if [ "${SLIMMING}x" != 'truex' ]; then \ + "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ + :;\ +fi + +USER ${USER} +RUN if [ "${SLIMMING}x" != 'truex' ]; then \ + $INVENTORY/orainstRoot.sh && \ + $GSM_HOME/root.sh && \ + rm -rf $INSTALL_DIR/install && \ + :;\ + fi + +#RUN if [ "${SLIMMING}x" == 'truex' ]; then \ +# mkdir /u01 && \ +# :; \ +#fi + +RUN rm -f $INSTALL_DIR/install/* && \ + sync + +############################################# +# ------------------------------------------- +# Start new layer for GSM runtime +# ------------------------------------------- +############################################# + +FROM gsm-image-slim-${SLIMMING} AS final + +COPY --from=builder /u01 /u01 + +RUN if [ ! -f $PYTHON_FILE ]; then \ + ln -s $PYTHON3_FILE $PYTHON_FILE && \ + :; \ + fi && \ + rm -f $INSTALL_DIR/install/* && \ + cp $SCRIPT_DIR/scripts/cmdExec $SCRIPT_DIR/ && \ + chown -R oracle:oinstall $SCRIPT_DIR && \ + chmod 755 $SCRIPT_DIR/*.sh && \ + chmod 755 $SCRIPT_DIR/scripts/*.py && \ + chmod 755 $SCRIPT_DIR/scripts/*.sh && \ + chmod 755 $SCRIPT_DIR/scripts/cmdExec && \ + chmod 755 $SCRIPT_DIR/cmdExec && \ + sync + +USER ${GSM_USER} +WORKDIR /home/${GSM_USER} +EXPOSE 1522 + +VOLUME ["$GSM_BASE/oradata"] + +HEALTHCHECK --interval=2m --start-period=25m \ + CMD "$SCRIPT_DIR/$CHECKLIVENESS" >/dev/null || exit 1 + +# Define default command to start Oracle Database. +CMD exec $SCRIPT_DIR/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/checkLiveness.sh b/container-based-sharding-deployment/containerfiles/23.5.0/checkLiveness.sh new file mode 100644 index 0000000..e917502 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/checkLiveness.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +export PYTHON="/bin/python3" + +$PYTHON $SCRIPT_DIR/scripts/$MAINPY --checkliveness='true' +retcode=$? + + if [ ${retcode} -eq 0 ]; then + exit 0 + else + exit 1 + fi diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/checkSpace.sh b/container-based-sharding-deployment/containerfiles/23.5.0/checkSpace.sh new file mode 100644 index 0000000..5d4b8d9 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/checkSpace.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +REQUIRED_SPACE_GB=2 +AVAILABLE_SPACE_GB=`df -PB 1G / | tail -n 1 | awk '{ print $4 }'` + +if [ $AVAILABLE_SPACE_GB -lt $REQUIRED_SPACE_GB ]; then + script_name=`basename "$0"` + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "$script_name: ERROR - There is not enough space available in the docker container." + echo "$script_name: The container needs at least $REQUIRED_SPACE_GB GB, but only $AVAILABLE_SPACE_GB GB are available." + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + exit 1; +fi; diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/installGSMBinaries.sh b/container-based-sharding-deployment/containerfiles/23.5.0/installGSMBinaries.sh new file mode 100644 index 0000000..adf6547 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/installGSMBinaries.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +export ORACLE_BASE=$GSM_BASE +export ORACLE_HOME=$GSM_HOME + +# Check whether ORACLE_BASE is set +if [ "$ORACLE_BASE" == "" ]; then + echo "ERROR: ORACLE_BASE has not been set!" + echo "You have to have the ORACLE_BASE environment variable set to a valid value!" + exit 1; +fi; + +# Check whether ORACLE_HOME is set +if [ "$ORACLE_HOME" == "" ]; then + echo "ERROR: ORACLE_HOME has not been set!" + echo "You have to have the ORACLE_HOME environment variable set to a valid value!" + exit 1; +fi; + + +# Replace place holders +# --------------------- + +sed -i -e "s|###INVENTORY###|$INVENTORY|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ +sed -i -e "s|###ORACLE_BASE###|$GSM_BASE|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ +sed -i -e "s|###ORACLE_HOME###|$GSM_HOME|g" $INSTALL_SCRIPTS/$INSTALL_RSP + +# Install Oracle binaries +cd $INSTALL_SCRIPTS && \ +unzip $INSTALL_FILE_1 && \ +rm $INSTALL_FILE_1 && \ +$INSTALL_SCRIPTS/gsm/runInstaller -silent -force -waitforcompletion -responsefile $INSTALL_SCRIPTS/$INSTALL_RSP -ignorePrereqFailure || true && \ +rm -rf gsm && \ +cd $HOME diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/runOracle.sh b/container-based-sharding-deployment/containerfiles/23.5.0/runOracle.sh new file mode 100644 index 0000000..473de50 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/runOracle.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +#This is the main file which calls other file to setup the sharding. +if [ -z ${BASE_DIR} ]; then + BASE_DIR=$INSTALL_DIR/sharding/scripts +fi + +if [ -z ${MAIN_SCRIPT} ]; then + SCRIPT_NAME="main.py" +fi + +if [ -z ${EXECUTOR} ]; then + EXECUTOR="python3" +fi + +cd $BASE_DIR +$EXECUTOR $SCRIPT_NAME + +# Tail on alert log and wait (otherwise container will exit) + +if [ -z ${DEV_MODE} ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/gsm/*/*/trace/alert*.log & +else + echo "The following output is now a tail of the /etc/passwd for dev mode" + tail -f /etc/passwd & +fi + +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/runUserScripts.sh b/container-based-sharding-deployment/containerfiles/23.5.0/runUserScripts.sh new file mode 100644 index 0000000..c1d1c44 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/runUserScripts.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +SCRIPTS_ROOT="$1"; + +# Check whether parameter has been passed on +if [ -z "$SCRIPTS_ROOT" ]; then + echo "$0: No SCRIPTS_ROOT passed on, no scripts will be run"; + exit 1; +fi; + +# Execute custom provided files (only if directory exists and has files in it) +if [ -d "$SCRIPTS_ROOT" ] && [ -n "$(ls -A $SCRIPTS_ROOT)" ]; then + + echo ""; + echo "Executing user defined scripts" + + for f in $SCRIPTS_ROOT/*; do + case "$f" in + *.sh) echo "$0: running $f"; . "$f" ;; + *.sql) echo "$0: running $f"; echo "exit" | $ORACLE_HOME/bin/sqlplus -s "/ as sysdba" @"$f"; echo ;; + *) echo "$0: ignoring $f" ;; + esac + echo ""; + done + + echo "DONE: Executing user defined scripts" + echo ""; + +fi; diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/cmdExec b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/cmdExec new file mode 100755 index 0000000..0e5ac30 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/cmdExec @@ -0,0 +1,23 @@ +#!/bin/bash + +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +TIMESTAMP=`date "+%Y-%m-%d"` +LOGFILE="/tmp/sharding_cmd_${TIMESTAMP}.log" + +echo $(date -u) " : " $@ >> $LOGFILE + +cmd=$@ + +$cmd + +if [ $? -eq 0 ]; then + exit 0 +else + exit 127 +fi diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/demoapp.sql b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/demoapp.sql new file mode 100755 index 0000000..3e96bfc --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/demoapp.sql @@ -0,0 +1,88 @@ + connect sys/'&1'@oshard-catalog-0:1521/CATCDB as sysdba + alter session set container=CAT1PDB; + alter session enable shard ddl; + create user app_schema identified by app_schema; + grant connect, resource, alter session to app_schema; + grant execute on dbms_crypto to app_schema; + grant create table, create procedure, create tablespace, create materialized view to app_schema; + grant unlimited tablespace to app_schema; + grant select_catalog_role to app_schema; + grant all privileges to app_schema; + grant gsmadmin_role to app_schema; + grant dba to app_schema; + conn app_schema/'&1'@oshard-catalog-0:1521/CAT1PDB + alter session enable shard ddl; + REM + REM Create a Sharded table for + REM + CREATE SHARDED TABLE Customers + ( + CustId VARCHAR2(60) NOT NULL, + FirstName VARCHAR2(60), + LastName VARCHAR2(60), + Class VARCHAR2(10), + Geo VARCHAR2(8), + CustProfile VARCHAR2(4000), + Passwd RAW(60), + CONSTRAINT pk_customers PRIMARY KEY (CustId), + CONSTRAINT json_customers CHECK (CustProfile IS JSON) + ) TABLESPACE SET TSP_SET_1 + PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO; + REM + REM Create a Sharded table for Orders + REM + CREATE SHARDED TABLE Orders + ( + OrderId INTEGER NOT NULL, + CustId VARCHAR2(60) NOT NULL, + OrderDate TIMESTAMP NOT NULL, + SumTotal NUMBER(19,4), + Status CHAR(4), + constraint pk_orders primary key (CustId, OrderId), + constraint fk_orders_parent foreign key (CustId) + references Customers on delete cascade + ) partition by reference (fk_orders_parent); + REM + REM Create the sequence used for the OrderId column + REM + CREATE SEQUENCE Orders_Seq; + REM + REM Create a Sharded table for LineItems + REM + CREATE SHARDED TABLE LineItems + ( + OrderId INTEGER NOT NULL, + CustId VARCHAR2(60) NOT NULL, + ProductId INTEGER NOT NULL, + Price NUMBER(19,4), + Qty NUMBER, + constraint pk_items primary key (CustId, OrderId, ProductId), + constraint fk_items_parent foreign key (CustId, OrderId) + references Orders on delete cascade + ) partition by reference (fk_items_parent); + REM + REM + CREATE DUPLICATED TABLE Products + ( + ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + Name VARCHAR2(128), + DescrUri VARCHAR2(128), + LastPrice NUMBER(19,4) + ) TABLESPACE products_tsp; + CREATE OR REPLACE FUNCTION PasswCreate(PASSW IN RAW) + RETURN RAW + IS + Salt RAW(8); + BEGIN + Salt := DBMS_CRYPTO.RANDOMBYTES(8); + RETURN UTL_RAW.CONCAT(Salt, DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(Salt,PASSW), DBMS_CRYPTO.HASH_SH256)); + END; + / + CREATE OR REPLACE FUNCTION PasswCheck(PASSW IN RAW, PHASH IN RAW) + RETURN INTEGER IS + BEGIN + RETURN UTL_RAW.COMPARE(DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(UTL_RAW.SUBSTR(PHASH, 1, 8), PASSW), DBMS_CRYPTO.HASH_SH256),UTL_RAW.SUBSTR(PHASH, 9)); + END; + / + REM + REM diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/main.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/main.py new file mode 100755 index 0000000..b7f0f17 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/main.py @@ -0,0 +1,171 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" +This is the main file which calls other file to setup the sharding. +""" + +from oralogger import * +from orafactory import * +from oraenv import * +from oracommon import * + + +def main(): + + # Checking Comand line Args + try: + opts, args = getopt.getopt(sys.argv[1:], '', ['addshard=','deleteshard=','validateshard=','checkliveness=','resetlistener=','restartdb=','createdir=','optype=','addshardgroup=','deployshard=','movechunks=','checkonlineshard=','cancelchunks=','checkchunks=','checkgsmshard=','checkreadyness=','validatenochunks=','invitednode=','resetpassword=','exporttdekey=','importtdekey=','help']) + except getopt.GetoptError: + pass + + # Initializing oraenv instance + oenv=OraEnv() + file_name = os.path.basename(__file__) + funcname = sys._getframe(1).f_code.co_name + + log_file_name = oenv.logfile_name("NONE") + + # Initialiing logger instance + oralogger = OraLogger(log_file_name) + console_handler = CHandler() + file_handler = FHandler() + stdout_handler = StdHandler() + # Setting next log handlers + stdout_handler.nextHandler = file_handler + file_handler.nextHandler = console_handler + console_handler.nextHandler = PassHandler() + + ocommon = OraCommon(oralogger,stdout_handler,oenv) + + for opt, arg in opts: + if opt in ('--help'): + oralogger.msg_ = '''{:^17}-{:^17} : You can pass parameter --addshard, --deleteshard, --validateshard, --checkliveness, --resetlistener, --restartdb, --createdir, --optype, --addshardgroup, --deployshard, '--checkonlineshard', '--cancelchunks', '--movechunks', '--checkchunks', '--checkgsmshard','--validatenochunks', '--checkreadyness','--invitednode', '--resetpassword','--exporttdekey','--importtdekey',or --help''' + stdout_handler.handle(oralogger) + elif opt in ('--addshard'): + file_name = oenv.logfile_name("ADD_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("ADD_SHARD",arg) + elif opt in ('--validateshard'): + file_name = oenv.logfile_name("VALIDATE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("VALIDATE_SHARD",arg) + elif opt in ('--deleteshard'): + file_name = oenv.logfile_name("REMOVE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("REMOVE_SHARD",arg) + elif opt in ('--checkliveness'): + oralogger.stdout_ = None + file_name = oenv.logfile_name("CHECK_LIVENESS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_LIVENESS",arg) + elif opt in ('--checkreadyness'): + oralogger.stdout_ = None + file_name = oenv.logfile_name("CHECK_READYNESS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_READYNESS",arg) + elif opt in ('--resetlistener'): + file_name = oenv.logfile_name("RESET_LISTENER") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESET_LISTENER",arg) + elif opt in ('--restartdb'): + file_name = oenv.logfile_name("RESTART_DB") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESTART_DB",arg) + elif opt in ('--createdir'): + file_name = oenv.logfile_name("CREATE_DIR") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CREATE_DIR",arg) + elif opt in ('--addshardgroup'): + file_name = oenv.logfile_name("ADD_SGROUP_PARAMS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("ADD_SGROUP_PARAMS",arg) + elif opt in ('--deployshard'): + file_name = oenv.logfile_name("DEPLOY_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("DEPLOY_SHARD",arg) + elif opt in ('--cancelchunks'): + file_name = oenv.logfile_name("CANCEL_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CANCEL_CHUNKS",arg) + elif opt in ('--movechunks'): + file_name = oenv.logfile_name("MOVE_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("MOVE_CHUNKS",arg) + elif opt in ('--checkchunks'): + file_name = oenv.logfile_name("CHECK_CHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_CHUNKS",arg) + elif opt in ('--validatenochunks'): + file_name = oenv.logfile_name("VALIDATE_NOCHUNKS") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("VALIDATE_NOCHUNKS",arg) + elif opt in ('--checkonlineshard'): + file_name = oenv.logfile_name("CHECK_ONLINE_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_ONLINE_SHARD",arg) + elif opt in ('--checkgsmshard'): + file_name = oenv.logfile_name("CHECK_GSM_SHARD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("CHECK_GSM_SHARD",arg) + elif opt in ('--invitednode'): + file_name = oenv.logfile_name("INVITED_NODE_OP") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("INVITED_NODE_OP",arg) + elif opt in ('--resetpassword'): + file_name = oenv.logfile_name("RESET_PASSWD") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("RESET_PASSWORD",arg) + elif opt in ('--exporttdekey'): + file_name = oenv.logfile_name("EXPORT_TDE_KEY") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("EXPORT_TDE_KEY",arg) + elif opt in ('--importtdekey'): + file_name = oenv.logfile_name("IMPORT_TDE_KEY") + oralogger.filename_ = file_name + ocommon.log_info_message("=======================================================================",file_name) + oenv.add_custom_variable("IMPORT_TDE_KEY",arg) + elif opt in ('--optype'): + oenv.add_custom_variable("OP_TYPE",arg) + else: + pass + + # Initializing orafactory instances + oralogger.msg_ = '''{:^17}-{:^17} : Calling OraFactory to start the setup'''.format(file_name,funcname) + stdout_handler.handle(oralogger) + orafactory = OraFactory(oralogger,stdout_handler,oenv,ocommon) + + # Get the ora objects + ofactory=orafactory.get_ora_objs() + + # Traverse through returned factory objects and execute the setup function + for obj in ofactory: + obj.setup() + +# Using the special variable +if __name__=="__main__": + main() diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oracommon.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oracommon.py new file mode 100755 index 0000000..42a319b --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oracommon.py @@ -0,0 +1,966 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +from oralogger import * +from oraenv import * +import subprocess +import sys +import time +import datetime +import os +import getopt +import shlex +import json +import logging +import socket +import re +import os.path +import socket +import string +import random + +class OraCommon: + def __init__(self,oralogger,orahandler,oraenv): + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + + def run_sqlplus(self,cmd,sql_cmd,dbenv): + """ + This function execute the ran sqlplus or rman script and return the output + """ + try: + message="Received Command : {0}\n{1}".format(self.mask_str(cmd),self.mask_str(sql_cmd)) + self.log_info_message(message,self.file_name) + sql_cmd=self.unmask_str(sql_cmd) + cmd=self.unmask_str(cmd) +# message="Received Command : {0}\n{1}".format(cmd,sql_cmd) +# self.log_info_message(message,self.file_name) + p = subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,env=dbenv,shell=True,universal_newlines=True) + p.stdin.write(sql_cmd) + # (stdout,stderr), retcode = p.communicate(sqlplus_script.encode('utf-8')), p.returncode + (stdout,stderr),retcode = p.communicate(),p.returncode + # stdout_lines = stdout.decode('utf-8').split("\n") + except: + error_msg=sys.exc_info() + self.log_error_message(error_msg,self.file_name) + self.prog_exit(self) + + return stdout.replace("\n\n", "\n"),stderr,retcode + + def execute_cmd(self,cmd,env,dir): + """ + Execute the OS command on host + """ + try: + message="Received Command : {0}".format(self.mask_str(cmd)) + self.log_info_message(message,self.file_name) + cmd=self.unmask_str(cmd) + out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,universal_newlines=True) + (output,error),retcode = out.communicate(),out.returncode + except: + error_msg=sys.exc_info() + self.log_error_message(error_msg,self.file_name) + self.prog_exit(self) + + return output,error,retcode + + def mask_str(self,mstr): + """ + Function to mask the string. + """ + newstr=None + if self.oenv.encrypt_str__: + newstr=mstr.replace('HIDDEN_STRING','********') + # self.log_info_message(newstr,self.file_name) + if newstr: + # message = "Masked the string as encryption flag is set in the singleton class" + # self.log_info_message(message,self.file_name) + return newstr + else: + return mstr + + + def unmask_str(self,mstr): + """ + Function to unmask the string. + """ + newstr=None + if self.oenv.encrypt_str__: + newstr=mstr.replace('HIDDEN_STRING',self.oenv.original_str__.rstrip()) + # self.log_info_message(newstr,self.file_name) + if newstr: + # message = "Unmasked the encrypted string and returning original string from singleton class" + # self.log_info_message(message,self.file_name) + return newstr + else: + return mstr + + def set_mask_str(self,mstr): + """ + Function to unmask the string. + """ + if mstr: + # message = "Setting encrypted String flag to True and original string in singleton class" + # self.log_info_message(message,self.file_name) + self.oenv.encrypt_str__ = True + self.oenv.original_str__ = mstr + else: + message = "Masked String is empty so no change required in encrypted String Flag and original string in singleton class" + self.log_info_message(message,self.file_name) + + def unset_mask_str(self): + """ + Function to unmask the string. + """ + # message = "Un-setting encrypted String flag and original string to None in Singleton class" + # self.log_info_message(message,self.file_name) + self.oenv.encrypt_str__ = None + self.oenv.original_str__ = None + + def prog_exit(self,message): + """ + This function exit the program because of some error + """ + sys.exit(127) + + def log_info_message(self,lmessage,fname): + """ + Print the INFO message in the logger + """ + funcname = sys._getframe(1).f_code.co_name + message = '''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_ = message + self.ologger.logtype_ = "INFO" + self.ohandler.handle(self.ologger) + + def log_error_message(self,lmessage,fname): + """ + Print the Error message in the logger + """ + funcname=sys._getframe(1).f_code.co_name + message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_=message + self.ologger.logtype_="ERROR" + self.ohandler.handle(self.ologger) + + def log_warn_message(self,lmessage,fname): + """ + Print the Error message in the logger + """ + funcname=sys._getframe(1).f_code.co_name + message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) + self.ologger.msg_=message + self.ologger.logtype_="WARN" + self.ohandler.handle(self.ologger) + + def check_sql_err(self,output,err,retcode,status): + """ + Check if there are any error in sql command output + """ + match=None + msg2='''Sql command failed.Flag is set not to ignore this error.Please Check the logs,Exiting the Program!''' + msg3='''Sql command failed.Flag is set to ignore this error!''' + self.log_info_message("output : " + str(output or "no Output"),self.file_name) + # self.log_info_message("Error : " + str(err or "no Error"),self.file_name) + # self.log_info_message("Sqlplus return code : " + str(retcode),self.file_name) + # self.log_info_message("Command Check Status Set to :" + str(status),self.file_name) + + if status: + if (retcode!=0): + self.log_info_message("Error : " + str(err or "no Error"),self.file_name) + self.log_error_message("Sql Login Failed.Please Check the logs,Exiting the Program!",self.file_name) + self.prog_exit(self) + + match=re.search("(?i)(?m)error",output) + if status: + if (match): + self.log_error_message(msg2,self.file_name) + self.prog_exit("error") + else: + self.log_info_message("Sql command completed successfully",self.file_name) + else: + if (match): + self.log_warn_message("Sql command failed. Flag is set to ignore the error.",self.file_name) + else: + self.log_info_message("Sql command completed sucessfully.",self.file_name) + + def check_os_err(self,output,err,retcode,status): + """ + Check if there are any error in OS command execution + """ + msg1='''OS command returned code : {0} and returned output : {1}'''.format(str(retcode),str(output or "no Output")) + msg2='''OS command returned code : {0}, returned error : {1} and returned output : {2}'''.format(str(retcode),str(err or "no returned error"),str(output or "no retruned output")) + msg3='''OS command failed. Flag is set to ignore this error!''' + + if status: + if (retcode != 0): + self.log_error_message(msg2,self.file_name) + self.prog_exit(self) + else: + self.log_info_message(msg1,self.file_name) + else: + if (retcode != 0): + self.log_warn_message(msg2,self.file_name) + self.log_warn_message(msg3,self.file_name) + else: + self.log_info_message(msg1,self.file_name) + + def check_key(self,key,env_dict): + """ + Check the key if it exist in dictionary. + Attributes: + key (string): String to check if key exist in dictionary + env_dict (dict): Contains the env variable related to seup + """ + if key in env_dict: + return True + else: + return False + + def empty_key(self,key): + """ + key is empty and print failure message. + Attributes: + key (string): String is empty + """ + msg='''Variable {0} is not defilned. Exiting!'''.format(key) + self.log_error_message(msg,self.file_name) + self.prog_exit(self) + + def add_key(self,key,value,env_dict): + """ + Add the key in the dictionary. + Attributes: + key (string): key String to add in the dictionary + value (String): value String to add in dictionary + + Return: + dict + """ + if self.check_key(key,env_dict): + msg='''Variable {0} already exist in the env variables'''.format(key) + self.log_info_message(msg,self.file_name) + else: + if value: + env_dict[key] = value + self.oenv.update_env_vars(env_dict) + else: + msg='''Variable {0} value is not defilned to add in the env variables. Exiting!'''.format(value) + self.log_error_message(msg,self.file_name) + self.prog_exit(self) + + return env_dict + + def update_key(self,key,value,env_dict): + """ + update the key in the dictionary. + Attributes: + key (string): key String to update in the dictionary + value (String): value String to update in dictionary + + Return: + dict + """ + if self.check_key(key,env_dict): + if value: + env_dict[key] = value + self.oenv.update_env_vars(env_dict) + else: + msg='''Variable {0} value is not defilned to update in the env variables!'''.format(key) + self.log_warn_message(msg,self.file_name) + else: + msg='''Variable {0} already exist in the env variables'''.format(key) + self.log_info_message(msg,self.file_name) + + return env_dict + + def check_file(self,file,local,remote,user): + """ + check locally or remotely + Attributes: + file (string): file to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside check_file()",self.file_name) + if local: + if os.path.isfile(file): + return True + else: + return False + + + def read_file(self,fname): + """ + Read the contents of a file and returns the contents to end user + Attributes: + fname (string): file to be read + + Return: + file data (string) + """ + f1 = open(fname, 'r') + fdata = f1.read() + f1.close + return fdata + + def write_file(self,fname,fdata): + """ + write the contents to a file + Attributes: + fname (string): file to be written + fdata (string): COnetents to be written + + Return: + file data (string) + """ + f1 = open(fname, 'w') + f1.write(fdata) + f1.close + + def append_file(self,fname,fdata): + """ + append the contents to a file + Attributes: + fname (string): file to be appended + fdata (string): COnetents to be appended + + Return: + file data (string) + """ + f1 = open(fname, 'a') + f1.write(fdata) + f1.close + + def create_dir(self,dir,local,remote,user): + """ + Create dir locally or remotely + Attributes: + dir (string): dir to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside create_dir()",self.file_name) + if local: + if not os.path.isdir(dir): + cmd='''mkdir -p {0}'''.format(dir) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + else: + msg='''Dir {0} already exist'''.format(dir) + self.log_info_message(msg,self.file_name) + + if remote: + pass + + def create_file(self,file,local,remote,user): + """ + Create dir locally or remotely + Attributes: + file (string): file to be created + local (boolean): dir to craetes locally + remote (boolean): dir to be created remotely + node (string): remote node name on which dir to be created + user (string): remote user to be connected + """ + self.log_info_message("Inside create_file()",self.file_name) + if local: + if not os.path.isfile(file): + cmd='''touch {0}'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + if remote: + pass + + def shutdown_db(self,env_dict): + """ + Shutdown the database + """ + file="/home/oracle/shutDown.sh" + if not os.path.isfile(file): + self.log_info_message("Inside shutdown_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + shutdown immediate; + ''' + self.log_info_message("Running the sqlplus command to shutdown the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + else: + cmd='''sh {0} immediate'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + def mount_db(self,env_dict): + """ + Mount the database + """ + self.log_info_message("Inside mount_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup mount; + ''' + self.log_info_message("Running the sqlplus command to mount the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def start_db(self,env_dict): + """ + startup the database + """ + file="/home/oracle/startUp.sh" + if not os.path.isfile(file): + self.log_info_message("Inside start_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup; + ''' + self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + else: + cmd='''sh {0}'''.format(file) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + def nomount_db(self,env_dict): + """ + No mount the database + """ + self.log_info_message("Inside start_db()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) + sqlcmd=''' + startup nomount; + ''' + self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def stop_gsm(self,env_dict): + """ + Stop the GSM + """ + self.log_info_message("Inside stop_gsm()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + gsmcmd=''' + stop gsm; + ''' + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + + def set_events(self,source): + """ + Seting events at DB level + """ + scope='' + accepted_scope = ['spfile', 'memory', 'both'] + + if self.check_key("DB_EVENTS",self.ora_env_dict): + events=str(self.ora_env_dict["DB_EVENTS"]).split(";") + + for event in events: + msg='''Setting up event {0}'''.format(event) + self.log_info_message(msg,self.file_name) + scope='' + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + source=event.split(":") + if len(source) > 1: + if source[1].split("=")[0] == "scope": + scope=source[1].split("=")[1] + + if scope not in accepted_scope: + sqlcmd=""" + alter system set events='{0}';""".format(source[0]) + else: + sqlcmd=""" + alter system set event='{0}' scope={1};""".format(source[0],scope) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + + def start_gsm(self,env_dict): + """ + Start the GSM + """ + self.log_info_message("Inside start_gsm()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + gsmcmd=''' + start gsm; + ''' + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + + def exec_gsm_cmd(self,gsmcmd,flag,env_dict): + """ + Get the GSM command output + """ + self.log_info_message("Inside exec_gsm_cmd()",self.file_name) + gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) + if gsmcmd: + output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) + self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) + self.check_sql_err(output,error,retcode,flag) + else: + self.log_info_message("GSM Command was set to empty. Executing nothing and setting output to None",self.file_name) + output=None + + return output,error,retcode + + + def check_substr_match(self,source_str,sub_str): + """ + CHeck if substring exist + """ + self.log_info_message("Inside check_substr_match()",self.file_name) + if (source_str.find(sub_str) != -1): + return True + else: + return False + + def find_str_in_string(self,source_str,delimeter,search_str): + """AI is creating summary for find_str_in_string + + Args: + source_str ([string]): [string where you need to search] + delimeter ([character]): [string delimeter] + search_str ([string]): [string to be searched] + """ + if delimeter == 'comma': + new_str=source_str.split(',') + for str in new_str: + if str.lower() == search_str.lower(): + return True + return False + + return False + + def check_status_value(self,match): + """ + return completed or notcompleted + """ + self.log_info_message("Inside check_status_value()",self.file_name) + if match: + return 'completed' + else: + return 'notcompleted' + + def remove_file(self,fname): + """ + Remove if file exist + """ + self.log_info_message("Inside remove_file()",self.file_name) + if os.path.exists(fname): + os.remove(fname) + + def get_sid_desc(self,gdbname,ohome,sid,sflag): + """ + get the SID_LISTENER_DESCRIPTION + """ + self.log_info_message("Inside get_sid_desc()",self.file_name) + sid_desc = "" + if sflag == 'SID_DESC1': + sid_desc = ''' ) + (SID_DESC = + (GLOBAL_DBNAME = {0}) + (ORACLE_HOME = {1}) + (SID_NAME = {2}) + ) + ) + '''.format(gdbname,ohome,sid) + elif sflag == 'SID_DESC': + sid_desc = '''(SID_LIST = + (SID_DESC = + (GLOBAL_DBNAME = {0}) + (ORACLE_HOME = {1}) + (SID_NAME = {2}) + ) + ) + '''.format(gdbname,ohome,sid) + else: + pass + + return sid_desc + + def get_lisora(self,port): + """ + return listener.ora listener settings + """ + self.log_info_message("Inside get_lisora()",self.file_name) + listener='''LISTENER = + (DESCRIPTION_LIST = + (DESCRIPTION = + (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = {0})) + (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC{0})) + ) + ) + '''.format(port) + return listener + + def get_domain(self,ohost): + """ + get the domain name from hostname + """ + return ohost.partition('.')[2] + +######### Get the DOMAIN############## + def get_host_domain(self): + """ + Return Public Hostname + """ + domain=None + domain=socket.getfqdn().split('.',1)[1] + if domain is None: + domain="example.info" + + return domain + + ######### get the public IP ############## + def get_ip(self,hostname,domain): + """ + Return the Ip based on hostname + """ + if not domain: + domain=self.get_host_domain() + + return socket.gethostbyname(hostname) + + def get_global_dbdomain(self,ohost,gdbname): + """ + get the global dbname + """ + domain = self.get_domain(ohost) + if domain: + global_dbname = gdbname + domain + else: + global_dbname = gdbname + + return gdbname + +######### Sqlplus connect string ########### + def get_sqlplus_str(self,home,osid,dbuser,password,hostname,port,svc,osep,role,wallet): + """ + return the sqlplus connect string + """ + path='''/usr/bin:/bin:/sbin:/usr/local/sbin:{0}/bin'''.format(home) + ldpath='''{0}/lib:/lib:/usr/lib'''.format(home) + export_cmd='''export ORACLE_HOME={0};export PATH={1};export LD_LIBRARY_PATH={2};export ORACLE_SID={3}'''.format(home,path,ldpath,osid) + if dbuser == 'sys' and password and hostname and port and svc: + return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4} as sysdba'''.format(dbuser,password,hostname,port,svc,export_cmd,home) + elif dbuser != 'sys' and password and hostname and svc: + return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4}'''.format(dbuser,password,hostname,"1521",svc,export_cmd,home) + elif dbuser and osep: + return dbuser + elif dbuser == 'sys' and not password: + return '''{1};{0}/bin/sqlplus "/ as sysdba"'''.format(home,export_cmd) + elif dbuser == 'sys' and password: + return '''{1};{0}/bin/sqlplus {2}/{3} as sysdba'''.format(home,export_cmd,dbuser,password) + elif dbuser != 'sys' and password: + return '''{1};{0}/bin/sqlplus {2}/{3}'''.format(home,export_cmd,dbuser,password) + else: + self.log_info_message("Atleast specify db user and password for db connectivity. Exiting...",self.file_name) + self.prog_exit("127") + +######### Get Password ############## + def get_os_password(self): + """ + get the OS password + """ + ospasswd=self.get_password(None) + return ospasswd + + def get_asm_passwd(self): + """ + get the ASM password + """ + asmpasswd=self.get_password(None) + return asmpasswd + + def get_db_passwd(self): + """ + get the DB password + """ + dbpasswd=self.get_password(None) + return dbpasswd + + def get_sys_passwd(self): + """ + get the sys user password + """ + dbpasswd=self.get_password(None) + return dbpasswd + + def get_password(self,key): + """ + get the password + """ + passwd_file_flag=False + password=None + password_file=None + if self.check_key("SECRET_VOLUME",self.ora_env_dict): + self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["SECRET_VOLUME"]) + msg='''SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) + else: + self.ora_env_dict=self.add_key("SECRET_VOLUME","/run/secrets",self.ora_env_dict) + msg='''SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("KEY_SECRET_VOLUME",self.ora_env_dict): + self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["KEY_SECRET_VOLUME"]) + msg='''KEY_SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + else: + if self.check_key("SECRET_VOLUME",self.ora_env_dict): + self.ora_env_dict=self.add_key("KEY_SECRET_VOLUME",self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict) + msg='''KEY_SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict): + msg='''COMMON_OS_PWD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) + else: + self.ora_env_dict=self.add_key("COMMON_OS_PWD_FILE","common_os_pwdfile.enc",self.ora_env_dict) + msg='''COMMON_OS_PWD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("PWD_KEY",self.ora_env_dict): + msg='''PWD_KEY passed as an env variable and set to {0}'''.format(self.ora_env_dict["PWD_KEY"]) + else: + self.ora_env_dict=self.add_key("PWD_KEY","pwd.key",self.ora_env_dict) + msg='''PWD_KEY not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PWD_KEY"]) + self.log_warn_message(msg,self.file_name) + + if self.check_key("PASSWORD_FILE",self.ora_env_dict): + msg='''PASSWORD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) + else: + self.ora_env_dict=self.add_key("PASSWORD_FILE","dbpasswd.file",self.ora_env_dict) + msg='''PASSWORD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) + self.log_warn_message(msg,self.file_name) + + secret_volume = self.ora_env_dict["SECRET_VOLUME"] + key_secret_volume= self.ora_env_dict["KEY_SECRET_VOLUME"] + common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"] + pwd_volume=None + if self.check_key("PWD_VOLUME",self.ora_env_dict): + pwd_volume=self.ora_env_dict["PWD_VOLUME"] + else: + pwd_volume="/var/tmp" + pwd_key = self.ora_env_dict["PWD_KEY"] + passwd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) + dbpasswd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["PASSWORD_FILE"]) + key_file='''{0}/{1}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"],self.ora_env_dict["PWD_KEY"]) + key_secret_volume='''{0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) + self.log_info_message("Password file set to : " + passwd_file,self.file_name) + self.log_info_message("key file set to : " + key_file,self.file_name) + self.log_info_message("dbpasswd file set to : " + dbpasswd_file,self.file_name) + self.log_info_message("key secret voluem set to file set to : " + key_secret_volume,self.file_name) + self.log_info_message("pwd volume set : " + pwd_volume,self.file_name) + #print(passwd_file) + if (os.path.isfile(passwd_file)) and (os.path.isfile(key_file)): + msg='''Passwd file {0} and key file {1} exist. Password file Check passed!'''.format(passwd_file,key_file) + self.log_info_message(msg,self.file_name) + msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file) + self.log_info_message(msg,self.file_name) + cmd=None + if self.check_key("ENCRYPTION_TYPE",self.ora_env_dict): + if self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "aes256": + cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out {2}/{1} -pass file:\"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + elif self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "rsautl": + cmd ='''openssl rsautl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + else: + pass + else: + cmd ='''openssl pkeyutl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) + + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + passwd_file_flag = True + password_file='''{0}/{1}'''.format(pwd_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) + elif os.path.isfile(dbpasswd_file): + msg='''Passwd file {0} exist. Password file Check passed!'''.format(dbpasswd_file) + self.log_info_message(msg,self.file_name) + msg='''Reading encrypted passwd from file {0}.'''.format(dbpasswd_file) + self.log_info_message(msg,self.file_name) + cmd='''openssl base64 -d -in \"{0}\" -out \"{2}/{1}\"'''.format(dbpasswd_file,self.ora_env_dict["PASSWORD_FILE"],pwd_volume) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + passwd_file_flag = True + password_file='''{1}/{0}'''.format(self.ora_env_dict["PASSWORD_FILE"],pwd_volume) + + if not passwd_file_flag: + # get random password pf length 8 with letters, digits, and symbols + characters1 = string.ascii_letters + string.digits + "_-%#" + str1 = ''.join(random.choice(string.ascii_uppercase) for i in range(4)) + str2 = ''.join(random.choice(characters1) for i in range(8)) + password=str1+str2 + else: + fname='''{0}'''.format(password_file) + fdata=self.read_file(fname) + password=fdata + self.remove_file(fname) + + if self.check_key("ORACLE_PWD",self.ora_env_dict): + if len(self.ora_env_dict["ORACLE_PWD"]) > 0: + msg="ORACLE_PWD is passed as an env variable. Check Passed!" + self.log_info_message(msg,self.file_name) + else: + msg="ORACLE_PWD passed as 0 length string" + self.log_info_message(msg,self.file_name) + self.ora_env_dict=self.update_key("ORACLE_PWD",password,self.ora_env_dict) + msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file" + self.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.add_key("ORACLE_PWD",password,self.ora_env_dict) + msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file" + self.log_info_message(msg,self.file_name) + +######### Get oraversion ############## + def get_oraversion(self,home): + """ + get the software version + """ + cmd='''{0}/bin/oraversion -majorVersion'''.format(home) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + + return output + +####### Get db lock file location ####### + def get_db_lock_location(self): + """ + get the db location + """ + if self.check_key("DB_LOCK_FILE_LOCATION",self.ora_env_dict): + return self.ora_env_dict["DB_LOCK_FILE_LOCATION"] + else: + ### Please note that you should not change following path as SIDB team is maintaining lock files under following location + return "/tmp/." + +####### Get the TDE Key ############### + def export_tde_key(self,filename): + """ + This function export the tde. + """ + self.log_info_message("Inside gettdekey()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + ALTER SESSION DISABLE SHARD DDL; + ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET {0} TO {1} IDENTIFIED BY {0}; + '''.format('HIDDEN_STRING',filename) + self.log_info_message("Running the sqlplus command to export the tde: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + +####### Get the TDE Key ############### + def import_tde_key(self,filename): + """ + This function import the TDE key. + """ + self.log_info_message("Inside importtdekey()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY {0}; + ADMINISTER KEY MANAGEMENT IMPORT ENCRYPTION KEYS WITH SECRET {0} FROM {1} IDENTIFIED BY {0} WITH BACKUP + '''.format('HIDDEN_STRING',filename) + self.log_info_message("Running the sqlplus command to import the tde key: " + sqlcmd,self.file_name) + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,True) + +####### Check PDB if it exist ############### + def check_pdb(self,pdbname): + """ + This function check the PDB. + """ + self.log_info_message("Inside check_pdb()",self.file_name) + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + sqlcmd=''' + set heading off + set feedback off + select NAME from gv$pdbs; + ''' + output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.check_sql_err(output,error,retcode,None) + pdblist=output.splitlines() + self.log_info_message("Checking pdb " + pdbname, self.file_name) + if pdbname in pdblist: + return True + else: + return False + +####### Create PDB if it does not exist ############### + def create_pdb(self,ohome,opdb,inst_sid): + """ + This function create the PDB. + """ + self.log_info_message("Inside create_pdb()",self.file_name) + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd='''{0}/bin/dbca -silent -createPluggableDatabase -pdbName {1} -sourceDB {2} <<< HIDDEN_STRING'''.format(ohome,opdb,inst_sid) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.unset_mask_str() + self.check_os_err(output,error,retcode,True) + + + +####### Create PDB tnsnames.ora entry ############### + def create_pdb_tns_entry(self,ohome,opdb): + """ + This function create the PDB tnsnames.ora entry. + """ + self.log_info_message("Inside create_pdb_tns_entry()",self.file_name) + tns_entry_string=""" +{0} = + (DESCRIPTION = + (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521)) + (CONNECT_DATA = + (SERVER = DEDICATED) + (SERVICE_NAME = {0}) + ) + ) + +""".format(opdb) + + tns_file='''{0}/network/admin/tnsnames.ora'''.format(ohome) + self.append_file(tns_file,tns_entry_string) + +######## Reset the DB Password in database ######## + def reset_passwd(self): + """ + This function reset the password. + """ + password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh") + self.log_info_message("Executing password reset", self.file_name) + if self.check_key("ORACLE_PWD",self.ora_env_dict) and self.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script): + cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING') + self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + output,error,retcode=self.execute_cmd(cmd,None,None) + self.check_os_err(output,error,retcode,True) + self.unset_mask_str() + else: + msg='''Error Occurred! Either HOME DIR {0} does not exist, ORACLE_PWD {1} is not set or PASSWORD SCRIPT {2} does not exist'''.format(self.ora_env_dict["HOME"],self.ora_env_dict["ORACLE_PWD"],password_script) + self.log_error_message(msg,self.file_name) + self.oracommon.prog_exit() diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oraenv.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oraenv.py new file mode 100755 index 0000000..dd96c48 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oraenv.py @@ -0,0 +1,139 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file read the env variables from a file or using env command and populate them in variable +""" + +import os + +class OraEnv: + __instance = None + __env_var_file = '/etc/rac_env_vars' + + __env_var_file_flag = None + __env_var_dict = {} + __ora_asm_diskgroup_name = '+DATA' + __ora_gimr_flag = 'false' + __ora_grid_user = 'grid' + __ora_db_user = 'oracle' + __ora_oinstall_group_name = 'oinstall' + encrypt_str__ = None + original_str__ = None + logdir__ = "/tmp/sharding" + + def __init__(self): + """ Virtually private constructor. """ + if OraEnv.__instance != None: + raise Exception("This class is a singleton!") + else: + OraEnv.__instance = self + OraEnv.read_variable() + OraEnv.add_variable() + try: + os.mkdir(OraEnv.logdir__) + except OSError as error: + pass + + @staticmethod + def get_instance(): + """ Static access method. """ + if OraEnv.__instance == None: + OraEnv() + return OraEnv.__instance + + @staticmethod + def read_variable(): + """ Read the variables from a file into dict """ + if OraEnv.__env_var_file_flag: + with open(OraEnv.__env_var_file) as envfile: + for line in envfile: + name, var = line.partition("=")[::2] + OraEnv.__env_var_dict[name.strip()] = var + else: + OraEnv.__env_var_dict = os.environ + + @staticmethod + def add_variable(): + """ Add more variable ased on enviornment with default values in __env_var_dict""" + OraEnv.__env_var_dict["GSM_LOCK_STATUS_FILE"] = "/tmp/.gsm_status_lock_file" + OraEnv.__env_var_dict["SHARD_LOCK_STATUS_FILE"] = "/tmp/.shard_status_lock_file" + if "ORA_ASM_DISKGROUP_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_ASM_DISKGROUP_NAME"] = "+DATA" + + if "ORA_GRID_USER" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_GRID_USER"] = "grid" + + if "ORA_DB_USER" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_DB_USER"] = "oracle" + + if "ORA_OINSTALL_GROUP_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["ORA_OINSTALL_GROUP_NAME"] = "oinstall" + + @staticmethod + def add_custom_variable(key,val): + """ Addcustom more variable passed from main.py values in __env_var_dict""" + if key not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict[key] = val + + @staticmethod + def get_env_vars(): + """ Static access method to get the env vars. """ + return OraEnv.__env_var_dict + + @staticmethod + def update_env_vars(env_dict): + """ Static access method to get the env vars. """ + OraEnv.__env_var_dict = env_dict + + @staticmethod + def logfile_name(file_type): + """ Static access method to return the logfile name. """ + if file_type == "NONE": + if "LOGFILE_NAME" not in OraEnv.__env_var_dict: + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/oracle_sharding_setup.log" + elif file_type == "ADD_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_addition.log" + elif file_type == "VALIDATE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_validation.log" + elif file_type == "REMOVE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_remove.log" + elif file_type == "CHECK_LIVENESS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkliveness.log" + elif file_type == "CHECK_READYNESS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkreadyness.log" + elif file_type == "RESET_LISTENER": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_listener.log" + elif file_type == "RESTART_DB": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/restart_db.log" + elif file_type == "CREATE_DIR": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/create_dir.log" + elif file_type == "ADD_SGROUP_PARAMS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/add_sgroup.log" + elif file_type == "DEPLOY_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/deploy_shard.log" + elif file_type == "CANCEL_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/cancel_chunk.log" + elif file_type == "MOVE_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/move_chunks.log" + elif file_type == "CHECK_CHUNKS": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_chunks.log" + elif file_type == "CHECK_ONLINE_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_online_shard.log" + elif file_type == "CHECK_GSM_SHARD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_gsm_shard.log" + elif file_type == "INVITED_NODE_OP": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/node_invited_op.log" + elif file_type == "RESET_PASSWD": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_passwd_file.log" + elif file_type == "TDE_KEY": + OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/tde_key.log" + else: + pass + + return OraEnv.__env_var_dict["LOG_FILE_NAME"] diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orafactory.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orafactory.py new file mode 100755 index 0000000..5ddb6e3 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orafactory.py @@ -0,0 +1,115 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file contains to the code call different classes objects based on setup type +""" + +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +from orapshard import * +from orasshard import * +from orapcatalog import * +from oragsm import * + +import os +import sys + +class OraFactory: + """ + This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def get_ora_objs(self): + ''' + Return the instance of a classes which will setup the enviornment. + + Returns: + ofactory_obj: List of objects + ''' + ofactory_obj = [] + + msg='''ora_env_dict set to : {0}'''.format(self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + msg="Checking the OP_TYPE and Version to begin the installation" + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the OP_TYPE + if self.ocommon.check_key("OP_TYPE",self.ora_env_dict): + msg='''OP_TYPE variable is set to {0}.'''.format(self.ora_env_dict["OP_TYPE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("OP_TYPE","nosetup",self.ora_env_dict) + msg="OP_TYPE variable is set to default nosetup. No value passed as an enviornment variable." + self.ocommon.log_info_message(msg,self.file_name) + + # Check the OP_TYPE value and call objects based on it value + if self.ora_env_dict["OP_TYPE"] == 'primaryshard': + msg="Creating and calling instance to setup primary shard" + opshard = OraPShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(opshard) + elif self.ora_env_dict["OP_TYPE"] == 'standbyshard': + msg="Creating and calling instance to setup standby shard" + osshard = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(osshard) + elif self.ora_env_dict["OP_TYPE"] == 'catalog': + msg="Creating and calling instance to setup Catalog DB" + opcat = OraPCatalog(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(opcat) + elif self.ora_env_dict["OP_TYPE"] == 'standbycatalog': + msg="Creating and calling instance to setup Catalog DB" + oscat = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(oscat) + elif self.ora_env_dict["OP_TYPE"] == 'gsm': + msg="Creating and calling instance to setup GSM" + ogsm = OraGSM(self.ologger,self.ohandler,self.oenv,self.ocommon) + self.ocommon.log_info_message(msg,self.file_name) + ofactory_obj.append(ogsm) + else: + msg="OP_TYPE must be set to {primaryshard|standbyshard|catalog|standbycatalog|gsm}" + self.ocommon.log_info_message(msg,self.file_name) + msg="Since OP_TYPE is set to nosetup, only compute env is being setup. Creating and calling instance to setup compute." + self.ocommon.log_info_message(msg,self.file_name) + omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + ofactory_obj.append(omachine) + + return ofactory_obj diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oragsm.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oragsm.py new file mode 100755 index 0000000..ef0bb06 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oragsm.py @@ -0,0 +1,2945 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +import os +import sys +import os.path +import re +import socket +import random +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +class OraGSM: + """ + This calss setup the Gsm after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraGsm class to setup the Gsm on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def setup(self): + """ + This function setup the Gsm on Primary DB. + """ + if self.ocommon.check_key("ADD_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.add_gsm_shard() + self.set_hostid_null() + self.add_invited_node("ADD_SHARD") + self.remove_invited_node("ADD_SHARD") + sys.exit(0) + if self.ocommon.check_key("DEPLOY_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.deploy_shard() + self.setup_gsm_service() + sys.exit(0) + elif self.ocommon.check_key("ADD_SGROUP_PARAMS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_gsm_shardg("ADD_SGROUP_PARAMS") + sys.exit(0) + elif self.ocommon.check_key("ADD_SSPACE_PARAMS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_gsm_sspace("ADD_SSPACE_PARAMS") + sys.exit(0) + elif self.ocommon.check_key("REMOVE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + status=self.remove_gsm_shard() + + if status: + sys.exit(0) + else: + sys.exit(1) + + elif self.ocommon.check_key("MOVE_CHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.move_shard_chunks() + sys.exit(0) + elif self.ocommon.check_key("TDE_KEY",self.ora_env_dict): + self.ocommon.get_tde_key() + sys.exit(0) + elif self.ocommon.check_key("CANCEL_CHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.cancel_move_chunks() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_NOCHUNKS",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.validate_nochunks() + sys.exit(0) + elif self.ocommon.check_key("CHECK_ONLINE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.verify_online_shard() + sys.exit(0) + elif self.ocommon.check_key("CHECK_GSM_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.verify_gsm_shard() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_SHARD",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.validate_gsm_shard() + sys.exit(0) + elif self.ocommon.check_key("VALIDATE_GSM",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + sys.exit(0) + elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + if os.path.exists(filename): + self.ocommon.log_info_message("provisioning is still in progress as file " + filename + " still exist!",self.file_name) + sys.exit(0) + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + status = self.check_gsm_director_status(None) + if not status: + self.ocommon.log_info_message("No GDS setup found on this system.",self.file_name) + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("GSM liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("INVITED_NODE_OP",self.ora_env_dict): + self.catalog_checks() + status = self.catalog_setup_checks() + if not status: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.ocommon.prog_exit("127") + else: + self.invited_node_op() + sys.exit(0) + elif self.ocommon.check_key("CATALOG_SETUP",self.ora_env_dict): + # If user pass env avariable CATALOG_SETUP true then it will just create gsm director and add catalog but will not add any shard + # It will also add service + status = self.catalog_setup_checks() + if status == False: + self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) + self.setup_machine() + self.catalog_checks() + self.reset_gsm_setup() + status1 = self.gsm_setup_check() + if status1: + self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) + self.start_gsm_director() + self.ocommon.log_info_message("Started GSM",self.file_name) + else: + # Perform Catalog setup after check GSM_MASTER FLAG. IF GSM MASTER FLAG is set then only catalog will be added. + self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) + master_flag=self.gsm_master_flag_check() + if master_flag: + self.setup_gsm_calog() + self.setup_gsm_director() + self.start_gsm_director() + self.status_gsm_director() + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': + self.setup_gsm_shardg("SHARD_GROUP") + else: + self.setup_gsm_shardg("SHARD_GROUP") + self.gsm_backup_file() + self.gsm_completion_message() + ### Running Custom Scripts + self.run_custom_scripts() + else: + self.add_gsm_director() + self.start_gsm_director() + self.gsm_backup_file() + self.gsm_completion_message() + else: + # This block run shard addition, catalog addition and service creation + # This block also verifies if master flag is not not GSM director then it will not create catalog but add GSM ony + self.setup_machine() + self.gsm_checks() + self.reset_gsm_setup() + status = self.gsm_setup_check() + if status: + self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) + self.start_gsm_director() + self.ocommon.log_info_message("Started GSM",self.file_name) + else: + # if the status = self.gsm_setup_check() return False then shard addition, catalog addition and service creation + master_flag=self.gsm_master_flag_check() + if master_flag: + self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) + self.setup_gsm_calog() + self.setup_gsm_director() + self.start_gsm_director() + self.status_gsm_director() + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': + self.setup_gsm_shardg("SHARD_GROUP") + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + self.setup_gsm_sspace("SHARD_SPACE") + else: + self.setup_gsm_shardg("SHARD_GROUP") + self.setup_gsm_shard() + self.set_hostid_null() + self.stop_gsm_director() + time.sleep(30) + self.start_gsm_director() + self.add_invited_node("SHARD") + self.remove_invited_node("SHARD") + self.stop_gsm_director() + time.sleep(30) + self.start_gsm_director() + self.deploy_shard() + self.setup_gsm_service() + self.setup_sample_schema() + self.gsm_backup_file() + self.gsm_completion_message() + ### Running Custom Scripts + self.run_custom_scripts() + else: + self.add_gsm_director() + self.start_gsm_director() + self.gsm_backup_file() + self.gsm_completion_message() + + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + filename = self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + touchfile = 'touch {0}'.format(filename) + if not os.path.isfile(filename): + self.ocommon.log_error_message("Setting file provisioning status file :" + filename ,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(touchfile,None,self.ora_env_dict) + if retcode == 1: + self.ocommon.log_error_message("error occurred while touching the file :" + filename + ". Exiting!",self.file_name) + self.ocommon.prog_exit("127") + + ########### ENDS here #################### + + def gsm_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.shard_user_check() + self.gsm_hostname_check() + self.director_params_checks() + self.catalog_params_check() + self.shard_params_check() + self.sgroup_params_check() + + + def catalog_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.shard_user_check() + self.gsm_hostname_check() + self.director_params_checks() + self.catalog_params_check() + self.sgroup_params_check() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit("127") + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def passwd_check(self): + """ + Set the password + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def shard_user_check(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def director_params_checks(self): + """ + This funnction check and set the shard director name + """ + status=False + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD Director PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + + def gsm_hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def catalog_params_check(self): + """ + This funnction check if CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''CATALOG PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + if stype: + if stype.lower() == 'user': + if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) + if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) + status=True + + if not status: + msg="CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is not set, exiting!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def shard_params_check(self): + """ + This funnction check if SHARD[1-9]_PARAMS such as SHARD1_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + + if not status: + msg="SHARD[1-9]_PARAMS such as SHARD1_PARAMS is not set, exiting!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def sgroup_params_check(self): + """ + This funnction check if SHARD[1-9]_GROUP_PARAMS such as SHARD1_GROUP_PARAMS is passed as an env variable or not. If not passed then exit. + """ + status=False + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + msg='''SHARD GROUP PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) + self.ocommon.log_info_message(msg,self.file_name) + status=True + def gsm_master_flag_check(self): + """ + This funnction check if MASTER_GSM is passed as an env variable or not. If not passed then exit. + """ + status=False + if self.ocommon.check_key("MASTER_GSM",self.ora_env_dict): + msg='''MASTER_GSM is set. This machine will be configured with as master GSM director.''' + self.ocommon.log_info_message(msg,self.file_name) + return True + else: + return False + + def catalog_setup_checks(self): + """ + This function checks if director and catalog is setup and connection is established. + """ + status = False + gsm_status = self.check_gsm_director(None) + #catalog_status = self.check_gsm_catalog() + + if gsm_status == 'completed': + status = True + else: + status = False + + #if catalog_status == 'completed': + # status = True + #else: + # status = False + + return status + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### + def reset_gsm_setup(self): + """ + This function delete the GSM files. + """ + self.ocommon.log_info_message("Inside reset_gsm_setup",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + cmd_list=[] + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + msg='''Deleteing files from {0}'''.format(gsmdata_loc) + self.ocommon.log_info_message(msg,self.file_name) + cmd_list[0]='''rm -f {0}/gsm.ora'''.format(gsmdata_loc) + cmd_list[1]='''rm -f {0}/tnsnames.ora'''.format(gsmdata_loc) + cmd_list[2]='''rm -rf {0}/wallets'''.format(gsmdata_loc) + for cmd in cmd_list: + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + def gsm_setup_check(self): + """ + This function check if GSM is already setup on this + """ + status=True + self.ocommon.log_info_message("Inside gsm_setup_check",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) + + gsmora='''{0}/gsm.ora'''.format(gsmdata_loc) + tnsnamesora='''{0}/tnsnames.ora'''.format(gsmdata_loc) + walletloc='''{0}/gsmwallet'''.format(gsmdata_loc) + + if os.path.isfile(gsmora): + cmd='''cp -r -v -f {0} {1}/'''.format(gsmora,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if os.path.isfile(tnsnamesora): + cmd='''cp -r -v -f {0} {1}/'''.format(tnsnamesora,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if os.path.isdir(walletloc): + cmd='''cp -r -v -f {0} {1}/'''.format(walletloc,gsmfile_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + else: + status=False + + if status: + return True + else: + return False + + #################### Catalog related Functions BEGINS Here ########################### + def setup_gsm_calog(self): + """ + This function setup the GSM catalog. + """ + self.ocommon.log_info_message("Inside setup_gsm_calog()",self.file_name) + status=False + reg_exp= self.catalog_regex() + counter=1 + end_counter=60 + catalog_db_status=None + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + catalog_db_status=self.check_setup_status(catalog_host,catalog_db,catalog_pdb,catalog_port) + if catalog_db_status == 'completed': + self.configure_gsm_clog(catalog_host,catalog_db,catalog_pdb,catalog_port,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname) + break + else: + msg='''Catalog Status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + if catalog_db_status == 'completed': + break + else: + msg='''Catalog setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + def process_clog_vars(self,key): + """ + This function process catalog vars based on key and return values to configure the GSM + """ + catalog_db=None + catalog_pdb=None + catalog_port=None + catalog_region=None + catalog_host=None + catalog_name=None + catalog_chunks=None + repl_type=None + repl_factor=None + repl_unit=None + stype=None + sspace=None + cfname=None + + self.ocommon.log_info_message("Inside process_clog_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'catalog_db': + catalog_db = cvar_dict[ckey] + if ckey == 'catalog_pdb': + catalog_pdb = cvar_dict[ckey] + if ckey == 'catalog_port': + catalog_port = cvar_dict[ckey] + if ckey == 'catalog_region': + catalog_region = cvar_dict[ckey] + if ckey == 'catalog_host': + catalog_host = cvar_dict[ckey] + if ckey == 'catalog_name': + catalog_name = cvar_dict[ckey] + if ckey == 'catalog_chunks': + catalog_chunks = cvar_dict[ckey] + if ckey == 'repl_type': + repl_type = cvar_dict[ckey] + if ckey == 'repl_factor': + repl_factor = cvar_dict[ckey] + if ckey == 'repl_unit': + repl_unit = cvar_dict[ckey] + if ckey == 'sharding_type': + stype = cvar_dict[ckey] + if ckey == 'shard_space': + sspace = cvar_dict[ckey] + if ckey == 'shard_configname': + cfname = cvar_dict[ckey] + + ## Set the values if not set in above block + if not catalog_port: + catalog_port=1521 + if not catalog_region: + catalog_region="region1,region2" + if stype: + if not sspace: + sspace="shardspace1,shardspace2" + + ### Check values must be set + if catalog_host and catalog_db and catalog_pdb and catalog_port and catalog_region and catalog_name: + return catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname + else: + msg1='''catalog_db={0},catalog_pdb={1}'''.format((catalog_db or "Missing Value"),(catalog_pdb or "Missing Value")) + msg2='''catalog_port={0},catalog_host={1}'''.format((catalog_port or "Missing Value"),(catalog_host or "Missing Value")) + msg3='''catalog_region={0},catalog_name={1}'''.format((catalog_region or "Missing Value"),(catalog_name or "Missing Value")) + msg='''Catalog params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def check_gsm_catalog(self): + """ + This function check the catalog status in GSM + """ + self.ocommon.log_info_message("Inside check_gsm_catalog()",self.file_name) + #dtrname,dtrport,dtregion=self.process_director_vars() + gsmcmd=''' + config; + exit; + '''.format("test") + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + match=self.ocommon.check_substr_match(matched_output[0],"test") + except: + match=False + return(self.ocommon.check_status_value(match)) + + # output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + # new_output=output[0].replace(" ","") + # self.ocommon.log_info_message(new_output,self.file_name) + # match=self.ocommon.check_substr_match(new_output,"Catalogconnectionisestablished") + # return(self.ocommon.check_status_value(match)) + + def catalog_regex(self): + """ + This function return the rgex to search the CATALOG PARAMS + """ + self.ocommon.log_info_message("Inside catalog_regex()",self.file_name) + return re.compile('CATALOG_PARAMS') + + + def configure_gsm_clog(self,chost,ccdb,cpdb,cport,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname): + """ + This function configure the GSM catalog. + """ + self.ocommon.log_info_message("Inside configure_gsm_clog()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + replist=['native'] + + ### User Define Shardig Variables + shardingtype=None + shardspace=None + configname=None + + # if stype and sspace: + if stype: + if stype.lower() == 'user': + shardingtype="-sharding user" + #shardspace="" + shardspace=" -shardspace {0}".format(sspace) + if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) + if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): + self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) + else: + shardspace="" + shardingtype="" + else: + shardspace="" + shardingtype="" + + if cfname: + configname=" -configname {0}".format(cfname) + else: + configname="" + + ### SNR Sharding + chunks=None + repl=None + repfactor=None + repunits=None + + if catalog_chunks: + chunks="-chunks {0}".format(catalog_chunks) + else: + chunks="" + + if repl_type and repl_type.lower() in replist: + self.ocommon.log_info_message("Repl_Type value Set to in block1:" + repl_type,self.file_name) + repl=" -repl {0}".format(repl_type) + else: + repl="" + + if repl_factor: + repfactor=" -repfactor {0}".format(repl_factor) + else: + repfactor="" + + if repl_unit: + repunits=" -repunits {0}".format(repl_unit) + else: + repunits="" + + invited_subnet="" + add_invited_subnet="" + if self.ocommon.check_key("INVITED_NODE_SUBNET_FLAG",self.ora_env_dict): + if self.ocommon.check_key("INVITED_NODE_SUBNET",self.ora_env_dict): + invited_subnet=self.ora_env_dict["INVITED_NODE_SUBNET"] + else: + #self.ocommon.log_info_message("The catalog Host name is :" + chost,self.file_name) + chost_ip=self.ocommon.get_ip(chost,None) + ip_parts=chost_ip.split('.') + invited_subnet=ip_parts[0] + "." + ip_parts[1] + '.*' + '.*' + add_invited_subnet='''add invitedsubnet {0};'''.format(invited_subnet) + + cpasswd="HIDDEN_STRING" + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})))\" {7} -user {3}/{4} -sdb {5} -region {6} -agent_port 8080 -agent_password {4} {8} {9} {10} {11} {12} {13} -autovncr off; + add invitednode {0}; + {14} + exit; + '''.format(chost,cport,cpdb,cadmin,cpasswd,catalog_name,catalog_region,chunks,repl,repfactor,repunits,shardingtype,shardspace,configname,add_invited_subnet) + + counter=1 + while counter < 5: + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + if retcode != 0: + self.ocommon.log_info_message("Error occurred while creating the shard catalog, sleeping for 60 seconds",self.file_name) + counter = counter + 1 + time.sleep(60) + else: + break + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ######################################## GSM director Functions Begins Here ##################### + def process_director_vars(self,key): + """ + This function process GSM director vars based on key and return values to configure the GSM + """ + dtrname=None + dtrport=None + dtregion=None + + self.ocommon.log_info_message("Inside process_director_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'director_name': + dtrname = cvar_dict[ckey] + if ckey == 'director_port': + dtrport = cvar_dict[ckey] + if ckey == 'director_region': + dtregion = cvar_dict[ckey] + + ### Check values must be set + if dtrname and dtrport and dtregion: + return dtrname,dtrport,dtregion + else: + msg1='''director_name={0},director_port={1}'''.format((dtrname or "Missing Value"),(dtrport or "Missing Value")) + msg2='''director_region={0}'''.format((dtregion or "Missing Value")) + msg='''Director params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_gsm_director(self,dname): + """ + This function check the GSM director status + """ + self.ocommon.log_info_message("Inside check_gsm_director()",self.file_name) + status=False + if dname: + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(matched_output[0],dname): + status=True + except: + status=False + else: + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(matched_output[0],dname): + status=True + except: + status=False + + return(self.ocommon.check_status_value(status)) + + def check_gsm_region(self,region): + """ + This function check the GSM regions + """ + self.ocommon.log_info_message("Inside check_gsm_region()",self.file_name) + gsmcmd=self.get_gsm_config_cmd(None) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Regions\n)(?:.+\n)+",output) + status=False + try: + if self.ocommon.check_substr_match(matched_output[0],region): + status=True + except: + status=False + return(self.ocommon.check_status_value(status)) + + def check_gsm_shardspace(self,sspace): + """ + This function check the GSM shardspace + """ + self.ocommon.log_info_message("Inside check_gsm_shardspace()",self.file_name) + gsmcmd=self.get_gsm_config_cmd(None) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard spaces\n)(?:.+\n)+",output) + status=False + try: + if self.ocommon.check_substr_match(matched_output[0],sspace): + status=True + except: + status=False + return(self.ocommon.check_status_value(status)) + + def check_gsm_director_status(self,dname): + """ + This function check the GSM director status using 'gdsctl status' + """ + self.ocommon.log_info_message("Inside check_gsm_director_status()",self.file_name) + status=False + gsmcmd=''' + status; + exit; + ''' + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + if "Connected to GDS catalog Y".replace(" ","").lower() in output.replace(" ","").lower(): + return True + else: + return False + + def add_gsm_director(self): + """ + This function add the GSM + """ + status=False + counter=1 + end_counter=60 + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + reg_exp= self.director_regex() + + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_director_status=None + dtrname,dtrport,dtregion=self.process_director_vars(key) + shard_director_status=self.check_gsm_director(dtrname) + if shard_director_status != 'completed': + self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) + status = self.check_gsm_director(None) + if status == 'completed': + break + + if status == 'completed': + break + else: + msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + status = self.check_gsm_director(None) + if status == 'completed': + msg='''Shard director setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 60 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def setup_gsm_director(self): + """ + This function setup in GSM + """ + self.ocommon.log_info_message("Inside setup_gsm_director()",self.file_name) + status=False + reg_exp= self.director_regex() + counter=1 + end_counter=3 + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_director_status=None + dtrname,dtrport,dtregion=self.process_director_vars(key) + shard_director_status=self.check_gsm_director(dtrname) + if shard_director_status != 'completed': + self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) + status = self.check_gsm_director(None) + if status == 'completed': + break + else: + msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + time.sleep(60) + counter=counter+1 + + status = self.check_gsm_director(None) + if status == 'completed': + msg='''Shard director setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 3 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin): + """ + This function configure GSM director + """ + ## Getting the values of catalog_port,catalog_pdb,catalog_host + cpasswd="HIDDEN_STRING" + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sregionFlag=self.check_gsm_region(dtregion) + if sregionFlag != 'completed': + self.configure_gsm_region(dtregion) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + add gsm -gsm {0} -listener {1} -pwd {2} -catalog {3}:{4}/{5} -region {6}; + exit; + '''.format(dtrname,dtrport,cpasswd,catalog_host,catalog_port,catalog_pdb,dtregion,gsmhost) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def start_gsm_director(self): + """ + This function start the director in the GSM + """ + status='noval' + self.ocommon.log_info_message("Inside start_gsm_director() function",self.file_name) + reg_exp= self.director_regex() + counter=1 + end_counter=10 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=''' + start gsm -gsm {0}; + exit; + '''.format(dtrname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + status=self.check_gsm_director(dtrname) + if status == 'completed': + break; + if status == 'completed': + filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] + remfile='''rm -f {0}'''.format(filename) + if os.path.isfile(filename): + output,error,retcode=self.ocommon.execute_cmd(remfile,None,self.ora_env_dict) + break + else: + msg='''GSM shard director failed to start.Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_error_message(msg,self.file_name) + time.sleep(30) + + counter=counter+1 + + + if status != 'completed': + msg='''GSM shard director failed to start.Exiting!''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def stop_gsm_director(self): + """ + This function stop the director in the GSM + """ + status=False + self.ocommon.log_info_message("Inside stop_gsm_director() function",self.file_name) + reg_exp= self.director_regex() + counter=1 + end_counter=2 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + gsmcmd=''' + stop gsm -gsm {0}; + exit; + '''.format(dtrname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + counter=counter+1 + + def status_gsm_director(self): + """ + This function check the GSM director status + """ + gsm_status = self.check_gsm_director(None) + #catalog_status = self.check_gsm_catalog() + + if gsm_status == 'completed': + msg='''Director setup completed in GSM and catalog is connected''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard director in GSM did not complete or not connected to catalog. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + ######################################## Shard Group Setup Begins Here ############################ + def setup_gsm_shardg(self,restype): + """ + This function setup the shard group. + """ + self.ocommon.log_info_message("Inside setup_gsm_shardg()",self.file_name) + status=False + if restype == 'ADD_SGROUP_PARAMS': + reg_exp = self.add_shardg_regex() + elif restype == 'SHARD_GROUP': + reg_exp = self.shardg_regex() + else: + self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SGROUP_PARAMS or SHARD_GROUP key to create a shard group",self.file_name) + self.ocommon.log_warn_message("Since no key specified for ADD_SGROUP_PARAMS and SHARD_GROUP, shardgroup will be created during shard creation",self.file_name) + + sgListC=[] + sgListP=[] + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_group_status=None + self.ocommon.log_info_message("Key is set to : " + key,self.file_name) + group_name,deploy_as,group_region=self.process_shardg_vars(key) + self.ocommon.log_info_message("Name: " + group_name + "deploy_as" + deploy_as + "group_region" + group_region,self.file_name) + if group_name is not None: + if group_name not in sgListC: + dtrname=self.get_director_name(group_region) + shard_group_status=self.check_shardg_status(group_name,dtrname) + if shard_group_status != 'completed': + self.configure_gsm_shardg(group_name,deploy_as,group_region,'add') + shard_group_status = self.check_shardg_status(group_name,None) + if shard_group_status == 'completed': + sgListC.append(group_name) + if group_name in sgListP: + sgListP.remove(group_name) + else: + sgListP=sgListP.append(group_name) + time.sleep(30) + counter=counter + 1 + + if sgListP == []: + msg='''Shard group setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def get_director_name(self,region_name): + """ + This function get the director name based on the region + """ + self.ocommon.log_info_message("Inside get_director_name()",self.file_name) + status=False + director_name=None + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + director_name=dtrname + gsm_status = self.check_gsm_director(dtrname) + if gsm_status == 'completed': + status = True + else: + status = False + if dtregion == region_name: + break + if status: + if director_name: + return director_name + else: + self.ocommon.log_error_message("No director exist to match the region",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.log_error_message("Shard Director is not running!",self.file_name) + self.ocommon.prog_exit("127") + + def get_shardg_region_name(self,sgname): + """ + This function get the region name based on shard group name + """ + self.ocommon.log_info_message("Inside get_region_name()",self.file_name) + status=False + region_name=None + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + group_name,deploy_as,group_region=self.process_shardg_vars(key) + region_name=group_region + if sgname == group_name: + status=True + break + if status: + return region_name + else: + self.ocommon.log_error_message("No such shard group exist! exiting!",self.file_name) + self.ocommon.prog_exit("127") + + def process_shardg_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + group_name=None + deploy_as=None + group_region=None + + self.ocommon.log_info_message("Inside process_shardg_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'group_name': + group_name = cvar_dict[ckey] + if ckey == 'deploy_as': + deploy_as = cvar_dict[ckey] + if ckey == 'group_region': + group_region = cvar_dict[ckey] + + ### Check values must be set + if group_name and deploy_as and group_region: + return group_name,deploy_as,group_region + else: + msg1='''group_name={0},deploy_as={1}'''.format((group_name or "Missing Value"),(deploy_as or "Missing Value")) + msg2='''group_region={0}'''.format((group_region or "Missing Value")) + msg='''Shard group params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + + def check_shardg_status(self,group_name,dname): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_shardg_status()",self.file_name) + status=False + + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) + if self.ocommon.check_substr_match(matched_output[0],group_name): + status=True + else: + status=False + + ''' + else: + reg_exp= self.shardg_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + group_name,deploy_as,group_region=self.process_shardg_vars(key) + dname=self.get_director_name(group_region) + gsmcmd=self.get_gsm_config_cmd(dname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) + # match=re.search("(?i)(?m)"+group_name,matched_output) + if self.ocommon.check_substr_match(matched_output[0],group_name): + status=True + else: + status=False + ''' + + return(self.ocommon.check_status_value(status)) + +############################################# Director Related Block ############ + def get_director_name(self,region_name): + """ + This function get the director name based on the region + """ + self.ocommon.log_info_message("Inside get_director_name()",self.file_name) + status=False + director_name=None + reg_exp= self.director_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + dtrname,dtrport,dtregion=self.process_director_vars(key) + director_name=dtrname + gsm_status = self.check_gsm_director(dtrname) + if gsm_status == 'completed': + status = True + else: + status = False + if dtregion == region_name: + break + if status: + if director_name: + return director_name + else: + self.ocommon.log_error_message("No director exist to match the region",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.log_error_message("Shard Director is not running!",self.file_name) + self.ocommon.prog_exit("127") + +######## + + def get_gsm_config_cmd(self,dname): + """ + Get the GSM config command + """ + self.ocommon.log_info_message("Inside get_gsm_config_cmd()",self.file_name) + gsmcmd=''' + config; + exit; + '''.format("test") + return gsmcmd + + def director_regex(self): + """ + This function return the rgex to search the SHARD DIRECTOR PARAMS + """ + self.ocommon.log_info_message("Inside director_regex()",self.file_name) + return re.compile('SHARD_DIRECTOR_PARAMS') + + def shardg_regex(self): + """ + This function return the rgex to search the SHARD GROUP PARAMS + """ + self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) + return re.compile('SHARD[0-9]+_GROUP_PARAMS') + + def add_shardg_regex(self): + """ + This function return the rgex to search the SHARD GROUP PARAMS + """ + self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) + return re.compile('ADD_SGROUP_PARAMS') + + def configure_gsm_shardg(self,group_name,deploy_as,group_region,type): + """ + This function configure the Shard Group. + """ + self.ocommon.log_info_message("Inside configure_gsm_shardg()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + dtrname=self.get_director_name(group_region) + reg_exp= self.catalog_regex() + if type == 'modify': + cmd=''' modify shardgroup -shardgroup {0} '''.format(group_name) + else: + cmd=''' add shardgroup -shardgroup {0} '''.format(group_name) + + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + if repl_type: + cmd=cmd + " -region {0} ".format(group_region) + else: + cmd=cmd + " -deploy_as {0} -region {1} ".format(deploy_as,group_region) + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + exit; + '''.format("NA",cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + +############# Adding Shard Regions ############### + def configure_gsm_region(self,region): + """ + This function configure the Shard region. + """ + self.ocommon.log_info_message("Inside configure_gsm_region()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + add region -region {3}; + exit; + '''.format("NA",cadmin,cpasswd,region) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + +##################### Adding Shard Space ############### + def process_sspace_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + sspace=None + chunks=None + repfactor=None + repunits=None + protectedmode=None + self.ocommon.log_info_message("Inside process_sspace_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'sspace_name': + sspace = cvar_dict[ckey] + if ckey == 'chunks': + chunks = cvar_dict[ckey] + if ckey == 'repfactor': + repfactor = cvar_dict[ckey] + if ckey == 'repunits': + repunits = cvar_dict[ckey] + if ckey == 'protectedmode': + protectedmode = cvar_dict[ckey] + + ### Check values must be set + if sspace: + return sspace,chunks,repfactor,repunits,protectedmode + else: + msg1='''sspace={0}'''.format((sspace or "Missing Value")) + msg='''Shard space params {0} is not set correctly. One or more value is missing {1}'''.format(key,msg1) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def setup_gsm_sspace(self,restype): + """ + This function setup the shard sspace. + """ + self.ocommon.log_info_message("Inside setup_gsm_sspace()",self.file_name) + status=False + if restype == 'ADD_SSPACE_PARAMS': + reg_exp = self.add_shardg_regex() + elif restype == 'SHARD_SPACE': + reg_exp = self.shardg_regex() + else: + self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SSPACE_PARAMS or SHARD_SPACE key to create a shard space",self.file_name) + self.ocommon.log_warn_message("Since no ADD_SSPACE_PARAMS or SHARD_SPACE defined, shardspace will be created during shard creation",self.file_name) + counter=1 + ssListC=[] + ssListP=[] + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_space_status=None + sspace,chunks,repfactor,repuntis,protectedmode=self.process_sspace_vars(key) + if sspace is not None: + if sspace not in ssListC: + shard_sspace_status=self.check_gsm_shardspace(sspace) + if shard_sspace_status != 'completed': + self.configure_gsm_sspace(sspace,chunks,repfactor,repuntis,protectedmode,'add') + shard_space_status = self.check_gsm_shardspace(sspace) + if shard_sspace_status == 'completed': + ssListC.append(sspace) + if sspace in sgListP: + sgListP.remove(sspace) + else: + sgListP=sgListP.append(sspace) + time.sleep(30) + counter=counter + 1 + + if ssListP == []: + msg='''Shard space setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete shard space setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def configure_gsm_sspace(self,sspace,chunks,repfactor,repunits,protectedmode,type): + """ + This function configure the Shard Group. + """ + self.ocommon.log_info_message("Inside configure_gsm_sspace()",self.file_name) + cmd=None + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + if type == 'MODIFY': + cmd=''' modify shardspace -shardspace {0} '''.format(sspace) + else: + cmd=''' add shardspace -shardspace {0} '''.format(sspace) + if chunks is not None: + cmd = cmd + ''' -chunks {0}'''.format(chunks) + if repfactor: + cmd = cmd + ''' -repfactor {0}'''.format(repfactor) + if repunits is not None: + cmd = cmd + ''' -repunits {0}'''.format(repfactor) + if protectedmode is not None: + cmd = cmd + ''' -protectedmode {0}'''.format(protectedmode) + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + exit; + '''.format("NA",cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + #########################################Shard Function Begins Here ############################## + def setup_gsm_shard(self): + """ + This function setup and add shard in the GSM + """ + self.ocommon.log_info_message("Inside setup_gsm_shard()",self.file_name) + status=False + reg_exp= self.shard_regex() + counter=1 + end_counter=60 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,sregion,sspace=self.process_shard_vars(key) + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + if shard_db_status == 'completed': + self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,sregion,sspace) + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + status = self.check_shard_status(None) + if status == 'completed': + break + else: + msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + + status = self.check_shard_status(None) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 60 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def add_gsm_shard(self): + """ + This function add the shard in the GSM + """ + self.ocommon.log_info_message("Inside add_gsm_shard()",self.file_name) + status=False + reg_exp= self.add_shard_regex() + counter=1 + end_counter=3 + shard_name="none" + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + self.ocommon.log_info_message("Shard Status : " + shard_db_status,self.file_name) + if shard_db_status == 'completed': + self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,shard_region,shard_space) + counter2=1 + end_counter2=5 + while counter2 < end_counter2: + status1 = self.check_shard_status(shard_name) + if status1 == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + break + else: + msg='''Shard DB is still not added in GSM. Sleeping for 60 seconds''' + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter2=counter2+1 + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + status = self.check_shard_status(None) + if status == 'completed': + break + else: + msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + self.ocommon.log_info_message(msg,self.file_name) + time.sleep(60) + counter=counter+1 + status = self.check_shard_status(shard_name) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 3 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def remove_gsm_shard(self): + """ + This function remove the shard in the GSM + """ + self.ocommon.log_info_message("Inside remove_gsm_shard()",self.file_name) + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars("CATALOG_PARAMS") + numOfShards=self.count_online_shards() + status=False + reg_exp=self.remove_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db_status=None + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shardname_to_delete=shard_db + "_" + shard_pdb + if repl_type is not None: + if(repl_type.upper() == 'NATIVE'): + self.move_shards_leader_rus(shardname_to_delete) + leaderCount=self.count_leader_shards(shardname_to_delete) + if(numOfShards < 4 or leaderCount > 0): + msg='''ruType=[{0}]. NumofShards=[{1}]. LeaderCount=[{2}]. Ignoring remove of shard [{3}]'''.format(repl_type,numOfShards,leaderCount,shardname_to_delete) + self.ocommon.log_info_message(msg,self.file_name) + break + + self.move_shard_rus(shardname_to_delete,None,None) + while self.count_shard_rus(shardname_to_delete) > 0: + self.ocommon.log_info_message("Waiting for all the shard chunks to be moved.",self.file_name) + time.sleep(15) + + shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) + if shard_db_status == 'completed': + self.delete_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group) + status=True + else: + msg='''Shard db status must return completed but returned value is {0}'''.format(status) + self.ocommon.log_info_message(msg,self.file_name) + + return status + + def move_shards_leader_rus(self,shardname_to_delete): + """ + This function move the shard leader RUs + """ + shards=self.get_online_shards() + leader_ru=self.get_rus(shardname_to_delete) + all_ru=self.get_rus(None) + count=0 + target_shards=[] + value=0 + + if len(shards) == 0: + msg="""No Shard is online so no RU is available to be moved""" + self.ocommon.log_info_message(msg,self.file_name) + else: + for line in leader_ru: + value=None + count += 1 + cols=line.split() + if len(cols) > 0: + if cols[0].lower() == shardname_to_delete.lower(): + if cols[1].isdigit: + value = int(cols[1]) + else: + continue + + target_shards.clear() + for line1 in all_ru: + cols1=line1.split() + print(cols1) + if len(cols1) > 5: + if cols1[0].lower() != shardname_to_delete.lower() and cols1[1].isdigit and cols1[2].lower() == 'follower': + if value is not None: + if int(cols1[1]) == value: + target_shards.append(cols1[0]) + break + + for shard in shards: + if shard.lower() != shardname_to_delete.lower(): + if shard in target_shards: + msg="Shard_name= " + shard + " Status=True" + " Value = " + str(value) + self.ocommon.log_info_message(msg,self.file_name) + self.move_shard_rus(shardname_to_delete,shard,value) + + def move_shard_chunks(self): + """ + This function move the shard chunks + """ + self.ocommon.log_info_message("Inside move_shard_chunks()",self.file_name) + status=False + reg_exp= self.move_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + shard_num = self.count_online_shards() + online_shard = self.check_online_shard(shard_name) + if shard_num > 1 and online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + MOVE CHUNK -CHUNK ALL -SOURCE {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def validate_nochunks(self): + """ + This function check the chnunks + """ + self.ocommon.log_info_message("Inside validate_nochunks()",self.file_name) + status=False + reg_exp= self.move_nochunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + shard_num = self.count_online_shards() + online_shard = self.check_online_shard(shard_name) + if shard_num > 1 and online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config chunks -shard {0} + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + matched_output=re.findall("(?:Chunks\n)(?:.+\n)+",output) + if self.ocommon.check_substr_match(matched_output[0].lower(),shard_name.lower()): + self.ocommon.prog_exit("127") + + def move_chunks_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside move_chnuks_regex()",self.file_name) + return re.compile('MOVE_CHUNKS') + + def move_nochunks_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside move_nochunks_regex()",self.file_name) + return re.compile('VALIDATE_NOCHUNKS') + + def check_shard_chunks(self): + """ + This function check the shard chunks + """ + self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) + status=False + reg_exp= self.check_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 0 : + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config chunks -shard {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + + def check_chunks_regex(self): + """ + This function return the rgex to search the chunks + """ + self.ocommon.log_info_message("Inside check_chunks_regex()",self.file_name) + return re.compile('CHECK_CHUNKS') + + def cancel_move_chunks(self): + """ + This function cancel the shard Chunks + """ + self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) + status=False + reg_exp= self.cancel_chunks_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + move_chunks_status=None + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 1: + self.ocommon.log_info_message("Shard is not online. Performing chunk cancellation in GSM to set the shard chunk status.",self.file_name) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + ALTER MOVE -cancel -SHARD {0} + config shard; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + else: + self.ocommon.log_info_message("Shard " + shard_name + " is online. Unable to perform chunk cancellation.",self.file_name) + + def cancel_chunks_regex(self): + """ + This function return the cancel chunk movement + """ + self.ocommon.log_info_message("Inside cancel_chunks_regex()",self.file_name) + return re.compile('CANCEL_CHUNKS') + + def verify_online_shard(self): + """ + This function verify online shard + """ + self.ocommon.log_info_message("Inside verify_online_shard()",self.file_name) + status=False + reg_exp= self.online_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + online_shard = self.check_online_shard(shard_name) + if online_shard == 0: + msg='''Shard {0} is online.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} is not online.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + + def online_shard_regex(self): + """ + This function return the rgex to search the ONLINE Shards + """ + self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) + return re.compile('CHECK_ONLINE_SHARD') + + def check_online_shard(self,shard_name): + """ + This function check the online shard + """ + self.ocommon.log_info_message("Inside check_online_shard()",self.file_name) + name_flag = False + availability_flag = False + state_flag = False + status_flag = False + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config shard -shard {0}; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + lines = output.split("\n") + for line in lines: + list1 = line.split(":") + if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): + name_flag = True + if list1[0].strip().lower() == 'Availability'.lower() and list1[1].strip().lower() == 'ONLINE'.lower(): + availability_flag = True + if list1[0].strip().lower() == 'STATUS'.lower() and list1[1].strip().lower() == 'OK'.lower(): + status_flag = True + if list1[0].strip().lower() == 'STATE'.lower() and list1[1].strip().lower() == 'DEPLOYED'.lower(): + state_flag = True + + del list1[:] + + if name_flag and availability_flag and state_flag and status_flag: + return 0 + else: + return 1 + + def verify_gsm_shard(self): + """ + This function verify GSM shard + """ + self.ocommon.log_info_message("Inside verify_gsm_shard()",self.file_name) + status=False + reg_exp= self.check_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb=self.process_chunks_vars(key) + shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) + gsm_shard = self.check_gsm_shard(shard_name) + if gsm_shard == 0: + msg='''Shard {0} is present in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} is not present in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + def check_shard_regex(self): + """ + This function return the rgex to search the Shards in GSM + """ + self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) + return re.compile('CHECK_GSM_SHARD') + + def check_gsm_shard(self,shard_name): + """ + This function check the shard in gsm + """ + self.ocommon.log_info_message("Inside check_gsm_shard()",self.file_name) + name_flag = False + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + config shard -shard {0}; + exit; + '''.format(shard_name,cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + lines = output.split("\n") + for line in lines: + list1 = line.split(":") + if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): + name_flag = True + + del list1[:] + + if name_flag: + return 0 + else: + return 1 + + def count_online_shards(self): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside count_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + config shard; + exit; + '''.format(cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + online_shard = 0 + lines = output.split("\n") + for line in lines: + if re.search('ok', line, re.IGNORECASE): + if re.search('deployed', line, re.IGNORECASE): + if re.search('online', line, re.IGNORECASE): + online_shard = online_shard + 1 + + return online_shard + + def get_online_shards(self): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + config shard; + exit; + '''.format(cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + shards=[] + online_shard = 0 + for line in output.split("\n"): + cols=line.split() + print(cols) + if len(cols) >= 5: + if cols[5].lower() == "online" and cols[2].lower() == "ok": + shards.append(cols[0]) + + return shards + + def get_rus(self,shardname_to_delete): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd=None + if shardname_to_delete is not None: + cmd='''status ru -leaders -shard {0}'''.format(shardname_to_delete) + else: + cmd='''status ru''' + + gsmcmd=''' + connect {0}/{1}; + {2}; + exit; + '''.format(cadmin,cpasswd,cmd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + return output.split('\n') + + def move_shard_rus(self,sshard,tshard,runum): + """ + This function move the shard rus + """ + self.ocommon.log_info_message("Inside move_shard_rus()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + cmd1="" + cmd2="" + shardname=sshard + if tshard is not None and runum is not None: + cmd1='''switchover ru -RU {0} -shard {1}'''.format(runum,tshard) + else: + cmd1='''MOVE RU -RU ALL -SOURCE {0}'''.format(shardname) + + gsmcmd=''' + connect {1}/{2}; + configure -verbose off -save_config; + {3}; + status RU -shard {0}; + exit; + '''.format(shardname,cadmin,cpasswd,cmd1,cmd2) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def count_shard_rus(self,shardname): + """ + This function return the returns the count of online shard chunks + """ + self.ocommon.log_info_message("Inside count_shard_chunks()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + status ru -shard {2}; + exit; + '''.format(cadmin,cpasswd,shardname) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ru_count = 0 + lines = output.split("\n") + for line in lines: + if re.search(shardname, line, re.IGNORECASE): + ru_count = ru_count + 1 + + return ru_count + + def count_leader_shards(self,shardName): + """ + This function return the returns the count of online shard + """ + self.ocommon.log_info_message("Inside count_leader_shards()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {0}/{1}; + status ru -shard {2} -leaders; + exit; + '''.format(cadmin,cpasswd,shardName) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + leader_shard = 0 + lines = output.split("\n") + for line in lines: + if re.search('ok', line, re.IGNORECASE): + if re.search('Leader', line, re.IGNORECASE): + leader_shard = leader_shard + 1 + + return leader_shard + + def validate_gsm_shard(self): + """ + This function validate the shard in the GSM + """ + self.ocommon.log_info_message("Inside validate_gsm_shard()",self.file_name) + status=False + reg_exp= self.validate_shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + status = self.check_shard_status(shard_name) + if status == 'completed': + msg='''Shard DB setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Shard {0} info does not exist in GSM.'''.format(shard_name) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("157") + + def process_shard_vars(self,key): + """ + This function process sgard vars based on key and return values to configure the GSM + """ + shard_db=None + shard_pdb=None + shard_port=None + shard_group=None + shard_host=None + shard_region=None + shard_space=None + shard_deploy_as=None + + self.ocommon.log_info_message("Inside process_shard_vars()",self.file_name) + # self.ocommon.log_info_message(key,self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_str=cvar_str.replace('"', '') + # self.ocommon.log_info_message(cvar_str,self.file_name) + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + # self.ocommon.log_info_message("key : " + ckey,self.file_name) + # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) + if ckey == 'shard_db': + shard_db = cvar_dict[ckey] + if ckey == 'shard_pdb': + shard_pdb = cvar_dict[ckey] + if ckey == 'shard_port': + shard_port = cvar_dict[ckey] + if ckey == 'shard_group': + shard_group = cvar_dict[ckey] + if ckey == 'shard_host': + shard_host = cvar_dict[ckey] + if ckey == 'shard_region': + #shard_region = self.validate_shard_param("region",cvar_dict[ckey]) + shard_region=cvar_dict[ckey] + if ckey == 'deploy_as': + shard_deploy_as=cvar_dict[ckey] + if ckey == 'shard_space': + #shard_space = self.validate_shard_param("shardspace",cvar_dict[ckey]) + shard_space=cvar_dict[ckey] + # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) + ## Set the values if not set in above block + if not shard_port: + shard_port=1521 + + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + shard_group="nogrp" + if not shard_deploy_as: + self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS","primary",self.ora_env_dict) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS",shard_deploy_as,self.ora_env_dict) + + ### Check values must be set + if shard_host and shard_db and shard_pdb and shard_port and shard_group: + return shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space + else: + msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) + msg2='''shard_port={0},shard_host={1}'''.format((shard_port or "Missing Value"),(shard_host or "Missing Value")) + msg3='''shard_group={0}'''.format((shard_group or "Missing Value")) + msg='''Shard DB params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def validate_shard_param(self,param_type,value): + """ + This function validaet the shard param such as region and shardspace + """ + status=False + reg_exp= self.catalog_regex() + stype=None + sspace=None + catalog_region=None + self.ocommon.log_info_message("Processing GSM params to verify the region and shardspace",self.file_name) + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + + if param_type == 'region': + if stype: + status=self.ocommon.find_str_in_string(catalog_region,'comma',value) + if status: + + return value + else: + return "" + + if param_type == 'shardspace': + if sspace: + status=self.ocommon.find_str_in_string(sspace,'comma',value) + if status: + return value + else: + return "" + + return False + + def process_chunks_vars(self,key): + """ + This function process the chunks vars + """ + shard_db=None + shard_pdb=None + self.ocommon.log_info_message("Inside process_chunks_vars()",self.file_name) + # self.ocommon.log_info_message(key,self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_str=cvar_str.replace('"', '') + # self.ocommon.log_info_message(cvar_str,self.file_name) + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + # self.ocommon.log_info_message("key : " + ckey,self.file_name) + # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) + if ckey == 'shard_db': + shard_db = cvar_dict[ckey] + if ckey == 'shard_pdb': + shard_pdb = cvar_dict[ckey] + # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) + ## Set the values if not set in above block + + ### Check values must be set + if shard_pdb and shard_db: + return shard_db,shard_pdb + else: + msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) + self.ocommon.log_info_message(msg1,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_shard_status(self,shard_name): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_shard_status()",self.file_name) + #gsmcmd=self.get_gsm_config_cmd(dname) + gsmcmd=''' + config; + exit; + ''' + counter=1 + end_counter=3 + status=False + while counter < end_counter: + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + error_check=re.findall("(?:GSM-45034\n)(?:.+\n)+",output) + try: + if self.ocommon.check_substr_match(error_check[0],"GSM-45034"): + count = counter + 1 + self.ocommon.log_info_message("Issue in catalog connection, retrying to connect to catalog in 30 seconds!",self.file_name) + time.sleep(20) + status=False + continue + except: + status=False + matched_output=re.findall("(?:Databases\n)(?:.+\n)+",output) + if shard_name: + try: + if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): + status=True + break + else: + status=False + except: + status=False + else: + reg_exp= self.shard_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_region,shard_host,shard_region,shard_space=self.process_shard_vars(key) + shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) + try: + if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): + status=True + else: + status=False + except: + status=False + if status: + break; + counter = counter + 1 + + return(self.ocommon.check_status_value(status)) + + def shard_regex(self): + """ + This function return the rgex to search the SHARD PARAMS + """ + self.ocommon.log_info_message("Inside shard_regex()",self.file_name) + return re.compile('SHARD[0-9]+_PARAMS') + + def add_shard_regex(self): + """ + This function return the rgex to search the ADD_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside add_shard_regex()",self.file_name) + return re.compile('ADD_SHARD') + + def remove_shard_regex(self): + """ + This function return the rgex to search the REMOVE_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) + return re.compile('REMOVE_SHARD') + + def validate_shard_regex(self): + """ + This function return the rgex to search the VALIDATE_SHARD_PARAMS + """ + self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) + return re.compile('VALIDATE_SHARD') + + def configure_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup,sregion,sspace): + """ + This function configure the shard db. + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + #dtrname,dtrport,dtregion=self.process_director_vars() + #group_region=self.get_shardg_region_name(sgroup) + #dtrname=self.get_director_name(group_region) + shard_name='''{0}_{1}'''.format(scdb,spdb) + shard_region=None + shard_space=None + shard_group=None + deploy_as=None + + if sregion: + regionFlag=self.check_gsm_region(sregion) + if regionFlag != 'completed': + self.configure_gsm_region(sregion) + shard_region=" -region {0}".format(sregion) + else: + shard_region="" + if sspace: + shard_space=" -shardspace {0}".format(sspace) + else: + shard_space="" + + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + sspaceFlag=self.check_gsm_shardspace(sspace) + if sspaceFlag != 'completed': + self.configure_gsm_sspace(sspace,None,None,None,None,'add') + shard_group="" + deploy_as,deploy_type=self.get_shard_deploy() + else: + shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) + shard_region="" + else: + shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) + shard_region="" + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + add cdb -connect {3}:{4}/{5} -pwd {2}; + add shard -cdb {5} -connect "(DESCRIPTION = (ADDRESS = (PROTOCOL = tcp)(HOST = {3})(PORT = {4})) (CONNECT_DATA = (SERVICE_NAME = {6}) (SERVER = DEDICATED)))" {7} -pwd {2} {9} {10} {11}; + config vncr; + exit; + '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,shard_group,shard_name,shard_region,shard_space,deploy_as) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def get_shard_deploy(self): + """ + get the shard deploy + """ + deploy_as=None + deploy_type=None + if self.ocommon.check_key("SHARD_DEPLOY_AS",self.ora_env_dict): + deploy_as="-deploy_as {0}".format(self.ora_env_dict["SHARD_DEPLOY_AS"]) + deploy_type=self.ora_env_dict["SHARD_DEPLOY_AS"] + else: + deploy_as="-deploy_as primary" + deploy_type='primary' + + return deploy_as,deploy_type + + def get_shardg_cmd(self,sgroup,sregion): + """ + Getting shard group cmd + """ + sgFlag=self.check_shardg_status(sgroup,None) + deploy_as,deploy_type=self.get_shard_deploy() + if sgFlag != 'completed': + self.configure_gsm_shardg(sgroup,deploy_type,sregion,'add') + else: + self.ocommon.log_info_message("Shardgroup exist " + sgroup, self.file_name) + + deploy_as="" + cmd=''' -shardgroup {0}'''.format(sgroup) + return cmd,deploy_as + + def delete_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup): + """ + This function delete the shard db. + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + shard_name='''{0}_{1}'''.format(scdb,spdb) + #group_region=self.get_shardg_region_name(sgroup) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + remove shard -shard {8}; + remove cdb -cdb {5}; + remove invitednode {3}; + config vncr; + exit; + '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,sgroup,shard_name) + + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_hostid_null(self): + """ + This function set the hostid to Null + """ + spasswd="HIDDEN_STRING" + admuser= self.ora_env_dict["SHARD_ADMIN_USER"] + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_pdb,admuser) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting host Id null in catalog as auto vncr is disabled''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set echo on + set termout on + set time on + update gsmadmin_internal.database set hostid=NULL; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + self.ocommon.unset_mask_str() + + def invited_node_op(self): + """ + This function perform the invitedaddition and deletion + """ + self.ocommon.log_info_message("Inside invited_node_op()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + shard_host=self.ora_env_dict["INVITED_NODE_OP"] + gsmcmd=''' + connect {1}/{2}; + remove invitednode {3}; + add invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,shard_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + def add_invited_node(self,op_str): + """ + This function add the invited in the GSM configuration + """ + self.ocommon.log_info_message("Inside add_invited_node()",self.file_name) + if op_str == "SHARD": + reg_exp = self.shard_regex() + else: + reg_exp = self.add_shard_regex() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + #group_region=self.get_shardg_region_name(shard_group) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + add invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,shard_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + def remove_invited_node(self,op_str): + """ + This function remove the invited in the GSM configuration + """ + self.ocommon.log_info_message("Inside remove_invited_node()",self.file_name) + if op_str == "SHARD": + reg_exp = self.shard_regex() + else: + reg_exp = self.add_shard_regex() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) + temp_host= shard_host.split('.',1)[0] + #group_region=self.get_shardg_region_name(shard_group) + #dtrname=self.get_director_name(group_region) + gsmcmd=''' + connect {1}/{2}; + remove invitednode {3}; + exit; + '''.format("NA",cadmin,cpasswd,temp_host) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + else: + self.ocommon.log_info_message("KUBE_SVC is not set. No need to remove invited node!",self.file_name) + + + def deploy_shard(self): + """ + This function deploy shard + """ + self.ocommon.log_info_message("Inside deploy_shard()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + shrdg_sspace=None + #dtrname,dtrport,dtregion=self.process_director_vars() + #if op_str == "SHARD": + # reg_exp = self.shard_regex() + #else: + # reg_exp = self.add_shard_regex() + + #for key in self.ora_env_dict.keys(): + # if(reg_exp.match(key)): + if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): + if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': + shardg_shardspace="config shardspace" + else: + shardg_shardspace="config shardgroup" + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + {3}; + config vncr; + deploy; + config shard; + exit; + '''.format("test",cadmin,cpasswd,shardg_shardspace) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def check_setup_status(self,host,ccdb,svc,port): + """ + This function check the shard status. + """ + systemStr='''{0}/bin/sqlplus "system/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,ccdb) + + fname='''/tmp/{0}'''.format("shard_setup.txt") + self.ocommon.remove_file(fname) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool {0} + select * from shardsetup WHERE ROWNUM = 1; + spool off + exit; + '''.format(fname) + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + if os.path.isfile(fname): + fdata=self.ocommon.read_file(fname) + else: + fdata='nosetup' + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + status = self.catalog_pdb_setup_check(host,ccdb,svc,port) + if status == 'completed': + return 'completed' + else: + return 'notcompleted' + else: + return 'notcompleted' + + + def catalog_pdb_setup_check(self,host,ccdb,svc,port): + """ + This function check the shard status. + """ + systemStr='''{0}/bin/sqlplus "pdbadmin/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,svc) + + fname='''/tmp/{0}'''.format("pdb_setup_check.txt") + self.ocommon.remove_file(fname) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Checking setup status in PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool {0} + select count(*) from dual; + spool off + exit; + '''.format(fname) + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + if os.path.isfile(fname): + fdata=self.ocommon.read_file(fname) + else: + fdata='nosetup' + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + if re.search('1',fdata): + return 'completed' + else: + return 'notcompleted' + + ############################# Setup GSM Service ############################################### + def setup_gsm_service(self): + """ + This function setup the shard service. + """ + self.ocommon.log_info_message("Inside setup_gsm_service()",self.file_name) + status=False + service_value="service_name=oltp_rw_svc;service_role=primary" + # self.ora_env_dict=self.ocommon.add_key("SERVICE1_PARAMS",service_value,self.ora_env_dict) + reg_exp= self.service_regex() + counter=1 + end_counter=3 + while counter < end_counter: + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + shard_service_status=None + service_name,service_role=self.process_service_vars(key) + shard_service_status=self.check_service_status(service_name) + if shard_service_status != 'completed': + self.configure_gsm_service(service_name,service_role) + status = self.check_service_status(None) + if status == 'completed': + break + else: + msg='''GSM service setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) + time.sleep(60) + counter=counter+1 + + status = self.check_service_status(None) + if status == 'completed': + msg='''Shard service setup completed in GSM''' + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("127") + + def process_service_vars(self,key): + """ + This function process shardG vars based on key and return values to configure the GSM + """ + service_name=None + service_role=None + + self.ocommon.log_info_message("Inside process_service_vars()",self.file_name) + cvar_str=self.ora_env_dict[key] + cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) + for ckey in cvar_dict.keys(): + if ckey == 'service_name': + service_name = cvar_dict[ckey] + if ckey == 'service_role': + service_role = cvar_dict[ckey] + + ### Check values must be set + if service_name and service_role: + return service_name,service_role + else: + msg1='''service_name={0},service_role={1}'''.format((service_name or "Missing Value"),(service_role or "Missing Value")) + msg='''Shard service params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit("Error occurred") + + def check_service_status(self,service_name): + """ + This function check the shard status in GSM + """ + self.ocommon.log_info_message("Inside check_service_status()",self.file_name) + #dtrname,dtrport,dtregion=self.process_director_vars() + gsmcmd=''' + config; + exit; + '''.format("test") + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + matched_output=re.findall("(?:Services\n)(?:.+\n)+",output) + status=False + if service_name: + try: + if self.ocommon.check_substr_match(matched_output[0],service_name): + status=True + else: + status=False + except: + status=False + else: + reg_exp= self.service_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + service_name,service_role=self.process_service_vars(key) + # match=re.search("(?i)(?m)"+service_name,matched_output) + try: + if self.ocommon.check_substr_match(matched_output[0],service_name): + status=True + else: + status=False + except: + status=False + + return(self.ocommon.check_status_value(status)) + + def service_regex(self): + """ + This function return the rgex to search the SERVICE[0-9]_PARAMS + """ + self.ocommon.log_info_message("Inside service_regex()",self.file_name) + return re.compile('SERVICE[0-9]+_PARAMS') + + def configure_gsm_service(self,service_name,service_role): + """ + This function configure the service creation. + """ + self.ocommon.log_info_message("Inside configure_gsm_service()",self.file_name) + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) + gsmcmd=''' + connect {1}/{2}; + add service -service {3} -role {4}; + start service -service {3}; + exit; + '''.format("test",cadmin,cpasswd,service_name,service_role) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ############################## GSM backup fIle function Begins Here ############################# + def gsm_backup_file(self): + """ + This function check the gsm setup status + """ + self.ocommon.log_info_message("Inside gsm_backup_file()",self.file_name) + gsmdata_loc='/opt/oracle/gsmdata' + gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) + + if os.path.isdir(gsmdata_loc): + msg='''Directory {0} exit'''.format(gsmdata_loc) + self.ocommon.log_info_message(msg,self.file_name) + + cmd='''cp -r -v {0}/* {1}/'''.format(gsmfile_loc,gsmdata_loc) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############### Deploy Sample Function Begins Here ########################## + def setup_sample_schema(self): + """ + This function deploy the sample app + """ + s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?" + passlen = 8 + passwd = "".join(random.sample(s,passlen )) + self.ocommon.log_info_message("Inside deploy_sample_schema()",self.file_name) + reg_exp= self.catalog_regex() + for key in self.ora_env_dict.keys(): + if(reg_exp.match(key)): + catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) + sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_db) + if self.ocommon.check_key("SAMPLE_SCHEMA",self.ora_env_dict): + if self.ora_env_dict["SAMPLE_SCHEMA"] == 'DEPLOY': + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Deploying sample schema''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set echo on + set termout on + set time on + spool /tmp/create_app_schema.lst + REM + REM Connect to the Shard Catalog and Create Schema + REM + alter session enable shard ddl; + alter session set container={2}; + alter session enable shard ddl; + create user app_schema identified by {3}; + grant connect, resource, alter session to app_schema; + grant execute on dbms_crypto to app_schema; + grant create table, create procedure, create tablespace, create materialized view to app_schema; + grant unlimited tablespace to app_schema; + grant select_catalog_role to app_schema; + grant all privileges to app_schema; + grant gsmadmin_role to app_schema; + grant dba to app_schema; + CREATE TABLESPACE SET tbsset1 IN SHARDSPACE shd1; + CREATE TABLESPACE SET tbsset2 IN SHARDSPACE shd2; + connect app_schema/{3}@{0}:{1}/{2} + alter session enable shard ddl; + + /* Customer shard table */ + + CREATE SHARDED TABLE customer + ( cust_id NUMBER NOT NULL, + cust_passwd VARCHAR2(20) NOT NULL, + cust_name VARCHAR2(60) NOT NULL, + cust_type VARCHAR2(10) NOT NULL, + cust_email VARCHAR2(100) NOT NULL) + partitionset by list (cust_type) + partition by consistent hash (cust_id) partitions auto + (partitionset individual values ('individual') tablespace set tbsset1, + partitionset business values ('business') tablespace set tbsset2 + ); + /* Invoice shard table */ + + CREATE SHARDED TABLE invoice + ( invoice_id NUMBER NOT NULL, + cust_id NUMBER NOT NULL, + cust_type VARCHAR2(10) NOT NULL, + vendor_name VARCHAR2(60) NOT NULL, + balance FLOAT(10) NOT NULL, + total FLOAT(10) NOT NULL, + status VARCHAR2(20), + CONSTRAINT InvoicePK PRIMARY KEY (cust_id, invoice_id)) + PARENT customer + partitionset by list (cust_type) + partition by consistent hash (cust_id) partitions auto + (partitionset individual values ('individual') tablespace set tbsset1, + partitionset business values ('business') tablespace set tbsset2 + ); + /* Data */ + insert into customer values (999, 'pass', 'Customer 999', 'individual', 'customer999@gmail.com'); + insert into customer values (250251, 'pass', 'Customer 250251', 'individual', 'customer250251@yahoo.com'); + insert into customer values (350351, 'pass', 'Customer 350351', 'individual', 'customer350351@gmail.com'); + insert into customer values (550551, 'pass', 'Customer 550551', 'business', 'customer550551@hotmail.com'); + insert into customer values (650651, 'pass', 'Customer 650651', 'business', 'customer650651@live.com'); + insert into invoice values (1001, 999, 'individual', 'VendorA', 10000, 20000, 'Due'); + insert into invoice values (1002, 999, 'individual', 'VendorB', 10000, 20000, 'Due'); + insert into invoice values (1001, 250251, 'individual', 'VendorA', 10000, 20000, 'Due'); + insert into invoice values (1002, 250251, 'individual', 'VendorB', 0, 10000, 'Paid'); + insert into invoice values (1003, 250251, 'individual', 'VendorC', 14000, 15000, 'Due'); + insert into invoice values (1001, 350351, 'individual', 'VendorD', 10000, 20000, 'Due'); + insert into invoice values (1002, 350351, 'individual', 'VendorE', 0, 10000, 'Paid'); + insert into invoice values (1003, 350351, 'individual', 'VendorF', 14000, 15000, 'Due'); + insert into invoice values (1004, 350351, 'individual', 'VendorG', 12000, 15000, 'Due'); + insert into invoice values (1001, 550551, 'business', 'VendorH', 10000, 20000, 'Due'); + insert into invoice values (1002, 550551, 'business', 'VendorI', 0, 10000, 'Paid'); + insert into invoice values (1003, 550551, 'business', 'VendorJ', 14000, 15000, 'Due'); + insert into invoice values (1004, 550551, 'business', 'VendorK', 10000, 20000, 'Due'); + insert into invoice values (1005, 550551, 'business', 'VendorL', 10000, 20000, 'Due'); + insert into invoice values (1006, 550551, 'business', 'VendorM', 0, 10000, 'Paid'); + insert into invoice values (1007, 550551, 'business', 'VendorN', 14000, 15000, 'Due'); + insert into invoice values (1008, 550551, 'business', 'VendorO', 10000, 20000, 'Due'); + insert into invoice values (1001, 650651, 'business', 'VendorT', 10000, 20000, 'Due'); + insert into invoice values (1002, 650651, 'business', 'VendorU', 0, 10000, 'Paid'); + insert into invoice values (1003, 650651, 'business', 'VendorV', 14000, 15000, 'Due'); + insert into invoice values (1004, 650651, 'business', 'VendorW', 10000, 20000, 'Due'); + insert into invoice values (1005, 650651, 'business', 'VendorX', 0, 20000, 'Paid'); + insert into invoice values (1006, 650651, 'business', 'VendorY', 0, 30000, 'Paid'); + insert into invoice values (1007, 650651, 'business', 'VendorZ', 0, 10000, 'Paid'); + commit; + select table_name from user_tables; + spool off + '''.format(catalog_host,catalog_port,catalog_pdb,passwd) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] + cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] + cpasswd="HIDDEN_STRING" + #dtrname,dtrport,dtregion=self.process_director_vars() + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + gsmcmd=''' + connect {1}/{2}; + show ddl; + exit; + '''.format("test",cadmin,cpasswd) + output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oralogger.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oralogger.py new file mode 100755 index 0000000..9a51b54 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oralogger.py @@ -0,0 +1,181 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +""" + This file provides the functionality to log the event in console and file +""" + +import logging +import os + +class LoggingType(object): + CONSOLE = 1 + FILE = 2 + STDOUT = 3 + +class OraLogger(object): + """ + This is a class constructor which sets parameter for logger. + + Attributes: + filename_ (string): Filename which we need to set to store logs in a file. + """ + def __init__(self, filename_): + """ + This is a class constructor which sets parameter for logger. + + Attributes: + filename_ (string): Filename which we need to set to store logs in a file. + """ + self.filename_ = filename_ + # Set to default values can be changed later from other classes objects + self.console_ = LoggingType.CONSOLE + self.file_ = LoggingType.FILE + self.stdout_ = LoggingType.STDOUT + self.msg_ = None + self.functname_ = None + self.lineno_ = None + self.logtype_ = "INFO" + self.fmtstr_ = "%(asctime)s: %(levelname)s: %(message)s" + self.datestr_ = "%m/%d/%Y %I:%M:%S %p" + self.root = logging.getLogger() + self.root.setLevel(logging.DEBUG) + self.formatter = logging.Formatter('%(asctime)s %(levelname)8s:%(message)s', "%m/%d/%Y %I:%M:%S %p") + self.stdoutfile_ = "/proc/1/fd/1" + # self.stdoutfile_ = "/tmp/test.log" + + def getStdOutValue(self): + return self.stdout_ + +class Handler(object): + """ + This is a class which sets the handler for next logger. + """ + def __init__(self): + """ + This is a handler class constructor and nexthandler is set to None. + """ + self.nextHandler = None + + def handle(self, request): + ''' + This is a function which set the next handler. + + Attributes: + request (object): Object of the class oralogger. + ''' + self.nextHandler.handle(request) + + def print_message(self,request,lhandler): + """ + This function set the log type to INFO, WARN, DEBUG and CRITICAL. + + Attribute: + request (object): Object of the class oralogger. + lhandler: This parameter accept the loghandler. + """ + if request.logtype_ == "WARN": + request.root.warning(request.msg_) + elif request.logtype_ == "DEBUG": + request.root.debug(request.msg_) + elif request.logtype_ == "CRITICAL": + request.root.critical(request.msg_) + elif request.logtype_ == "ERROR": + request.root.error(request.msg_) + else: + request.root.info(request.msg_) + + request.root.removeHandler(lhandler) + +class FHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribut: + request: Object of OraLogger + """ + if request.file_ == LoggingType.FILE: + fh = logging.FileHandler(request.filename_) + request.root.addHandler(fh) + fh.setFormatter(request.formatter) + self.print_message(request,fh) + super(FHandler, self).handle(request) + else: + super(FHandler, self).handle(request) + + def print_message(self,request,fh): + """ + This function log the message to console/file/stdout. + """ + super(FHandler, self).print_message(request,fh) + +class CHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribute: + request: Object of OraLogger + """ + if request.console_ == LoggingType.CONSOLE: + # ch = logging.StreamHandler() + ch = logging.FileHandler("/tmp/test.log") + request.root.addHandler(ch) + ch.setFormatter(request.formatter) + self.print_message(request,ch) + super(CHandler, self).handle(request) + else: + super(CHandler, self).handle(request) + + def print_message(self,request,ch): + """ + This function log the message to console/file/stdout. + """ + super(CHandler, self).print_message(request,ch) + + +class StdHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self,request): + """ + This function print the message and call next handler. + + Attribute: + request: Object of OraLogger + """ + request.stdout_ = request.getStdOutValue() + if request.stdout_ == LoggingType.STDOUT: + st = logging.FileHandler(request.stdoutfile_,mode="w") + request.root.addHandler(st) + st.setFormatter(request.formatter) + self.print_message(request,st) + super(StdHandler, self).handle(request) + else: + super(StdHandler, self).handle(request) + + def print_message(self,request,st): + """ + This function log the message to console/file/stdout. + """ + super(StdHandler, self).print_message(request,st) + +class PassHandler(Handler): + """ + This is a class which sets the handler for next logger. + """ + def handle(self, request): + pass diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oramachine.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oramachine.py new file mode 100755 index 0000000..2d1431a --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/oramachine.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +import os +import sys + +class OraMachine: + """ + This calss setup the compute before starting the installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraMachine class to setup the compute + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + + def setup(self): + """ + This function setup the compute before starting the installation + """ + msg="Machine setup completed sucessfully!" + self.ocommon.log_info_message(msg,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orapcatalog.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orapcatalog.py new file mode 100755 index 0000000..112f309 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orapcatalog.py @@ -0,0 +1,790 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * + +class OraPCatalog: + """ + This calss setup the Catalog after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraCatalog class to setup the catalog on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + + def setup(self): + """ + This function setup the catalog on Primary DB. + """ + if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): + self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) + if self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) + self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) + if os.path.exists(create_db_file_lck): + self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) + sys.exit(127) + elif os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) + status = self.catalog_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) + sys.exit(0) + else: + status = self.catalog_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): + status = self.catalog_setup_check() + if not status: + self.ocommon.log_info_message("Catalog readyness check completed sucessfully!",self.file_name) + self.ocommon.prog_exit("127") + elif self.ocommon.check_key("RESET_PASSWORD",self.ora_env_dict): + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + if os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Catalog database up and running. Resetting password...",self.file_name) + else: + self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to reset password",self.file_name) + self.ocommon.prog_exit("127") + elif self.ocommon.check_key("EXPORT_TDE_KEY",self.ora_env_dict): + exist_db_file_lck=self.ocommon.get_db_lock_location()+ self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + if os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Catalog database up and running.",self.file_name) + self.ocommon.export_tde_key(self.ora_env_dict["EXPORT_TDE_KEY"]) + else: + self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to export the tde key",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_machine() + self.db_checks() + self.reset_catalog_setup() + status = self.catalog_setup_check() + if status: + self.ocommon.log_info_message("catalog Setup is already completed on this database",self.file_name) + else: + self.reset_passwd() + self.setup_cdb_catalog() + self.set_spfile_nonm_params() + self.ocommon.set_events("spfile") + self.set_dbparams_version() + self.restart_db() + self.restart_for_db_unique_name() + self.create_pdb() + self.alter_db() + self.setup_pdb_catalog() + self.set_primary_listener() + self.restart_listener() + self.register_services() + self.list_services() + self.backup_files() + self.update_catalog_setup() + self.gsm_completion_message() + self.run_custom_scripts() + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + + ########### SETUP_MACHINE ENDS here #################### + + ########### DB_CHECKS Related Functions Begin Here #################### + ## Function to perfom DB checks ###### + def db_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.set_user() + self.sid_check() + self.dbunique_name_check() + self.hostname_check() + self.dbport_check() + self.dbr_dest_checks() + self.dpump_dir_checks() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit() + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def passwd_check(self): + """ + Function to set the password + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def set_user(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def sid_check(self): + """ + This funnction heck and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): + msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="ORACLE_SID is not set, existing!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def dbunique_name_check(self): + """ + This funnction check and set the db unique name for standby + """ + if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + + msg='''Setting the Flag to restart the DB to set DB_UNIQUE_NAME to {0}! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + restart_db_to_set_db_unique_name='true' + self.ora_env_dict=self.ocommon.add_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",restart_db_to_set_db_unique_name,self.ora_env_dict) + else: + msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" + self.ocommon.log_info_message(msg,self.file_name) + dbsid=self.ora_env_dict["ORACLE_SID"] + self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) + + + def hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + # hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def dbport_check(self): + """ + This funnction checks and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("DB_PORT",self.ora_env_dict): + msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) + msg="DB_PORT is not set, setting default to 1521" + self.ocommon.log_info_message(msg,self.file_name) + + def dbr_dest_checks(self): + """ + This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. + """ + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) + + # Checking the DB_RECOVERY_FILE_DEST_SIZE + + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the DB_CREATE_FILE_DEST + + if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): + msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) + + + def dpump_dir_checks(self): + """ + This funnction checks and set the DATA_PUMP dir and location. + """ + if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): + msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) + self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) + msg='''DATA_PUMP_DIR set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) + + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## RESET_PASSWORD function Begin here ############################# + ## Function to perform password reset + def reset_passwd(self): + """ + This function reset the password. + """ + self.ocommon.reset_passwd() + + ########## RESET_PASSWORD function ENDS here ############################# + + ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### + + def reset_catalog_setup(self): + """ + This function drop teh catalog setup table and reste the env to default values. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Inside reset_catalog_setup",self.file_name) + catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + if not os.path.isfile(catalog_reset_file): + msg='''Dropping catalogsetup table from CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + drop table system.shardsetup; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + else: + msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(catalog_reset_file) + self.ocommon.log_info_message(msg,self.file_name) + + + def catalog_setup_check(self): + """ + This function check the catalog status. + """ + #systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool /tmp/catalog_setup.txt + select * from system.shardsetup WHERE ROWNUM = 1; + spool off + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + fname='''/tmp/{0}'''.format("catalog_setup.txt") + fdata=self.ocommon.read_file(fname) + ### Unsetting the encrypt value to None + # self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + return True + else: + return False + + def setup_cdb_catalog(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + # Assigning variable + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] + dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] + host_name=self.ora_env_dict["ORACLE_HOSTNAME"] + dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] + db_port=self.ora_env_dict["DB_PORT"] + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting up catalog CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set db_create_file_dest=\"{0}\" scope=both; + alter system set db_recovery_file_dest_size={1} scope=both; + alter system set db_recovery_file_dest=\"{2}\" scope=both; + alter user gsmcatuser account unlock; + alter user gsmcatuser identified by HIDDEN_STRING; + alter system set local_listener='{4}:{5}' scope=both; + alter system set db_unique_name='{8}' scope=spfile; + '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_spfile_nonm_params(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set open_links_per_instance=16 scope=spfile; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set standby_file_management='AUTO' scope=spfile; + alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; + alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + + def set_dbparams_version(self): + """ + This function setup the shard parameter based on db version. + """ + ohome1=self.ora_env_dict["ORACLE_HOME"] + version=self.ocommon.get_oraversion(ohome1).strip() + self.ocommon.log_info_message(version,self.file_name) + if int(version) > 21: + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set wallet_root=\"{1}/oradata/{2}/{3}\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_db(self): + """ + restarting the db + """ + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + #self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) + #sqlcmd=''' + # alter database archivelog; + # alter database open; + #''' + #output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + #self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + #self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_for_db_unique_name(self): + """ + restarting the db, when db_unique_name is passed explicitly + """ + if self.ocommon.check_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",self.ora_env_dict): + if self.ora_env_dict["RESTART_DB_TO_SET_DB_UNIQUE_NAME"] == 'true': + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Restarting the Database to set the DB_UNIQUE_NAME! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + + def create_pdb(self): + """ + This function creates the PDB + """ + inst_sid=self.ora_env_dict["ORACLE_SID"] + ohome=self.ora_env_dict["ORACLE_HOME"] + if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): + self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) + opdb=self.ora_env_dict["ORACLE_PDB"] + status=self.ocommon.check_pdb(opdb) + if not status: + self.ocommon.create_pdb(ohome,opdb,inst_sid) + self.ocommon.create_pdb_tns_entry(ohome,opdb) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + def setup_pdb_catalog(self): + """ + This function setup the catalog. + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + # Assigning variable + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter pluggable database {0} close immediate; + alter pluggable database {0} open services=All; + ALTER PLUGGABLE DATABASE {0} SAVE STATE; + alter system register; + alter session set container={0}; + create user {1} identified by HIDDEN_STRING; + alter user {1} account unlock; + grant connect, create session, gsmadmin_role to {1}; + grant inherit privileges on user SYS to GSMADMIN_INTERNAL; + execute dbms_xdb.sethttpport(8080); + exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('HIDDEN_STRING'); + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def update_catalog_setup(self): + """ + This function update the catalog setup on this DB. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") + # systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Updating shardsetup table''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + create table system.shardsetup (status varchar2(10)); + insert into system.shardsetup values('completed'); + commit; + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Reset File + catalog_reset_dir='''{0}/.catalog'''.format(self.ora_env_dict["HOME"]) + catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) + + self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) + if not os.path.isdir(catalog_reset_dir): + self.ocommon.create_dir(catalog_reset_dir,True,None,None) + + if not os.path.isfile(catalog_reset_file): + self.ocommon.create_file(catalog_reset_file,True,None,None) + +# self.ocommon.unset_mask_str() + + ########## SETUP_CDB_catalog FUNCTION ENDS HERE ############################### + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + def set_primary_listener(self): + """ + Function to set the primary listener + """ + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + + def set_db_listener(self,gdbname,sid): + """ + Funtion to reset the listener + """ + self.ocommon.log_info_message("Inside reset_listener()",self.file_name) + start = 'SID_LIST_LISTENER' + end = '^\)$' + oracle_home=self.ora_env_dict["ORACLE_HOME"] + lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) + buffer = "SID_LIST_LISTENER=" + '\n' + start_flag = False + try: + with open(lisora) as f: + for line1 in f: + if start_flag == False: + if (re.match(start, line1.strip())): + start_flag = True + elif (re.match(end, line1.strip())): + line2 = f.next() + if (re.match(end, line2.strip())): + break + else: + buffer += line1 + buffer += line2 + else: + if start_flag == True: + buffer += line1 + except: + pass + + if start_flag == True: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + else: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + + wr = open(lisora, 'w') + wr.write(listener) + + def restart_listener(self): + """ + restart listener + """ + self.ocommon.log_info_message("Stopping Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl stop'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + self.ocommon.log_info_message("Starting Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl start'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + + def register_services(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system register; + alter session set container={0}; + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def list_services(self): + """ + restart listener + """ + self.ocommon.log_info_message("Listing Services",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl services'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + + def backup_files(self): + """ + This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig + """ + self.ocommon.log_info_message("Inside backup_files()",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + dbsid=self.ora_env_dict["ORACLE_SID"] + + version=self.ocommon.get_oraversion(ohome).strip() + wallet_backup_cmd='''ls -ltr /bin''' + self.ocommon.log_info_message("Check Version " + version,self.file_name) + if int(version) >= 21: + obase1=self.ora_env_dict["ORACLE_BASE"] + wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) + cmd_names=''' + mkdir -p {0}/oradata/{1}/{2} + cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ + cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ + cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ + touch {0}/oradata/{1}/{2}/status_completed + '''.format(obase,"dbconfig",dbuname,ohome) + cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] + for cmd in cmd_list: + msg='''Executing cmd {0}'''.format(cmd) + self.ocommon.log_info_message(msg,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Catalog Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orapshard.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orapshard.py new file mode 100755 index 0000000..e4be415 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orapshard.py @@ -0,0 +1,838 @@ +#!/usr/bin/python + +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +import traceback + +class OraPShard: + """ + This calss setup the primary shard after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraPShard class to setup the shard on primary DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + try: + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + except BaseException as ex: + ex_type, ex_value, ex_traceback = sys.exc_info() + trace_back = traceback.extract_tb(ex_traceback) + stack_trace = list() + for trace in trace_back: + stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) + self.ocommon.log_info_message(ex_type.__name__,self.file_name) + self.ocommon.log_info_message(ex_value,self.file_name) + self.ocommon.log_info_message(stack_trace,self.file_name) + def setup(self): + """ + This function setup the shard on Primary DB. + """ + if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): + self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) + if self.ocommon.check_key("RESET_LISTENER",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) + self.ocommon.prog_exit("127") + self.reset_listener() + self.restart_listener() + if self.ocommon.check_key("RESTART_DB",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) + self.ocommon.prog_exit("127") + else: + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.start_db(self.ora_env_dict) + elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): + create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" + exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" + self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) + self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) + if os.path.exists(create_db_file_lck): + self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) + sys.exit(127) + elif os.path.exists(exist_db_file_lck): + self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) + status = self.shard_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) + sys.exit(0) + else: + status = self.shard_setup_check() + if not status: + self.ocommon.prog_exit("127") + self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) + sys.exit(0) + elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): + status = self.shard_setup_check() + if not status: + self.ocommon.log_info_message("Shard readyness check completed sucessfully!",self.file_name) + self.ocommon.prog_exit("127") + else: + self.setup_machine() + self.db_checks() + self.reset_shard_setup() + status = self.shard_setup_check() + if status: + self.ocommon.log_info_message("Shard Setup is already completed on this database",self.file_name) + else: + self.reset_passwd() + self.setup_cdb_shard() + self.set_spfile_nonm_params() + self.ocommon.set_events("spfile") + self.set_dbparams_version() + self.restart_db() + self.restart_for_db_unique_name() + self.create_pdb() + self.alter_db() + self.setup_pdb_shard () + self.update_shard_setup() + self.set_primary_listener() + self.restart_listener() + self.register_services() + self.list_services() + self.backup_files() + self.gsm_completion_message() + self.run_custom_scripts() + + ########### SETUP_MACHINE begins here #################### + ## Function to machine setup + def setup_machine(self): + """ + This function performs the compute before performing setup + """ + self.omachine.setup() + ########### SETUP_MACHINE ENDS here #################### + + ########### DB_CHECKS Related Functions Begin Here #################### + ## Function to perfom DB checks ###### + def db_checks(self): + """ + This function perform db checks before starting the setup + """ + self.ohome_check() + self.passwd_check() + self.set_user() + self.sid_check() + self.dbunique_name_check() + self.hostname_check() + self.dbport_check() + self.dbr_dest_checks() + self.dpump_dir_checks() + + def ohome_check(self): + """ + This function performs the oracle home related checks + """ + if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): + self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) + else: + self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) + self.ocommon.prog_exit() + + if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): + msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def passwd_check(self): + """ + This funnction perform password related checks + """ + self.ocommon.get_password(None) + if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): + msg='''ORACLE_PWD key is set. Check Passed!''' + self.ocommon.log_info_message(msg,self.file_name) + + def set_user(self): + """ + This funnction set the user for pdb and cdb. + """ + if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): + msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) + msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + self.ocommon.log_info_message(msg,self.file_name) + + if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): + msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) + msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." + self.ocommon.log_info_message(msg,self.file_name) + + def sid_check(self): + """ + This funnction heck and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): + msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + msg="ORACLE_SID is not set, existing!" + self.ocommon.log_error_message(msg,self.file_name) + self.ocommon.prog_exit() + + def dbunique_name_check(self): + """ + This funnction check and set the db unique name for standby + """ + if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + + msg='''Setting the Flag to restart the DB to set DB_UNIQUE_NAME to {0}! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + restart_db_to_set_db_unique_name='true' + self.ora_env_dict=self.ocommon.add_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",restart_db_to_set_db_unique_name,self.ora_env_dict) + else: + msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" + self.ocommon.log_info_message(msg,self.file_name) + dbsid=self.ora_env_dict["ORACLE_SID"] + self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) + + def hostname_check(self): + """ + This function check and set the hostname. + """ + if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): + msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): + ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) + hostname='''{0}'''.format(socket.getfqdn()) + else: + hostname='''{0}'''.format(socket.gethostname()) + msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) + self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) + self.ocommon.log_info_message(msg,self.file_name) + + def dbport_check(self): + """ + This funnction checks and set the SID for cdb and PDB. + """ + if self.ocommon.check_key("DB_PORT",self.ora_env_dict): + msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) + msg="DB_PORT is not set, setting default to 1521" + self.ocommon.log_info_message(msg,self.file_name) + + def dbr_dest_checks(self): + """ + This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. + """ + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) + + # Checking the DB_RECOVERY_FILE_DEST_SIZE + + if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): + msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) + msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") + self.ocommon.log_info_message(msg,self.file_name) + + # Checking the DB_CREATE_FILE_DEST + + if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): + msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) + self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) + msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) + + + def dpump_dir_checks(self): + """ + This funnction checks and set the DATA_PUMP dir and location. + """ + if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): + msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + else: + dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) + self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) + msg='''DATA_PUMP_DIR set to {0}'''.format(dest) + self.ocommon.log_info_message(msg,self.file_name) + msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) + self.ocommon.log_info_message(msg,self.file_name) + self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) + + ########### DB_CHECKS Related Functions Begin Here #################### + + + ########## RESET_PASSWORD function Begin here ############################# + ## Function to perform password reset + def reset_passwd(self): + """ + This function reset the password. + """ + self.ocommon.reset_passwd() + + ########## RESET_PASSWORD function ENDS here ############################# + + ########## SETUP_CDB_SHARD FUNCTION BEGIN HERE ############################### + + def reset_shard_setup(self): + """ + This function drop teh shard setup table and reste the env to default values. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Inside reset_shard_setup",self.file_name) + shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) + if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): + if self.ora_env_dict["RESET_ENV"]: + if not os.path.isfile(shard_reset_file): + msg='''Dropping shardsetup table from CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + drop table system.shardsetup; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + else: + msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(shard_reset_file) + self.ocommon.log_info_message(msg,self.file_name) + + + def shard_setup_check(self): + """ + This function check the shard status. + """ +# systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + + # self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + msg='''Checking shardsetup table in CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + set term off + SET NEWPAGE NONE + spool /tmp/shard_setup.txt + select * from system.shardsetup WHERE ROWNUM = 1; + spool off + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + fname='''/tmp/{0}'''.format("shard_setup.txt") + fdata=self.ocommon.read_file(fname) + ### Unsetting the encrypt value to None + # self.ocommon.unset_mask_str() + + if re.search('completed',fdata): + return True + else: + return False + + def setup_cdb_shard(self): + """ + This function setup the shard. + """ + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] + dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] + host_name=self.ora_env_dict["ORACLE_HOSTNAME"] + dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] + db_port=self.ora_env_dict["DB_PORT"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + msg='''Setting up Shard CDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set db_create_file_dest=\"{0}\" scope=both; + alter system set db_recovery_file_dest_size={1} scope=both; + alter system set db_recovery_file_dest=\"{2}\" scope=both; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set standby_file_management='AUTO' scope=spfile; + alter user gsmrootuser account unlock; + grant sysdg to gsmrootuser; + grant sysbackup to gsmrootuser; + alter user gsmrootuser identified by HIDDEN_STRING container=all; + alter user GSMUSER account unlock; + alter user GSMUSER identified by HIDDEN_STRING container=all; + grant sysdg to GSMUSER; + grant sysbackup to GSMUSER; + create or replace directory DATA_PUMP_DIR as '{3}'; + grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; + alter system set local_listener='{4}:{5}' scope=spfile; + alter system set db_unique_name='{8}' scope=spfile; + '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def set_spfile_nonm_params(self): + """ + This function setup the catalog. + """ + #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + msg='''Setting up catalog CDB with spfile non modifiable parameters''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set open_links_per_instance=16 scope=spfile; + alter system set open_links=16 scope=spfile; + alter system set db_file_name_convert='*','{0}/' scope=spfile; + alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; + alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def set_dbparams_version(self): + """ + This function setup the catalog parameter based on db version. + """ + ohome1=self.ora_env_dict["ORACLE_HOME"] + version=self.ocommon.get_oraversion(ohome1).strip() + self.ocommon.log_info_message(version,self.file_name) + if int(version) > 21: + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + + + msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system set wallet_root=\"{1}/oradata/{2}/{3}/\" scope=spfile; + '''.format(dbf_dest,obase,"dbconfig",dbuname) + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def restart_db(self): + + """ + restarting the db + """ + if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): + if self.ora_env_dict["CLONE_DB"] != 'true': + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + # self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) + # sqlcmd=''' + # alter database archivelog; + # alter database open; + # ''' + # output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + # self.ocommon.check_sql_err(output,error,retcode,True) + + + def restart_for_db_unique_name(self): + """ + restarting the db, when db_unique_name is passed explicitly + """ + if self.ocommon.check_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",self.ora_env_dict): + if self.ora_env_dict["RESTART_DB_TO_SET_DB_UNIQUE_NAME"] == 'true': + msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Restarting the Database to set the DB_UNIQUE_NAME! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) + self.ocommon.log_info_message(msg,self.file_name) + + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) + self.ocommon.shutdown_db(self.ora_env_dict) + self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) + self.ocommon.start_db(self.ora_env_dict) + + + def create_pdb(self): + """ + This function creates the PDB + """ + inst_sid=self.ora_env_dict["ORACLE_SID"] + ohome=self.ora_env_dict["ORACLE_HOME"] + if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): + self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) + opdb=self.ora_env_dict["ORACLE_PDB"] + status=self.ocommon.check_pdb(opdb) + if not status: + self.ocommon.create_pdb(ohome,opdb,inst_sid) + self.ocommon.create_pdb_tns_entry(ohome,opdb) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + + def setup_pdb_shard(self): + """ + This function setup the shard. + """ + sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up Shard PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter pluggable database {0} close immediate; + alter pluggable database {0} open services=All; + ALTER PLUGGABLE DATABASE {0} SAVE STATE; + alter system register; + alter session set container={0}; + grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; + grant sysdg to GSMUSER; + grant sysbackup to GSMUSER; + execute DBMS_GSM_FIX.validateShard; + alter system register; + '''.format(self.ora_env_dict["ORACLE_PDB"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + def alter_db(self): + """ + Alter db + """ + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) + sqlcmd=''' + alter database flashback on; + alter database force logging; + ALTER PLUGGABLE DATABASE ALL OPEN; + ''' + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,None) + + def update_shard_setup(self): + """ + This function update the shard setup on this DB. + """ + # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") + systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + +# self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + + msg='''Updating shardsetup table''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + set heading off + set feedback off + create table system.shardsetup (status varchar2(10)); + insert into system.shardsetup values('completed'); + commit; + exit; + ''' + output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Reset File + shard_reset_dir='''{0}/.shard'''.format(self.ora_env_dict["HOME"]) + shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) + + self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) + if not os.path.isdir(shard_reset_dir): + self.ocommon.create_dir(shard_reset_dir,True,None,None) + + if not os.path.isfile(shard_reset_file): + self.ocommon.create_file(shard_reset_file,True,None,None) + +# self.ocommon.unset_mask_str() + + ########## SETUP_CDB_SHARD FUNCTION ENDS HERE ############################### + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ###################################### Run custom scripts ################################################## + def run_custom_scripts(self): + """ + Custom script to be excuted on every restart of enviornment + """ + self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): + shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] + if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): + shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] + script_file = '''{0}/{1}'''.format(shard_dir,shard_file) + if os.path.isfile(script_file): + msg='''Custom shard script exist {0}'''.format(script_file) + self.ocommon.log_info_message(msg,self.file_name) + cmd='''sh {0}'''.format(script_file) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,True) + + ############################### GSM Completion Message ####################################################### + def gsm_completion_message(self): + """ + Funtion print completion message + """ + self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) + msg=[] + msg.append('==============================================') + msg.append(' GSM Shard Setup Completed ') + msg.append('==============================================') + + for text in msg: + self.ocommon.log_info_message(text,self.file_name) + ################################ Reset and standby functions ################################################# + + def set_primary_listener(self): + """ + Function to set the primary listener + """ + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) + self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) + + def set_db_listener(self,gdbname,sid): + """ + Funtion to reset the listener + """ + self.ocommon.log_info_message("Inside reset_listener()",self.file_name) + start = 'SID_LIST_LISTENER' + end = '^\)$' + oracle_home=self.ora_env_dict["ORACLE_HOME"] + lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) + buffer = "SID_LIST_LISTENER=" + '\n' + start_flag = False + try: + with open(lisora) as f: + for line1 in f: + if start_flag == False: + if (re.match(start, line1.strip())): + start_flag = True + elif (re.match(end, line1.strip())): + line2 = f.next() + if (re.match(end, line2.strip())): + break + else: + buffer += line1 + buffer += line2 + else: + if start_flag == True: + buffer += line1 + except: + pass + + if start_flag == True: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + else: + buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") + listener = self.ocommon.get_lisora(1521) + listener += '\n' + buffer + + wr = open(lisora, 'w') + wr.write(listener) + + def restart_listener(self): + """ + restart listener + """ + self.ocommon.log_info_message("Stopping Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl stop'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + self.ocommon.log_info_message("Starting Listener",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl start'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + def register_services(self): + """ + This function setup the catalog. + """ + # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) + # Assigning variable + ohome=self.ora_env_dict["ORACLE_HOME"] + inst_sid=self.ora_env_dict["ORACLE_SID"] + sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) + self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) + if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): + msg='''Setting up catalog PDB''' + self.ocommon.log_info_message(msg,self.file_name) + sqlcmd=''' + alter system register; + alter session set container={0}; + alter system register; + exit; + '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) + + output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) + self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) + self.ocommon.check_sql_err(output,error,retcode,True) + + ### Unsetting the encrypt value to None + self.ocommon.unset_mask_str() + + def list_services(self): + """ + restart listener + """ + self.ocommon.log_info_message("Listing Services",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + cmd='''{0}/bin/lsnrctl services'''.format(ohome) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) + self.ocommon.check_os_err(output,error,retcode,None) + + def backup_files(self): + """ + This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig + """ + self.ocommon.log_info_message("Inside backup_files()",self.file_name) + ohome=self.ora_env_dict["ORACLE_HOME"] + obase=self.ora_env_dict["ORACLE_BASE"] + dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] + dbsid=self.ora_env_dict["ORACLE_SID"] + + version=self.ocommon.get_oraversion(ohome).strip() + wallet_backup_cmd='''ls -ltr /bin''' + self.ocommon.log_info_message("Check Version " + version,self.file_name) + if int(version) >= 21: + obase1=self.ora_env_dict["ORACLE_BASE"] + wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) + cmd_names=''' + mkdir -p {0}/oradata/{1}/{2} + cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ + cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ + cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ + cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ + {4} + touch {0}/oradata/{1}/{2}/status_completed + '''.format(obase,"dbconfig",dbuname,ohome,wallet_backup_cmd) + cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] + for cmd in cmd_list: + msg='''Executing cmd {0}'''.format(cmd) + self.ocommon.log_info_message(msg,self.file_name) + output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orascatalog.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orascatalog.py new file mode 100755 index 0000000..aa4ea65 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orascatalog.py @@ -0,0 +1,9 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orasshard.py b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orasshard.py new file mode 100755 index 0000000..58f168b --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/orasshard.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + + +import os +import sys +import os.path +import re +import socket +from oralogger import * +from oraenv import * +from oracommon import * +from oramachine import * +import traceback + +class OraSShard: + """ + This calss setup the standby shard after DB installation. + """ + def __init__(self,oralogger,orahandler,oraenv,oracommon): + """ + This constructor of OraSShard class to setup the shard on standby DB. + + Attributes: + oralogger (object): object of OraLogger Class. + ohandler (object): object of Handler class. + oenv (object): object of singleton OraEnv class. + ocommon(object): object of OraCommon class. + ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. + file_name(string): Filename from where logging message is populated. + """ + try: + self.ologger = oralogger + self.ohandler = orahandler + self.oenv = oraenv.get_instance() + self.ocommon = oracommon + self.ora_env_dict = oraenv.get_env_vars() + self.file_name = os.path.basename(__file__) + self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) + except BaseException as ex: + ex_type, ex_value, ex_traceback = sys.exc_info() + trace_back = traceback.extract_tb(ex_traceback) + stack_trace = list() + for trace in trace_back: + stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) + ocommon.log_info_message(ex_type.__name__,self.file_name) + ocommon.log_info_message(ex_value,self.file_name) + ocommon.log_info_message(stack_trace,self.file_name) + def setup(self): + """ + This function setup the shard on standby DB. + """ + pass diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/runOraShardSetup.sh b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/runOraShardSetup.sh new file mode 100644 index 0000000..c1b09b4 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/runOraShardSetup.sh @@ -0,0 +1,568 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +export CLONED_FILE="status_completed" +export STANDBY_STATUS="status_completed" + +########### Clone Files ##################### +function cloneDB { + +export NEW_ORACLE_SID=$ORACLE_SID +export ORACLE_SID=$OLD_ORACLE_SID +sqlplus / as sysdba << EOF + STARTUP mount; + exit; +EOF + +echo 'Y' | nid target=/ dbname="$NEW_ORACLE_SID" + +if [ $? -eq 0 ]; then + echo "DB name changed sucessfully" +else + echo "DB name change process failed" + exit 1; +fi + +if [ -z ${DB_RECOVERY_FILE_DEST} ]; then + export DB_RECOVERY_FILE_DEST=$ORACLE_BASE/oradata/fast_recovery_area/$NEW_ORACLE_SID +fi + +if [ -z ${DB_UNIQUE_NAME} ]; then + export DB_UNIQUE_NAME=$NEW_ORACLE_SID +fi + +export ORACLE_HOSTNAME=$( hostname -f ) + +echo "Changing DB name" +export ORACLE_SID=$NEW_ORACLE_SID +sqlplus / as sysdba << EOF + STARTUP nomount; + alter system set db_name=$ORACLE_SID scope=spfile; + alter system set open_links=16 scope=spfile; + alter system set open_links_per_instance=16 scope=spfile; + alter system set dg_broker_config_file1="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr2$DB_UNIQUE_NAME.dat" scope=spfile; + alter system set dg_broker_config_file2="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr1$DB_UNIQUE_NAME.dat" scope=spfile; + alter system set db_file_name_convert='*','$ORACLE_BASE/oradata/$DB_UNIQUE_NAME/' scope=spfile; + alter system set local_listener='$ORACLE_HOSTNAME' scope=spfile; + alter system set standby_file_management='auto' scope=spfile; + shutdown immediate + exit; +EOF + +## Get the version + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 21 ]; then + echo "Setting DB Parameter based on the vserion" + export ORACLE_SID=$NEW_ORACLE_SID + sqlplus / as sysdba << EOF + startup nomount + alter system set wallet_root="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME" scope=spfile; + shutdown immediate + exit; +EOF + fi + fi + +echo "Changing OLD SID string to new string" +sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_HOME/network/admin/tnsnames.ora +sed -i "s/$OLD_ORACLE_PDB/$ORACLE_PDB/g" $ORACLE_HOME/network/admin/tnsnames.ora + +echo "Starting Listener" + +$ORACLE_HOME/bin/lsnrctl start + +echo "Starting new cloned DB" + +sqlplus / as sysdba << EOF + STARTUP mount; + alter database archivelog; + alter database open resetlogs; + exit; +EOF + +echo "Renaming PDB" + +sqlplus / as sysdba << EOF + alter pluggable database $OLD_ORACLE_PDB open restricted; + alter session set container=$OLD_ORACLE_PDB; + alter pluggable database rename global_name to $ORACLE_PDB; + exit; +EOF + +echo " Closing and Opening PDB" + +sqlplus / as sysdba << EOF + alter pluggable database $ORACLE_PDB close immediate; + alter pluggable database $ORACLE_PDB open; + alter system register; + exit; +EOF + + +echo "Touching $CLONED_FILE as setup is completed" +touch $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE + +} + +############################################ +########### Symbolic link DB files ######### +############################################ +########### DB Version >= 23c ############## +############################################ +function symLinkFiles23c { + + if [ -z ${ORACLE_BASE_HOME} ]; then + # + export ORACLE_BASE_HOME=$ORACLE_HOME + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora + fi; + if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/listener.ora + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora + fi + if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then + unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + ## Link based on ORACLE_BASE +# ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/spfile$ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi + fi + fi; + + if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID + fi; + + if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID + fi; + + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then + ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB + fi; + # oracle user does not have permissions in /etc, hence cp and not ln + sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab + cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab + fi +fi + +} + + +############################################ +########### Symbolic link DB files ######### +############################################ +########### DB Version < 23c ############### +############################################ +function symLinkFiles { + + if [ -z ${ORACLE_BASE_HOME} ]; then + # + export ORACLE_BASE_HOME=$ORACLE_HOME + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then + unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + fi; + if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + fi; + if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora + fi; + if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/listener.ora + fi; + if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then + unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora + fi + if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then + unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID + fi; + if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then + unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$OLD_ORACLE_SID + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID + ## Link based on ORACLE_BASE + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora + fi + fi + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + else + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora + fi + fi + fi; + + if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID + fi; + + if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then + ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID + fi; + + if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then + mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID + fi; + + if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then + ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB + fi; + # oracle user does not have permissions in /etc, hence cp and not ln + sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab + cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab + fi +fi + +} + +################################### +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +# Check whether container has enough memory +# Github issue #219: Prevent integer overflow, +# only check if memory digits are less than 11 (single GB range and below) +if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes | wc -c` -lt 11 ]; then + if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` -lt 2147483648 ]; then + echo "Error: The container doesn't have enough memory allocated." + echo "A database container needs at least 2 GB of memory." + echo "You currently only have $((`cat /sys/fs/cgroup/memory/memory.limit_in_bytes`/1024/1024/1024)) GB allocated to the container." + exit 1; + fi; +fi; + + +# Check that hostname doesn't container any "_" +# Github issue #711 +if hostname | grep -q "_"; then + echo "Error: The hostname must not container any '_'". + echo "Your current hostname is '$(hostname)'" +fi; + +# Default for ORACLE SID +if [ "$OLD_ORACLE_SID" == "" ]; then + export OLD_ORACLE_SID=SEEDCDB +fi + +if [ ! -z ${ORACLE_SID} ]; then + # Make ORACLE_SID upper case + # Github issue # 984 + export ORACLE_SID=${ORACLE_SID^^} + + # Check whether SID is no longer than 12 bytes + # Github issue #246: Cannot start OracleDB image + if [ "${#ORACLE_SID}" -gt 12 ]; then + echo "Error: The ORACLE_SID must only be up to 12 characters long." + exit 1; + fi; + + # Check whether SID is alphanumeric + # Github issue #246: Cannot start OracleDB image + if [[ "$ORACLE_SID" =~ [^a-zA-Z0-9] ]]; then + echo "Error: The ORACLE_SID must be alphanumeric." + exit 1; + fi; +else + echo "Error: The ORACLE_SID must be defined." + exit 1; +fi; + + +if [ ! -z ${ORACLE_PDB} ]; then + export ORACLE_PDB=${ORACLE_PDB^^} + + if [ "${#ORACLE_PDB}" -gt 12 ]; then + echo "Error: The ORACLE_PDB must only be up to 12 characters long." + exit 1; + fi; +else + echo "Error: The ORACLE_PDB must be defined." + exit 1; +fi; + +if [ ! -z ${OLD_ORACLE_PDB} ]; then + export OLD_ORACLE_PDB=${OLD_ORACLE_PDB^^} +else + export OLD_ORACLE_PDB=SEEDPDB +fi; + + +# Default for ORACLE CHARACTERSET +export ORACLE_CHARACTERSET=${ORACLE_CHARACTERSET:-AL32UTF8} + +# Check whether database already exists +if [ ! -z ${CLONE_DB} ]; then +if [ ${CLONE_DB^^} == "TRUE" ]; then +echo "CLONE_DB is set to true, cloning DB from seed" +if [ -d $ORACLE_BASE/oradata/$OLD_ORACLE_SID ]; then + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 23 ]; then + symLinkFiles23c; + else + symLinkFiles; + fi; + else + echo "Unable to determine the Database Version, exiting.." + exit 1; + fi + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump + fi; + + # Make sure audit file destination exists + if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then + mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump + fi; + + if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE ]; + then + # Start database + echo "Starting Database as cloned status file exist" + $ORACLE_BASE/$START_FILE; + else + echo "Performing Cloning as cloned status file does not exist" + cloneDB; + $ORACLE_BASE/checkDBStatus.sh + if [ $? -eq 0 ]; then + echo "DB is in READ WRITE State" + touch "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" + $ORACLE_BASE/$LOCKING_SCRIPT --acquire --file "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" + else + echo "DB is not in READ WRITE state" + exit 1; + fi + fi +else + echo "Error: The $ORACLE_BASE/oradata/$OLD_ORACLE_SID (ORACLE_BASE/oradata/OLD_ORACLE_SID) dir does not exist. Error exiting ." + exit 1; +fi +fi +fi + +if [ ${OP_TYPE,,} == "standbyshard" ]; then + dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) + if [ ! -z ${dbversion} ]; then + if [ ${dbversion} -ge 23 ]; then + symLinkFiles23c; + else + symLinkFiles; + fi; + else + echo "Unable to determine the Database Version, exiting.." + exit 1; + fi + + if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/$STANDBY_STATUS ]; + then + # Start database + echo "Starting Database as standby setup status file exist" + $ORACLE_BASE/$START_FILE; + fi +fi + +#This is the main file which calls other file to setup the sharding. +if [ -z ${BASE_DIR} ]; then + BASE_DIR=/opt/oracle/scripts/sharding +fi + +if [ -z ${MAIN_SCRIPT} ]; then + SCRIPT_NAME="main.py" +fi + +if [ -z ${EXECUTOR} ]; then + EXECUTOR="python" +fi + +cd $BASE_DIR +$EXECUTOR $SCRIPT_NAME diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/scripts/runOracle.sh b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/runOracle.sh new file mode 100755 index 0000000..2266e99 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/scripts/runOracle.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# +# Since: January, 2020 +# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com + +########### SIGINT handler ############ +function _int() { + echo "Stopping container." + echo "SIGINT received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown immediate; + exit; +EOF + lsnrctl stop +} + +########### SIGTERM handler ############ +function _term() { + echo "Stopping container." + echo "SIGTERM received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown immediate; + exit; +EOF + lsnrctl stop +} + +########### SIGKILL handler ############ +function _kill() { + echo "SIGKILL received, shutting down database!" + sqlplus / as sysdba <<EOF + shutdown abort; + exit; +EOF + lsnrctl stop +} + + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +############# MAIN ################ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # +################################### + +if [ ! -z ${SHARD_SETUP} ]; then + if [ ${SHARD_SETUP,,} == "true" ]; then + sh $ORACLE_BASE/scripts/sharding/runOraShardSetup.sh + fi +fi + +if [ ! -z ${CLONE_DB} ]; then + if [ ${CLONE_DB^^} == "TRUE" ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & + fi +fi + +if [ ! -z ${OP_TYPE} ]; then + if [ ${OP_TYPE,,} == "standbyshard" ]; then + echo "The following output is now a tail of the alert.log:" + tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & + fi +fi + +# Set SIGINT handler +trap _int SIGINT + +# Set SIGTERM handler +trap _term SIGTERM + +# Set SIGKILL handler +trap _kill SIGKILL + + +childPID=$! +wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/setupGSM.sh b/container-based-sharding-deployment/containerfiles/23.5.0/setupGSM.sh new file mode 100644 index 0000000..4a6a6ca --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/setupGSM.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +# Create Directories +mkdir -p $GSM_BASE +mkdir -p $GSM_HOME +mkdir -p $INVENTORY + +chown -R oracle:oinstall $INVENTORY +chown -R oracle:oinstall $GSM_BASE +chown -R oracle:oinstall $GSM_HOME +chown -R oracle:oinstall $INSTALL_SCRIPTS +chmod 775 $INSTALL_SCRIPTS + +chmod 666 /etc/sudoers +echo "oracle ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +chmod 440 /etc/sudoers + +echo "export ORACLE_HOME=$GSM_HOME" >> /home/oracle/.bashrc +echo "export PATH=$GSM_PATH" >> /home/oracle/.bashrc +echo "export LD_LIBRARY_PATH=$GSM_LD_LIBRARY_PATH" >> /home/oracle/.bashrc +echo "export SCRIPT_DIR=$SCRIPT_DIR" >> /home/oracle/.bashrc +echo "export GSM_HOME=$GSM_HOME" >> /home/oracle/.bashrc diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/setupLinuxEnv.sh b/container-based-sharding-deployment/containerfiles/23.5.0/setupLinuxEnv.sh new file mode 100644 index 0000000..c652b9b --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/setupLinuxEnv.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +if grep -q "Oracle Linux Server release 9" /etc/oracle-release; then \ + curl --noproxy '*' https://ca-artifacts.oraclecorp.com/auto-build/x86_64-build-output-9-dev/oracle-database-preinstall-23ai-1.0-1.4.el9.x86_64.rpm --output oracle-database-preinstall-23ai-1.0-1.4.el9.x86_64.rpm && \ + dnf install -y oracle-database-preinstall-23ai-1.0-1.4.el9.x86_64.rpm && \ + rm -f /etc/systemd/system/oracle-database-preinstall-23ai-firstboot.service && \ + dnf clean all; \ +else \ + dnf -y install oraclelinux-developer-release-el8 && \ + dnf -y install oracle-database-preinstall-23c && \ + rm -f /etc/rc.d/init.d/oracle-database-preinstall-23c-firstboot && \ + dnf clean all; \ +fi && \ +dnf -y install net-tools zip unzip tar openssl openssh-server vim-minimal which passwd sudo python3 hostname fontconfig lsof && \ +dnf clean all && \ +chmod ug+x $SCRIPT_DIR/*.sh && \ +rm -f /etc/sysctl.conf && \ +rm -f /usr/lib/systemd/system/dnf-makecache.service \ No newline at end of file diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/setupOshardEnv.sh b/container-based-sharding-deployment/containerfiles/23.5.0/setupOshardEnv.sh new file mode 100755 index 0000000..5ae2692 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/23.5.0/setupOshardEnv.sh @@ -0,0 +1,970 @@ +#!/bin/bash +# +# LICENSE UPL 1.0 +# Since: November, 2020 +# Author: paramdeep.saini@oracle.com +# Description: +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020,2021 Oracle and/or its affiliates. +# + +export NOW=$(date +"%Y%m%d%H%M") +export LOGDIR="/tmp" +export LOGFILE="${LOGDIR}/oshard_${NOW}.log" +export STD_OUT_FILE="/proc/1/fd/1" +export STD_ERR_FILE="/proc/1/fd/2" +declare -x SECRET_VOLUME='/run/secrets/' ## Secret Volume +declare -x PWD_KEY='pwd.key' ## PWD Key File +declare -x COMMON_OS_PWD_FILE='common_os_pwdfile.enc' +declare -x DB_PWD_FILE +export PDB_SQL_SCRIPT="/tmp/pdb.sql" +export TOP_PID=$$ +rm -f /tmp/sqllog.output +rm -f $PDB_SQL_SCRIPT +rm -f $LOGFILE + +#################################### Print and Exit Functions Begin Here ####################### +error_exit() { +local NOW=$(date +"%m-%d-%Y %T %Z") + # Display error message and exit +# echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2 + echo "${NOW} : ${PROGNAME}: ${1:-"Unknown Error"}" | tee -a $LOGFILE > $STD_OUT_FILE + kill -s TERM $TOP_PID +} + +print_message () +{ + local NOW=$(date +"%m-%d-%Y %T %Z") + # Display message and return + echo "${NOW} : ${PROGNAME} : ${1:-"Unknown Message"}" | tee -a $LOGFILE > $STD_OUT_FILE + return $? +} +#################################### Print and Exit Functions End Here ####################### + + +####################################### Functions Related to checks #################### +dbChecks() +{ +if [ -z "$ORACLE_HOME" ] +then + error_exit "Set the ORACLE_HOME variable" +else + print_message "ORACLE_HOME set to $ORACLE_HOME" +fi + +# If ORACLE_HOME doesn't exist # +if [ ! -d "$ORACLE_HOME" ] +then + error_exit "The ORACLE_HOME $ORACLE_HOME does not exist" +else + print_message "ORACLE_HOME Directory Exist" +fi + +################## Checks for Password and Clustername and clustertype begins here ########### +if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then +cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' + +eval $cmd + +if [ $? -eq 0 ]; then +print_message "Password file generated" +else +error_exit "Error occurred during common os password file generation" +fi + +read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} +rm -f /tmp/${COMMON_OS_PWD_FILE} +else + print_message "Password is empty string" + export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 +fi + +if [ -z "${ORACLE_PWD}" ]; then + print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" + export ORACLE_PWD=${PASSWORD} +else + print_message "ORACLE_PWD is set to user specified password" +fi + +################################################################################################### + + +if [ -z "${SHARD_ADMIN_USER}" ] +then + print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + export SHARD_ADMIN_USER="mysdbadmin" +else + print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" +fi + + +if [ -z "${PDB_ADMIN_USER}" ] +then + print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" + export PDB_ADMIN_USER="pdbadmin" +else + print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" +fi + + +# Validate the value of ORACLE_SID # +if [ -z "${ORACLE_SID}" ] +then + error_exit "Set the ORACLE_SID variable" +else + print_message "ORACLE_SID is set to $ORACLE_SID" +fi + +if [ -z "${ORACLE_HOSTNAME}" ] +then + if [ -z "${KUBE_SVC}" ]; then + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname)" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + else + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + fi +else + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" +fi + + + +if [ -z "$DB_PORT" ] +then + print_message "Set the DB_PORT variable" + export DB_PORT=1521 +else + print_message "DB Port is set to $DB_PORT" +fi + +if [ -z "${DB_RECOVERY_FILE_DEST}" ]; then + print_message "Set the DB_RECOVERY_FILE_DEST is not set" + export DB_RECOVERY_FILE_DEST="${ORACLE_BASE}/oradata/fast_recovery_area/${ORACLE_SID}" +fi + +if [ -z "${DB_CREATE_FILE_DEST}" ]; then + print_message "Set the DB_CREATE_FILE_DEST is not set. Setting to ${ORACLE_BASE}/oradata/${ORACLE_SID}" + export DB_CREATE_FILE_DEST="${ORACLE_BASE}/oradata/${ORACLE_SID}" +fi + +if [ -z "${DATA_PUMP_DIR}" ]; then + print_message "DATA_PUMP_DIR is not set, it will se to ${ORACLE_BASE}/oradata/data_pump_dir" + export DATA_PUMP_DIR="${ORACLE_BASE}/oradata/data_pump_dir" +fi + +if [ ! -d "${DATA_PUMP_DIR}" ]; then + print_message "DATA_PUMP_DIR ${DATA_PUMP_DIR} directory does not exist" + mkdir -p "${DATA_PUMP_DIR}" +fi + +if [ ! -d "${DB_RECOVERY_FILE_DEST}" ]; then + print_message "DB_RECOVERY_FILE_DEST ${DB_RECOVERY_FILE_DEST} directory does not exist" + mkdir -p "${DB_RECOVERY_FILE_DEST}" +fi + +if [ -z "${DB_RECOVERY_FILE_DEST_SIZE}" ]; then + print_message "DB_RECOVERY_FILE_DEST_SIZE is not set" + export DB_RECOVERY_FILE_DEST_SIZE="40G" +else + print_message "DB_RECOVERY_FILE_DEST_SIZE is set to ${DB_RECOVERY_FILE_DEST_SIZE}" +fi + +} + +gsmChecks() +{ + print_message "Performing GSM related checks" + +if [ ! -z "${KUBE_SVC}" ]; then + lordinal=$( hostname | awk -F "-" '{ print $NF }' ) + print_message "lordinal is set to ${lordinal}" + region_num=$((lordinal+1)) + if [ -z "${REGION}" ]; then + print_message "REGION is not set. Setting to region$lordinal" + export REGION="region${region_num}" + fi +else + if [ -z "${REGION}" ]; then + error_exit "REGION Canot be set to empty" + fi +fi + +################## Checks for Password and Clustername and clustertype begins here ########### +if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then +cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' + +eval $cmd + +if [ $? -eq 0 ]; then +print_message "Password file generated" +else +error_exit "Error occurred during common os password file generation" +fi + +read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} +rm -f /tmp/${COMMON_OS_PWD_FILE} +else + print_message "Password is empty string" + export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 +fi + +if [ -z "${ORACLE_PWD}" ]; then + print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" + export ORACLE_PWD=${PASSWORD} +else + print_message "ORACLE_PWD is set to user specified password" +fi + +################################################################################################### + +if [ -z "$SHARD_ADMIN_USER" ] +then + print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" + export SHARD_ADMIN_USER="mysdbadmin" +else + print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" +fi + + +if [ -z "$PDB_ADMIN_USER" ] +then + print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" + export PDB_ADMIN_USER="pdbadmin" +else + print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" +fi + + +if [ -z "${SHARD_GROUP_NAME}" ]; then + print_message "SHARD_GROUP_NAME is not set, it will be set to primary_shardgroup" + export SHARD_GROUP_NAME="primary_shardgroup" +fi + +if [ -z "${SHARD_DEPLOYMENT_TYPE}" ]; then + print_message "SHARD_DEPLOYMENT_TYPE is not set, it will set to primary" + export SHARD_DEPLOYMENT_TYPE="primary" +fi + +if [ -z "${SHARD_DIRECTOR_NAME}" ]; then + print_message "SHARD_DIRECTOR_NAME is not set, it will set to sharddirector${region_num}" + export SHARD_DIRECTOR_NAME="sharddirector${region_num}" +fi + +if [ -z "${ORACLE_HOSTNAME}" ] +then + if [ -z "${KUBE_SVC}" ]; then + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname)" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + else + print_message "ORACLE_HOSTNAME variable is not set" + export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" + fi +else + print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" +fi + +} + +###################################### Function Related to Check end here ################### + +################################### Reset Password ########################################### +resetPassword() +{ +if [ -f "${HOME}/setPassword.sh" ]; then +if [ ! -z "${ORACLE_PWD}" ]; then +"${HOME}"/setPassword.sh "$ORACLE_PWD" +fi +fi +} + +############################################################################################### +setupCatalog() +{ + +localconnectStr="/ as sysdba" +systemStr="system/${ORACLE_PWD}" +sqlScript="/tmp/setapp.sql" +print_message "Setting up Paramteres in Spfile" + +cmd1="drop table shardsetup;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" +#cmd=$( eval echo "$cmd1" ) +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links_per_instance=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="@$ORACLE_HOME/rdbms/admin/setCatalogDBPrivs.sql;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" +print_message "cat /tmp/setup_grants_privs.lst" + +cmd1="alter user gsmcatuser account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmcatuser identified by $ORACLE_PWD;" +print_message "Sending query to sqlplus to execute alter user gsmcatuser identified by ORACLE_PWD;" +executeSQL "$cmd1" "$localconnectStr" + + +#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" +cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + + +cmd1="shutdown immediate;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="startup mount;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database archivelog;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database open;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database flashback on;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database force logging;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1", "$localconnectStr" + +cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +if [ ! -z "${ORACLE_PDB}" ]; then +setupCatalogPDB +fi + +cmd1="create table shardsetup (status varchar2(10));" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="insert into shardsetup values('completed');" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" +} + +configureSampleAppSchema() +{ +local sqlScript="/tmp/sqlScript.sql" +connectStr = "${SHARD_ADMIN_USER}/${ORACLE_PWD}" + +echo "alter session enable shard ddl;" > ${sqlScript} +echo "create user app_schema identified by '&1';" >> ${sqlScript} +echo "grant all privileges to app_schema;" >> ${sqlScript} +echo "grant gsmadmin_role to app_schema;" >> ${sqlScript} +echo "grant select_catalog_role to app_schema;" >> ${sqlScript} +echo "grant connect, resource to app_schema;" >> ${sqlScript} +echo "grant dba to app_schema;" >> ${sqlScript} +echo "grant execute on dbms_crypto to app_schema;" >> ${sqlScript} +echo "CREATE TABLESPACE SET TSP_SET_1 using template (datafile size 100m autoextend on next 10M maxsize unlimited extent management local segment space management auto);" >> ${sqlScript} +echo "CREATE TABLESPACE SET LOBTS1;" >> ${sqlScript} +echo "CREATE TABLESPACE products_tsp datafile size 100m autoextend on next 10M maxsize unlimited extent management local uniform size 1m; " >> ${sqlScript} +echo "CONNECT app_schema/'&1';" >> ${sqlScript} +echo "ALTER SESSION ENABLE SHARD DDL;" >> ${sqlScript} +echo "CREATE SHARDED TABLE Customers (CustId VARCHAR2(60) NOT NULL, FirstName VARCHAR2(60), LastName VARCHAR2(60), Class VARCHAR2(10), Geo VARCHAR2(8),CustProfile VARCHAR2(4000),Passwd RAW(60),CONSTRAINT pk_customers PRIMARY KEY (CustId),CONSTRAINT json_customers CHECK (CustProfile IS JSON)) TABLESPACE SET TSP_SET_1 PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO;" >> ${sqlScript} +echo "CREATE SHARDED TABLE Orders (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL, OrderDate TIMESTAMP NOT NULL,SumTotal NUMBER(19,4),Status CHAR(4), CONSTRAINT pk_orders PRIMARY KEY (CustId, OrderId),CONSTRAINT fk_orders_parent FOREIGN KEY (CustId) REFERENCES Customers ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_orders_parent);" >> ${sqlScript} +echo "CREATE SEQUENCE Orders_Seq;" >> ${sqlScript} +echo "CREATE SHARDED TABLE LineItems (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL,ProductId INTEGER NOT NULL,Price NUMBER(19,4),Qty NUMBER,CONSTRAINT pk_items PRIMARY KEY (CustId, OrderId, ProductId),CONSTRAINT fk_items_parent FOREIGN KEY (CustId, OrderId) REFERENCES Orders ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_items_parent);" >> ${sqlScript} +echo "CREATE DUPLICATED TABLE Products (ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,Name VARCHAR2(128),DescrUri VARCHAR2(128),LastPrice NUMBER(19,4)) TABLESPACE products_tsp;" >> ${sqlScript} + +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "$connectStr" "sqlScript" "${sqlScript}" + +} + + +setupCatalogPDB() +{ +#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" +pdbConnStr=" /as sysdba" + +local sqlScript="/tmp/sqlScript.sql" + +print_message "Settup Sql Script to setup Catalog PDB" +echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" +echo "create user ${SHARD_ADMIN_USER} identified by ${ORACLE_PWD};" >> "${sqlScript}" +echo "grant connect, create session, gsmadmin_role to ${SHARD_ADMIN_USER} ;" >> "${sqlScript}" +echo "grant inherit privileges on user SYS to GSMADMIN_INTERNAL;" >> "${sqlScript}" +echo "execute dbms_xdb.sethttpport(8080);" >> ${sqlScript} +echo "exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('${ORACLE_PWD}');" >> "${sqlScript}" + +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" +} + +######################################################################## Catalog Setup task ends here ################################# + +######################################################################## Primary Shard Setup task ends here ################################# + +setupShardPDB() +{ + +#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" +pdbConnStr=" /as sysdba" + +local sqlScript="/tmp/sqlScript.sql" +print_message "Settup Sql Script to setup Catalog PDB" +echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" +echo "grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" >> "${sqlScript}" +echo "grant sysdg to GSMUSER;" >> "${sqlScript}" +echo "grant sysbackup to GSMUSER;" >> "${sqlScript}" +echo "execute DBMS_GSM_FIX.validateShard;" >> ${sqlScript} +print_message "Executing sql script ${sqlScript}" +cat ${sqlScript} >> $LOGFILE +executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" + +} + +setupShardCDB() +{ +localconnectStr="/as sysdba" +systemStr="system/${ORACLE_PWD}" +print_message "Setting up Paramteres in Spfile" + +cmd1="drop table shardsetup;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + +cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set open_links_per_instance=16 scope=spfile;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmrootuser account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user gsmrootuser identified by ${ORACLE_PWD} container=all;" +print_message "Sending query to sqlplus to execute alter user gsmrootuser identified by ORACLE_PWD container=all;" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysdg to gsmrootuser;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysbackup to gsmrootuser;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user GSMUSER account unlock;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter user GSMUSER identified by ${ORACLE_PWD} container=all;" +print_message "Sending query to sqlplus to execute alter user GSMUSER identified by ORACLE_PWD container=all;" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysdg to GSMUSER;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant sysbackup to GSMUSER;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter system set dg_broker_start=true scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="create or replace directory DATA_PUMP_DIR as '${DATA_PUMP_DIR}';" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" +cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="shutdown immediate;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="startup mount;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database archivelog;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database open;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database flashback on;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="alter database force logging;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" +# cmd=$(eval echo "$cmd1") +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$localconnectStr" + + +if [ ! -z "${ORACLE_PDB}" ]; then + +setupShardPDB + +fi + +cmd1="create table shardsetup (status varchar2(10));" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + + +cmd1="insert into shardsetup values('completed');" +print_message "Sending query to sqlplus to execute $cmd1" +executeSQL "$cmd1" "$systemStr" + +} + +######################################################################## Primary Shard Setup ends here ################################# + +######################################################################## GSM Setup Task Begin here ##################################### +setupGSM() +{ +local cstatus='false' +local sstatus='false' + +setupGSMCatalog +startGSM +addShardGroup +setupGSMShard + +} + +startGSM() +{ + +cmd1="start gsm" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +deployShard() +{ + +cmd1="deploy" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +stopGSM() +{ + +cmd1="stop gsm" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +addInvitedNode() +{ + +chost=$1 + +cmd1="add invitednode $chost" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + + +addShardGroup() +{ + +cmd1="add shardgroup -shardgroup ${shardGName} -deploy_as ${deployment_type} -region ${region}" +print_message "Sending query to gsm to execute $cmd1" +executeGSM "$cmd1" +} + +checkStatus() +{ +host=$1 +port=1521 +cpdb=$3 +ccdb=$2 +uname="system" +cpasswd=${ORACLE_PWD} + +print_message "Connect String $uname/$cpasswd@//$host:$port/$ccdb" +output=$( "$ORACLE_HOME"/bin/sqlplus -s "$uname/$cpasswd@//$host:$port/$ccdb" <<EOF + set heading off feedback off verify off echo off PAGESIZE 0 + select status from shardsetup; + exit +EOF +) + + if [ "${output}" == 'completed' ];then + print_message "Returned status from catalog is $output" + else + print_message "Sleeping for 300 seconds as returned status is not $output " + sleep 300 + fi + + echo $output +} + +setupGSMCatalog() +{ +IFS='; ' read -r -a sarray <<< "$CATALOG_PARAMS" +for element in "${sarray[@]}" +do + print_message "1st String in Shard params $element" + type=$( echo $element | awk -F: '{print $NF }') + host=$( echo $element | awk -F: '{print $1 }') + db=$( echo $element | awk -F: '{print $2 }') + pdb=$( echo $element | awk -F: '{print $3 }') +done + +print_message "Set variables to host=${host} db=${db} pdb=${pdb}" +if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] +then +runtime="60 minute" +endtime=$(date -ud "$runtime" +%s) + +while [[ $(date -u +%s) -le $endtime ]] +do + + coutput=$( checkStatus $host $db $pdb ) + if [ "${coutput}" == 'completed' ] ;then + configureGSMCatalog $host $db $pdb + break + else + print_message "Catalog Status must return completed but returned value is $coutput" + fi + print_message "Catalog DB is still not ready. Sleeping for 60 seconds" + sleep 60 +done +fi + +if [ "${coutput}" != 'completed' ] ;then + error_exit "Shard Catalog is not setup, Unable to proceed futher" +fi + +} + +configureGSMCatalog() +{ +chost=$1 +cport=1521 +cpdb=$3 +ccdb=$2 +gsmhost=${ORACLE_HOSTNAME} +cadmin=${SHARD_ADMIN_USER} +cpasswd=${ORACLE_PWD} +########################## +region="${REGION}" +shardGName="${SHARD_GROUP_NAME}" +deployment_type="${SHARD_DEPLOYMENT_TYPE}" +local gdsScript="/tmp/gdsScript.sql" + +gsm_name="${SHARD_DIRECTOR_NAME}" +echo "create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=${chost})(PORT=${cport}))(CONNECT_DATA=(SERVICE_NAME=${cpdb})))\" -user ${cadmin}/${cpasswd} -sdb shardcatalog -region region1,region2 -agent_port 8080 -agent_password ${cpasswd} -autovncr off" > "${gdsScript}" +echo "add invitednode ${chost}" >> "${gdsScript}" +echo "add gsm -gsm ${gsm_name} -listener 1521 -pwd ${cpasswd} -catalog ${chost}:${cport}/${cpdb} -region region1 -endpoint '(ADDRESS=(PROTOCOL=tcp)(HOST=${gsmhost})(PORT=1521))'" >> "${gdsScript}" +echo "exit" >> "${gdsScript}" +print_message "Sending script to gsm to execute ${gdsScript}" +cat ${gdsScript} >> $LOGFILE +cp "${gdsScript}" "${gdsScript}.test" +executeGSM "$cmd1" "gdsScript" "${gdsScript}" +} + +setupGSMShard() +{ +IFS='; ' read -r -a sarray <<< "$PRIMARY_SHARD_PARAMS" +arrLen=$( echo "${#sarray[@]}" ) +count1=0 + +runtime="45 minute" +endtime=$(date -ud "$runtime" +%s) + +print_message "Set variables to host=${host} db=${db} pdb=${pdb}" +while [[ $(date -u +%s) -le $endtime ]] +do + for i in ${!sarray[@]}; do + print_message "1st String in Shard params $element" + host=$( echo ${sarray[i]} | awk -F: '{print $1 }') + db=$( echo ${sarray[i]} | awk -F: '{print $2 }') + pdb=$( echo ${sarray[i]} | awk -F: '{print $3 }') + print_message "shard env set to host=${host} db=${db} pdb=${pdb}" + if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] + then + coutput=$( checkStatus $host $db $pdb ) + if [ "${coutput}" == 'completed' ] ;then + configureGSMShard $host $db $pdb + unset sarray[i] + ((++count1)) + else + print_message "Catalog Status must return completed but returned value is $coutput" + fi + fi + done + if [ ${count1} -ge ${arrLen} ]; then + break; + fi + print_message "Shards are still not ready. Sleeping for 120 seconds" + sleep 120 +done +} + +configureGSMShard() +{ +chost=$1 +cport=1521 +cpdb=$3 +ccdb=$2 +cpasswd=${ORACLE_PWD} +region=${REGION} +shardGName="${SHARD_GROUP_NAME}" +deployment_type="${SHARD_DEPLOYMENT_TYPE}" +local gdsScript="/tmp/gdsScript.sql" +admuser="${PDB_ADMIN_USER}" + +echo "connect ${admuser}/${cpasswd}" > "${gdsScript}" +echo "add cdb -connect ${chost}:${cport}:${ccdb} -pwd ${cpasswd}" >> "${gdsScript}" +echo "add shard -cdb ${ccdb} -connect ${chost}:${cport}/${cpdb} -shardgroup ${shardGName} -pwd ${cpasswd}" >> "${gdsScript}" +echo "config vncr" >> "${gdsScript}" +echo "sql 'update gsmadmin_internal.database set hostid=NULL '" >> "${gdsScript}" +echo "exit" >> "${gdsScript}" +print_message "Sending script to gsm to execute ${gdsScript}" +cat ${gdsScript} >> $LOGFILE +executeGSM "$cmd1" "gdsScript" "${gdsScript}" +print_message " Calling Stop GSM function" +stopGSM +print_message "Stop GSM function completed, sleeping for 20 seconds" +sleep 20 +print_message " Calling Start GSM function" +startGSM +print_message "Start GSM function completed, sleeping for 30 seconds" +sleep 30 +print_message "Calling invitenode function to add the shard" +addInvitedNode $chost +deployShard +} + +####################################################################### GSM Setup Task Ends here ######################################### + + +######################################################################### Execute GSM Statements ######################################### +executeGSM() +{ +gsmQuery=$1 +type=$2 +gdsScript=$3 + +if [ -z "${gsmQuery}" ]; then + print_message "Empty gdsQuery passed to gds" +fi + +if [ -z "${type}" ]; then + type='notSet' +fi + +if [ -z "${gdsScript}" ]; then + gdsScript='notSet' +fi + +if [ "${type}" == "gdsScript" ]; then +print_message "Executing gds script " +"$ORACLE_HOME"/bin/gdsctl @${gdsScript} +else +print_message "Executing GSM query" +"$ORACLE_HOME"/bin/gdsctl << EOF >> $LOGFILE + $gsmQuery + exit +EOF +fi +} +######################################################################## Execute GSM Statements Ends here ################################ + +########################################################################## Execute SQL Function Begin here ############################## +executeSQL() +{ +sqlQuery=$1 +connectStr=$2 +type=$3 +sqlScript=$4 + +if [ -z "${sqlQuery}" ]; then + print_message "Empty sqlQuery passed to sqlplus. Operation Failed" +fi + +if [ -z "${connectStr}" ]; then + error_exit "Empty connectStr passed to sqlplus. Operation Failed" +fi + +if [ -z "${type}" ]; then + type='notSet' +fi + +if [ -z "${sqlScript}" ]; then + sqlScript='notSet' +fi + +if [ "${type}" == "sqlScript" ] && [ -f ${sqlScript} ]; then +print_message "Executing sql script using connect string" +"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE +@ ${sqlScript} +EOF +else +print_message "Executing sqlQuery using connect string" +"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE +$sqlQuery +EOF +fi +} + +############################################################################## Execute SQl Function ends here ################################# + +####################################### +################## MAIN ############### + +if [ "${OP_TYPE}" == "primaryshard" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + resetPassword + setupShardCDB +elif [ "${OP_TYPE}" == "standbyshard" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + setupShardStandby +elif [ "${OP_TYPE}" == "catalog" ]; then + print_message "Performing Checks before proceeding for setup" + dbChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + resetPassword + setupCatalog +elif [ "${OP_TYPE}" == "gsm" ]; then + print_message "Performing Checks before proceeding for setup" + gsmChecks + print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" + setupGSM +else + print_message "OP_TYPE must be set to (gsm|catalog|primaryshard|standbyshard)" + exit 15 +fi diff --git a/container-based-sharding-deployment/containerfiles/buildContainerImage.sh b/container-based-sharding-deployment/containerfiles/buildContainerImage.sh new file mode 100755 index 0000000..d529d82 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/buildContainerImage.sh @@ -0,0 +1,176 @@ +#!/bin/bash +# +# Since: November, 2018 +# Author: paramdeep.saini@oracle.com +# Description: Build script for building RAC container image +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2014,2024 Oracle and/or its affiliates. +# + +usage() { + cat << EOF + +Usage: buildContainerImage.sh -v [version] -t [image_name:tag] [-e | -s] [-i] [-o] [container build option] +It builds a container image for a DNS server + +Parameters: + -v: version to build + -i: ignores the MD5 checksums + -t: user defined image name and tag (e.g., image_name:ta + -o: passes on container build option (e.g., --build-arg SLIMMIMG=true for slim) + +LICENSE UPL 1.0 + +Copyright (c) 2014,2024 Oracle and/or its affiliates. + +EOF + exit 0 +} + +# Validate packages +checksumPackages() { + if hash md5sum 2>/dev/null; then + echo "Checking if required packages are present and valid..." + md5sum -c Checksum + # shellcheck disable=SC2181 + if [ "$?" -ne 0 ]; then + echo "MD5 for required packages to build this image did not match!" + echo "Make sure to download missing files in folder $VERSION." + # shellcheck disable=SC2320 + exit $? + fi + else + echo "Ignored MD5 sum, 'md5sum' command not available."; + fi +} + +############## +#### MAIN #### +############## + +if [ "$#" -eq 0 ]; then + usage; +fi + +# Parameters +VERSION="12.2.0.1" +SKIPMD5=0 +DOCKEROPS="" +IMAGE_NAME="" +SLIM="false" +DOCKEROPS=" --build-arg SLIMMING=false" +while getopts "hiv:o:t:" optname; do + case "$optname" in + "h") + usage + ;; + "i") + SKIPMD5=1 + ;; + "v") + VERSION="$OPTARG" + ;; + "o") + DOCKEROPS="$OPTARG" + if [[ "$DOCKEROPS" != *"--build-arg SLIMMING="* ]]; then + DOCKEROPS+=" --build-arg SLIMMING=false" + SLIM="false" + fi + if [[ "$OPTARG" == *"--build-arg SLIMMING=true"* ]]; then + SLIM="true" + fi + ;; + "t") + IMAGE_NAME="$OPTARG" + ;; + + "?") + usage; + ;; + *) + # Should not occur + echo "Unknown error while processing options inside buildContainerImage.sh" + ;; + esac +done + +# Oracle Database Image Name +if [ "${IMAGE_NAME}"x = "x" ] && [ "${SLIM}" == "true" ]; then + IMAGE_NAME="oracle/gsm:${VERSION}-slim" +elif [ "${IMAGE_NAME}"x = "x" ] && [ "${SLIM}" == "false" ]; then + IMAGE_NAME="oracle/gsm:${VERSION}" +else + echo "Image name is passed as an variable" +fi + + echo "Container Image set to : ${IMAGE_NAME}" + +# Go into version folder +cd "$VERSION" || exit + +if [ ! "$SKIPMD5" -eq 1 ]; then + checksumPackages +else + echo "Ignored MD5 checksum." +fi +echo "==========================" +echo "DOCKER info:" +docker info +echo "==========================" + +# Proxy settings +PROXY_SETTINGS="" +# shellcheck disable=SC2154 +if [ "${http_proxy}" != "" ]; then + PROXY_SETTINGS="$PROXY_SETTINGS --build-arg http_proxy=${http_proxy}" +fi +# shellcheck disable=SC2154 +if [ "${https_proxy}" != "" ]; then + PROXY_SETTINGS="$PROXY_SETTINGS --build-arg https_proxy=${https_proxy}" +fi +# shellcheck disable=SC2154 +if [ "${ftp_proxy}" != "" ]; then + PROXY_SETTINGS="$PROXY_SETTINGS --build-arg ftp_proxy=${ftp_proxy}" +fi +# shellcheck disable=SC2154 +if [ "${no_proxy}" != "" ]; then + PROXY_SETTINGS="$PROXY_SETTINGS --build-arg no_proxy=${no_proxy}" +fi +# shellcheck disable=SC2154 +if [ "$PROXY_SETTINGS" != "" ]; then + echo "Proxy settings were found and will be used during the build." +fi + +# ################## # +# BUILDING THE IMAGE # +# ################## # +echo "Building image '$IMAGE_NAME' ..." + +# BUILD THE IMAGE (replace all environment variables) +BUILD_START=$(date '+%s') +# shellcheck disable=SC2086 +docker build --force-rm=true --no-cache=true ${DOCKEROPS} ${PROXY_SETTINGS} -t ${IMAGE_NAME} -f Containerfile . || { + echo "There was an error building the image." + exit 1 +} +BUILD_END=$(date '+%s') +# shellcheck disable=SC2154,SC2003 +BUILD_ELAPSED=$((BUILD_END - BUILD_START)) + +echo "" +# shellcheck disable=SC2181,SC2320 +if [ $? -eq 0 ]; then +cat << EOF + Oracle GSM Container Image for version $VERSION is ready to be extended: + + --> $IMAGE_NAME + + Build completed in $BUILD_ELAPSED seconds. + +EOF + +else + echo "Oracle GSM Container Image was NOT successfully created. Check the output and correct any reported problems with the docker build operation." +fi diff --git a/container-based-sharding-deployment/containerfiles/setup_gdd_host.sh b/container-based-sharding-deployment/containerfiles/setup_gdd_host.sh new file mode 100755 index 0000000..b3b987d --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/setup_gdd_host.sh @@ -0,0 +1,502 @@ +#!/bin/bash +validate_environment_variables() { + local podman_compose_file="$1" + local env_variables=($(grep -oP '\${\K[^}]*' "$podman_compose_file" | sort -u)) + local missing_variables=() + + for var in "${env_variables[@]}"; do + if [[ -z "${!var}" ]]; then + missing_variables+=("$var") + fi + done + + if [ ${#missing_variables[@]} -eq 0 ]; then + echo "All required environment variables are present and exported." + return 0 + else + echo "The following required environment variables from podman-compose.yml(or may be wrong podman-compose.yml?) are missing or not exported:" + printf '%s\n' "${missing_variables[@]}" + return 1 + fi +} +setup_sharding_variables(){ + # Export the variables: + export PODMANVOLLOC='/scratch/oradata' + export NETWORK_INTERFACE='ens3' + export NETWORK_SUBNET="10.0.20.0/20" + export SIDB_IMAGE='oracle/database-ext-sharding:23.4.0-ee' + export GSM_IMAGE='oracle/gsm:23.4.0' + export LOCAL_NETWORK=10.0.20 + export healthcheck_interval=30s + export healthcheck_timeout=3s + export healthcheck_retries=40 + export CATALOG_OP_TYPE="catalog" + export ALLSHARD_OP_TYPE="primaryshard" + export GSM_OP_TYPE="gsm" + export PWD_SECRET_FILE=/opt/.secrets/pwdfile.enc + export KEY_SECRET_FILE=/opt/.secrets/key.pem + export CAT_SHARD_SETUP="true" + export CATALOG_ARCHIVELOG="true" + export SHARD_ARCHIVELOG="true" + export SHARD1_SHARD_SETUP="true" + export SHARD2_SHARD_SETUP="true" + export SHARD3_SHARD_SETUP="true" + export SHARD4_SHARD_SETUP="true" + export PRIMARY_GSM_SHARD_SETUP="true" + export STANDBY_GSM_SHARD_SETUP="true" + + export CONTAINER_RESTART_POLICY="always" + export CONTAINER_PRIVILEGED_FLAG="false" + export DOMAIN="example.com" + export DNS_SEARCH="example.com" + export CAT_CDB="CATCDB" + export CAT_PDB="CAT1PDB" + export CAT_HOSTNAME="oshard-catalog-0" + export CAT_CONTAINER_NAME="catalog" + + export SHARD1_CONTAINER_NAME="shard1" + export SHARD1_HOSTNAME="oshard1-0" + export SHARD1_CDB="ORCL1CDB" + export SHARD1_PDB="ORCL1PDB" + + export SHARD2_CONTAINER_NAME="shard2" + export SHARD2_HOSTNAME="oshard2-0" + export SHARD2_CDB="ORCL2CDB" + export SHARD2_PDB="ORCL2PDB" + + export SHARD3_CONTAINER_NAME="shard3" + export SHARD3_HOSTNAME="oshard3-0" + export SHARD3_CDB="ORCL3CDB" + export SHARD3_PDB="ORCL3PDB" + + export SHARD4_CONTAINER_NAME="shard4" + export SHARD4_HOSTNAME="oshard4-0" + export SHARD4_CDB="ORCL4CDB" + export SHARD4_PDB="ORCL4PDB" + + export PRIMARY_GSM_CONTAINER_NAME="gsm1" + export PRIMARY_GSM_HOSTNAME="oshard-gsm1" + export STANDBY_GSM_CONTAINER_NAME="gsm2" + export STANDBY_GSM_HOSTNAME="oshard-gsm2" + + + export PRIMARY_SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" + export PRIMARY_SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=primary;group_region=region1" + export PRIMARY_CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=30;repl_type=Native" + export PRIMARY_SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" + export PRIMARY_SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" + export PRIMARY_SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" + export PRIMARY_SERVICE2_PARAMS="service_name=oltp_rw_svc;service_role=primary" + + export STANDBY_SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region1;director_port=1522 " + export STANDBY_SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=active_standby;group_region=region1" + export STANDBY_CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=30;repl_type=Native" + export STANDBY_SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" + export STANDBY_SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" + export STANDBY_SHARD3_PARAMS="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" + export STANDBY_SHARD4_PARAMS="shard_host=oshard4-0;shard_db=ORCL4CDB;shard_pdb=ORCL4PDB;shard_port=1521;shard_group=shardgroup1" + export STANDBY_SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" + export STANDBY_SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" + + mkdir -p /opt/containers + rm -f /opt/containers/shard_host_file && touch /opt/containers/shard_host_file + sh -c "cat << EOF > /opt/containers/shard_host_file + 127.0.0.1 localhost.localdomain localhost + ${LOCAL_NETWORK}.100 oshard-gsm1.example.com oshard-gsm1 + ${LOCAL_NETWORK}.102 oshard-catalog-0.example.com oshard-catalog-0 + ${LOCAL_NETWORK}.103 oshard1-0.example.com oshard1-0 + ${LOCAL_NETWORK}.104 oshard2-0.example.com oshard2-0 + ${LOCAL_NETWORK}.105 oshard3-0.example.com oshard3-0 + ${LOCAL_NETWORK}.106 oshard4-0.example.com oshard4-0 + ${LOCAL_NETWORK}.101 oshard-gsm2.example.com oshard-gsm2 + +EOF +" + # Check if SELinux is enabled (enforcing or permissive) + if grep -q '^SELINUX=enforcing' /etc/selinux/config || grep -q '^SELINUX=permissive' /etc/selinux/config; then + if ! grep -q "/opt/containers/shard_host_file" /etc/selinux/targeted/contexts/files/file_contexts.local; then semanage fcontext -a -t container_file_t /opt/containers/shard_host_file; fi + restorecon -v /opt/containers/shard_host_file + echo "SELinux is enabled. Updated file contexts." + fi + rm -rf ${PODMANVOLLOC} + mkdir -p ${PODMANVOLLOC}/scripts + chown -R 54321:54321 ${PODMANVOLLOC}/scripts + chmod 755 ${PODMANVOLLOC}/scripts + + mkdir -p ${PODMANVOLLOC}/dbfiles/CATALOG + chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/CATALOG + + mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL1CDB + chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL1CDB + mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL2CDB + chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL2CDB + mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL3CDB + chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL3CDB + mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL4CDB + chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL4CDB + + mkdir -p ${PODMANVOLLOC}/dbfiles/GSMDATA + chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/GSMDATA + + mkdir -p ${PODMANVOLLOC}/dbfiles/GSM2DATA + chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/GSM2DATA + + + chmod 755 ${PODMANVOLLOC}/dbfiles/CATALOG + chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL1CDB + chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL2CDB + chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL3CDB + chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL4CDB + chmod 755 ${PODMANVOLLOC}/dbfiles/GSMDATA + chmod 755 ${PODMANVOLLOC}/dbfiles/GSM2DATA + create_secrets || return 1 + # List of files + files=( + "${PODMANVOLLOC}/dbfiles/CATALOG" + "/opt/containers/shard_host_file" + "${PODMANVOLLOC}/dbfiles/ORCL1CDB" + "${PODMANVOLLOC}/dbfiles/ORCL2CDB" + "${PODMANVOLLOC}/dbfiles/GSMDATA" + "${PODMANVOLLOC}/dbfiles/GSM2DATA" + "${PODMANVOLLOC}/dbfiles/ORCL3CDB" + "${PODMANVOLLOC}/dbfiles/ORCL4CDB" + ) + + if grep -q '^SELINUX=enforcing' /etc/selinux/config || grep -q '^SELINUX=permissive' /etc/selinux/config; then + for file in "${files[@]}"; do + # Check if file context exists + if ! matchpathcon -V "$file" | grep -q 'container_file_t'; then + # If not, add file context + semanage fcontext -a -t container_file_t "$file" + fi + restorecon -v "$file" + done + echo "Updated file contexts." + else + echo "SELinux is not enabled." + fi + echo "Sharding Environment Variables are setup successfully." + return 0 +} +setup_catalog_container(){ + podman-compose up -d catalog_db + return 0 +} + +setup_shard1_container(){ + podman-compose up -d shard1_db + return 0 +} +setup_shard2_container(){ + podman-compose up -d shard2_db + return 0 +} + +setup_shard3_container(){ + podman-compose up -d shard3_db + return 0 +} +setup_shard4_container(){ + podman-compose up -d shard4_db + return 0 +} +setup_gsm_primary_container(){ + podman-compose up -d primary_gsm + return 0 +} +setup_gsm_standby_container(){ + podman-compose up -d standby_gsm + return 0 +} + + +function DisplayUsage(){ + echo "Usage : + $0 [-ignoreOSVersion] [-cleanup|-export-sharding-env|-prepare-sharding-env|-sharding-deploy] [-help]" + return 0 +} + +# Function to check if a command is available +check_command() { + if ! command -v "$1" &>/dev/null; then + return 1 + fi +} + +# Function to install Podman +install_podman() { + if ! check_command podman; then + echo "INFO: Podman is not installed. Installing..." + sudo dnf install -y podman + else + echo "INFO: Podman is already installed." + fi + return 0 +} + +# Function to install Podman-Compose +install_podman_compose() { + if ! check_command podman-compose; then + echo "INFO: Podman-Compose is not installed. Installing..." + # Enable EPEL repository for Oracle Linux 9 + sudo dnf config-manager --enable ol8_developer_EPEL + # Install Podman-Compose + sudo dnf install -y podman-compose + else + echo "INFO: Podman-Compose is already installed." + fi + return 0 +} + +function setupSELinuxContext(){ + + dnf install selinux-policy-devel -y + [ -f /var/opt/sharding-podman.te ] && cp /var/opt/sharding-podman.te /var/opt/sharding-podman.te.ORG + [ -f /var/opt/sharding-podman.te ] && rm -rf /var/opt/sharding-podman.te + cat > /var/opt/sharding-podman.te <<EOF +module sharding-podman 1.0; + +require { + type kernel_t; + class system syslog_read; + type container_runtime_t; + type container_init_t; + class file getattr; + type container_file_t; + type lib_t; + type textrel_shlib_t; + type unlabeled_t; + class file read; + type bin_t; + class file { execmod execute map setattr }; +} + +#============= container_init_t ============== +allow container_init_t container_runtime_t:file getattr; +allow container_init_t bin_t:file map; +allow container_init_t bin_t:file execute; +allow container_init_t container_file_t:file execmod; +allow container_init_t lib_t:file execmod; +allow container_init_t textrel_shlib_t:file setattr; +allow container_init_t kernel_t:system syslog_read; +allow container_init_t unlabeled_t:file read; +EOF + + cd /var/opt + yes | make -f /usr/share/selinux/devel/Makefile sharding-podman.pp + semodule -l | grep -q "sharding-podman" && semodule -r sharding-podman + semodule -i sharding-podman.pp + semodule -l | grep rac-pod + sleep 3 + cd - +} + +# Function to delete and create secrets +delete_and_create_secret() { + local secret_name=$1 + local file_path=$2 + + # Check if the secret exists + if podman secret inspect $secret_name &> /dev/null; then + echo "INFO: Deleting existing secret $secret_name..." + podman secret rm $secret_name + fi + + # Create the new secret + echo "INFO: Creating new secret $secret_name..." + podman secret create $secret_name $file_path +} + +create_secrets() { + # Check if SHARDING_SECRET environment variable is defined + if [ -z "$SHARDING_SECRET" ]; then + echo "ERROR: SHARDING_SECRET environment variable is not defined." + return 1 + fi + mkdir -p /opt/.secrets/ + echo $SHARDING_SECRET > /opt/.secrets/pwdfile.txt + cd /opt/.secrets + openssl genrsa -out key.pem + openssl rsa -in key.pem -out key.pub -pubout + openssl pkeyutl -in pwdfile.txt -out pwdfile.enc -pubin -inkey key.pub -encrypt + rm -rf /opt/.secrets/pwdfile.txt + # Delete and create secrets + delete_and_create_secret "pwdsecret" "/opt/.secrets/pwdfile.enc" + delete_and_create_secret "keysecret" "/opt/.secrets/key.pem" + echo "INFO: Secrets created." + chown 54321:54321 /opt/.secrets/pwdfile.enc + chown 54321:54321 /opt/.secrets/key.pem + chown 54321:54321 /opt/.secrets/key.pub + chmod 400 /opt/.secrets/pwdfile.enc + chmod 400 /opt/.secrets/key.pem + chmod 400 /opt/.secrets/key.pub + # List of files + files=( + "/opt/.secrets/pwdfile.enc" + "/opt/.secrets/key.pem" + /opt/.secrets/key.pub + ) + if grep -q '^SELINUX=enforcing' /etc/selinux/config || grep -q '^SELINUX=permissive' /etc/selinux/config; then + for file in "${files[@]}"; do + # Check if file context exists + if ! grep -q "$(basename "$file")" /etc/selinux/targeted/contexts/files/file_contexts.local; then + # If not, add file context + semanage fcontext -a -t container_file_t "$file" + restorecon -v "$file" + fi + done + echo "SELinux is enabled. Updated file contexts." + + fi + + cd - + return 0 +} + +check_system_resources() { + # # Check swap space in GB + # swap_space=$(free -g | grep Swap | awk '{print $2}') + # if [ "$swap_space" -ge 32 ]; then + # echo "INFO: Swap space is sufficient ($swap_space GB)." + # else + # echo "ERROR: Swap space is insufficient ($swap_space GB). Minimum 32 GB required." + # return 1 + # fi + + # Check physical memory (RAM) in GB + total_memory=$(free -g | grep Mem | awk '{print $2}') + if [ "$total_memory" -ge 32 ]; then + echo "INFO: Physical memory is sufficient ($total_memory GB)." + else + echo "ERROR: Physical memory is insufficient ($total_memory GB). Minimum 32 GB required." + return 1 + fi + + # Both swap space and physical memory meet the requirements + return 0 +} + +setup_host_prepreq(){ + kernelVersionSupported=1 + # shellcheck disable=SC2317 + # shellcheck disable=SC2006 + OSVersion=`grep "Oracle Linux Server release 8" /etc/oracle-release` + OSstatus=$? + if [ ${OSstatus} -eq 0 ]; then + OSVersionSupported=1 + else + OSVersionSupported=0 + fi + + echo "INFO: Setting Podman env on OS [${OSVersion}]" + # shellcheck disable=SC2006 + kernelVersion=`uname -r | cut -d. -f1,2` + # shellcheck disable=SC2006 + majorKernelVersion=`echo ${kernelVersion} | cut -d. -f1` + # shellcheck disable=SC2006 + minorKernelVersion=`echo ${kernelVersion} | cut -d. -f2` + + echo "Running on Kernel [${kernelVersion}]" + + if [ ${majorKernelVersion} -lt 5 ]; then + kernelVersionSupported=0 + fi + + if [ $majorKernelVersion -eq 5 ]; then + if [ ${minorKernelVersion} -lt 14 ]; then + kernelVersionSupported=0 + fi + fi + + if [ $OSVersionSupported -eq 0 -o $kernelVersionSupported -eq 0 ]; then + if [ ${IGNOREOSVERSION} == "0" ]; then + echo "ERROR: OSVersion=${OSVersion}.. KernelVersion=${kernelVersion}. Exiting." + return 1 + fi + fi + install_podman + install_podman_compose + # shellcheck disable=SC2006 + SEMode=`getenforce` + if [ "${SEMode}" == "Enforcing" ]; then + echo "INFO: SELinux Enabled. Setting up SELinux Context" + setupSELinuxContext + else + echo "INFO: SELinux Disabled." + + fi + check_system_resources || return 1 + echo "INFO: Finished setting up the pre-requisites for Podman-Host" + return 0 +} +cleanup_env(){ + podman rm -f ${CAT_CONTAINER_NAME} + podman rm -f ${SHARD1_CONTAINER_NAME} + podman rm -f $SHARD2_CONTAINER_NAME + podman rm -f $SHARD3_CONTAINER_NAME + podman rm -f ${SHARD4_CONTAINER_NAME} + podman rm -f ${PRIMARY_GSM_CONTAINER_NAME} + podman rm -f ${STANDBY_GSM_CONTAINER_NAME} + podman network inspect shard_pub1_nw &> /dev/null && podman network rm shard_pub1_nw + rm -rf ${PODMANVOLLOC}/* + echo "INFO: Oracle Globally Distributed Database Container Environment Cleanup Successfully" + return 0 +} + +while [ $# -gt 0 ]; do + case "$1" in + -ignoreOSVersion) + IGNOREOSVERSION=1 + ;; + -help|-h) + DisplayUsage + ;; + -export-sharding-env) + setup_sharding_variables || echo "ERROR: Oracle Sharding Environment Variables setup has failed." + ;; + -deploy-catalog) + validate_environment_variables podman-compose.yml || exit 1 + setup_catalog_container || echo "ERROR: Oracle Catalog Container Setup has failed." + ;; + -deploy-shard1) + validate_environment_variables podman-compose.yml || exit 1 + setup_shard1_container || echo "ERROR: Oracle Shard1 Container Setup has failed." + ;; + -deploy-shard2) + validate_environment_variables podman-compose.yml || exit 1 + setup_shard2_container || echo "ERROR: Oracle Shard2 Container Setup has failed." + ;; + -deploy-shard3) + validate_environment_variables podman-compose.yml || exit 1 + setup_shard3_container || echo "ERROR: Oracle Shard4 Container Setup has failed." + ;; + -deploy-shard4) + validate_environment_variables podman-compose.yml || exit 1 + setup_shard4_container || echo "ERROR: Oracle Shard4 Container Setup has failed." + ;; + -deploy-gsm-primary) + validate_environment_variables podman-compose.yml || exit 1 + setup_gsm_primary_container || echo "ERROR: Oracle Primary GSM Container Setup has failed." + ;; + -deploy-gsm-standby) + validate_environment_variables podman-compose.yml || exit 1 + setup_gsm_standby_container || echo "ERROR: Oracle Standby GSM Container Setup has failed." + ;; + -cleanup) + validate_environment_variables podman-compose.yml || exit 1 + cleanup_env || echo "ERROR: Oracle RAC Environment Cleanup Setup has failed." + ;; + -prepare-sharding-env) + setup_host_prepreq || echo "ERROR: Oracle RAC preparation setups have failed." + ;; + *) + printf "***************************\n" + # shellcheck disable=SC2059 + printf "* Error: Invalid argument [$1] specified.*\n" + printf "***************************\n" + DisplayUsage + ;; + esac + shift +done + diff --git a/container-based-sharding-deployment/containerfiles/shard-podman.te b/container-based-sharding-deployment/containerfiles/shard-podman.te new file mode 100644 index 0000000..f57c737 --- /dev/null +++ b/container-based-sharding-deployment/containerfiles/shard-podman.te @@ -0,0 +1,27 @@ +module shard-podman 1.0; + +require { + type kernel_t; + class system syslog_read; + type container_runtime_t; + type container_init_t; + class file getattr; + type container_file_t; + type lib_t; + type textrel_shlib_t; + type unlabeled_t; + class file read; + type bin_t; + class file { execmod execute map setattr }; + +} + +#============= container_init_t ============== +allow container_init_t container_runtime_t:file getattr; +allow container_init_t bin_t:file map; +allow container_init_t bin_t:file execute; +allow container_init_t container_file_t:file execmod; +allow container_init_t lib_t:file execmod; +allow container_init_t textrel_shlib_t:file setattr; +allow container_init_t kernel_t:system syslog_read; +allow container_init_t unlabeled_t:file read; \ No newline at end of file diff --git a/container-based-sharding-deployment/docs/ENVVARIABLESCOMPOSE.md b/container-based-sharding-deployment/docs/ENVVARIABLESCOMPOSE.md new file mode 100644 index 0000000..ebe12a2 --- /dev/null +++ b/container-based-sharding-deployment/docs/ENVVARIABLESCOMPOSE.md @@ -0,0 +1,50 @@ +## ENVIRONMENT VARIABLE DETAILS FOR ORACLE GLOBALLY DISTRIBUTED DATABASE USING PODMAN COMPOSE + +| Environment Variable | Description | Default Value | +|--------------------------------|------------------------------------------------------------------------------------------------------|--------------------| +| PODMANVOLLOC | Location of podman volume for storing Database Files | /scratch/oradata | +| NETWORK_INTERFACE | Network interface name on host machines | ens3 | +| NETWORK_SUBNET | Network subnet | 10.0.20.0/20 | +| SIDB_IMAGE | Podman Image with sharding extension for SIDB container | oracle/database-ext-sharding:23.5.0-ee | +| GSM_IMAGE | Podman Image for GSM container | oracle/database-gsm:23.5.0 | +| LOCAL_NETWORK | Local network address | 10.0.20 | +| healthcheck_interval | Interval for health check | 30s | +| healthcheck_timeout | Timeout for health check | 3s | +| healthcheck_retries | Number of retries for health check | 40 | +| CATALOG_OP_TYPE | Operation type for catalog | catalog | +| ALLSHARD_OP_TYPE | Operation type for all shards | primaryshard | +| GSM_OP_TYPE | Operation type for GSM | gsm | +| PWD_SECRET_FILE | Path to the encrypted password file | /opt/.secrets/pwdfile.enc | +| KEY_SECRET_FILE | Path to the secret key file to decrypt the encrypted password file | /opt/.secrets/key.pem | +| CAT_SHARD_SETUP | Set to "true" to enable catalog shard setup | true | +| CATALOG_ARCHIVELOG | Set to "true" to enable catalog archivelog mode | true | +| SHARD_ARCHIVELOG | Set to "true" to enable shard archivelog mode | true | +| SHARD[1-4]_SHARD_SETUP | Set to "true" to enable shard setup for each shard | true | +| PRIMARY_GSM_SHARD_SETUP | Set to "true" to enable primary GSM shard setup | true | +| STANDBY_GSM_SHARD_SETUP | Set to "true" to enable standby GSM shard setup | true | +| CONTAINER_RESTART_POLICY | Container restart policy | always | +| CONTAINER_PRIVILEGED_FLAG | Set to "true" for container privileged mode, "false" otherwise | false | +| DOMAIN | Domain name | example.com | +| DNS_SEARCH | DNS search domain | example.com | +| CAT_CDB | Catalog CDB name | CATCDB | +| CAT_PDB | Catalog PDB name | CAT1PDB | +| CAT_HOSTNAME | Catalog hostname | oshard-catalog-0 | +| CAT_CONTAINER_NAME | Catalog container name | catalog | +| SHARD[1-4]_CONTAINER_NAME | Shard container name | shard1, shard2, shard3, shard4 | +| SHARD[1-4]_HOSTNAME | Shard hostname | oshard1-0, oshard2-0, oshard3-0, oshard4-0 | +| SHARD[1-4]_CDB | Shard CDB name | ORCL1CDB, ORCL2CDB, ORCL3CDB, ORCL4CDB | +| SHARD[1-4]_PDB | Shard PDB name | ORCL1PDB, ORCL2PDB, ORCL3PDB, ORCL4PDB | +| PRIMARY_GSM_CONTAINER_NAME | Primary GSM container name | gsm1 | +| PRIMARY_GSM_HOSTNAME | Primary GSM hostname | oshard-gsm1 | +| STANDBY_GSM_CONTAINER_NAME | Standby GSM container name | gsm2 | +| STANDBY_GSM_HOSTNAME | Standby GSM hostname | oshard-gsm2 | +| PRIMARY_SHARD_DIRECTOR_PARAMS | Parameters for primary shard director | director_name=sharddirector1;director_region=region1;director_port=1522 | +| PRIMARY_SHARD[1-2]_GROUP_PARAMS| Parameters for primary shard groups | group_name=shardgroup1;deploy_as=primary/active_standby;group_region=region1 | +| PRIMARY_CATALOG_PARAMS | Parameters for primary catalog | catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=30;repl_type=Native | +| PRIMARY_SHARD[1-2]_PARAMS | Parameters for primary shards | shard_host=oshard1-0/oshard2-0;shard_db=ORCL1CDB/ORCL2CDB;shard_pdb=ORCL1PDB/ORCL2PDB;shard_port=1521;shard_group=shardgroup1 | +| PRIMARY_SERVICE[1-2]_PARAMS | Parameters for primary services | service_name=oltp_rw_svc;service_role=primary | +| STANDBY_SHARD_DIRECTOR_PARAMS | Parameters for standby shard director | director_name=sharddirector2;director_region=region1;director_port=1522 | +| STANDBY_SHARD[1-4]_GROUP_PARAMS| Parameters for standby shard groups | group_name=shardgroup1;deploy_as=active_standby;group_region=region1 | +| STANDBY_CATALOG_PARAMS | Parameters for standby catalog | catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=30;repl_type=Native | +| STANDBY_SHARD[1-4]_PARAMS | Parameters for standby shards | shard_host=oshard1-0/oshard2-0/oshard3-0/oshard4-0;shard_db=ORCL1CDB/ORCL2CDB/ORCL3CDB/ORCL4CDB;shard_pdb=ORCL1PDB/ORCL2PDB/ORCL3PDB/ORCL4PDB;shard_port=1521;shard_group=shardgroup1 | +| STANDBY_SERVICE[1-2]_PARAMS | Parameters for standby services | service_name=oltp_rw_svc/oltp_ro_svc;service_role=standby | \ No newline at end of file diff --git a/container-based-sharding-deployment/docs/QUICKSTART.md b/container-based-sharding-deployment/docs/QUICKSTART.md new file mode 100644 index 0000000..c289f5b --- /dev/null +++ b/container-based-sharding-deployment/docs/QUICKSTART.md @@ -0,0 +1,226 @@ +# Oracle Globally Distributed Database Container QuickStart Guide + +Use this quickstart to help you deploy Oracle Globally Distributed Database with the RAFT Replication feature enabled using Podman Containers on a single Oracle Linux Host machine using Podman Compose. + +This deployment uses Oracle Globally Distributed Database Container Image and bridge network driver for Podman. + +- [Oracle Globally Distributed Database Container QuickStart Guide](#oracle-globally-distributed-database-container-quickstart-guide) + - [Before you begin](#before-you-begin) + - [Getting Oracle Globally Distributed Database Container Images](#getting-oracle-globally-distributed-database-container-images) + - [Networking in Oracle Globally Distributed Database Podman Container Environment](#networking-in-oracle-globally-distributed-database-podman-container-environment) + - [Deploy Oracle Globally Distributed Database Environment](#deploy-oracle-globally-distributed-database-on-podman-container-environment) + - [Validating Oracle Globally Distributed Database Environment](#validating-oracle-globally-distributed-database-container-environment) + - [Cleanup the environment](#cleanup-the-environment) + - [Environment Variables Explained](#environment-variables-explained) + - [Support](#support) + - [License](#license) + - [Copyright](#copyright) + +## Before you begin +- Before proceeding further, prepare the Podman host by completing prerequisites related to the Oracle Globally Distributed Database Containers on Podman host environment as explained in [Preparation Steps for running Oracle Globally Distributed Database Database in containers](../README.md#preparation-steps-for-running-oracle-globally-distributed-database-in-linux-containers). Oracle provides a precreated script, `setup_gdd_host.sh`, which will prepare the Podman host with the following prerequisites- + - Validate Host machine for supported Os version(OL >8), Kernel(>UEKR6), Memory(>32GB), etc. + - Install Podman + - Install Podman Compose + - Setup and Load SELinux modules + - Create Oracle Globally Distributed Database Podman secrets +- Set `secret-password` of your choice below, which is going to be used as a password for the Oracle Globally Distributed Database Container environment. + + Run the following command- + ```bash + export SHARDING_SECRET=<secret-password> + ``` +- To prepare the Podman host machine using a precreated script, copy the file `setup_gdd_host.sh` from [<GITHUB_REPO_CLONED_PATH>/db-sharding/container-based-sharding-deployment/containerfiles/setup_gdd_host.sh](../containerfiles/setup_gdd_host.sh) and run the following command - + + ```bash + ./setup_gdd_host.sh -prepare-sharding-env + ``` + Logs- + ```bash + INFO: Finished setting up the pre-requisites for Podman-Host + ``` +- In this quickstart, our working directory is `<GITHUB_REPO_CLONED_PATH>/db-sharding/container-based-sharding-deployment/containerfiles` from where all commands are run. + +## Getting Oracle Globally Distributed Database Container Images +- Refer to the [Getting Oracle Globally Distributed Database Container Images](../README.md#building-oracle-globally-distributed-database-container-images) section to get Oracle Globally Distributed Database Container Images used in quickstart setup. +- When Podman images are ready, such as is shown in this example used in this quickstart, you can proceed to the next steps- + ```bash + # podman images + REPOSITORY TAG IMAGE ID CREATED SIZE + localhost/oracle/database-ext-sharding 23.5.0-ee 1c17b71b710e 21 hours ago 7.06 GB + localhost/oracle/database 23.5.0-ee ee6a794351a0 22 hours ago 6.74 GB + localhost/oracle/gsm 23.5.0 8721eee1dbba 23 hours ago 2.14 GB + localhost/oracle/database 23.5.0-ee-base b40d790f3224 8 days ago 339 MB + ``` +## Networking in Oracle Globally Distributed Database Podman Container Environment +- In this Quick Start, we will create the following subnets for Oracle Globally Distributed Database Podman Container Environment- + + | Network Name | Subnet CIDR | Description | + |----------------|--------------|--------------------------------------| + | shard_pub1_nw | 10.0.20.0/20 | Public network for Oracle lobally Distributed Database Podman Container Environment| + +## Deploy Oracle Globally Distributed Database on Podman Container Environment +- Copy the `podman-compose.yml` file from this [<GITHUB_REPO_CLONED_PATH>/db-sharding/container-based-sharding-deployment/samples/compose-files/podman-compose.yml](../samples/compose-files/podman-compose.yml) in your working directory. +- Run the following command from your working directory to export the required environment variables required by the compose file in this quickstart- + ```bash + source ./setup_gdd_host.sh -export-sharding-env + ``` + Logs - + ```bash + INFO: Sharding Environment Variables are setup successfully. + ``` + Note: + * This Quickstart guide uses the variable `export PODMANVOLLOC='/scratch/oradata'` for storing all data files related to Oracle Globally Distributed Database containers. You can change this as needed in your environment where required free space is available. + +- Run the following command to deploy the Catalog Container- + ```bash + ./setup_gdd_host.sh -deploy-catalog + ``` + Monitor Logs - + ```bash + # podman-compose logs -f catalog_db + ``` + + Wait for the following message: + ``` + ============================================== + GSM Catalog Setup Completed + ============================================== + ``` +- Execute below to deploy the Shard1 Container- + ```bash + ./setup_gdd_host.sh -deploy-shard1 + ``` + Monitor Logs - + ```bash + podman-compose logs -f shard1_db + ``` + + Wait for the following message: + ``` + ============================================== + GSM Shard Setup Completed + ============================================== + ``` +- Run the following command to deploy the Shard2 Container- + ```bash + ./setup_gdd_host.sh -deploy-shard2 + ``` + Monitor Logs - + ```bash + podman-compose logs -f shard2_db + ``` + + Wait for the following message: + ``` + ============================================== + GSM Shard Setup Completed + ============================================== + ``` +- Run the following command to deploy the Shard3 Container- + ```bash + ./setup_gdd_host.sh -deploy-shard3 + ``` + Monitor Logs - + ```bash + podman-compose logs -f shard3_db + ``` + + Wait for the following message: + ``` + ============================================== + GSM Shard Setup Completed + ============================================== + ``` +- Run the following command to deploy the Shard4 Container- + ```bash + ./setup_gdd_host.sh -deploy-shard4 + ``` + Monitor Logs - + ```bash + podman-compose logs -f shard4_db + ``` + + Wait for the following message: + ``` + ============================================== + GSM Shard Setup Completed + ============================================== + ``` +- Run the following commanda to deploy the Primary GSM Container- + ```bash + ./setup_gdd_host.sh -deploy-gsm-primary + ``` + Monitor Logs - + ```bash + podman-compose logs -f primary_gsm + ``` + + Wait for the following message: + ``` + ============================================== + GSM Setup Completed + ============================================== + ``` +- Run the following command to deploy Standby GSM Container- + ```bash + ./setup_gdd_host.sh -deploy-gsm-standby + ``` + Monitor Logs - + ```bash + podman-compose logs -f standby_gsm + ``` + + Wait for the following message: + ``` + ============================================== + GSM Setup Completed + ============================================== + ``` + +## Validating Oracle Globally Distributed Database Container Environment +You can validate if the environment is set up properly by running the following command and checking the logs of each container- +```bash +# podman ps -a +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +181a4215b517 localhost/oracle/database-ext-sharding:23.5.0-ee /bin/sh -c exec $... 22 minutes ago Up 22 minutes catalog +2b5ade918112 localhost/oracle/database-ext-sharding:23.5.0-ee /bin/sh -c exec $... 18 minutes ago Up 18 minutes shard1 +f4943c6d67ce localhost/oracle/database-ext-sharding:23.5.0-ee /bin/sh -c exec $... 15 minutes ago Up 15 minutes shard2 +fa9611ad2bbe localhost/oracle/database-ext-sharding:23.5.0-ee /bin/sh -c exec $... 11 minutes ago Up 11 minutes shard3 +e19138866b51 localhost/oracle/database-ext-sharding:23.5.0-ee /bin/sh -c exec $... 7 minutes ago Up 7 minutes shard4 +e88e57c4e442 localhost/oracle/database-gsm:23.5.0 /bin/sh -c exec $... 3 minutes ago Up 3 minutes gsm1 +4e751cdfe01e localhost/oracle/database-gsm:23.5.0 /bin/sh -c exec $... 24 seconds ago Up 24 seconds gsm2 +``` + +## Clean up the environment + +If you want to clean up the Oracle Globally Distributed Database Container environment, then run the following command- +```bash +./setup_gdd_host.sh -cleanup +``` + +This command will clean up the Oracle Globally Distributed Database Containers, Oracle Storage Volume, Oracle Globally Distributed Database Podman Networks, and so on. + +Logs- +```bash +INFO: Oracle Globally Distributed Database Container Environment Cleanup Successfully +``` + +## Environment Variables Explained + +Refer to [Environment Variables Details for Oracle Globally Distributed Database using Podman Compose](./ENVVARIABLESCOMPOSE.md) for the explanation of all the environment variables related to Oracle Globally Distributed Database using Podman Compose. Change or Set these environment variables as required for your environment. + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + +## License + +To run Oracle Globally Distributed Database, regardless of whether it is inside or outside a Container, ensure that you download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/compose-files/docker-compose/README.md b/container-based-sharding-deployment/samples/compose-files/docker-compose/README.md new file mode 100644 index 0000000..dfd4821 --- /dev/null +++ b/container-based-sharding-deployment/samples/compose-files/docker-compose/README.md @@ -0,0 +1,106 @@ +# Deploying Oracle Globally Distributed Database Containers using docker-compose + +This document provides an example of how to use `docker-compose` to create the Docker network and to create the containers for an Oracle Globally Distributed Database Deployment on a single Oracle Linux 7 host using Docker Containers. + +**IMPORTANT:** This example uses 21c RDBMS and 21c GSM Docker Images. + +- [Step 1: Install Docker Compose](#install-docker-compose) +- [Step 2: Complete the prerequisite steps](#complete-the-prerequisite-steps) +- [Step 3: Create Docker Compose file](#create-docker-compose-file) +- [Step 4: Create services using "docker compose" command](#create-services-using-docker-compose-command) +- [Step 5: Check the logs](#check-the-logs) +- [Step 6: Remove the deployment](#remove-the-deployment) +- [Copyright](#copyright) + + +## Install Docker Compose +```bash +DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} +mkdir -p $DOCKER_CONFIG/cli-plugins +ls -lrt $DOCKER_CONFIG/cli-plugins +curl -SL https://github.com/docker/compose/releases/download/v2.23.1/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose +ls -lrt $DOCKER_CONFIG/cli-plugins +chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose +``` + +## Complete the prerequisite steps + +Use the file [docker-compose-prerequisites.sh](./docker-compose-prerequisites.sh) to export the environment variables, create the network host file, and create required directories. + +**NOTE:** Change the values for `SIDB_IMAGE` and `GSM_IMAGE` to use the images that you want to use for the deployment. + +```bash +source docker-compose-env-variables +``` + +Use the following commands to create an encrypted password file: + +```bash +rm -rf /opt/.secrets/ +mkdir /opt/.secrets/ +openssl genrsa -out /opt/.secrets/key.pem +openssl rsa -in /opt/.secrets/key.pem -out /opt/.secrets/key.pub -pubout + +# Edit the file /opt/.secrets/pwdfile.txt to add the password string +vi /opt/.secrets/pwdfile.txt + +# Encrypt the file having the password +openssl pkeyutl -in /opt/.secrets/pwdfile.txt -out /opt/.secrets/pwdfile.enc -pubin -inkey /opt/.secrets/key.pub -encrypt + +rm -f /opt/.secrets/pwdfile.txt +chown 54321:54321 /opt/.secrets/pwdfile.enc +chown 54321:54321 /opt/.secrets/key.pem +chown 54321:54321 /opt/.secrets/key.pub +chmod 400 /opt/.secrets/pwdfile.enc +chmod 400 /opt/.secrets/key.pem +chmod 400 /opt/.secrets/key.pub +``` + +## Create Docker Compose file + +Copy a Docker Compose file named [docker-compose.yaml](./docker-compose.yml) in your working directory. + + +## Create services using "docker compose" command +After you have successfully completed the prerequisties for deployment, run these commands to create the services: +```bash +# Switch to location with the `docker-compose.yaml` file and run: + +docker compose up -d +``` + +## Check the logs + +```bash +# You can monitor the logs for all the containers using below command: + +docker compose logs -f +``` + +Wait for all the Docker setup processes to complete, and each component indicates that it is up and ready. For example: +``` +# docker compose up -d +[+] Running 6/6 + ✔ Container pcatalog Healthy 0.0s + ✔ Container shard1 Healthy 0.0s + ✔ Container shard2 Healthy 0.0s + ✔ Container shard3 Healthy 0.0s + ✔ Container gsm1 Healthy 0.0s + ✔ Container gsm2 Started +``` + +## Remove the deployment + +If you want to remove the deployment, use the `docker-compose` command. To remove the deployment: + +- First export all the variables from the Prerequisites Sesion. +- Use the following command to remove the deployment: + +```bash +docker-compose down +``` + +## Copyright + +Copyright (c) 2022, 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/compose-files/docker-compose/docker-compose-prerequisites.sh b/container-based-sharding-deployment/samples/compose-files/docker-compose/docker-compose-prerequisites.sh new file mode 100644 index 0000000..41c154e --- /dev/null +++ b/container-based-sharding-deployment/samples/compose-files/docker-compose/docker-compose-prerequisites.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +# Export the variables: +export DOCKERVOLLOC='/scratch/oradata' +export NETWORK_INTERFACE='ens3' +export NETWORK_SUBNET="10.0.20.0/20" +export SIDB_IMAGE='oracle/database-ext-sharding:21.3.0-ee' +export GSM_IMAGE='oracle/gsm:21.3.0' +export LOCAL_NETWORK=10.0.20 +export CATALOG_INIT_SGA_SIZE=2048M +export CATALOG_INIT_PGA_SIZE=800M +export ALLSHARD_INIT_SGA_SIZE=2048M +export ALLSHARD_INIT_PGA_SIZE=800M +export healthcheck_interval=30s +export healthcheck_timeout=3s +export healthcheck_retries=40 +export CATALOG_OP_TYPE="catalog" +export ALLSHARD_OP_TYPE="primaryshard" +export GSM_OP_TYPE="gsm" +export COMMON_OS_PWD_FILE="pwdfile.enc" +export PWD_KEY="key.pem" +export CAT_SHARD_SETUP="true" +export CATALOG_ARCHIVELOG="true" +export SHARD_ARCHIVELOG="true" +export SHARD1_SHARD_SETUP="true" +export SHARD2_SHARD_SETUP="true" +export SHARD3_SHARD_SETUP="true" +export SHARD4_SHARD_SETUP="true" +export PRIMARY_GSM_SHARD_SETUP="true" +export STANDBY_GSM_SHARD_SETUP="true" + +export CONTAINER_RESTART_POLICY="always" +export CONTAINER_PRIVILEGED_FLAG="false" +export DOMAIN="example.com" +export DNS_SEARCH="example.com" +export CAT_CDB="CATCDB" +export CAT_PDB="CAT1PDB" +export CAT_HOSTNAME="oshard-catalog-0" +export CAT_CONTAINER_NAME="catalog" + +export SHARD1_CONTAINER_NAME="shard1" +export SHARD1_HOSTNAME="oshard1-0" +export SHARD1_CDB="ORCL1CDB" +export SHARD1_PDB="ORCL1PDB" + +export SHARD2_CONTAINER_NAME="shard2" +export SHARD2_HOSTNAME="oshard2-0" +export SHARD2_CDB="ORCL2CDB" +export SHARD2_PDB="ORCL2PDB" + +export PRIMARY_GSM_CONTAINER_NAME="gsm1" +export PRIMARY_GSM_HOSTNAME="oshard-gsm1" +export STANDBY_GSM_CONTAINER_NAME="gsm2" +export STANDBY_GSM_HOSTNAME="oshard-gsm2" + +export PRIMARY_SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" +export PRIMARY_SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=primary;group_region=region1" +export PRIMARY_CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2" +export PRIMARY_SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" +export PRIMARY_SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" +export PRIMARY_SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" +export PRIMARY_SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=primary" + +export STANDBY_SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region2;director_port=1522" +export STANDBY_SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=standby;group_region=region2" +export STANDBY_CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2" +export STANDBY_SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" +export STANDBY_SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" +export STANDBY_SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" +export STANDBY_SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" + +# Create file with Host IPs for containers +mkdir -p /opt/containers +touch /opt/containers/shard_host_file +sh -c "cat << EOF > /opt/containers/shard_host_file +127.0.0.1 localhost.localdomain localhost +${LOCAL_NETWORK}.100 oshard-gsm1.example.com oshard-gsm1 +${LOCAL_NETWORK}.102 oshard-catalog-0.example.com oshard-catalog-0 +${LOCAL_NETWORK}.103 oshard1-0.example.com oshard1-0 +${LOCAL_NETWORK}.104 oshard2-0.example.com oshard2-0 +${LOCAL_NETWORK}.105 oshard3-0.example.com oshard3-0 +${LOCAL_NETWORK}.106 oshard4-0.example.com oshard4-0 +${LOCAL_NETWORK}.101 oshard-gsm2.example.com oshard-gsm2 +EOF +" + +# Create an encrypted password file. We have used password "Oracle_21c" here and used the location "/opt/.secrets" to create the encrypted password file: + +rm -rf /opt/.secrets/ +mkdir /opt/.secrets/ +openssl genrsa -out /opt/.secrets/key.pem +openssl rsa -in /opt/.secrets/key.pem -out /opt/.secrets/key.pub -pubout +echo Oracle_21c > /opt/.secrets/pwdfile.txt +openssl pkeyutl -in /opt/.secrets/pwdfile.txt -out /opt/.secrets/pwdfile.enc -pubin -inkey /opt/.secrets/key.pub -encrypt + +rm -f /opt/.secrets/pwdfile.txt +chown 54321:54321 /opt/.secrets/pwdfile.enc +chown 54321:54321 /opt/.secrets/key.pem +chown 54321:54321 /opt/.secrets/key.pub +chmod 400 /opt/.secrets/pwdfile.enc +chmod 400 /opt/.secrets/key.pem +chmod 400 /opt/.secrets/key.pub + + +# Create required directories +mkdir -p ${DOCKERVOLLOC}/scripts +chown -R 54321:54321 ${DOCKERVOLLOC}/scripts +chmod 755 ${DOCKERVOLLOC}/scripts + +mkdir -p ${DOCKERVOLLOC}/dbfiles/CATALOG +chown -R 54321:54321 ${DOCKERVOLLOC}/dbfiles/CATALOG + +mkdir -p ${DOCKERVOLLOC}/dbfiles/ORCL1CDB +chown -R 54321:54321 ${DOCKERVOLLOC}/dbfiles/ORCL1CDB +mkdir -p ${DOCKERVOLLOC}/dbfiles/ORCL2CDB +chown -R 54321:54321 ${DOCKERVOLLOC}/dbfiles/ORCL2CDB + +mkdir -p ${DOCKERVOLLOC}/dbfiles/GSMDATA +chown -R 54321:54321 ${DOCKERVOLLOC}/dbfiles/GSMDATA + +mkdir -p ${DOCKERVOLLOC}/dbfiles/GSM2DATA +chown -R 54321:54321 ${DOCKERVOLLOC}/dbfiles/GSM2DATA + + +chmod 755 ${DOCKERVOLLOC}/dbfiles/CATALOG +chmod 755 ${DOCKERVOLLOC}/dbfiles/ORCL1CDB +chmod 755 ${DOCKERVOLLOC}/dbfiles/ORCL2CDB +chmod 755 ${DOCKERVOLLOC}/dbfiles/GSMDATA +chmod 755 ${DOCKERVOLLOC}/dbfiles/GSM2DATA + diff --git a/container-based-sharding-deployment/samples/compose-files/docker-compose/docker-compose.yml b/container-based-sharding-deployment/samples/compose-files/docker-compose/docker-compose.yml new file mode 100644 index 0000000..2d91aad --- /dev/null +++ b/container-based-sharding-deployment/samples/compose-files/docker-compose/docker-compose.yml @@ -0,0 +1,169 @@ +--- +version: "3.8" +networks: + shard_pub1_nw: + name: shard_pub1_nw + driver: bridge + ipam: + config: + - subnet: "${NETWORK_SUBNET}" +services: + catalog_db: + container_name: ${CAT_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${CAT_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + volumes: + - ${DOCKERVOLLOC}/dbfiles/CATALOG:/opt/oracle/oradata + - /opt/.secrets:/run/secrets:ro + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${CAT_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${CAT_CDB} + ORACLE_PDB: ${CAT_PDB} + OP_TYPE: ${CATALOG_OP_TYPE} + COMMON_OS_PWD_FILE: ${COMMON_OS_PWD_FILE} + PWD_KEY: ${PWD_KEY} + INIT_SGA_SIZE: ${CATALOG_INIT_SGA_SIZE} + INIT_PGA_SIZE: ${CATALOG_INIT_PGA_SIZE} + ENABLE_ARCHIVELOG: ${CATALOG_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.102 + healthcheck: + test: ["CMD-SHELL","if [ `cat /tmp/test.log | grep -c 'GSM Catalog Setup Completed'` -ge 1 ]; then exit 0;else exit 1;fi"] + interval: ${healthcheck_interval} + timeout: ${healthcheck_timeout} + retries: ${healthcheck_retries} + shard1_db: + container_name: ${SHARD1_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${SHARD1_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + volumes: + - ${DOCKERVOLLOC}/dbfiles/ORCL1CDB:/opt/oracle/oradata + - /opt/.secrets:/run/secrets:ro + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${SHARD1_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${SHARD1_CDB} + ORACLE_PDB: ${SHARD1_PDB} + OP_TYPE: ${ALLSHARD_OP_TYPE} + COMMON_OS_PWD_FILE: ${COMMON_OS_PWD_FILE} + PWD_KEY: ${PWD_KEY} + INIT_SGA_SIZE: ${ALLSHARD_INIT_SGA_SIZE} + INIT_PGA_SIZE: ${ALLSHARD_INIT_PGA_SIZE} + ENABLE_ARCHIVELOG: ${SHARD_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.103 + healthcheck: + test: ["CMD-SHELL","if [ `cat /tmp/test.log | grep -c 'GSM Shard Setup Completed'` -ge 1 ]; then exit 0;else exit 1;fi"] + interval: ${healthcheck_interval} + timeout: ${healthcheck_timeout} + retries: ${healthcheck_retries} + shard2_db: + container_name: ${SHARD2_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${SHARD2_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + volumes: + - ${DOCKERVOLLOC}/dbfiles/ORCL2CDB:/opt/oracle/oradata + - /opt/.secrets:/run/secrets:ro + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${SHARD2_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${SHARD2_CDB} + ORACLE_PDB: ${SHARD2_PDB} + OP_TYPE: ${ALLSHARD_OP_TYPE} + COMMON_OS_PWD_FILE: ${COMMON_OS_PWD_FILE} + PWD_KEY: ${PWD_KEY} + INIT_SGA_SIZE: ${ALLSHARD_INIT_SGA_SIZE} + INIT_PGA_SIZE: ${ALLSHARD_INIT_PGA_SIZE} + ENABLE_ARCHIVELOG: ${SHARD_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.104 + healthcheck: + test: ["CMD-SHELL","if [ `cat /tmp/test.log | grep -c 'GSM Shard Setup Completed'` -ge 1 ]; then exit 0;else exit 1;fi"] + interval: ${healthcheck_interval} + timeout: ${healthcheck_timeout} + retries: ${healthcheck_retries} + primary_gsm: + container_name: ${PRIMARY_GSM_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${PRIMARY_GSM_HOSTNAME} + image: ${GSM_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + volumes: + - ${DOCKERVOLLOC}/dbfiles/GSMDATA:/opt/oracle/gsmdata + - /opt/.secrets:/run/secrets:ro + - /opt/containers/shard_host_file:/etc/hosts + environment: + DOMAIN: ${DOMAIN} + SHARD_DIRECTOR_PARAMS: ${PRIMARY_SHARD_DIRECTOR_PARAMS} + SHARD1_GROUP_PARAMS: ${PRIMARY_SHARD1_GROUP_PARAMS} + CATALOG_PARAMS: ${PRIMARY_CATALOG_PARAMS} + SHARD1_PARAMS: ${PRIMARY_SHARD1_PARAMS} + SHARD2_PARAMS: ${PRIMARY_SHARD2_PARAMS} + SERVICE1_PARAMS: ${PRIMARY_SERVICE1_PARAMS} + SERVICE2_PARAMS: ${PRIMARY_SERVICE2_PARAMS} + COMMON_OS_PWD_FILE: ${COMMON_OS_PWD_FILE} + PWD_KEY: ${PWD_KEY} + MASTER_GSM: "TRUE" + OP_TYPE: ${GSM_OP_TYPE} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.100 + depends_on: + catalog_db: + condition: service_healthy + shard1_db: + condition: service_healthy + shard2_db: + condition: service_healthy + healthcheck: + test: ["CMD-SHELL","if [ `cat /tmp/test.log | grep -c 'GSM Setup Completed'` -ge 1 ]; then exit 0;else exit 1;fi"] + interval: ${healthcheck_interval} + timeout: ${healthcheck_timeout} + retries: ${healthcheck_retries} + standby_gsm: + container_name: ${STANDBY_GSM_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${STANDBY_GSM_HOSTNAME} + image: ${GSM_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + volumes: + - ${DOCKERVOLLOC}/dbfiles/GSM2DATA:/opt/oracle/gsmdata + - /opt/.secrets:/run/secrets:ro + - /opt/containers/shard_host_file:/etc/hosts + environment: + CATALOG_SETUP: ${STANDBY_GSM_SHARD_SETUP} + DOMAIN: ${DOMAIN} + SHARD_DIRECTOR_PARAMS: ${STANDBY_SHARD_DIRECTOR_PARAMS} + SHARD1_GROUP_PARAMS: ${STANDBY_SHARD1_GROUP_PARAMS} + CATALOG_PARAMS: ${STANDBY_CATALOG_PARAMS} + SHARD1_PARAMS: ${STANDBY_SHARD1_PARAMS} + SHARD2_PARAMS: ${STANDBY_SHARD2_PARAMS} + SERVICE1_PARAMS: ${STANDBY_SERVICE1_PARAMS} + SERVICE2_PARAMS: ${STANDBY_SERVICE2_PARAMS} + COMMON_OS_PWD_FILE: ${COMMON_OS_PWD_FILE} + PWD_KEY: ${PWD_KEY} + OP_TYPE: ${GSM_OP_TYPE} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.101 + depends_on: + primary_gsm: + condition: service_healthy \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/compose-files/podman-compose/README.md b/container-based-sharding-deployment/samples/compose-files/podman-compose/README.md new file mode 100644 index 0000000..b7736bb --- /dev/null +++ b/container-based-sharding-deployment/samples/compose-files/podman-compose/README.md @@ -0,0 +1,137 @@ +# Deploying Oracle Globally Distributed Database Containers using podman-compose +For Oracle Linux 8 host machines,`podman-compose` can be used for deploying containers to create an Oracle Globally Distributed Database. + +You can use Oracle 23ai GSM and RDBMS Podman Images (Enterprise or FREE) and deploy with the sharding option of your choice: `System-Managed Sharding`, `System-Managed Sharding Topology with Raft replication`, or `User Defined Sharding`. The sharding optoin is deployed with Oracle Globally Distributed Database. + +The example that follows shows how to use `podman-compose` to create the Podman network and to deploy containers for an Oracle Globally Distributed Database on a single Oracle Linux 8 host. + +In this example, we deploy an Oracle Globally Distributed Database with `System-Managed Sharding Topology with Raft replication` using Oracle 23ai GSM and RDBMS Images with Four shard containers, a Catalog Container, a Primary GSM container, and a Standby GSM Container. + +**IMPORTANT:** This example uses 23ai RDBMS and 23ai GSM Podman Images, and enables the RAFT Replication feature while deploying the Oracle Globally Distributed database. + + +- [Step 1: Install Podman compose](#install-podman-compose) +- [Step 2: Complete the prerequisite steps](#complete-the-prerequisite-steps) +- [Step 3: SELinux Configuration Management for Podman Host](#selinux-configuration-management-for-podman-host) +- [Step 4: Create Podman Compose file](#create-podman-compose-file) +- [Step 5: Create services using "podman-compose" command](#create-services-using-podman-compose-command) +- [Step 6: Check the logs](#check-the-logs) +- [Step 7: Remove the deployment](#remove-the-deployment) +- [Step 8: Oracle 23ai FREE Database and GSM Images](#oracle-23ai-free-database-and-gsm-images) +- [Copyright](#copyright) + + +## Install Podman compose +```bash +dnf config-manager --enable ol8_developer_EPEL +dnf install podman-compose +``` + +## Complete the prerequisite steps +Complete each of these steps before proceeding with deployment. + +### Create Podman Secrets + +Complete the procedure to create Podman secrets from [Password Management](../../container-files/podman-container-files/README.md#password-management). These Podman secrets are also used during the deployment of Oracle Globally Distributed Database Containers. + +### Prerequisites script file +Run the script file [podman-compose-prequisites.sh](./podman-compose-prequisites.sh). This script exports the environment variables, creates the network host file, and creates required directories. + +**NOTE:** You must change the values for `SIDB_IMAGE` and `GSM_IMAGE` to use the images that you want to use for the deployment. + +```bash +source podman-compose-prequisites.sh +``` + +## SELinux Configuration Management for Podman Host +If SELinux is enabled on your podman-host, then load the necessary `shard-podman` policy, as explained in [SELinux Configuration on Podman Host](../container-files/podman-container-files/README.md#selinux-configuration-on-podman-host) + +To set SELinux contexts for required files and folders, run the file [set-file-context.sh](./set-file-context.sh) +```bash +source set-file-context.sh +``` + +## Create Podman Compose file + +Copy the [podman-compose.yml](podman-compose.yml) into your working directory. In this example, our working directory is [<github_cloned_path>/db-sharding/container-based-sharding-deployment/containerfiles] + +## Create services using "podman-compose" command +After you have completed all the prerequisties successfully, run the following command to create the services: +```bash +# Ensure "podman-compose.yml" file is present in your working directory and then run the following command: + +podman-compose up -d +``` + +Wait for all the services setup to be complete and ready: +```bash +podman ps -a +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +56fd25ab3476 localhost/oracle/database-ext-sharding:23.5.0-ee /bin/sh -c exec $... 7 minutes ago Up 7 minutes catalog +05e1d72ae93e localhost/oracle/database-ext-sharding:23.5.0-ee /bin/sh -c exec $... 7 minutes ago Up 7 minutes shard1 +7dbd9ce5564b localhost/oracle/database-ext-sharding:23.5.0-ee /bin/sh -c exec $... 7 minutes ago Up 7 minutes shard2 +5e1341e3eeab localhost/oracle/database-ext-sharding:23.5.0-ee /bin/sh -c exec $... 7 minutes ago Up 7 minutes shard3 +dad4f89a8aaa localhost/oracle/database-ext-sharding:23.5.0-ee /bin/sh -c exec $... 7 minutes ago Up 7 minutes shard4 +a265f8438bb7 localhost/oracle/database-gsm:23.5.0 /bin/sh -c exec $... 7 minutes ago Up 7 minutes gsm1 +f155a7f61830 localhost/oracle/database-gsm:23.5.0 /bin/sh -c exec $... 7 minutes ago Up 7 minutes gsm2 +``` + +## Check the logs +```bash +# You can monitor the logs for all the containers using the following command: + +podman-compose logs -f +``` +Look for successful message in all containers. For example:- +```bash +podman logs -f catalog +============================================== + GSM Catalog Setup Completed +============================================== + +podman logs -f shard1 +============================================== + GSM Shard Setup Completed +============================================== + +podman logs -f shard2 +============================================== + GSM Shard Setup Completed +============================================== + +podman logs -f gsm1 +============================================== + GSM Setup Completed +============================================== + +podman logs -f gsm2 +============================================== + GSM Setup Completed +============================================== +``` + +## Remove the deployment + +If you want to remove the deployment, then run the `podman-compose` command. To remove the deployment: + +- With the environment variables set in [Prerequisites Section](#complete-the-prerequisite-steps), run the following command to remove the Oracle Globally Distributed Database Containers and folders: + +```bash +podman-compose down +rm -rf ${PODMANVOLLOC} +``` + +## Oracle 23ai FREE Database and GSM Images + +If you plan to use Oracle 23ai FREE Database and GSM Images for deploying the Oracle Globally Distributed Database, then complete these steps: + +- Use file [podman-compose-prequisites-free.sh](./podman-compose-prequisites-free.sh) as the prerequisites script file before running the setup as described above. + +**NOTE:** You must change the values for `SIDB_IMAGE` and `GSM_IMAGE` to use the Oracle 23ai FREE Images you want to use for the deployment. + +- Take the file [podman-compose-free.yml](./podman-compose-free.yml) and rename it as `podman-compose.yml` to deploy the setup using the `podman-compose` command. + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-free.yml b/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-free.yml new file mode 100644 index 0000000..66c1277 --- /dev/null +++ b/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-free.yml @@ -0,0 +1,213 @@ +--- +version: "3.8" +networks: + shard_pub1_nw: + name: shard_pub1_nw + driver: bridge + ipam: + config: + - subnet: "${NETWORK_SUBNET}" +secrets: + pwdsecret: + external: pwdsecret + keysecret: + external: keysecret +services: + catalog_db: + container_name: ${CAT_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${CAT_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/CATALOG:/opt/oracle/oradata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${CAT_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${CAT_SID} + ORACLE_PDB: ${CAT_PDB"} + ORACLE_FREE_PDB: ${CAT_FREE_PDB} + DB_UNIQUE_NAME: ${CAT_CDB} + OP_TYPE: ${CATALOG_OP_TYPE} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + ENABLE_ARCHIVELOG: ${CATALOG_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.102 + shard1_db: + container_name: ${SHARD1_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${SHARD1_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/ORCL1CDB:/opt/oracle/oradata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${SHARD1_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${SHARD1_SID} + ORACLE_PDB: ${SHARD1_PDB"} + ORACLE_FREE_PDB: ${SHARD1_FREE_PDB} + DB_UNIQUE_NAME: ${SHARD1_CDB} + OP_TYPE: ${ALLSHARD_OP_TYPE} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + ENABLE_ARCHIVELOG: ${SHARD_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.103 + shard2_db: + container_name: ${SHARD2_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${SHARD2_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/ORCL2CDB:/opt/oracle/oradata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${SHARD2_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${SHARD2_SID} + ORACLE_PDB: ${SHARD2_PDB"} + ORACLE_FREE_PDB: ${SHARD2_FREE_PDB} + DB_UNIQUE_NAME: ${SHARD2_CDB} + OP_TYPE: ${ALLSHARD_OP_TYPE} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + ENABLE_ARCHIVELOG: ${SHARD_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.104 + shard3_db: + container_name: ${SHARD3_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${SHARD3_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/ORCL3CDB:/opt/oracle/oradata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${SHARD3_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${SHARD3_SID} + ORACLE_PDB: ${SHARD3_PDB"} + ORACLE_FREE_PDB: ${SHARD3_FREE_PDB} + DB_UNIQUE_NAME: ${SHARD3_CDB} + OP_TYPE: ${ALLSHARD_OP_TYPE} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + ENABLE_ARCHIVELOG: ${SHARD_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.105 + shard4_db: + container_name: ${SHARD4_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${SHARD4_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + dbEdition: ${DB_EDITION} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/ORCL4CDB:/opt/oracle/oradata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${SHARD4_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${SHARD4_SID} + ORACLE_PDB: ${SHARD4_PDB"} + ORACLE_FREE_PDB: ${SHARD4_FREE_PDB} + DB_UNIQUE_NAME: ${SHARD4_CDB} + OP_TYPE: ${ALLSHARD_OP_TYPE} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + ENABLE_ARCHIVELOG: ${SHARD_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.106 + primary_gsm: + container_name: ${PRIMARY_GSM_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${PRIMARY_GSM_HOSTNAME} + image: ${GSM_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/GSMDATA:/opt/oracle/gsmdata + - /opt/containers/shard_host_file:/etc/hosts + environment: + DOMAIN: ${DOMAIN} + SHARD_DIRECTOR_PARAMS: ${PRIMARY_SHARD_DIRECTOR_PARAMS} + SHARD1_GROUP_PARAMS: ${PRIMARY_SHARD1_GROUP_PARAMS} + CATALOG_PARAMS: ${PRIMARY_CATALOG_PARAMS} + SHARD1_PARAMS: ${PRIMARY_SHARD1_PARAMS} + SHARD2_PARAMS: ${PRIMARY_SHARD2_PARAMS} + SHARD3_PARAMS: ${STANDBY_SHARD3_PARAMS} + SHARD4_PARAMS: ${STANDBY_SHARD4_PARAMS} + SERVICE1_PARAMS: ${PRIMARY_SERVICE1_PARAMS} + SERVICE2_PARAMS: ${PRIMARY_SERVICE2_PARAMS} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + MASTER_GSM: "TRUE" + OP_TYPE: ${GSM_OP_TYPE} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.100 + standby_gsm: + container_name: ${STANDBY_GSM_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${STANDBY_GSM_HOSTNAME} + image: ${GSM_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/GSM2DATA:/opt/oracle/gsmdata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${STANDBY_GSM_SHARD_SETUP} + DOMAIN: ${DOMAIN} + SHARD_DIRECTOR_PARAMS: ${STANDBY_SHARD_DIRECTOR_PARAMS} + SHARD1_GROUP_PARAMS: ${STANDBY_SHARD1_GROUP_PARAMS} + CATALOG_PARAMS: ${STANDBY_CATALOG_PARAMS} + SHARD1_PARAMS: ${STANDBY_SHARD1_PARAMS} + SHARD2_PARAMS: ${STANDBY_SHARD2_PARAMS} + SHARD3_PARAMS: ${STANDBY_SHARD3_PARAMS} + SHARD4_PARAMS: ${STANDBY_SHARD4_PARAMS} + SERVICE1_PARAMS: ${STANDBY_SERVICE1_PARAMS} + SERVICE2_PARAMS: ${STANDBY_SERVICE2_PARAMS} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + OP_TYPE: ${GSM_OP_TYPE} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.101 diff --git a/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-prerequisites-free.sh b/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-prerequisites-free.sh new file mode 100644 index 0000000..62c9f26 --- /dev/null +++ b/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-prerequisites-free.sh @@ -0,0 +1,139 @@ +#!/bin/bash + +# Variables to be exported before using podman-compose to deploy Globally Distributed Database using podman with FREE Images +export PODMANVOLLOC='/scratch/oradata' +export NETWORK_INTERFACE='ens3' +export NETWORK_SUBNET="10.0.20.0/20" +export SIDB_IMAGE='oracle/database-ext-sharding:23.5.0-ee-free' +export GSM_IMAGE='oracle/database-gsm:23.5.0-free' +export LOCAL_NETWORK=10.0.20 +export healthcheck_interval=30s +export healthcheck_timeout=3s +export healthcheck_retries=40 +export CATALOG_OP_TYPE="catalog" +export ALLSHARD_OP_TYPE="primaryshard" +export GSM_OP_TYPE="gsm" +export CAT_SHARD_SETUP="true" +export CATALOG_ARCHIVELOG="true" +export SHARD_ARCHIVELOG="true" +export SHARD1_SHARD_SETUP="true" +export SHARD2_SHARD_SETUP="true" +export SHARD3_SHARD_SETUP="true" +export SHARD4_SHARD_SETUP="true" +export PRIMARY_GSM_SHARD_SETUP="true" +export STANDBY_GSM_SHARD_SETUP="true" +export ORACLE_FREE_PDB="FREEPDB1" + +export CONTAINER_RESTART_POLICY="always" +export CONTAINER_PRIVILEGED_FLAG="false" +export DOMAIN="example.com" +export DNS_SEARCH="example.com" +export CAT_CDB="CATCDB" +export CAT_PDB="FREEPDB1" +export CAT_FREE_PDB="CAT1PDB" +export CAT_SID="FREE" +export CAT_HOSTNAME="oshard-catalog-0" +export CAT_CONTAINER_NAME="catalog" + +export SHARD1_CONTAINER_NAME="shard1" +export SHARD1_HOSTNAME="oshard1-0" +export SHARD1_CDB="ORCL1CDB" +export SHARD1_PDB="FREEPDB1" +export SHARD1_FREE_PDB="ORCL1PDB" +export SHARD1_SID="FREE" + +export SHARD2_CONTAINER_NAME="shard2" +export SHARD2_HOSTNAME="oshard2-0" +export SHARD2_CDB="ORCL2CDB" +export SHARD2_PDB="FREEPDB1" +export SHARD2_FREE_PDB="ORCL2PDB" +export SHARD2_SID="FREE" + +export SHARD3_CONTAINER_NAME="shard3" +export SHARD3_HOSTNAME="oshard3-0" +export SHARD3_CDB="ORCL3CDB" +export SHARD3_PDB="FREEPDB1" +export SHARD3_FREE_PDB="ORCL3PDB" +export SHARD3_SID="FREE" + +export SHARD4_CONTAINER_NAME="shard4" +export SHARD4_HOSTNAME="oshard4-0" +export SHARD4_CDB="ORCL4CDB" +export SHARD4_PDB="FREEPDB1" +export SHARD4_FREE_PDB="ORCL4PDB" +export SHARD4_SID="FREE" + +export PRIMARY_GSM_CONTAINER_NAME="gsm1" +export PRIMARY_GSM_HOSTNAME="oshard-gsm1" +export STANDBY_GSM_CONTAINER_NAME="gsm2" +export STANDBY_GSM_HOSTNAME="oshard-gsm2" + + +export PRIMARY_SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" +export PRIMARY_SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=primary;group_region=region1" +export PRIMARY_CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=12;repl_type=Native" +export PRIMARY_SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" +export PRIMARY_SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" +export PRIMARY_SHARD3_PARAMS="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" +export PRIMARY_SHARD4_PARAMS="shard_host=oshard4-0;shard_db=ORCL4CDB;shard_pdb=ORCL4PDB;shard_port=1521;shard_group=shardgroup1" +export PRIMARY_SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" +export PRIMARY_SERVICE2_PARAMS="service_name=oltp_rw_svc;service_role=primary" + +export STANDBY_SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region1;director_port=1522 " +export STANDBY_SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=active_standby;group_region=region1" +export STANDBY_CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=12;repl_type=Native" +export STANDBY_SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" +export STANDBY_SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" +export STANDBY_SHARD3_PARAMS="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" +export STANDBY_SHARD4_PARAMS="shard_host=oshard4-0;shard_db=ORCL4CDB;shard_pdb=ORCL4PDB;shard_port=1521;shard_group=shardgroup1" +export STANDBY_SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" +export STANDBY_SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" + + +# Create network host file +mkdir -p /opt/containers +rm -f /opt/containers/shard_host_file && touch /opt/containers/shard_host_file +sh -c "cat << EOF > /opt/containers/shard_host_file +127.0.0.1 localhost.localdomain localhost +${LOCAL_NETWORK}.100 oshard-gsm1.example.com oshard-gsm1 +${LOCAL_NETWORK}.102 oshard-catalog-0.example.com oshard-catalog-0 +${LOCAL_NETWORK}.103 oshard1-0.example.com oshard1-0 +${LOCAL_NETWORK}.104 oshard2-0.example.com oshard2-0 +${LOCAL_NETWORK}.105 oshard3-0.example.com oshard3-0 +${LOCAL_NETWORK}.106 oshard4-0.example.com oshard4-0 +${LOCAL_NETWORK}.101 oshard-gsm2.example.com oshard-gsm2 + +EOF +" + +# Create required directries + +mkdir -p ${PODMANVOLLOC}/scripts +chown -R 54321:54321 ${PODMANVOLLOC}/scripts +chmod 755 ${PODMANVOLLOC}/scripts + +mkdir -p ${PODMANVOLLOC}/dbfiles/CATALOG +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/CATALOG + +mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL1CDB +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL1CDB +mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL2CDB +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL2CDB +mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL3CDB +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL3CDB +mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL4CDB +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL4CDB + +mkdir -p ${PODMANVOLLOC}/dbfiles/GSMDATA +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/GSMDATA + +mkdir -p ${PODMANVOLLOC}/dbfiles/GSM2DATA +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/GSM2DATA + +chmod 755 ${PODMANVOLLOC}/dbfiles/CATALOG +chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL1CDB +chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL2CDB +chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL3CDB +chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL4CDB +chmod 755 ${PODMANVOLLOC}/dbfiles/GSMDATA +chmod 755 ${PODMANVOLLOC}/dbfiles/GSM2DATA diff --git a/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-prerequisites.sh b/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-prerequisites.sh new file mode 100644 index 0000000..7e6ae4e --- /dev/null +++ b/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose-prerequisites.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +# Variables to be exported before using podman-compose to deploy Globally Distributed Database using podman with Enterprise Images +export PODMANVOLLOC='/scratch/oradata' +export NETWORK_INTERFACE='ens3' +export NETWORK_SUBNET="10.0.20.0/20" +export SIDB_IMAGE='oracle/database-ext-sharding:23.5.0-ee' +export GSM_IMAGE='oracle/database-gsm:23.5.0' +export LOCAL_NETWORK=10.0.20 +export healthcheck_interval=30s +export healthcheck_timeout=3s +export healthcheck_retries=40 +export CATALOG_OP_TYPE="catalog" +export ALLSHARD_OP_TYPE="primaryshard" +export GSM_OP_TYPE="gsm" +export CAT_SHARD_SETUP="true" +export CATALOG_ARCHIVELOG="true" +export SHARD_ARCHIVELOG="true" +export SHARD1_SHARD_SETUP="true" +export SHARD2_SHARD_SETUP="true" +export SHARD3_SHARD_SETUP="true" +export SHARD4_SHARD_SETUP="true" +export PRIMARY_GSM_SHARD_SETUP="true" +export STANDBY_GSM_SHARD_SETUP="true" + +export CONTAINER_RESTART_POLICY="always" +export CONTAINER_PRIVILEGED_FLAG="false" +export DOMAIN="example.com" +export DNS_SEARCH="example.com" +export CAT_CDB="CATCDB" +export CAT_PDB="CAT1PDB" +export CAT_HOSTNAME="oshard-catalog-0" +export CAT_CONTAINER_NAME="catalog" + +export SHARD1_CONTAINER_NAME="shard1" +export SHARD1_HOSTNAME="oshard1-0" +export SHARD1_CDB="ORCL1CDB" +export SHARD1_PDB="ORCL1PDB" + +export SHARD2_CONTAINER_NAME="shard2" +export SHARD2_HOSTNAME="oshard2-0" +export SHARD2_CDB="ORCL2CDB" +export SHARD2_PDB="ORCL2PDB" + +export SHARD3_CONTAINER_NAME="shard3" +export SHARD3_HOSTNAME="oshard3-0" +export SHARD3_CDB="ORCL3CDB" +export SHARD3_PDB="ORCL3PDB" + +export SHARD4_CONTAINER_NAME="shard4" +export SHARD4_HOSTNAME="oshard4-0" +export SHARD4_CDB="ORCL4CDB" +export SHARD4_PDB="ORCL4PDB" + +export PRIMARY_GSM_CONTAINER_NAME="gsm1" +export PRIMARY_GSM_HOSTNAME="oshard-gsm1" +export STANDBY_GSM_CONTAINER_NAME="gsm2" +export STANDBY_GSM_HOSTNAME="oshard-gsm2" + + +export PRIMARY_SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" +export PRIMARY_SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=primary;group_region=region1" +export PRIMARY_CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=30;repl_type=Native" +export PRIMARY_SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" +export PRIMARY_SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" +export PRIMARY_SHARD3_PARAMS="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" +export PRIMARY_SHARD4_PARAMS="shard_host=oshard4-0;shard_db=ORCL4CDB;shard_pdb=ORCL4PDB;shard_port=1521;shard_group=shardgroup1" +export PRIMARY_SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" +export PRIMARY_SERVICE2_PARAMS="service_name=oltp_rw_svc;service_role=primary" + +export STANDBY_SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region1;director_port=1522 " +export STANDBY_SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=active_standby;group_region=region1" +export STANDBY_CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=30;repl_type=Native" +export STANDBY_SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" +export STANDBY_SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" +export STANDBY_SHARD3_PARAMS="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" +export STANDBY_SHARD4_PARAMS="shard_host=oshard4-0;shard_db=ORCL4CDB;shard_pdb=ORCL4PDB;shard_port=1521;shard_group=shardgroup1" +export STANDBY_SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" +export STANDBY_SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" + +# Create network host file +mkdir -p /opt/containers +rm -f /opt/containers/shard_host_file && touch /opt/containers/shard_host_file +sh -c "cat << EOF > /opt/containers/shard_host_file +127.0.0.1 localhost.localdomain localhost +${LOCAL_NETWORK}.100 oshard-gsm1.example.com oshard-gsm1 +${LOCAL_NETWORK}.102 oshard-catalog-0.example.com oshard-catalog-0 +${LOCAL_NETWORK}.103 oshard1-0.example.com oshard1-0 +${LOCAL_NETWORK}.104 oshard2-0.example.com oshard2-0 +${LOCAL_NETWORK}.105 oshard3-0.example.com oshard3-0 +${LOCAL_NETWORK}.106 oshard4-0.example.com oshard4-0 +${LOCAL_NETWORK}.101 oshard-gsm2.example.com oshard-gsm2 + +EOF +" + +# Create required directries +mkdir -p ${PODMANVOLLOC}/scripts +chown -R 54321:54321 ${PODMANVOLLOC}/scripts +chmod 755 ${PODMANVOLLOC}/scripts + +mkdir -p ${PODMANVOLLOC}/dbfiles/CATALOG +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/CATALOG + +mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL1CDB +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL1CDB +mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL2CDB +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL2CDB +mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL3CDB +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL3CDB +mkdir -p ${PODMANVOLLOC}/dbfiles/ORCL4CDB +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/ORCL4CDB + +mkdir -p ${PODMANVOLLOC}/dbfiles/GSMDATA +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/GSMDATA + +mkdir -p ${PODMANVOLLOC}/dbfiles/GSM2DATA +chown -R 54321:54321 ${PODMANVOLLOC}/dbfiles/GSM2DATA + +chmod 755 ${PODMANVOLLOC}/dbfiles/CATALOG +chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL1CDB +chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL2CDB +chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL3CDB +chmod 755 ${PODMANVOLLOC}/dbfiles/ORCL4CDB +chmod 755 ${PODMANVOLLOC}/dbfiles/GSMDATA +chmod 755 ${PODMANVOLLOC}/dbfiles/GSM2DATA + diff --git a/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose.yml b/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose.yml new file mode 100644 index 0000000..2598ab7 --- /dev/null +++ b/container-based-sharding-deployment/samples/compose-files/podman-compose/podman-compose.yml @@ -0,0 +1,202 @@ +--- +version: "3.8" +networks: + shard_pub1_nw: + name: shard_pub1_nw + driver: bridge + ipam: + config: + - subnet: "${NETWORK_SUBNET}" +secrets: + pwdsecret: + external: pwdsecret + keysecret: + external: keysecret +services: + catalog_db: + container_name: ${CAT_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${CAT_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/CATALOG:/opt/oracle/oradata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${CAT_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${CAT_CDB} + ORACLE_PDB: ${CAT_PDB} + OP_TYPE: ${CATALOG_OP_TYPE} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + ENABLE_ARCHIVELOG: ${CATALOG_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.102 + shard1_db: + container_name: ${SHARD1_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${SHARD1_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/ORCL1CDB:/opt/oracle/oradata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${SHARD1_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${SHARD1_CDB} + ORACLE_PDB: ${SHARD1_PDB} + OP_TYPE: ${ALLSHARD_OP_TYPE} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + ENABLE_ARCHIVELOG: ${SHARD_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.103 + shard2_db: + container_name: ${SHARD2_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${SHARD2_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/ORCL2CDB:/opt/oracle/oradata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${SHARD2_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${SHARD2_CDB} + ORACLE_PDB: ${SHARD2_PDB} + OP_TYPE: ${ALLSHARD_OP_TYPE} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + ENABLE_ARCHIVELOG: ${SHARD_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.104 + shard3_db: + container_name: ${SHARD3_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${SHARD3_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/ORCL3CDB:/opt/oracle/oradata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${SHARD3_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${SHARD3_CDB} + ORACLE_PDB: ${SHARD3_PDB} + OP_TYPE: ${ALLSHARD_OP_TYPE} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + ENABLE_ARCHIVELOG: ${SHARD_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.105 + shard4_db: + container_name: ${SHARD4_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${SHARD4_HOSTNAME} + image: ${SIDB_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/ORCL4CDB:/opt/oracle/oradata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${SHARD4_SHARD_SETUP} + DOMAIN: ${DOMAIN} + ORACLE_SID: ${SHARD4_CDB} + ORACLE_PDB: ${SHARD4_PDB} + OP_TYPE: ${ALLSHARD_OP_TYPE} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + ENABLE_ARCHIVELOG: ${SHARD_ARCHIVELOG} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.106 + primary_gsm: + container_name: ${PRIMARY_GSM_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${PRIMARY_GSM_HOSTNAME} + image: ${GSM_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/GSMDATA:/opt/oracle/gsmdata + - /opt/containers/shard_host_file:/etc/hosts + environment: + DOMAIN: ${DOMAIN} + SHARD_DIRECTOR_PARAMS: ${PRIMARY_SHARD_DIRECTOR_PARAMS} + SHARD1_GROUP_PARAMS: ${PRIMARY_SHARD1_GROUP_PARAMS} + CATALOG_PARAMS: ${PRIMARY_CATALOG_PARAMS} + SHARD1_PARAMS: ${PRIMARY_SHARD1_PARAMS} + SHARD2_PARAMS: ${PRIMARY_SHARD2_PARAMS} + SHARD3_PARAMS: ${STANDBY_SHARD3_PARAMS} + SHARD4_PARAMS: ${STANDBY_SHARD4_PARAMS} + SERVICE1_PARAMS: ${PRIMARY_SERVICE1_PARAMS} + SERVICE2_PARAMS: ${PRIMARY_SERVICE2_PARAMS} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + MASTER_GSM: "TRUE" + OP_TYPE: ${GSM_OP_TYPE} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.100 + standby_gsm: + container_name: ${STANDBY_GSM_CONTAINER_NAME} + privileged: ${CONTAINER_PRIVILEGED_FLAG} + hostname: ${STANDBY_GSM_HOSTNAME} + image: ${GSM_IMAGE} + dns_search: ${DNS_SEARCH} + restart: ${CONTAINER_RESTART_POLICY} + secrets: + - pwdsecret + - keysecret + volumes: + - ${PODMANVOLLOC}/dbfiles/GSM2DATA:/opt/oracle/gsmdata + - /opt/containers/shard_host_file:/etc/hosts + environment: + SHARD_SETUP: ${STANDBY_GSM_SHARD_SETUP} + DOMAIN: ${DOMAIN} + SHARD_DIRECTOR_PARAMS: ${STANDBY_SHARD_DIRECTOR_PARAMS} + SHARD1_GROUP_PARAMS: ${STANDBY_SHARD1_GROUP_PARAMS} + CATALOG_PARAMS: ${STANDBY_CATALOG_PARAMS} + SHARD1_PARAMS: ${STANDBY_SHARD1_PARAMS} + SHARD2_PARAMS: ${STANDBY_SHARD2_PARAMS} + SHARD3_PARAMS: ${STANDBY_SHARD3_PARAMS} + SHARD4_PARAMS: ${STANDBY_SHARD4_PARAMS} + SERVICE1_PARAMS: ${STANDBY_SERVICE1_PARAMS} + SERVICE2_PARAMS: ${STANDBY_SERVICE2_PARAMS} + COMMON_OS_PWD_FILE: pwdsecret + PWD_KEY: keysecret + OP_TYPE: ${GSM_OP_TYPE} + networks: + shard_pub1_nw: + ipv4_address: ${LOCAL_NETWORK}.101 diff --git a/container-based-sharding-deployment/samples/compose-files/podman-compose/set-file-context.sh b/container-based-sharding-deployment/samples/compose-files/podman-compose/set-file-context.sh new file mode 100644 index 0000000..20b623d --- /dev/null +++ b/container-based-sharding-deployment/samples/compose-files/podman-compose/set-file-context.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +files=( + "${PODMANVOLLOC}/dbfiles/CATALOG" + "/opt/containers/shard_host_file" + "${PODMANVOLLOC}/dbfiles/ORCL1CDB" + "${PODMANVOLLOC}/dbfiles/ORCL2CDB" + "${PODMANVOLLOC}/dbfiles/GSMDATA" + "${PODMANVOLLOC}/dbfiles/GSM2DATA" + "${PODMANVOLLOC}/dbfiles/ORCL3CDB" + "${PODMANVOLLOC}/dbfiles/ORCL4CDB" + ) + + # Check if SELinux is enabled (enforcing or permissive) + if grep -q '^SELINUX=enforcing' /etc/selinux/config || grep -q '^SELINUX=permissive' /etc/selinux/config; then + for file in "${files[@]}"; do + semanage fcontext -a -t container_file_t "$file" + restorecon -v "$file" + done + echo "SELinux is enabled. Updated file contexts." + fi diff --git a/container-based-sharding-deployment/samples/container-files/docker-container-files/README.md b/container-based-sharding-deployment/samples/container-files/docker-container-files/README.md new file mode 100644 index 0000000..5c5e4ea --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/docker-container-files/README.md @@ -0,0 +1,136 @@ +# Oracle Globally Distributed Database Containers on Docker + +Docker is used on Oracle Linux 7 Host Machines to create containers. This document provides the details to manually create the Docker containers to deploy an Oracle Globally Distributed Database. + +- [Prerequisites](#prerequisites) + - [Create Network Bridge](#create-network-bridge) + - [Macvlan Bridge](#macvlan-bridge) + - [Ipvlan Bridge](#ipvlan-bridge) + - [Bridge](#bridge) + - [Setup Hostfile](#setup-hostfile) + - [Password Setup](#password-setup) + - [Create Containers](#create-containers) + - [Deploy Oracle Globally Distributed Database with System-Managed Sharding](#deploy-oracle-globally-distributed-database-with-system-managed-sharding) + - [Deploy Oracle Globally Distributed Database with User-Defined Sharding](#deploy-oracle-globally-distributed-database-with-user-defined-sharding) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + + +## Prerequisites + +You must complete all of the prerequisites before deploying an Oracle Globally Distributed Database using Docker Containers. These prerequisites include creating the Docker network, creating the encrypted file with secrets, and other steps required before deployment. + + +### Create Network Bridge + +Before creating a container, you must create the Docker network by creating a Docker network bridge based on your environment. If you are using the bridge name with the network subnet mentioned in this README.md then you can use the same IPs mentioned in the [Create Containers](#create-containers) section. + +#### Macvlan Bridge + +```bash +docker network create -d macvlan --subnet=10.0.20.0/24 --gateway=10.0.20.1 -o parent=ens5 shard_pub1_nw +``` + +#### Ipvlan Bridge + +```bash +docker network create -d ipvlan --subnet=10.0.20.0/24 --gateway=10.0.20.1 -o parent=ens5 shard_pub1_nw +``` + +If you are planning to create a test environment within a single machine, then you can use a Docker bridge. However, these IPs will not be reachable on the user network. + +#### Bridge + +```bash +docker network create --driver=bridge --subnet=10.0.20.0/24 shard_pub1_nw +``` + +**Note:** You can change the subnet and choose one of the other Docker network bridge options mentioned above, based on your environment. + +### Setup Hostfile + +**Note:** You can skip this step of creating a Hostfile when you are using a DNS for the IP resolution. + +All containers will share a host file for name resolution. The shared hostfile must be available to all containers. Create the shared host file (if it doesn't exist) at `/opt/containers/shard_host_file`. + +For example: + +```bash +mkdir /opt/containers +rm -rf /opt/containers/shard_host_file && touch /opt/containers/shard_host_file +``` + +Because Oracle Database containers do not have root access to modify the `/etc/hosts` file, add the following host entries in `/opt/containers/shard_host_file` This file must be prepopulated. You can change these entries based on your environment and network setup. + +```bash +127.0.0.1 localhost.localdomain localhost +10.0.20.100 oshard-gsm1.example.com oshard-gsm1 +10.0.20.101 oshard-gsm2.example.com oshard-gsm2 +10.0.20.102 oshard-catalog-0.example.com oshard-catalog-0 +10.0.20.103 oshard1-0.example.com oshard1-0 +10.0.20.104 oshard2-0.example.com oshard2-0 +10.0.20.105 oshard3-0.example.com oshard3-0 +10.0.20.106 oshard4-0.example.com oshard4-0 +``` + +### Password Setup + +Specify the secret volume for resetting the database user password during catalog and shard setup. This secret volume can be a shared volume among all the containers + +```bash +mkdir /opt/.secrets/ +openssl genrsa -out /opt/.secrets/key.pem +openssl rsa -in /opt/.secrets/key.pem -out /opt/.secrets/key.pub -pubout +``` + +Edit the `/opt/.secrets/pwdfile.txt` and seed the password. The password will be a common password for all the database users. Execute following command: + +```bash +vi /opt/.secrets/pwdfile.txt +``` + +**Note**: Enter your secure password in the above file and save the file. + +After seeding password and saving the `/opt/.secrets/pwdfile.txt` file, run the following command: +```bash +openssl pkeyutl -in /opt/.secrets/pwdfile.txt -out /opt/.secrets/pwdfile.enc -pubin -inkey /opt/.secrets/key.pub -encrypt +rm -f /opt/.secrets/pwdfile.txt +chown 54321:54321 /opt/.secrets/pwdfile.enc +chown 54321:54321 /opt/.secrets/key.pem +chown 54321:54321 /opt/.secrets/key.pub +chmod 400 /opt/.secrets/pwdfile.enc +chmod 400 /opt/.secrets/key.pem +chmod 400 /opt/.secrets/key.pub +``` + +This password key is used for the initial Oracle Globally Distributed Database topology setup. After the Oracle Globally Distributed Database topology setup is completed, you must change the topology passwords based on your environment. + +## Create Containers + +Refer to the relevant section depending on whether you want to deploy the Oracle Globally Distributed Database using System-Managed Sharding, or User-Defined Sharding. + +### Deploy Oracle Globally Distributed Database with System-Managed Sharding + +Refer to [Sample Oracle Globally Distributed Database with System-Managed Sharding deployed manually using Docker Containers](./docker-sharded-database-with-system-sharding.md) to deploy a sample Oracle Globally Distributed Database with system-managed sharding using Docker containers. + +### Deploy Oracle Globally Distributed Database with User-Defined Sharding + +Refer to [Sample Oracle Globally Distributed Database with User-Defined Sharding deployed manually using Docker Containers](./docker-sharded-database-with-user-defined-sharding.md) to deploy a sample Oracle Globally Distributed Database with User-Defined sharding using Docker containers. + + +## Support + +Oracle 19c or Oracle 23ai GSM and RDBMS is supported for Oracle Linux 7. + +## License + +To run Oracle Globally Distributed Database, whether inside or outside a Container, you must download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker images are, unless otherwise noted, released under UPL 1.0 license. + +## Copyright + +Copyright (c) 2022, 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/container-files/docker-container-files/docker-sharded-database-with-system-sharding.md b/container-based-sharding-deployment/samples/container-files/docker-container-files/docker-sharded-database-with-system-sharding.md new file mode 100644 index 0000000..d806445 --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/docker-container-files/docker-sharded-database-with-system-sharding.md @@ -0,0 +1,579 @@ +# Deploy Oracle Globally Distributed Database with System-Managed Sharding using Docker Containers + +This page covers the steps to manually deploy a sample Oracle Globally Distributed Database with System-Managed Sharding using Docker Containers. + +- [Setup Details](#setup-details) +- [Prerequisites](#prerequisites) +- [Deploying Catalog Container](#deploying-catalog-container) + - [Create Directory](#create-directory) + - [Create Container](#create-container) +- [Deploying Shard Containers](#deploying-shard-containers) + - [Create Directories](#create-directories) + - [Shard1 Container](#shard1-container) + - [Shard2 Container](#shard2-container) +- [Deploying GSM Container](#deploying-gsm-container) + - [Create Directory for Master GSM Container](#create-directory-for-master-gsm-container) + - [Create Master GSM Container](#create-master-gsm-container) +- [Deploying Standby GSM Container](#deploying-standby-gsm-container) + - [Create Directory for Standby GSM Container](#create-directory-for-standby-gsm-container) + - [Create Standby GSM Container](#create-standby-gsm-container) +- [Scale-out an existing Oracle Globally Distributed Database](#scale-out-an-existing-oracle-globally-distributed-database) + - [Complete the prerequisite steps before creating Docker Container for new shard](#complete-the-prerequisite-steps-before-creating-docker-container-for-new-shard) + - [Create Docker Container for new shard](#create-docker-container-for-new-shard) + - [Add the new shard Database to the existing Oracle Globally Distributed Database](#add-the-new-shard-database-to-the-existing-oracle-globally-distributed-database) + - [Deploy the new shard](#deploy-the-new-shard) +- [Scale-in an existing Oracle Globally Distributed Database](#scale-in-an-existing-oracle-globally-distributed-database) + - [Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database Database](#confirm-the-shard-to-be-deleted-is-present-in-the-list-of-shards-in-the-oracle-globally-distributed-database) + - [Move the chunks out of the shard database which you want to delete](#move-the-chunks-out-of-the-shard-database-which-you-want-to-delete) + - [Delete the shard database from the Oracle Globally Distributed Database](#delete-the-shard-database-from-the-oracle-globally-distributed-database) + - [Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database](#confirm-the-shard-has-been-successfully-deleted-from-the-oracle-globally-distributed-database) + - [Remove the Docker Container](#remove-the-docker-container) +- [Environment Varibles Explained](#environment-variables-explained) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + +## Setup Details + +This setup involves deploying docker containers for: + +* Catalog Database +* Two Shard Database +* Primary GSM +* Standby GSM + +**NOTE:** You can use Oracle 19c or Oracle 21c RDBMS and GSM Docker Images for this sample deployment. + +**NOTE:** In the current Sample Oracle Globally Distributed Database Deployment, we have used Oralce 21c RDBMS and GSM Docker Images. + +## Prerequisites + +Before using this page to create a sample Oracle Globally Distributed Database, please complete the prerequisite steps mentioned in [Oracle Globally Distributed Database Containers on Docker](./README.md#prerequisites) + +Before creating the GSM container, you need to build the catalog and shard containers. Execute the following steps to create containers: + +## Deploying Catalog Container + +The shard catalog is a special-purpose Oracle Database that is a persistent store for SDB configuration data and plays a key role in the automated deployment and centralized management of Oracle Globally Distributed Database. It also hosts the gold schema of the application and the master copies of common reference data (duplicated tables) + +### Create Directory + +You need to create mountpoint on the docker host to save datafiles for Oracle Globally Distributed Database Catalog DB and expose as a volume to catalog container. This volume can be local on a docker host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this sample Oracle Globally Distributed Database, we used `/scratch/oradata/dbfiles/CATALOG` directory and exposed as volume to catalog container. + +```bash +mkdir -p /scratch/oradata/dbfiles/CATALOG +chown -R 54321:54321 /scratch/oradata/dbfiles/CATALOG +``` + +**Notes:** + +* Change the ownership for data volume `/scratch/oradata/dbfiles/CATALOG` exposed to catalog container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Container + +Before creating catalog container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change `/scratch/oradata/dbfiles/CATALOG` based on your enviornment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID enviornment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name catalog oracle/database:21.3.0-ee` with `--name catalog oracle/database:21.3.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/CATALOG` must contain the DB backup and it must not be in zipped format. E.g. `/scratch/oradata/dbfiles/CATALOG/SEEDCDB` where SEEDCDB is the cold backup and contains datafiles and PDB. + +```bash +docker run -d --hostname oshard-catalog-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.102 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=CATCDB \ +-e ORACLE_PDB=CAT1PDB \ +-e OP_TYPE=catalog \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +-v /oradata/dbfiles/CATALOG:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--privileged=false \ +--name catalog oracle/database-ext-sharding:21.3.0-ee +``` + +To check the catalog container/services creation logs, please tail docker logs. It will take 20 minutes to create the catalog container service. + +```bash +docker logs -f catalog +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Catalog database is ready to be used: + +```bash +============================================== + GSM Catalog Setup Completed +============================================== +``` + +## Deploying Shard Containers + +A database shard is a horizontal partition of data in a database or search engine. Each individual partition is referred to as a shard or database shard. You need to create mountpoint on docker host to save datafiles for Oracle Globally Distributed Database and expose as a volume to shard container. This volume can be local on a docker host or exposed from your central storage. It contains a file system such as EXT4. + +For Example: During the setup of this README.md, we used `/scratch/oradata/dbfiles/ORCL1CDB` directory and exposed as volume to shard container `shard1`. + +### Create Directories + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL1CDB +mkdir -p /scratch/oradata/dbfiles/ORCL2CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL1CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL2CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL1CDB` and `/scratch/oradata/dbfiles/ORCL2CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Shard1 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change `/scratch/oradata/dbfiles/ORCL1CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard1 oracle/database:21.3.0-ee` with `--name shard1 oracle/database:21.3.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL1CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL1CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +docker run -d --hostname oshard1-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.103 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL1CDB \ +-e ORACLE_PDB=ORCL1PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +-v /scratch/oradata/dbfiles/ORCL1CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--privileged=false \ +--name shard1 oracle/database-ext-sharding:21.3.0-ee +``` + +To check the shard1 container/services creation logs, please tail docker logs. It will take 20 minutes to create the shard1 container service. + +```bash +docker logs -f shard1 +``` + +### Shard2 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change `/scratch/oradata/dbfiles/ORCL2CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard2 oracle/database:21.3.0-ee` with `--name shard2 oracle/database:21.3.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL2CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL2CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +docker run -d --hostname oshard2-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.104 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL2CDB \ +-e ORACLE_PDB=ORCL2PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +-v /scratch/oradata/dbfiles/ORCL2CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--privileged=false \ +--name shard2 oracle/database-ext-sharding:21.3.0-ee +``` + +**Note**: You can add more shards based on your requirement. + +To check the shard2 container/services creation logs, please tail docker logs. It will take 20 minutes to create the shard2 container service + +```bash +docker logs -f shard2 +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Shard database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +## Deploying GSM Container + +The Global Data Services framework consists of at least one global service manager, a Global Data Services catalog, and the GDS configuration databases. You need to create mountpoint on docker host to save gsm setup related file for Oracle Global Service Manager and expose as a volume to GSM container. This volume can be local on a docker host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used `/scratch/oradata/dbfiles/GSMDATA` directory and exposed as volume to GSM container. + +### Create Directory for Master GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSMDATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSMDATA +``` + +### Create Master GSM Container + +```bash +docker run -d --hostname oshard-gsm1 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.100 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" \ +-e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=primary;group_region=region1" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=primary" \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="True" \ +-e OP_TYPE=gsm \ +-e MASTER_GSM="TRUE" \ +-v /scratch/oradata/dbfiles/GSMDATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--privileged=false \ +--name gsm1 oracle/gsm:21.3.0 +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, PRIMARY_SHARD_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm1 container/services creation logs, please tail docker logs. It will take 2 minutes to create the gsm container service. + +```bash +docker logs -f gsm1 +``` + +## Deploying Standby GSM Container + +You need standby GSM container to serve the connection when master GSM fails. + +### Create Directory for Standby GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSM2DATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSM2DATA +``` + +### Create Standby GSM Container + +```bash +docker run -d --hostname oshard-gsm2 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.101 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region2;director_port=1522" \ +-e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=active_standby;group_region=region2" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" \ +-e CATALOG_SETUP="True" \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="True" \ +-e OP_TYPE=gsm \ +--privileged=false \ +-v /scratch/oradata/dbfiles/GSM2DATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--name gsm2 oracle/gsm:21.3.0 +``` +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm2 container/services creation logs, please tail docker logs. It will take 2 minutes to create the gsm container service. + +```bash +docker logs -f gsm2 +``` + +**IMPORTANT:** The GSM Container Image used in this case is having the Oracle GSM installed. On first startup of the container, a new GSM setup will be created and the following lines highlight when the GSM setup is ready to be used: + +```bash +============================================== + GSM Setup Completed +============================================== +``` + +## Scale-out an existing Oracle Globally Distributed Database + +If you want to Scale-Out an existing Oracle Globally Distributed Database already deployed using the Docker Containers, then you will to complete the steps in below order: + +- Complete the prerequisite steps before creating the Docker Container for the new shard to be added to the Oracle Globally Distributed Database +- Create the Docker Container for the new shard +- Add the new shard Database to the existing Oracle Globally Distributed Database +- Deploy the new shard + +The below example covers the steps to add a new shard (shard3) to an existing Oracle Globally Distributed Database which was deployed earlier in this page with two shards (shard1 and shard2). + +### Complete the prerequisite steps before creating Docker Container for new shard + +Create the required directories for the new shard (shard3 in this case) container just like they were created for the earlier Shards (shard1 and shard2): + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL3CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL3CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL3CDB` and `/scratch/oradata/dbfiles/ORCL3CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Docker Container for new shard + +Before creating new shard (shard3 in this case) container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/ORCL3CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace following `--name shard3 oracle/database:21.3.0-ee` to `--name shard3 oracle/database:21.3.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL3CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL3CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +docker run -d --hostname oshard3-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.105 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL3CDB \ +-e ORACLE_PDB=ORCL3PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +-v /scratch/oradata/dbfiles/ORCL3CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--privileged=false \ +--name shard3 oracle/database-ext-sharding:21.3.0-ee +``` + +To check the shard3 container/services creation logs, please tail docker logs. It will take 20 minutes to create the shard1 container service. + +```bash +docker logs -f shard3 +``` + +**IMPORTANT:** Like the earlier shards (shard1 and shard2), wait for the following lines highlight when the Shard3 database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Add the new shard Database to the existing Oracle Globally Distributed Database + +Use the below command to add the new shard3: +```bash +docker exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --addshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" +``` + +Use the below command to check the status of the newly added shard: +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard +``` + +### Deploy the new shard + +Deploy the newly added shard (shard3): + +```bash +docker exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deployshard=true +``` + +Use the below command to check the status of the newly added shard and the chunks distribution: +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** The chunks redistribution after deploying the new shard may take some time to complete. + +## Scale-in an existing Oracle Globally Distributed Database + +If you want to Scale-in an existing Oracle Globally Distributed Database by removing a particular shard database out of the existing shard databases, then you will to complete the steps in below order: + +- Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database. +- Move the chunks out of the shard database which you want to delete. +- Delete the shard database from the Oracle Globally Distributed Database. +- Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database. + +### Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database + +Use the below commands to check the status of the shard which you want to delete and status of chunks present in this shard: +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Move the chunks out of the shard database which you want to delete + +In the current example, if you want to delete the shard3 database from the Oracle Globally Distributed Database, then you need to use the below command to move the chunks out of shard3 database: + +```bash +docker exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --movechunks="shard_db=ORCL3CDB;shard_pdb=ORCL3PDB" +``` + +**NOTE:** In this case, `ORCL3CDB` and `ORCL3PDB` are the names of CDB and PDB for the shard3 respectively. + +After moving the chunks out, use the below command to confirm there is no chunk present in the shard database which you want to delete: + +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** You will need to wait for some time for all the chunks to move out of the shard database which you want to delete. If the chunks are still moving out, you can rerun the above command to check the status after some time. + + +### Delete the shard database from the Oracle Globally Distributed Database + +Once you have confirmed that no chunk is present in the shard to be deleted in earlier step, you can use the below command to delete that shard(shard3 in this case): + +```bash +docker exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deleteshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" +``` + +**NOTE:** In this case, `oshard3-0`, `ORCL3CDB` and `ORCL3PDB` are the names of host, CDB and PDB for the shard3 respectively. + +### Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + +Once the shard is deleted from the Oracle Globally Distributed Database, use the below commands to check the status of the shards and chunk distribution in the Oracle Globally Distributed Database: + +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Remove the Docker Container + +Once the shard is deleted from the Oracle Globally Distributed Database, you can remove the Docker Container which was deployed earlier for the deleted shard database. + +If the deleted shard was "shard3", to remove its Docker Container, please use the below steps: + +- Stop and remove the Docker Container for shard3: +```bash +docker stop shard3 +docker rm shard3 +``` + +- Remove the directory containing the files for this deleted Docker Container: +```bash +rm -rf /scratch/oradata/dbfiles/ORCL3CDB +``` +## Environment Variables Explained + +**For Catalog and Shard Containers**- + +| Mandatory Parameters | Description | +|---------------------------|-----------------------------------------------------------------------------------------------------------| +| COMMON_OS_PWD_FILE | Specify the encrypted password file to be read inside the container | +| PWD_KEY | Specify password key file to decrypt the encrypted password file and read the password | +| OP_TYPE | Specify the operation type. For Shards it has to be set to catalog or primaryshard/standbyshard | +| DOMAIN | Specify the domain name | +| ORACLE_SID | CDB name | +| ORACLE_PDB | PDB name | + +| Optional Parameters | Description | +|---------------------------|-----------------------------------------------------------------------------------------------------------| +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts that you want to run after setting up the catalog or shard setup | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name which must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed | +| CLONE_DB | Specify value "true" if you want to avoid db creation and clone it from cold backup of existing Oracle DB | +| OLD_ORACLE_SID | Specify the OLD_ORACLE_SID if you are performing db seed clonging using existing cold backup of Oracle DB | +| OLD_ORACLE_PDB | Specify the OLD_ORACLE_PDB if you are performing db seed cloning using existing cold backup of Oracle DB | + + +**For GSM Containers**- + +| Mandatory Parameters | Description | +|---------------------------------|-------------------------------------------------------------------------------------------------------------| +| SHARD_DIRECTOR_PARAMS | Accepts key=value pairs for shard director configuration. | +| | - director_name: Shard director name | +| | - director_region: Shard director region | +| | - director_port: Shard director port | +| SHARD[1-9]_GROUP_PARAMS | Accepts key=value pairs for shard group configuration. | +| | - group_name: Shard group name | +| | - deploy_as: Deploy shard group as primary or active_standby | +| | - group_region: Shard group region name | +| CATALOG_PARAMS | Accepts key=value pairs for catalog configuration. | +| | - catalog_host: Catalog hostname | +| | - catalog_db: Catalog CDB name | +| | - catalog_pdb: Catalog PDB name | +| | - catalog_port: Catalog DB port name | +| | - catalog_name: Catalog name in GSM | +| | - catalog_region: Comma-separated region name for catalog DB deployment | +| SHARD[1-9]_PARAMS | Accepts key=value pairs for shard configuration. | +| | - shard_host: Shard hostname | +| | - shard_db: Shard CDB name | +| | - shard_pdb: Shard PDB name | +| | - shard_port: Shard DB port | +| | - shard_group: Shard group name | +| SERVICE[1-9]_PARAMS | Accepts key=value pairs for service configuration. | +| | - service_name: Service name | +| | - service_role: Service role (e.g., primary or physical_standby) | +| COMMON_OS_PWD_FILE | Specifies the encrypted password file to be read inside the container. | +| PWD_KEY | Specifies the password key file to decrypt the encrypted password file and read the password. | +| OP_TYPE | Specifies the operation type. For GSM, it has to be set to gsm. | +| DOMAIN | Specifies the domain of the container. | +| MASTER_GSM | Set to "TRUE" if you want the GSM to be a master GSM; otherwise, do not set it. | + +| Optional Parameters | Description | +|---------------------------------|-------------------------------------------------------------------------------------------------------------| +| SAMPLE_SCHEMA | Specify a value to "DEPLOY" if you want to deploy a sample app schema in the catalog DB during GSM setup. | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts that you want to run after setting up GSM. | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the filename that must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after GSM setup. | +| BASE_DIR | Specify BASE_DIR if you want to change the base location of the scripts to set up GSM. Default is set to $INSTALL_DIR/startup/scripts. | +| SCRIPT_NAME | Specify the script name which will be executed from BASE_DIR. Default set to main.py. | +| EXECUTOR | Specify the script executor such as /bin/python or /bin/bash. Default set to /bin/python. | +| CATALOG_SETUP | Accepts True. If set, it will only restrict till catalog connection and setup. | +| CATALOG_PARAMS | Accepts key-value pairs for catalog configuration. Refer to the Mandatory Parameters section. | + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + +## License + +To run Oracle Globally Distributed Database, regardless whether inside or outside a Container, ensure to download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/container-files/docker-container-files/docker-sharded-database-with-user-defined-sharding.md b/container-based-sharding-deployment/samples/container-files/docker-container-files/docker-sharded-database-with-user-defined-sharding.md new file mode 100644 index 0000000..3c4fc40 --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/docker-container-files/docker-sharded-database-with-user-defined-sharding.md @@ -0,0 +1,603 @@ +# Deploy Oracle Globally Distributed Database with User-Defined Sharding using Docker Containers + +This page covers the steps to manually deploy a sample Oracle Globally Distributed Database with User-Defined Sharding using Docker Containers. + +- [Setup Details](#setup-details) +- [Prerequisites](#prerequisites) +- [Deploying Catalog Container](#deploying-catalog-container) + - [Create Directory](#create-directory) + - [Create Container](#create-container) +- [Deploying Shard Containers](#deploying-shard-containers) + - [Create Directories](#create-directories) + - [Shard1 Container](#shard1-container) + - [Shard2 Container](#shard2-container) +- [Deploying GSM Container](#deploying-gsm-container) + - [Create Directory for Master GSM Container](#create-directory-for-master-gsm-container) + - [Create Master GSM Container](#create-master-gsm-container) +- [Deploying Standby GSM Container](#deploying-standby-gsm-container) + - [Create Directory for Standby GSM Container](#create-directory-for-standby-gsm-container) + - [Create Standby GSM Container](#create-standby-gsm-container) +- [Scale-out an existing Oracle Globally Distributed Database](#scale-out-an-existing-oracle-globally-distributed-database) + - [Complete the prerequisite steps before creating Docker Container for new shard](#complete-the-prerequisite-steps-before-creating-docker-container-for-new-shard) + - [Create Docker Container for new shard](#create-docker-container-for-new-shard) + - [Add the new shard Database to the existing Oracle Globally Distributed Database](#add-the-new-shard-database-to-the-existing-oracle-globally-distributed-database) + - [Deploy the new shard](#deploy-the-new-shard) + - [Move chunks](#move-chunks) +- [Scale-in an existing Oracle Globally Distributed Database](#scale-in-an-existing-oracle-globally-distributed-database) + - [Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database](#confirm-the-shard-to-be-deleted-is-present-in-the-list-of-shards-in-the-oracle-globally-distributed-database) + - [Move the chunks out of the shard database which you want to delete](#move-the-chunks-out-of-the-shard-database-which-you-want-to-delete) + - [Delete the shard database from the Oracle Globally Distributed Database](#delete-the-shard-database-from-the-oracle-globally-distributed-database) + - [Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database](#confirm-the-shard-has-been-successfully-deleted-from-the-oracle-globally-distributed-database) + - [Remove the Docker Container](#remove-the-docker-container) +- [Environment Varibles Explained](#environment-variables-explained) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + +## Setup Details + +This setup involves deploying docker containers for: + +* Catalog Database +* Two Shard Databases +* Primary GSM +* Standby GSM + +**NOTE:** You can use Oracle 19c or Oracle 21c RDBMS and GSM Docker Images for this sample deployment. + +**NOTE:** In the current Sample Oracle Globally Distributed Database Deployment, we have used Oralce 21c RDBMS and GSM Docker Images. + +## Prerequisites + +Before using this page to create a sample Oracle Globally Distributed Database, please complete the prerequisite steps mentioned in [Oracle Globally Distributed Database Containers on Docker](./README.md#prerequisites) + +Before creating the GSM container, you need to build the catalog and shard containers. Execute the following steps to create containers: + +## Deploying Catalog Container + +The shard catalog is a special-purpose Oracle Database that is a persistent store for SDB configuration data and plays a key role in the automated deployment and centralized management of an Oracle Globally Distributed Database. It also hosts the gold schema of the application and the master copies of common reference data (duplicated tables) + +### Create Directory + +You need to create mountpoint on the docker host to save datafiles for Oracle Sharding Catalog DB and expose as a volume to catalog container. This volume can be local on a docker host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this sample Oracle Globally Distributed Database, we used `/scratch/oradata/dbfiles/CATALOG` directory and exposed as volume to catalog container. + +```bash +mkdir -p /scratch/oradata/dbfiles/CATALOG +chown -R 54321:54321 /scratch/oradata/dbfiles/CATALOG +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/CATALOG` exposed to catalog container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Container + +Before creating catalog container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/CATALOG based on your enviornment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/scratch/oradata` based on ORACLE_SID enviornment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name catalog oracle/database:21.3.0-ee` with `--name catalog oracle/database:21.3.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, /scratch/oradata/dbfiles/CATALOG` must contain the DB backup and it must not be in zipped format. E.g. `/scratch/oradata/dbfiles/CATALOG/SEEDCDB` where SEEDCDB is the cold backup and contains datafiles and PDB. + +```bash +docker run -d --hostname oshard-catalog-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.102 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=CATCDB \ +-e ORACLE_PDB=CAT1PDB \ +-e OP_TYPE=catalog \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +-v /oradata/dbfiles/CATALOG:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--privileged=false \ +--name catalog oracle/database-ext-sharding:21.3.0-ee +``` + +To check the catalog container/services creation logs, please tail docker logs. It will take 20 minutes to create the catalog container service. + +```bash +docker logs -f catalog +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Catalog database is ready to be used: + +``` +============================================== + GSM Catalog Setup Completed +============================================== +``` + +## Deploying Shard Containers + +A database shard is a horizontal partition of data in a database or search engine. Each individual partition is referred to as a shard or database shard. You need to create mountpoint on docker host to save datafiles for Oracle Globally Distributed Database and expose as a volume to shard container. This volume can be local on a docker host or exposed from your central storage. It contains a file system such as EXT4. + +For Example: During the setup of this README.md, we used `/scratch/oradata/dbfiles/ORCL1CDB` directory and exposed as volume to shard container `shard1`. + +### Create Directories + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL1CDB +mkdir -p /scratch/oradata/dbfiles/ORCL2CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL1CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL2CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL1CDB` and `/scratch/oradata/dbfiles/ORCL2CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Shard1 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/ORCL1CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/scratch/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard1 oracle/database:21.3.0-ee` with `--name shard1 oracle/database:21.3.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL1CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL1CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +docker run -d --hostname oshard1-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.103 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL1CDB \ +-e ORACLE_PDB=ORCL1PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +-v /scratch/oradata/dbfiles/ORCL1CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--privileged=false \ +--name shard1 oracle/database-ext-sharding:21.3.0-ee +``` + +To check the shard1 container/services creation logs, please tail docker logs. It will take 20 minutes to create the shard1 container service. + +```bash +docker logs -f shard1 +``` + +### Shard2 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/ORCL2CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/scratch/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard2 oracle/database:21.3.0-ee` with `--name shard2 oracle/database:21.3.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL2CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL2CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +docker run -d --hostname oshard2-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.104 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL2CDB \ +-e ORACLE_PDB=ORCL2PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +-v /scratch/oradata/dbfiles/ORCL2CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--privileged=false \ +--name shard2 oracle/database-ext-sharding:21.3.0-ee +``` + +**Note**: You can add more shards based on your requirement. + +To check the shard2 container/services creation logs, please tail docker logs. It will take 20 minutes to create the shard2 container service + +```bash +docker logs -f shard2 +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Shard database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +## Deploying GSM Container + +The Global Data Services framework consists of at least one global service manager, a Global Data Services catalog, and the GDS configuration databases. You need to create mountpoint on docker host to save gsm setup related file for Oracle Global Service Manager and expose as a volume to GSM container. This volume can be local on a docker host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used /scratch/oradata/dbfiles/GSMDATA directory and exposed as volume to GSM container. + +### Create Directory for Master GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSMDATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSMDATA +``` + +### Create Master GSM Container + +```bash +docker run -d --hostname oshard-gsm1 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.100 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;sharding_type=USER;shard_space=shardspace1,shardspace2" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_space=shardspace1;shard_region=region1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_space=shardspace2;shard_region=region1" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=primary" \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="True" \ +-e OP_TYPE=gsm \ +-e MASTER_GSM="TRUE" \ +-v /scratch/oradata/dbfiles/GSMDATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--privileged=false \ +--name gsm1 oracle/gsm:21.3.0 +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, PRIMARY_SHARD_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm1 container/services creation logs, please tail docker logs. It will take 2 minutes to create the gsm container service. + +```bash +docker logs -f gsm1 +``` + +## Deploying Standby GSM Container + +You need standby GSM container to serve the connection when master GSM fails. + +### Create Directory for Standby GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSM2DATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSM2DATA +``` + +### Create Standby GSM Container + +```bash +docker run -d --hostname oshard-gsm2 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.101 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region2;director_port=1522" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;sharding_type=USER;shard_space=shardspace1,shardspace2" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_space=shardspace1;" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_space=shardspace2;" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" \ +-e CATALOG_SETUP="True" \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="True" \ +-e OP_TYPE=gsm \ +--privileged=false \ +-v /scratch/oradata/dbfiles/GSM2DATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--name gsm2 oracle/gsm:21.3.0 +``` + +**Notes:** + Change environment variables such as DOMAIN, CATALOG_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm2 container/services creation logs, please tail docker logs. It will take 2 minutes to create the gsm container service. + +```bash +docker logs -f gsm2 +``` + +**IMPORTANT:** The GSM Container Image used in this case is having the Oracle GSM installed. On first startup of the container, a new GSM setup will be created and the following lines highlight when the GSM setup is ready to be used: + +```bash +============================================== + GSM Setup Completed +============================================== +``` + +## Scale-out an existing Oracle Globally Distributed Database + +If you want to Scale-Out an existing Oracle Globally Distributed Database already deployed using the Docker Containers, then you will to complete the steps in below order: + +- Complete the prerequisite steps before creating the Docker Container for the new shard to be added to the Oracle Globally Distributed Database +- Create the Docker Container for the new shard +- Add the new shard Database to the existing Oracle Globally Distributed Database +- Deploy the new shard + +The below example covers the steps to add a new shard (shard3) to an existing Oracle Globally Distributed Database which was deployed earlier in this page with two shards (shard1 and shard2). + +### Complete the prerequisite steps before creating Docker Container for new shard + +Create the required directories for the new shard (shard3 in this case) container just like they were created for the earlier Shards (shard1 and shard2): + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL3CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL3CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL3CDB` and `/scratch/oradata/dbfiles/ORCL3CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Docker Container for new shard + +Before creating new shard (shard3 in this case) container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/ORCL3CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/scratch/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard3 oracle/database:21.3.0-ee` with `--name shard3 oracle/database:21.3.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL3CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL3CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +docker run -d --hostname oshard3-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.105 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL3CDB \ +-e ORACLE_PDB=ORCL3PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdfile.enc \ +-e PWD_KEY=key.pem \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +-v /scratch/oradata/dbfiles/ORCL3CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--volume /opt/.secrets:/run/secrets:ro \ +--privileged=false \ +--name shard3 oracle/database-ext-sharding:21.3.0-ee +``` + +To check the shard3 container/services creation logs, please tail docker logs. It will take 20 minutes to create the shard1 container service. + +```bash +docker logs -f shard3 +``` + +**IMPORTANT:** Like the earlier shards (shard1 and shard2), wait for the following lines highlight when the Shard3 database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Add the new shard Database to the existing Oracle Globally Distributed Database + +Use the below command to add the new shard3: +```bash +docker exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --addshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_space=shardspace3;shard_region=region1" +``` + +Use the below command to check the status of the newly added shard: +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard +``` + +### Deploy the new shard + +Deploy the newly added shard (shard3): + +```bash +docker exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deployshard=true +``` + +Use the below command to check the status of the newly added shard and the chunks distribution: +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Move chunks + +In case you want to move some chunks to the newly added Shard from an existing Shard, you can use the below command: + +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK $CHUNK_ID -SOURCE $SOURCE_SHARD -TARGET $TARGET_SHARD +``` + +Example: If you want to move the chunk with chunk id `3` from source shard `ORCL1CDB_ORCL1PDB` to target shard `ORCL3CDB_ORCL3PDB`, then you can use the below command: +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK 3 -SOURCE ORCL1CDB_ORCL1PDB -TARGET ORCL3CDB_ORCL3PDB +``` + +Use the below command to check the status of the chunks distribution: +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +## Scale-in an existing Oracle Globally Distributed Database + +If you want to Scale-in an existing Oracle Globally Distributed Database by removing a particular shard database out of the existing shard databases, then you will to complete the steps in below order: + +- Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database +- Move the chunks out of the shard database which you want to delete +- Delete the shard database from the Oracle Globally Distributed Database +- Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + + +### Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database + +Use the below commands to check the status of the shard which you want to delete and status of chunks present in this shard: +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + + +### Move the chunks out of the shard database which you want to delete + +In the current example, if you want to delete the shard3 database from the Oracle Globally Distributed Database, then you need to use the below command to move the chunks out of shard3 database: + +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK $CHUNK_ID -SOURCE $SOURCE_SHARD -TARGET $TARGET_SHARD +``` + +Example: If you want to move the chunk with chunk id `3` from source shard `ORCL3CDB_ORCL3PDB` to target shard `ORCL1CDB_ORCL1PDB`, then you can use the below command: +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK 3 -SOURCE ORCL3CDB_ORCL3PDB -TARGET ORCL1CDB_ORCL1PDB +``` + +**NOTE:** To move more than 1 chunk, you can specify comma separated chunk ids. + +After moving the chunks out, use the below command to confirm there is no chunk present in the shard database which you want to delete: +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** You will need to wait for some time for all the chunks to move out of the shard database which you want to delete. + + +### Delete the shard database from the Oracle Globally Distributed Database + +Once you have confirmed that no chunk is present in the shard to be deleted in earlier step, you can use the below command to delete that shard(shard3 in this case): + +```bash +docker exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deleteshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_space=shardspace3;shard_region=region1" +``` + +**NOTE:** In this case, `oshard3-0`, `ORCL3CDB` and `ORCL3PDB` are the names of host, CDB and PDB for the shard3 respectively. + +### Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + +Once the shard is deleted from the Oracle Globally Distributed Database, use the below commands to check the status of the shards and chunk distribution in the Oracle Globally Distributed Database: + +```bash +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +docker exec -it gsm1 $(docker exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Remove the Docker Container + +Once the shard is deleted from the Oracle Globally Distributed Database, you can remove the Docker Container which was deployed earlier for the deleted shard database. + +If the deleted shard was `shard3`, to remove its Docker Container, please use the below steps: + +- Stop and remove the Docker Container for shard3: +```bash +docker stop shard3 +docker rm shard3 +``` + +- Remove the directory containing the files for this deleted Docker Container: +```bash +rm -rf /scratch/oradata/dbfiles/ORCL3CDB +``` +## Environment Variables Explained + +**For Catalog and Shard Containers**- + +| Mandatory Parameters | Description | +|---------------------------|-----------------------------------------------------------------------------------------------------------| +| COMMON_OS_PWD_FILE | Specify the encrypted password file to be read inside the container | +| PWD_KEY | Specify password key file to decrypt the encrypted password file and read the password | +| OP_TYPE | Specify the operation type. For Shards it has to be set to catalog or primaryshard/standbyshard | +| DOMAIN | Specify the domain name | +| ORACLE_SID | CDB name | +| ORACLE_PDB | PDB name | + +| Optional Parameters | Description | +|---------------------------|-----------------------------------------------------------------------------------------------------------| +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts that you want to run after setting up the catalog or shard setup | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name which must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed | +| CLONE_DB | Specify value "true" if you want to avoid db creation and clone it from cold backup of existing Oracle DB | +| OLD_ORACLE_SID | Specify the OLD_ORACLE_SID if you are performing db seed clonging using existing cold backup of Oracle DB | +| OLD_ORACLE_PDB | Specify the OLD_ORACLE_PDB if you are performing db seed cloning using existing cold backup of Oracle DB | + + +**For GSM Containers**- + +| Mandatory Parameters | Description | +|---------------------------------|-------------------------------------------------------------------------------------------------------------| +| SHARD_DIRECTOR_PARAMS | Accepts key=value pairs for shard director configuration. | +| | - director_name: Shard director name | +| | - director_region: Shard director region | +| | - director_port: Shard director port | +| SHARD[1-9]_GROUP_PARAMS | Accepts key=value pairs for shard group configuration. | +| | - group_name: Shard group name | +| | - deploy_as: Deploy shard group as primary or active_standby | +| | - group_region: Shard group region name | +| CATALOG_PARAMS | Accepts key=value pairs for catalog configuration. | +| | - catalog_host: Catalog hostname | +| | - catalog_db: Catalog CDB name | +| | - catalog_pdb: Catalog PDB name | +| | - catalog_port: Catalog DB port name | +| | - catalog_name: Catalog name in GSM | +| | - catalog_region: Comma-separated region name for catalog DB deployment | +| SHARD[1-9]_PARAMS | Accepts key=value pairs for shard configuration. | +| | - shard_host: Shard hostname | +| | - shard_db: Shard CDB name | +| | - shard_pdb: Shard PDB name | +| | - shard_port: Shard DB port | +| | - shard_group: Shard group name | +| SERVICE[1-9]_PARAMS | Accepts key=value pairs for service configuration. | +| | - service_name: Service name | +| | - service_role: Service role (e.g., primary or physical_standby) | +| COMMON_OS_PWD_FILE | Specifies the encrypted password file to be read inside the container. | +| PWD_KEY | Specifies the password key file to decrypt the encrypted password file and read the password. | +| OP_TYPE | Specifies the operation type. For GSM, it has to be set to gsm. | +| DOMAIN | Specifies the domain of the container. | +| MASTER_GSM | Set to "TRUE" if you want the GSM to be a master GSM; otherwise, do not set it. | + +| Optional Parameters | Description | +|---------------------------------|-------------------------------------------------------------------------------------------------------------| +| SAMPLE_SCHEMA | Specify a value to "DEPLOY" if you want to deploy a sample app schema in the catalog DB during GSM setup. | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts that you want to run after setting up GSM. | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the filename that must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after GSM setup. | +| BASE_DIR | Specify BASE_DIR if you want to change the base location of the scripts to set up GSM. Default is set to $INSTALL_DIR/startup/scripts. | +| SCRIPT_NAME | Specify the script name which will be executed from BASE_DIR. Default set to main.py. | +| EXECUTOR | Specify the script executor such as /bin/python or /bin/bash. Default set to /bin/python. | +| CATALOG_SETUP | Accepts True. If set, it will only restrict till catalog connection and setup. | +| CATALOG_PARAMS | Accepts key-value pairs for catalog configuration. Refer to the Mandatory Parameters section. | + + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + +## License + +To run Oracle Globally Distributed Database, regardless whether inside or outside a Container, ensure to download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/container-files/podman-container-files-free/README.md b/container-based-sharding-deployment/samples/container-files/podman-container-files-free/README.md new file mode 100644 index 0000000..26085cf --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/podman-container-files-free/README.md @@ -0,0 +1,188 @@ +# Oracle Globally Distributed Database Containers using Oracle Database FREE Images on Podman + +In this installation guide, we deploy Oracle Globally Distributed Database Containers using Oracle Database FREE Images on Podman. This page provides detailed steps for various scenarios of Oracle Globally Distributed Database deployments using Oracle Database FREE Images using Podman Containers. +- [Oracle Globally Distributed Database Containers using Oracle Database FREE Images on Podman](#oracle-globally-distributed-database-containers-using-oracle-database-free-images-on-podman) + - [Prerequisites](#prerequisites) + - [Network Management](#network-management) + - [Macvlan Network](#macvlan-network) + - [Ipvlan Network](#ipvlan-network) + - [Bridge Network](#bridge-network) + - [Setup Hostfile](#setup-hostfile) + - [Password Management](#password-management) + - [SELinux Configuration on Podman Host](#selinux-configuration-on-podman-host) + - [Oracle Database FREE Images](#oracle-database-free-images) + - [Deploy Oracle Globally Distributed Database Containers using Oracle Database FREE Images](#deploy-oracle-globally-distributed-database-containers-using-oracle-database-free-images) + - [Deploy Oracle Globally Distributed Database with System-Managed Sharding using Oracle Database FREE Images](#deploy-oracle-globally-distributed-database-with-system-managed-sharding-using-oracle-database-free-images) + - [Deploy Oracle Globally Distributed Database with System-Managed Sharding with RAFT Replication enabled using Oracle Database FREE Images](#deploy-oracle-globally-distributed-database-with-system-managed-sharding-with-raft-replication-enabled-using-oracle-database-free-images) + - [Deploy Oracle Globally Distributed Database with User-Defined Sharding using Oracle Database FREE Images](#deploy-oracle-globally-distributed-database-with-user-defined-sharding-using-oracle-database-free-images) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + + +## Prerequisites + +You must complete all of the prerequisites before deploying an Oracle Globally Distributed Database using Podman Containers. These prerequisites include creating the Docker network, creating the encrypted file with secrets, and other steps required before deployment. + + +### Network Management + +Before creating a container, create the Podman network by creating the Podman network bridge based on your environment. If you are using the bridge name with the network subnet mentioned in this README.md, then you can use the same IPs mentioned in [Deploy Oracle Globally Distributed Database Containers using Oracle Database FREE Images](#create-containers) section. + +#### Macvlan Network + +To create a podman network with `macvlan` driver, run the following command: + +```bash +podman network create -d macvlan --subnet=10.0.20.0/24 --gateway=10.0.20.1 -o parent=ens5 shard_pub1_nw +``` + +#### Ipvlan Network + +To create a podman network with `ipvlan` driver, run the following command: + +```bash +podman network create -d ipvlan --subnet=10.0.20.0/24 --gateway=10.0.20.1 -o parent=ens5 shard_pub1_nw +``` + +If you are planning to create a test environment within a single machine, then you can use a Podman bridge. However, these IPs will not be reachable on the user network. + +#### Bridge Network + +To create a podman network with `bridge` driver, run the following command: + +```bash +podman network create --driver=bridge --subnet=10.0.20.0/24 shard_pub1_nw +``` + +**Note:** You can change subnet and choose one of the above mentioned podman network bridges based on your environment. + +### Setup Hostfile + +**Note:** You can skip this step of creating a Hostfile when you are using a DNS for the IP resolution. + +All containers will share a host file for name resolution. The shared hostfile must be available to all containers. Create the empty shared host file (if it doesn't exist) at `/opt/containers/shard_host_file`. + +For example: + +```bash +mkdir /opt/containers +rm -rf /opt/containers/shard_host_file && touch /opt/containers/shard_host_file +``` + +Because Oracle Database Containers do not have root access to modify the `/etc/hosts` file, add the following host entries in `/opt/containers/shard_host_file`. This file must be prepopulated. You can change these entries based on your environment and network setup. + +```text +127.0.0.1 localhost.localdomain localhost +10.0.20.100 oshard-gsm1.example.com oshard-gsm1 +10.0.20.101 oshard-gsm2.example.com oshard-gsm2 +10.0.20.102 oshard-catalog-0.example.com oshard-catalog-0 +10.0.20.103 oshard1-0.example.com oshard1-0 +10.0.20.104 oshard2-0.example.com oshard2-0 +10.0.20.105 oshard3-0.example.com oshard3-0 +10.0.20.106 oshard4-0.example.com oshard4-0 +``` + +### Password Management + +* Specify the secret volume for resetting database user passwords during catalog and shard setup. The secret volume can be a shared volume among all the containers + + ```bash + mkdir /opt/.secrets/ + cd /opt/.secrets + openssl genrsa -out key.pem + openssl rsa -in key.pem -out key.pub -pubout + ``` + +* Edit the `/opt/.secrets/pwdfile.txt` and seed the password. It will be a common password for all the database users. Execute following command: + + ```bash + vi /opt/.secrets/pwdfile.txt + ``` + **Note**: Enter your secure password in the above file and save the file. + +* After seeding password and saving the `/opt/.secrets/pwdfile.txt` file, run the following commands: + ```bash + openssl pkeyutl -in /opt/.secrets/pwdfile.txt -out /opt/.secrets/pwdfile.enc -pubin -inkey /opt/.secrets/key.pub -encrypt + rm -rf /opt/.secrets/pwdfile.txt + ``` + Oracle recommends using Podman secrets inside the containers. Run the following commands to create the Podman secrets: + + ```bash + podman secret create pwdsecret /opt/.secrets/pwdfile.enc + podman secret create keysecret /opt/.secrets/key.pem + + podman secret ls + ID NAME DRIVER CREATED UPDATED + 547eed65c01d525bc2b4cebd9 keysecret file 8 seconds ago 8 seconds ago + 8ad6e8e519c26e9234dbcf60a pwdsecret file 8 seconds ago 8 seconds ago + ``` + +**Note:** This password and key secrets are used for the initial Oracle Globally Distributed Database topology setup. After the Oracle Globally Distributed Database topology setup is complete, you must change the topology passwords based on your enviornment. + +## SELinux Configuration on Podman Host +To run Podman containers in an environment with Security-Enhanced Linux (SELinux) enabled, you must configure an SELinux policy for the containers. To check if your SELinux is enabled or not, run the `getenforce` command. +With SELinux, you must set a policy to implement permissions for your containers. If you do not configure a policy module for your containers, then they can end up restarting indefinitely or generate other permission errors. You must add all Podman host nodes for your cluster to the policy module `shard-podman`, by installing the necessary packages and creating a type enforcement file (designated by the `.te` suffix) to build the policy, and load the policy into the system. + +In the following example, the Podman host `podman-host` is configured in the SELinux policy module `shard-podman`: + +Copy [shard-podman.te](../../../containerfiles/shard-podman.te) to `/var/opt` folder in your host and then run the following commands- +```bash +cd /var/opt +make -f /usr/share/selinux/devel/Makefile shard-podman.pp +semodule -i shard-podman.pp +semodule -l | grep shard-pod +``` + +## Oracle Database FREE Images + +While using Oracle Database FREE Images, be aware of the following restrictions, defaults, and options: + +- There is a limit of 2 CPUs for foreground processes, 2 GB of RAM and 12 GB of user data on disk. +- The Total number of chunks for FREE Database defaults to 12 if `CATALOG_CHUNKS` value is not specified. This default value is determined with consideration of the 12 GB limit of user data on disk for Oracle Database FREE. +- Using `INIT_SGA_SIZE` and `INIT_PGA_SIZE` to control the SGA and PGA allocation at the database level is not supported. +- Provisioning the Oracle Globally Distributed Database using Cloning from Database Gold Image is NOT supported with Oracle Database Free Image. +- `ORACLE_SID` must be `FREE` +- The PDB specified using parameter `ORACLE_PDB` that is created with the Database deployment in a container must be `FREEPDB1` +- Additional PDBs can be specified using the parameter `ORACLE_FREE_PDB` +- You can specify a database unique name that is different from `ORACLE_SID` (which must be `FREE`) by using the parameter `DB_UNIQUE_NAME` + + +## Deploy Oracle Globally Distributed Database Containers using Oracle Database FREE Images + +Refer to the relevant section depending on whether you want to deploy the Oracle Globally Distributed Database using System-Managed Sharding, System-Managed Sharding with RAFT Replication enabled, or User-Defined Sharding. + +### Deploy Oracle Globally Distributed Database with System-Managed Sharding using Oracle Database FREE Images + +Refer to [Sample Oracle Globally Distributed Database with System-Managed Sharding deployed manually using Podman Containers and Oracle Database FREE Images](./podman-sharded-database-free-with-system-sharding.md) to deploy a sample Oracle Globally Distributed Database with System-Managed sharding using podman containers and Oracle Database FREE Images. + + +### Deploy Oracle Globally Distributed Database with System-Managed Sharding with RAFT Replication Enabled using Oracle Database FREE Images + +Refer to [Sample Oracle Globally Distributed Database with System-Managed Sharding with RAFT Replication enabled deployed manually using Podman Containers and Oracle Database FREE Images](./podman-sharded-database-free-with-system-sharding-with-snr-raft-enabled.md) to deploy a sample Oracle Globally Distributed Database with System-Managed sharding with RAFT Replication enabled using Podman containers and Oracle Database FREE Images. + +**NOTE:** The RAFT Replication Feature is available only for the Oracle Database 23ai RDBMS and the Oracle 23ai GSM version. + +### Deploy Oracle Globally Distributed Database with User-Defined Sharding using Oracle Database FREE Images + +Refer to [Sample Oracle Globally Distributed Database with User-Defined Sharding deployed manually using Podman Containers and Oracle Database FREE Images](./podman-sharded-database-free-with-user-defined-sharding.md) to deploy a sample Oracle Globally Distributed Database with User-Defined sharding using Podman containers and Oracle Database FREE Images. + + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and later releases. + + +## License + +To run Oracle Globally Distributed Database, whether inside or outside a Container, you must download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-system-sharding-with-snr-raft-enabled.md b/container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-system-sharding-with-snr-raft-enabled.md new file mode 100644 index 0000000..6f32cd8 --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-system-sharding-with-snr-raft-enabled.md @@ -0,0 +1,628 @@ +# Deploy Oracle Globally Distributed Database with System-Managed Sharding with RAFT Replication Enabled using Podman Containers and Oracle Database FREE Images + +This page covers the steps to manually deploy a sample Oracle Globally Distributed Database with System-Managed Sharding with RAFT Replication Enabled using Podman Containers and Oracle Database Free Images. + +- [Setup Details](#setup-details) +- [Prerequisites](#prerequisites) +- [Deploying Catalog Container](#deploying-catalog-container) + - [Create Directory](#create-directory) + - [Create Container](#create-container) +- [Deploying Shard Containers](#deploying-shard-containers) + - [Create Directories](#create-directories) + - [Shard1 Container](#shard1-container) + - [Shard2 Container](#shard2-container) + - [Shard3 Container](#shard3-container) +- [Deploying GSM Container](#deploying-gsm-container) + - [Create Directory for Master GSM Container](#create-directory-for-master-gsm-container) + - [Master GSM Container](#create-master-gsm-container) +- [Deploying Standby GSM Container](#deploying-standby-gsm-container) + - [Create Directory for Standby GSM Container](#create-directory-for-standby-gsm-container) + - [Standby GSM Container](#create-standby-gsm-container) +- [Scale-out an existing Oracle Globally Distributed Database](#scale-out-an-existing-oracle-globally-distributed-database) + - [Complete the prerequisite steps before creating Podman Container for new shard](#complete-the-prerequisite-steps-before-creating-podman-container-for-new-shard) + - [Create Podman Container for new shard](#create-podman-container-for-new-shard) + - [Add the new shard Database to the existing Oracle Globally Distributed Database](#add-the-new-shard-database-to-the-existing-oracle-globally-distributed-database) + - [Deploy the new shard](#deploy-the-new-shard) +- [Scale-in an existing Oracle Globally Distributed Database](#scale-in-an-existing-oracle-globally-distributed-database) + - [Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database](#confirm-the-shard-to-be-deleted-is-present-in-the-list-of-shards-in-the-oracle-globally-distributed-database) + - [Delete the shard database from the Oracle Globally Distributed Database](#delete-the-shard-database-from-the-oracle-globally-distributed-database) + - [Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database](#confirm-the-shard-has-been-successfully-deleted-from-the-oracle-globally-distributed-database) + - [Remove the Podman Container](#remove-the-podman-container) +- [Environment Variables Explained](#environment-variables-explained) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + +## Setup Details + +This setup involves deploying podman containers for: + +* Catalog Database +* Three Shard Databases +* Primary GSM +* Standby GSM + +**NOTE:** To use RAFT Replication feature, you need to deploy Oracle Globally Distributed Database with atleast three shards. + +**NOTE:** In the current Sample Oracle Globally Distributed Database Deployment, we have used Oracle 23ai FREE Database and GSM Podman Images. + +## Prerequisites + +Before using this page to create a sample Oracle Globally Distributed Database, please complete the prerequisite steps mentioned in [Oracle Globally Distributed Database Containers using Oracle Database FREE Images on Podman](./README.md#prerequisites) + +Refer to the page [Oracle Database Free](https://www.oracle.com/database/free/get-started/) for the details of the Oracle Database FREE Images for RDBMS and GSM. + +Before creating the GSM container, you need to build the catalog and shard containers. Execute the following steps to create containers for the deployment: + +## Deploying Catalog Container + +The shard catalog is a special-purpose Oracle Database that is a persistent store for SDB configuration data and plays a key role in the automated deployment and centralized management of a Oracle Globally Distributed Database. It also hosts the gold schema of the application and the master copies of common reference data (duplicated tables) + +### Create Directory + +You need to create mountpoint on the podman host to save datafiles for Oracle Sharding Catalog DB and expose as a volume to catalog container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this sample Oracle Globally Distributed Database, we used `/scratch/oradata/dbfiles/CATALOG` directory and exposed as volume to catalog container. + +```bash +mkdir -p /scratch/oradata/dbfiles/CATALOG +chown -R 54321:54321 /scratch/oradata/dbfiles/CATALOG +``` + +* If SELinux is enabled on podman host, then execute following- + +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/CATALOG +restorecon -v /scratch/oradata/dbfiles/CATALOG +semanage fcontext -a -t container_file_t /opt/containers/shard_host_file +restorecon -v /opt/containers/shard_host_file +``` + +**Notes:** + +* Change the ownership for data volume `/scratch/oradata/dbfiles/CATALOG` exposed to catalog container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Container + +Before creating catalog container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/CATALOG` based on your enviornment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID enviornment variable. + +```bash +podman run -d --hostname oshard-catalog-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.102 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=CAT1PDB \ +-e DB_UNIQUE_NAME=CATCDB \ +-e OP_TYPE=catalog \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/CATALOG:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name catalog container-registry.oracle.com/database/free:latest +``` + +To check the catalog container/services creation logs, please tail podman logs. It will take 20 minutes to create the catalog container service. + +```bash +podman logs -f catalog +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database FREE binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Catalog database is ready to be used: + +```bash +============================================== + GSM Catalog Setup Completed +============================================== +``` + +## Deploying Shard Containers + +A database shard is a horizontal partition of data in a database or search engine. Each individual partition is referred to as a shard or database shard. You need to create mountpoint on podman host to save datafiles for Oracle Globally Distributed Database and expose as a volume to shard container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used `/scratch/oradata/dbfiles/ORCL1CDB` directory and exposed as volume to shard container. + +### Create Directories + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL1CDB +mkdir -p /scratch/oradata/dbfiles/ORCL2CDB +mkdir -p /scratch/oradata/dbfiles/ORCL3CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL1CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL2CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL3CDB +``` + +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL1CDB +restorecon -v /scratch/oradata/dbfiles/ORCL1CDB +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL2CDB +restorecon -v /scratch/oradata/dbfiles/ORCL2CDB +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL3CDB +restorecon -v /scratch/oradata/dbfiles/ORCL3CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL1CDB`, `/scratch/oradata/dbfiles/ORCL2CDB` and `/scratch/oradata/dbfiles/ORCL3CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instace Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Shard1 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change /scratch/oradata/dbfiles/ORCL1CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. + +```bash +podman run -d --hostname oshard1-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.103 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=ORCL1PDB \ +-e DB_UNIQUE_NAME=ORCL1CDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL1CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard1 container-registry.oracle.com/database/free:latest +``` + +To check the shard1 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard1 container service. + +```bash +podman logs -f shard1 +``` + +### Shard2 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/ORCL2CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. + +```bash +podman run -d --hostname oshard2-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.104 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=ORCL2PDB \ +-e DB_UNIQUE_NAME=ORCL2CDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL2CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard2 container-registry.oracle.com/database/free:latest +``` + +To check the shard2 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard2 container service + +```bash +podman logs -f shard2 +``` + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Shard3 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/ORCL3CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. + +```bash +podman run -d --hostname oshard3-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.105 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=ORCL3PDB \ +-e DB_UNIQUE_NAME=ORCL3CDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL3CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard3 container-registry.oracle.com/database/free:latest +``` + +To check the shard3 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard3 container service + +```bash +podman logs -f shard3 +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database FREE binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Shard database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +## Deploying GSM Container + +The Global Data Services framework consists of at least one global service manager, a Global Data Services catalog, and the GDS configuration databases. You need to create mountpoint on podman host to save gsm setup related file for Oracle Global Service Manager and expose as a volume to GSM container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used `/scratch/oradata/dbfiles/GSMDATA` directory and exposed as volume to GSM container. + +### Create Directory for Master GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSMDATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSMDATA +``` + +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSMDATA +restorecon -v /scratch/oradata/dbfiles/GSMDATA +``` + +### Create Master GSM Container + +```bash +podman run -d --hostname oshard-gsm1 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.100 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" \ +-e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=primary;group_region=region1" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=12;repl_type=Native" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD3_PARAMS="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=primary" \ +-e SHARD_SETUP="true" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e OP_TYPE=gsm \ +-e MASTER_GSM="TRUE" \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/GSMDATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name gsm1 container-registry.oracle.com/database/gsm:latest +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, PRIMARY_SHARD_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm1 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm1 +``` + +## Deploying Standby GSM Container + +You need standby GSM container to serve the connection when master GSM fails. + +### Create Directory for Standby GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSM2DATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSM2DATA +``` + +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSM2DATA +restorecon -v /scratch/oradata/dbfiles/GSM2DATA +``` + +### Create Standby GSM Container + +```bash +podman run -d --hostname oshard-gsm2 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.101 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region2;director_port=1522" \ +-e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=standby;group_region=region2" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=12;repl_type=Native" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD3_PARAMS="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" \ +-e CATALOG_SETUP="True" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e OP_TYPE=gsm \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/GSM2DATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name gsm2 container-registry.oracle.com/database/gsm:latest +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm2 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm2 +``` + +**IMPORTANT:** The GSM Container Image used in this case is having the Oracle GSM installed. On first startup of the container, a new GSM setup will be created and the following lines highlight when the GSM setup is ready to be used: + +```bash +============================================== + GSM Setup Completed +============================================== +``` + +## Scale-out an existing Oracle Globally Distributed Database + +If you want to Scale-Out an existing Oracle Globally Distributed Database already deployed using the Podman Containers, then you will to complete the steps in below order: + +- Complete the prerequisite steps before creating the Podman Container for the new shard to be added to the Oracle Globally Distributed Database +- Create the Podman Container for the new shard +- Add the new shard Database to the existing Oracle Globally Distributed Database +- Deploy the new shard + +The below example covers the steps to add a new shard (shard4) to an existing Oracle Globally Distributed Database which was deployed earlier in this page with three shards (shard1, shard2 and shard3) with RAFT Replication enabled. + +### Complete the prerequisite steps before creating Podman Container for new shard + +Create the required directories for the new shard (shard4 in this case) container just like they were created for the earlier shards (shard1, shard2 and shard3): + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL4CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL4CDB +``` + +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL4CDB +restorecon -v /scratch/oradata/dbfiles/ORCL4CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL4CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instace Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Podman Container for new shard + +Before creating new shard (shard4 in this case) container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change /scratch/oradata/dbfiles/ORCL4CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. + +```bash +podman run -d --hostname oshard4-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.106 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=ORCL4PDB \ +-e DB_UNIQUE_NAME=ORCL4CDB \ +-e OP_TYPE=primaryshard \ +-e SHARD_SETUP="true" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL4CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard4 container-registry.oracle.com/database/free:latest +``` + +To check the shard4 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard4 container service. + +```bash +podman logs -f shard4 +``` + +**IMPORTANT:** Like the earlier shards (shard1, shard2 and shard3), wait for the following lines highlight when the Shard3 database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Add the new shard Database to the existing Oracle Globally Distributed Database + +Use the below command to add the new shard4: +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --addshard="shard_host=oshard4-0;shard_db=ORCL4CDB;shard_pdb=ORCL4PDB;shard_port=1521;shard_group=shardgroup1" +``` + +Use the below command to check the status of the newly added shard: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard +``` + +### Deploy the new shard + +Deploy the newly added shard (shard3): + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deployshard=true +``` + +Use the below command to check the status of the newly added shard and the chunks distribution: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** The chunks redistribution after deploying the new shard may take some time to complete. + +## Scale-in an existing Oracle Globally Distributed Database + +If you want to Scale-in an existing Oracle Globally Distributed Database by removing a particular shard database out of the existing shard databases, then you will need to complete the steps in below order: + +- Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database. +- Delete the shard database from the Oracle Globally Distributed Database. You will not need to manually move out chunks in this case. +- Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database. + + +### Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database + +Use the below commands to check the status of the shard which you want to delete and status of chunks present in this shard: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Delete the shard database from the Oracle Globally Distributed Database + +Once you have confirmed that no chunk is present in the shard to be deleted in earlier step, you can use the below command to delete that shard(shard4 in this case): + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deleteshard="shard_host=oshard4-0;shard_db=ORCL4CDB;shard_pdb=ORCL4PDB;shard_port=1521;shard_group=shardgroup1" +``` + +**NOTE:** In this case, `oshard4-0`, `ORCL4CDB` and `ORCL4PDB` are the names of host, CDB and PDB for the shard4 respectively. + +**NOTE:** You will need to wait for some time for all the chunks to move out of the shard database which you want to delete. + +### Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + +Once the shard is deleted from the Oracle Globally Distributed Database, use the below commands to check the status of the shards and chunk distribution in the Oracle Globally Distributed Database: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Remove the Podman Container + +Once the shard is deleted from the Oracle Globally Distributed Database, you can remove the Podman Container which was deployed earlier for the deleted shard database. + +If the deleted shard was "shard4", to remove its Podman Container, please use the below steps: + +- Stop and remove the Docker Container for shard4: +```bash +podman stop shard4 +podman rm shard4 +``` + +- Remove the directory containing the files for this deleted Podman Container: +```bash +rm -rf /scratch/oradata/dbfiles/ORCL4CDB +``` + +## Environment Variables Explained + +**For catalog, shard containers-** +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| COMMON_OS_PWD_FILE | Specify the podman secret for the password file to be read inside the container | Mandatory | +| PWD_KEY | Specify the podman secret for the password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For shards, it has to be set to primaryshard or standbyshard | Mandatory | +| DOMAIN | Specify the domain name | Mandatory | +| ORACLE_SID | CDB name which has to be "FREE" for Oracle Database FREE | Mandatory | +| ORACLE_PDB | PDB name which has to be "FREEPDB1" for Oracle Database FREE | Mandatory | +| ORACLE_FREE_PDB | PDB name which you want to create for the setup | Mandatory | +| DB_UNIQUE_NAME | DB_UNIQUE_NAME name which you want to set | Mandatory | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts which you want to run after setting up shard setup. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name that must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after shard db setup. | Optional | +| CLONE_DB | Specify value "true" if you want to avoid db creation and clone it from cold backup of existing Oracle DB. This DB must not have shard setup. Shard script will look for the backup at /opt/oracle/oradata. | Optional | +| OLD_ORACLE_SID | Specify the OLD_ORACLE_SID if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | +| OLD_ORACLE_PDB | Specify the OLD_ORACLE_PDB if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | + + +**For GSM Containers-** +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| SHARD_DIRECTOR_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=director_name, value=shard director name; key=director_region, value=shard director region; key=director_port, value=shard director port | Mandatory | +| SHARD[1-9]_GROUP_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=group_name, value=shard group name; key=deploy_as, value=deploy shard group as primary or standby or active_standby; key=group_region, value=shard group region name | Mandatory | +| CATALOG_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=catalog_host, value=catalog hostname; key=catalog_db, value=catalog cdb name; key=catalog_pdb, value=catalog pdb name; key=catalog_port, value=catalog db port name; key=catalog_name, value=catalog name in GSM; key=catalog_region, value=specify comma separated region name for catalog db deployment; key=catalog_chunks, value=number of unique chunks; key=repl_type, value=the replication type | Mandatory | +| SHARD[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=shard_host, value=shard hostname; key=shard_db, value=shard cdb name; key=shard_pdb, value=shard pdb name; key=shard_port, value=shard db port; key=shard_group, value=shard group name | Mandatory | +| SERVICE[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=service_name, value=service name; key=service_role, value=service role e.g. primary or physical_standby | Mandatory | +| COMMON_OS_PWD_FILE | Specify the encrypted password file to be read inside container | Mandatory | +| PWD_KEY | Specify password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For GSM it has to be set to gsm. | Mandatory | +| DOMAIN | Domain of the container. | Mandatory | +| MASTER_GSM | Set value to "TRUE" if you want the GSM to be a master GSM. Otherwise, do not set it. | Mandatory | +| CATALOG_SETUP | Accept True. If set then, it will only restrict till catalog connection and setup. | Mandatory | +| SAMPLE_SCHEMA | Specify a value to "DEPLOY" if you want to deploy sample app schema in catalog DB during GSM setup. | Optional | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts that you want to run after setting up GSM. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name which must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after GSM setup. | Optional | +| BASE_DIR | Specify BASE_DIR if you want to change the base location of the scripts to setup GSM. | Optional | +| SCRIPT_NAME | Specify the script name which will be executed from BASE_DIR. Default set to main.py. | Optional | +| EXECUTOR | Specify the script executor such as /bin/python or /bin/bash. Default set to /bin/python. | Optional | + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + +## License + +To run Oracle Globally Distributed Database, regardless whether inside or outside a Container, ensure to download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-system-sharding.md b/container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-system-sharding.md new file mode 100644 index 0000000..5c89357 --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-system-sharding.md @@ -0,0 +1,605 @@ +# Deploy Oracle Globally Distributed Database with System-Managed Sharding using Podman Containers and Oracle Database FREE Images + +This page covers the steps to manually deploy a sample Oracle Globally Distributed Database with System-Managed Sharding using Podman Containers and Oracle Database FREE Images. + +- [Setup Details](#setup-details) +- [Prerequisites](#prerequisites) +- [Deploying Catalog Container](#deploying-catalog-container) + - [Create Directory](#create-directory) + - [Create Container](#create-container) +- [Deploying Shard Containers](#deploying-shard-containers) + - [Create Directories](#create-directories) + - [Shard1 Container](#shard1-container) + - [Shard2 Container](#shard2-container) +- [Deploying GSM Container](#deploying-gsm-container) + - [Create Directory for Master GSM Container](#create-directory-for-master-gsm-container) + - [Create Master GSM Container](#master-gsm-container) +- [Deploying Standby GSM Container](#deploying-standby-gsm-container) + - [Create Directory for Standby GSM Container](#create-directory-for-standby-gsm-container) + - [Create Standby GSM Container](#create-standby-gsm-container) +- [Scale-out an existing Oracle Globally Distributed Database](#scale-out-an-existing-oracle-globally-distributed-database) + - [Complete the prerequisite steps before creating Podman Container for new shard](#complete-the-prerequisite-steps-before-creating-podman-container-for-new-shard) + - [Create Podman Container for new shard](#create-podman-container-for-new-shard) + - [Add the new shard Database to the existing Oracle Globally Distributed Database](#add-the-new-shard-database-to-the-existing-oracle-globally-distributed-database) + - [Deploy the new shard](#deploy-the-new-shard) +- [Scale-in an existing Oracle Globally Distributed Database](#scale-in-an-existing-oracle-globally-distributed-database) + - [Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database](#confirm-the-shard-to-be-deleted-is-present-in-the-list-of-shards-in-the-oracle-globally-distributed-database) + - [Move the chunks out of the shard database which you want to delete](#move-the-chunks-out-of-the-shard-database-which-you-want-to-delete) + - [Delete the shard database from the Oracle Globally Distributed Database](#delete-the-shard-database-from-the-oracle-globally-distributed-database) + - [Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database](#confirm-the-shard-has-been-successfully-deleted-from-the-oracle-globally-distributed-database) + - [Remove the Podman Container](#remove-the-podman-container) +- [Environment Variables Explained](#environment-variables-explained) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + +## Setup Details + +This setup initially involves deploying podman containers for: + +* Catalog Database +* Two Shard Databases +* Primary GSM +* Standby GSM + +**NOTE:** In the current Sample Oracle Globally Distributed Database Deployment, we have used Oracle 23ai FREE Database and GSM Podman Images. + +## Prerequisites + +Before using this page to create a sample Oracle Globally Distributed Database, please complete the prerequisite steps mentioned in [Oracle Globally Distributed Database Containers using Oracle Database FREE Images on Podman](./README.md#prerequisites) + +Refer to the page [Oracle Database Free](https://www.oracle.com/database/free/get-started/) for the details of the Oracle Database FREE Images for RDBMS and GSM. + +Before creating the GSM container, you need to build the catalog and shard containers. Execute the following steps to create containers for the deployment: + +## Deploying Catalog Container + +The shard catalog is a special-purpose Oracle Database that is a persistent store for SDB configuration data and plays a key role in the automated deployment and centralized management of an Oracle Globally Distributed Database. It also hosts the gold schema of the application and the master copies of common reference data (duplicated tables) + +### Create Directory + +You need to create mountpoint on the podman host to save datafiles for Oracle Sharding Catalog DB and expose as a volume to catalog container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this sample Oracle Globally Distributed Database, we used `/scratch/oradata/dbfiles/CATALOG` directory and exposed as volume to catalog container. + +```bash +mkdir -p /scratch/oradata/dbfiles/CATALOG +chown -R 54321:54321 /scratch/oradata/dbfiles/CATALOG +``` + +**Notes:** + +* Change the ownership for data volume `/scratch/oradata/dbfiles/CATALOG` exposed to catalog container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed, then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Container + +Before creating catalog container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/CATALOG` based on your enviornment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID enviornment variable. + +* If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/CATALOG +restorecon -v /scratch/oradata/dbfiles/CATALOG +semanage fcontext -a -t container_file_t /opt/containers/shard_host_file +restorecon -v /opt/containers/shard_host_file +``` + +```bash +podman run -d --hostname oshard-catalog-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.102 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=CAT1PDB \ +-e DB_UNIQUE_NAME=CATCDB \ +-e OP_TYPE=catalog \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/CATALOG:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name catalog container-registry.oracle.com/database/free:latest +``` + +To check the catalog container/services creation logs, please tail podman logs. It will take 20 minutes to create the catalog container service. + +```bash +podman logs -f catalog +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database FREE binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Catalog database is ready to be used: + +```bash +============================================== + GSM Catalog Setup Completed +============================================== +``` + +## Deploying Shard Containers + +A database shard is a horizontal partition of data in a database or search engine. Each individual partition is referred to as a shard or database shard. You need to create mountpoint on podman host to save datafiles for Oracle Globally Distributed Database and expose as a volume to shard container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used `/scratch/oradata/dbfiles/ORCL1CDB` directory and exposed as volume to shard container. + +### Create Directories + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL1CDB +mkdir -p /scratch/oradata/dbfiles/ORCL2CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL1CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL2CDB +``` + +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL1CDB +restorecon -v /scratch/oradata/dbfiles/ORCL1CDB +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL2CDB +restorecon -v /scratch/oradata/dbfiles/ORCL2CDB +``` + +**Notes:** + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL1CDB` and `/scratch/oradata/dbfiles/ORCL2CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/main/OracleDatabase/SingleInstance). + +### Shard1 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/ORCL1CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. + +```bash +podman run -d --hostname oshard1-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.103 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=ORCL1PDB \ +-e DB_UNIQUE_NAME=ORCL1CDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL1CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard1 container-registry.oracle.com/database/free:latest +``` + +To check the shard1 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard1 container service. + +```bash +podman logs -f shard1 +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Shard2 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/ORCL2CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. + +```bash +podman run -d --hostname oshard2-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.104 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=ORCL2PDB \ +-e DB_UNIQUE_NAME=ORCL2CDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL2CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard2 container-registry.oracle.com/database/free:latest +``` + +**Note**: You can add more shards based on your requirement. + +To check the shard2 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard2 container service + +```bash +podman logs -f shard2 +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database FREE binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Shard database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +## Deploying GSM Container + +The Global Data Services framework consists of at least one global service manager, a Global Data Services catalog, and the GDS configuration databases. You need to create mountpoint on podman host to save gsm setup related file for Oracle Global Service Manager and expose as a volume to GSM container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used `/scratch/oradata/dbfiles/GSMDATA` directory and exposed as volume to GSM container. + +### Create Directory for Master GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSMDATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSMDATA +``` + +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSMDATA +restorecon -v /scratch/oradata/dbfiles/GSMDATA +``` + +### Master GSM Container + +```bash +podman run -d --hostname oshard-gsm1 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.100 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" \ +-e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=primary;group_region=region1" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=12" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=primary" \ +-e SHARD_SETUP="true" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e OP_TYPE=gsm \ +-e MASTER_GSM="TRUE" \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/scratch/oradata/dbfiles/GSMDATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name gsm1 container-registry.oracle.com/database/gsm:latest +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, PRIMARY_SHARD_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm1 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm1 +============================================== + GSM Setup Completed +============================================== +``` + +## Deploying Standby GSM Container + +You need standby GSM container to serve the connection when master GSM fails. + +### Create Directory for Standby GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSM2DATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSM2DATA +``` + +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSM2DATA +restorecon -v /scratch/oradata/dbfiles/GSM2DATA +``` +### Create Standby GSM Container + +```bash +podman run -d --hostname oshard-gsm2 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.101 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region2;director_port=1522" \ +-e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=standby;group_region=region2" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=12" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD3_PARAMS="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" \ +-e CATALOG_SETUP="True" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e OP_TYPE=gsm \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/GSM2DATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name gsm2 container-registry.oracle.com/database/gsm:latest +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm2 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm2 +``` + +**IMPORTANT:** The GSM Container Image used in this case is having the Oracle GSM installed. On first startup of the container, a new GSM setup will be created and the following lines highlight when the GSM setup is ready to be used: + +```bash +============================================== + GSM Setup Completed +============================================== +``` + +## Scale-out an existing Oracle Globally Distributed Database + +If you want to Scale-Out an existing Oracle Globally Distributed Database already deployed using the Podman Containers, then you will to complete the steps in below order: + +- Complete the prerequisite steps before creating the Podman Container for the new shard to be added to the Oracle Globally Distributed Database +- Create the Podman Container for the new shard +- Add the new shard Database to the existing Oracle Globally Distributed Database +- Deploy the new shard + +The below example covers the steps to add a `new shard (shard3)` to an existing Oracle Globally Distributed Database which was deployed earlier in this page with `two shards (shard1 and shard2)`. + +### Complete the prerequisite steps before creating Podman Container for new shard + +Create the required directories for the new shard (shard3 in this case) container just like they were created for the earlier shards (shard1 and shard2): + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL3CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL3CDB +``` + +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL3CDB +restorecon -v /scratch/oradata/dbfiles/ORCL3CDB +``` + +**Notes:** + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL3CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instace Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Podman Container for new shard + +Before creating new shard (shard3 in this case) container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/ORCL3CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. + +```bash +podman run -d --hostname oshard3-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.105 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=ORCL3PDB \ +-e DB_UNIQUE_NAME=ORCL3CDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL3CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard3 container-registry.oracle.com/database/free:latest +``` + +To check the shard3 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard1 container service. + +```bash +podman logs -f shard3 +``` + +**IMPORTANT:** Like the earlier shards (shard1 and shard2), wait for the following lines highlight when the Shard3 database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Add the new shard Database to the existing Oracle Globally Distributed Database + +Use the below command to add the new shard3: +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --addshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" +``` + +Use the below command to check the status of the newly added shard: +``` bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard +``` + +### Deploy the new shard + +Deploy the newly added shard (shard3): + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deployshard=true +``` + +Use the below command to check the status of the newly added shard and the chunks distribution: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** The chunks redistribution after deploying the new shard may take some time to complete. + +## Scale-in an existing Oracle Globally Distributed Database + +If you want to Scale-in an existing Oracle Globally Distributed Database by removing a particular shard database out of the existing shard databases, then you will to complete the steps in below order: + +- Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database +- Move the chunks out of the shard database which you want to delete +- Delete the shard database from the Oracle Globally Distributed Database +- Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + + +### Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database + +Use the below commands to check the status of the shard which you want to delete and status of chunks present in this shard: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + + +### Move the chunks out of the shard database which you want to delete + +In the current example, if you want to delete the shard3 database from the Oracle Globally Distributed Database, then you need to use the below command to move the chunks out of shard3 database: + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --movechunks="shard_db=ORCL3CDB;shard_pdb=ORCL3PDB" +``` + +**NOTE:** In this case, `ORCL3CDB` and `ORCL3PDB` are the names of CDB and PDB for the shard3 respectively. + +After moving the chunks out, use the below command to confirm there is no chunk present in the shard database which you want to delete: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** You will need to wait for some time for all the chunks to move out of the shard database which you want to delete. If the chunks are still moving out, you can rerun the above command to check the status after some time. + + +### Delete the shard database from the Oracle Globally Distributed Database + +Once you have confirmed that no chunk is present in the shard to be deleted in earlier step, you can use the below command to delete that shard(shard3 in this case): + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deleteshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" +``` + +**NOTE:** In this case, `oshard3-0`, `ORCL3CDB` and `ORCL3PDB` are the names of host, CDB and PDB for the shard3 respectively. + + +### Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + +Once the shard is deleted from the Oracle Globally Distributed Database, use the below commands to check the status of the shards and chunk distribution in the Oracle Globally Distributed Database: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Remove the Podman Container + +Once the shard is deleted from the Oracle Globally Distributed Database, you can remove the Podman Container which was deployed earlier for the deleted shard database. + +If the deleted shard was "shard3", to remove its Podman Container, please use the below steps: + +- Stop and remove the Docker Container for shard3: + +```bash +podman stop shard3 +podman rm shard3 +``` + +- Remove the directory containing the files for this deleted Podman Container: + +```bash +rm -rf /scratch/oradata/dbfiles/ORCL3CDB +``` + +## Environment Variables Explained + +**For catalog, shard containers-** +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| COMMON_OS_PWD_FILE | Specify the podman secret for the password file to be read inside the container | Mandatory | +| PWD_KEY | Specify the podman secret for the password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For Shards it has to be set to primaryshard or standbyshard | Mandatory | +| DOMAIN | Specify the domain name | Mandatory | +| ORACLE_SID | CDB name which has to be "FREE" for Oracle Database FREE | Mandatory | +| ORACLE_PDB | PDB name which has to be "FREEPDB1" for Oracle Database FREE | Mandatory | +| ORACLE_FREE_PDB | PDB name which you want to create for the setup | Mandatory | +| DB_UNIQUE_NAME | DB_UNIQUE_NAME name which you want to set | Mandatory | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts which you want to run after setting up shard setup. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name that must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after shard db setup. | Optional | +| CLONE_DB | Specify value "true" if you want to avoid db creation using DBCA and clone it from cold backup of existing Oracle DB. This DB must not have shard setup. Shard script will look for the backup at /opt/oracle/oradata. | Optional | +| OLD_ORACLE_SID | Specify the OLD_ORACLE_SID if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | +| OLD_ORACLE_PDB | Specify the OLD_ORACLE_PDB if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | + + +**For GSM Containers-** +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| CATALOG_SETUP | Accept True. If set then, it will just create gsm director and add catalog but will not add any shard | Mandatory | +| CATALOG_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=catalog_host, value=catalog hostname;key=catalog_db, value=catalog cdb name;key=catalog_pdb, value=catalog pdb name;key=catalog_port, value=catalog db port name;key=catalog_name, value=catalog name in GSM;key=catalog_region, value=specify comma separated region name for catalog db deployment | Mandatory | +| SHARD_DIRECTOR_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=director_name, value=shard director name;key=director_region, value=shard director region;key=director_port, value=shard director port | Mandatory | +| SHARD[1-9]_GROUP_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=group_name, value=shard group name;key=deploy_as, value=deploy shard group as primary or standby or active_standby;key=group_region, value=shard group region name | Mandatory | +| SHARD[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=shard_host, value=shard hostname; key=shard_db, value=shard cdb name; key=shard_pdb, value=shard pdb name; key=shard_port, value=shard db port;key=shard_group value=shard group name | Mandatory | +| SERVICE[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=service_name, value=service name;key=service_role, value=service role e.g. primary or physical_standby | Mandatory | +| COMMON_OS_PWD_FILE | Specify the podman secret for the password file to be read inside the container | Mandatory | +| PWD_KEY | Specify the podman secret for the password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For GSM, it has to be set to gsm. | Mandatory | +| DOMAIN | Domain of the container. | Mandatory | +| MASTER_GSM | Set value to "TRUE" if you want the GSM to be a master GSM. Otherwise, do not set it. | Mandatory | +| SAMPLE_SCHEMA | Specify a value to "DEPLOY" if you want to deploy sample app schema in catalog DB during GSM setup. | Optional | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts that you want to run after setting up GSM. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name which must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after GSM setup. | Optional | +| BASE_DIR | Specify BASE_DIR if you want to change the base location of the scripts to setup GSM. | Optional | +| SCRIPT_NAME | Specify the script name which will be executed from BASE_DIR. Default set to main.py. | Optional | +| EXECUTOR | Specify the script executor such as /bin/python or /bin/bash. Default set to /bin/python. | Optional | + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + + +## License + +To run Oracle Globally Distributed Database, regardless whether inside or outside a Container, ensure to download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-user-defined-sharding.md b/container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-user-defined-sharding.md new file mode 100644 index 0000000..2edfbb8 --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/podman-container-files-free/podman-sharded-database-free-with-user-defined-sharding.md @@ -0,0 +1,615 @@ +# Deploy Oracle Globally Distributed Database with User-Defined Sharding using Podman Containers and Oracle Database FREE Images + +This page covers the steps to manually deploy a sample Oracle Globally Distributed Database with User-Defined Sharding using Podman Containers and Oracle Database FREE Images. + +- [Setup Details](#setup-details) +- [Prerequisites](#prerequisites) +- [Deploying Catalog Container](#deploying-catalog-container) + - [Create Directory](#create-directory) + - [Create Container](#create-container) +- [Deploying Shard Containers](#deploying-shard-containers) + - [Create Directories](#create-directories) + - [Shard1 Container](#shard1-container) + - [Shard2 Container](#shard2-container) +- [Deploying GSM Container](#deploying-gsm-container) + - [Create Directory for Master GSM Container](#create-directory-for-master-gsm-container) + - [Create Master GSM Container](#create-master-gsm-container) +- [Deploying Standby GSM Container](#deploying-standby-gsm-container) + - [Create Directory for Standby GSM Container](#create-directory-for-standby-gsm-container) + - [Create Standby GSM Container](#create-standby-gsm-container) +- [Scale-out an existing Oracle Globally Distributed Database](#scale-out-an-existing-oracle-globally-distributed-database) + - [Complete the prerequisite steps before creating Podman Container for new shard](#complete-the-prerequisite-steps-before-creating-podman-container-for-new-shard) + - [Create Podman Container for new shard](#create-podman-container-for-new-shard) + - [Add the new shard Database to the existing Oracle Globally Distributed Database](#add-the-new-shard-database-to-the-existing-oracle-globally-distributed-database) + - [Deploy the new shard](#deploy-the-new-shard) + - [Move chunks](#move-chunks) +- [Scale-in an existing Oracle Globally Distributed Database](#scale-in-an-existing-oracle-globally-distributed-database) + - [Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database](#confirm-the-shard-to-be-deleted-is-present-in-the-list-of-shards-in-the-oracle-globally-distributed-database) + - [Move the chunks out of the shard database which you want to delete](#move-the-chunks-out-of-the-shard-database-which-you-want-to-delete) + - [Delete the shard database from the Oracle Globally Distributed Database](#delete-the-shard-database-from-the-oracle-globally-distributed-database) + - [Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database](#confirm-the-shard-has-been-successfully-deleted-from-the-oracle-globally-distributed-database) + - [Remove the Podman Container](#remove-the-podman-container) +- [Environment Variables Explained](#environment-variables-explained) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + +## Setup Details + +This setup involves deploying podman containers for: + +* Catalog Database +* Two Shard Databases +* Primary GSM +* Standby GSM + +**NOTE:** In the current Sample Oracle Globally Distributed Database Deployment, we have used Oracle 23ai FREE Database and GSM Podman Images. + +## Prerequisites + +Before using this page to create a sample Oracle Globally Distributed Database, please complete the prerequisite steps mentioned in [Oracle Globally Distributed Database Containers using Oracle Database FREE Images on Podman](./README.md#prerequisites) + +Refer to the page [Oracle Database Free](https://www.oracle.com/database/free/get-started/) for the details of the Oracle Database FREE Images for RDBMS and GSM. + +Before creating the GSM container, you need to build the catalog and shard containers. Execute the following steps to create containers for the deployment: + +## Deploying Catalog Container + +The shard catalog is a special-purpose Oracle Database that is a persistent store for SDB configuration data and plays a key role in the automated deployment and centralized management of a Oracle Globally Distributed Database. It also hosts the gold schema of the application and the master copies of common reference data (duplicated tables) + +### Create Directory + +You need to create mountpoint on the podman host to save datafiles for Oracle Sharding Catalog DB and expose as a volume to catalog container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this sample Oracle Globally Distributed Database, we used `/scratch/oradata/dbfiles/CATALOG` directory and exposed as volume to catalog container. + +```bash +mkdir -p /scratch/oradata/dbfiles/CATALOG +chown -R 54321:54321 /scratch/oradata/dbfiles/CATALOG +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/CATALOG` exposed to catalog container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Container + +Before creating catalog container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/CATALOG` based on your enviornment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID enviornment variable. + + * If SELinux is enabled on podman host, then execute the following- + ```bash + semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/CATALOG + restorecon -v /scratch/oradata/dbfiles/CATALOG + semanage fcontext -a -t container_file_t /opt/containers/shard_host_file + restorecon -v /opt/containers/shard_host_file + ``` + +```bash +podman run -d --hostname oshard-catalog-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.102 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=CAT1PDB \ +-e DB_UNIQUE_NAME=CATCDB \ +-e OP_TYPE=catalog \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/CATALOG:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name catalog container-registry.oracle.com/database/free:latest +``` + +To check the catalog container/services creation logs, please tail podman logs. It will take 20 minutes to create the catalog container service. + +```bash +podman logs -f catalog +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Catalog database is ready to be used: + +```bash +============================================== + GSM Catalog Setup Completed +============================================== +``` + +## Deploying Shard Containers + +A database shard is a horizontal partition of data in a database or search engine. Each individual partition is referred to as a shard or database shard. You need to create mountpoint on podman host to save datafiles for Oracle Globally Distributed Database and expose as a volume to shard container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used /scratch/oradata/dbfiles/ORCL1CDB directory and exposed as volume to shard container. + +### Create Directories + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL1CDB +mkdir -p /scratch/oradata/dbfiles/ORCL2CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL1CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL2CDB +``` + +If SELinux is enabled on podman host, then execute the following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL1CDB +restorecon -v /scratch/oradata/dbfiles/ORCL1CDB +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL2CDB +restorecon -v /scratch/oradata/dbfiles/ORCL2CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL1CDB` and `/scratch/oradata/dbfiles/ORCL2CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instace Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Shard1 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/ORCL1CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. + +```bash +podman run -d --hostname oshard1-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.103 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=ORCL1PDB \ +-e DB_UNIQUE_NAME=ORCL1CDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL1CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard1 container-registry.oracle.com/database/free:latest +``` + +To check the shard1 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard1 container service. + +```bash +podman logs -f shard1 +``` + +### Shard2 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/ORCL2CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. + +```bash +podman run -d --hostname oshard2-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.104 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=ORCL2PDB \ +-e DB_UNIQUE_NAME=ORCL2CDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL2CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard2 container-registry.oracle.com/database/free:latest +``` + +**Note**: You can add more shards based on your requirement. + +To check the shard2 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard2 container service + +```bash +podman logs -f shard2 +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Shard database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +## Deploying GSM Container + +The Global Data Services framework consists of at least one global service manager, a Global Data Services catalog, and the GDS configuration databases. You need to create mountpoint on podman host to save gsm setup related file for Oracle Global Service Manager and expose as a volume to GSM container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used `/scratch/oradata/dbfiles/GSMDATA` directory and exposed as volume to GSM container. + +### Create Directory for Master GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSMDATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSMDATA +``` + +If SELinux is enabled on podman host, then execute the following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSMDATA +restorecon -v /scratch/oradata/dbfiles/GSMDATA +``` + +### Create Master GSM Container + +```bash +podman run -d --hostname oshard-gsm1 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.100 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;sharding_type=USER;shard_space=shardspace1,shardspace2;" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_space=shardspace1;deploy_as=primary;shard_region=region1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_space=shardspace2;deploy_as=primary;shard_region=region2" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=primary" \ +-e SHARD_SETUP="true" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e OP_TYPE=gsm \ +-e MASTER_GSM="TRUE" \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/scratch/oradata/dbfiles/GSMDATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name gsm1 container-registry.oracle.com/database/gsm:latest +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, PRIMARY_SHARD_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm1 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm1 +``` + +## Deploying Standby GSM Container + +You need standby GSM container to serve the connection when master GSM fails. + +### Create Directory for Standby GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSM2DATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSM2DATA +``` +If SELinux is enabled on podman host, then execute the following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSM2DATA +restorecon -v /scratch/oradata/dbfiles/GSM2DATA +``` + +### Create Standby GSM Container + +```bash +podman run -d --hostname oshard-gsm2 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.101 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region2;director_port=1522" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;sharding_type=USER;shard_space=shardspace1,shardspace2" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_space=shardspace1;" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_space=shardspace2;" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" \ +-e CATALOG_SETUP="True" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e OP_TYPE=gsm \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/GSM2DATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name gsm2 container-registry.oracle.com/database/gsm:latest +``` +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm2 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm2 +``` + +**IMPORTANT:** The GSM Container Image used in this case is having the Oracle GSM installed. On first startup of the container, a new GSM setup will be created and the following lines highlight when the GSM setup is ready to be used: + +```bash +============================================== + GSM Setup Completed +============================================== +``` + +**NOTE:** Once the Oracle Globally Distributed Database Deployment is complete using Used-Defined Sharding, you can load the data into this Oracle Globally Distributed Database. + +## Scale-out an existing Oracle Globally Distributed Database + +If you want to Scale-Out an existing Oracle Globally Distributed Database already deployed using the Podman Containers, then you will to complete the steps in below order: + +- Complete the prerequisite steps before creating the Podman Container for the new shard to be added to the Oracle Globally Distributed Database +- Create the Podman Container for the new shard +- Add the new shard Database to the existing Oracle Globally Distributed Database +- Deploy the new shard +- Move chunks + +The below example covers the steps to add a new shard (shard3) to an existing Oracle Globally Distributed Database which was deployed earlier in this page with two shards (shard1 and shard2). + +### Complete the prerequisite steps before creating Podman Container for new shard + +Create the required directories for the new shard (shard3 in this case) container just like they were created for the earlier shards (shard1 and shard2): + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL3CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL3CDB +``` +If SELinux is enabled on podman host, then execute the following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL3CDB +restorecon -v /scratch/oradata/dbfiles/ORCL3CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL3CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instace Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Podman Container for new shard + +Before creating new shard (shard3 in this case) container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_FREE_PDB, DB_UNIQUE_NAME based on your env. +* Change `/scratch/oradata/dbfiles/ORCL3CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. + +```bash +podman run -d --hostname oshard3-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.105 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=FREE \ +-e ORACLE_PDB=FREEPDB1 \ +-e ORACLE_FREE_PDB=ORCL3PDB \ +-e DB_UNIQUE_NAME=ORCL3CDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL3CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard3 container-registry.oracle.com/database/free:latest +``` + +To check the shard3 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard1 container service. + +```bash +podman logs -f shard3 +``` + +**IMPORTANT:** Like the earlier shards (shard1 and shard2), wait for the following lines highlight when the Shard3 database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Add the new shard Database to the existing Oracle Globally Distributed Database + +Use the below command to add the new shard3: +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --addshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_space=shardspace3;shard_region=region3" +``` + +Use the below command to check the status of the newly added shard: +``` bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard +``` + +### Deploy the new shard + +Deploy the newly added shard (shard3): + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deployshard=true +``` + +Use the below command to check the status of the newly added shard and the chunks distribution: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Move chunks + +In case you want to move some chunks to the newly added Shard from an existing Shard, you can use the below command: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK $CHUNK_ID -SOURCE $SOURCE_SHARD -TARGET $TARGET_SHARD +``` + +Example: If you want to move the chunk with chunk id `3` from source shard `ORCL1CDB_ORCL1PDB` to target shard `ORCL3CDB_ORCL3PDB`, then you can use the below command: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK 3 -SOURCE ORCL1CDB_ORCL1PDB -TARGET ORCL3CDB_ORCL3PDB +``` + +Use the below command to check the status of the chunks distribution: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +## Scale-in an existing Oracle Globally Distributed Database + +If you want to Scale-in an existing Oracle Globally Distributed Database by removing a particular shard database out of the existing Oracle Globally Distributed Database, then you will to complete the steps in below order: + +- Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database +- Move the chunks out of the shard database which you want to delete +- Delete the shard database from the Oracle Globally Distributed Database +- Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + + +### Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database + +Use the below commands to check the status of the shard which you want to delete and status of chunks present in this shard: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + + +### Move the chunks out of the shard database which you want to delete + +In the current example, if you want to delete the shard3 database from the Oracle Globally Distributed Database, then you need to use the below command to move the chunks out of shard3 database: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK $CHUNK_ID -SOURCE $SOURCE_SHARD -TARGET $TARGET_SHARD +``` + +Example: If you want to move the chunk with chunk id `3` from source shard `ORCL3CDB_ORCL3PDB` to target shard `ORCL1CDB_ORCL1PDB`, then you can use the below command: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK 3 -SOURCE ORCL3CDB_ORCL3PDB -TARGET ORCL1CDB_ORCL1PDB +``` + +**NOTE:** To move more than 1 chunk, you can specify comma separated chunk ids. + +After moving the chunks out, use the below command to confirm there is no chunk present in the shard database which you want to delete: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** You will need to wait for some time for all the chunks to move out of the shard database which you want to delete. + +### Delete the shard database from the Oracle Globally Distributed Database + +Once you have confirmed that no chunk is present in the shard to be deleted in earlier step, you can use the below command to delete that shard(shard3 in this case): +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deleteshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_space=shardspace3;shard_region=region3" +``` + +**NOTE:** In this case, `oshard3-0`, `ORCL3CDB` and `ORCL3PDB` are the names of host, CDB and PDB for the shard3 respectively. + + +### Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + +Once the shard is deleted from the Oracle Globally Distributed Database, use the below commands to check the status of the shards and chunk distribution in the Oracle Globally Distributed Database: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Remove the Podman Container + +Once the shard is deleted from the Oracle Globally Distributed Database, you can remove the Podman Container which was deployed earlier for the deleted shard database. + +If the deleted shard was `shard3`, to remove its Podman Container, please use the below steps: + +- Stop and remove the Docker Container for shard3: + +```bash +podman stop shard3 +podman rm shard3 +``` + +- Remove the directory containing the files for this deleted Podman Container: + +```bash +rm -rf /scratch/oradata/dbfiles/ORCL3CDB +``` + +## Environment Variables Explained + +**For catalog, shard containers-** +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| COMMON_OS_PWD_FILE | Specify the podman secret for the password file to be read inside the container | Mandatory | +| PWD_KEY | Specify the podman secret for the password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For Shards it has to be set to primaryshard or standbyshard | Mandatory | +| DOMAIN | Specify the domain name | Mandatory | +| ORACLE_SID | CDB name which has to be "FREE" for Oracle Database FREE | Mandatory | +| ORACLE_PDB | PDB name which has to be "FREEPDB1" for Oracle Database FREE | Mandatory | +| ORACLE_FREE_PDB | PDB name which you want to create for the setup | Mandatory | +| DB_UNIQUE_NAME | DB_UNIQUE_NAME name which you want to set | Mandatory | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts which you want to run after setting up shard setup. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name that must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after shard db setup. | Optional | +| CLONE_DB | Specify value "true" if you want to avoid db creation and clone it from cold backup of existing Oracle DB. This DB must not have shard setup. Shard script will look for the backup at /opt/oracle/oradata. | Optional | +| OLD_ORACLE_SID | Specify the OLD_ORACLE_SID if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | +| OLD_ORACLE_PDB | Specify the OLD_ORACLE_PDB if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | + +**For GSM Containers-** + +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| CATALOG_SETUP | Accept True. if set then , it will only restrict till catalog connection and setup. | Mandatory | +| CATALOG_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=catalog_host, value=catalog hostname; key=catalog_db, value=catalog cdb name; key=catalog_pdb, value=catalog pdb name; key=catalog_port, value=catalog db port name; key=catalog_name, value=catalog name in GSM; key=catalog_region, value=specify comma separated region name for catalog db deployment | Mandatory | +| SHARD_DIRECTOR_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=director_name, value=shard director name; key=director_region, value=shard director region; key=director_port, value=shard director port | Mandatory | +| SHARD[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=shard_host, value=shard hostname key=shard_db, value=shard cdb name key=shard_pdb, value=shard pdb name key=shard_port, value=shard db port key=shard_space, value=shard space name key=deploy_as, value=primary or standby key=shard_region, value=region name | Mandatory | +| SERVICE[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=service_name, value=service name; key=service_role, value=service role e.g. primary or physical_standby | Mandatory | +| COMMON_OS_PWD_FILE | Specify the encrypted password file to be read inside container | Mandatory | +| PWD_KEY | Specify the podman secret for the password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For GSM it has to be set to gsm. | Mandatory | +| DOMAIN | Domain of the container. | Mandatory | +| MASTER_GSM | Set value to "TRUE" if you want the GSM to be a master GSM. Otherwise, do not set it. | Mandatory | +| SAMPLE_SCHEMA | Specify a value to "DEPLOY" if you want to deploy sample app schema in catalog DB during GSM setup. | Optional | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts that you want to run after setting up GSM. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name which must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after GSM setup. | Optional | +| BASE_DIR | Specify BASE_DIR if you want to change the base location of the scripts to setup GSM. | Optional | +| SCRIPT_NAME | Specify the script name which will be executed from BASE_DIR. Default set to main.py. | Optional | +| EXECUTOR | Specify the script executor such as /bin/python or /bin/bash. Default set to /bin/python. | Optional | + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + + +## License + +To run Oracle Globally Distributed Database, regardless whether inside or outside a Container, ensure to download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/container-files/podman-container-files/README.md b/container-based-sharding-deployment/samples/container-files/podman-container-files/README.md new file mode 100644 index 0000000..5ee908c --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/podman-container-files/README.md @@ -0,0 +1,172 @@ +# Oracle Globally Distributed Database Containers on Podman + +In this installation guide, we deploy Oracle Globally Distributed Database Containers on Podman. This document provides detailed steps for various deployment scenarios of Oracle Globally Distributed Database using Podman Containers. +- [Oracle Globally Distributed Database Containers on Podman](#oracle-globally-distributed-database-containers-on-podman) + - [Prerequisites](#prerequisites) + - [Network Management](#network-management) + - [Macvlan Network](#macvlan-network) + - [Ipvlan Network](#ipvlan-network) + - [Bridge Network](#bridge-network) + - [Setup Hostfile](#setup-hostfile) + - [Password Management](#password-management) + - [SELinux Configuration on Podman Host](#selinux-configuration-on-podman-host) + - [Deploy Oracle Globally Distributed Database Containers](#deploy-oracle-globally-distributed-database-containers) + - [Deploy Oracle Globally Distributed Database with System-Managed Sharding](#deploy-oracle-globally-distributed-database-with-system-managed-sharding) + - [Deploy Oracle Globally Distributed Database with System-Managed Sharding with RAFT Replication enabled](#deploy-oracle-globally-distributed-database-with-system-managed-sharding-with-raft-replication-enabled) + - [Deploy Oracle Globally Distributed Database with User-Defined Sharding](#deploy-oracle-globally-distributed-database-with-user-defined-sharding) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + + +## Prerequisites + +You must complete all of the prerequisites before deploying an Oracle Globally Distributed Database using Podman Containers. These prerequisites include creating the Docker network, creating the encrypted file with secrets, and other steps required before deployment. + + +### Network Management + +Before creating a container, create the podman network by creating the Podman network bridge based on your environment. If you are using the bridge name with the network subnet mentioned in this README.md, then you can use the same IPs mentioned in the [Deploy Oracle Globally Distributed Database Containers](#create-containers) section. + +#### Macvlan Network + +To create a Podman network with `macvlan` driver, run the following command: + +```bash +podman network create -d macvlan --subnet=10.0.20.0/24 --gateway=10.0.20.1 -o parent=ens5 shard_pub1_nw +``` + +#### Ipvlan Network + +To create a Podman network with `ipvlan` driver, run the following command: + +```bash +podman network create -d ipvlan --subnet=10.0.20.0/24 --gateway=10.0.20.1 -o parent=ens5 shard_pub1_nw +``` + +If you are planning to create a test environment within a single machine, then you can use a Podman bridge. However, these IPs will not be reachable on the user network. + +#### Bridge Network + +To create a podman network with `bridge` driver, run the following command: + +```bash +podman network create --driver=bridge --subnet=10.0.20.0/24 shard_pub1_nw +``` + +**Note:** You can change subnet and choose one of the above mentioned podman network bridge based on your environment. + +### Setup Hostfile + +**Note:** You can skip this step of creating a Hostfile when you are using a DNS for the IP resolution. + +All containers will share a host file for name resolution. The shared hostfile must be available to all containers. Create the empty shared host file (if it doesn't exist) at `/opt/containers/shard_host_file`: + +For example: + +```bash +mkdir /opt/containers +rm -rf /opt/containers/shard_host_file && touch /opt/containers/shard_host_file +``` + +Because Oracle Database Containers do not have root access to modify the `/etc/hosts` file, add the following host entries in `/opt/containers/shard_host_file`. This file must be prepopulated. You can change these entries based on your environment and network setup. + +```text +127.0.0.1 localhost.localdomain localhost +10.0.20.100 oshard-gsm1.example.com oshard-gsm1 +10.0.20.101 oshard-gsm2.example.com oshard-gsm2 +10.0.20.102 oshard-catalog-0.example.com oshard-catalog-0 +10.0.20.103 oshard1-0.example.com oshard1-0 +10.0.20.104 oshard2-0.example.com oshard2-0 +10.0.20.105 oshard3-0.example.com oshard3-0 +10.0.20.106 oshard4-0.example.com oshard4-0 +``` + +### Password Management + +* Specify the secret volume for resetting database user passwords during catalog and shard setup. The secret volume can be a shared volume among all the containers + + ```bash + mkdir /opt/.secrets/ + cd /opt/.secrets + openssl genrsa -out key.pem + openssl rsa -in key.pem -out key.pub -pubout + ``` + +* Edit the `/opt/.secrets/pwdfile.txt` and seed the password. The password will be common for all the database users. Run the following command: + + ```bash + vi /opt/.secrets/pwdfile.txt + ``` + **Note**: Enter your secure password in the pwdfile.txt file and save the file. + +* After seeding password and saving the `/opt/.secrets/pwdfile.txt` file, run the following command: + ```bash + openssl pkeyutl -in /opt/.secrets/pwdfile.txt -out /opt/.secrets/pwdfile.enc -pubin -inkey /opt/.secrets/key.pub -encrypt + rm -rf /opt/.secrets/pwdfile.txt + ``` + Oracle recommends using Podman secrets inside the containers. Run the following command to create the Podman secrets: + + ```bash + podman secret create pwdsecret /opt/.secrets/pwdfile.enc + podman secret create keysecret /opt/.secrets/key.pem + + podman secret ls + ID NAME DRIVER CREATED UPDATED + 547eed65c01d525bc2b4cebd9 keysecret file 8 seconds ago 8 seconds ago + 8ad6e8e519c26e9234dbcf60a pwdsecret file 8 seconds ago 8 seconds ago + ``` + +**Note:** This password and key secrets are used for initial Oracle Globally Distributed Database topology setup. After the Oracle Globally Distributed Database topology setup is completed, you must change the topology passwords based on your enviornment. + +## SELinux Configuration on Podman Host +To run Podman containers in an environment with Security-Enhanced Linux (SELinux) enabled, you must configure an SELinux policy for the containers. To check if your SELinux is enabled or not, run the `getenforce` command. +With SELinux, you must set a policy to implement permissions for your containers. If you do not configure a policy module for your containers, then they can end up restarting indefinitely, or generate other permission errors. You must add all Podman host nodes for your cluster to the policy module `shard-podman`, by installing the necessary packages and creating a type enforcement file (designated by the `.te` suffix) to build the policy, and load the policy into the system. + +In the following example, the Podman host `podman-host` is configured in the SELinux policy module `shard-podman`: + +Copy [shard-podman.te](../../../containerfiles/shard-podman.te) to `/var/opt` folder in your host and then execute below- +```bash +cd /var/opt +make -f /usr/share/selinux/devel/Makefile shard-podman.pp +semodule -i shard-podman.pp +semodule -l | grep shard-pod +``` +## Deploy Oracle Globally Distributed Database Containers + +Refer to the relevant section depending on whether you want to deploy the Oracle Globally Distributed Database using System-Managed Sharding, System-Managed Sharding with RAFT Replication enabled, or User-Defined Sharding. + +### Deploy Oracle Globally Distributed Database with System-Managed Sharding + +Refer to [Sample Oracle Globally Distributed Database with System-Managed Sharding deployed manually using Podman Containers](./podman-sharded-database-with-system-sharding.md) to deploy a sample Oracle Globally Distributed Database with System-Managed sharding using podman containers. + + +### Deploy Oracle Globally Distributed Database with System-Managed Sharding with RAFT Replication Enabled + +Refer to [Sample Oracle Globally Distributed Database with System-Managed Sharding with RAFT Replication enabled deployed manually using Podman Containers](./podman-sharded-database-with-system-sharding-with-snr-raft-enabled.md) to deploy a sample Oracle Globally Distributed Database with System-Managed sharding with RAFT Replication enabled using podman containers. + +**NOTE:** The RAFT Replication Feature is available only for Oracle 23ai RDBMS and Oracle 23ai GSM version. + +### Deploy Oracle Globally Distributed Database with User-Defined Sharding + +Refer to [Sample Oracle Globally Distributed Database with User-Defined Sharding deployed manually using Podman Containers](./podman-sharded-database-with-user-defined-sharding.md) to deploy a sample Oracle Globally Distributed Database with User-Defined sharding using Podman containers. + + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and later releases. + + +## License + +To run Oracle Globally Distributed Database, whether inside or outside a Container, you must download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and the GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-system-sharding-with-snr-raft-enabled.md b/container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-system-sharding-with-snr-raft-enabled.md new file mode 100644 index 0000000..6577962 --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-system-sharding-with-snr-raft-enabled.md @@ -0,0 +1,627 @@ +# Deploy Oracle Globally Distributed Database with System-Managed Sharding with RAFT Replication Enabled using Podman Containers + +This page covers the steps to manually deploy a sample Oracle Globally Distributed Database with System-Managed Sharding with RAFT Replication Enabled using Podman Containers. + +- [Setup Details](#setup-details) +- [Prerequisites](#prerequisites) +- [Deploying Catalog Container](#deploying-catalog-container) + - [Create Directory](#create-directory) + - [Create Container](#create-container) +- [Deploying Shard Containers](#deploying-shard-containers) + - [Create Directories](#create-directories) + - [Shard1 Container](#shard1-container) + - [Shard2 Container](#shard2-container) + - [Shard3 Container](#shard3-container) +- [Deploying GSM Container](#deploying-gsm-container) + - [Create Directory for Master GSM Container](#create-directory-for-master-gsm-container) + - [Create Master GSM Container](#create-master-gsm-container) +- [Deploying Standby GSM Container](#deploying-standby-gsm-container) + - [Create Directory for Standby GSM Container](#create-directory-for-standby-gsm-container) + - [Create Standby GSM Container](#create-standby-gsm-container) +- [Scale-out an existing Oracle Globally Distributed Database](#scale-out-an-existing-oracle-globally-distributed-database) + - [Complete the prerequisite steps before creating Podman Container for new shard](#complete-the-prerequisite-steps-before-creating-podman-container-for-new-shard) + - [Create Podman Container for new shard](#create-podman-container-for-new-shard) + - [Add the new shard Database to the existing Oracle Globally Distributed Database](#add-the-new-shard-database-to-the-existing-oracle-globally-distributed-database) + - [Deploy the new shard](#deploy-the-new-shard) +- [Scale-in an existing Oracle Globally Distributed Database](#scale-in-an-existing-oracle-globally-distributed-database) + - [Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database](#confirm-the-shard-to-be-deleted-is-present-in-the-list-of-shards-in-the-oracle-globally-distributed-database) + - [Delete the shard database from the Oracle Globally Distributed Database](#delete-the-shard-database-from-the-oracle-globally-distributed-database) + - [Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database](#confirm-the-shard-has-been-successfully-deleted-from-the-oracle-globally-distributed-database) + - [Remove the Podman Container](#remove-the-podman-container) +- [Environment Variables Explained](#environment-variables-explained) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + +## Setup Details + +This setup involves deploying podman containers for: + +* Catalog Database +* Three Shard Databases +* Primary GSM +* Standby GSM + +**NOTE:** RAFT Replication Feature requires Oracle 23ai RDBMS and GSM Podman Images for this sample deployment. + +**NOTE:** To use RAFT Replication feature, you need to deploy Oracle Globally Distributed Database with atleast three shards. + +## Prerequisites + +Before using this page to create a sample Oracle Globally Distributed Database, please complete the prerequisite steps mentioned in [Oracle Globally Distributed Database Containers on Podman](./README.md#prerequisites) + +Before creating the GSM container, you need to build the catalog and shard containers. Execute the following steps to create containers for the deployment: + +## Deploying Catalog Container + +The shard catalog is a special-purpose Oracle Database that is a persistent store for SDB configuration data and plays a key role in the automated deployment and centralized management of a Oracle Globally Distributed Database. It also hosts the gold schema of the application and the master copies of common reference data (duplicated tables) + +### Create Directory + +You need to create mountpoint on the podman host to save datafiles for Oracle Sharding Catalog DB and expose as a volume to catalog container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this sample Oracle Globally Distributed Database, we used `/scratch/oradata/dbfiles/CATALOG` directory and exposed as volume to catalog container. + +```bash +mkdir -p /scratch/oradata/dbfiles/CATALOG +chown -R 54321:54321 /scratch/oradata/dbfiles/CATALOG +``` + +* If SELinux is enabled on podman host, then execute following- + +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/CATALOG +restorecon -v /scratch/oradata/dbfiles/CATALOG +semanage fcontext -a -t container_file_t /opt/containers/shard_host_file +restorecon -v /opt/containers/shard_host_file +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/CATALOG` exposed to catalog container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Container + +Before creating catalog container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change `/scratch/oradata/dbfiles/CATALOG` based on your enviornment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID enviornment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name catalog oracle/database:23.5.0-ee` with `--name catalog oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/CATALOG` must contain the DB backup and it must not be in zipped format. E.g. `/scratch/oradata/dbfiles/CATALOG/SEEDCDB` where SEEDCDB is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard-catalog-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.102 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=CATCDB \ +-e ORACLE_PDB=CAT1PDB \ +-e OP_TYPE=catalog \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/CATALOG:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name catalog oracle/database-ext-sharding:23.5.0-ee +``` + +To check the catalog container/services creation logs, please tail podman logs. It will take 20 minutes to create the catalog container service. + +```bash +podman logs -f catalog +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Catalog database is ready to be used: + +```bash +============================================== + GSM Catalog Setup Completed +============================================== +``` + +## Deploying Shard Containers + +A database shard is a horizontal partition of data in a database or search engine. Each individual partition is referred to as a shard or database shard. You need to create mountpoint on podman host to save datafiles for Oracle Globally Distributed Database and expose as a volume to shard container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. + +For example: During the setup of this README.md, we used `/scratch/oradata/dbfiles/ORCL1CDB` directory and exposed as volume to shard container `shard1`. + +### Create Directories + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL1CDB +mkdir -p /scratch/oradata/dbfiles/ORCL2CDB +mkdir -p /scratch/oradata/dbfiles/ORCL3CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL1CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL2CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL3CDB +``` + +If SELinux is enabled on podman host, then execute following- + +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL1CDB +restorecon -v /scratch/oradata/dbfiles/ORCL1CDB +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL2CDB +restorecon -v /scratch/oradata/dbfiles/ORCL2CDB +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL3CDB +restorecon -v /scratch/oradata/dbfiles/ORCL3CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL1CDB`, `/scratch/oradata/dbfiles/ORCL2CDB` and `/scratch/oradata/dbfiles/ORCL3CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instace Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Shard1 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change `/scratch/oradata/dbfiles/ORCL1CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard1 oracle/database:23.5.0-ee` with `--name shard1 oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL1CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL1CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard1-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.103 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL1CDB \ +-e ORACLE_PDB=ORCL1PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL1CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard1 oracle/database-ext-sharding:23.5.0-ee +``` + +To check the shard1 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard1 container service. + +```bash +podman logs -f shard1 +``` + +### Shard2 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/ORCL2CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard2 oracle/database:23.5.0-ee` with `--name shard2 oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL2CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL2CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard2-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.104 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL2CDB \ +-e ORACLE_PDB=ORCL2PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL2CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard2 oracle/database-ext-sharding:23.5.0-ee +``` + +To check the shard2 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard2 container service + +```bash +podman logs -f shard2 +``` + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Shard3 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change `/scratch/oradata/dbfiles/ORCL3CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard3 oracle/database:23.5.0-ee` with `--name shard3 oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL3CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL3CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard3-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.105 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL3CDB \ +-e ORACLE_PDB=ORCL3PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/ORCL3CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard3 oracle/database-ext-sharding:23.5.0-ee +``` + +To check the shard3 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard3 container service + +```bash +podman logs -f shard3 +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Shard database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +## Deploying GSM Container + +The Global Data Services framework consists of at least one global service manager, a Global Data Services catalog, and the GDS configuration databases. You need to create mountpoint on podman host to save gsm setup related file for Oracle Global Service Manager and expose as a volume to GSM container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used `/scratch/oradata/dbfiles/GSMDATA` directory and exposed as volume to GSM container. + +### Create Directory for Master GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSMDATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSMDATA +``` +If SELinux is enabled on podman host, then execute following- + +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSMDATA +restorecon -v /scratch/oradata/dbfiles/GSMDATA +``` + +### Create Master GSM Container + +```bash +podman run -d --hostname oshard-gsm1 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.100 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" \ +-e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=primary;group_region=region1" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=30;repl_type=Native" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD3_PARAMS="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=primary" \ +-e SHARD_SETUP="true" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e OP_TYPE=gsm \ +-e MASTER_GSM="TRUE" \ +--secret pwdsecret \ +--secret keysecret \ +-v /oradata/dbfiles/GSMDATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name gsm1 oracle/database-gsm:23.5.0 +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, PRIMARY_SHARD_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm1 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm1 +``` + +## Deploying Standby GSM Container + +You need standby GSM container to serve the connection when master GSM fails. + +### Create Directory for Standby GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSM2DATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSM2DATA +``` + +If SELinux is enabled on podman host, then execute following- + +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSM2DATA +restorecon -v /scratch/oradata/dbfiles/GSM2DATA +``` + +### Create Standby GSM Container + +```bash +podman run -d --hostname oshard-gsm2 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.101 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region2;director_port=1522" \ +-e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=active_standby;group_region=region2" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;catalog_chunks=30;repl_type=Native" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SHARD3_PARAMS="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" \ +-e CATALOG_SETUP="True" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e OP_TYPE=gsm \ +--secret pwdsecret \ +--secret keysecret \ +-v /oradata/dbfiles/GSM2DATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name gsm2 oracle/database-gsm:23.5.0 +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm2 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm2 +``` + +**IMPORTANT:** The GSM Container Image used in this case is having the Oracle GSM installed. On first startup of the container, a new GSM setup will be created and the following lines highlight when the GSM setup is ready to be used: + +```bash +============================================== + GSM Setup Completed +============================================== +``` + +## Scale-out an existing Oracle Globally Distributed Database + +If you want to Scale-Out an existing Oracle Globally Distributed Database already deployed using the Podman Containers, then you will to complete the steps in below order: + +- Complete the prerequisite steps before creating the Podman Container for the new shard to be added to the Oracle Globally Distributed Database +- Create the Podman Container for the new shard +- Add the new shard Database to the existing Oracle Globally Distributed Database +- Deploy the new shard + +The below example covers the steps to add a new shard (shard4) to an existing Oracle Globally Distributed Database which was deployed earlier in this page with three shards (shard1, shard2 and shard3) with RAFT Replication enabled. + +### Complete the prerequisite steps before creating Podman Container for new shard + +Create the required directories for the new shard (shard4 in this case) container just like they were created for the earlier shards (shard1, shard2 and shard3): + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL4CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL4CDB +``` +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL4CDB +restorecon -v /scratch/oradata/dbfiles/ORCL4CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL4CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instace Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Podman Container for new shard + +Before creating new shard (shard4 in this case) container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/ORCL4CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard4 oracle/database:23.5.0-ee` with `--name shard4 oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL4CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL4CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard4-0 \ + --dns-search=example.com \ + --network=shard_pub1_nw \ + --ip=10.0.20.106 \ + -e DOMAIN=example.com \ + -e ORACLE_SID=ORCL4CDB \ + -e ORACLE_PDB=ORCL4PDB \ + -e OP_TYPE=primaryshard \ + -e SHARD_SETUP="true" \ + -e COMMON_OS_PWD_FILE=pwdsecret \ + -e PWD_KEY=keysecret \ + -e SHARD_SETUP="true" \ + -e ENABLE_ARCHIVELOG=true \ + --secret pwdsecret \ + --secret keysecret \ + -v /oradata/dbfiles/ORCL4CDB:/opt/oracle/oradata \ + -v /opt/containers/shard_host_file:/etc/hosts \ + --privileged=false \ + --name shard4 oracle/database-ext-sharding:23.5.0-ee +``` + +To check the shard4 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard4 container service. + +```bash +podman logs -f shard4 +``` + +**IMPORTANT:** Like the earlier shards (shard1, shard2 and shard3), wait for the following lines highlight when the Shard3 database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Add the new shard Database to the existing Oracle Globally Distributed Database + +Use the below command to add the new shard4: +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --addshard="shard_host=oshard4-0;shard_db=ORCL4CDB;shard_pdb=ORCL4PDB;shard_port=1521;shard_group=shardgroup1" +``` + +Use the below command to check the status of the newly added shard: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard +``` + +### Deploy the new shard + +Deploy the newly added shard (shard3): + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deployshard=true +``` + +Use the below command to check the status of the newly added shard and the chunks distribution: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** The chunks redistribution after deploying the new shard may take some time to complete. + +## Scale-in an existing Oracle Globally Distributed Database + +If you want to Scale-in an existing Oracle Globally Distributed Database by removing a particular shard database out of the existing shard databases, then you will to complete the steps in below order: + +- Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database. +- Delete the shard database from the Oracle Globally Distributed Database. You will not need to manually move out chunks in this case. +- Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database. + + +### Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database + +Use the below commands to check the status of the shard which you want to delete and status of chunks present in this shard: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Delete the shard database from the Oracle Globally Distributed Database + +Once you have confirmed that no chunk is present in the shard to be deleted in earlier step, you can use the below command to delete that shard(shard4 in this case): + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deleteshard="shard_host=oshard4-0;shard_db=ORCL4CDB;shard_pdb=ORCL4PDB;shard_port=1521;shard_group=shardgroup1" +``` + +**NOTE:** In this case, `oshard4-0`, `ORCL4CDB` and `ORCL4PDB` are the names of host, CDB and PDB for the shard4 respectively. + +**NOTE:** You will need to wait for some time for all the chunks to move out of the shard database which you want to delete. + +### Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + +Once the shard is deleted from the Oracle Globally Distributed Database, use the below commands to check the status of the shards and chunk distribution in the Oracle Globally Distributed Database: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Remove the Podman Container + +Once the shard is deleted from the Oracle Globally Distributed Database, you can remove the Podman Container which was deployed earlier for the deleted shard database. + +If the deleted shard was "shard4", to remove its Podman Container, please use the below steps: + +- Stop and remove the Docker Container for shard4: +```bash +podman stop shard4 +podman rm shard4 +``` + +- Remove the directory containing the files for this deleted Podman Container: +```bash +rm -rf /scratch/oradata/dbfiles/ORCL4CDB +``` + +## Environment Variables Explained + +**For catalog, shard containers-** +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| COMMON_OS_PWD_FILE | Specify the podman secret for the password file to be read inside the container | Mandatory | +| PWD_KEY | Specify the podman secret for the password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For shards, it has to be set to primaryshard or standbyshard | Mandatory | +| DOMAIN | Specify the domain name | Mandatory | +| ORACLE_SID | CDB name | Mandatory | +| ORACLE_PDB | PDB name | Mandatory | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts which you want to run after setting up shard setup. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name that must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after shard db setup. | Optional | +| CLONE_DB | Specify value "true" if you want to avoid db creation and clone it from cold backup of existing Oracle DB. This DB must not have shard setup. Shard script will look for the backup at /opt/oracle/oradata. | Optional | +| OLD_ORACLE_SID | Specify the OLD_ORACLE_SID if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | +| OLD_ORACLE_PDB | Specify the OLD_ORACLE_PDB if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | + + +**For GSM Containers-** +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| SHARD_DIRECTOR_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=director_name, value=shard director name; key=director_region, value=shard director region; key=director_port, value=shard director port | Mandatory | +| SHARD[1-9]_GROUP_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=group_name, value=shard group name; key=deploy_as, value=deploy shard group as primary or standby or active_standby; key=group_region, value=shard group region name | Mandatory | +| CATALOG_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=catalog_host, value=catalog hostname; key=catalog_db, value=catalog cdb name; key=catalog_pdb, value=catalog pdb name; key=catalog_port, value=catalog db port name; key=catalog_name, value=catalog name in GSM; key=catalog_region, value=specify comma separated region name for catalog db deployment; key=catalog_chunks, value=number of unique chunks; key=repl_type, value=the replication type | Mandatory | +| SHARD[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=shard_host, value=shard hostname; key=shard_db, value=shard cdb name; key=shard_pdb, value=shard pdb name; key=shard_port, value=shard db port; key=shard_group, value=shard group name | Mandatory | +| SERVICE[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=service_name, value=service name; key=service_role, value=service role e.g. primary or physical_standby | Mandatory | +| COMMON_OS_PWD_FILE | Specify the encrypted password file to be read inside container | Mandatory | +| PWD_KEY | Specify password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For GSM it has to be set to gsm. | Mandatory | +| DOMAIN | Domain of the container. | Mandatory | +| MASTER_GSM | Set value to "TRUE" if you want the GSM to be a master GSM. Otherwise, do not set it. | Mandatory | +| CATALOG_SETUP | Accept True. If set then, it will only restrict till catalog connection and setup. | Mandatory | +| SAMPLE_SCHEMA | Specify a value to "DEPLOY" if you want to deploy sample app schema in catalog DB during GSM setup. | Optional | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts that you want to run after setting up GSM. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name which must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after GSM setup. | Optional | +| BASE_DIR | Specify BASE_DIR if you want to change the base location of the scripts to setup GSM. | Optional | +| SCRIPT_NAME | Specify the script name which will be executed from BASE_DIR. Default set to main.py. | Optional | +| EXECUTOR | Specify the script executor such as /bin/python or /bin/bash. Default set to /bin/python. | Optional | + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + +## License + +To run Oracle Globally Distributed Database, regardless whether inside or outside a Container, ensure to download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-system-sharding.md b/container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-system-sharding.md new file mode 100644 index 0000000..ad4745b --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-system-sharding.md @@ -0,0 +1,598 @@ +# Deploy Oracle Globally Distributed Database with System-Managed Sharding using Podman Containers + +This page covers the steps to manually deploy a sample Oracle Globally Distributed Database with System-Managed Sharding using Podman Containers. + +- [Setup Details](#setup-details) +- [Prerequisites](#prerequisites) +- [Deploying Catalog Container](#deploying-catalog-container) + - [Create Directory](#create-directory) + - [Create Container](#create-container) +- [Deploying Shard Containers](#deploying-shard-containers) + - [Create Directories](#create-directories) + - [Shard1 Container](#shard1-container) + - [Shard2 Container](#shard2-container) +- [Deploying GSM Container](#deploying-gsm-container) + - [Create Directory for Master GSM Container](#create-directory-for-master-gsm-container) + - [Master GSM Container](#master-gsm-container) +- [Deploying Standby GSM Container](#deploying-standby-gsm-container) + - [Create Directory for Standby GSM Container](#create-directory-for-standby-gsm-container) + - [Standby GSM Container](#create-standby-gsm-container) +- [Scale-out an existing Oracle Globally Distributed Database](#scale-out-an-existing-oracle-globally-distributed-database) + - [Complete the prerequisite steps before creating Podman Container for new shard](#complete-the-prerequisite-steps-before-creating-podman-container-for-new-shard) + - [Create Podman Container for new shard](#create-podman-container-for-new-shard) + - [Add the new shard Database to the existing Oracle Globally Distributed Database](#add-the-new-shard-database-to-the-existing-oracle-globally-distributed-database) + - [Deploy the new shard](#deploy-the-new-shard) +- [Scale-in an existing Oracle Globally Distributed Database](#scale-in-an-existing-oracle-globally-distributed-database) + - [Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database](#confirm-the-shard-to-be-deleted-is-present-in-the-list-of-shards-in-the-oracle-globally-distributed-database) + - [Move the chunks out of the shard database which you want to delete](#move-the-chunks-out-of-the-shard-database-which-you-want-to-delete) + - [Delete the shard database from the Oracle Globally Distributed Database](#delete-the-shard-database-from-the-oracle-globally-distributed-database) + - [Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database](#confirm-the-shard-has-been-successfully-deleted-from-the-oracle-globally-distributed-database) + - [Remove the Podman Container](#remove-the-podman-container) +- [Environment Variables Explained](#environment-variables-explained) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + +## Setup Details + +This setup initially involves deploying podman containers for: + +* Catalog Database +* Two Shard Databases +* Primary GSM +* Standby GSM + +**NOTE:** You can use Oracle 21c or Oracle 23ai RDBMS and GSM Podman Images for this sample deployment. + +**NOTE:** In the current Sample Oracle Globally Distributed Database Deployment, we have used Oralce 23ai RDBMS and GSM Podman Images. + +## Prerequisites + +Before using this page to create a sample Oracle Globally Distributed Database, please complete the prerequisite steps mentioned in [Oracle Globally Distributed Database Containers on Podman](./README.md#prerequisites) + +Before creating the GSM container, you need to build the catalog and shard containers. Execute the following steps to create containers for the deployment: + +## Deploying Catalog Container + +The shard catalog is a special-purpose Oracle Database that is a persistent store for SDB configuration data and plays a key role in the automated deployment and centralized management of an Oracle Globally Distributed Database. It also hosts the gold schema of the application and the master copies of common reference data (duplicated tables) + +### Create Directory + +You need to create mountpoint on the podman host to save datafiles for Oracle Sharding Catalog DB and expose as a volume to catalog container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this sample Oracle Globally Distributed Database, we used `/scratch/oradata/dbfiles/CATALOG` directory and exposed as volume to catalog container. + +```bash +mkdir -p /scratch/oradata/dbfiles/CATALOG +chown -R 54321:54321 /scratch/oradata/dbfiles/CATALOG +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/CATALOG` exposed to catalog container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed, then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Container + +Before creating catalog container, review the following notes carefully: + +**Notes:** +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/CATALOG based on your enviornment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID enviornment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace following `--name catalog oracle/database:23.5.0-ee` to `--name catalog oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, /scratch/oradata/dbfiles/CATALOG must contain the DB backup and it must not be in zipped format. E.g. /scratch/oradata/dbfiles/CATALOG/SEEDCDB where SEEDCDB is the cold backup and contains datafiles and PDB. +* If SELinux is enabled on podman host, then execute following- + ```bash + semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/CATALOG + restorecon -v /scratch/oradata/dbfiles/CATALOG + semanage fcontext -a -t container_file_t /opt/containers/shard_host_file + restorecon -v /opt/containers/shard_host_file + ``` + +```bash +podman run -d --hostname oshard-catalog-0 \ + --dns-search=example.com \ + --network=shard_pub1_nw \ + --ip=10.0.20.102 \ + -e DOMAIN=example.com \ + -e ORACLE_SID=CATCDB \ + -e ORACLE_PDB=CAT1PDB \ + -e OP_TYPE=catalog \ + -e COMMON_OS_PWD_FILE=pwdsecret \ + -e PWD_KEY=keysecret \ + -e SHARD_SETUP="true" \ + -e ENABLE_ARCHIVELOG=true \ + --secret pwdsecret \ + --secret keysecret \ + -v /scratch/oradata/dbfiles/CATALOG:/opt/oracle/oradata \ + -v /opt/containers/shard_host_file:/etc/hosts \ + --privileged=false \ + --name catalog oracle/database-ext-sharding:23.5.0-ee +``` + +To check the catalog container/services creation logs, please tail podman logs. It will take 20 minutes to create the catalog container service. + +```bash +podman logs -f catalog +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Catalog database is ready to be used: + +```bash +============================================== + GSM Catalog Setup Completed +============================================== +``` + +## Deploying Shard Containers + +A database shard is a horizontal partition of data in a database or search engine. Each individual partition is referred to as a shard or database shard. You need to create mountpoint on podman host to save datafiles for Oracle Globally Distributed Database and expose as a volume to shard container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. + +For example: During the setup of this README.md, we used `/scratch/oradata/dbfiles/ORCL1CDB` directory and exposed as volume to shard container `shard1`. + +### Create Directories + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL1CDB +mkdir -p /scratch/oradata/dbfiles/ORCL2CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL1CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL2CDB +``` +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL1CDB +restorecon -v /scratch/oradata/dbfiles/ORCL1CDB +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL2CDB +restorecon -v /scratch/oradata/dbfiles/ORCL2CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL1CDB` and `/scratch/oradata/dbfiles/ORCL2CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/main/OracleDatabase/SingleInstance). + +### Shard1 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/ORCL1CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace following `--name shard1 oracle/database:23.5.0-ee` to `--name shard1 oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL1CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL1CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard1-0 \ + --dns-search=example.com \ + --network=shard_pub1_nw \ + --ip=10.0.20.103 \ + -e DOMAIN=example.com \ + -e ORACLE_SID=ORCL1CDB \ + -e ORACLE_PDB=ORCL1PDB \ + -e OP_TYPE=primaryshard \ + -e COMMON_OS_PWD_FILE=pwdsecret \ + -e PWD_KEY=keysecret \ + -e SHARD_SETUP="true" \ + -e ENABLE_ARCHIVELOG=true \ + --secret pwdsecret \ + --secret keysecret \ + -v /scratch/oradata/dbfiles/ORCL1CDB:/opt/oracle/oradata \ + -v /opt/containers/shard_host_file:/etc/hosts \ + --privileged=false \ + --name shard1 oracle/database-ext-sharding:23.5.0-ee +``` + +To check the shard1 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard1 container service. + +```bash +podman logs -f shard1 +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Shard2 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/ORCL2CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace following `--name shard2 oracle/database:23.5.0-ee` to `--name shard2 oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL2CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL2CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard2-0 \ + --dns-search=example.com \ + --network=shard_pub1_nw \ + --ip=10.0.20.104 \ + -e DOMAIN=example.com \ + -e ORACLE_SID=ORCL2CDB \ + -e ORACLE_PDB=ORCL2PDB \ + -e OP_TYPE=primaryshard \ + -e COMMON_OS_PWD_FILE=pwdsecret \ + -e PWD_KEY=keysecret \ + -e SHARD_SETUP="true" \ + -e ENABLE_ARCHIVELOG=true \ + --secret pwdsecret \ + --secret keysecret \ + -v /scratch/oradata/dbfiles/ORCL2CDB:/opt/oracle/oradata \ + -v /opt/containers/shard_host_file:/etc/hosts \ + --privileged=false \ + --name shard2 oracle/database-ext-sharding:23.5.0-ee +``` + +**Note**: You can add more shards based on your requirement. + +To check the shard2 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard2 container service + +```bash +podman logs -f shard2 +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Shard database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +## Deploying GSM Container + +The Global Data Services framework consists of at least one global service manager, a Global Data Services catalog, and the GDS configuration databases. You need to create mountpoint on podman host to save gsm setup related file for Oracle Global Service Manager and expose as a volume to GSM container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used /scratch/oradata/dbfiles/GSMDATA directory and exposed as volume to GSM container. + +### Create Directory for Master GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSMDATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSMDATA +``` +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSMDATA +restorecon -v /scratch/oradata/dbfiles/GSMDATA +``` + +### Master GSM Container + +```bash +podman run -d --hostname oshard-gsm1 \ + --dns-search=example.com \ + --network=shard_pub1_nw \ + --ip=10.0.20.100 \ + -e DOMAIN=example.com \ + -e SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" \ + -e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=primary;group_region=region1" \ + -e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2" \ + -e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" \ + -e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" \ + -e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" \ + -e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=primary" \ + -e COMMON_OS_PWD_FILE=pwdsecret \ + -e PWD_KEY=keysecret \ + --secret pwdsecret \ + --secret keysecret \ + -e SHARD_SETUP="true" \ + -v /scratch/oradata/dbfiles/GSMDATA:/opt/oracle/gsmdata \ + -v /opt/containers/shard_host_file:/etc/hosts \ + -e OP_TYPE=gsm \ + -e MASTER_GSM="TRUE" \ + --privileged=false \ + --name gsm1 oracle/database-gsm:23.5.0 +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, PRIMARY_SHARD_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm1 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm1 +============================================== + GSM Setup Completed +============================================== +``` + +## Deploying Standby GSM Container + +You need standby GSM container to serve the connection when master GSM fails. + +### Create Directory for Standby GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSM2DATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSM2DATA +``` +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSM2DATA +restorecon -v /scratch/oradata/dbfiles/GSM2DATA +``` +### Create Standby GSM Container + +```bash +podman run -d --hostname oshard-gsm2 \ + --dns-search=example.com \ + --network=shard_pub1_nw \ + --ip=10.0.20.101 \ + -e DOMAIN=example.com \ + -e SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region2;director_port=1522" \ + -e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=active_standby;group_region=region2" \ + -e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2" \ + -e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_group=shardgroup1" \ + -e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_group=shardgroup1" \ + -e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" \ + -e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" \ + -e CATALOG_SETUP="True" \ + -e COMMON_OS_PWD_FILE=pwdsecret \ + -e PWD_KEY=keysecret \ + --secret pwdsecret \ + --secret keysecret \ + -v /scratch/oradata/dbfiles/GSM2DATA:/opt/oracle/gsmdata \ + -v /opt/containers/shard_host_file:/etc/hosts \ + -e OP_TYPE=gsm \ + --privileged=false \ + --name gsm2 oracle/database-gsm:23.5.0 +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm2 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm2 +``` + +**IMPORTANT:** The GSM Container Image used in this case is having the Oracle GSM installed. On first startup of the container, a new GSM setup will be created and the following lines highlight when the GSM setup is ready to be used: + +```bash +============================================== + GSM Setup Completed +============================================== +``` + +## Scale-out an existing Oracle Globally Distributed Database + +If you want to Scale-Out an existing Oracle Globally Distributed Database already deployed using the Podman Containers, then you will to complete the steps in below order: + +- Complete the prerequisite steps before creating the Podman Container for the new shard to be added to the Oracle Globally Distributed Database +- Create the Podman Container for the new shard +- Add the new shard Database to the existing Oracle Globally Distributed Database +- Deploy the new shard + +The below example covers the steps to add a `new shard (shard3)` to an existing Oracle Globally Distributed Database which was deployed earlier in this page with `two shards (shard1 and shard2)`. + +### Complete the prerequisite steps before creating Podman Container for new shard + +Create the required directories for the new shard (shard3 in this case) container just like they were created for the earlier shards (shard1 and shard2): + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL3CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL3CDB +``` +If SELinux is enabled on podman host, then execute following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL3CDB +restorecon -v /scratch/oradata/dbfiles/ORCL3CDB +``` + +**Notes:** + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL3CDB` and `/scratch/oradata/dbfiles/ORCL3CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instace Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Podman Container for new shard + +Before creating new shard (shard3 in this case) container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change /scratch/oradata/dbfiles/ORCL3CDB based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace following `--name shard3 oracle/database:23.5.0-ee` to `--name shard3 oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL3CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL3CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard3-0 \ + --dns-search=example.com \ + --network=shard_pub1_nw \ + --ip=10.0.20.105 \ + -e DOMAIN=example.com \ + -e ORACLE_SID=ORCL3CDB \ + -e ORACLE_PDB=ORCL3PDB \ + -e OP_TYPE=primaryshard \ + -e COMMON_OS_PWD_FILE=pwdsecret \ + -e PWD_KEY=keysecret \ + -e SHARD_SETUP="true" \ + -e ENABLE_ARCHIVELOG=true \ + --secret pwdsecret \ + --secret keysecret \ + -v /scratch/oradata/dbfiles/ORCL3CDB:/opt/oracle/oradata \ + -v /opt/containers/shard_host_file:/etc/hosts \ + --privileged=false \ + --name shard3 oracle/database-ext-sharding:23.5.0-ee +``` + +To check the shard3 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard1 container service. + +```bash +podman logs -f shard3 +``` + +**IMPORTANT:** Like the earlier shards (shard1 and shard2), wait for the following lines highlight when the Shard3 database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Add the new shard Database to the existing Oracle Globally Distributed Database + +Use the below command to add the new shard3: +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --addshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" +``` + +Use the below command to check the status of the newly added shard: +``` bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard +``` + +### Deploy the new shard + +Deploy the newly added shard (shard3): + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deployshard=true +``` + +Use the below command to check the status of the newly added shard and the chunks distribution: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** The chunks redistribution after deploying the new shard may take some time to complete. + +## Scale-in an existing Oracle Globally Distributed Database + +If you want to Scale-in an existing Oracle Globally Distributed Database by removing a particular shard database out of the existing shard databases, then you will to complete the steps in below order: + +- Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database +- Move the chunks out of the shard database which you want to delete +- Delete the shard database from the Oracle Globally Distributed Database +- Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + + +### Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database + +Use the below commands to check the status of the shard which you want to delete and status of chunks present in this shard: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + + +### Move the chunks out of the shard database which you want to delete + +In the current example, if you want to delete the shard3 database from the Oracle Globally Distributed Database, then you need to use the below command to move the chunks out of shard3 database: + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --movechunks="shard_db=ORCL3CDB;shard_pdb=ORCL3PDB" +``` + +**NOTE:** In this case, `ORCL3CDB` and `ORCL3PDB` are the names of CDB and PDB for the shard3 respectively. + +After moving the chunks out, use the below command to confirm there is no chunk present in the shard database which you want to delete: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** You will need to wait for some time for all the chunks to move out of the shard database which you want to delete. If the chunks are still moving out, you can rerun the above command to check the status after some time. + + +### Delete the shard database from the Oracle Globally Distributed Database + +Once you have confirmed that no chunk is present in the shard to be deleted in earlier step, you can use the below command to delete that shard(shard3 in this case): + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deleteshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_group=shardgroup1" +``` + +**NOTE:** In this case, `oshard3-0`, `ORCL3CDB` and `ORCL3PDB` are the names of host, CDB and PDB for the shard3 respectively. + + +### Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + +Once the shard is deleted from the Oracle Globally Distributed Database, use the below commands to check the status of the shards and chunk distribution in the Oracle Globally Distributed Database: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Remove the Podman Container + +Once the shard is deleted from the Oracle Globally Distributed Database, you can remove the Podman Container which was deployed earlier for the deleted shard database. + +If the deleted shard was "shard3", to remove its Podman Container, please use the below steps: + +- Stop and remove the Docker Container for shard3: + +```bash +podman stop shard3 +podman rm shard3 +``` + +- Remove the directory containing the files for this deleted Podman Container: + +```bash +rm -rf /scratch/oradata/dbfiles/ORCL3CDB +``` + +## Environment Variables Explained + +**For catalog, shard containers-** +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| COMMON_OS_PWD_FILE | Specify the podman secret for the password file to be read inside the container | Mandatory | +| PWD_KEY | Specify the podman secret for the password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For Shards it has to be set to primaryshard or standbyshard | Mandatory | +| DOMAIN | Specify the domain name | Mandatory | +| ORACLE_SID | CDB name | Mandatory | +| ORACLE_PDB | PDB name | Mandatory | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts which you want to run after setting up shard setup. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name that must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after shard db setup. | Optional | +| CLONE_DB | Specify value "true" if you want to avoid db creation using DBCA and clone it from cold backup of existing Oracle DB. This DB must not have shard setup. Shard script will look for the backup at /opt/oracle/oradata. | Optional | +| OLD_ORACLE_SID | Specify the OLD_ORACLE_SID if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | +| OLD_ORACLE_PDB | Specify the OLD_ORACLE_PDB if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | + + +**For GSM Containers-** +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| CATALOG_SETUP | Accept True. If set then, it will just create gsm director and add catalog but will not add any shard | Mandatory | +| CATALOG_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=catalog_host, value=catalog hostname;key=catalog_db, value=catalog cdb name;key=catalog_pdb, value=catalog pdb name;key=catalog_port, value=catalog db port name;key=catalog_name, value=catalog name in GSM;key=catalog_region, value=specify comma separated region name for catalog db deployment | Mandatory | +| SHARD_DIRECTOR_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=director_name, value=shard director name;key=director_region, value=shard director region;key=director_port, value=shard director port | Mandatory | +| SHARD[1-9]_GROUP_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=group_name, value=shard group name;key=deploy_as, value=deploy shard group as primary or standby or active_standby;key=group_region, value=shard group region name | Mandatory | +| SHARD[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=shard_host, value=shard hostname; key=shard_db, value=shard cdb name; key=shard_pdb, value=shard pdb name; key=shard_port, value=shard db port;key=shard_group value=shard group name | Mandatory | +| SERVICE[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=service_name, value=service name;key=service_role, value=service role e.g. primary or physical_standby | Mandatory | +| COMMON_OS_PWD_FILE | Specify the podman secret for the password file to be read inside the container | Mandatory | +| PWD_KEY | Specify the podman secret for the password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For GSM, it has to be set to gsm. | Mandatory | +| DOMAIN | Domain of the container. | Mandatory | +| MASTER_GSM | Set value to "TRUE" if you want the GSM to be a master GSM. Otherwise, do not set it. | Mandatory | +| SAMPLE_SCHEMA | Specify a value to "DEPLOY" if you want to deploy sample app schema in catalog DB during GSM setup. | Optional | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts that you want to run after setting up GSM. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name which must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after GSM setup. | Optional | +| BASE_DIR | Specify BASE_DIR if you want to change the base location of the scripts to setup GSM. | Optional | +| SCRIPT_NAME | Specify the script name which will be executed from BASE_DIR. Default set to main.py. | Optional | +| EXECUTOR | Specify the script executor such as /bin/python or /bin/bash. Default set to /bin/python. | Optional | + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + + +## License + +To run Oracle Globally Distributed Database, regardless whether inside or outside a Container, ensure to download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-user-defined-sharding.md b/container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-user-defined-sharding.md new file mode 100644 index 0000000..793ebd2 --- /dev/null +++ b/container-based-sharding-deployment/samples/container-files/podman-container-files/podman-sharded-database-with-user-defined-sharding.md @@ -0,0 +1,618 @@ +# Deploy Oracle Globally Distributed Database with User-Defined Sharding using Podman Containers + +This page covers the steps to manually deploy a sample Oracle Globally Distributed Database with User-Defined Sharding using Podman Containers. + +- [Setup Details](#setup-details) +- [Prerequisites](#prerequisites) +- [Deploying Catalog Container](#deploying-catalog-container) + - [Create Directory](#create-directory) + - [Create Container](#create-container) +- [Deploying Shard Containers](#deploying-shard-containers) + - [Create Directories](#create-directories) + - [Shard1 Container](#shard1-container) + - [Shard2 Container](#shard2-container) +- [Deploying GSM Container](#deploying-gsm-container) + - [Create Directory for Master GSM Container](#create-directory-for-master-gsm-container) + - [Create Master GSM Container](#create-master-gsm-container) +- [Deploying Standby GSM Container](#deploying-standby-gsm-container) + - [Create Directory for Standby GSM Container](#create-directory-for-standby-gsm-container) + - [Create Standby GSM Container](#create-standby-gsm-container) +- [Scale-out an existing Oracle Globally Distributed Database](#scale-out-an-existing-oracle-globally-distributed-database) + - [Complete the prerequisite steps before creating Podman Container for new shard](#complete-the-prerequisite-steps-before-creating-podman-container-for-new-shard) + - [Create Podman Container for new shard](#create-podman-container-for-new-shard) + - [Add the new shard Database to the existing Oracle Globally Distributed Database](#add-the-new-shard-database-to-the-existing-oracle-globally-distributed-database) + - [Deploy the new shard](#deploy-the-new-shard) + - [Move chunks](#move-chunks) +- [Scale-in an existing Oracle Globally Distributed Database](#scale-in-an-existing-oracle-globally-distributed-database) + - [Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database](#confirm-the-shard-to-be-deleted-is-present-in-the-list-of-shards-in-the-oracle-globally-distributed-database) + - [Move the chunks out of the shard database which you want to delete](#move-the-chunks-out-of-the-shard-database-which-you-want-to-delete) + - [Delete the shard database from the Oracle Globally Distributed Database](#delete-the-shard-database-from-the-oracle-globally-distributed-database) + - [Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database](#confirm-the-shard-has-been-successfully-deleted-from-the-oracle-globally-distributed-database) + - [Remove the Podman Container](#remove-the-podman-container) +- [Environment Variables Explained](#environment-variables-explained) +- [Support](#support) +- [License](#license) +- [Copyright](#copyright) + + +## Setup Details + +This setup involves deploying podman containers for: + +* Catalog Database +* Two Shard Databases +* Primary GSM +* Standby GSM + +**NOTE:** You can use Oracle 21c or Oracle 23ai RDBMS and GSM Podman Images for this sample deployment. + +**NOTE:** In the current Sample Oracle Globally Distributed Database Deployment, we have used Oralce 23ai RDBMS and GSM Podman Images. + +## Prerequisites + +Before using this page to create a sample Oracle Globally Distributed Database, please complete the prerequisite steps mentioned in [Oracle Globally Distributed Database Containers on Podman](./README.md#prerequisites) + +Before creating the GSM container, you need to build the catalog and shard containers. Execute the following steps to create containers for the deployment: + +## Deploying Catalog Container + +The shard catalog is a special-purpose Oracle Database that is a persistent store for SDB configuration data and plays a key role in the automated deployment and centralized management of a Oracle Globally Distributed Database. It also hosts the gold schema of the application and the master copies of common reference data (duplicated tables) + +### Create Directory + +You need to create mountpoint on the podman host to save datafiles for Oracle Sharding Catalog DB and expose as a volume to catalog container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this sample Oracle Globally Distributed Database, we used `/scratch/oradata/dbfiles/CATALOG` directory and exposed as volume to catalog container. + +```bash +mkdir -p /scratch/oradata/dbfiles/CATALOG +chown -R 54321:54321 /scratch/oradata/dbfiles/CATALOG +``` + +* If SELinux is enabled on podman host, then execute the following- + +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/CATALOG +restorecon -v /scratch/oradata/dbfiles/CATALOG +semanage fcontext -a -t container_file_t /opt/containers/shard_host_file +restorecon -v /opt/containers/shard_host_file +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/CATALOG` exposed to catalog container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instance Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Container + +Before creating catalog container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change `/scratch/oradata/dbfiles/CATALOG` based on your enviornment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID enviornment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name catalog oracle/database:23.5.0-ee` with `--name catalog oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/CATALOG` must contain the DB backup and it must not be in zipped format. E.g. `/scratch/oradata/dbfiles/CATALOG/SEEDCDB` where SEEDCDB is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard-catalog-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.102 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=CATCDB \ +-e ORACLE_PDB=CAT1PDB \ +-e OP_TYPE=catalog \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /scratch/oradata/dbfiles/CATALOG:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name catalog oracle/database-ext-sharding:23.5.0-ee +``` + +To check the catalog container/services creation logs, please tail podman logs. It will take 20 minutes to create the catalog container service. + +```bash +podman logs -f catalog +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Catalog database is ready to be used: + +```bash +============================================== + GSM Catalog Setup Completed +============================================== +``` + +## Deploying Shard Containers + +A database shard is a horizontal partition of data in a database or search engine. Each individual partition is referred to as a shard or database shard. You need to create mountpoint on podman host to save datafiles for Oracle Globally Distributed Database and expose as a volume to shard container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. + +For example: During the setup of this README.md, we used `/scratch/oradata/dbfiles/ORCL1CDB` directory and exposed as volume to shard container `shard1`. + +### Create Directories + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL1CDB +mkdir -p /scratch/oradata/dbfiles/ORCL2CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL1CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL2CDB +``` +If SELinux is enabled on podman host, then execute the following- +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL1CDB +restorecon -v /scratch/oradata/dbfiles/ORCL1CDB +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL2CDB +restorecon -v /scratch/oradata/dbfiles/ORCL2CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL1CDB` and `/scratch/oradata/dbfiles/ORCL2CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instace Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Shard1 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change `/scratch/oradata/dbfiles/ORCL1CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard1 oracle/database:23.5.0-ee` with `--name shard1 oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL1CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL1CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard1-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.103 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL1CDB \ +-e ORACLE_PDB=ORCL1PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /oradata/dbfiles/ORCL1CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard1 oracle/database-ext-sharding:23.5.0-ee +``` + +To check the shard1 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard1 container service. + +```bash +podman logs -f shard1 +``` + +### Shard2 Container + +Before creating shard1 container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change `/scratch/oradata/dbfiles/ORCL2CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard2 oracle/database:23.5.0-ee` with `--name shard2 oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL2CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL2CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard2-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.104 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL2CDB \ +-e ORACLE_PDB=ORCL2PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /oradata/dbfiles/ORCL2CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard2 oracle/database-ext-sharding:23.5.0-ee +``` + +**Note**: You can add more shards based on your requirement. + +To check the shard2 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard2 container service + +```bash +podman logs -f shard2 +``` + +**IMPORTANT:** The Database Container Image used in this case is having the Oracle Database binaries installed. On first startup of the container, a new database will be created and the following lines highlight when the Shard database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +## Deploying GSM Container + +The Global Data Services framework consists of at least one global service manager, a Global Data Services catalog, and the GDS configuration databases. You need to create mountpoint on podman host to save gsm setup related file for Oracle Global Service Manager and expose as a volume to GSM container. This volume can be local on a podman host or exposed from your central storage. It contains a file system such as EXT4. During the setup of this README.md, we used `/scratch/oradata/dbfiles/GSMDATA` directory and exposed as volume to GSM container. + +### Create Directory for Master GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSMDATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSMDATA +``` + +If SELinux is enabled on podman host, then execute the following- + +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSMDATA +restorecon -v /scratch/oradata/dbfiles/GSMDATA +``` + +### Create Master GSM Container + +```bash +podman run -d --hostname oshard-gsm1 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.100 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector1;director_region=region1;director_port=1522" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;sharding_type=USER;shard_space=shardspace1,shardspace2" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_space=shardspace1;deploy_as=primary;shard_region=region1" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_space=shardspace2;deploy_as=primary;shard_region=region2" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=primary" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=primary" \ +-e SHARD_SETUP="true" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e OP_TYPE=gsm \ +-e MASTER_GSM="TRUE" \ +--secret pwdsecret \ +--secret keysecret \ +-v /oradata/dbfiles/GSMDATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name gsm1 oracle/database-gsm:23.5.0 +``` + +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, PRIMARY_SHARD_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm1 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm1 +``` + +## Deploying Standby GSM Container + +You need standby GSM container to serve the connection when master GSM fails. + +### Create Directory for Standby GSM Container + +```bash +mkdir -p /scratch/oradata/dbfiles/GSM2DATA +chown -R 54321:54321 /scratch/oradata/dbfiles/GSM2DATA +``` + +If SELinux is enabled on podman host, then execute the following- + +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/GSM2DATA +restorecon -v /scratch/oradata/dbfiles/GSM2DATA +``` + +### Create Standby GSM Container + +```bash +podman run -d --hostname oshard-gsm2 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.101 \ +-e DOMAIN=example.com \ +-e SHARD_DIRECTOR_PARAMS="director_name=sharddirector2;director_region=region2;director_port=1522" \ +-e CATALOG_PARAMS="catalog_host=oshard-catalog-0;catalog_db=CATCDB;catalog_pdb=CAT1PDB;catalog_port=1521;catalog_name=shardcatalog1;catalog_region=region1,region2;sharding_type=USER;shard_space=shardspace1,shardspace2" \ +-e SHARD1_PARAMS="shard_host=oshard1-0;shard_db=ORCL1CDB;shard_pdb=ORCL1PDB;shard_port=1521;shard_space=shardspace1;" \ +-e SHARD2_PARAMS="shard_host=oshard2-0;shard_db=ORCL2CDB;shard_pdb=ORCL2PDB;shard_port=1521;shard_space=shardspace2;" \ +-e SERVICE1_PARAMS="service_name=oltp_rw_svc;service_role=standby" \ +-e SERVICE2_PARAMS="service_name=oltp_ro_svc;service_role=standby" \ +-e CATALOG_SETUP="True" \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e OP_TYPE=gsm \ +--secret pwdsecret \ +--secret keysecret \ +-v /oradata/dbfiles/GSM2DATA:/opt/oracle/gsmdata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name gsm2 oracle/database-gsm:23.5.0 +``` +**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. + +To check the gsm2 container/services creation logs, please tail podman logs. It will take 2 minutes to create the gsm container service. + +```bash +podman logs -f gsm2 +``` + +**IMPORTANT:** The GSM Container Image used in this case is having the Oracle GSM installed. On first startup of the container, a new GSM setup will be created and the following lines highlight when the GSM setup is ready to be used: + +```bash +============================================== + GSM Setup Completed +============================================== +``` + +**NOTE:** Once the Oracle Globally Distributed Database Deployment is complete using Used-Defined Sharding, you can load the data into this Oracle Globally Distributed Database. + +## Scale-out an existing Oracle Globally Distributed Database + +If you want to Scale-Out an existing Oracle Globally Distributed Database already deployed using the Podman Containers, then you will to complete the steps in below order: + +- Complete the prerequisite steps before creating the Podman Container for the new shard to be added to the Oracle Globally Distributed Database +- Create the Podman Container for the new shard +- Add the new shard Database to the existing Oracle Globally Distributed Database +- Deploy the new shard +- Move chunks + +The below example covers the steps to add a new shard (shard3) to an existing Oracle Globally Distributed Database which was deployed earlier in this page with two shards (shard1 and shard2). + +### Complete the prerequisite steps before creating Podman Container for new shard + +Create the required directories for the new shard (shard3 in this case) container just like they were created for the earlier shards (shard1 and shard2): + +```bash +mkdir -p /scratch/oradata/dbfiles/ORCL3CDB +chown -R 54321:54321 /scratch/oradata/dbfiles/ORCL3CDB +``` + +If SELinux is enabled on podman host, then execute the following- + +```bash +semanage fcontext -a -t container_file_t /scratch/oradata/dbfiles/ORCL3CDB +restorecon -v /scratch/oradata/dbfiles/ORCL3CDB +``` + +**Notes:**: + +* Change the ownership for data volume `/scratch/oradata/dbfiles/ORCL3CDB` exposed to shard container as it has to be writable by oracle "oracle" (uid: 54321) user inside the container. +* If this is not changed then database creation will fail. For details, please refer, [oracle/docker-images for Single Instace Database](https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). + +### Create Podman Container for new shard + +Before creating new shard (shard3 in this case) container, review the following notes carefully: + +**Notes:** + +* Change environment variable such as ORACLE_SID, ORACLE_PDB based on your env. +* Change `/scratch/oradata/dbfiles/ORCL3CDB` based on your environment. +* By default, Oracle Globally Distributed Database setup creates new database under `/opt/oracle/oradata` based on ORACLE_SID environment variable. +* If you are planing to perform seed cloning to expedite the Oracle Globally Distributed Database setup using existing cold DB backup, you need to replace `--name shard3 oracle/database:23.5.0-ee` with `--name shard3 oracle/database:23.5.0-ee /opt/oracle/scripts/setup/runOraShardSetup.sh` + * In this case, `/scratch/oradata/dbfiles/ORCL3CDB` must contain the DB backup and it must not be zipped. E.g. `/scratch/oradata/dbfiles/ORCL3CDB/SEEDCDB` where `SEEDCDB` is the cold backup and contains datafiles and PDB. + +```bash +podman run -d --hostname oshard3-0 \ +--dns-search=example.com \ +--network=shard_pub1_nw \ +--ip=10.0.20.105 \ +-e DOMAIN=example.com \ +-e ORACLE_SID=ORCL3CDB \ +-e ORACLE_PDB=ORCL3PDB \ +-e OP_TYPE=primaryshard \ +-e COMMON_OS_PWD_FILE=pwdsecret \ +-e PWD_KEY=keysecret \ +-e SHARD_SETUP="true" \ +-e ENABLE_ARCHIVELOG=true \ +--secret pwdsecret \ +--secret keysecret \ +-v /oradata/dbfiles/ORCL3CDB:/opt/oracle/oradata \ +-v /opt/containers/shard_host_file:/etc/hosts \ +--privileged=false \ +--name shard3 oracle/database-ext-sharding:23.5.0-ee +``` + +To check the shard3 container/services creation logs, please tail podman logs. It will take 20 minutes to create the shard1 container service. + +```bash +podman logs -f shard3 +``` + +**IMPORTANT:** Like the earlier shards (shard1 and shard2), wait for the following lines highlight when the Shard3 database is ready to be used: + +```bash +============================================== + GSM Shard Setup Completed +============================================== +``` + +### Add the new shard Database to the existing Oracle Globally Distributed Database + +Use the below command to add the new shard3: +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --addshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_space=shardspace3;shard_region=region3" +``` + +Use the below command to check the status of the newly added shard: +``` bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard +``` + +### Deploy the new shard + +Deploy the newly added shard (shard3): + +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deployshard=true +``` + +Use the below command to check the status of the newly added shard and the chunks distribution: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Move chunks + +In case you want to move some chunks to the newly added Shard from an existing Shard, you can use the below command: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK $CHUNK_ID -SOURCE $SOURCE_SHARD -TARGET $TARGET_SHARD +``` + +Example: If you want to move the chunk with chunk id `3` from source shard `ORCL1CDB_ORCL1PDB` to target shard `ORCL3CDB_ORCL3PDB`, then you can use the below command: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK 3 -SOURCE ORCL1CDB_ORCL1PDB -TARGET ORCL3CDB_ORCL3PDB +``` + +Use the below command to check the status of the chunks distribution: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +## Scale-in an existing Oracle Globally Distributed Database + +If you want to Scale-in an existing Oracle Globally Distributed Database by removing a particular shard database out of the existing shard databases, then you will to complete the steps in below order: + +- Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database +- Move the chunks out of the shard database which you want to delete +- Delete the shard database from the Oracle Globally Distributed Database +- Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + + +### Confirm the shard to be deleted is present in the list of shards in the Oracle Globally Distributed Database + +Use the below commands to check the status of the shard which you want to delete and status of chunks present in this shard: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + + +### Move the chunks out of the shard database which you want to delete + +In the current example, if you want to delete the shard3 database from the Oracle Globally Distributed Database, then you need to use the below command to move the chunks out of shard3 database: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK $CHUNK_ID -SOURCE $SOURCE_SHARD -TARGET $TARGET_SHARD +``` + +Example: If you want to move the chunk with chunk id `3` from source shard `ORCL3CDB_ORCL3PDB` to target shard `ORCL1CDB_ORCL1PDB`, then you can use the below command: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl MOVE CHUNK -CHUNK 3 -SOURCE ORCL3CDB_ORCL3PDB -TARGET ORCL1CDB_ORCL1PDB +``` + +**NOTE:** To move more than 1 chunk, you can specify comma separated chunk ids. + +After moving the chunks out, use the below command to confirm there is no chunk present in the shard database which you want to delete: +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +**NOTE:** You will need to wait for some time for all the chunks to move out of the shard database which you want to delete. + +### Delete the shard database from the Oracle Globally Distributed Database + +Once you have confirmed that no chunk is present in the shard to be deleted in earlier step, you can use the below command to delete that shard(shard3 in this case): +```bash +podman exec -it gsm1 python /opt/oracle/scripts/sharding/scripts/main.py --deleteshard="shard_host=oshard3-0;shard_db=ORCL3CDB;shard_pdb=ORCL3PDB;shard_port=1521;shard_space=shardspace3;shard_region=region3" +``` + +**NOTE:** In this case, `oshard3-0`, `ORCL3CDB` and `ORCL3PDB` are the names of host, CDB and PDB for the shard3 respectively. + + +### Confirm the shard has been successfully deleted from the Oracle Globally Distributed Database + +Once the shard is deleted from the Oracle Globally Distributed Database, use the below commands to check the status of the shards and chunk distribution in the Oracle Globally Distributed Database: + +```bash +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config shard + +podman exec -it gsm1 $(podman exec -it gsm1 env | grep ORACLE_HOME | cut -d= -f2 | tr -d '\r')/bin/gdsctl config chunks +``` + +### Remove the Podman Container + +Once the shard is deleted from the Oracle Globally Distributed Database, you can remove the Podman Container which was deployed earlier for the deleted shard database. + +If the deleted shard was `shard3`, to remove its Podman Container, please use the below steps: + +- Stop and remove the Docker Container for shard3: +```bash +podman stop shard3 +podman rm shard3 +``` + +- Remove the directory containing the files for this deleted Podman Container: +```bash +rm -rf /scratch/oradata/dbfiles/ORCL3CDB +``` + +## Environment Variables Explained + +**For catalog, shard containers-** +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| COMMON_OS_PWD_FILE | Specify the podman secret for the password file to be read inside the container | Mandatory | +| PWD_KEY | Specify the podman secret for the password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For Shards it has to be set to primaryshard or standbyshard | Mandatory | +| DOMAIN | Specify the domain name | Mandatory | +| ORACLE_SID | CDB name | Mandatory | +| ORACLE_PDB | PDB name | Mandatory | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts which you want to run after setting up shard setup. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name that must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after shard db setup. | Optional | +| CLONE_DB | Specify value "true" if you want to avoid db creation and clone it from cold backup of existing Oracle DB. This DB must not have shard setup. Shard script will look for the backup at /opt/oracle/oradata. | Optional | +| OLD_ORACLE_SID | Specify the OLD_ORACLE_SID if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | +| OLD_ORACLE_PDB | Specify the OLD_ORACLE_PDB if you are performing db seed cloning using existing cold backup of Oracle DB. | Optional | + +**For GSM Containers-** + +| Parameter | Description | Mandatory/Optional | +|----------------------------|----------------------------------------------------------------------------------------------------------------|---------------------| +| CATALOG_SETUP | Accept True. if set then , it will only restrict till catalog connection and setup. | Mandatory | +| CATALOG_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=catalog_host, value=catalog hostname; key=catalog_db, value=catalog cdb name; key=catalog_pdb, value=catalog pdb name; key=catalog_port, value=catalog db port name; key=catalog_name, value=catalog name in GSM; key=catalog_region, value=specify comma separated region name for catalog db deployment | Mandatory | +| SHARD_DIRECTOR_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=director_name, value=shard director name; key=director_region, value=shard director region; key=director_port, value=shard director port | Mandatory | +| SHARD[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=shard_host, value=shard hostname key=shard_db, value=shard cdb name key=shard_pdb, value=shard pdb name key=shard_port, value=shard db port key=shard_space, value=shard space name key=deploy_as, value=primary or standby key=shard_region, value=region name | Mandatory | +| SERVICE[1-9]_PARAMS | Accept key value pair separated by semicolon e.g. key1=value1;key2=value2 for following key=value pairs: key=service_name, value=service name; key=service_role, value=service role e.g. primary or physical_standby | Mandatory | +| COMMON_OS_PWD_FILE | Specify the encrypted password file to be read inside container | Mandatory | +| PWD_KEY | Specify the podman secret for the password key file to decrypt the encrypted password file and read the password | Mandatory | +| OP_TYPE | Specify the operation type. For GSM it has to be set to gsm. | Mandatory | +| DOMAIN | Domain of the container. | Mandatory | +| MASTER_GSM | Set value to "TRUE" if you want the GSM to be a master GSM. Otherwise, do not set it. | Mandatory | +| SAMPLE_SCHEMA | Specify a value to "DEPLOY" if you want to deploy sample app schema in catalog DB during GSM setup. | Optional | +| CUSTOM_SHARD_SCRIPT_DIR | Specify the location of custom scripts that you want to run after setting up GSM. | Optional | +| CUSTOM_SHARD_SCRIPT_FILE | Specify the file name which must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after GSM setup. | Optional | +| BASE_DIR | Specify BASE_DIR if you want to change the base location of the scripts to setup GSM. | Optional | +| SCRIPT_NAME | Specify the script name which will be executed from BASE_DIR. Default set to main.py. | Optional | +| EXECUTOR | Specify the script executor such as /bin/python or /bin/bash. Default set to /bin/python. | Optional | + +## Support + +Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + + +## License + +To run Oracle Globally Distributed Database, regardless whether inside or outside a Container, ensure to download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file From 4c215255199b710f5594ca472ace51f6975648aa Mon Sep 17 00:00:00 2001 From: Saurabh Ahuja <saurabh.ahuja@oracle.com> Date: Thu, 29 Aug 2024 15:53:44 +0000 Subject: [PATCH 2/3] pick latest changes --- README.md | 237 ++++++++++++------ .../containerfiles/23.4.0/Containerfile | 2 +- .../containerfiles/23.5.0/Containerfile | 2 +- 3 files changed, 164 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 0ec9203..f583929 100644 --- a/README.md +++ b/README.md @@ -1,114 +1,201 @@ -# Oracle Sharding tools and deployment automation library +# Oracle Globally Distributed Database in Linux Containers -[SDB-terraform-onprem]: https://github.com/oracle/db-sharding/tree/master/deployment-with-terraform/sdb-terraform-onprem -[SDB-terraform-oci]: https://github.com/oracle/db-sharding/tree/master/deployment-with-terraform/sdb-terraform-oci -[SDB-terraform]: https://github.com/oracle/db-sharding/tree/master/deployment-with-terraform/ -[SDB-Mid-Tier-Routing]: https://github.com/oracle/db-sharding/tree/master/Mid-Tier-Routing -[SDB-Fast-Data-Ingest]: https://github.com/oracle/db-sharding/tree/master/sharding-fast-data-ingest -[OKE-sharding]: https://github.com/oracle/db-sharding/tree/master/oke-based-sharding-deployment -[DOCKER-sharding]: https://github.com/oracle/db-sharding/tree/master/docker-based-sharding-deployment -[MTR-Intro]: https://github.com/oracle/db-sharding/wiki/Sharded-Database-Mid-Tier-Routing#introduction -[SDB-prod-page]: https://www.oracle.com/database/technologies/high-availability/sharding.html -[SDB-prod-doc]: https://docs.oracle.com/en/database/oracle/oracle-database/19/shard/ -[OCI]: https://www.oracle.com/cloud/ -[SDB]: https://www.oracle.com/database/technologies/high-availability/sharding.html +Learn about container deployment options for Oracle Globally Distributed Database in Linux Containers Release 23ai (v23.5). + +## Overview of Oracle Globally Distributed Database in Linux Containers + +Oracle Globally Distributed Database is a scalability and availability feature for custom-designed OLTP applications that enables the distribution and replication of data across a pool of Oracle Databases that do not share hardware or software. The pool of databases is presented to the application as a single logical database. + +This project provides sample container files to facilitate installation, configuration, and environment setup for DevOps users. For more information about Oracle Database, see: [Oracle Globally Distributed Database Management Documentation](http://docs.oracle.com/en/database/). -- [About](#about) -- [Terraform based deployment of Oracle sharded database](#terraform-based-deployment-of-oracle-sharded-database) - * [Overview](#overview) - * [Details](#details) -- [Mid-tier routing for use in Oracle sharded database client applications](#mid-tier-routing-for-use-in-oracle-sharded-database-client-applications) - * [Overview](#overview-1) - * [Details](#details-1) -- [OKE based deployment of Oracle sharded database](#oke-based-deployment-of-oracle-sharded-database) - * [Overview](#overview-2) - * [Details](#details-2) -- [Docker based deployment of Oracle sharded database](#docker-based-deployment-of-oracle-sharded-database) - * [Overview](#overview-3) - * [Details](#details-3) -- [Sharding Fast Data Ingest](#routing-implementations-for-use-in-oracle-sharding-client-applications) - * [Overview](#overview-4) - * [Details](#details-4) +Review each of the sections of this README in the order given. After reviewing each section of the README, you can skip the image or container creation sections that do not apply to you. + +This project offers example container files for the following: -## About +* Oracle Database 23ai Global Service Manager (GSM/GDS) (23.5.0) for Linux x86-64 +* Older Releases: Oracle 19c (19.3) and Oracle 21c (21.3) for Linux x86-64 -This repository provides Oracle Sharded database deployment automation and tools : -* Terraform based deployment of Oracle sharded database. -* Mid-tier routing for use in Oracle sharded database applications. -* OKE based deployment of Oracle sharded database. -* Fast data ingest for sharding applications. +## Using this Documentation +To create an Oracle Globally Distributed Database Container environment, follow these steps: -If you want to learn more about Oracle sharding a.k.a Oracle Sharded Database, please refer to the [product page][SDB-prod-page] and [product documentation][SDB-prod-doc]. +- [Oracle Globally Distributed Database in Linux Containers](#oracle-globally-distributed-database-in-linux-containers) + - [Overview of Oracle Globally Distributed Database in Linux Containers](#overview-of-oracle-globally-distributed-database-in-linux-containers) + - [Using this Documentation](#using-this-documentation) + - [Preparation Steps for running Oracle Globally Distributed Database in Linux Containers](#preparation-steps-for-running-oracle-globally-distributed-database-in-linux-containers) + - [QuickStart](#quickstart) + - [Building Oracle Globally Distributed Database Container Images](#building-oracle-globally-distributed-database-container-images) + - [Building Oracle Global Service Manager Image](#building-oracle-global-service-manager-image) + - [Building Oracle Database Image](#building-oracle-database-image) + - [Building Extended Oracle Database Image with Oracle Globally Distributed Database Feature](#building-extended-oracle-database-image-with-globally-distributed-database-feature) + - [Oracle Globally Distributed Database in Containers Deployment Scenarios](#oracle-globally-distributed-database-in-containers-deployment-scenarios) + - [Deploy Oracle Globally Distributed Database Containers](#deploy-oracle-database-globally-distributed-database-containers) + - [Deploy Oracle Globally Distributed Database Containers on Podman](#deploy-oracle-globally-distributed-database-containers-on-podman) + - [Deploy Oracle Globally Distributed Database Containers on Docker](#deploy-oracle-globally-distributed-database-containers-on-docker) + - [Deploy Oracle Globally Distributed Database Containers on Podman using Oracle 23ai FREE Images](#deploy-oracle-globally-distributed-database-containers-on-podman-using-oracle-23ai-free-images) + - [Oracle Globally Distributed Database in Containers Deployment using docker-compose](#oracle-globally-distributed-database-in-containers-deployment-using-docker-compose) + - [Oracle Globally Distributed Database in Containers Deployment using podman-compose](#oracle-globally-distributed-database-in-containers-deployment-using-podman-compose) + - [Support](#support) + - [License](#license) + - [Copyright](#copyright) + +## Preparation Steps for running Oracle Globally Distributed Database in Linux Containers +**Note :** All Steps or Commands in this guide must be run as `root` or with a `sudo` user. +* Before you proceed, complete the following prerequisites for your platform: + * If you are using Oracle Linux 7, then install Docker. + * If you are using an Oracle Linux 7 system, then you must install [Docker Engine](https://docs.oracle.com/en/operating-systems/oracle-linux/docker/). + * Install `docker-engine` and `docker-cli` using yum command. + ```bash + yum-config-manager --enable ol7_addons + yum install docker-engine docker-cli + yum start docker + systemctl enable --now docker + ``` + * If you are using Oracle Linux 8, then Install Podman. + * You must install and configure [Podman release 4.6.1 or later](https://docs.oracle.com/en/learn/intro_podman/index.html#introduction) or later on Oracle Linux 8.9 or later to run Oracle Globally Distributed Database on Podman. + * You need to install `podman-docker` utility using dnf command. + ```bash + # Enable the Oracle Linux 8 AppStream repository + dnf config-manager --enable ol8_appstream -<strong> Note </strong> : Oracle Sharding and Oracle Sharded Database (SDB) are interchangeably used names in the documentation and refer to the same entity. + # Install Podman and Podman-docker + dnf install -y podman podman-docker + ``` + * If SELinux is enabled on podman host, then install the following package as well: + ```bash + dnf install -y selinux-policy-devel + ``` - -## Terraform based deployment of Oracle sharded database +## QuickStart +Oracle recommends that you start with the Quickstart to become familiar with Oracle Globally Distributed Database in Linux Containers. See: [QuickStart documentation](./docs/QUICKSTART.md). -### Overview +After you become familiar with Oracle Globally Distributed Database in Linux Containers, you can explore more advanced setups, deployments, features, and so on, as explained in detail in [Oracle Globally Distributed Database in Containers Deployment Scenarios](#oracle-globally-distributed-database-in-containers-deployment-scenarios). -Provides Terraform modules, configuration and scripts that provisions the necessary components and resources for a quick and easy setup of [Oracle Sharded Database][SDB] (SDB) on either [Oracle Cloud Infrastructure][OCI] (OCI) or On-Premise. It creates and configures SDB infrastructure components necessary for a successful Sharded Database setup, such as Oracle Shard Director(s), Shard Catalog(s), Shard(s) and optionally Shard Standby(s) as well as Catalog standby using Data Guard for replication to provide high-availability and/or disaster recovery of the sharded data. +**Note:** +* Ensure that you have enough space in `/var/lib/containers` while building the Oracle Globally Distributed Database images. Also, if required use `export TMPDIR=</path/to/tmpdir>` for Podman to refer to any other folder as the temporary podman cache location instead of the default `/tmp` location. -### Details +## Building Oracle Globally Distributed Database Container Images -For more details, please refer to the [SDB-Terraform][SDB-terraform] documentation. +To assist with building the images, you can use the [buildContainerImage.sh](containerfiles/buildContainerImage.sh) script. -## Mid-tier routing for use in Oracle sharded database client applications +**IMPORTANT:** Oracle Global Service Manager (GDS) container is useful when you want to configure the Global Data Service Framework. A Global Data Services framework consists of at least one global service manager, a Global Data Services catalog, and the GDS configuration databases. -### Overview +### Building Oracle Global Service Manager Image -Please refer to the Sharded database [Mid-Tier Routing introduction][MTR-Intro] for an overview. +**IMPORTANT:** To create an Oracle Global Service Manager image (GSM image), you must provide the installation binaries of `Oracle Global Service Manager Oracle Database 23ai (23.5) for Linux x86-64` and put them into the `containerfiles/<version>` folder. You only need to provide the binaries for the edition you are going to install. The binaries can be downloaded from the [Oracle Technology Network](http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html). You must ensure that you have internet connectivity for the DNF package manager. -### Details +**Note:** Do not uncompress the binaries. -For more details, please refer to the [SDB Mid-Tier routing][SDB-Mid-Tier-Routing] documentation. +The `buildContainerImage.sh` script is just a utility shell script that performs MD5 checks. This script provides an easy way for beginners to get started. Expert users can directly call `podman build` with their preferred set of parameters. Before you build the image, ensure that you have provided the installation binaries and put them into the right folder. Go into the **containerfiles** folder and run the **buildContainerImage.sh** script as `root` or with `sudo` privileges: -## OKE based deployment of Oracle sharded database +```bash +./buildContainerImage.sh -v (Software Version) +./buildContainerImage.sh -v 23.5.0 +``` -### Overview +For detailed usage information for `buildContainerImage.sh`, run the following command: -Oracle Kubernetes Engine (OKE) based deployment of sharded database. +```bash +./buildContainerImage.sh -h +Usage: buildContainerImage.sh -v [version] -t [image_name:tag] [-e | -s] [-i] [-o] [container build option] +It builds a container image for a DNS server -### Details +Parameters: + -v: version to build + -i: ignores the MD5 checksums + -t: user defined image name and tag (e.g., image_name:ta + -o: passes on container build option (e.g., --build-arg SLIMMIMG=true for slim) -For more details, please refer to the [OKE sharding][OKE-sharding] documentation. +LICENSE UPL 1.0 -## Docker based deployment of Oracle sharded database +Copyright (c) 2014,2024 Oracle and/or its affiliates. +``` -### Overview +### Building Oracle Database Image -Docker based deployment of sharded database. +To build Oracle Globally Distributed Database on a container, download and build an Oracle 23.5.0 Database Image. See the Oracle Database Single Instance [README.MD](https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md), which is available on the Oracle GitHub repository. -### Details +**Note**: Use the [README.MD](https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md) to create the image, and do not use the container instructions. For the container, use the steps given in this document under the [Oracle Globally Distributed Database in Containers Deployment Scenarios](#oracle-globally-distributed-database-in-containers-deployment-scenarios) section. -For more details, please refer to the [Docker sharding][DOCKER-sharding] documentation. +### Building Extended Oracle Database Image with Oracle Globally Distributed Database Feature -## Fast data ingest +After creating the base image using `buildContainerImage.sh` in the previous step, use the `buildExtensions.sh` script that is under the `extensions` folder to build an extended image. This extended image will include the Oracle Globally Distributed Database Feature. For more information, refer to the [README.MD](https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/extensions/README.md) in the `extensions` folder for the Oracle Single Instance Database, which is available on the Oracle GitHub repository. -### Overview +For example: -The Fast data ingest library consist of several parts: - * Generic routing table interfaces - * Sharding metadata implementation - * Metadata reader (encapsulated select queries) - * Tools for efficient parallel splitting with respect to sharding key +```bash +./buildExtensions.sh -a -x sharding -b oracle/database:23.5.0-ee -t oracle/database-ext-sharding:23.5.0-ee -o "--build-arg BASE_IMAGE_VERSION=23.5.0" -### Details +Where: +"-x sharding" is to specify to have sharding feature in the extended image +"-b oracle/database:23.5.0-ee" is to specify the Base image created in previous step +"oracle/database-ext-sharding:23.5.0-ee" is to specify the name:tag for the extended image with Sharding Feature +-o "--build-arg BASE_IMAGE_VERSION=23.5.0" is to specify the BASE_IMAGE_VERSION to clone from db-sharding git repo +``` -For more details, please refer to the [Fast data ingest][SDB-Fast-Data-Ingest] documentation. +To see more usage instructions for the `buildExtensions.sh` script, run the following command: +```bash +./buildExtensions.sh -h -### Contributing +Usage: buildExtensions.sh -a -x [extensions] -b [base image] -t [image name] -v [version] [-o] [container build option] +Builds one of more Container Image Extensions. + +Parameters: + -a: Build all extensions + -x: Space separated extensions to build. Defaults to all + Choose from : k8s patching prebuiltdb sharding + -b: Base image to use + -v: Base version to extend (example 21.3.0) + -t: name:tag for the extended image + -o: passes on Container build option -This project welcomes contributions from the community. Before submitting a pull request, please [review our contribution guide](./CONTRIBUTING.md) +LICENSE UPL 1.0 -### Security +Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. +``` -Please consult the [security guide](./SECURITY.md) for our responsible security vulnerability disclosure process +## Oracle Globally Distributed Database in Containers Deployment Scenarios +### Deploy Oracle Globally Distributed Database Containers +If you want to manually deploy the Oracle Globally Distributed Database using Docker or Podman containers, then use the sections that follow to see the step by step procedure. -### License +#### Deploy Oracle Globally Distributed Database Containers on Podman -Copyright (c) 2020, 2023 Oracle and/or its affiliates. +To deploy an Oracle Globally Distributed Database on Podman, see: [Deploy Oracle Globally Distributed Database Containers on Podman](./samples/container-files/podman-container-files/README.md). This document provides the commands that you need to deploy an Oracle Globally Distributed Database using Podman with System-Managed Sharding or with System-Managed Sharding with RAFT replication or with User Defined Sharding. -Released under the Universal Permissive License v1.0 as shown at -<https://oss.oracle.com/licenses/upl/>. +**NOTE:** If you want to use Oracle Database 21c or Oracle Database 23ai release-based container images with Podman, then you must deploy on an Oracle Linux 8 host. + +#### Deploy Oracle Globally Distributed Database Containers on Docker + +To deploy an Oracle Globally Distributed Database on Docker, see: [Deploy Oracle Globally Distributed Database Containers on Docker](./samples/container-files/docker-container-files/README.md). This document provides the commands that you need to deploy an Oracle Globally Distributed Database using Docker with either System-Managed Sharding or with User Defined Sharding. + +**NOTE:** If you want to use the Oracle Database 19c or Oracle Database 21c release-based container images with Docker, then you must deploy on an Oracle Linux 7 host. + +#### Deploy Oracle Globally Distributed Database Containers on Podman using Oracle 23ai FREE Images + +To deploy an Oracle Globally Distributed Database on Podman using Oracle 23ai FREE Images, see: [Deploy Oracle Globally Distributed Database Containers on Podman using Oracle 23ai FREE Images](./samples/container-files/podman-container-files-free/README.md). This document provides the commands that you need to deploy an Oracle Globally Distributed Database with Oracle 23ai FREE Images using Podman with System-Managed Sharding or with System-Managed Sharding with RAFT replication or with User Defined Sharding. + +## Oracle Globally Distributed Database in Containers Deployment using docker-compose + +To deploy an Oracle Globally Distributed Database in Containers using docker-compose, refer to [Deploying Oracle Globally Distributed Database Containers using docker-compose](./samples/compose-files/docker-compose/README.md) + +## Oracle Globally Distributed Database in Containers Deployment using podman-compose + +To deploy an Oracle Globally Distributed Database in Containers using podman-compose, refer to [Deploying Oracle Globally Distributed Database Containers using podman-compose](./samples/compose-files/podman-compose/README.md) + +## Support + +Oracle Global Service Manager (GSM) and Oracle Globally Distributed Database on Docker is supported on Oracle Linux 7. +Oracle Database 23ai GSM and Oracle Globally Distributed Database on Podman is supported on Oracle Linux 8 and onwards. + + +## License + +To download and run Oracle Global Service Manager (GSM) and Oracle Globally Distributed Database, either inside or outside a Container, you must download the binaries from the Oracle website and accept the license indicated at that page. + +All scripts and files hosted in this project and GitHub docker-images/OracleDatabase repository required to build the Docker and Podman images are, unless otherwise noted, released under UPL 1.0 license. + + +## Copyright + +Copyright (c) 2022 - 2024 Oracle and/or its affiliates. +Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/ \ No newline at end of file diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/Containerfile b/container-based-sharding-deployment/containerfiles/23.4.0/Containerfile index 9d734f5..5b9420b 100644 --- a/container-based-sharding-deployment/containerfiles/23.4.0/Containerfile +++ b/container-based-sharding-deployment/containerfiles/23.4.0/Containerfile @@ -19,7 +19,7 @@ # ----------------------- # Put all downloaded files in the same directory as this Dockerfile # Run: -# $ docker build -t oracle/gsm:23.3.0 . +# $ docker build -t oracle/gsm:23.4.0 . # ARG BASE_OL_IMAGE=oraclelinux:8 diff --git a/container-based-sharding-deployment/containerfiles/23.5.0/Containerfile b/container-based-sharding-deployment/containerfiles/23.5.0/Containerfile index 9d734f5..997f629 100644 --- a/container-based-sharding-deployment/containerfiles/23.5.0/Containerfile +++ b/container-based-sharding-deployment/containerfiles/23.5.0/Containerfile @@ -19,7 +19,7 @@ # ----------------------- # Put all downloaded files in the same directory as this Dockerfile # Run: -# $ docker build -t oracle/gsm:23.3.0 . +# $ docker build -t oracle/gsm:23.5.0 . # ARG BASE_OL_IMAGE=oraclelinux:8 From 2f312be70a7d5815c9dd566feade5548d062be2f Mon Sep 17 00:00:00 2001 From: Saurabh Ahuja <saurabh.ahuja@oracle.com> Date: Thu, 29 Aug 2024 15:58:11 +0000 Subject: [PATCH 3/3] remove 23.3. and 23.4.0 --- .../containerfiles/23.3.0/23c_gsm_install.rsp | 35 - .../23.3.0/23c_gsm_install_sample.rsp | 35 - .../containerfiles/23.3.0/Checksum | 1 - .../containerfiles/23.3.0/Containerfile | 143 - .../containerfiles/23.3.0/Dockerfile_21c | 85 - .../containerfiles/23.3.0/checkLiveness.sh | 22 - .../containerfiles/23.3.0/checkSpace.sh | 23 - .../23.3.0/installGSMBinaries.sh | 43 - .../containerfiles/23.3.0/runOracle.sh | 39 - .../containerfiles/23.3.0/runUserScripts.sh | 35 - .../containerfiles/23.3.0/scripts/cmdExec | 23 - .../containerfiles/23.3.0/scripts/demoapp.sql | 88 - .../containerfiles/23.3.0/scripts/main.py | 171 - .../23.3.0/scripts/oracommon.py | 886 ----- .../containerfiles/23.3.0/scripts/oraenv.py | 139 - .../23.3.0/scripts/orafactory.py | 115 - .../containerfiles/23.3.0/scripts/oragsm.py | 2945 ----------------- .../23.3.0/scripts/oralogger.py | 181 - .../23.3.0/scripts/oramachine.py | 45 - .../23.3.0/scripts/orapcatalog.py | 748 ----- .../23.3.0/scripts/orapshard.py | 795 ----- .../23.3.0/scripts/orascatalog.py | 9 - .../23.3.0/scripts/orasshard.py | 58 - .../23.3.0/scripts/runOraShardSetup.sh | 568 ---- .../23.3.0/scripts/runOracle.sh | 78 - .../containerfiles/23.3.0/setupGSM.sh | 31 - .../containerfiles/23.3.0/setupLinuxEnv.sh | 14 - .../containerfiles/23.3.0/setupOshardEnv.sh | 970 ------ .../containerfiles/23.4.0/23c_gsm_install.rsp | 35 - .../23.4.0/23c_gsm_install_sample.rsp | 35 - .../containerfiles/23.4.0/Checksum | 1 - .../containerfiles/23.4.0/Containerfile | 232 -- .../containerfiles/23.4.0/checkLiveness.sh | 22 - .../containerfiles/23.4.0/checkSpace.sh | 23 - .../23.4.0/installGSMBinaries.sh | 43 - .../containerfiles/23.4.0/runOracle.sh | 39 - .../containerfiles/23.4.0/runUserScripts.sh | 35 - .../containerfiles/23.4.0/scripts/cmdExec | 23 - .../containerfiles/23.4.0/scripts/demoapp.sql | 88 - .../containerfiles/23.4.0/scripts/main.py | 171 - .../23.4.0/scripts/oracommon.py | 966 ------ .../containerfiles/23.4.0/scripts/oraenv.py | 139 - .../23.4.0/scripts/orafactory.py | 115 - .../containerfiles/23.4.0/scripts/oragsm.py | 2945 ----------------- .../23.4.0/scripts/oralogger.py | 181 - .../23.4.0/scripts/oramachine.py | 45 - .../23.4.0/scripts/orapcatalog.py | 790 ----- .../23.4.0/scripts/orapshard.py | 838 ----- .../23.4.0/scripts/orascatalog.py | 9 - .../23.4.0/scripts/orasshard.py | 58 - .../23.4.0/scripts/runOraShardSetup.sh | 568 ---- .../23.4.0/scripts/runOracle.sh | 78 - .../containerfiles/23.4.0/setupGSM.sh | 31 - .../containerfiles/23.4.0/setupLinuxEnv.sh | 28 - .../containerfiles/23.4.0/setupOshardEnv.sh | 970 ------ 55 files changed, 16833 deletions(-) delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install.rsp delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install_sample.rsp delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/Checksum delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/Containerfile delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/Dockerfile_21c delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/checkLiveness.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/checkSpace.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/installGSMBinaries.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/runOracle.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/runUserScripts.sh delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/cmdExec delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/demoapp.sql delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/main.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/oracommon.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/oraenv.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/orafactory.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/oragsm.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/oralogger.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/oramachine.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapcatalog.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapshard.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/orascatalog.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/orasshard.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOraShardSetup.sh delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOracle.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/setupGSM.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.3.0/setupLinuxEnv.sh delete mode 100755 container-based-sharding-deployment/containerfiles/23.3.0/setupOshardEnv.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install.rsp delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install_sample.rsp delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/Checksum delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/Containerfile delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/checkLiveness.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/checkSpace.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/installGSMBinaries.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/runOracle.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/runUserScripts.sh delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/cmdExec delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/demoapp.sql delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/main.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/oracommon.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/oraenv.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/orafactory.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/oragsm.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/oralogger.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/oramachine.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapcatalog.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapshard.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/orascatalog.py delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/orasshard.py delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOraShardSetup.sh delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOracle.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/setupGSM.sh delete mode 100644 container-based-sharding-deployment/containerfiles/23.4.0/setupLinuxEnv.sh delete mode 100755 container-based-sharding-deployment/containerfiles/23.4.0/setupOshardEnv.sh diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install.rsp b/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install.rsp deleted file mode 100644 index 102854f..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install.rsp +++ /dev/null @@ -1,35 +0,0 @@ - -############################################################################### -## Copyright(c) Oracle Corporation 1998,2022. All rights reserved. ## -## ## -## Specify values for the variables listed below to customize ## -## your installation. ## -## ## -## Each variable is associated with a comment. The comment ## -## can help to populate the variables with the appropriate ## -## values. ## -## ## -############################################################################### - -#------------------------------------------------------------------------------- -# Do not change the following system generated value. -#------------------------------------------------------------------------------- -oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v23.0.0 - -#------------------------------------------------------------------------------- -# Unix group to be set for the inventory directory. -#------------------------------------------------------------------------------- -UNIX_GROUP_NAME=oinstall -#------------------------------------------------------------------------------- -# Inventory location. -#------------------------------------------------------------------------------- -INVENTORY_LOCATION=###INVENTORY### -#------------------------------------------------------------------------------- -# Complete path of the Oracle Home -#------------------------------------------------------------------------------- -ORACLE_HOME=###ORACLE_HOME### - -#------------------------------------------------------------------------------- -# Complete path of the Oracle Base. -#------------------------------------------------------------------------------- -ORACLE_BASE=###ORACLE_BASE### diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install_sample.rsp b/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install_sample.rsp deleted file mode 100644 index fce54e3..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/23c_gsm_install_sample.rsp +++ /dev/null @@ -1,35 +0,0 @@ - -############################################################################### -## Copyright(c) Oracle Corporation 1998,2022. All rights reserved. ## -## ## -## Specify values for the variables listed below to customize ## -## your installation. ## -## ## -## Each variable is associated with a comment. The comment ## -## can help to populate the variables with the appropriate ## -## values. ## -## ## -############################################################################### - -#------------------------------------------------------------------------------- -# Do not change the following system generated value. -#------------------------------------------------------------------------------- -oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v23.0.0 - -#------------------------------------------------------------------------------- -# Unix group to be set for the inventory directory. -#------------------------------------------------------------------------------- -UNIX_GROUP_NAME= -#------------------------------------------------------------------------------- -# Inventory location. -#------------------------------------------------------------------------------- -INVENTORY_LOCATION= -#------------------------------------------------------------------------------- -# Complete path of the Oracle Home -#------------------------------------------------------------------------------- -ORACLE_HOME= - -#------------------------------------------------------------------------------- -# Complete path of the Oracle Base. -#------------------------------------------------------------------------------- -ORACLE_BASE= diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/Checksum b/container-based-sharding-deployment/containerfiles/23.3.0/Checksum deleted file mode 100644 index 5cd5a7a..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/Checksum +++ /dev/null @@ -1 +0,0 @@ -ba8e6b942ba8ff22d25dd3babc7b326c LINUX.X64_233000_gsm.zip diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/Containerfile b/container-based-sharding-deployment/containerfiles/23.3.0/Containerfile deleted file mode 100644 index 2ba24c1..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/Containerfile +++ /dev/null @@ -1,143 +0,0 @@ -# LICENSE UPL 1.0 -# -# Copyright (c) 2018,2022 Oracle and/or its affiliates. -# -# ORACLE DOCKERFILES PROJECT -# -------------------------- -# This is the Dockerfile for Oracle GSM 23c Release 3 to build the container image -# MAINTAINER <paramdeep.saini@oracle.com> -# -# This is the Dockerfile for Oracle GSM 23c -# -# REQUIRED FILES TO BUILD THIS IMAGE -# ---------------------------------- -# (1) LINUX.X64_233000_gsm.zip -# Download Oracle Database 23c GSM Software -# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html -# -# HOW TO BUILD THIS IMAGE -# ----------------------- -# Put all downloaded files in the same directory as this Dockerfile -# Run: -# $ docker build -t oracle/gsm:23.3.0 . -# - -ARG BASE_OL_IMAGE=oraclelinux:8 - -# Pull base image -# --------------- -FROM $BASE_OL_IMAGE AS base - -# Labels -# ------ -LABEL "provider"="Oracle" \ - "issues"="https://github.com/oracle/db-sharding/issues" \ - "volume.setup.location1"="/opt/oracle/scripts" \ - "port.listener"="1522" - -# Argument to control removal of components not needed after db software installation -ARG SLIMMING=false -ARG INSTALL_FILE_1="LINUX.X64_233000_gsm.zip" - -# Environment variables required for this build (do NOT change) -# ------------------------------------------------------------- -ENV GSM_BASE="/u01/app/oracle" \ - GSM_HOME="/u01/app/oracle/product/23c/gsmhome_1" \ - INVENTORY="/u01/app/oracle/oraInventory" \ - INSTALL_DIR="/opt/oracle/scripts" \ - INSTALL_FILE_1=$INSTALL_FILE_1 \ - INSTALL_RSP="23c_gsm_install.rsp" \ - RUN_FILE="runOracle.sh" \ - SETUP_LINUX_FILE="setupLinuxEnv.sh" \ - CHECK_SPACE_FILE="checkSpace.sh" \ - USER_SCRIPTS_FILE="runUserScripts.sh" \ - INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ - GSM_SETUP_FILE="setupOshardEnv.sh" \ - GSM_ENV_SETUP_FILE="setupGSM.sh" \ - GSM_SCRIPTS="scripts" \ - MAINPY="main.py" \ - PYTHON_FILE="/usr/bin/python" \ - PYTHON3_FILE="/usr/bin/python3" \ - CHECKLIVENESS="checkLiveness.sh" -# Use second ENV so that variable get substituted -ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ - ORACLE_HOME=$GSM_HOME \ - ORACLE_BASE=$GSM_BASE \ - SCRIPT_DIR=$INSTALL_DIR/sharding \ - PATH=/bin:/usr/bin:/sbin:/usr/sbin \ - GSM_PATH=$GSM_HOME/bin:$PATH \ - GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib - - -# Copy files needed during both installation and runtime -# ------------ -COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $GSM_ENV_SETUP_FILE $INSTALL_DIR/install/ -COPY $RUN_FILE $GSM_SETUP_FILE $CHECKLIVENESS $USER_SCRIPTS_FILE $SCRIPT_DIR/ -COPY $GSM_SCRIPTS $SCRIPT_DIR/scripts/ - -RUN chmod 755 $INSTALL_DIR/install/*.sh && \ - sync && \ - $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ - $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ - $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ - sync - -############################################# -# ------------------------------------------- -# Start new stage for installing the GSM -# ------------------------------------------- -############################################# - -from base AS builder - -COPY $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ - -RUN chmod 755 $INSTALL_SCRIPTS/*.sh && \ - sync && \ - sed -e '/hard *memlock/s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-21c.conf && \ - sed -e '/ *nofile /s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-21c.conf && \ - su oracle -c "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ - $INVENTORY/orainstRoot.sh && \ - $GSM_HOME/root.sh && \ - rm -rf $INSTALL_DIR/install && \ - rm -f /etc/sysctl.d/99-oracle-database-preinstall-21c-sysctl.conf && \ - rm -f /etc/sysctl.d/99-sysctl.conf && \ - rm -f /etc/rc.d/init.d/oracle-database-preinstall-21c-firstboot && \ - rm -f /etc/security/limits.d/oracle-database-preinstall-21c.conf && \ - sync - -############################################# -# ------------------------------------------- -# Start new layer for GSM runtime -# ------------------------------------------- -############################################# - -FROM base - -COPY --from=builder /u01 /u01 - -RUN if [ ! -f $PYTHON_FILE ]; then \ - ln -s $PYTHON3_FILE $PYTHON_FILE && \ - :; \ - fi && \ - rm -f $INSTALL_DIR/install/* && \ - cp $SCRIPT_DIR/scripts/cmdExec $SCRIPT_DIR/ && \ - chown -R oracle:oinstall $SCRIPT_DIR && \ - chmod 755 $SCRIPT_DIR/*.sh && \ - chmod 755 $SCRIPT_DIR/scripts/*.py && \ - chmod 755 $SCRIPT_DIR/scripts/*.sh && \ - chmod 755 $SCRIPT_DIR/scripts/cmdExec && \ - chmod 755 $SCRIPT_DIR/cmdExec && \ - sync - -USER oracle -WORKDIR /home/oracle -EXPOSE 1522 - -VOLUME ["$GSM_BASE/oradata"] - -HEALTHCHECK --interval=2m --start-period=25m \ - CMD "$SCRIPT_DIR/$CHECKLIVENESS" >/dev/null || exit 1 - -# Define default command to start Oracle Database. -CMD exec $SCRIPT_DIR/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/Dockerfile_21c b/container-based-sharding-deployment/containerfiles/23.3.0/Dockerfile_21c deleted file mode 100644 index 37f8fba..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/Dockerfile_21c +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright 2020, Oracle Corporation and/or affiliates. All rights reserved. -# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl -# MAINTAINER <paramdeep.saini@oracle.com> -# -# This is the Dockerfile for Oracle Database 21 -# -# REQUIRED FILES TO BUILD THIS IMAGE -# ---------------------------------- -# (1) LINUX.X64_213000_gsm.zip -# Download Oracle Database 21c GSM Software -# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html -# -# HOW TO BUILD THIS IMAGE -# ----------------------- -# Put all downloaded files in the same directory as this Dockerfile -# Run: -# $ docker build -t oracle/gsm:21.3.0 . -# -# Pull base image -# --------------- -FROM oraclelinux:7-slim as base - -# Maintainer -# ---------- -MAINTAINER Paramdeep Saini <paramdeep.saini@oracle.com> - -# Environment variables required for this build (do NOT change) -# ------------------------------------------------------------- -ENV GSM_BASE="/u01/app/oracle" \ - GSM_HOME="/u01/app/oracle/product/21c/gsmhome_1" \ - INVENTORY="/u01/app/oraInventory" \ - INSTALL_DIR="/opt/scripts" \ - INSTALL_FILE_1="LINUX.X64_213000_gsm.zip" \ - INSTALL_RSP="21c_gsm_install.rsp" \ - RUN_FILE="runOracle.sh" \ - SETUP_LINUX_FILE="setupLinuxEnv.sh" \ - CHECK_SPACE_FILE="checkSpace.sh" \ - USER_SCRIPTS_FILE="runUserScripts.sh" \ - INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ - GSM_SETUP_FILE="setupOshardEnv.sh" \ - GSM_ENV_SETUP_FILE="setupGSM.sh" \ - GSM_SCRIPTS="scripts" -# Use second ENV so that variable get substituted -ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ - ORACLE_HOME=$GSM_HOME \ - ORACLE_BASE=$GSM_BASE \ - SCRIPT_DIR=$INSTALL_DIR/startup \ - PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH \ - GSM_PATH=$GSM_HOME/bin:/usr/sbin:$PATH \ - GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib - - -# Copy files needed during both installation and runtime -# ------------ -COPY $INSTALL_FILE_1 $SETUP_LINUX_FILE $CHECK_SPACE_FILE $INSTALL_RSP $GSM_ENV_SETUP_FILE $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ -COPY $RUN_FILE $GSM_SETUP_FILE $USER_SCRIPTS_FILE $INSTALL_DIR/startup/ -COPY $GSM_SCRIPTS $INSTALL_DIR/startup/scripts - -RUN chmod 755 $INSTALL_DIR/install/*.sh && \ - sync && \ - $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ - $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ - $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ - sed -e '/hard *memlock/s/^/#/g' -i /etc/security/limits.d/oracle-database-preinstall-19c.conf && \ - su oracle -c "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ - $INVENTORY/orainstRoot.sh && \ - $GSM_HOME/root.sh && \ - rm -rf $INSTALL_DIR/install && \ - rm -f /etc/sysctl.d/99-oracle-database-preinstall-19c-sysctl.conf && \ - rm -f /etc/sysctl.d/99-sysctl.conf && \ - rm -f /etc/rc.d/init.d/oracle-database-preinstall-19c-firstboot && \ - rm -f /etc/security/limits.d/oracle-database-preinstall-19c.conf && \ - rm -f $INSTALL_DIR/install/* && \ - chown -R oracle:oinstall $SCRIPT_DIR && \ - chmod 755 $SCRIPT_DIR/*.sh && \ - sync - -USER oracle -WORKDIR /home/oracle -EXPOSE 1521 - -VOLUME ["$GSM_BASE/oradata"] - -# Define default command to start Oracle Database. -CMD exec $INSTALL_DIR/startup/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/checkLiveness.sh b/container-based-sharding-deployment/containerfiles/23.3.0/checkLiveness.sh deleted file mode 100644 index 32a9fe3..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/checkLiveness.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -# -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: Build script for building RAC container image -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -export PYTHON="/bin/python3" - -$PYTHON $SCRIPT_DIR/$MAINPY --checkliveness='true' -retcode=$? - - if [ ${retcode} -eq 0 ]; then - exit 0 - else - exit 1 - fi diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/checkSpace.sh b/container-based-sharding-deployment/containerfiles/23.3.0/checkSpace.sh deleted file mode 100644 index 5d4b8d9..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/checkSpace.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -REQUIRED_SPACE_GB=2 -AVAILABLE_SPACE_GB=`df -PB 1G / | tail -n 1 | awk '{ print $4 }'` - -if [ $AVAILABLE_SPACE_GB -lt $REQUIRED_SPACE_GB ]; then - script_name=`basename "$0"` - echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - echo "$script_name: ERROR - There is not enough space available in the docker container." - echo "$script_name: The container needs at least $REQUIRED_SPACE_GB GB, but only $AVAILABLE_SPACE_GB GB are available." - echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - exit 1; -fi; diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/installGSMBinaries.sh b/container-based-sharding-deployment/containerfiles/23.3.0/installGSMBinaries.sh deleted file mode 100644 index adf6547..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/installGSMBinaries.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -# -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: Build script for building RAC container image -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -export ORACLE_BASE=$GSM_BASE -export ORACLE_HOME=$GSM_HOME - -# Check whether ORACLE_BASE is set -if [ "$ORACLE_BASE" == "" ]; then - echo "ERROR: ORACLE_BASE has not been set!" - echo "You have to have the ORACLE_BASE environment variable set to a valid value!" - exit 1; -fi; - -# Check whether ORACLE_HOME is set -if [ "$ORACLE_HOME" == "" ]; then - echo "ERROR: ORACLE_HOME has not been set!" - echo "You have to have the ORACLE_HOME environment variable set to a valid value!" - exit 1; -fi; - - -# Replace place holders -# --------------------- - -sed -i -e "s|###INVENTORY###|$INVENTORY|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ -sed -i -e "s|###ORACLE_BASE###|$GSM_BASE|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ -sed -i -e "s|###ORACLE_HOME###|$GSM_HOME|g" $INSTALL_SCRIPTS/$INSTALL_RSP - -# Install Oracle binaries -cd $INSTALL_SCRIPTS && \ -unzip $INSTALL_FILE_1 && \ -rm $INSTALL_FILE_1 && \ -$INSTALL_SCRIPTS/gsm/runInstaller -silent -force -waitforcompletion -responsefile $INSTALL_SCRIPTS/$INSTALL_RSP -ignorePrereqFailure || true && \ -rm -rf gsm && \ -cd $HOME diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/runOracle.sh b/container-based-sharding-deployment/containerfiles/23.3.0/runOracle.sh deleted file mode 100644 index 473de50..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/runOracle.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: Build script for building RAC container image -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -#This is the main file which calls other file to setup the sharding. -if [ -z ${BASE_DIR} ]; then - BASE_DIR=$INSTALL_DIR/sharding/scripts -fi - -if [ -z ${MAIN_SCRIPT} ]; then - SCRIPT_NAME="main.py" -fi - -if [ -z ${EXECUTOR} ]; then - EXECUTOR="python3" -fi - -cd $BASE_DIR -$EXECUTOR $SCRIPT_NAME - -# Tail on alert log and wait (otherwise container will exit) - -if [ -z ${DEV_MODE} ]; then - echo "The following output is now a tail of the alert.log:" - tail -f $ORACLE_BASE/diag/gsm/*/*/trace/alert*.log & -else - echo "The following output is now a tail of the /etc/passwd for dev mode" - tail -f /etc/passwd & -fi - -childPID=$! -wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/runUserScripts.sh b/container-based-sharding-deployment/containerfiles/23.3.0/runUserScripts.sh deleted file mode 100644 index c1d1c44..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/runUserScripts.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -SCRIPTS_ROOT="$1"; - -# Check whether parameter has been passed on -if [ -z "$SCRIPTS_ROOT" ]; then - echo "$0: No SCRIPTS_ROOT passed on, no scripts will be run"; - exit 1; -fi; - -# Execute custom provided files (only if directory exists and has files in it) -if [ -d "$SCRIPTS_ROOT" ] && [ -n "$(ls -A $SCRIPTS_ROOT)" ]; then - - echo ""; - echo "Executing user defined scripts" - - for f in $SCRIPTS_ROOT/*; do - case "$f" in - *.sh) echo "$0: running $f"; . "$f" ;; - *.sql) echo "$0: running $f"; echo "exit" | $ORACLE_HOME/bin/sqlplus -s "/ as sysdba" @"$f"; echo ;; - *) echo "$0: ignoring $f" ;; - esac - echo ""; - done - - echo "DONE: Executing user defined scripts" - echo ""; - -fi; diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/cmdExec b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/cmdExec deleted file mode 100755 index 0e5ac30..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/cmdExec +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -TIMESTAMP=`date "+%Y-%m-%d"` -LOGFILE="/tmp/sharding_cmd_${TIMESTAMP}.log" - -echo $(date -u) " : " $@ >> $LOGFILE - -cmd=$@ - -$cmd - -if [ $? -eq 0 ]; then - exit 0 -else - exit 127 -fi diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/demoapp.sql b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/demoapp.sql deleted file mode 100755 index 3e96bfc..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/demoapp.sql +++ /dev/null @@ -1,88 +0,0 @@ - connect sys/'&1'@oshard-catalog-0:1521/CATCDB as sysdba - alter session set container=CAT1PDB; - alter session enable shard ddl; - create user app_schema identified by app_schema; - grant connect, resource, alter session to app_schema; - grant execute on dbms_crypto to app_schema; - grant create table, create procedure, create tablespace, create materialized view to app_schema; - grant unlimited tablespace to app_schema; - grant select_catalog_role to app_schema; - grant all privileges to app_schema; - grant gsmadmin_role to app_schema; - grant dba to app_schema; - conn app_schema/'&1'@oshard-catalog-0:1521/CAT1PDB - alter session enable shard ddl; - REM - REM Create a Sharded table for - REM - CREATE SHARDED TABLE Customers - ( - CustId VARCHAR2(60) NOT NULL, - FirstName VARCHAR2(60), - LastName VARCHAR2(60), - Class VARCHAR2(10), - Geo VARCHAR2(8), - CustProfile VARCHAR2(4000), - Passwd RAW(60), - CONSTRAINT pk_customers PRIMARY KEY (CustId), - CONSTRAINT json_customers CHECK (CustProfile IS JSON) - ) TABLESPACE SET TSP_SET_1 - PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO; - REM - REM Create a Sharded table for Orders - REM - CREATE SHARDED TABLE Orders - ( - OrderId INTEGER NOT NULL, - CustId VARCHAR2(60) NOT NULL, - OrderDate TIMESTAMP NOT NULL, - SumTotal NUMBER(19,4), - Status CHAR(4), - constraint pk_orders primary key (CustId, OrderId), - constraint fk_orders_parent foreign key (CustId) - references Customers on delete cascade - ) partition by reference (fk_orders_parent); - REM - REM Create the sequence used for the OrderId column - REM - CREATE SEQUENCE Orders_Seq; - REM - REM Create a Sharded table for LineItems - REM - CREATE SHARDED TABLE LineItems - ( - OrderId INTEGER NOT NULL, - CustId VARCHAR2(60) NOT NULL, - ProductId INTEGER NOT NULL, - Price NUMBER(19,4), - Qty NUMBER, - constraint pk_items primary key (CustId, OrderId, ProductId), - constraint fk_items_parent foreign key (CustId, OrderId) - references Orders on delete cascade - ) partition by reference (fk_items_parent); - REM - REM - CREATE DUPLICATED TABLE Products - ( - ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, - Name VARCHAR2(128), - DescrUri VARCHAR2(128), - LastPrice NUMBER(19,4) - ) TABLESPACE products_tsp; - CREATE OR REPLACE FUNCTION PasswCreate(PASSW IN RAW) - RETURN RAW - IS - Salt RAW(8); - BEGIN - Salt := DBMS_CRYPTO.RANDOMBYTES(8); - RETURN UTL_RAW.CONCAT(Salt, DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(Salt,PASSW), DBMS_CRYPTO.HASH_SH256)); - END; - / - CREATE OR REPLACE FUNCTION PasswCheck(PASSW IN RAW, PHASH IN RAW) - RETURN INTEGER IS - BEGIN - RETURN UTL_RAW.COMPARE(DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(UTL_RAW.SUBSTR(PHASH, 1, 8), PASSW), DBMS_CRYPTO.HASH_SH256),UTL_RAW.SUBSTR(PHASH, 9)); - END; - / - REM - REM diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/main.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/main.py deleted file mode 100755 index b7f0f17..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/main.py +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -""" -This is the main file which calls other file to setup the sharding. -""" - -from oralogger import * -from orafactory import * -from oraenv import * -from oracommon import * - - -def main(): - - # Checking Comand line Args - try: - opts, args = getopt.getopt(sys.argv[1:], '', ['addshard=','deleteshard=','validateshard=','checkliveness=','resetlistener=','restartdb=','createdir=','optype=','addshardgroup=','deployshard=','movechunks=','checkonlineshard=','cancelchunks=','checkchunks=','checkgsmshard=','checkreadyness=','validatenochunks=','invitednode=','resetpassword=','exporttdekey=','importtdekey=','help']) - except getopt.GetoptError: - pass - - # Initializing oraenv instance - oenv=OraEnv() - file_name = os.path.basename(__file__) - funcname = sys._getframe(1).f_code.co_name - - log_file_name = oenv.logfile_name("NONE") - - # Initialiing logger instance - oralogger = OraLogger(log_file_name) - console_handler = CHandler() - file_handler = FHandler() - stdout_handler = StdHandler() - # Setting next log handlers - stdout_handler.nextHandler = file_handler - file_handler.nextHandler = console_handler - console_handler.nextHandler = PassHandler() - - ocommon = OraCommon(oralogger,stdout_handler,oenv) - - for opt, arg in opts: - if opt in ('--help'): - oralogger.msg_ = '''{:^17}-{:^17} : You can pass parameter --addshard, --deleteshard, --validateshard, --checkliveness, --resetlistener, --restartdb, --createdir, --optype, --addshardgroup, --deployshard, '--checkonlineshard', '--cancelchunks', '--movechunks', '--checkchunks', '--checkgsmshard','--validatenochunks', '--checkreadyness','--invitednode', '--resetpassword','--exporttdekey','--importtdekey',or --help''' - stdout_handler.handle(oralogger) - elif opt in ('--addshard'): - file_name = oenv.logfile_name("ADD_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("ADD_SHARD",arg) - elif opt in ('--validateshard'): - file_name = oenv.logfile_name("VALIDATE_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("VALIDATE_SHARD",arg) - elif opt in ('--deleteshard'): - file_name = oenv.logfile_name("REMOVE_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("REMOVE_SHARD",arg) - elif opt in ('--checkliveness'): - oralogger.stdout_ = None - file_name = oenv.logfile_name("CHECK_LIVENESS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CHECK_LIVENESS",arg) - elif opt in ('--checkreadyness'): - oralogger.stdout_ = None - file_name = oenv.logfile_name("CHECK_READYNESS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CHECK_READYNESS",arg) - elif opt in ('--resetlistener'): - file_name = oenv.logfile_name("RESET_LISTENER") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("RESET_LISTENER",arg) - elif opt in ('--restartdb'): - file_name = oenv.logfile_name("RESTART_DB") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("RESTART_DB",arg) - elif opt in ('--createdir'): - file_name = oenv.logfile_name("CREATE_DIR") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CREATE_DIR",arg) - elif opt in ('--addshardgroup'): - file_name = oenv.logfile_name("ADD_SGROUP_PARAMS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("ADD_SGROUP_PARAMS",arg) - elif opt in ('--deployshard'): - file_name = oenv.logfile_name("DEPLOY_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("DEPLOY_SHARD",arg) - elif opt in ('--cancelchunks'): - file_name = oenv.logfile_name("CANCEL_CHUNKS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CANCEL_CHUNKS",arg) - elif opt in ('--movechunks'): - file_name = oenv.logfile_name("MOVE_CHUNKS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("MOVE_CHUNKS",arg) - elif opt in ('--checkchunks'): - file_name = oenv.logfile_name("CHECK_CHUNKS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CHECK_CHUNKS",arg) - elif opt in ('--validatenochunks'): - file_name = oenv.logfile_name("VALIDATE_NOCHUNKS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("VALIDATE_NOCHUNKS",arg) - elif opt in ('--checkonlineshard'): - file_name = oenv.logfile_name("CHECK_ONLINE_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CHECK_ONLINE_SHARD",arg) - elif opt in ('--checkgsmshard'): - file_name = oenv.logfile_name("CHECK_GSM_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CHECK_GSM_SHARD",arg) - elif opt in ('--invitednode'): - file_name = oenv.logfile_name("INVITED_NODE_OP") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("INVITED_NODE_OP",arg) - elif opt in ('--resetpassword'): - file_name = oenv.logfile_name("RESET_PASSWD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("RESET_PASSWORD",arg) - elif opt in ('--exporttdekey'): - file_name = oenv.logfile_name("EXPORT_TDE_KEY") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("EXPORT_TDE_KEY",arg) - elif opt in ('--importtdekey'): - file_name = oenv.logfile_name("IMPORT_TDE_KEY") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("IMPORT_TDE_KEY",arg) - elif opt in ('--optype'): - oenv.add_custom_variable("OP_TYPE",arg) - else: - pass - - # Initializing orafactory instances - oralogger.msg_ = '''{:^17}-{:^17} : Calling OraFactory to start the setup'''.format(file_name,funcname) - stdout_handler.handle(oralogger) - orafactory = OraFactory(oralogger,stdout_handler,oenv,ocommon) - - # Get the ora objects - ofactory=orafactory.get_ora_objs() - - # Traverse through returned factory objects and execute the setup function - for obj in ofactory: - obj.setup() - -# Using the special variable -if __name__=="__main__": - main() diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oracommon.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oracommon.py deleted file mode 100755 index 634a9f1..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oracommon.py +++ /dev/null @@ -1,886 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -from oralogger import * -from oraenv import * -import subprocess -import sys -import time -import datetime -import os -import getopt -import shlex -import json -import logging -import socket -import re -import os.path -import socket -import string -import random - -class OraCommon: - def __init__(self,oralogger,orahandler,oraenv): - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - - def run_sqlplus(self,cmd,sql_cmd,dbenv): - """ - This function execute the ran sqlplus or rman script and return the output - """ - try: - message="Received Command : {0}\n{1}".format(self.mask_str(cmd),self.mask_str(sql_cmd)) - self.log_info_message(message,self.file_name) - sql_cmd=self.unmask_str(sql_cmd) - cmd=self.unmask_str(cmd) -# message="Received Command : {0}\n{1}".format(cmd,sql_cmd) -# self.log_info_message(message,self.file_name) - p = subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,env=dbenv,shell=True,universal_newlines=True) - p.stdin.write(sql_cmd) - # (stdout,stderr), retcode = p.communicate(sqlplus_script.encode('utf-8')), p.returncode - (stdout,stderr),retcode = p.communicate(),p.returncode - # stdout_lines = stdout.decode('utf-8').split("\n") - except: - error_msg=sys.exc_info() - self.log_error_message(error_msg,self.file_name) - self.prog_exit(self) - - return stdout.replace("\n\n", "\n"),stderr,retcode - - def execute_cmd(self,cmd,env,dir): - """ - Execute the OS command on host - """ - try: - message="Received Command : {0}".format(self.mask_str(cmd)) - self.log_info_message(message,self.file_name) - cmd=self.unmask_str(cmd) - out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,universal_newlines=True) - (output,error),retcode = out.communicate(),out.returncode - except: - error_msg=sys.exc_info() - self.log_error_message(error_msg,self.file_name) - self.prog_exit(self) - - return output,error,retcode - - def mask_str(self,mstr): - """ - Function to mask the string. - """ - newstr=None - if self.oenv.encrypt_str__: - newstr=mstr.replace('HIDDEN_STRING','********') - # self.log_info_message(newstr,self.file_name) - if newstr: - # message = "Masked the string as encryption flag is set in the singleton class" - # self.log_info_message(message,self.file_name) - return newstr - else: - return mstr - - - def unmask_str(self,mstr): - """ - Function to unmask the string. - """ - newstr=None - if self.oenv.encrypt_str__: - newstr=mstr.replace('HIDDEN_STRING',self.oenv.original_str__.rstrip()) - # self.log_info_message(newstr,self.file_name) - if newstr: - # message = "Unmasked the encrypted string and returning original string from singleton class" - # self.log_info_message(message,self.file_name) - return newstr - else: - return mstr - - def set_mask_str(self,mstr): - """ - Function to unmask the string. - """ - if mstr: - # message = "Setting encrypted String flag to True and original string in singleton class" - # self.log_info_message(message,self.file_name) - self.oenv.encrypt_str__ = True - self.oenv.original_str__ = mstr - else: - message = "Masked String is empty so no change required in encrypted String Flag and original string in singleton class" - self.log_info_message(message,self.file_name) - - def unset_mask_str(self): - """ - Function to unmask the string. - """ - # message = "Un-setting encrypted String flag and original string to None in Singleton class" - # self.log_info_message(message,self.file_name) - self.oenv.encrypt_str__ = None - self.oenv.original_str__ = None - - def prog_exit(self,message): - """ - This function exit the program because of some error - """ - sys.exit(127) - - def log_info_message(self,lmessage,fname): - """ - Print the INFO message in the logger - """ - funcname = sys._getframe(1).f_code.co_name - message = '''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) - self.ologger.msg_ = message - self.ologger.logtype_ = "INFO" - self.ohandler.handle(self.ologger) - - def log_error_message(self,lmessage,fname): - """ - Print the Error message in the logger - """ - funcname=sys._getframe(1).f_code.co_name - message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) - self.ologger.msg_=message - self.ologger.logtype_="ERROR" - self.ohandler.handle(self.ologger) - - def log_warn_message(self,lmessage,fname): - """ - Print the Error message in the logger - """ - funcname=sys._getframe(1).f_code.co_name - message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) - self.ologger.msg_=message - self.ologger.logtype_="WARN" - self.ohandler.handle(self.ologger) - - def check_sql_err(self,output,err,retcode,status): - """ - Check if there are any error in sql command output - """ - match=None - msg2='''Sql command failed.Flag is set not to ignore this error.Please Check the logs,Exiting the Program!''' - msg3='''Sql command failed.Flag is set to ignore this error!''' - self.log_info_message("output : " + str(output or "no Output"),self.file_name) - # self.log_info_message("Error : " + str(err or "no Error"),self.file_name) - # self.log_info_message("Sqlplus return code : " + str(retcode),self.file_name) - # self.log_info_message("Command Check Status Set to :" + str(status),self.file_name) - - if status: - if (retcode!=0): - self.log_info_message("Error : " + str(err or "no Error"),self.file_name) - self.log_error_message("Sql Login Failed.Please Check the logs,Exiting the Program!",self.file_name) - self.prog_exit(self) - - match=re.search("(?i)(?m)error",output) - if status: - if (match): - self.log_error_message(msg2,self.file_name) - self.prog_exit("error") - else: - self.log_info_message("Sql command completed successfully",self.file_name) - else: - if (match): - self.log_warn_message("Sql command failed. Flag is set to ignore the error.",self.file_name) - else: - self.log_info_message("Sql command completed sucessfully.",self.file_name) - - def check_os_err(self,output,err,retcode,status): - """ - Check if there are any error in OS command execution - """ - msg1='''OS command returned code : {0} and returned output : {1}'''.format(str(retcode),str(output or "no Output")) - msg2='''OS command returned code : {0}, returned error : {1} and returned output : {2}'''.format(str(retcode),str(err or "no returned error"),str(output or "no retruned output")) - msg3='''OS command failed. Flag is set to ignore this error!''' - - if status: - if (retcode != 0): - self.log_error_message(msg2,self.file_name) - self.prog_exit(self) - else: - self.log_info_message(msg1,self.file_name) - else: - if (retcode != 0): - self.log_warn_message(msg2,self.file_name) - self.log_warn_message(msg3,self.file_name) - else: - self.log_info_message(msg1,self.file_name) - - def check_key(self,key,env_dict): - """ - Check the key if it exist in dictionary. - Attributes: - key (string): String to check if key exist in dictionary - env_dict (dict): Contains the env variable related to seup - """ - if key in env_dict: - return True - else: - return False - - def empty_key(self,key): - """ - key is empty and print failure message. - Attributes: - key (string): String is empty - """ - msg='''Variable {0} is not defilned. Exiting!'''.format(key) - self.log_error_message(msg,self.file_name) - self.prog_exit(self) - - def add_key(self,key,value,env_dict): - """ - Add the key in the dictionary. - Attributes: - key (string): key String to add in the dictionary - value (String): value String to add in dictionary - - Return: - dict - """ - if self.check_key(key,env_dict): - msg='''Variable {0} already exist in the env variables'''.format(key) - self.log_info_message(msg,self.file_name) - else: - if value: - env_dict[key] = value - self.oenv.update_env_vars(env_dict) - else: - msg='''Variable {0} value is not defilned to add in the env variables. Exiting!'''.format(value) - self.log_error_message(msg,self.file_name) - self.prog_exit(self) - - return env_dict - - def update_key(self,key,value,env_dict): - """ - update the key in the dictionary. - Attributes: - key (string): key String to update in the dictionary - value (String): value String to update in dictionary - - Return: - dict - """ - if self.check_key(key,env_dict): - if value: - env_dict[key] = value - self.oenv.update_env_vars(env_dict) - else: - msg='''Variable {0} value is not defilned to update in the env variables!'''.format(key) - self.log_warn_message(msg,self.file_name) - else: - msg='''Variable {0} already exist in the env variables'''.format(key) - self.log_info_message(msg,self.file_name) - - return env_dict - - def check_file(self,file,local,remote,user): - """ - check locally or remotely - Attributes: - file (string): file to be created - local (boolean): dir to craetes locally - remote (boolean): dir to be created remotely - node (string): remote node name on which dir to be created - user (string): remote user to be connected - """ - self.log_info_message("Inside check_file()",self.file_name) - if local: - if os.path.isfile(file): - return True - else: - return False - - - def read_file(self,fname): - """ - Read the contents of a file and returns the contents to end user - Attributes: - fname (string): file to be read - - Return: - file data (string) - """ - f1 = open(fname, 'r') - fdata = f1.read() - f1.close - return fdata - - def write_file(self,fname,fdata): - """ - write the contents to a file - Attributes: - fname (string): file to be written - fdata (string): COnetents to be written - - Return: - file data (string) - """ - f1 = open(fname, 'w') - f1.write(fdata) - f1.close - - def create_dir(self,dir,local,remote,user): - """ - Create dir locally or remotely - Attributes: - dir (string): dir to be created - local (boolean): dir to craetes locally - remote (boolean): dir to be created remotely - node (string): remote node name on which dir to be created - user (string): remote user to be connected - """ - self.log_info_message("Inside create_dir()",self.file_name) - if local: - if not os.path.isdir(dir): - cmd='''mkdir -p {0}'''.format(dir) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - else: - msg='''Dir {0} already exist'''.format(dir) - self.log_info_message(msg,self.file_name) - - if remote: - pass - - def create_file(self,file,local,remote,user): - """ - Create dir locally or remotely - Attributes: - file (string): file to be created - local (boolean): dir to craetes locally - remote (boolean): dir to be created remotely - node (string): remote node name on which dir to be created - user (string): remote user to be connected - """ - self.log_info_message("Inside create_file()",self.file_name) - if local: - if not os.path.isfile(file): - cmd='''touch {0}'''.format(file) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - - if remote: - pass - - def shutdown_db(self,env_dict): - """ - Shutdown the database - """ - file="/home/oracle/shutDown.sh" - if not os.path.isfile(file): - self.log_info_message("Inside shutdown_db()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) - sqlcmd=''' - shutdown immediate; - ''' - self.log_info_message("Running the sqlplus command to shutdown the database: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - else: - cmd='''sh {0} immediate'''.format(file) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - - def mount_db(self,env_dict): - """ - Mount the database - """ - self.log_info_message("Inside mount_db()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) - sqlcmd=''' - startup mount; - ''' - self.log_info_message("Running the sqlplus command to mount the database: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - - def start_db(self,env_dict): - """ - startup the database - """ - file="/home/oracle/startUp.sh" - if not os.path.isfile(file): - self.log_info_message("Inside start_db()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) - sqlcmd=''' - startup; - ''' - self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - else: - cmd='''sh {0}'''.format(file) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - - def nomount_db(self,env_dict): - """ - No mount the database - """ - self.log_info_message("Inside start_db()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) - sqlcmd=''' - startup nomount; - ''' - self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - - def stop_gsm(self,env_dict): - """ - Stop the GSM - """ - self.log_info_message("Inside stop_gsm()",self.file_name) - gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) - gsmcmd=''' - stop gsm; - ''' - output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) - self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) - self.check_sql_err(output,error,retcode,None) - - def set_events(self,source): - """ - Seting events at DB level - """ - scope='' - accepted_scope = ['spfile', 'memory', 'both'] - - if self.check_key("DB_EVENTS",self.ora_env_dict): - events=str(self.ora_env_dict["DB_EVENTS"]).split(";") - - for event in events: - msg='''Setting up event {0}'''.format(event) - self.log_info_message(msg,self.file_name) - scope='' - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - source=event.split(":") - if len(source) > 1: - if source[1].split("=")[0] == "scope": - scope=source[1].split("=")[1] - - if scope not in accepted_scope: - sqlcmd=""" - alter system set events='{0}';""".format(source[0]) - else: - sqlcmd=""" - alter system set event='{0}' scope={1};""".format(source[0],scope) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - - def start_gsm(self,env_dict): - """ - Start the GSM - """ - self.log_info_message("Inside start_gsm()",self.file_name) - gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) - gsmcmd=''' - start gsm; - ''' - output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) - self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) - self.check_sql_err(output,error,retcode,None) - - def exec_gsm_cmd(self,gsmcmd,flag,env_dict): - """ - Get the GSM command output - """ - self.log_info_message("Inside exec_gsm_cmd()",self.file_name) - gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) - if gsmcmd: - output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) - self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) - self.check_sql_err(output,error,retcode,flag) - else: - self.log_info_message("GSM Command was set to empty. Executing nothing and setting output to None",self.file_name) - output=None - - return output,error,retcode - - - def check_substr_match(self,source_str,sub_str): - """ - CHeck if substring exist - """ - self.log_info_message("Inside check_substr_match()",self.file_name) - if (source_str.find(sub_str) != -1): - return True - else: - return False - - def find_str_in_string(self,source_str,delimeter,search_str): - """AI is creating summary for find_str_in_string - - Args: - source_str ([string]): [string where you need to search] - delimeter ([character]): [string delimeter] - search_str ([string]): [string to be searched] - """ - if delimeter == 'comma': - new_str=source_str.split(',') - for str in new_str: - if str.lower() == search_str.lower(): - return True - return False - - return False - - def check_status_value(self,match): - """ - return completed or notcompleted - """ - self.log_info_message("Inside check_status_value()",self.file_name) - if match: - return 'completed' - else: - return 'notcompleted' - - def remove_file(self,fname): - """ - Remove if file exist - """ - self.log_info_message("Inside remove_file()",self.file_name) - if os.path.exists(fname): - os.remove(fname) - - def get_sid_desc(self,gdbname,ohome,sid,sflag): - """ - get the SID_LISTENER_DESCRIPTION - """ - self.log_info_message("Inside get_sid_desc()",self.file_name) - sid_desc = "" - if sflag == 'SID_DESC1': - sid_desc = ''' ) - (SID_DESC = - (GLOBAL_DBNAME = {0}) - (ORACLE_HOME = {1}) - (SID_NAME = {2}) - ) - ) - '''.format(gdbname,ohome,sid) - elif sflag == 'SID_DESC': - sid_desc = '''(SID_LIST = - (SID_DESC = - (GLOBAL_DBNAME = {0}) - (ORACLE_HOME = {1}) - (SID_NAME = {2}) - ) - ) - '''.format(gdbname,ohome,sid) - else: - pass - - return sid_desc - - def get_lisora(self,port): - """ - return listener.ora listener settings - """ - self.log_info_message("Inside get_lisora()",self.file_name) - listener='''LISTENER = - (DESCRIPTION_LIST = - (DESCRIPTION = - (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = {0})) - (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC{0})) - ) - ) - '''.format(port) - return listener - - def get_domain(self,ohost): - """ - get the domain name from hostname - """ - return ohost.partition('.')[2] - -######### Get the DOMAIN############## - def get_host_domain(self): - """ - Return Public Hostname - """ - domain=None - domain=socket.getfqdn().split('.',1)[1] - if domain is None: - domain="example.info" - - return domain - - ######### get the public IP ############## - def get_ip(self,hostname,domain): - """ - Return the Ip based on hostname - """ - if not domain: - domain=self.get_host_domain() - - return socket.gethostbyname(hostname) - - def get_global_dbdomain(self,ohost,gdbname): - """ - get the global dbname - """ - domain = self.get_domain(ohost) - if domain: - global_dbname = gdbname + domain - else: - global_dbname = gdbname - - return gdbname - -######### Sqlplus connect string ########### - def get_sqlplus_str(self,home,osid,dbuser,password,hostname,port,svc,osep,role,wallet): - """ - return the sqlplus connect string - """ - path='''/usr/bin:/bin:/sbin:/usr/local/sbin:{0}/bin'''.format(home) - ldpath='''{0}/lib:/lib:/usr/lib'''.format(home) - export_cmd='''export ORACLE_HOME={0};export PATH={1};export LD_LIBRARY_PATH={2};export ORACLE_SID={3}'''.format(home,path,ldpath,osid) - if dbuser == 'sys' and password and hostname and port and svc: - return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4} as sysdba'''.format(dbuser,password,hostname,port,svc,export_cmd,home) - elif dbuser != 'sys' and password and hostname and svc: - return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4}'''.format(dbuser,password,hostname,"1521",svc,export_cmd,home) - elif dbuser and osep: - return dbuser - elif dbuser == 'sys' and not password: - return '''{1};{0}/bin/sqlplus "/ as sysdba"'''.format(home,export_cmd) - elif dbuser == 'sys' and password: - return '''{1};{0}/bin/sqlplus {2}/{3} as sysdba'''.format(home,export_cmd,dbuser,password) - elif dbuser != 'sys' and password: - return '''{1};{0}/bin/sqlplus {2}/{3}'''.format(home,export_cmd,dbuser,password) - else: - self.log_info_message("Atleast specify db user and password for db connectivity. Exiting...",self.file_name) - self.prog_exit("127") - -######### Get Password ############## - def get_os_password(self): - """ - get the OS password - """ - ospasswd=self.get_password(None) - return ospasswd - - def get_asm_passwd(self): - """ - get the ASM password - """ - asmpasswd=self.get_password(None) - return asmpasswd - - def get_db_passwd(self): - """ - get the DB password - """ - dbpasswd=self.get_password(None) - return dbpasswd - - def get_sys_passwd(self): - """ - get the sys user password - """ - dbpasswd=self.get_password(None) - return dbpasswd - - def get_password(self,key): - """ - get the password - """ - passwd_file_flag=False - password=None - password_file=None - if self.check_key("SECRET_VOLUME",self.ora_env_dict): - self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["SECRET_VOLUME"]) - msg='''SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) - else: - self.ora_env_dict=self.add_key("SECRET_VOLUME","/run/secrets",self.ora_env_dict) - msg='''SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) - self.log_warn_message(msg,self.file_name) - - if self.check_key("KEY_SECRET_VOLUME",self.ora_env_dict): - self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["KEY_SECRET_VOLUME"]) - msg='''KEY_SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) - else: - if self.check_key("SECRET_VOLUME",self.ora_env_dict): - self.ora_env_dict=self.add_key("KEY_SECRET_VOLUME",self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict) - msg='''KEY_SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) - self.log_warn_message(msg,self.file_name) - - if self.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict): - msg='''COMMON_OS_PWD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) - else: - self.ora_env_dict=self.add_key("COMMON_OS_PWD_FILE","common_os_pwdfile.enc",self.ora_env_dict) - msg='''COMMON_OS_PWD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) - self.log_warn_message(msg,self.file_name) - - if self.check_key("PWD_KEY",self.ora_env_dict): - msg='''PWD_KEY passed as an env variable and set to {0}'''.format(self.ora_env_dict["PWD_KEY"]) - else: - self.ora_env_dict=self.add_key("PWD_KEY","pwd.key",self.ora_env_dict) - msg='''PWD_KEY not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PWD_KEY"]) - self.log_warn_message(msg,self.file_name) - - if self.check_key("PASSWORD_FILE",self.ora_env_dict): - msg='''PASSWORD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) - else: - self.ora_env_dict=self.add_key("PASSWORD_FILE","dbpasswd.file",self.ora_env_dict) - msg='''PASSWORD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) - self.log_warn_message(msg,self.file_name) - - secret_volume = self.ora_env_dict["SECRET_VOLUME"] - key_secret_volume= self.ora_env_dict["KEY_SECRET_VOLUME"] - common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"] - pwd_volume=None - if self.check_key("PWD_VOLUME",self.ora_env_dict): - pwd_volume=self.ora_env_dict["PWD_VOLUME"] - else: - pwd_volume="/var/tmp" - pwd_key = self.ora_env_dict["PWD_KEY"] - passwd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) - dbpasswd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["PASSWORD_FILE"]) - key_file='''{0}/{1}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"],self.ora_env_dict["PWD_KEY"]) - key_secret_volume='''{0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) - self.log_info_message("Password file set to : " + passwd_file,self.file_name) - self.log_info_message("key file set to : " + key_file,self.file_name) - self.log_info_message("dbpasswd file set to : " + dbpasswd_file,self.file_name) - self.log_info_message("key secret voluem set to file set to : " + key_secret_volume,self.file_name) - self.log_info_message("pwd volume set : " + pwd_volume,self.file_name) - #print(passwd_file) - if (os.path.isfile(passwd_file)) and (os.path.isfile(key_file)): - msg='''Passwd file {0} and key file {1} exist. Password file Check passed!'''.format(passwd_file,key_file) - self.log_info_message(msg,self.file_name) - msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file) - self.log_info_message(msg,self.file_name) - cmd=None - if self.check_key("ENCRYPTION_TYPE",self.ora_env_dict): - if self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "aes256": - cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out {2}/{1} -pass file:\"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) - elif self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "rsautl": - cmd ='''openssl rsautl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) - else: - pass - else: - cmd ='''openssl pkeyutl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) - - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - passwd_file_flag = True - password_file='''{0}/{1}'''.format(pwd_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) - elif os.path.isfile(dbpasswd_file): - msg='''Passwd file {0} exist. Password file Check passed!'''.format(dbpasswd_file) - self.log_info_message(msg,self.file_name) - msg='''Reading encrypted passwd from file {0}.'''.format(dbpasswd_file) - self.log_info_message(msg,self.file_name) - cmd='''openssl base64 -d -in \"{0}\" -out \"{2}/{1}\"'''.format(dbpasswd_file,self.ora_env_dict["PASSWORD_FILE"],pwd_volume) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - passwd_file_flag = True - password_file='''{1}/{0}'''.format(self.ora_env_dict["PASSWORD_FILE"],pwd_volume) - - if not passwd_file_flag: - # get random password pf length 8 with letters, digits, and symbols - characters1 = string.ascii_letters + string.digits + "_-%#" - str1 = ''.join(random.choice(string.ascii_uppercase) for i in range(4)) - str2 = ''.join(random.choice(characters1) for i in range(8)) - password=str1+str2 - else: - fname='''{0}'''.format(password_file) - fdata=self.read_file(fname) - password=fdata - self.remove_file(fname) - - if self.check_key("ORACLE_PWD",self.ora_env_dict): - msg="ORACLE_PWD is passed as an env variable. Check Passed!" - self.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.add_key("ORACLE_PWD",password,self.ora_env_dict) - msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file" - self.log_info_message(msg,self.file_name) - -######### Get oraversion ############## - def get_oraversion(self,home): - """ - get the software version - """ - cmd='''{0}/bin/oraversion -majorVersion'''.format(home) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - - return output - -####### Get db lock file location ####### - def get_db_lock_location(self): - """ - get the db location - """ - if self.check_key("DB_LOCK_FILE_LOCATION",self.ora_env_dict): - return self.ora_env_dict["DB_LOCK_FILE_LOCATION"] - else: - ### Please note that you should not change following path as SIDB team is maintaining lock files under following location - return "/tmp/." - -####### Get the TDE Key ############### - def export_tde_key(self,filename): - """ - This function export the tde. - """ - self.log_info_message("Inside gettdekey()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - sqlcmd=''' - ALTER SESSION DISABLE SHARD DDL; - ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET {0} TO {1} IDENTIFIED BY {0}; - '''.format('HIDDEN_STRING',filename) - self.log_info_message("Running the sqlplus command to export the tde: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - -####### Get the TDE Key ############### - def import_tde_key(self,filename): - """ - This function import the TDE key. - """ - self.log_info_message("Inside importtdekey()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - sqlcmd=''' - ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY {0}; - ADMINISTER KEY MANAGEMENT IMPORT ENCRYPTION KEYS WITH SECRET {0} FROM {1} IDENTIFIED BY {0} WITH BACKUP - '''.format('HIDDEN_STRING',filename) - self.log_info_message("Running the sqlplus command to import the tde key: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) -######## Reset the DB Password in database ######## - def reset_passwd(self): - """ - This function reset the password. - """ - password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh") - self.log_info_message("Executing password reset", self.file_name) - if self.check_key("ORACLE_PWD",self.ora_env_dict) and self.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script): - cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING') - self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - self.unset_mask_str() - else: - msg='''Error Occurred! Either HOME DIR {0} does not exist, ORACLE_PWD {1} is not set or PASSWORD SCRIPT {2} does not exist'''.format(self.ora_env_dict["HOME"],self.ora_env_dict["ORACLE_PWD"],password_script) - self.log_error_message(msg,self.file_name) - self.oracommon.prog_exit() \ No newline at end of file diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oraenv.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oraenv.py deleted file mode 100755 index dd96c48..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oraenv.py +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -""" - This file read the env variables from a file or using env command and populate them in variable -""" - -import os - -class OraEnv: - __instance = None - __env_var_file = '/etc/rac_env_vars' - - __env_var_file_flag = None - __env_var_dict = {} - __ora_asm_diskgroup_name = '+DATA' - __ora_gimr_flag = 'false' - __ora_grid_user = 'grid' - __ora_db_user = 'oracle' - __ora_oinstall_group_name = 'oinstall' - encrypt_str__ = None - original_str__ = None - logdir__ = "/tmp/sharding" - - def __init__(self): - """ Virtually private constructor. """ - if OraEnv.__instance != None: - raise Exception("This class is a singleton!") - else: - OraEnv.__instance = self - OraEnv.read_variable() - OraEnv.add_variable() - try: - os.mkdir(OraEnv.logdir__) - except OSError as error: - pass - - @staticmethod - def get_instance(): - """ Static access method. """ - if OraEnv.__instance == None: - OraEnv() - return OraEnv.__instance - - @staticmethod - def read_variable(): - """ Read the variables from a file into dict """ - if OraEnv.__env_var_file_flag: - with open(OraEnv.__env_var_file) as envfile: - for line in envfile: - name, var = line.partition("=")[::2] - OraEnv.__env_var_dict[name.strip()] = var - else: - OraEnv.__env_var_dict = os.environ - - @staticmethod - def add_variable(): - """ Add more variable ased on enviornment with default values in __env_var_dict""" - OraEnv.__env_var_dict["GSM_LOCK_STATUS_FILE"] = "/tmp/.gsm_status_lock_file" - OraEnv.__env_var_dict["SHARD_LOCK_STATUS_FILE"] = "/tmp/.shard_status_lock_file" - if "ORA_ASM_DISKGROUP_NAME" not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict["ORA_ASM_DISKGROUP_NAME"] = "+DATA" - - if "ORA_GRID_USER" not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict["ORA_GRID_USER"] = "grid" - - if "ORA_DB_USER" not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict["ORA_DB_USER"] = "oracle" - - if "ORA_OINSTALL_GROUP_NAME" not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict["ORA_OINSTALL_GROUP_NAME"] = "oinstall" - - @staticmethod - def add_custom_variable(key,val): - """ Addcustom more variable passed from main.py values in __env_var_dict""" - if key not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict[key] = val - - @staticmethod - def get_env_vars(): - """ Static access method to get the env vars. """ - return OraEnv.__env_var_dict - - @staticmethod - def update_env_vars(env_dict): - """ Static access method to get the env vars. """ - OraEnv.__env_var_dict = env_dict - - @staticmethod - def logfile_name(file_type): - """ Static access method to return the logfile name. """ - if file_type == "NONE": - if "LOGFILE_NAME" not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/oracle_sharding_setup.log" - elif file_type == "ADD_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_addition.log" - elif file_type == "VALIDATE_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_validation.log" - elif file_type == "REMOVE_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_remove.log" - elif file_type == "CHECK_LIVENESS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkliveness.log" - elif file_type == "CHECK_READYNESS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkreadyness.log" - elif file_type == "RESET_LISTENER": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_listener.log" - elif file_type == "RESTART_DB": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/restart_db.log" - elif file_type == "CREATE_DIR": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/create_dir.log" - elif file_type == "ADD_SGROUP_PARAMS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/add_sgroup.log" - elif file_type == "DEPLOY_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/deploy_shard.log" - elif file_type == "CANCEL_CHUNKS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/cancel_chunk.log" - elif file_type == "MOVE_CHUNKS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/move_chunks.log" - elif file_type == "CHECK_CHUNKS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_chunks.log" - elif file_type == "CHECK_ONLINE_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_online_shard.log" - elif file_type == "CHECK_GSM_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_gsm_shard.log" - elif file_type == "INVITED_NODE_OP": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/node_invited_op.log" - elif file_type == "RESET_PASSWD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_passwd_file.log" - elif file_type == "TDE_KEY": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/tde_key.log" - else: - pass - - return OraEnv.__env_var_dict["LOG_FILE_NAME"] diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orafactory.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orafactory.py deleted file mode 100755 index 5ddb6e3..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orafactory.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -""" - This file contains to the code call different classes objects based on setup type -""" - -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * -from orapshard import * -from orasshard import * -from orapcatalog import * -from oragsm import * - -import os -import sys - -class OraFactory: - """ - This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - - def get_ora_objs(self): - ''' - Return the instance of a classes which will setup the enviornment. - - Returns: - ofactory_obj: List of objects - ''' - ofactory_obj = [] - - msg='''ora_env_dict set to : {0}'''.format(self.ora_env_dict) - self.ocommon.log_info_message(msg,self.file_name) - - msg="Checking the OP_TYPE and Version to begin the installation" - self.ocommon.log_info_message(msg,self.file_name) - - # Checking the OP_TYPE - if self.ocommon.check_key("OP_TYPE",self.ora_env_dict): - msg='''OP_TYPE variable is set to {0}.'''.format(self.ora_env_dict["OP_TYPE"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("OP_TYPE","nosetup",self.ora_env_dict) - msg="OP_TYPE variable is set to default nosetup. No value passed as an enviornment variable." - self.ocommon.log_info_message(msg,self.file_name) - - # Check the OP_TYPE value and call objects based on it value - if self.ora_env_dict["OP_TYPE"] == 'primaryshard': - msg="Creating and calling instance to setup primary shard" - opshard = OraPShard(self.ologger,self.ohandler,self.oenv,self.ocommon) - self.ocommon.log_info_message(msg,self.file_name) - ofactory_obj.append(opshard) - elif self.ora_env_dict["OP_TYPE"] == 'standbyshard': - msg="Creating and calling instance to setup standby shard" - osshard = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) - self.ocommon.log_info_message(msg,self.file_name) - ofactory_obj.append(osshard) - elif self.ora_env_dict["OP_TYPE"] == 'catalog': - msg="Creating and calling instance to setup Catalog DB" - opcat = OraPCatalog(self.ologger,self.ohandler,self.oenv,self.ocommon) - self.ocommon.log_info_message(msg,self.file_name) - ofactory_obj.append(opcat) - elif self.ora_env_dict["OP_TYPE"] == 'standbycatalog': - msg="Creating and calling instance to setup Catalog DB" - oscat = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) - self.ocommon.log_info_message(msg,self.file_name) - ofactory_obj.append(oscat) - elif self.ora_env_dict["OP_TYPE"] == 'gsm': - msg="Creating and calling instance to setup GSM" - ogsm = OraGSM(self.ologger,self.ohandler,self.oenv,self.ocommon) - self.ocommon.log_info_message(msg,self.file_name) - ofactory_obj.append(ogsm) - else: - msg="OP_TYPE must be set to {primaryshard|standbyshard|catalog|standbycatalog|gsm}" - self.ocommon.log_info_message(msg,self.file_name) - msg="Since OP_TYPE is set to nosetup, only compute env is being setup. Creating and calling instance to setup compute." - self.ocommon.log_info_message(msg,self.file_name) - omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - ofactory_obj.append(omachine) - - return ofactory_obj diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oragsm.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oragsm.py deleted file mode 100755 index ef0bb06..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oragsm.py +++ /dev/null @@ -1,2945 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -import os -import sys -import os.path -import re -import socket -import random -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * - -class OraGSM: - """ - This calss setup the Gsm after DB installation. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This constructor of OraGsm class to setup the Gsm on primary DB. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - - def setup(self): - """ - This function setup the Gsm on Primary DB. - """ - if self.ocommon.check_key("ADD_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.add_gsm_shard() - self.set_hostid_null() - self.add_invited_node("ADD_SHARD") - self.remove_invited_node("ADD_SHARD") - sys.exit(0) - if self.ocommon.check_key("DEPLOY_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.deploy_shard() - self.setup_gsm_service() - sys.exit(0) - elif self.ocommon.check_key("ADD_SGROUP_PARAMS",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.setup_gsm_shardg("ADD_SGROUP_PARAMS") - sys.exit(0) - elif self.ocommon.check_key("ADD_SSPACE_PARAMS",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.setup_gsm_sspace("ADD_SSPACE_PARAMS") - sys.exit(0) - elif self.ocommon.check_key("REMOVE_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - status=self.remove_gsm_shard() - - if status: - sys.exit(0) - else: - sys.exit(1) - - elif self.ocommon.check_key("MOVE_CHUNKS",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.move_shard_chunks() - sys.exit(0) - elif self.ocommon.check_key("TDE_KEY",self.ora_env_dict): - self.ocommon.get_tde_key() - sys.exit(0) - elif self.ocommon.check_key("CANCEL_CHUNKS",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.cancel_move_chunks() - sys.exit(0) - elif self.ocommon.check_key("VALIDATE_NOCHUNKS",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.validate_nochunks() - sys.exit(0) - elif self.ocommon.check_key("CHECK_ONLINE_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.verify_online_shard() - sys.exit(0) - elif self.ocommon.check_key("CHECK_GSM_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.verify_gsm_shard() - sys.exit(0) - elif self.ocommon.check_key("VALIDATE_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.validate_gsm_shard() - sys.exit(0) - elif self.ocommon.check_key("VALIDATE_GSM",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - sys.exit(0) - elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): - filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] - if os.path.exists(filename): - self.ocommon.log_info_message("provisioning is still in progress as file " + filename + " still exist!",self.file_name) - sys.exit(0) - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - status = self.check_gsm_director_status(None) - if not status: - self.ocommon.log_info_message("No GDS setup found on this system.",self.file_name) - self.ocommon.prog_exit("127") - self.ocommon.log_info_message("GSM liveness check completed sucessfully!",self.file_name) - sys.exit(0) - elif self.ocommon.check_key("INVITED_NODE_OP",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.invited_node_op() - sys.exit(0) - elif self.ocommon.check_key("CATALOG_SETUP",self.ora_env_dict): - # If user pass env avariable CATALOG_SETUP true then it will just create gsm director and add catalog but will not add any shard - # It will also add service - status = self.catalog_setup_checks() - if status == False: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.setup_machine() - self.catalog_checks() - self.reset_gsm_setup() - status1 = self.gsm_setup_check() - if status1: - self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) - self.start_gsm_director() - self.ocommon.log_info_message("Started GSM",self.file_name) - else: - # Perform Catalog setup after check GSM_MASTER FLAG. IF GSM MASTER FLAG is set then only catalog will be added. - self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) - master_flag=self.gsm_master_flag_check() - if master_flag: - self.setup_gsm_calog() - self.setup_gsm_director() - self.start_gsm_director() - self.status_gsm_director() - if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': - self.setup_gsm_shardg("SHARD_GROUP") - else: - self.setup_gsm_shardg("SHARD_GROUP") - self.gsm_backup_file() - self.gsm_completion_message() - ### Running Custom Scripts - self.run_custom_scripts() - else: - self.add_gsm_director() - self.start_gsm_director() - self.gsm_backup_file() - self.gsm_completion_message() - else: - # This block run shard addition, catalog addition and service creation - # This block also verifies if master flag is not not GSM director then it will not create catalog but add GSM ony - self.setup_machine() - self.gsm_checks() - self.reset_gsm_setup() - status = self.gsm_setup_check() - if status: - self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) - self.start_gsm_director() - self.ocommon.log_info_message("Started GSM",self.file_name) - else: - # if the status = self.gsm_setup_check() return False then shard addition, catalog addition and service creation - master_flag=self.gsm_master_flag_check() - if master_flag: - self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) - self.setup_gsm_calog() - self.setup_gsm_director() - self.start_gsm_director() - self.status_gsm_director() - if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': - self.setup_gsm_shardg("SHARD_GROUP") - if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': - self.setup_gsm_sspace("SHARD_SPACE") - else: - self.setup_gsm_shardg("SHARD_GROUP") - self.setup_gsm_shard() - self.set_hostid_null() - self.stop_gsm_director() - time.sleep(30) - self.start_gsm_director() - self.add_invited_node("SHARD") - self.remove_invited_node("SHARD") - self.stop_gsm_director() - time.sleep(30) - self.start_gsm_director() - self.deploy_shard() - self.setup_gsm_service() - self.setup_sample_schema() - self.gsm_backup_file() - self.gsm_completion_message() - ### Running Custom Scripts - self.run_custom_scripts() - else: - self.add_gsm_director() - self.start_gsm_director() - self.gsm_backup_file() - self.gsm_completion_message() - - ########### SETUP_MACHINE begins here #################### - ## Function to machine setup - def setup_machine(self): - """ - This function performs the compute before performing setup - """ - self.omachine.setup() - filename = self.ora_env_dict["GSM_LOCK_STATUS_FILE"] - touchfile = 'touch {0}'.format(filename) - if not os.path.isfile(filename): - self.ocommon.log_error_message("Setting file provisioning status file :" + filename ,self.file_name) - output,error,retcode=self.ocommon.execute_cmd(touchfile,None,self.ora_env_dict) - if retcode == 1: - self.ocommon.log_error_message("error occurred while touching the file :" + filename + ". Exiting!",self.file_name) - self.ocommon.prog_exit("127") - - ########### ENDS here #################### - - def gsm_checks(self): - """ - This function perform db checks before starting the setup - """ - self.ohome_check() - self.passwd_check() - self.shard_user_check() - self.gsm_hostname_check() - self.director_params_checks() - self.catalog_params_check() - self.shard_params_check() - self.sgroup_params_check() - - - def catalog_checks(self): - """ - This function perform db checks before starting the setup - """ - self.ohome_check() - self.passwd_check() - self.shard_user_check() - self.gsm_hostname_check() - self.director_params_checks() - self.catalog_params_check() - self.sgroup_params_check() - - def ohome_check(self): - """ - This function performs the oracle home related checks - """ - if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): - self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) - else: - self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) - self.ocommon.prog_exit("127") - - if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): - msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def passwd_check(self): - """ - Set the password - """ - self.ocommon.get_password(None) - if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): - msg='''ORACLE_PWD key is set. Check Passed!''' - self.ocommon.log_info_message(msg,self.file_name) - - def shard_user_check(self): - """ - This funnction set the user for pdb and cdb. - """ - if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): - msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) - msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" - self.ocommon.log_info_message(msg,self.file_name) - - if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): - msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) - msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." - self.ocommon.log_info_message(msg,self.file_name) - - def director_params_checks(self): - """ - This funnction check and set the shard director name - """ - status=False - reg_exp= self.director_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - msg='''SHARD Director PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) - self.ocommon.log_info_message(msg,self.file_name) - status=True - - def gsm_hostname_check(self): - """ - This function check and set the hostname. - """ - if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): - msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): - ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) - hostname='''{0}'''.format(socket.getfqdn()) - else: - hostname='''{0}'''.format(socket.gethostname()) - msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) - self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) - self.ocommon.log_info_message(msg,self.file_name) - - def catalog_params_check(self): - """ - This funnction check if CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is passed as an env variable or not. If not passed then exit. - """ - status=False - reg_exp= self.catalog_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - msg='''CATALOG PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) - self.ocommon.log_info_message(msg,self.file_name) - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - if stype: - if stype.lower() == 'user': - if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) - if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): - self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) - status=True - - if not status: - msg="CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is not set, exiting!" - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def shard_params_check(self): - """ - This funnction check if SHARD[1-9]_PARAMS such as SHARD1_PARAMS is passed as an env variable or not. If not passed then exit. - """ - status=False - reg_exp= self.shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - msg='''SHARD PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) - self.ocommon.log_info_message(msg,self.file_name) - status=True - - if not status: - msg="SHARD[1-9]_PARAMS such as SHARD1_PARAMS is not set, exiting!" - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def sgroup_params_check(self): - """ - This funnction check if SHARD[1-9]_GROUP_PARAMS such as SHARD1_GROUP_PARAMS is passed as an env variable or not. If not passed then exit. - """ - status=False - reg_exp= self.shardg_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - msg='''SHARD GROUP PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) - self.ocommon.log_info_message(msg,self.file_name) - status=True - def gsm_master_flag_check(self): - """ - This funnction check if MASTER_GSM is passed as an env variable or not. If not passed then exit. - """ - status=False - if self.ocommon.check_key("MASTER_GSM",self.ora_env_dict): - msg='''MASTER_GSM is set. This machine will be configured with as master GSM director.''' - self.ocommon.log_info_message(msg,self.file_name) - return True - else: - return False - - def catalog_setup_checks(self): - """ - This function checks if director and catalog is setup and connection is established. - """ - status = False - gsm_status = self.check_gsm_director(None) - #catalog_status = self.check_gsm_catalog() - - if gsm_status == 'completed': - status = True - else: - status = False - - #if catalog_status == 'completed': - # status = True - #else: - # status = False - - return status - ########### DB_CHECKS Related Functions Begin Here #################### - - - ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### - def reset_gsm_setup(self): - """ - This function delete the GSM files. - """ - self.ocommon.log_info_message("Inside reset_gsm_setup",self.file_name) - gsmdata_loc='/opt/oracle/gsmdata' - cmd_list=[] - if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): - if self.ora_env_dict["RESET_ENV"]: - msg='''Deleteing files from {0}'''.format(gsmdata_loc) - self.ocommon.log_info_message(msg,self.file_name) - cmd_list[0]='''rm -f {0}/gsm.ora'''.format(gsmdata_loc) - cmd_list[1]='''rm -f {0}/tnsnames.ora'''.format(gsmdata_loc) - cmd_list[2]='''rm -rf {0}/wallets'''.format(gsmdata_loc) - for cmd in cmd_list: - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - def gsm_setup_check(self): - """ - This function check if GSM is already setup on this - """ - status=True - self.ocommon.log_info_message("Inside gsm_setup_check",self.file_name) - gsmdata_loc='/opt/oracle/gsmdata' - gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) - - gsmora='''{0}/gsm.ora'''.format(gsmdata_loc) - tnsnamesora='''{0}/tnsnames.ora'''.format(gsmdata_loc) - walletloc='''{0}/gsmwallet'''.format(gsmdata_loc) - - if os.path.isfile(gsmora): - cmd='''cp -r -v -f {0} {1}/'''.format(gsmora,gsmfile_loc) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - else: - status=False - - if os.path.isfile(tnsnamesora): - cmd='''cp -r -v -f {0} {1}/'''.format(tnsnamesora,gsmfile_loc) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - else: - status=False - - if os.path.isdir(walletloc): - cmd='''cp -r -v -f {0} {1}/'''.format(walletloc,gsmfile_loc) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - else: - status=False - - if status: - return True - else: - return False - - #################### Catalog related Functions BEGINS Here ########################### - def setup_gsm_calog(self): - """ - This function setup the GSM catalog. - """ - self.ocommon.log_info_message("Inside setup_gsm_calog()",self.file_name) - status=False - reg_exp= self.catalog_regex() - counter=1 - end_counter=60 - catalog_db_status=None - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - catalog_db_status=self.check_setup_status(catalog_host,catalog_db,catalog_pdb,catalog_port) - if catalog_db_status == 'completed': - self.configure_gsm_clog(catalog_host,catalog_db,catalog_pdb,catalog_port,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname) - break - else: - msg='''Catalog Status must return completed but returned value is {0}'''.format(status) - self.ocommon.log_info_message(msg,self.file_name) - if catalog_db_status == 'completed': - break - else: - msg='''Catalog setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - self.ocommon.log_info_message(msg,self.file_name) - time.sleep(60) - counter=counter+1 - - def process_clog_vars(self,key): - """ - This function process catalog vars based on key and return values to configure the GSM - """ - catalog_db=None - catalog_pdb=None - catalog_port=None - catalog_region=None - catalog_host=None - catalog_name=None - catalog_chunks=None - repl_type=None - repl_factor=None - repl_unit=None - stype=None - sspace=None - cfname=None - - self.ocommon.log_info_message("Inside process_clog_vars()",self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - if ckey == 'catalog_db': - catalog_db = cvar_dict[ckey] - if ckey == 'catalog_pdb': - catalog_pdb = cvar_dict[ckey] - if ckey == 'catalog_port': - catalog_port = cvar_dict[ckey] - if ckey == 'catalog_region': - catalog_region = cvar_dict[ckey] - if ckey == 'catalog_host': - catalog_host = cvar_dict[ckey] - if ckey == 'catalog_name': - catalog_name = cvar_dict[ckey] - if ckey == 'catalog_chunks': - catalog_chunks = cvar_dict[ckey] - if ckey == 'repl_type': - repl_type = cvar_dict[ckey] - if ckey == 'repl_factor': - repl_factor = cvar_dict[ckey] - if ckey == 'repl_unit': - repl_unit = cvar_dict[ckey] - if ckey == 'sharding_type': - stype = cvar_dict[ckey] - if ckey == 'shard_space': - sspace = cvar_dict[ckey] - if ckey == 'shard_configname': - cfname = cvar_dict[ckey] - - ## Set the values if not set in above block - if not catalog_port: - catalog_port=1521 - if not catalog_region: - catalog_region="region1,region2" - if stype: - if not sspace: - sspace="shardspace1,shardspace2" - - ### Check values must be set - if catalog_host and catalog_db and catalog_pdb and catalog_port and catalog_region and catalog_name: - return catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname - else: - msg1='''catalog_db={0},catalog_pdb={1}'''.format((catalog_db or "Missing Value"),(catalog_pdb or "Missing Value")) - msg2='''catalog_port={0},catalog_host={1}'''.format((catalog_port or "Missing Value"),(catalog_host or "Missing Value")) - msg3='''catalog_region={0},catalog_name={1}'''.format((catalog_region or "Missing Value"),(catalog_name or "Missing Value")) - msg='''Catalog params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def check_gsm_catalog(self): - """ - This function check the catalog status in GSM - """ - self.ocommon.log_info_message("Inside check_gsm_catalog()",self.file_name) - #dtrname,dtrport,dtregion=self.process_director_vars() - gsmcmd=''' - config; - exit; - '''.format("test") - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) - try: - match=self.ocommon.check_substr_match(matched_output[0],"test") - except: - match=False - return(self.ocommon.check_status_value(match)) - - # output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - # new_output=output[0].replace(" ","") - # self.ocommon.log_info_message(new_output,self.file_name) - # match=self.ocommon.check_substr_match(new_output,"Catalogconnectionisestablished") - # return(self.ocommon.check_status_value(match)) - - def catalog_regex(self): - """ - This function return the rgex to search the CATALOG PARAMS - """ - self.ocommon.log_info_message("Inside catalog_regex()",self.file_name) - return re.compile('CATALOG_PARAMS') - - - def configure_gsm_clog(self,chost,ccdb,cpdb,cport,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname): - """ - This function configure the GSM catalog. - """ - self.ocommon.log_info_message("Inside configure_gsm_clog()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - replist=['native'] - - ### User Define Shardig Variables - shardingtype=None - shardspace=None - configname=None - - # if stype and sspace: - if stype: - if stype.lower() == 'user': - shardingtype="-sharding user" - #shardspace="" - shardspace=" -shardspace {0}".format(sspace) - if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) - if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): - self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) - else: - shardspace="" - shardingtype="" - else: - shardspace="" - shardingtype="" - - if cfname: - configname=" -configname {0}".format(cfname) - else: - configname="" - - ### SNR Sharding - chunks=None - repl=None - repfactor=None - repunits=None - - if catalog_chunks: - chunks="-chunks {0}".format(catalog_chunks) - else: - chunks="" - - if repl_type and repl_type.lower() in replist: - self.ocommon.log_info_message("Repl_Type value Set to in block1:" + repl_type,self.file_name) - repl=" -repl {0}".format(repl_type) - else: - repl="" - - if repl_factor: - repfactor=" -repfactor {0}".format(repl_factor) - else: - repfactor="" - - if repl_unit: - repunits=" -repunits {0}".format(repl_unit) - else: - repunits="" - - invited_subnet="" - add_invited_subnet="" - if self.ocommon.check_key("INVITED_NODE_SUBNET_FLAG",self.ora_env_dict): - if self.ocommon.check_key("INVITED_NODE_SUBNET",self.ora_env_dict): - invited_subnet=self.ora_env_dict["INVITED_NODE_SUBNET"] - else: - #self.ocommon.log_info_message("The catalog Host name is :" + chost,self.file_name) - chost_ip=self.ocommon.get_ip(chost,None) - ip_parts=chost_ip.split('.') - invited_subnet=ip_parts[0] + "." + ip_parts[1] + '.*' + '.*' - add_invited_subnet='''add invitedsubnet {0};'''.format(invited_subnet) - - cpasswd="HIDDEN_STRING" - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - gsmcmd=''' - create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})))\" {7} -user {3}/{4} -sdb {5} -region {6} -agent_port 8080 -agent_password {4} {8} {9} {10} {11} {12} {13} -autovncr off; - add invitednode {0}; - {14} - exit; - '''.format(chost,cport,cpdb,cadmin,cpasswd,catalog_name,catalog_region,chunks,repl,repfactor,repunits,shardingtype,shardspace,configname,add_invited_subnet) - - counter=1 - while counter < 5: - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - if retcode != 0: - self.ocommon.log_info_message("Error occurred while creating the shard catalog, sleeping for 60 seconds",self.file_name) - counter = counter + 1 - time.sleep(60) - else: - break - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - ######################################## GSM director Functions Begins Here ##################### - def process_director_vars(self,key): - """ - This function process GSM director vars based on key and return values to configure the GSM - """ - dtrname=None - dtrport=None - dtregion=None - - self.ocommon.log_info_message("Inside process_director_vars()",self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - if ckey == 'director_name': - dtrname = cvar_dict[ckey] - if ckey == 'director_port': - dtrport = cvar_dict[ckey] - if ckey == 'director_region': - dtregion = cvar_dict[ckey] - - ### Check values must be set - if dtrname and dtrport and dtregion: - return dtrname,dtrport,dtregion - else: - msg1='''director_name={0},director_port={1}'''.format((dtrname or "Missing Value"),(dtrport or "Missing Value")) - msg2='''director_region={0}'''.format((dtregion or "Missing Value")) - msg='''Director params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("Error occurred") - - def check_gsm_director(self,dname): - """ - This function check the GSM director status - """ - self.ocommon.log_info_message("Inside check_gsm_director()",self.file_name) - status=False - if dname: - gsmcmd=self.get_gsm_config_cmd(dname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) - try: - if self.ocommon.check_substr_match(matched_output[0],dname): - status=True - except: - status=False - else: - reg_exp= self.director_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - dname,dtrport,dtregion=self.process_director_vars(key) - gsmcmd=self.get_gsm_config_cmd(dname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) - try: - if self.ocommon.check_substr_match(matched_output[0],dname): - status=True - except: - status=False - - return(self.ocommon.check_status_value(status)) - - def check_gsm_region(self,region): - """ - This function check the GSM regions - """ - self.ocommon.log_info_message("Inside check_gsm_region()",self.file_name) - gsmcmd=self.get_gsm_config_cmd(None) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:Regions\n)(?:.+\n)+",output) - status=False - try: - if self.ocommon.check_substr_match(matched_output[0],region): - status=True - except: - status=False - return(self.ocommon.check_status_value(status)) - - def check_gsm_shardspace(self,sspace): - """ - This function check the GSM shardspace - """ - self.ocommon.log_info_message("Inside check_gsm_shardspace()",self.file_name) - gsmcmd=self.get_gsm_config_cmd(None) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:Shard spaces\n)(?:.+\n)+",output) - status=False - try: - if self.ocommon.check_substr_match(matched_output[0],sspace): - status=True - except: - status=False - return(self.ocommon.check_status_value(status)) - - def check_gsm_director_status(self,dname): - """ - This function check the GSM director status using 'gdsctl status' - """ - self.ocommon.log_info_message("Inside check_gsm_director_status()",self.file_name) - status=False - gsmcmd=''' - status; - exit; - ''' - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - if "Connected to GDS catalog Y".replace(" ","").lower() in output.replace(" ","").lower(): - return True - else: - return False - - def add_gsm_director(self): - """ - This function add the GSM - """ - status=False - counter=1 - end_counter=60 - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - reg_exp= self.director_regex() - - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_director_status=None - dtrname,dtrport,dtregion=self.process_director_vars(key) - shard_director_status=self.check_gsm_director(dtrname) - if shard_director_status != 'completed': - self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) - status = self.check_gsm_director(None) - if status == 'completed': - break - - if status == 'completed': - break - else: - msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - self.ocommon.log_info_message(msg,self.file_name) - time.sleep(60) - counter=counter+1 - - status = self.check_gsm_director(None) - if status == 'completed': - msg='''Shard director setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 60 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def setup_gsm_director(self): - """ - This function setup in GSM - """ - self.ocommon.log_info_message("Inside setup_gsm_director()",self.file_name) - status=False - reg_exp= self.director_regex() - counter=1 - end_counter=3 - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_director_status=None - dtrname,dtrport,dtregion=self.process_director_vars(key) - shard_director_status=self.check_gsm_director(dtrname) - if shard_director_status != 'completed': - self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) - status = self.check_gsm_director(None) - if status == 'completed': - break - else: - msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - time.sleep(60) - counter=counter+1 - - status = self.check_gsm_director(None) - if status == 'completed': - msg='''Shard director setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 3 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin): - """ - This function configure GSM director - """ - ## Getting the values of catalog_port,catalog_pdb,catalog_host - cpasswd="HIDDEN_STRING" - reg_exp= self.catalog_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - sregionFlag=self.check_gsm_region(dtregion) - if sregionFlag != 'completed': - self.configure_gsm_region(dtregion) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - add gsm -gsm {0} -listener {1} -pwd {2} -catalog {3}:{4}/{5} -region {6}; - exit; - '''.format(dtrname,dtrport,cpasswd,catalog_host,catalog_port,catalog_pdb,dtregion,gsmhost) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def start_gsm_director(self): - """ - This function start the director in the GSM - """ - status='noval' - self.ocommon.log_info_message("Inside start_gsm_director() function",self.file_name) - reg_exp= self.director_regex() - counter=1 - end_counter=10 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - dtrname,dtrport,dtregion=self.process_director_vars(key) - gsmcmd=''' - start gsm -gsm {0}; - exit; - '''.format(dtrname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - status=self.check_gsm_director(dtrname) - if status == 'completed': - break; - if status == 'completed': - filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] - remfile='''rm -f {0}'''.format(filename) - if os.path.isfile(filename): - output,error,retcode=self.ocommon.execute_cmd(remfile,None,self.ora_env_dict) - break - else: - msg='''GSM shard director failed to start.Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - self.ocommon.log_error_message(msg,self.file_name) - time.sleep(30) - - counter=counter+1 - - - if status != 'completed': - msg='''GSM shard director failed to start.Exiting!''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def stop_gsm_director(self): - """ - This function stop the director in the GSM - """ - status=False - self.ocommon.log_info_message("Inside stop_gsm_director() function",self.file_name) - reg_exp= self.director_regex() - counter=1 - end_counter=2 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - dtrname,dtrport,dtregion=self.process_director_vars(key) - gsmcmd=''' - stop gsm -gsm {0}; - exit; - '''.format(dtrname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - counter=counter+1 - - def status_gsm_director(self): - """ - This function check the GSM director status - """ - gsm_status = self.check_gsm_director(None) - #catalog_status = self.check_gsm_catalog() - - if gsm_status == 'completed': - msg='''Director setup completed in GSM and catalog is connected''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Shard director in GSM did not complete or not connected to catalog. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - ######################################## Shard Group Setup Begins Here ############################ - def setup_gsm_shardg(self,restype): - """ - This function setup the shard group. - """ - self.ocommon.log_info_message("Inside setup_gsm_shardg()",self.file_name) - status=False - if restype == 'ADD_SGROUP_PARAMS': - reg_exp = self.add_shardg_regex() - elif restype == 'SHARD_GROUP': - reg_exp = self.shardg_regex() - else: - self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SGROUP_PARAMS or SHARD_GROUP key to create a shard group",self.file_name) - self.ocommon.log_warn_message("Since no key specified for ADD_SGROUP_PARAMS and SHARD_GROUP, shardgroup will be created during shard creation",self.file_name) - - sgListC=[] - sgListP=[] - counter=1 - end_counter=3 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_group_status=None - self.ocommon.log_info_message("Key is set to : " + key,self.file_name) - group_name,deploy_as,group_region=self.process_shardg_vars(key) - self.ocommon.log_info_message("Name: " + group_name + "deploy_as" + deploy_as + "group_region" + group_region,self.file_name) - if group_name is not None: - if group_name not in sgListC: - dtrname=self.get_director_name(group_region) - shard_group_status=self.check_shardg_status(group_name,dtrname) - if shard_group_status != 'completed': - self.configure_gsm_shardg(group_name,deploy_as,group_region,'add') - shard_group_status = self.check_shardg_status(group_name,None) - if shard_group_status == 'completed': - sgListC.append(group_name) - if group_name in sgListP: - sgListP.remove(group_name) - else: - sgListP=sgListP.append(group_name) - time.sleep(30) - counter=counter + 1 - - if sgListP == []: - msg='''Shard group setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def get_director_name(self,region_name): - """ - This function get the director name based on the region - """ - self.ocommon.log_info_message("Inside get_director_name()",self.file_name) - status=False - director_name=None - reg_exp= self.director_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - dtrname,dtrport,dtregion=self.process_director_vars(key) - director_name=dtrname - gsm_status = self.check_gsm_director(dtrname) - if gsm_status == 'completed': - status = True - else: - status = False - if dtregion == region_name: - break - if status: - if director_name: - return director_name - else: - self.ocommon.log_error_message("No director exist to match the region",self.file_name) - self.ocommon.prog_exit("127") - else: - self.ocommon.log_error_message("Shard Director is not running!",self.file_name) - self.ocommon.prog_exit("127") - - def get_shardg_region_name(self,sgname): - """ - This function get the region name based on shard group name - """ - self.ocommon.log_info_message("Inside get_region_name()",self.file_name) - status=False - region_name=None - reg_exp= self.shardg_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - group_name,deploy_as,group_region=self.process_shardg_vars(key) - region_name=group_region - if sgname == group_name: - status=True - break - if status: - return region_name - else: - self.ocommon.log_error_message("No such shard group exist! exiting!",self.file_name) - self.ocommon.prog_exit("127") - - def process_shardg_vars(self,key): - """ - This function process shardG vars based on key and return values to configure the GSM - """ - group_name=None - deploy_as=None - group_region=None - - self.ocommon.log_info_message("Inside process_shardg_vars()",self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - if ckey == 'group_name': - group_name = cvar_dict[ckey] - if ckey == 'deploy_as': - deploy_as = cvar_dict[ckey] - if ckey == 'group_region': - group_region = cvar_dict[ckey] - - ### Check values must be set - if group_name and deploy_as and group_region: - return group_name,deploy_as,group_region - else: - msg1='''group_name={0},deploy_as={1}'''.format((group_name or "Missing Value"),(deploy_as or "Missing Value")) - msg2='''group_region={0}'''.format((group_region or "Missing Value")) - msg='''Shard group params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("Error occurred") - - - def check_shardg_status(self,group_name,dname): - """ - This function check the shard status in GSM - """ - self.ocommon.log_info_message("Inside check_shardg_status()",self.file_name) - status=False - - gsmcmd=self.get_gsm_config_cmd(dname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) - if self.ocommon.check_substr_match(matched_output[0],group_name): - status=True - else: - status=False - - ''' - else: - reg_exp= self.shardg_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - group_name,deploy_as,group_region=self.process_shardg_vars(key) - dname=self.get_director_name(group_region) - gsmcmd=self.get_gsm_config_cmd(dname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) - # match=re.search("(?i)(?m)"+group_name,matched_output) - if self.ocommon.check_substr_match(matched_output[0],group_name): - status=True - else: - status=False - ''' - - return(self.ocommon.check_status_value(status)) - -############################################# Director Related Block ############ - def get_director_name(self,region_name): - """ - This function get the director name based on the region - """ - self.ocommon.log_info_message("Inside get_director_name()",self.file_name) - status=False - director_name=None - reg_exp= self.director_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - dtrname,dtrport,dtregion=self.process_director_vars(key) - director_name=dtrname - gsm_status = self.check_gsm_director(dtrname) - if gsm_status == 'completed': - status = True - else: - status = False - if dtregion == region_name: - break - if status: - if director_name: - return director_name - else: - self.ocommon.log_error_message("No director exist to match the region",self.file_name) - self.ocommon.prog_exit("127") - else: - self.ocommon.log_error_message("Shard Director is not running!",self.file_name) - self.ocommon.prog_exit("127") - -######## - - def get_gsm_config_cmd(self,dname): - """ - Get the GSM config command - """ - self.ocommon.log_info_message("Inside get_gsm_config_cmd()",self.file_name) - gsmcmd=''' - config; - exit; - '''.format("test") - return gsmcmd - - def director_regex(self): - """ - This function return the rgex to search the SHARD DIRECTOR PARAMS - """ - self.ocommon.log_info_message("Inside director_regex()",self.file_name) - return re.compile('SHARD_DIRECTOR_PARAMS') - - def shardg_regex(self): - """ - This function return the rgex to search the SHARD GROUP PARAMS - """ - self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) - return re.compile('SHARD[0-9]+_GROUP_PARAMS') - - def add_shardg_regex(self): - """ - This function return the rgex to search the SHARD GROUP PARAMS - """ - self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) - return re.compile('ADD_SGROUP_PARAMS') - - def configure_gsm_shardg(self,group_name,deploy_as,group_region,type): - """ - This function configure the Shard Group. - """ - self.ocommon.log_info_message("Inside configure_gsm_shardg()",self.file_name) - cmd=None - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - dtrname=self.get_director_name(group_region) - reg_exp= self.catalog_regex() - if type == 'modify': - cmd=''' modify shardgroup -shardgroup {0} '''.format(group_name) - else: - cmd=''' add shardgroup -shardgroup {0} '''.format(group_name) - - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - if repl_type: - cmd=cmd + " -region {0} ".format(group_region) - else: - cmd=cmd + " -deploy_as {0} -region {1} ".format(deploy_as,group_region) - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - gsmcmd=''' - connect {1}/{2}; - {3}; - exit; - '''.format("NA",cadmin,cpasswd,cmd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - -############# Adding Shard Regions ############### - def configure_gsm_region(self,region): - """ - This function configure the Shard region. - """ - self.ocommon.log_info_message("Inside configure_gsm_region()",self.file_name) - cmd=None - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - gsmcmd=''' - connect {1}/{2}; - add region -region {3}; - exit; - '''.format("NA",cadmin,cpasswd,region) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - -##################### Adding Shard Space ############### - def process_sspace_vars(self,key): - """ - This function process shardG vars based on key and return values to configure the GSM - """ - sspace=None - chunks=None - repfactor=None - repunits=None - protectedmode=None - self.ocommon.log_info_message("Inside process_sspace_vars()",self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - if ckey == 'sspace_name': - sspace = cvar_dict[ckey] - if ckey == 'chunks': - chunks = cvar_dict[ckey] - if ckey == 'repfactor': - repfactor = cvar_dict[ckey] - if ckey == 'repunits': - repunits = cvar_dict[ckey] - if ckey == 'protectedmode': - protectedmode = cvar_dict[ckey] - - ### Check values must be set - if sspace: - return sspace,chunks,repfactor,repunits,protectedmode - else: - msg1='''sspace={0}'''.format((sspace or "Missing Value")) - msg='''Shard space params {0} is not set correctly. One or more value is missing {1}'''.format(key,msg1) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("Error occurred") - - def setup_gsm_sspace(self,restype): - """ - This function setup the shard sspace. - """ - self.ocommon.log_info_message("Inside setup_gsm_sspace()",self.file_name) - status=False - if restype == 'ADD_SSPACE_PARAMS': - reg_exp = self.add_shardg_regex() - elif restype == 'SHARD_SPACE': - reg_exp = self.shardg_regex() - else: - self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SSPACE_PARAMS or SHARD_SPACE key to create a shard space",self.file_name) - self.ocommon.log_warn_message("Since no ADD_SSPACE_PARAMS or SHARD_SPACE defined, shardspace will be created during shard creation",self.file_name) - counter=1 - ssListC=[] - ssListP=[] - counter=1 - end_counter=3 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_space_status=None - sspace,chunks,repfactor,repuntis,protectedmode=self.process_sspace_vars(key) - if sspace is not None: - if sspace not in ssListC: - shard_sspace_status=self.check_gsm_shardspace(sspace) - if shard_sspace_status != 'completed': - self.configure_gsm_sspace(sspace,chunks,repfactor,repuntis,protectedmode,'add') - shard_space_status = self.check_gsm_shardspace(sspace) - if shard_sspace_status == 'completed': - ssListC.append(sspace) - if sspace in sgListP: - sgListP.remove(sspace) - else: - sgListP=sgListP.append(sspace) - time.sleep(30) - counter=counter + 1 - - if ssListP == []: - msg='''Shard space setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 2 minute to complete shard space setup in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def configure_gsm_sspace(self,sspace,chunks,repfactor,repunits,protectedmode,type): - """ - This function configure the Shard Group. - """ - self.ocommon.log_info_message("Inside configure_gsm_sspace()",self.file_name) - cmd=None - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - if type == 'MODIFY': - cmd=''' modify shardspace -shardspace {0} '''.format(sspace) - else: - cmd=''' add shardspace -shardspace {0} '''.format(sspace) - if chunks is not None: - cmd = cmd + ''' -chunks {0}'''.format(chunks) - if repfactor: - cmd = cmd + ''' -repfactor {0}'''.format(repfactor) - if repunits is not None: - cmd = cmd + ''' -repunits {0}'''.format(repfactor) - if protectedmode is not None: - cmd = cmd + ''' -protectedmode {0}'''.format(protectedmode) - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - gsmcmd=''' - connect {1}/{2}; - {3}; - exit; - '''.format("NA",cadmin,cpasswd,cmd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - #########################################Shard Function Begins Here ############################## - def setup_gsm_shard(self): - """ - This function setup and add shard in the GSM - """ - self.ocommon.log_info_message("Inside setup_gsm_shard()",self.file_name) - status=False - reg_exp= self.shard_regex() - counter=1 - end_counter=60 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db_status=None - shard_db,shard_pdb,shard_port,shard_group,shard_host,sregion,sspace=self.process_shard_vars(key) - shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) - if shard_db_status == 'completed': - self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,sregion,sspace) - else: - msg='''Shard db status must return completed but returned value is {0}'''.format(status) - self.ocommon.log_info_message(msg,self.file_name) - - status = self.check_shard_status(None) - if status == 'completed': - break - else: - msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - self.ocommon.log_info_message(msg,self.file_name) - time.sleep(60) - counter=counter+1 - - status = self.check_shard_status(None) - if status == 'completed': - msg='''Shard DB setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 60 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def add_gsm_shard(self): - """ - This function add the shard in the GSM - """ - self.ocommon.log_info_message("Inside add_gsm_shard()",self.file_name) - status=False - reg_exp= self.add_shard_regex() - counter=1 - end_counter=3 - shard_name="none" - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db_status=None - shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) - shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) - shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) - self.ocommon.log_info_message("Shard Status : " + shard_db_status,self.file_name) - if shard_db_status == 'completed': - self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,shard_region,shard_space) - counter2=1 - end_counter2=5 - while counter2 < end_counter2: - status1 = self.check_shard_status(shard_name) - if status1 == 'completed': - msg='''Shard DB setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - break - else: - msg='''Shard DB is still not added in GSM. Sleeping for 60 seconds''' - self.ocommon.log_info_message(msg,self.file_name) - time.sleep(60) - counter2=counter2+1 - else: - msg='''Shard db status must return completed but returned value is {0}'''.format(status) - self.ocommon.log_info_message(msg,self.file_name) - - status = self.check_shard_status(None) - if status == 'completed': - break - else: - msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - self.ocommon.log_info_message(msg,self.file_name) - time.sleep(60) - counter=counter+1 - status = self.check_shard_status(shard_name) - if status == 'completed': - msg='''Shard DB setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 3 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def remove_gsm_shard(self): - """ - This function remove the shard in the GSM - """ - self.ocommon.log_info_message("Inside remove_gsm_shard()",self.file_name) - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars("CATALOG_PARAMS") - numOfShards=self.count_online_shards() - status=False - reg_exp=self.remove_shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db_status=None - shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) - shardname_to_delete=shard_db + "_" + shard_pdb - if repl_type is not None: - if(repl_type.upper() == 'NATIVE'): - self.move_shards_leader_rus(shardname_to_delete) - leaderCount=self.count_leader_shards(shardname_to_delete) - if(numOfShards < 4 or leaderCount > 0): - msg='''ruType=[{0}]. NumofShards=[{1}]. LeaderCount=[{2}]. Ignoring remove of shard [{3}]'''.format(repl_type,numOfShards,leaderCount,shardname_to_delete) - self.ocommon.log_info_message(msg,self.file_name) - break - - self.move_shard_rus(shardname_to_delete,None,None) - while self.count_shard_rus(shardname_to_delete) > 0: - self.ocommon.log_info_message("Waiting for all the shard chunks to be moved.",self.file_name) - time.sleep(15) - - shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) - if shard_db_status == 'completed': - self.delete_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group) - status=True - else: - msg='''Shard db status must return completed but returned value is {0}'''.format(status) - self.ocommon.log_info_message(msg,self.file_name) - - return status - - def move_shards_leader_rus(self,shardname_to_delete): - """ - This function move the shard leader RUs - """ - shards=self.get_online_shards() - leader_ru=self.get_rus(shardname_to_delete) - all_ru=self.get_rus(None) - count=0 - target_shards=[] - value=0 - - if len(shards) == 0: - msg="""No Shard is online so no RU is available to be moved""" - self.ocommon.log_info_message(msg,self.file_name) - else: - for line in leader_ru: - value=None - count += 1 - cols=line.split() - if len(cols) > 0: - if cols[0].lower() == shardname_to_delete.lower(): - if cols[1].isdigit: - value = int(cols[1]) - else: - continue - - target_shards.clear() - for line1 in all_ru: - cols1=line1.split() - print(cols1) - if len(cols1) > 5: - if cols1[0].lower() != shardname_to_delete.lower() and cols1[1].isdigit and cols1[2].lower() == 'follower': - if value is not None: - if int(cols1[1]) == value: - target_shards.append(cols1[0]) - break - - for shard in shards: - if shard.lower() != shardname_to_delete.lower(): - if shard in target_shards: - msg="Shard_name= " + shard + " Status=True" + " Value = " + str(value) - self.ocommon.log_info_message(msg,self.file_name) - self.move_shard_rus(shardname_to_delete,shard,value) - - def move_shard_chunks(self): - """ - This function move the shard chunks - """ - self.ocommon.log_info_message("Inside move_shard_chunks()",self.file_name) - status=False - reg_exp= self.move_chunks_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - move_chunks_status=None - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - shard_num = self.count_online_shards() - online_shard = self.check_online_shard(shard_name) - if shard_num > 1 and online_shard == 0 : - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - MOVE CHUNK -CHUNK ALL -SOURCE {0} - config shard; - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def validate_nochunks(self): - """ - This function check the chnunks - """ - self.ocommon.log_info_message("Inside validate_nochunks()",self.file_name) - status=False - reg_exp= self.move_nochunks_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - move_chunks_status=None - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - shard_num = self.count_online_shards() - online_shard = self.check_online_shard(shard_name) - if shard_num > 1 and online_shard == 0 : - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - config chunks -shard {0} - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - matched_output=re.findall("(?:Chunks\n)(?:.+\n)+",output) - if self.ocommon.check_substr_match(matched_output[0].lower(),shard_name.lower()): - self.ocommon.prog_exit("127") - - def move_chunks_regex(self): - """ - This function return the rgex to search the SHARD PARAMS - """ - self.ocommon.log_info_message("Inside move_chnuks_regex()",self.file_name) - return re.compile('MOVE_CHUNKS') - - def move_nochunks_regex(self): - """ - This function return the rgex to search the SHARD PARAMS - """ - self.ocommon.log_info_message("Inside move_nochunks_regex()",self.file_name) - return re.compile('VALIDATE_NOCHUNKS') - - def check_shard_chunks(self): - """ - This function check the shard chunks - """ - self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) - status=False - reg_exp= self.check_chunks_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - move_chunks_status=None - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - online_shard = self.check_online_shard(shard_name) - if online_shard == 0 : - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - config chunks -shard {0} - config shard; - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - - def check_chunks_regex(self): - """ - This function return the rgex to search the chunks - """ - self.ocommon.log_info_message("Inside check_chunks_regex()",self.file_name) - return re.compile('CHECK_CHUNKS') - - def cancel_move_chunks(self): - """ - This function cancel the shard Chunks - """ - self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) - status=False - reg_exp= self.cancel_chunks_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - move_chunks_status=None - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - online_shard = self.check_online_shard(shard_name) - if online_shard == 1: - self.ocommon.log_info_message("Shard is not online. Performing chunk cancellation in GSM to set the shard chunk status.",self.file_name) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - ALTER MOVE -cancel -SHARD {0} - config shard; - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - else: - self.ocommon.log_info_message("Shard " + shard_name + " is online. Unable to perform chunk cancellation.",self.file_name) - - def cancel_chunks_regex(self): - """ - This function return the cancel chunk movement - """ - self.ocommon.log_info_message("Inside cancel_chunks_regex()",self.file_name) - return re.compile('CANCEL_CHUNKS') - - def verify_online_shard(self): - """ - This function verify online shard - """ - self.ocommon.log_info_message("Inside verify_online_shard()",self.file_name) - status=False - reg_exp= self.online_shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - online_shard = self.check_online_shard(shard_name) - if online_shard == 0: - msg='''Shard {0} is online.'''.format(shard_name) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Shard {0} is not online.'''.format(shard_name) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.prog_exit("157") - - - def online_shard_regex(self): - """ - This function return the rgex to search the ONLINE Shards - """ - self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) - return re.compile('CHECK_ONLINE_SHARD') - - def check_online_shard(self,shard_name): - """ - This function check the online shard - """ - self.ocommon.log_info_message("Inside check_online_shard()",self.file_name) - name_flag = False - availability_flag = False - state_flag = False - status_flag = False - - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - config shard -shard {0}; - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - lines = output.split("\n") - for line in lines: - list1 = line.split(":") - if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): - name_flag = True - if list1[0].strip().lower() == 'Availability'.lower() and list1[1].strip().lower() == 'ONLINE'.lower(): - availability_flag = True - if list1[0].strip().lower() == 'STATUS'.lower() and list1[1].strip().lower() == 'OK'.lower(): - status_flag = True - if list1[0].strip().lower() == 'STATE'.lower() and list1[1].strip().lower() == 'DEPLOYED'.lower(): - state_flag = True - - del list1[:] - - if name_flag and availability_flag and state_flag and status_flag: - return 0 - else: - return 1 - - def verify_gsm_shard(self): - """ - This function verify GSM shard - """ - self.ocommon.log_info_message("Inside verify_gsm_shard()",self.file_name) - status=False - reg_exp= self.check_shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - gsm_shard = self.check_gsm_shard(shard_name) - if gsm_shard == 0: - msg='''Shard {0} is present in GSM.'''.format(shard_name) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Shard {0} is not present in GSM.'''.format(shard_name) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.prog_exit("157") - - def check_shard_regex(self): - """ - This function return the rgex to search the Shards in GSM - """ - self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) - return re.compile('CHECK_GSM_SHARD') - - def check_gsm_shard(self,shard_name): - """ - This function check the shard in gsm - """ - self.ocommon.log_info_message("Inside check_gsm_shard()",self.file_name) - name_flag = False - - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - config shard -shard {0}; - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - lines = output.split("\n") - for line in lines: - list1 = line.split(":") - if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): - name_flag = True - - del list1[:] - - if name_flag: - return 0 - else: - return 1 - - def count_online_shards(self): - """ - This function return the returns the count of online shard - """ - self.ocommon.log_info_message("Inside count_online_shards()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {0}/{1}; - config shard; - exit; - '''.format(cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - online_shard = 0 - lines = output.split("\n") - for line in lines: - if re.search('ok', line, re.IGNORECASE): - if re.search('deployed', line, re.IGNORECASE): - if re.search('online', line, re.IGNORECASE): - online_shard = online_shard + 1 - - return online_shard - - def get_online_shards(self): - """ - This function return the returns the count of online shard - """ - self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {0}/{1}; - config shard; - exit; - '''.format(cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - shards=[] - online_shard = 0 - for line in output.split("\n"): - cols=line.split() - print(cols) - if len(cols) >= 5: - if cols[5].lower() == "online" and cols[2].lower() == "ok": - shards.append(cols[0]) - - return shards - - def get_rus(self,shardname_to_delete): - """ - This function return the returns the count of online shard - """ - self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - cmd=None - if shardname_to_delete is not None: - cmd='''status ru -leaders -shard {0}'''.format(shardname_to_delete) - else: - cmd='''status ru''' - - gsmcmd=''' - connect {0}/{1}; - {2}; - exit; - '''.format(cadmin,cpasswd,cmd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - return output.split('\n') - - def move_shard_rus(self,sshard,tshard,runum): - """ - This function move the shard rus - """ - self.ocommon.log_info_message("Inside move_shard_rus()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - cmd1="" - cmd2="" - shardname=sshard - if tshard is not None and runum is not None: - cmd1='''switchover ru -RU {0} -shard {1}'''.format(runum,tshard) - else: - cmd1='''MOVE RU -RU ALL -SOURCE {0}'''.format(shardname) - - gsmcmd=''' - connect {1}/{2}; - configure -verbose off -save_config; - {3}; - status RU -shard {0}; - exit; - '''.format(shardname,cadmin,cpasswd,cmd1,cmd2) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def count_shard_rus(self,shardname): - """ - This function return the returns the count of online shard chunks - """ - self.ocommon.log_info_message("Inside count_shard_chunks()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {0}/{1}; - status ru -shard {2}; - exit; - '''.format(cadmin,cpasswd,shardname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - ru_count = 0 - lines = output.split("\n") - for line in lines: - if re.search(shardname, line, re.IGNORECASE): - ru_count = ru_count + 1 - - return ru_count - - def count_leader_shards(self,shardName): - """ - This function return the returns the count of online shard - """ - self.ocommon.log_info_message("Inside count_leader_shards()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {0}/{1}; - status ru -shard {2} -leaders; - exit; - '''.format(cadmin,cpasswd,shardName) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - leader_shard = 0 - lines = output.split("\n") - for line in lines: - if re.search('ok', line, re.IGNORECASE): - if re.search('Leader', line, re.IGNORECASE): - leader_shard = leader_shard + 1 - - return leader_shard - - def validate_gsm_shard(self): - """ - This function validate the shard in the GSM - """ - self.ocommon.log_info_message("Inside validate_gsm_shard()",self.file_name) - status=False - reg_exp= self.validate_shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) - shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) - status = self.check_shard_status(shard_name) - if status == 'completed': - msg='''Shard DB setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Shard {0} info does not exist in GSM.'''.format(shard_name) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.prog_exit("157") - - def process_shard_vars(self,key): - """ - This function process sgard vars based on key and return values to configure the GSM - """ - shard_db=None - shard_pdb=None - shard_port=None - shard_group=None - shard_host=None - shard_region=None - shard_space=None - shard_deploy_as=None - - self.ocommon.log_info_message("Inside process_shard_vars()",self.file_name) - # self.ocommon.log_info_message(key,self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_str=cvar_str.replace('"', '') - # self.ocommon.log_info_message(cvar_str,self.file_name) - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - # self.ocommon.log_info_message("key : " + ckey,self.file_name) - # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) - if ckey == 'shard_db': - shard_db = cvar_dict[ckey] - if ckey == 'shard_pdb': - shard_pdb = cvar_dict[ckey] - if ckey == 'shard_port': - shard_port = cvar_dict[ckey] - if ckey == 'shard_group': - shard_group = cvar_dict[ckey] - if ckey == 'shard_host': - shard_host = cvar_dict[ckey] - if ckey == 'shard_region': - #shard_region = self.validate_shard_param("region",cvar_dict[ckey]) - shard_region=cvar_dict[ckey] - if ckey == 'deploy_as': - shard_deploy_as=cvar_dict[ckey] - if ckey == 'shard_space': - #shard_space = self.validate_shard_param("shardspace",cvar_dict[ckey]) - shard_space=cvar_dict[ckey] - # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) - ## Set the values if not set in above block - if not shard_port: - shard_port=1521 - - if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': - shard_group="nogrp" - if not shard_deploy_as: - self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS","primary",self.ora_env_dict) - else: - self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS",shard_deploy_as,self.ora_env_dict) - - ### Check values must be set - if shard_host and shard_db and shard_pdb and shard_port and shard_group: - return shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space - else: - msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) - msg2='''shard_port={0},shard_host={1}'''.format((shard_port or "Missing Value"),(shard_host or "Missing Value")) - msg3='''shard_group={0}'''.format((shard_group or "Missing Value")) - msg='''Shard DB params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.prog_exit("Error occurred") - - def validate_shard_param(self,param_type,value): - """ - This function validaet the shard param such as region and shardspace - """ - status=False - reg_exp= self.catalog_regex() - stype=None - sspace=None - catalog_region=None - self.ocommon.log_info_message("Processing GSM params to verify the region and shardspace",self.file_name) - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - - if param_type == 'region': - if stype: - status=self.ocommon.find_str_in_string(catalog_region,'comma',value) - if status: - - return value - else: - return "" - - if param_type == 'shardspace': - if sspace: - status=self.ocommon.find_str_in_string(sspace,'comma',value) - if status: - return value - else: - return "" - - return False - - def process_chunks_vars(self,key): - """ - This function process the chunks vars - """ - shard_db=None - shard_pdb=None - self.ocommon.log_info_message("Inside process_chunks_vars()",self.file_name) - # self.ocommon.log_info_message(key,self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_str=cvar_str.replace('"', '') - # self.ocommon.log_info_message(cvar_str,self.file_name) - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - # self.ocommon.log_info_message("key : " + ckey,self.file_name) - # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) - if ckey == 'shard_db': - shard_db = cvar_dict[ckey] - if ckey == 'shard_pdb': - shard_pdb = cvar_dict[ckey] - # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) - ## Set the values if not set in above block - - ### Check values must be set - if shard_pdb and shard_db: - return shard_db,shard_pdb - else: - msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) - self.ocommon.log_info_message(msg1,self.file_name) - self.ocommon.prog_exit("Error occurred") - - def check_shard_status(self,shard_name): - """ - This function check the shard status in GSM - """ - self.ocommon.log_info_message("Inside check_shard_status()",self.file_name) - #gsmcmd=self.get_gsm_config_cmd(dname) - gsmcmd=''' - config; - exit; - ''' - counter=1 - end_counter=3 - status=False - while counter < end_counter: - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - error_check=re.findall("(?:GSM-45034\n)(?:.+\n)+",output) - try: - if self.ocommon.check_substr_match(error_check[0],"GSM-45034"): - count = counter + 1 - self.ocommon.log_info_message("Issue in catalog connection, retrying to connect to catalog in 30 seconds!",self.file_name) - time.sleep(20) - status=False - continue - except: - status=False - matched_output=re.findall("(?:Databases\n)(?:.+\n)+",output) - if shard_name: - try: - if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): - status=True - break - else: - status=False - except: - status=False - else: - reg_exp= self.shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb,shard_port,shard_region,shard_host,shard_region,shard_space=self.process_shard_vars(key) - shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) - try: - if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): - status=True - else: - status=False - except: - status=False - if status: - break; - counter = counter + 1 - - return(self.ocommon.check_status_value(status)) - - def shard_regex(self): - """ - This function return the rgex to search the SHARD PARAMS - """ - self.ocommon.log_info_message("Inside shard_regex()",self.file_name) - return re.compile('SHARD[0-9]+_PARAMS') - - def add_shard_regex(self): - """ - This function return the rgex to search the ADD_SHARD_PARAMS - """ - self.ocommon.log_info_message("Inside add_shard_regex()",self.file_name) - return re.compile('ADD_SHARD') - - def remove_shard_regex(self): - """ - This function return the rgex to search the REMOVE_SHARD_PARAMS - """ - self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) - return re.compile('REMOVE_SHARD') - - def validate_shard_regex(self): - """ - This function return the rgex to search the VALIDATE_SHARD_PARAMS - """ - self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) - return re.compile('VALIDATE_SHARD') - - def configure_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup,sregion,sspace): - """ - This function configure the shard db. - """ - spasswd="HIDDEN_STRING" - admuser= self.ora_env_dict["SHARD_ADMIN_USER"] - #dtrname,dtrport,dtregion=self.process_director_vars() - #group_region=self.get_shardg_region_name(sgroup) - #dtrname=self.get_director_name(group_region) - shard_name='''{0}_{1}'''.format(scdb,spdb) - shard_region=None - shard_space=None - shard_group=None - deploy_as=None - - if sregion: - regionFlag=self.check_gsm_region(sregion) - if regionFlag != 'completed': - self.configure_gsm_region(sregion) - shard_region=" -region {0}".format(sregion) - else: - shard_region="" - if sspace: - shard_space=" -shardspace {0}".format(sspace) - else: - shard_space="" - - if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': - sspaceFlag=self.check_gsm_shardspace(sspace) - if sspaceFlag != 'completed': - self.configure_gsm_sspace(sspace,None,None,None,None,'add') - shard_group="" - deploy_as,deploy_type=self.get_shard_deploy() - else: - shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) - shard_region="" - else: - shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) - shard_region="" - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - add cdb -connect {3}:{4}/{5} -pwd {2}; - add shard -cdb {5} -connect "(DESCRIPTION = (ADDRESS = (PROTOCOL = tcp)(HOST = {3})(PORT = {4})) (CONNECT_DATA = (SERVICE_NAME = {6}) (SERVER = DEDICATED)))" {7} -pwd {2} {9} {10} {11}; - config vncr; - exit; - '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,shard_group,shard_name,shard_region,shard_space,deploy_as) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def get_shard_deploy(self): - """ - get the shard deploy - """ - deploy_as=None - deploy_type=None - if self.ocommon.check_key("SHARD_DEPLOY_AS",self.ora_env_dict): - deploy_as="-deploy_as {0}".format(self.ora_env_dict["SHARD_DEPLOY_AS"]) - deploy_type=self.ora_env_dict["SHARD_DEPLOY_AS"] - else: - deploy_as="-deploy_as primary" - deploy_type='primary' - - return deploy_as,deploy_type - - def get_shardg_cmd(self,sgroup,sregion): - """ - Getting shard group cmd - """ - sgFlag=self.check_shardg_status(sgroup,None) - deploy_as,deploy_type=self.get_shard_deploy() - if sgFlag != 'completed': - self.configure_gsm_shardg(sgroup,deploy_type,sregion,'add') - else: - self.ocommon.log_info_message("Shardgroup exist " + sgroup, self.file_name) - - deploy_as="" - cmd=''' -shardgroup {0}'''.format(sgroup) - return cmd,deploy_as - - def delete_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup): - """ - This function delete the shard db. - """ - spasswd="HIDDEN_STRING" - admuser= self.ora_env_dict["SHARD_ADMIN_USER"] - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - shard_name='''{0}_{1}'''.format(scdb,spdb) - #group_region=self.get_shardg_region_name(sgroup) - #dtrname=self.get_director_name(group_region) - gsmcmd=''' - connect {1}/{2}; - remove shard -shard {8}; - remove cdb -cdb {5}; - remove invitednode {3}; - config vncr; - exit; - '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,sgroup,shard_name) - - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def set_hostid_null(self): - """ - This function set the hostid to Null - """ - spasswd="HIDDEN_STRING" - admuser= self.ora_env_dict["SHARD_ADMIN_USER"] - reg_exp= self.catalog_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_pdb,admuser) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Setting host Id null in catalog as auto vncr is disabled''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set echo on - set termout on - set time on - update gsmadmin_internal.database set hostid=NULL; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - self.ocommon.unset_mask_str() - - def invited_node_op(self): - """ - This function perform the invitedaddition and deletion - """ - self.ocommon.log_info_message("Inside invited_node_op()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - shard_host=self.ora_env_dict["INVITED_NODE_OP"] - gsmcmd=''' - connect {1}/{2}; - remove invitednode {3}; - add invitednode {3}; - exit; - '''.format("NA",cadmin,cpasswd,shard_host) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - def add_invited_node(self,op_str): - """ - This function add the invited in the GSM configuration - """ - self.ocommon.log_info_message("Inside add_invited_node()",self.file_name) - if op_str == "SHARD": - reg_exp = self.shard_regex() - else: - reg_exp = self.add_shard_regex() - - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) - #group_region=self.get_shardg_region_name(shard_group) - #dtrname=self.get_director_name(group_region) - gsmcmd=''' - connect {1}/{2}; - add invitednode {3}; - exit; - '''.format("NA",cadmin,cpasswd,shard_host) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - def remove_invited_node(self,op_str): - """ - This function remove the invited in the GSM configuration - """ - self.ocommon.log_info_message("Inside remove_invited_node()",self.file_name) - if op_str == "SHARD": - reg_exp = self.shard_regex() - else: - reg_exp = self.add_shard_regex() - - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - - if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) - temp_host= shard_host.split('.',1)[0] - #group_region=self.get_shardg_region_name(shard_group) - #dtrname=self.get_director_name(group_region) - gsmcmd=''' - connect {1}/{2}; - remove invitednode {3}; - exit; - '''.format("NA",cadmin,cpasswd,temp_host) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - else: - self.ocommon.log_info_message("KUBE_SVC is not set. No need to remove invited node!",self.file_name) - - - def deploy_shard(self): - """ - This function deploy shard - """ - self.ocommon.log_info_message("Inside deploy_shard()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - shrdg_sspace=None - #dtrname,dtrport,dtregion=self.process_director_vars() - #if op_str == "SHARD": - # reg_exp = self.shard_regex() - #else: - # reg_exp = self.add_shard_regex() - - #for key in self.ora_env_dict.keys(): - # if(reg_exp.match(key)): - if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': - shardg_shardspace="config shardspace" - else: - shardg_shardspace="config shardgroup" - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - {3}; - config vncr; - deploy; - config shard; - exit; - '''.format("test",cadmin,cpasswd,shardg_shardspace) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def check_setup_status(self,host,ccdb,svc,port): - """ - This function check the shard status. - """ - systemStr='''{0}/bin/sqlplus "system/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,ccdb) - - fname='''/tmp/{0}'''.format("shard_setup.txt") - self.ocommon.remove_file(fname) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Checking shardsetup table in CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - set term off - SET NEWPAGE NONE - spool {0} - select * from shardsetup WHERE ROWNUM = 1; - spool off - exit; - '''.format(fname) - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - - if os.path.isfile(fname): - fdata=self.ocommon.read_file(fname) - else: - fdata='nosetup' - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - if re.search('completed',fdata): - status = self.catalog_pdb_setup_check(host,ccdb,svc,port) - if status == 'completed': - return 'completed' - else: - return 'notcompleted' - else: - return 'notcompleted' - - - def catalog_pdb_setup_check(self,host,ccdb,svc,port): - """ - This function check the shard status. - """ - systemStr='''{0}/bin/sqlplus "pdbadmin/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,svc) - - fname='''/tmp/{0}'''.format("pdb_setup_check.txt") - self.ocommon.remove_file(fname) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Checking setup status in PDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - set term off - SET NEWPAGE NONE - spool {0} - select count(*) from dual; - spool off - exit; - '''.format(fname) - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - - if os.path.isfile(fname): - fdata=self.ocommon.read_file(fname) - else: - fdata='nosetup' - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - if re.search('1',fdata): - return 'completed' - else: - return 'notcompleted' - - ############################# Setup GSM Service ############################################### - def setup_gsm_service(self): - """ - This function setup the shard service. - """ - self.ocommon.log_info_message("Inside setup_gsm_service()",self.file_name) - status=False - service_value="service_name=oltp_rw_svc;service_role=primary" - # self.ora_env_dict=self.ocommon.add_key("SERVICE1_PARAMS",service_value,self.ora_env_dict) - reg_exp= self.service_regex() - counter=1 - end_counter=3 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_service_status=None - service_name,service_role=self.process_service_vars(key) - shard_service_status=self.check_service_status(service_name) - if shard_service_status != 'completed': - self.configure_gsm_service(service_name,service_role) - status = self.check_service_status(None) - if status == 'completed': - break - else: - msg='''GSM service setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - time.sleep(60) - counter=counter+1 - - status = self.check_service_status(None) - if status == 'completed': - msg='''Shard service setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def process_service_vars(self,key): - """ - This function process shardG vars based on key and return values to configure the GSM - """ - service_name=None - service_role=None - - self.ocommon.log_info_message("Inside process_service_vars()",self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - if ckey == 'service_name': - service_name = cvar_dict[ckey] - if ckey == 'service_role': - service_role = cvar_dict[ckey] - - ### Check values must be set - if service_name and service_role: - return service_name,service_role - else: - msg1='''service_name={0},service_role={1}'''.format((service_name or "Missing Value"),(service_role or "Missing Value")) - msg='''Shard service params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("Error occurred") - - def check_service_status(self,service_name): - """ - This function check the shard status in GSM - """ - self.ocommon.log_info_message("Inside check_service_status()",self.file_name) - #dtrname,dtrport,dtregion=self.process_director_vars() - gsmcmd=''' - config; - exit; - '''.format("test") - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:Services\n)(?:.+\n)+",output) - status=False - if service_name: - try: - if self.ocommon.check_substr_match(matched_output[0],service_name): - status=True - else: - status=False - except: - status=False - else: - reg_exp= self.service_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - service_name,service_role=self.process_service_vars(key) - # match=re.search("(?i)(?m)"+service_name,matched_output) - try: - if self.ocommon.check_substr_match(matched_output[0],service_name): - status=True - else: - status=False - except: - status=False - - return(self.ocommon.check_status_value(status)) - - def service_regex(self): - """ - This function return the rgex to search the SERVICE[0-9]_PARAMS - """ - self.ocommon.log_info_message("Inside service_regex()",self.file_name) - return re.compile('SERVICE[0-9]+_PARAMS') - - def configure_gsm_service(self,service_name,service_role): - """ - This function configure the service creation. - """ - self.ocommon.log_info_message("Inside configure_gsm_service()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - gsmcmd=''' - connect {1}/{2}; - add service -service {3} -role {4}; - start service -service {3}; - exit; - '''.format("test",cadmin,cpasswd,service_name,service_role) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - ############################## GSM backup fIle function Begins Here ############################# - def gsm_backup_file(self): - """ - This function check the gsm setup status - """ - self.ocommon.log_info_message("Inside gsm_backup_file()",self.file_name) - gsmdata_loc='/opt/oracle/gsmdata' - gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) - - if os.path.isdir(gsmdata_loc): - msg='''Directory {0} exit'''.format(gsmdata_loc) - self.ocommon.log_info_message(msg,self.file_name) - - cmd='''cp -r -v {0}/* {1}/'''.format(gsmfile_loc,gsmdata_loc) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - ############### Deploy Sample Function Begins Here ########################## - def setup_sample_schema(self): - """ - This function deploy the sample app - """ - s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?" - passlen = 8 - passwd = "".join(random.sample(s,passlen )) - self.ocommon.log_info_message("Inside deploy_sample_schema()",self.file_name) - reg_exp= self.catalog_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_db) - if self.ocommon.check_key("SAMPLE_SCHEMA",self.ora_env_dict): - if self.ora_env_dict["SAMPLE_SCHEMA"] == 'DEPLOY': - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Deploying sample schema''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set echo on - set termout on - set time on - spool /tmp/create_app_schema.lst - REM - REM Connect to the Shard Catalog and Create Schema - REM - alter session enable shard ddl; - alter session set container={2}; - alter session enable shard ddl; - create user app_schema identified by {3}; - grant connect, resource, alter session to app_schema; - grant execute on dbms_crypto to app_schema; - grant create table, create procedure, create tablespace, create materialized view to app_schema; - grant unlimited tablespace to app_schema; - grant select_catalog_role to app_schema; - grant all privileges to app_schema; - grant gsmadmin_role to app_schema; - grant dba to app_schema; - CREATE TABLESPACE SET tbsset1 IN SHARDSPACE shd1; - CREATE TABLESPACE SET tbsset2 IN SHARDSPACE shd2; - connect app_schema/{3}@{0}:{1}/{2} - alter session enable shard ddl; - - /* Customer shard table */ - - CREATE SHARDED TABLE customer - ( cust_id NUMBER NOT NULL, - cust_passwd VARCHAR2(20) NOT NULL, - cust_name VARCHAR2(60) NOT NULL, - cust_type VARCHAR2(10) NOT NULL, - cust_email VARCHAR2(100) NOT NULL) - partitionset by list (cust_type) - partition by consistent hash (cust_id) partitions auto - (partitionset individual values ('individual') tablespace set tbsset1, - partitionset business values ('business') tablespace set tbsset2 - ); - /* Invoice shard table */ - - CREATE SHARDED TABLE invoice - ( invoice_id NUMBER NOT NULL, - cust_id NUMBER NOT NULL, - cust_type VARCHAR2(10) NOT NULL, - vendor_name VARCHAR2(60) NOT NULL, - balance FLOAT(10) NOT NULL, - total FLOAT(10) NOT NULL, - status VARCHAR2(20), - CONSTRAINT InvoicePK PRIMARY KEY (cust_id, invoice_id)) - PARENT customer - partitionset by list (cust_type) - partition by consistent hash (cust_id) partitions auto - (partitionset individual values ('individual') tablespace set tbsset1, - partitionset business values ('business') tablespace set tbsset2 - ); - /* Data */ - insert into customer values (999, 'pass', 'Customer 999', 'individual', 'customer999@gmail.com'); - insert into customer values (250251, 'pass', 'Customer 250251', 'individual', 'customer250251@yahoo.com'); - insert into customer values (350351, 'pass', 'Customer 350351', 'individual', 'customer350351@gmail.com'); - insert into customer values (550551, 'pass', 'Customer 550551', 'business', 'customer550551@hotmail.com'); - insert into customer values (650651, 'pass', 'Customer 650651', 'business', 'customer650651@live.com'); - insert into invoice values (1001, 999, 'individual', 'VendorA', 10000, 20000, 'Due'); - insert into invoice values (1002, 999, 'individual', 'VendorB', 10000, 20000, 'Due'); - insert into invoice values (1001, 250251, 'individual', 'VendorA', 10000, 20000, 'Due'); - insert into invoice values (1002, 250251, 'individual', 'VendorB', 0, 10000, 'Paid'); - insert into invoice values (1003, 250251, 'individual', 'VendorC', 14000, 15000, 'Due'); - insert into invoice values (1001, 350351, 'individual', 'VendorD', 10000, 20000, 'Due'); - insert into invoice values (1002, 350351, 'individual', 'VendorE', 0, 10000, 'Paid'); - insert into invoice values (1003, 350351, 'individual', 'VendorF', 14000, 15000, 'Due'); - insert into invoice values (1004, 350351, 'individual', 'VendorG', 12000, 15000, 'Due'); - insert into invoice values (1001, 550551, 'business', 'VendorH', 10000, 20000, 'Due'); - insert into invoice values (1002, 550551, 'business', 'VendorI', 0, 10000, 'Paid'); - insert into invoice values (1003, 550551, 'business', 'VendorJ', 14000, 15000, 'Due'); - insert into invoice values (1004, 550551, 'business', 'VendorK', 10000, 20000, 'Due'); - insert into invoice values (1005, 550551, 'business', 'VendorL', 10000, 20000, 'Due'); - insert into invoice values (1006, 550551, 'business', 'VendorM', 0, 10000, 'Paid'); - insert into invoice values (1007, 550551, 'business', 'VendorN', 14000, 15000, 'Due'); - insert into invoice values (1008, 550551, 'business', 'VendorO', 10000, 20000, 'Due'); - insert into invoice values (1001, 650651, 'business', 'VendorT', 10000, 20000, 'Due'); - insert into invoice values (1002, 650651, 'business', 'VendorU', 0, 10000, 'Paid'); - insert into invoice values (1003, 650651, 'business', 'VendorV', 14000, 15000, 'Due'); - insert into invoice values (1004, 650651, 'business', 'VendorW', 10000, 20000, 'Due'); - insert into invoice values (1005, 650651, 'business', 'VendorX', 0, 20000, 'Paid'); - insert into invoice values (1006, 650651, 'business', 'VendorY', 0, 30000, 'Paid'); - insert into invoice values (1007, 650651, 'business', 'VendorZ', 0, 10000, 'Paid'); - commit; - select table_name from user_tables; - spool off - '''.format(catalog_host,catalog_port,catalog_pdb,passwd) - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - show ddl; - exit; - '''.format("test",cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - ###################################### Run custom scripts ################################################## - def run_custom_scripts(self): - """ - Custom script to be excuted on every restart of enviornment - """ - self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): - shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): - shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] - script_file = '''{0}/{1}'''.format(shard_dir,shard_file) - if os.path.isfile(script_file): - msg='''Custom shard script exist {0}'''.format(script_file) - self.ocommon.log_info_message(msg,self.file_name) - cmd='''sh {0}'''.format(script_file) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - ############################### GSM Completion Message ####################################################### - def gsm_completion_message(self): - """ - Funtion print completion message - """ - self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) - msg=[] - msg.append('==============================================') - msg.append(' GSM Setup Completed ') - msg.append('==============================================') - - for text in msg: - self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oralogger.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oralogger.py deleted file mode 100755 index 9a51b54..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oralogger.py +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -""" - This file provides the functionality to log the event in console and file -""" - -import logging -import os - -class LoggingType(object): - CONSOLE = 1 - FILE = 2 - STDOUT = 3 - -class OraLogger(object): - """ - This is a class constructor which sets parameter for logger. - - Attributes: - filename_ (string): Filename which we need to set to store logs in a file. - """ - def __init__(self, filename_): - """ - This is a class constructor which sets parameter for logger. - - Attributes: - filename_ (string): Filename which we need to set to store logs in a file. - """ - self.filename_ = filename_ - # Set to default values can be changed later from other classes objects - self.console_ = LoggingType.CONSOLE - self.file_ = LoggingType.FILE - self.stdout_ = LoggingType.STDOUT - self.msg_ = None - self.functname_ = None - self.lineno_ = None - self.logtype_ = "INFO" - self.fmtstr_ = "%(asctime)s: %(levelname)s: %(message)s" - self.datestr_ = "%m/%d/%Y %I:%M:%S %p" - self.root = logging.getLogger() - self.root.setLevel(logging.DEBUG) - self.formatter = logging.Formatter('%(asctime)s %(levelname)8s:%(message)s', "%m/%d/%Y %I:%M:%S %p") - self.stdoutfile_ = "/proc/1/fd/1" - # self.stdoutfile_ = "/tmp/test.log" - - def getStdOutValue(self): - return self.stdout_ - -class Handler(object): - """ - This is a class which sets the handler for next logger. - """ - def __init__(self): - """ - This is a handler class constructor and nexthandler is set to None. - """ - self.nextHandler = None - - def handle(self, request): - ''' - This is a function which set the next handler. - - Attributes: - request (object): Object of the class oralogger. - ''' - self.nextHandler.handle(request) - - def print_message(self,request,lhandler): - """ - This function set the log type to INFO, WARN, DEBUG and CRITICAL. - - Attribute: - request (object): Object of the class oralogger. - lhandler: This parameter accept the loghandler. - """ - if request.logtype_ == "WARN": - request.root.warning(request.msg_) - elif request.logtype_ == "DEBUG": - request.root.debug(request.msg_) - elif request.logtype_ == "CRITICAL": - request.root.critical(request.msg_) - elif request.logtype_ == "ERROR": - request.root.error(request.msg_) - else: - request.root.info(request.msg_) - - request.root.removeHandler(lhandler) - -class FHandler(Handler): - """ - This is a class which sets the handler for next logger. - """ - def handle(self,request): - """ - This function print the message and call next handler. - - Attribut: - request: Object of OraLogger - """ - if request.file_ == LoggingType.FILE: - fh = logging.FileHandler(request.filename_) - request.root.addHandler(fh) - fh.setFormatter(request.formatter) - self.print_message(request,fh) - super(FHandler, self).handle(request) - else: - super(FHandler, self).handle(request) - - def print_message(self,request,fh): - """ - This function log the message to console/file/stdout. - """ - super(FHandler, self).print_message(request,fh) - -class CHandler(Handler): - """ - This is a class which sets the handler for next logger. - """ - def handle(self,request): - """ - This function print the message and call next handler. - - Attribute: - request: Object of OraLogger - """ - if request.console_ == LoggingType.CONSOLE: - # ch = logging.StreamHandler() - ch = logging.FileHandler("/tmp/test.log") - request.root.addHandler(ch) - ch.setFormatter(request.formatter) - self.print_message(request,ch) - super(CHandler, self).handle(request) - else: - super(CHandler, self).handle(request) - - def print_message(self,request,ch): - """ - This function log the message to console/file/stdout. - """ - super(CHandler, self).print_message(request,ch) - - -class StdHandler(Handler): - """ - This is a class which sets the handler for next logger. - """ - def handle(self,request): - """ - This function print the message and call next handler. - - Attribute: - request: Object of OraLogger - """ - request.stdout_ = request.getStdOutValue() - if request.stdout_ == LoggingType.STDOUT: - st = logging.FileHandler(request.stdoutfile_,mode="w") - request.root.addHandler(st) - st.setFormatter(request.formatter) - self.print_message(request,st) - super(StdHandler, self).handle(request) - else: - super(StdHandler, self).handle(request) - - def print_message(self,request,st): - """ - This function log the message to console/file/stdout. - """ - super(StdHandler, self).print_message(request,st) - -class PassHandler(Handler): - """ - This is a class which sets the handler for next logger. - """ - def handle(self, request): - pass diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oramachine.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oramachine.py deleted file mode 100755 index 2d1431a..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/oramachine.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * - -import os -import sys - -class OraMachine: - """ - This calss setup the compute before starting the installation. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This constructor of OraMachine class to setup the compute - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - - def setup(self): - """ - This function setup the compute before starting the installation - """ - msg="Machine setup completed sucessfully!" - self.ocommon.log_info_message(msg,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapcatalog.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapcatalog.py deleted file mode 100755 index 6638860..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapcatalog.py +++ /dev/null @@ -1,748 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -import os -import sys -import os.path -import re -import socket -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * - -class OraPCatalog: - """ - This calss setup the Catalog after DB installation. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This constructor of OraCatalog class to setup the catalog on primary DB. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - - def setup(self): - """ - This function setup the catalog on Primary DB. - """ - if self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): - create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" - exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" - self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) - self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) - if os.path.exists(create_db_file_lck): - self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) - sys.exit(127) - elif os.path.exists(exist_db_file_lck): - self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) - status = self.catalog_setup_check() - if not status: - self.ocommon.prog_exit("127") - self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) - sys.exit(0) - else: - status = self.catalog_setup_check() - if not status: - self.ocommon.prog_exit("127") - self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) - sys.exit(0) - elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): - status = self.catalog_setup_check() - if not status: - self.ocommon.log_info_message("Catalog readyness check completed sucessfully!",self.file_name) - self.ocommon.prog_exit("127") - elif self.ocommon.check_key("RESET_PASSWORD",self.ora_env_dict): - exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" - if os.path.exists(exist_db_file_lck): - self.ocommon.log_info_message("Catalog database up and running. Resetting password...",self.file_name) - else: - self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to reset password",self.file_name) - self.ocommon.prog_exit("127") - elif self.ocommon.check_key("EXPORT_TDE_KEY",self.ora_env_dict): - exist_db_file_lck=self.ocommon.get_db_lock_location()+ self.ora_env_dict["ORACLE_SID"] + ".exist_lck" - if os.path.exists(exist_db_file_lck): - self.ocommon.log_info_message("Catalog database up and running.",self.file_name) - self.ocommon.export_tde_key(self.ora_env_dict["EXPORT_TDE_KEY"]) - else: - self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to export the tde key",self.file_name) - self.ocommon.prog_exit("127") - else: - self.setup_machine() - self.db_checks() - self.reset_catalog_setup() - status = self.catalog_setup_check() - if status: - self.ocommon.log_info_message("catalog Setup is already completed on this database",self.file_name) - else: - self.reset_passwd() - self.setup_cdb_catalog() - self.set_spfile_nonm_params() - self.ocommon.set_events("spfile") - self.set_dbparams_version() - self.restart_db() - self.alter_db() - self.setup_pdb_catalog() - self.set_primary_listener() - self.restart_listener() - self.register_services() - self.list_services() - self.backup_files() - self.update_catalog_setup() - self.gsm_completion_message() - self.run_custom_scripts() - ########### SETUP_MACHINE begins here #################### - ## Function to machine setup - def setup_machine(self): - """ - This function performs the compute before performing setup - """ - self.omachine.setup() - - ########### SETUP_MACHINE ENDS here #################### - - ########### DB_CHECKS Related Functions Begin Here #################### - ## Function to perfom DB checks ###### - def db_checks(self): - """ - This function perform db checks before starting the setup - """ - self.ohome_check() - self.passwd_check() - self.set_user() - self.sid_check() - self.dbuinque_name_check() - self.hostname_check() - self.dbport_check() - self.dbr_dest_checks() - self.dpump_dir_checks() - - def ohome_check(self): - """ - This function performs the oracle home related checks - """ - if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): - self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) - else: - self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) - self.ocommon.prog_exit() - - if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): - msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit() - - def passwd_check(self): - """ - Function to set the password - """ - self.ocommon.get_password(None) - if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): - msg='''ORACLE_PWD key is set. Check Passed!''' - self.ocommon.log_info_message(msg,self.file_name) - - def set_user(self): - """ - This funnction set the user for pdb and cdb. - """ - if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): - msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) - msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" - self.ocommon.log_info_message(msg,self.file_name) - - if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): - msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) - msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." - self.ocommon.log_info_message(msg,self.file_name) - - def sid_check(self): - """ - This funnction heck and set the SID for cdb and PDB. - """ - if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): - msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg="ORACLE_SID is not set, existing!" - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit() - - def dbuinque_name_check(self): - """ - This funnction check and set the db unique name for standby - """ - if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): - msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" - self.ocommon.log_info_message(msg,self.file_name) - dbsid=self.ora_env_dict["ORACLE_SID"] - self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) - - - def hostname_check(self): - """ - This function check and set the hostname. - """ - if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): - msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): - # hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) - hostname='''{0}'''.format(socket.getfqdn()) - else: - hostname='''{0}'''.format(socket.gethostname()) - msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) - self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) - self.ocommon.log_info_message(msg,self.file_name) - - def dbport_check(self): - """ - This funnction checks and set the SID for cdb and PDB. - """ - if self.ocommon.check_key("DB_PORT",self.ora_env_dict): - msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) - msg="DB_PORT is not set, setting default to 1521" - self.ocommon.log_info_message(msg,self.file_name) - - def dbr_dest_checks(self): - """ - This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. - """ - if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): - msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) - self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) - msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) - - # Checking the DB_RECOVERY_FILE_DEST_SIZE - - if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): - msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) - msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") - self.ocommon.log_info_message(msg,self.file_name) - - # Checking the DB_CREATE_FILE_DEST - - if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): - msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) - self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) - msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) - - - def dpump_dir_checks(self): - """ - This funnction checks and set the DATA_PUMP dir and location. - """ - if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): - msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) - self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) - msg='''DATA_PUMP_DIR set to {0}'''.format(dest) - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) - - ########### DB_CHECKS Related Functions Begin Here #################### - - - ########## RESET_PASSWORD function Begin here ############################# - ## Function to perform password reset - def reset_passwd(self): - """ - This function reset the password. - """ - self.ocommon.reset_passwd() - - ########## RESET_PASSWORD function ENDS here ############################# - - ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### - - def reset_catalog_setup(self): - """ - This function drop teh catalog setup table and reste the env to default values. - """ - # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) - # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Inside reset_catalog_setup",self.file_name) - catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) - if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): - if self.ora_env_dict["RESET_ENV"]: - if not os.path.isfile(catalog_reset_file): - msg='''Dropping catalogsetup table from CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - drop table system.shardsetup; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - else: - msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(catalog_reset_file) - self.ocommon.log_info_message(msg,self.file_name) - - - def catalog_setup_check(self): - """ - This function check the catalog status. - """ - #systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - msg='''Checking shardsetup table in CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - set term off - SET NEWPAGE NONE - spool /tmp/catalog_setup.txt - select * from system.shardsetup WHERE ROWNUM = 1; - spool off - exit; - ''' - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - fname='''/tmp/{0}'''.format("catalog_setup.txt") - fdata=self.ocommon.read_file(fname) - ### Unsetting the encrypt value to None - # self.ocommon.unset_mask_str() - - if re.search('completed',fdata): - return True - else: - return False - - def setup_cdb_catalog(self): - """ - This function setup the catalog. - """ - #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - # Assigning variable - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] - dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] - host_name=self.ora_env_dict["ORACLE_HOSTNAME"] - dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] - db_port=self.ora_env_dict["DB_PORT"] - ohome=self.ora_env_dict["ORACLE_HOME"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Setting up catalog CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set db_create_file_dest=\"{0}\" scope=both; - alter system set db_recovery_file_dest_size={1} scope=both; - alter system set db_recovery_file_dest=\"{2}\" scope=both; - alter user gsmcatuser account unlock; - alter user gsmcatuser identified by HIDDEN_STRING; - alter system set local_listener='{4}:{5}' scope=both; - '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def set_spfile_nonm_params(self): - """ - This function setup the catalog. - """ - #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): - if self.ora_env_dict["CLONE_DB"] != 'true': - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - msg='''Setting up catalog CDB with spfile non modifiable parameters''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set open_links_per_instance=16 scope=spfile; - alter system set db_file_name_convert='*','{0}/' scope=spfile; - alter system set standby_file_management='AUTO' scope=spfile; - alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; - alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; - '''.format(dbf_dest,obase,"dbconfig",dbuname) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - - def set_dbparams_version(self): - """ - This function setup the shard parameter based on db version. - """ - ohome1=self.ora_env_dict["ORACLE_HOME"] - version=self.ocommon.get_oraversion(ohome1).strip() - self.ocommon.log_info_message(version,self.file_name) - if int(version) > 21: - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set wallet_root=\"{1}/oradata/{2}/{3}\" scope=spfile; - '''.format(dbf_dest,obase,"dbconfig",dbuname) - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - def restart_db(self): - """ - restarting the db - """ - if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): - if self.ora_env_dict["CLONE_DB"] != 'true': - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) - self.ocommon.shutdown_db(self.ora_env_dict) - self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) - self.ocommon.start_db(self.ora_env_dict) - - #self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) - #sqlcmd=''' - # alter database archivelog; - # alter database open; - #''' - #output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - #self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - #self.ocommon.check_sql_err(output,error,retcode,True) - - def alter_db(self): - """ - Alter db - """ - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) - sqlcmd=''' - alter database flashback on; - alter database force logging; - ALTER PLUGGABLE DATABASE ALL OPEN; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - - def setup_pdb_catalog(self): - """ - This function setup the catalog. - """ - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - # Assigning variable - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): - msg='''Setting up catalog PDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter pluggable database {0} close immediate; - alter pluggable database {0} open services=All; - ALTER PLUGGABLE DATABASE {0} SAVE STATE; - alter system register; - alter session set container={0}; - create user {1} identified by HIDDEN_STRING; - alter user {1} account unlock; - grant connect, create session, gsmadmin_role to {1}; - grant inherit privileges on user SYS to GSMADMIN_INTERNAL; - execute dbms_xdb.sethttpport(8080); - exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('HIDDEN_STRING'); - alter system register; - exit; - '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def update_catalog_setup(self): - """ - This function update the catalog setup on this DB. - """ - # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") - # systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - msg='''Updating shardsetup table''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - create table system.shardsetup (status varchar2(10)); - insert into system.shardsetup values('completed'); - commit; - exit; - ''' - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Reset File - catalog_reset_dir='''{0}/.catalog'''.format(self.ora_env_dict["HOME"]) - catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) - - self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) - if not os.path.isdir(catalog_reset_dir): - self.ocommon.create_dir(catalog_reset_dir,True,None,None) - - if not os.path.isfile(catalog_reset_file): - self.ocommon.create_file(catalog_reset_file,True,None,None) - -# self.ocommon.unset_mask_str() - - ########## SETUP_CDB_catalog FUNCTION ENDS HERE ############################### - - ###################################### Run custom scripts ################################################## - def run_custom_scripts(self): - """ - Custom script to be excuted on every restart of enviornment - """ - self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): - shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): - shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] - script_file = '''{0}/{1}'''.format(shard_dir,shard_file) - if os.path.isfile(script_file): - msg='''Custom shard script exist {0}'''.format(script_file) - self.ocommon.log_info_message(msg,self.file_name) - cmd='''sh {0}'''.format(script_file) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - def set_primary_listener(self): - """ - Function to set the primary listener - """ - global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") - self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) - global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) - self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) - - def set_db_listener(self,gdbname,sid): - """ - Funtion to reset the listener - """ - self.ocommon.log_info_message("Inside reset_listener()",self.file_name) - start = 'SID_LIST_LISTENER' - end = '^\)$' - oracle_home=self.ora_env_dict["ORACLE_HOME"] - lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) - buffer = "SID_LIST_LISTENER=" + '\n' - start_flag = False - try: - with open(lisora) as f: - for line1 in f: - if start_flag == False: - if (re.match(start, line1.strip())): - start_flag = True - elif (re.match(end, line1.strip())): - line2 = f.next() - if (re.match(end, line2.strip())): - break - else: - buffer += line1 - buffer += line2 - else: - if start_flag == True: - buffer += line1 - except: - pass - - if start_flag == True: - buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") - listener = self.ocommon.get_lisora(1521) - listener += '\n' + buffer - else: - buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") - listener = self.ocommon.get_lisora(1521) - listener += '\n' + buffer - - wr = open(lisora, 'w') - wr.write(listener) - - def restart_listener(self): - """ - restart listener - """ - self.ocommon.log_info_message("Stopping Listener",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl stop'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - self.ocommon.log_info_message("Starting Listener",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl start'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - - def register_services(self): - """ - This function setup the catalog. - """ - #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - # Assigning variable - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): - msg='''Setting up catalog PDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system register; - alter session set container={0}; - alter system register; - exit; - '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def list_services(self): - """ - restart listener - """ - self.ocommon.log_info_message("Listing Services",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl services'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - - def backup_files(self): - """ - This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig - """ - self.ocommon.log_info_message("Inside backup_files()",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - dbsid=self.ora_env_dict["ORACLE_SID"] - - version=self.ocommon.get_oraversion(ohome).strip() - wallet_backup_cmd='''ls -ltr /bin''' - self.ocommon.log_info_message("Check Version " + version,self.file_name) - if int(version) >= 21: - obase1=self.ora_env_dict["ORACLE_BASE"] - wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) - cmd_names=''' - mkdir -p {0}/oradata/{1}/{2} - cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ - cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ - cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ - cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ - cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ - touch {0}/oradata/{1}/{2}/status_completed - '''.format(obase,"dbconfig",dbuname,ohome) - cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] - for cmd in cmd_list: - msg='''Executing cmd {0}'''.format(cmd) - self.ocommon.log_info_message(msg,self.file_name) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - - ############################### GSM Completion Message ####################################################### - def gsm_completion_message(self): - """ - Funtion print completion message - """ - self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) - msg=[] - msg.append('==============================================') - msg.append(' GSM Catalog Setup Completed ') - msg.append('==============================================') - - for text in msg: - self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapshard.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapshard.py deleted file mode 100755 index d1b1273..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orapshard.py +++ /dev/null @@ -1,795 +0,0 @@ -#!/usr/bin/python - -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - - -import os -import sys -import os.path -import re -import socket -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * -import traceback - -class OraPShard: - """ - This calss setup the primary shard after DB installation. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This constructor of OraPShard class to setup the shard on primary DB. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - try: - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - except BaseException as ex: - ex_type, ex_value, ex_traceback = sys.exc_info() - trace_back = traceback.extract_tb(ex_traceback) - stack_trace = list() - for trace in trace_back: - stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) - self.ocommon.log_info_message(ex_type.__name__,self.file_name) - self.ocommon.log_info_message(ex_value,self.file_name) - self.ocommon.log_info_message(stack_trace,self.file_name) - def setup(self): - """ - This function setup the shard on Primary DB. - """ - if self.ocommon.check_key("RESET_LISTENER",self.ora_env_dict): - status = self.shard_setup_check() - if not status: - self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) - self.ocommon.prog_exit("127") - self.reset_listener() - self.restart_listener() - if self.ocommon.check_key("RESTART_DB",self.ora_env_dict): - status = self.shard_setup_check() - if not status: - self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) - self.ocommon.prog_exit("127") - else: - self.ocommon.shutdown_db(self.ora_env_dict) - self.ocommon.start_db(self.ora_env_dict) - elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): - create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" - exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" - self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) - self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) - if os.path.exists(create_db_file_lck): - self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) - sys.exit(127) - elif os.path.exists(exist_db_file_lck): - self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) - status = self.shard_setup_check() - if not status: - self.ocommon.prog_exit("127") - self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) - sys.exit(0) - else: - status = self.shard_setup_check() - if not status: - self.ocommon.prog_exit("127") - self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) - sys.exit(0) - elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): - status = self.shard_setup_check() - if not status: - self.ocommon.log_info_message("Shard readyness check completed sucessfully!",self.file_name) - self.ocommon.prog_exit("127") - else: - self.setup_machine() - self.db_checks() - self.reset_shard_setup() - status = self.shard_setup_check() - if status: - self.ocommon.log_info_message("Shard Setup is already completed on this database",self.file_name) - else: - self.reset_passwd() - self.setup_cdb_shard() - self.set_spfile_nonm_params() - self.ocommon.set_events("spfile") - self.set_dbparams_version() - self.restart_db() - self.alter_db() - self.setup_pdb_shard () - self.update_shard_setup() - self.set_primary_listener() - self.restart_listener() - self.register_services() - self.list_services() - self.backup_files() - self.gsm_completion_message() - self.run_custom_scripts() - - ########### SETUP_MACHINE begins here #################### - ## Function to machine setup - def setup_machine(self): - """ - This function performs the compute before performing setup - """ - self.omachine.setup() - ########### SETUP_MACHINE ENDS here #################### - - ########### DB_CHECKS Related Functions Begin Here #################### - ## Function to perfom DB checks ###### - def db_checks(self): - """ - This function perform db checks before starting the setup - """ - self.ohome_check() - self.passwd_check() - self.set_user() - self.sid_check() - self.dbuinque_name_check() - self.hostname_check() - self.dbport_check() - self.dbr_dest_checks() - self.dpump_dir_checks() - - def ohome_check(self): - """ - This function performs the oracle home related checks - """ - if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): - self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) - else: - self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) - self.ocommon.prog_exit() - - if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): - msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit() - - def passwd_check(self): - """ - This funnction perform password related checks - """ - self.ocommon.get_password(None) - if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): - msg='''ORACLE_PWD key is set. Check Passed!''' - self.ocommon.log_info_message(msg,self.file_name) - - def set_user(self): - """ - This funnction set the user for pdb and cdb. - """ - if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): - msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) - msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" - self.ocommon.log_info_message(msg,self.file_name) - - if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): - msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) - msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." - self.ocommon.log_info_message(msg,self.file_name) - - def sid_check(self): - """ - This funnction heck and set the SID for cdb and PDB. - """ - if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): - msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg="ORACLE_SID is not set, existing!" - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit() - - def dbuinque_name_check(self): - """ - This funnction check and set the db unique name for standby - """ - if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): - msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" - self.ocommon.log_info_message(msg,self.file_name) - dbsid=self.ora_env_dict["ORACLE_SID"] - self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) - - def hostname_check(self): - """ - This function check and set the hostname. - """ - if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): - msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): - ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) - hostname='''{0}'''.format(socket.getfqdn()) - else: - hostname='''{0}'''.format(socket.gethostname()) - msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) - self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) - self.ocommon.log_info_message(msg,self.file_name) - - def dbport_check(self): - """ - This funnction checks and set the SID for cdb and PDB. - """ - if self.ocommon.check_key("DB_PORT",self.ora_env_dict): - msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) - msg="DB_PORT is not set, setting default to 1521" - self.ocommon.log_info_message(msg,self.file_name) - - def dbr_dest_checks(self): - """ - This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. - """ - if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): - msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) - self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) - msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) - - # Checking the DB_RECOVERY_FILE_DEST_SIZE - - if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): - msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) - msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") - self.ocommon.log_info_message(msg,self.file_name) - - # Checking the DB_CREATE_FILE_DEST - - if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): - msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) - self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) - msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) - - - def dpump_dir_checks(self): - """ - This funnction checks and set the DATA_PUMP dir and location. - """ - if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): - msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) - self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) - msg='''DATA_PUMP_DIR set to {0}'''.format(dest) - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) - - ########### DB_CHECKS Related Functions Begin Here #################### - - - ########## RESET_PASSWORD function Begin here ############################# - ## Function to perform password reset - def reset_passwd(self): - """ - This function reset the password. - """ - self.ocommon.reset_passwd() - - ########## RESET_PASSWORD function ENDS here ############################# - - ########## SETUP_CDB_SHARD FUNCTION BEGIN HERE ############################### - - def reset_shard_setup(self): - """ - This function drop teh shard setup table and reste the env to default values. - """ - # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) - # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Inside reset_shard_setup",self.file_name) - shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) - if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): - if self.ora_env_dict["RESET_ENV"]: - if not os.path.isfile(shard_reset_file): - msg='''Dropping shardsetup table from CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - drop table system.shardsetup; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - else: - msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(shard_reset_file) - self.ocommon.log_info_message(msg,self.file_name) - - - def shard_setup_check(self): - """ - This function check the shard status. - """ -# systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - - # self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - msg='''Checking shardsetup table in CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - set term off - SET NEWPAGE NONE - spool /tmp/shard_setup.txt - select * from system.shardsetup WHERE ROWNUM = 1; - spool off - exit; - ''' - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - fname='''/tmp/{0}'''.format("shard_setup.txt") - fdata=self.ocommon.read_file(fname) - ### Unsetting the encrypt value to None - # self.ocommon.unset_mask_str() - - if re.search('completed',fdata): - return True - else: - return False - - def setup_cdb_shard(self): - """ - This function setup the shard. - """ - # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - # Assigning variable - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] - dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] - host_name=self.ora_env_dict["ORACLE_HOSTNAME"] - dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] - db_port=self.ora_env_dict["DB_PORT"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Setting up Shard CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set db_create_file_dest=\"{0}\" scope=both; - alter system set db_recovery_file_dest_size={1} scope=both; - alter system set db_recovery_file_dest=\"{2}\" scope=both; - alter system set db_file_name_convert='*','{0}/' scope=spfile; - alter system set standby_file_management='AUTO' scope=spfile; - alter user gsmrootuser account unlock; - grant sysdg to gsmrootuser; - grant sysbackup to gsmrootuser; - alter user gsmrootuser identified by HIDDEN_STRING container=all; - alter user GSMUSER account unlock; - alter user GSMUSER identified by HIDDEN_STRING container=all; - grant sysdg to GSMUSER; - grant sysbackup to GSMUSER; - create or replace directory DATA_PUMP_DIR as '{3}'; - grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; - alter system set local_listener='{4}:{5}' scope=spfile; - '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def set_spfile_nonm_params(self): - """ - This function setup the catalog. - """ - #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): - if self.ora_env_dict["CLONE_DB"] != 'true': - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - msg='''Setting up catalog CDB with spfile non modifiable parameters''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set open_links_per_instance=16 scope=spfile; - alter system set open_links=16 scope=spfile; - alter system set db_file_name_convert='*','{0}/' scope=spfile; - alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; - alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; - '''.format(dbf_dest,obase,"dbconfig",dbuname) - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - def set_dbparams_version(self): - """ - This function setup the catalog parameter based on db version. - """ - ohome1=self.ora_env_dict["ORACLE_HOME"] - version=self.ocommon.get_oraversion(ohome1).strip() - self.ocommon.log_info_message(version,self.file_name) - if int(version) > 21: - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - - msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set wallet_root=\"{1}/oradata/{2}/{3}/\" scope=spfile; - '''.format(dbf_dest,obase,"dbconfig",dbuname) - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - def restart_db(self): - - """ - restarting the db - """ - if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): - if self.ora_env_dict["CLONE_DB"] != 'true': - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) - self.ocommon.shutdown_db(self.ora_env_dict) - self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) - self.ocommon.start_db(self.ora_env_dict) - - # self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) - # sqlcmd=''' - # alter database archivelog; - # alter database open; - # ''' - # output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - # self.ocommon.check_sql_err(output,error,retcode,True) - - def alter_db(self): - """ - Alter db - """ - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) - sqlcmd=''' - alter database flashback on; - alter database force logging; - ALTER PLUGGABLE DATABASE ALL OPEN; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - - - def setup_pdb_shard(self): - """ - This function setup the shard. - """ - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - # Assigning variable - if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): - msg='''Setting up Shard PDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter pluggable database {0} close immediate; - alter pluggable database {0} open services=All; - ALTER PLUGGABLE DATABASE {0} SAVE STATE; - alter system register; - alter session set container={0}; - grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; - grant sysdg to GSMUSER; - grant sysbackup to GSMUSER; - execute DBMS_GSM_FIX.validateShard; - alter system register; - '''.format(self.ora_env_dict["ORACLE_PDB"]) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - def alter_db(self): - """ - Alter db - """ - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) - sqlcmd=''' - alter database flashback on; - alter database force logging; - ALTER PLUGGABLE DATABASE ALL OPEN; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - - def update_shard_setup(self): - """ - This function update the shard setup on this DB. - """ - # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") - systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - -# self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - - msg='''Updating shardsetup table''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - create table system.shardsetup (status varchar2(10)); - insert into system.shardsetup values('completed'); - commit; - exit; - ''' - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Reset File - shard_reset_dir='''{0}/.shard'''.format(self.ora_env_dict["HOME"]) - shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) - - self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) - if not os.path.isdir(shard_reset_dir): - self.ocommon.create_dir(shard_reset_dir,True,None,None) - - if not os.path.isfile(shard_reset_file): - self.ocommon.create_file(shard_reset_file,True,None,None) - -# self.ocommon.unset_mask_str() - - ########## SETUP_CDB_SHARD FUNCTION ENDS HERE ############################### - ###################################### Run custom scripts ################################################## - def run_custom_scripts(self): - """ - Custom script to be excuted on every restart of enviornment - """ - self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): - shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] - - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): - shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] - - script_file = '''{0}/{1}'''.format(shard_dir,shard_file) - - if os.path.isfile(script_file): - msg='''Custom shard script exist {0}'''.format(script_file) - self.ocommon.log_info_message(msg,self.file_name) - cmd='''sh {0}'''.format(script_file) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - ###################################### Run custom scripts ################################################## - def run_custom_scripts(self): - """ - Custom script to be excuted on every restart of enviornment - """ - self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): - shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): - shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] - script_file = '''{0}/{1}'''.format(shard_dir,shard_file) - if os.path.isfile(script_file): - msg='''Custom shard script exist {0}'''.format(script_file) - self.ocommon.log_info_message(msg,self.file_name) - cmd='''sh {0}'''.format(script_file) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - ############################### GSM Completion Message ####################################################### - def gsm_completion_message(self): - """ - Funtion print completion message - """ - self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) - msg=[] - msg.append('==============================================') - msg.append(' GSM Shard Setup Completed ') - msg.append('==============================================') - - for text in msg: - self.ocommon.log_info_message(text,self.file_name) - ################################ Reset and standby functions ################################################# - - def set_primary_listener(self): - """ - Function to set the primary listener - """ - global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") - self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) - global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) - self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) - - def set_db_listener(self,gdbname,sid): - """ - Funtion to reset the listener - """ - self.ocommon.log_info_message("Inside reset_listener()",self.file_name) - start = 'SID_LIST_LISTENER' - end = '^\)$' - oracle_home=self.ora_env_dict["ORACLE_HOME"] - lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) - buffer = "SID_LIST_LISTENER=" + '\n' - start_flag = False - try: - with open(lisora) as f: - for line1 in f: - if start_flag == False: - if (re.match(start, line1.strip())): - start_flag = True - elif (re.match(end, line1.strip())): - line2 = f.next() - if (re.match(end, line2.strip())): - break - else: - buffer += line1 - buffer += line2 - else: - if start_flag == True: - buffer += line1 - except: - pass - - if start_flag == True: - buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") - listener = self.ocommon.get_lisora(1521) - listener += '\n' + buffer - else: - buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") - listener = self.ocommon.get_lisora(1521) - listener += '\n' + buffer - - wr = open(lisora, 'w') - wr.write(listener) - - def restart_listener(self): - """ - restart listener - """ - self.ocommon.log_info_message("Stopping Listener",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl stop'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - self.ocommon.log_info_message("Starting Listener",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl start'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - def register_services(self): - """ - This function setup the catalog. - """ - # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - # Assigning variable - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): - msg='''Setting up catalog PDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system register; - alter session set container={0}; - alter system register; - exit; - '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def list_services(self): - """ - restart listener - """ - self.ocommon.log_info_message("Listing Services",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl services'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - def backup_files(self): - """ - This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig - """ - self.ocommon.log_info_message("Inside backup_files()",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - dbsid=self.ora_env_dict["ORACLE_SID"] - - version=self.ocommon.get_oraversion(ohome).strip() - wallet_backup_cmd='''ls -ltr /bin''' - self.ocommon.log_info_message("Check Version " + version,self.file_name) - if int(version) >= 21: - obase1=self.ora_env_dict["ORACLE_BASE"] - wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) - cmd_names=''' - mkdir -p {0}/oradata/{1}/{2} - cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ - cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ - cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ - cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ - cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ - {4} - touch {0}/oradata/{1}/{2}/status_completed - '''.format(obase,"dbconfig",dbuname,ohome,wallet_backup_cmd) - cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] - for cmd in cmd_list: - msg='''Executing cmd {0}'''.format(cmd) - self.ocommon.log_info_message(msg,self.file_name) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orascatalog.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orascatalog.py deleted file mode 100755 index aa4ea65..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orascatalog.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - - diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orasshard.py b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orasshard.py deleted file mode 100755 index 58f168b..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/orasshard.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - - -import os -import sys -import os.path -import re -import socket -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * -import traceback - -class OraSShard: - """ - This calss setup the standby shard after DB installation. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This constructor of OraSShard class to setup the shard on standby DB. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - try: - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - except BaseException as ex: - ex_type, ex_value, ex_traceback = sys.exc_info() - trace_back = traceback.extract_tb(ex_traceback) - stack_trace = list() - for trace in trace_back: - stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) - ocommon.log_info_message(ex_type.__name__,self.file_name) - ocommon.log_info_message(ex_value,self.file_name) - ocommon.log_info_message(stack_trace,self.file_name) - def setup(self): - """ - This function setup the shard on standby DB. - """ - pass diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOraShardSetup.sh b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOraShardSetup.sh deleted file mode 100755 index c1b09b4..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOraShardSetup.sh +++ /dev/null @@ -1,568 +0,0 @@ -#!/bin/bash -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -export CLONED_FILE="status_completed" -export STANDBY_STATUS="status_completed" - -########### Clone Files ##################### -function cloneDB { - -export NEW_ORACLE_SID=$ORACLE_SID -export ORACLE_SID=$OLD_ORACLE_SID -sqlplus / as sysdba << EOF - STARTUP mount; - exit; -EOF - -echo 'Y' | nid target=/ dbname="$NEW_ORACLE_SID" - -if [ $? -eq 0 ]; then - echo "DB name changed sucessfully" -else - echo "DB name change process failed" - exit 1; -fi - -if [ -z ${DB_RECOVERY_FILE_DEST} ]; then - export DB_RECOVERY_FILE_DEST=$ORACLE_BASE/oradata/fast_recovery_area/$NEW_ORACLE_SID -fi - -if [ -z ${DB_UNIQUE_NAME} ]; then - export DB_UNIQUE_NAME=$NEW_ORACLE_SID -fi - -export ORACLE_HOSTNAME=$( hostname -f ) - -echo "Changing DB name" -export ORACLE_SID=$NEW_ORACLE_SID -sqlplus / as sysdba << EOF - STARTUP nomount; - alter system set db_name=$ORACLE_SID scope=spfile; - alter system set open_links=16 scope=spfile; - alter system set open_links_per_instance=16 scope=spfile; - alter system set dg_broker_config_file1="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr2$DB_UNIQUE_NAME.dat" scope=spfile; - alter system set dg_broker_config_file2="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr1$DB_UNIQUE_NAME.dat" scope=spfile; - alter system set db_file_name_convert='*','$ORACLE_BASE/oradata/$DB_UNIQUE_NAME/' scope=spfile; - alter system set local_listener='$ORACLE_HOSTNAME' scope=spfile; - alter system set standby_file_management='auto' scope=spfile; - shutdown immediate - exit; -EOF - -## Get the version - dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) - if [ ! -z ${dbversion} ]; then - if [ ${dbversion} -ge 21 ]; then - echo "Setting DB Parameter based on the vserion" - export ORACLE_SID=$NEW_ORACLE_SID - sqlplus / as sysdba << EOF - startup nomount - alter system set wallet_root="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME" scope=spfile; - shutdown immediate - exit; -EOF - fi - fi - -echo "Changing OLD SID string to new string" -sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_HOME/network/admin/tnsnames.ora -sed -i "s/$OLD_ORACLE_PDB/$ORACLE_PDB/g" $ORACLE_HOME/network/admin/tnsnames.ora - -echo "Starting Listener" - -$ORACLE_HOME/bin/lsnrctl start - -echo "Starting new cloned DB" - -sqlplus / as sysdba << EOF - STARTUP mount; - alter database archivelog; - alter database open resetlogs; - exit; -EOF - -echo "Renaming PDB" - -sqlplus / as sysdba << EOF - alter pluggable database $OLD_ORACLE_PDB open restricted; - alter session set container=$OLD_ORACLE_PDB; - alter pluggable database rename global_name to $ORACLE_PDB; - exit; -EOF - -echo " Closing and Opening PDB" - -sqlplus / as sysdba << EOF - alter pluggable database $ORACLE_PDB close immediate; - alter pluggable database $ORACLE_PDB open; - alter system register; - exit; -EOF - - -echo "Touching $CLONED_FILE as setup is completed" -touch $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE - -} - -############################################ -########### Symbolic link DB files ######### -############################################ -########### DB Version >= 23c ############## -############################################ -function symLinkFiles23c { - - if [ -z ${ORACLE_BASE_HOME} ]; then - # - export ORACLE_BASE_HOME=$ORACLE_HOME - fi - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then - mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID - fi; - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then - mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump - fi; - - if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then - unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora - fi; - if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then - unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - fi; - if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID - fi; - if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID - fi; - if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora - fi; - if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/listener.ora - fi; - if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora - fi - if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then - unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID - fi; - if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora - ## Link based on ORACLE_BASE -# ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/spfile$ORACLE_SID.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - ## Link based on ORACLE_BASE - # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - ## Link based on ORACLE_BASE - # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID - ## Link based on ORACLE_BASE - # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID - ## Link based on ORACLE_BASE - # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID - ## Link based on ORACLE_BASE - # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora - fi - fi - fi; - - if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID - fi; - - if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID - fi; - - if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then - mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID - fi; - - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then - ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB - fi; - # oracle user does not have permissions in /etc, hence cp and not ln - sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab - cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab - fi -fi - -} - - -############################################ -########### Symbolic link DB files ######### -############################################ -########### DB Version < 23c ############### -############################################ -function symLinkFiles { - - if [ -z ${ORACLE_BASE_HOME} ]; then - # - export ORACLE_BASE_HOME=$ORACLE_HOME - fi - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then - mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID - fi; - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then - mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump - fi; - - if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then - unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora - fi; - if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then - unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - fi; - if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID - fi; - if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID - fi; - if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora - fi; - if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/listener.ora - fi; - if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora - fi - if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then - unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID - fi; - if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$OLD_ORACLE_SID - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora - fi - fi - fi; - - if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID - fi; - - if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID - fi; - - if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then - mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID - fi; - - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then - ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB - fi; - # oracle user does not have permissions in /etc, hence cp and not ln - sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab - cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab - fi -fi - -} - -################################### -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # -############# MAIN ################ -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # -################################### - -# Check whether container has enough memory -# Github issue #219: Prevent integer overflow, -# only check if memory digits are less than 11 (single GB range and below) -if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes | wc -c` -lt 11 ]; then - if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` -lt 2147483648 ]; then - echo "Error: The container doesn't have enough memory allocated." - echo "A database container needs at least 2 GB of memory." - echo "You currently only have $((`cat /sys/fs/cgroup/memory/memory.limit_in_bytes`/1024/1024/1024)) GB allocated to the container." - exit 1; - fi; -fi; - - -# Check that hostname doesn't container any "_" -# Github issue #711 -if hostname | grep -q "_"; then - echo "Error: The hostname must not container any '_'". - echo "Your current hostname is '$(hostname)'" -fi; - -# Default for ORACLE SID -if [ "$OLD_ORACLE_SID" == "" ]; then - export OLD_ORACLE_SID=SEEDCDB -fi - -if [ ! -z ${ORACLE_SID} ]; then - # Make ORACLE_SID upper case - # Github issue # 984 - export ORACLE_SID=${ORACLE_SID^^} - - # Check whether SID is no longer than 12 bytes - # Github issue #246: Cannot start OracleDB image - if [ "${#ORACLE_SID}" -gt 12 ]; then - echo "Error: The ORACLE_SID must only be up to 12 characters long." - exit 1; - fi; - - # Check whether SID is alphanumeric - # Github issue #246: Cannot start OracleDB image - if [[ "$ORACLE_SID" =~ [^a-zA-Z0-9] ]]; then - echo "Error: The ORACLE_SID must be alphanumeric." - exit 1; - fi; -else - echo "Error: The ORACLE_SID must be defined." - exit 1; -fi; - - -if [ ! -z ${ORACLE_PDB} ]; then - export ORACLE_PDB=${ORACLE_PDB^^} - - if [ "${#ORACLE_PDB}" -gt 12 ]; then - echo "Error: The ORACLE_PDB must only be up to 12 characters long." - exit 1; - fi; -else - echo "Error: The ORACLE_PDB must be defined." - exit 1; -fi; - -if [ ! -z ${OLD_ORACLE_PDB} ]; then - export OLD_ORACLE_PDB=${OLD_ORACLE_PDB^^} -else - export OLD_ORACLE_PDB=SEEDPDB -fi; - - -# Default for ORACLE CHARACTERSET -export ORACLE_CHARACTERSET=${ORACLE_CHARACTERSET:-AL32UTF8} - -# Check whether database already exists -if [ ! -z ${CLONE_DB} ]; then -if [ ${CLONE_DB^^} == "TRUE" ]; then -echo "CLONE_DB is set to true, cloning DB from seed" -if [ -d $ORACLE_BASE/oradata/$OLD_ORACLE_SID ]; then - dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) - if [ ! -z ${dbversion} ]; then - if [ ${dbversion} -ge 23 ]; then - symLinkFiles23c; - else - symLinkFiles; - fi; - else - echo "Unable to determine the Database Version, exiting.." - exit 1; - fi - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump ]; then - mkdir -p $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump - fi; - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then - mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE ]; - then - # Start database - echo "Starting Database as cloned status file exist" - $ORACLE_BASE/$START_FILE; - else - echo "Performing Cloning as cloned status file does not exist" - cloneDB; - $ORACLE_BASE/checkDBStatus.sh - if [ $? -eq 0 ]; then - echo "DB is in READ WRITE State" - touch "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" - $ORACLE_BASE/$LOCKING_SCRIPT --acquire --file "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" - else - echo "DB is not in READ WRITE state" - exit 1; - fi - fi -else - echo "Error: The $ORACLE_BASE/oradata/$OLD_ORACLE_SID (ORACLE_BASE/oradata/OLD_ORACLE_SID) dir does not exist. Error exiting ." - exit 1; -fi -fi -fi - -if [ ${OP_TYPE,,} == "standbyshard" ]; then - dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) - if [ ! -z ${dbversion} ]; then - if [ ${dbversion} -ge 23 ]; then - symLinkFiles23c; - else - symLinkFiles; - fi; - else - echo "Unable to determine the Database Version, exiting.." - exit 1; - fi - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/$STANDBY_STATUS ]; - then - # Start database - echo "Starting Database as standby setup status file exist" - $ORACLE_BASE/$START_FILE; - fi -fi - -#This is the main file which calls other file to setup the sharding. -if [ -z ${BASE_DIR} ]; then - BASE_DIR=/opt/oracle/scripts/sharding -fi - -if [ -z ${MAIN_SCRIPT} ]; then - SCRIPT_NAME="main.py" -fi - -if [ -z ${EXECUTOR} ]; then - EXECUTOR="python" -fi - -cd $BASE_DIR -$EXECUTOR $SCRIPT_NAME diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOracle.sh b/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOracle.sh deleted file mode 100755 index 2266e99..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/scripts/runOracle.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -########### SIGINT handler ############ -function _int() { - echo "Stopping container." - echo "SIGINT received, shutting down database!" - sqlplus / as sysdba <<EOF - shutdown immediate; - exit; -EOF - lsnrctl stop -} - -########### SIGTERM handler ############ -function _term() { - echo "Stopping container." - echo "SIGTERM received, shutting down database!" - sqlplus / as sysdba <<EOF - shutdown immediate; - exit; -EOF - lsnrctl stop -} - -########### SIGKILL handler ############ -function _kill() { - echo "SIGKILL received, shutting down database!" - sqlplus / as sysdba <<EOF - shutdown abort; - exit; -EOF - lsnrctl stop -} - - -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # -############# MAIN ################ -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # -################################### - -if [ ! -z ${SHARD_SETUP} ]; then - if [ ${SHARD_SETUP,,} == "true" ]; then - sh $ORACLE_BASE/scripts/sharding/runOraShardSetup.sh - fi -fi - -if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - echo "The following output is now a tail of the alert.log:" - tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & - fi -fi - -if [ ! -z ${OP_TYPE} ]; then - if [ ${OP_TYPE,,} == "standbyshard" ]; then - echo "The following output is now a tail of the alert.log:" - tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & - fi -fi - -# Set SIGINT handler -trap _int SIGINT - -# Set SIGTERM handler -trap _term SIGTERM - -# Set SIGKILL handler -trap _kill SIGKILL - - -childPID=$! -wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/setupGSM.sh b/container-based-sharding-deployment/containerfiles/23.3.0/setupGSM.sh deleted file mode 100644 index 4a6a6ca..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/setupGSM.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: Build script for building RAC container image -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -# Create Directories -mkdir -p $GSM_BASE -mkdir -p $GSM_HOME -mkdir -p $INVENTORY - -chown -R oracle:oinstall $INVENTORY -chown -R oracle:oinstall $GSM_BASE -chown -R oracle:oinstall $GSM_HOME -chown -R oracle:oinstall $INSTALL_SCRIPTS -chmod 775 $INSTALL_SCRIPTS - -chmod 666 /etc/sudoers -echo "oracle ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers -chmod 440 /etc/sudoers - -echo "export ORACLE_HOME=$GSM_HOME" >> /home/oracle/.bashrc -echo "export PATH=$GSM_PATH" >> /home/oracle/.bashrc -echo "export LD_LIBRARY_PATH=$GSM_LD_LIBRARY_PATH" >> /home/oracle/.bashrc -echo "export SCRIPT_DIR=$SCRIPT_DIR" >> /home/oracle/.bashrc -echo "export GSM_HOME=$GSM_HOME" >> /home/oracle/.bashrc diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/setupLinuxEnv.sh b/container-based-sharding-deployment/containerfiles/23.3.0/setupLinuxEnv.sh deleted file mode 100644 index 29c3339..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/setupLinuxEnv.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: Build script for building RAC container image -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -chmod ug+x $SCRIPT_DIR/*.sh && \ -yum -y install oracle-database-preinstall-21c net-tools zip unzip tar openssl openssh-server vim-minimal which passwd sudo python3 hostname && \ -yum clean all diff --git a/container-based-sharding-deployment/containerfiles/23.3.0/setupOshardEnv.sh b/container-based-sharding-deployment/containerfiles/23.3.0/setupOshardEnv.sh deleted file mode 100755 index 5ae2692..0000000 --- a/container-based-sharding-deployment/containerfiles/23.3.0/setupOshardEnv.sh +++ /dev/null @@ -1,970 +0,0 @@ -#!/bin/bash -# -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -export NOW=$(date +"%Y%m%d%H%M") -export LOGDIR="/tmp" -export LOGFILE="${LOGDIR}/oshard_${NOW}.log" -export STD_OUT_FILE="/proc/1/fd/1" -export STD_ERR_FILE="/proc/1/fd/2" -declare -x SECRET_VOLUME='/run/secrets/' ## Secret Volume -declare -x PWD_KEY='pwd.key' ## PWD Key File -declare -x COMMON_OS_PWD_FILE='common_os_pwdfile.enc' -declare -x DB_PWD_FILE -export PDB_SQL_SCRIPT="/tmp/pdb.sql" -export TOP_PID=$$ -rm -f /tmp/sqllog.output -rm -f $PDB_SQL_SCRIPT -rm -f $LOGFILE - -#################################### Print and Exit Functions Begin Here ####################### -error_exit() { -local NOW=$(date +"%m-%d-%Y %T %Z") - # Display error message and exit -# echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2 - echo "${NOW} : ${PROGNAME}: ${1:-"Unknown Error"}" | tee -a $LOGFILE > $STD_OUT_FILE - kill -s TERM $TOP_PID -} - -print_message () -{ - local NOW=$(date +"%m-%d-%Y %T %Z") - # Display message and return - echo "${NOW} : ${PROGNAME} : ${1:-"Unknown Message"}" | tee -a $LOGFILE > $STD_OUT_FILE - return $? -} -#################################### Print and Exit Functions End Here ####################### - - -####################################### Functions Related to checks #################### -dbChecks() -{ -if [ -z "$ORACLE_HOME" ] -then - error_exit "Set the ORACLE_HOME variable" -else - print_message "ORACLE_HOME set to $ORACLE_HOME" -fi - -# If ORACLE_HOME doesn't exist # -if [ ! -d "$ORACLE_HOME" ] -then - error_exit "The ORACLE_HOME $ORACLE_HOME does not exist" -else - print_message "ORACLE_HOME Directory Exist" -fi - -################## Checks for Password and Clustername and clustertype begins here ########### -if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then -cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' - -eval $cmd - -if [ $? -eq 0 ]; then -print_message "Password file generated" -else -error_exit "Error occurred during common os password file generation" -fi - -read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} -rm -f /tmp/${COMMON_OS_PWD_FILE} -else - print_message "Password is empty string" - export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 -fi - -if [ -z "${ORACLE_PWD}" ]; then - print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" - export ORACLE_PWD=${PASSWORD} -else - print_message "ORACLE_PWD is set to user specified password" -fi - -################################################################################################### - - -if [ -z "${SHARD_ADMIN_USER}" ] -then - print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" - export SHARD_ADMIN_USER="mysdbadmin" -else - print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" -fi - - -if [ -z "${PDB_ADMIN_USER}" ] -then - print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" - export PDB_ADMIN_USER="pdbadmin" -else - print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" -fi - - -# Validate the value of ORACLE_SID # -if [ -z "${ORACLE_SID}" ] -then - error_exit "Set the ORACLE_SID variable" -else - print_message "ORACLE_SID is set to $ORACLE_SID" -fi - -if [ -z "${ORACLE_HOSTNAME}" ] -then - if [ -z "${KUBE_SVC}" ]; then - print_message "ORACLE_HOSTNAME variable is not set" - export ORACLE_HOSTNAME="$(hostname)" - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" - else - print_message "ORACLE_HOSTNAME variable is not set" - export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" - fi -else - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" -fi - - - -if [ -z "$DB_PORT" ] -then - print_message "Set the DB_PORT variable" - export DB_PORT=1521 -else - print_message "DB Port is set to $DB_PORT" -fi - -if [ -z "${DB_RECOVERY_FILE_DEST}" ]; then - print_message "Set the DB_RECOVERY_FILE_DEST is not set" - export DB_RECOVERY_FILE_DEST="${ORACLE_BASE}/oradata/fast_recovery_area/${ORACLE_SID}" -fi - -if [ -z "${DB_CREATE_FILE_DEST}" ]; then - print_message "Set the DB_CREATE_FILE_DEST is not set. Setting to ${ORACLE_BASE}/oradata/${ORACLE_SID}" - export DB_CREATE_FILE_DEST="${ORACLE_BASE}/oradata/${ORACLE_SID}" -fi - -if [ -z "${DATA_PUMP_DIR}" ]; then - print_message "DATA_PUMP_DIR is not set, it will se to ${ORACLE_BASE}/oradata/data_pump_dir" - export DATA_PUMP_DIR="${ORACLE_BASE}/oradata/data_pump_dir" -fi - -if [ ! -d "${DATA_PUMP_DIR}" ]; then - print_message "DATA_PUMP_DIR ${DATA_PUMP_DIR} directory does not exist" - mkdir -p "${DATA_PUMP_DIR}" -fi - -if [ ! -d "${DB_RECOVERY_FILE_DEST}" ]; then - print_message "DB_RECOVERY_FILE_DEST ${DB_RECOVERY_FILE_DEST} directory does not exist" - mkdir -p "${DB_RECOVERY_FILE_DEST}" -fi - -if [ -z "${DB_RECOVERY_FILE_DEST_SIZE}" ]; then - print_message "DB_RECOVERY_FILE_DEST_SIZE is not set" - export DB_RECOVERY_FILE_DEST_SIZE="40G" -else - print_message "DB_RECOVERY_FILE_DEST_SIZE is set to ${DB_RECOVERY_FILE_DEST_SIZE}" -fi - -} - -gsmChecks() -{ - print_message "Performing GSM related checks" - -if [ ! -z "${KUBE_SVC}" ]; then - lordinal=$( hostname | awk -F "-" '{ print $NF }' ) - print_message "lordinal is set to ${lordinal}" - region_num=$((lordinal+1)) - if [ -z "${REGION}" ]; then - print_message "REGION is not set. Setting to region$lordinal" - export REGION="region${region_num}" - fi -else - if [ -z "${REGION}" ]; then - error_exit "REGION Canot be set to empty" - fi -fi - -################## Checks for Password and Clustername and clustertype begins here ########### -if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then -cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' - -eval $cmd - -if [ $? -eq 0 ]; then -print_message "Password file generated" -else -error_exit "Error occurred during common os password file generation" -fi - -read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} -rm -f /tmp/${COMMON_OS_PWD_FILE} -else - print_message "Password is empty string" - export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 -fi - -if [ -z "${ORACLE_PWD}" ]; then - print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" - export ORACLE_PWD=${PASSWORD} -else - print_message "ORACLE_PWD is set to user specified password" -fi - -################################################################################################### - -if [ -z "$SHARD_ADMIN_USER" ] -then - print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" - export SHARD_ADMIN_USER="mysdbadmin" -else - print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" -fi - - -if [ -z "$PDB_ADMIN_USER" ] -then - print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" - export PDB_ADMIN_USER="pdbadmin" -else - print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" -fi - - -if [ -z "${SHARD_GROUP_NAME}" ]; then - print_message "SHARD_GROUP_NAME is not set, it will be set to primary_shardgroup" - export SHARD_GROUP_NAME="primary_shardgroup" -fi - -if [ -z "${SHARD_DEPLOYMENT_TYPE}" ]; then - print_message "SHARD_DEPLOYMENT_TYPE is not set, it will set to primary" - export SHARD_DEPLOYMENT_TYPE="primary" -fi - -if [ -z "${SHARD_DIRECTOR_NAME}" ]; then - print_message "SHARD_DIRECTOR_NAME is not set, it will set to sharddirector${region_num}" - export SHARD_DIRECTOR_NAME="sharddirector${region_num}" -fi - -if [ -z "${ORACLE_HOSTNAME}" ] -then - if [ -z "${KUBE_SVC}" ]; then - print_message "ORACLE_HOSTNAME variable is not set" - export ORACLE_HOSTNAME="$(hostname)" - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" - else - print_message "ORACLE_HOSTNAME variable is not set" - export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" - fi -else - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" -fi - -} - -###################################### Function Related to Check end here ################### - -################################### Reset Password ########################################### -resetPassword() -{ -if [ -f "${HOME}/setPassword.sh" ]; then -if [ ! -z "${ORACLE_PWD}" ]; then -"${HOME}"/setPassword.sh "$ORACLE_PWD" -fi -fi -} - -############################################################################################### -setupCatalog() -{ - -localconnectStr="/ as sysdba" -systemStr="system/${ORACLE_PWD}" -sqlScript="/tmp/setapp.sql" -print_message "Setting up Paramteres in Spfile" - -cmd1="drop table shardsetup;" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" - -cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - -cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - -cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" -#cmd=$( eval echo "$cmd1" ) -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter system set open_links=16 scope=spfile;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter system set open_links_per_instance=16 scope=spfile;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="@$ORACLE_HOME/rdbms/admin/setCatalogDBPrivs.sql;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" -print_message "cat /tmp/setup_grants_privs.lst" - -cmd1="alter user gsmcatuser account unlock;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter user gsmcatuser identified by $ORACLE_PWD;" -print_message "Sending query to sqlplus to execute alter user gsmcatuser identified by ORACLE_PWD;" -executeSQL "$cmd1" "$localconnectStr" - - -#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" -cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - - -cmd1="shutdown immediate;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="startup mount;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database archivelog;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database open;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database flashback on;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database force logging;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1", "$localconnectStr" - -cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - -if [ ! -z "${ORACLE_PDB}" ]; then -setupCatalogPDB -fi - -cmd1="create table shardsetup (status varchar2(10));" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" - -cmd1="insert into shardsetup values('completed');" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" -} - -configureSampleAppSchema() -{ -local sqlScript="/tmp/sqlScript.sql" -connectStr = "${SHARD_ADMIN_USER}/${ORACLE_PWD}" - -echo "alter session enable shard ddl;" > ${sqlScript} -echo "create user app_schema identified by '&1';" >> ${sqlScript} -echo "grant all privileges to app_schema;" >> ${sqlScript} -echo "grant gsmadmin_role to app_schema;" >> ${sqlScript} -echo "grant select_catalog_role to app_schema;" >> ${sqlScript} -echo "grant connect, resource to app_schema;" >> ${sqlScript} -echo "grant dba to app_schema;" >> ${sqlScript} -echo "grant execute on dbms_crypto to app_schema;" >> ${sqlScript} -echo "CREATE TABLESPACE SET TSP_SET_1 using template (datafile size 100m autoextend on next 10M maxsize unlimited extent management local segment space management auto);" >> ${sqlScript} -echo "CREATE TABLESPACE SET LOBTS1;" >> ${sqlScript} -echo "CREATE TABLESPACE products_tsp datafile size 100m autoextend on next 10M maxsize unlimited extent management local uniform size 1m; " >> ${sqlScript} -echo "CONNECT app_schema/'&1';" >> ${sqlScript} -echo "ALTER SESSION ENABLE SHARD DDL;" >> ${sqlScript} -echo "CREATE SHARDED TABLE Customers (CustId VARCHAR2(60) NOT NULL, FirstName VARCHAR2(60), LastName VARCHAR2(60), Class VARCHAR2(10), Geo VARCHAR2(8),CustProfile VARCHAR2(4000),Passwd RAW(60),CONSTRAINT pk_customers PRIMARY KEY (CustId),CONSTRAINT json_customers CHECK (CustProfile IS JSON)) TABLESPACE SET TSP_SET_1 PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO;" >> ${sqlScript} -echo "CREATE SHARDED TABLE Orders (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL, OrderDate TIMESTAMP NOT NULL,SumTotal NUMBER(19,4),Status CHAR(4), CONSTRAINT pk_orders PRIMARY KEY (CustId, OrderId),CONSTRAINT fk_orders_parent FOREIGN KEY (CustId) REFERENCES Customers ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_orders_parent);" >> ${sqlScript} -echo "CREATE SEQUENCE Orders_Seq;" >> ${sqlScript} -echo "CREATE SHARDED TABLE LineItems (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL,ProductId INTEGER NOT NULL,Price NUMBER(19,4),Qty NUMBER,CONSTRAINT pk_items PRIMARY KEY (CustId, OrderId, ProductId),CONSTRAINT fk_items_parent FOREIGN KEY (CustId, OrderId) REFERENCES Orders ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_items_parent);" >> ${sqlScript} -echo "CREATE DUPLICATED TABLE Products (ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,Name VARCHAR2(128),DescrUri VARCHAR2(128),LastPrice NUMBER(19,4)) TABLESPACE products_tsp;" >> ${sqlScript} - -print_message "Executing sql script ${sqlScript}" -cat ${sqlScript} >> $LOGFILE -executeSQL "$cmd1" "$connectStr" "sqlScript" "${sqlScript}" - -} - - -setupCatalogPDB() -{ -#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" -pdbConnStr=" /as sysdba" - -local sqlScript="/tmp/sqlScript.sql" - -print_message "Settup Sql Script to setup Catalog PDB" -echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" -echo "create user ${SHARD_ADMIN_USER} identified by ${ORACLE_PWD};" >> "${sqlScript}" -echo "grant connect, create session, gsmadmin_role to ${SHARD_ADMIN_USER} ;" >> "${sqlScript}" -echo "grant inherit privileges on user SYS to GSMADMIN_INTERNAL;" >> "${sqlScript}" -echo "execute dbms_xdb.sethttpport(8080);" >> ${sqlScript} -echo "exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('${ORACLE_PWD}');" >> "${sqlScript}" - -print_message "Executing sql script ${sqlScript}" -cat ${sqlScript} >> $LOGFILE -executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" -} - -######################################################################## Catalog Setup task ends here ################################# - -######################################################################## Primary Shard Setup task ends here ################################# - -setupShardPDB() -{ - -#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" -pdbConnStr=" /as sysdba" - -local sqlScript="/tmp/sqlScript.sql" -print_message "Settup Sql Script to setup Catalog PDB" -echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" -echo "grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" >> "${sqlScript}" -echo "grant sysdg to GSMUSER;" >> "${sqlScript}" -echo "grant sysbackup to GSMUSER;" >> "${sqlScript}" -echo "execute DBMS_GSM_FIX.validateShard;" >> ${sqlScript} -print_message "Executing sql script ${sqlScript}" -cat ${sqlScript} >> $LOGFILE -executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" - -} - -setupShardCDB() -{ -localconnectStr="/as sysdba" -systemStr="system/${ORACLE_PWD}" -print_message "Setting up Paramteres in Spfile" - -cmd1="drop table shardsetup;" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" - -cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - -cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - -cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter system set open_links=16 scope=spfile;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter system set open_links_per_instance=16 scope=spfile;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter user gsmrootuser account unlock;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter user gsmrootuser identified by ${ORACLE_PWD} container=all;" -print_message "Sending query to sqlplus to execute alter user gsmrootuser identified by ORACLE_PWD container=all;" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="grant sysdg to gsmrootuser;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="grant sysbackup to gsmrootuser;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter user GSMUSER account unlock;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter user GSMUSER identified by ${ORACLE_PWD} container=all;" -print_message "Sending query to sqlplus to execute alter user GSMUSER identified by ORACLE_PWD container=all;" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="grant sysdg to GSMUSER;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="grant sysbackup to GSMUSER;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter system set dg_broker_start=true scope=both;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="create or replace directory DATA_PUMP_DIR as '${DATA_PUMP_DIR}';" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" -cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="shutdown immediate;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="startup mount;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database archivelog;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database open;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database flashback on;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database force logging;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -if [ ! -z "${ORACLE_PDB}" ]; then - -setupShardPDB - -fi - -cmd1="create table shardsetup (status varchar2(10));" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" - - -cmd1="insert into shardsetup values('completed');" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" - -} - -######################################################################## Primary Shard Setup ends here ################################# - -######################################################################## GSM Setup Task Begin here ##################################### -setupGSM() -{ -local cstatus='false' -local sstatus='false' - -setupGSMCatalog -startGSM -addShardGroup -setupGSMShard - -} - -startGSM() -{ - -cmd1="start gsm" -print_message "Sending query to gsm to execute $cmd1" -executeGSM "$cmd1" -} - -deployShard() -{ - -cmd1="deploy" -print_message "Sending query to gsm to execute $cmd1" -executeGSM "$cmd1" -} - -stopGSM() -{ - -cmd1="stop gsm" -print_message "Sending query to gsm to execute $cmd1" -executeGSM "$cmd1" -} - -addInvitedNode() -{ - -chost=$1 - -cmd1="add invitednode $chost" -print_message "Sending query to gsm to execute $cmd1" -executeGSM "$cmd1" -} - - -addShardGroup() -{ - -cmd1="add shardgroup -shardgroup ${shardGName} -deploy_as ${deployment_type} -region ${region}" -print_message "Sending query to gsm to execute $cmd1" -executeGSM "$cmd1" -} - -checkStatus() -{ -host=$1 -port=1521 -cpdb=$3 -ccdb=$2 -uname="system" -cpasswd=${ORACLE_PWD} - -print_message "Connect String $uname/$cpasswd@//$host:$port/$ccdb" -output=$( "$ORACLE_HOME"/bin/sqlplus -s "$uname/$cpasswd@//$host:$port/$ccdb" <<EOF - set heading off feedback off verify off echo off PAGESIZE 0 - select status from shardsetup; - exit -EOF -) - - if [ "${output}" == 'completed' ];then - print_message "Returned status from catalog is $output" - else - print_message "Sleeping for 300 seconds as returned status is not $output " - sleep 300 - fi - - echo $output -} - -setupGSMCatalog() -{ -IFS='; ' read -r -a sarray <<< "$CATALOG_PARAMS" -for element in "${sarray[@]}" -do - print_message "1st String in Shard params $element" - type=$( echo $element | awk -F: '{print $NF }') - host=$( echo $element | awk -F: '{print $1 }') - db=$( echo $element | awk -F: '{print $2 }') - pdb=$( echo $element | awk -F: '{print $3 }') -done - -print_message "Set variables to host=${host} db=${db} pdb=${pdb}" -if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] -then -runtime="60 minute" -endtime=$(date -ud "$runtime" +%s) - -while [[ $(date -u +%s) -le $endtime ]] -do - - coutput=$( checkStatus $host $db $pdb ) - if [ "${coutput}" == 'completed' ] ;then - configureGSMCatalog $host $db $pdb - break - else - print_message "Catalog Status must return completed but returned value is $coutput" - fi - print_message "Catalog DB is still not ready. Sleeping for 60 seconds" - sleep 60 -done -fi - -if [ "${coutput}" != 'completed' ] ;then - error_exit "Shard Catalog is not setup, Unable to proceed futher" -fi - -} - -configureGSMCatalog() -{ -chost=$1 -cport=1521 -cpdb=$3 -ccdb=$2 -gsmhost=${ORACLE_HOSTNAME} -cadmin=${SHARD_ADMIN_USER} -cpasswd=${ORACLE_PWD} -########################## -region="${REGION}" -shardGName="${SHARD_GROUP_NAME}" -deployment_type="${SHARD_DEPLOYMENT_TYPE}" -local gdsScript="/tmp/gdsScript.sql" - -gsm_name="${SHARD_DIRECTOR_NAME}" -echo "create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=${chost})(PORT=${cport}))(CONNECT_DATA=(SERVICE_NAME=${cpdb})))\" -user ${cadmin}/${cpasswd} -sdb shardcatalog -region region1,region2 -agent_port 8080 -agent_password ${cpasswd} -autovncr off" > "${gdsScript}" -echo "add invitednode ${chost}" >> "${gdsScript}" -echo "add gsm -gsm ${gsm_name} -listener 1521 -pwd ${cpasswd} -catalog ${chost}:${cport}/${cpdb} -region region1 -endpoint '(ADDRESS=(PROTOCOL=tcp)(HOST=${gsmhost})(PORT=1521))'" >> "${gdsScript}" -echo "exit" >> "${gdsScript}" -print_message "Sending script to gsm to execute ${gdsScript}" -cat ${gdsScript} >> $LOGFILE -cp "${gdsScript}" "${gdsScript}.test" -executeGSM "$cmd1" "gdsScript" "${gdsScript}" -} - -setupGSMShard() -{ -IFS='; ' read -r -a sarray <<< "$PRIMARY_SHARD_PARAMS" -arrLen=$( echo "${#sarray[@]}" ) -count1=0 - -runtime="45 minute" -endtime=$(date -ud "$runtime" +%s) - -print_message "Set variables to host=${host} db=${db} pdb=${pdb}" -while [[ $(date -u +%s) -le $endtime ]] -do - for i in ${!sarray[@]}; do - print_message "1st String in Shard params $element" - host=$( echo ${sarray[i]} | awk -F: '{print $1 }') - db=$( echo ${sarray[i]} | awk -F: '{print $2 }') - pdb=$( echo ${sarray[i]} | awk -F: '{print $3 }') - print_message "shard env set to host=${host} db=${db} pdb=${pdb}" - if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] - then - coutput=$( checkStatus $host $db $pdb ) - if [ "${coutput}" == 'completed' ] ;then - configureGSMShard $host $db $pdb - unset sarray[i] - ((++count1)) - else - print_message "Catalog Status must return completed but returned value is $coutput" - fi - fi - done - if [ ${count1} -ge ${arrLen} ]; then - break; - fi - print_message "Shards are still not ready. Sleeping for 120 seconds" - sleep 120 -done -} - -configureGSMShard() -{ -chost=$1 -cport=1521 -cpdb=$3 -ccdb=$2 -cpasswd=${ORACLE_PWD} -region=${REGION} -shardGName="${SHARD_GROUP_NAME}" -deployment_type="${SHARD_DEPLOYMENT_TYPE}" -local gdsScript="/tmp/gdsScript.sql" -admuser="${PDB_ADMIN_USER}" - -echo "connect ${admuser}/${cpasswd}" > "${gdsScript}" -echo "add cdb -connect ${chost}:${cport}:${ccdb} -pwd ${cpasswd}" >> "${gdsScript}" -echo "add shard -cdb ${ccdb} -connect ${chost}:${cport}/${cpdb} -shardgroup ${shardGName} -pwd ${cpasswd}" >> "${gdsScript}" -echo "config vncr" >> "${gdsScript}" -echo "sql 'update gsmadmin_internal.database set hostid=NULL '" >> "${gdsScript}" -echo "exit" >> "${gdsScript}" -print_message "Sending script to gsm to execute ${gdsScript}" -cat ${gdsScript} >> $LOGFILE -executeGSM "$cmd1" "gdsScript" "${gdsScript}" -print_message " Calling Stop GSM function" -stopGSM -print_message "Stop GSM function completed, sleeping for 20 seconds" -sleep 20 -print_message " Calling Start GSM function" -startGSM -print_message "Start GSM function completed, sleeping for 30 seconds" -sleep 30 -print_message "Calling invitenode function to add the shard" -addInvitedNode $chost -deployShard -} - -####################################################################### GSM Setup Task Ends here ######################################### - - -######################################################################### Execute GSM Statements ######################################### -executeGSM() -{ -gsmQuery=$1 -type=$2 -gdsScript=$3 - -if [ -z "${gsmQuery}" ]; then - print_message "Empty gdsQuery passed to gds" -fi - -if [ -z "${type}" ]; then - type='notSet' -fi - -if [ -z "${gdsScript}" ]; then - gdsScript='notSet' -fi - -if [ "${type}" == "gdsScript" ]; then -print_message "Executing gds script " -"$ORACLE_HOME"/bin/gdsctl @${gdsScript} -else -print_message "Executing GSM query" -"$ORACLE_HOME"/bin/gdsctl << EOF >> $LOGFILE - $gsmQuery - exit -EOF -fi -} -######################################################################## Execute GSM Statements Ends here ################################ - -########################################################################## Execute SQL Function Begin here ############################## -executeSQL() -{ -sqlQuery=$1 -connectStr=$2 -type=$3 -sqlScript=$4 - -if [ -z "${sqlQuery}" ]; then - print_message "Empty sqlQuery passed to sqlplus. Operation Failed" -fi - -if [ -z "${connectStr}" ]; then - error_exit "Empty connectStr passed to sqlplus. Operation Failed" -fi - -if [ -z "${type}" ]; then - type='notSet' -fi - -if [ -z "${sqlScript}" ]; then - sqlScript='notSet' -fi - -if [ "${type}" == "sqlScript" ] && [ -f ${sqlScript} ]; then -print_message "Executing sql script using connect string" -"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE -@ ${sqlScript} -EOF -else -print_message "Executing sqlQuery using connect string" -"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE -$sqlQuery -EOF -fi -} - -############################################################################## Execute SQl Function ends here ################################# - -####################################### -################## MAIN ############### - -if [ "${OP_TYPE}" == "primaryshard" ]; then - print_message "Performing Checks before proceeding for setup" - dbChecks - print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" - resetPassword - setupShardCDB -elif [ "${OP_TYPE}" == "standbyshard" ]; then - print_message "Performing Checks before proceeding for setup" - dbChecks - print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" - setupShardStandby -elif [ "${OP_TYPE}" == "catalog" ]; then - print_message "Performing Checks before proceeding for setup" - dbChecks - print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" - resetPassword - setupCatalog -elif [ "${OP_TYPE}" == "gsm" ]; then - print_message "Performing Checks before proceeding for setup" - gsmChecks - print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" - setupGSM -else - print_message "OP_TYPE must be set to (gsm|catalog|primaryshard|standbyshard)" - exit 15 -fi diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install.rsp b/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install.rsp deleted file mode 100644 index 102854f..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install.rsp +++ /dev/null @@ -1,35 +0,0 @@ - -############################################################################### -## Copyright(c) Oracle Corporation 1998,2022. All rights reserved. ## -## ## -## Specify values for the variables listed below to customize ## -## your installation. ## -## ## -## Each variable is associated with a comment. The comment ## -## can help to populate the variables with the appropriate ## -## values. ## -## ## -############################################################################### - -#------------------------------------------------------------------------------- -# Do not change the following system generated value. -#------------------------------------------------------------------------------- -oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v23.0.0 - -#------------------------------------------------------------------------------- -# Unix group to be set for the inventory directory. -#------------------------------------------------------------------------------- -UNIX_GROUP_NAME=oinstall -#------------------------------------------------------------------------------- -# Inventory location. -#------------------------------------------------------------------------------- -INVENTORY_LOCATION=###INVENTORY### -#------------------------------------------------------------------------------- -# Complete path of the Oracle Home -#------------------------------------------------------------------------------- -ORACLE_HOME=###ORACLE_HOME### - -#------------------------------------------------------------------------------- -# Complete path of the Oracle Base. -#------------------------------------------------------------------------------- -ORACLE_BASE=###ORACLE_BASE### diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install_sample.rsp b/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install_sample.rsp deleted file mode 100644 index fce54e3..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/23c_gsm_install_sample.rsp +++ /dev/null @@ -1,35 +0,0 @@ - -############################################################################### -## Copyright(c) Oracle Corporation 1998,2022. All rights reserved. ## -## ## -## Specify values for the variables listed below to customize ## -## your installation. ## -## ## -## Each variable is associated with a comment. The comment ## -## can help to populate the variables with the appropriate ## -## values. ## -## ## -############################################################################### - -#------------------------------------------------------------------------------- -# Do not change the following system generated value. -#------------------------------------------------------------------------------- -oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v23.0.0 - -#------------------------------------------------------------------------------- -# Unix group to be set for the inventory directory. -#------------------------------------------------------------------------------- -UNIX_GROUP_NAME= -#------------------------------------------------------------------------------- -# Inventory location. -#------------------------------------------------------------------------------- -INVENTORY_LOCATION= -#------------------------------------------------------------------------------- -# Complete path of the Oracle Home -#------------------------------------------------------------------------------- -ORACLE_HOME= - -#------------------------------------------------------------------------------- -# Complete path of the Oracle Base. -#------------------------------------------------------------------------------- -ORACLE_BASE= diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/Checksum b/container-based-sharding-deployment/containerfiles/23.4.0/Checksum deleted file mode 100644 index faf7c8c..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/Checksum +++ /dev/null @@ -1 +0,0 @@ -ba8e6b942ba8ff22d25dd3babc7b326c LINUX.X64_234000_gsm.zip diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/Containerfile b/container-based-sharding-deployment/containerfiles/23.4.0/Containerfile deleted file mode 100644 index 5b9420b..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/Containerfile +++ /dev/null @@ -1,232 +0,0 @@ -# LICENSE UPL 1.0 -# -# Copyright (c) 2018,2022 Oracle and/or its affiliates. -# -# ORACLE DOCKERFILES PROJECT -# -------------------------- -# This is the Dockerfile for Oracle GSM 23ai Release 4 to build the container image -# MAINTAINER <paramdeep.saini@oracle.com> -# -# This is the Dockerfile for Oracle GSM 23ai -# -# REQUIRED FILES TO BUILD THIS IMAGE -# ---------------------------------- -# (1) LINUX.X64_234000_gsm.zip -# Download Oracle Database 23ai GSM Software -# from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html -# -# HOW TO BUILD THIS IMAGE -# ----------------------- -# Put all downloaded files in the same directory as this Dockerfile -# Run: -# $ docker build -t oracle/gsm:23.4.0 . -# - -ARG BASE_OL_IMAGE=oraclelinux:8 - -# Pull base image -# --------------- -FROM $BASE_OL_IMAGE AS base -ARG SLIMMING=false - -# Labels -# ------ -LABEL "provider"="Oracle" \ - "issues"="https://github.com/oracle/db-sharding/issues" \ - "volume.setup.location1"="/opt/oracle/scripts" \ - "port.listener"="1522" - -# Argument to control removal of components not needed after db software installation - -ARG INSTALL_FILE_1="LINUX.X64_234000_gsm.zip" -ARG USER="root" - -# Environment variables required for this build (do NOT change) -# ------------------------------------------------------------- -ENV GSM_BASE="/u01/app/oracle" \ - GSM_USER="oracle" \ - GSM_HOME="/u01/app/oracle/product/23ai/gsmhome_1" \ - INVENTORY="/u01/app/oracle/oraInventory" \ - INSTALL_DIR="/opt/oracle/scripts" \ - INSTALL_FILE_1=$INSTALL_FILE_1 \ - INSTALL_RSP="23c_gsm_install.rsp" \ - RUN_FILE="runOracle.sh" \ - SETUP_LINUX_FILE="setupLinuxEnv.sh" \ - CHECK_SPACE_FILE="checkSpace.sh" \ - USER_SCRIPTS_FILE="runUserScripts.sh" \ - INSTALL_GSM_BINARIES_FILE="installGSMBinaries.sh" \ - GSM_SETUP_FILE="setupOshardEnv.sh" \ - GSM_ENV_SETUP_FILE="setupGSM.sh" \ - GSM_SCRIPTS="scripts" \ - MAINPY="main.py" \ - PYTHON_FILE="/usr/bin/python" \ - PYTHON3_FILE="/usr/bin/python3" \ - ORAPCATALOG="orapcatalog.py" \ - CMDEXEC="cmdExec" \ - ORAMACHINE="oramachine.py" \ - ORALOGGER="oralogger.py" \ - ORAFACTORY="orafactory.py" \ - ORAGSM="oragsm.py" \ - ORASSHARD="orasshard.py" \ - ORAENV="oraenv.py" \ - ORAPSHARD="orapshard.py" \ - MAINPY="main.py" \ - ORASCATALOG="orascatalog.py" \ - ORACOMMON="oracommon.py" \ - DEMOAPPSQL="demoapp.sql" \ - RUNORASHARD="runOraShardSetup.sh" \ - CHECKLIVENESS="checkLiveness.sh" -# Use second ENV so that variable get substituted -ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ - ORACLE_HOME=$GSM_HOME \ - ORACLE_BASE=$GSM_BASE \ - SCRIPT_DIR=$INSTALL_DIR/sharding \ - PATH=/bin:/usr/bin:/sbin:/usr/sbin \ - GSM_PATH=$GSM_HOME/bin:$PATH \ - GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib - -############################################# -# ------------------------------------------- -# Start new stage for slim image -# ------------------------------------------- -############################################# -FROM base AS gsm-image-slim-false -ARG SLIMMING - -# Environment variables required for this build (do NOT change) -# ------------------------------------------------------------- -# Linux Env Variable -ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ - ORACLE_HOME=$GSM_HOME \ - ORACLE_BASE=$GSM_BASE \ - SCRIPT_DIR=$INSTALL_DIR/sharding \ - PATH=/bin:/usr/bin:/sbin:/usr/sbin \ - GSM_PATH=$GSM_HOME/bin:$PATH \ - GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib \ - INSTALL_SCRIPTS=$INSTALL_DIR/install \ - PATH=/bin:/usr/bin:/sbin:/usr/sbin \ - GSM_SCRIPTS="scripts" - -# Copy binaries -# ------------- -# COPY Binaries -COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $GSM_ENV_SETUP_FILE $INSTALL_SCRIPTS/ -COPY $RUN_FILE $GSM_SETUP_FILE $CHECKLIVENESS $USER_SCRIPTS_FILE $SCRIPT_DIR/ -COPY $GSM_SCRIPTS/$ORAPCATALOG $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$ORAPSHARD $GSM_SCRIPTS/$MAINPY $GSM_SCRIPTS/$ORASCATALOG $GSM_SCRIPTS/$ORACOMMON $GSM_SCRIPTS/$DEMOAPPSQL $GSM_SCRIPTS/$RUNORASHARD $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$ORAMACHINE $GSM_SCRIPTS/$ORALOGGER $GSM_SCRIPTS/$ORAFACTORY $GSM_SCRIPTS/$ORAGSM $GSM_SCRIPTS/$ORASSHARD $GSM_SCRIPTS/$ORAENV $SCRIPT_DIR/scripts/ - -RUN chmod 755 $INSTALL_DIR/install/*.sh && \ - sync && \ - $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ - $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ - $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ - sync - -############################################# -# ------------------------------------------- -# Start new stage for slim image true -# ------------------------------------------- -############################################# -FROM base AS gsm-image-slim-true -ARG SLIMMING - -# Environment variables required for this build (do NOT change) -# ------------------------------------------------------------- -# Linux Env Variable -ENV INSTALL_SCRIPTS=$INSTALL_DIR/install \ - ORACLE_HOME=$GSM_HOME \ - ORACLE_BASE=$GSM_BASE \ - SCRIPT_DIR=$INSTALL_DIR/sharding \ - PATH=/bin:/usr/bin:/sbin:/usr/sbin \ - GSM_PATH=$GSM_HOME/bin:$PATH \ - GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib \ - INSTALL_SCRIPTS=$INSTALL_DIR/install \ - PATH=/bin:/usr/bin:/sbin:/usr/sbin \ - GSM_SCRIPTS="scripts" - -# Copy binaries -# ------------- -# COPY Binaries -COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $GSM_ENV_SETUP_FILE $INSTALL_SCRIPTS/ -COPY $RUN_FILE $GSM_SETUP_FILE $CHECKLIVENESS $USER_SCRIPTS_FILE $SCRIPT_DIR/ -COPY $GSM_SCRIPTS/$ORAPCATALOG $GSM_SCRIPTS/$ORAPSHARD $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$MAINPY $GSM_SCRIPTS/$ORASCATALOG $GSM_SCRIPTS/$ORACOMMON $GSM_SCRIPTS/$DEMOAPPSQL $GSM_SCRIPTS/$RUNORASHARD $GSM_SCRIPTS/$CMDEXEC $GSM_SCRIPTS/$ORAMACHINE $GSM_SCRIPTS/$ORALOGGER $GSM_SCRIPTS/$ORAFACTORY $GSM_SCRIPTS/$ORAGSM $GSM_SCRIPTS/$ORASSHARD $GSM_SCRIPTS/$ORAENV $SCRIPT_DIR/scripts/ - -RUN chmod 755 $INSTALL_DIR/install/*.sh && \ - sync && \ - $INSTALL_DIR/install/$CHECK_SPACE_FILE && \ - $INSTALL_DIR/install/$SETUP_LINUX_FILE && \ - $INSTALL_DIR/install/$GSM_ENV_SETUP_FILE && \ - sync - -############################################# -# ------------------------------------------- -# Start new stage for installing the grid and DB -# ------------------------------------------- -############################################# - -FROM gsm-image-slim-${SLIMMING} AS builder -ARG SLIMMING - -COPY $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_GSM_BINARIES_FILE $GSM_SETUP_FILE $INSTALL_DIR/install/ - -USER ${USER} -RUN if [ "${SLIMMING}x" != 'truex' ]; then \ - chmod 755 $INSTALL_SCRIPTS/*.sh && \ - :;\ - fi -USER ${GSM_USER} -RUN if [ "${SLIMMING}x" != 'truex' ]; then \ - "$INSTALL_DIR/install/$INSTALL_GSM_BINARIES_FILE" && \ - :;\ -fi - -USER ${USER} -RUN if [ "${SLIMMING}x" != 'truex' ]; then \ - $INVENTORY/orainstRoot.sh && \ - $GSM_HOME/root.sh && \ - rm -rf $INSTALL_DIR/install && \ - :;\ - fi - -#RUN if [ "${SLIMMING}x" == 'truex' ]; then \ -# mkdir /u01 && \ -# :; \ -#fi - -RUN rm -f $INSTALL_DIR/install/* && \ - sync - -############################################# -# ------------------------------------------- -# Start new layer for GSM runtime -# ------------------------------------------- -############################################# - -FROM gsm-image-slim-${SLIMMING} AS final - -COPY --from=builder /u01 /u01 - -RUN if [ ! -f $PYTHON_FILE ]; then \ - ln -s $PYTHON3_FILE $PYTHON_FILE && \ - :; \ - fi && \ - rm -f $INSTALL_DIR/install/* && \ - cp $SCRIPT_DIR/scripts/cmdExec $SCRIPT_DIR/ && \ - chown -R oracle:oinstall $SCRIPT_DIR && \ - chmod 755 $SCRIPT_DIR/*.sh && \ - chmod 755 $SCRIPT_DIR/scripts/*.py && \ - chmod 755 $SCRIPT_DIR/scripts/*.sh && \ - chmod 755 $SCRIPT_DIR/scripts/cmdExec && \ - chmod 755 $SCRIPT_DIR/cmdExec && \ - sync - -USER ${GSM_USER} -WORKDIR /home/${GSM_USER} -EXPOSE 1522 - -VOLUME ["$GSM_BASE/oradata"] - -HEALTHCHECK --interval=2m --start-period=25m \ - CMD "$SCRIPT_DIR/$CHECKLIVENESS" >/dev/null || exit 1 - -# Define default command to start Oracle Database. -CMD exec $SCRIPT_DIR/$RUN_FILE diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/checkLiveness.sh b/container-based-sharding-deployment/containerfiles/23.4.0/checkLiveness.sh deleted file mode 100644 index e917502..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/checkLiveness.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -# -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: Build script for building RAC container image -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -export PYTHON="/bin/python3" - -$PYTHON $SCRIPT_DIR/scripts/$MAINPY --checkliveness='true' -retcode=$? - - if [ ${retcode} -eq 0 ]; then - exit 0 - else - exit 1 - fi diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/checkSpace.sh b/container-based-sharding-deployment/containerfiles/23.4.0/checkSpace.sh deleted file mode 100644 index 5d4b8d9..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/checkSpace.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -REQUIRED_SPACE_GB=2 -AVAILABLE_SPACE_GB=`df -PB 1G / | tail -n 1 | awk '{ print $4 }'` - -if [ $AVAILABLE_SPACE_GB -lt $REQUIRED_SPACE_GB ]; then - script_name=`basename "$0"` - echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - echo "$script_name: ERROR - There is not enough space available in the docker container." - echo "$script_name: The container needs at least $REQUIRED_SPACE_GB GB, but only $AVAILABLE_SPACE_GB GB are available." - echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - exit 1; -fi; diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/installGSMBinaries.sh b/container-based-sharding-deployment/containerfiles/23.4.0/installGSMBinaries.sh deleted file mode 100644 index adf6547..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/installGSMBinaries.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -# -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: Build script for building RAC container image -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -export ORACLE_BASE=$GSM_BASE -export ORACLE_HOME=$GSM_HOME - -# Check whether ORACLE_BASE is set -if [ "$ORACLE_BASE" == "" ]; then - echo "ERROR: ORACLE_BASE has not been set!" - echo "You have to have the ORACLE_BASE environment variable set to a valid value!" - exit 1; -fi; - -# Check whether ORACLE_HOME is set -if [ "$ORACLE_HOME" == "" ]; then - echo "ERROR: ORACLE_HOME has not been set!" - echo "You have to have the ORACLE_HOME environment variable set to a valid value!" - exit 1; -fi; - - -# Replace place holders -# --------------------- - -sed -i -e "s|###INVENTORY###|$INVENTORY|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ -sed -i -e "s|###ORACLE_BASE###|$GSM_BASE|g" $INSTALL_SCRIPTS/$INSTALL_RSP && \ -sed -i -e "s|###ORACLE_HOME###|$GSM_HOME|g" $INSTALL_SCRIPTS/$INSTALL_RSP - -# Install Oracle binaries -cd $INSTALL_SCRIPTS && \ -unzip $INSTALL_FILE_1 && \ -rm $INSTALL_FILE_1 && \ -$INSTALL_SCRIPTS/gsm/runInstaller -silent -force -waitforcompletion -responsefile $INSTALL_SCRIPTS/$INSTALL_RSP -ignorePrereqFailure || true && \ -rm -rf gsm && \ -cd $HOME diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/runOracle.sh b/container-based-sharding-deployment/containerfiles/23.4.0/runOracle.sh deleted file mode 100644 index 473de50..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/runOracle.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: Build script for building RAC container image -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -#This is the main file which calls other file to setup the sharding. -if [ -z ${BASE_DIR} ]; then - BASE_DIR=$INSTALL_DIR/sharding/scripts -fi - -if [ -z ${MAIN_SCRIPT} ]; then - SCRIPT_NAME="main.py" -fi - -if [ -z ${EXECUTOR} ]; then - EXECUTOR="python3" -fi - -cd $BASE_DIR -$EXECUTOR $SCRIPT_NAME - -# Tail on alert log and wait (otherwise container will exit) - -if [ -z ${DEV_MODE} ]; then - echo "The following output is now a tail of the alert.log:" - tail -f $ORACLE_BASE/diag/gsm/*/*/trace/alert*.log & -else - echo "The following output is now a tail of the /etc/passwd for dev mode" - tail -f /etc/passwd & -fi - -childPID=$! -wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/runUserScripts.sh b/container-based-sharding-deployment/containerfiles/23.4.0/runUserScripts.sh deleted file mode 100644 index c1d1c44..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/runUserScripts.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -SCRIPTS_ROOT="$1"; - -# Check whether parameter has been passed on -if [ -z "$SCRIPTS_ROOT" ]; then - echo "$0: No SCRIPTS_ROOT passed on, no scripts will be run"; - exit 1; -fi; - -# Execute custom provided files (only if directory exists and has files in it) -if [ -d "$SCRIPTS_ROOT" ] && [ -n "$(ls -A $SCRIPTS_ROOT)" ]; then - - echo ""; - echo "Executing user defined scripts" - - for f in $SCRIPTS_ROOT/*; do - case "$f" in - *.sh) echo "$0: running $f"; . "$f" ;; - *.sql) echo "$0: running $f"; echo "exit" | $ORACLE_HOME/bin/sqlplus -s "/ as sysdba" @"$f"; echo ;; - *) echo "$0: ignoring $f" ;; - esac - echo ""; - done - - echo "DONE: Executing user defined scripts" - echo ""; - -fi; diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/cmdExec b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/cmdExec deleted file mode 100755 index 0e5ac30..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/cmdExec +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -TIMESTAMP=`date "+%Y-%m-%d"` -LOGFILE="/tmp/sharding_cmd_${TIMESTAMP}.log" - -echo $(date -u) " : " $@ >> $LOGFILE - -cmd=$@ - -$cmd - -if [ $? -eq 0 ]; then - exit 0 -else - exit 127 -fi diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/demoapp.sql b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/demoapp.sql deleted file mode 100755 index 3e96bfc..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/demoapp.sql +++ /dev/null @@ -1,88 +0,0 @@ - connect sys/'&1'@oshard-catalog-0:1521/CATCDB as sysdba - alter session set container=CAT1PDB; - alter session enable shard ddl; - create user app_schema identified by app_schema; - grant connect, resource, alter session to app_schema; - grant execute on dbms_crypto to app_schema; - grant create table, create procedure, create tablespace, create materialized view to app_schema; - grant unlimited tablespace to app_schema; - grant select_catalog_role to app_schema; - grant all privileges to app_schema; - grant gsmadmin_role to app_schema; - grant dba to app_schema; - conn app_schema/'&1'@oshard-catalog-0:1521/CAT1PDB - alter session enable shard ddl; - REM - REM Create a Sharded table for - REM - CREATE SHARDED TABLE Customers - ( - CustId VARCHAR2(60) NOT NULL, - FirstName VARCHAR2(60), - LastName VARCHAR2(60), - Class VARCHAR2(10), - Geo VARCHAR2(8), - CustProfile VARCHAR2(4000), - Passwd RAW(60), - CONSTRAINT pk_customers PRIMARY KEY (CustId), - CONSTRAINT json_customers CHECK (CustProfile IS JSON) - ) TABLESPACE SET TSP_SET_1 - PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO; - REM - REM Create a Sharded table for Orders - REM - CREATE SHARDED TABLE Orders - ( - OrderId INTEGER NOT NULL, - CustId VARCHAR2(60) NOT NULL, - OrderDate TIMESTAMP NOT NULL, - SumTotal NUMBER(19,4), - Status CHAR(4), - constraint pk_orders primary key (CustId, OrderId), - constraint fk_orders_parent foreign key (CustId) - references Customers on delete cascade - ) partition by reference (fk_orders_parent); - REM - REM Create the sequence used for the OrderId column - REM - CREATE SEQUENCE Orders_Seq; - REM - REM Create a Sharded table for LineItems - REM - CREATE SHARDED TABLE LineItems - ( - OrderId INTEGER NOT NULL, - CustId VARCHAR2(60) NOT NULL, - ProductId INTEGER NOT NULL, - Price NUMBER(19,4), - Qty NUMBER, - constraint pk_items primary key (CustId, OrderId, ProductId), - constraint fk_items_parent foreign key (CustId, OrderId) - references Orders on delete cascade - ) partition by reference (fk_items_parent); - REM - REM - CREATE DUPLICATED TABLE Products - ( - ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, - Name VARCHAR2(128), - DescrUri VARCHAR2(128), - LastPrice NUMBER(19,4) - ) TABLESPACE products_tsp; - CREATE OR REPLACE FUNCTION PasswCreate(PASSW IN RAW) - RETURN RAW - IS - Salt RAW(8); - BEGIN - Salt := DBMS_CRYPTO.RANDOMBYTES(8); - RETURN UTL_RAW.CONCAT(Salt, DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(Salt,PASSW), DBMS_CRYPTO.HASH_SH256)); - END; - / - CREATE OR REPLACE FUNCTION PasswCheck(PASSW IN RAW, PHASH IN RAW) - RETURN INTEGER IS - BEGIN - RETURN UTL_RAW.COMPARE(DBMS_CRYPTO.HASH(UTL_RAW.CONCAT(UTL_RAW.SUBSTR(PHASH, 1, 8), PASSW), DBMS_CRYPTO.HASH_SH256),UTL_RAW.SUBSTR(PHASH, 9)); - END; - / - REM - REM diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/main.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/main.py deleted file mode 100755 index b7f0f17..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/main.py +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -""" -This is the main file which calls other file to setup the sharding. -""" - -from oralogger import * -from orafactory import * -from oraenv import * -from oracommon import * - - -def main(): - - # Checking Comand line Args - try: - opts, args = getopt.getopt(sys.argv[1:], '', ['addshard=','deleteshard=','validateshard=','checkliveness=','resetlistener=','restartdb=','createdir=','optype=','addshardgroup=','deployshard=','movechunks=','checkonlineshard=','cancelchunks=','checkchunks=','checkgsmshard=','checkreadyness=','validatenochunks=','invitednode=','resetpassword=','exporttdekey=','importtdekey=','help']) - except getopt.GetoptError: - pass - - # Initializing oraenv instance - oenv=OraEnv() - file_name = os.path.basename(__file__) - funcname = sys._getframe(1).f_code.co_name - - log_file_name = oenv.logfile_name("NONE") - - # Initialiing logger instance - oralogger = OraLogger(log_file_name) - console_handler = CHandler() - file_handler = FHandler() - stdout_handler = StdHandler() - # Setting next log handlers - stdout_handler.nextHandler = file_handler - file_handler.nextHandler = console_handler - console_handler.nextHandler = PassHandler() - - ocommon = OraCommon(oralogger,stdout_handler,oenv) - - for opt, arg in opts: - if opt in ('--help'): - oralogger.msg_ = '''{:^17}-{:^17} : You can pass parameter --addshard, --deleteshard, --validateshard, --checkliveness, --resetlistener, --restartdb, --createdir, --optype, --addshardgroup, --deployshard, '--checkonlineshard', '--cancelchunks', '--movechunks', '--checkchunks', '--checkgsmshard','--validatenochunks', '--checkreadyness','--invitednode', '--resetpassword','--exporttdekey','--importtdekey',or --help''' - stdout_handler.handle(oralogger) - elif opt in ('--addshard'): - file_name = oenv.logfile_name("ADD_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("ADD_SHARD",arg) - elif opt in ('--validateshard'): - file_name = oenv.logfile_name("VALIDATE_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("VALIDATE_SHARD",arg) - elif opt in ('--deleteshard'): - file_name = oenv.logfile_name("REMOVE_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("REMOVE_SHARD",arg) - elif opt in ('--checkliveness'): - oralogger.stdout_ = None - file_name = oenv.logfile_name("CHECK_LIVENESS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CHECK_LIVENESS",arg) - elif opt in ('--checkreadyness'): - oralogger.stdout_ = None - file_name = oenv.logfile_name("CHECK_READYNESS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CHECK_READYNESS",arg) - elif opt in ('--resetlistener'): - file_name = oenv.logfile_name("RESET_LISTENER") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("RESET_LISTENER",arg) - elif opt in ('--restartdb'): - file_name = oenv.logfile_name("RESTART_DB") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("RESTART_DB",arg) - elif opt in ('--createdir'): - file_name = oenv.logfile_name("CREATE_DIR") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CREATE_DIR",arg) - elif opt in ('--addshardgroup'): - file_name = oenv.logfile_name("ADD_SGROUP_PARAMS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("ADD_SGROUP_PARAMS",arg) - elif opt in ('--deployshard'): - file_name = oenv.logfile_name("DEPLOY_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("DEPLOY_SHARD",arg) - elif opt in ('--cancelchunks'): - file_name = oenv.logfile_name("CANCEL_CHUNKS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CANCEL_CHUNKS",arg) - elif opt in ('--movechunks'): - file_name = oenv.logfile_name("MOVE_CHUNKS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("MOVE_CHUNKS",arg) - elif opt in ('--checkchunks'): - file_name = oenv.logfile_name("CHECK_CHUNKS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CHECK_CHUNKS",arg) - elif opt in ('--validatenochunks'): - file_name = oenv.logfile_name("VALIDATE_NOCHUNKS") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("VALIDATE_NOCHUNKS",arg) - elif opt in ('--checkonlineshard'): - file_name = oenv.logfile_name("CHECK_ONLINE_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CHECK_ONLINE_SHARD",arg) - elif opt in ('--checkgsmshard'): - file_name = oenv.logfile_name("CHECK_GSM_SHARD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("CHECK_GSM_SHARD",arg) - elif opt in ('--invitednode'): - file_name = oenv.logfile_name("INVITED_NODE_OP") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("INVITED_NODE_OP",arg) - elif opt in ('--resetpassword'): - file_name = oenv.logfile_name("RESET_PASSWD") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("RESET_PASSWORD",arg) - elif opt in ('--exporttdekey'): - file_name = oenv.logfile_name("EXPORT_TDE_KEY") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("EXPORT_TDE_KEY",arg) - elif opt in ('--importtdekey'): - file_name = oenv.logfile_name("IMPORT_TDE_KEY") - oralogger.filename_ = file_name - ocommon.log_info_message("=======================================================================",file_name) - oenv.add_custom_variable("IMPORT_TDE_KEY",arg) - elif opt in ('--optype'): - oenv.add_custom_variable("OP_TYPE",arg) - else: - pass - - # Initializing orafactory instances - oralogger.msg_ = '''{:^17}-{:^17} : Calling OraFactory to start the setup'''.format(file_name,funcname) - stdout_handler.handle(oralogger) - orafactory = OraFactory(oralogger,stdout_handler,oenv,ocommon) - - # Get the ora objects - ofactory=orafactory.get_ora_objs() - - # Traverse through returned factory objects and execute the setup function - for obj in ofactory: - obj.setup() - -# Using the special variable -if __name__=="__main__": - main() diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oracommon.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oracommon.py deleted file mode 100755 index 42a319b..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oracommon.py +++ /dev/null @@ -1,966 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -from oralogger import * -from oraenv import * -import subprocess -import sys -import time -import datetime -import os -import getopt -import shlex -import json -import logging -import socket -import re -import os.path -import socket -import string -import random - -class OraCommon: - def __init__(self,oralogger,orahandler,oraenv): - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - - def run_sqlplus(self,cmd,sql_cmd,dbenv): - """ - This function execute the ran sqlplus or rman script and return the output - """ - try: - message="Received Command : {0}\n{1}".format(self.mask_str(cmd),self.mask_str(sql_cmd)) - self.log_info_message(message,self.file_name) - sql_cmd=self.unmask_str(sql_cmd) - cmd=self.unmask_str(cmd) -# message="Received Command : {0}\n{1}".format(cmd,sql_cmd) -# self.log_info_message(message,self.file_name) - p = subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,env=dbenv,shell=True,universal_newlines=True) - p.stdin.write(sql_cmd) - # (stdout,stderr), retcode = p.communicate(sqlplus_script.encode('utf-8')), p.returncode - (stdout,stderr),retcode = p.communicate(),p.returncode - # stdout_lines = stdout.decode('utf-8').split("\n") - except: - error_msg=sys.exc_info() - self.log_error_message(error_msg,self.file_name) - self.prog_exit(self) - - return stdout.replace("\n\n", "\n"),stderr,retcode - - def execute_cmd(self,cmd,env,dir): - """ - Execute the OS command on host - """ - try: - message="Received Command : {0}".format(self.mask_str(cmd)) - self.log_info_message(message,self.file_name) - cmd=self.unmask_str(cmd) - out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,universal_newlines=True) - (output,error),retcode = out.communicate(),out.returncode - except: - error_msg=sys.exc_info() - self.log_error_message(error_msg,self.file_name) - self.prog_exit(self) - - return output,error,retcode - - def mask_str(self,mstr): - """ - Function to mask the string. - """ - newstr=None - if self.oenv.encrypt_str__: - newstr=mstr.replace('HIDDEN_STRING','********') - # self.log_info_message(newstr,self.file_name) - if newstr: - # message = "Masked the string as encryption flag is set in the singleton class" - # self.log_info_message(message,self.file_name) - return newstr - else: - return mstr - - - def unmask_str(self,mstr): - """ - Function to unmask the string. - """ - newstr=None - if self.oenv.encrypt_str__: - newstr=mstr.replace('HIDDEN_STRING',self.oenv.original_str__.rstrip()) - # self.log_info_message(newstr,self.file_name) - if newstr: - # message = "Unmasked the encrypted string and returning original string from singleton class" - # self.log_info_message(message,self.file_name) - return newstr - else: - return mstr - - def set_mask_str(self,mstr): - """ - Function to unmask the string. - """ - if mstr: - # message = "Setting encrypted String flag to True and original string in singleton class" - # self.log_info_message(message,self.file_name) - self.oenv.encrypt_str__ = True - self.oenv.original_str__ = mstr - else: - message = "Masked String is empty so no change required in encrypted String Flag and original string in singleton class" - self.log_info_message(message,self.file_name) - - def unset_mask_str(self): - """ - Function to unmask the string. - """ - # message = "Un-setting encrypted String flag and original string to None in Singleton class" - # self.log_info_message(message,self.file_name) - self.oenv.encrypt_str__ = None - self.oenv.original_str__ = None - - def prog_exit(self,message): - """ - This function exit the program because of some error - """ - sys.exit(127) - - def log_info_message(self,lmessage,fname): - """ - Print the INFO message in the logger - """ - funcname = sys._getframe(1).f_code.co_name - message = '''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) - self.ologger.msg_ = message - self.ologger.logtype_ = "INFO" - self.ohandler.handle(self.ologger) - - def log_error_message(self,lmessage,fname): - """ - Print the Error message in the logger - """ - funcname=sys._getframe(1).f_code.co_name - message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) - self.ologger.msg_=message - self.ologger.logtype_="ERROR" - self.ohandler.handle(self.ologger) - - def log_warn_message(self,lmessage,fname): - """ - Print the Error message in the logger - """ - funcname=sys._getframe(1).f_code.co_name - message='''{:^15}-{:^20}:{}'''.format(fname,funcname,lmessage) - self.ologger.msg_=message - self.ologger.logtype_="WARN" - self.ohandler.handle(self.ologger) - - def check_sql_err(self,output,err,retcode,status): - """ - Check if there are any error in sql command output - """ - match=None - msg2='''Sql command failed.Flag is set not to ignore this error.Please Check the logs,Exiting the Program!''' - msg3='''Sql command failed.Flag is set to ignore this error!''' - self.log_info_message("output : " + str(output or "no Output"),self.file_name) - # self.log_info_message("Error : " + str(err or "no Error"),self.file_name) - # self.log_info_message("Sqlplus return code : " + str(retcode),self.file_name) - # self.log_info_message("Command Check Status Set to :" + str(status),self.file_name) - - if status: - if (retcode!=0): - self.log_info_message("Error : " + str(err or "no Error"),self.file_name) - self.log_error_message("Sql Login Failed.Please Check the logs,Exiting the Program!",self.file_name) - self.prog_exit(self) - - match=re.search("(?i)(?m)error",output) - if status: - if (match): - self.log_error_message(msg2,self.file_name) - self.prog_exit("error") - else: - self.log_info_message("Sql command completed successfully",self.file_name) - else: - if (match): - self.log_warn_message("Sql command failed. Flag is set to ignore the error.",self.file_name) - else: - self.log_info_message("Sql command completed sucessfully.",self.file_name) - - def check_os_err(self,output,err,retcode,status): - """ - Check if there are any error in OS command execution - """ - msg1='''OS command returned code : {0} and returned output : {1}'''.format(str(retcode),str(output or "no Output")) - msg2='''OS command returned code : {0}, returned error : {1} and returned output : {2}'''.format(str(retcode),str(err or "no returned error"),str(output or "no retruned output")) - msg3='''OS command failed. Flag is set to ignore this error!''' - - if status: - if (retcode != 0): - self.log_error_message(msg2,self.file_name) - self.prog_exit(self) - else: - self.log_info_message(msg1,self.file_name) - else: - if (retcode != 0): - self.log_warn_message(msg2,self.file_name) - self.log_warn_message(msg3,self.file_name) - else: - self.log_info_message(msg1,self.file_name) - - def check_key(self,key,env_dict): - """ - Check the key if it exist in dictionary. - Attributes: - key (string): String to check if key exist in dictionary - env_dict (dict): Contains the env variable related to seup - """ - if key in env_dict: - return True - else: - return False - - def empty_key(self,key): - """ - key is empty and print failure message. - Attributes: - key (string): String is empty - """ - msg='''Variable {0} is not defilned. Exiting!'''.format(key) - self.log_error_message(msg,self.file_name) - self.prog_exit(self) - - def add_key(self,key,value,env_dict): - """ - Add the key in the dictionary. - Attributes: - key (string): key String to add in the dictionary - value (String): value String to add in dictionary - - Return: - dict - """ - if self.check_key(key,env_dict): - msg='''Variable {0} already exist in the env variables'''.format(key) - self.log_info_message(msg,self.file_name) - else: - if value: - env_dict[key] = value - self.oenv.update_env_vars(env_dict) - else: - msg='''Variable {0} value is not defilned to add in the env variables. Exiting!'''.format(value) - self.log_error_message(msg,self.file_name) - self.prog_exit(self) - - return env_dict - - def update_key(self,key,value,env_dict): - """ - update the key in the dictionary. - Attributes: - key (string): key String to update in the dictionary - value (String): value String to update in dictionary - - Return: - dict - """ - if self.check_key(key,env_dict): - if value: - env_dict[key] = value - self.oenv.update_env_vars(env_dict) - else: - msg='''Variable {0} value is not defilned to update in the env variables!'''.format(key) - self.log_warn_message(msg,self.file_name) - else: - msg='''Variable {0} already exist in the env variables'''.format(key) - self.log_info_message(msg,self.file_name) - - return env_dict - - def check_file(self,file,local,remote,user): - """ - check locally or remotely - Attributes: - file (string): file to be created - local (boolean): dir to craetes locally - remote (boolean): dir to be created remotely - node (string): remote node name on which dir to be created - user (string): remote user to be connected - """ - self.log_info_message("Inside check_file()",self.file_name) - if local: - if os.path.isfile(file): - return True - else: - return False - - - def read_file(self,fname): - """ - Read the contents of a file and returns the contents to end user - Attributes: - fname (string): file to be read - - Return: - file data (string) - """ - f1 = open(fname, 'r') - fdata = f1.read() - f1.close - return fdata - - def write_file(self,fname,fdata): - """ - write the contents to a file - Attributes: - fname (string): file to be written - fdata (string): COnetents to be written - - Return: - file data (string) - """ - f1 = open(fname, 'w') - f1.write(fdata) - f1.close - - def append_file(self,fname,fdata): - """ - append the contents to a file - Attributes: - fname (string): file to be appended - fdata (string): COnetents to be appended - - Return: - file data (string) - """ - f1 = open(fname, 'a') - f1.write(fdata) - f1.close - - def create_dir(self,dir,local,remote,user): - """ - Create dir locally or remotely - Attributes: - dir (string): dir to be created - local (boolean): dir to craetes locally - remote (boolean): dir to be created remotely - node (string): remote node name on which dir to be created - user (string): remote user to be connected - """ - self.log_info_message("Inside create_dir()",self.file_name) - if local: - if not os.path.isdir(dir): - cmd='''mkdir -p {0}'''.format(dir) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - else: - msg='''Dir {0} already exist'''.format(dir) - self.log_info_message(msg,self.file_name) - - if remote: - pass - - def create_file(self,file,local,remote,user): - """ - Create dir locally or remotely - Attributes: - file (string): file to be created - local (boolean): dir to craetes locally - remote (boolean): dir to be created remotely - node (string): remote node name on which dir to be created - user (string): remote user to be connected - """ - self.log_info_message("Inside create_file()",self.file_name) - if local: - if not os.path.isfile(file): - cmd='''touch {0}'''.format(file) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - - if remote: - pass - - def shutdown_db(self,env_dict): - """ - Shutdown the database - """ - file="/home/oracle/shutDown.sh" - if not os.path.isfile(file): - self.log_info_message("Inside shutdown_db()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) - sqlcmd=''' - shutdown immediate; - ''' - self.log_info_message("Running the sqlplus command to shutdown the database: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - else: - cmd='''sh {0} immediate'''.format(file) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - - def mount_db(self,env_dict): - """ - Mount the database - """ - self.log_info_message("Inside mount_db()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) - sqlcmd=''' - startup mount; - ''' - self.log_info_message("Running the sqlplus command to mount the database: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - - def start_db(self,env_dict): - """ - startup the database - """ - file="/home/oracle/startUp.sh" - if not os.path.isfile(file): - self.log_info_message("Inside start_db()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) - sqlcmd=''' - startup; - ''' - self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - else: - cmd='''sh {0}'''.format(file) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - - def nomount_db(self,env_dict): - """ - No mount the database - """ - self.log_info_message("Inside start_db()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(env_dict["ORACLE_HOME"]) - sqlcmd=''' - startup nomount; - ''' - self.log_info_message("Running the sqlplus command to start the database: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - - def stop_gsm(self,env_dict): - """ - Stop the GSM - """ - self.log_info_message("Inside stop_gsm()",self.file_name) - gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) - gsmcmd=''' - stop gsm; - ''' - output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) - self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) - self.check_sql_err(output,error,retcode,None) - - def set_events(self,source): - """ - Seting events at DB level - """ - scope='' - accepted_scope = ['spfile', 'memory', 'both'] - - if self.check_key("DB_EVENTS",self.ora_env_dict): - events=str(self.ora_env_dict["DB_EVENTS"]).split(";") - - for event in events: - msg='''Setting up event {0}'''.format(event) - self.log_info_message(msg,self.file_name) - scope='' - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - source=event.split(":") - if len(source) > 1: - if source[1].split("=")[0] == "scope": - scope=source[1].split("=")[1] - - if scope not in accepted_scope: - sqlcmd=""" - alter system set events='{0}';""".format(source[0]) - else: - sqlcmd=""" - alter system set event='{0}' scope={1};""".format(source[0],scope) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - - def start_gsm(self,env_dict): - """ - Start the GSM - """ - self.log_info_message("Inside start_gsm()",self.file_name) - gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) - gsmcmd=''' - start gsm; - ''' - output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) - self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) - self.check_sql_err(output,error,retcode,None) - - def exec_gsm_cmd(self,gsmcmd,flag,env_dict): - """ - Get the GSM command output - """ - self.log_info_message("Inside exec_gsm_cmd()",self.file_name) - gsmctl='''{0}/bin/gdsctl'''.format(env_dict["ORACLE_HOME"]) - if gsmcmd: - output,error,retcode=self.run_sqlplus(gsmctl,gsmcmd,None) - self.log_info_message("Calling check_sql_err() to validate the gsm command return status",self.file_name) - self.check_sql_err(output,error,retcode,flag) - else: - self.log_info_message("GSM Command was set to empty. Executing nothing and setting output to None",self.file_name) - output=None - - return output,error,retcode - - - def check_substr_match(self,source_str,sub_str): - """ - CHeck if substring exist - """ - self.log_info_message("Inside check_substr_match()",self.file_name) - if (source_str.find(sub_str) != -1): - return True - else: - return False - - def find_str_in_string(self,source_str,delimeter,search_str): - """AI is creating summary for find_str_in_string - - Args: - source_str ([string]): [string where you need to search] - delimeter ([character]): [string delimeter] - search_str ([string]): [string to be searched] - """ - if delimeter == 'comma': - new_str=source_str.split(',') - for str in new_str: - if str.lower() == search_str.lower(): - return True - return False - - return False - - def check_status_value(self,match): - """ - return completed or notcompleted - """ - self.log_info_message("Inside check_status_value()",self.file_name) - if match: - return 'completed' - else: - return 'notcompleted' - - def remove_file(self,fname): - """ - Remove if file exist - """ - self.log_info_message("Inside remove_file()",self.file_name) - if os.path.exists(fname): - os.remove(fname) - - def get_sid_desc(self,gdbname,ohome,sid,sflag): - """ - get the SID_LISTENER_DESCRIPTION - """ - self.log_info_message("Inside get_sid_desc()",self.file_name) - sid_desc = "" - if sflag == 'SID_DESC1': - sid_desc = ''' ) - (SID_DESC = - (GLOBAL_DBNAME = {0}) - (ORACLE_HOME = {1}) - (SID_NAME = {2}) - ) - ) - '''.format(gdbname,ohome,sid) - elif sflag == 'SID_DESC': - sid_desc = '''(SID_LIST = - (SID_DESC = - (GLOBAL_DBNAME = {0}) - (ORACLE_HOME = {1}) - (SID_NAME = {2}) - ) - ) - '''.format(gdbname,ohome,sid) - else: - pass - - return sid_desc - - def get_lisora(self,port): - """ - return listener.ora listener settings - """ - self.log_info_message("Inside get_lisora()",self.file_name) - listener='''LISTENER = - (DESCRIPTION_LIST = - (DESCRIPTION = - (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = {0})) - (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC{0})) - ) - ) - '''.format(port) - return listener - - def get_domain(self,ohost): - """ - get the domain name from hostname - """ - return ohost.partition('.')[2] - -######### Get the DOMAIN############## - def get_host_domain(self): - """ - Return Public Hostname - """ - domain=None - domain=socket.getfqdn().split('.',1)[1] - if domain is None: - domain="example.info" - - return domain - - ######### get the public IP ############## - def get_ip(self,hostname,domain): - """ - Return the Ip based on hostname - """ - if not domain: - domain=self.get_host_domain() - - return socket.gethostbyname(hostname) - - def get_global_dbdomain(self,ohost,gdbname): - """ - get the global dbname - """ - domain = self.get_domain(ohost) - if domain: - global_dbname = gdbname + domain - else: - global_dbname = gdbname - - return gdbname - -######### Sqlplus connect string ########### - def get_sqlplus_str(self,home,osid,dbuser,password,hostname,port,svc,osep,role,wallet): - """ - return the sqlplus connect string - """ - path='''/usr/bin:/bin:/sbin:/usr/local/sbin:{0}/bin'''.format(home) - ldpath='''{0}/lib:/lib:/usr/lib'''.format(home) - export_cmd='''export ORACLE_HOME={0};export PATH={1};export LD_LIBRARY_PATH={2};export ORACLE_SID={3}'''.format(home,path,ldpath,osid) - if dbuser == 'sys' and password and hostname and port and svc: - return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4} as sysdba'''.format(dbuser,password,hostname,port,svc,export_cmd,home) - elif dbuser != 'sys' and password and hostname and svc: - return '''{5};{6}/bin/sqlplus {0}/{1}@//{2}:{3}/{4}'''.format(dbuser,password,hostname,"1521",svc,export_cmd,home) - elif dbuser and osep: - return dbuser - elif dbuser == 'sys' and not password: - return '''{1};{0}/bin/sqlplus "/ as sysdba"'''.format(home,export_cmd) - elif dbuser == 'sys' and password: - return '''{1};{0}/bin/sqlplus {2}/{3} as sysdba'''.format(home,export_cmd,dbuser,password) - elif dbuser != 'sys' and password: - return '''{1};{0}/bin/sqlplus {2}/{3}'''.format(home,export_cmd,dbuser,password) - else: - self.log_info_message("Atleast specify db user and password for db connectivity. Exiting...",self.file_name) - self.prog_exit("127") - -######### Get Password ############## - def get_os_password(self): - """ - get the OS password - """ - ospasswd=self.get_password(None) - return ospasswd - - def get_asm_passwd(self): - """ - get the ASM password - """ - asmpasswd=self.get_password(None) - return asmpasswd - - def get_db_passwd(self): - """ - get the DB password - """ - dbpasswd=self.get_password(None) - return dbpasswd - - def get_sys_passwd(self): - """ - get the sys user password - """ - dbpasswd=self.get_password(None) - return dbpasswd - - def get_password(self,key): - """ - get the password - """ - passwd_file_flag=False - password=None - password_file=None - if self.check_key("SECRET_VOLUME",self.ora_env_dict): - self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["SECRET_VOLUME"]) - msg='''SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) - else: - self.ora_env_dict=self.add_key("SECRET_VOLUME","/run/secrets",self.ora_env_dict) - msg='''SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["SECRET_VOLUME"]) - self.log_warn_message(msg,self.file_name) - - if self.check_key("KEY_SECRET_VOLUME",self.ora_env_dict): - self.log_info_message("Secret_Volume set to : ",self.ora_env_dict["KEY_SECRET_VOLUME"]) - msg='''KEY_SECRET_VOLUME passed as an env variable and set to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) - else: - if self.check_key("SECRET_VOLUME",self.ora_env_dict): - self.ora_env_dict=self.add_key("KEY_SECRET_VOLUME",self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict) - msg='''KEY_SECRET_VOLUME not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) - self.log_warn_message(msg,self.file_name) - - if self.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict): - msg='''COMMON_OS_PWD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) - else: - self.ora_env_dict=self.add_key("COMMON_OS_PWD_FILE","common_os_pwdfile.enc",self.ora_env_dict) - msg='''COMMON_OS_PWD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["COMMON_OS_PWD_FILE"]) - self.log_warn_message(msg,self.file_name) - - if self.check_key("PWD_KEY",self.ora_env_dict): - msg='''PWD_KEY passed as an env variable and set to {0}'''.format(self.ora_env_dict["PWD_KEY"]) - else: - self.ora_env_dict=self.add_key("PWD_KEY","pwd.key",self.ora_env_dict) - msg='''PWD_KEY not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PWD_KEY"]) - self.log_warn_message(msg,self.file_name) - - if self.check_key("PASSWORD_FILE",self.ora_env_dict): - msg='''PASSWORD_FILE passed as an env variable and set to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) - else: - self.ora_env_dict=self.add_key("PASSWORD_FILE","dbpasswd.file",self.ora_env_dict) - msg='''PASSWORD_FILE not passed as an env variable. Setting default to {0}'''.format(self.ora_env_dict["PASSWORD_FILE"]) - self.log_warn_message(msg,self.file_name) - - secret_volume = self.ora_env_dict["SECRET_VOLUME"] - key_secret_volume= self.ora_env_dict["KEY_SECRET_VOLUME"] - common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"] - pwd_volume=None - if self.check_key("PWD_VOLUME",self.ora_env_dict): - pwd_volume=self.ora_env_dict["PWD_VOLUME"] - else: - pwd_volume="/var/tmp" - pwd_key = self.ora_env_dict["PWD_KEY"] - passwd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) - dbpasswd_file='''{0}/{1}'''.format(secret_volume,self.ora_env_dict["PASSWORD_FILE"]) - key_file='''{0}/{1}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"],self.ora_env_dict["PWD_KEY"]) - key_secret_volume='''{0}'''.format(self.ora_env_dict["KEY_SECRET_VOLUME"]) - self.log_info_message("Password file set to : " + passwd_file,self.file_name) - self.log_info_message("key file set to : " + key_file,self.file_name) - self.log_info_message("dbpasswd file set to : " + dbpasswd_file,self.file_name) - self.log_info_message("key secret voluem set to file set to : " + key_secret_volume,self.file_name) - self.log_info_message("pwd volume set : " + pwd_volume,self.file_name) - #print(passwd_file) - if (os.path.isfile(passwd_file)) and (os.path.isfile(key_file)): - msg='''Passwd file {0} and key file {1} exist. Password file Check passed!'''.format(passwd_file,key_file) - self.log_info_message(msg,self.file_name) - msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file) - self.log_info_message(msg,self.file_name) - cmd=None - if self.check_key("ENCRYPTION_TYPE",self.ora_env_dict): - if self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "aes256": - cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out {2}/{1} -pass file:\"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) - elif self.ora_env_dict["ENCRYPTION_TYPE"].lower() == "rsautl": - cmd ='''openssl rsautl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) - else: - pass - else: - cmd ='''openssl pkeyutl -decrypt -in \"{0}/{1}\" -out {2}/{1} -inkey \"{3}/{4}\"'''.format(secret_volume,common_os_pwd_file,pwd_volume,key_secret_volume,pwd_key) - - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - passwd_file_flag = True - password_file='''{0}/{1}'''.format(pwd_volume,self.ora_env_dict["COMMON_OS_PWD_FILE"]) - elif os.path.isfile(dbpasswd_file): - msg='''Passwd file {0} exist. Password file Check passed!'''.format(dbpasswd_file) - self.log_info_message(msg,self.file_name) - msg='''Reading encrypted passwd from file {0}.'''.format(dbpasswd_file) - self.log_info_message(msg,self.file_name) - cmd='''openssl base64 -d -in \"{0}\" -out \"{2}/{1}\"'''.format(dbpasswd_file,self.ora_env_dict["PASSWORD_FILE"],pwd_volume) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - passwd_file_flag = True - password_file='''{1}/{0}'''.format(self.ora_env_dict["PASSWORD_FILE"],pwd_volume) - - if not passwd_file_flag: - # get random password pf length 8 with letters, digits, and symbols - characters1 = string.ascii_letters + string.digits + "_-%#" - str1 = ''.join(random.choice(string.ascii_uppercase) for i in range(4)) - str2 = ''.join(random.choice(characters1) for i in range(8)) - password=str1+str2 - else: - fname='''{0}'''.format(password_file) - fdata=self.read_file(fname) - password=fdata - self.remove_file(fname) - - if self.check_key("ORACLE_PWD",self.ora_env_dict): - if len(self.ora_env_dict["ORACLE_PWD"]) > 0: - msg="ORACLE_PWD is passed as an env variable. Check Passed!" - self.log_info_message(msg,self.file_name) - else: - msg="ORACLE_PWD passed as 0 length string" - self.log_info_message(msg,self.file_name) - self.ora_env_dict=self.update_key("ORACLE_PWD",password,self.ora_env_dict) - msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file" - self.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.add_key("ORACLE_PWD",password,self.ora_env_dict) - msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file" - self.log_info_message(msg,self.file_name) - -######### Get oraversion ############## - def get_oraversion(self,home): - """ - get the software version - """ - cmd='''{0}/bin/oraversion -majorVersion'''.format(home) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - - return output - -####### Get db lock file location ####### - def get_db_lock_location(self): - """ - get the db location - """ - if self.check_key("DB_LOCK_FILE_LOCATION",self.ora_env_dict): - return self.ora_env_dict["DB_LOCK_FILE_LOCATION"] - else: - ### Please note that you should not change following path as SIDB team is maintaining lock files under following location - return "/tmp/." - -####### Get the TDE Key ############### - def export_tde_key(self,filename): - """ - This function export the tde. - """ - self.log_info_message("Inside gettdekey()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - sqlcmd=''' - ALTER SESSION DISABLE SHARD DDL; - ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET {0} TO {1} IDENTIFIED BY {0}; - '''.format('HIDDEN_STRING',filename) - self.log_info_message("Running the sqlplus command to export the tde: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - -####### Get the TDE Key ############### - def import_tde_key(self,filename): - """ - This function import the TDE key. - """ - self.log_info_message("Inside importtdekey()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - sqlcmd=''' - ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY {0}; - ADMINISTER KEY MANAGEMENT IMPORT ENCRYPTION KEYS WITH SECRET {0} FROM {1} IDENTIFIED BY {0} WITH BACKUP - '''.format('HIDDEN_STRING',filename) - self.log_info_message("Running the sqlplus command to import the tde key: " + sqlcmd,self.file_name) - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,True) - -####### Check PDB if it exist ############### - def check_pdb(self,pdbname): - """ - This function check the PDB. - """ - self.log_info_message("Inside check_pdb()",self.file_name) - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - sqlcmd=''' - set heading off - set feedback off - select NAME from gv$pdbs; - ''' - output,error,retcode=self.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.check_sql_err(output,error,retcode,None) - pdblist=output.splitlines() - self.log_info_message("Checking pdb " + pdbname, self.file_name) - if pdbname in pdblist: - return True - else: - return False - -####### Create PDB if it does not exist ############### - def create_pdb(self,ohome,opdb,inst_sid): - """ - This function create the PDB. - """ - self.log_info_message("Inside create_pdb()",self.file_name) - self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - cmd='''{0}/bin/dbca -silent -createPluggableDatabase -pdbName {1} -sourceDB {2} <<< HIDDEN_STRING'''.format(ohome,opdb,inst_sid) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.unset_mask_str() - self.check_os_err(output,error,retcode,True) - - - -####### Create PDB tnsnames.ora entry ############### - def create_pdb_tns_entry(self,ohome,opdb): - """ - This function create the PDB tnsnames.ora entry. - """ - self.log_info_message("Inside create_pdb_tns_entry()",self.file_name) - tns_entry_string=""" -{0} = - (DESCRIPTION = - (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521)) - (CONNECT_DATA = - (SERVER = DEDICATED) - (SERVICE_NAME = {0}) - ) - ) - -""".format(opdb) - - tns_file='''{0}/network/admin/tnsnames.ora'''.format(ohome) - self.append_file(tns_file,tns_entry_string) - -######## Reset the DB Password in database ######## - def reset_passwd(self): - """ - This function reset the password. - """ - password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh") - self.log_info_message("Executing password reset", self.file_name) - if self.check_key("ORACLE_PWD",self.ora_env_dict) and self.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script): - cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING') - self.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - output,error,retcode=self.execute_cmd(cmd,None,None) - self.check_os_err(output,error,retcode,True) - self.unset_mask_str() - else: - msg='''Error Occurred! Either HOME DIR {0} does not exist, ORACLE_PWD {1} is not set or PASSWORD SCRIPT {2} does not exist'''.format(self.ora_env_dict["HOME"],self.ora_env_dict["ORACLE_PWD"],password_script) - self.log_error_message(msg,self.file_name) - self.oracommon.prog_exit() diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oraenv.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oraenv.py deleted file mode 100755 index dd96c48..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oraenv.py +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -""" - This file read the env variables from a file or using env command and populate them in variable -""" - -import os - -class OraEnv: - __instance = None - __env_var_file = '/etc/rac_env_vars' - - __env_var_file_flag = None - __env_var_dict = {} - __ora_asm_diskgroup_name = '+DATA' - __ora_gimr_flag = 'false' - __ora_grid_user = 'grid' - __ora_db_user = 'oracle' - __ora_oinstall_group_name = 'oinstall' - encrypt_str__ = None - original_str__ = None - logdir__ = "/tmp/sharding" - - def __init__(self): - """ Virtually private constructor. """ - if OraEnv.__instance != None: - raise Exception("This class is a singleton!") - else: - OraEnv.__instance = self - OraEnv.read_variable() - OraEnv.add_variable() - try: - os.mkdir(OraEnv.logdir__) - except OSError as error: - pass - - @staticmethod - def get_instance(): - """ Static access method. """ - if OraEnv.__instance == None: - OraEnv() - return OraEnv.__instance - - @staticmethod - def read_variable(): - """ Read the variables from a file into dict """ - if OraEnv.__env_var_file_flag: - with open(OraEnv.__env_var_file) as envfile: - for line in envfile: - name, var = line.partition("=")[::2] - OraEnv.__env_var_dict[name.strip()] = var - else: - OraEnv.__env_var_dict = os.environ - - @staticmethod - def add_variable(): - """ Add more variable ased on enviornment with default values in __env_var_dict""" - OraEnv.__env_var_dict["GSM_LOCK_STATUS_FILE"] = "/tmp/.gsm_status_lock_file" - OraEnv.__env_var_dict["SHARD_LOCK_STATUS_FILE"] = "/tmp/.shard_status_lock_file" - if "ORA_ASM_DISKGROUP_NAME" not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict["ORA_ASM_DISKGROUP_NAME"] = "+DATA" - - if "ORA_GRID_USER" not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict["ORA_GRID_USER"] = "grid" - - if "ORA_DB_USER" not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict["ORA_DB_USER"] = "oracle" - - if "ORA_OINSTALL_GROUP_NAME" not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict["ORA_OINSTALL_GROUP_NAME"] = "oinstall" - - @staticmethod - def add_custom_variable(key,val): - """ Addcustom more variable passed from main.py values in __env_var_dict""" - if key not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict[key] = val - - @staticmethod - def get_env_vars(): - """ Static access method to get the env vars. """ - return OraEnv.__env_var_dict - - @staticmethod - def update_env_vars(env_dict): - """ Static access method to get the env vars. """ - OraEnv.__env_var_dict = env_dict - - @staticmethod - def logfile_name(file_type): - """ Static access method to return the logfile name. """ - if file_type == "NONE": - if "LOGFILE_NAME" not in OraEnv.__env_var_dict: - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/oracle_sharding_setup.log" - elif file_type == "ADD_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_addition.log" - elif file_type == "VALIDATE_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_validation.log" - elif file_type == "REMOVE_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_remove.log" - elif file_type == "CHECK_LIVENESS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkliveness.log" - elif file_type == "CHECK_READYNESS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/shard_checkreadyness.log" - elif file_type == "RESET_LISTENER": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_listener.log" - elif file_type == "RESTART_DB": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/restart_db.log" - elif file_type == "CREATE_DIR": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/create_dir.log" - elif file_type == "ADD_SGROUP_PARAMS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/add_sgroup.log" - elif file_type == "DEPLOY_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/deploy_shard.log" - elif file_type == "CANCEL_CHUNKS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/cancel_chunk.log" - elif file_type == "MOVE_CHUNKS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/move_chunks.log" - elif file_type == "CHECK_CHUNKS": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_chunks.log" - elif file_type == "CHECK_ONLINE_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_online_shard.log" - elif file_type == "CHECK_GSM_SHARD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/check_gsm_shard.log" - elif file_type == "INVITED_NODE_OP": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/node_invited_op.log" - elif file_type == "RESET_PASSWD": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/reset_passwd_file.log" - elif file_type == "TDE_KEY": - OraEnv.__env_var_dict["LOG_FILE_NAME"] = OraEnv.logdir__ + "/tde_key.log" - else: - pass - - return OraEnv.__env_var_dict["LOG_FILE_NAME"] diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orafactory.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orafactory.py deleted file mode 100755 index 5ddb6e3..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orafactory.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -""" - This file contains to the code call different classes objects based on setup type -""" - -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * -from orapshard import * -from orasshard import * -from orapcatalog import * -from oragsm import * - -import os -import sys - -class OraFactory: - """ - This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This is a class for calling child objects to setup RAC/DG/GRID/DB/Sharding based on OP_TYPE env variable. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - - def get_ora_objs(self): - ''' - Return the instance of a classes which will setup the enviornment. - - Returns: - ofactory_obj: List of objects - ''' - ofactory_obj = [] - - msg='''ora_env_dict set to : {0}'''.format(self.ora_env_dict) - self.ocommon.log_info_message(msg,self.file_name) - - msg="Checking the OP_TYPE and Version to begin the installation" - self.ocommon.log_info_message(msg,self.file_name) - - # Checking the OP_TYPE - if self.ocommon.check_key("OP_TYPE",self.ora_env_dict): - msg='''OP_TYPE variable is set to {0}.'''.format(self.ora_env_dict["OP_TYPE"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("OP_TYPE","nosetup",self.ora_env_dict) - msg="OP_TYPE variable is set to default nosetup. No value passed as an enviornment variable." - self.ocommon.log_info_message(msg,self.file_name) - - # Check the OP_TYPE value and call objects based on it value - if self.ora_env_dict["OP_TYPE"] == 'primaryshard': - msg="Creating and calling instance to setup primary shard" - opshard = OraPShard(self.ologger,self.ohandler,self.oenv,self.ocommon) - self.ocommon.log_info_message(msg,self.file_name) - ofactory_obj.append(opshard) - elif self.ora_env_dict["OP_TYPE"] == 'standbyshard': - msg="Creating and calling instance to setup standby shard" - osshard = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) - self.ocommon.log_info_message(msg,self.file_name) - ofactory_obj.append(osshard) - elif self.ora_env_dict["OP_TYPE"] == 'catalog': - msg="Creating and calling instance to setup Catalog DB" - opcat = OraPCatalog(self.ologger,self.ohandler,self.oenv,self.ocommon) - self.ocommon.log_info_message(msg,self.file_name) - ofactory_obj.append(opcat) - elif self.ora_env_dict["OP_TYPE"] == 'standbycatalog': - msg="Creating and calling instance to setup Catalog DB" - oscat = OraSShard(self.ologger,self.ohandler,self.oenv,self.ocommon) - self.ocommon.log_info_message(msg,self.file_name) - ofactory_obj.append(oscat) - elif self.ora_env_dict["OP_TYPE"] == 'gsm': - msg="Creating and calling instance to setup GSM" - ogsm = OraGSM(self.ologger,self.ohandler,self.oenv,self.ocommon) - self.ocommon.log_info_message(msg,self.file_name) - ofactory_obj.append(ogsm) - else: - msg="OP_TYPE must be set to {primaryshard|standbyshard|catalog|standbycatalog|gsm}" - self.ocommon.log_info_message(msg,self.file_name) - msg="Since OP_TYPE is set to nosetup, only compute env is being setup. Creating and calling instance to setup compute." - self.ocommon.log_info_message(msg,self.file_name) - omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - ofactory_obj.append(omachine) - - return ofactory_obj diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oragsm.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oragsm.py deleted file mode 100755 index ef0bb06..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oragsm.py +++ /dev/null @@ -1,2945 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -import os -import sys -import os.path -import re -import socket -import random -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * - -class OraGSM: - """ - This calss setup the Gsm after DB installation. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This constructor of OraGsm class to setup the Gsm on primary DB. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - - def setup(self): - """ - This function setup the Gsm on Primary DB. - """ - if self.ocommon.check_key("ADD_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.add_gsm_shard() - self.set_hostid_null() - self.add_invited_node("ADD_SHARD") - self.remove_invited_node("ADD_SHARD") - sys.exit(0) - if self.ocommon.check_key("DEPLOY_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.deploy_shard() - self.setup_gsm_service() - sys.exit(0) - elif self.ocommon.check_key("ADD_SGROUP_PARAMS",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.setup_gsm_shardg("ADD_SGROUP_PARAMS") - sys.exit(0) - elif self.ocommon.check_key("ADD_SSPACE_PARAMS",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.setup_gsm_sspace("ADD_SSPACE_PARAMS") - sys.exit(0) - elif self.ocommon.check_key("REMOVE_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - status=self.remove_gsm_shard() - - if status: - sys.exit(0) - else: - sys.exit(1) - - elif self.ocommon.check_key("MOVE_CHUNKS",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.move_shard_chunks() - sys.exit(0) - elif self.ocommon.check_key("TDE_KEY",self.ora_env_dict): - self.ocommon.get_tde_key() - sys.exit(0) - elif self.ocommon.check_key("CANCEL_CHUNKS",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.cancel_move_chunks() - sys.exit(0) - elif self.ocommon.check_key("VALIDATE_NOCHUNKS",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.validate_nochunks() - sys.exit(0) - elif self.ocommon.check_key("CHECK_ONLINE_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.verify_online_shard() - sys.exit(0) - elif self.ocommon.check_key("CHECK_GSM_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.verify_gsm_shard() - sys.exit(0) - elif self.ocommon.check_key("VALIDATE_SHARD",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.validate_gsm_shard() - sys.exit(0) - elif self.ocommon.check_key("VALIDATE_GSM",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - sys.exit(0) - elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): - filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] - if os.path.exists(filename): - self.ocommon.log_info_message("provisioning is still in progress as file " + filename + " still exist!",self.file_name) - sys.exit(0) - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - status = self.check_gsm_director_status(None) - if not status: - self.ocommon.log_info_message("No GDS setup found on this system.",self.file_name) - self.ocommon.prog_exit("127") - self.ocommon.log_info_message("GSM liveness check completed sucessfully!",self.file_name) - sys.exit(0) - elif self.ocommon.check_key("INVITED_NODE_OP",self.ora_env_dict): - self.catalog_checks() - status = self.catalog_setup_checks() - if not status: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.ocommon.prog_exit("127") - else: - self.invited_node_op() - sys.exit(0) - elif self.ocommon.check_key("CATALOG_SETUP",self.ora_env_dict): - # If user pass env avariable CATALOG_SETUP true then it will just create gsm director and add catalog but will not add any shard - # It will also add service - status = self.catalog_setup_checks() - if status == False: - self.ocommon.log_info_message("No existing catalog and GDS setup found on this system. Setting up GDS and will configure catalog on this machine.",self.file_name) - self.setup_machine() - self.catalog_checks() - self.reset_gsm_setup() - status1 = self.gsm_setup_check() - if status1: - self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) - self.start_gsm_director() - self.ocommon.log_info_message("Started GSM",self.file_name) - else: - # Perform Catalog setup after check GSM_MASTER FLAG. IF GSM MASTER FLAG is set then only catalog will be added. - self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) - master_flag=self.gsm_master_flag_check() - if master_flag: - self.setup_gsm_calog() - self.setup_gsm_director() - self.start_gsm_director() - self.status_gsm_director() - if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': - self.setup_gsm_shardg("SHARD_GROUP") - else: - self.setup_gsm_shardg("SHARD_GROUP") - self.gsm_backup_file() - self.gsm_completion_message() - ### Running Custom Scripts - self.run_custom_scripts() - else: - self.add_gsm_director() - self.start_gsm_director() - self.gsm_backup_file() - self.gsm_completion_message() - else: - # This block run shard addition, catalog addition and service creation - # This block also verifies if master flag is not not GSM director then it will not create catalog but add GSM ony - self.setup_machine() - self.gsm_checks() - self.reset_gsm_setup() - status = self.gsm_setup_check() - if status: - self.ocommon.log_info_message("Gsm Setup is already completed on this database",self.file_name) - self.start_gsm_director() - self.ocommon.log_info_message("Started GSM",self.file_name) - else: - # if the status = self.gsm_setup_check() return False then shard addition, catalog addition and service creation - master_flag=self.gsm_master_flag_check() - if master_flag: - self.ocommon.log_info_message("No existing GDS found on this system. Setting up GDS on this machine.",self.file_name) - self.setup_gsm_calog() - self.setup_gsm_director() - self.start_gsm_director() - self.status_gsm_director() - if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - if self.ora_env_dict["SHARDING_TYPE"].upper() != 'USER': - self.setup_gsm_shardg("SHARD_GROUP") - if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': - self.setup_gsm_sspace("SHARD_SPACE") - else: - self.setup_gsm_shardg("SHARD_GROUP") - self.setup_gsm_shard() - self.set_hostid_null() - self.stop_gsm_director() - time.sleep(30) - self.start_gsm_director() - self.add_invited_node("SHARD") - self.remove_invited_node("SHARD") - self.stop_gsm_director() - time.sleep(30) - self.start_gsm_director() - self.deploy_shard() - self.setup_gsm_service() - self.setup_sample_schema() - self.gsm_backup_file() - self.gsm_completion_message() - ### Running Custom Scripts - self.run_custom_scripts() - else: - self.add_gsm_director() - self.start_gsm_director() - self.gsm_backup_file() - self.gsm_completion_message() - - ########### SETUP_MACHINE begins here #################### - ## Function to machine setup - def setup_machine(self): - """ - This function performs the compute before performing setup - """ - self.omachine.setup() - filename = self.ora_env_dict["GSM_LOCK_STATUS_FILE"] - touchfile = 'touch {0}'.format(filename) - if not os.path.isfile(filename): - self.ocommon.log_error_message("Setting file provisioning status file :" + filename ,self.file_name) - output,error,retcode=self.ocommon.execute_cmd(touchfile,None,self.ora_env_dict) - if retcode == 1: - self.ocommon.log_error_message("error occurred while touching the file :" + filename + ". Exiting!",self.file_name) - self.ocommon.prog_exit("127") - - ########### ENDS here #################### - - def gsm_checks(self): - """ - This function perform db checks before starting the setup - """ - self.ohome_check() - self.passwd_check() - self.shard_user_check() - self.gsm_hostname_check() - self.director_params_checks() - self.catalog_params_check() - self.shard_params_check() - self.sgroup_params_check() - - - def catalog_checks(self): - """ - This function perform db checks before starting the setup - """ - self.ohome_check() - self.passwd_check() - self.shard_user_check() - self.gsm_hostname_check() - self.director_params_checks() - self.catalog_params_check() - self.sgroup_params_check() - - def ohome_check(self): - """ - This function performs the oracle home related checks - """ - if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): - self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) - else: - self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) - self.ocommon.prog_exit("127") - - if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): - msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def passwd_check(self): - """ - Set the password - """ - self.ocommon.get_password(None) - if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): - msg='''ORACLE_PWD key is set. Check Passed!''' - self.ocommon.log_info_message(msg,self.file_name) - - def shard_user_check(self): - """ - This funnction set the user for pdb and cdb. - """ - if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): - msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) - msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" - self.ocommon.log_info_message(msg,self.file_name) - - if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): - msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) - msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." - self.ocommon.log_info_message(msg,self.file_name) - - def director_params_checks(self): - """ - This funnction check and set the shard director name - """ - status=False - reg_exp= self.director_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - msg='''SHARD Director PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) - self.ocommon.log_info_message(msg,self.file_name) - status=True - - def gsm_hostname_check(self): - """ - This function check and set the hostname. - """ - if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): - msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): - ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) - hostname='''{0}'''.format(socket.getfqdn()) - else: - hostname='''{0}'''.format(socket.gethostname()) - msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) - self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) - self.ocommon.log_info_message(msg,self.file_name) - - def catalog_params_check(self): - """ - This funnction check if CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is passed as an env variable or not. If not passed then exit. - """ - status=False - reg_exp= self.catalog_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - msg='''CATALOG PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) - self.ocommon.log_info_message(msg,self.file_name) - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - if stype: - if stype.lower() == 'user': - if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) - if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): - self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) - status=True - - if not status: - msg="CATALOG[1-9]_PARAMS such as CATALOG_PARAMS is not set, exiting!" - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def shard_params_check(self): - """ - This funnction check if SHARD[1-9]_PARAMS such as SHARD1_PARAMS is passed as an env variable or not. If not passed then exit. - """ - status=False - reg_exp= self.shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - msg='''SHARD PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) - self.ocommon.log_info_message(msg,self.file_name) - status=True - - if not status: - msg="SHARD[1-9]_PARAMS such as SHARD1_PARAMS is not set, exiting!" - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def sgroup_params_check(self): - """ - This funnction check if SHARD[1-9]_GROUP_PARAMS such as SHARD1_GROUP_PARAMS is passed as an env variable or not. If not passed then exit. - """ - status=False - reg_exp= self.shardg_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - msg='''SHARD GROUP PARAMS {0} is set to {1}'''.format(key,self.ora_env_dict[key]) - self.ocommon.log_info_message(msg,self.file_name) - status=True - def gsm_master_flag_check(self): - """ - This funnction check if MASTER_GSM is passed as an env variable or not. If not passed then exit. - """ - status=False - if self.ocommon.check_key("MASTER_GSM",self.ora_env_dict): - msg='''MASTER_GSM is set. This machine will be configured with as master GSM director.''' - self.ocommon.log_info_message(msg,self.file_name) - return True - else: - return False - - def catalog_setup_checks(self): - """ - This function checks if director and catalog is setup and connection is established. - """ - status = False - gsm_status = self.check_gsm_director(None) - #catalog_status = self.check_gsm_catalog() - - if gsm_status == 'completed': - status = True - else: - status = False - - #if catalog_status == 'completed': - # status = True - #else: - # status = False - - return status - ########### DB_CHECKS Related Functions Begin Here #################### - - - ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### - def reset_gsm_setup(self): - """ - This function delete the GSM files. - """ - self.ocommon.log_info_message("Inside reset_gsm_setup",self.file_name) - gsmdata_loc='/opt/oracle/gsmdata' - cmd_list=[] - if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): - if self.ora_env_dict["RESET_ENV"]: - msg='''Deleteing files from {0}'''.format(gsmdata_loc) - self.ocommon.log_info_message(msg,self.file_name) - cmd_list[0]='''rm -f {0}/gsm.ora'''.format(gsmdata_loc) - cmd_list[1]='''rm -f {0}/tnsnames.ora'''.format(gsmdata_loc) - cmd_list[2]='''rm -rf {0}/wallets'''.format(gsmdata_loc) - for cmd in cmd_list: - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - def gsm_setup_check(self): - """ - This function check if GSM is already setup on this - """ - status=True - self.ocommon.log_info_message("Inside gsm_setup_check",self.file_name) - gsmdata_loc='/opt/oracle/gsmdata' - gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) - - gsmora='''{0}/gsm.ora'''.format(gsmdata_loc) - tnsnamesora='''{0}/tnsnames.ora'''.format(gsmdata_loc) - walletloc='''{0}/gsmwallet'''.format(gsmdata_loc) - - if os.path.isfile(gsmora): - cmd='''cp -r -v -f {0} {1}/'''.format(gsmora,gsmfile_loc) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - else: - status=False - - if os.path.isfile(tnsnamesora): - cmd='''cp -r -v -f {0} {1}/'''.format(tnsnamesora,gsmfile_loc) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - else: - status=False - - if os.path.isdir(walletloc): - cmd='''cp -r -v -f {0} {1}/'''.format(walletloc,gsmfile_loc) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - else: - status=False - - if status: - return True - else: - return False - - #################### Catalog related Functions BEGINS Here ########################### - def setup_gsm_calog(self): - """ - This function setup the GSM catalog. - """ - self.ocommon.log_info_message("Inside setup_gsm_calog()",self.file_name) - status=False - reg_exp= self.catalog_regex() - counter=1 - end_counter=60 - catalog_db_status=None - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - catalog_db_status=self.check_setup_status(catalog_host,catalog_db,catalog_pdb,catalog_port) - if catalog_db_status == 'completed': - self.configure_gsm_clog(catalog_host,catalog_db,catalog_pdb,catalog_port,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname) - break - else: - msg='''Catalog Status must return completed but returned value is {0}'''.format(status) - self.ocommon.log_info_message(msg,self.file_name) - if catalog_db_status == 'completed': - break - else: - msg='''Catalog setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - self.ocommon.log_info_message(msg,self.file_name) - time.sleep(60) - counter=counter+1 - - def process_clog_vars(self,key): - """ - This function process catalog vars based on key and return values to configure the GSM - """ - catalog_db=None - catalog_pdb=None - catalog_port=None - catalog_region=None - catalog_host=None - catalog_name=None - catalog_chunks=None - repl_type=None - repl_factor=None - repl_unit=None - stype=None - sspace=None - cfname=None - - self.ocommon.log_info_message("Inside process_clog_vars()",self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - if ckey == 'catalog_db': - catalog_db = cvar_dict[ckey] - if ckey == 'catalog_pdb': - catalog_pdb = cvar_dict[ckey] - if ckey == 'catalog_port': - catalog_port = cvar_dict[ckey] - if ckey == 'catalog_region': - catalog_region = cvar_dict[ckey] - if ckey == 'catalog_host': - catalog_host = cvar_dict[ckey] - if ckey == 'catalog_name': - catalog_name = cvar_dict[ckey] - if ckey == 'catalog_chunks': - catalog_chunks = cvar_dict[ckey] - if ckey == 'repl_type': - repl_type = cvar_dict[ckey] - if ckey == 'repl_factor': - repl_factor = cvar_dict[ckey] - if ckey == 'repl_unit': - repl_unit = cvar_dict[ckey] - if ckey == 'sharding_type': - stype = cvar_dict[ckey] - if ckey == 'shard_space': - sspace = cvar_dict[ckey] - if ckey == 'shard_configname': - cfname = cvar_dict[ckey] - - ## Set the values if not set in above block - if not catalog_port: - catalog_port=1521 - if not catalog_region: - catalog_region="region1,region2" - if stype: - if not sspace: - sspace="shardspace1,shardspace2" - - ### Check values must be set - if catalog_host and catalog_db and catalog_pdb and catalog_port and catalog_region and catalog_name: - return catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname - else: - msg1='''catalog_db={0},catalog_pdb={1}'''.format((catalog_db or "Missing Value"),(catalog_pdb or "Missing Value")) - msg2='''catalog_port={0},catalog_host={1}'''.format((catalog_port or "Missing Value"),(catalog_host or "Missing Value")) - msg3='''catalog_region={0},catalog_name={1}'''.format((catalog_region or "Missing Value"),(catalog_name or "Missing Value")) - msg='''Catalog params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def check_gsm_catalog(self): - """ - This function check the catalog status in GSM - """ - self.ocommon.log_info_message("Inside check_gsm_catalog()",self.file_name) - #dtrname,dtrport,dtregion=self.process_director_vars() - gsmcmd=''' - config; - exit; - '''.format("test") - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) - try: - match=self.ocommon.check_substr_match(matched_output[0],"test") - except: - match=False - return(self.ocommon.check_status_value(match)) - - # output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - # new_output=output[0].replace(" ","") - # self.ocommon.log_info_message(new_output,self.file_name) - # match=self.ocommon.check_substr_match(new_output,"Catalogconnectionisestablished") - # return(self.ocommon.check_status_value(match)) - - def catalog_regex(self): - """ - This function return the rgex to search the CATALOG PARAMS - """ - self.ocommon.log_info_message("Inside catalog_regex()",self.file_name) - return re.compile('CATALOG_PARAMS') - - - def configure_gsm_clog(self,chost,ccdb,cpdb,cport,catalog_name,catalog_region,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname): - """ - This function configure the GSM catalog. - """ - self.ocommon.log_info_message("Inside configure_gsm_clog()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - replist=['native'] - - ### User Define Shardig Variables - shardingtype=None - shardspace=None - configname=None - - # if stype and sspace: - if stype: - if stype.lower() == 'user': - shardingtype="-sharding user" - #shardspace="" - shardspace=" -shardspace {0}".format(sspace) - if not self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - self.ora_env_dict=self.ocommon.add_key("SHARDING_TYPE","USER",self.ora_env_dict) - if not self.ocommon.check_key("SHARD_SPACE",self.ora_env_dict): - self.ora_env_dict=self.ocommon.add_key("SHARD_SPACE",sspace,self.ora_env_dict) - else: - shardspace="" - shardingtype="" - else: - shardspace="" - shardingtype="" - - if cfname: - configname=" -configname {0}".format(cfname) - else: - configname="" - - ### SNR Sharding - chunks=None - repl=None - repfactor=None - repunits=None - - if catalog_chunks: - chunks="-chunks {0}".format(catalog_chunks) - else: - chunks="" - - if repl_type and repl_type.lower() in replist: - self.ocommon.log_info_message("Repl_Type value Set to in block1:" + repl_type,self.file_name) - repl=" -repl {0}".format(repl_type) - else: - repl="" - - if repl_factor: - repfactor=" -repfactor {0}".format(repl_factor) - else: - repfactor="" - - if repl_unit: - repunits=" -repunits {0}".format(repl_unit) - else: - repunits="" - - invited_subnet="" - add_invited_subnet="" - if self.ocommon.check_key("INVITED_NODE_SUBNET_FLAG",self.ora_env_dict): - if self.ocommon.check_key("INVITED_NODE_SUBNET",self.ora_env_dict): - invited_subnet=self.ora_env_dict["INVITED_NODE_SUBNET"] - else: - #self.ocommon.log_info_message("The catalog Host name is :" + chost,self.file_name) - chost_ip=self.ocommon.get_ip(chost,None) - ip_parts=chost_ip.split('.') - invited_subnet=ip_parts[0] + "." + ip_parts[1] + '.*' + '.*' - add_invited_subnet='''add invitedsubnet {0};'''.format(invited_subnet) - - cpasswd="HIDDEN_STRING" - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - gsmcmd=''' - create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})))\" {7} -user {3}/{4} -sdb {5} -region {6} -agent_port 8080 -agent_password {4} {8} {9} {10} {11} {12} {13} -autovncr off; - add invitednode {0}; - {14} - exit; - '''.format(chost,cport,cpdb,cadmin,cpasswd,catalog_name,catalog_region,chunks,repl,repfactor,repunits,shardingtype,shardspace,configname,add_invited_subnet) - - counter=1 - while counter < 5: - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - if retcode != 0: - self.ocommon.log_info_message("Error occurred while creating the shard catalog, sleeping for 60 seconds",self.file_name) - counter = counter + 1 - time.sleep(60) - else: - break - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - ######################################## GSM director Functions Begins Here ##################### - def process_director_vars(self,key): - """ - This function process GSM director vars based on key and return values to configure the GSM - """ - dtrname=None - dtrport=None - dtregion=None - - self.ocommon.log_info_message("Inside process_director_vars()",self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - if ckey == 'director_name': - dtrname = cvar_dict[ckey] - if ckey == 'director_port': - dtrport = cvar_dict[ckey] - if ckey == 'director_region': - dtregion = cvar_dict[ckey] - - ### Check values must be set - if dtrname and dtrport and dtregion: - return dtrname,dtrport,dtregion - else: - msg1='''director_name={0},director_port={1}'''.format((dtrname or "Missing Value"),(dtrport or "Missing Value")) - msg2='''director_region={0}'''.format((dtregion or "Missing Value")) - msg='''Director params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("Error occurred") - - def check_gsm_director(self,dname): - """ - This function check the GSM director status - """ - self.ocommon.log_info_message("Inside check_gsm_director()",self.file_name) - status=False - if dname: - gsmcmd=self.get_gsm_config_cmd(dname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) - try: - if self.ocommon.check_substr_match(matched_output[0],dname): - status=True - except: - status=False - else: - reg_exp= self.director_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - dname,dtrport,dtregion=self.process_director_vars(key) - gsmcmd=self.get_gsm_config_cmd(dname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:GSMs\n)(?:.+\n)+",output) - try: - if self.ocommon.check_substr_match(matched_output[0],dname): - status=True - except: - status=False - - return(self.ocommon.check_status_value(status)) - - def check_gsm_region(self,region): - """ - This function check the GSM regions - """ - self.ocommon.log_info_message("Inside check_gsm_region()",self.file_name) - gsmcmd=self.get_gsm_config_cmd(None) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:Regions\n)(?:.+\n)+",output) - status=False - try: - if self.ocommon.check_substr_match(matched_output[0],region): - status=True - except: - status=False - return(self.ocommon.check_status_value(status)) - - def check_gsm_shardspace(self,sspace): - """ - This function check the GSM shardspace - """ - self.ocommon.log_info_message("Inside check_gsm_shardspace()",self.file_name) - gsmcmd=self.get_gsm_config_cmd(None) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:Shard spaces\n)(?:.+\n)+",output) - status=False - try: - if self.ocommon.check_substr_match(matched_output[0],sspace): - status=True - except: - status=False - return(self.ocommon.check_status_value(status)) - - def check_gsm_director_status(self,dname): - """ - This function check the GSM director status using 'gdsctl status' - """ - self.ocommon.log_info_message("Inside check_gsm_director_status()",self.file_name) - status=False - gsmcmd=''' - status; - exit; - ''' - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - if "Connected to GDS catalog Y".replace(" ","").lower() in output.replace(" ","").lower(): - return True - else: - return False - - def add_gsm_director(self): - """ - This function add the GSM - """ - status=False - counter=1 - end_counter=60 - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - reg_exp= self.director_regex() - - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_director_status=None - dtrname,dtrport,dtregion=self.process_director_vars(key) - shard_director_status=self.check_gsm_director(dtrname) - if shard_director_status != 'completed': - self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) - status = self.check_gsm_director(None) - if status == 'completed': - break - - if status == 'completed': - break - else: - msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - self.ocommon.log_info_message(msg,self.file_name) - time.sleep(60) - counter=counter+1 - - status = self.check_gsm_director(None) - if status == 'completed': - msg='''Shard director setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 60 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def setup_gsm_director(self): - """ - This function setup in GSM - """ - self.ocommon.log_info_message("Inside setup_gsm_director()",self.file_name) - status=False - reg_exp= self.director_regex() - counter=1 - end_counter=3 - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_director_status=None - dtrname,dtrport,dtregion=self.process_director_vars(key) - shard_director_status=self.check_gsm_director(dtrname) - if shard_director_status != 'completed': - self.configure_gsm_director(dtrname,dtrport,dtregion,gsmhost,cadmin) - status = self.check_gsm_director(None) - if status == 'completed': - break - else: - msg='''GSM shard director setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - time.sleep(60) - counter=counter+1 - - status = self.check_gsm_director(None) - if status == 'completed': - msg='''Shard director setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 3 minute to complete shard director in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin): - """ - This function configure GSM director - """ - ## Getting the values of catalog_port,catalog_pdb,catalog_host - cpasswd="HIDDEN_STRING" - reg_exp= self.catalog_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - sregionFlag=self.check_gsm_region(dtregion) - if sregionFlag != 'completed': - self.configure_gsm_region(dtregion) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - add gsm -gsm {0} -listener {1} -pwd {2} -catalog {3}:{4}/{5} -region {6}; - exit; - '''.format(dtrname,dtrport,cpasswd,catalog_host,catalog_port,catalog_pdb,dtregion,gsmhost) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def start_gsm_director(self): - """ - This function start the director in the GSM - """ - status='noval' - self.ocommon.log_info_message("Inside start_gsm_director() function",self.file_name) - reg_exp= self.director_regex() - counter=1 - end_counter=10 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - dtrname,dtrport,dtregion=self.process_director_vars(key) - gsmcmd=''' - start gsm -gsm {0}; - exit; - '''.format(dtrname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - status=self.check_gsm_director(dtrname) - if status == 'completed': - break; - if status == 'completed': - filename=self.ora_env_dict["GSM_LOCK_STATUS_FILE"] - remfile='''rm -f {0}'''.format(filename) - if os.path.isfile(filename): - output,error,retcode=self.ocommon.execute_cmd(remfile,None,self.ora_env_dict) - break - else: - msg='''GSM shard director failed to start.Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - self.ocommon.log_error_message(msg,self.file_name) - time.sleep(30) - - counter=counter+1 - - - if status != 'completed': - msg='''GSM shard director failed to start.Exiting!''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def stop_gsm_director(self): - """ - This function stop the director in the GSM - """ - status=False - self.ocommon.log_info_message("Inside stop_gsm_director() function",self.file_name) - reg_exp= self.director_regex() - counter=1 - end_counter=2 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - dtrname,dtrport,dtregion=self.process_director_vars(key) - gsmcmd=''' - stop gsm -gsm {0}; - exit; - '''.format(dtrname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - counter=counter+1 - - def status_gsm_director(self): - """ - This function check the GSM director status - """ - gsm_status = self.check_gsm_director(None) - #catalog_status = self.check_gsm_catalog() - - if gsm_status == 'completed': - msg='''Director setup completed in GSM and catalog is connected''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Shard director in GSM did not complete or not connected to catalog. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - ######################################## Shard Group Setup Begins Here ############################ - def setup_gsm_shardg(self,restype): - """ - This function setup the shard group. - """ - self.ocommon.log_info_message("Inside setup_gsm_shardg()",self.file_name) - status=False - if restype == 'ADD_SGROUP_PARAMS': - reg_exp = self.add_shardg_regex() - elif restype == 'SHARD_GROUP': - reg_exp = self.shardg_regex() - else: - self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SGROUP_PARAMS or SHARD_GROUP key to create a shard group",self.file_name) - self.ocommon.log_warn_message("Since no key specified for ADD_SGROUP_PARAMS and SHARD_GROUP, shardgroup will be created during shard creation",self.file_name) - - sgListC=[] - sgListP=[] - counter=1 - end_counter=3 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_group_status=None - self.ocommon.log_info_message("Key is set to : " + key,self.file_name) - group_name,deploy_as,group_region=self.process_shardg_vars(key) - self.ocommon.log_info_message("Name: " + group_name + "deploy_as" + deploy_as + "group_region" + group_region,self.file_name) - if group_name is not None: - if group_name not in sgListC: - dtrname=self.get_director_name(group_region) - shard_group_status=self.check_shardg_status(group_name,dtrname) - if shard_group_status != 'completed': - self.configure_gsm_shardg(group_name,deploy_as,group_region,'add') - shard_group_status = self.check_shardg_status(group_name,None) - if shard_group_status == 'completed': - sgListC.append(group_name) - if group_name in sgListP: - sgListP.remove(group_name) - else: - sgListP=sgListP.append(group_name) - time.sleep(30) - counter=counter + 1 - - if sgListP == []: - msg='''Shard group setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def get_director_name(self,region_name): - """ - This function get the director name based on the region - """ - self.ocommon.log_info_message("Inside get_director_name()",self.file_name) - status=False - director_name=None - reg_exp= self.director_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - dtrname,dtrport,dtregion=self.process_director_vars(key) - director_name=dtrname - gsm_status = self.check_gsm_director(dtrname) - if gsm_status == 'completed': - status = True - else: - status = False - if dtregion == region_name: - break - if status: - if director_name: - return director_name - else: - self.ocommon.log_error_message("No director exist to match the region",self.file_name) - self.ocommon.prog_exit("127") - else: - self.ocommon.log_error_message("Shard Director is not running!",self.file_name) - self.ocommon.prog_exit("127") - - def get_shardg_region_name(self,sgname): - """ - This function get the region name based on shard group name - """ - self.ocommon.log_info_message("Inside get_region_name()",self.file_name) - status=False - region_name=None - reg_exp= self.shardg_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - group_name,deploy_as,group_region=self.process_shardg_vars(key) - region_name=group_region - if sgname == group_name: - status=True - break - if status: - return region_name - else: - self.ocommon.log_error_message("No such shard group exist! exiting!",self.file_name) - self.ocommon.prog_exit("127") - - def process_shardg_vars(self,key): - """ - This function process shardG vars based on key and return values to configure the GSM - """ - group_name=None - deploy_as=None - group_region=None - - self.ocommon.log_info_message("Inside process_shardg_vars()",self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - if ckey == 'group_name': - group_name = cvar_dict[ckey] - if ckey == 'deploy_as': - deploy_as = cvar_dict[ckey] - if ckey == 'group_region': - group_region = cvar_dict[ckey] - - ### Check values must be set - if group_name and deploy_as and group_region: - return group_name,deploy_as,group_region - else: - msg1='''group_name={0},deploy_as={1}'''.format((group_name or "Missing Value"),(deploy_as or "Missing Value")) - msg2='''group_region={0}'''.format((group_region or "Missing Value")) - msg='''Shard group params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1,msg2) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("Error occurred") - - - def check_shardg_status(self,group_name,dname): - """ - This function check the shard status in GSM - """ - self.ocommon.log_info_message("Inside check_shardg_status()",self.file_name) - status=False - - gsmcmd=self.get_gsm_config_cmd(dname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) - if self.ocommon.check_substr_match(matched_output[0],group_name): - status=True - else: - status=False - - ''' - else: - reg_exp= self.shardg_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - group_name,deploy_as,group_region=self.process_shardg_vars(key) - dname=self.get_director_name(group_region) - gsmcmd=self.get_gsm_config_cmd(dname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:Shard Groups\n)(?:.+\n)+",output) - # match=re.search("(?i)(?m)"+group_name,matched_output) - if self.ocommon.check_substr_match(matched_output[0],group_name): - status=True - else: - status=False - ''' - - return(self.ocommon.check_status_value(status)) - -############################################# Director Related Block ############ - def get_director_name(self,region_name): - """ - This function get the director name based on the region - """ - self.ocommon.log_info_message("Inside get_director_name()",self.file_name) - status=False - director_name=None - reg_exp= self.director_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - dtrname,dtrport,dtregion=self.process_director_vars(key) - director_name=dtrname - gsm_status = self.check_gsm_director(dtrname) - if gsm_status == 'completed': - status = True - else: - status = False - if dtregion == region_name: - break - if status: - if director_name: - return director_name - else: - self.ocommon.log_error_message("No director exist to match the region",self.file_name) - self.ocommon.prog_exit("127") - else: - self.ocommon.log_error_message("Shard Director is not running!",self.file_name) - self.ocommon.prog_exit("127") - -######## - - def get_gsm_config_cmd(self,dname): - """ - Get the GSM config command - """ - self.ocommon.log_info_message("Inside get_gsm_config_cmd()",self.file_name) - gsmcmd=''' - config; - exit; - '''.format("test") - return gsmcmd - - def director_regex(self): - """ - This function return the rgex to search the SHARD DIRECTOR PARAMS - """ - self.ocommon.log_info_message("Inside director_regex()",self.file_name) - return re.compile('SHARD_DIRECTOR_PARAMS') - - def shardg_regex(self): - """ - This function return the rgex to search the SHARD GROUP PARAMS - """ - self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) - return re.compile('SHARD[0-9]+_GROUP_PARAMS') - - def add_shardg_regex(self): - """ - This function return the rgex to search the SHARD GROUP PARAMS - """ - self.ocommon.log_info_message("Inside shardg_regex()",self.file_name) - return re.compile('ADD_SGROUP_PARAMS') - - def configure_gsm_shardg(self,group_name,deploy_as,group_region,type): - """ - This function configure the Shard Group. - """ - self.ocommon.log_info_message("Inside configure_gsm_shardg()",self.file_name) - cmd=None - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - dtrname=self.get_director_name(group_region) - reg_exp= self.catalog_regex() - if type == 'modify': - cmd=''' modify shardgroup -shardgroup {0} '''.format(group_name) - else: - cmd=''' add shardgroup -shardgroup {0} '''.format(group_name) - - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - if repl_type: - cmd=cmd + " -region {0} ".format(group_region) - else: - cmd=cmd + " -deploy_as {0} -region {1} ".format(deploy_as,group_region) - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - gsmcmd=''' - connect {1}/{2}; - {3}; - exit; - '''.format("NA",cadmin,cpasswd,cmd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - -############# Adding Shard Regions ############### - def configure_gsm_region(self,region): - """ - This function configure the Shard region. - """ - self.ocommon.log_info_message("Inside configure_gsm_region()",self.file_name) - cmd=None - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - gsmcmd=''' - connect {1}/{2}; - add region -region {3}; - exit; - '''.format("NA",cadmin,cpasswd,region) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - -##################### Adding Shard Space ############### - def process_sspace_vars(self,key): - """ - This function process shardG vars based on key and return values to configure the GSM - """ - sspace=None - chunks=None - repfactor=None - repunits=None - protectedmode=None - self.ocommon.log_info_message("Inside process_sspace_vars()",self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - if ckey == 'sspace_name': - sspace = cvar_dict[ckey] - if ckey == 'chunks': - chunks = cvar_dict[ckey] - if ckey == 'repfactor': - repfactor = cvar_dict[ckey] - if ckey == 'repunits': - repunits = cvar_dict[ckey] - if ckey == 'protectedmode': - protectedmode = cvar_dict[ckey] - - ### Check values must be set - if sspace: - return sspace,chunks,repfactor,repunits,protectedmode - else: - msg1='''sspace={0}'''.format((sspace or "Missing Value")) - msg='''Shard space params {0} is not set correctly. One or more value is missing {1}'''.format(key,msg1) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("Error occurred") - - def setup_gsm_sspace(self,restype): - """ - This function setup the shard sspace. - """ - self.ocommon.log_info_message("Inside setup_gsm_sspace()",self.file_name) - status=False - if restype == 'ADD_SSPACE_PARAMS': - reg_exp = self.add_shardg_regex() - elif restype == 'SHARD_SPACE': - reg_exp = self.shardg_regex() - else: - self.ocommon.log_warn_message("No Key Specified! You can only pass ADD_SSPACE_PARAMS or SHARD_SPACE key to create a shard space",self.file_name) - self.ocommon.log_warn_message("Since no ADD_SSPACE_PARAMS or SHARD_SPACE defined, shardspace will be created during shard creation",self.file_name) - counter=1 - ssListC=[] - ssListP=[] - counter=1 - end_counter=3 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_space_status=None - sspace,chunks,repfactor,repuntis,protectedmode=self.process_sspace_vars(key) - if sspace is not None: - if sspace not in ssListC: - shard_sspace_status=self.check_gsm_shardspace(sspace) - if shard_sspace_status != 'completed': - self.configure_gsm_sspace(sspace,chunks,repfactor,repuntis,protectedmode,'add') - shard_space_status = self.check_gsm_shardspace(sspace) - if shard_sspace_status == 'completed': - ssListC.append(sspace) - if sspace in sgListP: - sgListP.remove(sspace) - else: - sgListP=sgListP.append(sspace) - time.sleep(30) - counter=counter + 1 - - if ssListP == []: - msg='''Shard space setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 2 minute to complete shard space setup in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def configure_gsm_sspace(self,sspace,chunks,repfactor,repunits,protectedmode,type): - """ - This function configure the Shard Group. - """ - self.ocommon.log_info_message("Inside configure_gsm_sspace()",self.file_name) - cmd=None - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - if type == 'MODIFY': - cmd=''' modify shardspace -shardspace {0} '''.format(sspace) - else: - cmd=''' add shardspace -shardspace {0} '''.format(sspace) - if chunks is not None: - cmd = cmd + ''' -chunks {0}'''.format(chunks) - if repfactor: - cmd = cmd + ''' -repfactor {0}'''.format(repfactor) - if repunits is not None: - cmd = cmd + ''' -repunits {0}'''.format(repfactor) - if protectedmode is not None: - cmd = cmd + ''' -protectedmode {0}'''.format(protectedmode) - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - gsmcmd=''' - connect {1}/{2}; - {3}; - exit; - '''.format("NA",cadmin,cpasswd,cmd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - #########################################Shard Function Begins Here ############################## - def setup_gsm_shard(self): - """ - This function setup and add shard in the GSM - """ - self.ocommon.log_info_message("Inside setup_gsm_shard()",self.file_name) - status=False - reg_exp= self.shard_regex() - counter=1 - end_counter=60 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db_status=None - shard_db,shard_pdb,shard_port,shard_group,shard_host,sregion,sspace=self.process_shard_vars(key) - shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) - if shard_db_status == 'completed': - self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,sregion,sspace) - else: - msg='''Shard db status must return completed but returned value is {0}'''.format(status) - self.ocommon.log_info_message(msg,self.file_name) - - status = self.check_shard_status(None) - if status == 'completed': - break - else: - msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - self.ocommon.log_info_message(msg,self.file_name) - time.sleep(60) - counter=counter+1 - - status = self.check_shard_status(None) - if status == 'completed': - msg='''Shard DB setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 60 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def add_gsm_shard(self): - """ - This function add the shard in the GSM - """ - self.ocommon.log_info_message("Inside add_gsm_shard()",self.file_name) - status=False - reg_exp= self.add_shard_regex() - counter=1 - end_counter=3 - shard_name="none" - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db_status=None - shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) - shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) - shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) - self.ocommon.log_info_message("Shard Status : " + shard_db_status,self.file_name) - if shard_db_status == 'completed': - self.configure_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group,shard_region,shard_space) - counter2=1 - end_counter2=5 - while counter2 < end_counter2: - status1 = self.check_shard_status(shard_name) - if status1 == 'completed': - msg='''Shard DB setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - break - else: - msg='''Shard DB is still not added in GSM. Sleeping for 60 seconds''' - self.ocommon.log_info_message(msg,self.file_name) - time.sleep(60) - counter2=counter2+1 - else: - msg='''Shard db status must return completed but returned value is {0}'''.format(status) - self.ocommon.log_info_message(msg,self.file_name) - - status = self.check_shard_status(None) - if status == 'completed': - break - else: - msg='''Shard DB setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - self.ocommon.log_info_message(msg,self.file_name) - time.sleep(60) - counter=counter+1 - status = self.check_shard_status(shard_name) - if status == 'completed': - msg='''Shard DB setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 3 minute to complete shard db setup in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def remove_gsm_shard(self): - """ - This function remove the shard in the GSM - """ - self.ocommon.log_info_message("Inside remove_gsm_shard()",self.file_name) - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars("CATALOG_PARAMS") - numOfShards=self.count_online_shards() - status=False - reg_exp=self.remove_shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db_status=None - shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) - shardname_to_delete=shard_db + "_" + shard_pdb - if repl_type is not None: - if(repl_type.upper() == 'NATIVE'): - self.move_shards_leader_rus(shardname_to_delete) - leaderCount=self.count_leader_shards(shardname_to_delete) - if(numOfShards < 4 or leaderCount > 0): - msg='''ruType=[{0}]. NumofShards=[{1}]. LeaderCount=[{2}]. Ignoring remove of shard [{3}]'''.format(repl_type,numOfShards,leaderCount,shardname_to_delete) - self.ocommon.log_info_message(msg,self.file_name) - break - - self.move_shard_rus(shardname_to_delete,None,None) - while self.count_shard_rus(shardname_to_delete) > 0: - self.ocommon.log_info_message("Waiting for all the shard chunks to be moved.",self.file_name) - time.sleep(15) - - shard_db_status=self.check_setup_status(shard_host,shard_db,shard_pdb,shard_port) - if shard_db_status == 'completed': - self.delete_gsm_shard(shard_host,shard_db,shard_pdb,shard_port,shard_group) - status=True - else: - msg='''Shard db status must return completed but returned value is {0}'''.format(status) - self.ocommon.log_info_message(msg,self.file_name) - - return status - - def move_shards_leader_rus(self,shardname_to_delete): - """ - This function move the shard leader RUs - """ - shards=self.get_online_shards() - leader_ru=self.get_rus(shardname_to_delete) - all_ru=self.get_rus(None) - count=0 - target_shards=[] - value=0 - - if len(shards) == 0: - msg="""No Shard is online so no RU is available to be moved""" - self.ocommon.log_info_message(msg,self.file_name) - else: - for line in leader_ru: - value=None - count += 1 - cols=line.split() - if len(cols) > 0: - if cols[0].lower() == shardname_to_delete.lower(): - if cols[1].isdigit: - value = int(cols[1]) - else: - continue - - target_shards.clear() - for line1 in all_ru: - cols1=line1.split() - print(cols1) - if len(cols1) > 5: - if cols1[0].lower() != shardname_to_delete.lower() and cols1[1].isdigit and cols1[2].lower() == 'follower': - if value is not None: - if int(cols1[1]) == value: - target_shards.append(cols1[0]) - break - - for shard in shards: - if shard.lower() != shardname_to_delete.lower(): - if shard in target_shards: - msg="Shard_name= " + shard + " Status=True" + " Value = " + str(value) - self.ocommon.log_info_message(msg,self.file_name) - self.move_shard_rus(shardname_to_delete,shard,value) - - def move_shard_chunks(self): - """ - This function move the shard chunks - """ - self.ocommon.log_info_message("Inside move_shard_chunks()",self.file_name) - status=False - reg_exp= self.move_chunks_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - move_chunks_status=None - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - shard_num = self.count_online_shards() - online_shard = self.check_online_shard(shard_name) - if shard_num > 1 and online_shard == 0 : - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - MOVE CHUNK -CHUNK ALL -SOURCE {0} - config shard; - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def validate_nochunks(self): - """ - This function check the chnunks - """ - self.ocommon.log_info_message("Inside validate_nochunks()",self.file_name) - status=False - reg_exp= self.move_nochunks_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - move_chunks_status=None - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - shard_num = self.count_online_shards() - online_shard = self.check_online_shard(shard_name) - if shard_num > 1 and online_shard == 0 : - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - config chunks -shard {0} - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - matched_output=re.findall("(?:Chunks\n)(?:.+\n)+",output) - if self.ocommon.check_substr_match(matched_output[0].lower(),shard_name.lower()): - self.ocommon.prog_exit("127") - - def move_chunks_regex(self): - """ - This function return the rgex to search the SHARD PARAMS - """ - self.ocommon.log_info_message("Inside move_chnuks_regex()",self.file_name) - return re.compile('MOVE_CHUNKS') - - def move_nochunks_regex(self): - """ - This function return the rgex to search the SHARD PARAMS - """ - self.ocommon.log_info_message("Inside move_nochunks_regex()",self.file_name) - return re.compile('VALIDATE_NOCHUNKS') - - def check_shard_chunks(self): - """ - This function check the shard chunks - """ - self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) - status=False - reg_exp= self.check_chunks_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - move_chunks_status=None - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - online_shard = self.check_online_shard(shard_name) - if online_shard == 0 : - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - config chunks -shard {0} - config shard; - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - - def check_chunks_regex(self): - """ - This function return the rgex to search the chunks - """ - self.ocommon.log_info_message("Inside check_chunks_regex()",self.file_name) - return re.compile('CHECK_CHUNKS') - - def cancel_move_chunks(self): - """ - This function cancel the shard Chunks - """ - self.ocommon.log_info_message("Inside check_shard_chunks()",self.file_name) - status=False - reg_exp= self.cancel_chunks_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - move_chunks_status=None - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - online_shard = self.check_online_shard(shard_name) - if online_shard == 1: - self.ocommon.log_info_message("Shard is not online. Performing chunk cancellation in GSM to set the shard chunk status.",self.file_name) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - ALTER MOVE -cancel -SHARD {0} - config shard; - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - else: - self.ocommon.log_info_message("Shard " + shard_name + " is online. Unable to perform chunk cancellation.",self.file_name) - - def cancel_chunks_regex(self): - """ - This function return the cancel chunk movement - """ - self.ocommon.log_info_message("Inside cancel_chunks_regex()",self.file_name) - return re.compile('CANCEL_CHUNKS') - - def verify_online_shard(self): - """ - This function verify online shard - """ - self.ocommon.log_info_message("Inside verify_online_shard()",self.file_name) - status=False - reg_exp= self.online_shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - online_shard = self.check_online_shard(shard_name) - if online_shard == 0: - msg='''Shard {0} is online.'''.format(shard_name) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Shard {0} is not online.'''.format(shard_name) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.prog_exit("157") - - - def online_shard_regex(self): - """ - This function return the rgex to search the ONLINE Shards - """ - self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) - return re.compile('CHECK_ONLINE_SHARD') - - def check_online_shard(self,shard_name): - """ - This function check the online shard - """ - self.ocommon.log_info_message("Inside check_online_shard()",self.file_name) - name_flag = False - availability_flag = False - state_flag = False - status_flag = False - - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - config shard -shard {0}; - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - lines = output.split("\n") - for line in lines: - list1 = line.split(":") - if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): - name_flag = True - if list1[0].strip().lower() == 'Availability'.lower() and list1[1].strip().lower() == 'ONLINE'.lower(): - availability_flag = True - if list1[0].strip().lower() == 'STATUS'.lower() and list1[1].strip().lower() == 'OK'.lower(): - status_flag = True - if list1[0].strip().lower() == 'STATE'.lower() and list1[1].strip().lower() == 'DEPLOYED'.lower(): - state_flag = True - - del list1[:] - - if name_flag and availability_flag and state_flag and status_flag: - return 0 - else: - return 1 - - def verify_gsm_shard(self): - """ - This function verify GSM shard - """ - self.ocommon.log_info_message("Inside verify_gsm_shard()",self.file_name) - status=False - reg_exp= self.check_shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb=self.process_chunks_vars(key) - shard_name = '''{0}_{1}'''.format(shard_db,shard_pdb) - gsm_shard = self.check_gsm_shard(shard_name) - if gsm_shard == 0: - msg='''Shard {0} is present in GSM.'''.format(shard_name) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Shard {0} is not present in GSM.'''.format(shard_name) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.prog_exit("157") - - def check_shard_regex(self): - """ - This function return the rgex to search the Shards in GSM - """ - self.ocommon.log_info_message("Inside online_shard_regex()",self.file_name) - return re.compile('CHECK_GSM_SHARD') - - def check_gsm_shard(self,shard_name): - """ - This function check the shard in gsm - """ - self.ocommon.log_info_message("Inside check_gsm_shard()",self.file_name) - name_flag = False - - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - config shard -shard {0}; - exit; - '''.format(shard_name,cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - lines = output.split("\n") - for line in lines: - list1 = line.split(":") - if list1[0].strip() == 'Name' and list1[1].strip().lower() == shard_name.lower(): - name_flag = True - - del list1[:] - - if name_flag: - return 0 - else: - return 1 - - def count_online_shards(self): - """ - This function return the returns the count of online shard - """ - self.ocommon.log_info_message("Inside count_online_shards()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {0}/{1}; - config shard; - exit; - '''.format(cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - online_shard = 0 - lines = output.split("\n") - for line in lines: - if re.search('ok', line, re.IGNORECASE): - if re.search('deployed', line, re.IGNORECASE): - if re.search('online', line, re.IGNORECASE): - online_shard = online_shard + 1 - - return online_shard - - def get_online_shards(self): - """ - This function return the returns the count of online shard - """ - self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {0}/{1}; - config shard; - exit; - '''.format(cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - shards=[] - online_shard = 0 - for line in output.split("\n"): - cols=line.split() - print(cols) - if len(cols) >= 5: - if cols[5].lower() == "online" and cols[2].lower() == "ok": - shards.append(cols[0]) - - return shards - - def get_rus(self,shardname_to_delete): - """ - This function return the returns the count of online shard - """ - self.ocommon.log_info_message("Inside get_online_shards()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - cmd=None - if shardname_to_delete is not None: - cmd='''status ru -leaders -shard {0}'''.format(shardname_to_delete) - else: - cmd='''status ru''' - - gsmcmd=''' - connect {0}/{1}; - {2}; - exit; - '''.format(cadmin,cpasswd,cmd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - return output.split('\n') - - def move_shard_rus(self,sshard,tshard,runum): - """ - This function move the shard rus - """ - self.ocommon.log_info_message("Inside move_shard_rus()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - cmd1="" - cmd2="" - shardname=sshard - if tshard is not None and runum is not None: - cmd1='''switchover ru -RU {0} -shard {1}'''.format(runum,tshard) - else: - cmd1='''MOVE RU -RU ALL -SOURCE {0}'''.format(shardname) - - gsmcmd=''' - connect {1}/{2}; - configure -verbose off -save_config; - {3}; - status RU -shard {0}; - exit; - '''.format(shardname,cadmin,cpasswd,cmd1,cmd2) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def count_shard_rus(self,shardname): - """ - This function return the returns the count of online shard chunks - """ - self.ocommon.log_info_message("Inside count_shard_chunks()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {0}/{1}; - status ru -shard {2}; - exit; - '''.format(cadmin,cpasswd,shardname) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - ru_count = 0 - lines = output.split("\n") - for line in lines: - if re.search(shardname, line, re.IGNORECASE): - ru_count = ru_count + 1 - - return ru_count - - def count_leader_shards(self,shardName): - """ - This function return the returns the count of online shard - """ - self.ocommon.log_info_message("Inside count_leader_shards()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {0}/{1}; - status ru -shard {2} -leaders; - exit; - '''.format(cadmin,cpasswd,shardName) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - leader_shard = 0 - lines = output.split("\n") - for line in lines: - if re.search('ok', line, re.IGNORECASE): - if re.search('Leader', line, re.IGNORECASE): - leader_shard = leader_shard + 1 - - return leader_shard - - def validate_gsm_shard(self): - """ - This function validate the shard in the GSM - """ - self.ocommon.log_info_message("Inside validate_gsm_shard()",self.file_name) - status=False - reg_exp= self.validate_shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) - shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) - status = self.check_shard_status(shard_name) - if status == 'completed': - msg='''Shard DB setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Shard {0} info does not exist in GSM.'''.format(shard_name) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.prog_exit("157") - - def process_shard_vars(self,key): - """ - This function process sgard vars based on key and return values to configure the GSM - """ - shard_db=None - shard_pdb=None - shard_port=None - shard_group=None - shard_host=None - shard_region=None - shard_space=None - shard_deploy_as=None - - self.ocommon.log_info_message("Inside process_shard_vars()",self.file_name) - # self.ocommon.log_info_message(key,self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_str=cvar_str.replace('"', '') - # self.ocommon.log_info_message(cvar_str,self.file_name) - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - # self.ocommon.log_info_message("key : " + ckey,self.file_name) - # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) - if ckey == 'shard_db': - shard_db = cvar_dict[ckey] - if ckey == 'shard_pdb': - shard_pdb = cvar_dict[ckey] - if ckey == 'shard_port': - shard_port = cvar_dict[ckey] - if ckey == 'shard_group': - shard_group = cvar_dict[ckey] - if ckey == 'shard_host': - shard_host = cvar_dict[ckey] - if ckey == 'shard_region': - #shard_region = self.validate_shard_param("region",cvar_dict[ckey]) - shard_region=cvar_dict[ckey] - if ckey == 'deploy_as': - shard_deploy_as=cvar_dict[ckey] - if ckey == 'shard_space': - #shard_space = self.validate_shard_param("shardspace",cvar_dict[ckey]) - shard_space=cvar_dict[ckey] - # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) - ## Set the values if not set in above block - if not shard_port: - shard_port=1521 - - if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': - shard_group="nogrp" - if not shard_deploy_as: - self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS","primary",self.ora_env_dict) - else: - self.ora_env_dict=self.ocommon.add_key("SHARD_DEPLOY_AS",shard_deploy_as,self.ora_env_dict) - - ### Check values must be set - if shard_host and shard_db and shard_pdb and shard_port and shard_group: - return shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space - else: - msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) - msg2='''shard_port={0},shard_host={1}'''.format((shard_port or "Missing Value"),(shard_host or "Missing Value")) - msg3='''shard_group={0}'''.format((shard_group or "Missing Value")) - msg='''Shard DB params {0} is not set correctly. One or more value is missing {1} {2} {3}'''.format(key,msg1,msg2,msg3) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.prog_exit("Error occurred") - - def validate_shard_param(self,param_type,value): - """ - This function validaet the shard param such as region and shardspace - """ - status=False - reg_exp= self.catalog_regex() - stype=None - sspace=None - catalog_region=None - self.ocommon.log_info_message("Processing GSM params to verify the region and shardspace",self.file_name) - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - - if param_type == 'region': - if stype: - status=self.ocommon.find_str_in_string(catalog_region,'comma',value) - if status: - - return value - else: - return "" - - if param_type == 'shardspace': - if sspace: - status=self.ocommon.find_str_in_string(sspace,'comma',value) - if status: - return value - else: - return "" - - return False - - def process_chunks_vars(self,key): - """ - This function process the chunks vars - """ - shard_db=None - shard_pdb=None - self.ocommon.log_info_message("Inside process_chunks_vars()",self.file_name) - # self.ocommon.log_info_message(key,self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_str=cvar_str.replace('"', '') - # self.ocommon.log_info_message(cvar_str,self.file_name) - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - # self.ocommon.log_info_message("key : " + ckey,self.file_name) - # self.ocommon.log_info_message("Value: " + cvar_dict[ckey],self.file_name) - if ckey == 'shard_db': - shard_db = cvar_dict[ckey] - if ckey == 'shard_pdb': - shard_pdb = cvar_dict[ckey] - # # self.ocommon.log_info_message("shard_host: " + shard_host, self.file_name) - ## Set the values if not set in above block - - ### Check values must be set - if shard_pdb and shard_db: - return shard_db,shard_pdb - else: - msg1='''shard_db={0},shard_pdb={1}'''.format((shard_db or "Missing Value"),(shard_pdb or "Missing Value")) - self.ocommon.log_info_message(msg1,self.file_name) - self.ocommon.prog_exit("Error occurred") - - def check_shard_status(self,shard_name): - """ - This function check the shard status in GSM - """ - self.ocommon.log_info_message("Inside check_shard_status()",self.file_name) - #gsmcmd=self.get_gsm_config_cmd(dname) - gsmcmd=''' - config; - exit; - ''' - counter=1 - end_counter=3 - status=False - while counter < end_counter: - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - error_check=re.findall("(?:GSM-45034\n)(?:.+\n)+",output) - try: - if self.ocommon.check_substr_match(error_check[0],"GSM-45034"): - count = counter + 1 - self.ocommon.log_info_message("Issue in catalog connection, retrying to connect to catalog in 30 seconds!",self.file_name) - time.sleep(20) - status=False - continue - except: - status=False - matched_output=re.findall("(?:Databases\n)(?:.+\n)+",output) - if shard_name: - try: - if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): - status=True - break - else: - status=False - except: - status=False - else: - reg_exp= self.shard_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb,shard_port,shard_region,shard_host,shard_region,shard_space=self.process_shard_vars(key) - shard_name='''{0}_{1}'''.format(shard_db,shard_pdb) - try: - if self.ocommon.check_substr_match(matched_output[0],shard_name.lower()): - status=True - else: - status=False - except: - status=False - if status: - break; - counter = counter + 1 - - return(self.ocommon.check_status_value(status)) - - def shard_regex(self): - """ - This function return the rgex to search the SHARD PARAMS - """ - self.ocommon.log_info_message("Inside shard_regex()",self.file_name) - return re.compile('SHARD[0-9]+_PARAMS') - - def add_shard_regex(self): - """ - This function return the rgex to search the ADD_SHARD_PARAMS - """ - self.ocommon.log_info_message("Inside add_shard_regex()",self.file_name) - return re.compile('ADD_SHARD') - - def remove_shard_regex(self): - """ - This function return the rgex to search the REMOVE_SHARD_PARAMS - """ - self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) - return re.compile('REMOVE_SHARD') - - def validate_shard_regex(self): - """ - This function return the rgex to search the VALIDATE_SHARD_PARAMS - """ - self.ocommon.log_info_message("Inside remove_shard_regex()",self.file_name) - return re.compile('VALIDATE_SHARD') - - def configure_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup,sregion,sspace): - """ - This function configure the shard db. - """ - spasswd="HIDDEN_STRING" - admuser= self.ora_env_dict["SHARD_ADMIN_USER"] - #dtrname,dtrport,dtregion=self.process_director_vars() - #group_region=self.get_shardg_region_name(sgroup) - #dtrname=self.get_director_name(group_region) - shard_name='''{0}_{1}'''.format(scdb,spdb) - shard_region=None - shard_space=None - shard_group=None - deploy_as=None - - if sregion: - regionFlag=self.check_gsm_region(sregion) - if regionFlag != 'completed': - self.configure_gsm_region(sregion) - shard_region=" -region {0}".format(sregion) - else: - shard_region="" - if sspace: - shard_space=" -shardspace {0}".format(sspace) - else: - shard_space="" - - if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': - sspaceFlag=self.check_gsm_shardspace(sspace) - if sspaceFlag != 'completed': - self.configure_gsm_sspace(sspace,None,None,None,None,'add') - shard_group="" - deploy_as,deploy_type=self.get_shard_deploy() - else: - shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) - shard_region="" - else: - shard_group,deploy_as=self.get_shardg_cmd(sgroup,sregion) - shard_region="" - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - add cdb -connect {3}:{4}/{5} -pwd {2}; - add shard -cdb {5} -connect "(DESCRIPTION = (ADDRESS = (PROTOCOL = tcp)(HOST = {3})(PORT = {4})) (CONNECT_DATA = (SERVICE_NAME = {6}) (SERVER = DEDICATED)))" {7} -pwd {2} {9} {10} {11}; - config vncr; - exit; - '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,shard_group,shard_name,shard_region,shard_space,deploy_as) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def get_shard_deploy(self): - """ - get the shard deploy - """ - deploy_as=None - deploy_type=None - if self.ocommon.check_key("SHARD_DEPLOY_AS",self.ora_env_dict): - deploy_as="-deploy_as {0}".format(self.ora_env_dict["SHARD_DEPLOY_AS"]) - deploy_type=self.ora_env_dict["SHARD_DEPLOY_AS"] - else: - deploy_as="-deploy_as primary" - deploy_type='primary' - - return deploy_as,deploy_type - - def get_shardg_cmd(self,sgroup,sregion): - """ - Getting shard group cmd - """ - sgFlag=self.check_shardg_status(sgroup,None) - deploy_as,deploy_type=self.get_shard_deploy() - if sgFlag != 'completed': - self.configure_gsm_shardg(sgroup,deploy_type,sregion,'add') - else: - self.ocommon.log_info_message("Shardgroup exist " + sgroup, self.file_name) - - deploy_as="" - cmd=''' -shardgroup {0}'''.format(sgroup) - return cmd,deploy_as - - def delete_gsm_shard(self,shost,scdb,spdb,sdbport,sgroup): - """ - This function delete the shard db. - """ - spasswd="HIDDEN_STRING" - admuser= self.ora_env_dict["SHARD_ADMIN_USER"] - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - shard_name='''{0}_{1}'''.format(scdb,spdb) - #group_region=self.get_shardg_region_name(sgroup) - #dtrname=self.get_director_name(group_region) - gsmcmd=''' - connect {1}/{2}; - remove shard -shard {8}; - remove cdb -cdb {5}; - remove invitednode {3}; - config vncr; - exit; - '''.format("NA",admuser,spasswd,shost,sdbport,scdb,spdb,sgroup,shard_name) - - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def set_hostid_null(self): - """ - This function set the hostid to Null - """ - spasswd="HIDDEN_STRING" - admuser= self.ora_env_dict["SHARD_ADMIN_USER"] - reg_exp= self.catalog_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_pdb,admuser) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Setting host Id null in catalog as auto vncr is disabled''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set echo on - set termout on - set time on - update gsmadmin_internal.database set hostid=NULL; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - self.ocommon.unset_mask_str() - - def invited_node_op(self): - """ - This function perform the invitedaddition and deletion - """ - self.ocommon.log_info_message("Inside invited_node_op()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - shard_host=self.ora_env_dict["INVITED_NODE_OP"] - gsmcmd=''' - connect {1}/{2}; - remove invitednode {3}; - add invitednode {3}; - exit; - '''.format("NA",cadmin,cpasswd,shard_host) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - def add_invited_node(self,op_str): - """ - This function add the invited in the GSM configuration - """ - self.ocommon.log_info_message("Inside add_invited_node()",self.file_name) - if op_str == "SHARD": - reg_exp = self.shard_regex() - else: - reg_exp = self.add_shard_regex() - - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) - #group_region=self.get_shardg_region_name(shard_group) - #dtrname=self.get_director_name(group_region) - gsmcmd=''' - connect {1}/{2}; - add invitednode {3}; - exit; - '''.format("NA",cadmin,cpasswd,shard_host) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - def remove_invited_node(self,op_str): - """ - This function remove the invited in the GSM configuration - """ - self.ocommon.log_info_message("Inside remove_invited_node()",self.file_name) - if op_str == "SHARD": - reg_exp = self.shard_regex() - else: - reg_exp = self.add_shard_regex() - - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - - if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_db,shard_pdb,shard_port,shard_group,shard_host,shard_region,shard_space=self.process_shard_vars(key) - temp_host= shard_host.split('.',1)[0] - #group_region=self.get_shardg_region_name(shard_group) - #dtrname=self.get_director_name(group_region) - gsmcmd=''' - connect {1}/{2}; - remove invitednode {3}; - exit; - '''.format("NA",cadmin,cpasswd,temp_host) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - else: - self.ocommon.log_info_message("KUBE_SVC is not set. No need to remove invited node!",self.file_name) - - - def deploy_shard(self): - """ - This function deploy shard - """ - self.ocommon.log_info_message("Inside deploy_shard()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - shrdg_sspace=None - #dtrname,dtrport,dtregion=self.process_director_vars() - #if op_str == "SHARD": - # reg_exp = self.shard_regex() - #else: - # reg_exp = self.add_shard_regex() - - #for key in self.ora_env_dict.keys(): - # if(reg_exp.match(key)): - if self.ocommon.check_key("SHARDING_TYPE",self.ora_env_dict): - if self.ora_env_dict["SHARDING_TYPE"].upper() == 'USER': - shardg_shardspace="config shardspace" - else: - shardg_shardspace="config shardgroup" - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - {3}; - config vncr; - deploy; - config shard; - exit; - '''.format("test",cadmin,cpasswd,shardg_shardspace) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def check_setup_status(self,host,ccdb,svc,port): - """ - This function check the shard status. - """ - systemStr='''{0}/bin/sqlplus "system/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,ccdb) - - fname='''/tmp/{0}'''.format("shard_setup.txt") - self.ocommon.remove_file(fname) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Checking shardsetup table in CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - set term off - SET NEWPAGE NONE - spool {0} - select * from shardsetup WHERE ROWNUM = 1; - spool off - exit; - '''.format(fname) - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - - if os.path.isfile(fname): - fdata=self.ocommon.read_file(fname) - else: - fdata='nosetup' - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - if re.search('completed',fdata): - status = self.catalog_pdb_setup_check(host,ccdb,svc,port) - if status == 'completed': - return 'completed' - else: - return 'notcompleted' - else: - return 'notcompleted' - - - def catalog_pdb_setup_check(self,host,ccdb,svc,port): - """ - This function check the shard status. - """ - systemStr='''{0}/bin/sqlplus "pdbadmin/HIDDEN_STRING@{1}:{2}/{3}"'''.format(self.ora_env_dict["ORACLE_HOME"],host,port,svc) - - fname='''/tmp/{0}'''.format("pdb_setup_check.txt") - self.ocommon.remove_file(fname) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Checking setup status in PDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - set term off - SET NEWPAGE NONE - spool {0} - select count(*) from dual; - spool off - exit; - '''.format(fname) - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - - if os.path.isfile(fname): - fdata=self.ocommon.read_file(fname) - else: - fdata='nosetup' - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - if re.search('1',fdata): - return 'completed' - else: - return 'notcompleted' - - ############################# Setup GSM Service ############################################### - def setup_gsm_service(self): - """ - This function setup the shard service. - """ - self.ocommon.log_info_message("Inside setup_gsm_service()",self.file_name) - status=False - service_value="service_name=oltp_rw_svc;service_role=primary" - # self.ora_env_dict=self.ocommon.add_key("SERVICE1_PARAMS",service_value,self.ora_env_dict) - reg_exp= self.service_regex() - counter=1 - end_counter=3 - while counter < end_counter: - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - shard_service_status=None - service_name,service_role=self.process_service_vars(key) - shard_service_status=self.check_service_status(service_name) - if shard_service_status != 'completed': - self.configure_gsm_service(service_name,service_role) - status = self.check_service_status(None) - if status == 'completed': - break - else: - msg='''GSM service setup is still not completed in GSM. Sleeping for 60 seconds and sleeping count is {0}'''.format(counter) - time.sleep(60) - counter=counter+1 - - status = self.check_service_status(None) - if status == 'completed': - msg='''Shard service setup completed in GSM''' - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''Waited 2 minute to complete catalog setup in GSM but setup did not complete or failed. Exiting...''' - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("127") - - def process_service_vars(self,key): - """ - This function process shardG vars based on key and return values to configure the GSM - """ - service_name=None - service_role=None - - self.ocommon.log_info_message("Inside process_service_vars()",self.file_name) - cvar_str=self.ora_env_dict[key] - cvar_dict=dict(item.split("=") for item in cvar_str.split(";")) - for ckey in cvar_dict.keys(): - if ckey == 'service_name': - service_name = cvar_dict[ckey] - if ckey == 'service_role': - service_role = cvar_dict[ckey] - - ### Check values must be set - if service_name and service_role: - return service_name,service_role - else: - msg1='''service_name={0},service_role={1}'''.format((service_name or "Missing Value"),(service_role or "Missing Value")) - msg='''Shard service params {0} is not set correctly. One or more value is missing {1} {2}'''.format(key,msg1) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit("Error occurred") - - def check_service_status(self,service_name): - """ - This function check the shard status in GSM - """ - self.ocommon.log_info_message("Inside check_service_status()",self.file_name) - #dtrname,dtrport,dtregion=self.process_director_vars() - gsmcmd=''' - config; - exit; - '''.format("test") - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - matched_output=re.findall("(?:Services\n)(?:.+\n)+",output) - status=False - if service_name: - try: - if self.ocommon.check_substr_match(matched_output[0],service_name): - status=True - else: - status=False - except: - status=False - else: - reg_exp= self.service_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - service_name,service_role=self.process_service_vars(key) - # match=re.search("(?i)(?m)"+service_name,matched_output) - try: - if self.ocommon.check_substr_match(matched_output[0],service_name): - status=True - else: - status=False - except: - status=False - - return(self.ocommon.check_status_value(status)) - - def service_regex(self): - """ - This function return the rgex to search the SERVICE[0-9]_PARAMS - """ - self.ocommon.log_info_message("Inside service_regex()",self.file_name) - return re.compile('SERVICE[0-9]+_PARAMS') - - def configure_gsm_service(self,service_name,service_role): - """ - This function configure the service creation. - """ - self.ocommon.log_info_message("Inside configure_gsm_service()",self.file_name) - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmlogin='''{0}/bin/gdsctl'''.format(self.ora_env_dict["ORACLE_HOME"]) - gsmcmd=''' - connect {1}/{2}; - add service -service {3} -role {4}; - start service -service {3}; - exit; - '''.format("test",cadmin,cpasswd,service_name,service_role) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - ############################## GSM backup fIle function Begins Here ############################# - def gsm_backup_file(self): - """ - This function check the gsm setup status - """ - self.ocommon.log_info_message("Inside gsm_backup_file()",self.file_name) - gsmdata_loc='/opt/oracle/gsmdata' - gsmfile_loc='''{0}/network/admin'''.format(self.ora_env_dict["ORACLE_HOME"]) - - if os.path.isdir(gsmdata_loc): - msg='''Directory {0} exit'''.format(gsmdata_loc) - self.ocommon.log_info_message(msg,self.file_name) - - cmd='''cp -r -v {0}/* {1}/'''.format(gsmfile_loc,gsmdata_loc) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - ############### Deploy Sample Function Begins Here ########################## - def setup_sample_schema(self): - """ - This function deploy the sample app - """ - s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?" - passlen = 8 - passwd = "".join(random.sample(s,passlen )) - self.ocommon.log_info_message("Inside deploy_sample_schema()",self.file_name) - reg_exp= self.catalog_regex() - for key in self.ora_env_dict.keys(): - if(reg_exp.match(key)): - catalog_db,catalog_pdb,catalog_port,catalog_region,catalog_host,catalog_name,catalog_chunks,repl_type,repl_factor,repl_unit,stype,sspace,cfname=self.process_clog_vars(key) - sqlpluslogin='''{0}/bin/sqlplus "sys/HIDDEN_STRING@{1}:{2}/{3} as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"],catalog_host,catalog_port,catalog_db) - if self.ocommon.check_key("SAMPLE_SCHEMA",self.ora_env_dict): - if self.ora_env_dict["SAMPLE_SCHEMA"] == 'DEPLOY': - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Deploying sample schema''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set echo on - set termout on - set time on - spool /tmp/create_app_schema.lst - REM - REM Connect to the Shard Catalog and Create Schema - REM - alter session enable shard ddl; - alter session set container={2}; - alter session enable shard ddl; - create user app_schema identified by {3}; - grant connect, resource, alter session to app_schema; - grant execute on dbms_crypto to app_schema; - grant create table, create procedure, create tablespace, create materialized view to app_schema; - grant unlimited tablespace to app_schema; - grant select_catalog_role to app_schema; - grant all privileges to app_schema; - grant gsmadmin_role to app_schema; - grant dba to app_schema; - CREATE TABLESPACE SET tbsset1 IN SHARDSPACE shd1; - CREATE TABLESPACE SET tbsset2 IN SHARDSPACE shd2; - connect app_schema/{3}@{0}:{1}/{2} - alter session enable shard ddl; - - /* Customer shard table */ - - CREATE SHARDED TABLE customer - ( cust_id NUMBER NOT NULL, - cust_passwd VARCHAR2(20) NOT NULL, - cust_name VARCHAR2(60) NOT NULL, - cust_type VARCHAR2(10) NOT NULL, - cust_email VARCHAR2(100) NOT NULL) - partitionset by list (cust_type) - partition by consistent hash (cust_id) partitions auto - (partitionset individual values ('individual') tablespace set tbsset1, - partitionset business values ('business') tablespace set tbsset2 - ); - /* Invoice shard table */ - - CREATE SHARDED TABLE invoice - ( invoice_id NUMBER NOT NULL, - cust_id NUMBER NOT NULL, - cust_type VARCHAR2(10) NOT NULL, - vendor_name VARCHAR2(60) NOT NULL, - balance FLOAT(10) NOT NULL, - total FLOAT(10) NOT NULL, - status VARCHAR2(20), - CONSTRAINT InvoicePK PRIMARY KEY (cust_id, invoice_id)) - PARENT customer - partitionset by list (cust_type) - partition by consistent hash (cust_id) partitions auto - (partitionset individual values ('individual') tablespace set tbsset1, - partitionset business values ('business') tablespace set tbsset2 - ); - /* Data */ - insert into customer values (999, 'pass', 'Customer 999', 'individual', 'customer999@gmail.com'); - insert into customer values (250251, 'pass', 'Customer 250251', 'individual', 'customer250251@yahoo.com'); - insert into customer values (350351, 'pass', 'Customer 350351', 'individual', 'customer350351@gmail.com'); - insert into customer values (550551, 'pass', 'Customer 550551', 'business', 'customer550551@hotmail.com'); - insert into customer values (650651, 'pass', 'Customer 650651', 'business', 'customer650651@live.com'); - insert into invoice values (1001, 999, 'individual', 'VendorA', 10000, 20000, 'Due'); - insert into invoice values (1002, 999, 'individual', 'VendorB', 10000, 20000, 'Due'); - insert into invoice values (1001, 250251, 'individual', 'VendorA', 10000, 20000, 'Due'); - insert into invoice values (1002, 250251, 'individual', 'VendorB', 0, 10000, 'Paid'); - insert into invoice values (1003, 250251, 'individual', 'VendorC', 14000, 15000, 'Due'); - insert into invoice values (1001, 350351, 'individual', 'VendorD', 10000, 20000, 'Due'); - insert into invoice values (1002, 350351, 'individual', 'VendorE', 0, 10000, 'Paid'); - insert into invoice values (1003, 350351, 'individual', 'VendorF', 14000, 15000, 'Due'); - insert into invoice values (1004, 350351, 'individual', 'VendorG', 12000, 15000, 'Due'); - insert into invoice values (1001, 550551, 'business', 'VendorH', 10000, 20000, 'Due'); - insert into invoice values (1002, 550551, 'business', 'VendorI', 0, 10000, 'Paid'); - insert into invoice values (1003, 550551, 'business', 'VendorJ', 14000, 15000, 'Due'); - insert into invoice values (1004, 550551, 'business', 'VendorK', 10000, 20000, 'Due'); - insert into invoice values (1005, 550551, 'business', 'VendorL', 10000, 20000, 'Due'); - insert into invoice values (1006, 550551, 'business', 'VendorM', 0, 10000, 'Paid'); - insert into invoice values (1007, 550551, 'business', 'VendorN', 14000, 15000, 'Due'); - insert into invoice values (1008, 550551, 'business', 'VendorO', 10000, 20000, 'Due'); - insert into invoice values (1001, 650651, 'business', 'VendorT', 10000, 20000, 'Due'); - insert into invoice values (1002, 650651, 'business', 'VendorU', 0, 10000, 'Paid'); - insert into invoice values (1003, 650651, 'business', 'VendorV', 14000, 15000, 'Due'); - insert into invoice values (1004, 650651, 'business', 'VendorW', 10000, 20000, 'Due'); - insert into invoice values (1005, 650651, 'business', 'VendorX', 0, 20000, 'Paid'); - insert into invoice values (1006, 650651, 'business', 'VendorY', 0, 30000, 'Paid'); - insert into invoice values (1007, 650651, 'business', 'VendorZ', 0, 10000, 'Paid'); - commit; - select table_name from user_tables; - spool off - '''.format(catalog_host,catalog_port,catalog_pdb,passwd) - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogin,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - gsmhost=self.ora_env_dict["ORACLE_HOSTNAME"] - cadmin=self.ora_env_dict["SHARD_ADMIN_USER"] - cpasswd="HIDDEN_STRING" - #dtrname,dtrport,dtregion=self.process_director_vars() - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - gsmcmd=''' - connect {1}/{2}; - show ddl; - exit; - '''.format("test",cadmin,cpasswd) - output,error,retcode=self.ocommon.exec_gsm_cmd(gsmcmd,None,self.ora_env_dict) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - ###################################### Run custom scripts ################################################## - def run_custom_scripts(self): - """ - Custom script to be excuted on every restart of enviornment - """ - self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): - shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): - shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] - script_file = '''{0}/{1}'''.format(shard_dir,shard_file) - if os.path.isfile(script_file): - msg='''Custom shard script exist {0}'''.format(script_file) - self.ocommon.log_info_message(msg,self.file_name) - cmd='''sh {0}'''.format(script_file) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - ############################### GSM Completion Message ####################################################### - def gsm_completion_message(self): - """ - Funtion print completion message - """ - self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) - msg=[] - msg.append('==============================================') - msg.append(' GSM Setup Completed ') - msg.append('==============================================') - - for text in msg: - self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oralogger.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oralogger.py deleted file mode 100755 index 9a51b54..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oralogger.py +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -""" - This file provides the functionality to log the event in console and file -""" - -import logging -import os - -class LoggingType(object): - CONSOLE = 1 - FILE = 2 - STDOUT = 3 - -class OraLogger(object): - """ - This is a class constructor which sets parameter for logger. - - Attributes: - filename_ (string): Filename which we need to set to store logs in a file. - """ - def __init__(self, filename_): - """ - This is a class constructor which sets parameter for logger. - - Attributes: - filename_ (string): Filename which we need to set to store logs in a file. - """ - self.filename_ = filename_ - # Set to default values can be changed later from other classes objects - self.console_ = LoggingType.CONSOLE - self.file_ = LoggingType.FILE - self.stdout_ = LoggingType.STDOUT - self.msg_ = None - self.functname_ = None - self.lineno_ = None - self.logtype_ = "INFO" - self.fmtstr_ = "%(asctime)s: %(levelname)s: %(message)s" - self.datestr_ = "%m/%d/%Y %I:%M:%S %p" - self.root = logging.getLogger() - self.root.setLevel(logging.DEBUG) - self.formatter = logging.Formatter('%(asctime)s %(levelname)8s:%(message)s', "%m/%d/%Y %I:%M:%S %p") - self.stdoutfile_ = "/proc/1/fd/1" - # self.stdoutfile_ = "/tmp/test.log" - - def getStdOutValue(self): - return self.stdout_ - -class Handler(object): - """ - This is a class which sets the handler for next logger. - """ - def __init__(self): - """ - This is a handler class constructor and nexthandler is set to None. - """ - self.nextHandler = None - - def handle(self, request): - ''' - This is a function which set the next handler. - - Attributes: - request (object): Object of the class oralogger. - ''' - self.nextHandler.handle(request) - - def print_message(self,request,lhandler): - """ - This function set the log type to INFO, WARN, DEBUG and CRITICAL. - - Attribute: - request (object): Object of the class oralogger. - lhandler: This parameter accept the loghandler. - """ - if request.logtype_ == "WARN": - request.root.warning(request.msg_) - elif request.logtype_ == "DEBUG": - request.root.debug(request.msg_) - elif request.logtype_ == "CRITICAL": - request.root.critical(request.msg_) - elif request.logtype_ == "ERROR": - request.root.error(request.msg_) - else: - request.root.info(request.msg_) - - request.root.removeHandler(lhandler) - -class FHandler(Handler): - """ - This is a class which sets the handler for next logger. - """ - def handle(self,request): - """ - This function print the message and call next handler. - - Attribut: - request: Object of OraLogger - """ - if request.file_ == LoggingType.FILE: - fh = logging.FileHandler(request.filename_) - request.root.addHandler(fh) - fh.setFormatter(request.formatter) - self.print_message(request,fh) - super(FHandler, self).handle(request) - else: - super(FHandler, self).handle(request) - - def print_message(self,request,fh): - """ - This function log the message to console/file/stdout. - """ - super(FHandler, self).print_message(request,fh) - -class CHandler(Handler): - """ - This is a class which sets the handler for next logger. - """ - def handle(self,request): - """ - This function print the message and call next handler. - - Attribute: - request: Object of OraLogger - """ - if request.console_ == LoggingType.CONSOLE: - # ch = logging.StreamHandler() - ch = logging.FileHandler("/tmp/test.log") - request.root.addHandler(ch) - ch.setFormatter(request.formatter) - self.print_message(request,ch) - super(CHandler, self).handle(request) - else: - super(CHandler, self).handle(request) - - def print_message(self,request,ch): - """ - This function log the message to console/file/stdout. - """ - super(CHandler, self).print_message(request,ch) - - -class StdHandler(Handler): - """ - This is a class which sets the handler for next logger. - """ - def handle(self,request): - """ - This function print the message and call next handler. - - Attribute: - request: Object of OraLogger - """ - request.stdout_ = request.getStdOutValue() - if request.stdout_ == LoggingType.STDOUT: - st = logging.FileHandler(request.stdoutfile_,mode="w") - request.root.addHandler(st) - st.setFormatter(request.formatter) - self.print_message(request,st) - super(StdHandler, self).handle(request) - else: - super(StdHandler, self).handle(request) - - def print_message(self,request,st): - """ - This function log the message to console/file/stdout. - """ - super(StdHandler, self).print_message(request,st) - -class PassHandler(Handler): - """ - This is a class which sets the handler for next logger. - """ - def handle(self, request): - pass diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oramachine.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oramachine.py deleted file mode 100755 index 2d1431a..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/oramachine.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * - -import os -import sys - -class OraMachine: - """ - This calss setup the compute before starting the installation. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This constructor of OraMachine class to setup the compute - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - - def setup(self): - """ - This function setup the compute before starting the installation - """ - msg="Machine setup completed sucessfully!" - self.ocommon.log_info_message(msg,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapcatalog.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapcatalog.py deleted file mode 100755 index 112f309..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapcatalog.py +++ /dev/null @@ -1,790 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -import os -import sys -import os.path -import re -import socket -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * - -class OraPCatalog: - """ - This calss setup the Catalog after DB installation. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This constructor of OraCatalog class to setup the catalog on primary DB. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - - def setup(self): - """ - This function setup the catalog on Primary DB. - """ - if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): - self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) - if self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): - create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" - exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" - self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) - self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) - if os.path.exists(create_db_file_lck): - self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) - sys.exit(127) - elif os.path.exists(exist_db_file_lck): - self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) - status = self.catalog_setup_check() - if not status: - self.ocommon.prog_exit("127") - self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) - sys.exit(0) - else: - status = self.catalog_setup_check() - if not status: - self.ocommon.prog_exit("127") - self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name) - sys.exit(0) - elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): - status = self.catalog_setup_check() - if not status: - self.ocommon.log_info_message("Catalog readyness check completed sucessfully!",self.file_name) - self.ocommon.prog_exit("127") - elif self.ocommon.check_key("RESET_PASSWORD",self.ora_env_dict): - exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" - if os.path.exists(exist_db_file_lck): - self.ocommon.log_info_message("Catalog database up and running. Resetting password...",self.file_name) - else: - self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to reset password",self.file_name) - self.ocommon.prog_exit("127") - elif self.ocommon.check_key("EXPORT_TDE_KEY",self.ora_env_dict): - exist_db_file_lck=self.ocommon.get_db_lock_location()+ self.ora_env_dict["ORACLE_SID"] + ".exist_lck" - if os.path.exists(exist_db_file_lck): - self.ocommon.log_info_message("Catalog database up and running.",self.file_name) - self.ocommon.export_tde_key(self.ora_env_dict["EXPORT_TDE_KEY"]) - else: - self.ocommon.log_info_message("Catalog doesn't seems to be ready. Unable to export the tde key",self.file_name) - self.ocommon.prog_exit("127") - else: - self.setup_machine() - self.db_checks() - self.reset_catalog_setup() - status = self.catalog_setup_check() - if status: - self.ocommon.log_info_message("catalog Setup is already completed on this database",self.file_name) - else: - self.reset_passwd() - self.setup_cdb_catalog() - self.set_spfile_nonm_params() - self.ocommon.set_events("spfile") - self.set_dbparams_version() - self.restart_db() - self.restart_for_db_unique_name() - self.create_pdb() - self.alter_db() - self.setup_pdb_catalog() - self.set_primary_listener() - self.restart_listener() - self.register_services() - self.list_services() - self.backup_files() - self.update_catalog_setup() - self.gsm_completion_message() - self.run_custom_scripts() - ########### SETUP_MACHINE begins here #################### - ## Function to machine setup - def setup_machine(self): - """ - This function performs the compute before performing setup - """ - self.omachine.setup() - - ########### SETUP_MACHINE ENDS here #################### - - ########### DB_CHECKS Related Functions Begin Here #################### - ## Function to perfom DB checks ###### - def db_checks(self): - """ - This function perform db checks before starting the setup - """ - self.ohome_check() - self.passwd_check() - self.set_user() - self.sid_check() - self.dbunique_name_check() - self.hostname_check() - self.dbport_check() - self.dbr_dest_checks() - self.dpump_dir_checks() - - def ohome_check(self): - """ - This function performs the oracle home related checks - """ - if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): - self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) - else: - self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) - self.ocommon.prog_exit() - - if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): - msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit() - - def passwd_check(self): - """ - Function to set the password - """ - self.ocommon.get_password(None) - if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): - msg='''ORACLE_PWD key is set. Check Passed!''' - self.ocommon.log_info_message(msg,self.file_name) - - def set_user(self): - """ - This funnction set the user for pdb and cdb. - """ - if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): - msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) - msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" - self.ocommon.log_info_message(msg,self.file_name) - - if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): - msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) - msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." - self.ocommon.log_info_message(msg,self.file_name) - - def sid_check(self): - """ - This funnction heck and set the SID for cdb and PDB. - """ - if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): - msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg="ORACLE_SID is not set, existing!" - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit() - - def dbunique_name_check(self): - """ - This funnction check and set the db unique name for standby - """ - if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): - msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) - self.ocommon.log_info_message(msg,self.file_name) - - msg='''Setting the Flag to restart the DB to set DB_UNIQUE_NAME to {0}! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) - self.ocommon.log_info_message(msg,self.file_name) - restart_db_to_set_db_unique_name='true' - self.ora_env_dict=self.ocommon.add_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",restart_db_to_set_db_unique_name,self.ora_env_dict) - else: - msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" - self.ocommon.log_info_message(msg,self.file_name) - dbsid=self.ora_env_dict["ORACLE_SID"] - self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) - - - def hostname_check(self): - """ - This function check and set the hostname. - """ - if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): - msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): - # hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) - hostname='''{0}'''.format(socket.getfqdn()) - else: - hostname='''{0}'''.format(socket.gethostname()) - msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) - self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) - self.ocommon.log_info_message(msg,self.file_name) - - def dbport_check(self): - """ - This funnction checks and set the SID for cdb and PDB. - """ - if self.ocommon.check_key("DB_PORT",self.ora_env_dict): - msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) - msg="DB_PORT is not set, setting default to 1521" - self.ocommon.log_info_message(msg,self.file_name) - - def dbr_dest_checks(self): - """ - This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. - """ - if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): - msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) - self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) - msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) - - # Checking the DB_RECOVERY_FILE_DEST_SIZE - - if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): - msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) - msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") - self.ocommon.log_info_message(msg,self.file_name) - - # Checking the DB_CREATE_FILE_DEST - - if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): - msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) - self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) - msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) - - - def dpump_dir_checks(self): - """ - This funnction checks and set the DATA_PUMP dir and location. - """ - if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): - msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) - self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) - msg='''DATA_PUMP_DIR set to {0}'''.format(dest) - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) - - ########### DB_CHECKS Related Functions Begin Here #################### - - - ########## RESET_PASSWORD function Begin here ############################# - ## Function to perform password reset - def reset_passwd(self): - """ - This function reset the password. - """ - self.ocommon.reset_passwd() - - ########## RESET_PASSWORD function ENDS here ############################# - - ########## SETUP_CDB_catalog FUNCTION BEGIN HERE ############################### - - def reset_catalog_setup(self): - """ - This function drop teh catalog setup table and reste the env to default values. - """ - # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) - # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Inside reset_catalog_setup",self.file_name) - catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) - if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): - if self.ora_env_dict["RESET_ENV"]: - if not os.path.isfile(catalog_reset_file): - msg='''Dropping catalogsetup table from CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - drop table system.shardsetup; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - else: - msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(catalog_reset_file) - self.ocommon.log_info_message(msg,self.file_name) - - - def catalog_setup_check(self): - """ - This function check the catalog status. - """ - #systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - msg='''Checking shardsetup table in CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - set term off - SET NEWPAGE NONE - spool /tmp/catalog_setup.txt - select * from system.shardsetup WHERE ROWNUM = 1; - spool off - exit; - ''' - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - fname='''/tmp/{0}'''.format("catalog_setup.txt") - fdata=self.ocommon.read_file(fname) - ### Unsetting the encrypt value to None - # self.ocommon.unset_mask_str() - - if re.search('completed',fdata): - return True - else: - return False - - def setup_cdb_catalog(self): - """ - This function setup the catalog. - """ - #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - # Assigning variable - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] - dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] - host_name=self.ora_env_dict["ORACLE_HOSTNAME"] - dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] - db_port=self.ora_env_dict["DB_PORT"] - ohome=self.ora_env_dict["ORACLE_HOME"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Setting up catalog CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set db_create_file_dest=\"{0}\" scope=both; - alter system set db_recovery_file_dest_size={1} scope=both; - alter system set db_recovery_file_dest=\"{2}\" scope=both; - alter user gsmcatuser account unlock; - alter user gsmcatuser identified by HIDDEN_STRING; - alter system set local_listener='{4}:{5}' scope=both; - alter system set db_unique_name='{8}' scope=spfile; - '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def set_spfile_nonm_params(self): - """ - This function setup the catalog. - """ - #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): - if self.ora_env_dict["CLONE_DB"] != 'true': - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - msg='''Setting up catalog CDB with spfile non modifiable parameters''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set open_links_per_instance=16 scope=spfile; - alter system set db_file_name_convert='*','{0}/' scope=spfile; - alter system set standby_file_management='AUTO' scope=spfile; - alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; - alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; - '''.format(dbf_dest,obase,"dbconfig",dbuname) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - - def set_dbparams_version(self): - """ - This function setup the shard parameter based on db version. - """ - ohome1=self.ora_env_dict["ORACLE_HOME"] - version=self.ocommon.get_oraversion(ohome1).strip() - self.ocommon.log_info_message(version,self.file_name) - if int(version) > 21: - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set wallet_root=\"{1}/oradata/{2}/{3}\" scope=spfile; - '''.format(dbf_dest,obase,"dbconfig",dbuname) - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - def restart_db(self): - """ - restarting the db - """ - if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): - if self.ora_env_dict["CLONE_DB"] != 'true': - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) - self.ocommon.shutdown_db(self.ora_env_dict) - self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) - self.ocommon.start_db(self.ora_env_dict) - - #self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) - #sqlcmd=''' - # alter database archivelog; - # alter database open; - #''' - #output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - #self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - #self.ocommon.check_sql_err(output,error,retcode,True) - - def restart_for_db_unique_name(self): - """ - restarting the db, when db_unique_name is passed explicitly - """ - if self.ocommon.check_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",self.ora_env_dict): - if self.ora_env_dict["RESTART_DB_TO_SET_DB_UNIQUE_NAME"] == 'true': - msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Restarting the Database to set the DB_UNIQUE_NAME! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) - self.ocommon.log_info_message(msg,self.file_name) - - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) - self.ocommon.shutdown_db(self.ora_env_dict) - self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) - self.ocommon.start_db(self.ora_env_dict) - - - def create_pdb(self): - """ - This function creates the PDB - """ - inst_sid=self.ora_env_dict["ORACLE_SID"] - ohome=self.ora_env_dict["ORACLE_HOME"] - if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): - self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) - opdb=self.ora_env_dict["ORACLE_PDB"] - status=self.ocommon.check_pdb(opdb) - if not status: - self.ocommon.create_pdb(ohome,opdb,inst_sid) - self.ocommon.create_pdb_tns_entry(ohome,opdb) - - def alter_db(self): - """ - Alter db - """ - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) - sqlcmd=''' - alter database flashback on; - alter database force logging; - ALTER PLUGGABLE DATABASE ALL OPEN; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - - def setup_pdb_catalog(self): - """ - This function setup the catalog. - """ - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - # Assigning variable - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): - msg='''Setting up catalog PDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter pluggable database {0} close immediate; - alter pluggable database {0} open services=All; - ALTER PLUGGABLE DATABASE {0} SAVE STATE; - alter system register; - alter session set container={0}; - create user {1} identified by HIDDEN_STRING; - alter user {1} account unlock; - grant connect, create session, gsmadmin_role to {1}; - grant inherit privileges on user SYS to GSMADMIN_INTERNAL; - execute dbms_xdb.sethttpport(8080); - exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('HIDDEN_STRING'); - alter system register; - exit; - '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def update_catalog_setup(self): - """ - This function update the catalog setup on this DB. - """ - # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") - # systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - msg='''Updating shardsetup table''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - create table system.shardsetup (status varchar2(10)); - insert into system.shardsetup values('completed'); - commit; - exit; - ''' - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Reset File - catalog_reset_dir='''{0}/.catalog'''.format(self.ora_env_dict["HOME"]) - catalog_reset_file='''{0}/.catalog/reset_catalog_completed'''.format(self.ora_env_dict["HOME"]) - - self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) - if not os.path.isdir(catalog_reset_dir): - self.ocommon.create_dir(catalog_reset_dir,True,None,None) - - if not os.path.isfile(catalog_reset_file): - self.ocommon.create_file(catalog_reset_file,True,None,None) - -# self.ocommon.unset_mask_str() - - ########## SETUP_CDB_catalog FUNCTION ENDS HERE ############################### - - ###################################### Run custom scripts ################################################## - def run_custom_scripts(self): - """ - Custom script to be excuted on every restart of enviornment - """ - self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): - shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): - shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] - script_file = '''{0}/{1}'''.format(shard_dir,shard_file) - if os.path.isfile(script_file): - msg='''Custom shard script exist {0}'''.format(script_file) - self.ocommon.log_info_message(msg,self.file_name) - cmd='''sh {0}'''.format(script_file) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - def set_primary_listener(self): - """ - Function to set the primary listener - """ - global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") - self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) - global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) - self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) - - def set_db_listener(self,gdbname,sid): - """ - Funtion to reset the listener - """ - self.ocommon.log_info_message("Inside reset_listener()",self.file_name) - start = 'SID_LIST_LISTENER' - end = '^\)$' - oracle_home=self.ora_env_dict["ORACLE_HOME"] - lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) - buffer = "SID_LIST_LISTENER=" + '\n' - start_flag = False - try: - with open(lisora) as f: - for line1 in f: - if start_flag == False: - if (re.match(start, line1.strip())): - start_flag = True - elif (re.match(end, line1.strip())): - line2 = f.next() - if (re.match(end, line2.strip())): - break - else: - buffer += line1 - buffer += line2 - else: - if start_flag == True: - buffer += line1 - except: - pass - - if start_flag == True: - buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") - listener = self.ocommon.get_lisora(1521) - listener += '\n' + buffer - else: - buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") - listener = self.ocommon.get_lisora(1521) - listener += '\n' + buffer - - wr = open(lisora, 'w') - wr.write(listener) - - def restart_listener(self): - """ - restart listener - """ - self.ocommon.log_info_message("Stopping Listener",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl stop'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - self.ocommon.log_info_message("Starting Listener",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl start'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - - def register_services(self): - """ - This function setup the catalog. - """ - #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - # Assigning variable - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): - msg='''Setting up catalog PDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system register; - alter session set container={0}; - alter system register; - exit; - '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def list_services(self): - """ - restart listener - """ - self.ocommon.log_info_message("Listing Services",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl services'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - - def backup_files(self): - """ - This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig - """ - self.ocommon.log_info_message("Inside backup_files()",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - dbsid=self.ora_env_dict["ORACLE_SID"] - - version=self.ocommon.get_oraversion(ohome).strip() - wallet_backup_cmd='''ls -ltr /bin''' - self.ocommon.log_info_message("Check Version " + version,self.file_name) - if int(version) >= 21: - obase1=self.ora_env_dict["ORACLE_BASE"] - wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) - cmd_names=''' - mkdir -p {0}/oradata/{1}/{2} - cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ - cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ - cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ - cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ - cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ - touch {0}/oradata/{1}/{2}/status_completed - '''.format(obase,"dbconfig",dbuname,ohome) - cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] - for cmd in cmd_list: - msg='''Executing cmd {0}'''.format(cmd) - self.ocommon.log_info_message(msg,self.file_name) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - - ############################### GSM Completion Message ####################################################### - def gsm_completion_message(self): - """ - Funtion print completion message - """ - self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) - msg=[] - msg.append('==============================================') - msg.append(' GSM Catalog Setup Completed ') - msg.append('==============================================') - - for text in msg: - self.ocommon.log_info_message(text,self.file_name) diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapshard.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapshard.py deleted file mode 100755 index e4be415..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orapshard.py +++ /dev/null @@ -1,838 +0,0 @@ -#!/usr/bin/python - -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - - -import os -import sys -import os.path -import re -import socket -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * -import traceback - -class OraPShard: - """ - This calss setup the primary shard after DB installation. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This constructor of OraPShard class to setup the shard on primary DB. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - try: - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - except BaseException as ex: - ex_type, ex_value, ex_traceback = sys.exc_info() - trace_back = traceback.extract_tb(ex_traceback) - stack_trace = list() - for trace in trace_back: - stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) - self.ocommon.log_info_message(ex_type.__name__,self.file_name) - self.ocommon.log_info_message(ex_value,self.file_name) - self.ocommon.log_info_message(stack_trace,self.file_name) - def setup(self): - """ - This function setup the shard on Primary DB. - """ - if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): - self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) - if self.ocommon.check_key("RESET_LISTENER",self.ora_env_dict): - status = self.shard_setup_check() - if not status: - self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) - self.ocommon.prog_exit("127") - self.reset_listener() - self.restart_listener() - if self.ocommon.check_key("RESTART_DB",self.ora_env_dict): - status = self.shard_setup_check() - if not status: - self.ocommon.log_info_message("Primary shard is still not setup.Exiting...",self.file_name) - self.ocommon.prog_exit("127") - else: - self.ocommon.shutdown_db(self.ora_env_dict) - self.ocommon.start_db(self.ora_env_dict) - elif self.ocommon.check_key("CHECK_LIVENESS",self.ora_env_dict): - create_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".create_lck" - exist_db_file_lck=self.ocommon.get_db_lock_location() + self.ora_env_dict["ORACLE_SID"] + ".exist_lck" - self.ocommon.log_info_message("DB create lock file set to :" + create_db_file_lck ,self.file_name) - self.ocommon.log_info_message("DB exist lock file set to :" + exist_db_file_lck ,self.file_name) - if os.path.exists(create_db_file_lck): - self.ocommon.log_info_message("provisioning is still in progress as file " + create_db_file_lck + " still exist!",self.file_name) - sys.exit(127) - elif os.path.exists(exist_db_file_lck): - self.ocommon.log_info_message("Database is up and running as file " + exist_db_file_lck + " exist!",self.file_name) - status = self.shard_setup_check() - if not status: - self.ocommon.prog_exit("127") - self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) - sys.exit(0) - else: - status = self.shard_setup_check() - if not status: - self.ocommon.prog_exit("127") - self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name) - sys.exit(0) - elif self.ocommon.check_key("CHECK_READYNESS",self.ora_env_dict): - status = self.shard_setup_check() - if not status: - self.ocommon.log_info_message("Shard readyness check completed sucessfully!",self.file_name) - self.ocommon.prog_exit("127") - else: - self.setup_machine() - self.db_checks() - self.reset_shard_setup() - status = self.shard_setup_check() - if status: - self.ocommon.log_info_message("Shard Setup is already completed on this database",self.file_name) - else: - self.reset_passwd() - self.setup_cdb_shard() - self.set_spfile_nonm_params() - self.ocommon.set_events("spfile") - self.set_dbparams_version() - self.restart_db() - self.restart_for_db_unique_name() - self.create_pdb() - self.alter_db() - self.setup_pdb_shard () - self.update_shard_setup() - self.set_primary_listener() - self.restart_listener() - self.register_services() - self.list_services() - self.backup_files() - self.gsm_completion_message() - self.run_custom_scripts() - - ########### SETUP_MACHINE begins here #################### - ## Function to machine setup - def setup_machine(self): - """ - This function performs the compute before performing setup - """ - self.omachine.setup() - ########### SETUP_MACHINE ENDS here #################### - - ########### DB_CHECKS Related Functions Begin Here #################### - ## Function to perfom DB checks ###### - def db_checks(self): - """ - This function perform db checks before starting the setup - """ - self.ohome_check() - self.passwd_check() - self.set_user() - self.sid_check() - self.dbunique_name_check() - self.hostname_check() - self.dbport_check() - self.dbr_dest_checks() - self.dpump_dir_checks() - - def ohome_check(self): - """ - This function performs the oracle home related checks - """ - if self.ocommon.check_key("ORACLE_HOME",self.ora_env_dict): - self.ocommon.log_info_message("ORACLE_HOME variable is set. Check Passed!",self.file_name) - else: - self.ocommon.log_error_message("ORACLE_HOME variable is not set. Exiting!",self.file_name) - self.ocommon.prog_exit() - - if os.path.isdir(self.ora_env_dict["ORACLE_HOME"]): - msg='''ORACLE_HOME {0} dirctory exist. Directory Check passed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg='''ORACLE_HOME {0} dirctory does not exist. Directory Check Failed!'''.format(self.ora_env_dict["ORACLE_HOME"]) - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit() - - def passwd_check(self): - """ - This funnction perform password related checks - """ - self.ocommon.get_password(None) - if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict): - msg='''ORACLE_PWD key is set. Check Passed!''' - self.ocommon.log_info_message(msg,self.file_name) - - def set_user(self): - """ - This funnction set the user for pdb and cdb. - """ - if self.ocommon.check_key("SHARD_ADMIN_USER",self.ora_env_dict): - msg='''SHARD_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["SHARD_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("SHARD_ADMIN_USER","mysdbadmin",self.ora_env_dict) - msg="SHARD_ADMIN_USER is not set, setting default to mysdbadmin" - self.ocommon.log_info_message(msg,self.file_name) - - if self.ocommon.check_key("PDB_ADMIN_USER",self.ora_env_dict): - msg='''PDB_ADMIN_USER {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["PDB_ADMIN_USER"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("PDB_ADMIN_USER","PDBADMIN",self.ora_env_dict) - msg="PDB_ADMIN_USER is not set, setting default to PDBADMIN." - self.ocommon.log_info_message(msg,self.file_name) - - def sid_check(self): - """ - This funnction heck and set the SID for cdb and PDB. - """ - if self.ocommon.check_key("ORACLE_SID",self.ora_env_dict): - msg='''ORACLE_SID {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_SID"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - msg="ORACLE_SID is not set, existing!" - self.ocommon.log_error_message(msg,self.file_name) - self.ocommon.prog_exit() - - def dbunique_name_check(self): - """ - This funnction check and set the db unique name for standby - """ - if self.ocommon.check_key("DB_UNIQUE_NAME",self.ora_env_dict): - msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) - self.ocommon.log_info_message(msg,self.file_name) - - msg='''Setting the Flag to restart the DB to set DB_UNIQUE_NAME to {0}! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) - self.ocommon.log_info_message(msg,self.file_name) - restart_db_to_set_db_unique_name='true' - self.ora_env_dict=self.ocommon.add_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",restart_db_to_set_db_unique_name,self.ora_env_dict) - else: - msg="DB_UNIQUE_NAME is not set. Setting DB_UNIQUE_NAME to Oracle_SID" - self.ocommon.log_info_message(msg,self.file_name) - dbsid=self.ora_env_dict["ORACLE_SID"] - self.ora_env_dict=self.ocommon.add_key("DB_UNIQUE_NAME",dbsid,self.ora_env_dict) - - def hostname_check(self): - """ - This function check and set the hostname. - """ - if self.ocommon.check_key("ORACLE_HOSTNAME",self.ora_env_dict): - msg='''ORACLE_HOSTNAME {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["ORACLE_HOSTNAME"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - if self.ocommon.check_key("KUBE_SVC",self.ora_env_dict): - ## hostname='''{0}.{1}'''.format(socket.gethostname(),self.ora_env_dict["KUBE_SVC"]) - hostname='''{0}'''.format(socket.getfqdn()) - else: - hostname='''{0}'''.format(socket.gethostname()) - msg='''ORACLE_HOSTNAME is not set, setting it to hostname {0} of the compute!'''.format(hostname) - self.ora_env_dict=self.ocommon.add_key("ORACLE_HOSTNAME",hostname,self.ora_env_dict) - self.ocommon.log_info_message(msg,self.file_name) - - def dbport_check(self): - """ - This funnction checks and set the SID for cdb and PDB. - """ - if self.ocommon.check_key("DB_PORT",self.ora_env_dict): - msg='''DB_PORT {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_PORT"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("DB_PORT","1521",self.ora_env_dict) - msg="DB_PORT is not set, setting default to 1521" - self.ocommon.log_info_message(msg,self.file_name) - - def dbr_dest_checks(self): - """ - This funnction checks and set the DB_CREATE_FILE_DEST and DB_CREATE_FILE_DEST_SIZE. - """ - if self.ocommon.check_key("DB_RECOVERY_FILE_DEST",self.ora_env_dict): - msg='''DB_RECOVERY_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/fast_recovery_area/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) - self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST",dest,self.ora_env_dict) - msg='''DB_RECOVERY_FILE_DEST set to {0}'''.format(dest) - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DB_RECOVERY_FILE_DEST"],True,None,None) - - # Checking the DB_RECOVERY_FILE_DEST_SIZE - - if self.ocommon.check_key("DB_RECOVERY_FILE_DEST_SIZE",self.ora_env_dict): - msg='''DB_RECOVERY_FILE_DEST_SIZE {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - self.ora_env_dict=self.ocommon.add_key("DB_RECOVERY_FILE_DEST_SIZE","40G",self.ora_env_dict) - msg='''DB_RECOVERY_FILE_DEST_SIZE set to {0}'''.format("40G") - self.ocommon.log_info_message(msg,self.file_name) - - # Checking the DB_CREATE_FILE_DEST - - if self.ocommon.check_key("DB_CREATE_FILE_DEST",self.ora_env_dict): - msg='''DB_CREATE_FILE_DEST {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/{1}'''.format(self.ora_env_dict["ORACLE_BASE"],self.ora_env_dict["ORACLE_SID"]) - self.ora_env_dict=self.ocommon.add_key("DB_CREATE_FILE_DEST",dest,self.ora_env_dict) - msg='''DB_CREATE_FILE_DEST set to {0}'''.format("40") - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DB_CREATE_FILE_DEST"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DB_CREATE_FILE_DEST"],True,None,None) - - - def dpump_dir_checks(self): - """ - This funnction checks and set the DATA_PUMP dir and location. - """ - if self.ocommon.check_key("DATA_PUMP_DIR",self.ora_env_dict): - msg='''DATA_PUMP_DIR {0} is passed as an env variable. Check Passed!'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) - self.ocommon.log_info_message(msg,self.file_name) - else: - dest='''{0}/oradata/data_pump_dir'''.format(self.ora_env_dict["ORACLE_BASE"]) - self.ora_env_dict=self.ocommon.add_key("DATA_PUMP_DIR",dest,self.ora_env_dict) - msg='''DATA_PUMP_DIR set to {0}'''.format(dest) - self.ocommon.log_info_message(msg,self.file_name) - msg='''Checking dir {0} on local machine. If not then create the dir {0} on local machine'''.format(self.ora_env_dict["DATA_PUMP_DIR"]) - self.ocommon.log_info_message(msg,self.file_name) - self.ocommon.create_dir(self.ora_env_dict["DATA_PUMP_DIR"],True,None,None) - - ########### DB_CHECKS Related Functions Begin Here #################### - - - ########## RESET_PASSWORD function Begin here ############################# - ## Function to perform password reset - def reset_passwd(self): - """ - This function reset the password. - """ - self.ocommon.reset_passwd() - - ########## RESET_PASSWORD function ENDS here ############################# - - ########## SETUP_CDB_SHARD FUNCTION BEGIN HERE ############################### - - def reset_shard_setup(self): - """ - This function drop teh shard setup table and reste the env to default values. - """ - # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system",self.ora_env_dict["ORACLE_PWD"]) - # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Inside reset_shard_setup",self.file_name) - shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) - if self.ocommon.check_key("RESET_ENV",self.ora_env_dict): - if self.ora_env_dict["RESET_ENV"]: - if not os.path.isfile(shard_reset_file): - msg='''Dropping shardsetup table from CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - drop table system.shardsetup; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - else: - msg='''Reset env already completed on this enviornment as {0} exist on this machine and not executing env reset'''.format(shard_reset_file) - self.ocommon.log_info_message(msg,self.file_name) - - - def shard_setup_check(self): - """ - This function check the shard status. - """ -# systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - - # self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - systemStr=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - msg='''Checking shardsetup table in CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - set term off - SET NEWPAGE NONE - spool /tmp/shard_setup.txt - select * from system.shardsetup WHERE ROWNUM = 1; - spool off - exit; - ''' - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - fname='''/tmp/{0}'''.format("shard_setup.txt") - fdata=self.ocommon.read_file(fname) - ### Unsetting the encrypt value to None - # self.ocommon.unset_mask_str() - - if re.search('completed',fdata): - return True - else: - return False - - def setup_cdb_shard(self): - """ - This function setup the shard. - """ - # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - # Assigning variable - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - dbr_dest=self.ora_env_dict["DB_RECOVERY_FILE_DEST"] - dbr_dest_size=self.ora_env_dict["DB_RECOVERY_FILE_DEST_SIZE"] - host_name=self.ora_env_dict["ORACLE_HOSTNAME"] - dpump_dir = self.ora_env_dict["DATA_PUMP_DIR"] - db_port=self.ora_env_dict["DB_PORT"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - msg='''Setting up Shard CDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set db_create_file_dest=\"{0}\" scope=both; - alter system set db_recovery_file_dest_size={1} scope=both; - alter system set db_recovery_file_dest=\"{2}\" scope=both; - alter system set db_file_name_convert='*','{0}/' scope=spfile; - alter system set standby_file_management='AUTO' scope=spfile; - alter user gsmrootuser account unlock; - grant sysdg to gsmrootuser; - grant sysbackup to gsmrootuser; - alter user gsmrootuser identified by HIDDEN_STRING container=all; - alter user GSMUSER account unlock; - alter user GSMUSER identified by HIDDEN_STRING container=all; - grant sysdg to GSMUSER; - grant sysbackup to GSMUSER; - create or replace directory DATA_PUMP_DIR as '{3}'; - grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; - alter system set local_listener='{4}:{5}' scope=spfile; - alter system set db_unique_name='{8}' scope=spfile; - '''.format(dbf_dest,dbr_dest_size,dbr_dest,dpump_dir,host_name,db_port,obase,"dbconfig",dbuname) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def set_spfile_nonm_params(self): - """ - This function setup the catalog. - """ - #sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): - if self.ora_env_dict["CLONE_DB"] != 'true': - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - msg='''Setting up catalog CDB with spfile non modifiable parameters''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set open_links_per_instance=16 scope=spfile; - alter system set open_links=16 scope=spfile; - alter system set db_file_name_convert='*','{0}/' scope=spfile; - alter system set dg_broker_config_file1=\"{1}/oradata/{2}/{3}/dr2{3}.dat\" scope=spfile; - alter system set dg_broker_config_file2=\"{1}/oradata/{2}/{3}/dr1{3}.dat\" scope=spfile; - '''.format(dbf_dest,obase,"dbconfig",dbuname) - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - def set_dbparams_version(self): - """ - This function setup the catalog parameter based on db version. - """ - ohome1=self.ora_env_dict["ORACLE_HOME"] - version=self.ocommon.get_oraversion(ohome1).strip() - self.ocommon.log_info_message(version,self.file_name) - if int(version) > 21: - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - dbf_dest=self.ora_env_dict["DB_CREATE_FILE_DEST"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - - - msg='''Setting up catalog CDB with spfile non modifiable parameters based on version''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system set wallet_root=\"{1}/oradata/{2}/{3}/\" scope=spfile; - '''.format(dbf_dest,obase,"dbconfig",dbuname) - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - def restart_db(self): - - """ - restarting the db - """ - if self.ocommon.check_key("CLONE_DB",self.ora_env_dict): - if self.ora_env_dict["CLONE_DB"] != 'true': - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) - self.ocommon.shutdown_db(self.ora_env_dict) - self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) - self.ocommon.start_db(self.ora_env_dict) - - # self.ocommon.log_info_message("Enabling archivelog at DB level",self.file_name) - # sqlcmd=''' - # alter database archivelog; - # alter database open; - # ''' - # output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - # self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - # self.ocommon.check_sql_err(output,error,retcode,True) - - - def restart_for_db_unique_name(self): - """ - restarting the db, when db_unique_name is passed explicitly - """ - if self.ocommon.check_key("RESTART_DB_TO_SET_DB_UNIQUE_NAME",self.ora_env_dict): - if self.ora_env_dict["RESTART_DB_TO_SET_DB_UNIQUE_NAME"] == 'true': - msg='''DB_UNIQUE_NAME {0} is passed as an env variable. Restarting the Database to set the DB_UNIQUE_NAME! '''.format(self.ora_env_dict["DB_UNIQUE_NAME"]) - self.ocommon.log_info_message(msg,self.file_name) - - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Calling shutdown_db() to shutdown the database",self.file_name) - self.ocommon.shutdown_db(self.ora_env_dict) - self.ocommon.log_info_message("Calling startup_mount() to mount the database",self.file_name) - self.ocommon.start_db(self.ora_env_dict) - - - def create_pdb(self): - """ - This function creates the PDB - """ - inst_sid=self.ora_env_dict["ORACLE_SID"] - ohome=self.ora_env_dict["ORACLE_HOME"] - if self.ocommon.check_key("ORACLE_FREE_PDB",self.ora_env_dict): - self.ora_env_dict=self.ocommon.update_key("ORACLE_PDB",self.ora_env_dict["ORACLE_FREE_PDB"],self.ora_env_dict) - opdb=self.ora_env_dict["ORACLE_PDB"] - status=self.ocommon.check_pdb(opdb) - if not status: - self.ocommon.create_pdb(ohome,opdb,inst_sid) - self.ocommon.create_pdb_tns_entry(ohome,opdb) - - def alter_db(self): - """ - Alter db - """ - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) - sqlcmd=''' - alter database flashback on; - alter database force logging; - ALTER PLUGGABLE DATABASE ALL OPEN; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - - - def setup_pdb_shard(self): - """ - This function setup the shard. - """ - sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - # Assigning variable - if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): - msg='''Setting up Shard PDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter pluggable database {0} close immediate; - alter pluggable database {0} open services=All; - ALTER PLUGGABLE DATABASE {0} SAVE STATE; - alter system register; - alter session set container={0}; - grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL; - grant sysdg to GSMUSER; - grant sysbackup to GSMUSER; - execute DBMS_GSM_FIX.validateShard; - alter system register; - '''.format(self.ora_env_dict["ORACLE_PDB"]) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - def alter_db(self): - """ - Alter db - """ - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.log_info_message("Enabling flashback and force logging at DB level",self.file_name) - sqlcmd=''' - alter database flashback on; - alter database force logging; - ALTER PLUGGABLE DATABASE ALL OPEN; - ''' - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,None) - - def update_shard_setup(self): - """ - This function update the shard setup on this DB. - """ - # systemStr='''{0}/bin/sqlplus {1}/{2}'''.format(self.ora_env_dict["ORACLE_HOME"],"system","HIDDEN_STRING") - systemStr='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - -# self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - - msg='''Updating shardsetup table''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - set heading off - set feedback off - create table system.shardsetup (status varchar2(10)); - insert into system.shardsetup values('completed'); - commit; - exit; - ''' - output,error,retcode=self.ocommon.run_sqlplus(systemStr,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Reset File - shard_reset_dir='''{0}/.shard'''.format(self.ora_env_dict["HOME"]) - shard_reset_file='''{0}/.shard/reset_shard_completed'''.format(self.ora_env_dict["HOME"]) - - self.ocommon.log_info_message("Creating reset_file_fir if it does not exist",self.file_name) - if not os.path.isdir(shard_reset_dir): - self.ocommon.create_dir(shard_reset_dir,True,None,None) - - if not os.path.isfile(shard_reset_file): - self.ocommon.create_file(shard_reset_file,True,None,None) - -# self.ocommon.unset_mask_str() - - ########## SETUP_CDB_SHARD FUNCTION ENDS HERE ############################### - ###################################### Run custom scripts ################################################## - def run_custom_scripts(self): - """ - Custom script to be excuted on every restart of enviornment - """ - self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): - shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] - - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): - shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] - - script_file = '''{0}/{1}'''.format(shard_dir,shard_file) - - if os.path.isfile(script_file): - msg='''Custom shard script exist {0}'''.format(script_file) - self.ocommon.log_info_message(msg,self.file_name) - cmd='''sh {0}'''.format(script_file) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - ###################################### Run custom scripts ################################################## - def run_custom_scripts(self): - """ - Custom script to be excuted on every restart of enviornment - """ - self.ocommon.log_info_message("Inside run_custom_scripts()",self.file_name) - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_DIR",self.ora_env_dict): - shard_dir=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_DIR"] - if self.ocommon.check_key("CUSTOM_SHARD_SCRIPT_FILE",self.ora_env_dict): - shard_file=self.ora_env_dict["CUSTOM_SHARD_SCRIPT_FILE"] - script_file = '''{0}/{1}'''.format(shard_dir,shard_file) - if os.path.isfile(script_file): - msg='''Custom shard script exist {0}'''.format(script_file) - self.ocommon.log_info_message(msg,self.file_name) - cmd='''sh {0}'''.format(script_file) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,True) - - ############################### GSM Completion Message ####################################################### - def gsm_completion_message(self): - """ - Funtion print completion message - """ - self.ocommon.log_info_message("Inside gsm_completion_message()",self.file_name) - msg=[] - msg.append('==============================================') - msg.append(' GSM Shard Setup Completed ') - msg.append('==============================================') - - for text in msg: - self.ocommon.log_info_message(text,self.file_name) - ################################ Reset and standby functions ################################################# - - def set_primary_listener(self): - """ - Function to set the primary listener - """ - global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"] + "_DGMRL") - self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) - global_dbname=self.ocommon.get_global_dbdomain(self.ora_env_dict["ORACLE_HOSTNAME"],self.ora_env_dict["DB_UNIQUE_NAME"]) - self.set_db_listener(global_dbname,self.ora_env_dict["DB_UNIQUE_NAME"]) - - def set_db_listener(self,gdbname,sid): - """ - Funtion to reset the listener - """ - self.ocommon.log_info_message("Inside reset_listener()",self.file_name) - start = 'SID_LIST_LISTENER' - end = '^\)$' - oracle_home=self.ora_env_dict["ORACLE_HOME"] - lisora='''{0}/network/admin/listener.ora'''.format(oracle_home) - buffer = "SID_LIST_LISTENER=" + '\n' - start_flag = False - try: - with open(lisora) as f: - for line1 in f: - if start_flag == False: - if (re.match(start, line1.strip())): - start_flag = True - elif (re.match(end, line1.strip())): - line2 = f.next() - if (re.match(end, line2.strip())): - break - else: - buffer += line1 - buffer += line2 - else: - if start_flag == True: - buffer += line1 - except: - pass - - if start_flag == True: - buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC1") - listener = self.ocommon.get_lisora(1521) - listener += '\n' + buffer - else: - buffer += self.ocommon.get_sid_desc(gdbname,oracle_home,sid,"SID_DESC") - listener = self.ocommon.get_lisora(1521) - listener += '\n' + buffer - - wr = open(lisora, 'w') - wr.write(listener) - - def restart_listener(self): - """ - restart listener - """ - self.ocommon.log_info_message("Stopping Listener",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl stop'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - self.ocommon.log_info_message("Starting Listener",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl start'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - def register_services(self): - """ - This function setup the catalog. - """ - # sqlpluslogincmd='''{0}/bin/sqlplus "/as sysdba"'''.format(self.ora_env_dict["ORACLE_HOME"]) - # Assigning variable - ohome=self.ora_env_dict["ORACLE_HOME"] - inst_sid=self.ora_env_dict["ORACLE_SID"] - sqlpluslogincmd=self.ocommon.get_sqlplus_str(ohome,inst_sid,"sys",None,None,None,None,None,None,None) - self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"]) - if self.ocommon.check_key("ORACLE_PDB",self.ora_env_dict): - msg='''Setting up catalog PDB''' - self.ocommon.log_info_message(msg,self.file_name) - sqlcmd=''' - alter system register; - alter session set container={0}; - alter system register; - exit; - '''.format(self.ora_env_dict["ORACLE_PDB"],self.ora_env_dict["SHARD_ADMIN_USER"]) - - output,error,retcode=self.ocommon.run_sqlplus(sqlpluslogincmd,sqlcmd,None) - self.ocommon.log_info_message("Calling check_sql_err() to validate the sql command return status",self.file_name) - self.ocommon.check_sql_err(output,error,retcode,True) - - ### Unsetting the encrypt value to None - self.ocommon.unset_mask_str() - - def list_services(self): - """ - restart listener - """ - self.ocommon.log_info_message("Listing Services",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - cmd='''{0}/bin/lsnrctl services'''.format(ohome) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) - self.ocommon.check_os_err(output,error,retcode,None) - - def backup_files(self): - """ - This function backup the files such as spfile, password file and other required files to a under oradata/dbconfig - """ - self.ocommon.log_info_message("Inside backup_files()",self.file_name) - ohome=self.ora_env_dict["ORACLE_HOME"] - obase=self.ora_env_dict["ORACLE_BASE"] - dbuname=self.ora_env_dict["DB_UNIQUE_NAME"] - dbsid=self.ora_env_dict["ORACLE_SID"] - - version=self.ocommon.get_oraversion(ohome).strip() - wallet_backup_cmd='''ls -ltr /bin''' - self.ocommon.log_info_message("Check Version " + version,self.file_name) - if int(version) >= 21: - obase1=self.ora_env_dict["ORACLE_BASE"] - wallet_backup_cmd='''cp -r {3}/admin/ {0}/oradata/{1}/{2}/'''.format(obase,"dbconfig",dbuname,ohome) - cmd_names=''' - mkdir -p {0}/oradata/{1}/{2} - cp {3}/dbs/spfile{2}.ora {0}/oradata/{1}/{2}/ - cp {3}/dbs/orapw{2} {0}/oradata/{1}/{2}/ - cp {3}/network/admin/sqlnet.ora {0}/oradata/{1}/{2}/ - cp {3}/network/admin/listener.ora {0}/oradata/{1}/{2}/ - cp {3}/network/admin/tnsnames.ora {0}/oradata/{1}/{2}/ - {4} - touch {0}/oradata/{1}/{2}/status_completed - '''.format(obase,"dbconfig",dbuname,ohome,wallet_backup_cmd) - cmd_list = [y for y in (x.strip() for x in cmd_names.splitlines()) if y] - for cmd in cmd_list: - msg='''Executing cmd {0}'''.format(cmd) - self.ocommon.log_info_message(msg,self.file_name) - output,error,retcode=self.ocommon.execute_cmd(cmd,None,None) diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orascatalog.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orascatalog.py deleted file mode 100755 index aa4ea65..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orascatalog.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - - diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orasshard.py b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orasshard.py deleted file mode 100755 index 58f168b..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/orasshard.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/python -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - - -import os -import sys -import os.path -import re -import socket -from oralogger import * -from oraenv import * -from oracommon import * -from oramachine import * -import traceback - -class OraSShard: - """ - This calss setup the standby shard after DB installation. - """ - def __init__(self,oralogger,orahandler,oraenv,oracommon): - """ - This constructor of OraSShard class to setup the shard on standby DB. - - Attributes: - oralogger (object): object of OraLogger Class. - ohandler (object): object of Handler class. - oenv (object): object of singleton OraEnv class. - ocommon(object): object of OraCommon class. - ora_env_dict(dict): Dict of env variable populated based on env variable for the setup. - file_name(string): Filename from where logging message is populated. - """ - try: - self.ologger = oralogger - self.ohandler = orahandler - self.oenv = oraenv.get_instance() - self.ocommon = oracommon - self.ora_env_dict = oraenv.get_env_vars() - self.file_name = os.path.basename(__file__) - self.omachine = OraMachine(self.ologger,self.ohandler,self.oenv,self.ocommon) - except BaseException as ex: - ex_type, ex_value, ex_traceback = sys.exc_info() - trace_back = traceback.extract_tb(ex_traceback) - stack_trace = list() - for trace in trace_back: - stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3])) - ocommon.log_info_message(ex_type.__name__,self.file_name) - ocommon.log_info_message(ex_value,self.file_name) - ocommon.log_info_message(stack_trace,self.file_name) - def setup(self): - """ - This function setup the shard on standby DB. - """ - pass diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOraShardSetup.sh b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOraShardSetup.sh deleted file mode 100644 index c1b09b4..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOraShardSetup.sh +++ /dev/null @@ -1,568 +0,0 @@ -#!/bin/bash -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -export CLONED_FILE="status_completed" -export STANDBY_STATUS="status_completed" - -########### Clone Files ##################### -function cloneDB { - -export NEW_ORACLE_SID=$ORACLE_SID -export ORACLE_SID=$OLD_ORACLE_SID -sqlplus / as sysdba << EOF - STARTUP mount; - exit; -EOF - -echo 'Y' | nid target=/ dbname="$NEW_ORACLE_SID" - -if [ $? -eq 0 ]; then - echo "DB name changed sucessfully" -else - echo "DB name change process failed" - exit 1; -fi - -if [ -z ${DB_RECOVERY_FILE_DEST} ]; then - export DB_RECOVERY_FILE_DEST=$ORACLE_BASE/oradata/fast_recovery_area/$NEW_ORACLE_SID -fi - -if [ -z ${DB_UNIQUE_NAME} ]; then - export DB_UNIQUE_NAME=$NEW_ORACLE_SID -fi - -export ORACLE_HOSTNAME=$( hostname -f ) - -echo "Changing DB name" -export ORACLE_SID=$NEW_ORACLE_SID -sqlplus / as sysdba << EOF - STARTUP nomount; - alter system set db_name=$ORACLE_SID scope=spfile; - alter system set open_links=16 scope=spfile; - alter system set open_links_per_instance=16 scope=spfile; - alter system set dg_broker_config_file1="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr2$DB_UNIQUE_NAME.dat" scope=spfile; - alter system set dg_broker_config_file2="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME/dr1$DB_UNIQUE_NAME.dat" scope=spfile; - alter system set db_file_name_convert='*','$ORACLE_BASE/oradata/$DB_UNIQUE_NAME/' scope=spfile; - alter system set local_listener='$ORACLE_HOSTNAME' scope=spfile; - alter system set standby_file_management='auto' scope=spfile; - shutdown immediate - exit; -EOF - -## Get the version - dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) - if [ ! -z ${dbversion} ]; then - if [ ${dbversion} -ge 21 ]; then - echo "Setting DB Parameter based on the vserion" - export ORACLE_SID=$NEW_ORACLE_SID - sqlplus / as sysdba << EOF - startup nomount - alter system set wallet_root="$ORACLE_BASE/oradata/dbconfig/$DB_UNIQUE_NAME" scope=spfile; - shutdown immediate - exit; -EOF - fi - fi - -echo "Changing OLD SID string to new string" -sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_HOME/network/admin/tnsnames.ora -sed -i "s/$OLD_ORACLE_PDB/$ORACLE_PDB/g" $ORACLE_HOME/network/admin/tnsnames.ora - -echo "Starting Listener" - -$ORACLE_HOME/bin/lsnrctl start - -echo "Starting new cloned DB" - -sqlplus / as sysdba << EOF - STARTUP mount; - alter database archivelog; - alter database open resetlogs; - exit; -EOF - -echo "Renaming PDB" - -sqlplus / as sysdba << EOF - alter pluggable database $OLD_ORACLE_PDB open restricted; - alter session set container=$OLD_ORACLE_PDB; - alter pluggable database rename global_name to $ORACLE_PDB; - exit; -EOF - -echo " Closing and Opening PDB" - -sqlplus / as sysdba << EOF - alter pluggable database $ORACLE_PDB close immediate; - alter pluggable database $ORACLE_PDB open; - alter system register; - exit; -EOF - - -echo "Touching $CLONED_FILE as setup is completed" -touch $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE - -} - -############################################ -########### Symbolic link DB files ######### -############################################ -########### DB Version >= 23c ############## -############################################ -function symLinkFiles23c { - - if [ -z ${ORACLE_BASE_HOME} ]; then - # - export ORACLE_BASE_HOME=$ORACLE_HOME - fi - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then - mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID - fi; - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then - mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump - fi; - - if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then - unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora - fi; - if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then - unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - fi; - if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID - fi; - if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID - fi; - if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora - fi; - if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/listener.ora - fi; - if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora - fi - if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then - unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID - fi; - if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora - ## Link based on ORACLE_BASE -# ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/spfile$ORACLE_SID.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - ## Link based on ORACLE_BASE - # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - ## Link based on ORACLE_BASE - # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID - ## Link based on ORACLE_BASE - # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dbs/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID - ## Link based on ORACLE_BASE - # ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID - ## Link based on ORACLE_BASE - # ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/dbs/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora - fi - fi - fi; - - if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID - fi; - - if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID - fi; - - if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then - mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID - fi; - - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then - ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB - fi; - # oracle user does not have permissions in /etc, hence cp and not ln - sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab - cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab - fi -fi - -} - - -############################################ -########### Symbolic link DB files ######### -############################################ -########### DB Version < 23c ############### -############################################ -function symLinkFiles { - - if [ -z ${ORACLE_BASE_HOME} ]; then - # - export ORACLE_BASE_HOME=$ORACLE_HOME - fi - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then - mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID - fi; - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then - mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump - fi; - - if [ -L $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora ]; then - unlink $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora - fi; - if [ -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then - unlink $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - fi; - if [ -L $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID - fi; - if [ -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/orapw$ORACLE_SID - fi; - if [ -L $ORACLE_BASE_HOME/network/admin/sqlnet.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/sqlnet.ora - fi; - if [ -L $ORACLE_HOME/network/admin/listener.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/listener.ora - fi; - if [ -L $ORACLE_BASE_HOME/network/admin/tnsnames.ora ]; then - unlink $ORACLE_BASE_HOME/network/admin/tnsnames.ora - fi - if [ -L $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID ]; then - unlink $ORACLE_BASE_HOME/dbs/dr1$ORACLE_SID - fi; - if [ -L $ORACLE_BASE_HOME/dbs/dr2$ORACLE_SID ]; then - unlink $ORACLE_HOME/dbs/dr2$ORACLE_SID - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$OLD_ORACLE_SID.ora - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$OLD_ORACLE_SID.ora - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/spfile$OLD_ORACLE_SID.ora $ORACLE_BASE/dbs/spfile$ORACLE_SID.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$OLD_ORACLE_SID - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$OLD_ORACLE_SID - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID - ## Link based on ORACLE_BASE - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora - fi - fi - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora - else - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora - fi - fi - fi; - - if [ -f $ORACLE_HOME/dbs/dr1$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr1$ORACLE_SID $ORACLE_HOME/dbs/dr1$ORACLE_SID - fi; - - if [ -f $ORACLE_HOME/dbs/dr2$ORACLE_SID ]; then - ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/dr2$ORACLE_SID $ORACLE_HOME/dbs/dr2$ORACLE_SID - fi; - - if [ ! -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then - mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID - fi; - - if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - if [ ! -L $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB ]; then - ln -s $ORACLE_BASE/oradata/$OLD_ORACLE_SID/$OLD_ORACLE_PDB $ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB - fi; - # oracle user does not have permissions in /etc, hence cp and not ln - sed -i "s/$OLD_ORACLE_SID/$ORACLE_SID/g" $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab - cp $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/oratab /etc/oratab - fi -fi - -} - -################################### -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # -############# MAIN ################ -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # -################################### - -# Check whether container has enough memory -# Github issue #219: Prevent integer overflow, -# only check if memory digits are less than 11 (single GB range and below) -if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes | wc -c` -lt 11 ]; then - if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` -lt 2147483648 ]; then - echo "Error: The container doesn't have enough memory allocated." - echo "A database container needs at least 2 GB of memory." - echo "You currently only have $((`cat /sys/fs/cgroup/memory/memory.limit_in_bytes`/1024/1024/1024)) GB allocated to the container." - exit 1; - fi; -fi; - - -# Check that hostname doesn't container any "_" -# Github issue #711 -if hostname | grep -q "_"; then - echo "Error: The hostname must not container any '_'". - echo "Your current hostname is '$(hostname)'" -fi; - -# Default for ORACLE SID -if [ "$OLD_ORACLE_SID" == "" ]; then - export OLD_ORACLE_SID=SEEDCDB -fi - -if [ ! -z ${ORACLE_SID} ]; then - # Make ORACLE_SID upper case - # Github issue # 984 - export ORACLE_SID=${ORACLE_SID^^} - - # Check whether SID is no longer than 12 bytes - # Github issue #246: Cannot start OracleDB image - if [ "${#ORACLE_SID}" -gt 12 ]; then - echo "Error: The ORACLE_SID must only be up to 12 characters long." - exit 1; - fi; - - # Check whether SID is alphanumeric - # Github issue #246: Cannot start OracleDB image - if [[ "$ORACLE_SID" =~ [^a-zA-Z0-9] ]]; then - echo "Error: The ORACLE_SID must be alphanumeric." - exit 1; - fi; -else - echo "Error: The ORACLE_SID must be defined." - exit 1; -fi; - - -if [ ! -z ${ORACLE_PDB} ]; then - export ORACLE_PDB=${ORACLE_PDB^^} - - if [ "${#ORACLE_PDB}" -gt 12 ]; then - echo "Error: The ORACLE_PDB must only be up to 12 characters long." - exit 1; - fi; -else - echo "Error: The ORACLE_PDB must be defined." - exit 1; -fi; - -if [ ! -z ${OLD_ORACLE_PDB} ]; then - export OLD_ORACLE_PDB=${OLD_ORACLE_PDB^^} -else - export OLD_ORACLE_PDB=SEEDPDB -fi; - - -# Default for ORACLE CHARACTERSET -export ORACLE_CHARACTERSET=${ORACLE_CHARACTERSET:-AL32UTF8} - -# Check whether database already exists -if [ ! -z ${CLONE_DB} ]; then -if [ ${CLONE_DB^^} == "TRUE" ]; then -echo "CLONE_DB is set to true, cloning DB from seed" -if [ -d $ORACLE_BASE/oradata/$OLD_ORACLE_SID ]; then - dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) - if [ ! -z ${dbversion} ]; then - if [ ${dbversion} -ge 23 ]; then - symLinkFiles23c; - else - symLinkFiles; - fi; - else - echo "Unable to determine the Database Version, exiting.." - exit 1; - fi - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump ]; then - mkdir -p $ORACLE_BASE/admin/$OLD_ORACLE_SID/adump - fi; - - # Make sure audit file destination exists - if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then - mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump - fi; - - if [ -f $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE ]; - then - # Start database - echo "Starting Database as cloned status file exist" - $ORACLE_BASE/$START_FILE; - else - echo "Performing Cloning as cloned status file does not exist" - cloneDB; - $ORACLE_BASE/checkDBStatus.sh - if [ $? -eq 0 ]; then - echo "DB is in READ WRITE State" - touch "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" - $ORACLE_BASE/$LOCKING_SCRIPT --acquire --file "$ORACLE_BASE/oradata/.${ORACLE_SID}.exist_lck" - else - echo "DB is not in READ WRITE state" - exit 1; - fi - fi -else - echo "Error: The $ORACLE_BASE/oradata/$OLD_ORACLE_SID (ORACLE_BASE/oradata/OLD_ORACLE_SID) dir does not exist. Error exiting ." - exit 1; -fi -fi -fi - -if [ ${OP_TYPE,,} == "standbyshard" ]; then - dbversion=$( $ORACLE_HOME/bin/oraversion -majorVersion ) - if [ ! -z ${dbversion} ]; then - if [ ${dbversion} -ge 23 ]; then - symLinkFiles23c; - else - symLinkFiles; - fi; - else - echo "Unable to determine the Database Version, exiting.." - exit 1; - fi - - if [ -f $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/$STANDBY_STATUS ]; - then - # Start database - echo "Starting Database as standby setup status file exist" - $ORACLE_BASE/$START_FILE; - fi -fi - -#This is the main file which calls other file to setup the sharding. -if [ -z ${BASE_DIR} ]; then - BASE_DIR=/opt/oracle/scripts/sharding -fi - -if [ -z ${MAIN_SCRIPT} ]; then - SCRIPT_NAME="main.py" -fi - -if [ -z ${EXECUTOR} ]; then - EXECUTOR="python" -fi - -cd $BASE_DIR -$EXECUTOR $SCRIPT_NAME diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOracle.sh b/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOracle.sh deleted file mode 100755 index 2266e99..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/scripts/runOracle.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash -# LICENSE UPL 1.0 -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# -# Since: January, 2020 -# Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com - -########### SIGINT handler ############ -function _int() { - echo "Stopping container." - echo "SIGINT received, shutting down database!" - sqlplus / as sysdba <<EOF - shutdown immediate; - exit; -EOF - lsnrctl stop -} - -########### SIGTERM handler ############ -function _term() { - echo "Stopping container." - echo "SIGTERM received, shutting down database!" - sqlplus / as sysdba <<EOF - shutdown immediate; - exit; -EOF - lsnrctl stop -} - -########### SIGKILL handler ############ -function _kill() { - echo "SIGKILL received, shutting down database!" - sqlplus / as sysdba <<EOF - shutdown abort; - exit; -EOF - lsnrctl stop -} - - -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # -############# MAIN ################ -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # -################################### - -if [ ! -z ${SHARD_SETUP} ]; then - if [ ${SHARD_SETUP,,} == "true" ]; then - sh $ORACLE_BASE/scripts/sharding/runOraShardSetup.sh - fi -fi - -if [ ! -z ${CLONE_DB} ]; then - if [ ${CLONE_DB^^} == "TRUE" ]; then - echo "The following output is now a tail of the alert.log:" - tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & - fi -fi - -if [ ! -z ${OP_TYPE} ]; then - if [ ${OP_TYPE,,} == "standbyshard" ]; then - echo "The following output is now a tail of the alert.log:" - tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log & - fi -fi - -# Set SIGINT handler -trap _int SIGINT - -# Set SIGTERM handler -trap _term SIGTERM - -# Set SIGKILL handler -trap _kill SIGKILL - - -childPID=$! -wait $childPID diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/setupGSM.sh b/container-based-sharding-deployment/containerfiles/23.4.0/setupGSM.sh deleted file mode 100644 index 4a6a6ca..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/setupGSM.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: Build script for building RAC container image -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -# Create Directories -mkdir -p $GSM_BASE -mkdir -p $GSM_HOME -mkdir -p $INVENTORY - -chown -R oracle:oinstall $INVENTORY -chown -R oracle:oinstall $GSM_BASE -chown -R oracle:oinstall $GSM_HOME -chown -R oracle:oinstall $INSTALL_SCRIPTS -chmod 775 $INSTALL_SCRIPTS - -chmod 666 /etc/sudoers -echo "oracle ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers -chmod 440 /etc/sudoers - -echo "export ORACLE_HOME=$GSM_HOME" >> /home/oracle/.bashrc -echo "export PATH=$GSM_PATH" >> /home/oracle/.bashrc -echo "export LD_LIBRARY_PATH=$GSM_LD_LIBRARY_PATH" >> /home/oracle/.bashrc -echo "export SCRIPT_DIR=$SCRIPT_DIR" >> /home/oracle/.bashrc -echo "export GSM_HOME=$GSM_HOME" >> /home/oracle/.bashrc diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/setupLinuxEnv.sh b/container-based-sharding-deployment/containerfiles/23.4.0/setupLinuxEnv.sh deleted file mode 100644 index c652b9b..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/setupLinuxEnv.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: Build script for building RAC container image -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -if grep -q "Oracle Linux Server release 9" /etc/oracle-release; then \ - curl --noproxy '*' https://ca-artifacts.oraclecorp.com/auto-build/x86_64-build-output-9-dev/oracle-database-preinstall-23ai-1.0-1.4.el9.x86_64.rpm --output oracle-database-preinstall-23ai-1.0-1.4.el9.x86_64.rpm && \ - dnf install -y oracle-database-preinstall-23ai-1.0-1.4.el9.x86_64.rpm && \ - rm -f /etc/systemd/system/oracle-database-preinstall-23ai-firstboot.service && \ - dnf clean all; \ -else \ - dnf -y install oraclelinux-developer-release-el8 && \ - dnf -y install oracle-database-preinstall-23c && \ - rm -f /etc/rc.d/init.d/oracle-database-preinstall-23c-firstboot && \ - dnf clean all; \ -fi && \ -dnf -y install net-tools zip unzip tar openssl openssh-server vim-minimal which passwd sudo python3 hostname fontconfig lsof && \ -dnf clean all && \ -chmod ug+x $SCRIPT_DIR/*.sh && \ -rm -f /etc/sysctl.conf && \ -rm -f /usr/lib/systemd/system/dnf-makecache.service \ No newline at end of file diff --git a/container-based-sharding-deployment/containerfiles/23.4.0/setupOshardEnv.sh b/container-based-sharding-deployment/containerfiles/23.4.0/setupOshardEnv.sh deleted file mode 100755 index 5ae2692..0000000 --- a/container-based-sharding-deployment/containerfiles/23.4.0/setupOshardEnv.sh +++ /dev/null @@ -1,970 +0,0 @@ -#!/bin/bash -# -# LICENSE UPL 1.0 -# Since: November, 2020 -# Author: paramdeep.saini@oracle.com -# Description: -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright (c) 2020,2021 Oracle and/or its affiliates. -# - -export NOW=$(date +"%Y%m%d%H%M") -export LOGDIR="/tmp" -export LOGFILE="${LOGDIR}/oshard_${NOW}.log" -export STD_OUT_FILE="/proc/1/fd/1" -export STD_ERR_FILE="/proc/1/fd/2" -declare -x SECRET_VOLUME='/run/secrets/' ## Secret Volume -declare -x PWD_KEY='pwd.key' ## PWD Key File -declare -x COMMON_OS_PWD_FILE='common_os_pwdfile.enc' -declare -x DB_PWD_FILE -export PDB_SQL_SCRIPT="/tmp/pdb.sql" -export TOP_PID=$$ -rm -f /tmp/sqllog.output -rm -f $PDB_SQL_SCRIPT -rm -f $LOGFILE - -#################################### Print and Exit Functions Begin Here ####################### -error_exit() { -local NOW=$(date +"%m-%d-%Y %T %Z") - # Display error message and exit -# echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2 - echo "${NOW} : ${PROGNAME}: ${1:-"Unknown Error"}" | tee -a $LOGFILE > $STD_OUT_FILE - kill -s TERM $TOP_PID -} - -print_message () -{ - local NOW=$(date +"%m-%d-%Y %T %Z") - # Display message and return - echo "${NOW} : ${PROGNAME} : ${1:-"Unknown Message"}" | tee -a $LOGFILE > $STD_OUT_FILE - return $? -} -#################################### Print and Exit Functions End Here ####################### - - -####################################### Functions Related to checks #################### -dbChecks() -{ -if [ -z "$ORACLE_HOME" ] -then - error_exit "Set the ORACLE_HOME variable" -else - print_message "ORACLE_HOME set to $ORACLE_HOME" -fi - -# If ORACLE_HOME doesn't exist # -if [ ! -d "$ORACLE_HOME" ] -then - error_exit "The ORACLE_HOME $ORACLE_HOME does not exist" -else - print_message "ORACLE_HOME Directory Exist" -fi - -################## Checks for Password and Clustername and clustertype begins here ########### -if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then -cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' - -eval $cmd - -if [ $? -eq 0 ]; then -print_message "Password file generated" -else -error_exit "Error occurred during common os password file generation" -fi - -read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} -rm -f /tmp/${COMMON_OS_PWD_FILE} -else - print_message "Password is empty string" - export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 -fi - -if [ -z "${ORACLE_PWD}" ]; then - print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" - export ORACLE_PWD=${PASSWORD} -else - print_message "ORACLE_PWD is set to user specified password" -fi - -################################################################################################### - - -if [ -z "${SHARD_ADMIN_USER}" ] -then - print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" - export SHARD_ADMIN_USER="mysdbadmin" -else - print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" -fi - - -if [ -z "${PDB_ADMIN_USER}" ] -then - print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" - export PDB_ADMIN_USER="pdbadmin" -else - print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" -fi - - -# Validate the value of ORACLE_SID # -if [ -z "${ORACLE_SID}" ] -then - error_exit "Set the ORACLE_SID variable" -else - print_message "ORACLE_SID is set to $ORACLE_SID" -fi - -if [ -z "${ORACLE_HOSTNAME}" ] -then - if [ -z "${KUBE_SVC}" ]; then - print_message "ORACLE_HOSTNAME variable is not set" - export ORACLE_HOSTNAME="$(hostname)" - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" - else - print_message "ORACLE_HOSTNAME variable is not set" - export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" - fi -else - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" -fi - - - -if [ -z "$DB_PORT" ] -then - print_message "Set the DB_PORT variable" - export DB_PORT=1521 -else - print_message "DB Port is set to $DB_PORT" -fi - -if [ -z "${DB_RECOVERY_FILE_DEST}" ]; then - print_message "Set the DB_RECOVERY_FILE_DEST is not set" - export DB_RECOVERY_FILE_DEST="${ORACLE_BASE}/oradata/fast_recovery_area/${ORACLE_SID}" -fi - -if [ -z "${DB_CREATE_FILE_DEST}" ]; then - print_message "Set the DB_CREATE_FILE_DEST is not set. Setting to ${ORACLE_BASE}/oradata/${ORACLE_SID}" - export DB_CREATE_FILE_DEST="${ORACLE_BASE}/oradata/${ORACLE_SID}" -fi - -if [ -z "${DATA_PUMP_DIR}" ]; then - print_message "DATA_PUMP_DIR is not set, it will se to ${ORACLE_BASE}/oradata/data_pump_dir" - export DATA_PUMP_DIR="${ORACLE_BASE}/oradata/data_pump_dir" -fi - -if [ ! -d "${DATA_PUMP_DIR}" ]; then - print_message "DATA_PUMP_DIR ${DATA_PUMP_DIR} directory does not exist" - mkdir -p "${DATA_PUMP_DIR}" -fi - -if [ ! -d "${DB_RECOVERY_FILE_DEST}" ]; then - print_message "DB_RECOVERY_FILE_DEST ${DB_RECOVERY_FILE_DEST} directory does not exist" - mkdir -p "${DB_RECOVERY_FILE_DEST}" -fi - -if [ -z "${DB_RECOVERY_FILE_DEST_SIZE}" ]; then - print_message "DB_RECOVERY_FILE_DEST_SIZE is not set" - export DB_RECOVERY_FILE_DEST_SIZE="40G" -else - print_message "DB_RECOVERY_FILE_DEST_SIZE is set to ${DB_RECOVERY_FILE_DEST_SIZE}" -fi - -} - -gsmChecks() -{ - print_message "Performing GSM related checks" - -if [ ! -z "${KUBE_SVC}" ]; then - lordinal=$( hostname | awk -F "-" '{ print $NF }' ) - print_message "lordinal is set to ${lordinal}" - region_num=$((lordinal+1)) - if [ -z "${REGION}" ]; then - print_message "REGION is not set. Setting to region$lordinal" - export REGION="region${region_num}" - fi -else - if [ -z "${REGION}" ]; then - error_exit "REGION Canot be set to empty" - fi -fi - -################## Checks for Password and Clustername and clustertype begins here ########### -if [ -f "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" ]; then -cmd='openssl enc -d -aes-256-cbc -in "${SECRET_VOLUME}/${COMMON_OS_PWD_FILE}" -out /tmp/${COMMON_OS_PWD_FILE} -pass file:"${SECRET_VOLUME}/${PWD_KEY}"' - -eval $cmd - -if [ $? -eq 0 ]; then -print_message "Password file generated" -else -error_exit "Error occurred during common os password file generation" -fi - -read PASSWORD < /tmp/${COMMON_OS_PWD_FILE} -rm -f /tmp/${COMMON_OS_PWD_FILE} -else - print_message "Password is empty string" - export PASSWORD=O$(openssl rand -base64 6 | tr -d "=+/")_1 -fi - -if [ -z "${ORACLE_PWD}" ]; then - print_message "Setting ORACLE_PWD to PASSWORD passed from encrypted files" - export ORACLE_PWD=${PASSWORD} -else - print_message "ORACLE_PWD is set to user specified password" -fi - -################################################################################################### - -if [ -z "$SHARD_ADMIN_USER" ] -then - print_message "SHARD_ADMIN_USER is not set, setting default to mysdbadmin" - export SHARD_ADMIN_USER="mysdbadmin" -else - print_message "SHARD_ADMIn_USER set to $SHARD_ADMIN_USER" -fi - - -if [ -z "$PDB_ADMIN_USER" ] -then - print_message "PDB_ADMIN_USER is not set, setting default to PDBADMIN" - export PDB_ADMIN_USER="pdbadmin" -else - print_message "PDB_ADMIN_USER set to $PDB_ADMIN_USER" -fi - - -if [ -z "${SHARD_GROUP_NAME}" ]; then - print_message "SHARD_GROUP_NAME is not set, it will be set to primary_shardgroup" - export SHARD_GROUP_NAME="primary_shardgroup" -fi - -if [ -z "${SHARD_DEPLOYMENT_TYPE}" ]; then - print_message "SHARD_DEPLOYMENT_TYPE is not set, it will set to primary" - export SHARD_DEPLOYMENT_TYPE="primary" -fi - -if [ -z "${SHARD_DIRECTOR_NAME}" ]; then - print_message "SHARD_DIRECTOR_NAME is not set, it will set to sharddirector${region_num}" - export SHARD_DIRECTOR_NAME="sharddirector${region_num}" -fi - -if [ -z "${ORACLE_HOSTNAME}" ] -then - if [ -z "${KUBE_SVC}" ]; then - print_message "ORACLE_HOSTNAME variable is not set" - export ORACLE_HOSTNAME="$(hostname)" - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" - else - print_message "ORACLE_HOSTNAME variable is not set" - export ORACLE_HOSTNAME="$(hostname).${KUBE_SVC}" - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" - fi -else - print_message "ORACLE_HOSTNAME is set to $ORACLE_HOSTNAME" -fi - -} - -###################################### Function Related to Check end here ################### - -################################### Reset Password ########################################### -resetPassword() -{ -if [ -f "${HOME}/setPassword.sh" ]; then -if [ ! -z "${ORACLE_PWD}" ]; then -"${HOME}"/setPassword.sh "$ORACLE_PWD" -fi -fi -} - -############################################################################################### -setupCatalog() -{ - -localconnectStr="/ as sysdba" -systemStr="system/${ORACLE_PWD}" -sqlScript="/tmp/setapp.sql" -print_message "Setting up Paramteres in Spfile" - -cmd1="drop table shardsetup;" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" - -cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - -cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - -cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" -#cmd=$( eval echo "$cmd1" ) -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter system set open_links=16 scope=spfile;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter system set open_links_per_instance=16 scope=spfile;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="@$ORACLE_HOME/rdbms/admin/setCatalogDBPrivs.sql;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" -print_message "cat /tmp/setup_grants_privs.lst" - -cmd1="alter user gsmcatuser account unlock;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter user gsmcatuser identified by $ORACLE_PWD;" -print_message "Sending query to sqlplus to execute alter user gsmcatuser identified by ORACLE_PWD;" -executeSQL "$cmd1" "$localconnectStr" - - -#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" -cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - - -cmd1="shutdown immediate;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="startup mount;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database archivelog;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database open;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database flashback on;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database force logging;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1", "$localconnectStr" - -cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - -if [ ! -z "${ORACLE_PDB}" ]; then -setupCatalogPDB -fi - -cmd1="create table shardsetup (status varchar2(10));" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" - -cmd1="insert into shardsetup values('completed');" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" -} - -configureSampleAppSchema() -{ -local sqlScript="/tmp/sqlScript.sql" -connectStr = "${SHARD_ADMIN_USER}/${ORACLE_PWD}" - -echo "alter session enable shard ddl;" > ${sqlScript} -echo "create user app_schema identified by '&1';" >> ${sqlScript} -echo "grant all privileges to app_schema;" >> ${sqlScript} -echo "grant gsmadmin_role to app_schema;" >> ${sqlScript} -echo "grant select_catalog_role to app_schema;" >> ${sqlScript} -echo "grant connect, resource to app_schema;" >> ${sqlScript} -echo "grant dba to app_schema;" >> ${sqlScript} -echo "grant execute on dbms_crypto to app_schema;" >> ${sqlScript} -echo "CREATE TABLESPACE SET TSP_SET_1 using template (datafile size 100m autoextend on next 10M maxsize unlimited extent management local segment space management auto);" >> ${sqlScript} -echo "CREATE TABLESPACE SET LOBTS1;" >> ${sqlScript} -echo "CREATE TABLESPACE products_tsp datafile size 100m autoextend on next 10M maxsize unlimited extent management local uniform size 1m; " >> ${sqlScript} -echo "CONNECT app_schema/'&1';" >> ${sqlScript} -echo "ALTER SESSION ENABLE SHARD DDL;" >> ${sqlScript} -echo "CREATE SHARDED TABLE Customers (CustId VARCHAR2(60) NOT NULL, FirstName VARCHAR2(60), LastName VARCHAR2(60), Class VARCHAR2(10), Geo VARCHAR2(8),CustProfile VARCHAR2(4000),Passwd RAW(60),CONSTRAINT pk_customers PRIMARY KEY (CustId),CONSTRAINT json_customers CHECK (CustProfile IS JSON)) TABLESPACE SET TSP_SET_1 PARTITION BY CONSISTENT HASH (CustId) PARTITIONS AUTO;" >> ${sqlScript} -echo "CREATE SHARDED TABLE Orders (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL, OrderDate TIMESTAMP NOT NULL,SumTotal NUMBER(19,4),Status CHAR(4), CONSTRAINT pk_orders PRIMARY KEY (CustId, OrderId),CONSTRAINT fk_orders_parent FOREIGN KEY (CustId) REFERENCES Customers ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_orders_parent);" >> ${sqlScript} -echo "CREATE SEQUENCE Orders_Seq;" >> ${sqlScript} -echo "CREATE SHARDED TABLE LineItems (OrderId INTEGER NOT NULL,CustId VARCHAR2(60) NOT NULL,ProductId INTEGER NOT NULL,Price NUMBER(19,4),Qty NUMBER,CONSTRAINT pk_items PRIMARY KEY (CustId, OrderId, ProductId),CONSTRAINT fk_items_parent FOREIGN KEY (CustId, OrderId) REFERENCES Orders ON DELETE CASCADE ) PARTITION BY REFERENCE (fk_items_parent);" >> ${sqlScript} -echo "CREATE DUPLICATED TABLE Products (ProductId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,Name VARCHAR2(128),DescrUri VARCHAR2(128),LastPrice NUMBER(19,4)) TABLESPACE products_tsp;" >> ${sqlScript} - -print_message "Executing sql script ${sqlScript}" -cat ${sqlScript} >> $LOGFILE -executeSQL "$cmd1" "$connectStr" "sqlScript" "${sqlScript}" - -} - - -setupCatalogPDB() -{ -#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" -pdbConnStr=" /as sysdba" - -local sqlScript="/tmp/sqlScript.sql" - -print_message "Settup Sql Script to setup Catalog PDB" -echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" -echo "create user ${SHARD_ADMIN_USER} identified by ${ORACLE_PWD};" >> "${sqlScript}" -echo "grant connect, create session, gsmadmin_role to ${SHARD_ADMIN_USER} ;" >> "${sqlScript}" -echo "grant inherit privileges on user SYS to GSMADMIN_INTERNAL;" >> "${sqlScript}" -echo "execute dbms_xdb.sethttpport(8080);" >> ${sqlScript} -echo "exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('${ORACLE_PWD}');" >> "${sqlScript}" - -print_message "Executing sql script ${sqlScript}" -cat ${sqlScript} >> $LOGFILE -executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" -} - -######################################################################## Catalog Setup task ends here ################################# - -######################################################################## Primary Shard Setup task ends here ################################# - -setupShardPDB() -{ - -#pdbConnStr="${PDB_ADMIN_USER}/${ORACLE_PWD}@//${ORACLE_HOSTNAME}:1521/${ORACLE_PDB}" -pdbConnStr=" /as sysdba" - -local sqlScript="/tmp/sqlScript.sql" -print_message "Settup Sql Script to setup Catalog PDB" -echo "alter session set container=${ORACLE_PDB};" > "${sqlScript}" -echo "grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" >> "${sqlScript}" -echo "grant sysdg to GSMUSER;" >> "${sqlScript}" -echo "grant sysbackup to GSMUSER;" >> "${sqlScript}" -echo "execute DBMS_GSM_FIX.validateShard;" >> ${sqlScript} -print_message "Executing sql script ${sqlScript}" -cat ${sqlScript} >> $LOGFILE -executeSQL "$cmd1" "${pdbConnStr}" "sqlScript" "${sqlScript}" - -} - -setupShardCDB() -{ -localconnectStr="/as sysdba" -systemStr="system/${ORACLE_PWD}" -print_message "Setting up Paramteres in Spfile" - -cmd1="drop table shardsetup;" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" - -cmd1="alter system set db_create_file_dest=\"${DB_CREATE_FILE_DEST}\" scope=both;" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - -cmd1="alter system set db_recovery_file_dest_size=${DB_RECOVERY_FILE_DEST_SIZE} scope=both;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - -cmd1="alter system set db_recovery_file_dest=\"${DB_RECOVERY_FILE_DEST}\" scope=both;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter system set open_links=16 scope=spfile;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter system set open_links_per_instance=16 scope=spfile;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter user gsmrootuser account unlock;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter user gsmrootuser identified by ${ORACLE_PWD} container=all;" -print_message "Sending query to sqlplus to execute alter user gsmrootuser identified by ORACLE_PWD container=all;" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="grant sysdg to gsmrootuser;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="grant sysbackup to gsmrootuser;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter user GSMUSER account unlock;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter user GSMUSER identified by ${ORACLE_PWD} container=all;" -print_message "Sending query to sqlplus to execute alter user GSMUSER identified by ORACLE_PWD container=all;" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="grant sysdg to GSMUSER;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="grant sysbackup to GSMUSER;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter system set dg_broker_start=true scope=both;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="create or replace directory DATA_PUMP_DIR as '${DATA_PUMP_DIR}';" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="grant read,write on directory DATA_PUMP_DIR to GSMADMIN_INTERNAL;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -#cmd1="alter system set remote_listener=\"\(ADDRESS=\(HOST=$ORACLE_HOSTNAME\)\(PORT=$DB_PORT\)\(PROTOCOL=tcp\)\)\";" -cmd1="alter system set remote_listener=\"(ADDRESS=(HOST=$ORACLE_HOSTNAME)(PORT=$DB_PORT)(PROTOCOL=tcp))\" scope=both;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="shutdown immediate;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="startup mount;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database archivelog;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database open;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database flashback on;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="alter database force logging;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -cmd1="ALTER PLUGGABLE DATABASE ALL OPEN;" -# cmd=$(eval echo "$cmd1") -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$localconnectStr" - - -if [ ! -z "${ORACLE_PDB}" ]; then - -setupShardPDB - -fi - -cmd1="create table shardsetup (status varchar2(10));" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" - - -cmd1="insert into shardsetup values('completed');" -print_message "Sending query to sqlplus to execute $cmd1" -executeSQL "$cmd1" "$systemStr" - -} - -######################################################################## Primary Shard Setup ends here ################################# - -######################################################################## GSM Setup Task Begin here ##################################### -setupGSM() -{ -local cstatus='false' -local sstatus='false' - -setupGSMCatalog -startGSM -addShardGroup -setupGSMShard - -} - -startGSM() -{ - -cmd1="start gsm" -print_message "Sending query to gsm to execute $cmd1" -executeGSM "$cmd1" -} - -deployShard() -{ - -cmd1="deploy" -print_message "Sending query to gsm to execute $cmd1" -executeGSM "$cmd1" -} - -stopGSM() -{ - -cmd1="stop gsm" -print_message "Sending query to gsm to execute $cmd1" -executeGSM "$cmd1" -} - -addInvitedNode() -{ - -chost=$1 - -cmd1="add invitednode $chost" -print_message "Sending query to gsm to execute $cmd1" -executeGSM "$cmd1" -} - - -addShardGroup() -{ - -cmd1="add shardgroup -shardgroup ${shardGName} -deploy_as ${deployment_type} -region ${region}" -print_message "Sending query to gsm to execute $cmd1" -executeGSM "$cmd1" -} - -checkStatus() -{ -host=$1 -port=1521 -cpdb=$3 -ccdb=$2 -uname="system" -cpasswd=${ORACLE_PWD} - -print_message "Connect String $uname/$cpasswd@//$host:$port/$ccdb" -output=$( "$ORACLE_HOME"/bin/sqlplus -s "$uname/$cpasswd@//$host:$port/$ccdb" <<EOF - set heading off feedback off verify off echo off PAGESIZE 0 - select status from shardsetup; - exit -EOF -) - - if [ "${output}" == 'completed' ];then - print_message "Returned status from catalog is $output" - else - print_message "Sleeping for 300 seconds as returned status is not $output " - sleep 300 - fi - - echo $output -} - -setupGSMCatalog() -{ -IFS='; ' read -r -a sarray <<< "$CATALOG_PARAMS" -for element in "${sarray[@]}" -do - print_message "1st String in Shard params $element" - type=$( echo $element | awk -F: '{print $NF }') - host=$( echo $element | awk -F: '{print $1 }') - db=$( echo $element | awk -F: '{print $2 }') - pdb=$( echo $element | awk -F: '{print $3 }') -done - -print_message "Set variables to host=${host} db=${db} pdb=${pdb}" -if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] -then -runtime="60 minute" -endtime=$(date -ud "$runtime" +%s) - -while [[ $(date -u +%s) -le $endtime ]] -do - - coutput=$( checkStatus $host $db $pdb ) - if [ "${coutput}" == 'completed' ] ;then - configureGSMCatalog $host $db $pdb - break - else - print_message "Catalog Status must return completed but returned value is $coutput" - fi - print_message "Catalog DB is still not ready. Sleeping for 60 seconds" - sleep 60 -done -fi - -if [ "${coutput}" != 'completed' ] ;then - error_exit "Shard Catalog is not setup, Unable to proceed futher" -fi - -} - -configureGSMCatalog() -{ -chost=$1 -cport=1521 -cpdb=$3 -ccdb=$2 -gsmhost=${ORACLE_HOSTNAME} -cadmin=${SHARD_ADMIN_USER} -cpasswd=${ORACLE_PWD} -########################## -region="${REGION}" -shardGName="${SHARD_GROUP_NAME}" -deployment_type="${SHARD_DEPLOYMENT_TYPE}" -local gdsScript="/tmp/gdsScript.sql" - -gsm_name="${SHARD_DIRECTOR_NAME}" -echo "create shardcatalog -database \"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=${chost})(PORT=${cport}))(CONNECT_DATA=(SERVICE_NAME=${cpdb})))\" -user ${cadmin}/${cpasswd} -sdb shardcatalog -region region1,region2 -agent_port 8080 -agent_password ${cpasswd} -autovncr off" > "${gdsScript}" -echo "add invitednode ${chost}" >> "${gdsScript}" -echo "add gsm -gsm ${gsm_name} -listener 1521 -pwd ${cpasswd} -catalog ${chost}:${cport}/${cpdb} -region region1 -endpoint '(ADDRESS=(PROTOCOL=tcp)(HOST=${gsmhost})(PORT=1521))'" >> "${gdsScript}" -echo "exit" >> "${gdsScript}" -print_message "Sending script to gsm to execute ${gdsScript}" -cat ${gdsScript} >> $LOGFILE -cp "${gdsScript}" "${gdsScript}.test" -executeGSM "$cmd1" "gdsScript" "${gdsScript}" -} - -setupGSMShard() -{ -IFS='; ' read -r -a sarray <<< "$PRIMARY_SHARD_PARAMS" -arrLen=$( echo "${#sarray[@]}" ) -count1=0 - -runtime="45 minute" -endtime=$(date -ud "$runtime" +%s) - -print_message "Set variables to host=${host} db=${db} pdb=${pdb}" -while [[ $(date -u +%s) -le $endtime ]] -do - for i in ${!sarray[@]}; do - print_message "1st String in Shard params $element" - host=$( echo ${sarray[i]} | awk -F: '{print $1 }') - db=$( echo ${sarray[i]} | awk -F: '{print $2 }') - pdb=$( echo ${sarray[i]} | awk -F: '{print $3 }') - print_message "shard env set to host=${host} db=${db} pdb=${pdb}" - if [ ! -z "${host}" ] && [ ! -z "${db}" ] && [ ! -z "${pdb}" ] - then - coutput=$( checkStatus $host $db $pdb ) - if [ "${coutput}" == 'completed' ] ;then - configureGSMShard $host $db $pdb - unset sarray[i] - ((++count1)) - else - print_message "Catalog Status must return completed but returned value is $coutput" - fi - fi - done - if [ ${count1} -ge ${arrLen} ]; then - break; - fi - print_message "Shards are still not ready. Sleeping for 120 seconds" - sleep 120 -done -} - -configureGSMShard() -{ -chost=$1 -cport=1521 -cpdb=$3 -ccdb=$2 -cpasswd=${ORACLE_PWD} -region=${REGION} -shardGName="${SHARD_GROUP_NAME}" -deployment_type="${SHARD_DEPLOYMENT_TYPE}" -local gdsScript="/tmp/gdsScript.sql" -admuser="${PDB_ADMIN_USER}" - -echo "connect ${admuser}/${cpasswd}" > "${gdsScript}" -echo "add cdb -connect ${chost}:${cport}:${ccdb} -pwd ${cpasswd}" >> "${gdsScript}" -echo "add shard -cdb ${ccdb} -connect ${chost}:${cport}/${cpdb} -shardgroup ${shardGName} -pwd ${cpasswd}" >> "${gdsScript}" -echo "config vncr" >> "${gdsScript}" -echo "sql 'update gsmadmin_internal.database set hostid=NULL '" >> "${gdsScript}" -echo "exit" >> "${gdsScript}" -print_message "Sending script to gsm to execute ${gdsScript}" -cat ${gdsScript} >> $LOGFILE -executeGSM "$cmd1" "gdsScript" "${gdsScript}" -print_message " Calling Stop GSM function" -stopGSM -print_message "Stop GSM function completed, sleeping for 20 seconds" -sleep 20 -print_message " Calling Start GSM function" -startGSM -print_message "Start GSM function completed, sleeping for 30 seconds" -sleep 30 -print_message "Calling invitenode function to add the shard" -addInvitedNode $chost -deployShard -} - -####################################################################### GSM Setup Task Ends here ######################################### - - -######################################################################### Execute GSM Statements ######################################### -executeGSM() -{ -gsmQuery=$1 -type=$2 -gdsScript=$3 - -if [ -z "${gsmQuery}" ]; then - print_message "Empty gdsQuery passed to gds" -fi - -if [ -z "${type}" ]; then - type='notSet' -fi - -if [ -z "${gdsScript}" ]; then - gdsScript='notSet' -fi - -if [ "${type}" == "gdsScript" ]; then -print_message "Executing gds script " -"$ORACLE_HOME"/bin/gdsctl @${gdsScript} -else -print_message "Executing GSM query" -"$ORACLE_HOME"/bin/gdsctl << EOF >> $LOGFILE - $gsmQuery - exit -EOF -fi -} -######################################################################## Execute GSM Statements Ends here ################################ - -########################################################################## Execute SQL Function Begin here ############################## -executeSQL() -{ -sqlQuery=$1 -connectStr=$2 -type=$3 -sqlScript=$4 - -if [ -z "${sqlQuery}" ]; then - print_message "Empty sqlQuery passed to sqlplus. Operation Failed" -fi - -if [ -z "${connectStr}" ]; then - error_exit "Empty connectStr passed to sqlplus. Operation Failed" -fi - -if [ -z "${type}" ]; then - type='notSet' -fi - -if [ -z "${sqlScript}" ]; then - sqlScript='notSet' -fi - -if [ "${type}" == "sqlScript" ] && [ -f ${sqlScript} ]; then -print_message "Executing sql script using connect string" -"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE -@ ${sqlScript} -EOF -else -print_message "Executing sqlQuery using connect string" -"$ORACLE_HOME"/bin/sqlplus -s "$connectStr" << EOF >> $LOGFILE -$sqlQuery -EOF -fi -} - -############################################################################## Execute SQl Function ends here ################################# - -####################################### -################## MAIN ############### - -if [ "${OP_TYPE}" == "primaryshard" ]; then - print_message "Performing Checks before proceeding for setup" - dbChecks - print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" - resetPassword - setupShardCDB -elif [ "${OP_TYPE}" == "standbyshard" ]; then - print_message "Performing Checks before proceeding for setup" - dbChecks - print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" - setupShardStandby -elif [ "${OP_TYPE}" == "catalog" ]; then - print_message "Performing Checks before proceeding for setup" - dbChecks - print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" - resetPassword - setupCatalog -elif [ "${OP_TYPE}" == "gsm" ]; then - print_message "Performing Checks before proceeding for setup" - gsmChecks - print_message "OP_TYPE set to ${OP_TYPE}. Process to setup ${OP_TYPE} will begin now" - setupGSM -else - print_message "OP_TYPE must be set to (gsm|catalog|primaryshard|standbyshard)" - exit 15 -fi