Java 类com.amazonaws.services.route53.model.ListResourceRecordSetsRequest 实例源码

项目:TopStackDNS53    文件:ListResourceRecordSets.java   
public ListResourceRecordSetsRequest unmarshall(HttpServletRequest req) {
    ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest();
    SlashObject so = new SlashObject(req.getPathInfo());
    List<String> paths = so.getList();
    if (paths.size() != 4) {
        throw DNS53Faults.InternalError();
    }
    String zoneId = paths.get(2);
    request.setHostedZoneId(zoneId);

    Map<String, String[]> map = req.getParameterMap();
    String name = QueryUtil.getString(map, "name");
    String type = QueryUtil.getString(map, "type");
    String identifier = QueryUtil.getString(map, "identifier");
    String maxItems = QueryUtil.getString(map, "maxitems");

    request.setStartRecordName(name);
    request.setStartRecordType(type);
    request.setStartRecordIdentifier(identifier);
    request.setMaxItems(maxItems);
    return request;
}
项目:Ec2InstanceStarter    文件:SimpleRecordService.java   
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;
    }
项目:awsroute53    文件:SimpleRecordService.java   
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;
}
项目:route53-dynamic-dns    文件:UpdateDns.java   
/**
 * 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 + "\"");
}
项目:TopStackDNS53    文件:ListResourceRecordSets.java   
@Override
public ListResourceRecordSetsResult process0(Session session,
        HttpServletRequest req, HttpServletResponse resp,
        Map<String, String[]> map) throws Exception {
    ListResourceRecordSetsRequest request = unmarshall(req);
    return listResourceRecordSets(session, request);
}
项目:TopStackDNS53    文件:DNS53IntegrationTest.java   
@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);
}
项目:TopStackDNS53    文件:DNS53IntegrationTest.java   
@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);
}
项目:TopStackDNS53    文件:DNS53IntegrationTest.java   
@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);
}
项目:TopStackDNS53    文件:Route53Test.java   
public static void ListResourceRecordSets(AmazonRoute53Client client) {
    ListResourceRecordSetsRequest req = new ListResourceRecordSetsRequest();
    req.setHostedZoneId("Z6C671E6E1A044F6695AD50EE258D8BAE");
    // req.setMaxItems("1");
    // req.setStartRecordType("NS");
    System.out.println(client.listResourceRecordSets(req));
}
项目:TopStackDNS53    文件:DNS53HostedZonesTest.java   
@Test
public void testListResourceRecordSets(){
    ListResourceRecordSetsRequest req = new ListResourceRecordSetsRequest();
    req.setHostedZoneId("ZB20159C9F447440CA75A34B7AAB1BFFA");
    //req.setStartRecordType("SOA");
    //req.setStartRecordName("example-dkim.com");
    //req.setMaxItems("1");
    this.getRoute53Client().listResourceRecordSets(req);
}
项目:TopStackDNS53    文件:DNS53Client.java   
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;
}
项目:jwrapper-maven-plugin    文件:CarrotRoute53.java   
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;

    }
项目:jwrapper-maven-plugin    文件:CarrotRoute53.java   
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;

    }