Skip to content

Commit 29b0dda

Browse files
committed
CLOUDSTACK-8708 bypass exclusion cache in adaptors
1 parent 0ba23c3 commit 29b0dda

5 files changed

Lines changed: 22 additions & 5 deletions

File tree

core/src/com/cloud/serializer/GsonHelper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.cloudstack.agent.transport.CommandTypeAdaptor;
2727
import org.apache.log4j.Logger;
2828

29+
import com.google.gson.ExclusionStrategy;
2930
import com.google.gson.Gson;
3031
import com.google.gson.GsonBuilder;
3132
import com.google.gson.reflect.TypeToken;
@@ -46,13 +47,15 @@ public class GsonHelper {
4647

4748
protected static final Gson s_gson;
4849
protected static final Gson s_gogger;
50+
private static final ExclusionStrategy excluder;
4951

5052
static {
5153
GsonBuilder gsonBuilder = new GsonBuilder();
5254
s_gson = setDefaultGsonConfig(gsonBuilder);
5355
GsonBuilder loggerBuilder = new GsonBuilder();
5456
loggerBuilder.disableHtmlEscaping();
55-
loggerBuilder.setExclusionStrategies(new LoggingExclusionStrategy(s_logger));
57+
excluder = new LoggingExclusionStrategy(s_logger);
58+
loggerBuilder.setExclusionStrategies(getExcluder());
5659
s_gogger = setDefaultGsonConfig(loggerBuilder);
5760
s_logger.info("Default Builder inited.");
5861
}
@@ -93,4 +96,8 @@ public final static Gson getGsonLogger() {
9396
public final static Logger getLogger() {
9497
return s_logger;
9598
}
99+
100+
public static ExclusionStrategy getExcluder() {
101+
return excluder;
102+
}
96103
}

core/src/org/apache/cloudstack/agent/transport/AnswerArrayTypeAdaptor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ protected void writeElement(JsonWriter out, Answer elem) {
2020
try {
2121
String data = _gson.toJson(elem);
2222
if(data != null && !data.equals("null")) {
23+
out.beginObject();
2324
out.name(elem.getClass().getCanonicalName());
2425
out.jsonValue(data);
26+
out.endObject();
2527
}
2628
} catch (IOException e) {
2729
throw new CloudRuntimeException("serializing json failed for " + elem.getClass(), e);

core/src/org/apache/cloudstack/agent/transport/CommandArrayTypeAdaptor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.lang.reflect.Array;
55

66
import com.cloud.agent.api.Command;
7+
import com.cloud.serializer.GsonHelper;
8+
import com.google.gson.ExclusionStrategy;
79
import com.google.gson.Gson;
810
import com.google.gson.TypeAdapter;
911
import com.google.gson.stream.JsonWriter;
@@ -21,7 +23,13 @@ public void initGson(Gson gson) {
2123

2224
@Override
2325
protected void writeElement(JsonWriter out, Command elem) throws IOException {
24-
_adaptor.write(out,elem);
26+
// get the gsonHelper.
27+
ExclusionStrategy excluder = GsonHelper.getExcluder();
28+
if (!excluder.shouldSkipClass(elem.getClass())) {
29+
out.beginObject();
30+
_adaptor.write(out,elem);
31+
out.endObject();
32+
}
2533
}
2634

2735
}

core/src/org/apache/cloudstack/agent/transport/GenericArrayTypeAdaptor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public void write(JsonWriter out, T[] value) throws IOException {
2828
}
2929
out.beginArray();
3030
for (T elem : (T[])value) {
31-
out.beginObject();
3231
writeElement(out, elem);
33-
out.endObject();
3432
}
3533
out.endArray();
3634
}

core/test/com/cloud/agent/transport/RequestTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,10 @@ public void testLogging() {
219219
Logger logger = Logger.getLogger(GsonHelper.class);
220220
Level level = logger.getLevel();
221221

222+
String log;
223+
222224
logger.setLevel(Level.DEBUG);
223-
String log = sreq.log("Debug", true, Level.DEBUG);
225+
log = sreq.log("Debug", true, Level.DEBUG);
224226
assertNull("did not expect a string for this level." + log , log);
225227

226228
log = sreq.log("Debug", false, Level.DEBUG);

0 commit comments

Comments
 (0)