use of org.apache.samza.SamzaException in project samza by apache.
the class AvroFileHdfsReader method open.
@Override
public void open(String pathStr, String singleFileOffset) {
LOG.info(String.format("%s: Open file [%s] with file offset [%s] for read", systemStreamPartition, pathStr, singleFileOffset));
Path path = new Path(pathStr);
try {
AvroFSInput input = new AvroFSInput(FileContext.getFileContext(path.toUri()), path);
fileReader = new DataFileReader<>(input, new GenericDatumReader<>());
seek(singleFileOffset);
} catch (IOException e) {
throw new SamzaException(e);
}
}
use of org.apache.samza.SamzaException in project samza by apache.
the class AvroFileHdfsReader method close.
@Override
public void close() {
LOG.info("About to close file reader for " + systemStreamPartition);
try {
fileReader.close();
} catch (IOException e) {
throw new SamzaException(e);
}
LOG.info("File reader closed for " + systemStreamPartition);
}
use of org.apache.samza.SamzaException in project samza by apache.
the class TestHdfsSystemConsumer method testEmptyStagingDirectory.
/*
* Ensure that empty staging directory will not break system admin,
* but should fail system consumer
*/
@Test
public void testEmptyStagingDirectory() throws Exception {
Map<String, String> configMap = new HashMap<>();
configMap.put(String.format(HdfsConfig.CONSUMER_PARTITIONER_WHITELIST(), SYSTEM_NAME), ".*avro");
Config config = new MapConfig(configMap);
HdfsSystemFactory systemFactory = new HdfsSystemFactory();
// create admin and do partitioning
HdfsSystemAdmin systemAdmin = systemFactory.getAdmin(SYSTEM_NAME, config);
String stream = WORKING_DIRECTORY;
Set<String> streamNames = new HashSet<>();
streamNames.add(stream);
generateAvroDataFiles();
Map<String, SystemStreamMetadata> streamMetadataMap = systemAdmin.getSystemStreamMetadata(streamNames);
SystemStreamMetadata systemStreamMetadata = streamMetadataMap.get(stream);
Assert.assertEquals(NUM_FILES, systemStreamMetadata.getSystemStreamPartitionMetadata().size());
// create consumer and read from files
HdfsSystemConsumer systemConsumer = systemFactory.getConsumer(SYSTEM_NAME, config, new NoOpMetricsRegistry());
Partition partition = new Partition(0);
SystemStreamPartition ssp = new SystemStreamPartition(SYSTEM_NAME, stream, partition);
try {
systemConsumer.register(ssp, "0");
Assert.fail("Empty staging directory should fail system consumer");
} catch (UncheckedExecutionException e) {
Assert.assertTrue(e.getCause() instanceof SamzaException);
}
}
use of org.apache.samza.SamzaException in project samza by apache.
the class LocalApplicationRunner method run.
@Override
public void run(StreamApplication app) {
try {
// 1. initialize and plan
ExecutionPlan plan = getExecutionPlan(app);
writePlanJsonFile(plan.getPlanAsJson());
// 2. create the necessary streams
createStreams(plan.getIntermediateStreams());
// 3. create the StreamProcessors
if (plan.getJobConfigs().isEmpty()) {
throw new SamzaException("No jobs to run.");
}
plan.getJobConfigs().forEach(jobConfig -> {
log.debug("Starting job {} StreamProcessor with config {}", jobConfig.getName(), jobConfig);
LocalStreamProcessorLifeCycleListener listener = new LocalStreamProcessorLifeCycleListener();
StreamProcessor processor = createStreamProcessor(jobConfig, app, listener);
listener.setProcessor(processor);
processors.add(processor);
});
numProcessorsToStart.set(processors.size());
// 4. start the StreamProcessors
processors.forEach(StreamProcessor::start);
} catch (Exception e) {
throw new SamzaException("Failed to start application", e);
}
}
use of org.apache.samza.SamzaException in project samza by apache.
the class ScriptRunner method waitForExitValue.
/**
* Waits for a finite time interval for the script to complete.
*
* @param p the process on which this method will wait.
* @return the exit code returned by the process.
* @throws InterruptedException if the thread is interrupted while waiting for the process to finish.
*/
private int waitForExitValue(final Process p) throws InterruptedException {
log.debug("Waiting for the exit value for process {}", p);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
p.waitFor();
} catch (InterruptedException ignore) {
return;
}
}
});
t.start();
try {
t.join(TimeUnit.MILLISECONDS.convert(getScriptTimeoutS(), TimeUnit.SECONDS));
} catch (InterruptedException e) {
t.interrupt();
throw new SamzaException("Timeout running shell command", e);
}
int exitVal = p.exitValue();
log.debug("Exit value {}", exitVal);
return exitVal;
}
Aggregations