/// <summary> /// 创建弹性伸缩策略 /// </summary> public CreateScalingPolicyResponse CreateScalingPolicy(CreateScalingPolicyRequest createScalingPolicyRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); string urlPath = HttpUtils.AddUrlPath("/autoscaling-api/v1/{project_id}/scaling_policy", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", createScalingPolicyRequest); SdkResponse response = DoHttpRequest("POST", request); return(JsonUtils.DeSerialize <CreateScalingPolicyResponse>(response)); }
/// <summary> /// Create a new scaling policy /// </summary> /// <param name="projectId">Your Google Cloud Project Id</param> /// <param name="policyId">Id of the scaling policy</param> /// <param name="deploymentId">Id of the deployment to scale</param> public string CreateScalingPolicy( string projectId = "YOUR-PROJECT-ID", string policyId = "YOUR-SCALING-POLICY-ID", string deploymentId = "YOUR-DEPLOYMENT-ID") { // Initialize the client var client = ScalingPoliciesServiceClient.Create(); // Construct the request string parent = $"projects/{projectId}/locations/global"; string policyName = $"{parent}/scalingPolicies/{policyId}"; string deploymentName = $"{parent}/gameServerDeployments/{deploymentId}"; var autoscalerSettings = new FleetAutoscalerSettings { BufferSizeAbsolute = 1, MinReplicas = 1, MaxReplicas = 2 }; var scalingPolicy = new ScalingPolicy { Name = policyName, Priority = 1, FleetAutoscalerSettings = autoscalerSettings, GameServerDeployment = deploymentName }; var scalingPolicyRequest = new CreateScalingPolicyRequest { Parent = parent, ScalingPolicyId = policyId, ScalingPolicy = scalingPolicy }; // Call the API try { var created = client.CreateScalingPolicy(scalingPolicyRequest); // Inspect the result return($"Scaling policy created for {policyName}. Operation Id {created.Name}"); } catch (Exception e) { Console.WriteLine($"CreateScalingPolicy error:"); Console.WriteLine($"{e.Message}"); throw; } }
/// <summary> /// 本接口(CreateScalingPolicy)用于创建告警触发策略。 /// </summary> /// <param name="req">参考<see cref="CreateScalingPolicyRequest"/></param> /// <returns>参考<see cref="CreateScalingPolicyResponse"/>实例</returns> public async Task <CreateScalingPolicyResponse> CreateScalingPolicy(CreateScalingPolicyRequest req) { JsonResponseModel <CreateScalingPolicyResponse> rsp = null; try { var strResp = await this.InternalRequest(req, "CreateScalingPolicy"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <CreateScalingPolicyResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
// Scaling Policy V1 // createScalingPolicyV1 private static void CreateScalingPolicy(AsClient asClient) { var createScalingPolicyRequest = new CreateScalingPolicyRequest() { Body = new CreateScalingPolicyRequestBody { ScalingPolicyName = "test_policy", ScalingGroupId = "fa07d522-6794-4c1c-98be-c1c2c4d43fbe", ScalingPolicyType = CreateScalingPolicyRequestBody.ScalingPolicyTypeEnum.ALARM, AlarmId = "al1584674706316rxR3Rjz7x", ScalingPolicyAction = new ScalingPolicyAction() { Operation = ScalingPolicyAction.OperationEnum.ADD, InstanceNumber = 1 } } }; try { var createScalingPolicyResponse = asClient.CreateScalingPolicy(createScalingPolicyRequest); Console.WriteLine(createScalingPolicyResponse.ScalingPolicyId); } 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); } }