Search in sources :

Example 1 with SchemaRecordReader

use of org.apache.nifi.repository.schema.SchemaRecordReader in project nifi by apache.

the class EventIdFirstSchemaRecordReader method readHeader.

@Override
@SuppressWarnings("unchecked")
protected synchronized void readHeader(final DataInputStream in, final int serializationVersion) throws IOException {
    verifySerializationVersion(serializationVersion);
    final int eventSchemaLength = in.readInt();
    final byte[] buffer = new byte[eventSchemaLength];
    StreamUtils.fillBuffer(in, buffer);
    try (final ByteArrayInputStream bais = new ByteArrayInputStream(buffer)) {
        schema = RecordSchema.readFrom(bais);
    }
    recordReader = SchemaRecordReader.fromSchema(schema);
    final int headerSchemaLength = in.readInt();
    final byte[] headerSchemaBuffer = new byte[headerSchemaLength];
    StreamUtils.fillBuffer(in, headerSchemaBuffer);
    final RecordSchema headerSchema;
    try (final ByteArrayInputStream bais = new ByteArrayInputStream(headerSchemaBuffer)) {
        headerSchema = RecordSchema.readFrom(bais);
    }
    final SchemaRecordReader headerReader = SchemaRecordReader.fromSchema(headerSchema);
    final Record headerRecord = headerReader.readRecord(in);
    componentIds = (List<String>) headerRecord.getFieldValue(EventIdFirstHeaderSchema.FieldNames.COMPONENT_IDS);
    componentTypes = (List<String>) headerRecord.getFieldValue(EventIdFirstHeaderSchema.FieldNames.COMPONENT_TYPES);
    queueIds = (List<String>) headerRecord.getFieldValue(EventIdFirstHeaderSchema.FieldNames.QUEUE_IDS);
    eventTypes = (List<String>) headerRecord.getFieldValue(EventIdFirstHeaderSchema.FieldNames.EVENT_TYPES);
    firstEventId = (Long) headerRecord.getFieldValue(EventIdFirstHeaderSchema.FieldNames.FIRST_EVENT_ID);
    systemTimeOffset = (Long) headerRecord.getFieldValue(EventIdFirstHeaderSchema.FieldNames.TIMESTAMP_OFFSET);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Record(org.apache.nifi.repository.schema.Record) LookupTableEventRecord(org.apache.nifi.provenance.schema.LookupTableEventRecord) RecordSchema(org.apache.nifi.repository.schema.RecordSchema) SchemaRecordReader(org.apache.nifi.repository.schema.SchemaRecordReader)

Example 2 with SchemaRecordReader

use of org.apache.nifi.repository.schema.SchemaRecordReader in project nifi by apache.

the class SchemaSwapDeserializer method deserializeFlowFiles.

@Override
@SuppressWarnings("unchecked")
public SwapContents deserializeFlowFiles(final DataInputStream in, final String swapLocation, final FlowFileQueue queue, final ResourceClaimManager claimManager) throws IOException {
    final RecordSchema schema = RecordSchema.readFrom(in);
    final SchemaRecordReader reader = SchemaRecordReader.fromSchema(schema);
    final Record parentRecord = reader.readRecord(in);
    final List<Record> flowFileRecords = (List<Record>) parentRecord.getFieldValue(SwapSchema.FLOWFILE_CONTENTS);
    final List<FlowFileRecord> flowFiles = new ArrayList<>(flowFileRecords.size());
    for (final Record record : flowFileRecords) {
        flowFiles.add(FlowFileRecordFieldMap.getFlowFile(record, claimManager));
    }
    final Record summaryRecord = (Record) parentRecord.getFieldValue(SwapSchema.SWAP_SUMMARY);
    final SwapSummary swapSummary = SwapSummaryFieldMap.getSwapSummary(summaryRecord, claimManager);
    return new StandardSwapContents(swapSummary, flowFiles);
}
Also used : ArrayList(java.util.ArrayList) SwapSummary(org.apache.nifi.controller.repository.SwapSummary) Record(org.apache.nifi.repository.schema.Record) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) ArrayList(java.util.ArrayList) List(java.util.List) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) RecordSchema(org.apache.nifi.repository.schema.RecordSchema) SchemaRecordReader(org.apache.nifi.repository.schema.SchemaRecordReader)

Example 3 with SchemaRecordReader

use of org.apache.nifi.repository.schema.SchemaRecordReader in project nifi by apache.

the class SchemaRepositoryRecordSerde method deserializeRecord.

@Override
public RepositoryRecord deserializeRecord(final DataInputStream in, final int version) throws IOException {
    final SchemaRecordReader reader = SchemaRecordReader.fromSchema(recoverySchema);
    final Record updateRecord = reader.readRecord(in);
    if (updateRecord == null) {
        // null may be returned by reader.readRecord() if it encounters end-of-stream
        return null;
    }
    // Top level is always going to be a "Repository Record Update" record because we need a 'Union' type record at the
    // top level that indicates which type of record we have.
    final Record record = (Record) updateRecord.getFieldValue(RepositoryRecordSchema.REPOSITORY_RECORD_UPDATE_V2);
    final String actionType = (String) record.getFieldValue(RepositoryRecordSchema.ACTION_TYPE_FIELD);
    final RepositoryRecordType recordType = RepositoryRecordType.valueOf(actionType);
    switch(recordType) {
        case CREATE:
            return createRecord(record);
        case CONTENTMISSING:
        case DELETE:
            return deleteRecord(record);
        case SWAP_IN:
            return swapInRecord(record);
        case SWAP_OUT:
            return swapOutRecord(record);
        case UPDATE:
            return updateRecord(record);
    }
    throw new IOException("Found unrecognized Update Type '" + actionType + "'");
}
Also used : Record(org.apache.nifi.repository.schema.Record) IOException(java.io.IOException) SchemaRecordReader(org.apache.nifi.repository.schema.SchemaRecordReader)

Aggregations

Record (org.apache.nifi.repository.schema.Record)3 SchemaRecordReader (org.apache.nifi.repository.schema.SchemaRecordReader)3 RecordSchema (org.apache.nifi.repository.schema.RecordSchema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FlowFileRecord (org.apache.nifi.controller.repository.FlowFileRecord)1 SwapSummary (org.apache.nifi.controller.repository.SwapSummary)1 LookupTableEventRecord (org.apache.nifi.provenance.schema.LookupTableEventRecord)1