Search in sources :

Example 1 with SamzaException

use of org.apache.samza.SamzaException in project samza by apache.

the class ClusterBasedJobCoordinator method main.

/**
   * The entry point for the {@link ClusterBasedJobCoordinator}
   * @param args args
   */
public static void main(String[] args) {
    Config coordinatorSystemConfig = null;
    final String coordinatorSystemEnv = System.getenv(ShellCommandConfig.ENV_COORDINATOR_SYSTEM_CONFIG());
    try {
        //Read and parse the coordinator system config.
        log.info("Parsing coordinator system config {}", coordinatorSystemEnv);
        coordinatorSystemConfig = new MapConfig(SamzaObjectMapper.getObjectMapper().readValue(coordinatorSystemEnv, Config.class));
    } catch (IOException e) {
        log.error("Exception while reading coordinator stream config {}", e);
        throw new SamzaException(e);
    }
    ClusterBasedJobCoordinator jc = new ClusterBasedJobCoordinator(coordinatorSystemConfig);
    jc.run();
}
Also used : ClusterManagerConfig(org.apache.samza.config.ClusterManagerConfig) ShellCommandConfig(org.apache.samza.config.ShellCommandConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MapConfig(org.apache.samza.config.MapConfig) IOException(java.io.IOException) SamzaException(org.apache.samza.SamzaException)

Example 2 with SamzaException

use of org.apache.samza.SamzaException in project samza by apache.

the class TestSamzaContainerExceptionHandler method testExceptionHandler.

@Test
public void testExceptionHandler() {
    final AtomicBoolean exitCalled = new AtomicBoolean(false);
    Thread.UncaughtExceptionHandler exceptionHandler = new SamzaContainerExceptionHandler(() -> exitCalled.getAndSet(true));
    exceptionHandler.uncaughtException(Thread.currentThread(), new SamzaException());
    assertTrue(exitCalled.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SamzaException(org.apache.samza.SamzaException) Test(org.junit.Test)

Example 3 with SamzaException

use of org.apache.samza.SamzaException in project samza by apache.

the class DirectoryPartitioner method validateAndGetOriginalFilteredFiles.

/*
    * This class holds the assumption that the directory remains immutable.
    * If the directory does changes:
    * ignore new files showing up in the directory based on an old version of partition descriptor;
    * throw {@link org.apache.samza.SamzaException} if at least one old file doesn't exist anymore
    */
private List<FileMetadata> validateAndGetOriginalFilteredFiles(List<FileMetadata> newFileList, Map<Partition, List<String>> existingPartitionDescriptor) {
    assert newFileList != null;
    assert existingPartitionDescriptor != null;
    Set<String> oldFileSet = new HashSet<>();
    existingPartitionDescriptor.values().forEach(oldFileSet::addAll);
    Set<String> newFileSet = new HashSet<>();
    newFileList.forEach(file -> newFileSet.add(file.getPath()));
    if (!newFileSet.containsAll(oldFileSet)) {
        throw new SamzaException("The list of new files is not a super set of the old files. diff = " + oldFileSet.removeAll(newFileSet));
    }
    Iterator<FileMetadata> iterator = newFileList.iterator();
    while (iterator.hasNext()) {
        FileMetadata file = iterator.next();
        if (!oldFileSet.contains(file.getPath())) {
            iterator.remove();
        }
    }
    return newFileList;
}
Also used : FileMetadata(org.apache.samza.system.hdfs.partitioner.FileSystemAdapter.FileMetadata) SamzaException(org.apache.samza.SamzaException) HashSet(java.util.HashSet)

Example 4 with SamzaException

use of org.apache.samza.SamzaException in project samza by apache.

the class RemoteApplicationRunner method status.

@Override
public ApplicationStatus status(StreamApplication app) {
    try {
        boolean hasNewJobs = false;
        boolean hasRunningJobs = false;
        ApplicationStatus unsuccessfulFinishStatus = null;
        ExecutionPlan plan = getExecutionPlan(app);
        for (JobConfig jobConfig : plan.getJobConfigs()) {
            JobRunner runner = new JobRunner(jobConfig);
            ApplicationStatus status = runner.status();
            log.debug("Status is {} for job {}", new Object[] { status, jobConfig.getName() });
            switch(status.getStatusCode()) {
                case New:
                    hasNewJobs = true;
                    break;
                case Running:
                    hasRunningJobs = true;
                    break;
                case UnsuccessfulFinish:
                    unsuccessfulFinishStatus = status;
                    break;
                case SuccessfulFinish:
                    break;
                default:
            }
        }
        if (hasNewJobs) {
            // There are jobs not started, report as New
            return ApplicationStatus.New;
        } else if (hasRunningJobs) {
            // All jobs are started, some are running
            return ApplicationStatus.Running;
        } else if (unsuccessfulFinishStatus != null) {
            // All jobs are finished, some are not successful
            return unsuccessfulFinishStatus;
        } else {
            // All jobs are finished successfully
            return ApplicationStatus.SuccessfulFinish;
        }
    } catch (Throwable t) {
        throw new SamzaException("Failed to get status for application", t);
    }
}
Also used : JobRunner(org.apache.samza.job.JobRunner) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) ApplicationStatus(org.apache.samza.job.ApplicationStatus) SamzaException(org.apache.samza.SamzaException) JobConfig(org.apache.samza.config.JobConfig)

Example 5 with SamzaException

use of org.apache.samza.SamzaException in project samza by apache.

the class StorageRecovery method getSystemFactoriesAndAdmins.

/**
   * get the SystemFactories and SystemAdmins specified in the config file and
   * put them into the maps
   */
private void getSystemFactoriesAndAdmins() {
    JavaSystemConfig systemConfig = new JavaSystemConfig(jobConfig);
    List<String> systems = systemConfig.getSystemNames();
    for (String system : systems) {
        String systemFactory = systemConfig.getSystemFactory(system);
        if (systemFactory == null) {
            throw new SamzaException("A stream uses system " + system + " which is missing from the configuration.");
        }
        systemFactories.put(system, Util.<SystemFactory>getObj(systemFactory));
        systemAdmins.put(system, Util.<SystemFactory>getObj(systemFactory).getAdmin(system, jobConfig));
    }
    log.info("Got system factories: " + systemFactories.keySet().toString());
    log.info("Got system admins: " + systemAdmins.keySet().toString());
}
Also used : JavaSystemConfig(org.apache.samza.config.JavaSystemConfig) SystemFactory(org.apache.samza.system.SystemFactory) SamzaException(org.apache.samza.SamzaException)

Aggregations

SamzaException (org.apache.samza.SamzaException)256 IOException (java.io.IOException)61 HashMap (java.util.HashMap)57 Test (org.junit.Test)40 Map (java.util.Map)38 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)34 ArrayList (java.util.ArrayList)30 List (java.util.List)27 File (java.io.File)26 JobConfig (org.apache.samza.config.JobConfig)26 Config (org.apache.samza.config.Config)25 VisibleForTesting (com.google.common.annotations.VisibleForTesting)24 SystemStream (org.apache.samza.system.SystemStream)24 CompletableFuture (java.util.concurrent.CompletableFuture)23 Logger (org.slf4j.Logger)21 LoggerFactory (org.slf4j.LoggerFactory)21 Set (java.util.Set)20 Collections (java.util.Collections)19 MapConfig (org.apache.samza.config.MapConfig)18 TaskName (org.apache.samza.container.TaskName)18