diff --git a/weblogic-azure-aks/src/main/arm/scripts/py-scripts/checkApplicationStatus.py b/weblogic-azure-aks/src/main/arm/scripts/py-scripts/checkApplicationStatus.py new file mode 100644 index 000000000..0cfa5c4b7 --- /dev/null +++ b/weblogic-azure-aks/src/main/arm/scripts/py-scripts/checkApplicationStatus.py @@ -0,0 +1,58 @@ +# Copyright (c) 2021, Oracle Corporation and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +import sys + +def usage(): + print(sys.argv[0] + '-user -password -t3ChannelAddress
-t3ChannelPort ') + +if len(sys.argv) < 4: + usage() + sys.exit(0) + +#domainUser is hard-coded to weblogic. You can change to other name of your choice. Command line paramter -user. +domainUser = 'weblogic' +#domainPassword will be passed by Command line parameter -password. +domainPassword = None +t3ChannelPort = None +t3ChannelAddress = None + +i = 1 +while i < len(sys.argv): + if sys.argv[i] == '-user': + domainUser = sys.argv[i + 1] + i += 2 + elif sys.argv[i] == '-password': + domainPassword = sys.argv[i + 1] + i += 2 + elif sys.argv[i] == '-t3ChannelAddress': + t3ChannelAddress = sys.argv[i + 1] + i += 2 + elif sys.argv[i] == '-t3ChannelPort': + t3ChannelPort = sys.argv[i + 1] + i += 2 + else: + print('Unexpected argument switch at position ' + str(i) + ': ' + str(sys.argv[i])) + usage() + sys.exit(1) + +t3ConnectionUri='t3://'+t3ChannelAddress+':'+t3ChannelPort +connect(domainUser, domainPassword, t3ConnectionUri) +myapps=cmo.getAppDeployments() +inactiveApp=0 +for app in myapps: + bean=getMBean('/AppDeployments/'+app.getName()+'/Targets/') + targetsbean=bean.getTargets() + for target in targetsbean: + domainRuntime() + cd('AppRuntimeStateRuntime/AppRuntimeStateRuntime') + appstatus=cmo.getCurrentState(app.getName(),target.getName()) + if appstatus != 'STATE_ACTIVE': + inactiveApp=inactiveApp+1 + serverConfig() + +# TIGHT COUPLING: this exact print text is expected to indicate a successful return. +if inactiveApp == 0: + print("Summary: all applications are active!") +else: + print("Summary: number of inactive application:" + inactiveApp + '.') \ No newline at end of file diff --git a/weblogic-azure-aks/src/main/arm/scripts/setupWLSDomain.sh b/weblogic-azure-aks/src/main/arm/scripts/setupWLSDomain.sh index f8b2ede38..f585f5e7b 100644 --- a/weblogic-azure-aks/src/main/arm/scripts/setupWLSDomain.sh +++ b/weblogic-azure-aks/src/main/arm/scripts/setupWLSDomain.sh @@ -735,6 +735,16 @@ function setup_wls_domain() { wait_for_image_update_completed wait_for_pod_completed + + # make sure all the application are active, if not, fail the deployment. + scriptCheckAppStatus=$scriptDir/checkApplicationStatus.py + chmod ugo+x $scriptDir/checkApplicationStatus.py + utility_validate_application_status \ + ${wlsDomainNS} \ + ${wlsAdminSvcName} \ + ${wlsUserName} \ + ${wlsPassword} \ + ${scriptCheckAppStatus} } # Main script @@ -790,6 +800,7 @@ export sasTokenValidTime=3600 export storageFileShareName="weblogic" export storageResourceGroup=${currentResourceGroup} export sharedPath="/shared" +export wlsAdminSvcName="${wlsDomainUID}-admin-server" export wlsDomainNS="${wlsDomainUID}-ns" export wlsOptHelmChart="https://oracle.github.io/weblogic-kubernetes-operator/charts" export wlsOptNameSpace="weblogic-operator-ns" diff --git a/weblogic-azure-aks/src/main/arm/scripts/utility.sh b/weblogic-azure-aks/src/main/arm/scripts/utility.sh index 42b0cf113..fc4040a5e 100644 --- a/weblogic-azure-aks/src/main/arm/scripts/utility.sh +++ b/weblogic-azure-aks/src/main/arm/scripts/utility.sh @@ -141,6 +141,42 @@ function utility_upload_file_to_fileshare() { fi } +# +# Make sure all the applications are running +# Exit with error if there is inactive application. +# $1 - namespace of the domain +# $2 - ClusterIP service name of admin server +# $3 - domain user +# $4 - domain password +# $5 - path of python script which checks application status, the script will run on admin server pod. +function utility_validate_application_status() { + local wlsDomainNS=$1 + local wlsAdminSvcName=$2 + local wlsUser=$3 + local wlsPassword=$4 + local pyScriptPath=$5 + + local podName=$(kubectl -n ${wlsDomainNS} get pod -l weblogic.serverName=admin-server -o json \ + | jq '.items[0] | .metadata.name' \ + | tr -d "\"") + + # get non-ssl port + local adminTargetPort=$(kubectl get svc ${wlsAdminSvcName} -n ${wlsDomainNS} -o json | jq '.spec.ports[] | select(.name=="default") | .port') + local t3ChannelAddress="${podName}.${wlsDomainNS}" + + local targetFilePath=/tmp/checkApplicationStatus.py + echo "copy ${pyScriptPath} to ${targetFilePath}" + kubectl cp ${pyScriptPath} -n ${wlsDomainNS} ${podName}:${targetFilePath} + kubectl exec -it ${podName} -n ${wlsDomainNS} -c "weblogic-server" \ + -- bash -c "wlst.sh ${targetFilePath} -user ${wlsUser} -password ${wlsPassword} -t3ChannelAddress ${t3ChannelAddress} -t3ChannelPort ${adminTargetPort}" | + grep "Summary: all applications are active" + + if [ $? == 1 ];then + echo "Failed to deploy application to WLS cluster. Please make sure the configurations are correct." + exit 1 + fi +} + # Call this function to make sure pods of a domain are running. # * Make sure the admin server pod is running # * Make sure all the managed server pods are running diff --git a/weblogic-azure-aks/src/main/bicep/modules/_deployment-scripts/_ds-create-wls-cluster.bicep b/weblogic-azure-aks/src/main/bicep/modules/_deployment-scripts/_ds-create-wls-cluster.bicep index e7fafd739..33468b2b3 100644 --- a/weblogic-azure-aks/src/main/bicep/modules/_deployment-scripts/_ds-create-wls-cluster.bicep +++ b/weblogic-azure-aks/src/main/bicep/modules/_deployment-scripts/_ds-create-wls-cluster.bicep @@ -62,6 +62,7 @@ var const_arguments = '${ocrSSOUser} ${ocrSSOPSW} ${aksClusterRGName} ${aksClust var const_buildDockerImageScript='createVMAndBuildImage.sh' var const_commonScript = 'common.sh' var const_invokeSetUpDomainScript = 'invokeSetupWLSDomain.sh' +var const_pyCheckAppStatusScript = 'py-scripts/checkApplicationStatus.py' var const_pvTempalte = 'pv.yaml.template' var const_pvcTempalte = 'pvc.yaml.template' var const_scriptLocation = uri(_artifactsLocation, 'scripts/') @@ -88,6 +89,7 @@ resource deploymentScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = { uri(const_scriptLocation, '${const_commonScript}${_artifactsLocationSasToken}') uri(const_scriptLocation, '${const_buildDockerImageScript}${_artifactsLocationSasToken}') uri(const_scriptLocation, '${const_updateDomainConfigScript}${_artifactsLocationSasToken}') + uri(const_scriptLocation, '${const_pyCheckAppStatusScript}${_artifactsLocationSasToken}') ] cleanupPreference: 'OnSuccess' retentionInterval: 'P1D'