Search in sources :

Example 16 with RecordWithMetadata

use of org.apache.gobblin.type.RecordWithMetadata in project incubator-gobblin by apache.

the class RecordWithMetadataSchemaRegistrationConverter method convertRecord.

@Override
public Iterable<RecordWithMetadata<?>> convertRecord(String outputSchema, RecordWithMetadata<?> inputRecord, WorkUnitState workUnit) throws DataConversionException {
    Preconditions.checkNotNull(schemaId);
    Metadata metadata = inputRecord.getMetadata();
    metadata.getGlobalMetadata().setContentType(CONTENT_TYPE);
    metadata.getRecordMetadata().put(SCHEMA_ID_KEY, schemaId);
    return Collections.singleton(new RecordWithMetadata<>(inputRecord.getRecord(), metadata));
}
Also used : Metadata(org.apache.gobblin.metadata.types.Metadata) RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata)

Example 17 with RecordWithMetadata

use of org.apache.gobblin.type.RecordWithMetadata in project incubator-gobblin by apache.

the class SerializedRecordToEncryptedSerializedRecordConverterTest method setUp.

@BeforeTest
public void setUp() {
    workUnitState = new WorkUnitState();
    converter = new SerializedRecordToEncryptedSerializedRecordConverter();
    sampleRecord = new RecordWithMetadata<>(new byte[] { 'a', 'b', 'c', 'd' }, new Metadata());
    shiftedValue = new byte[] { 'b', 'c', 'd', 'e' };
    insecureShiftTag = InsecureShiftCodec.TAG;
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Metadata(org.apache.gobblin.metadata.types.Metadata) RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata) BeforeTest(org.testng.annotations.BeforeTest)

Example 18 with RecordWithMetadata

use of org.apache.gobblin.type.RecordWithMetadata in project incubator-gobblin by apache.

the class EncryptedSerializedRecordToSerializedRecordConverterBase method convertRecord.

@Override
public Iterable<RecordWithMetadata<byte[]>> convertRecord(String outputSchema, RecordWithMetadata<byte[]> inputRecord, WorkUnitState workUnit) throws DataConversionException {
    try {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(inputRecord.getRecord());
        byte[] decryptedBytes;
        try (InputStream decryptedInputStream = decryptor.decodeInputStream(inputStream)) {
            decryptedBytes = IOUtils.toByteArray(decryptedInputStream);
        }
        inputRecord.getMetadata().getGlobalMetadata().addTransferEncoding(decryptor.getTag());
        RecordWithMetadata<byte[]> serializedRecord = new RecordWithMetadata<byte[]>(decryptedBytes, inputRecord.getMetadata());
        return Collections.singleton(serializedRecord);
    } catch (Exception e) {
        throw new DataConversionException(e);
    }
}
Also used : RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 19 with RecordWithMetadata

use of org.apache.gobblin.type.RecordWithMetadata in project incubator-gobblin by apache.

the class SerializedRecordToEncryptedSerializedRecordConverterBase method convertRecord.

@Override
public Iterable<RecordWithMetadata<byte[]>> convertRecord(String outputSchema, RecordWithMetadata<byte[]> inputRecord, WorkUnitState workUnit) throws DataConversionException {
    try {
        ByteArrayOutputStream bOs = new ByteArrayOutputStream();
        try (OutputStream encryptedStream = encryptor.encodeOutputStream(bOs)) {
            encryptedStream.write(inputRecord.getRecord());
        }
        inputRecord.getMetadata().getGlobalMetadata().addTransferEncoding(encryptor.getTag());
        RecordWithMetadata<byte[]> serializedRecord = new RecordWithMetadata<byte[]>(bOs.toByteArray(), inputRecord.getMetadata());
        return Collections.singleton(serializedRecord);
    } catch (Exception e) {
        throw new DataConversionException(e);
    }
}
Also used : RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

RecordWithMetadata (org.apache.gobblin.type.RecordWithMetadata)19 Metadata (org.apache.gobblin.metadata.types.Metadata)13 Test (org.testng.annotations.Test)11 JsonNode (org.codehaus.jackson.JsonNode)7 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)6 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)6 HashMap (java.util.HashMap)3 GlobalMetadata (org.apache.gobblin.metadata.types.GlobalMetadata)3 BeforeTest (org.testng.annotations.BeforeTest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 JsonParser (org.codehaus.jackson.JsonParser)1