Ejemplo n.º 1
0
        // Scaling Policy V1
        // actionScalingPolicy
        private static void ActionScalingPolicy(AsClient asClient)
        {
            var operateScalingPolicyRequest = new ExecuteScalingPolicyRequest
            {
                ScalingPolicyId = "0d930a61-3c83-43c9-a820-8686d0d4d42d",
                Body            = new ExecuteScalingPolicyRequestBody
                {
                    Action = ExecuteScalingPolicyRequestBody.ActionEnum.PAUSE
                }
            };

            try
            {
                var actionScalingPolicyResponse = asClient.ExecuteScalingPolicy(operateScalingPolicyRequest);
                Console.WriteLine(actionScalingPolicyResponse.HttpStatusCode);
            }
            catch (RequestTimeoutException requestTimeoutException)
            {
                Console.WriteLine(requestTimeoutException.ErrorMessage);
            }
            catch (ServiceResponseException clientRequestException)
            {
                Console.WriteLine(clientRequestException.HttpStatusCode);
                Console.WriteLine(clientRequestException.ErrorCode);
                Console.WriteLine(clientRequestException.ErrorMsg);
            }
            catch (ConnectionException connectionException)
            {
                Console.WriteLine(connectionException.ErrorMessage);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 执行或启用或停止弹性伸缩策略。
        /// </summary>
        public ExecuteScalingPolicyResponse ExecuteScalingPolicy(ExecuteScalingPolicyRequest executeScalingPolicyRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();

            urlParam.Add("scaling_policy_id", executeScalingPolicyRequest.ScalingPolicyId.ToString());
            string      urlPath  = HttpUtils.AddUrlPath("/autoscaling-api/v1/{project_id}/scaling_policy/{scaling_policy_id}/action", urlParam);
            SdkRequest  request  = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", executeScalingPolicyRequest);
            SdkResponse response = DoHttpRequest("POST", request);

            return(JsonUtils.DeSerializeNull <ExecuteScalingPolicyResponse>(response));
        }
        /// <summary>
        /// 本接口(ExecuteScalingPolicy)用于执行伸缩策略。
        ///
        /// * 可以根据伸缩策略ID执行伸缩策略。
        /// * 伸缩策略所属伸缩组处于伸缩活动时,会拒绝执行伸缩策略。
        /// </summary>
        /// <param name="req">参考<see cref="ExecuteScalingPolicyRequest"/></param>
        /// <returns>参考<see cref="ExecuteScalingPolicyResponse"/>实例</returns>
        public async Task <ExecuteScalingPolicyResponse> ExecuteScalingPolicy(ExecuteScalingPolicyRequest req)
        {
            JsonResponseModel <ExecuteScalingPolicyResponse> rsp = null;

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

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