Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard reset #80

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 93 additions & 41 deletions openshift/manage
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ usage () {
The following operations are performed during a reset:
- All credentials are be requeued for posting.
- The 'event-processor-log-db' is reset and reinitialized.
- The wallet is reset, by restoring initial copy of ICIA Wallet.
- The process pauses at the end to confirm the corresponding ICOB reset process has completed
- The wallet is reset, by restoring initial copy of BC Registries Agent Wallet.
- The process pauses at the end to confirm the corresponding OrgBook reset process has completed
before scalling up the controller which performs its issuer registration on startup.
- Various pods are scaled up and down automatically during the process.

Expand Down Expand Up @@ -259,6 +259,20 @@ resourceSuffix="${resourceSuffix:--primary}"
# Process the local command line arguments and pass everything else along.
# - The 'getopts' options string must start with ':' for this to work.
# -----------------------------------------------------------------------------------------------------------------
for arg in "$@"; do
# Remove recognized arguments from the list after processing.
shift
case "$arg" in
--hard-reset)
HARD_RESET=1
;;
*)
# If not recognized, save it for later processing ...
set -- "$@" "$arg"
;;
esac
done

while [ ${OPTIND} -le $# ]; do
if getopts :s: FLAG; then
case ${FLAG} in
Expand Down Expand Up @@ -401,6 +415,14 @@ function deleteDatabase() {
echoWarning "\nThe databases on ${_podName}${resourceSuffix} have been deleted."
}

function hardReset() {
if [ ! -z ${HARD_RESET} ]; then
return 0
else
return 1
fi
}

function reset() {
(
agentPod=${1}
Expand All @@ -423,7 +445,7 @@ function reset() {

# Explain what is about to happen and wait for confirmation ...
txtMsg=$(cat <<-EOF
The [${targetNamespace}] ICIA environment will be RESET using the following settings:
The [${targetNamespace}] BC Registries Agent environment will be RESET using the following settings:
- agentPod: ${agentPod}${resourceSuffix}
- controllerPod: ${controllerPod}${resourceSuffix}
- eventDbPod: ${eventDbPod}${resourceSuffix}
Expand All @@ -435,28 +457,51 @@ The [${targetNamespace}] ICIA environment will be RESET using the following sett
- walletDbBackupSpec: ${walletDbBackupSpec}
- walletDbBackupFileFilter: ${walletDbBackupFileFilter}
- walletDbAdminPasswordKey: ${walletDbAdminPasswordKey}
EOF
)

if hardReset; then
txtMsg+=$(cat <<-EOF
\n
\033[0;31mYou have requested a Hard Reset. The following operations will be performed (ALL DATA WILL BE LOST):
\033[1;33m- The process will pause at the beginning to ensure the related OrgBook reset process has started.
- All credentials will be requeued for posting.
- The 'event-processor-log-db' will be reset and reinitialized.
- The wallet will be deleted and recreated.
- The process will pause at the end to confirm the corresponding OrgBook reset process has completed
before scalling up the controller which will perform its issuer registration on startup.
- Various pods will be scaled up and down automatically during the process.\n
EOF
)
else
txtMsg+=$(cat <<-EOF
\n
The following operations will be performed:
- All credentials will be requeued for posting.
- The 'event-processor-log-db' will be reset and reinitialized.
- The wallet will be reset, by restoring initial copy of ICIA Wallet.
- The process will pause at the end to confirm the corresponding ICOB reset process has completed
- The wallet will be reset, by restoring initial copy of BC Registries Agent Wallet.
- The process will pause at the end to confirm the corresponding OrgBook reset process has completed
before scalling up the controller which will perform its issuer registration on startup.
- Various pods will be scaled up and down automatically during the process.\n
EOF
)
printAndAskToContinue "${txtMsg}"
fi

if ! printAndWaitForYes "${txtMsg}"; then
echoWarning "Exiting ..."
exit 1
fi

# - scaledown ICIA controller and agent
# - scaledown BC Registries Agent controller and agent
echo "Scaling down ${agentPod}${resourceSuffix} and ${controllerPod}${resourceSuffix} ..."
scaleDown -w "${controllerPod}${resourceSuffix}" "${agentPod}${resourceSuffix}"
exitOnError

# Nonblocking - Indicate the ICOB reset could safely start now ...
# Nonblocking - Indicate the OrgBook reset could safely start now ...
echoWarning "\n================================================================================="
echoWarning "*********************************************************************************"
echo
echoWarning "You can now safely start the reset process in the corresponding ICOB environment."
echoWarning "You can now safely start the reset process in the corresponding OrgBook environment."
echo
echoWarning "*********************************************************************************"
echoWarning "=================================================================================\n\n"
Expand All @@ -468,47 +513,54 @@ EOF
requeueProcessedCreds "${eventDbPod}"
exitOnError

# - reset ICIA event-processor-log-db
# - reset BC Registries Agent event-processor-log-db
echo -e "\nResetting ${eventProcessorLogDbPod}${resourceSuffix} ..."
resetEventProcLogDatabase -q "${eventProcessorLogDbPod}" "${eventProcessorPod}"
exitOnError

# - reset ICIA Wallet Database, by restoring initial copy of ICIA Wallet.
echo -e "\nResetting ${walletDbPod}${resourceSuffix} ..."
if isScaledUp ${backupPod}${resourceSuffix}; then
local backupStarted=1
if hardReset; then
# - Delete Wallet Database
echoError "Deleteing ${walletDbPod}${resourceSuffix} ..."
deleteDatabase "${walletDbPod}"
exitOnError
else
local unset backupStarted
scaleUp -w "${backupPod}${resourceSuffix}"
# - reset BC Registries Agent Wallet Database, by restoring initial copy of BC Registries Agent Wallet.
echo -e "\nResetting ${walletDbPod}${resourceSuffix} ..."
if isScaledUp ${backupPod}${resourceSuffix}; then
local backupStarted=1
else
local unset backupStarted
scaleUp -w "${backupPod}${resourceSuffix}"
exitOnError
fi

runInContainer -i \
${backupPod}${resourceSuffix} \
"./backup.sh -s -a $(getSecret ${walletDbPod}${resourceSuffix} ${walletDbAdminPasswordKey}) -r ${walletDbBackupSpec} -f ${walletDbBackupFileFilter}"
exitOnError
fi

runInContainer -i \
${backupPod}${resourceSuffix} \
"./backup.sh -s -a $(getSecret ${walletDbPod}${resourceSuffix} ${walletDbAdminPasswordKey}) -r ${walletDbBackupSpec} -f ${walletDbBackupFileFilter}"
exitOnError
if [ -z ${backupStarted} ]; then
# Leave the backup container in the same state we found it.
scaleDown "${backupPod}${resourceSuffix}"
exitOnError
fi

if [ -z ${backupStarted} ]; then
# Leave the backup container in the same state we found it.
scaleDown "${backupPod}${resourceSuffix}"
# - verify BC Registries Agent Wallet - There should only be 4 items.
recordCounts=$(getRecordCounts "${walletDbPod}" "${walletDbName}")
numItems=$(echo "${recordCounts}" | grep items | awk '{print $5}')
if (( ${numItems} >= 4 )); then
echo "Wallet 'items' count verified; ${numItems} items found."
else
echoError "Wallet 'items' count verification failed; ${numItems} items found. Please fix the issue and try again."
exit 1
fi
exitOnError
fi

# - verify ICIA Wallet - There should only be 4 items.
recordCounts=$(getRecordCounts "${walletDbPod}" "${walletDbName}")
numItems=$(echo "${recordCounts}" | grep items | awk '{print $5}')
if (( ${numItems} >= 4 )); then
echo "Wallet 'items' count verified; ${numItems} items found."
else
echoError "Wallet 'items' count verification failed; ${numItems} items found. Please fix the issue and try again."
exit 1
fi
exitOnError

# - Pause for ICOB reset
printAndAskToContinue "Please ensure the ICOB reset is complete before you continue."
# - Pause for OrgBook reset
printAndAskToContinue "Please ensure the OrgBook reset is complete before you continue."

# - scaleup ICIA agent
# - scaleup BC Registries Agent agent
echo "Scaling up ${agentPod}${resourceSuffix} ..."
scaleUp -w "${agentPod}${resourceSuffix}"
exitOnError
Expand All @@ -518,14 +570,14 @@ EOF
removeAgentConnections "${agentPod}"
exitOnError

# - scaleup ICIA controller
# - scaleup BC Registries Agent controller
echo "Scaling up ${controllerPod}${resourceSuffix} ..."
scaleUp -w "${controllerPod}${resourceSuffix}"
exitOnError

# - verify ICIA registered with ICOB
# - verify BC Registries Agent registered with OrgBook
# - Test posting a few credentials using the pipelines
echo "You can now verifiy ICIA has successfully registered with ICOB. Following that you can test things by issuing a few credentials."
echo "You can now verifiy BC Registries Agent has successfully registered with OrgBook. Following that you can test things by issuing a few credentials."
)
}

Expand Down
4 changes: 2 additions & 2 deletions openshift/templates/agent/agent-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ parameters:
displayName: Source Image Registry
description: The name of the Source Image Registry.
required: false
value: artifacts.developer.gov.bc.ca/docker-remote/
value: artifacts.developer.gov.bc.ca/github-docker-remote/
- name: SOURCE_IMAGE_NAME
displayName: Source Image Name
description: The name of the Docker image to be used for the build. Overrides the FROM instruction in the Dockerfile.
required: false
value: bcgovimages/aries-cloudagent:py36-1.16-1_0.7.0
value: hyperledger/aries-cloudagent-python:py3.9-indy-1.16.0-0.12.1
- name: CPU_REQUEST
displayName: Resources CPU Request
description: The resources CPU request (in cores) for this build.
Expand Down