Search in sources :

Example 1 with ResourceRecord

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

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

the class Route53Setup method buildChangesList.

List<Change> buildChangesList(List<String> prefixes) {
    List<Change> changes = new ArrayList<Change>();
    for (String prefix : prefixes) {
        String rName = config.getEnvironmentSubdomainCNAME(prefix);
        String rValue = config.getEnvironmentCNAMEPrefix(prefix) + ".us-east-1.elasticbeanstalk.com";
        ResourceRecordSet rrs = getResourceRecordSetForRecordName(rName);
        if (rrs == null) {
            ResourceRecord rr = new ResourceRecord().withValue(rValue);
            rrs = new ResourceRecordSet().withType(RRType.CNAME).withName(rName).withTTL(300L).withResourceRecords(rr);
            Change change = new Change().withAction(ChangeAction.CREATE).withResourceRecordSet(rrs);
            changes.add(change);
        }
    }
    return changes;
}
Also used : ResourceRecordSet(com.amazonaws.services.route53.model.ResourceRecordSet) ArrayList(java.util.ArrayList) Change(com.amazonaws.services.route53.model.Change) ResourceRecord(com.amazonaws.services.route53.model.ResourceRecord)

Example 3 with ResourceRecord

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

Example 4 with ResourceRecord

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

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

the class TestHelper method createListExpectedListResourceRecordSetsRequestNoneFound.

public static Map<ListResourceRecordSetsRequest, ListResourceRecordSetsResult> createListExpectedListResourceRecordSetsRequestNoneFound(String stack) {
    Map<ListResourceRecordSetsRequest, ListResourceRecordSetsResult> m = new HashMap<ListResourceRecordSetsRequest, ListResourceRecordSetsResult>();
    // For Auth and Portal, simulate 'not last' situation i.e. the next record is returned
    List<String> svcPrefixes = Arrays.asList(Constants.PREFIX_PORTAL);
    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") + "2.elasticbeanstalk.com");
        ListResourceRecordSetsResult res = new ListResourceRecordSetsResult().withResourceRecordSets(new ResourceRecordSet().withName(map.get(svcPrefix + ".service.environment.subdomain.cname") + "2").withTTL(300L).withType(RRType.CNAME).withResourceRecords(rr));
        m.put(req, res);
    }
    // For Repo and Workers, simulate 'last' situation i.e. no record is returned
    svcPrefixes = Arrays.asList(Constants.PREFIX_REPO, Constants.PREFIX_WORKERS);
    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 = null;
        ListResourceRecordSetsResult res = new ListResourceRecordSetsResult().withResourceRecordSets(new ArrayList<ResourceRecordSet>());
        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

ResourceRecord (com.amazonaws.services.route53.model.ResourceRecord)4 ResourceRecordSet (com.amazonaws.services.route53.model.ResourceRecordSet)4 Change (com.amazonaws.services.route53.model.Change)2 ListResourceRecordSetsRequest (com.amazonaws.services.route53.model.ListResourceRecordSetsRequest)2 ListResourceRecordSetsResult (com.amazonaws.services.route53.model.ListResourceRecordSetsResult)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AmazonRoute53Client (com.amazonaws.services.route53.AmazonRoute53Client)1 ChangeBatch (com.amazonaws.services.route53.model.ChangeBatch)1 ChangeResourceRecordSetsRequest (com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest)1 ChangeResourceRecordSetsResult (com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult)1 NotFoundException (com.netflix.simianarmy.NotFoundException)1