コード例 #1
0
        /// <summary>
        /// signals AWS to move on from terminate
        /// wait by completing the action
        /// </summary>
        public bool TryCompleteTerminateWait()
        {
            bool returnValue = false;

            //Ok now  its complicated, we need the LifecycleHookName and LifecycleActionToken
            //        to complete the request, there should be a message for us in the queue
            if (!(_TerminatingLifeCycleHookName.IsNullOrWhiteSpace()))
            {
                using (AmazonAutoScalingClient scalingClient = new AmazonAutoScalingClient())
                {
                    CompleteLifecycleActionRequest completeLifecycleActionRequest = new CompleteLifecycleActionRequest
                    {
                        InstanceId            = _InstanceId,
                        LifecycleActionResult = "CONTINUE",
                        AutoScalingGroupName  = _AutoScalingGroupName,
                        LifecycleHookName     = _TerminatingLifeCycleHookName
                    };
                    try
                    {
                        CompleteLifecycleActionResponse completeLifecycleActionResponse = scalingClient.CompleteLifecycleActionAsync(completeLifecycleActionRequest).Result;
                        if (completeLifecycleActionResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                        {
                            returnValue = true;
                        }
                    }
                    catch (Exception)
                    {
                        //Yes AWS throws Exceptions and System.AggregrateExceptions
                        //so for now this is the right way to handle it
                        returnValue = false;
                    }
                }
            }
            return(returnValue);
        }
コード例 #2
0
        /// <summary>
        /// 伸缩实例生命周期回调
        /// </summary>
        public CompleteLifecycleActionResponse CompleteLifecycleAction(CompleteLifecycleActionRequest completeLifecycleActionRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();

            urlParam.Add("scaling_group_id", completeLifecycleActionRequest.ScalingGroupId.ToString());
            string      urlPath  = HttpUtils.AddUrlPath("/autoscaling-api/v1/{project_id}/scaling_instance_hook/{scaling_group_id}/callback", urlParam);
            SdkRequest  request  = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", completeLifecycleActionRequest);
            SdkResponse response = DoHttpRequest("PUT", request);

            return(JsonUtils.DeSerializeNull <CompleteLifecycleActionResponse>(response));
        }
コード例 #3
0
        /// <summary>
        /// 本接口(CompleteLifecycleAction)用于完成生命周期动作。
        ///
        /// * 用户通过调用本接口,指定一个具体的生命周期挂钩的结果(“CONITNUE”或者“ABANDON”)。如果一直不调用本接口,则生命周期挂钩会在超时后按照“DefaultResult”进行处理。
        /// </summary>
        /// <param name="req">参考<see cref="CompleteLifecycleActionRequest"/></param>
        /// <returns>参考<see cref="CompleteLifecycleActionResponse"/>实例</returns>
        public async Task <CompleteLifecycleActionResponse> CompleteLifecycleAction(CompleteLifecycleActionRequest req)
        {
            JsonResponseModel <CompleteLifecycleActionResponse> rsp = null;

            try
            {
                var strResp = await this.InternalRequest(req, "CompleteLifecycleAction");

                rsp = JsonConvert.DeserializeObject <JsonResponseModel <CompleteLifecycleActionResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }