diff --git a/docker-based-sharding-deployment/README.md b/docker-based-sharding-deployment/README.md
index 2726bbb..b245a6a 100644
--- a/docker-based-sharding-deployment/README.md
+++ b/docker-based-sharding-deployment/README.md
@@ -117,23 +117,26 @@ Specify the secret volume for resetting database users password during catalog a
 
 ```
 mkdir /opt/.secrets/
-openssl rand -hex 64 -out /opt/.secrets/pwd.key
+openssl genrsa -out /opt/.secrets/key.pem
+openssl rsa -in /opt/.secrets/key.pem -out /opt/.secrets/key.pub -pubout
 ```
 
-Edit the `/opt/.secrets/common_os_pwdfile` and seed the password for grid/oracle and database. It will be a common password for all the database users. Execute following command:  
+Edit the /opt/.secrets/pwdfile.txt and seed the password. It will be a common password for all the database users. Execute following command: 
 ```
-vi /opt/.secrets/common_os_pwdfile
+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/common_os_pwdfile` file, execute following command:  
+After seeding password and saving the `/opt/.secrets/pwdfile.txt` file, execute following command:  
 ```
-openssl enc -aes-256-cbc -salt -in /opt/.secrets/common_os_pwdfile -out /opt/.secrets/common_os_pwdfile.enc -pass file:/opt/.secrets/pwd.key
-rm -f /opt/.secrets/common_os_pwdfile
-chown 54321:54321 /opt/.secrets/common_os_pwdfile.enc
-chown 54321:54321 /opt/.secrets/pwd.key
-chmod 400 /opt/.secrets/common_os_pwdfile.enc
-chmod 400 /opt/.secrets/pwd.key
+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 is being used for initial sharding topology setup. Once the sharding topology setup is completed, user must change the sharding topology passwords based on his enviornment.
@@ -145,8 +148,8 @@ The shard catalog is a special-purpose Oracle Database that is a persistent stor
 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 README.md, we used /oradata/dbfiles/CATALOG directory and exposed as volume to catalog container.
 
 ```
-mkdir -p /oradata/dbfiles/CATALOG
-chown -R 54321:54321 /oradata/dbfiles/CATALOG
+mkdir -p /scratch/oradata/dbfiles/CATALOG
+chown -R 54321:54321 /scratch/oradata/dbfiles/CATALOG
 ```
 
 **Notes**: 
@@ -172,14 +175,14 @@ docker run -d --hostname oshard-catalog-0 \
  -e ORACLE_SID=CATCDB \
  -e ORACLE_PDB=CAT1PDB \
  -e OP_TYPE=catalog \
- -e COMMON_OS_PWD_FILE=common_os_pwdfile.enc \
- -e PWD_KEY=pwd.key \
+ -e COMMON_OS_PWD_FILE=pwdfile.enc \
+ -e PWD_KEY=key.pem \
  -e SHARD_SETUP="true" \
- -v /oradata/dbfiles/CATALOG:/opt/oracle/oradata \
+ -v /scratch/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:21.3.0-ee
+ --name catalog oracle/database-ext-sharding:21.3.0-ee
  
     Mandatory Parameters:
       COMMON_OS_PWD_FILE:       Specify the encrypted password file to be read inside the ontainer
@@ -204,20 +207,20 @@ docker logs -f catalog
 ```
 
 **IMPORTANT:** The resulting images will be an image with the Oracle binaries installed. On first startup of the container a new database will be created, the following lines highlight when the Shard database is ready to be used:
-
-    ################################################
-	Oracle GSM Catalog Setup Completed Successfully!
-	################################################
-	
+```bash
+################################################
+Oracle GSM Catalog Setup Completed Successfully!
+################################################
+```
 #### 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 Sharding DB 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. During the setup of this README.md, we used /oradata/dbfiles/ORCL1CDB directory and exposed as volume to shard container.
 
 ##### Create Directories
 ```
-mkdir -p /oradata/dbfiles/ORCL1CDB
-mkdir -p /oradata/dbfiles/ORCL2CDB
-chown -R 54321:54321 /oradata/dbfiles/ORCL2CDB
-chown -R 54321:54321 /oradata/dbfiles/ORCL1CDB
+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**: 
@@ -237,25 +240,26 @@ Before creating shard1 container, review the following notes carefully:
 
 ```
 docker run -d --hostname oshard1-0 \
-  --dns-search=example.com \
+ --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 COMMON_OS_PWD_FILE=common_os_pwdfile.enc \
- -e PWD_KEY=pwd.key \
- -v /oradata/dbfiles/ORCL1CDB:/opt/oracle/oradata \
+ -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:21.3.0-ee
+ --name shard1 oracle/database-ext-sharding:21.3.0-ee
  
    Mandatory Parameters:
       COMMON_OS_PWD_FILE:       Specify the encrypted password file to be read inside container
-      PWD.key:                  Specify password key file to decrypt the encrypted password file and read the password
+      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 primaryshard or standbyshard
       DOMAIN:                   Specify the domain name
       ORACLE_SID:               CDB name
@@ -265,15 +269,20 @@ docker run -d --hostname oshard1-0 \
       CUSTOM_SHARD_SCRIPT_DIR:  Specify the location of custom scripts which you want to run after setting up shard setup.
       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.
       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.
-      OLD_ORACLE_SID: Specify the OLD_ORACLE_SID if you are performing db seed clonging using existing cold backup of Oracle DB.
+      OLD_ORACLE_SID: Specify the OLD_ORACLE_SID if you are performing db seed cloning 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.
 ```
 
 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
 ```
+```bash
+##############################################
+Oracle GSM Shard Setup Completed Successfully!
+###############################################
+```	
 
 ##### Shard2 Container
 Before creating shard1 container, review the following notes carefully:  
@@ -287,25 +296,26 @@ Before creating shard1 container, review the following notes carefully:
 
 ```
 docker run -d --hostname oshard2-0 \
-  --dns-search=example.com \
+ --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=common_os_pwdfile.enc \
- -e PWD_KEY=pwd.key \
+ -e COMMON_OS_PWD_FILE=pwdfile.enc \
+ -e PWD_KEY=key.pem \
  -e SHARD_SETUP="true" \
- -v /oradata/dbfiles/ORCL2CDB:/opt/oracle/oradata \
+ -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:21.3.0-ee
+ --name shard2 oracle/database-ext-sharding:21.3.0-ee
   
      Mandatory Parameters:
       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
+      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 primaryshard or standbyshard
       DOMAIN:                   Specify the domain name
       ORACLE_SID:               CDB name
@@ -315,7 +325,7 @@ docker run -d --hostname oshard2-0 \
       CUSTOM_SHARD_SCRIPT_DIR:  Specify the location of custom scripts that you want to run after setting up the shard setup.
       CUSTOM_SHARD_SCRIPT_FILE: Specify the file name which must be available on CUSTOM_SHARD_SCRIPT_DIR location to be executed after shard db setup.
       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.
-      OLD_ORACLE_SID: Specify the OLD_ORACLE_SID if you are performing db seed clonging using existing cold backup of Oracle DB.
+      OLD_ORACLE_SID: Specify the OLD_ORACLE_SID if you are performing db seed cloning 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.
 ```
 
@@ -328,57 +338,58 @@ docker logs -f shard2
 
 **IMPORTANT:** The resulting images will be an image with the Oracle binaries installed. On first startup of the container a new database will be created, the following lines highlight when the Shard database is ready to be used:
 
