Skip to content

Commit fa08b82

Browse files
authored
Fix for mac os and validation error messages when no parameters are specified (OWLS-86060) (#2062)
* Fix for mac os and validation error messages when no parameters are specified (OWLS-86060) * Fix error message * Provide usage information when validation fails. * Fix error message when domain resource not found. * Validate that domain resource exists before validating server/cluster name in config map. * Fix error message as per review comment. * Fixed error message.
1 parent 47d323d commit fa08b82

File tree

7 files changed

+80
-52
lines changed

7 files changed

+80
-52
lines changed

kubernetes/samples/scripts/domain-lifecycle/helper.sh

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,7 @@ function getSortedListOfServers {
257257
local sortedServers=()
258258
local otherServers=()
259259

260-
getConfigMap "${domainUid}" "${domainNamespace}" configMap
261-
topology=$(echo "${configMap}" | jq '.data["topology.yaml"]')
262-
jsonTopology=$(python -c \
263-
'import sys, yaml, json; print json.dumps(yaml.safe_load('"${topology}"'), indent=4)')
260+
getTopology "${domainUid}" "${domainNamespace}" jsonTopology
264261
clusterTopology=$(echo ${jsonTopology} | jq -r '.domain | .configuredClusters[] | select (.name == '\"${clusterName}\"')')
265262
dynaCluster=$(echo ${clusterTopology} | jq .dynamicServersConfig)
266263
if [ "${dynaCluster}" == "null" ]; then
@@ -509,10 +506,7 @@ function validateServerAndFindCluster {
509506

510507
eval $__isValidServer=false
511508
eval $__clusterName=UNKNOWN
512-
getConfigMap "${domainUid}" "${domainNamespace}" configMap
513-
topology=$(echo "${configMap}" | jq '.data["topology.yaml"]')
514-
jsonTopology=$(python -c \
515-
'import sys, yaml, json; print json.dumps(yaml.safe_load('"${topology}"'), indent=4)')
509+
getTopology "${domainUid}" "${domainNamespace}" jsonTopology
516510
adminServer=$(echo $jsonTopology | jq -r .domain.adminServerName)
517511
if [ "${serverName}" == "${adminServer}" ]; then
518512
printError "Server '${serverName}' is administration server. The '${script}' script doesn't support starting or stopping administration server."
@@ -578,12 +572,7 @@ function validateClusterName {
578572
local clusterName=$3
579573
local __isValidCluster=$4
580574

581-
getConfigMap "${domainUid}" "${domainNamespace}" configMap
582-
configMap=$(${kubernetesCli} get cm ${domainUid}-weblogic-domain-introspect-cm \
583-
-n ${domainNamespace} -o json)
584-
topology=$(echo "${configMap}" | jq '.data["topology.yaml"]')
585-
jsonTopology=$(python -c \
586-
'import sys, yaml, json; print json.dumps(yaml.safe_load('"${topology}"'), indent=4)')
575+
getTopology "${domainUid}" "${domainNamespace}" jsonTopology
587576
clusters=($(echo $jsonTopology | jq -cr .domain.configuredClusters[].name))
588577
if checkStringInArray "${clusterName}" "${clusters[@]}" ; then
589578
eval $__isValidCluster=true
@@ -592,20 +581,31 @@ function validateClusterName {
592581
fi
593582
}
594583

595-
function getConfigMap {
584+
function getTopology {
596585
local domainUid=$1
597586
local domainNamespace=$2
598587
local __result=$3
599588

600-
configMap=$(${kubernetesCli} get cm ${domainUid}-weblogic-domain-introspect-cm \
601-
-n ${domainNamespace} -o json --ignore-not-found)
589+
if [[ "$OSTYPE" == "darwin"* ]]; then
590+
configMap=$(${kubernetesCli} get cm ${domainUid}-weblogic-domain-introspect-cm \
591+
-n ${domainNamespace} -o yaml --ignore-not-found)
592+
else
593+
configMap=$(${kubernetesCli} get cm ${domainUid}-weblogic-domain-introspect-cm \
594+
-n ${domainNamespace} -o json --ignore-not-found)
595+
fi
602596
if [ -z "${configMap}" ]; then
603597
printError "Domain config map '${domainUid}-weblogic-domain-introspect-cm' not found. \
604598
This script requires that the introspector job for the specified domain ran \
605599
successfully and generated this config map. Exiting."
606600
exit 1
601+
elif [[ "$OSTYPE" == "darwin"* ]]; then
602+
jsonTopology=$(echo "${configMap}" | yq r - data.[topology.yaml] | yq r - -j)
603+
else
604+
topology=$(echo "${configMap}" | jq '.data["topology.yaml"]')
605+
jsonTopology=$(python -c \
606+
'import sys, yaml, json; print json.dumps(yaml.safe_load('"${topology}"'), indent=4)')
607607
fi
608-
eval $__result="'${configMap}'"
608+
eval $__result="'${jsonTopology}'"
609609
}
610610

611611

@@ -629,6 +629,12 @@ function validateJqAvailable {
629629
fi
630630
}
631631

632+
function validateYqAvailable {
633+
if [[ "$OSTYPE" == "darwin"* ]] && ! [ -x "$(command -v yq)" ]; then
634+
validationError "yq is not installed"
635+
fi
636+
}
637+
632638
# try to execute python to see whether python is available
633639
function validatePythonAvailable {
634640
if ! [ -x "$(command -v python)" ]; then
@@ -643,14 +649,6 @@ function validateKubernetesCliAvailable {
643649
fi
644650
}
645651

646-
#
647-
# Function to exit and print an error message
648-
# $1 - text of message
649-
function fail {
650-
printError $*
651-
exit 1
652-
}
653-
654652
# Function to print an error message
655653
function printError {
656654
echo [`timestamp`][ERROR] $*
@@ -714,6 +712,7 @@ function validationError {
714712
#
715713
function failIfValidationErrors {
716714
if [ "$validateErrors" = true ]; then
717-
fail 'The errors listed above must be resolved before the script can continue'
715+
printError 'The errors listed above must be resolved before the script can continue. Please see usage information below.'
716+
usage 1
718717
fi
719718
}

kubernetes/samples/scripts/domain-lifecycle/startCluster.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,31 @@ function initialize {
7777

7878
validateKubernetesCliAvailable
7979
validateJqAvailable
80+
validateYqAvailable
8081

8182
if [ -z "${clusterName}" ]; then
8283
validationError "Please specify cluster name using '-c' parameter e.g. '-c cluster-1'."
8384
fi
8485

85-
isValidCluster=""
86-
validateClusterName "${domainUid}" "${domainNamespace}" "${clusterName}" isValidCluster
87-
88-
if [ "${isValidCluster}" != 'true' ]; then
89-
validationError "cluster ${clusterName} is not part of domain ${domainUid} in namespace ${domainNamespace}."
90-
fi
91-
9286
failIfValidationErrors
87+
9388
}
9489

9590
initialize
9691

9792
# Get the domain in json format
98-
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json)
93+
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json --ignore-not-found)
94+
if [ -z "${domainJson}" ]; then
95+
printError "Unable to get domain resource for domain '${domainUid}' in namespace '${domainNamespace}'. Please make sure the 'domain_uid' and 'namespace' specified by the '-d' and '-n' arguments are correct. Exiting."
96+
exit 1
97+
fi
98+
99+
isValidCluster=""
100+
validateClusterName "${domainUid}" "${domainNamespace}" "${clusterName}" isValidCluster
101+
if [ "${isValidCluster}" != 'true' ]; then
102+
printError "cluster ${clusterName} is not part of domain ${domainUid} in namespace ${domainNamespace}. Please make sure that cluster name is correct."
103+
exit 1
104+
fi
99105

100106
getDomainPolicy "${domainJson}" domainStartPolicy
101107
# Fail if effective start policy of domain is NEVER or ADMIN_ONLY

kubernetes/samples/scripts/domain-lifecycle/startDomain.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,20 @@ function initialize {
6767

6868
validateKubernetesCliAvailable
6969
validateJqAvailable
70+
validateYqAvailable
71+
7072
failIfValidationErrors
7173
}
7274

7375
initialize
7476

7577
# Get the domain in json format
76-
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json)
78+
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json --ignore-not-found)
79+
80+
if [ -z "${domainJson}" ]; then
81+
printError "Domain resource for domain '${domainUid}' not found in namespace '${domainNamespace}'. Exiting."
82+
exit 1
83+
fi
7784

7885
getDomainPolicy "${domainJson}" serverStartPolicy
7986

kubernetes/samples/scripts/domain-lifecycle/startServer.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function initialize {
120120

121121
validateKubernetesCliAvailable
122122
validateJqAvailable
123+
validateYqAvailable
123124

124125
# Validate that server name parameter is specified.
125126
if [ -z "${serverName}" ]; then
@@ -132,9 +133,9 @@ function initialize {
132133
initialize
133134

134135
# Get the domain in json format
135-
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json)
136-
if [ $? -ne 0 ]; then
137-
printError "Unable to get domain resource. Please make sure 'domain_uid' and 'namespace' provided with '-d' and '-n' arguments are correct."
136+
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json --ignore-not-found)
137+
if [ -z "${domainJson}" ]; then
138+
printError "Unable to get domain resource for domain '${domainUid}' in namespace '${domainNamespace}'. Please make sure the 'domain_uid' and 'namespace' specified by the '-d' and '-n' arguments are correct. Exiting."
138139
exit 1
139140
fi
140141

kubernetes/samples/scripts/domain-lifecycle/stopCluster.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,30 @@ function initialize {
7575

7676
validateKubernetesCliAvailable
7777
validateJqAvailable
78+
validateYqAvailable
7879

7980
if [ -z "${clusterName}" ]; then
8081
validationError "Please specify cluster name using '-c' parameter e.g. '-c cluster-1'."
8182
fi
8283

83-
isValidCluster=""
84-
validateClusterName "${domainUid}" "${domainNamespace}" "${clusterName}" isValidCluster
85-
86-
if [ "${isValidCluster}" != 'true' ]; then
87-
validationError "cluster ${clusterName} is not part of domain ${domainUid} in namespace ${domainNamespace}. "
88-
fi
89-
9084
failIfValidationErrors
9185
}
9286

9387
initialize
9488

9589
# Get the domain in json format
96-
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json)
90+
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json --ignore-not-found)
91+
if [ -z "${domainJson}" ]; then
92+
printError "Unable to get domain resource for domain '${domainUid}' in namespace '${domainNamespace}'. Please make sure the 'domain_uid' and 'namespace' specified by the '-d' and '-n' arguments are correct. Exiting."
93+
exit 1
94+
fi
95+
96+
isValidCluster=""
97+
validateClusterName "${domainUid}" "${domainNamespace}" "${clusterName}" isValidCluster
98+
if [ "${isValidCluster}" != 'true' ]; then
99+
printError "cluster ${clusterName} is not part of domain ${domainUid} in namespace ${domainNamespace}. Please make sure that cluster name is correct."
100+
exit 1
101+
fi
97102

98103
# Get server start policy for this server
99104
getClusterPolicy "${domainJson}" "${clusterName}" startPolicy

kubernetes/samples/scripts/domain-lifecycle/stopDomain.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,19 @@ function initialize {
6666

6767
validateKubernetesCliAvailable
6868
validateJqAvailable
69+
validateYqAvailable
6970
failIfValidationErrors
7071
}
7172

7273
initialize
7374

7475
# Get the domain in json format
75-
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json)
76+
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json --ignore-not-found)
77+
78+
if [ -z "${domainJson}" ]; then
79+
printError "Domain resource for domain '${domainUid}' not found in namespace '${domainNamespace}'. Exiting."
80+
exit 1
81+
fi
7682

7783
getDomainPolicy "${domainJson}" serverStartPolicy
7884

kubernetes/samples/scripts/domain-lifecycle/stopServer.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ function initialize {
116116

117117
validateKubernetesCliAvailable
118118
validateJqAvailable
119+
validateYqAvailable
119120

120121
# Validate that server name parameter is specified.
121122
if [ -z "${serverName}" ]; then
@@ -127,17 +128,20 @@ function initialize {
127128

128129
initialize
129130

131+
# Get the domain in json format
132+
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json --ignore-not-found)
133+
if [ -z "${domainJson}" ]; then
134+
printError "Unable to get domain resource for domain '${domainUid}' in namespace '${domainNamespace}'. Please make sure the 'domain_uid' and 'namespace' specified by the '-d' and '-n' arguments are correct. Exiting."
135+
exit 1
136+
fi
137+
130138
# Validate that specified server is either part of a cluster or is an independent managed server
131139
validateServerAndFindCluster "${domainUid}" "${domainNamespace}" "${serverName}" isValidServer clusterName
132140
if [ "${isValidServer}" != 'true' ]; then
133141
printError "Server ${serverName} is not part of any cluster and it's not an independent managed server. Please make sure that server name specified is correct."
134142
exit 1
135143
fi
136144

137-
138-
# Get the domain in json format
139-
domainJson=$(${kubernetesCli} get domain ${domainUid} -n ${domainNamespace} -o json)
140-
141145
getEffectivePolicy "${domainJson}" "${serverName}" "${clusterName}" effectivePolicy
142146
if [ -n "${clusterName}" ]; then
143147
# Server is part of a cluster, check currently started servers

0 commit comments

Comments
 (0)