Fixes to de-couple the AffinityGroupResponse from UserVmResponse, since ApiDiscoveryService breaks, if we nest two response objects into each other.

This commit is contained in:
Prachi Damle 2013-04-05 17:01:06 -07:00
parent 3403b54773
commit 0f565f2167
3 changed files with 16 additions and 26 deletions

View File

@ -16,8 +16,10 @@
// under the License.
package org.apache.cloudstack.affinity;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.cloudstack.api.ApiConstants;
@ -57,12 +59,12 @@ public class AffinityGroupResponse extends BaseResponse implements ControlledVie
@Param(description = "the type of the affinity group")
private String type;
@SerializedName("virtualmachine")
@Param(description = "virtual machines associated with this affinity group ", responseObject = UserVmResponse.class)
private Set<UserVmResponse> vmList;
@SerializedName("virtualmachineIds")
@Param(description = "virtual machine Ids associated with this affinity group ")
private List<String> vmIdList;
public AffinityGroupResponse() {
this.vmList = new LinkedHashSet<UserVmResponse>();
this.vmIdList = new ArrayList<String>();
}
@Override
@ -142,12 +144,12 @@ public class AffinityGroupResponse extends BaseResponse implements ControlledVie
}
public void setVMList(Set<UserVmResponse> vmList) {
this.vmList = vmList;
public void setVMIdList(List<String> vmIdList) {
this.vmIdList = vmIdList;
}
public void addVM(UserVmResponse vm) {
this.vmList.add(vm);
public void addVMId(String vmId) {
this.vmIdList.add(vmId);
}
}

View File

@ -25,13 +25,10 @@ import javax.inject.Inject;
import org.apache.cloudstack.affinity.AffinityGroup;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.query.vo.AffinityGroupJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.user.Account;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@ -72,13 +69,9 @@ public class AffinityGroupJoinDaoImpl extends GenericDaoBase<AffinityGroupJoinVO
// update vm information
long instanceId = vag.getVmId();
if (instanceId > 0) {
UserVmResponse resp = new UserVmResponse();
resp.setObjectName("virtualmachine");
resp.setId(vag.getVmUuid());
resp.setName(vag.getVmName());
resp.setDisplayName(vag.getVmDisplayName());
resp.setState(vag.getVmState().toString());
agResponse.addVM(resp);
List<String> vmIdList = new ArrayList<String>();
vmIdList.add(vag.getVmUuid());
agResponse.setVMIdList(vmIdList);
}
agResponse.setObjectName("affinitygroup");
@ -90,13 +83,7 @@ public class AffinityGroupJoinDaoImpl extends GenericDaoBase<AffinityGroupJoinVO
// update vm information
long instanceId = vag.getVmId();
if (instanceId > 0) {
UserVmResponse resp = new UserVmResponse();
resp.setObjectName("virtualmachine");
resp.setId(vag.getVmUuid());
resp.setName(vag.getVmName());
resp.setDisplayName(vag.getVmDisplayName());
resp.setState(vag.getVmState().toString());
vagData.addVM(resp);
vagData.addVMId(vag.getVmUuid());
}
return vagData;
}

View File

@ -162,7 +162,8 @@ CREATE TABLE `cloud`.`affinity_group_vm_map` (
`affinity_group_id` bigint unsigned NOT NULL,
`instance_id` bigint unsigned NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_agvm__group_id` FOREIGN KEY(`affinity_group_id`) REFERENCES `affinity_group`(`id`)
CONSTRAINT `fk_agvm__group_id` FOREIGN KEY(`affinity_group_id`) REFERENCES `affinity_group`(`id`) ON DELETE CASCADE,
CONSTRAINT `fk_affinity_group_vm_map___instance_id` FOREIGN KEY(`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;