Search in sources :

Example 1 with ListResourceRecordSetsRequest

use of com.amazonaws.services.route53.model.ListResourceRecordSetsRequest in project SimianArmy by Netflix.

the class AWSClient method deleteDNSRecord.

/** {@inheritDoc} */
@Override
public void deleteDNSRecord(String dnsName, String dnsType, String hostedZoneID) {
    Validate.notEmpty(dnsName);
    Validate.notEmpty(dnsType);
    if (dnsType.equals("A") || dnsType.equals("AAAA") || dnsType.equals("CNAME")) {
        LOGGER.info(String.format("Deleting DNS Route 53 record %s", dnsName));
        AmazonRoute53Client route53Client = route53Client();
        // AWS API requires us to query for the record first
        ListResourceRecordSetsRequest listRequest = new ListResourceRecordSetsRequest(hostedZoneID);
        listRequest.setMaxItems("1");
        listRequest.setStartRecordType(dnsType);
        listRequest.setStartRecordName(dnsName);
        ListResourceRecordSetsResult listResult = route53Client.listResourceRecordSets(listRequest);
        if (listResult.getResourceRecordSets().size() < 1) {
            throw new NotFoundException("Could not find Route53 record for " + dnsName + " (" + dnsType + ") in zone " + hostedZoneID);
        } else {
            ResourceRecordSet resourceRecord = listResult.getResourceRecordSets().get(0);
            ArrayList<Change> changeList = new ArrayList<>();
            Change recordChange = new Change(ChangeAction.DELETE, resourceRecord);
            changeList.add(recordChange);
            ChangeBatch recordChangeBatch = new ChangeBatch(changeList);
            ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest(hostedZoneID, recordChangeBatch);
            ChangeResourceRecordSetsResult result = route53Client.changeResourceRecordSets(request);
        }
    } else {
        LOGGER.error("dnsType must be one of 'A', 'AAAA', or 'CNAME'");
    }
}
Also used : NotFoundException(com.netflix.simianarmy.NotFoundException) AmazonRoute53Client(com.amazonaws.services.route53.AmazonRoute53Client)

Example 2 with ListResourceRecordSetsRequest

use of com.amazonaws.services.route53.model.ListResourceRecordSetsRequest in project GNS by MobilityFirst.

the class Route53 method listRecordSetsForHostedZone.

//  private void test() {
//    route53.createHostedZone(new CreateHostedZoneRequest()
//            .withName("myDomainName.com")
//            .withCallerReference(CALLER_REFERENCE)
//            .withHostedZoneConfig(new HostedZoneConfig()
//            .withComment("my first Route 53 hosted zone!")));
//  }
private static void listRecordSetsForHostedZone() {
    ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest();
    request.setHostedZoneId(HOSTED_ZONE_ID);
    ListResourceRecordSetsResult result = route53.listResourceRecordSets(request);
    List<ResourceRecordSet> recordSets = result.getResourceRecordSets();
    for (ResourceRecordSet recordSet : recordSets) {
        System.out.println(recordSet.toString());
    }
}
Also used : ResourceRecordSet(com.amazonaws.services.route53.model.ResourceRecordSet) ListResourceRecordSetsRequest(com.amazonaws.services.route53.model.ListResourceRecordSetsRequest) ListResourceRecordSetsResult(com.amazonaws.services.route53.model.ListResourceRecordSetsResult)

Example 3 with ListResourceRecordSetsRequest

use of com.amazonaws.services.route53.model.ListResourceRecordSetsRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class Route53Setup method getResourceRecordSetForRecordName.

// TODO:	See if this could be done with a single call to listResourceRecordSets() to return all the CNAMEs,
// pass in a list of recordNames and getting back a list of ResourceRecordSets
ResourceRecordSet getResourceRecordSetForRecordName(String recordName) {
    ListResourceRecordSetsRequest req = new ListResourceRecordSetsRequest();
    req.setHostedZoneId(hostedZone.getId());
    req.setStartRecordType(RRType.CNAME);
    req.setStartRecordName(recordName);
    req.setMaxItems("1");
    ListResourceRecordSetsResult res = route53Client.listResourceRecordSets(req);
    ResourceRecordSet rrs = null;
    if ((res.getResourceRecordSets().size() > 0) && (recordName.equals(res.getResourceRecordSets().get(0).getName()))) {
        rrs = res.getResourceRecordSets().get(0);
    }
    return rrs;
}
Also used : ResourceRecordSet(com.amazonaws.services.route53.model.ResourceRecordSet) ListResourceRecordSetsRequest(com.amazonaws.services.route53.model.ListResourceRecordSetsRequest) ListResourceRecordSetsResult(com.amazonaws.services.route53.model.ListResourceRecordSetsResult)

Example 4 with ListResourceRecordSetsRequest

use of com.amazonaws.services.route53.model.ListResourceRecordSetsRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class Route53SetupTest method testGetResourceRecordSetForRecordNameAllFound.

