Example usage for com.amazonaws.services.route53.model ChangeBatch withChanges

List of usage examples for com.amazonaws.services.route53.model ChangeBatch withChanges

Introduction

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

Prototype


public ChangeBatch withChanges(java.util.Collection<Change> changes) 

Source Link

Document

Information about the changes to make to the record sets.

Usage

From source file:com.renatodelgaudio.awsupdate.SimpleRecordService.java

License:Open Source License

@Override
public boolean updateRecord(String ip) {

    String recordName = config.getRecordName();

    ChangeResourceRecordSetsRequest changeRequest = new ChangeResourceRecordSetsRequest();
    changeRequest.setHostedZoneId(config.getZoneId());
    ChangeBatch batch = new ChangeBatch();
    Change change = new Change();

    ResourceRecordSet set = getCurrentRecordSet();
    if (set != null) {
        if (!equalsIgnoreCase("A", set.getType())) {
            log.error("Record already exists but not as Type A. No actions were performed.");
            return false;
        }//from ww  w  . ja va2s .  c o  m
        change.setAction("UPSERT");
        log.info("Record [" + recordName + "] already present on AWS Route 53. Upating it..");
    } else {
        change.setAction("CREATE");
        log.info("Record [" + recordName + "] not present on AWS Route 53. Creating it..");
        set = new ResourceRecordSet().withName(recordName).withType("A");
    }

    set.setTTL(Long.parseLong(config.getTTL()));
    List<ResourceRecord> l = new ArrayList<ResourceRecord>();
    l.add(new ResourceRecord(ip));
    set.setResourceRecords(l);

    change.setResourceRecordSet(set);
    batch.withChanges(change);

    changeRequest.setChangeBatch(batch);

    log.info("Updating DNS " + recordName + " with IP " + ip);

    ChangeResourceRecordSetsResult result = config.getAmazonRoute53Client()
            .changeResourceRecordSets(changeRequest);
    log.info(result.toString());
    return true;
}