use of org.apache.samza.SamzaException in project samza by apache.
the class TestCoordinatorStreamSystemConsumer method testCoordinatorStreamSystemConsumer.
@Test
public void testCoordinatorStreamSystemConsumer() {
Map<String, String> expectedConfig = new LinkedHashMap<String, String>();
expectedConfig.put("job.id", "1234");
SystemStream systemStream = new SystemStream("system", "stream");
MockSystemConsumer systemConsumer = new MockSystemConsumer(new SystemStreamPartition(systemStream, new Partition(0)));
CoordinatorStreamSystemConsumer consumer = new CoordinatorStreamSystemConsumer(systemStream, systemConsumer, new SinglePartitionWithoutOffsetsSystemAdmin());
assertEquals(0, systemConsumer.getRegisterCount());
consumer.register();
assertEquals(1, systemConsumer.getRegisterCount());
assertFalse(systemConsumer.isStarted());
consumer.start();
assertTrue(systemConsumer.isStarted());
try {
consumer.getConfig();
fail("Should have failed when retrieving config before bootstrapping.");
} catch (SamzaException e) {
// Expected.
}
consumer.bootstrap();
assertEquals(expectedConfig, consumer.getConfig());
assertFalse(systemConsumer.isStopped());
consumer.stop();
assertTrue(systemConsumer.isStopped());
}
use of org.apache.samza.SamzaException in project samza by apache.
the class ZkUtils method publishJobModel.
/**
* Publishes new job model into ZK.
* This call should FAIL if the node already exists.
* @param jobModelVersion version of the jobModeL to publish
* @param jobModel jobModel to publish
*
*/
public void publishJobModel(String jobModelVersion, JobModel jobModel) {
try {
ObjectMapper mmapper = SamzaObjectMapper.getObjectMapper();
String jobModelStr = mmapper.writerWithDefaultPrettyPrinter().writeValueAsString(jobModel);
LOG.info("jobModelAsString=" + jobModelStr);
zkClient.createPersistent(keyBuilder.getJobModelPath(jobModelVersion), jobModelStr);
LOG.info("wrote jobModel path =" + keyBuilder.getJobModelPath(jobModelVersion));
} catch (Exception e) {
LOG.error("JobModel publish failed for version=" + jobModelVersion, e);
throw new SamzaException(e);
}
}
use of org.apache.samza.SamzaException in project samza by apache.
the class AbstractContainerAllocator method runStreamProcessor.
/**
* Updates the request state and runs a container process on the specified host. Assumes a resource
* is available on the preferred host, so the caller must verify that before invoking this method.
*
* @param request the {@link SamzaResourceRequest} which is being handled.
* @param preferredHost the preferred host on which the StreamProcessor process should be run or
* {@link ResourceRequestState#ANY_HOST} if there is no host preference.
* @throws
* SamzaException if there is no allocated resource in the specified host.
*/
protected void runStreamProcessor(SamzaResourceRequest request, String preferredHost) {
CommandBuilder builder = getCommandBuilder(request.getContainerID());
// Get the available resource
SamzaResource resource = peekAllocatedResource(preferredHost);
if (resource == null)
throw new SamzaException("Expected resource was unavailable on host " + preferredHost);
// Update state
resourceRequestState.updateStateAfterAssignment(request, preferredHost, resource);
String containerID = request.getContainerID();
//run container on resource
log.info("Found available resources on {}. Assigning request for container_id {} with " + "timestamp {} to resource {}", new Object[] { preferredHost, String.valueOf(containerID), request.getRequestTimestampMs(), resource.getResourceID() });
try {
//launches a StreamProcessor on the resource
clusterResourceManager.launchStreamProcessor(resource, builder);
if (state.neededContainers.decrementAndGet() == 0) {
state.jobHealthy.set(true);
}
state.runningContainers.put(request.getContainerID(), resource);
} catch (SamzaContainerLaunchException e) {
log.warn(String.format("Got exception while starting resource %s. Requesting a new resource on any host", resource), e);
resourceRequestState.releaseUnstartableContainer(resource);
requestResource(containerID, ResourceRequestState.ANY_HOST);
}
}
use of org.apache.samza.SamzaException in project samza by apache.
the class PartitionDescriptorUtil method getDescriptorMapFromJson.
public static Map<Partition, List<String>> getDescriptorMapFromJson(String json) {
try {
@SuppressWarnings("unchecked") Map<String, String> rawMap = new ObjectMapper().readValue(json, HashMap.class);
Map<Partition, List<String>> descriptorMap = new HashMap<>();
rawMap.forEach((key, value) -> descriptorMap.put(new Partition(Integer.valueOf(key)), getPathsFromString(value)));
return descriptorMap;
} catch (IOException | NumberFormatException e) {
throw new SamzaException("Failed to convert json: " + json, e);
}
}
use of org.apache.samza.SamzaException in project samza by apache.
the class PartitionDescriptorUtil method getJsonFromDescriptorMap.
public static String getJsonFromDescriptorMap(Map<Partition, List<String>> descriptorMap) {
JSONObject out = new JSONObject();
descriptorMap.forEach((partition, paths) -> {
String descriptorStr = getStringFromPaths(paths);
try {
out.put(String.valueOf(partition.getPartitionId()), descriptorStr);
} catch (JSONException e) {
throw new SamzaException(String.format("Invalid description to encode. partition=%s, descriptor=%s", partition, descriptorStr), e);
}
});
try {
return out.toString(INDENT_FACTOR);
} catch (JSONException e) {
throw new SamzaException("Failed to generate json string.", e);
}
}
Aggregations