@Test
public void testGetResourceRecordSetForRecordNameAllFound() {
    String stack = "stack";
    String hostedZoneDomainName = stack + ".sagebase.org.";
    ListHostedZonesResult res = new ListHostedZonesResult();
    List<HostedZone> expectedHostedZones = new ArrayList<HostedZone>();
    HostedZone hz = new HostedZone().withName(hostedZoneDomainName);
    expectedHostedZones.add(hz);
    hz = new HostedZone().withName("anotherzone.sagebase.org");
    expectedHostedZones.add(hz);
    res.setHostedZones(expectedHostedZones);
    Map<ListResourceRecordSetsRequest, ListResourceRecordSetsResult> expectedResourceRecordSetsResults = TestHelper.createListExpectedListResourceRecordSetsRequestAllFound(stack);
    when(mockClient.listHostedZones()).thenReturn(res);
    // Args for getResourceRecordSetForRecordName().listResourceRecordSets()
    for (ListResourceRecordSetsRequest req : expectedResourceRecordSetsResults.keySet()) {
        when(mockClient.listResourceRecordSets(req)).thenReturn(expectedResourceRecordSetsResults.get(req));
    }
    Route53Setup r53Setup = new Route53Setup(factory, config, resources);
    for (String svcPrefix : Arrays.asList(Constants.PREFIX_PORTAL, Constants.PREFIX_REPO, Constants.PREFIX_WORKERS)) {
        ResourceRecordSet rrs = r53Setup.getResourceRecordSetForRecordName(svcPrefix + ".stack.inst.r53.sagebase.org");
        assertFalse(rrs == null);
        assertEquals(rrs.getName(), svcPrefix + ".stack.inst.r53.sagebase.org");
        assertEquals(rrs.getResourceRecords().get(0).getValue(), svcPrefix + "-stack-inst-sagebase-org.elasticbeanstalk.com");
    }
}
Also used : HostedZone(com.amazonaws.services.route53.model.HostedZone) ResourceRecordSet(com.amazonaws.services.route53.model.ResourceRecordSet) ListResourceRecordSetsRequest(com.amazonaws.services.route53.model.ListResourceRecordSetsRequest) ArrayList(java.util.ArrayList) ListHostedZonesResult(com.amazonaws.services.route53.model.ListHostedZonesResult) ListResourceRecordSetsResult(com.amazonaws.services.route53.model.ListResourceRecordSetsResult) Test(org.junit.Test)

Example 5 with ListResourceRecordSetsRequest

use of com.amazonaws.services.route53.model.ListResourceRecordSetsRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class TestHelper method createListExpectedListResourceRecordSetsRequestAllFound.

public static Map<ListResourceRecordSetsRequest, ListResourceRecordSetsResult> createListExpectedListResourceRecordSetsRequestAllFound(String stack) {
    Map<ListResourceRecordSetsRequest, ListResourceRecordSetsResult> m = new HashMap<ListResourceRecordSetsRequest, ListResourceRecordSetsResult>();
    List<String> svcPrefixes = Arrays.asList(Constants.PREFIX_PORTAL, Constants.PREFIX_REPO, Constants.PREFIX_WORKERS);
    Map<String, String> map = getSvcCNAMEsProps(stack, svcPrefixes);
    for (String svcPrefix : svcPrefixes) {
        ListResourceRecordSetsRequest req = new ListResourceRecordSetsRequest().withStartRecordType(RRType.CNAME).withStartRecordName(map.get(svcPrefix + ".service.environment.subdomain.cname")).withMaxItems("1");
        ResourceRecord rr = new ResourceRecord().withValue(map.get(svcPrefix + ".service.environment.cname.prefix") + ".elasticbeanstalk.com");
        ListResourceRecordSetsResult res = new ListResourceRecordSetsResult().withResourceRecordSets(new ResourceRecordSet().withName(map.get(svcPrefix + ".service.environment.subdomain.cname")).withTTL(300L).withType(RRType.CNAME).withResourceRecords(rr));
        m.put(req, res);
    }
    return m;
}
Also used : ResourceRecordSet(com.amazonaws.services.route53.model.ResourceRecordSet) ListResourceRecordSetsRequest(com.amazonaws.services.route53.model.ListResourceRecordSetsRequest) HashMap(java.util.HashMap) ResourceRecord(com.amazonaws.services.route53.model.ResourceRecord) ListResourceRecordSetsResult(com.amazonaws.services.route53.model.ListResourceRecordSetsResult)

Aggregations

ListResourceRecordSetsRequest (com.amazonaws.services.route53.model.ListResourceRecordSetsRequest)8 ListResourceRecordSetsResult (com.amazonaws.services.route53.model.ListResourceRecordSetsResult)8 ResourceRecordSet (com.amazonaws.services.route53.model.ResourceRecordSet)6 ListHostedZonesResult (com.amazonaws.services.route53.model.ListHostedZonesResult)4 Test (org.junit.Test)4 HostedZone (com.amazonaws.services.route53.model.HostedZone)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ResourceRecord (com.amazonaws.services.route53.model.ResourceRecord)2 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)1 ListMetricsRequest (com.amazonaws.services.cloudwatch.model.ListMetricsRequest)1 ListMetricsResult (com.amazonaws.services.cloudwatch.model.ListMetricsResult)1 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)1 PutMetricDataResult (com.amazonaws.services.cloudwatch.model.PutMetricDataResult)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)1 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)1 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1