Skip to content

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

Merged
merged 36 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4d6de23
owls-83995 - Scripts to start/stop a managed server/cluster/domain
ankedia Oct 20, 2020
e20b630
fix method comments
ankedia Oct 20, 2020
7a2b1e3
Minor changes
ankedia Oct 20, 2020
cf096af
Address review comments and fix script comments/usages.
ankedia Oct 21, 2020
302a597
Added integration tests, made few doc changes based on review comment…
ankedia Oct 22, 2020
a134689
Clarify script usage, updated README file and minor changes.
ankedia Oct 22, 2020
97b7fcd
Changes to add script usage details
ankedia Oct 22, 2020
fde5cb8
Address PR review comments
ankedia Oct 22, 2020
2927762
Review comment and cleanup.
ankedia Oct 22, 2020
01e6307
Documentation changes based on PR review comments.
ankedia Oct 23, 2020
4eba072
Fully qualified replica value as per review comments
ankedia Oct 23, 2020
eadad48
edit docs
rosemarymarano Oct 23, 2020
5845883
edit README
rosemarymarano Oct 23, 2020
1fda64a
Address PR review comments
ankedia Oct 23, 2020
71922eb
Changes to address PR review comments and removed ItLifecycleSampleSc…
ankedia Oct 23, 2020
d66c1a8
fix indentation
ankedia Oct 23, 2020
05c5a3f
fix comment and typo
ankedia Oct 23, 2020
0ba9537
Added validation as per review comment.
ankedia Oct 24, 2020
0ab8bd0
changes to address review comment and minor cleanup
ankedia Oct 25, 2020
3950815
PR review comment - changes to assume default policy is IF_NEEDED if …
ankedia Oct 26, 2020
2859f08
changes for new algorithm as documented on http://aseng-wiki.us.oracl…
ankedia Oct 30, 2020
81e0486
More changes for new algorithm.
ankedia Oct 31, 2020
c6c287b
code refactoring and minor doc update.
ankedia Nov 1, 2020
3456c68
Minor change for dynamic server name validation
ankedia Nov 2, 2020
df3c33f
Changes to address review comments.
ankedia Nov 2, 2020
3e028fb
More review comment changes and cleanup.
ankedia Nov 3, 2020
10feb99
Unset policy to start independent (stadalone) maanged server instead …
ankedia Nov 3, 2020
15c725a
Latest review comment changes.
ankedia Nov 3, 2020
e5b1044
More changes based on review comments.
ankedia Nov 4, 2020
b17410a
Chnages for latest review comments.
ankedia Nov 4, 2020
38d442d
Remove unused action variable and assignments.
ankedia Nov 4, 2020
e4bf493
Fix the logic to display error when config map not found and return p…
ankedia Nov 4, 2020
b775210
Changes for latest review comments.
ankedia Nov 4, 2020
c1f109d
Changes for latest round of review comments.
ankedia Nov 4, 2020
2c5ae36
use printError instead of echo
ankedia Nov 4, 2020
899073a
Changes to remove integration tests and doc review comments.
ankedia Nov 5, 2020
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
Prev Previous commit
Next Next commit
Latest review comment changes.
  • Loading branch information
