@SuppressWarnings("unchecked") private void putBranch( final String key, final Map<String, Object> schemaBranch, final Object val ) throws InvalidValuePathException, InvalidValueTypeException { final Config branch; if(val instanceof Config) { branch = new BasicConfig((Config) val); } else if(val instanceof Map) { branch = new BasicConfig(pathSep, schemaBranch, (Map<String, Object>) val); } else { throw new InvalidValuePathException(key); } node.put(key, branch); }
@Override public void val(final String path, final Object val) throws InvalidValuePathException, InvalidValueTypeException { final int sepPos = path.indexOf(pathSep); if(sepPos == 0 || sepPos == path.length() - 1) { throw new InvalidValuePathException(path); } if(sepPos > 0) { final String key = path.substring(0, sepPos); final String childPath = path.substring(sepPos + 1); val(key, childPath, val); } else { leafVal(path, val); } }
protected void leafVal(final String key, final Object val) throws InvalidValuePathException, InvalidValueTypeException { final Object schemaVal = schema.get(key); if(schemaVal instanceof Class) { putLeaf(key, (Class) schemaVal, val); } else { throw new InvalidValuePathException(key); } }
@Override public Config configVal(final String path) throws InvalidValuePathException, InvalidValueTypeException { return (Config) val(path); }
if(schemaVal instanceof Map) { try { putBranch(key, (Map<String, Object>) schemaVal, val); } catch(final InvalidValuePathException e) { throw new InvalidValuePathException(key + pathSep + e.path()); putLeaf(key, (Class) schemaVal, val); } catch(final InvalidValuePathException e) { throw new InvalidValuePathException(key + pathSep + e.path());
@Override public String stringVal(final String path) throws InvalidValuePathException, NoSuchElementException { return (String) val(path); }
static Config merge(final String pathSep, final List<Config> configs) { final Map<String, Object> schema = configs.stream() .map(Config::schema) .reduce(TreeUtil::addBranches) .orElseGet(Collections::emptyMap); final Map<String, Object> configTree = configs.stream() .map(Config::deepToMap) .reduce(TreeUtil::addBranches) .orElseGet(Collections::emptyMap); return new BasicConfig(pathSep, schema, configTree); }
@Override @SuppressWarnings("unchecked") public <E> List<E> listVal(final String path) throws InvalidValuePathException, NoSuchElementException { final Object v = val(path); try { return (List<E>) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, List.class, v.getClass()); } }
protected LoadStepBase( final Config config, final List<Extension> extensions, final List<Config> ctxConfigs, final MetricsManager metricsMgr) { this.config = new BasicConfig(config); this.extensions = extensions; this.ctxConfigs = ctxConfigs; this.metricsMgr = metricsMgr; Loggers.CONFIG.info(ConfigUtil.toString(config)); }
@Override public char charVal(final String path) throws InvalidValueTypeException, NoSuchElementException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Character.TYPE, null); } try { return (char) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Character.TYPE, v.getClass()); } }
static Config initSlice(final Config config) { final Config configSlice = new BasicConfig(config); // disable the distributed mode on the slave nodes configSlice.val("load-step-node-addrs", Collections.EMPTY_LIST); return configSlice; }
@Override public float floatVal(final String path) throws InvalidValueTypeException, NoSuchElementException, NumberFormatException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Float.TYPE, null); } else if(v instanceof String) { return Float.parseFloat((String) v); } else { try { return (float) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Float.TYPE, v.getClass()); } } }
static Config resolveAndReduce( final String id, final ClassLoader clsLoader, final String pathSep, final Map<String, Object> schema ) throws Exception { final List<Config> resolvedConfigs = resolve(id, clsLoader, pathSep, schema); if(resolvedConfigs == null || resolvedConfigs.size() == 0) { return null; } final List<Map<String, Object>> configForest = resolvedConfigs .stream() .map(c -> c.mapVal(Config.ROOT_PATH)) .collect(Collectors.toList()); final Map<String, Object> configTree = reduceForest(configForest); return new BasicConfig(pathSep, schema, configTree); } }
@Override public boolean boolVal(final String path) throws InvalidValuePathException, InvalidValueTypeException, NoSuchElementException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Boolean.TYPE, null); } else if(v instanceof String) { return Boolean.parseBoolean((String) v); } else { try { return (boolean) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Boolean.TYPE, v.getClass()); } } }
@Override public final <T extends LoadStepClient> T append(final Map<String, Object> context) throws InterruptRunException { final List<Config> ctxConfigsCopy; if (ctxConfigs == null) { ctxConfigsCopy = new ArrayList<>(1); } else { ctxConfigsCopy = ctxConfigs.stream().map(BasicConfig::new).collect(Collectors.toList()); } final Map<String, String> argValPairs = new HashMap<>(); flatten(context, argValPairs, config.pathSep(), null); final List<Map<String, Object>> aliasingConfig = config.listVal("aliasing"); final Config ctxConfig = new BasicConfig(config); try { final Map<String, String> aliasedArgs = AliasingUtil.apply(argValPairs, aliasingConfig); aliasedArgs.forEach(ctxConfig::val); // merge } catch (final Exception e) { LogUtil.exception(Level.FATAL, e, "Scenario syntax error"); throw new InterruptRunException(e); } ctxConfigsCopy.add(ctxConfig); return copyInstance(config, ctxConfigsCopy); }
@Override public int intVal(final String path) throws InvalidValuePathException, NoSuchElementException, NumberFormatException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Integer.TYPE, null); } else if(v instanceof String) { return Integer.parseInt((String) v); } else if(v instanceof Short) { return (short) v; } else { try { return (int) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Integer.TYPE, v.getClass()); } } }
childConfig = (Config) child; } else { childConfig = new BasicConfig(pathSep, (Map<String, Object>) schemaVal); node.put(key, childConfig);
@Override public byte byteVal(final String path) throws InvalidValueTypeException, NoSuchElementException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Byte.TYPE, null); } else if(v instanceof String) { return Byte.parseByte((String) v); } else { try { return (byte) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Byte.TYPE, v.getClass()); } } }
specificConfig = new BasicConfig(config); specificConfig.val("output-metrics-average-persist", false); specificConfig.val("output-metrics-summary-perfDbResultsFile", false); specificConfig = new BasicConfig(config); final String ioTypeName = opType.name().toLowerCase(); specificConfig.val("load-op-type", ioTypeName); specificConfig = new BasicConfig(config); specificConfig.val("load-op-type", OpType.READ.name().toLowerCase()); specificConfig.val("item-data-verify", true); "ReadVerifyLoad", baseLoadStepFactory.createClient(specificConfig, extensions, metricsMgr)); specificConfig = new BasicConfig(config); specificConfig.val("load-op-type", OpType.READ.name().toLowerCase()); specificConfig.val("item-data-ranges-random", 1); baseLoadStepFactory.createClient(specificConfig, extensions, metricsMgr)); specificConfig = new BasicConfig(config); specificConfig.val("load-op-type", OpType.READ.name().toLowerCase()); specificConfig.val("item-data-verify", true); specificConfig = new BasicConfig(config); specificConfig.val("load-op-type", OpType.UPDATE.name().toLowerCase()); specificConfig.val("item-data-ranges-random", 1);
@Override public short shortVal(final String path) throws InvalidValueTypeException, NoSuchElementException, NumberFormatException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Short.TYPE, null); } else if(v instanceof String) { return Short.parseShort((String) v); } else { try { return (short) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Short.TYPE, v.getClass()); } } }