/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { UpdateAutoScalingGroupResponse response = new UpdateAutoScalingGroupResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.IsStartElement) { if (context.TestExpression("UpdateAutoScalingGroupResult", 2)) { UnmarshallResult(context, response); continue; } if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context); } } } return(response); }
/// <summary> /// <para> Updates the configuration for the specified AutoScalingGroup. </para> <para><b>NOTE:</b> To update an Auto Scaling group with a /// launch configuration that has the InstanceMonitoring.enabled flag set to false, you must first ensure that collection of group metrics is /// disabled. Otherwise, calls to UpdateAutoScalingGroup will fail. If you have previously enabled group metrics collection, you can disable /// collection of all group metrics by calling DisableMetricsCollection. </para> <para> The new settings are registered upon the completion of /// this call. Any launch configuration settings take effect on any triggers after this call returns. Triggers that are currently in progress /// aren't affected. </para> <para><b>NOTE:</b> If the new values are specified for the MinSize or MaxSize parameters, then there will be an /// implicit call to SetDesiredCapacity to set the group to the new MaxSize. All optional parameters are left unchanged if not passed in the /// request. </para> /// </summary> /// /// <param name="updateAutoScalingGroupRequest">Container for the necessary parameters to execute the UpdateAutoScalingGroup service method on /// AmazonAutoScaling.</param> /// /// <exception cref="ScalingActivityInProgressException"/> public UpdateAutoScalingGroupResponse UpdateAutoScalingGroup(UpdateAutoScalingGroupRequest updateAutoScalingGroupRequest) { IRequest <UpdateAutoScalingGroupRequest> request = new UpdateAutoScalingGroupRequestMarshaller().Marshall(updateAutoScalingGroupRequest); UpdateAutoScalingGroupResponse response = Invoke <UpdateAutoScalingGroupRequest, UpdateAutoScalingGroupResponse> (request, this.signer, UpdateAutoScalingGroupResponseUnmarshaller.GetInstance()); return(response); }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { UpdateAutoScalingGroupResponse response = new UpdateAutoScalingGroupResponse(); while (context.Read()) { if (context.IsStartElement) { if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context); } } } return(response); }
private static void UnmarshallResult(XmlUnmarshallerContext context, UpdateAutoScalingGroupResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { } } return; }
public virtual void failover() { try { // Modify the autoscaling group to remove the AZ affected which is the AZ passed in the input // Find the autoscaling group that this is deployed into // Note: This changes the asynchronous call to a synchronous one DescribeAutoScalingGroupsResponse autoScalingGroupsResponse = AUTO_SCALING_CLIENT.DescribeAutoScalingGroupsAsync().GetAwaiter().GetResult(); if (autoScalingGroupsResponse != null && autoScalingGroupsResponse.AutoScalingGroups.Count > 0) { // Note: This assumes an Auto Scaling group exists; no error checking for readability AutoScalingGroup autoScalingGroup = autoScalingGroupsResponse.AutoScalingGroups[0]; string autoScalingGroupName = autoScalingGroup.AutoScalingGroupName; // Find all subnets in the availability zone passed in the input DescribeSubnetsResponse subnetsResult = EC2_CLIENT.DescribeSubnetsAsync(new DescribeSubnetsRequest() { Filters = new List <Amazon.EC2.Model.Filter> { new Amazon.EC2.Model.Filter { Name = "vpc-id", Values = new List <string> { vpcId } } } }).GetAwaiter().GetResult(); IList <string> desiredSubnetsForASG = new List <string>(); foreach (Amazon.EC2.Model.Subnet subnet in subnetsResult.Subnets) { if (!string.Equals(subnet.AvailabilityZone, azId, StringComparison.OrdinalIgnoreCase)) { desiredSubnetsForASG.Add(subnet.SubnetId); } } List <string> desiredSubnets = new List <String>(autoScalingGroup.VPCZoneIdentifier.Split(new[] { ',' }, StringSplitOptions.None)); var tempList = new List <String>(desiredSubnets); foreach (var subnet in desiredSubnets) { if (!desiredSubnetsForASG.Contains(subnet)) { tempList.Remove(subnet); } } desiredSubnets = tempList; Console.WriteLine("Updating the auto scaling group " + autoScalingGroupName + " to remove the subnet in the AZ"); // Note: This turns the asynchronous call into a synchronous one UpdateAutoScalingGroupResponse updateAutoScalingGroupResponse = AUTO_SCALING_CLIENT.UpdateAutoScalingGroupAsync(new UpdateAutoScalingGroupRequest { AutoScalingGroupName = autoScalingGroupName, VPCZoneIdentifier = string.Join(",", desiredSubnets) }).GetAwaiter().GetResult(); } // Find all subnets in the availability zone passed in the input // Note: This turns the asynchronous call into a synchronous one DescribeSubnetsResponse describeSubnetsResult = EC2_CLIENT.DescribeSubnetsAsync(new DescribeSubnetsRequest { Filters = new List <Amazon.EC2.Model.Filter> { new Amazon.EC2.Model.Filter { Name = "vpc-id", Values = new List <string> { vpcId } }, new Amazon.EC2.Model.Filter { Name = "availabilityZone", Values = new List <string> { azId } } } }).GetAwaiter().GetResult(); IList <string> desiredSubnetsForAddingNewNacl = new List <string>(); foreach (Amazon.EC2.Model.Subnet subnet in describeSubnetsResult.Subnets) { desiredSubnetsForAddingNewNacl.Add(subnet.SubnetId); } //Find all the network acl associations matching the subnets identified above // Note: This turns the asynchronous call into a synchronous one DescribeNetworkAclsResponse describeNetworkAclsResult = EC2_CLIENT.DescribeNetworkAclsAsync(new DescribeNetworkAclsRequest() { Filters = new List <Amazon.EC2.Model.Filter> { new Amazon.EC2.Model.Filter { Name = "association.subnet-id", Values = (List <string>)desiredSubnetsForAddingNewNacl } } }).GetAwaiter().GetResult(); IList <NetworkAclAssociation> desiredAclAssociations = new List <NetworkAclAssociation>(); // Note: This assumes a Network ACL is present for readability IList <NetworkAclAssociation> networkAclsAssociatedWithSubnet = describeNetworkAclsResult.NetworkAcls[0].Associations; foreach (string subnetId in desiredSubnetsForAddingNewNacl) { foreach (NetworkAclAssociation networkAcl in networkAclsAssociatedWithSubnet) { if (string.Equals(networkAcl.SubnetId, subnetId, StringComparison.OrdinalIgnoreCase)) { desiredAclAssociations.Add(networkAcl); } } } //create new network acl association with both ingress and egress denying to all the traffic CreateNetworkAclRequest createNetworkAclRequest = new CreateNetworkAclRequest(); createNetworkAclRequest.VpcId = vpcId; // Note: This turns the asynchronous call into a synchronous one CreateNetworkAclResponse createNetworkAclResponse = EC2_CLIENT.CreateNetworkAclAsync(createNetworkAclRequest).GetAwaiter().GetResult(); string networkAclId = createNetworkAclResponse.NetworkAcl.NetworkAclId; createNetworkAclEntry(networkAclId, 100, "0.0.0.0/0", true, "-1", createPortRange(0, 65535), RuleAction.Deny); createNetworkAclEntry(networkAclId, 101, "0.0.0.0/0", false, "-1", createPortRange(0, 65535), RuleAction.Deny); // replace all the network acl associations identified for the above subnets with the new network // acl association which will deny all traffic for those subnets in that AZ Console.WriteLine("Creating new network ACL associations"); replaceNetworkAclAssociations(desiredAclAssociations, networkAclId); //fail over rds which is in the same AZ // Note: This turns the asynchronous call into a synchronous one DescribeDBInstancesResponse describeDBInstancesResult = RDS_CLIENT.DescribeDBInstancesAsync().GetAwaiter().GetResult(); IList <DBInstance> dbInstances = describeDBInstancesResult.DBInstances; string dbInstancedId = null; foreach (DBInstance dbInstance in dbInstances) { if (string.Equals(dbInstance.DBSubnetGroup.VpcId, vpcId, StringComparison.OrdinalIgnoreCase) && (string.Equals(dbInstance.AvailabilityZone, azId, StringComparison.OrdinalIgnoreCase)) && dbInstance.MultiAZ && dbInstance.StatusInfos.Count == 0) { dbInstancedId = dbInstance.DBInstanceIdentifier; } } // we want to fail over rds if rds is present in the same az where it is affected if (!string.IsNullOrEmpty(dbInstancedId)) { RebootDBInstanceRequest rebootDBInstanceRequest = new RebootDBInstanceRequest(); rebootDBInstanceRequest.DBInstanceIdentifier = dbInstancedId; rebootDBInstanceRequest.ForceFailover = true; Console.WriteLine("Rebooting dbInstanceId to secondary AZ " + dbInstancedId); // Note: This turns the asynchronous call into a synchronous one RDS_CLIENT.RebootDBInstanceAsync(rebootDBInstanceRequest).GetAwaiter().GetResult(); } } catch (Exception exception) { Console.WriteLine("Unkown exception occured " + exception.Message); } }
public virtual async Task Failover() { try { Console.WriteLine($"Simulating AZ failure for {azName}"); // Find all subnets in the availability zone passed in the input DescribeSubnetsResponse subnetsInSpecifiedAZandVpc = await ec2Client.DescribeSubnetsAsync(new DescribeSubnetsRequest() { Filters = new List <Amazon.EC2.Model.Filter> { new Amazon.EC2.Model.Filter { Name = "vpc-id", Values = { vpcId } }, new Amazon.EC2.Model.Filter { Name = "availability-zone", Values = { azName } } } }); List <string> subnetIdsInSpecifiedAZ = subnetsInSpecifiedAZandVpc.Subnets.Select(x => x.SubnetId).ToList(); // Modify the autoscaling group to remove the AZ affected which is the AZ passed in the input // Find the autoscaling group that this is deployed into DescribeAutoScalingGroupsResponse autoScalingGroupsResponse = await asClient.DescribeAutoScalingGroupsAsync(); if (autoScalingGroupsResponse != null && autoScalingGroupsResponse.AutoScalingGroups.Count > 0) { // Note: This assumes an Auto Scaling group exists; no error checking for readability AutoScalingGroup autoScalingGroup = autoScalingGroupsResponse.AutoScalingGroups[0]; Console.WriteLine($"Updating the auto scaling group {autoScalingGroup.AutoScalingGroupName} to remove the subnet in {azName}"); UpdateAutoScalingGroupResponse updateAutoScalingGroupResponse = await asClient.UpdateAutoScalingGroupAsync(new UpdateAutoScalingGroupRequest { AutoScalingGroupName = autoScalingGroup.AutoScalingGroupName, VPCZoneIdentifier = String.Join(",", autoScalingGroup.VPCZoneIdentifier.Split(',').Where(x => !subnetIdsInSpecifiedAZ.Contains(x))) }); } Console.WriteLine("Creating new network ACL associations"); await BlockSubnetsInAZ(vpcId, subnetIdsInSpecifiedAZ); Console.WriteLine("Failing over database"); //fail over rds which is in the same AZ DescribeDBInstancesResponse describeDBInstancesResult = await rdsClient.DescribeDBInstancesAsync(); string dbInstancedId = describeDBInstancesResult.DBInstances.Where(x => String.Equals(x.DBSubnetGroup.VpcId, vpcId, StringComparison.OrdinalIgnoreCase) && String.Equals(x.AvailabilityZone, azName, StringComparison.OrdinalIgnoreCase) && x.MultiAZ && !x.StatusInfos.Any())?.Select(x => x.DBInstanceIdentifier).FirstOrDefault(); // we want to fail over rds if rds is present in the same az where it is affected if (!String.IsNullOrEmpty(dbInstancedId)) { Console.WriteLine("Rebooting dbInstanceId to secondary AZ " + dbInstancedId); var response = await rdsClient.RebootDBInstanceAsync(new RebootDBInstanceRequest() { DBInstanceIdentifier = dbInstancedId, ForceFailover = true }); } else { Console.WriteLine($"Didn't find DB in the same AZ as {azName}"); } Console.Write("Done"); } catch (Exception exception) { Console.WriteLine("Unknown exception occurred " + exception.Message); } }