ankedia committed Nov 3, 2020
commit 15c725a6c333bfd7675506f68ce06f1efa20bd39
199 changes: 99 additions & 100 deletions kubernetes/samples/scripts/domain-lifecycle/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# Function to get server start policy at cluster level
# $1 - Domain resource in json format
# $2 - Name of cluster
# $3 - Return value containing cluster level server start policy
# $3 - Return value for cluster level server start policy.
# Legal return values are "NEVER" or "IF_NEEDED" or "".
#
function getClusterPolicy {
local domainJson=$1
Expand All @@ -27,7 +28,8 @@ function getClusterPolicy {
#
# Function to get server start policy at domain level
# $1 - Domain resource in json format
# $2 - Return value containing domain level server start policy
# $2 - Return value containing domain level server start policy.
# Legal retrun values are "NEVER" or "IF_NEEDED" or "ADMIN_ONLY".
#
function getDomainPolicy {
local domainJson=$1
Expand All @@ -48,6 +50,7 @@ function getDomainPolicy {
# $2 - Name of server
# $3 - Name of cluster
# $4 - Return value containing effective server start policy
# Legal retrun values are "NEVER" or "IF_NEEDED" or "ALWAYS".
#
function getEffectivePolicy {
local domainJson=$1
Expand Down Expand Up @@ -76,6 +79,7 @@ function getEffectivePolicy {
# $1 - Domain resource in json format
# $2 - Name of server
# $3 - Return value containing current server start policy
# Legal retrun values are "NEVER" or "IF_NEEDED", "ALWAYS" or "".
#
function getServerPolicy {
local domainJson=$1
Expand Down Expand Up @@ -172,7 +176,7 @@ function createPatchJsonToUpdateReplica {
}

#
# Function to create patch json string to unset policy
# Function to create patch json string to update replica and policy
# $1 - Domain resource in json format
# $2 - Name of server whose policy will be patched
# $3 - Return value containing patch json string
Expand Down Expand Up @@ -210,7 +214,8 @@ function createPatchJsonToUnsetPolicy {
# $1 - Domain resource in json format
# $2 - Name of server
# $3 - Name of cluster
# $4 - Indicates if policy of current server would be unset
# $4 - Indicates if policy of current server would be unset.
# valid values are "UNSET" and "CONSTANT"
#
function getSortedListOfServers {
local domainJson=$1
Expand Down Expand Up @@ -245,29 +250,23 @@ function getSortedListOfServers {
done
fi
# Create arrays of ALWAYS policy servers and other servers
sortedServersSize=${#sortedServers[@]}
if [ "${sortedServersSize}" -gt 0 ]; then
for localServerName in "${sortedServers[@]}"; do
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy
# Update policy when server name matches current server and unsetting
if [[ "${withPolicy}" == "UNSET" && "${serverName}" == "${localServerName}" ]]; then
policy=UNSET
fi
if [ "${policy}" == "ALWAYS" ]; then
sortedByAlwaysServers+=(${localServerName})
else
otherServers+=(${localServerName})
fi
done
fi
for localServerName in ${sortedServers[@]:-}; do
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy
# Update policy when server name matches current server and unsetting
if [[ "${withPolicy}" == "UNSET" && "${serverName}" == "${localServerName}" ]]; then
policy=UNSET
fi
if [ "${policy}" == "ALWAYS" ]; then
sortedByAlwaysServers+=(${localServerName})
else
otherServers+=(${localServerName})
fi
done

# append other servers to the list of servers with always policy
otherServersSize=${#otherServers[@]}
if [ "${otherServersSize}" -gt 0 ]; then
for otherServer in "${otherServers[@]}"; do
sortedByAlwaysServers+=($otherServer)
done
fi
for otherServer in ${otherServers[@]:-}; do
sortedByAlwaysServers+=($otherServer)
done
}

#
Expand All @@ -284,6 +283,12 @@ function getReplicaCount {
replicasCmd="(.spec.clusters[] \
| select (.clusterName == \"${clusterName}\")).replicas"
replicaCount=$(echo ${domainJson} | jq "${replicasCmd}")
if [[ -z "${replicaCount}" || "${replicaCount}" == "null" ]]; then
replicaCount=$(echo ${domainJson} | jq .spec.replicas)
fi
if [[ -z "${replicaCount}" || "${replicaCount}" == "null" ]]; then
replicaCount=0
fi
eval $__replicaCount="'${replicaCount}'"

}
Expand All @@ -294,9 +299,11 @@ function getReplicaCount {
# $1 - Domain resource in json format
# $2 - Name of server
# $3 - Name of cluster
# $4 - Indicates if replicas will stay constant, incremented or decremented
# $5 - Indicates if policy of current server will stay same or unset
# $6 - Return value indicating if current server will be started
# $4 - Indicates if replicas will stay constant, incremented or decremented.
# Valid values are "CONSTANT", "INCREMENT" and "DECREMENT"
# $5 - Indicates if policy of current server will stay constant or unset.
# Valid values are "CONSTANT" and "UNSET"
# $6 - Return value of "true" or "false" indicating if current server will be started
#
function checkStartedServers {
local domainJson=$1
Expand All @@ -321,23 +328,20 @@ function checkStartedServers {
elif [ "${withReplicas}" == "DECREASED" ]; then
replicaCount=$((replicaCount-1))
fi
sortedByAlwaysSize=${#sortedByAlwaysServers[@]}
if [ "${sortedByAlwaysSize}" -gt 0 ]; then
for localServerName in "${sortedByAlwaysServers[@]}"; do
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy
# Update policy when server name matches current server and unsetting
if [[ "${serverName}" == "${localServerName}" && "${withPolicy}" == "UNSET" ]]; then
policy=UNSET
fi
# check if server should start based on replica count, policy and current replicas
shouldStart "${currentReplicas}" "${policy}" "${replicaCount}" result
if [ "${result}" == 'True' ]; then
# server should start, increment current replicas and add server to list of started servers
currentReplicas=$((currentReplicas+1))
startedServers+=(${localServerName})
fi
done
fi
for localServerName in ${sortedByAlwaysServers[@]:-}; do
getEffectivePolicy "${domainJson}" "${localServerName}" "${clusterName}" policy
# Update policy when server name matches current server and unsetting
if [[ "${serverName}" == "${localServerName}" && "${withPolicy}" == "UNSET" ]]; then
policy=UNSET
fi
# check if server should start based on replica count, policy and current replicas
shouldStart "${currentReplicas}" "${policy}" "${replicaCount}" result
if [ "${result}" == 'true' ]; then
# server should start, increment current replicas and add server to list of started servers
currentReplicas=$((currentReplicas+1))
startedServers+=(${localServerName})
fi
done
startedSize=${#startedServers[@]}
if [ ${startedSize} -gt 0 ]; then
# check if current server is in the list of started servers
Expand All @@ -354,7 +358,7 @@ function checkStartedServers {
# $1 - Current number of replicas
# $2 - Server start policy
# $3 - Replica count
# $4 - Return value
# $4 - Returns "true" or "false" indicating if server should start.
#
function shouldStart {
local currentReplicas=$1
Expand All @@ -363,23 +367,24 @@ function shouldStart {
local __result=$4

if [ "$policy" == "ALWAYS" ]; then
eval $__result=True
eval $__result=true
elif [ "$policy" == "NEVER" ]; then
eval $__result=False
eval $__result=false
elif [ "${currentReplicas}" -lt "${replicaCount}" ]; then
eval $__result=True
eval $__result=true
else
eval $__result=False
eval $__result=false
fi
}

#
# Function to create patch string for updating replica count
# $1 - Domain resource in json format
# $2 - Name of cluster whose replica count will be patched
# $3 - operatation string indicating whether to increment or decrement count
# $3 - operation string indicating whether to increment or decrement replica count.
# Valid values are "INCREMENT" and "DECREMENT"
# $4 - Return value containing replica update patch string
# $5 - Retrun value containing updated replica count
# $5 - Return value containing updated replica count
#
function createReplicaPatch {
local domainJson=$1
Expand All @@ -388,29 +393,23 @@ function createReplicaPatch {
local __result=$4
local __replicaCount=$5
local maxReplicas=""
local errorMessage="@@ ERROR: Maximum number of servers allowed (maxReplica = ${maxReplicas}) \
are already running. Please increase cluster size to start new servers."
local infoMessage="Current replica count value is same as maximum number of replica count. \
Not increasing replica count value."

replicasCmd="(.spec.clusters[] \
| select (.clusterName == \"${clusterName}\")).replicas"
maxReplicaCmd="(.status.clusters[] | select (.clusterName == \"${clusterName}\")) \
| .maximumReplicas"
replica=$(echo ${domainJson} | jq "${replicasCmd}")
if [[ -z "${replica}" || "${replica}" == "null" ]]; then
replica=$(echo ${domainJson} | jq .spec.replicas)
fi
getReplicaCount "${domainJson}" "${clusterName}" replica
if [ "${operation}" == "DECREMENT" ]; then
replica=$((replica-1))
if [ ${replica} -lt 0 ]; then
replica=0
fi
elif [ "${operation}" == "INCREMENT" ]; then
replica=$((replica+1))
maxReplicas=$(echo ${domainJson} | jq "${maxReplicaCmd}")
if [ ${replica} -gt ${maxReplicas} ]; then
echo "${errorMessage}"
eval $__result="MAX_REPLICA_COUNT_EXCEEDED"
return
if [ ${replica} -eq ${maxReplicas} ]; then
printInfo "${infoMessage}"
else
replica=$((replica+1))
fi
fi

Expand All @@ -426,7 +425,7 @@ are already running. Please increase cluster size to start new servers."
# $1 - Domain unique id.
# $2 - Domain namespace.
# $3 - Server name.
# $4 - Return value indicating if server is valid (i.e. if it's part of a cluster or independent server).
# $4 - Return value of "true" or "false" indicating if server is valid (i.e. if it's part of a cluster or independent server).
# $5 - Retrun value containting cluster name to which this server belongs.
#
function validateServerAndFindCluster {
Expand All @@ -439,6 +438,8 @@ function validateServerAndFindCluster {
local errorMessage="Server name is outside the range of allowed servers. \
Please make sure server name is correct."

eval $__isValidServer=false
eval $__clusterName=UNKNOWN
configMap=$(${kubernetesCli} get cm ${domainUid}-weblogic-domain-introspect-cm \
-n ${domainNamespace} -o json)
topology=$(echo "${configMap}" | jq '.data["topology.yaml"]')
Expand All @@ -454,43 +455,39 @@ Please make sure server name is correct."
max:.dynamicServersConfig.maxDynamicClusterSize}"
dynamicClusters=($(echo $jsonTopology | jq "${dynamicClause}" | jq -cr "${namePrefixSize}"))
dynamicClustersSize=${#dynamicClusters[@]}
if [ "${dynamicClustersSize}" -gt 0 ]; then
for dynaClusterNamePrefix in "${dynamicClusters[@]}"; do
prefix=$(echo ${dynaClusterNamePrefix} | jq -r .prefix)
if [[ "${serverName}" == "${prefix}"* ]]; then
maxSize=$(echo ${dynaClusterNamePrefix} | jq -r .max)
number='^[0-9]+$'
if [ $(echo "${serverName}" | grep -c -Eo '[0-9]+$') -gt 0 ]; then
serverCount=$(echo "${serverName}" | grep -Eo '[0-9]+$')
fi
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
for dynaClusterNamePrefix in ${dynamicClusters[@]:-}; do
prefix=$(echo ${dynaClusterNamePrefix} | jq -r .prefix)
if [[ "${serverName}" == "${prefix}"* ]]; then
maxSize=$(echo ${dynaClusterNamePrefix} | jq -r .max)
number='^[0-9]+$'
if [ $(echo "${serverName}" | grep -c -Eo '[0-9]+$') -gt 0 ]; then
serverCount=$(echo "${serverName}" | grep -Eo '[0-9]+$')
fi
done
fi
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
done
staticClause=".domain.configuredClusters[] | select (.dynamicServersConfig == null)"
nameCmd=" . | {name: .name, serverName: .servers[].name}"
configuredClusters=($(echo $jsonTopology | jq "${staticClause}" | jq -cr "${nameCmd}"))
configuredClusterSize=${#configuredClusters[@]}
if [ "${configuredClusterSize}" -gt 0 ]; then
for configuredClusterName in "${configuredClusters[@]}"; do
name=$(echo ${configuredClusterName} | jq -r .serverName)
if [ "${serverName}" == "${name}" ]; then
eval $__clusterName="'$(echo ${configuredClusterName} | jq -r .name)'"
eval $__isValidServer=true
break
fi
done
fi
for configuredClusterName in ${configuredClusters[@]:-}; do
name=$(echo ${configuredClusterName} | jq -r .serverName)
if [ "${serverName}" == "${name}" ]; then
eval $__clusterName="'$(echo ${configuredClusterName} | jq -r .name)'"
eval $__isValidServer=true
break
fi
done
fi
}

Expand All @@ -499,7 +496,7 @@ Please make sure server name is correct."
# $1 - Domain unique id.
# $2 - Domain namespace.
# $3 - cluster name
# $4 - Retrun value indicating whether cluster name is valid
# $4 - Retrun value "true" or "false" indicating whether cluster name is valid
#
function validateClusterName {
local domainUid=$1
Expand All @@ -515,6 +512,8 @@ function validateClusterName {
clusters=($(echo $jsonTopology | jq -cr .domain.configuredClusters[].name))
if checkStringInArray "${clusterName}" "${clusters[@]}" ; then
eval $__isValidCluster=true
else
eval $__isValidCluster=false
fi
}

Expand Down Expand Up @@ -574,7 +573,7 @@ function printInfo {
# purpose: echo timestamp in the form yyyymmddThh:mm:ss.mmm ZZZ
# example: 20181001T14:00:00.001 UTC
function timestamp() {
local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S %N %s %Z' 2>&1`"
timestamp="$(set +e && date --utc '+%Y-%m-%dT%H:%M:%S %N %s %Z' 2>&1 || echo illegal)"
if [ ! "${timestamp/illegal/xyz}" = "${timestamp}" ]; then
# old shell versions don't support %N or --utc
timestamp="`date -u '+%Y-%m-%dT%H:%M:%S 000000 %s %Z' 2>&1`"
Expand Down
3 changes: 2 additions & 1 deletion kubernetes/samples/scripts/domain-lifecycle/startCluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ function usage() {
'spec.clusters[<cluster-name>].serverStartPolicy' attribute of the domain
resource to 'IF_NEEDED'. This change will cause the operator to initiate
startup of cluster's WebLogic server instance pods if the pods are not
already running.
already running and the spec.replicas or
'spec.clusters[<cluster-name>].serverStartPolicy' is set higher than zero.

Usage:

Expand Down
3 changes: 0 additions & 3 deletions kubernetes/samples/scripts/domain-lifecycle/startServer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ if [[ -n ${clusterName} && "${keepReplicaConstant}" != 'true' ]]; then
checkStartedServers "${domainJson}" "${serverName}" "${clusterName}" "${withReplicas}" "${withPolicy}" startsByReplicaIncreaseAndPolicyUnset
operation="INCREMENT"
createReplicaPatch "${domainJson}" "${clusterName}" "${operation}" incrementReplicaPatch replicaCount
if [ "${incrementReplicaPatch}" == "MAX_REPLICA_COUNT_EXCEEDED" ]; then
exit 1
fi
if [[ -n ${managedServerPolicy} && ${startsByReplicaIncreaseAndPolicyUnset} == "true" ]]; then
# Server starts by increasing replicas and policy unset, increment and unset
printInfo "Unsetting the current start policy '${managedServerPolicy}' for '${serverName}' and incrementing replica count."
Expand Down