Example usage for com.amazonaws.services.route53.model ResourceRecord setValue

List of usage examples for com.amazonaws.services.route53.model ResourceRecord setValue

Introduction

In this page you can find the example usage for com.amazonaws.services.route53.model ResourceRecord setValue.

Prototype


public void setValue(String value) 

Source Link

Document

The current or new DNS record value, not to exceed 4,000 characters.

Usage

From source file:com.msi.dns53.client.DNS53Client.java

License:Apache License

public ListResourceRecordSetsResult listResourceRecordSets(ListResourceRecordSetsRequest req)
        throws AmazonServiceException, AmazonClientException {
    Client c = Client.create();//from   w  w  w .  j  av a 2 s.  c  o m
    WebResource r = c.resource(this.serverURL);
    MultivaluedMap<String, String> paramMap = new MultivaluedMapImpl();
    if (req.getStartRecordName() != null) {
        paramMap.add("name", req.getStartRecordName());
    }
    if (req.getStartRecordType() != null) {
        paramMap.add("type", req.getStartRecordType());
    }
    if (req.getStartRecordIdentifier() != null) {
        paramMap.add("identifier", req.getStartRecordIdentifier());
    }
    if (req.getMaxItems() != null) {
        paramMap.add("maxitems", req.getMaxItems());
    }

    ClientResponse response = r.path(req.getHostedZoneId() + "/rrset").queryParams(paramMap)
            .type(MediaType.APPLICATION_XML_TYPE).accept(MediaType.TEXT_XML)
            .header("X-Amzn-Authorization",
                    "AWS3 AWSAccessKeyId=" + this.accessKey + "," + "Algorithm=HmacSHA256,"
                            + "SignedHeaders=Host;X-Amz-Date," + "Signature=THISISANEXAMPLESIGNATURE=")
            .get(ClientResponse.class);

    String resultXml = response.getEntity(String.class);
    if (response.getStatus() != 200) {
        exceptionMapper(response, resultXml);
    }

    ListResourceRecordSetsResponsePOJO interResult = null;
    try {
        StringReader reader = new StringReader(resultXml);
        JAXBContext context = JAXBContext.newInstance(ListResourceRecordSetsResponsePOJO.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        interResult = (ListResourceRecordSetsResponsePOJO) unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        e.printStackTrace();
        return null;
    }
    if (interResult == null) {
        return null;
    }

    ListResourceRecordSetsResult result = new ListResourceRecordSetsResult();
    result.setMaxItems(interResult.getMaxItems());
    result.setIsTruncated(interResult.isTruncated());
    if (interResult.getResourceRecordSets() != null) {
        Collection<ResourceRecordSet> rrSets = new LinkedList<ResourceRecordSet>();
        for (ResourceRecordSetPOJO p : interResult.getResourceRecordSets()) {
            ResourceRecordSet temp = new ResourceRecordSet();
            temp.setName(p.getName());
            temp.setSetIdentifier(p.getSetIdentifier());
            temp.setTTL(p.getTTL());
            temp.setType(p.getType());
            temp.setWeight(p.getWeight());
            if (p.getResourceRecords() != null) {
                Collection<ResourceRecord> resourceRecords = new LinkedList<ResourceRecord>();
                for (ResourceRecordPOJO record : p.getResourceRecords()) {
                    ResourceRecord newRec = new ResourceRecord();
                    newRec.setValue(record.getValue());
                    resourceRecords.add(newRec);
                }
                temp.setResourceRecords(resourceRecords);
            }
            rrSets.add(temp);
        }
        result.setResourceRecordSets(rrSets);
    }

    return result;
}

From source file:com.msi.dns53.client.DNS53MetadataUtil.java

License:Apache License

public void populateServiceMetadata(final ServletConfig config, String serviceName) {
    logger.debug("init(): TXT record will be created for this service regarding its port and context path.");
    String contextPath = config.getServletContext().getContextPath();
    String port = Appctx.getBean("TOMCAT_PORT");
    String master_passwd = Appctx.getBean("DB_PASSWORD");

    final String fqdn = (String) ConfigurationUtil.getConfiguration(Arrays.asList(new String[] { "FQDN" }));
    final String domain = (String) ConfigurationUtil
            .getConfiguration(Arrays.asList(new String[] { "FQDN_DOMAIN" }));
    String txtRecordValue = ":" + port + contextPath;
    String baseDNSServerURL = "http://localhost:" + port + "/DNS53Server/2012-02-29/";

    logger.debug("Tomcat port = " + port + "; FQDN = " + fqdn + "; domain = " + domain + "; TXT Record Value = "
            + txtRecordValue + "; BaseDNSServerUrl = " + baseDNSServerURL);

    DNS53Client client = new DNS53Client(baseDNSServerURL + "hostedzone", baseDNSServerURL + "change", "admin",
            master_passwd);// ww  w .j a v  a2  s .c  om

    logger.debug("Service name = " + serviceName);
    String recordName = serviceName + "-" + fqdn;
    logger.debug("TXT Record Name: " + recordName);

    logger.debug("init(): Calling ListHostedZones to find the target zone!");
    ListHostedZonesRequest lhzReq = new ListHostedZonesRequest();
    lhzReq.setMaxItems("1");

    ListHostedZonesResult lhzResult = client.listHostedZones(lhzReq);

    HostedZone zone = null;
    List<HostedZone> zones = lhzResult.getHostedZones();
    if (zones != null && zones.size() > 0) {
        for (HostedZone hz : zones) {
            if (hz.getName().equals(domain + ".") || hz.getName().equals(domain)) {
                zone = hz;
            }
        }
    } else {
        logger.error(
                "BaseAsyncServlet encountered an error while it was trying to find the target hosted zone.");
        throw ErrorResponse.InternalFailure();
    }

    if (zone == null) {
        logger.error("BaseAsyncServlet could not find any zone for this TopStackWeb instance.");
        throw ErrorResponse.InternalFailure();
    }

    // TODO (optional) check for the CNAME record for this service before proceeding

    logger.debug("init(): Creating a new TXT record for " + recordName + " with \"" + txtRecordValue
            + "\" as its value!");
    String zoneId = zone.getId();
    ChangeResourceRecordSetsRequest crrsReq = new ChangeResourceRecordSetsRequest();
    crrsReq.setHostedZoneId(zoneId);
    ChangeBatch cb = new ChangeBatch();
    cb.setComment(
            "BaseAsyncServlet => init(): Registering " + serviceName + " service for Transcend TopStack.");
    Collection<Change> changes = new LinkedList<Change>();
    Change change = new Change();
    change.setAction(ChangeAction.CREATE);
    ResourceRecordSet rrSet = new ResourceRecordSet();
    rrSet.setName(recordName);
    rrSet.setTTL(900L);
    rrSet.setType(RRType.TXT);
    Collection<ResourceRecord> rr = new LinkedList<ResourceRecord>();
    ResourceRecord record = new ResourceRecord();
    record.setValue(txtRecordValue);
    rr.add(record);
    rrSet.setResourceRecords(rr);
    change.setResourceRecordSet(rrSet);
    changes.add(change);
    cb.setChanges(changes);
    crrsReq.setChangeBatch(cb);
    ChangeResourceRecordSetsResult result = client.changeResourceRecordSets(crrsReq);
    logger.debug("Result for the last ChangeResourceRecordSets request: " + result.toString());
}

From source file:edu.umass.cs.aws.support.Route53.java

License:Apache License

private static void createRecordSetFromHostedZone() {

    List<ResourceRecord> records = new ArrayList<>();
    ResourceRecord record = new ResourceRecord();
    record.setValue("http://www.marksdevserver.com");
    records.add(record);//ww w  .  ja  va  2 s .  c o  m

    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());

}

