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);
}
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);
}
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 + "'");
}
Aggregations