reverted an unintended change

This commit is contained in:
Alex Huang 2011-06-13 10:59:09 -07:00
parent 2f4ffb590e
commit 60db03f6be
1 changed files with 43 additions and 14 deletions

View File

@ -29,7 +29,6 @@ import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.SecStorageFirewallCfgCommand.PortConfig;
import com.cloud.exception.UnsupportedVersionException;
import com.cloud.storage.VolumeVO;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
@ -93,8 +92,8 @@ public class Request {
s_gBuilder = new GsonBuilder();
s_gBuilder.registerTypeAdapter(Command[].class, new ArrayTypeAdaptor<Command>());
s_gBuilder.registerTypeAdapter(Answer[].class, new ArrayTypeAdaptor<Answer>());
final Type listType = new TypeToken<List<VolumeVO>>() {}.getType();
s_gBuilder.registerTypeAdapter(listType, new VolListTypeAdaptor());
// final Type listType = new TypeToken<List<VolumeVO>>() {}.getType();
// s_gBuilder.registerTypeAdapter(listType, new VolListTypeAdaptor());
s_gBuilder.registerTypeAdapter(new TypeToken<List<PortConfig>>() {}.getType(), new PortConfigListTypeAdaptor());
s_gBuilder.registerTypeAdapter(new TypeToken<Pair<Long, Long>>() {}.getType(), new NwGroupsCommandTypeAdaptor());
s_logger.info("Builder inited.");
@ -122,6 +121,7 @@ public class Request {
_seq = seq;
_agentId = agentId;
_mgmtId = mgmtId;
setInSequence(cmds);
}
protected Request(Version ver, long seq, long agentId, long mgmtId, short flags, final String content) {
@ -140,6 +140,18 @@ public class Request {
setRevertOnError(revert);
}
protected void setInSequence(Command[] cmds) {
if (cmds == null) {
return;
}
for (Command cmd : cmds) {
if (cmd.executeInSequence()) {
setInSequence(true);
break;
}
}
}
protected Request(final Request that, final Command[] cmds) {
this._ver = that._ver;
this._seq = that._seq;
@ -290,6 +302,34 @@ public class Request {
protected short getFlags() {
return (short)(((this instanceof Response) ? FLAG_RESPONSE : FLAG_REQUEST) | _flags);
}
public void log(long agentId, String msg) {
if (!s_logger.isDebugEnabled()) {
return;
}
StringBuilder buf = new StringBuilder("Seq ");
buf.append(agentId).append("-").append(_seq).append(": ");
boolean debug = false;
if (_cmds != null) {
for (Command cmd : _cmds) {
if (!cmd.logTrace()) {
debug = true;
break;
}
}
} else {
debug = true;
}
buf.append(msg).append(toString());
if (executeInSequence() || debug) {
s_logger.debug(buf.toString());
} else {
s_logger.trace(buf.toString());
}
}
/**
* Factory method for Request and Response. It expects the bytes to be
@ -379,10 +419,6 @@ public class Request {
}
public static class NwGroupsCommandTypeAdaptor implements JsonDeserializer<Pair<Long, Long>>, JsonSerializer<Pair<Long,Long>> {
static final GsonBuilder s_gBuilder;
static {
s_gBuilder = Request.initBuilder();
}
public NwGroupsCommandTypeAdaptor() {
}
@ -432,12 +468,6 @@ public class Request {
}
public static class PortConfigListTypeAdaptor implements JsonDeserializer<List<PortConfig>>, JsonSerializer<List<PortConfig>> {
static final GsonBuilder s_gBuilder;
static {
s_gBuilder = Request.initBuilder();
}
static final Type listType = new TypeToken<List<PortConfig>>() {}.getType();
public PortConfigListTypeAdaptor() {
}
@ -474,6 +504,5 @@ public class Request {
}
return pcs;
}
}
}