List of usage examples for com.amazonaws.services.route53.model RRType CNAME
RRType CNAME
To view the source code for com.amazonaws.services.route53.model RRType CNAME.
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 ava 2 s. 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 . j a v a2 s. c om*/ 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);//from w ww.ja va2s. co 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: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);/*from w w w. j a v a2 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:fr.xebia.cloud.amazon.aws.tools.AmazonAwsUtils.java
License:Apache License
public static void deleteCnameIfExist(Iterable<String> cnames, HostedZone hostedZone, AmazonRoute53 route53) { // List all/* ww w.j a va 2 s . c o m*/ ListResourceRecordSetsRequest listResourceRecordSetsRequest = new ListResourceRecordSetsRequest() // .withStartRecordType(RRType.CNAME) .withHostedZoneId(hostedZone.getId()); ListResourceRecordSetsResult listResourceRecordSetsResult = route53 .listResourceRecordSets(listResourceRecordSetsRequest); if (listResourceRecordSetsResult.isTruncated()) { logger.warn("truncated result"); } Function<ResourceRecordSet, String> cnameExtractor = new Function<ResourceRecordSet, String>() { @Override public String apply(@Nullable ResourceRecordSet resourceRecordSet) { if (resourceRecordSet == null) { return null; } if (!RRType.CNAME.equals(RRType.fromValue(resourceRecordSet.getType()))) { return null; } return resourceRecordSet.getName(); } }; Iterable<ResourceRecordSet> existingCnamesAsResourceRecordSet = Iterables .filter(listResourceRecordSetsResult.getResourceRecordSets(), new Predicate<ResourceRecordSet>() { @Override public boolean apply(@Nullable ResourceRecordSet resourceRecordSet) { return RRType.CNAME.equals(RRType.fromValue(resourceRecordSet.getType())); } }); final ImmutableMap<String, ResourceRecordSet> existingCnames = Maps .uniqueIndex(existingCnamesAsResourceRecordSet, cnameExtractor); Sets.SetView<String> cnamesToDelete = Sets.intersection(Sets.newHashSet(cnames), existingCnames.keySet()); Function<String, Change> cnameToDeleteCnameChange = new Function<String, Change>() { @Override public Change apply(@Nullable String cname) { ResourceRecordSet existingResourceRecordSet = existingCnames.get(cname); return new Change().withAction(ChangeAction.DELETE) .withResourceRecordSet(new ResourceRecordSet().withType(RRType.CNAME).withName(cname) .withTTL(existingResourceRecordSet.getTTL()) .withResourceRecords(existingResourceRecordSet.getResourceRecords())); } }; List<Change> changes = Lists.newArrayList(Iterables.transform(cnamesToDelete, cnameToDeleteCnameChange)); if (changes.isEmpty()) { logger.debug("No CNAME to delete"); return; } logger.info("Delete CNAME changes {}", changes); ChangeResourceRecordSetsRequest changeResourceRecordSetsRequest = new ChangeResourceRecordSetsRequest() .withHostedZoneId(hostedZone.getId()).withChangeBatch(new ChangeBatch().withChanges(changes)); route53.changeResourceRecordSets(changeResourceRecordSetsRequest); }
From source file:fr.xebia.cloud.amazon.aws.tools.AmazonAwsUtils.java
License:Apache License
public static void createCnamesForInstances(Map<String, Instance> cnameToInstances, HostedZone hostedZone, AmazonRoute53 route53) {//from w w w .jav a2 s. co m Function<Map.Entry<String, Instance>, Change> cnameAndInstanceToChange = new Function<Map.Entry<String, Instance>, Change>() { @Override public Change apply(@Nullable Map.Entry<String, Instance> entry) { String cname = entry.getKey(); Instance instance = entry.getValue(); return new Change().withAction(ChangeAction.CREATE).withResourceRecordSet( new ResourceRecordSet().withType(RRType.CNAME).withName(cname).withTTL(300L) .withResourceRecords(new ResourceRecord(instance.getPublicDnsName()))); } }; List<Change> changes = Lists .newArrayList(Iterables.transform(cnameToInstances.entrySet(), cnameAndInstanceToChange)); logger.debug("Create CNAME {}", changes); ChangeResourceRecordSetsRequest changeResourceRecordSetsRequest = new ChangeResourceRecordSetsRequest() .withHostedZoneId(hostedZone.getId()).withChangeBatch(new ChangeBatch().withChanges(changes)); route53.changeResourceRecordSets(changeResourceRecordSetsRequest); }
From source file:jp.classmethod.aws.gradle.route53.AmazonRoute53ChangeRecordSetTask.java
License:Apache License
@TaskAction public void changeResourceRecordSets() { // to enable conventionMappings feature String hostedZoneId = getHostedZoneId(); String rrsName = getRrsName(); String resourceRecord = getResourceRecord(); AmazonRoute53PluginExtension ext = getProject().getExtensions() .getByType(AmazonRoute53PluginExtension.class); AmazonRoute53 route53 = ext.getClient(); route53.changeResourceRecordSets(new ChangeResourceRecordSetsRequest().withHostedZoneId(hostedZoneId) .withChangeBatch(new ChangeBatch() .withChanges(new Change(ChangeAction.CREATE, new ResourceRecordSet(rrsName, RRType.CNAME) .withResourceRecords(new ResourceRecord(resourceRecord)))))); getLogger().info("change {} requested", hostedZoneId); }
From source file:org.ofbiz.tenant.amazonaws.util.AwsUtil.java
License:Apache License
/** * get resource record type//w ww.ja va2s .com * @param value * @return * @throws GeneralException */ public static RRType getRRType(String value) throws GeneralException { RRType rrType = null; if ("A".equals(value)) { rrType = RRType.A; } else if ("CNAME".equals(value)) { rrType = RRType.CNAME; } else if ("MX".equals(value)) { rrType = RRType.MX; } else if ("AAAA".equals(value)) { rrType = RRType.AAAA; } else if ("TXT".equals(value)) { rrType = RRType.TXT; } else if ("PTR".equals(value)) { rrType = RRType.PTR; } else if ("SRV".equals(value)) { rrType = RRType.SRV; } else if ("SPF".equals(value)) { rrType = RRType.SPF; } else if ("NS".equals(value)) { rrType = RRType.NS; } else if ("SOA".equals(value)) { rrType = RRType.SOA; } else { throw new GeneralException( "The type need to be one of: A, CNAME, MX, AAAA, TXT, PTR, SRV, SPF, NS, SOA"); } return rrType; }