Search in sources :

Example 1 with ResourceRecordSet

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

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

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

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

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

Aggregations

ResourceRecordSet (com.amazonaws.services.route53.model.ResourceRecordSet)8 ListResourceRecordSetsRequest (com.amazonaws.services.route53.model.ListResourceRecordSetsRequest)6 ListResourceRecordSetsResult (com.amazonaws.services.route53.model.ListResourceRecordSetsResult)6 ResourceRecord (com.amazonaws.services.route53.model.ResourceRecord)4 ArrayList (java.util.ArrayList)4 Change (com.amazonaws.services.route53.model.Change)2 HostedZone (com.amazonaws.services.route53.model.HostedZone)2 ListHostedZonesResult (com.amazonaws.services.route53.model.ListHostedZonesResult)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)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 ListResourceRecordSetsRequest (software.amazon.awssdk.services.route53.model.ListResourceRecordSetsRequest)1 ListResourceRecordSetsResponse (software.amazon.awssdk.services.route53.model.ListResourceRecordSetsResponse)1 ResourceRecordSet (software.amazon.awssdk.services.route53.model.ResourceRecordSet)1 Route53Exception (software.amazon.awssdk.services.route53.model.Route53Exception)1