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

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

Introduction

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

Prototype


public java.util.List<Change> getChanges() 

Source Link

Document

Information about the changes to make to the record sets.

Usage

From source file:br.com.ingenieux.mojo.beanstalk.cmd.dns.BindDomainsCommand.java

License:Apache License

protected void assignDomain(BindDomainsContext ctx, String record, String zoneId) {
    ChangeBatch changeBatch = new ChangeBatch();

    changeBatch.setComment(format("Updated for env %s", ctx.getCurEnv().getCNAME()));

    /**//w ww  .  j  av a  2s  .  c  om
     * Look for Existing Resource Record Sets
     */
    {
        ResourceRecordSet resourceRecordSet = null;

        ListResourceRecordSetsResult listResourceRecordSets = r53
                .listResourceRecordSets(new ListResourceRecordSetsRequest(zoneId));

        for (ResourceRecordSet rrs : listResourceRecordSets.getResourceRecordSets()) {
            if (!rrs.getName().equals(record)) {
                continue;
            }

            boolean matchesTypes = "A".equals(rrs.getType()) || "CNAME".equals(rrs.getType());

            if (!matchesTypes) {
                continue;
            }

            if (isInfoEnabled()) {
                info("Excluding resourceRecordSet %s for domain %s", rrs, record);
            }

            changeBatch.getChanges().add(new Change(ChangeAction.DELETE, rrs));
        }
    }

    /**
     * Then Add Ours
     */
    ResourceRecordSet resourceRecordSet = new ResourceRecordSet();

    resourceRecordSet.setName(record);
    resourceRecordSet.setType(RRType.A);

    if (ctx.singleInstance) {
        final String address = ctx.getCurEnv().getEndpointURL();
        ResourceRecord resourceRecord = new ResourceRecord(address);

        resourceRecordSet.setTTL(60L);
        resourceRecordSet.setResourceRecords(asList(resourceRecord));

        if (isInfoEnabled()) {
            info("Adding resourceRecordSet %s for domain %s mapped to %s", resourceRecordSet, record, address);
        }
    } else {
        AliasTarget aliasTarget = new AliasTarget();

        aliasTarget.setHostedZoneId(ctx.getElbHostedZoneId());
        aliasTarget.setDNSName(ctx.getCurEnv().getEndpointURL());

        resourceRecordSet.setAliasTarget(aliasTarget);

        if (isInfoEnabled()) {
            info("Adding resourceRecordSet %s for domain %s mapped to %s", resourceRecordSet, record,
                    aliasTarget.getDNSName());
        }
    }

    changeBatch.getChanges().add(new Change(ChangeAction.CREATE, resourceRecordSet));

    if (isInfoEnabled()) {
        info("Changes to be sent: %s", changeBatch.getChanges());
    }

    ChangeResourceRecordSetsRequest req = new ChangeResourceRecordSetsRequest(zoneId, changeBatch);

    r53.changeResourceRecordSets(req);
}

From source file:tech.greenfield.aws.route53.EventHandler.java

License:Open Source License

/**
 * Start an DNS registration for the launched instance
 * @param ec2InstanceId instance ID of instance that needs to be registered
 * @param ttl TTL in seconds to use when creating a new record
 *///w  w  w . ja  v  a 2  s  . c o  m
private void registerInstance(String ec2InstanceId) throws NoIpException {
    logger.info("Registering " + ec2InstanceId);
    ChangeBatch cb = message.getUpsertChanges(Collections.singletonList(getInstance(ec2InstanceId)));

    if (Route53Message.isDebug())
        logger.fine("Adding instance with addresses: " + cb);

    for (Change c : cb.getChanges()) {
        ResourceRecordSet rr = c.getResourceRecordSet();
        ResourceRecordSet oldrr = Tools.getRecordSet(rr.getName(), rr.getType());
        if (Objects.nonNull(oldrr))
            oldrr.getResourceRecords().forEach(r -> rr.withResourceRecords(r));
    }
    ChangeResourceRecordSetsRequest req = new ChangeResourceRecordSetsRequest(Route53Message.getHostedZoneId(),
            cb);
    if (Route53Message.isDebug())
        logger.fine("Sending rr change request: " + req);
    Tools.waitFor(route53().changeResourceRecordSets(req));
}

From source file:tech.greenfield.aws.route53.EventHandler.java

License:Open Source License

/**
 * Start a DNS re-registration for the terminated instance
 * @param ec2InstanceId instance ID of instance that needs to be de-registered
 * @param ttl TTL in seconds to use when creating a new record
 * @throws NoIpException /* w  ww. ja  v a2  s .  c o m*/
 */
private void deregisterInstance(String ec2InstanceId) throws NoIpException {
    logger.info("Deregistering " + ec2InstanceId);
    ChangeBatch changes = message.getRemoveChanges(getInstance(ec2InstanceId));
    if (changes.getChanges().isEmpty()) {
        logger.info("Nothing to remove");
        return;
    }
    ChangeResourceRecordSetsRequest req = new ChangeResourceRecordSetsRequest(Route53Message.getHostedZoneId(),
            changes);
    if (Route53Message.isDebug())
        logger.fine("Sending rr change request: " + req);
    Tools.waitFor(route53().changeResourceRecordSets(req));
}