Refactoring ListVMGroupsCmd and InstanceGroupResponse.

This commit is contained in:
Min Chen 2012-12-10 13:52:33 -08:00 committed by Rohit Yadav
parent 98033905e4
commit bba96254f5
16 changed files with 440 additions and 84 deletions

View File

@ -64,6 +64,8 @@ import org.apache.cloudstack.api.command.admin.systemvm.UpgradeSystemVMCmd;
import org.apache.cloudstack.api.command.admin.resource.UploadCustomCertificateCmd;
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
import org.apache.cloudstack.api.view.vo.EventJoinVO;
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
import com.cloud.async.AsyncJob;
import com.cloud.capacity.Capacity;
import com.cloud.configuration.Configuration;
@ -307,7 +309,7 @@ public interface ManagementService {
InstanceGroup updateVmGroup(UpdateVMGroupCmd cmd);
Pair<List<? extends InstanceGroup>, Integer> searchForVmGroups(ListVMGroupsCmd cmd);
Pair<List<InstanceGroupJoinVO>, Integer> searchForVmGroups(ListVMGroupsCmd cmd);
Map<String, Object> listCapabilities(ListCapabilitiesCmd cmd);

View File

@ -152,6 +152,7 @@ import com.cloud.uservm.UserVm;
import com.cloud.vm.InstanceGroup;
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
import org.apache.cloudstack.api.view.vo.EventJoinVO;
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
import org.apache.cloudstack.api.view.vo.UserVmJoinVO;
@ -214,6 +215,8 @@ public interface ResponseGenerator {
InstanceGroupResponse createInstanceGroupResponse(InstanceGroup group);
List<InstanceGroupResponse> createInstanceGroupResponse(InstanceGroupJoinVO... groups);
StoragePoolResponse createStoragePoolResponse(StoragePool pool);
ClusterResponse createClusterResponse(Cluster cluster, Boolean showCapacities);

View File

@ -26,8 +26,12 @@ 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.response.EventResponse;
import org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.view.vo.EventJoinVO;
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
import com.cloud.utils.Pair;
import com.cloud.vm.InstanceGroup;
@ -71,16 +75,10 @@ public class ListVMGroupsCmd extends BaseListProjectAndAccountResourcesCmd {
@Override
public void execute(){
Pair<List<? extends InstanceGroup>, Integer> groups = _mgr.searchForVmGroups(this);
Pair<List<InstanceGroupJoinVO>, Integer> groups = _mgr.searchForVmGroups(this);
ListResponse<InstanceGroupResponse> response = new ListResponse<InstanceGroupResponse>();
List<InstanceGroupResponse> responses = new ArrayList<InstanceGroupResponse>();
for (InstanceGroup group : groups.first()) {
InstanceGroupResponse groupResponse = _responseGenerator.createInstanceGroupResponse(group);
groupResponse.setObjectName("instancegroup");
responses.add(groupResponse);
}
response.setResponses(responses, groups.second());
List<InstanceGroupResponse> grpResponses = _responseGenerator.createInstanceGroupResponse(groups.first().toArray(new InstanceGroupJoinVO[groups.first().size()]));
response.setResponses(grpResponses, groups.second());
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

View File

@ -28,9 +28,9 @@ import com.google.gson.annotations.SerializedName;
@SuppressWarnings("unused")
@Entity(value = InstanceGroup.class)
public class InstanceGroupResponse extends BaseResponse implements ControlledEntityResponse{
public class InstanceGroupResponse extends BaseResponse implements ControlledViewEntityResponse{
@SerializedName(ApiConstants.ID) @Param(description="the id of the instance group")
private IdentityProxy id = new IdentityProxy("instance_group");
private String id;
@SerializedName(ApiConstants.NAME) @Param(description="the name of the instance group")
private String name;
@ -42,19 +42,19 @@ public class InstanceGroupResponse extends BaseResponse implements ControlledEnt
private String accountName;
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the group")
private IdentityProxy projectId = new IdentityProxy("projects");
private String projectId;
@SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the group")
private String projectName;
@SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain ID of the instance group")
private IdentityProxy domainId = new IdentityProxy("domain");
private String domainId;
@SerializedName(ApiConstants.DOMAIN) @Param(description="the domain name of the instance group")
private String domainName;
public void setId(Long id) {
this.id.setValue(id);
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
@ -71,8 +71,8 @@ public class InstanceGroupResponse extends BaseResponse implements ControlledEnt
}
@Override
public void setDomainId(Long domainId) {
this.domainId.setValue(domainId);
public void setDomainId(String domainId) {
this.domainId = domainId;
}
@Override
@ -81,8 +81,8 @@ public class InstanceGroupResponse extends BaseResponse implements ControlledEnt
}
@Override
public void setProjectId(Long projectId) {
this.projectId.setValue(projectId);
public void setProjectId(String projectId) {
this.projectId = projectId;
}
@Override

View File

@ -0,0 +1,215 @@
// 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 org.apache.cloudstack.api.view.vo;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name="instance_group_view")
public class InstanceGroupJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="uuid")
private String uuid;
@Column(name="name")
String name;
@Column(name=GenericDao.REMOVED_COLUMN)
private Date removed;
@Column(name=GenericDao.CREATED_COLUMN)
private Date created;
@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="project_id")
private long projectId;
@Column(name="project_uuid")
private String projectUuid;
@Column(name="project_name")
private String projectName;
public InstanceGroupJoinVO() {
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
@Override
public long getAccountId() {
return accountId;
}
public void setAccountId(long accountId) {
this.accountId = accountId;
}
@Override
public String getAccountUuid() {
return accountUuid;
}
public void setAccountUuid(String accountUuid) {
this.accountUuid = accountUuid;
}
@Override
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
@Override
public short getAccountType() {
return accountType;
}
public void setAccountType(short accountType) {
this.accountType = accountType;
}
@Override
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;
}
@Override
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
@Override
public String getDomainPath() {
return domainPath;
}
public void setDomainPath(String domainPath) {
this.domainPath = domainPath;
}
public long getProjectId() {
return projectId;
}
public void setProjectId(long projectId) {
this.projectId = projectId;
}
@Override
public String getProjectUuid() {
return projectUuid;
}
public void setProjectUuid(String projectUuid) {
this.projectUuid = projectUuid;
}
@Override
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getRemoved() {
return removed;
}
public void setRemoved(Date removed) {
this.removed = removed;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
}

View File

@ -25,11 +25,13 @@ import java.util.Set;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
import org.apache.cloudstack.api.view.vo.EventJoinVO;
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
import org.apache.cloudstack.api.view.vo.UserVmJoinVO;
@ -166,6 +168,7 @@ import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.InstanceGroup;
import com.cloud.vm.InstanceGroupVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.UserVmDetailVO;
@ -177,6 +180,7 @@ 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.InstanceGroupJoinDao;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.UserVmDetailsDao;
import com.cloud.vm.dao.UserVmJoinDao;
@ -251,6 +255,7 @@ public class ApiDBUtils {
private static CounterDao _counterDao;
private static ResourceTagJoinDao _tagJoinDao;
private static EventJoinDao _eventJoinDao;
private static InstanceGroupJoinDao _vmGroupJoinDao;
static {
_ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name);
@ -983,4 +988,12 @@ public class ApiDBUtils {
public static EventJoinVO newEventView(Event e){
return _eventJoinDao.newEventView(e);
}
public static InstanceGroupResponse newInstanceGroupResponse(InstanceGroupJoinVO ve) {
return _vmGroupJoinDao.newInstanceGroupResponse(ve);
}
public static InstanceGroupJoinVO newInstanceGroupView(InstanceGroup e){
return _vmGroupJoinDao.newInstanceGroupView(e);
}
}

View File

@ -115,6 +115,7 @@ import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
import org.apache.cloudstack.api.view.vo.ControlledViewEntity;
import org.apache.cloudstack.api.view.vo.EventJoinVO;
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
import org.apache.cloudstack.api.view.vo.UserVmJoinVO;
@ -1188,15 +1189,20 @@ public class ApiResponseHelper implements ResponseGenerator {
@Override
public InstanceGroupResponse createInstanceGroupResponse(InstanceGroup group) {
InstanceGroupResponse groupResponse = new InstanceGroupResponse();
groupResponse.setId(group.getId());
groupResponse.setName(group.getName());
groupResponse.setCreated(group.getCreated());
InstanceGroupJoinVO vgroup = ApiDBUtils.newInstanceGroupView(group);
return ApiDBUtils.newInstanceGroupResponse(vgroup);
populateOwner(groupResponse, group);
}
groupResponse.setObjectName("instancegroup");
return groupResponse;
@Override
public List<InstanceGroupResponse> createInstanceGroupResponse(InstanceGroupJoinVO... groups) {
List<InstanceGroupResponse> respList = new ArrayList<InstanceGroupResponse>();
for (InstanceGroupJoinVO vt : groups){
respList.add(ApiDBUtils.newInstanceGroupResponse(vt));
}
return respList;
}
@Override

View File

@ -52,6 +52,7 @@ import javax.servlet.http.HttpSession;
import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.ConnectionClosedException;
import org.apache.http.HttpException;
@ -443,7 +444,8 @@ public class ApiServer implements HttpRequestHandler {
if (cmdObj instanceof BaseListCmd && !(cmdObj instanceof ListVMsCmd) && !(cmdObj instanceof ListRoutersCmd)
&& !(cmdObj instanceof ListSecurityGroupsCmd)
&& !(cmdObj instanceof ListTagsCmd)
&& !(cmdObj instanceof ListEventsCmd)) {
&& !(cmdObj instanceof ListEventsCmd)
&& !(cmdObj instanceof ListVMGroupsCmd)) {
buildAsyncListResponse((BaseListCmd) cmdObj, caller);
}

View File

@ -112,7 +112,6 @@ public class EventJoinDaoImpl extends GenericDaoBase<EventJoinVO, Long> implemen
@Override
public EventJoinVO newEventView(Event vr) {
List<EventJoinVO> uvList = new ArrayList<EventJoinVO>();
SearchCriteria<EventJoinVO> sc = vrIdSearch.create();
sc.setParameters("id", vr.getId());
List<EventJoinVO> vms = searchIncludingRemoved(sc, null, null, false);

View File

@ -162,16 +162,10 @@ public class SecurityGroupJoinDaoImpl extends GenericDaoBase<SecurityGroupJoinVO
@Override
public List<SecurityGroupJoinVO> newSecurityGroupView(SecurityGroup sg) {
List<SecurityGroupJoinVO> uvList = new ArrayList<SecurityGroupJoinVO>();
SearchCriteria<SecurityGroupJoinVO> sc = sgIdSearch.create();
sc.setParameters("id", sg.getId());
List<SecurityGroupJoinVO> sgs = searchIncludingRemoved(sc, null, null, false);
if (sgs != null) {
for (SecurityGroupJoinVO uvm : sgs) {
uvList.add(uvm);
}
}
return uvList;
return searchIncludingRemoved(sc, null, null, false);
}
@Override

View File

@ -100,6 +100,8 @@ import org.apache.cloudstack.api.command.admin.resource.UploadCustomCertificateC
import org.apache.cloudstack.api.response.ExtractResponse;
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
import org.apache.cloudstack.api.view.vo.EventJoinVO;
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
import com.cloud.async.AsyncJob;
import com.cloud.async.AsyncJobExecutor;
import com.cloud.async.AsyncJobManager;
@ -262,6 +264,7 @@ 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.InstanceGroupJoinDao;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.SecondaryStorageVmDao;
import com.cloud.vm.dao.UserVmDao;
@ -317,6 +320,7 @@ public class ManagementServerImpl implements ManagementServer {
private final AsyncJobManager _asyncMgr;
private final int _purgeDelay;
private final InstanceGroupDao _vmGroupDao;
private final InstanceGroupJoinDao _vmGroupJoinDao;
private final UploadMonitor _uploadMonitor;
private final UploadDao _uploadDao;
private final SSHKeyPairDao _sshKeyPairDao;
@ -393,6 +397,7 @@ public class ManagementServerImpl implements ManagementServer {
_guestOSCategoryDao = locator.getDao(GuestOSCategoryDao.class);
_poolDao = locator.getDao(StoragePoolDao.class);
_vmGroupDao = locator.getDao(InstanceGroupDao.class);
_vmGroupJoinDao = locator.getDao(InstanceGroupJoinDao.class);
_uploadDao = locator.getDao(UploadDao.class);
_configs = _configDao.getConfiguration();
_vmInstanceDao = locator.getDao(VMInstanceDao.class);
@ -3205,7 +3210,7 @@ public class ManagementServerImpl implements ManagementServer {
}
@Override
public Pair<List<? extends InstanceGroup>, Integer> searchForVmGroups(ListVMGroupsCmd cmd) {
public Pair<List<InstanceGroupJoinVO>, Integer> searchForVmGroups(ListVMGroupsCmd cmd) {
Long id = cmd.getId();
String name = cmd.getGroupName();
String keyword = cmd.getKeyword();
@ -3221,52 +3226,26 @@ public class ManagementServerImpl implements ManagementServer {
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
Filter searchFilter = new Filter(InstanceGroupVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
Filter searchFilter = new Filter(InstanceGroupJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder<InstanceGroupVO> sb = _vmGroupDao.createSearchBuilder();
SearchBuilder<InstanceGroupJoinVO> sb = _vmGroupJoinDao.createSearchBuilder();
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, 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
SearchBuilder<DomainVO> domainSearch = _domainDao.createSearchBuilder();
domainSearch.and("path", domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER);
}
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);
}
}
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
SearchCriteria<InstanceGroupVO> sc = sb.create();
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.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
} else {
sc.setParameters("domainId", domainId);
}
}
SearchCriteria<InstanceGroupJoinVO> sc = sb.create();
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (keyword != null) {
SearchCriteria<InstanceGroupVO> ssc = _vmGroupDao.createSearchCriteria();
SearchCriteria<InstanceGroupJoinVO> ssc = _vmGroupJoinDao.createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
}
if (id != null) {
sc.setParameters("id", id);
}
@ -3275,8 +3254,7 @@ public class ManagementServerImpl implements ManagementServer {
sc.setParameters("name", "%" + name + "%");
}
Pair<List<InstanceGroupVO>, Integer> result = _vmGroupDao.searchAndCount(sc, searchFilter);
return new Pair<List<? extends InstanceGroup>, Integer>(result.first(), result.second());
return _vmGroupJoinDao.searchAndCount(sc, searchFilter);
}
@Override

View File

@ -92,7 +92,6 @@ public class ResourceTagJoinDaoImpl extends GenericDaoBase<ResourceTagJoinVO, Lo
@Override
public ResourceTagJoinVO newResourceTagView(ResourceTag vr) {
List<ResourceTagJoinVO> uvList = new ArrayList<ResourceTagJoinVO>();
SearchCriteria<ResourceTagJoinVO> sc = vrIdSearch.create();
sc.setParameters("id", vr.getId());
List<ResourceTagJoinVO> vms = searchIncludingRemoved(sc, null, null, false);

View File

@ -194,17 +194,9 @@ public class DomainRouterJoinDaoImpl extends GenericDaoBase<DomainRouterJoinVO,
@Override
public List<DomainRouterJoinVO> newDomainRouterView(VirtualRouter vr) {
List<DomainRouterJoinVO> uvList = new ArrayList<DomainRouterJoinVO>();
SearchCriteria<DomainRouterJoinVO> sc = vrIdSearch.create();
sc.setParameters("id", vr.getId());
List<DomainRouterJoinVO> vms = searchIncludingRemoved(sc, null, null, false);
if (vms != null) {
for (DomainRouterJoinVO uvm : vms) {
uvList.add(uvm);
}
}
return uvList;
return searchIncludingRemoved(sc, null, null, false);
}
}

View File

@ -0,0 +1,35 @@
// 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 org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.InstanceGroup;
public interface InstanceGroupJoinDao extends GenericDao<InstanceGroupJoinVO, Long> {
InstanceGroupResponse newInstanceGroupResponse(InstanceGroupJoinVO group);
InstanceGroupJoinVO newInstanceGroupView(InstanceGroup group);
List<InstanceGroupJoinVO> searchByIds(Long... ids);
}

View File

@ -0,0 +1,96 @@
// 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 javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.api.ApiResponseHelper;
import org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.vm.InstanceGroup;
@Local(value={InstanceGroupJoinDao.class})
public class InstanceGroupJoinDaoImpl extends GenericDaoBase<InstanceGroupJoinVO, Long> implements InstanceGroupJoinDao {
public static final Logger s_logger = Logger.getLogger(InstanceGroupJoinDaoImpl.class);
private SearchBuilder<InstanceGroupJoinVO> vrSearch;
private SearchBuilder<InstanceGroupJoinVO> vrIdSearch;
protected InstanceGroupJoinDaoImpl() {
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 instance_group_view WHERE ";
}
@Override
public InstanceGroupResponse newInstanceGroupResponse(InstanceGroupJoinVO group) {
InstanceGroupResponse groupResponse = new InstanceGroupResponse();
groupResponse.setId(group.getUuid());
groupResponse.setName(group.getName());
groupResponse.setCreated(group.getCreated());
ApiResponseHelper.populateOwner(groupResponse, group);
groupResponse.setObjectName("instancegroup");
return groupResponse;
}
@Override
public InstanceGroupJoinVO newInstanceGroupView(InstanceGroup group) {
SearchCriteria<InstanceGroupJoinVO> sc = vrIdSearch.create();
sc.setParameters("id", group.getId());
List<InstanceGroupJoinVO> grps = searchIncludingRemoved(sc, null, null, false);
assert grps != null && grps.size() == 1 : "No vm group found for group id " + group.getId();
return grps.get(0);
}
@Override
public List<InstanceGroupJoinVO> searchByIds(Long... ids) {
SearchCriteria<InstanceGroupJoinVO> sc = vrSearch.create();
sc.setParameters("idIN", ids);
return searchIncludingRemoved(sc, null, null, false);
}
}

View File

@ -2835,3 +2835,27 @@ inner join domain on event.domain_id=domain.id
inner join user on event.user_id = user.id
left join projects on projects.project_account_id = event.account_id
left join event eve on event.start_id = eve.id;
DROP VIEW IF EXISTS `cloud`.`instance_group_view`;
CREATE VIEW instance_group_view AS
select
instance_group.id,
instance_group.uuid,
instance_group.name,
instance_group.removed,
instance_group.created,
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
from instance_group
inner join account on instance_group.account_id=account.id
inner join domain on account.domain_id=domain.id
left join projects on projects.project_account_id = instance_group.account_id;