Skip to content

Commit 8cae543

Browse files
authored
Merge pull request #43 from galiacheng/validate-app
Make sure applications are active in the cluster
2 parents cc947f7 + 848ce8b commit 8cae543

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (c) 2021, Oracle Corporation and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
import sys
5+
6+
def usage():
7+
print(sys.argv[0] + '-user <domain-user> -password <domain-password> -t3ChannelAddress <address of the cluster> -t3ChannelPort <t3 channel port>')
8+
9+
if len(sys.argv) < 4:
10+
usage()
11+
sys.exit(0)
12+
13+
#domainUser is hard-coded to weblogic. You can change to other name of your choice. Command line paramter -user.
14+
domainUser = 'weblogic'
15+
#domainPassword will be passed by Command line parameter -password.
16+
domainPassword = None
17+
t3ChannelPort = None
18+
t3ChannelAddress = None
19+
20+
i = 1
21+
while i < len(sys.argv):
22+
if sys.argv[i] == '-user':
23+
domainUser = sys.argv[i + 1]
24+
i += 2
25+
elif sys.argv[i] == '-password':
26+
domainPassword = sys.argv[i + 1]
27+
i += 2
28+
elif sys.argv[i] == '-t3ChannelAddress':
29+
t3ChannelAddress = sys.argv[i + 1]
30+
i += 2
31+
elif sys.argv[i] == '-t3ChannelPort':
32+
t3ChannelPort = sys.argv[i + 1]
33+
i += 2
34+
else:
35+
print('Unexpected argument switch at position ' + str(i) + ': ' + str(sys.argv[i]))
36+
usage()
37+
sys.exit(1)
38+
39+
t3ConnectionUri='t3://'+t3ChannelAddress+':'+t3ChannelPort
40+
connect(domainUser, domainPassword, t3ConnectionUri)
41+
myapps=cmo.getAppDeployments()
42+
inactiveApp=0
43+
for app in myapps:
44+
bean=getMBean('/AppDeployments/'+app.getName()+'/Targets/')
45+
targetsbean=bean.getTargets()
46+
for target in targetsbean:
47+
domainRuntime()
48+
cd('AppRuntimeStateRuntime/AppRuntimeStateRuntime')
49+
appstatus=cmo.getCurrentState(app.getName(),target.getName())
50+
if appstatus != 'STATE_ACTIVE':
51+
inactiveApp=inactiveApp+1
52+
serverConfig()
53+
54+
# TIGHT COUPLING: this exact print text is expected to indicate a successful return.
55+
if inactiveApp == 0:
56+
print("Summary: all applications are active!")
57+
else:
58+
print("Summary: number of inactive application:" + inactiveApp + '.')

weblogic-azure-aks/src/main/arm/scripts/setupWLSDomain.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,16 @@ function setup_wls_domain() {
735735
wait_for_image_update_completed
736736

737737
wait_for_pod_completed
738+
739+
# make sure all the application are active, if not, fail the deployment.
740+
scriptCheckAppStatus=$scriptDir/checkApplicationStatus.py
741+
chmod ugo+x $scriptDir/checkApplicationStatus.py
742+
utility_validate_application_status \
743+
${wlsDomainNS} \
744+
${wlsAdminSvcName} \
745+
${wlsUserName} \
746+
${wlsPassword} \
747+
${scriptCheckAppStatus}
738748
}
739749

740750
# Main script
@@ -790,6 +800,7 @@ export sasTokenValidTime=3600
790800
export storageFileShareName="weblogic"
791801
export storageResourceGroup=${currentResourceGroup}
792802
export sharedPath="/shared"
803+
export wlsAdminSvcName="${wlsDomainUID}-admin-server"
793804
export wlsDomainNS="${wlsDomainUID}-ns"
794805
export wlsOptHelmChart="https://oracle.github.io/weblogic-kubernetes-operator/charts"
795806
export wlsOptNameSpace="weblogic-operator-ns"

weblogic-azure-aks/src/main/arm/scripts/utility.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,42 @@ function utility_upload_file_to_fileshare() {
141141
fi
142142
}
143143

144+
#
145+
# Make sure all the applications are running
146+
# Exit with error if there is inactive application.
147+
# $1 - namespace of the domain
148+
# $2 - ClusterIP service name of admin server
149+
# $3 - domain user
150+
# $4 - domain password
151+
# $5 - path of python script which checks application status, the script will run on admin server pod.
152+
function utility_validate_application_status() {
153+
local wlsDomainNS=$1
154+
local wlsAdminSvcName=$2
155+
local wlsUser=$3
156+
local wlsPassword=$4
157+
local pyScriptPath=$5
158+
159+
local podName=$(kubectl -n ${wlsDomainNS} get pod -l weblogic.serverName=admin-server -o json \
160+
| jq '.items[0] | .metadata.name' \
161+
| tr -d "\"")
162+
163+
# get non-ssl port
164+
local adminTargetPort=$(kubectl get svc ${wlsAdminSvcName} -n ${wlsDomainNS} -o json | jq '.spec.ports[] | select(.name=="default") | .port')
165+
local t3ChannelAddress="${podName}.${wlsDomainNS}"
166+
167+
local targetFilePath=/tmp/checkApplicationStatus.py
168+
echo "copy ${pyScriptPath} to ${targetFilePath}"
169+
kubectl cp ${pyScriptPath} -n ${wlsDomainNS} ${podName}:${targetFilePath}
170+
kubectl exec -it ${podName} -n ${wlsDomainNS} -c "weblogic-server" \
171+
-- bash -c "wlst.sh ${targetFilePath} -user ${wlsUser} -password ${wlsPassword} -t3ChannelAddress ${t3ChannelAddress} -t3ChannelPort ${adminTargetPort}" |
172+
grep "Summary: all applications are active"
173+
174+
if [ $? == 1 ];then
175+
echo "Failed to deploy application to WLS cluster. Please make sure the configurations are correct."
176+
exit 1
177+
fi
178+
}
179+
144180
# Call this function to make sure pods of a domain are running.
145181
# * Make sure the admin server pod is running
146182
# * Make sure all the managed server pods are running

weblogic-azure-aks/src/main/bicep/modules/_deployment-scripts/_ds-create-wls-cluster.bicep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var const_arguments = '${ocrSSOUser} ${ocrSSOPSW} ${aksClusterRGName} ${aksClust
6262
var const_buildDockerImageScript='createVMAndBuildImage.sh'
6363
var const_commonScript = 'common.sh'
6464
var const_invokeSetUpDomainScript = 'invokeSetupWLSDomain.sh'
65+
var const_pyCheckAppStatusScript = 'py-scripts/checkApplicationStatus.py'
6566
var const_pvTempalte = 'pv.yaml.template'
6667
var const_pvcTempalte = 'pvc.yaml.template'
6768
var const_scriptLocation = uri(_artifactsLocation, 'scripts/')
@@ -88,6 +89,7 @@ resource deploymentScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
8889
uri(const_scriptLocation, '${const_commonScript}${_artifactsLocationSasToken}')
8990
uri(const_scriptLocation, '${const_buildDockerImageScript}${_artifactsLocationSasToken}')
9091
uri(const_scriptLocation, '${const_updateDomainConfigScript}${_artifactsLocationSasToken}')
92+
uri(const_scriptLocation, '${const_pyCheckAppStatusScript}${_artifactsLocationSasToken}')
9193
]
9294
cleanupPreference: 'OnSuccess'
9395
retentionInterval: 'P1D'

0 commit comments

Comments
 (0)