List of usage examples for com.amazonaws.services.route53.model ChangeResourceRecordSetsRequest ChangeResourceRecordSetsRequest
public ChangeResourceRecordSetsRequest(String hostedZoneId, ChangeBatch changeBatch)
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())); /**// ww w .ja v a 2 s.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:com.deploymentio.ec2namer.helpers.DnsRegistrar.java
License:Apache License
/** * Registers the reserved name and all additional names along with their * health-checks if requested. This will be done in Route53. * /* ww w. j a va 2 s . c o m*/ * @param req * the namer request * @param context * the lambda function execution context * @param name * the reserved name for this instance * @throws IOException * if the DNS name(s) cannot registered in Route53 */ public void register(NamerRequest req, LambdaContext context, ReservedName name) throws IOException { List<Change> changes = new ArrayList<Change>(); // lets create the first record changes.add(createName(req, context, name.getHostname())); // delete existing health-checks for this instance deleteHealthChecks(req, context); // create the additional names for (RequestedName additionalName : req.getRequestedNames()) { changes.add(createName(req, context, additionalName, name.getHostname())); } // execute the changes String zoneId = (String) context.get("hosted-zone"); route53.changeResourceRecordSets( new ChangeResourceRecordSetsRequest(zoneId, new ChangeBatch().withChanges(changes))); }
From source file:org.ofbiz.tenant.amazonaws.AwsServices.java
License:Apache License
/** * create Amazon Rout53 resource record set * @param ctx/*from w ww.j a v a2 s . c om*/ * @param context * @return */ public static Map<String, Object> createAmazonRoute53ResourceRecordSet(DispatchContext ctx, Map<String, Object> context) { String hostedZoneId = (String) context.get("hostedZoneId"); String recordSetName = (String) context.get("recordSetName"); String recordSetType = (String) context.get("recordSetType"); List<String> domainNames = UtilGenerics.checkList(context.get("domainNames")); String dNSName = (String) context.get("dNSName"); String resourceRecordSetId = (String) context.get("resourceRecordSetId"); Long weight = (Long) context.get("weight"); Long tTL = (Long) context.get("tTL"); try { AmazonRoute53 route53 = AwsFactory.getAmazonRoute53(); RRType rrType = AwsUtil.getRRType(recordSetType); ResourceRecordSet resourceRecordSet = new ResourceRecordSet(recordSetName, rrType); // set alias target if (UtilValidate.isNotEmpty(dNSName)) { AliasTarget aliasTarget = new AliasTarget(hostedZoneId, dNSName); resourceRecordSet.setAliasTarget(aliasTarget); } // set resource record set identifier if (UtilValidate.isNotEmpty(resourceRecordSetId)) { resourceRecordSet.setSetIdentifier(resourceRecordSetId); } // set resource records List<ResourceRecord> resourceRecords = FastList.newInstance(); for (String domainName : domainNames) { ResourceRecord resourceRecord = new ResourceRecord(domainName); resourceRecords.add(resourceRecord); } resourceRecordSet.setResourceRecords(resourceRecords); // set weight if (UtilValidate.isEmpty(weight)) { weight = 0L; } resourceRecordSet.setWeight(weight); // set TTL if (UtilValidate.isEmpty(tTL)) { tTL = 300L; } resourceRecordSet.setTTL(tTL); Change change = new Change(ChangeAction.CREATE, resourceRecordSet); List<Change> changes = FastList.newInstance(); changes.add(change); ChangeBatch changeBatch = new ChangeBatch(changes); ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest(hostedZoneId, changeBatch); ChangeResourceRecordSetsResult resourceRecordSetsResult = route53.changeResourceRecordSets(request); ChangeInfo changeInfo = resourceRecordSetsResult.getChangeInfo(); String changeId = changeInfo.getId(); String status = changeInfo.getStatus(); Date submittedAt = changeInfo.getSubmittedAt(); String comment = changeInfo.getComment(); Map<String, Object> results = ServiceUtil.returnSuccess(); results.put("changeId", changeId); results.put("status", status); results.put("submittedAt", submittedAt); results.put("comment", comment); return results; } catch (Exception e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } }
From source file:org.ofbiz.tenant.amazonaws.AwsServices.java
License:Apache License
/** * update Amazon Rout53 resource record set * @param ctx/* w ww . j a v a 2 s. co m*/ * @param context * @return */ public static Map<String, Object> updateAmazonRoute53ResourceRecordSet(DispatchContext ctx, Map<String, Object> context) { String hostedZoneId = (String) context.get("hostedZoneId"); String recordSetName = (String) context.get("recordSetName"); String recordSetType = (String) context.get("recordSetType"); List<String> domainNames = UtilGenerics.checkList(context.get("domainNames")); List<String> newDomainNames = UtilGenerics.checkList(context.get("newDomainNames")); String dNSName = (String) context.get("dNSName"); String resourceRecordSetId = (String) context.get("resourceRecordSetId"); Long weight = (Long) context.get("weight"); Long tTL = (Long) context.get("tTL"); try { AmazonRoute53 route53 = AwsFactory.getAmazonRoute53(); RRType rrType = AwsUtil.getRRType(recordSetType); ResourceRecordSet deleteResourceRecordSet = new ResourceRecordSet(recordSetName, rrType); ResourceRecordSet createResourceRecordSet = new ResourceRecordSet(recordSetName, rrType); // set alias target if (UtilValidate.isNotEmpty(dNSName)) { AliasTarget aliasTarget = new AliasTarget(hostedZoneId, dNSName); deleteResourceRecordSet.setAliasTarget(aliasTarget); createResourceRecordSet.setAliasTarget(aliasTarget); } // set resource record set identifier if (UtilValidate.isNotEmpty(resourceRecordSetId)) { deleteResourceRecordSet.setSetIdentifier(resourceRecordSetId); createResourceRecordSet.setSetIdentifier(resourceRecordSetId); } // set weight if (UtilValidate.isEmpty(weight)) { weight = 0L; } deleteResourceRecordSet.setWeight(weight); createResourceRecordSet.setWeight(weight); // set TTL if (UtilValidate.isEmpty(tTL)) { tTL = 300L; } deleteResourceRecordSet.setTTL(tTL); createResourceRecordSet.setTTL(tTL); //--------- Delete Resource Record Set Change List<ResourceRecord> deleteResourceRecords = FastList.newInstance(); // set delete resource records for (String domainName : domainNames) { ResourceRecord resourceRecord = new ResourceRecord(domainName); deleteResourceRecords.add(resourceRecord); } deleteResourceRecordSet.setResourceRecords(deleteResourceRecords); Change deleteChange = new Change(ChangeAction.DELETE, deleteResourceRecordSet); //-------- Create New Resource Record Set Change List<ResourceRecord> createResourceRecords = FastList.newInstance(); // set create resource records for (String newDomainName : newDomainNames) { ResourceRecord resourceRecord = new ResourceRecord(newDomainName); createResourceRecords.add(resourceRecord); } createResourceRecordSet.setResourceRecords(createResourceRecords); Change createChange = new Change(ChangeAction.CREATE, createResourceRecordSet); // send request List<Change> changes = FastList.newInstance(); changes.add(deleteChange); changes.add(createChange); ChangeBatch changeBatch = new ChangeBatch(changes); ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest(hostedZoneId, changeBatch); ChangeResourceRecordSetsResult resourceRecordSetsResult = route53.changeResourceRecordSets(request); ChangeInfo changeInfo = resourceRecordSetsResult.getChangeInfo(); String changeId = changeInfo.getId(); String status = changeInfo.getStatus(); Date submittedAt = changeInfo.getSubmittedAt(); String comment = changeInfo.getComment(); Map<String, Object> results = ServiceUtil.returnSuccess(); results.put("changeId", changeId); results.put("status", status); results.put("submittedAt", submittedAt); results.put("comment", comment); return results; } catch (Exception e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } }
From source file:org.ofbiz.tenant.amazonaws.AwsServices.java
License:Apache License
/** * delete Amazon Rout53 resource record set * @param ctx/* w ww . j a v a 2 s. c om*/ * @param context * @return */ public static Map<String, Object> deleteAmazonRoute53ResourceRecordSet(DispatchContext ctx, Map<String, Object> context) { String hostedZoneId = (String) context.get("hostedZoneId"); String recordSetName = (String) context.get("recordSetName"); String recordSetType = (String) context.get("recordSetType"); List<String> domainNames = UtilGenerics.checkList(context.get("domainNames")); String dNSName = (String) context.get("dNSName"); String resourceRecordSetId = (String) context.get("resourceRecordSetId"); Long weight = (Long) context.get("weight"); Long tTL = (Long) context.get("tTL"); try { AmazonRoute53 route53 = AwsFactory.getAmazonRoute53(); RRType rrType = AwsUtil.getRRType(recordSetType); ResourceRecordSet resourceRecordSet = new ResourceRecordSet(recordSetName, rrType); // set alias target if (UtilValidate.isNotEmpty(dNSName)) { AliasTarget aliasTarget = new AliasTarget(hostedZoneId, dNSName); resourceRecordSet.setAliasTarget(aliasTarget); } // set resource record set identifier if (UtilValidate.isNotEmpty(resourceRecordSetId)) { resourceRecordSet.setSetIdentifier(resourceRecordSetId); } // set resource records List<ResourceRecord> resourceRecords = FastList.newInstance(); for (String domainName : domainNames) { ResourceRecord resourceRecord = new ResourceRecord(domainName); resourceRecords.add(resourceRecord); } resourceRecordSet.setResourceRecords(resourceRecords); // set weight if (UtilValidate.isEmpty(weight)) { weight = 0L; } resourceRecordSet.setWeight(weight); // set TTL if (UtilValidate.isEmpty(tTL)) { tTL = 300L; } resourceRecordSet.setTTL(tTL); Change change = new Change(ChangeAction.DELETE, resourceRecordSet); List<Change> changes = FastList.newInstance(); changes.add(change); ChangeBatch changeBatch = new ChangeBatch(changes); ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest(hostedZoneId, changeBatch); ChangeResourceRecordSetsResult resourceRecordSetsResult = route53.changeResourceRecordSets(request); ChangeInfo changeInfo = resourceRecordSetsResult.getChangeInfo(); String changeId = changeInfo.getId(); String status = changeInfo.getStatus(); Date submittedAt = changeInfo.getSubmittedAt(); String comment = changeInfo.getComment(); Map<String, Object> results = ServiceUtil.returnSuccess(); results.put("changeId", changeId); results.put("status", status); results.put("submittedAt", submittedAt); results.put("comment", comment); return results; } catch (Exception e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } }
From source file:tech.greenfield.aws.route53.EventHandler.java
License:Open Source License
private void rebuildAllRRs(String asgName) { List<Instance> instances = Tools.getASGInstances(asgName).stream() .filter(i -> i.getHealthStatus().equals("Healthy")).map(Tools::asInstanceToEC2) .filter(Objects::nonNull).collect(Collectors.toList()); ChangeBatch changes = instances.isEmpty() ? message.getDeleteChanges() : message.getUpsertChanges(instances); if (Route53Message.isDebug()) logger.info("Sending DNS change request: " + changes); try {/* www . jav a2s . c o m*/ ChangeResourceRecordSetsRequest req = new ChangeResourceRecordSetsRequest( Route53Message.getHostedZoneId(), changes); Tools.waitFor(route53().changeResourceRecordSets(req)); } catch (IllegalArgumentException e) { Tools.logException(logger, "Error in submitting Route53 update", e); throw new SdkBaseException(e); } }
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 *//*from ww w . j a va 2 s. com*/ 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 //from w ww .j ava 2s . 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)); }