/** Example of asynchronously updating a sink. */ // [TARGET updateAsync(SinkInfo)] // [VARIABLE "my_sink_name"] // [VARIABLE "my_dataset"] public Sink updateSinkAsync(String sinkName, String datasetName) throws ExecutionException, InterruptedException { // [START updateSinkAsync] SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)) .setVersionFormat(SinkInfo.VersionFormat.V2) .setFilter("severity>=ERROR") .build(); Future<Sink> future = logging.updateAsync(sinkInfo); // ... Sink sink = future.get(); // [END updateSinkAsync] return sink; }
static SinkInfo fromPb(LogSink sinkPb) { Builder builder = newBuilder(sinkPb.getName(), Destination.fromPb(sinkPb.getDestination())) .setVersionFormat(VersionFormat.fromPb(sinkPb.getOutputVersionFormat())); if (!sinkPb.getFilter().equals("")) { builder.setFilter(sinkPb.getFilter()); } return builder.build(); } }
static SinkInfo fromPb(LogSink sinkPb) { Builder builder = newBuilder(sinkPb.getName(), Destination.fromPb(sinkPb.getDestination())) .setVersionFormat(VersionFormat.fromPb(sinkPb.getOutputVersionFormat())); if (!sinkPb.getFilter().equals("")) { builder.setFilter(sinkPb.getFilter()); } return builder.build(); } }
@Test public void testToBuilder() { compareSinkInfo(BUCKET_SINK_INFO, BUCKET_SINK_INFO.toBuilder().build()); compareSinkInfo(DATASET_SINK_INFO, DATASET_SINK_INFO.toBuilder().build()); compareSinkInfo(TOPIC_SINK_INFO, TOPIC_SINK_INFO.toBuilder().build()); SinkInfo updatedSinkInfo = BUCKET_SINK_INFO .toBuilder() .setDestination(TOPIC_DESTINATION) .setName("newName") .setFilter("logName=projects/my-projectid/logs/syslog") .setVersionFormat(VersionFormat.V2) .build(); assertEquals("newName", updatedSinkInfo.getName()); assertEquals(TOPIC_DESTINATION, updatedSinkInfo.getDestination()); assertEquals("logName=projects/my-projectid/logs/syslog", updatedSinkInfo.getFilter()); assertEquals(VersionFormat.V2, updatedSinkInfo.getVersionFormat()); updatedSinkInfo = BUCKET_SINK_INFO .toBuilder() .setDestination(BUCKET_DESTINATION) .setName(NAME) .setFilter(FILTER) .setVersionFormat(VersionFormat.V1) .build(); assertEquals(BUCKET_SINK_INFO, updatedSinkInfo); }
@Test public void testCreateGetUpdateAndDeleteSink() { String name = formatForTest("test-create-get-update-sink"); SinkInfo sinkInfo = SinkInfo.newBuilder(name, DatasetDestination.of("dataset")) .setFilter("severity>=ERROR") .setVersionFormat(SinkInfo.VersionFormat.V2) .build(); Sink sink = logging().create(sinkInfo); assertEquals(name, sink.getName()); assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); assertEquals("severity>=ERROR", sink.getFilter()); DatasetDestination datasetDestination = sink.getDestination(); assertEquals(logging().getOptions().getProjectId(), datasetDestination.getProject()); assertEquals("dataset", datasetDestination.getDataset()); assertEquals(sink, logging().getSink(name)); sink = sink.toBuilder().setFilter("severity<=ERROR").build().update(); assertEquals(name, sink.getName()); assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); assertEquals("severity<=ERROR", sink.getFilter()); assertTrue(sink.delete()); assertFalse(sink.delete()); }
/** Example of updating a sink. */ // [TARGET update(SinkInfo)] // [VARIABLE "my_sink_name"] // [VARIABLE "my_dataset"] public Sink updateSink(String sinkName, String datasetName) { // [START logging_update_sink] SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)) .setVersionFormat(SinkInfo.VersionFormat.V2) .setFilter("severity>=ERROR") .build(); Sink sink = logging.update(sinkInfo); // [END logging_update_sink] return sink; }
@Test public void testUpdateNonExistingSink() { String name = formatForTest("test-update-non-existing-sink"); SinkInfo sinkInfo = SinkInfo.newBuilder(name, DatasetDestination.of("dataset")) .setFilter("severity>=ERROR") .setVersionFormat(SinkInfo.VersionFormat.V2) .build(); assertNull(logging().getSink(name)); thrown.expect(LoggingException.class); thrown.expectMessage("NOT_FOUND"); logging().update(sinkInfo); }