/// <summary>
        /// Initiates the asynchronous execution of the PutScalingPolicy operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PutScalingPolicy operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <PutScalingPolicyResponse> PutScalingPolicyAsync(PutScalingPolicyRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new PutScalingPolicyRequestMarshaller();
            var unmarshaller = PutScalingPolicyResponseUnmarshaller.Instance;

            return(InvokeAsync <PutScalingPolicyRequest, PutScalingPolicyResponse>(request, marshaller,
                                                                                   unmarshaller, cancellationToken));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the PutScalingPolicy operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PutScalingPolicy operation on AmazonApplicationAutoScalingClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndPutScalingPolicy
        ///         operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/application-autoscaling-2016-02-06/PutScalingPolicy">REST API Reference for PutScalingPolicy Operation</seealso>
        public IAsyncResult BeginPutScalingPolicy(PutScalingPolicyRequest request, AsyncCallback callback, object state)
        {
            var marshaller   = new PutScalingPolicyRequestMarshaller();
            var unmarshaller = PutScalingPolicyResponseUnmarshaller.Instance;

            return(BeginInvoke <PutScalingPolicyRequest>(request, marshaller, unmarshaller,
                                                         callback, state));
        }
Example #3
0
        /// <summary>
        /// Initiates the asynchronous execution of the PutScalingPolicy operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PutScalingPolicy operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/application-autoscaling-2016-02-06/PutScalingPolicy">REST API Reference for PutScalingPolicy Operation</seealso>
        public virtual Task <PutScalingPolicyResponse> PutScalingPolicyAsync(PutScalingPolicyRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = PutScalingPolicyRequestMarshaller.Instance;
            options.ResponseUnmarshaller = PutScalingPolicyResponseUnmarshaller.Instance;

            return(InvokeAsync <PutScalingPolicyResponse>(request, options, cancellationToken));
        }
Example #4
0
        internal virtual PutScalingPolicyResponse PutScalingPolicy(PutScalingPolicyRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = PutScalingPolicyRequestMarshaller.Instance;
            options.ResponseUnmarshaller = PutScalingPolicyResponseUnmarshaller.Instance;

            return(Invoke <PutScalingPolicyResponse>(request, options));
        }
Example #5
0
        /// <summary>
        /// 用于设置动态扩缩容配置
        /// </summary>
        /// <param name="req"><see cref="PutScalingPolicyRequest"/></param>
        /// <returns><see cref="PutScalingPolicyResponse"/></returns>
        public PutScalingPolicyResponse PutScalingPolicySync(PutScalingPolicyRequest req)
        {
            JsonResponseModel <PutScalingPolicyResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "PutScalingPolicy");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <PutScalingPolicyResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