-    ##############################################
-	Oracle GSM Shard Setup Completed Successfully!
-	###############################################
-	
+```bash
+##############################################
+Oracle GSM Shard Setup Completed Successfully!
+###############################################
+```	
 #### 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 /oradata/dbfiles/GSMDATA directory and exposed as volume to GSM container.
 
 ##### Create Directory
 ```
-mkdir -p /oradata/dbfiles/GSMDATA
-chown -R 54321:54321 /oradata/dbfiles/GSMDATA
+mkdir -p /scratch/oradata/dbfiles/GSMDATA
+chown -R 54321:54321 /scratch/oradata/dbfiles/GSMDATA
 ```
 
 ##### Create GSM Master Container
 ```
-  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=common_os_pwdfile.enc \
-   -e PWD_KEY=pwd.key \
-   -v /oradata/dbfiles/GSMDATA:/opt/oracle/gsmdata \
-   -v /opt/containers/shard_host_file:/etc/hosts \
-   --volume /opt/.secrets:/run/secrets:ro \
-   -e OP_TYPE=gsm \
-   -e MASTER_GSM="TRUE" \
-   --privileged=false \
-   --name gsm1 oracle/database-gsm:21.3.0
+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 \
+ -v /scratch/oradata/dbfiles/GSMDATA:/opt/oracle/gsmdata \
+ -v /opt/containers/shard_host_file:/etc/hosts \
+ --volume /opt/.secrets:/run/secrets:ro \
+ -e OP_TYPE=gsm \
+ -e MASTER_GSM="TRUE" \
+ --privileged=false \
+ --name gsm1 oracle/database-gsm:21.3.0 
    
    Mandatory Parameters:
       SHARD_DIRECTOR_PARAMS:     Accept key value pair separated by semicolon e.g. <key>=<value>;<key>=<value> 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
-                                 
+
       SHARD[1-9]_GROUP_PARAMS:   Accept key value pair separated by semicolon e.g. <key>=<value>;<key>=<value> for following <key>=<value> pairs:
                                  key=group_name,        value=shard group name
                                  key=deploy_as,         value=deploy shard group as primary or active_standby
                                  key=group_region,      value=shard group region name
-         **Notes**: 
-           SHARD[1-9]_GROUP_PARAMS is in regex form, you can specify env parameter based on your enviornment such SHARD1_GROUP_PARAMS, SHARD2_GROUP_PARAMS.
+         **Notes**:
+           SHARD[1-9]_GROUP_PARAMS is in regex form, you can specify env parameter based on your environment such SHARD1_GROUP_PARAMS, SHARD2_GROUP_PARAMS.
            Each SHARD[1-9]_GROUP_PARAMS must have above key value pair.
-         
+
       CATALOG_PARAMS:            Accept key value pair separated by semicolon e.g. <key>=<value>;<key>=<value> for following <key>=<value> pairs:
                                  key=catalog_host,       value=catalog hostname
                                  key=catalog_db,         value=catalog cdb name
@@ -386,26 +397,26 @@ chown -R 54321:54321 /oradata/dbfiles/GSMDATA
                                  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
-                                 
+
       SHARD[1-9]_PARAMS:         Accept key value pair separated by semicolon e.g. <key>=<value>;<key>=<value> for following <key>=<value> pairs:
-                                 key=shard_host,         value=shard hostname 
+                                 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
-        **Notes**: 
-           SHARD[1-9]_PARAMS is in regex form, you can specify env parameter based on your enviornment such SHARD1_PARAMS, SHARD2_PARAMS.
+        **Notes**:
+           SHARD[1-9]_PARAMS is in regex form, you can specify env parameter based on your environment such SHARD1_PARAMS, SHARD2_PARAMS.
            Each SHARD[1-9]_PARAMS must have above key value pair.
-                                  
+
       SERVICE[1-9]_PARAMS:      Accept key value pair separated by semicolon e.g. <key>=<value>;<key>=<value> for following <key>=<value> pairs:
                                  key=service_name,       value=service name
                                  key=service_role,       value=service role e.g. primary or physical_standby
-        **Notes**: 
-           SERVICE[1-9]_PARAMS is in regex form, you can specify env parameter based on your enviornment such SERVICE1_PARAMS, SERVICE2_PARAMS.
-           Each SERVICE[1-9]_PARAMS must have above key value pair. 
-           
+        **Notes**:
+           SERVICE[1-9]_PARAMS is in regex form, you can specify env parameter based on your environment such SERVICE1_PARAMS, SERVICE2_PARAMS.
+           Each SERVICE[1-9]_PARAMS must have above key value pair.
+
       COMMON_OS_PWD_FILE:       Specify the encrypted password file to be read inside container
-      PWD.key:                  Specify password key file to decrypt the encrypted password file and read the password
+      PWD_KEY:                  Specify password key file to decrypt the encrypted password file and read the password
       OP_TYPE:                  Specify the operation type. For GSM it has to be set to gsm.
       DOMAIN:                   Domain of the container.
       MASTER_GSM:               Set value to "TRUE" if you want the GSM to be a master GSM. Otherwise, do not set it.
@@ -419,42 +430,54 @@ chown -R 54321:54321 /oradata/dbfiles/GSMDATA
       EXECUTOR:                 Specify the script executor such as /bin/python or /bin/bash. Default set to /bin/python.
 ```
 
-**Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, PRIMARY_SHARD_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment. 
+**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
 ```
+```bash
+##############################################
+Oracle GSM Setup Completed Successfully!
+###############################################
+```
+#### Deploying Standby GSM Container
 
-#### Create GSM Standby Container
-You need GSM standby container to serve the connection when master GSM fails.
+You need standby GSM container to serve the connection when master GSM fails.
 
-##### Create Directory
-```
+##### Create Directory for Standby GSM Container
+
+```bash
 mkdir -p /oradata/dbfiles/GSM2DATA
 chown -R 54321:54321 /oradata/dbfiles/GSM2DATA
 ```
 
-##### Create Container
+##### Create Standby GSM Container
+
 ```
-  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=region1;director_port=1522" \
-   -e SHARD1_GROUP_PARAMS="group_name=shardgroup1;deploy_as=active_standby;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 CATALOG_SETUP="True" \
-   -e COMMON_OS_PWD_FILE=common_os_pwdfile.enc \
-   -e PWD_KEY=pwd.key \
-   -v /oradata/dbfiles/GSM2DATA:/opt/oracle/gsmdata \
-   -v /opt/containers/shard_host_file:/etc/hosts \
-   --volume /opt/.secrets:/run/secrets:ro \
-   -e OP_TYPE=gsm \
-   --privileged=false \
-   --name gsm2 oracle/database-gsm:21.3.0
+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=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 \
+ -v /oradata/dbfiles/GSM2DATA:/opt/oracle/gsmdata \
+ -v /opt/containers/shard_host_file:/etc/hosts \
+ --volume /opt/.secrets:/run/secrets:ro \
+ -e OP_TYPE=gsm \
+ --privileged=false \
+ --name gsm2 oracle/database-gsm:21.3.0
+
 **Note:** Change environment variables such as DOMAIN, CATALOG_PARAMS, COMMON_OS_PWD_FILE and PWD_KEY according to your environment.
 
    Mandatory Parameters:
@@ -468,18 +491,20 @@ chown -R 54321:54321 /oradata/dbfiles/GSM2DATA
                                  key=catalog_region,     value=specify comma separated region name for catalog db deployment
 ```
 
+**IMPORTANT:** The resulting images will be an image with the Oracle GSM binaries installed. On first startup of the container a new GSM setup will be created, the following lines highlight when the GSM setup is ready to be used:
+
 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 resulting images will be an image with the Oracle GSM binaries installed. On first startup of the container a new GSM setup will be created, the following lines highlight when the GSM setup is ready to be used:
 
