Search in sources :

Example 11 with Zone

use of com.google.cloud.dns.Zone in project google-cloud-java by GoogleCloudPlatform.

the class ITDnsTest method testCreateZoneWithOptionsBatch.

@Test
public void testCreateZoneWithOptionsBatch() {
    try {
        DnsBatch batch = DNS.batch();
        DnsBatchResult<Zone> batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.CREATION_TIME));
        batch.submit();
        Zone created = batchResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNotNull(created.getCreationTimeMillis());
        assertNull(created.getDescription());
        assertNull(created.getDnsName());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        batch = DNS.batch();
        batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.DESCRIPTION));
        batch.submit();
        created = batchResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertEquals(ZONE1.getDescription(), created.getDescription());
        assertNull(created.getDnsName());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        batch = DNS.batch();
        batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.DNS_NAME));
        batch.submit();
        created = batchResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertEquals(ZONE1.getDnsName(), created.getDnsName());
        assertNull(created.getDescription());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        batch = DNS.batch();
        batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME));
        batch.submit();
        created = batchResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        batch = DNS.batch();
        batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME_SERVER_SET));
        batch.submit();
        created = batchResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        // we did not set it
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        batch = DNS.batch();
        batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME_SERVERS));
        batch.submit();
        created = batchResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        assertFalse(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        batch = DNS.batch();
        batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.ZONE_ID));
        batch.submit();
        created = batchResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        assertNotNull(created.getNameServers());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNotNull(created.getGeneratedId());
        created.delete();
        batch = DNS.batch();
        batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.ZONE_ID, ZoneField.NAME_SERVERS, ZoneField.NAME_SERVER_SET, ZoneField.DESCRIPTION));
        batch.submit();
        // combination of multiple things
        created = batchResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertEquals(ZONE1.getDescription(), created.getDescription());
        assertFalse(created.getNameServers().isEmpty());
        // we did not set it
        assertNull(created.getNameServerSet());
        assertNotNull(created.getGeneratedId());
    } finally {
        DNS.delete(ZONE1.getName());
    }
}
Also used : Zone(com.google.cloud.dns.Zone) DnsBatch(com.google.cloud.dns.DnsBatch) Test(org.junit.Test)

Example 12 with Zone

use of com.google.cloud.dns.Zone in project google-cloud-java by GoogleCloudPlatform.

the class ITDnsTest method clear.

private static void clear() {
    for (String zoneName : ZONE_NAMES) {
        Zone zone = DNS.getZone(zoneName);
        if (zone != null) {
            /* We wait for all changes to complete before retrieving a list of DNS records to be
        deleted. Waiting is necessary as changes potentially might create more records between
        when the list has been retrieved and executing the subsequent delete operation. */
            Iterator<ChangeRequest> iterator = zone.listChangeRequests().iterateAll().iterator();
            while (iterator.hasNext()) {
                waitForChangeToComplete(zoneName, iterator.next().getGeneratedId());
            }
            Iterator<RecordSet> recordSetIterator = zone.listRecordSets().iterateAll().iterator();
            List<RecordSet> toDelete = new LinkedList<>();
            while (recordSetIterator.hasNext()) {
                RecordSet recordSet = recordSetIterator.next();
                if (!ImmutableList.of(RecordSet.Type.NS, RecordSet.Type.SOA).contains(recordSet.getType())) {
                    toDelete.add(recordSet);
                }
            }
            if (!toDelete.isEmpty()) {
                ChangeRequest deletion = zone.applyChangeRequest(ChangeRequest.newBuilder().setDeletions(toDelete).build());
                waitForChangeToComplete(zone.getName(), deletion.getGeneratedId());
            }
            zone.delete();
        }
    }
}
Also used : Zone(com.google.cloud.dns.Zone) RecordSet(com.google.cloud.dns.RecordSet) ChangeRequest(com.google.cloud.dns.ChangeRequest) LinkedList(java.util.LinkedList)

Example 13 with Zone

use of com.google.cloud.dns.Zone in project google-cloud-java by GoogleCloudPlatform.

the class ITDnsTest method testBatchCombined.

