Search in sources :

Example 16 with SamzaException

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

the class ClusterBasedJobCoordinator method run.

/**
   * Starts the JobCoordinator.
   *
   */
public void run() {
    if (!isStarted.compareAndSet(false, true)) {
        log.info("Attempting to start an already started job coordinator. ");
        return;
    }
    // set up JmxServer (if jmx is enabled)
    if (isJmxEnabled) {
        jmxServer = new JmxServer();
        state.jmxUrl = jmxServer.getJmxUrl();
        state.jmxTunnelingUrl = jmxServer.getTunnelingJmxUrl();
    } else {
        jmxServer = null;
    }
    try {
        //initialize JobCoordinator state
        log.info("Starting Cluster Based Job Coordinator");
        containerProcessManager.start();
        boolean isInterrupted = false;
        while (!containerProcessManager.shouldShutdown() && !isInterrupted) {
            try {
                Thread.sleep(jobCoordinatorSleepInterval);
            } catch (InterruptedException e) {
                isInterrupted = true;
                log.error("Interrupted in job coordinator loop {} ", e);
                Thread.currentThread().interrupt();
            }
        }
    } catch (Throwable e) {
        log.error("Exception thrown in the JobCoordinator loop {} ", e);
        throw new SamzaException(e);
    } finally {
        onShutDown();
    }
}
Also used : JmxServer(org.apache.samza.metrics.JmxServer) SamzaException(org.apache.samza.SamzaException)

Example 17 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 18 with SamzaException

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

the class ContainerProcessManager method getContainerProcessManagerFactory.

/**
   * Returns an instantiated {@link ResourceManagerFactory} from a {@link ClusterManagerConfig}. The
   * {@link ResourceManagerFactory} is used to return an implementation of a {@link ClusterResourceManager}
   *
   * @param clusterManagerConfig, the cluster manager config to parse.
   *
   */
private ResourceManagerFactory getContainerProcessManagerFactory(final ClusterManagerConfig clusterManagerConfig) {
    final String containerManagerFactoryClass = clusterManagerConfig.getContainerManagerClass();
    final ResourceManagerFactory factory;
    try {
        factory = ClassLoaderHelper.<ResourceManagerFactory>fromClassName(containerManagerFactoryClass);
    } catch (InstantiationException e) {
        log.error("Instantiation exception when creating ContainerManager", e);
        throw new SamzaException(e);
    } catch (IllegalAccessException e) {
        log.error("Illegal access exception when creating ContainerManager", e);
        throw new SamzaException(e);
    } catch (ClassNotFoundException e) {
        log.error("ClassNotFound Exception when creating ContainerManager", e);
        throw new SamzaException(e);
    }
    return factory;
}
Also used : SamzaException(org.apache.samza.SamzaException)

Example 19 with SamzaException

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

the class MockCoordinatorStreamWrappedConsumer method convertConfigToCoordinatorMessage.

private void convertConfigToCoordinatorMessage(Config config) {
    try {
        for (Map.Entry<String, String> configPair : config.entrySet()) {
            byte[] keyBytes = null;
            byte[] messgeBytes = null;
            if (configPair.getKey().startsWith(CHANGELOGPREFIX)) {
                String[] changelogInfo = configPair.getKey().split(":");
                String changeLogPartition = configPair.getValue();
                SetChangelogMapping changelogMapping = new SetChangelogMapping(changelogInfo[1], changelogInfo[2], Integer.parseInt(changeLogPartition));
                keyBytes = MAPPER.writeValueAsString(changelogMapping.getKeyArray()).getBytes("UTF-8");
                messgeBytes = MAPPER.writeValueAsString(changelogMapping.getMessageMap()).getBytes("UTF-8");
            } else {
                SetConfig setConfig = new SetConfig("source", configPair.getKey(), configPair.getValue());
                keyBytes = MAPPER.writeValueAsString(setConfig.getKeyArray()).getBytes("UTF-8");
                messgeBytes = MAPPER.writeValueAsString(setConfig.getMessageMap()).getBytes("UTF-8");
            }
            // The ssp here is the coordinator ssp (which is always fixed) and not the task ssp.
            put(systemStreamPartition, new IncomingMessageEnvelope(systemStreamPartition, "", keyBytes, messgeBytes));
        }
        setIsAtHead(systemStreamPartition, true);
    } catch (Exception e) {
        throw new SamzaException(e);
    }
}
Also used : IncomingMessageEnvelope(org.apache.samza.system.IncomingMessageEnvelope) SetChangelogMapping(org.apache.samza.coordinator.stream.messages.SetChangelogMapping) SetConfig(org.apache.samza.coordinator.stream.messages.SetConfig) BlockingEnvelopeMap(org.apache.samza.util.BlockingEnvelopeMap) Map(java.util.Map) SamzaException(org.apache.samza.SamzaException) IOException(java.io.IOException) SamzaException(org.apache.samza.SamzaException)

Example 20 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)

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