예제 #1
0
        internal UpdateHealthCheckResponse UpdateHealthCheck(UpdateHealthCheckRequest request)
        {
            var marshaller   = new UpdateHealthCheckRequestMarshaller();
            var unmarshaller = UpdateHealthCheckResponseUnmarshaller.Instance;

            return(Invoke <UpdateHealthCheckRequest, UpdateHealthCheckResponse>(request, marshaller, unmarshaller));
        }
예제 #2
0
        /// <summary>Snippet for Update</summary>
        public void UpdateRequestObject()
        {
            // Snippet: Update(UpdateHealthCheckRequest, CallSettings)
            // Create client
            HealthChecksClient healthChecksClient = HealthChecksClient.Create();
            // Initialize request argument(s)
            UpdateHealthCheckRequest request = new UpdateHealthCheckRequest
            {
                RequestId           = "",
                HealthCheckResource = new HealthCheck(),
                Project             = "",
                HealthCheck         = "",
            };
            // Make the request
            lro::Operation <Operation, Operation> response = healthChecksClient.Update(request);

            // Poll until the returned long-running operation is complete
            lro::Operation <Operation, Operation> completedResponse = response.PollUntilCompleted();
            // Retrieve the operation result
            Operation result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            lro::Operation <Operation, Operation> retrievedResponse = healthChecksClient.PollOnceUpdate(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Operation retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
예제 #3
0
        /// <summary>
        /// Initiates the asynchronous execution of the UpdateHealthCheck operation.
        /// <seealso cref="Amazon.Route53.IAmazonRoute53"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the UpdateHealthCheck 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 <UpdateHealthCheckResponse> UpdateHealthCheckAsync(UpdateHealthCheckRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new UpdateHealthCheckRequestMarshaller();
            var unmarshaller = UpdateHealthCheckResponseUnmarshaller.Instance;

            return(InvokeAsync <UpdateHealthCheckRequest, UpdateHealthCheckResponse>(request, marshaller,
                                                                                     unmarshaller, cancellationToken));
        }
예제 #4
0
 /// <summary>Snippet for Update</summary>
 public void UpdateRequestObject()
 {
     // Snippet: Update(UpdateHealthCheckRequest, CallSettings)
     // Create client
     HealthChecksClient healthChecksClient = HealthChecksClient.Create();
     // Initialize request argument(s)
     UpdateHealthCheckRequest request = new UpdateHealthCheckRequest
     {
         RequestId           = "",
         HealthCheckResource = new HealthCheck(),
         Project             = "",
         HealthCheck         = "",
     };
     // Make the request
     Operation response = healthChecksClient.Update(request);
     // End snippet
 }
예제 #5
0
        /// <summary>Snippet for UpdateAsync</summary>
        public async Task UpdateRequestObjectAsync()
        {
            // Snippet: UpdateAsync(UpdateHealthCheckRequest, CallSettings)
            // Additional: UpdateAsync(UpdateHealthCheckRequest, CancellationToken)
            // Create client
            HealthChecksClient healthChecksClient = await HealthChecksClient.CreateAsync();

            // Initialize request argument(s)
            UpdateHealthCheckRequest request = new UpdateHealthCheckRequest
            {
                RequestId           = "",
                HealthCheckResource = new HealthCheck(),
                Project             = "",
                HealthCheck         = "",
            };
            // Make the request
            Operation response = await healthChecksClient.UpdateAsync(request);

            // End snippet
        }
예제 #6
0
파일: R53Trigger.cs 프로젝트: zyborg/VMBot
        void CopyOrReset(HealthCheckConfig oldConfig, HealthCheckConfig newConfig, UpdateHealthCheckRequest delta)
        {
            var hcType = typeof(HealthCheckConfig);
            var upType = typeof(UpdateHealthCheckRequest);
            var bFlags = BindingFlags.Public | BindingFlags.Instance;

            foreach (var hcProp in hcType.GetProperties(bFlags))
            {
                var oldValue = hcProp.GetValue(oldConfig);
                var newValue = hcProp.GetValue(newConfig);
                // Cheap way to compare values, even for complex objects
                var oldValueJson = JsonSerializer.Serialize(oldValue);
                var newValueJson = JsonSerializer.Serialize(newValue);
                if (oldValueJson != newValueJson)
                {
                    var upProp = upType.GetProperty(hcProp.Name, bFlags);
                    if (upProp == null)
                    {
                        _logger.LogWarning($"Detected Health Check config change for property [{hcProp.Name}]"
                                           + " but value CANNOT be updated on existing Health Check");
                    }
                    else
                    {
                        if (newValueJson == null && ResettableHealthCheckElements.Contains(hcProp.Name))
                        {
                            if (delta.ResetElements == null)
                            {
                                delta.ResetElements = new List <string>();
                            }
                            delta.ResetElements.Add(hcProp.Name);
                        }
                        else
                        {
                            upProp.SetValue(delta, newValue);
                        }
                    }
                }
            }
        }
예제 #7
0
 public virtual Task <UpdateHealthCheckResponse> UpdateHealthCheckAsync(UpdateHealthCheckRequest request, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
예제 #8
0
 public Task <UpdateHealthCheckResponse> UpdateHealthCheckAsync(
     UpdateHealthCheckRequest request,
     CancellationToken cancellationToken = default(CancellationToken))
 => _locker.Lock(() => _client.UpdateHealthCheckAsync(request, cancellationToken).EnsureSuccessAsync());
예제 #9
0
파일: R53Trigger.cs 프로젝트: zyborg/VMBot
        public async Task HandleInitR53(Instance inst, Dictionary <string, string> tags, string ec2State)
        {
            _logger.LogInformation("Handling CREATING R53 records");

            var r53Spec    = ResolveR53RecordSpec(inst, tags);
            var r53Routing = ResolveR53RoutingSpec(inst, tags);
            var r53Health  = await ResolveR53HealthCheckSpec(inst, tags);

            HealthCheck existingHealth = await FindExistingHealthCheck(r53Health);

            // We apply the Health Check if any, first because
            // the subsequent Route policy may depend on it
            string healthCheckId = null;

            if (r53Health != null)
            {
                if (existingHealth == null)
                {
                    var createRequ = new CreateHealthCheckRequest
                    {
                        CallerReference   = r53Health.RefName,
                        HealthCheckConfig = r53Health.Config,
                    };
                    var createResp = await _r53.CreateHealthCheckAsync(createRequ);

                    _logger.LogInformation("CREATE Health Check request completed, response:");
                    _logger.LogInformation(JsonSerializer.Serialize(createResp));
                    if (createResp.HealthCheck == null)
                    {
                        throw new Exception("failed to create Health Check");
                    }
                    healthCheckId = createResp.HealthCheck.Id;

                    var tagRequ = new ChangeTagsForResourceRequest
                    {
                        ResourceType = TagResourceType.Healthcheck,
                        ResourceId   = healthCheckId,
                        AddTags      = new List <Amazon.Route53.Model.Tag>
                        {
                            new Amazon.Route53.Model.Tag
                            {
                                Key   = "Name",
                                Value = r53Health.RefName,
                            },
                            new Amazon.Route53.Model.Tag
                            {
                                Key   = "vmbot:memo",
                                Value = $"Managed by VMBot {nameof(R53Trigger)}",
                            },
                        },
                    };
                    var tagResp = await _r53.ChangeTagsForResourceAsync(tagRequ);

                    _logger.LogInformation("CHANGED TAGS for Health Check:");
                    _logger.LogInformation(JsonSerializer.Serialize(tagResp));
                }
                else
                {
                    var updateRequ = new UpdateHealthCheckRequest
                    {
                        HealthCheckId      = existingHealth.Id,
                        HealthCheckVersion = existingHealth.HealthCheckVersion,
                    };
                    CopyOrReset(existingHealth.HealthCheckConfig, r53Health.Config, updateRequ);
                    _logger.LogInformation("Resolved Health Check delta:");
                    _logger.LogInformation(JsonSerializer.Serialize(updateRequ));
                    var updateResp = await _r53.UpdateHealthCheckAsync(updateRequ);

                    _logger.LogInformation("UPDATE Health Check request completed, response:");
                    _logger.LogInformation(JsonSerializer.Serialize(updateResp));
                    healthCheckId = updateResp.HealthCheck.Id;
                }
            }

            if (r53Spec != null)
            {
                var rrset = new ResourceRecordSet
                {
                    Name            = r53Spec.Name,
                    Type            = RRType.FindValue(r53Spec.Type),
                    TTL             = r53Spec.TTL,
                    ResourceRecords = new List <ResourceRecord>
                    {
                        new ResourceRecord(r53Spec.Value),
                    },
                };
                if (healthCheckId != null)
                {
                    rrset.HealthCheckId = healthCheckId;
                }

                // Optional routing policy configuration
                r53Routing?.Apply(rrset);

                var changeRequ = new ChangeResourceRecordSetsRequest
                {
                    HostedZoneId = r53Spec.Zone,
                    ChangeBatch  = new ChangeBatch
                    {
                        Changes = new List <Change>
                        {
                            new Change
                            {
                                Action            = ChangeAction.UPSERT,
                                ResourceRecordSet = rrset,
                            }
                        },
                        Comment = "change request applied by VMBot",
                    }
                };

                var changeResp = await _r53.ChangeResourceRecordSetsAsync(changeRequ);

                _logger.LogInformation("UPSERT Resource Record request completed, response:");
                _logger.LogInformation(JsonSerializer.Serialize(changeResp));
            }
        }