/** * @param azkProps Azkaban Properties */ public GangliaMetricEmitter(final Props azkProps) { this.gmetricPath = azkProps.get(GANGLIA_METRIC_REPORTER_PATH); }
@Inject public AzkabanCommonModuleConfig(final Props props) { this.props = props; this.storageImplementation = props.getString(AZKABAN_STORAGE_TYPE, this.storageImplementation); this.localStorageBaseDirPath = props .getString(AZKABAN_STORAGE_LOCAL_BASEDIR, this.localStorageBaseDirPath); this.hdfsRootUri = props.get(AZKABAN_STORAGE_HDFS_ROOT_URI) != null ? props .getUri(AZKABAN_STORAGE_HDFS_ROOT_URI) : null; }
/** * Logs the property in the given logger */ public void logProperties(final Logger logger, final String comment) { logger.info(comment); for (final String key : getKeySet()) { logger.info(" key=" + key + " value=" + get(key)); } }
/** * Return value if available in current Props otherwise return from parent */ public String get(final Object key) { if (this._current.containsKey(key)) { return this._current.get(key); } else if (this._parent != null) { return this._parent.get(key); } else { return null; } }
/** * Put all properties in the props into the current props. Will handle null p. */ public void putAll(final Props p) { if (p == null) { return; } for (final String key : p.getKeySet()) { this.put(key, p.get(key)); } }
/** * Returns a java.util.Properties file populated with the current Properties in here. * Note: if you want to import parent properties (e.g., database credentials), please use * toAllProperties */ public Properties toProperties() { final Properties p = new Properties(); for (final String key : this._current.keySet()) { p.setProperty(key, get(key)); } return p; }
public static Map<String, String> toStringMap(final Props props, final boolean localOnly) { final HashMap<String, String> map = new HashMap<>(); final Set<String> keyset = localOnly ? props.localKeySet() : props.getKeySet(); for (final String key : keyset) { final String value = props.get(key); map.put(key, value); } return map; }
/** * Store only those properties defined at this local level * * @param out The output stream to write to * @throws IOException If the file can't be found or there is an io error */ public void storeLocal(final OutputStream out) throws IOException { final Properties p = new Properties(); for (final String key : this._current.keySet()) { p.setProperty(key, get(key)); } p.store(out, null); }
/** * Returns the double representation of the value. If the value is null, then the default value is * returned. If the value isn't a double, then a parse exception will be thrown. */ public double getDouble(final String name, final double defaultValue) { if (containsKey(name)) { return Double.parseDouble(get(name).trim()); } else { return defaultValue; } }
/** * Gets the string from the Props. If it doesn't exist, it will return the defaultValue */ public String getString(final String key, final String defaultValue) { if (containsKey(key)) { return get(key); } else { return defaultValue; } }
/** * Returns true if the value equals "true". If the value is null, then the default value is * returned. */ public boolean getBoolean(final String key, final boolean defaultValue) { if (containsKey(key)) { return "true".equalsIgnoreCase(get(key).trim()); } else { return defaultValue; } }
/** * Returns the long representation of the value. If the value is null, then the default value is * returned. If the value isn't a long, then a parse exception will be thrown. */ public long getLong(final String name, final long defaultValue) { if (containsKey(name)) { return Long.parseLong(get(name)); } else { return defaultValue; } }
/** * Returns the int representation of the value. If the value is null, then the default value is * returned. If the value isn't a int, then a parse exception will be thrown. */ public int getInt(final String name, final int defaultValue) { if (containsKey(name)) { return Integer.parseInt(get(name).trim()); } else { return defaultValue; } }
public Class<?> getClass(final String key, final boolean initialize, final ClassLoader cl) { try { if (containsKey(key)) { return Class.forName(get(key), initialize, cl); } else { throw new UndefinedPropertyException("Missing required property '" + key + "'"); } } catch (final ClassNotFoundException e) { throw new IllegalArgumentException(e); } }
/** * Returns true if the value equals "true". If the value is null, then an * UndefinedPropertyException is thrown. */ public boolean getBoolean(final String key) { if (containsKey(key)) { return "true".equalsIgnoreCase(get(key)); } else { throw new UndefinedPropertyException("Missing required property '" + key + "'"); } }
/** * Puts only the local props from p into the current properties */ public void putLocal(final Props p) { for (final String key : p.localKeySet()) { this.put(key, p.get(key)); } }
/** * Gets the string from the Props. If it doesn't exist, throw and UndefinedPropertiesException */ public String getString(final String key) { if (containsKey(key)) { return get(key); } else { throw new UndefinedPropertyException("Missing required property '" + key + "'"); } }
@Test public void testGetFlowProps() { final Props flowProps = FlowLoaderUtils.getPropsFromYamlFile(BASIC_FLOW_NAME, ExecutionsTestUtil.getFlowFile(BASIC_FLOW_YML_TEST_DIR, BASIC_FLOW_YML_FILE)); assertThat(flowProps.size()).isEqualTo(2); assertThat(flowProps.get(Constants.NODE_TYPE)).isEqualTo(Constants.FLOW_NODE_TYPE); assertThat(flowProps.get(FLOW_CONFIG_KEY)).isEqualTo(FLOW_CONFIG_VALUE); }
@Test public void testGetJobPropsFromBasicFlow() { final Props jobProps = FlowLoaderUtils .getPropsFromYamlFile(BASIC_FLOW_NAME + Constants.PATH_DELIMITER + SHELL_ECHO, ExecutionsTestUtil.getFlowFile(BASIC_FLOW_YML_TEST_DIR, BASIC_FLOW_YML_FILE)); assertThat(jobProps.size()).isEqualTo(2); assertThat(jobProps.get(Constants.NODE_TYPE)).isEqualTo(TYPE_COMMAND); assertThat(jobProps.get(TYPE_COMMAND)).isEqualTo(ECHO_COMMAND); }
@Test public void testInvalidSyntax() throws Exception { final Props propsGrandParent = new Props(); final Props propsParent = new Props(propsGrandParent); final Props props = new Props(propsParent); propsParent.put("my", "name"); props.put("res1", "$(my)"); final Props resolved = PropsUtils.resolveProps(props); Assert.assertEquals("$(my)", resolved.get("res1")); }