From 1eb89be1a8e4fa6ceaac92434b28cad969ff431d Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 11 Oct 2016 17:37:30 +0200 Subject: [PATCH] Update Logging examples, snippets and READMEs to use renamed getters/setters/builders --- README.md | 6 ++-- TESTING.md | 2 +- .../examples/logging/LoggingExample.java | 16 +++++----- .../snippets/CreateAndListMetrics.java | 4 +-- .../logging/snippets/CreateAndListSinks.java | 4 +-- .../logging/snippets/LoggingSnippets.java | 24 +++++++------- .../logging/snippets/MetricSnippets.java | 4 +-- .../logging/snippets/SinkSnippets.java | 4 +-- .../snippets/WriteAndListLogEntries.java | 6 ++-- google-cloud-logging/README.md | 10 +++--- .../com/google/cloud/logging/Logging.java | 32 +++++++++---------- .../java/com/google/cloud/logging/Metric.java | 4 +-- .../java/com/google/cloud/logging/Sink.java | 4 +-- .../google/cloud/logging/package-info.java | 6 ++-- .../cloud/logging/testing/package-info.java | 2 +- 15 files changed, 64 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index c2eea2a7da6a..b597353c6e4e 100644 --- a/README.md +++ b/README.md @@ -412,9 +412,9 @@ import java.util.Iterator; LoggingOptions options = LoggingOptions.defaultInstance(); try(Logging logging = options.service()) { - LogEntry firstEntry = LogEntry.builder(StringPayload.of("message")) - .logName("test-log") - .resource(MonitoredResource.builder("global") + LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message")) + .setLogName("test-log") + .setResource(MonitoredResource.builder("global") .addLabel("project_id", options.projectId()) .build()) .build(); diff --git a/TESTING.md b/TESTING.md index 830f2b72ca78..957b20fe2931 100644 --- a/TESTING.md +++ b/TESTING.md @@ -163,7 +163,7 @@ uses the `RemoteLoggingHelper` to create a metric. ```java RemoteLoggingHelper loggingHelper = RemoteLoggingHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json")); - Logging logging = loggingHelper.options().service(); + Logging logging = loggingHelper.getOptions().service(); // Pick a name for the resource with low probability of clashing String metricName = RemoteLoggingHelper.formatForTest("test-metric"); MetricInfo metricInfo = MetricInfo.of(name, "logName:syslog"); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/LoggingExample.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/LoggingExample.java index f41535bc8afa..3cab8c4dd3de 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/LoggingExample.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/LoggingExample.java @@ -353,9 +353,9 @@ SinkInfo parse(String... args) throws Exception { default: throw new IllegalArgumentException("Second argument must be bucket|dataset|topic."); } - SinkInfo.Builder builder = SinkInfo.builder(name, destination); + SinkInfo.Builder builder = SinkInfo.newBuilder(name, destination); if (args.length == 4) { - builder.filter(args[3]); + builder.setFilter(args[3]); } return builder.build(); } @@ -395,10 +395,10 @@ private static class WriteEntryAction extends LoggingAction { @Override public void run(Logging logging, LogEntry entry) { - MonitoredResource resource = MonitoredResource.builder("global") + MonitoredResource resource = MonitoredResource.newBuilder("global") .addLabel("project_id", logging.options().projectId()) .build(); - LogEntry entryWithResource = entry.toBuilder().resource(resource).build(); + LogEntry entryWithResource = entry.toBuilder().setResource(resource).build(); logging.write(Collections.singleton(entryWithResource)); System.out.printf("Written entry %s%n", entryWithResource); } @@ -416,10 +416,10 @@ LogEntry parse(String... args) throws Exception { for (int i = 3; i < args.length; i += 2) { labels.put(args[i], args[i + 1]); } - return LogEntry.builder(StringPayload.of(message)) - .logName(logName) - .severity(severity) - .labels(labels) + return LogEntry.newBuilder(StringPayload.of(message)) + .setLogName(logName) + .setSeverity(severity) + .setLabels(labels) .build(); } else { throw new IllegalArgumentException("Missing required arguments."); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListMetrics.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListMetrics.java index b32e50725db0..151b5428910b 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListMetrics.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListMetrics.java @@ -39,8 +39,8 @@ public static void main(String... args) throws Exception { try(Logging logging = LoggingOptions.defaultInstance().service()) { // Create a metric - MetricInfo metricInfo = MetricInfo.builder("test-metric", "severity >= ERROR") - .description("Log entries with severity higher or equal to ERROR") + MetricInfo metricInfo = MetricInfo.newBuilder("test-metric", "severity >= ERROR") + .setDescription("Log entries with severity higher or equal to ERROR") .build(); logging.create(metricInfo); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListSinks.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListSinks.java index 2a2f7008c480..cb5b378bd7b5 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListSinks.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListSinks.java @@ -39,8 +39,8 @@ public static void main(String... args) throws Exception { try(Logging logging = LoggingOptions.defaultInstance().service()) { // Create a sink to back log entries to a BigQuery dataset - SinkInfo sinkInfo = SinkInfo.builder("test-sink", DatasetDestination.of("test-dataset")) - .filter("severity >= ERROR") + SinkInfo sinkInfo = SinkInfo.newBuilder("test-sink", DatasetDestination.of("test-dataset")) + .setFilter("severity >= ERROR") .build(); logging.create(sinkInfo); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/LoggingSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/LoggingSnippets.java index 23e32bce2ca7..a4db3bb185fa 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/LoggingSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/LoggingSnippets.java @@ -97,9 +97,9 @@ public Sink createSinkAsync(String sinkName, String datasetName) // [VARIABLE "my_dataset"] public Sink updateSink(String sinkName, String datasetName) { // [START updateSink] - SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName)) - .versionFormat(SinkInfo.VersionFormat.V2) - .filter("severity>=ERROR") + SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)) + .setVersionFormat(SinkInfo.VersionFormat.V2) + .setFilter("severity>=ERROR") .build(); Sink sink = logging.update(sinkInfo); // [END updateSink] @@ -115,9 +115,9 @@ public Sink updateSink(String sinkName, String datasetName) { public Sink updateSinkAsync(String sinkName, String datasetName) throws ExecutionException, InterruptedException { // [START updateSinkAsync] - SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName)) - .versionFormat(SinkInfo.VersionFormat.V2) - .filter("severity>=ERROR") + SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)) + .setVersionFormat(SinkInfo.VersionFormat.V2) + .setFilter("severity>=ERROR") .build(); Future future = logging.updateAsync(sinkInfo); // ... @@ -337,8 +337,8 @@ public Metric createMetricAsync(String metricName) // [VARIABLE "my_metric_name"] public Metric updateMetric(String metricName) { // [START updateMetric] - MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR") - .description("new description") + MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR") + .setDescription("new description") .build(); Metric metric = logging.update(metricInfo); // [END updateMetric] @@ -353,8 +353,8 @@ public Metric updateMetric(String metricName) { public Metric updateMetricAsync(String metricName) throws ExecutionException, InterruptedException { // [START updateMetricAsync] - MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR") - .description("new description") + MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR") + .setDescription("new description") .build(); Future future = logging.updateAsync(metricInfo); // ... @@ -480,7 +480,7 @@ public void write(String logName) { entries.add(LogEntry.of(JsonPayload.of(jsonMap))); logging.write(entries, WriteOption.logName(logName), - WriteOption.resource(MonitoredResource.builder("global").build())); + WriteOption.resource(MonitoredResource.newBuilder("global").build())); // [END write] } @@ -500,7 +500,7 @@ public Future writeAsync(String logName) { Future future = logging.writeAsync( entries, WriteOption.logName(logName), - WriteOption.resource(MonitoredResource.builder("global").build())); + WriteOption.resource(MonitoredResource.newBuilder("global").build())); // [END writeAsync] return future; } diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/MetricSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/MetricSnippets.java index 48c6193c16fb..b986d5206e04 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/MetricSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/MetricSnippets.java @@ -75,7 +75,7 @@ public Metric reloadAsync() throws ExecutionException, InterruptedException { public Metric update() { // [START update] Metric updatedMetric = metric.toBuilder() - .description("A more detailed description") + .setDescription("A more detailed description") .build() .update(); // [END update] @@ -89,7 +89,7 @@ public Metric update() { public Metric updateAsync() throws ExecutionException, InterruptedException { // [START updateAsync] Future future = metric.toBuilder() - .description("A more detailed description") + .setDescription("A more detailed description") .build() .updateAsync(); // ... diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/SinkSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/SinkSnippets.java index 4383d07b4f62..d3896dd5f8f3 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/SinkSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/SinkSnippets.java @@ -75,7 +75,7 @@ public Sink reloadAsync() throws ExecutionException, InterruptedException { public Sink update() { // [START update] Sink updatedSink = sink.toBuilder() - .filter("severity<=ERROR") + .setFilter("severity<=ERROR") .build() .update(); // [END update] @@ -89,7 +89,7 @@ public Sink update() { public Sink updateAsync() throws ExecutionException, InterruptedException { // [START updateAsync] Future future = sink.toBuilder() - .filter("severity<=ERROR") + .setFilter("severity<=ERROR") .build() .updateAsync(); // ... diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java index 69785430891a..cc0b8fe175c8 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java @@ -42,9 +42,9 @@ public static void main(String... args) throws Exception { try(Logging logging = options.service()) { // Create a log entry - LogEntry firstEntry = LogEntry.builder(StringPayload.of("message")) - .logName("test-log") - .resource(MonitoredResource.builder("global") + LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message")) + .setLogName("test-log") + .setResource(MonitoredResource.newBuilder("global") .addLabel("project_id", options.projectId()) .build()) .build(); diff --git a/google-cloud-logging/README.md b/google-cloud-logging/README.md index adb28e74160a..90e302dc5157 100644 --- a/google-cloud-logging/README.md +++ b/google-cloud-logging/README.md @@ -112,8 +112,8 @@ import com.google.cloud.logging.MetricInfo; Then, to create the metric, use the following code: ```java -MetricInfo metricInfo = MetricInfo.builder("test-metric", "severity >= ERROR") - .description("Log entries with severity higher or equal to ERROR") +MetricInfo metricInfo = MetricInfo.newBuilder("test-metric", "severity >= ERROR") + .setDescription("Log entries with severity higher or equal to ERROR") .build(); logging.create(metricInfo); ``` @@ -131,9 +131,9 @@ import java.util.Collections; ``` Then, to write the log entries, use the following code: ```java -LogEntry firstEntry = LogEntry.builder(StringPayload.of("message")) - .logName("test-log") - .resource(MonitoredResource.builder("global") +LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message")) + .setLogName("test-log") + .setResource(MonitoredResource.builder("global") .addLabel("project_id", options.projectId()) .build()) .build(); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java index 2f4b9c0b1cb7..0db8c916d5f8 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java @@ -234,9 +234,9 @@ public static EntryListOption filter(String filter) { *
 {@code
    * String sinkName = "my_sink_name";
    * String datasetName = "my_dataset";
-   * SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName))
-   *     .versionFormat(SinkInfo.VersionFormat.V2)
-   *     .filter("severity>=ERROR")
+   * SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName))
+   *     .setVersionFormat(SinkInfo.VersionFormat.V2)
+   *     .setFilter("severity>=ERROR")
    *     .build();
    * Sink sink = logging.update(sinkInfo);
    * }
