Skip to content

Commit

Permalink
Merge pull request #1448 from mattrjacobs/remove-cbor-dependency
Browse files Browse the repository at this point in the history
Remove dependency of hystrix-serialization on jackson-cbor by depreca…
  • Loading branch information
mattrjacobs authored Dec 20, 2016
2 parents 0dd3cf5 + 0c8cef7 commit 148e8f1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 225 deletions.
1 change: 0 additions & 1 deletion hystrix-serialization/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dependencies {
compileApi 'com.fasterxml.jackson.core:jackson-databind:2.7.5'
compileApi 'com.fasterxml.jackson.core:jackson-annotations:2.7.5'
compile 'com.fasterxml.jackson.module:jackson-module-afterburner:2.7.5'
compileApi 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.7.5'

testCompile 'junit:junit-dep:4.10'
testCompile 'org.mockito:mockito-all:1.9.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@
package com.netflix.hystrix.serial;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.cbor.CBORParser;
import com.netflix.hystrix.HystrixCollapserKey;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.config.HystrixCollapserConfiguration;
import com.netflix.hystrix.config.HystrixCommandConfiguration;
Expand All @@ -30,33 +26,18 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class SerialHystrixConfiguration extends SerialHystrixMetric {

private static final Logger logger = LoggerFactory.getLogger(SerialHystrixConfiguration.class);

@Deprecated
public static byte[] toBytes(HystrixConfiguration config) {
byte[] retVal = null;

try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JsonGenerator cbor = cborFactory.createGenerator(bos);

serializeConfiguration(config, cbor);

retVal = bos.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
}

return retVal;
throw new UnsupportedOperationException("Not implemented anymore. Will be implemented in a new class shortly");
}

public static String toJsonString(HystrixConfiguration config) {
Expand Down Expand Up @@ -109,108 +90,9 @@ private static void serializeConfiguration(HystrixConfiguration config, JsonGene

}

@Deprecated
public static HystrixConfiguration fromByteBuffer(ByteBuffer bb) {
byte[] byteArray = new byte[bb.remaining()];
bb.get(byteArray);

Map<HystrixCommandKey, HystrixCommandConfiguration> commandConfigMap = new HashMap<HystrixCommandKey, HystrixCommandConfiguration>();
Map<HystrixThreadPoolKey, HystrixThreadPoolConfiguration> threadPoolConfigMap = new HashMap<HystrixThreadPoolKey, HystrixThreadPoolConfiguration>();
Map<HystrixCollapserKey, HystrixCollapserConfiguration> collapserConfigMap = new HashMap<HystrixCollapserKey, HystrixCollapserConfiguration>();

try {
CBORParser parser = cborFactory.createParser(byteArray);
JsonNode rootNode = mapper.readTree(parser);

Iterator<Map.Entry<String, JsonNode>> commands = rootNode.path("commands").fields();
Iterator<Map.Entry<String, JsonNode>> threadPools = rootNode.path("threadpools").fields();
Iterator<Map.Entry<String, JsonNode>> collapsers = rootNode.path("collapsers").fields();

while (commands.hasNext()) {
Map.Entry<String, JsonNode> command = commands.next();

JsonNode executionConfig = command.getValue().path("execution");

JsonNode circuitBreakerConfig = command.getValue().path("circuitBreaker");
JsonNode metricsConfig = command.getValue().path("metrics");
HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey(command.getKey());
HystrixCommandConfiguration commandConfig = new HystrixCommandConfiguration(
commandKey,
HystrixThreadPoolKey.Factory.asKey(command.getValue().path("threadPoolKey").asText()),
HystrixCommandGroupKey.Factory.asKey(command.getValue().path("groupKey").asText()),
new HystrixCommandConfiguration.HystrixCommandExecutionConfig(
executionConfig.path("semaphoreSize").asInt(),
HystrixCommandProperties.ExecutionIsolationStrategy.valueOf(
executionConfig.path("isolationStrategy").asText()),
executionConfig.path("threadInterruptOnTimeout").asBoolean(),
executionConfig.path("threadPoolKeyOverride").asText(),
executionConfig.path("timeoutEnabled").asBoolean(),
executionConfig.path("timeoutInMilliseconds").asInt(),
executionConfig.path("fallbackEnabled").asBoolean(),
executionConfig.path("fallbackSemaphoreSize").asInt(),
executionConfig.path("requestCacheEnabled").asBoolean(),
executionConfig.path("requestLogEnabled").asBoolean()
),
new HystrixCommandConfiguration.HystrixCommandCircuitBreakerConfig(
circuitBreakerConfig.path("enabled").asBoolean(),
circuitBreakerConfig.path("errorPercentageThreshold").asInt(),
circuitBreakerConfig.path("isForcedClosed").asBoolean(),
circuitBreakerConfig.path("isForcedOpen").asBoolean(),
circuitBreakerConfig.path("requestVolumeThreshold").asInt(),
circuitBreakerConfig.path("sleepInMilliseconds").asInt()
),
new HystrixCommandConfiguration.HystrixCommandMetricsConfig(
metricsConfig.path("healthBucketSizeInMs").asInt(),
metricsConfig.path("percentileEnabled").asBoolean(),
metricsConfig.path("percentileBucketCount").asInt(),
metricsConfig.path("percentileBucketSizeInMilliseconds").asInt(),
metricsConfig.path("counterBucketCount").asInt(),
metricsConfig.path("counterBucketSizeInMilliseconds").asInt()
)
);

commandConfigMap.put(commandKey, commandConfig);
}

while (threadPools.hasNext()) {
Map.Entry<String, JsonNode> threadPool = threadPools.next();
HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey(threadPool.getKey());
HystrixThreadPoolConfiguration threadPoolConfig = new HystrixThreadPoolConfiguration(
threadPoolKey,
threadPool.getValue().path("coreSize").asInt(),
threadPool.getValue().path("maximumSize").asInt(),
threadPool.getValue().path("maxQueueSize").asInt(),
threadPool.getValue().path("queueRejectionThreshold").asInt(),
threadPool.getValue().path("keepAliveTimeInMinutes").asInt(),
threadPool.getValue().path("allowMaximumSizeToDivergeFromCoreSize").asBoolean(),
threadPool.getValue().path("counterBucketCount").asInt(),
threadPool.getValue().path("counterBucketSizeInMilliseconds").asInt()
);
threadPoolConfigMap.put(threadPoolKey, threadPoolConfig);
}

while (collapsers.hasNext()) {
Map.Entry<String, JsonNode> collapser = collapsers.next();
HystrixCollapserKey collapserKey = HystrixCollapserKey.Factory.asKey(collapser.getKey());
JsonNode metricsConfig = collapser.getValue().path("metrics");
HystrixCollapserConfiguration collapserConfig = new HystrixCollapserConfiguration(
collapserKey,
collapser.getValue().path("maxRequestsInBatch").asInt(),
collapser.getValue().path("timerDelayInMilliseconds").asInt(),
collapser.getValue().path("requestCacheEnabled").asBoolean(),
new HystrixCollapserConfiguration.CollapserMetricsConfig(
metricsConfig.path("percentileBucketCount").asInt(),
metricsConfig.path("percentileBucketSizeInMilliseconds").asInt(),
metricsConfig.path("percentileEnabled").asBoolean(),
metricsConfig.path("counterBucketCount").asInt(),
metricsConfig.path("counterBucketSizeInMilliseconds").asInt()
)
);
collapserConfigMap.put(collapserKey, collapserConfig);
}
} catch (IOException ioe) {
logger.error("IO Exception during deserialization of HystrixConfiguration : " + ioe);
}
return new HystrixConfiguration(commandConfigMap, threadPoolConfigMap, collapserConfigMap);
throw new UnsupportedOperationException("Not implemented anymore. Will be implemented in a new class shortly");
}

private static void writeCommandConfigJson(JsonGenerator json, HystrixCommandKey key, HystrixCommandConfiguration commandConfig) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
import com.netflix.hystrix.metric.consumer.HystrixDashboardStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rx.Observable;
import rx.functions.Func0;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
Expand All @@ -41,20 +39,9 @@ public class SerialHystrixDashboardData extends SerialHystrixMetric {

private static final Logger logger = LoggerFactory.getLogger(SerialHystrixDashboardData.class);

@Deprecated
public static byte[] toBytes(HystrixDashboardStream.DashboardData dashboardData) {
byte[] retVal = null;

try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JsonGenerator cbor = cborFactory.createGenerator(bos);
writeDashboardData(cbor, dashboardData);
retVal = bos.toByteArray();

} catch (Exception e) {
throw new RuntimeException(e);
}

return retVal;
throw new UnsupportedOperationException("Not implemented anymore. Will be implemented in a new class shortly");
}

public static String toJsonString(HystrixDashboardStream.DashboardData dashboardData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,19 @@
package com.netflix.hystrix.serial;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import com.fasterxml.jackson.dataformat.cbor.CBORParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.ByteBuffer;

public class SerialHystrixMetric {
protected final static JsonFactory jsonFactory = new JsonFactory();
protected final static CBORFactory cborFactory = new CBORFactory();
protected final static ObjectMapper mapper = new ObjectMapper();
protected final static Logger logger = LoggerFactory.getLogger(SerialHystrixMetric.class);

@Deprecated
public static String fromByteBufferToString(ByteBuffer bb) {
byte[] byteArray = new byte[bb.remaining()];
bb.get(byteArray);

try {
CBORParser parser = cborFactory.createParser(byteArray);
JsonNode rootNode = mapper.readTree(parser);

return rootNode.toString();
} catch (IOException ioe) {
logger.error("IO Exception during deserialization of ByteBuffer of Hystrix Metric : " + ioe);
return "";
}
throw new UnsupportedOperationException("Not implemented anymore. Will be implemented in a new class shortly");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,16 @@
import com.netflix.hystrix.HystrixEventType;
import com.netflix.hystrix.metric.HystrixRequestEvents;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;

public class SerialHystrixRequestEvents extends SerialHystrixMetric {

@Deprecated
public static byte[] toBytes(HystrixRequestEvents requestEvents) {
byte[] retVal = null;

try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JsonGenerator cbor = cborFactory.createGenerator(bos);

serializeRequestEvents(requestEvents, cbor);

retVal = bos.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
}

return retVal;
throw new UnsupportedOperationException("Not implemented anymore. Will be implemented in a new class shortly");
}

public static String toJsonString(HystrixRequestEvents requestEvents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,26 @@
package com.netflix.hystrix.serial;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.cbor.CBORParser;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.config.HystrixConfiguration;
import com.netflix.hystrix.metric.sample.HystrixCommandUtilization;
import com.netflix.hystrix.metric.sample.HystrixThreadPoolUtilization;
import com.netflix.hystrix.metric.sample.HystrixUtilization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class SerialHystrixUtilization extends SerialHystrixMetric {

private final static Logger logger = LoggerFactory.getLogger(SerialHystrixUtilization.class);

@Deprecated
public static byte[] toBytes(HystrixUtilization utilization) {
byte[] retVal = null;

try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JsonGenerator cbor = cborFactory.createGenerator(bos);

serializeUtilization(utilization, cbor);

retVal = bos.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
}

return retVal;
throw new UnsupportedOperationException("Not implemented anymore. Will be implemented in a new class shortly");
}

public static String toJsonString(HystrixUtilization utilization) {
Expand Down Expand Up @@ -97,42 +79,9 @@ private static void serializeUtilization(HystrixUtilization utilization, JsonGen
}
}

@Deprecated
public static HystrixUtilization fromByteBuffer(ByteBuffer bb) {
byte[] byteArray = new byte[bb.remaining()];
bb.get(byteArray);

Map<HystrixCommandKey, HystrixCommandUtilization> commandUtilizationMap = new HashMap<HystrixCommandKey, HystrixCommandUtilization>();
Map<HystrixThreadPoolKey, HystrixThreadPoolUtilization> threadPoolUtilizationMap = new HashMap<HystrixThreadPoolKey, HystrixThreadPoolUtilization>();

try {
CBORParser parser = cborFactory.createParser(byteArray);
JsonNode rootNode = mapper.readTree(parser);

Iterator<Map.Entry<String, JsonNode>> commands = rootNode.path("commands").fields();
Iterator<Map.Entry<String, JsonNode>> threadPools = rootNode.path("threadpools").fields();

while (commands.hasNext()) {
Map.Entry<String, JsonNode> command = commands.next();
HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey(command.getKey());
HystrixCommandUtilization commandUtilization = new HystrixCommandUtilization(command.getValue().path("activeCount").asInt());
commandUtilizationMap.put(commandKey, commandUtilization);
}

while (threadPools.hasNext()) {
Map.Entry<String, JsonNode> threadPool = threadPools.next();
HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey(threadPool.getKey());
HystrixThreadPoolUtilization threadPoolUtilization = new HystrixThreadPoolUtilization(
threadPool.getValue().path("activeCount").asInt(),
threadPool.getValue().path("corePoolSize").asInt(),
threadPool.getValue().path("poolSize").asInt(),
threadPool.getValue().path("queueSize").asInt()
);
threadPoolUtilizationMap.put(threadPoolKey, threadPoolUtilization);
}
} catch (IOException ioe) {
logger.error("IO Exception during desrialization of HystrixUtilization : " + ioe);
}
return new HystrixUtilization(commandUtilizationMap, threadPoolUtilizationMap);
throw new UnsupportedOperationException("Not implemented anymore. Will be implemented in a new class shortly");
}

private static void writeCommandUtilizationJson(JsonGenerator json, HystrixCommandKey key, HystrixCommandUtilization utilization) throws IOException {
Expand Down

0 comments on commit 148e8f1

Please sign in to comment.