use of com.linkedin.data.template.StringArray in project rest.li by linkedin.
the class LoadBalancerStrategyPropertiesConverter method toConfig.
@SuppressWarnings({ "unchecked" })
public static D2LoadBalancerStrategyProperties toConfig(Map<String, Object> properties) {
D2LoadBalancerStrategyProperties config = new D2LoadBalancerStrategyProperties();
if (properties.containsKey(PropertyKeys.HTTP_LB_GLOBAL_STEP_DOWN)) {
config.setGlobalStepDown(coerce(properties.get(PropertyKeys.HTTP_LB_GLOBAL_STEP_DOWN), Double.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_GLOBAL_STEP_UP)) {
config.setGlobalStepUp(coerce(properties.get(PropertyKeys.HTTP_LB_GLOBAL_STEP_UP), Double.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_INITIAL_RECOVERY_LEVEL)) {
config.setInitialRecoveryLevel(coerce(properties.get(PropertyKeys.HTTP_LB_INITIAL_RECOVERY_LEVEL), Double.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_RING_RAMP_FACTOR)) {
config.setRingRampFactor(coerce(properties.get(PropertyKeys.HTTP_LB_RING_RAMP_FACTOR), Double.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_HIGH_WATER_MARK)) {
config.setHighWaterMark(coerce(properties.get(PropertyKeys.HTTP_LB_HIGH_WATER_MARK), Double.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_LOW_WATER_MARK)) {
config.setLowWaterMark(coerce(properties.get(PropertyKeys.HTTP_LB_LOW_WATER_MARK), Double.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_POINTS_PER_WEIGHT)) {
config.setPointsPerWeight(coerce(properties.get(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_POINTS_PER_WEIGHT), Integer.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS)) {
config.setUpdateIntervalMs(coerce(properties.get(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS), Long.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_HIGH_WATER_MARK)) {
config.setMinCallCountHighWaterMark(coerce(properties.get(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_HIGH_WATER_MARK), Long.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_LOW_WATER_MARK)) {
config.setMinCallCountLowWaterMark(coerce(properties.get(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_LOW_WATER_MARK), Long.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_HASHRING_POINT_CLEANUP_RATE)) {
config.setHashRingPointCleanupRate(coerce(properties.get(PropertyKeys.HTTP_LB_HASHRING_POINT_CLEANUP_RATE), Double.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_HASH_METHOD)) {
String hashMethodString = coerce(properties.get(PropertyKeys.HTTP_LB_HASH_METHOD), String.class);
if (DegraderLoadBalancerStrategyV3.HASH_METHOD_NONE.equalsIgnoreCase(hashMethodString)) {
config.setHashMethod(hashMethodEnum.RANDOM);
} else if (DegraderLoadBalancerStrategyV3.HASH_METHOD_URI_REGEX.equalsIgnoreCase(hashMethodString)) {
config.setHashMethod(hashMethodEnum.URI_REGEX);
}
}
if (properties.containsKey(PropertyKeys.HTTP_LB_HASH_CONFIG)) {
hashConfigType hashConfig = new hashConfigType();
Map<String, Object> hashConfigProperties = (Map<String, Object>) properties.get(PropertyKeys.HTTP_LB_HASH_CONFIG);
if (hashConfigProperties.containsKey(URIRegexHash.KEY_REGEXES)) {
List<String> uriRegexes = (List<String>) hashConfigProperties.get(URIRegexHash.KEY_REGEXES);
hashConfig.setUriRegexes(new StringArray(uriRegexes));
}
if (hashConfigProperties.containsKey(URIRegexHash.KEY_WARN_ON_NO_MATCH)) {
String warnOnNoMatchString = (String) hashConfigProperties.get(URIRegexHash.KEY_WARN_ON_NO_MATCH);
hashConfig.setWarnOnNoMatch(Boolean.parseBoolean(warnOnNoMatchString));
}
if (hashConfigProperties.containsKey(URIRegexHash.KEY_FAIL_ON_NO_MATCH)) {
String failOnNoMatchString = (String) hashConfigProperties.get(URIRegexHash.KEY_FAIL_ON_NO_MATCH);
hashConfig.setFailOnNoMatch(Boolean.parseBoolean(failOnNoMatchString));
}
config.setHashConfig(hashConfig);
}
if (properties.containsKey(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_ONLY_AT_INTERVAL)) {
config.setUpdateOnlyAtInterval(coerce(properties.get(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_ONLY_AT_INTERVAL), Boolean.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_CONSISTENT_HASH_ALGORITHM)) {
String consistentHashAlgorithm = coerce(properties.get(PropertyKeys.HTTP_LB_CONSISTENT_HASH_ALGORITHM), String.class);
if (DegraderRingFactory.POINT_BASED_CONSISTENT_HASH.equalsIgnoreCase(consistentHashAlgorithm)) {
config.setConsistentHashAlgorithm(ConsistentHashAlgorithmEnum.POINT_BASED);
} else if (DegraderRingFactory.MULTI_PROBE_CONSISTENT_HASH.equalsIgnoreCase(consistentHashAlgorithm)) {
config.setConsistentHashAlgorithm(ConsistentHashAlgorithmEnum.MULTI_PROBE);
}
}
if (properties.containsKey(PropertyKeys.HTTP_LB_CONSISTENT_HASH_NUM_PROBES)) {
config.setNumberOfProbes(coerce(properties.get(PropertyKeys.HTTP_LB_CONSISTENT_HASH_NUM_PROBES), Integer.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT) || properties.containsKey(PropertyKeys.HTTP_LB_QUARANTINE_METHOD) || properties.containsKey(PropertyKeys.HTTP_LB_QUARANTINE_LATENCY)) {
quarantineInfo quarantineInfo = new quarantineInfo();
if (properties.containsKey(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT)) {
quarantineInfo.setQuarantineMaxPercent(coerce(properties.get(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT), Double.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_QUARANTINE_METHOD)) {
quarantineInfo.setQuarantineMethod(coerce(properties.get(PropertyKeys.HTTP_LB_QUARANTINE_METHOD), String.class));
}
if (properties.containsKey(PropertyKeys.HTTP_LB_QUARANTINE_LATENCY)) {
quarantineInfo.setQuarantineLatency(coerce(properties.get(PropertyKeys.HTTP_LB_QUARANTINE_LATENCY), Long.class));
}
config.setQuarantineCfg(quarantineInfo);
}
if (properties.containsKey(PropertyKeys.HTTP_LB_ERROR_STATUS_REGEX)) {
config.setErrorStatusRegex(coerce(properties.get(PropertyKeys.HTTP_LB_ERROR_STATUS_REGEX), String.class));
}
return config;
}
use of com.linkedin.data.template.StringArray in project rest.li by linkedin.
the class LoadBalancerStrategyPropertiesConverterTest method testLoadBalancerStrategyPropertiesConverter.
@Test
public void testLoadBalancerStrategyPropertiesConverter() {
final Double globalStepDown = 0.4;
final Double globalStepUp = 0.3;
final Double recoveryLevel = 1.0;
final Double ringRampFactor = 0.01;
final Double highWaterMark = 1000d;
final Double lowWaterMark = 500d;
final Integer pointsPerWeight = 100;
final Long updateIntervalMs = 50000l;
final Integer minCallCountHighWaterMark = 3000;
final Integer minCallCountLowWaterMark = 1500;
final hashMethodEnum hashMethod = hashMethodEnum.URI_REGEX;
final hashConfigType hashConfig = new hashConfigType();
final StringArray regexes = new StringArray();
final Double hashringPointCleanupRate = 0.2;
final ConsistentHashAlgorithmEnum consistentHashAlgorithm = ConsistentHashAlgorithmEnum.MULTI_PROBE;
final Integer numProbes = 1024;
final Double quarantineMaxPercent = 0.2;
final String quarantineMethod = "OPTIONS:/test/path";
final Long quarantineLatency = 200l;
final quarantineInfo quarantineInfo = new quarantineInfo().setQuarantineMaxPercent(quarantineMaxPercent).setQuarantineMethod(quarantineMethod).setQuarantineLatency(quarantineLatency);
final String errorStatusRegex = "(5..)";
regexes.add("+231{w+)");
hashConfig.setUriRegexes(regexes);
hashConfig.setWarnOnNoMatch(false);
hashConfig.setFailOnNoMatch(true);
Map<String, Object> loadBalancerStrategyProperties = new HashMap<>();
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_GLOBAL_STEP_DOWN, globalStepDown.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_GLOBAL_STEP_UP, globalStepUp.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_INITIAL_RECOVERY_LEVEL, recoveryLevel.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_RING_RAMP_FACTOR, ringRampFactor.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HIGH_WATER_MARK, highWaterMark.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_LOW_WATER_MARK, lowWaterMark.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_POINTS_PER_WEIGHT, pointsPerWeight.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS, updateIntervalMs.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_HIGH_WATER_MARK, minCallCountHighWaterMark.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_LOW_WATER_MARK, minCallCountLowWaterMark.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HASH_METHOD, DegraderLoadBalancerStrategyV3.HASH_METHOD_URI_REGEX);
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HASHRING_POINT_CLEANUP_RATE, hashringPointCleanupRate.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CONSISTENT_HASH_ALGORITHM, DegraderRingFactory.MULTI_PROBE_CONSISTENT_HASH);
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CONSISTENT_HASH_NUM_PROBES, numProbes.toString());
Map<String, Object> hashConfigMap = new HashMap<>();
hashConfigMap.put(URIRegexHash.KEY_REGEXES, regexes.stream().collect(Collectors.toList()));
hashConfigMap.put(URIRegexHash.KEY_WARN_ON_NO_MATCH, "false");
hashConfigMap.put(URIRegexHash.KEY_FAIL_ON_NO_MATCH, "true");
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HASH_CONFIG, hashConfigMap);
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, quarantineMaxPercent.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_QUARANTINE_METHOD, quarantineMethod);
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_QUARANTINE_LATENCY, quarantineLatency.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_ERROR_STATUS_REGEX, errorStatusRegex);
D2LoadBalancerStrategyProperties d2LoadBalancerStrategyProperties = new D2LoadBalancerStrategyProperties().setGlobalStepDown(globalStepDown).setGlobalStepUp(globalStepUp).setInitialRecoveryLevel(recoveryLevel).setRingRampFactor(ringRampFactor).setHighWaterMark(highWaterMark).setLowWaterMark(lowWaterMark).setPointsPerWeight(pointsPerWeight).setUpdateIntervalMs(updateIntervalMs).setMinCallCountHighWaterMark(minCallCountHighWaterMark).setMinCallCountLowWaterMark(minCallCountLowWaterMark).setHashMethod(hashMethod).setHashConfig(hashConfig).setHashRingPointCleanupRate(hashringPointCleanupRate).setConsistentHashAlgorithm(consistentHashAlgorithm).setNumberOfProbes(numProbes).setQuarantineCfg(quarantineInfo).setErrorStatusRegex(errorStatusRegex);
Assert.assertEquals(LoadBalancerStrategyPropertiesConverter.toConfig(loadBalancerStrategyProperties), d2LoadBalancerStrategyProperties);
Assert.assertEquals(LoadBalancerStrategyPropertiesConverter.toProperties(d2LoadBalancerStrategyProperties), loadBalancerStrategyProperties);
}
use of com.linkedin.data.template.StringArray in project rest.li by linkedin.
the class TransportClientPropertiesConverterTest method testTransportClientPropertiesConverter.
@Test
public void testTransportClientPropertiesConverter() {
final Integer queryPostThreshold = 8192;
final Long requestTimeout = 10000l;
final Long maxResponseSize = 1003300l;
final Integer poolSize = 200;
final Integer poolWaiterSize = 32768;
final Long idleTimeout = 600000l;
final Long shutdownTimeout = 50000l;
final List<String> responseCompressionRaw = Arrays.asList("finder:*");
final List<String> responseContentEncoding = Arrays.asList("gzip", "snappy");
final List<String> requestContentEncoding = Arrays.asList("lz4", "identity");
final Boolean useResponseCompression = true;
final Integer maxHeaderSize = 8192;
final Integer maxChunkSize = 4096;
final poolStrategyType poolStrategy = poolStrategyType.LRU;
final Integer minPoolSize = 5;
final Integer maxConcurrentConnections = 1000;
final HttpProtocolVersionType protocolVersion = HttpProtocolVersionType.HTTP_1_1;
final List<String> allowedClientOverrideKeys = Arrays.asList(PropertyKeys.HTTP_REQUEST_TIMEOUT, PropertyKeys.HTTP_QUERY_POST_THRESHOLD);
Map<String, Object> transportClientProperties = new HashMap<>();
transportClientProperties.put(PropertyKeys.HTTP_QUERY_POST_THRESHOLD, queryPostThreshold.toString());
transportClientProperties.put(PropertyKeys.HTTP_REQUEST_TIMEOUT, requestTimeout.toString());
transportClientProperties.put(PropertyKeys.HTTP_MAX_RESPONSE_SIZE, maxResponseSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_POOL_SIZE, poolSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_POOL_WAITER_SIZE, poolWaiterSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_IDLE_TIMEOUT, idleTimeout.toString());
transportClientProperties.put(PropertyKeys.HTTP_SHUTDOWN_TIMEOUT, shutdownTimeout.toString());
transportClientProperties.put(PropertyKeys.HTTP_RESPONSE_COMPRESSION_OPERATIONS, responseCompressionRaw.stream().collect(Collectors.joining(",")));
transportClientProperties.put(PropertyKeys.HTTP_RESPONSE_CONTENT_ENCODINGS, responseContentEncoding.stream().collect(Collectors.joining(",")));
transportClientProperties.put(PropertyKeys.HTTP_REQUEST_CONTENT_ENCODINGS, requestContentEncoding.stream().collect(Collectors.joining(",")));
transportClientProperties.put(PropertyKeys.HTTP_USE_RESPONSE_COMPRESSION, useResponseCompression.toString());
transportClientProperties.put(PropertyKeys.HTTP_MAX_HEADER_SIZE, maxHeaderSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_MAX_CHUNK_SIZE, maxChunkSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_POOL_STRATEGY, poolStrategy.name());
transportClientProperties.put(PropertyKeys.HTTP_POOL_MIN_SIZE, minPoolSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_MAX_CONCURRENT_CONNECTIONS, maxConcurrentConnections.toString());
transportClientProperties.put(PropertyKeys.HTTP_PROTOCOL_VERSION, protocolVersion.name());
transportClientProperties.put(PropertyKeys.ALLOWED_CLIENT_OVERRIDE_KEYS, allowedClientOverrideKeys.stream().collect(Collectors.joining(",")));
D2TransportClientProperties d2TransportClientProperties = new D2TransportClientProperties().setQueryPostThreshold(queryPostThreshold).setRequestTimeout(requestTimeout).setMaxResponseSize(maxResponseSize).setPoolSize(poolSize).setPoolWaiterSize(poolWaiterSize).setIdleTimeout(idleTimeout).setShutdownTimeout(shutdownTimeout).setResponseCompressionOperations(new StringArray(responseCompressionRaw)).setResponseContentEncodings(new StringArray(responseContentEncoding)).setRequestContentEncodings(new StringArray(requestContentEncoding)).setUseResponseCompression(useResponseCompression).setMaxHeaderSize(maxHeaderSize).setMaxChunkSize(maxChunkSize).setPoolStrategy(poolStrategy).setMinPoolSize(minPoolSize).setMaxConcurrentConnections(maxConcurrentConnections).setProtocolVersion(protocolVersion).setAllowedClientOverrideKeys(new StringArray(allowedClientOverrideKeys));
Assert.assertEquals(TransportClientPropertiesConverter.toConfig(transportClientProperties), d2TransportClientProperties);
Assert.assertEquals(TransportClientPropertiesConverter.toProperties(d2TransportClientProperties), transportClientProperties);
}
use of com.linkedin.data.template.StringArray in project rest.li by linkedin.
the class TestMap method testStringArrayMap.
@Test
public void testStringArrayMap() {
TestDataTemplateUtil.FieldInfo fieldInfo = TestDataTemplateUtil.fieldInfo(new MapTest(), "stringArrayMap");
@SuppressWarnings("unchecked") Class<StringArrayMap> templateClass = (Class<StringArrayMap>) fieldInfo.getFieldClass();
MapDataSchema schema = (MapDataSchema) fieldInfo.getField().getType();
Map<String, StringArray> input = new HashMap<String, StringArray>();
for (int i = 0; i < 5; ++i) {
String key = "input" + i;
input.put(key, new StringArray());
input.get(key).add("subinput" + i);
}
Map<String, StringArray> adds = new HashMap<String, StringArray>();
for (int i = 0; i < 5; ++i) {
String key = "add" + i;
adds.put(key, new StringArray());
adds.get(key).add("subadd" + i);
}
TestMapTemplate.testMap(templateClass, schema, input, adds);
}
use of com.linkedin.data.template.StringArray in project rest.li by linkedin.
the class ArrayGeneratorTest method testWithPrimitivesArray.
@Test
public void testWithPrimitivesArray() throws Throwable {
String json = load("WithPrimitivesArray.json");
WithPrimitivesArray original = new WithPrimitivesArray();
IntegerArray ints = new IntegerArray();
ints.add(1);
ints.add(2);
ints.add(3);
original.setInts(ints);
LongArray longs = new LongArray();
longs.add(10L);
longs.add(20L);
longs.add(30L);
original.setLongs(longs);
FloatArray floats = new FloatArray();
floats.add(1.1f);
floats.add(2.2f);
floats.add(3.3f);
original.setFloats(floats);
DoubleArray doubles = new DoubleArray();
doubles.add(11.1d);
doubles.add(22.2d);
doubles.add(33.3d);
original.setDoubles(doubles);
BooleanArray booleans = new BooleanArray();
booleans.add(false);
booleans.add(true);
original.setBooleans(booleans);
StringArray strings = new StringArray();
strings.add("a");
strings.add("b");
strings.add("c");
original.setStrings(strings);
BytesArray bytes = new BytesArray();
bytes.add(SchemaFixtures.bytes1);
bytes.add(SchemaFixtures.bytes2);
original.setBytes(bytes);
assertJson(original, json);
WithPrimitivesArray roundTripped = new WithPrimitivesArray(roundTrip(original.data()));
assertJson(roundTripped, json);
}
Aggregations