Search in sources :

Example 1 with ChangeResourceRecordSetsResult

use of com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult 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 ChangeResourceRecordSetsResult

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

the class Route53 method createRecordSetFromHostedZone.

private static void createRecordSetFromHostedZone() {
    List<ResourceRecord> records = new ArrayList<>();
    ResourceRecord record = new ResourceRecord();
    record.setValue("http://www.marksdevserver.com");
    records.add(record);
    ResourceRecordSet recordSet = new ResourceRecordSet();
    recordSet.setName("markstest.domain.com.");
    recordSet.setType(RRType.CNAME);
    recordSet.setTTL(new Long(60));
    recordSet.setResourceRecords(records);
    // Create the Change
    List<Change> changes = new ArrayList<>();
    Change change = new Change();
    change.setAction(ChangeAction.CREATE);
    change.setResourceRecordSet(recordSet);
    changes.add(change);
    // Create a batch and add the change to it
    ChangeBatch batch = new ChangeBatch();
    batch.setChanges(changes);
    // Create a Request and add the batch to it.
    ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest();
    request.setHostedZoneId(HOSTED_ZONE_ID);
    request.setChangeBatch(batch);
    // send the request
    ChangeResourceRecordSetsResult result = route53.changeResourceRecordSets(request);
    System.out.println(result.toString());
}
Also used : ResourceRecordSet(com.amazonaws.services.route53.model.ResourceRecordSet) ChangeBatch(com.amazonaws.services.route53.model.ChangeBatch) ArrayList(java.util.ArrayList) Change(com.amazonaws.services.route53.model.Change) ResourceRecord(com.amazonaws.services.route53.model.ResourceRecord) ChangeResourceRecordSetsRequest(com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest) ChangeResourceRecordSetsResult(com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult)

Example 3 with ChangeResourceRecordSetsResult

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

the class Route53Setup method setupResources.

public void setupResources() throws InterruptedException {
    List<Change> changes = buildChangesList(Constants.ROUTE53_PREFIXES);
    if (changes.size() > 0) {
        ChangeBatch changeBatch = new ChangeBatch().withChanges(changes);
        ChangeResourceRecordSetsRequest cReq = new ChangeResourceRecordSetsRequest().withHostedZoneId(hostedZone.getId()).withChangeBatch(changeBatch);
        ChangeResourceRecordSetsResult cRes = route53Client.changeResourceRecordSets(cReq);
        GetChangeRequest gcReq = new GetChangeRequest(cRes.getChangeInfo().getId());
        GetChangeResult gcRes = route53Client.getChange(gcReq);
        // TODO: No real need to wait here, could just exit
        while (!"INSYNC".equals(gcRes.getChangeInfo().getStatus())) {
            Thread.sleep(1000L);
            gcRes = route53Client.getChange(gcReq);
            String s = gcRes.getChangeInfo().getStatus();
        }
    }
}
Also used : ChangeBatch(com.amazonaws.services.route53.model.ChangeBatch) Change(com.amazonaws.services.route53.model.Change) ChangeResourceRecordSetsRequest(com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest) ChangeResourceRecordSetsResult(com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult) GetChangeRequest(com.amazonaws.services.route53.model.GetChangeRequest) GetChangeResult(com.amazonaws.services.route53.model.GetChangeResult)

Example 4 with ChangeResourceRecordSetsResult

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

the class Route53SetupTest method testSetupResourcesAllFound.

@Ignore
@Test
public void testSetupResourcesAllFound() throws Exception {
    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));
    }
    ChangeInfo expectedChangeInfo = new ChangeInfo().withId("changeInfoId").withStatus(ChangeStatus.INSYNC);
    ChangeResourceRecordSetsResult expectedChangeResourceRecordSetsResult = new ChangeResourceRecordSetsResult().withChangeInfo(expectedChangeInfo);
    when(mockClient.changeResourceRecordSets(any(ChangeResourceRecordSetsRequest.class))).thenReturn(expectedChangeResourceRecordSetsResult);
    Route53Setup r53Setup = new Route53Setup(factory, config, resources);
}
Also used : HostedZone(com.amazonaws.services.route53.model.HostedZone) ListResourceRecordSetsRequest(com.amazonaws.services.route53.model.ListResourceRecordSetsRequest) ChangeInfo(com.amazonaws.services.route53.model.ChangeInfo) ArrayList(java.util.ArrayList) ListHostedZonesResult(com.amazonaws.services.route53.model.ListHostedZonesResult) ChangeResourceRecordSetsResult(com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult) ChangeResourceRecordSetsRequest(com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest) ListResourceRecordSetsResult(com.amazonaws.services.route53.model.ListResourceRecordSetsResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ChangeResourceRecordSetsRequest (com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest)3 ChangeResourceRecordSetsResult (com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult)3 Change (com.amazonaws.services.route53.model.Change)2 ChangeBatch (com.amazonaws.services.route53.model.ChangeBatch)2 ArrayList (java.util.ArrayList)2 AmazonRoute53Client (com.amazonaws.services.route53.AmazonRoute53Client)1 ChangeInfo (com.amazonaws.services.route53.model.ChangeInfo)1 GetChangeRequest (com.amazonaws.services.route53.model.GetChangeRequest)1 GetChangeResult (com.amazonaws.services.route53.model.GetChangeResult)1 HostedZone (com.amazonaws.services.route53.model.HostedZone)1 ListHostedZonesResult (com.amazonaws.services.route53.model.ListHostedZonesResult)1 ListResourceRecordSetsRequest (com.amazonaws.services.route53.model.ListResourceRecordSetsRequest)1 ListResourceRecordSetsResult (com.amazonaws.services.route53.model.ListResourceRecordSetsResult)1 ResourceRecord (com.amazonaws.services.route53.model.ResourceRecord)1 ResourceRecordSet (com.amazonaws.services.route53.model.ResourceRecordSet)1 NotFoundException (com.netflix.simianarmy.NotFoundException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1