@@ -255,9 +255,9 @@ public static EntryListOption filter(String filter) { *
 {@code
    * String sinkName = "my_sink_name";
    * String datasetName = "my_dataset";
-   * SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName))
-   *     .versionFormat(SinkInfo.VersionFormat.V2)
-   *     .filter("severity>=ERROR")
+   * SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName))
+   *     .setVersionFormat(SinkInfo.VersionFormat.V2)
+   *     .setFilter("severity>=ERROR")
    *     .build();
    * Future future = logging.updateAsync(sinkInfo);
    * // ...
@@ -274,7 +274,7 @@ public static EntryListOption filter(String filter) {
    * 
 {@code
    * String sinkName = "my_sink_name";
    * Sink sink = logging.getSink(sinkName);
-   * if (sink != null) {
+   * if (sink == null) {
    *   // sink was not found
    * }
    * }
@@ -293,7 +293,7 @@ public static EntryListOption filter(String filter) { * Future future = logging.getSinkAsync(sinkName); * // ... * Sink sink = future.get(); - * if (sink != null) { + * if (sink == null) { * // sink was not found * } * }
@@ -501,8 +501,8 @@ Future> listMonitoredResourceDescriptorsA *

Example of updating a metric. *

 {@code
    * String metricName = "my_metric_name";
-   * MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR")
-   *     .description("new description")
+   * MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR")
+   *     .setDescription("new description")
    *     .build();
    * Metric metric = logging.update(metricInfo);
    * }
@@ -520,8 +520,8 @@ Future> listMonitoredResourceDescriptorsA *

Example of asynchronously updating a metric. *

 {@code
    * String metricName = "my_metric_name";
-   * MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR")
-   *     .description("new description")
+   * MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR")
+   *     .setDescription("new description")
    *     .build();
    * Future future = logging.updateAsync(metricInfo);
    * // ...
@@ -538,7 +538,7 @@ Future> listMonitoredResourceDescriptorsA
    * 
 {@code
    * String metricName = "my_metric_name";
    * Metric metric = logging.getMetric(metricName);
-   * if (metric != null) {
+   * if (metric == null) {
    *   // metric was not found
    * }
    * }
@@ -557,7 +557,7 @@ Future> listMonitoredResourceDescriptorsA * Future future = logging.getMetricAsync(metricName); * // ... * Metric metric = future.get(); - * if (metric != null) { + * if (metric == null) { * // metric was not found * } * }
@@ -662,7 +662,7 @@ Future> listMonitoredResourceDescriptorsA * entries.add(LogEntry.of(JsonPayload.of(jsonMap))); * logging.write(entries, * WriteOption.logName(logName), - * WriteOption.resource(MonitoredResource.builder("global").build())); + * WriteOption.resource(MonitoredResource.newBuilder("global").build())); * } * */ @@ -688,7 +688,7 @@ Future> listMonitoredResourceDescriptorsA * Future future = logging.writeAsync( * entries, * WriteOption.logName(logName), - * WriteOption.resource(MonitoredResource.builder("global").build())); + * WriteOption.resource(MonitoredResource.newBuilder("global").build())); * } * */ diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java index 22d09a6cdd66..b5a8c85c3976 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java @@ -233,7 +233,7 @@ public Future reloadAsync() { *

Example of updating the metric's information. *

 {@code
    * Metric updatedMetric = metric.toBuilder()
-   *     .description("A more detailed description")
+   *     .setDescription("A more detailed description")
    *     .build()
    *     .update();
    * }
@@ -253,7 +253,7 @@ public Metric update() { *

Example of asynchronously updating the metric's information. *

 {@code
    * Future future = metric.toBuilder()
-   *     .description("A more detailed description")
+   *     .setDescription("A more detailed description")
    *     .build()
    *     .updateAsync();
    * // ...
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java
index 291aea6d022f..4451dc4e8e88 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java
@@ -252,7 +252,7 @@ public Future reloadAsync() {
    * 

Example of updating the sink's information. *

 {@code
    * Sink updatedSink = sink.toBuilder()
-   *     .filter("severity<=ERROR")
+   *     .setFilter("severity<=ERROR")
    *     .build()
    *     .update();
    * }
@@ -272,7 +272,7 @@ public Sink update() { *

Example of asynchronously updating the sink's information. *

 {@code
    * Future future = sink.toBuilder()
-   *     .filter("severity<=ERROR")
+   *     .setFilter("severity<=ERROR")
    *     .build()
    *     .updateAsync();
    * // ...
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java
index 244533e69a21..ab456dc1c615 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java
@@ -25,9 +25,9 @@
  * LoggingOptions options = LoggingOptions.defaultInstance();
  * try(Logging logging = options.service()) {
  *
- *   LogEntry firstEntry = LogEntry.builder(StringPayload.of("message"))
- *       .logName("test-log")
- *       .resource(MonitoredResource.builder("global")
+ *   LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
+ *       .setLogName("test-log")
+ *       .setResource(MonitoredResource.builder("global")
  *           .addLabel("project_id", options.projectId())
  *           .build())
  *       .build();
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java
index 59ac80ff542f..3c765aab6095 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java
@@ -22,7 +22,7 @@
  * 

Before the test: *

 {@code
  * RemoteLoggingHelper helper = RemoteLoggingHelper.create();
- * Logging logging = helper.options().service();
+ * Logging logging = helper.getOptions().service();
  * } 
* *

Format resource names to avoid name clashes: