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();
}
}
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();
}
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;
}
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);
}
}
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());
}
Aggregations