-```
-    ##############################################
-	Oracle GSM Setup Completed Successfully!
-	###############################################
+```bash
+##############################################
+Oracle GSM Setup Completed Successfully!
+###############################################
 ```
 
 ## Support 
@@ -494,4 +519,4 @@ All scripts and files hosted in this project and GitHub docker-images/OracleData
 
 ## Copyright 
 
-Copyright (c) 2014-2021 Oracle and/or its affiliates.
+Copyright (c) 2014-2024 Oracle and/or its affiliates.
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/Dockerfile b/docker-based-sharding-deployment/dockerfiles/19.3.0/Dockerfile
index 366922a..a1cbf87 100644
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/Dockerfile
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/Dockerfile
@@ -18,11 +18,22 @@
 #
 # Pull base image
 # ---------------
-FROM oraclelinux:7-slim as base
+ARG BASE_OL_IMAGE=oraclelinux:7-slim
 
-# Maintainer
-# ----------
-MAINTAINER Paramdeep Saini <paramdeep.saini@oracle.com>
+# 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_193000_gsm.zip"
 
 # Environment variables required for this build (do NOT change)
 # -------------------------------------------------------------
@@ -30,7 +41,7 @@ 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_FILE_1=$INSTALL_FILE_1 \
     INSTALL_RSP="19c_gsm_install.rsp" \
     RUN_FILE="runOracle.sh" \
     SETUP_LINUX_FILE="setupLinuxEnv.sh" \
@@ -41,20 +52,22 @@ ENV GSM_BASE="/u01/app/oracle" \
     GSM_ENV_SETUP_FILE="setupGSM.sh" \
     GSM_SCRIPTS="scripts" \
     MAINPY="main.py" \
-    CHECKLIVENESS="checkLiveness.sh" 
+    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:$PATH \
-     GSM_PATH=$GSM_HOME/bin:/usr/sbin:$PATH \
-     GSM_LD_LIBRARY_PATH=$GSM_HOME/lib:/usr/lib:/lib 
-    
+     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 $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 $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/
 
@@ -63,7 +76,22 @@ RUN chmod 755 $INSTALL_DIR/install/*.sh && \
     $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-19c.conf && \
+    sed -e '/ *nofile /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 && \
@@ -72,10 +100,30 @@ RUN chmod 755 $INSTALL_DIR/install/*.sh && \
     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 && \
+    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
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/cmdExec b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/cmdExec
old mode 100644
new mode 100755
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/demoapp.sql b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/demoapp.sql
old mode 100644
new mode 100755
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/main.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/main.py
old mode 100644
new mode 100755
index da0c6a9..b7f0f17
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/main.py
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/main.py
@@ -20,7 +20,7 @@ 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=','validatenochunks=','invitednode=','help'])
+      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
   
@@ -45,7 +45,7 @@ def main():
 
    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', '--invitednode', or --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")   
@@ -68,6 +68,12 @@ def main():
            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
@@ -83,8 +89,6 @@ def main():
            oralogger.filename_ =  file_name
            ocommon.log_info_message("=======================================================================",file_name)
            oenv.add_custom_variable("CREATE_DIR",arg)
-      elif opt in ('--optype'):
-          oenv.add_custom_variable("OP_TYPE",arg)
       elif opt in ('--addshardgroup'):
            file_name = oenv.logfile_name("ADD_SGROUP_PARAMS")
            oralogger.filename_ =  file_name
@@ -130,6 +134,23 @@ def main():
            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
 
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oracommon.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oracommon.py
old mode 100644
new mode 100755
index f5c2f14..634a9f1
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oracommon.py
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oracommon.py
@@ -13,7 +13,6 @@
 import time
 import datetime
 import os
-import commands
 import getopt
 import shlex
 import json
@@ -22,12 +21,15 @@
 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):
@@ -41,7 +43,7 @@ def run_sqlplus(self,cmd,sql_cmd,dbenv):
             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)
+            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
@@ -51,7 +53,7 @@ def run_sqlplus(self,cmd,sql_cmd,dbenv):
             self.log_error_message(error_msg,self.file_name)
             self.prog_exit(self)
 
-          return stdout,stderr,retcode
+          return stdout.replace("\n\n", "\n"),stderr,retcode
 
       def execute_cmd(self,cmd,env,dir):
           """
@@ -61,7 +63,7 @@ def execute_cmd(self,cmd,env,dir):
             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)
+            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()
@@ -280,6 +282,24 @@ def update_key(self,key,value,env_dict):
 
           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
@@ -328,7 +348,7 @@ def create_dir(self,dir,local,remote,user):
                  msg='''Dir {0} already exist'''.format(dir)
                  self.log_info_message(msg,self.file_name)
 
-          if remote and node:
+          if remote:
              pass
 
       def create_file(self,file,local,remote,user):
@@ -348,14 +368,14 @@ def create_file(self,file,local,remote,user):
                  output,error,retcode=self.execute_cmd(cmd,None,None)
                  self.check_os_err(output,error,retcode,True)
 
-          if remote and node:
+          if remote:
              pass
 
       def shutdown_db(self,env_dict):
            """
            Shutdown the database
            """
-           file="/home/oracle/shutDown.sh immediate"
+           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"])
@@ -367,7 +387,7 @@ def shutdown_db(self,env_dict):
               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)
+              cmd='''sh {0} immediate'''.format(file)
               output,error,retcode=self.execute_cmd(cmd,None,None)
               self.check_os_err(output,error,retcode,True)
                  
@@ -432,6 +452,39 @@ def stop_gsm(self,env_dict):
            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
@@ -472,6 +525,23 @@ def check_substr_match(self,source_str,sub_str):
            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
@@ -539,7 +609,28 @@ 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):
            """
@@ -607,24 +698,121 @@ def get_sys_passwd(self):
          return dbpasswd
 
       def get_password(self,key):
-         """
-         get the password
-         """
-         passwd_file_flag=False
-         self.log_info_message("Getting the OS password",self.file_name)
-         if key == 'ASM':
-            pass
-         elif key == 'OS':
-            pass
-         else:
+            """
+            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)
 
-######### Get Password ##############
+            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
@@ -634,3 +822,65 @@ def get_oraversion(self,home):
          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/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oraenv.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oraenv.py
old mode 100644
new mode 100755
index f33bb1a..dd96c48
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oraenv.py
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oraenv.py
@@ -15,6 +15,7 @@
 class OraEnv:
    __instance                                  = None
    __env_var_file                              = '/etc/rac_env_vars'
+   
    __env_var_file_flag                         = None
    __env_var_dict                              = {}
    __ora_asm_diskgroup_name                    = '+DATA'
@@ -60,6 +61,8 @@ def read_variable():
    @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"
  
@@ -102,6 +105,8 @@ def logfile_name(file_type):
          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":
@@ -122,6 +127,12 @@ def logfile_name(file_type):
          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
 
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orafactory.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orafactory.py
old mode 100644
new mode 100755
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oragsm.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oragsm.py
old mode 100644
new mode 100755
index 4a5266e..ef0bb06
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oragsm.py
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oragsm.py
@@ -74,7 +74,16 @@ def setup(self):
                 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.self.setup_gsm_shardg("ADD_SGROUP_PARAMS")
+                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()
@@ -83,8 +92,13 @@ def setup(self):
                 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.remove_gsm_shard()
+                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()
@@ -94,6 +108,9 @@ def setup(self):
              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()
@@ -148,10 +165,18 @@ def setup(self):
              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):
@@ -186,7 +211,11 @@ def setup(self):
                      self.setup_gsm_director()
                      self.start_gsm_director()
                      self.status_gsm_director()
-                     self.setup_gsm_shardg("SHARD_GROUP")
+                     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
@@ -216,7 +245,13 @@ def setup(self):
                    self.setup_gsm_director()
                    self.start_gsm_director()
                    self.status_gsm_director()
-                   self.setup_gsm_shardg("SHARD_GROUP")
+                   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()
@@ -247,8 +282,16 @@ 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")
 
-      ###########  SETUP_MACHINE ENDS here ####################
+      ###########   ENDS here ####################
 
       def gsm_checks(self):
           """
@@ -259,7 +302,7 @@ def gsm_checks(self):
           self.shard_user_check()
           self.gsm_hostname_check()
           self.director_params_checks()
-	  self.catalog_params_check()
+          self.catalog_params_check()
           self.shard_params_check()
           self.sgroup_params_check()
 
@@ -295,65 +338,13 @@ def ohome_check(self):
                    self.ocommon.prog_exit("127")
 
       def passwd_check(self):
-                 """
-                 This funnction perform password related checks
-                 """
-                 passwd_file_flag = False
-                 if self.ocommon.check_key("SECRET_VOLUME",self.ora_env_dict):
-                    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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-                 if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-                 if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-                 secret_volume = self.ora_env_dict["SECRET_VOLUME"]
-                 common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"]
-                 pwd_key = self.ora_env_dict["PWD_KEY"]
-                 passwd_file='''{0}/{1}'''.format(self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict["COMMON_OS_PWD_FILE"])
-                 if os.path.isfile(passwd_file):
-                    msg='''Passwd file {0} exist. Password file Check passed!'''.format(passwd_file)
-                    self.ocommon.log_info_message(msg,self.file_name)
-                    msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file)
-                    self.ocommon.log_info_message(msg,self.file_name)
-                    cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out /tmp/{1} -pass file:\"{0}/{2}\"'''.format(secret_volume,common_os_pwd_file,pwd_key)
-                    output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
-                    self.ocommon.check_os_err(output,error,retcode,True)
-                    passwd_file_flag = True
-
-                 if not passwd_file_flag:
-                    s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
-                    passlen = 8
-                    password  =  "".join(random.sample(s,passlen ))
-                 else:
-                    fname='''/tmp/{0}'''.format(common_os_pwd_file)
-                    fdata=self.ocommon.read_file(fname)
-                    password=fdata
-                    self.ocommon.remove_file(fname)
-
-                 if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict):
-                    msg="ORACLE_PWD is passed as an env variable. Check Passed!"
-                    self.ocommon.log_info_message(msg,self.file_name)
-                 else:
-                    self.ora_env_dict=self.ocommon.add_key("ORACLE_PWD",password,self.ora_env_dict)
-                    msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file"
-                    self.ocommon.log_info_message(msg,self.file_name)
+           """
+           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):
                  """
@@ -396,7 +387,8 @@ def gsm_hostname_check(self):
                     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}.{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)
@@ -413,6 +405,13 @@ def catalog_params_check(self):
                      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:
@@ -554,10 +553,10 @@ def setup_gsm_calog(self):
                  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=self.process_clog_vars(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)
+                                 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)
@@ -581,6 +580,12 @@ def process_clog_vars(self,key):
           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]
@@ -599,16 +604,32 @@ def process_clog_vars(self,key):
               if ckey == 'catalog_name':
                  catalog_name = cvar_dict[ckey]
               if ckey == 'catalog_chunks':
-                     catalog_chunks = cvar_dict[ckey]                 
+                 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
+              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"))
@@ -649,27 +670,101 @@ def catalog_regex(self):
           return re.compile('CATALOG_PARAMS') 
 
       
-      def configure_gsm_clog(self,chost,ccdb,cpdb,cport,catalog_name,catalog_region,catalog_chunks):
+      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} -autovncr off;
+                  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)
+                  '''.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
 
-                 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()
 
@@ -697,9 +792,9 @@ def process_director_vars(self,key):
           if dtrname and dtrport and dtregion:
              return dtrname,dtrport,dtregion
           else:
-             msg1='''director_name={0},director_port={1}'''.format((director_name or "Missing Value"),(director_port or "Missing Value"))
-             msg2='''director_region={0}'''.format((director_region or "Missing Value"))
-             msg='''Director params {0} is not set correctly. One or more value is missing {1} {2}'''.format(SHARD_DIRECTOR_PARAMS,msg1,msg2)
+             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")
 
@@ -734,6 +829,54 @@ def check_gsm_director(self,dname):
 
           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
@@ -796,12 +939,12 @@ def setup_gsm_director(self):
                             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                              
+                     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':
@@ -809,8 +952,8 @@ def setup_gsm_director(self):
                    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") 
+                   self.ocommon.log_error_message(msg,self.file_name)
+                   self.ocommon.prog_exit("127") 
 
       def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin):
                  """
@@ -821,7 +964,10 @@ def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin):
                  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=self.process_clog_vars(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};
@@ -854,6 +1000,10 @@ def start_gsm_director(self):
                           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)
@@ -915,31 +1065,37 @@ def setup_gsm_shardg(self,restype):
                  elif restype == 'SHARD_GROUP':
                     reg_exp = self.shardg_regex()
                  else:
-                    self.ocommon.log_error_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.prog_exit("127")
+                    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)
-                              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)
-
-                       status = self.check_shardg_status(None,None)
-                       if status == 'completed':
-                          break
-                       else:
-                         msg='''GSM shard group 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_shardg_status(None,None)
-                 if status == 'completed':
+                              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:
@@ -1026,20 +1182,23 @@ def process_shardg_vars(self,key):
              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
-          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("(?:Shard Groups\n)(?:.+\n)+",output)
-             if self.ocommon.check_substr_match(matched_output[0],group_name):
-                status=True
-             else:
-                status=False
+         """
+         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():
@@ -1054,7 +1213,41 @@ def check_shardg_status(self,group_name,dname):
                           status=True
                      else:
                           status=False
-          return(self.ocommon.check_status_value(status))
+         '''
+         
+         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):
           """
@@ -1088,27 +1281,177 @@ def add_shardg_regex(self):
           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):
+      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};
-                   add shardgroup -shardgroup {3} -deploy_as {4} -region {5}
+                   {3};
                  exit;
-                  '''.format("NA",cadmin,cpasswd,group_name,deploy_as,group_region)
+                  '''.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):
                 """
@@ -1123,11 +1466,10 @@ def setup_gsm_shard(self):
                       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=self.process_shard_vars(key)
-
+                             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)
+                                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)
@@ -1164,12 +1506,25 @@ def add_gsm_shard(self):
                       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=self.process_shard_vars(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)
                              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)
+                                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)
@@ -1196,20 +1551,83 @@ 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()
+                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=self.process_shard_vars(key)
+                          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
@@ -1521,6 +1939,147 @@ def count_online_shards(self):
 
           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
@@ -1530,7 +2089,7 @@ def validate_gsm_shard(self):
                 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=self.process_shard_vars(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':
@@ -1550,6 +2109,9 @@ def process_shard_vars(self,key):
           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)
@@ -1570,14 +2132,30 @@ def process_shard_vars(self,key):
                  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
+              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"))
@@ -1586,6 +2164,39 @@ def process_shard_vars(self,key):
               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
@@ -1655,7 +2266,7 @@ def check_shard_status(self,shard_name):
                 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=self.process_shard_vars(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()):
@@ -1698,51 +2309,112 @@ def validate_shard_regex(self):
           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):
-                 """
-                  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)
-                 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)))" -shardgroup {7} -pwd {2};
-                  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 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()
+         """
+         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):
           """
@@ -1753,7 +2425,7 @@ def set_hostid_null(self):
           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=self.process_clog_vars(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'''
@@ -1770,232 +2442,238 @@ def set_hostid_null(self):
                  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)
+         """
+         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=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)
+         """
+         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=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)  
+         """
+         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"])
-                #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)):
-                self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"])
-                gsmcmd='''
-                    connect {1}/{2};
-                    config shardspace;
-                    config shardgroup;
-                    config vncr;
-                    deploy;
-                    config shard; 
-                   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()
-
-      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)
+         """
+         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"
             
-            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
+         self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"])
+         gsmcmd='''
+            connect {1}/{2};
+            {3};
+            config vncr;
+            deploy;
+            config shard; 
             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)
+         '''.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()
 
-            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'
+      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'
+               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'
+         """
+            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
+         """
+         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")
+         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):
           """
@@ -2067,27 +2745,27 @@ def service_regex(self):
           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()
+         """
+         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):
@@ -2118,7 +2796,7 @@ def setup_sample_schema(self):
           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=self.process_clog_vars(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':
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oralogger.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oralogger.py
old mode 100644
new mode 100755
index d9e0484..9a51b54
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oralogger.py
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oralogger.py
@@ -159,7 +159,7 @@ def handle(self,request):
           """
           request.stdout_ =  request.getStdOutValue()
           if request.stdout_ == LoggingType.STDOUT:
-            st = logging.FileHandler(request.stdoutfile_)
+            st = logging.FileHandler(request.stdoutfile_,mode="w")
             request.root.addHandler(st)
             st.setFormatter(request.formatter)
             self.print_message(request,st)
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oramachine.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/oramachine.py
old mode 100644
new mode 100755
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orapcatalog.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orapcatalog.py
old mode 100644
new mode 100755
index 52232cf..6638860
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orapcatalog.py
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orapcatalog.py
@@ -45,11 +45,46 @@ 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")
-            self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name)
-            sys.exit(0)
           else:
             self.setup_machine()
             self.db_checks()
@@ -61,6 +96,8 @@ def setup(self):
                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()
@@ -118,65 +155,13 @@ def ohome_check(self):
 
       def passwd_check(self):
            """
-           This funnction perform password related checks
+           Function to set the password
            """
-           passwd_file_flag = False
-           if self.ocommon.check_key("SECRET_VOLUME",self.ora_env_dict) and self.ocommon.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict) and self.ocommon.check_key("PWD_KEY",self.ora_env_dict):
-              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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-           if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-           if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-           secret_volume = self.ora_env_dict["SECRET_VOLUME"]
-           common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"]
-           pwd_key = self.ora_env_dict["PWD_KEY"]
-           passwd_file='''{0}/{1}'''.format(self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict["COMMON_OS_PWD_FILE"])
-           if os.path.isfile(passwd_file):
-              msg='''Passwd file {0} exist. Password file Check passed!'''.format(passwd_file)
-              self.ocommon.log_info_message(msg,self.file_name)
-              msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file)
-              self.ocommon.log_info_message(msg,self.file_name)
-              cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out /tmp/{1} -pass file:\"{0}/{2}\"'''.format(secret_volume,common_os_pwd_file,pwd_key)
-              output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
-              self.ocommon.check_os_err(output,error,retcode,True)
-              passwd_file_flag = True
-
-           if not passwd_file_flag:
-              s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
-              passlen = 8
-              password  =  "".join(random.sample(s,passlen ))
-           else:
-              fname='''/tmp/{0}'''.format(common_os_pwd_file)
-              fdata=self.ocommon.read_file(fname)
-              password=fdata
-              self.ocommon.remove_file(fname)
-
+           self.ocommon.get_password(None)
            if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict):
-              msg="ORACLE_PWD is passed as an env variable. Check Passed!"
-              self.ocommon.log_info_message(msg,self.file_name)
-           else:
-              self.ora_env_dict=self.ocommon.add_key("ORACLE_PWD",password,self.ora_env_dict)
-              msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file"
-              self.ocommon.log_info_message(msg,self.file_name)
-
+               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.
@@ -232,7 +217,8 @@ def hostname_check(self):
               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}.{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)
@@ -317,18 +303,7 @@ def reset_passwd(self):
          """
            This function reset the password.
          """
-         password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh")
-         self.ocommon.log_info_message("Executing password reset", self.file_name)
-         if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict) and self.ocommon.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script):
-            cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING')
-            self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"])
-            output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
-            self.ocommon.check_os_err(output,error,retcode,True)
-            self.ocommon.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.ocommon.log_error_message(msg,self.file_name)
-            self.oracommon.prog_exit()
+         self.ocommon.reset_passwd()
 
        ########## RESET_PASSWORD function ENDS here #############################
 
@@ -424,7 +399,6 @@ def setup_cdb_catalog(self):
              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 dg_broker_start=true scope=both;
              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)
 
@@ -440,29 +414,31 @@ 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 not self.ocommon.check_key("CLONE_DB",self.ora_env_dict):
-              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 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;
-               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)
-
+           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.
@@ -470,7 +446,7 @@ def set_dbparams_version(self):
            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:
+           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)
@@ -482,7 +458,7 @@ def set_dbparams_version(self):
               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}/admin\" scope=spfile;
+                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)
@@ -492,14 +468,15 @@ def restart_db(self):
           """
           restarting the db 
           """ 
-          if not self.ocommon.check_key("CLONE_DB",self.ora_env_dict):
-            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)
+          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='''
@@ -546,6 +523,7 @@ def setup_pdb_catalog(self):
               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);
@@ -570,7 +548,7 @@ def update_catalog_setup(self):
 
            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)
+           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='''
@@ -694,7 +672,7 @@ def register_services(self):
            # 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)
+           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'''
@@ -738,7 +716,7 @@ def backup_files(self):
           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_HOME"]
+             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}
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orapshard.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orapshard.py
old mode 100644
new mode 100755
index f5aa54e..d1b1273
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orapshard.py
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orapshard.py
@@ -49,9 +49,9 @@ def __init__(self,oralogger,orahandler,oraenv,oracommon):
           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)
+          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.
@@ -72,16 +72,31 @@ def setup(self):
                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")
-            self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name)
-            sys.exit(0)
-          elif self.ocommon.check_key("CREATE_DIR",self.ora_env_dict):
-            status = self.shard_setup_check()
-            if not status:
-               self.ocommon.prog_exit("127")
-            self.ocommon.create_dir(self.ora_env_dict["CREATE_DIR"],True,None,None) 
           else: 
             self.setup_machine() 
             self.db_checks()
@@ -93,6 +108,7 @@ def setup(self):
               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()
@@ -153,63 +169,11 @@ def passwd_check(self):
            """
            This funnction perform password related checks
            """
-           passwd_file_flag = False
-           if self.ocommon.check_key("SECRET_VOLUME",self.ora_env_dict) and self.ocommon.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict) and self.ocommon.check_key("PWD_KEY",self.ora_env_dict):
-              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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-           if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
- 
-           if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-              
-           secret_volume = self.ora_env_dict["SECRET_VOLUME"]
-           common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"]
-           pwd_key = self.ora_env_dict["PWD_KEY"]
-           passwd_file='''{0}/{1}'''.format(self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict["COMMON_OS_PWD_FILE"])
-           if os.path.isfile(passwd_file):
-              msg='''Passwd file {0} exist. Password file Check passed!'''.format(passwd_file)
-              self.ocommon.log_info_message(msg,self.file_name)
-              msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file)
-              self.ocommon.log_info_message(msg,self.file_name)
-              cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out /tmp/{1} -pass file:\"{0}/{2}\"'''.format(secret_volume,common_os_pwd_file,pwd_key)
-              output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
-              self.ocommon.check_os_err(output,error,retcode,True) 
-              passwd_file_flag = True
-
-           if not passwd_file_flag:
-              s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
-              passlen = 8
-              password  =  "".join(random.sample(s,passlen ))
-           else:
-              fname='''/tmp/{0}'''.format(common_os_pwd_file)
-              fdata=self.ocommon.read_file(fname)
-              password=fdata
-              self.ocommon.remove_file(fname)
-    
+           self.ocommon.get_password(None)
            if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict):
-              msg="ORACLE_PWD is passed as an env variable. Check Passed!"
-              self.ocommon.log_info_message(msg,self.file_name)              
-           else:
-              self.ora_env_dict=self.ocommon.add_key("ORACLE_PWD",password,self.ora_env_dict)
-              msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file"
-              self.ocommon.log_info_message(msg,self.file_name)
-
+               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.
@@ -264,7 +228,8 @@ def hostname_check(self):
               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}.{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)
@@ -349,18 +314,7 @@ def reset_passwd(self):
          """
            This function reset the password.
          """ 
-         password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh")
-         self.ocommon.log_info_message("Executing password reset", self.file_name)
-         if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict) and self.ocommon.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script):
-            cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING')
-            self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"])
-            output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
-            self.ocommon.check_os_err(output,error,retcode,True)
-            self.ocommon.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.ocommon.log_error_message(msg,self.file_name)
-            self.oracommon.prog_exit()
+         self.ocommon.reset_passwd()
 
        ########## RESET_PASSWORD function ENDS here #############################
 
@@ -436,7 +390,7 @@ def setup_cdb_shard(self):
            # 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)
+           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"]
@@ -454,6 +408,7 @@ def setup_cdb_shard(self):
              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;
@@ -462,10 +417,9 @@ def setup_cdb_shard(self):
              alter user GSMUSER  identified by HIDDEN_STRING  container=all;
              grant sysdg to GSMUSER;
              grant sysbackup to GSMUSER;
-             alter system set dg_broker_start=true scope=both;
              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=both;
+             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)
@@ -479,27 +433,28 @@ 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 not self.ocommon.check_key("CLONE_DB",self.ora_env_dict):
-              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)
+           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):
            """
@@ -508,7 +463,7 @@ def set_dbparams_version(self):
            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:
+           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)
@@ -517,10 +472,11 @@ def set_dbparams_version(self):
               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}/admin\" scope=spfile;
+                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)
@@ -531,14 +487,15 @@ def restart_db(self):
           """
           restarting the db
           """
-          if not self.ocommon.check_key("CLONE_DB",self.ora_env_dict):
-            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)
+          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='''
@@ -648,7 +605,7 @@ def update_shard_setup(self):
         
        ########## SETUP_CDB_SHARD FUNCTION ENDS HERE ###############################
           ###################################### Run custom scripts ##################################################
-      def run_custom_scripts():
+      def run_custom_scripts(self):
           """
            Custom script to be excuted on every restart of enviornment
           """
@@ -776,7 +733,7 @@ def register_services(self):
            # 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)
+           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'''
@@ -819,7 +776,7 @@ def backup_files(self):
           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_HOME"]
+             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}
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orascatalog.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orascatalog.py
old mode 100644
new mode 100755
index 0827a57..aa4ea65
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orascatalog.py
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orascatalog.py
@@ -6,4 +6,4 @@
 # Since: January, 2020
 # Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com
 
-class Common
+
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orasshard.py b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/orasshard.py
old mode 100644
new mode 100755
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/runOraShardSetup.sh b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/runOraShardSetup.sh
old mode 100644
new mode 100755
index d26037c..c1b09b4
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/runOraShardSetup.sh
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/runOraShardSetup.sh
@@ -36,6 +36,7 @@ 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
@@ -46,7 +47,9 @@ sqlplus / as sysdba << EOF
    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='*','/' 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
@@ -107,11 +110,12 @@ touch $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE
 
 }
 
-
 ############################################
-
-########### Symbolic link DB files ############
-function symLinkFiles {
+########### Symbolic link DB files #########
+############################################
+########### DB Version >= 23c ##############
+############################################
+function symLinkFiles23c {
 
    if [ -z ${ORACLE_BASE_HOME} ]; then
     # 
@@ -156,6 +160,152 @@ function symLinkFiles {
       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
@@ -163,7 +313,7 @@ function symLinkFiles {
    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 
+      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
@@ -191,7 +341,7 @@ function symLinkFiles {
        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 
+         ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID
        fi
      fi
    fi;
@@ -241,9 +391,9 @@ function symLinkFiles {
  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 
+      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 
+   # 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
@@ -333,7 +483,17 @@ 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
-   symLinkFiles;
+   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
@@ -353,6 +513,15 @@ if [ -d $ORACLE_BASE/oradata/$OLD_ORACLE_SID ]; then
    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 ."
@@ -362,7 +531,18 @@ fi
 fi
 
 if [ ${OP_TYPE,,} == "standbyshard" ]; then
-   symLinkFiles;
+   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
diff --git a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/runOracle.sh b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/runOracle.sh
old mode 100644
new mode 100755
index a404c0f..2266e99
--- a/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/runOracle.sh
+++ b/docker-based-sharding-deployment/dockerfiles/19.3.0/scripts/runOracle.sh
@@ -44,8 +44,8 @@ EOF
 # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
 ###################################
 
-if [ ! -z ${SHARD_SETUP} ]; then 
- if [ ${SHARD_SETUP,,} == "true" ]; then
+if [ ! -z ${SHARD_SETUP} ]; then
+  if [ ${SHARD_SETUP,,} == "true" ]; then
    sh $ORACLE_BASE/scripts/sharding/runOraShardSetup.sh
  fi
 fi
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/Dockerfile b/docker-based-sharding-deployment/dockerfiles/21.3.0/Dockerfile
index 39c7733..67cf141 100644
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/Dockerfile
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/Dockerfile
@@ -23,11 +23,22 @@
 #
 # Pull base image
 # ---------------
-FROM oraclelinux:7-slim as base
+ARG BASE_OL_IMAGE=oraclelinux:7-slim
 
-# Maintainer
-# ----------
-MAINTAINER Paramdeep Saini <paramdeep.saini@oracle.com>
+# 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)
 # -------------------------------------------------------------
@@ -35,7 +46,7 @@ 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="LINUX.X64_213000_gsm.zip" \
+    INSTALL_FILE_1=$INSTALL_FILE_1 \
     INSTALL_RSP="21c_gsm_install.rsp" \
     RUN_FILE="runOracle.sh" \
     SETUP_LINUX_FILE="setupLinuxEnv.sh" \
@@ -46,7 +57,9 @@ ENV GSM_BASE="/u01/app/oracle" \
     GSM_ENV_SETUP_FILE="setupGSM.sh" \
     GSM_SCRIPTS="scripts" \
     MAINPY="main.py" \
-    CHECKLIVENESS="checkLiveness.sh" 
+    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 \
@@ -54,12 +67,12 @@ ENV  INSTALL_SCRIPTS=$INSTALL_DIR/install \
      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 
-    
+     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 $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/
 
@@ -68,7 +81,22 @@ RUN chmod 755 $INSTALL_DIR/install/*.sh && \
     $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 && \
@@ -77,10 +105,30 @@ RUN chmod 755 $INSTALL_DIR/install/*.sh && \
     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
@@ -93,4 +141,4 @@ 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
+CMD exec $SCRIPT_DIR/$RUN_FILE
\ No newline at end of file
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/cmdExec b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/cmdExec
old mode 100644
new mode 100755
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/demoapp.sql b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/demoapp.sql
old mode 100644
new mode 100755
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/main.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/main.py
old mode 100644
new mode 100755
index da0c6a9..b7f0f17
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/main.py
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/main.py
@@ -20,7 +20,7 @@ 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=','validatenochunks=','invitednode=','help'])
+      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
   
@@ -45,7 +45,7 @@ def main():
 
    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', '--invitednode', or --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")   
@@ -68,6 +68,12 @@ def main():
            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
@@ -83,8 +89,6 @@ def main():
            oralogger.filename_ =  file_name
            ocommon.log_info_message("=======================================================================",file_name)
            oenv.add_custom_variable("CREATE_DIR",arg)
-      elif opt in ('--optype'):
-          oenv.add_custom_variable("OP_TYPE",arg)
       elif opt in ('--addshardgroup'):
            file_name = oenv.logfile_name("ADD_SGROUP_PARAMS")
            oralogger.filename_ =  file_name
@@ -130,6 +134,23 @@ def main():
            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
 
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oracommon.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oracommon.py
old mode 100644
new mode 100755
index f5c2f14..634a9f1
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oracommon.py
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oracommon.py
@@ -13,7 +13,6 @@
 import time
 import datetime
 import os
-import commands
 import getopt
 import shlex
 import json
@@ -22,12 +21,15 @@
 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):
@@ -41,7 +43,7 @@ def run_sqlplus(self,cmd,sql_cmd,dbenv):
             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)
+            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
@@ -51,7 +53,7 @@ def run_sqlplus(self,cmd,sql_cmd,dbenv):
             self.log_error_message(error_msg,self.file_name)
             self.prog_exit(self)
 
-          return stdout,stderr,retcode
+          return stdout.replace("\n\n", "\n"),stderr,retcode
 
       def execute_cmd(self,cmd,env,dir):
           """
@@ -61,7 +63,7 @@ def execute_cmd(self,cmd,env,dir):
             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)
+            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()
@@ -280,6 +282,24 @@ def update_key(self,key,value,env_dict):
 
           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
@@ -328,7 +348,7 @@ def create_dir(self,dir,local,remote,user):
                  msg='''Dir {0} already exist'''.format(dir)
                  self.log_info_message(msg,self.file_name)
 
-          if remote and node:
+          if remote:
              pass
 
       def create_file(self,file,local,remote,user):
@@ -348,14 +368,14 @@ def create_file(self,file,local,remote,user):
                  output,error,retcode=self.execute_cmd(cmd,None,None)
                  self.check_os_err(output,error,retcode,True)
 
-          if remote and node:
+          if remote:
              pass
 
       def shutdown_db(self,env_dict):
            """
            Shutdown the database
            """
-           file="/home/oracle/shutDown.sh immediate"
+           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"])
@@ -367,7 +387,7 @@ def shutdown_db(self,env_dict):
               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)
+              cmd='''sh {0} immediate'''.format(file)
               output,error,retcode=self.execute_cmd(cmd,None,None)
               self.check_os_err(output,error,retcode,True)
                  
@@ -432,6 +452,39 @@ def stop_gsm(self,env_dict):
            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
@@ -472,6 +525,23 @@ def check_substr_match(self,source_str,sub_str):
            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
@@ -539,7 +609,28 @@ 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):
            """
@@ -607,24 +698,121 @@ def get_sys_passwd(self):
          return dbpasswd
 
       def get_password(self,key):
-         """
-         get the password
-         """
-         passwd_file_flag=False
-         self.log_info_message("Getting the OS password",self.file_name)
-         if key == 'ASM':
-            pass
-         elif key == 'OS':
-            pass
-         else:
+            """
+            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)
 
-######### Get Password ##############
+            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
@@ -634,3 +822,65 @@ def get_oraversion(self,home):
          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/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oraenv.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oraenv.py
old mode 100644
new mode 100755
index f33bb1a..dd96c48
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oraenv.py
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oraenv.py
@@ -15,6 +15,7 @@
 class OraEnv:
    __instance                                  = None
    __env_var_file                              = '/etc/rac_env_vars'
+   
    __env_var_file_flag                         = None
    __env_var_dict                              = {}
    __ora_asm_diskgroup_name                    = '+DATA'
@@ -60,6 +61,8 @@ def read_variable():
    @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"
  
@@ -102,6 +105,8 @@ def logfile_name(file_type):
          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":
@@ -122,6 +127,12 @@ def logfile_name(file_type):
          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
 
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orafactory.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orafactory.py
old mode 100644
new mode 100755
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oragsm.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oragsm.py
old mode 100644
new mode 100755
index 4a5266e..ef0bb06
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oragsm.py
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oragsm.py
@@ -74,7 +74,16 @@ def setup(self):
                 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.self.setup_gsm_shardg("ADD_SGROUP_PARAMS")
+                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()
@@ -83,8 +92,13 @@ def setup(self):
                 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.remove_gsm_shard()
+                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()
@@ -94,6 +108,9 @@ def setup(self):
              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()
@@ -148,10 +165,18 @@ def setup(self):
              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):
@@ -186,7 +211,11 @@ def setup(self):
                      self.setup_gsm_director()
                      self.start_gsm_director()
                      self.status_gsm_director()
-                     self.setup_gsm_shardg("SHARD_GROUP")
+                     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
@@ -216,7 +245,13 @@ def setup(self):
                    self.setup_gsm_director()
                    self.start_gsm_director()
                    self.status_gsm_director()
-                   self.setup_gsm_shardg("SHARD_GROUP")
+                   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()
@@ -247,8 +282,16 @@ 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")
 
-      ###########  SETUP_MACHINE ENDS here ####################
+      ###########   ENDS here ####################
 
       def gsm_checks(self):
           """
@@ -259,7 +302,7 @@ def gsm_checks(self):
           self.shard_user_check()
           self.gsm_hostname_check()
           self.director_params_checks()
-	  self.catalog_params_check()
+          self.catalog_params_check()
           self.shard_params_check()
           self.sgroup_params_check()
 
@@ -295,65 +338,13 @@ def ohome_check(self):
                    self.ocommon.prog_exit("127")
 
       def passwd_check(self):
-                 """
-                 This funnction perform password related checks
-                 """
-                 passwd_file_flag = False
-                 if self.ocommon.check_key("SECRET_VOLUME",self.ora_env_dict):
-                    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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-                 if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-                 if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-                 secret_volume = self.ora_env_dict["SECRET_VOLUME"]
-                 common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"]
-                 pwd_key = self.ora_env_dict["PWD_KEY"]
-                 passwd_file='''{0}/{1}'''.format(self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict["COMMON_OS_PWD_FILE"])
-                 if os.path.isfile(passwd_file):
-                    msg='''Passwd file {0} exist. Password file Check passed!'''.format(passwd_file)
-                    self.ocommon.log_info_message(msg,self.file_name)
-                    msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file)
-                    self.ocommon.log_info_message(msg,self.file_name)
-                    cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out /tmp/{1} -pass file:\"{0}/{2}\"'''.format(secret_volume,common_os_pwd_file,pwd_key)
-                    output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
-                    self.ocommon.check_os_err(output,error,retcode,True)
-                    passwd_file_flag = True
-
-                 if not passwd_file_flag:
-                    s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
-                    passlen = 8
-                    password  =  "".join(random.sample(s,passlen ))
-                 else:
-                    fname='''/tmp/{0}'''.format(common_os_pwd_file)
-                    fdata=self.ocommon.read_file(fname)
-                    password=fdata
-                    self.ocommon.remove_file(fname)
-
-                 if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict):
-                    msg="ORACLE_PWD is passed as an env variable. Check Passed!"
-                    self.ocommon.log_info_message(msg,self.file_name)
-                 else:
-                    self.ora_env_dict=self.ocommon.add_key("ORACLE_PWD",password,self.ora_env_dict)
-                    msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file"
-                    self.ocommon.log_info_message(msg,self.file_name)
+           """
+           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):
                  """
@@ -396,7 +387,8 @@ def gsm_hostname_check(self):
                     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}.{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)
@@ -413,6 +405,13 @@ def catalog_params_check(self):
                      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:
@@ -554,10 +553,10 @@ def setup_gsm_calog(self):
                  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=self.process_clog_vars(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)
+                                 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)
@@ -581,6 +580,12 @@ def process_clog_vars(self,key):
           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]
@@ -599,16 +604,32 @@ def process_clog_vars(self,key):
               if ckey == 'catalog_name':
                  catalog_name = cvar_dict[ckey]
               if ckey == 'catalog_chunks':
-                     catalog_chunks = cvar_dict[ckey]                 
+                 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
+              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"))
@@ -649,27 +670,101 @@ def catalog_regex(self):
           return re.compile('CATALOG_PARAMS') 
 
       
-      def configure_gsm_clog(self,chost,ccdb,cpdb,cport,catalog_name,catalog_region,catalog_chunks):
+      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} -autovncr off;
+                  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)
+                  '''.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
 
-                 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()
 
@@ -697,9 +792,9 @@ def process_director_vars(self,key):
           if dtrname and dtrport and dtregion:
              return dtrname,dtrport,dtregion
           else:
-             msg1='''director_name={0},director_port={1}'''.format((director_name or "Missing Value"),(director_port or "Missing Value"))
-             msg2='''director_region={0}'''.format((director_region or "Missing Value"))
-             msg='''Director params {0} is not set correctly. One or more value is missing {1} {2}'''.format(SHARD_DIRECTOR_PARAMS,msg1,msg2)
+             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")
 
@@ -734,6 +829,54 @@ def check_gsm_director(self,dname):
 
           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
@@ -796,12 +939,12 @@ def setup_gsm_director(self):
                             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                              
+                     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':
@@ -809,8 +952,8 @@ def setup_gsm_director(self):
                    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") 
+                   self.ocommon.log_error_message(msg,self.file_name)
+                   self.ocommon.prog_exit("127") 
 
       def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin):
                  """
@@ -821,7 +964,10 @@ def configure_gsm_director(self,dtrname,dtrport,dtregion,gsmhost,cadmin):
                  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=self.process_clog_vars(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};
@@ -854,6 +1000,10 @@ def start_gsm_director(self):
                           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)
@@ -915,31 +1065,37 @@ def setup_gsm_shardg(self,restype):
                  elif restype == 'SHARD_GROUP':
                     reg_exp = self.shardg_regex()
                  else:
-                    self.ocommon.log_error_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.prog_exit("127")
+                    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)
-                              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)
-
-                       status = self.check_shardg_status(None,None)
-                       if status == 'completed':
-                          break
-                       else:
-                         msg='''GSM shard group 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_shardg_status(None,None)
-                 if status == 'completed':
+                              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:
@@ -1026,20 +1182,23 @@ def process_shardg_vars(self,key):
              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
-          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("(?:Shard Groups\n)(?:.+\n)+",output)
-             if self.ocommon.check_substr_match(matched_output[0],group_name):
-                status=True
-             else:
-                status=False
+         """
+         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():
@@ -1054,7 +1213,41 @@ def check_shardg_status(self,group_name,dname):
                           status=True
                      else:
                           status=False
-          return(self.ocommon.check_status_value(status))
+         '''
+         
+         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):
           """
@@ -1088,27 +1281,177 @@ def add_shardg_regex(self):
           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):
+      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};
-                   add shardgroup -shardgroup {3} -deploy_as {4} -region {5}
+                   {3};
                  exit;
-                  '''.format("NA",cadmin,cpasswd,group_name,deploy_as,group_region)
+                  '''.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):
                 """
@@ -1123,11 +1466,10 @@ def setup_gsm_shard(self):
                       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=self.process_shard_vars(key)
-
+                             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)
+                                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)
@@ -1164,12 +1506,25 @@ def add_gsm_shard(self):
                       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=self.process_shard_vars(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)
                              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)
+                                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)
@@ -1196,20 +1551,83 @@ 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()
+                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=self.process_shard_vars(key)
+                          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
@@ -1521,6 +1939,147 @@ def count_online_shards(self):
 
           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
@@ -1530,7 +2089,7 @@ def validate_gsm_shard(self):
                 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=self.process_shard_vars(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':
@@ -1550,6 +2109,9 @@ def process_shard_vars(self,key):
           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)
@@ -1570,14 +2132,30 @@ def process_shard_vars(self,key):
                  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
+              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"))
@@ -1586,6 +2164,39 @@ def process_shard_vars(self,key):
               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
@@ -1655,7 +2266,7 @@ def check_shard_status(self,shard_name):
                 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=self.process_shard_vars(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()):
@@ -1698,51 +2309,112 @@ def validate_shard_regex(self):
           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):
-                 """
-                  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)
-                 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)))" -shardgroup {7} -pwd {2};
-                  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 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()
+         """
+         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):
           """
@@ -1753,7 +2425,7 @@ def set_hostid_null(self):
           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=self.process_clog_vars(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'''
@@ -1770,232 +2442,238 @@ def set_hostid_null(self):
                  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)
+         """
+         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=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)
+         """
+         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=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)  
+         """
+         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"])
-                #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)):
-                self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"])
-                gsmcmd='''
-                    connect {1}/{2};
-                    config shardspace;
-                    config shardgroup;
-                    config vncr;
-                    deploy;
-                    config shard; 
-                   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()
-
-      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)
+         """
+         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"
             
-            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
+         self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"])
+         gsmcmd='''
+            connect {1}/{2};
+            {3};
+            config vncr;
+            deploy;
+            config shard; 
             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)
+         '''.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()
 
-            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'
+      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'
+               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'
+         """
+            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
+         """
+         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")
+         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):
           """
@@ -2067,27 +2745,27 @@ def service_regex(self):
           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()
+         """
+         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):
@@ -2118,7 +2796,7 @@ def setup_sample_schema(self):
           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=self.process_clog_vars(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':
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oralogger.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oralogger.py
old mode 100644
new mode 100755
index d9e0484..9a51b54
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oralogger.py
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oralogger.py
@@ -159,7 +159,7 @@ def handle(self,request):
           """
           request.stdout_ =  request.getStdOutValue()
           if request.stdout_ == LoggingType.STDOUT:
-            st = logging.FileHandler(request.stdoutfile_)
+            st = logging.FileHandler(request.stdoutfile_,mode="w")
             request.root.addHandler(st)
             st.setFormatter(request.formatter)
             self.print_message(request,st)
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oramachine.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/oramachine.py
old mode 100644
new mode 100755
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orapcatalog.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orapcatalog.py
old mode 100644
new mode 100755
index 52232cf..6638860
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orapcatalog.py
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orapcatalog.py
@@ -45,11 +45,46 @@ 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")
-            self.ocommon.log_info_message("Catalog liveness check completed sucessfully!",self.file_name)
-            sys.exit(0)
           else:
             self.setup_machine()
             self.db_checks()
@@ -61,6 +96,8 @@ def setup(self):
                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()
@@ -118,65 +155,13 @@ def ohome_check(self):
 
       def passwd_check(self):
            """
-           This funnction perform password related checks
+           Function to set the password
            """
-           passwd_file_flag = False
-           if self.ocommon.check_key("SECRET_VOLUME",self.ora_env_dict) and self.ocommon.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict) and self.ocommon.check_key("PWD_KEY",self.ora_env_dict):
-              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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-           if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-           if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-           secret_volume = self.ora_env_dict["SECRET_VOLUME"]
-           common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"]
-           pwd_key = self.ora_env_dict["PWD_KEY"]
-           passwd_file='''{0}/{1}'''.format(self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict["COMMON_OS_PWD_FILE"])
-           if os.path.isfile(passwd_file):
-              msg='''Passwd file {0} exist. Password file Check passed!'''.format(passwd_file)
-              self.ocommon.log_info_message(msg,self.file_name)
-              msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file)
-              self.ocommon.log_info_message(msg,self.file_name)
-              cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out /tmp/{1} -pass file:\"{0}/{2}\"'''.format(secret_volume,common_os_pwd_file,pwd_key)
-              output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
-              self.ocommon.check_os_err(output,error,retcode,True)
-              passwd_file_flag = True
-
-           if not passwd_file_flag:
-              s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
-              passlen = 8
-              password  =  "".join(random.sample(s,passlen ))
-           else:
-              fname='''/tmp/{0}'''.format(common_os_pwd_file)
-              fdata=self.ocommon.read_file(fname)
-              password=fdata
-              self.ocommon.remove_file(fname)
-
+           self.ocommon.get_password(None)
            if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict):
-              msg="ORACLE_PWD is passed as an env variable. Check Passed!"
-              self.ocommon.log_info_message(msg,self.file_name)
-           else:
-              self.ora_env_dict=self.ocommon.add_key("ORACLE_PWD",password,self.ora_env_dict)
-              msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file"
-              self.ocommon.log_info_message(msg,self.file_name)
-
+               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.
@@ -232,7 +217,8 @@ def hostname_check(self):
               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}.{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)
@@ -317,18 +303,7 @@ def reset_passwd(self):
          """
            This function reset the password.
          """
-         password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh")
-         self.ocommon.log_info_message("Executing password reset", self.file_name)
-         if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict) and self.ocommon.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script):
-            cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING')
-            self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"])
-            output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
-            self.ocommon.check_os_err(output,error,retcode,True)
-            self.ocommon.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.ocommon.log_error_message(msg,self.file_name)
-            self.oracommon.prog_exit()
+         self.ocommon.reset_passwd()
 
        ########## RESET_PASSWORD function ENDS here #############################
 
@@ -424,7 +399,6 @@ def setup_cdb_catalog(self):
              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 dg_broker_start=true scope=both;
              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)
 
@@ -440,29 +414,31 @@ 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 not self.ocommon.check_key("CLONE_DB",self.ora_env_dict):
-              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 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;
-               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)
-
+           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.
@@ -470,7 +446,7 @@ def set_dbparams_version(self):
            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:
+           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)
@@ -482,7 +458,7 @@ def set_dbparams_version(self):
               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}/admin\" scope=spfile;
+                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)
@@ -492,14 +468,15 @@ def restart_db(self):
           """
           restarting the db 
           """ 
-          if not self.ocommon.check_key("CLONE_DB",self.ora_env_dict):
-            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)
+          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='''
@@ -546,6 +523,7 @@ def setup_pdb_catalog(self):
               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);
@@ -570,7 +548,7 @@ def update_catalog_setup(self):
 
            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)
+           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='''
@@ -694,7 +672,7 @@ def register_services(self):
            # 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)
+           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'''
@@ -738,7 +716,7 @@ def backup_files(self):
           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_HOME"]
+             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}
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orapshard.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orapshard.py
old mode 100644
new mode 100755
index f5aa54e..d1b1273
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orapshard.py
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orapshard.py
@@ -49,9 +49,9 @@ def __init__(self,oralogger,orahandler,oraenv,oracommon):
           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)
+          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.
@@ -72,16 +72,31 @@ def setup(self):
                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")
-            self.ocommon.log_info_message("Shard liveness check completed sucessfully!",self.file_name)
-            sys.exit(0)
-          elif self.ocommon.check_key("CREATE_DIR",self.ora_env_dict):
-            status = self.shard_setup_check()
-            if not status:
-               self.ocommon.prog_exit("127")
-            self.ocommon.create_dir(self.ora_env_dict["CREATE_DIR"],True,None,None) 
           else: 
             self.setup_machine() 
             self.db_checks()
@@ -93,6 +108,7 @@ def setup(self):
               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()
@@ -153,63 +169,11 @@ def passwd_check(self):
            """
            This funnction perform password related checks
            """
-           passwd_file_flag = False
-           if self.ocommon.check_key("SECRET_VOLUME",self.ora_env_dict) and self.ocommon.check_key("COMMON_OS_PWD_FILE",self.ora_env_dict) and self.ocommon.check_key("PWD_KEY",self.ora_env_dict):
-              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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-
-           if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
- 
-           if self.ocommon.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.ocommon.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.ocommon.log_warn_message(msg,self.file_name)
-              
-           secret_volume = self.ora_env_dict["SECRET_VOLUME"]
-           common_os_pwd_file = self.ora_env_dict["COMMON_OS_PWD_FILE"]
-           pwd_key = self.ora_env_dict["PWD_KEY"]
-           passwd_file='''{0}/{1}'''.format(self.ora_env_dict["SECRET_VOLUME"],self.ora_env_dict["COMMON_OS_PWD_FILE"])
-           if os.path.isfile(passwd_file):
-              msg='''Passwd file {0} exist. Password file Check passed!'''.format(passwd_file)
-              self.ocommon.log_info_message(msg,self.file_name)
-              msg='''Reading encrypted passwd from file {0}.'''.format(passwd_file)
-              self.ocommon.log_info_message(msg,self.file_name)
-              cmd='''openssl enc -d -aes-256-cbc -in \"{0}/{1}\" -out /tmp/{1} -pass file:\"{0}/{2}\"'''.format(secret_volume,common_os_pwd_file,pwd_key)
-              output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
-              self.ocommon.check_os_err(output,error,retcode,True) 
-              passwd_file_flag = True
-
-           if not passwd_file_flag:
-              s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
-              passlen = 8
-              password  =  "".join(random.sample(s,passlen ))
-           else:
-              fname='''/tmp/{0}'''.format(common_os_pwd_file)
-              fdata=self.ocommon.read_file(fname)
-              password=fdata
-              self.ocommon.remove_file(fname)
-    
+           self.ocommon.get_password(None)
            if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict):
-              msg="ORACLE_PWD is passed as an env variable. Check Passed!"
-              self.ocommon.log_info_message(msg,self.file_name)              
-           else:
-              self.ora_env_dict=self.ocommon.add_key("ORACLE_PWD",password,self.ora_env_dict)
-              msg="ORACLE_PWD set to HIDDEN_STRING generated using encrypted password file"
-              self.ocommon.log_info_message(msg,self.file_name)
-
+               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.
@@ -264,7 +228,8 @@ def hostname_check(self):
               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}.{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)
@@ -349,18 +314,7 @@ def reset_passwd(self):
          """
            This function reset the password.
          """ 
-         password_script='''{0}/{1}'''.format(self.ora_env_dict["HOME"],"setPassword.sh")
-         self.ocommon.log_info_message("Executing password reset", self.file_name)
-         if self.ocommon.check_key("ORACLE_PWD",self.ora_env_dict) and self.ocommon.check_key("HOME",self.ora_env_dict) and os.path.isfile(password_script):
-            cmd='''{0} {1} '''.format(password_script,'HIDDEN_STRING')
-            self.ocommon.set_mask_str(self.ora_env_dict["ORACLE_PWD"])
-            output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
-            self.ocommon.check_os_err(output,error,retcode,True)
-            self.ocommon.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.ocommon.log_error_message(msg,self.file_name)
-            self.oracommon.prog_exit()
+         self.ocommon.reset_passwd()
 
        ########## RESET_PASSWORD function ENDS here #############################
 
@@ -436,7 +390,7 @@ def setup_cdb_shard(self):
            # 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)
+           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"]
@@ -454,6 +408,7 @@ def setup_cdb_shard(self):
              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;
@@ -462,10 +417,9 @@ def setup_cdb_shard(self):
              alter user GSMUSER  identified by HIDDEN_STRING  container=all;
              grant sysdg to GSMUSER;
              grant sysbackup to GSMUSER;
-             alter system set dg_broker_start=true scope=both;
              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=both;
+             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)
@@ -479,27 +433,28 @@ 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 not self.ocommon.check_key("CLONE_DB",self.ora_env_dict):
-              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)
+           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):
            """
@@ -508,7 +463,7 @@ def set_dbparams_version(self):
            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:
+           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)
@@ -517,10 +472,11 @@ def set_dbparams_version(self):
               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}/admin\" scope=spfile;
+                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)
@@ -531,14 +487,15 @@ def restart_db(self):
           """
           restarting the db
           """
-          if not self.ocommon.check_key("CLONE_DB",self.ora_env_dict):
-            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)
+          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='''
@@ -648,7 +605,7 @@ def update_shard_setup(self):
         
        ########## SETUP_CDB_SHARD FUNCTION ENDS HERE ###############################
           ###################################### Run custom scripts ##################################################
-      def run_custom_scripts():
+      def run_custom_scripts(self):
           """
            Custom script to be excuted on every restart of enviornment
           """
@@ -776,7 +733,7 @@ def register_services(self):
            # 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)
+           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'''
@@ -819,7 +776,7 @@ def backup_files(self):
           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_HOME"]
+             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}
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orascatalog.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orascatalog.py
old mode 100644
new mode 100755
index 0827a57..aa4ea65
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orascatalog.py
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orascatalog.py
@@ -6,4 +6,4 @@
 # Since: January, 2020
 # Author: sanjay.singh@oracle.com, paramdeep.saini@oracle.com
 
-class Common
+
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orasshard.py b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/orasshard.py
old mode 100644
new mode 100755
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/runOraShardSetup.sh b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/runOraShardSetup.sh
old mode 100644
new mode 100755
index d26037c..c1b09b4
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/runOraShardSetup.sh
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/runOraShardSetup.sh
@@ -36,6 +36,7 @@ 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
@@ -46,7 +47,9 @@ sqlplus / as sysdba << EOF
    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='*','/' 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
@@ -107,11 +110,12 @@ touch $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/$CLONED_FILE
 
 }
 
-
 ############################################
-
-########### Symbolic link DB files ############
-function symLinkFiles {
+########### Symbolic link DB files #########
+############################################
+########### DB Version >= 23c ##############
+############################################
+function symLinkFiles23c {
 
    if [ -z ${ORACLE_BASE_HOME} ]; then
     # 
@@ -156,6 +160,152 @@ function symLinkFiles {
       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
@@ -163,7 +313,7 @@ function symLinkFiles {
    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 
+      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
@@ -191,7 +341,7 @@ function symLinkFiles {
        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 
+         ln -s $ORACLE_BASE/oradata/dbconfig/$OLD_ORACLE_SID/orapw$OLD_ORACLE_SID $ORACLE_BASE/dbs/orapw$ORACLE_SID
        fi
      fi
    fi;
@@ -241,9 +391,9 @@ function symLinkFiles {
  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 
+      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 
+   # 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
@@ -333,7 +483,17 @@ 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
-   symLinkFiles;
+   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
@@ -353,6 +513,15 @@ if [ -d $ORACLE_BASE/oradata/$OLD_ORACLE_SID ]; then
    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 ."
@@ -362,7 +531,18 @@ fi
 fi
 
 if [ ${OP_TYPE,,} == "standbyshard" ]; then
-   symLinkFiles;
+   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
diff --git a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/runOracle.sh b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/runOracle.sh
old mode 100644
new mode 100755
index 5c21bae..2266e99
--- a/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/runOracle.sh
+++ b/docker-based-sharding-deployment/dockerfiles/21.3.0/scripts/runOracle.sh
@@ -45,7 +45,7 @@ EOF
 ###################################
 
 if [ ! -z ${SHARD_SETUP} ]; then
- if [ ${SHARD_SETUP,,} == "true" ]; then
+  if [ ${SHARD_SETUP,,} == "true" ]; then
    sh $ORACLE_BASE/scripts/sharding/runOraShardSetup.sh
  fi
 fi