@Test
public void testBatchCombined() {
    // the results are validated in the other test methods
    try {
        DNS.create(ZONE1);
        DnsBatch batch = DNS.batch();
        DnsBatchResult<Zone> zoneResult = batch.getZone(ZONE_NAME1);
        DnsBatchResult<ChangeRequest> changeRequestResult = batch.getChangeRequest(ZONE_NAME1, "0");
        DnsBatchResult<Page<RecordSet>> pageResult = batch.listRecordSets(ZONE_NAME1);
        DnsBatchResult<ProjectInfo> projectResult = batch.getProject();
        assertFalse(zoneResult.completed());
        try {
            zoneResult.get();
            fail("this should be submitted first");
        } catch (IllegalStateException ex) {
        // expected
        }
        batch.submit();
        assertNotNull(zoneResult.get().getCreationTimeMillis());
        assertEquals(ZONE1.getDnsName(), zoneResult.get().getDnsName());
        assertEquals(ZONE1.getDescription(), zoneResult.get().getDescription());
        assertFalse(zoneResult.get().getNameServers().isEmpty());
        // we did not set it
        assertNull(zoneResult.get().getNameServerSet());
        assertNotNull(zoneResult.get().getGeneratedId());
        assertNotNull(projectResult.get().getQuota());
        assertEquals(2, Iterables.size(pageResult.get().getValues()));
        assertNotNull(changeRequestResult.get());
    } finally {
        DNS.delete(ZONE1.getName());
    }
}
Also used : Zone(com.google.cloud.dns.Zone) ProjectInfo(com.google.cloud.dns.ProjectInfo) Page(com.google.api.gax.paging.Page) DnsBatch(com.google.cloud.dns.DnsBatch) ChangeRequest(com.google.cloud.dns.ChangeRequest) Test(org.junit.Test)

Example 14 with Zone

use of com.google.cloud.dns.Zone in project google-cloud-java by GoogleCloudPlatform.

the class ITDnsTest method testListZonesBatch.

@Test
public void testListZonesBatch() {
    try {
        DnsBatch batch = DNS.batch();
        DnsBatchResult<Page<Zone>> result = batch.listZones();
        batch.submit();
        List<Zone> zones = filter(result.get().iterateAll().iterator());
        assertEquals(0, zones.size());
        // some zones exists
        Zone firstZone = DNS.create(ZONE1);
        batch = DNS.batch();
        result = batch.listZones();
        batch.submit();
        zones = filter(result.get().iterateAll().iterator());
        assertEquals(1, zones.size());
        assertEquals(firstZone, zones.get(0));
        Zone created = DNS.create(ZONE_EMPTY_DESCRIPTION);
        batch = DNS.batch();
        result = batch.listZones();
        DnsBatchResult<Page<Zone>> zeroSizeError = batch.listZones(Dns.ZoneListOption.pageSize(0));
        DnsBatchResult<Page<Zone>> negativeSizeError = batch.listZones(Dns.ZoneListOption.pageSize(-1));
        DnsBatchResult<Page<Zone>> okSize = batch.listZones(Dns.ZoneListOption.pageSize(1));
        DnsBatchResult<Page<Zone>> nameError = batch.listZones(Dns.ZoneListOption.dnsName("aaaaa"));
        DnsBatchResult<Page<Zone>> okName = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()));
        DnsBatchResult<Page<Zone>> idResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.ZONE_ID));
        DnsBatchResult<Page<Zone>> timeResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.CREATION_TIME));
        DnsBatchResult<Page<Zone>> dnsNameResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.DNS_NAME));
        DnsBatchResult<Page<Zone>> descriptionResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.DESCRIPTION));
        DnsBatchResult<Page<Zone>> nameServersResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.NAME_SERVERS));
        DnsBatchResult<Page<Zone>> nameServerSetResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.NAME_SERVER_SET));
        DnsBatchResult<Page<Zone>> combinationResult = batch.listZones(Dns.ZoneListOption.fields(ZoneField.ZONE_ID, ZoneField.DESCRIPTION), Dns.ZoneListOption.pageSize(1));
        batch.submit();
        zones = filter(result.get().iterateAll().iterator());
        assertEquals(2, zones.size());
        assertTrue(zones.contains(firstZone));
        assertTrue(zones.contains(created));
        // error in options
        try {
            zeroSizeError.get();
            fail();
        } catch (DnsException ex) {
            // expected
            assertEquals(400, ex.getCode());
            assertFalse(ex.isRetryable());
        }
        try {
            negativeSizeError.get();
            fail();
        } catch (DnsException ex) {
            // expected
            assertEquals(400, ex.getCode());
            assertFalse(ex.isRetryable());
        }
        // ok size
        assertEquals(1, Iterables.size(okSize.get().getValues()));
        // dns name problems
        try {
            nameError.get();
            fail();
        } catch (DnsException ex) {
            // expected
            assertEquals(400, ex.getCode());
            assertFalse(ex.isRetryable());
        }
        // ok name
        zones = filter(okName.get().iterateAll().iterator());
        assertEquals(1, zones.size());
        // field options
        Iterator<Zone> zoneIterator = idResult.get().iterateAll().iterator();
        Zone zone = zoneIterator.next();
        assertNull(zone.getCreationTimeMillis());
        assertNotNull(zone.getName());
        assertNull(zone.getDnsName());
        assertNull(zone.getDescription());
        assertNull(zone.getNameServerSet());
        assertTrue(zone.getNameServers().isEmpty());
        assertNotNull(zone.getGeneratedId());
        assertFalse(zoneIterator.hasNext());
        zoneIterator = timeResult.get().iterateAll().iterator();
        zone = zoneIterator.next();
        assertNotNull(zone.getCreationTimeMillis());
        assertNotNull(zone.getName());
        assertNull(zone.getDnsName());
        assertNull(zone.getDescription());
        assertNull(zone.getNameServerSet());
        assertTrue(zone.getNameServers().isEmpty());
        assertNull(zone.getGeneratedId());
        assertFalse(zoneIterator.hasNext());
        zoneIterator = dnsNameResult.get().iterateAll().iterator();
        zone = zoneIterator.next();
        assertNull(zone.getCreationTimeMillis());
        assertNotNull(zone.getName());
        assertNotNull(zone.getDnsName());
        assertNull(zone.getDescription());
        assertNull(zone.getNameServerSet());
        assertTrue(zone.getNameServers().isEmpty());
        assertNull(zone.getGeneratedId());
        assertFalse(zoneIterator.hasNext());
        zoneIterator = descriptionResult.get().iterateAll().iterator();
        zone = zoneIterator.next();
        assertNull(zone.getCreationTimeMillis());
        assertNotNull(zone.getName());
        assertNull(zone.getDnsName());
        assertNotNull(zone.getDescription());
        assertNull(zone.getNameServerSet());
        assertTrue(zone.getNameServers().isEmpty());
        assertNull(zone.getGeneratedId());
        assertFalse(zoneIterator.hasNext());
        zoneIterator = nameServersResult.get().iterateAll().iterator();
        zone = zoneIterator.next();
        assertNull(zone.getCreationTimeMillis());
        assertNotNull(zone.getName());
        assertNull(zone.getDnsName());
        assertNull(zone.getDescription());
        assertNull(zone.getNameServerSet());
        assertFalse(zone.getNameServers().isEmpty());
        assertNull(zone.getGeneratedId());
        assertFalse(zoneIterator.hasNext());
        zoneIterator = nameServerSetResult.get().iterateAll().iterator();
        zone = zoneIterator.next();
        assertNull(zone.getCreationTimeMillis());
        assertNotNull(zone.getName());
        assertNull(zone.getDnsName());
        assertNull(zone.getDescription());
        // we cannot set it using google-cloud
        assertNull(zone.getNameServerSet());
        assertTrue(zone.getNameServers().isEmpty());
        assertNull(zone.getGeneratedId());
        assertFalse(zoneIterator.hasNext());
        // several combined
        zones = filter(combinationResult.get().iterateAll().iterator());
        assertEquals(2, zones.size());
        for (Zone current : zones) {
            assertNull(current.getCreationTimeMillis());
            assertNotNull(current.getName());
            assertNull(current.getDnsName());
            assertNotNull(current.getDescription());
            assertNull(current.getNameServerSet());
            assertTrue(zone.getNameServers().isEmpty());
            assertNotNull(current.getGeneratedId());
        }
    } finally {
        DNS.delete(ZONE1.getName());
        DNS.delete(ZONE_EMPTY_DESCRIPTION.getName());
    }
}
Also used : DnsException(com.google.cloud.dns.DnsException) Zone(com.google.cloud.dns.Zone) Page(com.google.api.gax.paging.Page) DnsBatch(com.google.cloud.dns.DnsBatch) Test(org.junit.Test)