Example #6
0
        static async Task <string> CreateFleet(string name, string version, string buildId)
        {
            var config = new AmazonGameLiftConfig();

            config.RegionEndpoint = region;
            using (AmazonGameLiftClient aglc = new AmazonGameLiftClient(config))
            {
                // create launch configuration
                var serverProcess = new ServerProcess();
                serverProcess.ConcurrentExecutions = 1;
                serverProcess.LaunchPath           = @"C:\game\GameLiftUnity.exe"; // @"/local/game/ReproGLLinux.x86_64";
                serverProcess.Parameters           = "-batchmode -nographics";

                // create inbound IP permissions
                var permission1 = new IpPermission();
                permission1.FromPort = 1935;
                permission1.ToPort   = 1935;
                permission1.Protocol = IpProtocol.TCP;
                permission1.IpRange  = "0.0.0.0/0";

                // create inbound IP permissions
                var permission2 = new IpPermission();
                permission2.FromPort = 3389;
                permission2.ToPort   = 3389;
                permission2.Protocol = IpProtocol.TCP;
                permission2.IpRange  = "0.0.0.0/0";

                // create fleet
                var cfreq = new CreateFleetRequest();
                cfreq.Name            = name;
                cfreq.Description     = version;
                cfreq.BuildId         = buildId;
                cfreq.EC2InstanceType = EC2InstanceType.C4Large;
                cfreq.EC2InboundPermissions.Add(permission1);
                cfreq.EC2InboundPermissions.Add(permission2);
                cfreq.RuntimeConfiguration = new RuntimeConfiguration();
                cfreq.RuntimeConfiguration.ServerProcesses = new List <ServerProcess>();
                cfreq.RuntimeConfiguration.ServerProcesses.Add(serverProcess);
                cfreq.NewGameSessionProtectionPolicy = ProtectionPolicy.NoProtection;
                CreateFleetResponse cfres = await aglc.CreateFleetAsync(cfreq);

                // set fleet capacity
                var ufcreq = new UpdateFleetCapacityRequest();
                ufcreq.MinSize          = 0;
                ufcreq.DesiredInstances = 1;
                ufcreq.MaxSize          = 1;
                ufcreq.FleetId          = cfres.FleetAttributes.FleetId;
                UpdateFleetCapacityResponse ufcres = await aglc.UpdateFleetCapacityAsync(ufcreq);

                // set scaling rule (switch fleet off after 1 day of inactivity)
                // If [MetricName] is [ComparisonOperator] [Threshold] for [EvaluationPeriods] minutes, then [ScalingAdjustmentType] to/by [ScalingAdjustment].
                var pspreq = new PutScalingPolicyRequest();
                pspreq.Name                  = "Switch fleet off after 1 day of inactivity";
                pspreq.MetricName            = MetricName.ActiveGameSessions;
                pspreq.ComparisonOperator    = ComparisonOperatorType.LessThanOrEqualToThreshold;
                pspreq.Threshold             = 0.0;  // double (don't use int)
                pspreq.EvaluationPeriods     = 1435; // just under 1 day, 1435 appears to be the maximum permitted value now.
                pspreq.ScalingAdjustmentType = ScalingAdjustmentType.ExactCapacity;
                pspreq.ScalingAdjustment     = 0;
                pspreq.FleetId               = cfres.FleetAttributes.FleetId;
                PutScalingPolicyResponse pspres = await aglc.PutScalingPolicyAsync(pspreq);

                return(cfres.FleetAttributes.FleetId);
            }
        }
 public void PutScalingPolicyAsync(PutScalingPolicyRequest request, AmazonServiceCallback <PutScalingPolicyRequest, PutScalingPolicyResponse> callback, AsyncOptions options = null)
 {
     throw new System.NotImplementedException();
 }
        public static void Configure()
        {
            //Amazon Credentials
            string accessKey = ConfigurationManager.AppSettings["AWSAccessKeyId"];
            string secretKey = ConfigurationManager.AppSettings["AWSSecretKey"];

            string launchConfigurationName = "ScheduledServicesLaunchConfiguration";

            string autoScalingGroupName = "ScheduledServiceASG";
            string scaleOutPolicyName   = "ScheduledServicesScaleOutSQSPolicy";
            string scaleInPolicyName    = "ScheduledServicesScaleInSQSPolicy";

            string scaleOutARN = "";
            string scaleInARN  = "";

            string queueName = "ScheduledServicesSQS";
            string queueURL  = "";

            string amiID        = "AMI_ID";
            string instanceType = "INSTANCE_TYPE";

            AmazonAutoScalingClient autoScaleClient = new AmazonAutoScalingClient(accessKey, secretKey, RegionEndpoint.USWest2);

            AmazonSQSClient sqsClient = new AmazonSQSClient(accessKey, secretKey, RegionEndpoint.USWest2);

            Console.WriteLine("¡¡¡CONFIGURATION INITIALIZED!!!");
            Console.WriteLine("");

            Console.WriteLine("--------- SQS ---------");
            Console.WriteLine("");

            Console.WriteLine("Creating the simple queue service item");
            Console.WriteLine("");

            //Get or create the sqs instance
            CreateQueueRequest  createQueueRequest  = new CreateQueueRequest(queueName);
            CreateQueueResponse createQueueResponse = sqsClient.CreateQueue(createQueueRequest);

            queueURL = createQueueResponse.QueueUrl;

            Console.WriteLine("Created the simple queue service item with name: " + queueName + " and  url: " + queueURL);
            Console.WriteLine("");

            Console.WriteLine("--------- EC2 ---------");
            Console.WriteLine("");

            //If not exists any launch configuration with this name, creates
            DescribeLaunchConfigurationsRequest describeLaunchConfigurationsRequest = new DescribeLaunchConfigurationsRequest();

            describeLaunchConfigurationsRequest.LaunchConfigurationNames = new List <string>()
            {
                launchConfigurationName
            };
            DescribeLaunchConfigurationsResponse describeLaunchConfigurationsResponse = autoScaleClient.DescribeLaunchConfigurations(describeLaunchConfigurationsRequest);

            Console.WriteLine("Creating the launch configuration");
            Console.WriteLine("");
            if (describeLaunchConfigurationsResponse.LaunchConfigurations.Count == 0)
            {
                //Create Launch Configuration Request
                CreateLaunchConfigurationRequest launchConfigurationRequest = new CreateLaunchConfigurationRequest();
                launchConfigurationRequest.LaunchConfigurationName = launchConfigurationName;
                launchConfigurationRequest.ImageId      = amiID;
                launchConfigurationRequest.InstanceType = instanceType;

                //Create Launch Configuration Response
                CreateLaunchConfigurationResponse launchConfigurationResponse = autoScaleClient.CreateLaunchConfiguration(launchConfigurationRequest);

                Console.WriteLine("Created the launch configuration with name: " + launchConfigurationName);
                Console.WriteLine("");
            }
            else
            {
                Console.WriteLine("Founded the launch configuration with name: " + launchConfigurationName);
                Console.WriteLine("");
            }

            Console.WriteLine("Creating the autoscaling group");
            Console.WriteLine("");


            DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest = new DescribeAutoScalingGroupsRequest();

            describeAutoScalingGroupsRequest.AutoScalingGroupNames = new List <string>()
            {
                autoScalingGroupName
            };
            DescribeAutoScalingGroupsResponse describeAutoScalingGroupsResponse = autoScaleClient.DescribeAutoScalingGroups(describeAutoScalingGroupsRequest);

            if (describeAutoScalingGroupsResponse.AutoScalingGroups.Count == 0)
            {
                //Create Auto Scaling Group Request
                CreateAutoScalingGroupRequest autoScalingGroupRequest = new CreateAutoScalingGroupRequest();
                autoScalingGroupRequest.AutoScalingGroupName = autoScalingGroupName;
                autoScalingGroupRequest.MinSize           = 1;
                autoScalingGroupRequest.MaxSize           = 3;
                autoScalingGroupRequest.DesiredCapacity   = 1;
                autoScalingGroupRequest.AvailabilityZones = new List <string>()
                {
                    "us-west-2a", "us-west-2b", "us-west-2c"
                };
                autoScalingGroupRequest.LaunchConfigurationName = launchConfigurationName;

                //Create Auto Scaling Group Response
                autoScaleClient.CreateAutoScalingGroup(autoScalingGroupRequest);

                Console.WriteLine("Created the autoscaling group with name: " + autoScalingGroupName);
                Console.WriteLine("");
            }
            else
            {
                Console.WriteLine("Founded the autoscaling group with name: " + autoScalingGroupName);
                Console.WriteLine("");
            }

            Console.WriteLine("Creating the scale out policy");
            Console.WriteLine("");

            //Policies
            //Creating scaling out policy for the SQS
            PutScalingPolicyRequest scalingOutPolicyRequest = new PutScalingPolicyRequest();

            scalingOutPolicyRequest.PolicyName           = scaleOutPolicyName;
            scalingOutPolicyRequest.AutoScalingGroupName = autoScalingGroupName;
            scalingOutPolicyRequest.ScalingAdjustment    = -1;
            scalingOutPolicyRequest.AdjustmentType       = "ChangeInCapacity";

            PutScalingPolicyResponse scalingOutPolicyResponse = autoScaleClient.PutScalingPolicy(scalingOutPolicyRequest);

            scaleOutARN = scalingOutPolicyResponse.PolicyARN;

            Console.WriteLine("Created the scale out policy with arn: " + scaleOutARN);
            Console.WriteLine("");

            Console.WriteLine("Creating the scale in policy");
            Console.WriteLine("");

            //Creating scaling in policy for the SQS
            PutScalingPolicyRequest scalingInPolicyRequest = new PutScalingPolicyRequest();

            scalingInPolicyRequest.PolicyName           = scaleInPolicyName;
            scalingInPolicyRequest.AutoScalingGroupName = autoScalingGroupName;
            scalingInPolicyRequest.ScalingAdjustment    = 1;
            scalingInPolicyRequest.AdjustmentType       = "ChangeInCapacity";

            PutScalingPolicyResponse scalingInPolicyResponse = autoScaleClient.PutScalingPolicy(scalingInPolicyRequest);

            scaleInARN = scalingInPolicyResponse.PolicyARN;

            Console.WriteLine("Created the scale in policy with arn: " + scaleInARN);
            Console.WriteLine("");

            AmazonCloudWatchClient cloudWatchClient = new AmazonCloudWatchClient(accessKey, secretKey, RegionEndpoint.USWest2);

            Console.WriteLine("--------- CLOUD WATCH ---------");
            Console.WriteLine("");

            Console.WriteLine("Creating the scale in policy");
            Console.WriteLine("");

            //Scale In
            PutMetricAlarmRequest metricAlarmScaleInRequest = new PutMetricAlarmRequest();

            metricAlarmScaleInRequest.AlarmName          = "ScheduledServicesScaleInMetric";
            metricAlarmScaleInRequest.MetricName         = "ApproximateNumberOfMessagesVisible";
            metricAlarmScaleInRequest.Namespace          = "AWS/SQS";
            metricAlarmScaleInRequest.Period             = 300;
            metricAlarmScaleInRequest.Threshold          = 3;
            metricAlarmScaleInRequest.ComparisonOperator = ComparisonOperator.GreaterThanOrEqualToThreshold;
            metricAlarmScaleInRequest.Statistic          = new Statistic("Average");

            Dimension dimensionScaleIn = new Dimension();

            dimensionScaleIn.Name  = "QueueName";
            dimensionScaleIn.Value = queueName;

            metricAlarmScaleInRequest.Dimensions.Add(dimensionScaleIn);
            metricAlarmScaleInRequest.EvaluationPeriods = 2;
            metricAlarmScaleInRequest.AlarmActions.Add(scaleInARN);

            cloudWatchClient.PutMetricAlarm(metricAlarmScaleInRequest);

            Console.WriteLine("Created the scale in policy with name: ScheduledServicesScaleInMetric");
            Console.WriteLine("");

            Console.WriteLine("Creating the scale out policy");
            Console.WriteLine("");

            //Scale Out
            PutMetricAlarmRequest metricAlarmScaleOutRequest = new PutMetricAlarmRequest();

            metricAlarmScaleOutRequest.AlarmName          = "ScheduledServicesScaleOutMetric";
            metricAlarmScaleOutRequest.MetricName         = "ApproximateNumberOfMessagesVisible";
            metricAlarmScaleOutRequest.Namespace          = "AWS/SQS";
            metricAlarmScaleOutRequest.Period             = 300;
            metricAlarmScaleOutRequest.Threshold          = 3;
            metricAlarmScaleOutRequest.ComparisonOperator = ComparisonOperator.LessThanThreshold;
            metricAlarmScaleOutRequest.Statistic          = new Statistic("Average");

            Dimension dimensionScaleOut = new Dimension();

            dimensionScaleOut.Name  = "QueueName";
            dimensionScaleOut.Value = queueName;

            metricAlarmScaleOutRequest.Dimensions.Add(dimensionScaleOut);
            metricAlarmScaleOutRequest.EvaluationPeriods = 2;
            metricAlarmScaleOutRequest.AlarmActions.Add(scaleOutARN);

            cloudWatchClient.PutMetricAlarm(metricAlarmScaleOutRequest);

            Console.WriteLine("Created the scale out policy with name: ScheduledServicesScaleOutMetric");
            Console.WriteLine("");

            Console.WriteLine("¡¡¡CONFIGURATION FINISHED!!!");
        }