Search in sources :

Example 1 with PageImpl

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

the class DnsImpl method listRecordSets.

private static Page<RecordSet> listRecordSets(final String zoneName, final DnsOptions serviceOptions, final Map<DnsRpc.Option, ?> optionsMap) {
    try {
        // get a list of record sets
        final DnsRpc rpc = serviceOptions.getDnsRpcV1();
        DnsRpc.ListResult<ResourceRecordSet> result = runWithRetries(new Callable<DnsRpc.ListResult<ResourceRecordSet>>() {

            @Override
            public DnsRpc.ListResult<ResourceRecordSet> call() {
                return rpc.listRecordSets(zoneName, optionsMap);
            }
        }, serviceOptions.getRetrySettings(), EXCEPTION_HANDLER, serviceOptions.getClock());
        String cursor = result.pageToken();
        // transform that list into record sets
        Iterable<RecordSet> recordSets = result.results() == null ? ImmutableList.<RecordSet>of() : Iterables.transform(result.results(), RecordSet.FROM_PB_FUNCTION);
        return new PageImpl<>(new RecordSetPageFetcher(zoneName, serviceOptions, cursor, optionsMap), cursor, recordSets);
    } catch (RetryHelper.RetryHelperException e) {
        throw DnsException.translateAndThrow(e);
    }
}
Also used : ResourceRecordSet(com.google.api.services.dns.model.ResourceRecordSet) PageImpl(com.google.cloud.PageImpl) RetryHelper(com.google.cloud.RetryHelper) DnsRpc(com.google.cloud.dns.spi.v1.DnsRpc) ResourceRecordSet(com.google.api.services.dns.model.ResourceRecordSet)

Example 2 with PageImpl

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

the class DnsImpl method listZones.

private static Page<Zone> listZones(final DnsOptions serviceOptions, final Map<DnsRpc.Option, ?> optionsMap) {
    try {
        // get a list of managed zones
        final DnsRpc rpc = serviceOptions.getDnsRpcV1();
        DnsRpc.ListResult<ManagedZone> result = runWithRetries(new Callable<DnsRpc.ListResult<ManagedZone>>() {

            @Override
            public DnsRpc.ListResult<ManagedZone> call() {
                return rpc.listZones(optionsMap);
            }
        }, serviceOptions.getRetrySettings(), EXCEPTION_HANDLER, serviceOptions.getClock());
        String cursor = result.pageToken();
        // transform that list into zone objects
        Iterable<Zone> zones = result.results() == null ? ImmutableList.<Zone>of() : Iterables.transform(result.results(), zoneFromPb(serviceOptions));
        return new PageImpl<>(new ZonePageFetcher(serviceOptions, cursor, optionsMap), cursor, zones);
    } catch (RetryHelper.RetryHelperException e) {
        throw DnsException.translateAndThrow(e);
    }
}
Also used : PageImpl(com.google.cloud.PageImpl) RetryHelper(com.google.cloud.RetryHelper) ManagedZone(com.google.api.services.dns.model.ManagedZone) DnsRpc(com.google.cloud.dns.spi.v1.DnsRpc) ManagedZone(com.google.api.services.dns.model.ManagedZone)

Example 3 with PageImpl

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

the class DnsImpl method listChangeRequests.

private static Page<ChangeRequest> listChangeRequests(final String zoneName, final DnsOptions serviceOptions, final Map<DnsRpc.Option, ?> optionsMap) {
    try {
        // get a list of changes
        final DnsRpc rpc = serviceOptions.getDnsRpcV1();
        DnsRpc.ListResult<Change> result = runWithRetries(new Callable<DnsRpc.ListResult<Change>>() {

            @Override
            public DnsRpc.ListResult<Change> call() {
                return rpc.listChangeRequests(zoneName, optionsMap);
            }
        }, serviceOptions.getRetrySettings(), EXCEPTION_HANDLER, serviceOptions.getClock());
        String cursor = result.pageToken();
        // transform that list into change request objects
        Iterable<ChangeRequest> changes = result.results() == null ? ImmutableList.<ChangeRequest>of() : Iterables.transform(result.results(), ChangeRequest.fromPbFunction(serviceOptions.getService(), zoneName));
        return new PageImpl<>(new ChangeRequestPageFetcher(zoneName, serviceOptions, cursor, optionsMap), cursor, changes);
    } catch (RetryHelper.RetryHelperException e) {
        throw DnsException.translateAndThrow(e);
    }
}
Also used : PageImpl(com.google.cloud.PageImpl) RetryHelper(com.google.cloud.RetryHelper) Change(com.google.api.services.dns.model.Change) DnsRpc(com.google.cloud.dns.spi.v1.DnsRpc)

Aggregations

PageImpl (com.google.cloud.PageImpl)3 RetryHelper (com.google.cloud.RetryHelper)3 DnsRpc (com.google.cloud.dns.spi.v1.DnsRpc)3 Change (com.google.api.services.dns.model.Change)1 ManagedZone (com.google.api.services.dns.model.ManagedZone)1 ResourceRecordSet (com.google.api.services.dns.model.ResourceRecordSet)1