List of usage examples for com.amazonaws.services.route53.model ChangeAction UPSERT
ChangeAction UPSERT
To view the source code for com.amazonaws.services.route53.model ChangeAction UPSERT.
Click Source Link
From source file:com.deploymentio.ec2namer.helpers.DnsRegistrar.java
License:Apache License
protected Change createName(NamerRequest req, LambdaContext context, String name) { Instance instance = instanceLookup.lookup(context, req.getInstanceId()); boolean isVpc = req.isAlwaysUsePublicName() ? false : !StringUtils.isEmpty(instance.getVpcId()); RRType recordType = isVpc ? RRType.A : RRType.CNAME; ResourceRecordSet set = new ResourceRecordSet(req.createFqdn(name) + ".", recordType); set.withTTL(60l);//from w w w . j av a 2s .c o m set.withResourceRecords( new ResourceRecord(isVpc ? instance.getPrivateIpAddress() : instance.getPublicDnsName())); return new Change(ChangeAction.UPSERT, set); }
From source file:com.deploymentio.ec2namer.helpers.DnsRegistrar.java
License:Apache License
protected Change createName(NamerRequest req, LambdaContext context, RequestedName additionalName, String assignedName) {//from w w w .java 2 s . c o m String fullAssignedName = req.createFqdn(assignedName); String fullAdditionalName = req.createFqdn(additionalName.getName()); Instance instance = instanceLookup.lookup(context, req.getInstanceId()); boolean usePublicHostname = req.isAlwaysUsePublicName() || StringUtils.isEmpty(instance.getVpcId()); ResourceRecordSet set = new ResourceRecordSet(fullAdditionalName + ".", RRType.CNAME).withTTL(60l) .withResourceRecords( new ResourceRecord(usePublicHostname ? instance.getPublicDnsName() : fullAssignedName)) .withSetIdentifier(fullAssignedName).withWeight(Long.valueOf(additionalName.getWeight())); if (additionalName.isHealthChecked()) { String uuid = instance.getInstanceId() + "-" + UUID.randomUUID().toString(); String hcId = null; for (int i = 0; i < 5; i++) { try { if (i > 0) { Thread.sleep(5000); } CreateHealthCheckResult result = route53.createHealthCheck( new CreateHealthCheckRequest().withCallerReference(uuid).withHealthCheckConfig( new HealthCheckConfig().withFullyQualifiedDomainName(fullAssignedName) .withIPAddress(instance.getPublicIpAddress()) .withPort(additionalName.getHealthCheckPort()) .withType(additionalName.getHealthCheckType()) .withResourcePath(additionalName.getHealthCheckUri()))); hcId = result.getHealthCheck().getId(); context.log("Created health-check: Name=" + fullAdditionalName + " Protocol=" + additionalName.getHealthCheckType() + " Port=" + additionalName.getHealthCheckPort() + " Uri=" + additionalName.getHealthCheckUri() + " Id=" + hcId); // create tags on health-check route53.changeTagsForResource(new ChangeTagsForResourceRequest().withResourceId(hcId) .withResourceType(TagResourceType.Healthcheck).withAddTags( new Tag().withKey("Name").withValue(req.getEnvironment() + ":" + assignedName), new Tag().withKey("InstanceId").withValue(req.getInstanceId()))); break; } catch (Exception e) { context.log("Can't create health-check: Attempt= " + (i + 1) + " Name=" + fullAdditionalName + " Protocol=" + additionalName.getHealthCheckType() + " Port=" + additionalName.getHealthCheckPort() + " Uri=" + additionalName.getHealthCheckUri() + " Id=" + hcId + " Ref=" + uuid + " Error=" + e.getMessage()); } } if (!StringUtils.isEmpty(hcId)) { set.setHealthCheckId(hcId); } } return new Change(ChangeAction.UPSERT, set); }
From source file:com.github.blacklocus.rdsecho.EchoPromote.java
License:Open Source License
@Override boolean traverseStage(DBInstance instance) { LOG.info("Reading current DNS records"); String tld = EchoUtil.getTLD(cfg.promoteCname()) + '.'; HostedZone hostedZone = route53Find.hostedZone(nameEquals(tld)).get(); LOG.info(" Found corresponding HostedZone. name: {} id: {}", hostedZone.getName(), hostedZone.getId()); ResourceRecordSet resourceRecordSet = route53Find .resourceRecordSet(hostedZone.getId(), cnameEquals(cfg.promoteCname())).get(); ResourceRecord resourceRecord = getOnlyElement(resourceRecordSet.getResourceRecords()); LOG.info(" Found CNAME {} with current value {}", resourceRecordSet.getName(), resourceRecord.getValue()); Endpoint endpoint = instance.getEndpoint(); String tagEchoManaged = echo.getTagEchoManaged(); String dbInstanceId = instance.getDBInstanceIdentifier(); if (null == endpoint) { LOG.info("Echo DB instance {} (id: {}) has no address. Is it still initializing?", tagEchoManaged, dbInstanceId);// ww w.ja v a2 s .c o m return false; } String instanceAddr = endpoint.getAddress(); if (resourceRecord.getValue().equals(instanceAddr)) { LOG.info(" Echo DB instance {} ({}) lines up with CNAME {}. Nothing to do.", tagEchoManaged, instanceAddr, resourceRecordSet.getName()); return false; } else { LOG.info(" Echo DB instance {} ({}) differs from CNAME {}.", tagEchoManaged, instanceAddr, resourceRecordSet.getName()); } if (cfg.interactive()) { String format = "Are you sure you want to promote %s to be the new target of %s? Input %s to confirm."; if (!EchoUtil.prompt(dbInstanceId, format, dbInstanceId, cfg.promoteCname(), dbInstanceId)) { LOG.info("User declined to proceed. Exiting."); return false; } } LOG.info("Updating CNAME {} from {} to {}", cfg.name(), resourceRecord.getValue(), instanceAddr); ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest() .withHostedZoneId(hostedZone.getId()) .withChangeBatch(new ChangeBatch().withChanges( new Change(ChangeAction.UPSERT, new ResourceRecordSet(cfg.promoteCname(), RRType.CNAME) .withResourceRecords(new ResourceRecord(instanceAddr)).withTTL(cfg.promoteTtl())))); route53.changeResourceRecordSets(request); Optional<String[]> promoteTags = cfg.promoteTags(); if (promoteTags.isPresent()) { List<Tag> tags = EchoUtil.parseTags(promoteTags.get()); if (tags.size() > 0) { LOG.info("Applying tags on promote: {}", Arrays.asList(tags)); AddTagsToResourceRequest tagsRequest = new AddTagsToResourceRequest().withResourceName( RdsFind.instanceArn(cfg.region(), cfg.accountNumber(), instance.getDBInstanceIdentifier())); tagsRequest.setTags(tags); rds.addTagsToResource(tagsRequest); } } LOG.info("Searching for any existing promoted instance to demote."); return true; }
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."); }/*from w w w . j a v a 2s. 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, ",")); } } } }
From source file:net.za.slyfox.dyn53.route53.Route53Updater.java
License:Apache License
/** * Updates the configured resource record set with the value of an IP address. * * @param inetAddress the address to update the resource record set with *//*from w w w. jav a2s .c om*/ @Override public void accept(InetAddress inetAddress) { final String address = inetAddress.getHostAddress(); logger.info("Updating resource record set {} in hosted zone {} to {}", resourceRecordSetName, hostedZoneId, address); final ResourceRecordSet resourceRecordSet = new ResourceRecordSet(resourceRecordSetName, getResourceRecordType(inetAddress)).withResourceRecords(new ResourceRecord(address)) .withTTL(resourceRecordSetTtl); final Change change = new Change(ChangeAction.UPSERT, resourceRecordSet); final ChangeBatch changeBatch = new ChangeBatch().withChanges(change).withComment("Dyn53 update"); final ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest() .withHostedZoneId(hostedZoneId).withChangeBatch(changeBatch); if (logger.isDebugEnabled()) { logger.debug("Requesting change: {}", change); } final ChangeResourceRecordSetsResult result = route53.changeResourceRecordSets(request); if (logger.isInfoEnabled()) { logger.info("Result of change request {}: {}", result.getChangeInfo().getId(), result.getChangeInfo().getStatus()); } }