Search in sources :

Example 1 with Sink

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

the class ITLoggingSnippets method testSink.

@Test
public void testSink() throws ExecutionException, InterruptedException {
    String sinkName1 = RemoteLoggingHelper.formatForTest("sink_name1");
    String sinkName2 = RemoteLoggingHelper.formatForTest("sink_name2");
    Sink sink1 = loggingSnippets.createSink(sinkName1, DATASET);
    Sink sink2 = loggingSnippets.createSinkAsync(sinkName2, DATASET);
    assertNotNull(sink1);
    assertNotNull(sink2);
    sink1 = loggingSnippets.getSink(sinkName1);
    sink2 = loggingSnippets.getSinkAsync(sinkName2);
    assertNotNull(sink1);
    assertNotNull(sink2);
    sink1 = loggingSnippets.updateSink(sinkName1, DATASET);
    sink2 = loggingSnippets.updateSinkAsync(sinkName2, DATASET);
    Set<Sink> sinks = Sets.newHashSet(loggingSnippets.listSinks().iterateAll());
    while (!sinks.contains(sink1) || !sinks.contains(sink2)) {
        Thread.sleep(500);
        sinks = Sets.newHashSet(loggingSnippets.listSinks().iterateAll());
    }
    sinks = Sets.newHashSet(loggingSnippets.listSinksAsync().iterateAll());
    while (!sinks.contains(sink1) || !sinks.contains(sink2)) {
        Thread.sleep(500);
        sinks = Sets.newHashSet(loggingSnippets.listSinksAsync().iterateAll());
    }
    assertTrue(loggingSnippets.deleteSink(sinkName1));
    assertTrue(loggingSnippets.deleteSinkAsync(sinkName2));
}
Also used : Sink(com.google.cloud.logging.Sink) Test(org.junit.Test)

Example 2 with Sink

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

the class ITSinkSnippets method testSink.

@Test
public void testSink() throws InterruptedException, ExecutionException {
    Sink sink = sinkSnippets.reload();
    assertNotNull(sink);
    Sink updatedSink = sinkSnippets.update();
    assertEquals(UPDATED_SINK_FILTER, updatedSink.getFilter());
    updatedSink = sinkSnippets.reloadAsync();
    assertNotNull(updatedSink);
    assertEquals(UPDATED_SINK_FILTER, updatedSink.getFilter());
    sink.update();
    updatedSink = sinkSnippets.updateAsync();
    assertEquals(UPDATED_SINK_FILTER, updatedSink.getFilter());
    assertTrue(sinkSnippets.delete());
    assertFalse(sinkSnippets.deleteAsync());
}
Also used : Sink(com.google.cloud.logging.Sink) Test(org.junit.Test)

Example 3 with Sink

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

the class CreateAndListSinks method main.

public static void main(String... args) throws Exception {
    // Credentials are inferred from the environment
    try (Logging logging = LoggingOptions.getDefaultInstance().getService()) {
        // Create a sink to back log entries to a BigQuery dataset
        SinkInfo sinkInfo = SinkInfo.newBuilder("test-sink", DatasetDestination.of("test-dataset")).setFilter("severity >= ERROR").build();
        logging.create(sinkInfo);
        // List sinks
        Page<Sink> sinks = logging.listSinks();
        for (Sink sink : sinks.iterateAll()) {
            System.out.println(sink);
        }
    }
}
Also used : Logging(com.google.cloud.logging.Logging) Sink(com.google.cloud.logging.Sink) SinkInfo(com.google.cloud.logging.SinkInfo)

Example 4 with Sink

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

the class SinkSnippets method reloadAsync.

/**
   * Example of asynchronously getting the sink's latest information.
   */
// [TARGET reloadAsync()]
public Sink reloadAsync() throws ExecutionException, InterruptedException {
    // [START reloadAsync]
    Future<Sink> future = sink.reloadAsync();
    // ...
    Sink latestSink = future.get();
    if (latestSink == null) {
    // the sink was not found
    }
    // [END reloadAsync]
    return latestSink;
}
Also used : Sink(com.google.cloud.logging.Sink)

Example 5 with Sink

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

the class SinkSnippets method updateAsync.

/**
   * Example of asynchronously updating the sink's information.
   */
// [TARGET updateAsync()]
public Sink updateAsync() throws ExecutionException, InterruptedException {
    // [START updateAsync]
    Future<Sink> future = sink.toBuilder().setFilter("severity<=ERROR").build().updateAsync();
    // ...
    Sink updatedSink = future.get();
    // [END updateAsync]
    return updatedSink;
}
Also used : Sink(com.google.cloud.logging.Sink)

Aggregations

Sink (com.google.cloud.logging.Sink)11 SinkInfo (com.google.cloud.logging.SinkInfo)5 Test (org.junit.Test)2 AsyncPage (com.google.api.gax.paging.AsyncPage)1 Logging (com.google.cloud.logging.Logging)1