use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class JsonDecoder method close.
@Override
public void close() {
try {
if (parser != null) {
parser.close();
parser = null;
}
} catch (IOException e) {
// Ensure unexpected errors are still reported to the Flow API
log.error("Unexpected error closing decoder: {}", e.getMessage(), e);
throw new EUnexpected(e);
} finally {
super.close();
}
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class JsonDecoder method decodeChunk.
@Override
protected void decodeChunk(ByteBuf chunk) {
try {
var bytes = new byte[chunk.readableBytes()];
chunk.readBytes(bytes);
parser.feedInput(bytes, 0, bytes.length);
JsonToken token;
while ((token = parser.nextToken()) != JsonToken.NOT_AVAILABLE) parser.acceptToken(token);
} catch (JacksonException e) {
// This exception is a "well-behaved" parse failure, parse location and message should be meaningful
var errorMessage = String.format("JSON decoding failed on line %d: %s", e.getLocation().getLineNr(), e.getOriginalMessage());
log.error(errorMessage, e);
throw new EDataCorruption(errorMessage, e);
} catch (IOException e) {
// Decoders work on a stream of buffers, "real" IO exceptions should not occur
// IO exceptions here indicate parse failures, not file/socket communication errors
// This is likely to be a more "badly-behaved" failure, or at least one that was not anticipated
var errorMessage = "JSON decoding failed, content is garbled: " + e.getMessage();
log.error(errorMessage, e);
throw new EDataCorruption(errorMessage, e);
} catch (Throwable e) {
// Ensure unexpected errors are still reported to the Flow API
log.error("Unexpected error during decoding", e);
throw new EUnexpected(e);
} finally {
chunk.release();
}
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class ArrowFileDecoder method decodeChunk.
@Override
protected void decodeChunk(ByteBuf chunk) {
try (var stream = new ByteSeekableChannel(chunk);
var reader = new ArrowFileReader(stream, arrowAllocator);
var root = reader.getVectorSchemaRoot()) {
var schema = root.getSchema();
emitBlock(DataBlock.forSchema(schema));
var unloader = new VectorUnloader(root);
while (reader.loadNextBatch()) {
var batch = unloader.getRecordBatch();
emitBlock(DataBlock.forRecords(batch));
}
} catch (InvalidArrowFileException e) {
// A nice clean validation failure from the Arrow framework
// E.g. missing / incorrect magic number at the start (or end) of the file
var errorMessage = "Arrow file decoding failed, file is invalid: " + e.getMessage();
log.error(errorMessage, e);
throw new EDataCorruption(errorMessage, e);
} catch (IllegalArgumentException | IndexOutOfBoundsException | IOException e) {
// These errors occur if the data stream contains bad values for vector sizes, offsets etc.
// This may be as a result of a corrupt data stream, or a maliciously crafted message
// Decoders work on a stream of buffers, "real" IO exceptions should not occur
var errorMessage = "Arrow file decoding failed, content is garbled";
log.error(errorMessage, e);
throw new EDataCorruption(errorMessage, e);
} catch (Throwable e) {
// Ensure unexpected errors are still reported to the Flow API
log.error("Unexpected error in Arrow file decoding", e);
throw new EUnexpected(e);
} finally {
chunk.release();
}
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class ArrowSchema method tracToArrow.
public static Schema tracToArrow(SchemaDefinition tracSchema) {
// Unexpected error - TABLE is the only TRAC schema type currently available
if (tracSchema.getSchemaType() != SchemaType.TABLE)
throw new EUnexpected();
var tracTableSchema = tracSchema.getTable();
var arrowFields = new ArrayList<Field>(tracTableSchema.getFieldsCount());
for (var tracField : tracTableSchema.getFieldsList()) {
var fieldName = tracField.getFieldName();
// only business keys are not nullable
var nullable = !tracField.getBusinessKey();
var arrowType = TRAC_ARROW_TYPE_MAPPING.get(tracField.getFieldType());
// Unexpected error - All TRAC primitive types are mapped
if (arrowType == null)
throw new EUnexpected();
var arrowFieldType = new FieldType(nullable, arrowType, /* dictionary = */
null);
var arrowField = new Field(fieldName, arrowFieldType, /* children = */
null);
arrowFields.add(arrowField);
}
return new Schema(arrowFields);
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class ConfigManagerTest method setup.
@BeforeEach
void setup() throws Exception {
plugins = new PluginManager();
plugins.initConfigPlugins();
Files.createDirectory(tempDir.resolve("config_dir"));
for (var sourceFile : CONFIG_SAMPLES) {
var fileName = Paths.get(sourceFile).getFileName();
var targetPath = tempDir.resolve("config_dir").resolve(fileName);
try (var inputStream = getClass().getResourceAsStream(sourceFile);
var outputStream = Files.newOutputStream(targetPath)) {
if (inputStream == null)
throw new EUnexpected();
inputStream.transferTo(outputStream);
}
}
TestConfigPlugin.setCurrentTempDir(tempDir);
}
Aggregations