diff --git a/api/src/com/cloud/api/response/BaseResponse.java b/api/src/com/cloud/api/response/BaseResponse.java index 14aa2b920c0..dbe84202e39 100755 --- a/api/src/com/cloud/api/response/BaseResponse.java +++ b/api/src/com/cloud/api/response/BaseResponse.java @@ -46,17 +46,26 @@ public abstract class BaseResponse implements ResponseObject { this.objectName = objectName; } + //TODO: TO be replaced by getObjectUuid() after all response refactoring public Long getObjectId() { return null; } + public String getObjectUuid(){ + return null; + } + // For use by list commands with pending async jobs - @SerializedName(ApiConstants.JOB_ID) @Param(description="the ID of the latest async job acting on this object") + //TODO: To be replaced by jobUuid after all response refactoring protected IdentityProxy jobId = new IdentityProxy("async_job"); + @SerializedName(ApiConstants.JOB_ID) @Param(description="the UUID of the latest async job acting on this object") + protected String jobUuid; + @SerializedName(ApiConstants.JOB_STATUS) @Param(description="the current status of the latest async job acting on this object") private Integer jobStatus; + //TODO: TO be replaced by getter and setters for jobUuid. public Long getJobId() { return jobId.getValue(); } @@ -65,6 +74,14 @@ public abstract class BaseResponse implements ResponseObject { this.jobId.setValue(jobId); } + public String getJobUuid() { + return jobUuid; + } + + public void setJobUuid(String jobUuid) { + this.jobUuid = jobUuid; + } + public Integer getJobStatus() { return jobStatus; } diff --git a/api/src/com/cloud/api/response/ControlledViewEntityResponse.java b/api/src/com/cloud/api/response/ControlledViewEntityResponse.java new file mode 100644 index 00000000000..471a8d1000d --- /dev/null +++ b/api/src/com/cloud/api/response/ControlledViewEntityResponse.java @@ -0,0 +1,31 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.api.response; + +public interface ControlledViewEntityResponse { + + public void setAccountName(String accountName); + + public void setProjectId(String projectId); + + public void setProjectName(String projectName); + + public void setDomainId(String domainId); + + public void setDomainName(String domainName); +} + diff --git a/api/src/com/cloud/api/response/DomainRouterResponse.java b/api/src/com/cloud/api/response/DomainRouterResponse.java index 8170b2efa41..6db46fad429 100644 --- a/api/src/com/cloud/api/response/DomainRouterResponse.java +++ b/api/src/com/cloud/api/response/DomainRouterResponse.java @@ -18,6 +18,9 @@ package com.cloud.api.response; import java.util.Date; import java.util.List; +import java.util.HashSet; +import java.util.Set; + import org.apache.cloudstack.api.ApiConstants; import com.cloud.serializer.Param; @@ -26,12 +29,12 @@ import com.cloud.vm.VirtualMachine.State; import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") -public class DomainRouterResponse extends BaseResponse implements ControlledEntityResponse{ +public class DomainRouterResponse extends BaseResponse implements ControlledViewEntityResponse{ @SerializedName(ApiConstants.ID) @Param(description="the id of the router") - private IdentityProxy id = new IdentityProxy("vm_instance"); + private String id; @SerializedName(ApiConstants.ZONE_ID) @Param(description="the Zone ID for the router") - private IdentityProxy zoneId = new IdentityProxy("data_center"); + private String zoneId; @SerializedName(ApiConstants.ZONE_NAME) @Param(description="the Zone name for the router") private String zoneName; @@ -52,10 +55,10 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti private String name; @SerializedName(ApiConstants.POD_ID) @Param(description="the Pod ID for the router") - private IdentityProxy podId = new IdentityProxy("host_pod_ref"); + private String podId; @SerializedName(ApiConstants.HOST_ID) @Param(description="the host ID for the router") - private IdentityProxy hostId = new IdentityProxy("host"); + private String hostId; @SerializedName("hostname") @Param(description="the hostname for the router") private String hostName; @@ -70,7 +73,7 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti private String linkLocalNetmask; @SerializedName(ApiConstants.LINK_LOCAL_NETWORK_ID) @Param(description="the ID of the corresponding link local network") - private IdentityProxy linkLocalNetworkId = new IdentityProxy("networks"); + private String linkLocalNetworkId; @SerializedName(ApiConstants.PUBLIC_IP) @Param(description="the public IP address for the router") private String publicIp; @@ -82,7 +85,7 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti private String publicNetmask; @SerializedName("publicnetworkid") @Param(description="the ID of the corresponding public network") - private IdentityProxy publicNetworkId = new IdentityProxy("networks"); + private String publicNetworkId; @SerializedName("guestipaddress") @Param(description="the guest IP address for the router") private String guestIpAddress; @@ -94,10 +97,10 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti private String guestNetmask; @SerializedName("guestnetworkid") @Param(description="the ID of the corresponding guest network") - private IdentityProxy guestNetworkId = new IdentityProxy("networks"); + private String guestNetworkId; @SerializedName(ApiConstants.TEMPLATE_ID) @Param(description="the template ID for the router") - private IdentityProxy templateId = new IdentityProxy("vm_template"); + private String templateId; @SerializedName(ApiConstants.CREATED) @Param(description="the date and time the router was created") private Date created; @@ -109,19 +112,19 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti private String accountName; @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the ipaddress") - private IdentityProxy projectId = new IdentityProxy("projects"); + private String projectId; @SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the address") private String projectName; @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain ID associated with the router") - private IdentityProxy domainId = new IdentityProxy("domain"); + private String domainId; @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain associated with the router") private String domainName; @SerializedName(ApiConstants.SERVICE_OFFERING_ID) @Param(description="the ID of the service offering of the virtual machine") - private IdentityProxy serviceOfferingId = new IdentityProxy("disk_offering"); + private String serviceOfferingId; @SerializedName("serviceofferingname") @Param(description="the name of the service offering of the virtual machine") private String serviceOfferingName; @@ -139,27 +142,31 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti private String scriptsVersion; @SerializedName(ApiConstants.VPC_ID) @Param(description="VPC the network belongs to") - private IdentityProxy vpcId = new IdentityProxy("vpc"); + private String vpcId; @SerializedName("nic") @Param(description="the list of nics associated with the router", responseObject = NicResponse.class, since="4.0") - private List nics; + private Set nics; + + public DomainRouterResponse(){ + nics = new HashSet(); + } @Override - public Long getObjectId() { - return getId(); + public String getObjectUuid() { + return this.getId(); } - public Long getId() { - return id.getValue(); + public String getId() { + return id; } - public void setId(Long id) { - this.id.setValue(id); + public void setId(String id) { + this.id = id; } - public void setZoneId(Long zoneId) { - this.zoneId.setValue(zoneId); + public void setZoneId(String zoneId) { + this.zoneId = zoneId; } public void setZoneName(String zoneName) { @@ -186,12 +193,12 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti this.name = name; } - public void setPodId(Long podId) { - this.podId.setValue(podId); + public void setPodId(String podId) { + this.podId = podId; } - public void setHostId(Long hostId) { - this.hostId.setValue(hostId); + public void setHostId(String hostId) { + this.hostId = hostId; } public void setHostName(String hostName) { @@ -222,8 +229,8 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti this.guestNetmask = guestNetmask; } - public void setTemplateId(Long templateId) { - this.templateId.setValue(templateId); + public void setTemplateId(String templateId) { + this.templateId = templateId; } public void setCreated(Date created) { @@ -240,8 +247,8 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti } @Override - public void setDomainId(Long domainId) { - this.domainId.setValue(domainId); + public void setDomainId(String domainId) { + this.domainId = domainId; } @Override @@ -249,12 +256,12 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti this.domainName = domainName; } - public void setPublicNetworkId(Long publicNetworkId) { - this.publicNetworkId.setValue(publicNetworkId); + public void setPublicNetworkId(String publicNetworkId) { + this.publicNetworkId = publicNetworkId; } - public void setGuestNetworkId(Long guestNetworkId) { - this.guestNetworkId.setValue(guestNetworkId); + public void setGuestNetworkId(String guestNetworkId) { + this.guestNetworkId = guestNetworkId; } public void setLinkLocalIp(String linkLocalIp) { @@ -269,12 +276,12 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti this.linkLocalNetmask = linkLocalNetmask; } - public void setLinkLocalNetworkId(Long linkLocalNetworkId) { - this.linkLocalNetworkId.setValue(linkLocalNetworkId); + public void setLinkLocalNetworkId(String linkLocalNetworkId) { + this.linkLocalNetworkId = linkLocalNetworkId; } - public void setServiceOfferingId(Long serviceOfferingId) { - this.serviceOfferingId.setValue(serviceOfferingId); + public void setServiceOfferingId(String serviceOfferingId) { + this.serviceOfferingId = serviceOfferingId; } public void setServiceOfferingName(String serviceOfferingName) { @@ -305,8 +312,8 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti this.scriptsVersion = scriptsVersion; } @Override - public void setProjectId(Long projectId) { - this.projectId.setValue(projectId); + public void setProjectId(String projectId) { + this.projectId = projectId; } @Override @@ -314,11 +321,15 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti this.projectName = projectName; } - public void setVpcId(Long vpcId) { - this.vpcId.setValue(vpcId); + public void setVpcId(String vpcId) { + this.vpcId = vpcId; } - public void setNics(List nics) { + public void setNics(Set nics) { this.nics = nics; } + + public void addNic(NicResponse nic) { + this.nics.add(nic); + } } diff --git a/api/src/com/cloud/api/response/NicResponse.java b/api/src/com/cloud/api/response/NicResponse.java index e27a8cf19f5..7001e12c015 100755 --- a/api/src/com/cloud/api/response/NicResponse.java +++ b/api/src/com/cloud/api/response/NicResponse.java @@ -17,7 +17,6 @@ package com.cloud.api.response; import org.apache.cloudstack.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @@ -25,10 +24,10 @@ import com.google.gson.annotations.SerializedName; public class NicResponse extends BaseResponse { @SerializedName("id") @Param(description="the ID of the nic") - private final IdentityProxy id = new IdentityProxy("nics"); + private String id; @SerializedName("networkid") @Param(description="the ID of the corresponding network") - private final IdentityProxy networkId = new IdentityProxy("networks"); + private String networkId; @SerializedName("networkname") @Param(description="the name of the corresponding network") private String networkName ; @@ -60,16 +59,21 @@ public class NicResponse extends BaseResponse { @SerializedName("macaddress") @Param(description="true if nic is default, false otherwise") private String macAddress; - public Long getId() { - return id.getValue(); + public String getId() { + return id; } - public void setId(Long id) { - this.id.setValue(id); + public void setId(String id) { + this.id = id; } - public void setNetworkid(Long networkid) { - this.networkId.setValue(networkid); + @Override + public String getObjectUuid() { + return this.getId(); + } + + public void setNetworkid(String networkid) { + this.networkId = networkid; } public void setNetworkName(String networkname) { @@ -116,7 +120,8 @@ public class NicResponse extends BaseResponse { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); + String oid = this.getId(); + result = prime * result + ((oid== null) ? 0 : oid.hashCode()); return result; } @@ -129,10 +134,11 @@ public class NicResponse extends BaseResponse { if (getClass() != obj.getClass()) return false; NicResponse other = (NicResponse) obj; - if (id == null) { - if (other.id != null) + String oid = this.getId(); + if (oid == null) { + if (other.getId() != null) return false; - } else if (!id.equals(other.id)) + } else if (!oid.equals(other.getId())) return false; return true; } diff --git a/api/src/com/cloud/api/response/UserVmResponse.java b/api/src/com/cloud/api/response/UserVmResponse.java index e7665b5404b..572d4ed2d11 100755 --- a/api/src/com/cloud/api/response/UserVmResponse.java +++ b/api/src/com/cloud/api/response/UserVmResponse.java @@ -17,20 +17,21 @@ package com.cloud.api.response; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.Entity; import com.cloud.vm.VirtualMachine; import com.cloud.serializer.Param; -import com.cloud.utils.IdentityProxy; import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") @Entity(value = VirtualMachine.class) public class UserVmResponse extends BaseResponse implements ControlledEntityResponse { @SerializedName(ApiConstants.ID) @Param(description="the ID of the virtual machine") - private IdentityProxy id = new IdentityProxy("vm_instance"); + private String id; @SerializedName(ApiConstants.NAME) @Param(description="the name of the virtual machine") private String name; @@ -42,13 +43,13 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp private String accountName; @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the vm") - private IdentityProxy projectId = new IdentityProxy("projects"); + private String projectId; @SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the vm") private String projectName; @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the ID of the domain in which the virtual machine exists") - private IdentityProxy domainId = new IdentityProxy("domain"); + private String domainId; @SerializedName(ApiConstants.DOMAIN) @Param(description="the name of the domain in which the virtual machine exists") private String domainName; @@ -63,25 +64,25 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp private Boolean haEnable; @SerializedName(ApiConstants.GROUP_ID) @Param(description="the group ID of the virtual machine") - private IdentityProxy groupId = new IdentityProxy("instance_group"); + private String groupId; @SerializedName(ApiConstants.GROUP) @Param(description="the group name of the virtual machine") private String group; @SerializedName(ApiConstants.ZONE_ID) @Param(description="the ID of the availablility zone for the virtual machine") - private IdentityProxy zoneId = new IdentityProxy("data_center"); + private String zoneId; @SerializedName(ApiConstants.ZONE_NAME) @Param(description="the name of the availability zone for the virtual machine") private String zoneName; @SerializedName(ApiConstants.HOST_ID) @Param(description="the ID of the host for the virtual machine") - private IdentityProxy hostId = new IdentityProxy("host"); + private String hostId; @SerializedName("hostname") @Param(description="the name of the host for the virtual machine") private String hostName; @SerializedName(ApiConstants.TEMPLATE_ID) @Param(description="the ID of the template for the virtual machine. A -1 is returned if the virtual machine was created from an ISO file.") - private IdentityProxy templateId = new IdentityProxy("vm_template"); + private String templateId; @SerializedName("templatename") @Param(description="the name of the template for the virtual machine") private String templateName; @@ -93,7 +94,7 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp private Boolean passwordEnabled; @SerializedName("isoid") @Param(description="the ID of the ISO attached to the virtual machine") - private IdentityProxy isoId = new IdentityProxy("vm_template"); + private String isoId; @SerializedName("isoname") @Param(description="the name of the ISO attached to the virtual machine") private String isoName; @@ -102,7 +103,7 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp private String isoDisplayText; @SerializedName(ApiConstants.SERVICE_OFFERING_ID) @Param(description="the ID of the service offering of the virtual machine") - private IdentityProxy serviceOfferingId = new IdentityProxy("disk_offering"); + private String serviceOfferingId; @SerializedName("serviceofferingname") @Param(description="the name of the service offering of the virtual machine") private String serviceOfferingName; @@ -129,7 +130,7 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp private Long networkKbsWrite; @SerializedName("guestosid") @Param(description="Os type ID of the virtual machine") - private IdentityProxy guestOsId = new IdentityProxy("guest_os"); + private String guestOsId; @SerializedName("rootdeviceid") @Param(description="device ID of the root volume") private Long rootDeviceId; @@ -138,19 +139,19 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp private String rootDeviceType; @SerializedName("securitygroup") @Param(description="list of security groups associated with the virtual machine", responseObject = SecurityGroupResponse.class) - private List securityGroupList; + private Set securityGroupList; @SerializedName(ApiConstants.PASSWORD) @Param(description="the password (if exists) of the virtual machine") private String password; @SerializedName("nic") @Param(description="the list of nics associated with vm", responseObject = NicResponse.class) - private List nics; + private Set nics; @SerializedName("hypervisor") @Param(description="the hypervisor on which the template runs") private String hypervisor; @SerializedName(ApiConstants.PUBLIC_IP_ID) @Param(description="public IP address id associated with vm via Static nat rule") - private IdentityProxy publicIpId = new IdentityProxy("user_ip_address"); + private String publicIpId; @SerializedName(ApiConstants.PUBLIC_IP) @Param(description="public IP address id associated with vm via Static nat rule") private String publicIp; @@ -159,21 +160,32 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp private String instanceName; @SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with vm", responseObject = ResourceTagResponse.class) - private List tags; + private Set tags; @SerializedName(ApiConstants.SSH_KEYPAIR) @Param(description="ssh key-pair") private String keyPairName; + public UserVmResponse(){ + securityGroupList = new HashSet(); + nics = new HashSet(); + tags = new HashSet(); + } + public void setHypervisor(String hypervisor) { this.hypervisor = hypervisor; } - public void setId(Long id) { - this.id.setValue(id); + public void setId(String id) { + this.id = id; } - public Long getId() { - return this.id.getValue(); + public String getId() { + return this.id; + } + + @Override + public String getObjectUuid() { + return this.getId(); } public void setName(String name) { @@ -188,8 +200,8 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp this.accountName = accountName; } - public void setDomainId(Long domainId) { - this.domainId.setValue(domainId); + public void setDomainId(String domainId) { + this.domainId = domainId; } public void setDomainName(String domainName) { @@ -208,32 +220,32 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp this.haEnable = haEnable; } - public void setGroupId(Long groupId) { - this.groupId.setValue(groupId); + public void setGroupId(String groupId) { + this.groupId = groupId; } public void setGroup(String group) { this.group = group; } - public void setZoneId(Long zoneId) { - this.zoneId.setValue(zoneId); + public void setZoneId(String zoneId) { + this.zoneId = zoneId; } public void setZoneName(String zoneName) { this.zoneName = zoneName; } - public void setHostId(Long hostId) { - this.hostId.setValue(hostId); + public void setHostId(String hostId) { + this.hostId = hostId; } public void setHostName(String hostName) { this.hostName = hostName; } - public void setTemplateId(Long templateId) { - this.templateId.setValue(templateId); + public void setTemplateId(String templateId) { + this.templateId = templateId; } public void setTemplateName(String templateName) { @@ -248,8 +260,8 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp this.passwordEnabled = passwordEnabled; } - public void setIsoId(Long isoId) { - this.isoId.setValue(isoId); + public void setIsoId(String isoId) { + this.isoId = isoId; } public void setIsoName(String isoName) { @@ -260,8 +272,8 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp this.isoDisplayText = isoDisplayText; } - public void setServiceOfferingId(Long serviceOfferingId) { - this.serviceOfferingId.setValue(serviceOfferingId); + public void setServiceOfferingId(String serviceOfferingId) { + this.serviceOfferingId = serviceOfferingId; } public void setServiceOfferingName(String serviceOfferingName) { @@ -292,8 +304,8 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp this.networkKbsWrite = networkKbsWrite; } - public void setGuestOsId(Long guestOsId) { - this.guestOsId.setValue(guestOsId); + public void setGuestOsId(String guestOsId) { + this.guestOsId = guestOsId; } public void setRootDeviceId(Long rootDeviceId) { @@ -308,30 +320,24 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp this.password = password; } -/* - public void setJobId(Long jobId) { - super.setJobId(jobId); - } - - public void setJobStatus(Integer jobStatus) { - this.jobStatus = jobStatus; - } -*/ public void setForVirtualNetwork(Boolean forVirtualNetwork) { this.forVirtualNetwork = forVirtualNetwork; } - public void setNics(List nics) { + public void setNics(Set nics) { this.nics = nics; } - public void setSecurityGroupList(List securityGroups) { + public void addNic(NicResponse nic) { + this.nics.add(nic); + } + + public void setSecurityGroupList(Set securityGroups) { this.securityGroupList = securityGroups; } - @Override - public void setProjectId(Long projectId) { - this.projectId.setValue(projectId); + public void setProjectId(String projectId) { + this.projectId = projectId; } @Override @@ -339,8 +345,8 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp this.projectName = projectName; } - public void setPublicIpId(Long publicIpId) { - this.publicIpId.setValue(publicIpId); + public void setPublicIpId(String publicIpId) { + this.publicIpId = publicIpId; } public void setPublicIp(String publicIp) { @@ -351,11 +357,33 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp this.instanceName = instanceName; } - public void setTags(List tags) { + public void setTags(Set tags) { this.tags = tags; } + public void addTag(ResourceTagResponse tag){ + this.tags.add(tag); + } + public void setKeyPairName(String keyPairName) { this.keyPairName = keyPairName; } + + @Override + public void setProjectId(Long projectId) { + // TODO: remove this later + } + + @Override + public void setDomainId(Long domainId) { + // TODO: remove this later + } + + public void setProjectUuid(String projectUuid){ + this.projectId = projectUuid; + } + + public void setDomainUuid(String domainUuid){ + this.domainId = domainUuid; + } } diff --git a/api/src/com/cloud/api/view/vo/ControlledViewEntity.java b/api/src/com/cloud/api/view/vo/ControlledViewEntity.java new file mode 100644 index 00000000000..163e001a3c1 --- /dev/null +++ b/api/src/com/cloud/api/view/vo/ControlledViewEntity.java @@ -0,0 +1,45 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.api.view.vo; + +import com.cloud.acl.ControlledEntity; + +/** + * This is the interface for all VO classes representing DB views created for previous ControlledEntity. + * + * @author minc + * + */ +public interface ControlledViewEntity extends ControlledEntity { + + public String getDomainPath(); + + public short getAccountType(); + + public String getAccountUuid(); + + public String getAccountName(); + + public String getDomainUuid(); + + public String getDomainName(); + + public String getProjectUuid(); + + public String getProjectName(); + +} diff --git a/api/src/com/cloud/api/view/vo/DomainRouterJoinVO.java b/api/src/com/cloud/api/view/vo/DomainRouterJoinVO.java new file mode 100644 index 00000000000..58e69bfbb6c --- /dev/null +++ b/api/src/com/cloud/api/view/vo/DomainRouterJoinVO.java @@ -0,0 +1,928 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.api.view.vo; + +import java.net.URI; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Table; + +import com.cloud.network.Network.GuestType; +import com.cloud.network.Networks.TrafficType; +import com.cloud.network.router.VirtualRouter.RedundantState; +import com.cloud.utils.db.GenericDao; +import com.cloud.vm.VirtualMachine.State; + +@Entity +@Table(name="domain_router_view") +public class DomainRouterJoinVO implements ControlledViewEntity { + + @Column(name="id", updatable=false, nullable = false) + private long id; + + @Column(name="name", updatable=false, nullable=false, length=255) + private String name = null; + + + @Column(name="account_id") + private long accountId; + + @Column(name="account_uuid") + private String accountUuid; + + @Column(name="account_name") + private String accountName = null; + + @Column(name="account_type") + private short accountType; + + @Column(name="domain_id") + private long domainId; + + @Column(name="domain_uuid") + private String domainUuid; + + @Column(name="domain_name") + private String domainName = null; + + @Column(name="domain_path") + private String domainPath = null; + + /** + * Note that state is intentionally missing the setter. Any updates to + * the state machine needs to go through the DAO object because someone + * else could be updating it as well. + */ + @Enumerated(value=EnumType.STRING) + @Column(name="state", updatable=true, nullable=false, length=32) + private State state = null; + + @Column(name=GenericDao.CREATED_COLUMN) + private Date created; + + @Column(name=GenericDao.REMOVED_COLUMN) + private Date removed; + + @Column(name="instance_name", updatable=true, nullable=false) + private String instanceName; + + @Column(name="pod_id", updatable=true, nullable=false) + private Long podId; + + @Column(name="pod_uuid") + private String podUuid; + + @Column(name="data_center_id") + private long dataCenterId; + + @Column(name="data_center_uuid") + private String dataCenterUuid; + + @Column(name="data_center_name") + private String dataCenterName = null; + + @Column(name="dns1") + private String dns1 = null; + + @Column(name="dns2") + private String dns2 = null; + + + @Column(name="host_id", updatable=true, nullable=true) + private long hostId; + + @Column(name="host_uuid") + private String hostUuid; + + @Column(name="host_name", nullable=false) + private String hostName; + + @Column(name="template_id", updatable=true, nullable=true, length=17) + private long templateId; + + @Column(name="template_uuid") + private String templateUuid; + + @Column(name="service_offering_id") + private long serviceOfferingId; + + @Column(name="service_offering_uuid") + private String serviceOfferingUuid; + + @Column(name="service_offering_name") + private String serviceOfferingName; + + + @Column(name = "vpc_id") + private long vpcId; + + @Column(name = "vpc_uuid") + private String vpcUuid; + + @Column(name = "nic_id") + private long nicId; + + @Column(name = "nic_uuid") + private String nicUuid; + + @Column(name = "is_default_nic") + private boolean isDefaultNic; + + @Column(name = "ip_address") + private String ipAddress; + + @Column(name = "gateway") + private String gateway; + + @Column(name = "netmask") + private String netmask; + + @Column(name = "mac_address") + private String macAddress; + + @Column(name = "broadcast_uri") + private URI broadcastUri; + + @Column(name = "isolation_uri") + private URI isolationUri; + + @Column(name="network_id") + private long networkId; + + @Column(name="network_uuid") + private String networkUuid; + + @Column(name="network_name") + private String networkName; + + @Column(name="network_domain") + private String networkDomain; + + @Column(name="traffic_type") + @Enumerated(value=EnumType.STRING) + private TrafficType trafficType; + + + @Column(name="project_id") + private long projectId; + + @Column(name="project_uuid") + private String projectUuid; + + @Column(name="project_name") + private String projectName; + + @Column(name="job_id") + private long jobId; + + @Column(name="job_uuid") + private String jobUuid; + + @Column(name="job_status") + private int jobStatus; + + + @Column(name="uuid") + private String uuid; + + @Column(name="template_version") + private String templateVersion; + + @Column(name="scripts_version") + private String scriptsVersion; + + @Column(name="redundant_state") + @Enumerated(EnumType.STRING) + private RedundantState redundantState; + + @Column(name="is_redundant_router") + boolean isRedundantRouter; + + @Column(name="guest_type") + @Enumerated(value=EnumType.STRING) + private GuestType guestType; + + + public DomainRouterJoinVO() { + } + + + + + public String getUuid() { + return uuid; + } + + + + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + + public long getId() { + return id; + } + + + public void setId(long id) { + this.id = id; + } + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + + + public long getAccountId() { + return accountId; + } + + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + + public String getAccountUuid() { + return accountUuid; + } + + + + + public void setAccountUuid(String accountUuid) { + this.accountUuid = accountUuid; + } + + + + + public String getAccountName() { + return accountName; + } + + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + + public short getAccountType() { + return accountType; + } + + + public void setAccountType(short accountType) { + this.accountType = accountType; + } + + + public long getDomainId() { + return domainId; + } + + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + @Override + public String getDomainUuid() { + return domainUuid; + } + + + + + public void setDomainUuid(String domainUuid) { + this.domainUuid = domainUuid; + } + + + + + public String getDomainName() { + return domainName; + } + + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public String getDomainPath() { + return domainPath; + } + + + public void setDomainPath(String domainPath) { + this.domainPath = domainPath; + } + + + public State getState() { + return state; + } + + + public void setState(State state) { + this.state = state; + } + + + public Date getCreated() { + return created; + } + + + public void setCreated(Date created) { + this.created = created; + } + + + public Date getRemoved() { + return removed; + } + + + public void setRemoved(Date removed) { + this.removed = removed; + } + + + public String getInstanceName() { + return instanceName; + } + + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + + public String getPodUuid() { + return podUuid; + } + + + + + public void setPodUuid(String podUuid) { + this.podUuid = podUuid; + } + + + public String getDataCenterUuid() { + return dataCenterUuid; + } + + public void setDataCenterUuid(String zoneUuid) { + this.dataCenterUuid = zoneUuid; + } + + public String getDataCenterName() { + return dataCenterName; + } + + + public void setDataCenterName(String zoneName) { + this.dataCenterName = zoneName; + } + + + public Long getHostId() { + return hostId; + } + + + public void setHostId(long hostId) { + this.hostId = hostId; + } + + + public String getHostUuid() { + return hostUuid; + } + + + + + public void setHostUuid(String hostUuid) { + this.hostUuid = hostUuid; + } + + + + + public String getHostName() { + return hostName; + } + + + public void setHostName(String hostName) { + this.hostName = hostName; + } + + + public long getTemplateId() { + return templateId; + } + + + public void setTemplateId(long templateId) { + this.templateId = templateId; + } + + + + public String getTemplateUuid() { + return templateUuid; + } + + + + + public void setTemplateUuid(String templateUuid) { + this.templateUuid = templateUuid; + } + + + + + + public String getServiceOfferingUuid() { + return serviceOfferingUuid; + } + + + public void setServiceOfferingUuid(String serviceOfferingUuid) { + this.serviceOfferingUuid = serviceOfferingUuid; + } + + + + + public String getServiceOfferingName() { + return serviceOfferingName; + } + + + public void setServiceOfferingName(String serviceOfferingName) { + this.serviceOfferingName = serviceOfferingName; + } + + public long getVpcId() { + return vpcId; + } + + public void setVpcId(long vpcId) { + this.vpcId = vpcId; + } + + + + + public long getNicId() { + return nicId; + } + + + public void setNicId(long nicId) { + this.nicId = nicId; + } + + + public boolean isDefaultNic() { + return isDefaultNic; + } + + + public void setDefaultNic(boolean isDefaultNic) { + this.isDefaultNic = isDefaultNic; + } + + + public String getIpAddress() { + return ipAddress; + } + + + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + + public String getGateway() { + return gateway; + } + + + public void setGateway(String gateway) { + this.gateway = gateway; + } + + + public String getNetmask() { + return netmask; + } + + + public void setNetmask(String netmask) { + this.netmask = netmask; + } + + + public String getMacAddress() { + return macAddress; + } + + + public void setMacAddress(String macAddress) { + this.macAddress = macAddress; + } + + + public URI getBroadcastUri() { + return broadcastUri; + } + + + public void setBroadcastUri(URI broadcastUri) { + this.broadcastUri = broadcastUri; + } + + + public URI getIsolationUri() { + return isolationUri; + } + + + public void setIsolationUri(URI isolationUri) { + this.isolationUri = isolationUri; + } + + + public long getNetworkId() { + return networkId; + } + + + public void setNetworkId(long networkId) { + this.networkId = networkId; + } + + + public String getNetworkName() { + return networkName; + } + + + + + public void setNetworkName(String networkName) { + this.networkName = networkName; + } + + + + + public String getNetworkDomain() { + return networkDomain; + } + + + + + public void setNetworkDomain(String networkDomain) { + this.networkDomain = networkDomain; + } + + + + + public TrafficType getTrafficType() { + return trafficType; + } + + + public void setTrafficType(TrafficType trafficType) { + this.trafficType = trafficType; + } + + + + public long getServiceOfferingId() { + return serviceOfferingId; + } + + + + + public void setServiceOfferingId(long serviceOfferingId) { + this.serviceOfferingId = serviceOfferingId; + } + + + + + public long getProjectId() { + return projectId; + } + + + + + public void setProjectId(long projectId) { + this.projectId = projectId; + } + + + + + public String getProjectUuid() { + return projectUuid; + } + + + + + public void setProjectUuid(String projectUuid) { + this.projectUuid = projectUuid; + } + + + + + public String getProjectName() { + return projectName; + } + + + + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + + + + + + public String getVpcUuid() { + return vpcUuid; + } + + + + + public void setVpcUuid(String vpcUuid) { + this.vpcUuid = vpcUuid; + } + + + + + public String getNicUuid() { + return nicUuid; + } + + + + + public void setNicUuid(String nicUuid) { + this.nicUuid = nicUuid; + } + + + + + public String getNetworkUuid() { + return networkUuid; + } + + + + + public void setNetworkUuid(String networkUuid) { + this.networkUuid = networkUuid; + } + + + public long getJobId() { + return jobId; + } + + + + + public void setJobId(long jobId) { + this.jobId = jobId; + } + + + + + public String getJobUuid() { + return jobUuid; + } + + + + + public void setJobUuid(String jobUuid) { + this.jobUuid = jobUuid; + } + + + + + public int getJobStatus() { + return jobStatus; + } + + + + + public void setJobStatus(int jobStatus) { + this.jobStatus = jobStatus; + } + + + + public Long getPodId() { + return podId; + } + + + + + public void setPodId(Long podId) { + this.podId = podId; + } + + + + + public long getDataCenterId() { + return dataCenterId; + } + + + + + public void setDataCenterId(long zoneId) { + this.dataCenterId = zoneId; + } + + + + + public String getDns1() { + return dns1; + } + + + + + public void setDns1(String dns1) { + this.dns1 = dns1; + } + + + + + public String getDns2() { + return dns2; + } + + + + + public void setDns2(String dns2) { + this.dns2 = dns2; + } + + + + + public String getTemplateVersion() { + return templateVersion; + } + + + + + public void setTemplateVersion(String templateVersion) { + this.templateVersion = templateVersion; + } + + + + + public String getScriptsVersion() { + return scriptsVersion; + } + + + + + public void setScriptsVersion(String scriptsVersion) { + this.scriptsVersion = scriptsVersion; + } + + + + + public RedundantState getRedundantState() { + return redundantState; + } + + + + + public void setRedundantState(RedundantState redundantState) { + this.redundantState = redundantState; + } + + + + + public boolean isRedundantRouter() { + return isRedundantRouter; + } + + + + + public void setRedundantRouter(boolean isRedundantRouter) { + this.isRedundantRouter = isRedundantRouter; + } + + + + + public GuestType getGuestType() { + return guestType; + } + + + + + public void setGuestType(GuestType guestType) { + this.guestType = guestType; + } + + + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (id ^ (id >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DomainRouterJoinVO other = (DomainRouterJoinVO) obj; + if (id != other.id) + return false; + return true; + } +} diff --git a/api/src/com/cloud/api/view/vo/UserVmJoinVO.java b/api/src/com/cloud/api/view/vo/UserVmJoinVO.java new file mode 100644 index 00000000000..1aa137bbda0 --- /dev/null +++ b/api/src/com/cloud/api/view/vo/UserVmJoinVO.java @@ -0,0 +1,1623 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.api.view.vo; + +import java.net.URI; +import java.util.Date; +import java.util.Map; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Table; +import javax.persistence.Transient; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.network.Network.GuestType; +import com.cloud.network.Networks.TrafficType; +import com.cloud.server.ResourceTag.TaggedResourceType; +import com.cloud.storage.Volume; +import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.utils.db.Encrypt; +import com.cloud.utils.db.GenericDao; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.State; + +@Entity +@Table(name="user_vm_view") +public class UserVmJoinVO implements ControlledViewEntity { + + @Column(name="id", updatable=false, nullable = false) + private long id; + + @Column(name="name", updatable=false, nullable=false, length=255) + private String name = null; + + @Column(name="display_name", updatable=false, nullable=false, length=255) + private String displayName = null; + + @Column(name="account_id") + private long accountId; + + @Column(name="account_uuid") + private String accountUuid; + + @Column(name="account_name") + private String accountName = null; + + @Column(name="account_type") + private short accountType; + + @Column(name="domain_id") + private long domainId; + + @Column(name="domain_uuid") + private String domainUuid; + + @Column(name="domain_name") + private String domainName = null; + + @Column(name="domain_path") + private String domainPath = null; + + @Column(name="instance_group_id") + private long instanceGroupId; + + @Column(name="instance_group_uuid") + private String instanceGroupUuid; + + @Column(name="instance_group_name") + private String instanceGroupName; + + @Column(name="vm_type", updatable=false, nullable=false, length=32) + @Enumerated(value=EnumType.STRING) + protected VirtualMachine.Type type; + + /** + * Note that state is intentionally missing the setter. Any updates to + * the state machine needs to go through the DAO object because someone + * else could be updating it as well. + */ + @Enumerated(value=EnumType.STRING) + @Column(name="state", updatable=true, nullable=false, length=32) + private State state = null; + + @Column(name=GenericDao.CREATED_COLUMN) + private Date created; + + @Column(name=GenericDao.REMOVED_COLUMN) + private Date removed; + + @Column(name="instance_name", updatable=true, nullable=false) + private String instanceName; + + @Column(name="guest_os_id", nullable=false, length=17) + private long guestOsId; + + @Column(name="guest_os_uuid") + private String guestOsUuid; + + @Column(name="hypervisor_type") + @Enumerated(value=EnumType.STRING) + private HypervisorType hypervisorType; + + @Column(name="ha_enabled", updatable=true, nullable=true) + private boolean haEnabled; + + @Encrypt + @Column(name="vnc_password", updatable=true, nullable=false, length=255) + protected String vncPassword; + + @Column(name="limit_cpu_use", updatable=true, nullable=true) + private boolean limitCpuUse; + + @Column(name="last_host_id", updatable=true, nullable=true) + private Long lastHostId; + + @Column(name="private_ip_address", updatable=true) + private String privateIpAddress; + + + @Column(name="private_mac_address", updatable=true, nullable=true) + private String privateMacAddress; + + @Column(name="pod_id", updatable=true, nullable=false) + private Long podId; + + @Column(name="pod_uuid") + private String podUuid; + + @Column(name="data_center_id") + private long dataCenterId; + + @Column(name="data_center_uuid") + private String dataCenterUuid; + + @Column(name="data_center_name") + private String dataCenterName = null; + + @Column(name="security_group_enabled") + private boolean securityGroupEnabled; + + @Column(name="host_id", updatable=true, nullable=true) + private long hostId; + + @Column(name="host_uuid") + private String hostUuid; + + @Column(name="host_name", nullable=false) + private String hostName; + + @Column(name="template_id", updatable=true, nullable=true, length=17) + private long templateId; + + @Column(name="template_uuid") + private String templateUuid; + + @Column(name="template_name") + private String templateName; + + @Column(name="template_display_text", length=4096) + private String templateDisplayText; + + @Column(name="password_enabled") + private boolean passwordEnabled; + + @Column(name="iso_id", updatable=true, nullable=true, length=17) + private long isoId; + + @Column(name="iso_uuid") + private String isoUuid; + + @Column(name="iso_name") + private String isoName; + + @Column(name="iso_display_text", length=4096) + private String isoDisplayText; + + @Column(name="service_offering_id") + private long serviceOfferingId; + + @Column(name="service_offering_uuid") + private String serviceOfferingUuid; + + @Column(name="service_offering_name") + private String serviceOfferingName; + + @Column(name="cpu") + private int cpu; + + @Column(name="speed") + private int speed; + + @Column(name="ram_size") + private int ramSize; + + @Column(name="pool_id", updatable=false, nullable = false) + private long poolId; + + @Column(name="pool_uuid") + private String poolUuid; + + @Column(name="pool_type", updatable=false, nullable=false, length=32) + @Enumerated(value=EnumType.STRING) + private StoragePoolType poolType; + + @Column(name = "volume_id") + private long volume_id; + + @Column(name = "volume_uuid") + private String volume_uuid; + + @Column(name = "volume_device_id") + private Long volumeDeviceId = null; + + @Column(name = "volume_type") + @Enumerated(EnumType.STRING) + private Volume.Type volumeType; + + @Column(name = "security_group_id") + private long securityGroupId; + + @Column(name = "security_group_uuid") + private String securityGroupUuid; + + @Column(name = "security_group_name") + private String securityGroupName; + + @Column(name = "security_group_description") + private String securityGroupDescription; + + @Column(name = "vpc_id") + private long vpcId; + + @Column(name = "vpc_uuid") + private String vpcUuid; + + @Column(name = "nic_id") + private long nicId; + + @Column(name = "nic_uuid") + private String nicUuid; + + @Column(name = "is_default_nic") + private boolean isDefaultNic; + + @Column(name = "ip_address") + private String ipAddress; + + @Column(name = "gateway") + private String gateway; + + @Column(name = "netmask") + private String netmask; + + @Column(name = "mac_address") + private String macAddress; + + @Column(name = "broadcast_uri") + private URI broadcastUri; + + @Column(name = "isolation_uri") + private URI isolationUri; + + @Column(name="network_id") + private long networkId; + + @Column(name="network_uuid") + private String networkUuid; + + @Column(name="traffic_type") + @Enumerated(value=EnumType.STRING) + private TrafficType trafficType; + + @Column(name="guest_type") + @Enumerated(value=EnumType.STRING) + private GuestType guestType; + + @Column(name = "public_ip_id") + private long publicIpId; + + @Column(name = "public_ip_uuid") + private String publicIpUuid; + + @Column(name = "public_ip_address") + private String publicIpAddress; + + @Column(name="user_data", updatable=true, nullable=true, length=2048) + private String userData; + + @Column(name="project_id") + private long projectId; + + @Column(name="project_uuid") + private String projectUuid; + + @Column(name="project_name") + private String projectName; + + @Column(name="keypair_name") + private String keypairName; + + @Column(name="job_id") + private long jobId; + + @Column(name="job_uuid") + private String jobUuid; + + @Column(name="job_status") + private int jobStatus; + + @Column(name="tag_id") + private long tagId; + + @Column(name="tag_uuid") + private String tagUuid; + + @Column(name="tag_key") + private String tagKey; + + @Column(name="tag_value") + private String tagValue; + + @Column(name="tag_domain_id") + private long tagDomainId; + + @Column(name="tag_account_id") + private long tagAccountId; + + @Column(name="tag_resource_id") + private long tagResourceId; + + @Column(name="tag_resource_uuid") + private String tagResourceUuid; + + @Column(name="tag_resource_type") + @Enumerated(value=EnumType.STRING) + private TaggedResourceType tagResourceType; + + @Column(name="tag_customer") + private String tagCustomer; + + transient String password; + + @Transient + Map details; + + @Column(name="uuid") + private String uuid; + + public UserVmJoinVO() { + } + + + + + public String getUuid() { + return uuid; + } + + + + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public long getId() { + return id; + } + + + public void setId(long id) { + this.id = id; + } + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public String getDisplayName() { + return displayName; + } + + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + + public long getAccountId() { + return accountId; + } + + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + + public String getAccountUuid() { + return accountUuid; + } + + + + + public void setAccountUuid(String accountUuid) { + this.accountUuid = accountUuid; + } + + + + + public String getAccountName() { + return accountName; + } + + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + + public short getAccountType() { + return accountType; + } + + + public void setAccountType(short accountType) { + this.accountType = accountType; + } + + + public long getDomainId() { + return domainId; + } + + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + + public String getDomainUuid() { + return domainUuid; + } + + + + + public void setDomainUuid(String domainUuid) { + this.domainUuid = domainUuid; + } + + + + + public String getDomainName() { + return domainName; + } + + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + + public String getDomainPath() { + return domainPath; + } + + + public void setDomainPath(String domainPath) { + this.domainPath = domainPath; + } + + + + + public long getInstanceGroupId() { + return instanceGroupId; + } + + + public void setInstanceGroupId(long instanceGroupId) { + this.instanceGroupId = instanceGroupId; + } + + + public String getInstanceGroupUuid() { + return instanceGroupUuid; + } + + + + + public void setInstanceGroupUuid(String instanceGroupUuid) { + this.instanceGroupUuid = instanceGroupUuid; + } + + + + + public String getInstanceGroupName() { + return instanceGroupName; + } + + + public void setInstanceGroupName(String instanceGroupName) { + this.instanceGroupName = instanceGroupName; + } + + + public VirtualMachine.Type getType() { + return type; + } + + + + + public void setType(VirtualMachine.Type type) { + this.type = type; + } + + + + + public State getState() { + return state; + } + + + public void setState(State state) { + this.state = state; + } + + + public Date getCreated() { + return created; + } + + + public void setCreated(Date created) { + this.created = created; + } + + + public Date getRemoved() { + return removed; + } + + + public void setRemoved(Date removed) { + this.removed = removed; + } + + + public String getInstanceName() { + return instanceName; + } + + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + + public long getGuestOSId() { + return guestOsId; + } + + + public void setGuestOSId(long guestOSId) { + this.guestOsId = guestOSId; + } + + + public String getGuestOsUuid() { + return guestOsUuid; + } + + + + + public void setGuestOsUuid(String guestOsUuid) { + this.guestOsUuid = guestOsUuid; + } + + + + + public HypervisorType getHypervisorType() { + return hypervisorType; + } + + + public void setHypervisorType(HypervisorType hypervisorType) { + this.hypervisorType = hypervisorType; + } + + + public boolean isHaEnabled() { + return haEnabled; + } + + + public void setHaEnabled(boolean haEnabled) { + this.haEnabled = haEnabled; + } + + public void setVncPassword(String vncPassword) { + this.vncPassword = vncPassword; + } + + public String getVncPassword() { + return vncPassword; + } + + + + + public String getPrivateIpAddress() { + return privateIpAddress; + } + + + + + public void setPrivateIpAddress(String privateIpAddress) { + this.privateIpAddress = privateIpAddress; + } + + + + + public String getPrivateMacAddress() { + return privateMacAddress; + } + + + + + public void setPrivateMacAddress(String privateMacAddress) { + this.privateMacAddress = privateMacAddress; + } + + + + + public Long getLastHostId() { + return lastHostId; + } + + + + + public void setLastHostId(Long lastHostId) { + this.lastHostId = lastHostId; + } + + + + + + + public Long getPodId() { + return podId; + } + + + + + public void setPodId(Long podIdToDeployIn) { + this.podId = podIdToDeployIn; + } + + + + + public String getPodUuid() { + return podUuid; + } + + + + + public void setPodUuid(String podUuid) { + this.podUuid = podUuid; + } + + + + + public long getDataCenterId() { + return dataCenterId; + } + + + + + public void setDataCenterId(long dataCenterIdToDeployIn) { + this.dataCenterId = dataCenterIdToDeployIn; + } + + + public boolean limitCpuUse() { + return limitCpuUse; + } + + public void setLimitCpuUse(boolean value) { + limitCpuUse = value; + } + + + public String getDataCenterUuid() { + return dataCenterUuid; + } + + + + + public void setDataCenterUuid(String zoneUuid) { + this.dataCenterUuid = zoneUuid; + } + + + + + public String getDataCenterName() { + return dataCenterName; + } + + + public void setDataCenterName(String zoneName) { + this.dataCenterName = zoneName; + } + + + public boolean isSecurityGroupEnabled() { + return securityGroupEnabled; + } + + + public void setSecurityGroupEnabled(boolean securityGroupEnabled) { + this.securityGroupEnabled = securityGroupEnabled; + } + + + public Long getHostId() { + return hostId; + } + + + public void setHostId(long hostId) { + this.hostId = hostId; + } + + + public String getHostUuid() { + return hostUuid; + } + + + + + public void setHostUuid(String hostUuid) { + this.hostUuid = hostUuid; + } + + + + + public String getHostName() { + return hostName; + } + + + public void setHostName(String hostName) { + this.hostName = hostName; + } + + + public long getTemplateId() { + return templateId; + } + + + public void setTemplateId(long templateId) { + this.templateId = templateId; + } + + + + public String getTemplateUuid() { + return templateUuid; + } + + + + + public void setTemplateUuid(String templateUuid) { + this.templateUuid = templateUuid; + } + + + + + public String getTemplateName() { + return templateName; + } + + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + + public String getTemplateDisplayText() { + return templateDisplayText; + } + + + public void setTemplateDisplayText(String templateDisplayText) { + this.templateDisplayText = templateDisplayText; + } + + + public boolean isPasswordEnabled() { + return passwordEnabled; + } + + + public void setPasswordEnabled(boolean passwordEnabled) { + this.passwordEnabled = passwordEnabled; + } + + + public Long getIsoId() { + return isoId; + } + + + public void setIsoId(long isoId) { + this.isoId = isoId; + } + + + public String getIsoUuid() { + return isoUuid; + } + + + + + public void setIsoUuid(String isoUuid) { + this.isoUuid = isoUuid; + } + + + + + public String getIsoName() { + return isoName; + } + + + public void setIsoName(String isoName) { + this.isoName = isoName; + } + + + public String getIsoDisplayText() { + return isoDisplayText; + } + + public void setIsoDisplayText(String isoDisplayText) { + this.isoDisplayText = isoDisplayText; + } + + + + + public String getServiceOfferingUuid() { + return serviceOfferingUuid; + } + + + + + public void setServiceOfferingUuid(String serviceOfferingUuid) { + this.serviceOfferingUuid = serviceOfferingUuid; + } + + + + + public String getServiceOfferingName() { + return serviceOfferingName; + } + + + public void setServiceOfferingName(String serviceOfferingName) { + this.serviceOfferingName = serviceOfferingName; + } + + + public int getCpu() { + return cpu; + } + + + public void setCpu(int cpu) { + this.cpu = cpu; + } + + + public int getSpeed() { + return speed; + } + + + public void setSpeed(int speed) { + this.speed = speed; + } + + + public int getRamSize() { + return ramSize; + } + + + public void setRamSize(int ramSize) { + this.ramSize = ramSize; + } + + + public long getPoolId() { + return poolId; + } + + + public void setPoolId(long poolId) { + this.poolId = poolId; + } + + + public StoragePoolType getPoolType() { + return poolType; + } + + + public void setPoolType(StoragePoolType poolType) { + this.poolType = poolType; + } + + + public long getVolume_id() { + return volume_id; + } + + + public void setVolume_id(long volume_id) { + this.volume_id = volume_id; + } + + + public Long getVolumeDeviceId() { + return volumeDeviceId; + } + + + public void setVolumeDeviceId(Long volumeDeviceId) { + this.volumeDeviceId = volumeDeviceId; + } + + + public Volume.Type getVolumeType() { + return volumeType; + } + + + public void setVolumeType(Volume.Type volumeType) { + this.volumeType = volumeType; + } + + + public long getSecurityGroupId() { + return securityGroupId; + } + + + public void setSecurityGroupId(long securityGroupId) { + this.securityGroupId = securityGroupId; + } + + + public String getSecurityGroupName() { + return securityGroupName; + } + + + public void setSecurityGroupName(String securityGroupName) { + this.securityGroupName = securityGroupName; + } + + + public String getSecurityGroupDescription() { + return securityGroupDescription; + } + + + public void setSecurityGroupDescription(String securityGroupDescription) { + this.securityGroupDescription = securityGroupDescription; + } + + + public long getVpcId() { + return vpcId; + } + + + + public void setVpcId(long vpcId) { + this.vpcId = vpcId; + } + + + + + public long getNicId() { + return nicId; + } + + + public void setNicId(long nicId) { + this.nicId = nicId; + } + + + public boolean isDefaultNic() { + return isDefaultNic; + } + + + public void setDefaultNic(boolean isDefaultNic) { + this.isDefaultNic = isDefaultNic; + } + + + public String getIpAddress() { + return ipAddress; + } + + + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + + public String getGateway() { + return gateway; + } + + + public void setGateway(String gateway) { + this.gateway = gateway; + } + + + public String getNetmask() { + return netmask; + } + + + public void setNetmask(String netmask) { + this.netmask = netmask; + } + + + public String getMacAddress() { + return macAddress; + } + + + public void setMacAddress(String macAddress) { + this.macAddress = macAddress; + } + + + public URI getBroadcastUri() { + return broadcastUri; + } + + + public void setBroadcastUri(URI broadcastUri) { + this.broadcastUri = broadcastUri; + } + + + public URI getIsolationUri() { + return isolationUri; + } + + + public void setIsolationUri(URI isolationUri) { + this.isolationUri = isolationUri; + } + + + public long getNetworkId() { + return networkId; + } + + + public void setNetworkId(long networkId) { + this.networkId = networkId; + } + + + public TrafficType getTrafficType() { + return trafficType; + } + + + public void setTrafficType(TrafficType trafficType) { + this.trafficType = trafficType; + } + + + public GuestType getGuestType() { + return guestType; + } + + + public void setGuestType(GuestType guestType) { + this.guestType = guestType; + } + + + public long getPublicIpId() { + return publicIpId; + } + + + + + public void setPublicIpId(long publicIpId) { + this.publicIpId = publicIpId; + } + + + + + public String getPublicIpAddress() { + return publicIpAddress; + } + + + public void setPublicIpAddress(String publicIpAddress) { + this.publicIpAddress = publicIpAddress; + } + + + + public long getServiceOfferingId() { + return serviceOfferingId; + } + + + + + public void setServiceOfferingId(long serviceOfferingId) { + this.serviceOfferingId = serviceOfferingId; + } + + + public Map getDetails() { + return details; + } + + public String getDetail(String name) { + assert (details != null) : "Did you forget to load the details?"; + + return details != null ? details.get(name) : null; + } + + public void setDetail(String name, String value) { + assert (details != null) : "Did you forget to load the details?"; + + details.put(name, value); + } + + public void setDetails(Map details) { + this.details = details; + } + + public void setUserData(String userData) { + this.userData = userData; + } + + public String getUserData() { + return userData; + } + + + + public long getGuestOsId() { + return guestOsId; + } + + + + + public void setGuestOsId(long guestOsId) { + this.guestOsId = guestOsId; + } + + + + + public long getProjectId() { + return projectId; + } + + + + + public void setProjectId(long projectId) { + this.projectId = projectId; + } + + + + + public String getProjectUuid() { + return projectUuid; + } + + + + + public void setProjectUuid(String projectUuid) { + this.projectUuid = projectUuid; + } + + + + + public String getProjectName() { + return projectName; + } + + + + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + + + + public String getKeypairName() { + return keypairName; + } + + + + + public void setKeypairName(String keypairName) { + this.keypairName = keypairName; + } + + + + + public long getTagId() { + return tagId; + } + + + + + public void setTagId(long tagId) { + this.tagId = tagId; + } + + + + + public String getTagUuid() { + return tagUuid; + } + + + + + public void setTagUuid(String tagUuid) { + this.tagUuid = tagUuid; + } + + + + + public String getTagKey() { + return tagKey; + } + + + + + public void setTagKey(String tagKey) { + this.tagKey = tagKey; + } + + + + + public String getTagValue() { + return tagValue; + } + + + + + public void setTagValue(String tagValue) { + this.tagValue = tagValue; + } + + + + + public long getTagDomainId() { + return tagDomainId; + } + + + + + public void setTagDomainId(long tagDomainId) { + this.tagDomainId = tagDomainId; + } + + + + + public long getTagAccountId() { + return tagAccountId; + } + + + + + public void setTagAccountId(long tagAccountId) { + this.tagAccountId = tagAccountId; + } + + + + + public long getTagResourceId() { + return tagResourceId; + } + + + + + public void setTagResourceId(long tagResourceId) { + this.tagResourceId = tagResourceId; + } + + + + + public String getTagResourceUuid() { + return tagResourceUuid; + } + + + + + public void setTagResourceUuid(String tagResourceUuid) { + this.tagResourceUuid = tagResourceUuid; + } + + + + + public TaggedResourceType getTagResourceType() { + return tagResourceType; + } + + + + + public void setTagResourceType(TaggedResourceType tagResourceType) { + this.tagResourceType = tagResourceType; + } + + + + + public String getTagCustomer() { + return tagCustomer; + } + + + + + public void setTagCustomer(String tagCustomer) { + this.tagCustomer = tagCustomer; + } + + + + + public boolean isLimitCpuUse() { + return limitCpuUse; + } + + + + public String getPoolUuid() { + return poolUuid; + } + + + + + public void setPoolUuid(String poolUuid) { + this.poolUuid = poolUuid; + } + + + + + public String getVolume_uuid() { + return volume_uuid; + } + + + + + public void setVolume_uuid(String volume_uuid) { + this.volume_uuid = volume_uuid; + } + + + + + public String getSecurityGroupUuid() { + return securityGroupUuid; + } + + + + + public void setSecurityGroupUuid(String securityGroupUuid) { + this.securityGroupUuid = securityGroupUuid; + } + + + + + public String getVpcUuid() { + return vpcUuid; + } + + + + + public void setVpcUuid(String vpcUuid) { + this.vpcUuid = vpcUuid; + } + + + + + public String getNicUuid() { + return nicUuid; + } + + + + + public void setNicUuid(String nicUuid) { + this.nicUuid = nicUuid; + } + + + + + public String getNetworkUuid() { + return networkUuid; + } + + + + + public void setNetworkUuid(String networkUuid) { + this.networkUuid = networkUuid; + } + + + + + public String getPublicIpUuid() { + return publicIpUuid; + } + + + + + public void setPublicIpUuid(String publicIpUuid) { + this.publicIpUuid = publicIpUuid; + } + + + + public long getJobId() { + return jobId; + } + + + + + public void setJobId(long jobId) { + this.jobId = jobId; + } + + + + + public String getJobUuid() { + return jobUuid; + } + + + + + public void setJobUuid(String jobUuid) { + this.jobUuid = jobUuid; + } + + + + + public int getJobStatus() { + return jobStatus; + } + + + + + public void setJobStatus(int jobStatus) { + this.jobStatus = jobStatus; + } + + + + transient String toString; + @Override + public String toString() { + if (toString == null) { + toString = new StringBuilder("VM[").append(id).append("|").append(hostName).append("]").toString(); + } + return toString; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (id ^ (id >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + UserVmJoinVO other = (UserVmJoinVO) obj; + if (id != other.id) + return false; + return true; + } +} diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index 78f2cb5e168..1b43662416d 100755 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -62,6 +62,7 @@ import org.apache.cloudstack.api.user.iso.command.UpdateIsoCmd; import org.apache.cloudstack.api.user.vmgroup.command.UpdateVMGroupCmd; import com.cloud.api.commands.UpgradeSystemVMCmd; import com.cloud.api.commands.UploadCustomCertificateCmd; +import com.cloud.api.view.vo.DomainRouterJoinVO; import com.cloud.async.AsyncJob; import com.cloud.capacity.Capacity; import com.cloud.configuration.Configuration; @@ -184,7 +185,7 @@ public interface ManagementService { * @param cmd * @return List of DomainRouters. */ - Pair, Integer> searchForRouters(ListRoutersCmd cmd); + Pair, Integer> searchForRouters(ListRoutersCmd cmd); /** * Obtains a list of IP Addresses by the specified search criteria. Can search by: "userId", "dataCenterId", diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java index 04fa6007f09..4568944d733 100755 --- a/api/src/com/cloud/vm/UserVmService.java +++ b/api/src/com/cloud/vm/UserVmService.java @@ -37,6 +37,7 @@ import org.apache.cloudstack.api.user.vm.command.RestoreVMCmd; import org.apache.cloudstack.api.user.vm.command.StartVMCmd; import org.apache.cloudstack.api.user.vm.command.UpdateVMCmd; import org.apache.cloudstack.api.user.vm.command.UpgradeVMCmd; +import com.cloud.api.view.vo.UserVmJoinVO; import com.cloud.dc.DataCenter; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -379,7 +380,7 @@ public interface UserVmService { * the API command that wraps the search criteria * @return List of UserVMs. */ - Pair, Integer> searchForUserVMs(ListVMsCmd cmd); + Pair, Integer> searchForUserVMs(ListVMsCmd cmd); HypervisorType getHypervisorTypeOfUserVM(long vmid); diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java index 99398550a1f..aeafe6a665c 100755 --- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java +++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java @@ -152,6 +152,8 @@ import com.cloud.user.User; import com.cloud.user.UserAccount; import com.cloud.uservm.UserVm; import com.cloud.vm.InstanceGroup; +import com.cloud.api.view.vo.DomainRouterJoinVO; +import com.cloud.api.view.vo.UserVmJoinVO; import com.cloud.vm.VirtualMachine; public interface ResponseGenerator { @@ -175,6 +177,10 @@ public interface ResponseGenerator { SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy); + List createUserVmResponse(String objectName, UserVmJoinVO... userVms); + + List createUserVmResponse(String objectName, EnumSet details, UserVmJoinVO... userVms); + List createUserVmResponse(String objectName, UserVm... userVms); List createUserVmResponse(String objectName, EnumSet details, UserVm... userVms); @@ -183,6 +189,8 @@ public interface ResponseGenerator { DomainRouterResponse createDomainRouterResponse(VirtualRouter router); + List createDomainRouterResponse(DomainRouterJoinVO... router); + HostResponse createHostResponse(Host host, EnumSet details); HostResponse createHostResponse(Host host); diff --git a/api/src/org/apache/cloudstack/api/ResponseObject.java b/api/src/org/apache/cloudstack/api/ResponseObject.java index ff03c204149..fd327fab09a 100644 --- a/api/src/org/apache/cloudstack/api/ResponseObject.java +++ b/api/src/org/apache/cloudstack/api/ResponseObject.java @@ -49,6 +49,11 @@ public interface ResponseObject { */ Long getObjectId(); + /** + * Returns the object uuid. To replace getObjectId() later. + */ + String getObjectUuid(); + /** * Returns the job id * @@ -56,6 +61,12 @@ public interface ResponseObject { */ Long getJobId(); + /** + * Return the async job uuid. To replace getJobId() later. + * @return + */ + String getJobUuid(); + /** * Sets the job id * @@ -63,6 +74,12 @@ public interface ResponseObject { */ void setJobId(Long jobId); + /** + * Set the job uuid. To replace setJobId() later. + * @param jobUuid job uuid + */ + void setJobUuid(String jobUuid); + /** * Returns the job status * diff --git a/api/src/org/apache/cloudstack/api/admin/router/command/ListRoutersCmd.java b/api/src/org/apache/cloudstack/api/admin/router/command/ListRoutersCmd.java index 1659bea7827..e517dc14a39 100644 --- a/api/src/org/apache/cloudstack/api/admin/router/command/ListRoutersCmd.java +++ b/api/src/org/apache/cloudstack/api/admin/router/command/ListRoutersCmd.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.api.admin.router.command; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import org.apache.log4j.Logger; @@ -26,8 +27,17 @@ import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; import org.apache.cloudstack.api.IdentityMapper; import org.apache.cloudstack.api.Implementation; import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ApiConstants.VMDetails; + +import com.cloud.api.response.UserVmResponse; +import com.cloud.api.view.vo.DomainRouterJoinVO; +import com.cloud.api.view.vo.UserVmJoinVO; + import com.cloud.api.response.DomainRouterResponse; import com.cloud.api.response.ListResponse; +import com.cloud.api.response.UserVmResponse; +import com.cloud.api.view.vo.DomainRouterJoinVO; +import com.cloud.api.view.vo.UserVmJoinVO; import com.cloud.async.AsyncJob; import com.cloud.network.router.VirtualRouter; import com.cloud.utils.Pair; @@ -130,15 +140,10 @@ public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd { @Override public void execute(){ - Pair, Integer> result = _mgr.searchForRouters(this); + Pair, Integer> result = _mgr.searchForRouters(this); ListResponse response = new ListResponse(); - List routerResponses = new ArrayList(); - for (VirtualRouter router : result.first()) { - DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(router); - routerResponse.setObjectName("router"); - routerResponses.add(routerResponse); - } + List routerResponses = _responseGenerator.createDomainRouterResponse(result.first().toArray(new DomainRouterJoinVO[result.first().size()])); response.setResponses(routerResponses, result.second()); response.setResponseName(getCommandName()); this.setResponseObject(response); diff --git a/api/src/org/apache/cloudstack/api/user/vm/command/ListVMsCmd.java b/api/src/org/apache/cloudstack/api/user/vm/command/ListVMsCmd.java index 4acee5cc72f..9ed9bb3e0a7 100644 --- a/api/src/org/apache/cloudstack/api/user/vm/command/ListVMsCmd.java +++ b/api/src/org/apache/cloudstack/api/user/vm/command/ListVMsCmd.java @@ -32,8 +32,8 @@ import com.cloud.api.response.ListResponse; import com.cloud.api.response.UserVmResponse; import com.cloud.async.AsyncJob; import com.cloud.exception.InvalidParameterValueException; -import com.cloud.uservm.UserVm; import com.cloud.utils.Pair; +import com.cloud.api.view.vo.UserVmJoinVO; @Implementation(description="List the virtual machines owned by the account.", responseObject=UserVmResponse.class) @@ -199,16 +199,10 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd { @Override public void execute(){ - Pair, Integer> result = _userVmService.searchForUserVMs(this); + Pair, Integer> result = _userVmService.searchForUserVMs(this); ListResponse response = new ListResponse(); EnumSet details = getDetails(); - List vmResponses; - if (details.contains(VMDetails.all)){ // for all use optimized version - vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", result.first().toArray(new UserVm[result.first().size()])); - } - else { - vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", getDetails(), result.first().toArray(new UserVm[result.first().size()])); - } + List vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", getDetails(), result.first().toArray(new UserVmJoinVO[result.first().size()])); response.setResponses(vmResponses, result.second()); response.setResponseName(getCommandName()); this.setResponseObject(response); diff --git a/api/test/src/com/cloud/api/commands/test/ListRoutersCmdTest.java b/api/test/src/com/cloud/api/commands/test/ListRoutersCmdTest.java new file mode 100644 index 00000000000..d922474e743 --- /dev/null +++ b/api/test/src/com/cloud/api/commands/test/ListRoutersCmdTest.java @@ -0,0 +1,170 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package src.com.cloud.api.commands.test; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; + + +import com.cloud.api.ResponseGenerator; +import com.cloud.api.ServerApiException; +import com.cloud.api.commands.ListRoutersCmd; +import com.cloud.api.response.DomainRouterResponse; +import com.cloud.api.response.ListResponse; +import com.cloud.api.view.vo.DomainRouterJoinVO; +import com.cloud.server.ManagementService; +import com.cloud.utils.Pair; + + +public class ListRoutersCmdTest extends TestCase { + + private ListRoutersCmd listVrCmd; + private ManagementService mgrService; + private ResponseGenerator responseGenerator; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Before + public void setUp() { + listVrCmd = new ListRoutersCmd(); + mgrService = Mockito.mock(ManagementService.class); + responseGenerator = Mockito.mock(ResponseGenerator.class); + + listVrCmd._mgr = mgrService; + listVrCmd._responseGenerator = responseGenerator; + } + + @Test + public void testExecuteForSingleResult() throws Exception { + + List vrList = new ArrayList(); + DomainRouterJoinVO vr = new DomainRouterJoinVO(); + String uuid = UUID.randomUUID().toString(); + vr.setUuid(uuid); + vrList.add(vr); + + List respList = new ArrayList(); + DomainRouterResponse resp = new DomainRouterResponse(); + resp.setId(uuid); + respList.add(resp); + + Mockito.when(mgrService.searchForRouters(listVrCmd)) + .thenReturn(new Pair, Integer>(vrList, 1)); + Mockito.when(responseGenerator.createDomainRouterResponse(vr)).thenReturn(respList); + + + try { + listVrCmd.execute(); + ListResponse listResp = (ListResponse)listVrCmd.getResponseObject(); + assertNotNull(listResp); + assertEquals(1, listResp.getCount().intValue()); + List vrResp = listResp.getResponses(); + assertTrue(vrResp != null && vrResp.size() == 1); + DomainRouterResponse v = vrResp.get(0); + assertEquals(uuid, v.getId()); + } catch (ServerApiException exception) { + assertEquals("Failed to list domain routers", + exception.getDescription()); + } + } + + + @Test + public void testExecuteForPagedResult() throws Exception { + + + List vrList = new ArrayList(); + DomainRouterJoinVO vr1 = new DomainRouterJoinVO(); + String uuid1 = UUID.randomUUID().toString(); + vr1.setUuid(uuid1); + vrList.add(vr1); + DomainRouterJoinVO vr2 = new DomainRouterJoinVO(); + String uuid2 = UUID.randomUUID().toString(); + vrList.add(vr2); + + List respList = new ArrayList(); + DomainRouterResponse resp1 = new DomainRouterResponse(); + resp1.setId(uuid1); + respList.add(resp1); + DomainRouterResponse resp2 = new DomainRouterResponse(); + resp2.setId(uuid2); + respList.add(resp2); + + // without paging + Mockito.when(mgrService.searchForRouters(listVrCmd)) + .thenReturn(new Pair, Integer>(vrList, 2)); + Mockito.when(responseGenerator.createDomainRouterResponse(vr1, vr2)).thenReturn(respList); + try { + listVrCmd.execute(); + ListResponse listResp = (ListResponse)listVrCmd.getResponseObject(); + assertNotNull(listResp); + assertEquals(2, listResp.getCount().intValue()); + List vrResp = listResp.getResponses(); + assertTrue(vrResp != null && vrResp.size() == 2); + } catch (ServerApiException exception) { + assertEquals("Failed to list domain routers without pagination", + exception.getDescription()); + } + + // with pagination + List pVrList = new ArrayList(); + pVrList.add(vr1); + + List pRespList = new ArrayList(); + pRespList.add(resp1); + + listVrCmd = new ListRoutersCmd() { + public Integer getPage() { + return 1; + } + + public Integer getPageSize() { + return 1; + } + + }; + Mockito.when(mgrService.searchForRouters(listVrCmd)) + .thenReturn(new Pair, Integer>(pVrList, 2)); + Mockito.when(responseGenerator.createDomainRouterResponse(vr1)).thenReturn(pRespList); + + try { + listVrCmd.execute(); + ListResponse listResp = (ListResponse)listVrCmd.getResponseObject(); + assertNotNull(listResp); + assertEquals(2, listResp.getCount().intValue()); + List vmResp = listResp.getResponses(); + assertTrue(vmResp != null && vmResp.size() == 1); + DomainRouterResponse v = vmResp.get(0); + assertEquals(uuid1, v.getId()); + } catch (ServerApiException exception) { + assertEquals("Failed to list domain routers with pagination", + exception.getDescription()); + } + } +} + diff --git a/api/test/src/com/cloud/api/commands/test/ListVmsCmdTest.java b/api/test/src/com/cloud/api/commands/test/ListVmsCmdTest.java new file mode 100644 index 00000000000..ca6d95e2d71 --- /dev/null +++ b/api/test/src/com/cloud/api/commands/test/ListVmsCmdTest.java @@ -0,0 +1,173 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package src.com.cloud.api.commands.test; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; + +import com.cloud.api.ApiConstants; +import com.cloud.api.ApiConstants.VMDetails; +import com.cloud.api.BaseCmd; +import com.cloud.api.ResponseGenerator; +import com.cloud.api.ServerApiException; +import com.cloud.api.commands.ListVMsCmd; +import com.cloud.api.response.ListResponse; +import com.cloud.api.response.UserVmResponse; +import com.cloud.api.view.vo.UserVmJoinVO; +import com.cloud.utils.Pair; +import com.cloud.vm.UserVmService; + +public class ListVmsCmdTest extends TestCase { + + private ListVMsCmd listVmCmd; + private UserVmService userVmService; + private ResponseGenerator responseGenerator; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Before + public void setUp() { + listVmCmd = new ListVMsCmd(); + userVmService = Mockito.mock(UserVmService.class); + responseGenerator = Mockito.mock(ResponseGenerator.class); + + listVmCmd._userVmService = userVmService; + listVmCmd._responseGenerator = responseGenerator; + } + + @Test + public void testExecuteForSingleResult() throws Exception { + + List vmList = new ArrayList(); + UserVmJoinVO vm = new UserVmJoinVO(); + String uuid = UUID.randomUUID().toString(); + vm.setUuid(uuid); + vmList.add(vm); + + List respList = new ArrayList(); + UserVmResponse resp = new UserVmResponse(); + resp.setId(uuid); + respList.add(resp); + + Mockito.when(userVmService.searchForUserVMs(listVmCmd)) + .thenReturn(new Pair, Integer>(vmList, 1)); + Mockito.when(responseGenerator.createUserVmResponse("virtualmachine", EnumSet.of(VMDetails.all), vm)).thenReturn(respList); + + + try { + listVmCmd.execute(); + ListResponse listResp = (ListResponse)listVmCmd.getResponseObject(); + assertNotNull(listResp); + assertEquals(1, listResp.getCount().intValue()); + List vmResp = listResp.getResponses(); + assertTrue(vmResp != null && vmResp.size() == 1); + UserVmResponse v = vmResp.get(0); + assertEquals(uuid, v.getId()); + } catch (ServerApiException exception) { + assertEquals("Failed to list user vms", + exception.getDescription()); + } + } + + + @Test + public void testExecuteForPagedResult() throws Exception { + + + List vmList = new ArrayList(); + UserVmJoinVO vm1 = new UserVmJoinVO(); + String uuid1 = UUID.randomUUID().toString(); + vm1.setUuid(uuid1); + vmList.add(vm1); + UserVmJoinVO vm2 = new UserVmJoinVO(); + String uuid2 = UUID.randomUUID().toString(); + vmList.add(vm2); + + List respList = new ArrayList(); + UserVmResponse resp1 = new UserVmResponse(); + resp1.setId(uuid1); + respList.add(resp1); + UserVmResponse resp2 = new UserVmResponse(); + resp2.setId(uuid2); + respList.add(resp2); + + // without paging + Mockito.when(userVmService.searchForUserVMs(listVmCmd)) + .thenReturn(new Pair, Integer>(vmList, 2)); + Mockito.when(responseGenerator.createUserVmResponse("virtualmachine", EnumSet.of(VMDetails.all), vm1, vm2)).thenReturn(respList); + try { + listVmCmd.execute(); + ListResponse listResp = (ListResponse)listVmCmd.getResponseObject(); + assertNotNull(listResp); + assertEquals(2, listResp.getCount().intValue()); + List vmResp = listResp.getResponses(); + assertTrue(vmResp != null && vmResp.size() == 2); + } catch (ServerApiException exception) { + assertEquals("Failed to list user vms without pagination", + exception.getDescription()); + } + + // with pagination + List pVmList = new ArrayList(); + pVmList.add(vm1); + + List pRespList = new ArrayList(); + pRespList.add(resp1); + + listVmCmd = new ListVMsCmd() { + public Integer getPage() { + return 1; + } + + public Integer getPageSize() { + return 1; + } + + }; + Mockito.when(userVmService.searchForUserVMs(listVmCmd)) + .thenReturn(new Pair, Integer>(pVmList, 2)); + Mockito.when(responseGenerator.createUserVmResponse("virtualmachine", EnumSet.of(VMDetails.all), vm1)).thenReturn(pRespList); + + try { + listVmCmd.execute(); + ListResponse listResp = (ListResponse)listVmCmd.getResponseObject(); + assertNotNull(listResp); + assertEquals(2, listResp.getCount().intValue()); + List vmResp = listResp.getResponses(); + assertTrue(vmResp != null && vmResp.size() == 1); + UserVmResponse v = vmResp.get(0); + assertEquals(uuid1, v.getId()); + } catch (ServerApiException exception) { + assertEquals("Failed to list user vms with pagination", + exception.getDescription()); + } + } +} diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 3b5f634f216..5dc24129b9f 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -17,11 +17,16 @@ package com.cloud.api; import java.util.ArrayList; -import java.util.Hashtable; +import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.cloudstack.api.ApiConstants.VMDetails; +import com.cloud.api.response.DomainRouterResponse; +import com.cloud.api.response.UserVmResponse; +import com.cloud.api.view.vo.DomainRouterJoinVO; +import com.cloud.api.view.vo.UserVmJoinVO; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobVO; import com.cloud.capacity.CapacityVO; @@ -84,6 +89,7 @@ import com.cloud.network.dao.NetworkDomainDao; import com.cloud.network.dao.NetworkRuleConfigDao; import com.cloud.network.dao.Site2SiteVpnGatewayDao; import com.cloud.network.dao.Site2SiteCustomerGatewayDao; +import com.cloud.network.router.VirtualRouter; import com.cloud.network.security.SecurityGroup; import com.cloud.network.security.SecurityGroupManager; import com.cloud.network.security.SecurityGroupVO; @@ -160,9 +166,11 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.VmStats; import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.DomainRouterDao; +import com.cloud.vm.dao.DomainRouterJoinDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmData; import com.cloud.vm.dao.UserVmDetailsDao; +import com.cloud.vm.dao.UserVmJoinDao; import com.cloud.vm.dao.VMInstanceDao; public class ApiDBUtils { @@ -181,6 +189,7 @@ public class ApiDBUtils { private static DiskOfferingDao _diskOfferingDao; private static DomainDao _domainDao; private static DomainRouterDao _domainRouterDao; + private static DomainRouterJoinDao _domainRouterJoinDao; private static GuestOSDao _guestOSDao; private static GuestOSCategoryDao _guestOSCategoryDao; private static HostDao _hostDao; @@ -200,6 +209,7 @@ public class ApiDBUtils { private static UserDao _userDao; private static UserStatisticsDao _userStatsDao; private static UserVmDao _userVmDao; + private static UserVmJoinDao _userVmJoinDao; private static VlanDao _vlanDao; private static VolumeDao _volumeDao; private static Site2SiteVpnGatewayDao _site2SiteVpnGatewayDao; @@ -246,6 +256,7 @@ public class ApiDBUtils { _diskOfferingDao = locator.getDao(DiskOfferingDao.class); _domainDao = locator.getDao(DomainDao.class); _domainRouterDao = locator.getDao(DomainRouterDao.class); + _domainRouterJoinDao = locator.getDao(DomainRouterJoinDao.class); _guestOSDao = locator.getDao(GuestOSDao.class); _guestOSCategoryDao = locator.getDao(GuestOSCategoryDao.class); _hostDao = locator.getDao(HostDao.class); @@ -264,6 +275,7 @@ public class ApiDBUtils { _userDao = locator.getDao(UserDao.class); _userStatsDao = locator.getDao(UserStatisticsDao.class); _userVmDao = locator.getDao(UserVmDao.class); + _userVmJoinDao = locator.getDao(UserVmJoinDao.class); _vlanDao = locator.getDao(VlanDao.class); _volumeDao = locator.getDao(VolumeDao.class); _site2SiteVpnGatewayDao = locator.getDao(Site2SiteVpnGatewayDao.class); @@ -344,7 +356,7 @@ public class ApiDBUtils { return _ms.getVersion(); } - public static List searchForUserVMs(Criteria c, List permittedAccounts) { + public static List searchForUserVMs(Criteria c, List permittedAccounts) { return _userVmMgr.searchForUserVMs(c, _accountDao.findById(Account.ACCOUNT_ID_SYSTEM), null, false, permittedAccounts, false, null, null).first(); } @@ -745,10 +757,6 @@ public class ApiDBUtils { return _firewallCidrsDao.getSourceCidrs(id); } - public static Hashtable listVmDetails(Hashtable vmData){ - return _userVmDao.listVmDetails(vmData); - } - public static Account getProjectOwner(long projectId) { return _projectMgr.getProjectOwner(projectId); } @@ -889,3 +897,33 @@ public class ApiDBUtils { public static CounterVO getCounter(long counterId) { return _counterDao.findById(counterId); }} + + + /////////////////////////////////////////////////////////////////////// + // Newly Added Utility Methods for List API refactoring // + /////////////////////////////////////////////////////////////////////// + + public static DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO vr, Account caller) { + return _domainRouterJoinDao.newDomainRouterResponse(vr, caller); + } + + public static DomainRouterResponse fillRouterDetails(DomainRouterResponse vrData, DomainRouterJoinVO vr){ + return _domainRouterJoinDao.setDomainRouterResponse(vrData, vr); + } + + public static List newDomainRouterView(VirtualRouter vr){ + return _domainRouterJoinDao.newDomainRouterView(vr); + } + + public static UserVmResponse newUserVmResponse(String objectName, UserVmJoinVO userVm, EnumSet details, Account caller) { + return _userVmJoinDao.newUserVmResponse(objectName, userVm, details, caller); + } + + public static UserVmResponse fillVmDetails(UserVmResponse vmData, UserVmJoinVO vm){ + return _userVmJoinDao.setUserVmResponse(vmData, vm); + } + + public static List newUserVmView(UserVm... userVms){ + return _userVmJoinDao.newUserVmView(userVms); + } +} diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 24fb480944e..84950d3b155 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -63,6 +63,7 @@ import com.cloud.api.response.FirewallResponse; import com.cloud.api.response.FirewallRuleResponse; import com.cloud.api.response.HostResponse; import com.cloud.api.response.HypervisorCapabilitiesResponse; +import com.cloud.api.response.ControlledViewEntityResponse; import com.cloud.api.response.IPAddressResponse; import com.cloud.api.response.InstanceGroupResponse; import com.cloud.api.response.IpForwardingRuleResponse; @@ -115,6 +116,9 @@ import com.cloud.api.response.VpcOfferingResponse; import com.cloud.api.response.VpcResponse; import com.cloud.api.response.VpnUsersResponse; import com.cloud.api.response.ZoneResponse; +import com.cloud.api.view.vo.DomainRouterJoinVO; +import com.cloud.api.view.vo.ControlledViewEntity; +import com.cloud.api.view.vo.UserVmJoinVO; import com.cloud.async.AsyncJob; import com.cloud.capacity.Capacity; import com.cloud.capacity.CapacityVO; @@ -360,12 +364,12 @@ public class ApiResponseHelper implements ResponseGenerator { List permittedAccounts = new ArrayList(); permittedAccounts.add(account.getId()); - List virtualMachines = ApiDBUtils.searchForUserVMs(new Criteria(), permittedAccounts); + List virtualMachines = ApiDBUtils.searchForUserVMs(new Criteria(), permittedAccounts); // get Running/Stopped VMs - for (Iterator iter = virtualMachines.iterator(); iter.hasNext();) { + for (Iterator iter = virtualMachines.iterator(); iter.hasNext();) { // count how many stopped/running vms we have - UserVm vm = iter.next(); + UserVmJoinVO vm = iter.next(); if (vm.getState() == State.Stopped) { vmStopped++; @@ -1386,400 +1390,72 @@ public class ApiResponseHelper implements ResponseGenerator { @Override public List createUserVmResponse(String objectName, EnumSet details, UserVm... userVms) { - Account caller = UserContext.current().getCaller(); - Map dataCenters = new HashMap(); - Map hosts = new HashMap(); - Map templates = new HashMap(); - Map serviceOfferings = new HashMap(); - Map networks = new HashMap(); + List viewVms = ApiDBUtils.newUserVmView(userVms); + return createUserVmResponse(objectName, details, viewVms.toArray(new UserVmJoinVO[viewVms.size()])); - List vmResponses = new ArrayList(); - - for (UserVm userVm : userVms) { - UserVmResponse userVmResponse = new UserVmResponse(); - Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId())); - if (acct != null) { - userVmResponse.setAccountName(acct.getAccountName()); - userVmResponse.setDomainId(acct.getDomainId()); - userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName()); - } - - userVmResponse.setId(userVm.getId()); - userVmResponse.setName(userVm.getHostName()); - userVmResponse.setCreated(userVm.getCreated()); - - userVmResponse.setHaEnable(userVm.isHaEnabled()); - - if (userVm.getDisplayName() != null) { - userVmResponse.setDisplayName(userVm.getDisplayName()); - } else { - userVmResponse.setDisplayName(userVm.getHostName()); - } - - if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN) { - userVmResponse.setInstanceName(userVm.getInstanceName()); - } - - - if (userVm.getPassword() != null) { - userVmResponse.setPassword(userVm.getPassword()); - } - - if (details.contains(VMDetails.all) || details.contains(VMDetails.group)) { - InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(userVm.getId()); - if (group != null) { - userVmResponse.setGroup(group.getName()); - userVmResponse.setGroupId(group.getId()); - } - - } - - // Data Center Info - DataCenter zone = dataCenters.get(userVm.getDataCenterIdToDeployIn()); - if (zone == null) { - zone = ApiDBUtils.findZoneById(userVm.getDataCenterIdToDeployIn()); - dataCenters.put(zone.getId(), zone); - } - - userVmResponse.setZoneId(zone.getId()); - userVmResponse.setZoneName(zone.getName()); - - // if user is an admin, display host id - if (((caller == null) || (caller.getType() == Account.ACCOUNT_TYPE_ADMIN)) && (userVm.getHostId() != null)) { - Host host = hosts.get(userVm.getHostId()); - - if (host == null) { - host = ApiDBUtils.findHostById(userVm.getHostId()); - hosts.put(host.getId(), host); - } - - userVmResponse.setHostId(host.getId()); - userVmResponse.setHostName(host.getName()); - } - - if (userVm.getState() != null) { - if (userVm.getHostId() != null) { - Host host = hosts.get(userVm.getHostId()); - - if (host == null) { - host = ApiDBUtils.findHostById(userVm.getHostId()); - hosts.put(host.getId(), host); - } - if (host.getStatus() != com.cloud.host.Status.Up) { - userVmResponse.setState(VirtualMachine.State.Unknown.toString()); - } else { - userVmResponse.setState(userVm.getState().toString()); - } - } else { - userVmResponse.setState(userVm.getState().toString()); - } - } - - if (userVm.getHypervisorType() != null) { - userVmResponse.setHypervisor(userVm.getHypervisorType().toString()); - } - - if (details.contains(VMDetails.all) || details.contains(VMDetails.tmpl)) { - // Template Info - VMTemplateVO template = templates.get(userVm.getTemplateId()); - if (template == null) { - template = ApiDBUtils.findTemplateById(userVm.getTemplateId()); - if (template != null) { - templates.put(template.getId(), template); - } - } - - if (template != null) { - userVmResponse.setTemplateId(userVm.getTemplateId()); - userVmResponse.setTemplateName(template.getName()); - userVmResponse.setTemplateDisplayText(template.getDisplayText()); - userVmResponse.setPasswordEnabled(template.getEnablePassword()); - } else { - userVmResponse.setTemplateId(-1L); - userVmResponse.setTemplateName("ISO Boot"); - userVmResponse.setTemplateDisplayText("ISO Boot"); - userVmResponse.setPasswordEnabled(false); - } - } - - if (details.contains(VMDetails.all) || details.contains(VMDetails.iso)) { - // ISO Info - VMTemplateVO iso = templates.get(userVm.getIsoId()); - if (iso == null) { - iso = ApiDBUtils.findTemplateById(userVm.getIsoId()); - if (iso != null) { - templates.put(iso.getId(), iso); - } - } - - if (iso != null) { - userVmResponse.setIsoId(iso.getId()); - userVmResponse.setIsoName(iso.getName()); - } - } - - if (details.contains(VMDetails.all) || details.contains(VMDetails.servoff)) { - // Service Offering Info - ServiceOffering offering = serviceOfferings.get(userVm.getServiceOfferingId()); - - if (offering == null) { - offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId()); - serviceOfferings.put(offering.getId(), offering); - } - - userVmResponse.setServiceOfferingId(offering.getId()); - userVmResponse.setServiceOfferingName(offering.getName()); - userVmResponse.setCpuNumber(offering.getCpu()); - userVmResponse.setCpuSpeed(offering.getSpeed()); - userVmResponse.setMemory(offering.getRamSize()); - } - - if (details.contains(VMDetails.all) || details.contains(VMDetails.volume)) { - VolumeVO rootVolume = ApiDBUtils.findRootVolume(userVm.getId()); - if (rootVolume != null) { - userVmResponse.setRootDeviceId(rootVolume.getDeviceId()); - String rootDeviceType = "Not created"; - if (rootVolume.getPoolId() != null) { - StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId()); - rootDeviceType = storagePool.getPoolType().toString(); - } - userVmResponse.setRootDeviceType(rootDeviceType); - } - } - - if (details.contains(VMDetails.all) || details.contains(VMDetails.stats)) { - // stats calculation - DecimalFormat decimalFormat = new DecimalFormat("#.##"); - String cpuUsed = null; - VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId()); - if (vmStats != null) { - float cpuUtil = (float) vmStats.getCPUUtilization(); - cpuUsed = decimalFormat.format(cpuUtil) + "%"; - userVmResponse.setCpuUsed(cpuUsed); - - Double networkKbRead = Double.valueOf(vmStats.getNetworkReadKBs()); - userVmResponse.setNetworkKbsRead(networkKbRead.longValue()); - - Double networkKbWrite = Double.valueOf(vmStats.getNetworkWriteKBs()); - userVmResponse.setNetworkKbsWrite(networkKbWrite.longValue()); - } - } - - userVmResponse.setGuestOsId(userVm.getGuestOSId()); - - if (details.contains(VMDetails.all) || details.contains(VMDetails.secgrp)) { - // security groups - list only when zone is security group enabled - if (zone.isSecurityGroupEnabled()) { - List securityGroups = ApiDBUtils.getSecurityGroupsForVm(userVm.getId()); - List securityGroupResponse = new ArrayList(); - for (SecurityGroupVO grp : securityGroups) { - SecurityGroupResponse resp = new SecurityGroupResponse(); - resp.setId(grp.getId()); - resp.setName(grp.getName()); - resp.setDescription(grp.getDescription()); - resp.setObjectName("securitygroup"); - securityGroupResponse.add(resp); - } - userVmResponse.setSecurityGroupList(securityGroupResponse); - } - } - - if (details.contains(VMDetails.all) || details.contains(VMDetails.nics)) { - List nicProfiles = ApiDBUtils.getNics(userVm); - List nicResponses = new ArrayList(); - for (NicProfile singleNicProfile : nicProfiles) { - NicResponse nicResponse = new NicResponse(); - nicResponse.setId(singleNicProfile.getId()); - nicResponse.setIpaddress(singleNicProfile.getIp4Address()); - nicResponse.setGateway(singleNicProfile.getGateway()); - nicResponse.setNetmask(singleNicProfile.getNetmask()); - nicResponse.setNetworkid(singleNicProfile.getNetworkId()); - nicResponse.setNetworkName(ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId()).getName()); - if (acct.getType() == Account.ACCOUNT_TYPE_ADMIN) { - if (singleNicProfile.getBroadCastUri() != null) { - nicResponse.setBroadcastUri(singleNicProfile.getBroadCastUri().toString()); - } - if (singleNicProfile.getIsolationUri() != null) { - nicResponse.setIsolationUri(singleNicProfile.getIsolationUri().toString()); - } - } - - // Long networkId = singleNicProfile.getNetworkId(); - Network network = networks.get(singleNicProfile.getNetworkId()); - if (network == null) { - network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId()); - networks.put(singleNicProfile.getNetworkId(), network); - } - - nicResponse.setTrafficType(network.getTrafficType().toString()); - nicResponse.setType(network.getGuestType().toString()); - nicResponse.setIsDefault(singleNicProfile.isDefaultNic()); - nicResponse.setObjectName("nic"); - nicResponses.add(nicResponse); - } - userVmResponse.setNics(nicResponses); - } - - //set tag information - List tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.UserVm, userVm.getId()); - List tagResponses = new ArrayList(); - for (ResourceTag tag : tags) { - ResourceTagResponse tagResponse = createResourceTagResponse(tag, true); - tagResponses.add(tagResponse); - } - userVmResponse.setTags(tagResponses); - - IpAddress ip = ApiDBUtils.findIpByAssociatedVmId(userVm.getId()); - if (ip != null) { - userVmResponse.setPublicIpId(ip.getId()); - userVmResponse.setPublicIp(ip.getAddress().addr()); - } - - userVmResponse.setObjectName(objectName); - vmResponses.add(userVmResponse); - } - - return vmResponses; } @Override public List createUserVmResponse(String objectName, UserVm... userVms) { - Account caller = UserContext.current().getCaller(); - boolean caller_is_admin = ((caller == null) || (caller.getType() == Account.ACCOUNT_TYPE_ADMIN)); + List viewVms = ApiDBUtils.newUserVmView(userVms); + return createUserVmResponse(objectName, viewVms.toArray(new UserVmJoinVO[viewVms.size()])); + } - Hashtable vmDataList = new Hashtable(); + @Override + public List createUserVmResponse(String objectName, UserVmJoinVO... userVms) { + return createUserVmResponse(objectName, EnumSet.of(VMDetails.all), userVms); + } + + @Override + public List createUserVmResponse(String objectName, EnumSet details, UserVmJoinVO... userVms) { + Account caller = UserContext.current().getCaller(); + + s_logger.debug(">>>Converting UserVm VO to UserVmResponse"); + Hashtable vmDataList = new Hashtable(); // Initialise the vmdatalist with the input data - for (UserVm userVm : userVms) { - UserVmData userVmData = newUserVmData(userVm); + + + for (UserVmJoinVO userVm : userVms) { + UserVmResponse userVmData = vmDataList.get(userVm.getId()); + if ( userVmData == null ){ + // first time encountering this vm + userVmData = ApiDBUtils.newUserVmResponse(objectName, userVm, details, caller); + } else{ + // update nics, securitygroups, tags for 1 to many mapping fields + userVmData = ApiDBUtils.fillVmDetails(userVmData, userVm); + } vmDataList.put(userVm.getId(), userVmData); } - - vmDataList = ApiDBUtils.listVmDetails(vmDataList); - - // initialize vmresponse from vmdatalist - List vmResponses = new ArrayList(); - DecimalFormat decimalFormat = new DecimalFormat("#.##"); - for (UserVmData uvd : vmDataList.values()) { - UserVmResponse userVmResponse = newUserVmResponse(uvd, caller_is_admin); - - // stats calculation - String cpuUsed = null; - // VmStats vmStats = ApiDBUtils.getVmStatistics(userVmResponse.getId()); - VmStats vmStats = ApiDBUtils.getVmStatistics(uvd.getId()); - if (vmStats != null) { - float cpuUtil = (float) vmStats.getCPUUtilization(); - cpuUsed = decimalFormat.format(cpuUtil) + "%"; - userVmResponse.setCpuUsed(cpuUsed); - - Double networkKbRead = Double.valueOf(vmStats.getNetworkReadKBs()); - userVmResponse.setNetworkKbsRead(networkKbRead.longValue()); - - Double networkKbWrite = Double.valueOf(vmStats.getNetworkWriteKBs()); - userVmResponse.setNetworkKbsWrite(networkKbWrite.longValue()); - } - userVmResponse.setObjectName(objectName); - - vmResponses.add(userVmResponse); - } - return vmResponses; + s_logger.debug(">>>Done with creating vm response"); + return new ArrayList(vmDataList.values()); } @Override public DomainRouterResponse createDomainRouterResponse(VirtualRouter router) { + List viewVrs = ApiDBUtils.newDomainRouterView(router); + List listVrs = createDomainRouterResponse(viewVrs.toArray(new DomainRouterJoinVO[viewVrs.size()])); + assert listVrs != null && listVrs.size() == 1 : "There should be one virtual router returned"; + return listVrs.get(0); + } + + @Override + public List createDomainRouterResponse(DomainRouterJoinVO... routers) { Account caller = UserContext.current().getCaller(); - Map serviceOfferings = new HashMap(); - - DomainRouterResponse routerResponse = new DomainRouterResponse(); - routerResponse.setId(router.getId()); - routerResponse.setZoneId(router.getDataCenterIdToDeployIn()); - routerResponse.setName(router.getHostName()); - routerResponse.setTemplateId(router.getTemplateId()); - routerResponse.setCreated(router.getCreated()); - routerResponse.setState(router.getState()); - routerResponse.setIsRedundantRouter(router.getIsRedundantRouter()); - routerResponse.setRedundantState(router.getRedundantState().toString()); - - if (caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_ADMIN) { - if (router.getHostId() != null) { - routerResponse.setHostId(router.getHostId()); - routerResponse.setHostName(ApiDBUtils.findHostById(router.getHostId()).getName()); + Hashtable vrDataList = new Hashtable(); + // Initialise the vrdatalist with the input data + for (DomainRouterJoinVO vr : routers) { + DomainRouterResponse vrData = vrDataList.get(vr.getId()); + if ( vrData == null ){ + // first time encountering this vm + vrData = ApiDBUtils.newDomainRouterResponse(vr, caller); } - routerResponse.setPodId(router.getPodIdToDeployIn()); - List nicProfiles = ApiDBUtils.getNics(router); - List nicResponses = new ArrayList(); - for (NicProfile singleNicProfile : nicProfiles) { - Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId()); - //legacy code, public/control/guest nic info is kept in nics response object - if (network != null) { - if (network.getTrafficType() == TrafficType.Public) { - routerResponse.setPublicIp(singleNicProfile.getIp4Address()); - routerResponse.setPublicMacAddress(singleNicProfile.getMacAddress()); - routerResponse.setPublicNetmask(singleNicProfile.getNetmask()); - routerResponse.setGateway(singleNicProfile.getGateway()); - routerResponse.setPublicNetworkId(singleNicProfile.getNetworkId()); - } else if (network.getTrafficType() == TrafficType.Control) { - routerResponse.setLinkLocalIp(singleNicProfile.getIp4Address()); - routerResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress()); - routerResponse.setLinkLocalNetmask(singleNicProfile.getNetmask()); - routerResponse.setLinkLocalNetworkId(singleNicProfile.getNetworkId()); - } else if (network.getTrafficType() == TrafficType.Guest) { - routerResponse.setGuestIpAddress(singleNicProfile.getIp4Address()); - routerResponse.setGuestMacAddress(singleNicProfile.getMacAddress()); - routerResponse.setGuestNetmask(singleNicProfile.getNetmask()); - routerResponse.setGuestNetworkId(singleNicProfile.getNetworkId()); - routerResponse.setNetworkDomain(network.getNetworkDomain()); - } - - NicResponse nicResponse = new NicResponse(); - nicResponse.setId(singleNicProfile.getId()); - nicResponse.setIpaddress(singleNicProfile.getIp4Address()); - nicResponse.setGateway(singleNicProfile.getGateway()); - nicResponse.setNetmask(singleNicProfile.getNetmask()); - nicResponse.setNetworkid(singleNicProfile.getNetworkId()); - nicResponse.setNetworkName(network.getName()); - - if (singleNicProfile.getBroadCastUri() != null) { - nicResponse.setBroadcastUri(singleNicProfile.getBroadCastUri().toString()); - } - if (singleNicProfile.getIsolationUri() != null) { - nicResponse.setIsolationUri(singleNicProfile.getIsolationUri().toString()); - } - - nicResponse.setTrafficType(network.getTrafficType().toString()); - if (network.getGuestType() != null) { - nicResponse.setType(network.getGuestType().toString()); - } - nicResponse.setIsDefault(singleNicProfile.isDefaultNic()); - nicResponse.setObjectName("nic"); - nicResponses.add(nicResponse); - } + else{ + // update nics for 1 to many mapping fields + vrData = ApiDBUtils.fillRouterDetails(vrData, vr); } - routerResponse.setNics(nicResponses); + vrDataList.put(vr.getId(), vrData); } - - // Service Offering Info - ServiceOffering offering = serviceOfferings.get(router.getServiceOfferingId()); - - if (offering == null) { - offering = ApiDBUtils.findServiceOfferingById(router.getServiceOfferingId()); - serviceOfferings.put(offering.getId(), offering); - } - routerResponse.setServiceOfferingId(offering.getId()); - routerResponse.setServiceOfferingName(offering.getName()); - - populateOwner(routerResponse, router); - - DataCenter zone = ApiDBUtils.findZoneById(router.getDataCenterIdToDeployIn()); - if (zone != null) { - routerResponse.setZoneName(zone.getName()); - routerResponse.setDns1(zone.getDns1()); - routerResponse.setDns2(zone.getDns2()); - } - - routerResponse.setVpcId(router.getVpcId()); - - routerResponse.setObjectName("domainrouter"); - return routerResponse; + return new ArrayList(vrDataList.values()); } @Override @@ -3209,141 +2885,6 @@ public class ApiResponseHelper implements ResponseGenerator { return response; } - public UserVmData newUserVmData(UserVm userVm) { - UserVmData userVmData = new UserVmData(); - userVmData.setId(userVm.getId()); - userVmData.setName(userVm.getHostName()); - userVmData.setCreated(userVm.getCreated()); - userVmData.setGuestOsId(userVm.getGuestOSId()); - userVmData.setHaEnable(userVm.isHaEnabled()); - if (userVm.getState() != null) { - userVmData.setState(userVm.getState().toString()); - } - if (userVm.getDisplayName() != null) { - userVmData.setDisplayName(userVm.getDisplayName()); - } else { - userVmData.setDisplayName(userVm.getHostName()); - } - userVmData.setInstanceName(userVm.getInstanceName()); - - userVmData.setDomainId(userVm.getDomainId()); - - if (userVm.getHypervisorType() != null) { - userVmData.setHypervisor(userVm.getHypervisorType().toString()); - } - - if (userVm.getPassword() != null) { - userVmData.setPassword(userVm.getPassword()); - } - return userVmData; - } - - public UserVmResponse newUserVmResponse(UserVmData userVmData, boolean caller_is_admin) { - UserVmResponse userVmResponse = new UserVmResponse(); - - userVmResponse.setHypervisor(userVmData.getHypervisor()); - userVmResponse.setId(userVmData.getId()); - userVmResponse.setName(userVmData.getName()); - - userVmResponse.setDisplayName(userVmData.getDisplayName()); - - populateAccount(userVmResponse, userVmData.getAccountId()); - populateDomain(userVmResponse, userVmData.getDomainId()); - - userVmResponse.setCreated(userVmData.getCreated()); - userVmResponse.setState(userVmData.getState()); - userVmResponse.setHaEnable(userVmData.getHaEnable()); - userVmResponse.setGroupId(userVmData.getGroupId()); - userVmResponse.setGroup(userVmData.getGroup()); - userVmResponse.setZoneId(userVmData.getZoneId()); - userVmResponse.setZoneName(userVmData.getZoneName()); - if (caller_is_admin) { - userVmResponse.setInstanceName(userVmData.getInstanceName()); - userVmResponse.setHostId(userVmData.getHostId()); - userVmResponse.setHostName(userVmData.getHostName()); - } - userVmResponse.setTemplateId(userVmData.getTemplateId()); - userVmResponse.setTemplateName(userVmData.getTemplateName()); - userVmResponse.setTemplateDisplayText(userVmData.getTemplateDisplayText()); - userVmResponse.setPasswordEnabled(userVmData.getPasswordEnabled()); - userVmResponse.setIsoId(userVmData.getIsoId()); - userVmResponse.setIsoName(userVmData.getIsoName()); - userVmResponse.setIsoDisplayText(userVmData.getIsoDisplayText()); - userVmResponse.setServiceOfferingId(userVmData.getServiceOfferingId()); - userVmResponse.setServiceOfferingName(userVmData.getServiceOfferingName()); - userVmResponse.setCpuNumber(userVmData.getCpuNumber()); - userVmResponse.setCpuSpeed(userVmData.getCpuSpeed()); - userVmResponse.setMemory(userVmData.getMemory()); - userVmResponse.setCpuUsed(userVmData.getCpuUsed()); - userVmResponse.setNetworkKbsRead(userVmData.getNetworkKbsRead()); - userVmResponse.setNetworkKbsWrite(userVmData.getNetworkKbsWrite()); - userVmResponse.setGuestOsId(userVmData.getGuestOsId()); - userVmResponse.setRootDeviceId(userVmData.getRootDeviceId()); - userVmResponse.setRootDeviceType(userVmData.getRootDeviceType()); - userVmResponse.setPassword(userVmData.getPassword()); - userVmResponse.setJobId(userVmData.getJobId()); - userVmResponse.setJobStatus(userVmData.getJobStatus()); - userVmResponse.setForVirtualNetwork(userVmData.getForVirtualNetwork()); - - Set securityGroupResponse = new HashSet(); - for (SecurityGroupData sgd : userVmData.getSecurityGroupList()) { - if (sgd.getId() != null) { - SecurityGroupResponse sgr = new SecurityGroupResponse(); - sgr.setId(sgd.getId()); - sgr.setName(sgd.getName()); - sgr.setDescription(sgd.getDescription()); - - Account account = ApiDBUtils.findAccountByNameDomain(sgd.getAccountName(), sgd.getDomainId()); - if (account != null) { - populateAccount(sgr, account.getId()); - populateDomain(sgr, account.getDomainId()); - } - - sgr.setObjectName(sgd.getObjectName()); - securityGroupResponse.add(sgr); - } - } - userVmResponse.setSecurityGroupList(new ArrayList(securityGroupResponse)); - - Set nicResponses = new HashSet(); - for (NicData nd : userVmData.getNics()) { - NicResponse nr = new NicResponse(); - nr.setId(nd.getId()); - nr.setNetworkid(nd.getNetworkid()); - nr.setNetmask(nd.getNetmask()); - nr.setGateway(nd.getGateway()); - nr.setIpaddress(nd.getIpaddress()); - nr.setIsolationUri(nd.getIsolationUri()); - nr.setBroadcastUri(nd.getBroadcastUri()); - nr.setTrafficType(nd.getTrafficType()); - nr.setType(nd.getType()); - nr.setIsDefault(nd.getIsDefault()); - nr.setMacAddress(nd.getMacAddress()); - nr.setObjectName(nd.getObjectName()); - nicResponses.add(nr); - } - userVmResponse.setNics(new ArrayList(nicResponses)); - userVmResponse.setPublicIpId(userVmData.getPublicIpId()); - userVmResponse.setPublicIp(userVmData.getPublicIp()); - - //set tag information - List tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.UserVm, userVmData.getId()); - List tagResponses = new ArrayList(); - for (ResourceTag tag : tags) { - ResourceTagResponse tagResponse = createResourceTagResponse(tag, true); - tagResponses.add(tagResponse); - } - userVmResponse.setTags(tagResponses); - - UserVmDetailVO userVmDetail = ApiDBUtils.findPublicKeyByVmId(userVmData.getId()); - if (userVmDetail != null && userVmDetail.getValue() != null) { - String keyPairName = ApiDBUtils.getKeyPairName(userVmDetail.getValue()); - userVmResponse.setKeyPairName(keyPairName); - } - - return userVmResponse; - } - @Override public HypervisorCapabilitiesResponse createHypervisorCapabilitiesResponse(HypervisorCapabilities hpvCapabilities) { HypervisorCapabilitiesResponse hpvCapabilitiesResponse = new HypervisorCapabilitiesResponse(); @@ -3355,6 +2896,8 @@ public class ApiResponseHelper implements ResponseGenerator { return hpvCapabilitiesResponse; } + // TODO: we may need to refactor once ControlledEntityResponse and ControlledEntity id to uuid conversion are all done. + // currently code is scattered in private void populateOwner(ControlledEntityResponse response, ControlledEntity object) { Account account = ApiDBUtils.findAccountByIdIncludingRemoved(object.getAccountId()); @@ -3372,6 +2915,19 @@ public class ApiResponseHelper implements ResponseGenerator { response.setDomainName(domain.getName()); } + public static void populateOwner(ControlledViewEntityResponse response, ControlledViewEntity object) { + + if (object.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) { + response.setProjectId(object.getProjectUuid()); + response.setProjectName(object.getProjectName()); + } else { + response.setAccountName(object.getAccountName()); + } + + response.setDomainId(object.getDomainUuid()); + response.setDomainName(object.getDomainName()); + } + private void populateAccount(ControlledEntityResponse response, long accountId) { Account account = ApiDBUtils.findAccountByIdIncludingRemoved(accountId); if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) { diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index 2c4f7cf60d4..d75c8e169ad 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -78,6 +78,8 @@ import org.apache.http.protocol.ResponseDate; import org.apache.http.protocol.ResponseServer; import org.apache.log4j.Logger; +import org.apache.cloudstack.api.admin.router.command.ListRoutersCmd; +import org.apache.cloudstack.api.user.vm.command.ListVMsCmd; import com.cloud.acl.ControlledEntity; import com.cloud.api.response.ApiResponseSerializer; import com.cloud.api.response.ExceptionResponse; @@ -435,7 +437,7 @@ public class ApiServer implements HttpRequestHandler { // if the command is of the listXXXCommand, we will need to also return the // the job id and status if possible - if (cmdObj instanceof BaseListCmd) { + if (cmdObj instanceof BaseListCmd && !(cmdObj instanceof ListVMsCmd) && !(cmdObj instanceof ListRoutersCmd)) { buildAsyncListResponse((BaseListCmd) cmdObj, caller); } diff --git a/server/src/com/cloud/api/response/ApiResponseSerializer.java b/server/src/com/cloud/api/response/ApiResponseSerializer.java index 70d7edd1d15..cc2725eea8b 100644 --- a/server/src/com/cloud/api/response/ApiResponseSerializer.java +++ b/server/src/com/cloud/api/response/ApiResponseSerializer.java @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Date; import java.util.List; import java.util.regex.Matcher; @@ -210,8 +211,8 @@ public class ApiResponseSerializer { if (isAsync) { sb.append(""); } - } else if (fieldValue instanceof List) { - List subResponseList = (List) fieldValue; + } else if (fieldValue instanceof Collection) { + Collection subResponseList = (Collection) fieldValue; boolean usedUuidList = false; for (Object value : subResponseList) { if (value instanceof ResponseObject) { diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index ef61044d06b..ec543ed20fc 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -198,11 +198,13 @@ import com.cloud.vm.ItWorkDaoImpl; import com.cloud.vm.UserVmManagerImpl; import com.cloud.vm.dao.ConsoleProxyDaoImpl; import com.cloud.vm.dao.DomainRouterDaoImpl; +import com.cloud.vm.dao.DomainRouterJoinDaoImpl; import com.cloud.vm.dao.InstanceGroupDaoImpl; import com.cloud.vm.dao.InstanceGroupVMMapDaoImpl; import com.cloud.vm.dao.NicDaoImpl; import com.cloud.vm.dao.SecondaryStorageVmDaoImpl; import com.cloud.vm.dao.UserVmDaoImpl; +import com.cloud.vm.dao.UserVmJoinDaoImpl; import com.cloud.vm.dao.UserVmDetailsDaoImpl; import com.cloud.vm.dao.VMInstanceDaoImpl; @@ -216,6 +218,8 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addDao("HostDao", HostDaoImpl.class); addDao("VMInstanceDao", VMInstanceDaoImpl.class); addDao("UserVmDao", UserVmDaoImpl.class); + addDao("UserVmJoinDao", UserVmJoinDaoImpl.class); + addDao("DomainRouterJoinDao", DomainRouterJoinDaoImpl.class); ComponentInfo> info = addDao("ServiceOfferingDao", ServiceOfferingDaoImpl.class); info.addParameter("cache.size", "50"); info.addParameter("cache.time.to.live", "600"); @@ -359,6 +363,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com if (_daos.size() == 0) { populateDaos(); } + //FIXME: Incorrect method return definition return _daos; } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 7a8d5623c28..cced7630720 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -98,6 +98,8 @@ import org.apache.cloudstack.api.user.vmgroup.command.UpdateVMGroupCmd; import com.cloud.api.commands.UpgradeSystemVMCmd; import com.cloud.api.commands.UploadCustomCertificateCmd; import com.cloud.api.response.ExtractResponse; +import com.cloud.api.view.vo.DomainRouterJoinVO; +import com.cloud.api.view.vo.UserVmJoinVO; import com.cloud.async.AsyncJob; import com.cloud.async.AsyncJobExecutor; import com.cloud.async.AsyncJobManager; @@ -236,6 +238,7 @@ import com.cloud.utils.db.Filter; import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.JoinBuilder; import com.cloud.utils.db.JoinBuilder.JoinType; +import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; @@ -258,6 +261,7 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfileImpl; import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.DomainRouterDao; +import com.cloud.vm.dao.DomainRouterJoinDao; import com.cloud.vm.dao.InstanceGroupDao; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.SecondaryStorageVmDao; @@ -275,6 +279,7 @@ public class ManagementServerImpl implements ManagementServer { private final AlertManager _alertMgr; private final IPAddressDao _publicIpAddressDao; private final DomainRouterDao _routerDao; + private final DomainRouterJoinDao _routerJoinDao; private final ConsoleProxyDao _consoleProxyDao; private final ClusterDao _clusterDao; private final SecondaryStorageVmDao _secStorageVmDao; @@ -349,6 +354,7 @@ public class ManagementServerImpl implements ManagementServer { ComponentLocator locator = ComponentLocator.getLocator(Name); _configDao = locator.getDao(ConfigurationDao.class); _routerDao = locator.getDao(DomainRouterDao.class); + _routerJoinDao = locator.getDao(DomainRouterJoinDao.class); _eventDao = locator.getDao(EventDao.class); _dcDao = locator.getDao(DataCenterDao.class); _vlanDao = locator.getDao(VlanDao.class); @@ -1635,7 +1641,7 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public Pair, Integer> searchForRouters(ListRoutersCmd cmd) { + public Pair, Integer> searchForRouters(ListRoutersCmd cmd) { Long id = cmd.getId(); String name = cmd.getRouterName(); String state = cmd.getState(); @@ -1655,16 +1661,19 @@ public class ManagementServerImpl implements ManagementServer { Long domainId = domainIdRecursiveListProject.first(); Boolean isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter searchFilter = new Filter(DomainRouterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); - SearchBuilder sb = _routerDao.createSearchBuilder(); - _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + // no default orderBy + //Filter searchFilter = new Filter(DomainRouterJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter searchFilter = new Filter(DomainRouterJoinVO.class, null, true, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchBuilder sb = _routerJoinDao.createSearchBuilder(); + sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct ids to get number of records with pagination + _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); sb.and("name", sb.entity().getHostName(), SearchCriteria.Op.LIKE); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.IN); sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ); - sb.and("dataCenterId", sb.entity().getDataCenterIdToDeployIn(), SearchCriteria.Op.EQ); - sb.and("podId", sb.entity().getPodIdToDeployIn(), SearchCriteria.Op.EQ); + sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); + sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ); sb.and("hostId", sb.entity().getHostId(), SearchCriteria.Op.EQ); sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ); @@ -1677,20 +1686,14 @@ public class ManagementServerImpl implements ManagementServer { } if (networkId != null) { - SearchBuilder nicSearch = _nicDao.createSearchBuilder(); - nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); - SearchBuilder networkSearch = _networkDao.createSearchBuilder(); - networkSearch.and("networkId", networkSearch.entity().getId(), SearchCriteria.Op.EQ); - nicSearch.join("networkSearch", networkSearch, nicSearch.entity().getNetworkId(), networkSearch.entity().getId(), JoinBuilder.JoinType.INNER); - - sb.join("nicSearch", nicSearch, sb.entity().getId(), nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); + sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ); } - - SearchCriteria sc = sb.create(); - _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + + SearchCriteria sc = sb.create(); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); if (keyword != null) { - SearchCriteria ssc = _routerDao.createSearchCriteria(); + SearchCriteria ssc = _routerJoinDao.createSearchCriteria(); ssc.addOr("hostName", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("instanceName", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("state", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -1730,8 +1733,21 @@ public class ManagementServerImpl implements ManagementServer { sc.setParameters("vpcId", vpcId); } - Pair, Integer> result = _routerDao.searchAndCount(sc, searchFilter); - return new Pair, Integer>(result.first(), result.second()); + // search VR details by ids + Pair, Integer> uniqueVrPair = _routerJoinDao.searchAndCount(sc, searchFilter); + Integer count = uniqueVrPair.second(); + if ( count.intValue() == 0 ) { + // empty result + return uniqueVrPair; + } + List uniqueVrs = uniqueVrPair.first(); + Long[] vrIds = new Long[uniqueVrs.size()]; + int i = 0; + for (DomainRouterJoinVO v : uniqueVrs ){ + vrIds[i++] = v.getId(); + } + List vrs = _routerJoinDao.searchByIds(vrIds); + return new Pair, Integer>(vrs, count); } @Override diff --git a/server/src/com/cloud/user/AccountManager.java b/server/src/com/cloud/user/AccountManager.java index 90a34ad82b3..3cc7d12e7a2 100755 --- a/server/src/com/cloud/user/AccountManager.java +++ b/server/src/com/cloud/user/AccountManager.java @@ -21,6 +21,7 @@ import java.util.Map; import com.cloud.acl.ControlledEntity; import com.cloud.acl.SecurityChecker.AccessType; +import com.cloud.api.view.vo.ControlledViewEntity; import com.cloud.domain.Domain; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.PermissionDeniedException; @@ -93,9 +94,15 @@ public interface AccountManager extends AccountService { void buildACLSearchBuilder(SearchBuilder sb, Long domainId, boolean isRecursive, List permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria); + void buildACLViewSearchBuilder(SearchBuilder sb, Long domainId, + boolean isRecursive, List permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria); + void buildACLSearchCriteria(SearchCriteria sc, Long domainId, boolean isRecursive, List permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria); + void buildACLViewSearchCriteria(SearchCriteria sc, + Long domainId, boolean isRecursive, List permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria); + void buildACLSearchParameters(Account caller, Long id, String accountName, Long projectId, List permittedAccounts, Ternary domainIdRecursiveListProject, boolean listAll, boolean forProjectInvitation); diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index ab04a9c6191..59b7584d6b8 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -41,6 +41,7 @@ import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import com.cloud.acl.ControlledEntity; +import com.cloud.api.view.vo.ControlledViewEntity; import com.cloud.acl.SecurityChecker; import com.cloud.acl.SecurityChecker.AccessType; import com.cloud.api.ApiDBUtils; @@ -2380,8 +2381,51 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag } } - @Override - public UserAccount getUserByApiKey(String apiKey) { - return _userAccountDao.getUserByApiKey(apiKey); - } + @Override + public void buildACLViewSearchBuilder(SearchBuilder sb, Long domainId, + boolean isRecursive, List permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria) { + + sb.and("accountIdIN", sb.entity().getAccountId(), SearchCriteria.Op.IN); + sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ); + + if (((permittedAccounts.isEmpty()) && (domainId != null) && isRecursive)) { + // if accountId isn't specified, we can do a domain match for the + // admin case if isRecursive is true + sb.and("domainPath", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE); + } + + if (listProjectResourcesCriteria != null) { + if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) { + sb.and("accountType", sb.entity().getAccountType(), SearchCriteria.Op.EQ); + } else if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) { + sb.and("accountType", sb.entity().getAccountType(), SearchCriteria.Op.NEQ); + } + } + + } + + @Override + public void buildACLViewSearchCriteria(SearchCriteria sc, + Long domainId, boolean isRecursive, List permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria) { + + if (listProjectResourcesCriteria != null) { + sc.setParameters("accountType", Account.ACCOUNT_TYPE_PROJECT); + } + + if (!permittedAccounts.isEmpty()) { + sc.setParameters("accountIdIN", permittedAccounts.toArray()); + } else if (domainId != null) { + DomainVO domain = _domainDao.findById(domainId); + if (isRecursive) { + sc.setParameters("domainPath", domain.getPath() + "%"); + } else { + sc.setParameters("domainId", domainId); + } + } + } + + @Override + public UserAccount getUserByApiKey(String apiKey) { + return _userAccountDao.getUserByApiKey(apiKey); + } } diff --git a/server/src/com/cloud/vm/UserVmManager.java b/server/src/com/cloud/vm/UserVmManager.java index 4ce9bfee86d..1a2f50808d3 100755 --- a/server/src/com/cloud/vm/UserVmManager.java +++ b/server/src/com/cloud/vm/UserVmManager.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import com.cloud.agent.api.VmStatsEntry; +import com.cloud.api.view.vo.UserVmJoinVO; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; @@ -98,7 +99,7 @@ public interface UserVmManager extends VirtualMachineGuru, UserVmServi * @param tags TODO * @return List of UserVMs + count */ - Pair, Integer> searchForUserVMs(Criteria c, Account caller, Long domainId, boolean isRecursive, List permittedAccounts, boolean listAll, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags); + Pair, Integer> searchForUserVMs(Criteria c, Account caller, Long domainId, boolean isRecursive, List permittedAccounts, boolean listAll, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags); String getChecksum(Long hostId, String templatePath); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index eacf7f4ce51..5729035a1ff 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -74,6 +74,7 @@ import org.apache.cloudstack.api.user.vm.command.RestoreVMCmd; import org.apache.cloudstack.api.user.vm.command.StartVMCmd; import org.apache.cloudstack.api.user.vm.command.UpdateVMCmd; import org.apache.cloudstack.api.user.vm.command.UpgradeVMCmd; +import com.cloud.api.view.vo.UserVmJoinVO; import com.cloud.async.AsyncJobExecutor; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobVO; @@ -151,6 +152,8 @@ import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.org.Cluster; import com.cloud.org.Grouping; import com.cloud.projects.Project.ListProjectResourcesCriteria; +import com.cloud.projects.Project; +import com.cloud.projects.ProjectInvitationVO; import com.cloud.projects.ProjectManager; import com.cloud.resource.ResourceManager; import com.cloud.resource.ResourceState; @@ -222,6 +225,7 @@ import com.cloud.utils.db.JoinBuilder; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.ExecutionException; import com.cloud.utils.fsm.NoTransitionException; @@ -232,6 +236,7 @@ import com.cloud.vm.dao.InstanceGroupVMMapDao; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDetailsDao; +import com.cloud.vm.dao.UserVmJoinDao; import com.cloud.vm.dao.VMInstanceDao; @Local(value = { UserVmManager.class, UserVmService.class }) @@ -259,6 +264,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager @Inject protected UserVmDao _vmDao = null; @Inject + protected UserVmJoinDao _vmJoinDao = null; + @Inject protected VolumeDao _volsDao = null; @Inject protected DataCenterDao _dcDao = null; @@ -3040,7 +3047,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } @Override - public Pair, Integer> searchForUserVMs(ListVMsCmd cmd) { + public Pair, Integer> searchForUserVMs(ListVMsCmd cmd) { Account caller = UserContext.current().getCaller(); List permittedAccounts = new ArrayList(); String hypervisor = cmd.getHypervisor(); @@ -3054,7 +3061,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager Boolean isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal()); + // removing order by, orderBy shouold be specified in ListVMsCmd parameters + //Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal()); + Criteria c = new Criteria(null, Boolean.FALSE, cmd.getStartIndex(), cmd.getPageSizeVal()); c.addCriteria(Criteria.KEYWORD, cmd.getKeyword()); c.addCriteria(Criteria.ID, cmd.getId()); c.addCriteria(Criteria.NAME, cmd.getInstanceName()); @@ -3089,18 +3098,19 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } c.addCriteria(Criteria.ISADMIN, _accountMgr.isAdmin(caller.getType())); - Pair, Integer> result = searchForUserVMs(c, caller, domainId, isRecursive, + return searchForUserVMs(c, caller, domainId, isRecursive, permittedAccounts, listAll, listProjectResourcesCriteria, tags); - return new Pair, Integer>(result.first(), result.second()); } @Override - public Pair, Integer> searchForUserVMs(Criteria c, Account caller, Long domainId, boolean isRecursive, + public Pair, Integer> searchForUserVMs(Criteria c, Account caller, Long domainId, boolean isRecursive, List permittedAccounts, boolean listAll, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags) { - Filter searchFilter = new Filter(UserVmVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit()); + Filter searchFilter = new Filter(UserVmJoinVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit()); - SearchBuilder sb = _vmDao.createSearchBuilder(); - _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + //first search distinct vm id by using query criteria and pagination + SearchBuilder sb = _vmJoinDao.createSearchBuilder(); + sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct ids + _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); Object id = c.getCriteria(Criteria.ID); Object name = c.getCriteria(Criteria.NAME); @@ -3127,88 +3137,60 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager sb.and("stateEQ", sb.entity().getState(), SearchCriteria.Op.EQ); sb.and("stateNEQ", sb.entity().getState(), SearchCriteria.Op.NEQ); sb.and("stateNIN", sb.entity().getState(), SearchCriteria.Op.NIN); - sb.and("dataCenterId", sb.entity().getDataCenterIdToDeployIn(), SearchCriteria.Op.EQ); - sb.and("podId", sb.entity().getPodIdToDeployIn(), SearchCriteria.Op.EQ); + sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); + sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ); sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ); sb.and("hostIdEQ", sb.entity().getHostId(), SearchCriteria.Op.EQ); - sb.and("hostIdIN", sb.entity().getHostId(), SearchCriteria.Op.IN); + sb.and("hostName", sb.entity().getHostName(), SearchCriteria.Op.LIKE); sb.and("templateId", sb.entity().getTemplateId(), SearchCriteria.Op.EQ); - sb.and("isoId", sb.entity().getTemplateId(), SearchCriteria.Op.EQ); + sb.and("isoId", sb.entity().getIsoId(), SearchCriteria.Op.EQ); + sb.and("instanceGroupId", sb.entity().getInstanceGroupId(), SearchCriteria.Op.EQ); - if (groupId != null && (Long) groupId == -1) { - SearchBuilder vmSearch = _groupVMMapDao.createSearchBuilder(); - vmSearch.and("instanceId", vmSearch.entity().getInstanceId(), SearchCriteria.Op.EQ); - sb.join("vmSearch", vmSearch, sb.entity().getId(), vmSearch.entity().getInstanceId(), JoinBuilder.JoinType.LEFTOUTER); - } else if (groupId != null) { - SearchBuilder groupSearch = _groupVMMapDao.createSearchBuilder(); - groupSearch.and("groupId", groupSearch.entity().getGroupId(), SearchCriteria.Op.EQ); - sb.join("groupSearch", groupSearch, sb.entity().getId(), groupSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); + if (groupId != null && (Long) groupId != -1) { + sb.and("instanceGroupId", sb.entity().getInstanceGroupId(), SearchCriteria.Op.EQ); } if (tags != null && !tags.isEmpty()) { - SearchBuilder tagSearch = _resourceTagDao.createSearchBuilder(); for (int count=0; count < tags.size(); count++) { - tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ); - tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ); - tagSearch.cp(); + sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ); + sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ); + sb.cp(); } - tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); - sb.groupBy(sb.entity().getId()); - sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER); } if (networkId != null) { - SearchBuilder nicSearch = _nicDao.createSearchBuilder(); - nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); - - SearchBuilder networkSearch = _networkDao.createSearchBuilder(); - networkSearch.and("networkId", networkSearch.entity().getId(), SearchCriteria.Op.EQ); - nicSearch.join("networkSearch", networkSearch, nicSearch.entity().getNetworkId(), networkSearch.entity().getId(), JoinBuilder.JoinType.INNER); - - sb.join("nicSearch", nicSearch, sb.entity().getId(), nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); + sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ); } if(vpcId != null && networkId == null){ - SearchBuilder nicSearch = _nicDao.createSearchBuilder(); - - SearchBuilder networkSearch = _networkDao.createSearchBuilder(); - nicSearch.join("networkSearch", networkSearch, nicSearch.entity().getNetworkId(), networkSearch.entity().getId(), JoinBuilder.JoinType.INNER); - - SearchBuilder vpcSearch = _vpcDao.createSearchBuilder(); - vpcSearch.and("vpcId", vpcSearch.entity().getId(), SearchCriteria.Op.EQ); - networkSearch.join("vpcSearch", vpcSearch, networkSearch.entity().getVpcId(), vpcSearch.entity().getId(), JoinBuilder.JoinType.INNER); - - sb.join("nicSearch", nicSearch, sb.entity().getId(), nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); + sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ); } if (storageId != null) { - SearchBuilder volumeSearch = _volsDao.createSearchBuilder(); - volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), SearchCriteria.Op.EQ); - sb.join("volumeSearch", volumeSearch, sb.entity().getId(), volumeSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); + sb.and("poolId", sb.entity().getPoolId(), SearchCriteria.Op.EQ); } // populate the search criteria with the values passed in - SearchCriteria sc = sb.create(); - _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + SearchCriteria sc = sb.create(); + + // building ACL condition + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); if (tags != null && !tags.isEmpty()) { int count = 0; - sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.UserVm.toString()); - for (String key : tags.keySet()) { - sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key); - sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key)); + for (String key : tags.keySet()) { + sc.setParameters("key" + String.valueOf(count), key); + sc.setParameters("value" + String.valueOf(count), tags.get(key)); count++; } } - if (groupId != null && (Long) groupId == -1) { - sc.setJoinParameters("vmSearch", "instanceId", (Object) null); - } else if (groupId != null) { - sc.setJoinParameters("groupSearch", "groupId", groupId); + if (groupId != null && (Long)groupId != -1) { + sc.setParameters("instanceGroupId", groupId); } if (keyword != null) { - SearchCriteria ssc = _vmDao.createSearchCriteria(); + SearchCriteria ssc = _vmJoinDao.createSearchCriteria(); ssc.addOr("displayName", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("hostName", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("instanceName", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -3230,11 +3212,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } if (networkId != null) { - sc.setJoinParameters("nicSearch", "networkId", networkId); + sc.setParameters("networkId", networkId); } if(vpcId != null && networkId == null){ - sc.setJoinParameters("vpcSearch", "vpcId", vpcId); + sc.setParameters("vpcId", vpcId); } if (name != null) { @@ -3277,25 +3259,29 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager sc.setParameters("hostIdEQ", hostId); } else { if (hostName != null) { - List hosts = _resourceMgr.listHostsByNameLike((String) hostName); - if (hosts != null & !hosts.isEmpty()) { - Long[] hostIds = new Long[hosts.size()]; - for (int i = 0; i < hosts.size(); i++) { - HostVO host = hosts.get(i); - hostIds[i] = host.getId(); - } - sc.setParameters("hostIdIN", (Object[]) hostIds); - } else { - return new Pair, Integer>(new ArrayList(), 0); - } + sc.setParameters("hostName", hostName); } } if (storageId != null) { - sc.setJoinParameters("volumeSearch", "poolId", storageId); + sc.setParameters("poolId", storageId); } - - return _vmDao.searchAndCount(sc, searchFilter); + + // search vm details by ids + Pair, Integer> uniqueVmPair = _vmJoinDao.searchAndCount(sc, searchFilter); + Integer count = uniqueVmPair.second(); + if ( count.intValue() == 0 ){ + // handle empty result cases + return uniqueVmPair; + } + List uniqueVms = uniqueVmPair.first(); + Long[] vmIds = new Long[uniqueVms.size()]; + int i = 0; + for (UserVmJoinVO v : uniqueVms ){ + vmIds[i++] = v.getId(); + } + List vms = _vmJoinDao.searchByIds(vmIds); + return new Pair, Integer>(vms, count); } @Override diff --git a/server/src/com/cloud/vm/dao/DomainRouterJoinDao.java b/server/src/com/cloud/vm/dao/DomainRouterJoinDao.java new file mode 100644 index 00000000000..c7c749b5690 --- /dev/null +++ b/server/src/com/cloud/vm/dao/DomainRouterJoinDao.java @@ -0,0 +1,36 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.vm.dao; + +import java.util.List; + +import com.cloud.api.response.DomainRouterResponse; +import com.cloud.api.view.vo.DomainRouterJoinVO; +import com.cloud.network.router.VirtualRouter; +import com.cloud.user.Account; +import com.cloud.utils.db.GenericDao; + +public interface DomainRouterJoinDao extends GenericDao { + + DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO uvo, Account caller); + + DomainRouterResponse setDomainRouterResponse(DomainRouterResponse userVmData, DomainRouterJoinVO uvo); + + List newDomainRouterView(VirtualRouter vr); + + List searchByIds(Long... ids); +} diff --git a/server/src/com/cloud/vm/dao/DomainRouterJoinDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterJoinDaoImpl.java new file mode 100644 index 00000000000..a3f7d77bcdf --- /dev/null +++ b/server/src/com/cloud/vm/dao/DomainRouterJoinDaoImpl.java @@ -0,0 +1,231 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.vm.dao; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Hashtable; +import java.util.List; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiDBUtils; +import com.cloud.api.ApiResponseHelper; +import com.cloud.api.response.DomainRouterResponse; +import com.cloud.api.response.NicResponse; +import com.cloud.api.response.ResourceTagResponse; +import com.cloud.api.response.SecurityGroupResponse; +import com.cloud.api.response.UserVmResponse; +import com.cloud.api.view.vo.DomainRouterJoinVO; +import com.cloud.dc.DataCenter; +import com.cloud.network.Network; +import com.cloud.network.Networks.TrafficType; +import com.cloud.network.router.VirtualRouter; +import com.cloud.offering.ServiceOffering; +import com.cloud.user.Account; +import com.cloud.uservm.UserVm; +import com.cloud.utils.Pair; +import com.cloud.utils.db.Attribute; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.JoinBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.NicProfile; + + +@Local(value={DomainRouterJoinDao.class}) +public class DomainRouterJoinDaoImpl extends GenericDaoBase implements DomainRouterJoinDao { + public static final Logger s_logger = Logger.getLogger(DomainRouterJoinDaoImpl.class); + + private SearchBuilder vrSearch; + + private SearchBuilder vrIdSearch; + + protected DomainRouterJoinDaoImpl() { + + vrSearch = createSearchBuilder(); + vrSearch.and("idIN", vrSearch.entity().getId(), SearchCriteria.Op.IN); + vrSearch.done(); + + vrIdSearch = createSearchBuilder(); + vrIdSearch.and("id", vrIdSearch.entity().getId(), SearchCriteria.Op.EQ); + vrIdSearch.done(); + + this._count = "select count(distinct id) from domain_router_view WHERE "; + } + + + @Override + public DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO router, Account caller) { + DomainRouterResponse routerResponse = new DomainRouterResponse(); + routerResponse.setId(router.getUuid()); + routerResponse.setZoneId(router.getDataCenterUuid()); + routerResponse.setName(router.getHostName()); + routerResponse.setTemplateId(router.getTemplateUuid()); + routerResponse.setCreated(router.getCreated()); + routerResponse.setState(router.getState()); + routerResponse.setIsRedundantRouter(router.isRedundantRouter()); + routerResponse.setRedundantState(router.getRedundantState().toString()); + + if (caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN + || caller.getType() == Account.ACCOUNT_TYPE_ADMIN) { + if (router.getHostId() != null) { + routerResponse.setHostId(router.getHostUuid()); + routerResponse.setHostName(router.getHostName()); + } + routerResponse.setPodId(router.getPodUuid()); + long nic_id = router.getNicId(); + if (nic_id > 0) { + TrafficType ty = router.getTrafficType(); + if (ty != null) { + // legacy code, public/control/guest nic info is kept in + // nics response object + if (ty == TrafficType.Public) { + routerResponse.setPublicIp(router.getIpAddress()); + routerResponse.setPublicMacAddress(router.getMacAddress()); + routerResponse.setPublicNetmask(router.getNetmask()); + routerResponse.setGateway(router.getGateway()); + routerResponse.setPublicNetworkId(router.getNetworkUuid()); + } else if (ty == TrafficType.Control) { + routerResponse.setLinkLocalIp(router.getIpAddress()); + routerResponse.setLinkLocalMacAddress(router.getMacAddress()); + routerResponse.setLinkLocalNetmask(router.getNetmask()); + routerResponse.setLinkLocalNetworkId(router.getNetworkUuid()); + } else if (ty == TrafficType.Guest) { + routerResponse.setGuestIpAddress(router.getIpAddress()); + routerResponse.setGuestMacAddress(router.getMacAddress()); + routerResponse.setGuestNetmask(router.getNetmask()); + routerResponse.setGuestNetworkId(router.getNetworkUuid()); + routerResponse.setNetworkDomain(router.getNetworkDomain()); + } + } + + NicResponse nicResponse = new NicResponse(); + nicResponse.setId(router.getNicUuid()); + nicResponse.setIpaddress(router.getIpAddress()); + nicResponse.setGateway(router.getGateway()); + nicResponse.setNetmask(router.getNetmask()); + nicResponse.setNetworkid(router.getNetworkUuid()); + nicResponse.setNetworkName(router.getNetworkName()); + nicResponse.setMacAddress(router.getMacAddress()); + if (router.getBroadcastUri() != null) { + nicResponse.setBroadcastUri(router.getBroadcastUri().toString()); + } + if (router.getIsolationUri() != null) { + nicResponse.setIsolationUri(router.getIsolationUri().toString()); + } + if (router.getTrafficType() != null) { + nicResponse.setTrafficType(router.getTrafficType().toString()); + } + if (router.getGuestType() != null) { + nicResponse.setType(router.getGuestType().toString()); + } + nicResponse.setIsDefault(router.isDefaultNic()); + nicResponse.setObjectName("nic"); + routerResponse.addNic(nicResponse); + } + } + + routerResponse.setServiceOfferingId(router.getServiceOfferingUuid()); + routerResponse.setServiceOfferingName(router.getServiceOfferingName()); + + // populate owner. + ApiResponseHelper.populateOwner(routerResponse, router); + + + routerResponse.setDomainId(router.getDomainUuid()); + routerResponse.setDomainName(router.getDomainName()); + + routerResponse.setZoneName(router.getDataCenterName()); + routerResponse.setDns1(router.getDns1()); + routerResponse.setDns2(router.getDns2()); + + routerResponse.setVpcId(router.getVpcUuid()); + + routerResponse.setObjectName("router"); + + return routerResponse; + } + + + @Override + public DomainRouterResponse setDomainRouterResponse(DomainRouterResponse vrData, DomainRouterJoinVO vr) { + long nic_id = vr.getNicId(); + if (nic_id > 0) { + NicResponse nicResponse = new NicResponse(); + nicResponse.setId(vr.getNicUuid()); + nicResponse.setIpaddress(vr.getIpAddress()); + nicResponse.setGateway(vr.getGateway()); + nicResponse.setNetmask(vr.getNetmask()); + nicResponse.setNetworkid(vr.getNetworkUuid()); + nicResponse.setMacAddress(vr.getMacAddress()); + if (vr.getBroadcastUri() != null) { + nicResponse.setBroadcastUri(vr.getBroadcastUri().toString()); + } + if (vr.getIsolationUri() != null) { + nicResponse.setIsolationUri(vr.getIsolationUri().toString()); + } + if (vr.getTrafficType() != null) { + nicResponse.setTrafficType(vr.getTrafficType().toString()); + } + if (vr.getGuestType() != null) { + nicResponse.setType(vr.getGuestType().toString()); + } + nicResponse.setIsDefault(vr.isDefaultNic()); + nicResponse.setObjectName("nic"); + vrData.addNic(nicResponse); + } + return vrData; + } + + + + + @Override + public List searchByIds(Long... ids) { + SearchCriteria sc = vrSearch.create(); + sc.setParameters("idIN", ids); + return searchIncludingRemoved(sc, null, null, false); + } + + + @Override + public List newDomainRouterView(VirtualRouter vr) { + + List uvList = new ArrayList(); + SearchCriteria sc = vrIdSearch.create(); + sc.setParameters("id", vr.getId()); + List vms = searchIncludingRemoved(sc, null, null, false); + if (vms != null) { + for (DomainRouterJoinVO uvm : vms) { + uvList.add(uvm); + } + } + return uvList; + + } + +} diff --git a/server/src/com/cloud/vm/dao/UserVmJoinDao.java b/server/src/com/cloud/vm/dao/UserVmJoinDao.java new file mode 100644 index 00000000000..adeef63339d --- /dev/null +++ b/server/src/com/cloud/vm/dao/UserVmJoinDao.java @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.vm.dao; + +import java.util.EnumSet; +import java.util.List; + +import com.cloud.api.ApiConstants.VMDetails; +import com.cloud.api.response.UserVmResponse; +import com.cloud.api.view.vo.UserVmJoinVO; +import com.cloud.user.Account; +import com.cloud.uservm.UserVm; +import com.cloud.utils.db.GenericDao; + +public interface UserVmJoinDao extends GenericDao { + + UserVmResponse newUserVmResponse(String objectName, UserVmJoinVO userVm, EnumSet details, Account caller); + + UserVmResponse setUserVmResponse(UserVmResponse userVmData, UserVmJoinVO uvo); + + List newUserVmView(UserVm... userVms); + + List searchByIds(Long... ids); +} diff --git a/server/src/com/cloud/vm/dao/UserVmJoinDaoImpl.java b/server/src/com/cloud/vm/dao/UserVmJoinDaoImpl.java new file mode 100644 index 00000000000..5b7a2c15ac3 --- /dev/null +++ b/server/src/com/cloud/vm/dao/UserVmJoinDaoImpl.java @@ -0,0 +1,384 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.vm.dao; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumSet; +import java.util.Hashtable; +import java.util.List; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiDBUtils; +import com.cloud.api.ApiConstants.VMDetails; +import com.cloud.api.response.NicResponse; +import com.cloud.api.response.ResourceTagResponse; +import com.cloud.api.response.SecurityGroupResponse; +import com.cloud.api.response.UserVmResponse; +import com.cloud.api.view.vo.UserVmJoinVO; +import com.cloud.user.Account; +import com.cloud.uservm.UserVm; +import com.cloud.utils.Pair; +import com.cloud.utils.db.Attribute; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.JoinBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.VmStats; + + +@Local(value={UserVmJoinDao.class}) +public class UserVmJoinDaoImpl extends GenericDaoBase implements UserVmJoinDao { + public static final Logger s_logger = Logger.getLogger(UserVmJoinDaoImpl.class); + + private static final int VM_DETAILS_BATCH_SIZE=100; + + private SearchBuilder VmDetailSearch; + + protected UserVmJoinDaoImpl() { + + VmDetailSearch = createSearchBuilder(); + VmDetailSearch.and("idIN", VmDetailSearch.entity().getId(), SearchCriteria.Op.IN); + VmDetailSearch.done(); + + this._count = "select count(distinct id) from user_vm_view WHERE "; + } + + public UserVmResponse newUserVmResponse(String objectName, UserVmJoinVO userVm, EnumSet details, Account caller) { + UserVmResponse userVmResponse = new UserVmResponse(); + + if (userVm.getHypervisorType() != null){ + userVmResponse.setHypervisor(userVm.getHypervisorType().toString()); + } + userVmResponse.setId(userVm.getUuid()); + userVmResponse.setName(userVm.getName()); + + userVmResponse.setDisplayName(userVm.getDisplayName()); + + if (userVm.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) { + userVmResponse.setProjectId(userVm.getProjectUuid()); + userVmResponse.setProjectName(userVm.getProjectName()); + } else { + userVmResponse.setAccountName(userVm.getAccountName()); + } + + userVmResponse.setDomainId(userVm.getDomainUuid()); + userVmResponse.setDomainName(userVm.getDomainName()); + + userVmResponse.setCreated(userVm.getCreated()); + + if (userVm.getState() != null) { + userVmResponse.setState(userVm.getState().toString()); + } + userVmResponse.setHaEnable(userVm.isHaEnabled()); + if (details.contains(VMDetails.all) || details.contains(VMDetails.group)) { + userVmResponse.setGroupId(userVm.getInstanceGroupUuid()); + userVmResponse.setGroup(userVm.getInstanceGroupName()); + } + userVmResponse.setZoneId(userVm.getDataCenterUuid()); + userVmResponse.setZoneName(userVm.getDataCenterName()); + if ((caller == null) || (caller.getType() == Account.ACCOUNT_TYPE_ADMIN)) { + userVmResponse.setInstanceName(userVm.getInstanceName()); + userVmResponse.setHostId(userVm.getHostUuid()); + userVmResponse.setHostName(userVm.getHostName()); + } + + if (details.contains(VMDetails.all) || details.contains(VMDetails.tmpl)) { + userVmResponse.setTemplateId(userVm.getTemplateUuid()); + userVmResponse.setTemplateName(userVm.getTemplateName()); + userVmResponse.setTemplateDisplayText(userVm.getTemplateDisplayText()); + userVmResponse.setPasswordEnabled(userVm.isPasswordEnabled()); + } + if (details.contains(VMDetails.all) || details.contains(VMDetails.iso)) { + userVmResponse.setIsoId(userVm.getIsoUuid()); + userVmResponse.setIsoName(userVm.getIsoName()); + userVmResponse.setIsoDisplayText(userVm.getIsoDisplayText()); + } + if (details.contains(VMDetails.all) || details.contains(VMDetails.servoff)) { + userVmResponse.setServiceOfferingId(userVm.getServiceOfferingUuid()); + userVmResponse.setServiceOfferingName(userVm.getServiceOfferingName()); + userVmResponse.setCpuNumber(userVm.getCpu()); + userVmResponse.setCpuSpeed(userVm.getSpeed()); + userVmResponse.setMemory(userVm.getRamSize()); + } + userVmResponse.setGuestOsId(userVm.getGuestOsUuid()); + if (details.contains(VMDetails.all) || details.contains(VMDetails.volume)) { + userVmResponse.setRootDeviceId(userVm.getVolumeDeviceId()); + if (userVm.getVolumeType() != null) { + userVmResponse.setRootDeviceType(userVm.getVolumeType().toString()); + } + } + userVmResponse.setPassword(userVm.getPassword()); + userVmResponse.setJobUuid(userVm.getJobUuid()); + userVmResponse.setJobStatus(userVm.getJobStatus()); + //userVmResponse.setForVirtualNetwork(userVm.getForVirtualNetwork()); + + userVmResponse.setPublicIpId(userVm.getPublicIpUuid()); + userVmResponse.setPublicIp(userVm.getPublicIpAddress()); + userVmResponse.setKeyPairName(userVm.getKeypairName()); + + if (details.contains(VMDetails.all) || details.contains(VMDetails.stats)) { + DecimalFormat decimalFormat = new DecimalFormat("#.##"); + // stats calculation + String cpuUsed = null; + VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId()); + if (vmStats != null) { + float cpuUtil = (float) vmStats.getCPUUtilization(); + cpuUsed = decimalFormat.format(cpuUtil) + "%"; + userVmResponse.setCpuUsed(cpuUsed); + + Double networkKbRead = Double.valueOf(vmStats.getNetworkReadKBs()); + userVmResponse.setNetworkKbsRead(networkKbRead.longValue()); + + Double networkKbWrite = Double.valueOf(vmStats.getNetworkWriteKBs()); + userVmResponse.setNetworkKbsWrite(networkKbWrite.longValue()); + } + } + + if (details.contains(VMDetails.all) || details.contains(VMDetails.secgrp)) { + Long securityGroupId = userVm.getSecurityGroupId(); + if (securityGroupId != null && securityGroupId.longValue() != 0) { + SecurityGroupResponse resp = new SecurityGroupResponse(); + resp.setId(userVm.getSecurityGroupId()); // TODO: change + // SecurityGroupResponse + // IdentityProxy + resp.setName(userVm.getSecurityGroupName()); + resp.setDescription(userVm.getSecurityGroupDescription()); + resp.setObjectName("securitygroup"); + if (userVm.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) { + resp.setProjectId(userVm.getProjectId()); // TODO: pending + // SecurityGroupResponse + // uuid change + resp.setProjectName(userVm.getProjectName()); + } else { + resp.setAccountName(userVm.getAccountName()); + } + userVmResponse.addSecurityGroup(resp); + } + } + + if (details.contains(VMDetails.all) || details.contains(VMDetails.nics)) { + long nic_id = userVm.getNicId(); + if (nic_id > 0) { + NicResponse nicResponse = new NicResponse(); + nicResponse.setId(userVm.getNicUuid()); + nicResponse.setIpaddress(userVm.getIpAddress()); + nicResponse.setGateway(userVm.getGateway()); + nicResponse.setNetmask(userVm.getNetmask()); + nicResponse.setNetworkid(userVm.getNetworkUuid()); + nicResponse.setMacAddress(userVm.getMacAddress()); + if (userVm.getBroadcastUri() != null) { + nicResponse.setBroadcastUri(userVm.getBroadcastUri().toString()); + } + if (userVm.getIsolationUri() != null) { + nicResponse.setIsolationUri(userVm.getIsolationUri().toString()); + } + if (userVm.getTrafficType() != null) { + nicResponse.setTrafficType(userVm.getTrafficType().toString()); + } + if (userVm.getGuestType() != null) { + nicResponse.setType(userVm.getGuestType().toString()); + } + nicResponse.setIsDefault(userVm.isDefaultNic()); + nicResponse.setObjectName("nic"); + userVmResponse.addNic(nicResponse); + } + } + + // update tag information + long tag_id = userVm.getTagId(); + if (tag_id > 0) { + ResourceTagResponse tag = new ResourceTagResponse(); + tag.setKey(userVm.getTagKey()); + tag.setValue(userVm.getTagValue()); + if (userVm.getTagResourceType() != null) { + tag.setResourceType(userVm.getTagResourceType().toString()); + } + tag.setId(userVm.getTagResourceUuid()); // tag resource uuid + tag.setCustomer(userVm.getTagCustomer()); + // TODO: assuming tagAccountId and tagDomainId are the same as VM + // accountId and domainId + tag.setDomainId(userVm.getTagDomainId()); + if (userVm.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) { + tag.setProjectId(userVm.getProjectId()); + tag.setProjectName(userVm.getProjectName()); + } else { + tag.setAccountName(userVm.getAccountName()); + } + tag.setDomainId(userVm.getDomainId()); // TODO: pending tag resource + // response uuid change + tag.setDomainName(userVm.getDomainName()); + + tag.setObjectName("tag"); + userVmResponse.addTag(tag); + } + userVmResponse.setObjectName(objectName); + + return userVmResponse; + } + + public UserVmResponse setUserVmResponse(UserVmResponse userVmData, UserVmJoinVO uvo) { + Long securityGroupId = uvo.getSecurityGroupId(); + if (securityGroupId != null && securityGroupId.longValue() != 0) { + SecurityGroupResponse resp = new SecurityGroupResponse(); + resp.setId(uvo.getSecurityGroupId()); // TODO: change + // SecurityGroupResponse + // IdentityProxy + resp.setName(uvo.getSecurityGroupName()); + resp.setDescription(uvo.getSecurityGroupDescription()); + resp.setObjectName("securitygroup"); + if (uvo.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) { + resp.setProjectId(uvo.getProjectId()); // TODO: pending + // SecurityGroupResponse + // uuid change + resp.setProjectName(uvo.getProjectName()); + } else { + resp.setAccountName(uvo.getAccountName()); + } + userVmData.addSecurityGroup(resp); + } + + long nic_id = uvo.getNicId(); + if (nic_id > 0) { + NicResponse nicResponse = new NicResponse(); + nicResponse.setId(uvo.getNicUuid()); + nicResponse.setIpaddress(uvo.getIpAddress()); + nicResponse.setGateway(uvo.getGateway()); + nicResponse.setNetmask(uvo.getNetmask()); + nicResponse.setNetworkid(uvo.getNetworkUuid()); + nicResponse.setMacAddress(uvo.getMacAddress()); + if (uvo.getBroadcastUri() != null) { + nicResponse.setBroadcastUri(uvo.getBroadcastUri().toString()); + } + if (uvo.getIsolationUri() != null) { + nicResponse.setIsolationUri(uvo.getIsolationUri().toString()); + } + if (uvo.getTrafficType() != null) { + nicResponse.setTrafficType(uvo.getTrafficType().toString()); + } + if (uvo.getGuestType() != null) { + nicResponse.setType(uvo.getGuestType().toString()); + } + nicResponse.setIsDefault(uvo.isDefaultNic()); + nicResponse.setObjectName("nic"); + userVmData.addNic(nicResponse); + } + + long tag_id = uvo.getTagId(); + if (tag_id > 0) { + ResourceTagResponse tag = new ResourceTagResponse(); + tag.setKey(uvo.getTagKey()); + tag.setValue(uvo.getTagValue()); + if (uvo.getTagResourceType() != null) { + tag.setResourceType(uvo.getTagResourceType().toString()); + } + tag.setId(uvo.getTagResourceUuid()); // tag resource uuid + tag.setCustomer(uvo.getTagCustomer()); + // TODO: assuming tagAccountId and tagDomainId are the same as VM + // accountId and domainId + tag.setDomainId(uvo.getTagDomainId()); + if (uvo.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) { + tag.setProjectId(uvo.getProjectId()); + tag.setProjectName(uvo.getProjectName()); + } else { + tag.setAccountName(uvo.getAccountName()); + } + tag.setDomainId(uvo.getDomainId()); // TODO: pending tag resource + // response uuid change + tag.setDomainName(uvo.getDomainName()); + + tag.setObjectName("tag"); + userVmData.addTag(tag); + } + return userVmData; + } + + + @Override + public List searchByIds(Long... vmIds) { + SearchCriteria sc = VmDetailSearch.create(); + sc.setParameters("idIN", vmIds); + return searchIncludingRemoved(sc, null, null, false); + } + + @Override + public List newUserVmView(UserVm... userVms) { + + int curr_index = 0; + + Hashtable userVmDataHash = new Hashtable(); + for (UserVm vm : userVms){ + if ( !userVmDataHash.containsKey(vm.getId())){ + userVmDataHash.put(vm.getId(), vm); + } + } + + List uvList = new ArrayList(); + List userVmIdList = new ArrayList(userVmDataHash.keySet()); + if (userVmIdList.size() > VM_DETAILS_BATCH_SIZE) { + while ((curr_index + VM_DETAILS_BATCH_SIZE) <= userVmIdList.size()) { + // set current ids + Long[] vmIds = new Long[VM_DETAILS_BATCH_SIZE]; + for (int k = 0, j = curr_index; j < curr_index + VM_DETAILS_BATCH_SIZE; j++, k++) { + vmIds[k] = userVmIdList.get(j); + } + SearchCriteria sc = VmDetailSearch.create(); + sc.setParameters("idIN", vmIds); + List vms = searchIncludingRemoved(sc, null, null, false); + if (vms != null) { + for (UserVmJoinVO uvm : vms) { + uvList.add(uvm); + } + } + curr_index += VM_DETAILS_BATCH_SIZE; + } + } + + if (curr_index < userVmIdList.size()) { + int batch_size = (userVmIdList.size() - curr_index); + // set the ids value + Long[] vmIds = new Long[batch_size]; + for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) { + vmIds[k] = userVmIdList.get(j); + } + SearchCriteria sc = VmDetailSearch.create(); + sc.setParameters("idIN", vmIds); + List vms = searchIncludingRemoved(sc, null, null, false); + if (vms != null) { + for (UserVmJoinVO uvm : vms) { + UserVm vm = userVmDataHash.get(uvm.getId()); + assert vm != null : "We should not find details of vm not in the passed UserVm list"; + uvList.add(uvm); + } + } + } + return uvList; + + } + +} diff --git a/server/test/com/cloud/keystore/KeystoreTest.java b/server/test/com/cloud/keystore/KeystoreTest.java index 3a0bb71d49f..a0ffb688f26 100644 --- a/server/test/com/cloud/keystore/KeystoreTest.java +++ b/server/test/com/cloud/keystore/KeystoreTest.java @@ -153,7 +153,7 @@ public class KeystoreTest extends TestCase { */ public void testUuid() { UserVmResponse vm = new UserVmResponse(); - vm.setId(3L); + vm.setId(Long.toString(3L)); /* vm.setAccountName("admin"); vm.setName("i-2-3-KY"); diff --git a/server/test/com/cloud/user/MockAccountManagerImpl.java b/server/test/com/cloud/user/MockAccountManagerImpl.java index b8d9043e27f..3b1adc6609a 100644 --- a/server/test/com/cloud/user/MockAccountManagerImpl.java +++ b/server/test/com/cloud/user/MockAccountManagerImpl.java @@ -30,6 +30,7 @@ import org.apache.cloudstack.api.user.account.command.ListAccountsCmd; import com.cloud.api.commands.RegisterCmd; import com.cloud.api.commands.UpdateAccountCmd; import org.apache.cloudstack.api.admin.user.command.UpdateUserCmd; +import com.cloud.api.view.vo.ControlledViewEntity; import com.cloud.domain.Domain; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.PermissionDeniedException; @@ -334,6 +335,18 @@ public class MockAccountManagerImpl implements Manager, AccountManager, AccountS // TODO Auto-generated method stub } + @Override + public void buildACLViewSearchBuilder(SearchBuilder sb, Long domainId, + boolean isRecursive, List permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria) { + // TODO Auto-generated method stub + } + + @Override + public void buildACLViewSearchCriteria(SearchCriteria sc, Long domainId, + boolean isRecursive, List permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria) { + // TODO Auto-generated method stub + } + /* (non-Javadoc) * @see com.cloud.user.AccountService#getUserByApiKey(java.lang.String) */ diff --git a/server/test/com/cloud/vm/MockUserVmManagerImpl.java b/server/test/com/cloud/vm/MockUserVmManagerImpl.java index 71e38715158..d9360959d6c 100644 --- a/server/test/com/cloud/vm/MockUserVmManagerImpl.java +++ b/server/test/com/cloud/vm/MockUserVmManagerImpl.java @@ -44,6 +44,7 @@ import org.apache.cloudstack.api.user.vm.command.RestoreVMCmd; import org.apache.cloudstack.api.user.vm.command.StartVMCmd; import org.apache.cloudstack.api.user.vm.command.UpdateVMCmd; import org.apache.cloudstack.api.user.vm.command.UpgradeVMCmd; +import com.cloud.api.view.vo.UserVmJoinVO; import com.cloud.dc.DataCenter; import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; @@ -192,7 +193,7 @@ public class MockUserVmManagerImpl implements UserVmManager, UserVmService, Mana } @Override - public Pair, Integer> searchForUserVMs(Criteria c, Account caller, Long domainId, boolean isRecursive, List permittedAccounts, boolean listAll, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags) { + public Pair, Integer> searchForUserVMs(Criteria c, Account caller, Long domainId, boolean isRecursive, List permittedAccounts, boolean listAll, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags) { // TODO Auto-generated method stub return null; } @@ -401,7 +402,7 @@ public class MockUserVmManagerImpl implements UserVmManager, UserVmService, Mana } @Override - public Pair, Integer> searchForUserVMs(ListVMsCmd cmd) { + public Pair, Integer> searchForUserVMs(ListVMsCmd cmd) { // TODO Auto-generated method stub return null; } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index fff084e6336..3f452850cf1 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2510,3 +2510,218 @@ INSERT INTO `cloud`.`counter` (id, source, name, value,created) VALUES (3,'snmp' INSERT INTO `cloud`.`counter` (id, source, name, value,created) VALUES (100,'netscaler','Response Time - microseconds', 'RESPTIME', now()); SET foreign_key_checks = 1; + + +--- DB views for list api --- +DROP VIEW IF EXISTS `cloud`.`user_vm_view`; +CREATE VIEW `cloud`.`user_vm_view` AS +select +vm_instance.id id, +vm_instance.name name, +user_vm.display_name display_name, +user_vm.user_data user_data, +account.id account_id, +account.uuid account_uuid, +account.account_name account_name, +account.type account_type, +domain.id domain_id, +domain.uuid domain_uuid, +domain.name domain_name, +domain.path domain_path, +projects.id project_id, +projects.uuid project_uuid, +projects.name project_name, +instance_group.id instance_group_id, +instance_group.uuid instance_group_uuid, +instance_group.name instance_group_name, +vm_instance.uuid uuid, +vm_instance.last_host_id last_host_id, +vm_instance.vm_type type, +vm_instance.vnc_password vnc_password, +vm_instance.limit_cpu_use limit_cpu_use, +vm_instance.created created, +vm_instance.state state, +vm_instance.removed removed, +vm_instance.ha_enabled ha_enabled, +vm_instance.hypervisor_type hypervisor_type, +vm_instance.instance_name instance_name, +vm_instance.guest_os_id guest_os_id, +guest_os.uuid guest_os_uuid, +vm_instance.pod_id pod_id, +host_pod_ref.uuid pod_uuid, +vm_instance.private_ip_address private_ip_address, +vm_instance.private_mac_address private_mac_address, +vm_instance.vm_type vm_type, +data_center.id data_center_id, +data_center.uuid data_center_uuid, +data_center.name data_center_name, +data_center.is_security_group_enabled security_group_enabled, +host.id host_id, +host.uuid host_uuid, +host.name host_name, +vm_template.id template_id, +vm_template.uuid template_uuid, +vm_template.name template_name, +vm_template.display_text template_display_text, +vm_template.enable_password password_enabled, +iso.id iso_id, +iso.uuid iso_uuid, +iso.name iso_name, +iso.display_text iso_display_text, +service_offering.id service_offering_id, +disk_offering.uuid service_offering_uuid, +service_offering.cpu cpu, +service_offering.speed speed, +service_offering.ram_size ram_size, +disk_offering.name service_offering_name, +storage_pool.id pool_id, +storage_pool.uuid pool_uuid, +storage_pool.pool_type pool_type, +volumes.id volume_id, +volumes.uuid volume_uuid, +volumes.device_id volume_device_id, +volumes.volume_type volume_type, +security_group.id security_group_id, +security_group.uuid security_group_uuid, +security_group.name security_group_name, +security_group.description security_group_description, +nics.id nic_id, +nics.uuid nic_uuid, +nics.network_id network_id, +nics.ip4_address ip_address, +nics.default_nic is_default_nic, +nics.gateway gateway, +nics.netmask netmask, +nics.mac_address mac_address, +nics.broadcast_uri broadcast_uri, +nics.isolation_uri isolation_uri, +vpc.id vpc_id, +vpc.uuid vpc_uuid, +networks.uuid network_uuid, +networks.traffic_type traffic_type, +networks.guest_type guest_type, +user_ip_address.id public_ip_id, +user_ip_address.uuid public_ip_uuid, +user_ip_address.public_ip_address public_ip_address, +ssh_keypairs.keypair_name keypair_name, +resource_tags.id tag_id, +resource_tags.uuid tag_uuid, +resource_tags.key tag_key, +resource_tags.value tag_value, +resource_tags.domain_id tag_domain_id, +resource_tags.account_id tag_account_id, +resource_tags.resource_id tag_resource_id, +resource_tags.resource_uuid tag_resource_uuid, +resource_tags.resource_type tag_resource_type, +resource_tags.customer tag_customer, +async_job.id job_id, +async_job.uuid job_uuid, +async_job.job_status job_status, +async_job.account_id job_account_id +from user_vm +inner join vm_instance on vm_instance.id = user_vm.id and vm_instance.removed is NULL +inner join account on vm_instance.account_id=account.id +inner join domain on vm_instance.domain_id=domain.id +left join guest_os on vm_instance.guest_os_id = guest_os.id +left join host_pod_ref on vm_instance.pod_id = host_pod_ref.id +left join projects on projects.project_account_id = account.id +left join instance_group_vm_map on vm_instance.id=instance_group_vm_map.instance_id +left join instance_group on instance_group_vm_map.group_id=instance_group.id +left join data_center on vm_instance.data_center_id=data_center.id +left join host on vm_instance.host_id=host.id +left join vm_template on vm_instance.vm_template_id=vm_template.id +left join vm_template iso on iso.id=user_vm.iso_id +left join service_offering on vm_instance.service_offering_id=service_offering.id +left join disk_offering on vm_instance.service_offering_id=disk_offering.id +left join volumes on vm_instance.id=volumes.instance_id +left join storage_pool on volumes.pool_id=storage_pool.id +left join security_group_vm_map on vm_instance.id=security_group_vm_map.instance_id +left join security_group on security_group_vm_map.security_group_id=security_group.id +left join nics on vm_instance.id=nics.instance_id +left join networks on nics.network_id=networks.id +left join vpc on networks.vpc_id = vpc.id +left join user_ip_address on user_ip_address.vm_id=vm_instance.id +left join user_vm_details on user_vm_details.vm_id=vm_instance.id and user_vm_details.name = "SSH.PublicKey" +left join ssh_keypairs on ssh_keypairs.public_key = user_vm_details.value +left join resource_tags on resource_tags.resource_id = vm_instance.id and resource_tags.resource_type = "UserVm" +left join async_job on async_job.instance_id = vm_instance.id and async_job.instance_type = "VirtualMachine" and async_job.job_status = 0; + +DROP VIEW IF EXISTS `cloud`.`domain_router_view`; +CREATE VIEW domain_router_view AS +select +vm_instance.id id, +vm_instance.name name, +account.id account_id, +account.uuid account_uuid, +account.account_name account_name, +account.type account_type, +domain.id domain_id, +domain.uuid domain_uuid, +domain.name domain_name, +domain.path domain_path, +projects.id project_id, +projects.uuid project_uuid, +projects.name project_name, +vm_instance.uuid uuid, +vm_instance.created created, +vm_instance.state state, +vm_instance.removed removed, +vm_instance.pod_id pod_id, +vm_instance.instance_name instance_name, +host_pod_ref.uuid pod_uuid, +data_center.id data_center_id, +data_center.uuid data_center_uuid, +data_center.name data_center_name, +data_center.dns1 dns1, +data_center.dns2 dns2, +host.id host_id, +host.uuid host_uuid, +host.name host_name, +vm_template.id template_id, +vm_template.uuid template_uuid, +service_offering.id service_offering_id, +disk_offering.uuid service_offering_uuid, +disk_offering.name service_offering_name, +nics.id nic_id, +nics.uuid nic_uuid, +nics.network_id network_id, +nics.ip4_address ip_address, +nics.default_nic is_default_nic, +nics.gateway gateway, +nics.netmask netmask, +nics.mac_address mac_address, +nics.broadcast_uri broadcast_uri, +nics.isolation_uri isolation_uri, +vpc.id vpc_id, +vpc.uuid vpc_uuid, +networks.uuid network_uuid, +networks.name network_name, +networks.network_domain network_domain, +networks.traffic_type traffic_type, +networks.guest_type guest_type, +async_job.id job_id, +async_job.uuid job_uuid, +async_job.job_status job_status, +async_job.account_id job_account_id, +domain_router.template_version template_version, +domain_router.scripts_version scripts_version, +domain_router.is_redundant_router is_redundant_router, +domain_router.redundant_state redundant_state, +domain_router.stop_pending stop_pending +from domain_router +inner join vm_instance on vm_instance.id = domain_router.id +inner join account on vm_instance.account_id=account.id +inner join domain on vm_instance.domain_id=domain.id +left join host_pod_ref on vm_instance.pod_id = host_pod_ref.id +left join projects on projects.project_account_id = account.id +left join data_center on vm_instance.data_center_id=data_center.id +left join host on vm_instance.host_id=host.id +left join vm_template on vm_instance.vm_template_id=vm_template.id +left join service_offering on vm_instance.service_offering_id=service_offering.id +left join disk_offering on vm_instance.service_offering_id=disk_offering.id +left join volumes on vm_instance.id=volumes.instance_id +left join storage_pool on volumes.pool_id=storage_pool.id +left join nics on vm_instance.id=nics.instance_id +left join networks on nics.network_id=networks.id +left join vpc on networks.vpc_id = vpc.id +left join async_job on async_job.instance_id = vm_instance.id and async_job.instance_type = "DomainRouter" and async_job.job_status = 0; diff --git a/utils/src/com/cloud/utils/db/GenericDaoBase.java b/utils/src/com/cloud/utils/db/GenericDaoBase.java index 8d5cb96abc9..be0fe89f3a7 100755 --- a/utils/src/com/cloud/utils/db/GenericDaoBase.java +++ b/utils/src/com/cloud/utils/db/GenericDaoBase.java @@ -50,6 +50,7 @@ import javax.persistence.EmbeddedId; import javax.persistence.EntityExistsException; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.Table; import javax.persistence.TableGenerator; import net.sf.cglib.proxy.Callback; @@ -1653,6 +1654,13 @@ public abstract class GenericDaoBase implements Gene @DB(txn=false) protected void setField(final Object entity, final ResultSet rs, ResultSetMetaData meta, final int index) throws SQLException { Attribute attr = _allColumns.get(new Pair(meta.getTableName(index), meta.getColumnName(index))); + if ( attr == null ){ + // work around for mysql bug to return original table name instead of view name in db view case + Table tbl = entity.getClass().getSuperclass().getAnnotation(Table.class); + if ( tbl != null ){ + attr = _allColumns.get(new Pair(tbl.name(), meta.getColumnLabel(index))); + } + } assert (attr != null) : "How come I can't find " + meta.getCatalogName(index) + "." + meta.getColumnName(index); setField(entity, attr.field, rs, index); } @@ -1798,7 +1806,8 @@ public abstract class GenericDaoBase implements Gene } } - List groupByValues = addGroupBy(str, sc); + // we have to disable group by in getting count, since count for groupBy clause will be different. + //List groupByValues = addGroupBy(str, sc); final Transaction txn = Transaction.currentTxn(); final String sql = str.toString(); @@ -1816,11 +1825,13 @@ public abstract class GenericDaoBase implements Gene i = addJoinAttributes(i, pstmt, joins); } + /* if (groupByValues != null) { for (Object value : groupByValues) { pstmt.setObject(i++, value); } } + */ final ResultSet rs = pstmt.executeQuery(); while (rs.next()) {