public ResourceRecordSet getCurrentRecordSet() { if (log.isDebugEnabled()) { log.debug("zoneId:" + config.getZoneId()); log.debug("recordName:" + config.getRecordName()); } ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest(); request.setHostedZoneId(config.getZoneId()); ListResourceRecordSetsResult result = config.getAmazonRoute53Client() .listResourceRecordSets(request); List<ResourceRecordSet> recordSets = result.getResourceRecordSets(); for (ResourceRecordSet recordSet : recordSets) { String currName = recordSet.getName(); if (currName == null) continue; currName = currName.trim(); // AWS ends name with dot. if (currName.endsWith(".")) currName = currName.substring(0, currName.length() - 1); if (equalsIgnoreCase(config.getRecordName(), currName)) { return recordSet; } } return null; }
public ResourceRecordSet getCurrentRecordSet() { if (log.isDebugEnabled()){ log.debug("zoneId:"+config.getZoneId()); log.debug("recordName:"+config.getRecordName()); } ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest(); request.setHostedZoneId(config.getZoneId()); ListResourceRecordSetsResult result = config.getAmazonClient().listResourceRecordSets(request); List<ResourceRecordSet> recordSets = result.getResourceRecordSets(); for(ResourceRecordSet recordSet : recordSets) { String currName = recordSet.getName(); if (currName == null) continue; currName = currName.trim(); // AWS ends name with dot. if (currName.endsWith(".")) currName = currName.substring(0,currName.length()-1); if (equalsIgnoreCase(config.getRecordName(),currName)) { return recordSet; } } return null; }
/** * TODO: assumes exactly one A record for record set * @param recordSetName * @return value for A record of record set */ private String getCurrentAValue(final String recordSetName) { final ListResourceRecordSetsRequest listResourceRecordSetsRequest = new ListResourceRecordSetsRequest() .withHostedZoneId(hostedZoneId) .withMaxItems("1") .withStartRecordName(recordSetName); ListResourceRecordSetsResult listResourceRecordSetsResult = execWithRetries(new Callable<ListResourceRecordSetsResult>() { @Override public ListResourceRecordSetsResult call() throws Exception { return route53.listResourceRecordSets(listResourceRecordSetsRequest); } }); List<ResourceRecordSet> resourceRecordSets = listResourceRecordSetsResult.getResourceRecordSets(); if (resourceRecordSets.isEmpty()) { throw new IllegalStateException("Could not find any resource record sets for \"" + recordSetName + "\" in hosted zone \"" + hostedZoneId + "\""); } for (ResourceRecordSet resourceRecordSet : resourceRecordSets) { if (RRType.valueOf(resourceRecordSet.getType()) == RRType.A) { List<ResourceRecord> resourceRecords = resourceRecordSet.getResourceRecords(); if (resourceRecords.isEmpty()) { throw new IllegalStateException("Could not find any A records for set \"" + resourceRecordSet.getName() + "\" in hosted zone \"" + hostedZoneId + "\""); } return resourceRecords.get(0).getValue(); } } throw new IllegalStateException("Could not find any A records for record set \"" + recordSetName + "\""); }
@Override public ListResourceRecordSetsResult process0(Session session, HttpServletRequest req, HttpServletResponse resp, Map<String, String[]> map) throws Exception { ListResourceRecordSetsRequest request = unmarshall(req); return listResourceRecordSets(session, request); }
@Test public void listResourceRecordSets0() { ListResourceRecordSetsRequest req = new ListResourceRecordSetsRequest( this.getZoneId(zoneName0)); ListResourceRecordSetsResult result = customDNS53Client .listResourceRecordSets(req); assertNotNull(result); assertNotNull(result.getResourceRecordSets()); assertEquals(true, result.getResourceRecordSets().size() > 0); boolean found = false; for (ResourceRecordSet rrSet : result.getResourceRecordSets()) { if (rrSet.getName().equals("www." + zoneName0) && rrSet.getTTL().equals(300L) && rrSet.getType().equals("A") && rrSet.getResourceRecords().get(0).getValue() .equals("172.31.255.235")) { found = true; } } assertEquals(true, found); assertEquals(false, result.getIsTruncated()); assertEquals("100", result.getMaxItems()); assertEquals(null, result.getNextRecordIdentifier()); assertEquals(null, result.getNextRecordName()); assertEquals(null, result.getNextRecordType()); System.out.println(result); }
@Test // (expected = NoSuchHostedZoneException.class) public void listResourceRecordSets1() { ListResourceRecordSetsRequest req = new ListResourceRecordSetsRequest( "BOGUS_HOSTED_ZONE_ID"); ListResourceRecordSetsResult result = null; try { result = customDNS53Client.listResourceRecordSets(req); } catch (AmazonServiceException e) { assertEquals("NoSuchHostedZone", e.getErrorCode()); } System.out.println(result); }
@Test public void listResourceRecordSets2() { ListResourceRecordSetsRequest req = new ListResourceRecordSetsRequest( this.getZoneId(zoneName0)); ListResourceRecordSetsResult result = customDNS53Client .listResourceRecordSets(req); assertNotNull(result); assertNotNull(result.getResourceRecordSets()); assertEquals(true, result.getResourceRecordSets().size() > 0); /* * boolean found = false; for(ResourceRecordSet rrSet : * result.getResourceRecordSets()){ if(rrSet.getName().equals("w2." + * zoneName0) && rrSet.getTTL().equals(300L) && * rrSet.getType().equals("A") && * rrSet.getResourceRecords().get(0).getValue * ().equals("172.31.255.235")){ * if(rrSet.getResourceRecords().get(1).getValue * ().equals("172.31.255.234")){ found = true; } } } assertEquals(true, * found); */ assertEquals(false, result.getIsTruncated()); assertEquals("100", result.getMaxItems()); assertEquals(null, result.getNextRecordIdentifier()); assertEquals(null, result.getNextRecordName()); assertEquals(null, result.getNextRecordType()); System.out.println(result); }
public ListResourceRecordSetsResult listResourceRecordSets(ListResourceRecordSetsRequest req) throws AmazonServiceException, AmazonClientException{ Client c = Client.create(); WebResource r = c.resource(this.serverURL); MultivaluedMap<String, String> paramMap = new MultivaluedMapImpl(); if(req.getStartRecordName() != null){ paramMap.add("name", req.getStartRecordName()); } if(req.getStartRecordType() != null){ paramMap.add("type", req.getStartRecordType()); } if(req.getStartRecordIdentifier() != null){ paramMap.add("identifier", req.getStartRecordIdentifier()); } if(req.getMaxItems() != null){ paramMap.add("maxitems", req.getMaxItems()); } ClientResponse response = r .path(req.getHostedZoneId() + "/rrset") .queryParams(paramMap) .type(MediaType.APPLICATION_XML_TYPE) .accept(MediaType.TEXT_XML) .header("X-Amzn-Authorization", "AWS3 AWSAccessKeyId=" + this.accessKey + "," + "Algorithm=HmacSHA256," + "SignedHeaders=Host;X-Amz-Date," + "Signature=THISISANEXAMPLESIGNATURE=") .get(ClientResponse.class); String resultXml = response.getEntity(String.class); if(response.getStatus() != 200){ exceptionMapper(response, resultXml); } ListResourceRecordSetsResponsePOJO interResult = null; try { StringReader reader = new StringReader(resultXml); JAXBContext context = JAXBContext.newInstance(ListResourceRecordSetsResponsePOJO.class); Unmarshaller unmarshaller = context.createUnmarshaller(); interResult = (ListResourceRecordSetsResponsePOJO) unmarshaller.unmarshal(reader); } catch (JAXBException e) { e.printStackTrace(); return null; } if(interResult == null){ return null; } ListResourceRecordSetsResult result = new ListResourceRecordSetsResult(); result.setMaxItems(interResult.getMaxItems()); result.setIsTruncated(interResult.isTruncated()); if(interResult.getResourceRecordSets() != null){ Collection<ResourceRecordSet> rrSets = new LinkedList<ResourceRecordSet>(); for(ResourceRecordSetPOJO p : interResult.getResourceRecordSets()){ ResourceRecordSet temp = new ResourceRecordSet(); temp.setName(p.getName()); temp.setSetIdentifier(p.getSetIdentifier()); temp.setTTL(p.getTTL()); temp.setType(p.getType()); temp.setWeight(p.getWeight()); if(p.getResourceRecords() != null){ Collection<ResourceRecord> resourceRecords = new LinkedList<ResourceRecord>(); for(ResourceRecordPOJO record : p.getResourceRecords()){ ResourceRecord newRec = new ResourceRecord(); newRec.setValue(record.getValue()); resourceRecords.add(newRec); } temp.setResourceRecords(resourceRecords); } rrSets.add(temp); } result.setResourceRecordSets(rrSets); } return result; }
@Override public String marshall(MarshallStruct<ListResourceRecordSetsResult> input, HttpServletResponse resp) throws Exception { ListResourceRecordSetsResult result = input.getMainObject(); XMLNode response = new XMLNode( DNS53Constants.LISTRESOURCERECORDSETSRESPONSE); response.addAttr(DNS53Constants.XMLNS, DNS53Constants.XMLNS_VALUE); if (result.getResourceRecordSets() != null) { XMLNode rrSet = QueryUtil.addNode(response, DNS53Constants.RESOURCERECORDSETS); for (ResourceRecordSet rrs : result.getResourceRecordSets()) { XMLNode rr = QueryUtil.addNode(rrSet, DNS53Constants.RESOURCERECORDSET); QueryUtil.addNode(rr, DNS53Constants.NAME, rrs.getName()); QueryUtil.addNode(rr, DNS53Constants.TYPE, rrs.getType()); QueryUtil.addNode(rr, DNS53Constants.TTL, rrs.getTTL()); if (rrs.getSetIdentifier() != null) { QueryUtil.addNode(rr, DNS53Constants.SETIDENTIFIER, rrs.getSetIdentifier()); } if (rrs.getWeight() != null && rrs.getWeight() != -1) { QueryUtil.addNode(rr, DNS53Constants.WEIGHT, rrs.getWeight()); } if (rrs.getResourceRecords() != null && rrs.getResourceRecords().size() > 0) { XMLNode records = QueryUtil.addNode(rr, DNS53Constants.RESOURCERECORDS); for (ResourceRecord record : rrs.getResourceRecords()) { XMLNode r = QueryUtil.addNode(records, DNS53Constants.RESOURCERECORD); QueryUtil.addNode(r, DNS53Constants.VALUE, record.getValue()); } } } } QueryUtil.addNode(response, DNS53Constants.ISTRUNCATED, result.getIsTruncated()); QueryUtil.addNode(response, DNS53Constants.MAXITEMS, result.getMaxItems()); if (result.getIsTruncated() && result.getNextRecordName() != null) { QueryUtil.addNode(response, DNS53Constants.NEXTRECORDNAME, result.getNextRecordName()); } if (result.getIsTruncated() && result.getNextRecordType() != null) { QueryUtil.addNode(response, DNS53Constants.NEXTRECORDTYPE, result.getNextRecordType()); } if (result.getIsTruncated() && result.getNextRecordIdentifier() != null) { QueryUtil.addNode(response, DNS53Constants.NEXTRECORDIDENTIFIER, result.getNextRecordIdentifier()); } return response.toString(); }
public ResourceRecordSet findRecord(final String zoneId, final String source) { final ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest(); request.setHostedZoneId(zoneId); final ListResourceRecordSetsResult result = amazonClient .listResourceRecordSets(request); final List<ResourceRecordSet> recordList = result .getResourceRecordSets(); for (final ResourceRecordSet record : recordList) { final String name = record.getName(); if (name.equals(source)) { return record; } } return null; }
public List<String> listZone(final String source) { final List<String> nameList = new LinkedList<String>(); final HostedZone zone = findZone(source); if (zone == null) { return nameList; } final ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest(); request.setHostedZoneId(zone.getId()); while (true) { final ListResourceRecordSetsResult result = amazonClient .listResourceRecordSets(request); final List<ResourceRecordSet> recordList = result .getResourceRecordSets(); for (final ResourceRecordSet record : recordList) { nameList.add(record.getName()); } if (!result.isTruncated()) { break; } request.setStartRecordName(result.getNextRecordName()); } return nameList; }