gson 1.5 is now in

This commit is contained in:
Alex Huang 2010-11-16 15:22:15 -08:00
parent c03131d9dd
commit 957547a65f
12 changed files with 71 additions and 53 deletions

View File

@ -317,7 +317,7 @@
<fileset dir="${deps.dir}">
<include name="log4j-1.2.15.jar" />
<include name="apache-log4j-extras-1.0.jar" />
<include name="gson-1.5.jar" />
<include name="gson.jar" />
</fileset>
</copy>

View File

@ -57,7 +57,7 @@
<include name="cloud-ws-commons-util-1.0.2.jar" />
<include name="cloud-log4j.jar" />
<include name="cloud-apache-log4j-extras-1.0.jar" />
<include name="cloud-gson-1.3.jar" />
<include name="cloud-gson.jar" />
<include name="cloud-commons-httpclient-3.1.jar" />
<include name="cloud-commons-logging-1.1.1.jar" />
<include name="cloud-commons-collections-3.2.1.jar" />
@ -169,7 +169,7 @@
<include name="cloud-ws-commons-util-1.0.2.jar" />
<include name="cloud-log4j.jar" />
<include name="cloud-apache-log4j-extras-1.0.jar" />
<include name="cloud-gson-1.3.jar" />
<include name="cloud-gson.jar" />
<include name="cloud-commons-httpclient-3.1.jar" />
<include name="cloud-commons-logging-1.1.1.jar" />
<include name="cloud-commons-collections-3.2.1.jar" />

View File

@ -38,7 +38,7 @@ public class ModifyStoragePoolCommand extends Command {
public ModifyStoragePoolCommand(boolean add, StoragePoolVO pool, String localPath) {
this.add = add;
this.pool = pool;
this.pool = new StoragePoolVO(pool);
this.localPath = localPath;
}

View File

@ -21,8 +21,8 @@ import java.util.List;
import com.cloud.storage.VolumeVO;
import com.cloud.vm.DomainRouter;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.DomainRouter.Role;
import com.cloud.vm.DomainRouterVO;
public class StartRouterCommand extends AbstractStartCommand {
@ -46,7 +46,7 @@ public class StartRouterCommand extends AbstractStartCommand {
String routerName, String[] storageIps, List<VolumeVO> vols, boolean mirroredVols,
String guestOSDescription, String mgmtHost) {
super(routerName, storageIps, vols, mirroredVols);
this.router = router;
this.router = new DomainRouterVO(router);
this.networkRateMbps = networkRateMbps;
this.networkRateMulticastMbps = networkRateMulticastMbps;
this.guestOSDescription = guestOSDescription;

View File

@ -38,7 +38,7 @@ public class StartSecStorageVmCommand extends AbstractStartCommand {
protected StartSecStorageVmCommand() {
}
public StartSecStorageVmCommand(int networkRateMbps, int networkRateMulticastMbps, int proxyCmdPort,
SecondaryStorageVmVO secStorageVm, String vmName, String storageHost,
List<VolumeVO> vols, String mgmtHost, int mgmtPort, boolean sslCopy, String guestOSDescription) {
@ -46,7 +46,7 @@ public class StartSecStorageVmCommand extends AbstractStartCommand {
this.networkRateMbps = networkRateMbps;
this.networkRateMulticastMbps = networkRateMulticastMbps;
this.proxyCmdPort = proxyCmdPort;
this.secStorageVm = secStorageVm;
this.secStorageVm = new SecondaryStorageVmVO(secStorageVm);
this.mgmt_host = mgmtHost;
this.mgmt_port = mgmtPort;

View File

@ -22,10 +22,9 @@ import java.lang.reflect.Array;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.cloud.agent.api.Command;
import com.cloud.storage.VolumeVO;
import com.cloud.utils.exception.CloudRuntimeException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -33,19 +32,18 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
public class ArrayTypeAdaptor<T> implements JsonDeserializer<T[]>, JsonSerializer<T[]> {
static final GsonBuilder s_gBuilder;
static {
s_gBuilder = new GsonBuilder();
final Type listType = new TypeToken<List<VolumeVO>>() {}.getType();
s_gBuilder.registerTypeAdapter(listType, new VolListTypeAdaptor());
s_gBuilder = Request.initBuilder();
// final Type listType = new TypeToken<List<VolumeVO>>() {}.getType();
// s_gBuilder.registerTypeAdapter(listType, new VolListTypeAdaptor());
}
@ -53,35 +51,39 @@ public class ArrayTypeAdaptor<T> implements JsonDeserializer<T[]>, JsonSerialize
public ArrayTypeAdaptor() {
}
@Override
public JsonElement serialize(T[] src, Type typeOfSrc, JsonSerializationContext context) {
Gson gson = s_gBuilder.create();
JsonArray array = new JsonArray();
for (T cmd : src) {
String result = gson.toJson(cmd);
array.add(new JsonPrimitive(cmd.getClass().getName().substring(s_pkg.length())));
array.add(new JsonPrimitive(result));
JsonObject obj = new JsonObject();
obj.add(cmd.getClass().getName().substring(s_pkg.length()), gson.toJsonTree(cmd));
array.add(obj);
}
return array;
}
@Override
@SuppressWarnings("unchecked")
public T[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
JsonArray array = json.getAsJsonArray();
Iterator<JsonElement> it = array.iterator();
ArrayList<T> cmds = new ArrayList<T>();
Gson gson = Request.initBuilder().create();
Gson gson = s_gBuilder.create();
while (it.hasNext()) {
JsonElement element = it.next();
String name = s_pkg + element.getAsString();
JsonObject element = (JsonObject)it.next();
Map.Entry<String, JsonElement> entry = element.entrySet().iterator().next();
String name = s_pkg + entry.getKey();
Class<?> clazz;
try {
clazz = Class.forName(name);
} catch (ClassNotFoundException e) {
throw new CloudRuntimeException("can't find " + name);
}
T cmd = (T)gson.fromJson(it.next().getAsString(), clazz);
T cmd = (T)gson.fromJson(entry.getValue(), clazz);
cmds.add(cmd);
}
Class<?> type = ((Class<?>)typeOfT).getComponentType();

View File

@ -161,6 +161,7 @@ public class StoragePoolVO implements StoragePool {
private Long clusterId;
@Override
public Long getClusterId() {
return clusterId;
}
@ -195,6 +196,10 @@ public class StoragePoolVO implements StoragePool {
this.setStatus(Status.Up);
}
public StoragePoolVO(StoragePoolVO that) {
this(that.id, that.name, that.uuid, that.poolType, that.dataCenterId, that.podId, that.availableBytes, that.capacityBytes, that.hostAddress, that.port, that.path);
}
public StoragePoolVO(StoragePoolType type, String hostAddress, int port, String path) {
this.poolType = type;
this.hostAddress = hostAddress;
@ -224,6 +229,7 @@ public class StoragePoolVO implements StoragePool {
this.uuid = uuid;
}
@Override
public int getPort() {
return port;
}
@ -257,7 +263,8 @@ public class StoragePoolVO implements StoragePool {
return null;
}
public Long getPodId() {
@Override
public Long getPodId() {
return podId;
}

View File

@ -90,6 +90,11 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter {
@Enumerated(EnumType.STRING)
private Role role = Role.DHCP_FIREWALL_LB_PASSWD_USERDATA;
public DomainRouterVO(DomainRouterVO that) {
this(that.id, that.serviceOfferingId, that.instanceName, that.privateMacAddress, that.privateIpAddress, that.privateNetmask, that.templateId, that.guestOSId, that.guestMacAddress, that.guestIpAddress, that.guestNetmask, that.accountId, that.domainId, that.publicMacAddress, that.publicIpAddress, that.publicNetmask, that.vlanDbId, that.vlanId, that.podId, that.dataCenterId, that.ramSize, that.gateway, that.domain, that.dns1, that.dns2);
this.vnet = that.vnet;
}
public DomainRouterVO(long id,
long serviceOfferingId,
String name,

View File

@ -26,8 +26,6 @@ import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import com.cloud.vm.VirtualMachine.Type;
/**
* SecondaryStorageVmVO domain object
@ -87,7 +85,9 @@ public class SecondaryStorageVmVO extends VMInstanceVO implements SecondaryStora
@Temporal(TemporalType.TIMESTAMP)
@Column(name="last_update", updatable=true, nullable=true)
private Date lastUpdateTime;
private Date lastUpdateTime;
public SecondaryStorageVmVO(long id, long serviceOfferingId, String name, long templateId, long guestOSId, long dataCenterId,
long domainId, long accountId) {
@ -140,6 +140,10 @@ public class SecondaryStorageVmVO extends VMInstanceVO implements SecondaryStora
this.ramSize = ramSize;
this.setGuid(guid);
this.nfsShare = nfsShare;
}
public SecondaryStorageVmVO(SecondaryStorageVmVO that) {
this(that.id, that.serviceOfferingId, that.instanceName, that.guestMacAddress, that.guestIpAddress, that.guestNetmask, that.privateMacAddress, that.privateIpAddress, that.privateNetmask, that.templateId, that.guestOSId, that.publicMacAddress, that.publicIpAddress, that.publicNetmask, that.vlanDbId, that.vlanId, that.podId, that.dataCenterId, that.domainId, that.accountId, that.gateway, that.hostId, that.dns1, that.dns2, that.domain, that.ramSize, that.guid, that.nfsShare);
}
protected SecondaryStorageVmVO() {

View File

@ -47,20 +47,20 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
@Id
@TableGenerator(name="vm_instance_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="vm_instance_seq", allocationSize=1)
@Column(name="id", updatable=false, nullable = false)
private long id;
protected long id;
@Column(name="name", updatable=false, nullable=false, length=255)
private String hostName = null;
protected String hostName = null;
@Column(name="vnc_password", updatable=true, nullable=false, length=255)
String vncPassword;
protected String vncPassword;
@Column(name="proxy_id", updatable=true, nullable=true)
Long proxyId;
protected Long proxyId;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="proxy_assign_time", updatable=true, nullable=true)
Date proxyAssignTime;
protected Date proxyAssignTime;
/**
* Note that state is intentionally missing the setter. Any updates to
@ -70,72 +70,72 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
@Enumerated(value=EnumType.STRING)
@StateMachine(state=State.class, event=Event.class)
@Column(name="state", updatable=true, nullable=false, length=32)
private State state = null;
protected State state = null;
@Column(name="private_ip_address", updatable=true)
private String privateIpAddress;
protected String privateIpAddress;
@Column(name="instance_name", updatable=true, nullable=false)
private String instanceName;
protected String instanceName;
@Column(name="vm_template_id", updatable=false, nullable=true, length=17)
private Long templateId = new Long(-1);
protected Long templateId = new Long(-1);
@Column(name="guest_os_id", nullable=false, length=17)
private long guestOSId;
protected long guestOSId;
@Column(name="host_id", updatable=true, nullable=true)
private Long hostId;
protected Long hostId;
@Column(name="last_host_id", updatable=true, nullable=true)
private Long lastHostId;
protected Long lastHostId;
@Column(name="pod_id", updatable=true, nullable=false)
private Long podId;
protected Long podId;
@Column(name="private_mac_address", updatable=true, nullable=true)
String privateMacAddress;
protected String privateMacAddress;
@Column(name="private_netmask")
private String privateNetmask;
protected String privateNetmask;
@Column(name="data_center_id", updatable=true, nullable=false)
long dataCenterId;
protected long dataCenterId;
@Column(name="type", updatable=false, nullable=false, length=32)
@Enumerated(value=EnumType.STRING)
Type type;
protected Type type;
@Column(name="ha_enabled", updatable=true, nullable=true)
boolean haEnabled;
protected boolean haEnabled;
@Column(name="mirrored_vols", updatable=true, nullable=true)
boolean mirroredVols;
protected boolean mirroredVols;
@Column(name="update_count", updatable = true, nullable=false)
long updated; // This field should be updated everytime the state is updated. There's no set method in the vo object because it is done with in the dao code.
protected long updated; // This field should be updated everytime the state is updated. There's no set method in the vo object because it is done with in the dao code.
@Column(name=GenericDao.CREATED_COLUMN)
Date created;
protected Date created;
@Column(name=GenericDao.REMOVED_COLUMN)
Date removed;
protected Date removed;
@Column(name="update_time", updatable=true)
@Temporal(value=TemporalType.TIMESTAMP)
Date updateTime;
protected Date updateTime;
@Column(name="domain_id")
long domainId;
protected long domainId;
@Column(name="account_id")
long accountId;
protected long accountId;
@Column(name="service_offering_id")
long serviceOfferingId;
protected long serviceOfferingId;
@Column(name="reservation_id")
String reservationId;
protected String reservationId;
public VMInstanceVO(long id,
long serviceOfferingId,

Binary file not shown.

BIN
deps/cloud-gson.jar vendored Normal file

Binary file not shown.