From source file:io.kodokojo.service.aws.Route53DnsManager.java

License:Open Source License

@Override
public void createOrUpdateDnsEntries(Set<DnsEntry> dnsEntries) {
    if (dnsEntries == null) {
        throw new IllegalArgumentException("dnsEntries must be defined.");
    }/* w  w w. j a  v  a2  s.  c o  m*/

    HostedZone hostedZone = getHostedZone();
    List<Change> changes = new ArrayList<>();
    if (hostedZone != null) {
        for (DnsEntry dnsEntry : dnsEntries) {
            if (!containEntry(dnsEntry, true)) {
                List<ResourceRecord> resourceRecords = new ArrayList<>();

                ResourceRecord resourceRecord = new ResourceRecord();
                String value = dnsEntry.getValue();
                resourceRecord.setValue(
                        (dnsEntry.getType().equals(DnsEntry.Type.CNAME) ? valideDnsName(value) : value));
                resourceRecords.add(resourceRecord);

                ResourceRecordSet resourceRecordSet = new ResourceRecordSet();
                resourceRecordSet.setName(valideDnsName(dnsEntry.getName()));
                resourceRecordSet.setType(RRType.valueOf(dnsEntry.getType().toString()));
                resourceRecordSet.setTTL(300L);

                resourceRecordSet.setResourceRecords(resourceRecords);

                Change change = new Change();
                change.setAction(dnsEntryExist(dnsEntry) ? ChangeAction.UPSERT : ChangeAction.CREATE);
                change.setResourceRecordSet(resourceRecordSet);
                changes.add(change);
            }
        }
        if (CollectionUtils.isNotEmpty(changes)) {
            ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest();
            ChangeBatch changeBatch = new ChangeBatch();
            changeBatch.setChanges(changes);
            request.setChangeBatch(changeBatch);
            request.setHostedZoneId(getHostedZoneID(hostedZone));
            //ChangeResourceRecordSetsResult result =
            try {
                client.changeResourceRecordSets(request);
            } catch (PriorRequestNotCompleteException e) {
                LOGGER.error("Unable to create or update follwing entry in Route53 {}.",
                        StringUtils.join(dnsEntries, ","));
            }
        }
    }

}