@Override public Map<String, SystemStreamMetadata> apply() { throw new SamzaException("Failed to get system stream metadata"); } };
private static void validateFactory(TaskFactory factory) { if (factory == null) { throw new SamzaException("Either the task class name or the task factory instance is required."); } if (!(factory instanceof StreamTaskFactory) && !(factory instanceof AsyncStreamTaskFactory)) { throw new SamzaException(String.format("TaskFactory must be either StreamTaskFactory or AsyncStreamTaskFactory. %s is not supported", factory.getClass())); } }
protected static String getStreamName(String jobName, String jobId) { if (jobName == null) { throw new SamzaException("job name is null. Please specify job.name"); } if (jobId == null) { jobId = "1"; } String streamName = "__samza_" + jobName + "_" + jobId + "_logs"; return streamName.replace("-", "_"); }
private String validateRequiredConfig(String value, String fieldName, String systemName, String streamName) { if (value == null) { throw new SamzaException(String.format("Missing %s configuration for system: %s, stream: %s", fieldName, systemName, streamName)); } return value; }
public ProcessorData(String data) { String[] splt = data.split(" "); if (splt.length != 2) { throw new SamzaException("incorrect processor data format = " + data); } locationId = splt[0]; processorId = splt[1]; }
public String fromBytes(byte[] bytes) { if (bytes != null) { try { return new String(bytes, 0, bytes.length, encoding); } catch (UnsupportedEncodingException e) { throw new SamzaException("Unsupported encoding " + encoding, e); } } else { return null; } } }
protected static String getStreamName(String jobName, String jobId) { if (jobName == null) { throw new SamzaException("job name is null. Please specify job.name"); } if (jobId == null) { jobId = "1"; } String streamName = "__samza_" + jobName + "_" + jobId + "_logs"; return streamName.replace("-", "_"); }
@Override public synchronized void register(String source) { LOG.info("Registering source {}", source); if (isStarted) { String msg = "Cannot register once the producer is started."; throw new SamzaException(msg); } }
public byte[] toBytes(String obj) { if (obj != null) { try { return obj.getBytes(encoding); } catch (UnsupportedEncodingException e) { throw new SamzaException("Unsupported encoding " + encoding, e); } } else { return null; } }
private static void validateFactory(TaskFactory factory) { if (factory == null) { throw new SamzaException("Either the task class name or the task factory instance is required."); } if (!(factory instanceof StreamTaskFactory) && !(factory instanceof AsyncStreamTaskFactory)) { throw new SamzaException(String.format("TaskFactory must be either StreamTaskFactory or AsyncStreamTaskFactory. %s is not supported", factory.getClass())); } }
private static void validateFactory(TaskFactory factory) { if (factory == null) { throw new SamzaException("Either the task class name or the task factory instance is required."); } if (!(factory instanceof StreamTaskFactory) && !(factory instanceof AsyncStreamTaskFactory)) { throw new SamzaException(String.format("TaskFactory must be either StreamTaskFactory or AsyncStreamTaskFactory. %s is not supported", factory.getClass())); } }
public SystemAdmin getSystemAdmin(String systemName) { if (!systemAdminMap.containsKey(systemName)) { throw new SamzaException("Cannot get systemAdmin for system " + systemName); } return systemAdminMap.get(systemName); }
/** * Get the current file index from the offset string * @param offset offset string that contains both file index and offset within file * @return the file index part */ public static int getCurFileIndex(String offset) { String[] elements = offset.split(DELIMITER); if (elements.length < 2) { throw new SamzaException("Invalid offset for MultiFileHdfsReader: " + offset); } return Integer.parseInt(elements[0]); }
public byte[] toBytes(T obj) { if (obj != null) { try { String str = mapper.writeValueAsString(obj); return str.getBytes("UTF-8"); } catch (Exception e) { throw new SamzaException("Error serializing data.", e); } } else { return null; } }
public SystemAdmin getSystemAdmin(String systemName) { if (!systemAdminMap.containsKey(systemName)) { throw new SamzaException("Cannot get systemAdmin for system " + systemName); } return systemAdminMap.get(systemName); }
private String getHostName() { try { return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOG.error("Failed to fetch hostname of the processor", e); throw new SamzaException(e); } }
@Override public Startpoint fromBytes(byte[] bytes) { try { LinkedHashMap<String, String> deserialized = mapper.readValue(bytes, LinkedHashMap.class); Class<? extends Startpoint> startpointClass = (Class<? extends Startpoint>) Class.forName(deserialized.get(STARTPOINT_CLASS)); return mapper.readValue(deserialized.get(STARTPOINT_OBJ), startpointClass); } catch (Exception e) { throw new SamzaException(String.format("Exception in de-serializing startpoint bytes: %s", Arrays.toString(bytes)), e); } }
public boolean shouldShutdown() { log.debug(" TaskManager state: Completed containers: {}, Configured containers: {}, Is there too many FailedContainers: {}, Is AllocatorThread alive: {} " , new Object[]{state.completedContainers.get(), state.containerCount, tooManyFailedContainers ? "yes" : "no", allocatorThread.isAlive() ? "yes" : "no"}); if (exceptionOccurred != null) { log.error("Exception in ContainerProcessManager", exceptionOccurred); throw new SamzaException(exceptionOccurred); } return tooManyFailedContainers || state.completedContainers.get() == state.containerCount.get() || !allocatorThread.isAlive(); }
public static SingleFileHdfsReader getHdfsReader(ReaderType readerType, SystemStreamPartition systemStreamPartition) { switch (readerType) { case AVRO: return new AvroFileHdfsReader(systemStreamPartition); default: throw new SamzaException("Unsupported reader type: " + readerType); } }
@Override public byte[] toBytes(SamzaSqlRelMessage p) { try { ObjectMapper mapper = new ObjectMapper(); // Enable object typing to handle nested records mapper.enableDefaultTyping(); return mapper.writeValueAsString(p).getBytes("UTF-8"); } catch (Exception e) { throw new SamzaException(e); } } }