Example 15 with Zone

use of com.google.cloud.dns.Zone in project google-cloud-java by GoogleCloudPlatform.

the class ITDnsTest method testCreateZoneWithErrorsBatch.

@Test
public void testCreateZoneWithErrorsBatch() {
    try {
        DnsBatch batch = DNS.batch();
        DnsBatchResult<Zone> nameErrorResult = batch.createZone(ZONE_NAME_ERROR);
        DnsBatchResult<Zone> noPeriodResult = batch.createZone(ZONE_DNS_NO_PERIOD);
        batch.submit();
        try {
            nameErrorResult.get();
            fail("Zone name is too long. The service returns an error.");
        } catch (DnsException ex) {
            // expected
            assertFalse(ex.isRetryable());
        }
        try {
            noPeriodResult.get();
            fail("Zone name is missing a period. The service returns an error.");
        } catch (DnsException ex) {
            // expected
            assertFalse(ex.isRetryable());
        }
    } finally {
        DNS.delete(ZONE_NAME_ERROR.getName());
        DNS.delete(ZONE_DNS_NO_PERIOD.getName());
    }
}
Also used : DnsException(com.google.cloud.dns.DnsException) Zone(com.google.cloud.dns.Zone) DnsBatch(com.google.cloud.dns.DnsBatch) Test(org.junit.Test)

Aggregations

Zone (com.google.cloud.dns.Zone)21 Test (org.junit.Test)17 DnsBatch (com.google.cloud.dns.DnsBatch)9 ChangeRequest (com.google.cloud.dns.ChangeRequest)8 DnsException (com.google.cloud.dns.DnsException)6 RecordSet (com.google.cloud.dns.RecordSet)6 Page (com.google.api.gax.paging.Page)3 ChangeRequestInfo (com.google.cloud.dns.ChangeRequestInfo)3 Dns (com.google.cloud.dns.Dns)3 ZoneInfo (com.google.cloud.dns.ZoneInfo)2 LinkedList (java.util.LinkedList)2 ProjectInfo (com.google.cloud.dns.ProjectInfo)1