[英]How to show In progress status during HDI cluster creation in Azure on Node js
I am creating a cluster using the following azure cli 2.0 command 我正在使用以下azure cli 2.0命令创建集群
create-cluster.sh 创建群集.sh
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# -e: immediately exit if any command has a non-zero exit status
# -o: prevents errors in a pipeline from being masked
# IFS new value is less likely to cause confusing bugs when looping arrays or arguments (e.g. $@)
usage() { echo "Usage: $0 -i <subscriptionId> -g <resourceGroupName> -n <deploymentName> -l <resourceGroupLocation>" 1>&2; exit 1; }
declare subscriptionId=""
declare resourceGroupName=""
declare deploymentName=""
declare resourceGroupLocation=""
# Initialize parameters specified from command line
while getopts ":i:g:n:l:" arg; do
case "${arg}" in
i)
subscriptionId=${OPTARG}
;;
g)
resourceGroupName=${OPTARG}
;;
n)
deploymentName=${OPTARG}
;;
l)
resourceGroupLocation=${OPTARG}
;;
h)
echo "This message"
esac
done
shift $((OPTIND-1))
#Prompt for parameters is some required parameters are missing
if [[ -z "$subscriptionId" ]]; then
echo "Your subscription ID can be looked up with the CLI using: az account show --out json "
echo "Enter your subscription ID:"
read subscriptionId
[[ "${subscriptionId:?}" ]]
fi
if [[ -z "$resourceGroupName" ]]; then
echo "This script will look for an existing resource group, otherwise a new one will be created "
echo "You can create new resource groups with the CLI using: az group create "
echo "Enter a resource group name"
read resourceGroupName
[[ "${resourceGroupName:?}" ]]
fi
if [[ -z "$deploymentName" ]]; then
echo "Enter a name for this deployment:"
read deploymentName
fi
if [[ -z "$resourceGroupLocation" ]]; then
echo "If creating a *new* resource group, you need to set a location "
echo "You can lookup locations with the CLI using: az account list-locations "
echo "Enter resource group location:"
read resourceGroupLocation
fi
#templateFile Path - template file to be used
templateFilePath="template.json"
if [ ! -f "$templateFilePath" ]; then
echo "$templateFilePath not found"
exit 1
fi
#parameter file path
parametersFilePath="parameters.json"
if [ ! -f "$parametersFilePath" ]; then
echo "$parametersFilePath not found"
exit 1
fi
if [ -z "$subscriptionId" ] || [ -z "$resourceGroupName" ] || [ -z "$deploymentName" ]; then
echo "Either one of subscriptionId, resourceGroupName, deploymentName is empty"
usage
fi
#login to azure using your credentials
az account show 1> /dev/null
if [ $? != 0 ];
then
az login
fi
#set the default subscription id
az account set --subscription $subscriptionId
set +e
#Check for existing RG
az group show $resourceGroupName 1> /dev/null
if [ $? != 0 ]; then
echo "Resource group with name" $resourceGroupName "could not be found. Creating new resource group.."
set -e
(
set -x
az group create --name $resourceGroupName --location $resourceGroupLocation 1> /dev/null
)
else
echo "Using existing resource group..."
fi
#Start deployment
echo "Starting deployment..."
(
set -x
az group deployment create --name "$deploymentName" --resource-group "$resourceGroupName" --template-file "$templateFilePath" --parameters "@${parametersFilePath}"
)
if [ $? == 0 ];
then
echo "Template has been successfully deployed"
fi
I have used cluster template and parameters to create a cluster and it takes around 15 minutes for completion. 我已经使用集群模板和参数来创建集群,完成大约需要15分钟。
In my Node js application UI, I have to show as "Cluster creation InProgress" when cluster creation starts (ie when calling above create-cluster.sh). 在我的Node js应用程序UI中,当群集创建开始时(即,在create-cluster.sh上方调用时),我必须显示为“ Cluster creation InProgress”。
I have to show status as "In progress" in UI till cluster creation completes. 在集群创建完成之前,我必须在UI中将状态显示为“进行中”。
To show as "In Progress" in UI, I am calling command to get the status of HDI cluster. 为了在UI中显示为“进行中”,我正在调用命令以获取HDI群集的状态。 Where I have to execute the below command.
我必须执行以下命令的地方。 Is it end of create-cluster.sh?
它是create-cluster.sh的结尾吗?
az resource show --ids /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.HDInsight/clusters/$clusterName
If my understanding is right, you could write a script to check whether deployment is succeed. 如果我的理解正确,则可以编写脚本来检查部署是否成功。 For example:
例如:
az group deployment show --name HDInsight__2018-03-15T01.36.14.356Z --resource-group shuihdi2 --query '{"status":properties.provisioningState}'
When the status is Succeeded
, you could call delete-cluster.sh
to delete HDI cluster. 状态为
Succeeded
,可以调用delete-cluster.sh
删除HDI群集。
I test in my lab, you could check the test result. 我在实验室测试,您可以检查测试结果。
Update: 更新:
You could make creating HDI process run in the background. 您可以使创建HDI流程在后台运行。 Using like below:
使用如下所示:
nohup az group deployment create --name "$deploymentName" --resource-group "$resourceGroupName" --template-file "$templateFilePath" --parameters "@${parametersFilePath}" > /dev/null 2>&1 &
Then use az group deployment show
to check the deployment status. 然后使用
az group deployment show
检查部署状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.