Skip to content

Commit 17442b0

Browse files
committed
Merge pull request #750 from mderka/readme
README was added for DNS and the main README was updated accordingly.
2 parents 736b6e1 + f7f4de8 commit 17442b0

File tree

8 files changed

+688
-24
lines changed

8 files changed

+688
-24
lines changed

README.md

+73-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This client supports the following Google Cloud Platform services:
1616

1717
- [Google Cloud BigQuery] (#google-cloud-bigquery-alpha) (Alpha)
1818
- [Google Cloud Datastore] (#google-cloud-datastore)
19+
- [Google Cloud DNS] (#google-cloud-dns-alpha) (Alpha)
1920
- [Google Cloud Resource Manager] (#google-cloud-resource-manager-alpha) (Alpha)
2021
- [Google Cloud Storage] (#google-cloud-storage)
2122

@@ -48,8 +49,10 @@ Example Applications
4849
- Read more about using this application on the [`BigQueryExample` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/bigquery/BigQueryExample.html).
4950
- [`Bookshelf`](https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/bookshelf) - An App Engine app that manages a virtual bookshelf.
5051
- This app uses `gcloud-java` to interface with Cloud Datastore and Cloud Storage. It also uses Cloud SQL, another Google Cloud Platform service.
51-
- [`DatastoreExample`](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/datastore/DatastoreExample.java) - A simple command line interface for the Cloud Datastore
52+
- [`DatastoreExample`](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/datastore/DatastoreExample.java) - A simple command line interface for Cloud Datastore
5253
- Read more about using this application on the [`DatastoreExample` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/datastore/DatastoreExample.html).
54+
- [`DnsExample`](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/DnsExample.java) - A simple command line interface for Cloud DNS
55+
- Read more about using this application on the [`DnsExample` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/dns/DnsExample.html).
5356
- [`ResourceManagerExample`](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/resourcemanager/ResourceManagerExample.java) - A simple command line interface providing some of Cloud Resource Manager's functionality
5457
- Read more about using this application on the [`ResourceManagerExample` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/resourcemanager/ResourceManagerExample.html).
5558
- [`SparkDemo`](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/managed_vms/sparkjava) - An example of using gcloud-java-datastore from within the SparkJava and App Engine Managed VM frameworks.
@@ -218,6 +221,71 @@ if (entity != null) {
218221
}
219222
```
220223
224+
Google Cloud DNS (Alpha)
225+
----------------------
226+
- [API Documentation][dns-api]
227+
- [Official Documentation][cloud-dns-docs]
228+
229+
*Follow the [activation instructions][cloud-dns-activation] to use the Google Cloud DNS API with your project.*
230+
231+
#### Preview
232+
233+
Here are two code snippets showing simple usage examples from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
234+
235+
The first snippet shows how to create a zone resource. Complete source code can be found on
236+
[CreateZone.java](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/CreateZone.java).
237+
238+
```java
239+
import com.google.gcloud.dns.Dns;
240+
import com.google.gcloud.dns.DnsOptions;
241+
import com.google.gcloud.dns.Zone;
242+
import com.google.gcloud.dns.ZoneInfo;
243+
244+
Dns dns = DnsOptions.defaultInstance().service();
245+
String zoneName = "my-unique-zone";
246+
String domainName = "someexampledomain.com.";
247+
String description = "This is a gcloud-java-dns sample zone.";
248+
ZoneInfo zoneInfo = ZoneInfo.of(zoneName, domainName, description);
249+
Zone zone = dns.create(zoneInfo);
250+
```
251+
252+
The second snippet shows how to create records inside a zone. The complete code can be found on [CreateOrUpdateDnsRecords.java](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/CreateOrUpdateDnsRecords.java).
253+
254+
```java
255+
import com.google.gcloud.dns.ChangeRequest;
256+
import com.google.gcloud.dns.Dns;
257+
import com.google.gcloud.dns.DnsOptions;
258+
import com.google.gcloud.dns.DnsRecord;
259+
import com.google.gcloud.dns.Zone;
260+
261+
import java.util.Iterator;
262+
import java.util.concurrent.TimeUnit;
263+
264+
Dns dns = DnsOptions.defaultInstance().service();
265+
String zoneName = "my-unique-zone";
266+
Zone zone = dns.getZone(zoneName);
267+
String ip = "12.13.14.15";
268+
DnsRecord toCreate = DnsRecord.builder("www.someexampledomain.com.", DnsRecord.Type.A)
269+
.ttl(24, TimeUnit.HOURS)
270+
.addRecord(ip)
271+
.build();
272+
ChangeRequest.Builder changeBuilder = ChangeRequest.builder().add(toCreate);
273+
274+
// Verify that the record does not exist yet.
275+
// If it does exist, we will overwrite it with our prepared record.
276+
Iterator<DnsRecord> recordIterator = zone.listDnsRecords().iterateAll();
277+
while (recordIterator.hasNext()) {
278+
DnsRecord current = recordIterator.next();
279+
if (toCreate.name().equals(current.name()) &&
280+
toCreate.type().equals(current.type())) {
281+
changeBuilder.delete(current);
282+
}
283+
}
284+
285+
ChangeRequest changeRequest = changeBuilder.build();
286+
zone.applyChangeRequest(changeRequest);
287+
```
288+
221289
Google Cloud Resource Manager (Alpha)
222290
----------------------
223291
@@ -359,6 +427,10 @@ Apache 2.0 - See [LICENSE] for more information.
359427
[cloud-datastore-activation]: https://cloud.google.com/datastore/docs/activate
360428
[datastore-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/datastore/package-summary.html
361429
430+
[dns-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/dns/package-summary.html
431+
[cloud-dns-docs]: https://cloud.google.com/dns/docs
432+
[cloud-dns-activation]: https://console.cloud.google.com/start/api?id=dns
433+
362434
[cloud-pubsub]: https://cloud.google.com/pubsub/
363435
[cloud-pubsub-docs]: https://cloud.google.com/pubsub/docs
364436

0 commit comments

Comments
 (0)