Last active
September 30, 2019 07:46
-
-
Save charmygarg/3902dc4a7b635d4df6c3a38dc0d841b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ENVIRONMENTS=("dev2", "tst2", "shiptst1", "shiptst2", "stg1", "shipstg1") | |
SHIPS=("prd", "allure", "adventure", "anthem", "brilliance", "constellation", "edge", "enchantment", "equinox", "harmony", "independence", "liberty", "mariner", "majesty", "millennium", "navigator", "oasis", "ovation", "pursuit", "quantum", "reflection", "spectrum", "summit", "serenade", "symphony", "vision") | |
if [[ "$environmentGroup" == "dev" && "$environmentChoice" == "all" ]] | |
then | |
ENV_NAMES=("dev2") | |
elif [[ "$environmentGroup" == "test" && "$environmentChoice" == "all" ]] | |
then | |
ENV_NAMES=("tst2" "shiptst1" "shiptst2") | |
elif [[ "$environmentGroup" == "stage" && "$environmentChoice" == "all" ]] | |
then | |
ENV_NAMES=("stg1" "shipstg1") | |
elif [[ "$environmentGroup" == "prod" && "$environmentChoice" == "all" ]] | |
then | |
SHIP_NAMES=("prd" "allure" "adventure" "anthem" "brilliance" "constellation" "edge" "enchantment" "equinox" "harmony" "independence" "liberty" "mariner" "majesty" "millennium" "navigator" "oasis" "ovation" "pursuit" "quantum" "reflection" "spectrum" "summit" "serenade" "symphony" "vision") | |
elif [[ "$environmentGroup" == "prod" ]] | |
then | |
SHIP_NAMES=(${environmentChoice}) | |
else | |
ENV_NAMES=(${environmentChoice}) | |
fi | |
lower_env_delete_data() { | |
for ENV in ${ENV_NAMES[*]} | |
do | |
if [[ "${ENVIRONMENTS[@]}" =~ "${ENV}" ]] | |
then | |
local SAIL_DATE="$1" | |
echo "****************************************************************************" | |
echo "Environment: $ENV" | |
echo "Sailing: $SAIL_DATE" | |
echo "Collection: $collectionName" | |
echo "****************************************************************************" | |
local QUERY="http://${ENV}.mesos.rccl.com/solr-cloud/v3/solr/${collectionName}" | |
process_data_deletion "${QUERY}" "${SAIL_DATE}" | |
else | |
echo "Incorrect environment choice!! Please enter (all) or specific environment from (${ENVIRONMENTS[*]})" | |
fi | |
done | |
} | |
prod_delete_data() { | |
for SHIP in ${SHIP_NAMES[*]} | |
do | |
if [[ "${SHIPS[@]}" =~ "${SHIP}" ]] | |
then | |
local SAIL_DATE="$1" | |
echo "****************************************************************************" | |
echo "Environment: $SHIP" | |
echo "Sailing: $SAIL_DATE" | |
echo "Collection: $collectionName" | |
echo "****************************************************************************" | |
if [[ "$SHIP" == "prd" ]] | |
then | |
echo "****************************************************************************" | |
local QUERY="http://${SHIP}.mesos.rccl.com/solr-cloud/v3/solr/${collectionName}" | |
process_data_deletion "${QUERY}" "${SAIL_DATE}" | |
else | |
echo "****************************************************************************" | |
local QUERY="http://mesos.${SHIP}.sh.rccl.com/solr-cloud/v3/solr/${collectionName}" | |
process_data_deletion "${QUERY}" "${SAIL_DATE}" | |
fi | |
else | |
echo "Incorrect ship choice!! Please enter (all) or specific ship from (${SHIPS[*]})" | |
fi | |
done | |
} | |
process_data_deletion() { | |
local QUERY="$1" SAIL_DATE="$2" | |
curl "$QUERY/select?q=id:??${SAIL_DATE}&rows=0" >> idNumFound.json | |
curl "$QUERY/select?q=*:*&rows=0" >> allNumFound.json | |
local DELETION_COUNT=$(perl -nle'print $& while m{"numFound"\s*:\s*\K\d+}g' idNumFound.json) | |
local TOTAL_COUNT=$(perl -nle'print $& while m{"numFound"\s*:\s*\K\d+}g' allNumFound.json) | |
if [[ "${DELETION_COUNT}" -ne 0 && "${TOTAL_COUNT}" -ne 0 ]] | |
then | |
echo "****************************************************************************" | |
echo "Deleting ($DELETION_COUNT) products from ${SHIP} Solr:" | |
echo "${collectionName}: Current ($TOTAL_COUNT) | Deleting ($DELETION_COUNT) | Proposed ($(($TOTAL_COUNT-$DELETION_COUNT)))" | |
echo "****************************************************************************" | |
curl "$QUERY/update?commit=true" -H "Content-type: text/xml" \ | |
--data-binary "<delete><query>id:??${SAIL_DATE}</query></delete>" | |
echo "****************************************************************************" | |
echo "Success: Deleted ($DELETION_COUNT) products from ${SHIP} Solr:" | |
echo "${collectionName}: Current ($TOTAL_COUNT) | Deleted ($DELETION_COUNT)" | |
echo "****************************************************************************" | |
else | |
echo "****************************************************************************" | |
echo "No document to delete as NumFound is (0) for ${SAIL_DATE}" | |
fi | |
[[ -e idNumFound.json ]] && rm idNumFound.json && [[ -e allNumFound.json ]] && rm allNumFound.json | |
} | |
delete_old_data() { | |
local SAILING="$1" | |
if [[ "${#SHIP_NAMES[@]}" -ne 0 ]] | |
then | |
prod_delete_data "${SAILING}" | |
elif [[ "${#ENV_NAMES[@]}" -ne 0 ]] | |
then | |
lower_env_delete_data "${SAILING}" | |
else | |
echo "Incorrect sailing!!" | |
fi | |
} | |
delete_all_data() { | |
echo Deleting data for \"2017\", \"2018\", \"201901\", \"201902\", \"201903\", \"201904\" | |
SAILINGS=("2017*" "2018*" "201901*" "201902*" "201903*" "201904*" "201905*") | |
for SAILING in ${SAILINGS[*]} | |
do | |
delete_old_data "${SAILING}" | |
done | |
} | |
delete_recurring_data() { | |
SAILING=$(date --date="-3 month" +%Y%m)* | |
delete_old_data "${SAILING}" | |
} | |
case ${choice} in | |
1) delete_all_data;; | |
2) delete_recurring_data;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment