-
Notifications
You must be signed in to change notification settings - Fork 217
Owls83995 - Sample scripts to shutdown and start a specific managed server/cluster/domain #2002
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
Changes from 1 commit
4d6de23
e20b630
7a2b1e3
cf096af
302a597
a134689
97b7fcd
fde5cb8
2927762
01e6307
4eba072
eadad48
5845883
1fda64a
71922eb
d66c1a8
05c5a3f
0ba9537
0ab8bd0
3950815
2859f08
81e0486
c6c287b
3456c68
df3c33f
3e028fb
10feb99
15c725a
e5b1044
b17410a
38d442d
e4bf493
b775210
c1f109d
2c5ae36
899073a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,22 +171,28 @@ function getSortedListOfServers { | |
done | ||
fi | ||
# Get servers with ALWAYS policy | ||
for localServerName in "${sortedServers[@]}"; do | ||
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy | ||
#if unset policy is true and server is current server | ||
if [[ "${unsetPolicy}" == "true" && "${serverName}" == "${localServerName}" ]]; then | ||
policy=UNSET | ||
fi | ||
if [ "${policy}" == "ALWAYS" ]; then | ||
sortedByAlwaysServers+=(${localServerName}) | ||
else | ||
otherServers+=(${localServerName}) | ||
fi | ||
done | ||
sortedServersSize=${#sortedServers[@]} | ||
if [ "${sortedServersSize}" -gt 0 ]; then | ||
for localServerName in "${sortedServers[@]}"; do | ||
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy | ||
#if unset policy is true and server is current server | ||
if [[ "${unsetPolicy}" == "true" && "${serverName}" == "${localServerName}" ]]; then | ||
policy=UNSET | ||
fi | ||
if [ "${policy}" == "ALWAYS" ]; then | ||
sortedByAlwaysServers+=(${localServerName}) | ||
else | ||
otherServers+=(${localServerName}) | ||
fi | ||
done | ||
fi | ||
|
||
for otherServer in "${otherServers[@]}"; do | ||
sortedByAlwaysServers+=($otherServer) | ||
done | ||
otherServersSize=${#otherServers[@]} | ||
if [ "${otherServersSize}" -gt 0 ]; then | ||
for otherServer in "${otherServers[@]}"; do | ||
sortedByAlwaysServers+=($otherServer) | ||
done | ||
fi | ||
} | ||
|
||
function getReplicaCount { | ||
|
@@ -219,19 +225,22 @@ function checkServersStoppedByUnsetPolicyWhenAlways { | |
echo "started servers before are -> ${startedServers[@]}" | ||
fi | ||
replicaCount=$((replicaCount-1)) | ||
for localServerName in "${sortedByAlwaysServers[@]}"; do | ||
# Get effictive server policy | ||
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy | ||
if [ "${serverName}" == "${localServerName}" ]; then | ||
policy=UNSET | ||
fi | ||
# check if server should be started based on policy and replica count | ||
shouldStart ${currentReplicas} ${policy} ${replicaCount} result | ||
if [ "${result}" == 'True' ]; then | ||
currentReplicas=$((currentReplicas+1)) | ||
startedServers+=(${localServerName}) | ||
fi | ||
done | ||
sortedByAlwaysSize=${#sortedByAlwaysServers[@]} | ||
if [ "${sortedByAlwaysSize}" -gt 0 ]; then | ||
for localServerName in "${sortedByAlwaysServers[@]}"; do | ||
# Get effictive server policy | ||
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy | ||
if [ "${serverName}" == "${localServerName}" ]; then | ||
policy=UNSET | ||
fi | ||
# check if server should be started based on policy and replica count | ||
shouldStart ${currentReplicas} ${policy} ${replicaCount} result | ||
if [ "${result}" == 'True' ]; then | ||
currentReplicas=$((currentReplicas+1)) | ||
startedServers+=(${localServerName}) | ||
fi | ||
done | ||
fi | ||
|
||
startedSize=${#startedServers[@]} | ||
if [ ${startedSize} -gt 0 ]; then | ||
|
@@ -261,19 +270,22 @@ function checkServersStoppedByDecreasingReplicasAndUnsetPolicy { | |
getReplicaCount "${domainJson}" "${clusterName}" replicaCount | ||
startedSize=${#startedServers[@]} | ||
replicaCount=$((replicaCount-1)) | ||
for localServerName in "${sortedByAlwaysServers[@]}"; do | ||
# Get effictive server policy | ||
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy | ||
# check if server should be started based on policy and replica count | ||
if [ "${serverName}" == "${localServerName}" ]; then | ||
policy=UNSET | ||
fi | ||
shouldStart ${currentReplicas} ${policy} ${replicaCount} result | ||
if [ "${result}" == 'True' ]; then | ||
currentReplicas=$((currentReplicas+1)) | ||
startedServers+=(${localServerName}) | ||
fi | ||
done | ||
sortedByAlwaysSize=${#sortedByAlwaysServers[@]} | ||
if [ "${sortedByAlwaysSize}" -gt 0 ]; then | ||
for localServerName in "${sortedByAlwaysServers[@]}"; do | ||
# Get effictive server policy | ||
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy | ||
# check if server should be started based on policy and replica count | ||
if [ "${serverName}" == "${localServerName}" ]; then | ||
policy=UNSET | ||
fi | ||
shouldStart ${currentReplicas} ${policy} ${replicaCount} result | ||
if [ "${result}" == 'True' ]; then | ||
currentReplicas=$((currentReplicas+1)) | ||
startedServers+=(${localServerName}) | ||
fi | ||
done | ||
fi | ||
|
||
startedSize=${#startedServers[@]} | ||
if [ ${startedSize} -gt 0 ]; then | ||
|
@@ -303,16 +315,19 @@ function checkServersStartedByCurrentReplicasAndPolicy { | |
unsetPolicy="false" | ||
getSortedListOfServers "${domainJson}" "${serverName}" "${clusterName}" "${unsetPolicy}" | ||
getReplicaCount "${domainJson}" "${clusterName}" replicaCount | ||
for localServerName in "${sortedByAlwaysServers[@]}"; do | ||
# Get effictive server policy | ||
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy | ||
# check if server should be started based on policy and replica count | ||
shouldStart ${currentReplicas} ${policy} ${replicaCount} result | ||
if [ "${result}" == 'True' ]; then | ||
currentReplicas=$((currentReplicas+1)) | ||
startedServers+=(${localServerName}) | ||
fi | ||
done | ||
sortedByAlwaysSize=${#sortedByAlwaysServers[@]} | ||
if [ "${sortedByAlwaysSize}" -gt 0 ]; then | ||
for localServerName in "${sortedByAlwaysServers[@]}"; do | ||
# Get effictive server policy | ||
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy | ||
# check if server should be started based on policy and replica count | ||
shouldStart ${currentReplicas} ${policy} ${replicaCount} result | ||
if [ "${result}" == 'True' ]; then | ||
currentReplicas=$((currentReplicas+1)) | ||
startedServers+=(${localServerName}) | ||
fi | ||
done | ||
fi | ||
startedSize=${#startedServers[@]} | ||
if [ ${startedSize} -gt 0 ]; then | ||
if checkStringInArray ${serverName} ${startedServers[@]}; then | ||
|
@@ -323,11 +338,12 @@ function checkServersStartedByCurrentReplicasAndPolicy { | |
eval $__started="false" | ||
} | ||
|
||
function checkServerStartByIncreasingReplicasAndUnsetPolicy { | ||
function checkServerStartByUnsetPolicy { | ||
local domainJson=$1 | ||
local serverName=$2 | ||
local clusterName=$3 | ||
local __started=$4 | ||
local withReplicas=$4 | ||
local __started=$5 | ||
local localServerName="" | ||
local policy="" | ||
local replicaCount=0 | ||
|
@@ -338,20 +354,25 @@ function checkServerStartByIncreasingReplicasAndUnsetPolicy { | |
unsetPolicy="true" | ||
getSortedListOfServers "${domainJson}" "${serverName}" "${clusterName}" "${unsetPolicy}" | ||
getReplicaCount "${domainJson}" "${clusterName}" replicaCount | ||
replicaCount=$((replicaCount+1)) | ||
for localServerName in "${sortedByAlwaysServers[@]}"; do | ||
# Get effictive server policy | ||
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy | ||
# check if server should be started based on policy and replica count | ||
if [ "${serverName}" == "${localServerName}" ]; then | ||
policy=UNSET | ||
fi | ||
shouldStart "${currentReplicas}" "${policy}" "${replicaCount}" result | ||
if [ "${result}" == 'True' ]; then | ||
currentReplicas=$((currentReplicas+1)) | ||
startedServers+=(${localServerName}) | ||
fi | ||
done | ||
if [ "${withReplicas}" == "INCREASED" ]; then | ||
replicaCount=$((replicaCount+1)) | ||
fi | ||
sortedByAlwaysSize=${#sortedByAlwaysServers[@]} | ||
if [ "${sortedByAlwaysSize}" -gt 0 ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a minor point: in my experimentation changing to the following:
is nearly equivalent to:
The drawback is that it (a) assumes server names won't have special chars like quotes in them - which is probably a reasonable assumption, and (b) it defeats the 'set -u' var name check so a bad var name would short circuit the loop... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to use new syntax to avoid size check for empty arrays. |
||
for localServerName in "${sortedByAlwaysServers[@]}"; do | ||
# Get effictive server policy | ||
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy | ||
# check if server should be started based on policy and replica count | ||
if [ "${serverName}" == "${localServerName}" ]; then | ||
policy=UNSET | ||
fi | ||
shouldStart "${currentReplicas}" "${policy}" "${replicaCount}" result | ||
if [ "${result}" == 'True' ]; then | ||
currentReplicas=$((currentReplicas+1)) | ||
startedServers+=(${localServerName}) | ||
fi | ||
done | ||
fi | ||
startedSize=${#startedServers[@]} | ||
if [ ${startedSize} -gt 0 ]; then | ||
if checkStringInArray ${serverName} ${startedServers[@]}; then | ||
|
@@ -458,20 +479,28 @@ Please make sure server name is correct." | |
namePrefixSize=". | {name: .name, prefix:.dynamicServersConfig.serverNamePrefix, \ | ||
max:.dynamicServersConfig.maxDynamicClusterSize}" | ||
dynamicClusters=($(echo $jsonTopology | jq "${dynamicClause}" | jq -cr "${namePrefixSize}")) | ||
for dynaClusterNamePrefix in "${dynamicClusters[@]}"; do | ||
prefix=$(echo ${dynaClusterNamePrefix} | jq -r .prefix) | ||
if [[ "${serverName}" == "${prefix}"* ]]; then | ||
serverCount=$(echo "${serverName: -1}") | ||
maxSize=$(echo ${dynaClusterNamePrefix} | jq -r .max) | ||
if [ "${serverCount}" -gt "${maxSize}" ]; then | ||
printError "${errorMessage}" | ||
exit 1 | ||
dynamicClustersSize=${#dynamicClusters[@]} | ||
if [ "${dynamicClustersSize}" -gt 0 ]; then | ||
for dynaClusterNamePrefix in "${dynamicClusters[@]}"; do | ||
prefix=$(echo ${dynaClusterNamePrefix} | jq -r .prefix) | ||
if [[ "${serverName}" == "${prefix}"* ]]; then | ||
serverCount=$(echo "${serverName: -1}") | ||
maxSize=$(echo ${dynaClusterNamePrefix} | jq -r .max) | ||
number='^[0-9]+$' | ||
if ! [[ $serverCount =~ $number ]] ; then | ||
echo "error: Server name is not valid for dynamic cluster." | ||
exit 1 | ||
fi | ||
if [ "${serverCount}" -gt "${maxSize}" ]; then | ||
printError "${errorMessage}" | ||
exit 1 | ||
fi | ||
eval $__clusterName="'$(echo ${dynaClusterNamePrefix} | jq -r .name)'" | ||
eval $__isValidServer=true | ||
break | ||
fi | ||
eval $__clusterName="'$(echo ${dynaClusterNamePrefix} | jq -r .name)'" | ||
eval $__isValidServer=true | ||
break | ||
fi | ||
done | ||
done | ||
fi | ||
staticClause=".domain.configuredClusters[] | select (.dynamicServersConfig == null)" | ||
nameCmd=" . | {name: .name, serverName: .servers[].name}" | ||
configuredClusters=($(echo $jsonTopology | jq "${staticClause}" | jq -cr "${nameCmd}")) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,9 @@ keepReplicaConstant=false | |
verboseMode=false | ||
managedServerPolicy="" | ||
action="" | ||
isValidServer="" | ||
withRelicas="" | ||
patchJson="" | ||
|
||
while getopts "vkd:n:m:s:h" opt; do | ||
case $opt in | ||
|
@@ -120,29 +123,37 @@ if [ "${domainPolicy}" == 'NEVER' ]; then | |
fi | ||
|
||
tbarnes-us marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getEffectivePolicy "${domainJson}" "${serverName}" "${clusterName}" effectivePolicy | ||
checkServersStartedByCurrentReplicasAndPolicy "${domainJson}" "${serverName}" "${clusterName}" started | ||
if [[ ${effectivePolicy} == "IF_NEEDED" && ${started} == "true" ]]; then | ||
echo "[INFO] The server should be already started or it's starting. The start policy for server ${serverName} is ${effectivePolicy} and server is chosen to be started based on current replica count." | ||
exit 0 | ||
elif [[ "${effectivePolicy}" == "ALWAYS" && ${started} == "true" ]]; then | ||
echo "[INFO] The server should be already started or it's starting. The start policy for server ${serverName} is ${effectivePolicy}." | ||
exit 0 | ||
if [ -n "${clusterName}" ]; then | ||
checkServersStartedByCurrentReplicasAndPolicy "${domainJson}" "${serverName}" "${clusterName}" started | ||
if [[ ${effectivePolicy} == "IF_NEEDED" && ${started} == "true" ]]; then | ||
echo "[INFO] The server should be already started or it's starting. The start policy for server ${serverName} is ${effectivePolicy} and server is chosen to be started based on current replica count." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe let's have a zoom and word-smith the script's messages a little together? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, sure. That would be helpful. |
||
exit 0 | ||
elif [[ "${effectivePolicy}" == "ALWAYS" && ${started} == "true" ]]; then | ||
echo "[INFO] The server should be already started or it's starting. The start policy for server ${serverName} is ${effectivePolicy}." | ||
exit 0 | ||
fi | ||
else | ||
if [ "${effectivePolicy}" == "ALWAYS" ]; then | ||
echo "[INFO] The server should be already started or it's starting. The start policy for server ${serverName} is ${effectivePolicy}." | ||
exit 0 | ||
fi | ||
fi | ||
|
||
# Get current server start policy of the server | ||
getCurrentPolicy "${domainJson}" "${serverName}" managedServerPolicy | ||
targetPolicy="ALWAYS" | ||
tbarnes-us marked this conversation as resolved.
Show resolved
Hide resolved
|
||
createServerStartPolicyPatch "${domainJson}" "${serverName}" "${targetPolicy}" alwaysStartPolicyPatch | ||
|
||
# if server is part of a cluster and replica count needs to be updated, patch the replica count and server start policy | ||
if [[ -n ${clusterName} && "${keepReplicaConstant}" != 'true' ]]; then | ||
#check if server can be started by increasing replicas and unsetting policy | ||
checkServerStartByIncreasingReplicasAndUnsetPolicy "${domainJson}" "${serverName}" "${clusterName}" started | ||
withRelicas="INCREASED" | ||
checkServerStartByUnsetPolicy "${domainJson}" "${serverName}" "${clusterName}" "${withRelicas}" started | ||
operation="INCREMENT" | ||
createReplicaPatch "${domainJson}" "${clusterName}" "${operation}" incrementReplicaPatch replicaCount | ||
if [ "${incrementReplicaPatch}" == "MAX_REPLICA_COUNT_EXCEEDED" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the replica count is already maxed out, why not just continue and start the server by unsetting it (e.g. implicitly bringing it to IF_NEEDED)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code path for the default case where script increases the replica count. I'm not sure if unsetting policy (bringing it to IF_NEEDED) will start the server. The user can use '-k' to keep replica constant and start the server by unsetting policy. For e.g. if server1 to server4 are running and max replica count is 4. If user wants to start server5 and policy is NEVER, unsetting policy will not start server. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed, the assumption is that this case will be caught by previous validation check. I have removed the check. |
||
exit 1 | ||
fi | ||
targetPolicy="ALWAYS" | ||
createServerStartPolicyPatch "${domainJson}" "${serverName}" "${targetPolicy}" alwaysStartPolicyPatch | ||
if [[ -n ${managedServerPolicy} && ${started} == "true" ]]; then | ||
# Server starts by increasing replicas and policy unset, increment and unset | ||
echo "[INFO] Unsetting the current start policy '${managedServerPolicy}' for '${serverName}' and incrementing replica count." | ||
|
@@ -155,26 +166,30 @@ if [[ -n ${clusterName} && "${keepReplicaConstant}" != 'true' ]]; then | |
action="PATCH_REPLICA" | ||
else | ||
# Patch server policy to always and increment replicas | ||
patchJson="{\"spec\": {\"clusters\": "${incrementReplicaPatch}",\"managedServers\": "${alwaysStartPolicyPatch}"}}" | ||
action="PATCH_REPLICA_AND_POLICY" | ||
echo "[INFO] Patching start policy of server '${serverName}' from '${effectivePolicy}' to 'ALWAYS' and \ | ||
incrementing replica count for cluster '${clusterName}'." | ||
patchJson="{\"spec\": {\"clusters\": "${incrementReplicaPatch}",\"managedServers\": "${alwaysStartPolicyPatch}"}}" | ||
action="PATCH_REPLICA_AND_POLICY" | ||
fi | ||
elif [[ -n ${clusterName} && "${keepReplicaConstant}" == 'true' ]]; then | ||
# if replica count needs to stay constant, only patch server start policy | ||
# Replica count needs to stay constant | ||
# check if server can be started by unsetting policy | ||
withRelicas="CONSTANT" | ||
checkServerStartByUnsetPolicy "${domainJson}" "${serverName}" "${clusterName}" "${withRelicas}" started | ||
if [[ "${effectivePolicy}" == "NEVER" && ${started} == "true" ]]; then | ||
# Server starts by unsetting policy, unset policy | ||
echo "[INFO] Unsetting the current start policy '${effectivePolicy}' for '${serverName}'." | ||
createPatchJsonToUnsetPolicy "${domainJson}" "${serverName}" patchJson | ||
action="UNSET_POLICY" | ||
else | ||
# Patch server policy to always | ||
echo "[INFO] Patching start policy for '${serverName}' to '${targetPolicy}'." | ||
patchJson="{\"spec\": {\"managedServers\": "${alwaysStartPolicyPatch}"}}" | ||
action="PATCH_POLICY" | ||
fi | ||
else | ||
# if server is an independent managed server, only patch server start policy | ||
patchJson="{\"spec\": {\"managedServers\": "${serverStartPolicyPatch}"}}" | ||
# if server is an independent managed server, only patch server start policy to ALWAYS | ||
patchJson="{\"spec\": {\"managedServers\": "${alwaysStartPolicyPatch}"}}" | ||
action="PATCH_POLICY" | ||
fi | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.