Search in sources :

Example 41 with SamzaException

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);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) GenericDatumReader(org.apache.avro.generic.GenericDatumReader) IOException(java.io.IOException) AvroFSInput(org.apache.hadoop.fs.AvroFSInput) SamzaException(org.apache.samza.SamzaException)

Example 42 with SamzaException

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);
}
Also used : IOException(java.io.IOException) SamzaException(org.apache.samza.SamzaException)

Example 43 with SamzaException

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);
    }
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) HashMap(java.util.HashMap) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) SystemStreamMetadata(org.apache.samza.system.SystemStreamMetadata) SamzaException(org.apache.samza.SamzaException) NoOpMetricsRegistry(org.apache.samza.util.NoOpMetricsRegistry) MapConfig(org.apache.samza.config.MapConfig) HashSet(java.util.HashSet) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 44 with 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);
    }
}
Also used : StreamProcessor(org.apache.samza.processor.StreamProcessor) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) SamzaException(org.apache.samza.SamzaException) SamzaException(org.apache.samza.SamzaException)

Example 45 with SamzaException

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;
}
Also used : SamzaException(org.apache.samza.SamzaException)

Aggregations

SamzaException (org.apache.samza.SamzaException)58 IOException (java.io.IOException)15 HashMap (java.util.HashMap)9 Config (org.apache.samza.config.Config)6 Test (org.junit.Test)6 Partition (org.apache.samza.Partition)5 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)5 HashSet (java.util.HashSet)4 JobConfig (org.apache.samza.config.JobConfig)4 MapConfig (org.apache.samza.config.MapConfig)4 Map (java.util.Map)3 ExecutionPlan (org.apache.samza.execution.ExecutionPlan)3 IncomingMessageEnvelope (org.apache.samza.system.IncomingMessageEnvelope)3 SystemFactory (org.apache.samza.system.SystemFactory)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 ZkInterruptedException (org.I0Itec.zkclient.exception.ZkInterruptedException)2 Path (org.apache.hadoop.fs.Path)2