Search in sources :

Example 1 with SplunkWriteError

use of org.apache.beam.sdk.io.splunk.SplunkWriteError in project DataflowTemplates by GoogleCloudPlatform.

the class GCSToSplunk method run.

/**
 * Runs the pipeline to completion with the specified options.
 *
 * @param options The execution options.
 * @return The pipeline result.
 */
public static PipelineResult run(GCSToSplunkOptions options) {
    Pipeline pipeline = Pipeline.create(options);
    CoderRegistry registry = pipeline.getCoderRegistry();
    registry.registerCoderForClass(SplunkEvent.class, SplunkEventCoder.of());
    registry.registerCoderForType(FAILSAFE_ELEMENT_CODER.getEncodedTypeDescriptor(), FAILSAFE_ELEMENT_CODER);
    PCollectionTuple readCsvTuple = pipeline.apply("Read CSV", readFromCsv(options));
    PCollectionTuple failsafeTransformedLines = readCsvTuple.apply("Convert To JSON", convertToFailsafeAndMaybeApplyUdf(options));
    PCollectionTuple splunkEventTuple = failsafeTransformedLines.get(UDF_OUT).apply("Convert to Splunk Event", convertToSplunkEvent());
    PCollection<SplunkWriteError> wrappedSplunkWriteErrors = splunkEventTuple.get(SPLUNK_EVENT_OUT).apply("Write to Splunk", writeToSplunk(options));
    flattenErrorsAndConvertToString(failsafeTransformedLines.get(UDF_ERROR_OUT), splunkEventTuple.get(SPLUNK_EVENT_ERROR_OUT), wrappedSplunkWriteErrors).apply("Output Errors To GCS", writeErrorsToGCS(options));
    return pipeline.run();
}
Also used : CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry) PCollectionTuple(org.apache.beam.sdk.values.PCollectionTuple) SplunkWriteError(org.apache.beam.sdk.io.splunk.SplunkWriteError) Pipeline(org.apache.beam.sdk.Pipeline)

Example 2 with SplunkWriteError

use of org.apache.beam.sdk.io.splunk.SplunkWriteError in project DataflowTemplates by GoogleCloudPlatform.

the class SplunkWriteErrorCoderTest method testEncodeDecode.

@Test
public void testEncodeDecode() throws IOException {
    String payload = "test-payload";
    String message = "test-message";
    Integer statusCode = 123;
    SplunkWriteError actualError = SplunkWriteError.newBuilder().withPayload(payload).withStatusCode(statusCode).withStatusMessage(message).create();
    SplunkWriteErrorCoder coder = SplunkWriteErrorCoder.of();
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        coder.encode(actualError, bos);
        try (ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray())) {
            SplunkWriteError decodedWriteError = coder.decode(bin);
            assertThat(decodedWriteError).isEqualTo(actualError);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SplunkWriteError(org.apache.beam.sdk.io.splunk.SplunkWriteError) Test(org.junit.Test)

Example 3 with SplunkWriteError

use of org.apache.beam.sdk.io.splunk.SplunkWriteError in project DataflowTemplates by GoogleCloudPlatform.

the class GCSToSplunkTest method testGCSToSplunkConvertWriteErrors.

@Test
public void testGCSToSplunkConvertWriteErrors() {
    // Arrange
    String stringifiedSplunkError = "Payload: test-payload. Error Message: test-message. Splunk write status code: 123.";
    String firstStringifiedFailsafeError = "Payload: world. Error Message: failed!.";
    String secondStringifiedFailsafeError = "Payload: one. Error Message: error!.";
    CoderRegistry coderRegistry = pipeline.getCoderRegistry();
    coderRegistry.registerCoderForType(FAILSAFE_ELEMENT_CODER.getEncodedTypeDescriptor(), FAILSAFE_ELEMENT_CODER);
    SplunkWriteError splunkWriteError = SplunkWriteError.newBuilder().withPayload("test-payload").withStatusCode(123).withStatusMessage("test-message").create();
    PCollection<SplunkWriteError> splunkErrorCollection = pipeline.apply("Add Splunk Errors", Create.of(splunkWriteError).withCoder(SplunkWriteErrorCoder.of()));
    FailsafeElement<String, String> firstFailsafeElement = FailsafeElement.of("hello", "world").setErrorMessage("failed!");
    PCollection<FailsafeElement<String, String>> firstFailsafeElementCollection = pipeline.apply("Add FailsafeElements to First", Create.of(firstFailsafeElement).withCoder(FAILSAFE_ELEMENT_CODER));
    FailsafeElement<String, String> secondFailsafeElement = FailsafeElement.of("another", "one").setErrorMessage("error!");
    PCollection<FailsafeElement<String, String>> secondFailsafeElementCollection = pipeline.apply("Add FailsafeElements to Second", Create.of(secondFailsafeElement).withCoder(FAILSAFE_ELEMENT_CODER));
    // Act
    PCollectionTuple stringifiedErrors = flattenErrorsAndConvertToString(firstFailsafeElementCollection, secondFailsafeElementCollection, splunkErrorCollection);
    // Assert
    PAssert.that(stringifiedErrors.get(COMBINED_ERRORS)).containsInAnyOrder(stringifiedSplunkError, firstStringifiedFailsafeError, secondStringifiedFailsafeError);
    // Execute pipeline
    pipeline.run();
}
Also used : CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry) PCollectionTuple(org.apache.beam.sdk.values.PCollectionTuple) GCSToSplunk.flattenErrorsAndConvertToString(com.google.cloud.teleport.v2.templates.GCSToSplunk.flattenErrorsAndConvertToString) SplunkWriteError(org.apache.beam.sdk.io.splunk.SplunkWriteError) FailsafeElement(com.google.cloud.teleport.v2.values.FailsafeElement) Test(org.junit.Test)

Aggregations

SplunkWriteError (org.apache.beam.sdk.io.splunk.SplunkWriteError)3 CoderRegistry (org.apache.beam.sdk.coders.CoderRegistry)2 PCollectionTuple (org.apache.beam.sdk.values.PCollectionTuple)2 Test (org.junit.Test)2 GCSToSplunk.flattenErrorsAndConvertToString (com.google.cloud.teleport.v2.templates.GCSToSplunk.flattenErrorsAndConvertToString)1 FailsafeElement (com.google.cloud.teleport.v2.values.FailsafeElement)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Pipeline (org.apache.beam.sdk.Pipeline)1