public String remove(Object s) { throw new ConfigException("Config is immutable."); } }
@Test public void testMissingInputDescriptorFields() { String systemName = "eventHub"; String streamId = "input-stream"; EventHubsSystemDescriptor systemDescriptor = new EventHubsSystemDescriptor(systemName); try { systemDescriptor.getInputDescriptor(streamId, null, null, new StringSerde()); fail("Should have thrown Config Exception"); } catch (ConfigException exception) { assertEquals(String.format("Missing namespace and entity path Event Hubs input descriptor in " // + "system: {%s}, stream: {%s}", systemName, streamId), exception.getMessage()); } }
@Test public void testMissingOutputDescriptorFields() { String systemName = "eventHub"; String streamId = "input-stream"; EventHubsSystemDescriptor systemDescriptor = new EventHubsSystemDescriptor(systemName); try { systemDescriptor.getOutputDescriptor(streamId, null, null, new StringSerde()); fail("Should have thrown Config Exception"); } catch (ConfigException exception) { assertEquals(String.format("Missing namespace and entity path Event Hubs output descriptor in " // + "system: {%s}, stream: {%s}", systemName, streamId), exception.getMessage()); } }
public void putAll(Map<? extends String, ? extends String> m) { throw new ConfigException("Config is immutable."); }
public void clear() { throw new ConfigException("Config is immutable."); }
public String put(String key, String value) { throw new ConfigException("Config is immutable."); }
public String remove(Object s) { throw new ConfigException("Config is immutable."); } }
public String put(String key, String value) { throw new ConfigException("Config is immutable."); }
public void putAll(Map<? extends String, ? extends String> m) { throw new ConfigException("Config is immutable."); }
public void clear() { throw new ConfigException("Config is immutable."); }
@SuppressWarnings("unchecked") public <T> T getNewInstance(String k) { try { return (T) getClass(k).newInstance(); } catch (Exception e) { throw new ConfigException("Unable to instantiate class.", e); } }
@SuppressWarnings("unchecked") public <T> Class<T> getClass(String k) { if (containsKey(k)) { try { return (Class<T>) Class.forName(get(k)); } catch (Exception e) { throw new ConfigException("Unable to find class.", e); } } else { throw new ConfigException("Missing key " + k + "."); } }
public Date getDate(String k, SimpleDateFormat format) { if (!containsKey(k)) throw new ConfigException("Missing key " + k + "."); try { return format.parse(get(k)); } catch (ParseException e) { throw new ConfigException("Date format exception.", e); } }
@SuppressWarnings("unchecked") public <T> Class<T> getClass(String k) { if (containsKey(k)) { try { return (Class<T>) Class.forName(get(k)); } catch (Exception e) { throw new ConfigException("Unable to find class.", e); } } else { throw new ConfigException("Missing key " + k + "."); } }
/** * Get the log4j system name from the config. * If it's not defined, throw a ConfigException * * @return log4j system name */ public String getSystemName() { String log4jSystem = get(TASK_LOG4J_SYSTEM, null); if (log4jSystem == null) { throw new ConfigException("Missing " + TASK_LOG4J_SYSTEM + " configuration. Can't figure out the system name to use."); } return log4jSystem; }
@SuppressWarnings("unchecked") public <T> T getNewInstance(String k) { try { return (T) getClass(k).newInstance(); } catch (Exception e) { throw new ConfigException("Unable to instantiate class.", e); } }
public Date getDate(String k, SimpleDateFormat format) { if (!containsKey(k)) throw new ConfigException("Missing key " + k + "."); try { return format.parse(get(k)); } catch (ParseException e) { throw new ConfigException("Date format exception.", e); } }
/** * Get the log4j system name from the config. * If it's not defined, throw a ConfigException * * @return log4j system name */ public String getSystemName() { String log4jSystem = get(TASK_LOG4J_SYSTEM, null); if (log4jSystem == null) { throw new ConfigException("Missing " + TASK_LOG4J_SYSTEM + " configuration. Can't figure out the system name to use."); } return log4jSystem; }
/** * Get the {@link ApplicationRunner} that runs the {@code userApp} * * @param userApp the user application object * @param config the configuration for this application * @return the {@link ApplicationRunner} object that will run the {@code userApp} */ public static final ApplicationRunner getApplicationRunner(SamzaApplication userApp, Config config) { String appRunnerClassName = getAppRunnerClass(config); try { Class<?> runnerClass = Class.forName(appRunnerClassName); if (!ApplicationRunner.class.isAssignableFrom(runnerClass)) { throw new ConfigException( String.format("Class %s does not extend ApplicationRunner properly", appRunnerClassName)); } Constructor<?> constructor = runnerClass.getConstructor(SamzaApplication.class, Config.class); // *sigh* return (ApplicationRunner) constructor.newInstance(userApp, config); } catch (ConfigException ce) { // this is thrown due to invalid app.runner.class configuration throw ce; } catch (Exception e) { // other types of exception during class loading and construction of new instance throw new ConfigException(String.format("Could not load ApplicationRunner class %s", appRunnerClassName), e); } }
/** * Get the {@link ApplicationRunner} that runs the {@code userApp} * * @param userApp the user application object * @param config the configuration for this application * @return the {@link ApplicationRunner} object that will run the {@code userApp} */ public static final ApplicationRunner getApplicationRunner(SamzaApplication userApp, Config config) { String appRunnerClassName = getAppRunnerClass(config); try { Class<?> runnerClass = Class.forName(appRunnerClassName); if (!ApplicationRunner.class.isAssignableFrom(runnerClass)) { throw new ConfigException( String.format("Class %s does not extend ApplicationRunner properly", appRunnerClassName)); } Constructor<?> constructor = runnerClass.getConstructor(SamzaApplication.class, Config.class); // *sigh* return (ApplicationRunner) constructor.newInstance(userApp, config); } catch (ConfigException ce) { // this is thrown due to invalid app.runner.class configuration throw ce; } catch (Exception e) { // other types of exception during class loading and construction of new instance throw new ConfigException(String.format("Could not load ApplicationRunner class %s", appRunnerClassName), e); } }