Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 39179FD41 for ; Wed, 8 May 2013 20:48:02 +0000 (UTC) Received: (qmail 72428 invoked by uid 500); 8 May 2013 20:47:35 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 70970 invoked by uid 500); 8 May 2013 20:47:30 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 69772 invoked by uid 99); 8 May 2013 20:47:28 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 May 2013 20:47:28 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 66A78889F33; Wed, 8 May 2013 20:47:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: alena1108@apache.org To: commits@cloudstack.apache.org Date: Wed, 08 May 2013 20:47:48 -0000 Message-Id: <659abe9339b34c73af05ff3dcca0da5a@git.apache.org> In-Reply-To: <7a0950acb4dd4b0e93e0b027ce95ffe0@git.apache.org> References: <7a0950acb4dd4b0e93e0b027ce95ffe0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/90] [abbrv] [partial] Moved most of the VOs and DAOs from server package into engine-schema as well http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/DomainRouterDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/DomainRouterDao.java b/engine/schema/src/com/cloud/vm/dao/DomainRouterDao.java new file mode 100755 index 0000000..95d1ea6 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/DomainRouterDao.java @@ -0,0 +1,149 @@ +// 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.network.Network; +import com.cloud.network.router.VirtualRouter; +import com.cloud.network.router.VirtualRouter.Role; +import com.cloud.utils.db.GenericDao; +import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.VirtualMachine.State; + +/** + * + * DomainRouterDao implements + */ +public interface DomainRouterDao extends GenericDao { + /** + * gets the DomainRouterVO by user id and data center + * @Param dcId data center Id. + * @return list of DomainRouterVO + */ + public List listByDataCenter(long dcId); + + /** + * gets the DomainRouterVO by account id and data center + * @param account id of the user. + * @Param dcId data center Id. + * @return DomainRouterVO + */ + public List findBy(long accountId, long dcId); + + /** + * gets the DomainRouterVO by user id. + * @param userId id of the user. + * @Param dcId data center Id. + * @return list of DomainRouterVO + */ + public List listBy(long userId); + + /** + * list virtual machine routers by host id. pass in null to get all + * virtual machine routers. + * @param hostId id of the host. null if to get all. + * @return list of DomainRouterVO + */ + public List listByHostId(Long hostId); + public List listByLastHostId(Long hostId); + + /** + * list virtual machine routers by pod id. pass in null to get all + * virtual machine routers. + * @param podId id of the pod. null if to get all. + * @return list of DomainRouterVO + */ + public List listByPodId(Long podId); + + /** + * list virtual machine routers by pod id. pass in null to get all + * virtual machine routers. + * @param podId id of the pod. null if to get all. + * @param state state of the domain router. null if to get all. + * @return list of DomainRouterVO + */ + public List listByPodIdAndStates(Long podId, State... states); + + /** + * list virtual machine routers by host id. + * pass in null to get all + * virtual machine routers. + * @param hostId id of the host. null if to get all. + * @return list of DomainRouterVO + */ + public List listIsolatedByHostId(Long hostId); + + /** + * Find the list of domain routers for a domain + * @param id + * @return + */ + public List listByDomain(Long id); + + List findBy(long accountId, long dcId, Role role); + + List findByNetwork(long networkId); + + List listActive(long networkId); + + /** + * List domain routers by state and network type which reside on Host managed by the specified management server + * @return + */ + List listByStateAndNetworkType(State state, Network.GuestType type, long mgmtSrvrId); + + List findByNetworkOutsideThePod(long networkId, long podId, State state, Role role); + + List listByNetworkAndPodAndRole(long networkId, long podId, Role role); + + List listByNetworkAndRole(long networkId, Role role); + + List listByElementId(long elementId); + + /** + * Persists the domain router instance + creates the reference to the guest network (if not null) + * @param guestNetworks TODO + * @return + */ + DomainRouterVO persist(DomainRouterVO router, List guestNetworks); + + /** + * @param routerId + * @return + */ + List getRouterNetworks(long routerId); + + /** + * @param vpcId + * @return + */ + List listByVpcId(long vpcId); + + /** + * @param routerId + * @param guestNetwork + */ + void addRouterToGuestNetwork(VirtualRouter router, Network guestNetwork); + + /** + * @param routerId + * @param guestNetworkId + */ + void removeRouterFromGuestNetwork(long routerId, long guestNetworkId); + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/DomainRouterDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/DomainRouterDaoImpl.java new file mode 100755 index 0000000..391fa58 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -0,0 +1,358 @@ +// 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.annotation.PostConstruct; +import javax.ejb.Local; +import javax.inject.Inject; + +import org.springframework.stereotype.Component; + +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; +import com.cloud.host.dao.HostDaoImpl; +import com.cloud.network.Network; +import com.cloud.network.dao.RouterNetworkDao; +import com.cloud.network.dao.RouterNetworkDaoImpl; +import com.cloud.network.dao.RouterNetworkVO; +import com.cloud.network.router.VirtualRouter; +import com.cloud.network.router.VirtualRouter.Role; +import com.cloud.offering.NetworkOffering; +import com.cloud.offerings.dao.NetworkOfferingDao; +import com.cloud.offerings.dao.NetworkOfferingDaoImpl; +import com.cloud.user.UserStatisticsVO; +import com.cloud.user.dao.UserStatisticsDao; +import com.cloud.user.dao.UserStatisticsDaoImpl; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.JoinBuilder.JoinType; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.UpdateBuilder; +import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.State; + +@Component +@Local(value = { DomainRouterDao.class }) +@DB +public class DomainRouterDaoImpl extends GenericDaoBase implements DomainRouterDao { + + protected SearchBuilder AllFieldsSearch; + protected SearchBuilder IdNetworkIdStatesSearch; + protected SearchBuilder HostUpSearch; + protected SearchBuilder StateNetworkTypeSearch; + protected SearchBuilder OutsidePodSearch; + @Inject HostDao _hostsDao; + @Inject RouterNetworkDao _routerNetworkDao; + @Inject UserStatisticsDao _userStatsDao; + @Inject NetworkOfferingDao _offDao; + protected SearchBuilder VpcSearch; + + public DomainRouterDaoImpl() { + } + + @PostConstruct + protected void init() { + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), Op.EQ); + AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), Op.EQ); + AllFieldsSearch.and("role", AllFieldsSearch.entity().getRole(), Op.EQ); + AllFieldsSearch.and("domainId", AllFieldsSearch.entity().getDomainId(), Op.EQ); + AllFieldsSearch.and("host", AllFieldsSearch.entity().getHostId(), Op.EQ); + AllFieldsSearch.and("lastHost", AllFieldsSearch.entity().getLastHostId(), Op.EQ); + AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ); + AllFieldsSearch.and("states", AllFieldsSearch.entity().getState(), Op.IN); + SearchBuilder joinRouterNetwork = _routerNetworkDao.createSearchBuilder(); + joinRouterNetwork.and("networkId", joinRouterNetwork.entity().getNetworkId(), Op.EQ); + AllFieldsSearch.join("networkRouter", joinRouterNetwork, joinRouterNetwork.entity().getRouterId(), AllFieldsSearch.entity().getId(), JoinType.INNER); + AllFieldsSearch.and("podId", AllFieldsSearch.entity().getPodIdToDeployIn(), Op.EQ); + AllFieldsSearch.and("elementId", AllFieldsSearch.entity().getElementId(), Op.EQ); + AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ); + AllFieldsSearch.done(); + + VpcSearch = createSearchBuilder(); + VpcSearch.and("role", VpcSearch.entity().getRole(), Op.EQ); + VpcSearch.and("vpcId", VpcSearch.entity().getVpcId(), Op.EQ); + VpcSearch.done(); + + IdNetworkIdStatesSearch = createSearchBuilder(); + IdNetworkIdStatesSearch.and("id", IdNetworkIdStatesSearch.entity().getId(), Op.EQ); + SearchBuilder joinRouterNetwork1 = _routerNetworkDao.createSearchBuilder(); + joinRouterNetwork1.and("networkId", joinRouterNetwork1.entity().getNetworkId(), Op.EQ); + IdNetworkIdStatesSearch.join("networkRouter", joinRouterNetwork1, joinRouterNetwork1.entity().getRouterId(), IdNetworkIdStatesSearch.entity().getId(), JoinType.INNER); + IdNetworkIdStatesSearch.and("states", IdNetworkIdStatesSearch.entity().getState(), Op.IN); + IdNetworkIdStatesSearch.done(); + + HostUpSearch = createSearchBuilder(); + HostUpSearch.and("host", HostUpSearch.entity().getHostId(), Op.EQ); + HostUpSearch.and("states", HostUpSearch.entity().getState(), Op.NIN); + SearchBuilder joinRouterNetwork3 = _routerNetworkDao.createSearchBuilder(); + joinRouterNetwork3.and("networkId", joinRouterNetwork3.entity().getNetworkId(), Op.EQ); + joinRouterNetwork3.and("type", joinRouterNetwork3.entity().getGuestType(), Op.EQ); + HostUpSearch.join("networkRouter", joinRouterNetwork3, joinRouterNetwork3.entity().getRouterId(), HostUpSearch.entity().getId(), JoinType.INNER); + HostUpSearch.done(); + + StateNetworkTypeSearch = createSearchBuilder(); + StateNetworkTypeSearch.and("state", StateNetworkTypeSearch.entity().getState(), Op.EQ); + SearchBuilder joinRouterNetwork4 = _routerNetworkDao.createSearchBuilder(); + joinRouterNetwork4.and("networkId", joinRouterNetwork4.entity().getNetworkId(), Op.EQ); + joinRouterNetwork4.and("type", joinRouterNetwork4.entity().getGuestType(), Op.EQ); + StateNetworkTypeSearch.join("networkRouter", joinRouterNetwork4, joinRouterNetwork4.entity().getRouterId(), StateNetworkTypeSearch.entity().getId(), JoinType.INNER); + + SearchBuilder joinHost = _hostsDao.createSearchBuilder(); + joinHost.and("mgmtServerId", joinHost.entity().getManagementServerId(), Op.EQ); + StateNetworkTypeSearch.join("host", joinHost, joinHost.entity().getId(), + StateNetworkTypeSearch.entity().getHostId(), JoinType.INNER); + StateNetworkTypeSearch.done(); + + + OutsidePodSearch = createSearchBuilder(); + SearchBuilder joinRouterNetwork2 = _routerNetworkDao.createSearchBuilder(); + joinRouterNetwork2.and("networkId", joinRouterNetwork2.entity().getNetworkId(), Op.EQ); + OutsidePodSearch.join("networkRouter", joinRouterNetwork2, joinRouterNetwork2.entity().getRouterId(), + OutsidePodSearch.entity().getId(), JoinType.INNER); + OutsidePodSearch.and("podId", OutsidePodSearch.entity().getPodIdToDeployIn(), Op.NEQ); + OutsidePodSearch.and("state", OutsidePodSearch.entity().getState(), Op.EQ); + OutsidePodSearch.and("role", OutsidePodSearch.entity().getRole(), Op.EQ); + OutsidePodSearch.done(); + + } + + @Override + public boolean remove(Long id) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + DomainRouterVO router = createForUpdate(); + router.setPublicIpAddress(null); + UpdateBuilder ub = getUpdateBuilder(router); + ub.set(router, "state", State.Destroyed); + update(id, ub, router); + + boolean result = super.remove(id); + txn.commit(); + return result; + } + + @Override + public List listByDataCenter(long dcId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("dc", dcId); + return listBy(sc); + } + + @Override + public List findBy(long accountId, long dcId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("account", accountId); + sc.setParameters("dc", dcId); + sc.setParameters("role", Role.VIRTUAL_ROUTER); + return listBy(sc); + } + + @Override + public List findBy(long accountId, long dcId, Role role) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("account", accountId); + sc.setParameters("dc", dcId); + sc.setParameters("role", role); + return listBy(sc); + } + + + @Override + public List listBy(long accountId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("account", accountId); + return listBy(sc); + } + + @Override + public List listByHostId(Long hostId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("host", hostId); + return listBy(sc); + } + + @Override + public List listByPodId(Long podId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("podId", podId); + return listBy(sc); + } + + @Override + public List listByPodIdAndStates(Long podId, State... states) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("podId", podId); + sc.setParameters("states", (Object[]) states); + return listBy(sc); + } + + @Override + public List listIsolatedByHostId(Long hostId) { + SearchCriteria sc = HostUpSearch.create(); + if (hostId != null) { + sc.setParameters("host", hostId); + } + sc.setJoinParameters("networkRouter", "type", Network.GuestType.Isolated); + return listBy(sc); + } + + @Override + public List listByDomain(Long domainId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("domainId", domainId); + return listBy(sc); + } + + @Override + public List findByNetwork(long networkId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setJoinParameters("networkRouter", "networkId", networkId); + return listBy(sc); + } + + @Override + public List listByLastHostId(Long hostId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("lastHost", hostId); + sc.setParameters("state", State.Stopped); + return listBy(sc); + } + + @Override + public List listActive(long networkId) { + SearchCriteria sc = IdNetworkIdStatesSearch.create(); + sc.setJoinParameters("networkRouter", "networkId", networkId); + sc.setParameters("states", State.Running, State.Migrating, State.Stopping, State.Starting); + return listBy(sc); + } + + @Override + public List listByStateAndNetworkType(State state, Network.GuestType type, long mgmtSrvrId) { + SearchCriteria sc = StateNetworkTypeSearch.create(); + sc.setParameters("state", state); + sc.setJoinParameters("networkRouter", "type", type); + sc.setJoinParameters("host", "mgmtServerId", mgmtSrvrId); + return listBy(sc); + } + + @Override + public List findByNetworkOutsideThePod(long networkId, long podId, State state, Role role) { + SearchCriteria sc = OutsidePodSearch.create(); + sc.setJoinParameters("networkRouter", "networkId", networkId); + sc.setParameters("podId", podId); + sc.setParameters("state", state); + sc.setParameters("role", role); + return listBy(sc); + } + + @Override + public List listByNetworkAndPodAndRole(long networkId, long podId, Role role) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setJoinParameters("networkRouter", "networkId", networkId); + sc.setParameters("podId", podId); + sc.setParameters("role", role); + return listBy(sc); + } + + @Override + public List listByNetworkAndRole(long networkId, Role role) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setJoinParameters("networkRouter", "networkId", networkId); + sc.setParameters("role", role); + return listBy(sc); + } + + @Override + public List listByElementId(long elementId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("elementId", elementId); + return listBy(sc); + } + + @Override + @DB + public DomainRouterVO persist(DomainRouterVO router, List guestNetworks) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + + // 1) create network + DomainRouterVO newRouter = super.persist(router); + + if (guestNetworks != null && !guestNetworks.isEmpty()) { + // 2) add router to the network + for (Network guestNetwork : guestNetworks) { + addRouterToGuestNetwork(router, guestNetwork); + } + } + + txn.commit(); + return newRouter; + } + + @Override + @DB + public void addRouterToGuestNetwork(VirtualRouter router, Network guestNetwork) { + if (_routerNetworkDao.findByRouterAndNetwork(router.getId(), guestNetwork.getId()) == null) { + NetworkOffering off = _offDao.findById(guestNetwork.getNetworkOfferingId()); + if (!(off.getName().equalsIgnoreCase(NetworkOffering.SystemPrivateGatewayNetworkOffering))) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + //1) add router to network + RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType()); + _routerNetworkDao.persist(routerNtwkMap); + //2) create user stats entry for the network + UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), + guestNetwork.getId(), null, router.getId(), router.getType().toString()); + if (stats == null) { + stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterId(), null, router.getId(), + router.getType().toString(), guestNetwork.getId()); + _userStatsDao.persist(stats); + } + txn.commit(); + } + } + } + + @Override + public void removeRouterFromGuestNetwork(long routerId, long guestNetworkId) { + RouterNetworkVO routerNtwkMap = _routerNetworkDao.findByRouterAndNetwork(routerId, guestNetworkId); + if (routerNtwkMap != null) { + _routerNetworkDao.remove(routerNtwkMap.getId()); + } + } + + @Override + public List getRouterNetworks(long routerId) { + return _routerNetworkDao.getRouterNetworks(routerId); + } + + @Override + public List listByVpcId(long vpcId) { + SearchCriteria sc = VpcSearch.create(); + sc.setParameters("vpcId", vpcId); + sc.setParameters("role", Role.VIRTUAL_ROUTER); + return listBy(sc); + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/InstanceGroupDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/InstanceGroupDao.java b/engine/schema/src/com/cloud/vm/dao/InstanceGroupDao.java new file mode 100644 index 0000000..681a893 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/InstanceGroupDao.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.utils.db.GenericDao; +import com.cloud.vm.InstanceGroupVO; + +public interface InstanceGroupDao extends GenericDao{ + List listByAccountId(long id); + boolean isNameInUse(Long accountId, String name); + InstanceGroupVO findByAccountAndName(Long accountId, String name); + + /** + * Updates name for the vm + * @param id - group id + * @param name + */ + void updateVmGroup(long id, String name); + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/InstanceGroupDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/InstanceGroupDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/InstanceGroupDaoImpl.java new file mode 100644 index 0000000..0ce127e --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/InstanceGroupDaoImpl.java @@ -0,0 +1,80 @@ +// 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.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.vm.InstanceGroupVO; + +@Component +@Local (value={InstanceGroupDao.class}) +public class InstanceGroupDaoImpl extends GenericDaoBase implements InstanceGroupDao{ + private SearchBuilder AccountIdNameSearch; + protected final SearchBuilder AccountSearch; + + protected InstanceGroupDaoImpl() { + AccountSearch = createSearchBuilder(); + AccountSearch.and("account", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + AccountSearch.done(); + + AccountIdNameSearch = createSearchBuilder(); + AccountIdNameSearch.and("accountId", AccountIdNameSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + AccountIdNameSearch.and("groupName", AccountIdNameSearch.entity().getName(), SearchCriteria.Op.EQ); + AccountIdNameSearch.done(); + + } + + @Override + public boolean isNameInUse(Long accountId, String name) { + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("name", SearchCriteria.Op.EQ, name); + if (accountId != null) { + sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); + } + List vmGroups = listBy(sc); + return ((vmGroups != null) && !vmGroups.isEmpty()); + } + + @Override + public InstanceGroupVO findByAccountAndName(Long accountId, String name) { + SearchCriteria sc = AccountIdNameSearch.create(); + sc.setParameters("accountId", accountId); + sc.setParameters("groupName", name); + return findOneBy(sc); + } + + @Override + public void updateVmGroup(long id, String name) { + InstanceGroupVO vo = createForUpdate(); + vo.setName(name); + update(id, vo); + } + + @Override + public List listByAccountId(long id) { + SearchCriteria sc = AccountSearch.create(); + sc.setParameters("account", id); + return listBy(sc); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/InstanceGroupVMMapDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/InstanceGroupVMMapDao.java b/engine/schema/src/com/cloud/vm/dao/InstanceGroupVMMapDao.java new file mode 100644 index 0000000..28a0f53 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/InstanceGroupVMMapDao.java @@ -0,0 +1,28 @@ +// 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.utils.db.GenericDao; +import com.cloud.vm.InstanceGroupVMMapVO; + +public interface InstanceGroupVMMapDao extends GenericDao{ + List listByInstanceId(long instanceId); + List listByGroupId(long groupId); + InstanceGroupVMMapVO findByVmIdGroupId(long instanceId, long groupId); +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/InstanceGroupVMMapDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/InstanceGroupVMMapDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/InstanceGroupVMMapDaoImpl.java new file mode 100644 index 0000000..a33cc84 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/InstanceGroupVMMapDaoImpl.java @@ -0,0 +1,75 @@ +// 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.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.vm.InstanceGroupVMMapVO; + +@Component +@Local(value={InstanceGroupVMMapDao.class}) +public class InstanceGroupVMMapDaoImpl extends GenericDaoBase implements InstanceGroupVMMapDao{ + + private SearchBuilder ListByVmId; + private SearchBuilder ListByGroupId; + private SearchBuilder ListByVmIdGroupId; + + protected InstanceGroupVMMapDaoImpl() { + ListByVmId = createSearchBuilder(); + ListByVmId.and("instanceId", ListByVmId.entity().getInstanceId(), SearchCriteria.Op.EQ); + ListByVmId.done(); + + ListByGroupId = createSearchBuilder(); + ListByGroupId.and("groupId", ListByGroupId.entity().getGroupId(), SearchCriteria.Op.EQ); + ListByGroupId.done(); + + ListByVmIdGroupId = createSearchBuilder(); + ListByVmIdGroupId.and("instanceId", ListByVmIdGroupId.entity().getInstanceId(), SearchCriteria.Op.EQ); + ListByVmIdGroupId.and("groupId", ListByVmIdGroupId.entity().getGroupId(), SearchCriteria.Op.EQ); + ListByVmIdGroupId.done(); + } + + @Override + public List listByInstanceId(long vmId) { + SearchCriteria sc = ListByVmId.create(); + sc.setParameters("instanceId", vmId); + return listBy(sc); + } + + @Override + public List listByGroupId(long groupId) { + SearchCriteria sc = ListByGroupId.create(); + sc.setParameters("groupId", groupId); + return listBy(sc); + } + + @Override + public InstanceGroupVMMapVO findByVmIdGroupId(long instanceId, long groupId) { + SearchCriteria sc = ListByVmIdGroupId.create(); + sc.setParameters("groupId", groupId); + sc.setParameters("instanceId", instanceId); + return findOneBy(sc); + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/NicDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/NicDao.java b/engine/schema/src/com/cloud/vm/dao/NicDao.java new file mode 100644 index 0000000..67c1e07 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/NicDao.java @@ -0,0 +1,69 @@ +// 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.utils.db.GenericDao; +import com.cloud.vm.NicVO; +import com.cloud.vm.VirtualMachine; + +public interface NicDao extends GenericDao { + List listByVmId(long instanceId); + + List listIpAddressInNetwork(long networkConfigId); + List listByVmIdIncludingRemoved(long instanceId); + + List listByNetworkId(long networkId); + + NicVO findByInstanceIdAndNetworkId(long networkId, long instanceId); + + NicVO findByInstanceIdAndNetworkIdIncludingRemoved(long networkId, long instanceId); + + NicVO findByNetworkIdTypeAndGateway(long networkId, VirtualMachine.Type vmType, String gateway); + + void removeNicsForInstance(long instanceId); + + NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType); + + NicVO findByIp4AddressAndNetworkId(String ip4Address, long networkId); + + NicVO findDefaultNicForVM(long instanceId); + + /** + * @param networkId + * @param instanceId + * @return + */ + NicVO findNonReleasedByInstanceIdAndNetworkId(long networkId, long instanceId); + + String getIpAddress(long networkId, long instanceId); + + int countNics(long instanceId); + + NicVO findByNetworkIdInstanceIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri); + + NicVO findByIp4AddressAndNetworkIdAndInstanceId(long networkId, long instanceId, String ip4Address); + + List listByVmIdAndNicId(Long vmId, Long nicId); + + NicVO findByIp4AddressAndVmId(String ip4Address, long instance); + + List listPlaceholderNicsByNetworkId(long networkId); + + List listPlaceholderNicsByNetworkIdAndVmType(long networkId, VirtualMachine.Type vmType); +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java new file mode 100644 index 0000000..c70d194 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java @@ -0,0 +1,241 @@ +// 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.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Func; +import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.vm.Nic; +import com.cloud.vm.Nic.State; +import com.cloud.vm.NicVO; +import com.cloud.vm.VirtualMachine; + +@Component +@Local(value=NicDao.class) +public class NicDaoImpl extends GenericDaoBase implements NicDao { + private final SearchBuilder AllFieldsSearch; + private final GenericSearchBuilder IpSearch; + private final SearchBuilder NonReleasedSearch; + final GenericSearchBuilder CountBy; + + + public NicDaoImpl() { + super(); + + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), Op.EQ); + AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ); + AllFieldsSearch.and("gateway", AllFieldsSearch.entity().getGateway(), Op.EQ); + AllFieldsSearch.and("vmType", AllFieldsSearch.entity().getVmType(), Op.EQ); + AllFieldsSearch.and("address", AllFieldsSearch.entity().getIp4Address(), Op.EQ); + AllFieldsSearch.and("isDefault", AllFieldsSearch.entity().isDefaultNic(), Op.EQ); + AllFieldsSearch.and("broadcastUri", AllFieldsSearch.entity().getBroadcastUri(), Op.EQ); + AllFieldsSearch.and("secondaryip", AllFieldsSearch.entity().getSecondaryIp(), Op.EQ); + AllFieldsSearch.and("nicid", AllFieldsSearch.entity().getId(), Op.EQ); + AllFieldsSearch.done(); + + IpSearch = createSearchBuilder(String.class); + IpSearch.select(null, Func.DISTINCT, IpSearch.entity().getIp4Address()); + IpSearch.and("network", IpSearch.entity().getNetworkId(), Op.EQ); + IpSearch.and("address", IpSearch.entity().getIp4Address(), Op.NNULL); + IpSearch.done(); + + NonReleasedSearch = createSearchBuilder(); + NonReleasedSearch.and("instance", NonReleasedSearch.entity().getInstanceId(), Op.EQ); + NonReleasedSearch.and("network", NonReleasedSearch.entity().getNetworkId(), Op.EQ); + NonReleasedSearch.and("state", NonReleasedSearch.entity().getState(), Op.NOTIN); + NonReleasedSearch.done(); + + CountBy = createSearchBuilder(Integer.class); + CountBy.select(null, Func.COUNT, CountBy.entity().getId()); + CountBy.and("vmId", CountBy.entity().getInstanceId(), Op.EQ); + CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL); + CountBy.done(); + } + + @Override + public void removeNicsForInstance(long instanceId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instance", instanceId); + remove(sc); + } + + @Override + public List listByVmId(long instanceId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instance", instanceId); + return listBy(sc); + } + + @Override + public List listByVmIdIncludingRemoved(long instanceId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instance", instanceId); + return listIncludingRemovedBy(sc); + } + + + @Override + public List listIpAddressInNetwork(long networkId) { + SearchCriteria sc = IpSearch.create(); + sc.setParameters("network", networkId); + return customSearch(sc, null); + } + + @Override + public List listByNetworkId(long networkId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + return listBy(sc); + } + + @Override + public NicVO findByInstanceIdAndNetworkId(long networkId, long instanceId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("instance", instanceId); + return findOneBy(sc); + } + + @Override + public NicVO findByInstanceIdAndNetworkIdIncludingRemoved(long networkId, long instanceId) { + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("networkId", SearchCriteria.Op.EQ, networkId); + sc.addAnd("instanceId", SearchCriteria.Op.EQ, instanceId); + return findOneIncludingRemovedBy(sc); + } + + @Override + public NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("vmType", vmType); + return findOneBy(sc); + } + + @Override + public NicVO findByNetworkIdTypeAndGateway(long networkId, VirtualMachine.Type vmType, String gateway) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("vmType", vmType); + sc.setParameters("gateway", gateway); + return findOneBy(sc); + } + + @Override + public NicVO findByIp4AddressAndNetworkId(String ip4Address, long networkId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("address", ip4Address); + sc.setParameters("network", networkId); + return findOneBy(sc); + } + + @Override + public NicVO findDefaultNicForVM(long instanceId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instance", instanceId); + sc.setParameters("isDefault", 1); + return findOneBy(sc); + } + + @Override + public NicVO findNonReleasedByInstanceIdAndNetworkId(long networkId, long instanceId) { + SearchCriteria sc = NonReleasedSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("instance", instanceId); + sc.setParameters("state", State.Releasing, Nic.State.Deallocating); + return findOneBy(sc); + } + + @Override + public String getIpAddress(long networkId, long instanceId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("instance", instanceId); + return findOneBy(sc).getIp4Address(); + } + + @Override + public int countNics(long instanceId) { + SearchCriteria sc = CountBy.create(); + sc.setParameters("vmId", instanceId); + List results = customSearch(sc, null); + return results.get(0); + } + + + @Override + public NicVO findByNetworkIdInstanceIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("instance", instanceId); + sc.setParameters("broadcastUri", broadcastUri); + return findOneBy(sc); + } + + @Override + public NicVO findByIp4AddressAndNetworkIdAndInstanceId(long networkId, long instanceId, String ip4Address) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("instance", instanceId); + sc.setParameters("address", ip4Address); + return findOneBy(sc); + } + + @Override + public List listByVmIdAndNicId(Long vmId, Long nicId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instance", vmId); + sc.setParameters("nicid", nicId); + return listBy(sc); + } + + @Override + public NicVO findByIp4AddressAndVmId(String ip4Address, long instance) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("address", ip4Address); + sc.setParameters("instance", instance); + return findOneBy(sc); + } + + @Override + public List listPlaceholderNicsByNetworkId(long networkId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("strategy", Nic.ReservationStrategy.PlaceHolder.toString()); + return listBy(sc); + } + + @Override + public List listPlaceholderNicsByNetworkIdAndVmType(long networkId, VirtualMachine.Type vmType) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("strategy", Nic.ReservationStrategy.PlaceHolder.toString()); + sc.setParameters("vmType", vmType); + return listBy(sc); + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDao.java b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDao.java new file mode 100644 index 0000000..da96df4 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDao.java @@ -0,0 +1,53 @@ +// 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.utils.db.GenericDao; + +public interface NicSecondaryIpDao extends GenericDao { + List listByVmId(long instanceId); + + List listSecondaryIpAddressInNetwork(long networkConfigId); + List listByNetworkId(long networkId); + + NicSecondaryIpVO findByInstanceIdAndNetworkId(long networkId, long instanceId); + + // void removeNicsForInstance(long instanceId); + // void removeSecondaryIpForNic(long nicId); + + NicSecondaryIpVO findByIp4AddressAndNetworkId(String ip4Address, long networkId); + + /** + * @param networkId + * @param instanceId + * @return + */ + + List getSecondaryIpAddressesForVm(long vmId); + + List listByNicId(long nicId); + + List listByNicIdAndVmid(long nicId, long vmId); + + NicSecondaryIpVO findByIp4AddressAndNicId(String ip4Address, long nicId); + + NicSecondaryIpVO findByIp4AddressAndNetworkIdAndInstanceId(long networkId, + Long vmId, String vmIp); + + List getSecondaryIpAddressesForNic(long nicId); +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java new file mode 100644 index 0000000..3befaf7 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java @@ -0,0 +1,138 @@ +// 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.ArrayList; +import java.util.List; + +import javax.ejb.Local; + +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Func; +import com.cloud.utils.db.SearchCriteria.Op; + +@Component +@Local(value=NicSecondaryIpDao.class) +public class NicSecondaryIpDaoImpl extends GenericDaoBase implements NicSecondaryIpDao { + private final SearchBuilder AllFieldsSearch; + private final GenericSearchBuilder IpSearch; + + protected NicSecondaryIpDaoImpl() { + super(); + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("instanceId", AllFieldsSearch.entity().getVmId(), Op.EQ); + AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ); + AllFieldsSearch.and("address", AllFieldsSearch.entity().getIp4Address(), Op.EQ); + AllFieldsSearch.and("nicId", AllFieldsSearch.entity().getNicId(), Op.EQ); + AllFieldsSearch.done(); + + IpSearch = createSearchBuilder(String.class); + IpSearch.select(null, Func.DISTINCT, IpSearch.entity().getIp4Address()); + IpSearch.and("network", IpSearch.entity().getNetworkId(), Op.EQ); + IpSearch.and("address", IpSearch.entity().getIp4Address(), Op.NNULL); + IpSearch.done(); + } + + @Override + public List listByVmId(long instanceId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instanceId", instanceId); + return listBy(sc); + } + + @Override + public List listByNicId(long nicId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("nicId", nicId); + return listBy(sc); + } + + @Override + public List listSecondaryIpAddressInNetwork(long networkId) { + SearchCriteria sc = IpSearch.create(); + sc.setParameters("network", networkId); + return customSearch(sc, null); + } + + @Override + public List listByNetworkId(long networkId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + return listBy(sc); + } + + @Override + public List listByNicIdAndVmid(long nicId, long vmId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("nicId", nicId); + sc.setParameters("instanceId", vmId); + return listBy(sc); + } + + @Override + public List getSecondaryIpAddressesForVm(long vmId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instanceId", vmId); + return listBy(sc); + } + + @Override + public List getSecondaryIpAddressesForNic(long nicId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("nicId", nicId); + List results = search(sc, null); + List ips = new ArrayList(results.size()); + for (NicSecondaryIpVO result : results) { + ips.add(result.getIp4Address()); + } + return ips; + } + + @Override + public NicSecondaryIpVO findByInstanceIdAndNetworkId(long networkId, long instanceId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public NicSecondaryIpVO findByIp4AddressAndNetworkId(String ip4Address, long networkId) { + // TODO Auto-generated method stub + return null; + } + @Override + public NicSecondaryIpVO findByIp4AddressAndNicId(String ip4Address, long nicId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("address", ip4Address); + sc.setParameters("nicId", nicId); + return findOneBy(sc); + } + + @Override + public NicSecondaryIpVO findByIp4AddressAndNetworkIdAndInstanceId( + long networkId, Long vmId, String vmIp) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("instanceId", vmId); + sc.setParameters("address", vmIp); + return findOneBy(sc); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpVO.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpVO.java b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpVO.java new file mode 100644 index 0000000..770e188 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpVO.java @@ -0,0 +1,160 @@ +// 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.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.utils.db.GenericDao; +import com.cloud.vm.NicSecondaryIp; + +@Entity +@Table(name = "nic_secondary_ips") +public class NicSecondaryIpVO implements NicSecondaryIp { + + public NicSecondaryIpVO(Long nicId, String ipaddr, Long vmId, + Long accountId, Long domainId, Long networkId) { + this.nicId = nicId; + this.vmId = vmId; + this.ip4Address = ipaddr; + this.accountId = accountId; + this.domainId = domainId; + this.networkId = networkId; + } + + protected NicSecondaryIpVO() { + } + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + long id; + + @Column(name = "nicId") + long nicId; + + @Column(name="domain_id", updatable=false) + long domainId; + + @Column(name="account_id", updatable=false) + private Long accountId; + + @Column(name = "ip4_address") + String ip4Address; + + @Column(name = "ip6_address") + String ip6Address; + + @Column(name = "network_id") + long networkId; + + @Column(name = GenericDao.CREATED_COLUMN) + Date created; + + @Column(name = "uuid") + String uuid = UUID.randomUUID().toString(); + + @Column(name = "vmId") + Long vmId; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getNicId() { + return nicId; + } + + public void setNicId(long nicId) { + this.nicId = nicId; + } + + public long getDomainId() { + return domainId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } + + public long getAccountId() { + return accountId; + } + + public void setAccountId(Long accountId) { + this.accountId = accountId; + } + + public String getIp4Address() { + return ip4Address; + } + + public void setIp4Address(String ip4Address) { + this.ip4Address = ip4Address; + } + + public String getIp6Address() { + return ip6Address; + } + + public void setIp6Address(String ip6Address) { + this.ip6Address = ip6Address; + } + + public long getNetworkId() { + return networkId; + } + + public void setNetworkId(long networkId) { + this.networkId = networkId; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public long getVmId() { + return vmId; + } + + public void setVmId(Long vmId) { + this.vmId = vmId; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/SecondaryStorageVmDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/SecondaryStorageVmDao.java b/engine/schema/src/com/cloud/vm/dao/SecondaryStorageVmDao.java new file mode 100644 index 0000000..857b637 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/SecondaryStorageVmDao.java @@ -0,0 +1,42 @@ +// 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.utils.db.GenericDao; +import com.cloud.vm.SecondaryStorageVm; +import com.cloud.vm.SecondaryStorageVmVO; +import com.cloud.vm.VirtualMachine.State; + +public interface SecondaryStorageVmDao extends GenericDao { + + public List getSecStorageVmListInStates(SecondaryStorageVm.Role role, long dataCenterId, State... states); + public List getSecStorageVmListInStates(SecondaryStorageVm.Role role, State... states); + + public List listByHostId(SecondaryStorageVm.Role role, long hostId); + public List listByLastHostId(SecondaryStorageVm.Role role, long hostId); + + public List listUpByHostId(SecondaryStorageVm.Role role, long hostId); + + public List listByZoneId(SecondaryStorageVm.Role role, long zoneId); + + public List getRunningSecStorageVmListByMsid(SecondaryStorageVm.Role role, long msid); + + public List listRunningSecStorageOrderByLoad(SecondaryStorageVm.Role role, long zoneId); + SecondaryStorageVmVO findByInstanceName(String instanceName); +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java new file mode 100644 index 0000000..f802a90 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java @@ -0,0 +1,269 @@ +// 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.List; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.Attribute; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.UpdateBuilder; +import com.cloud.vm.SecondaryStorageVm; +import com.cloud.vm.SecondaryStorageVmVO; +import com.cloud.vm.VirtualMachine.State; + +@Component +@Local(value={SecondaryStorageVmDao.class}) +public class SecondaryStorageVmDaoImpl extends GenericDaoBase implements SecondaryStorageVmDao { + private static final Logger s_logger = Logger.getLogger(SecondaryStorageVmDaoImpl.class); + + protected SearchBuilder DataCenterStatusSearch; + protected SearchBuilder StateSearch; + protected SearchBuilder HostSearch; + protected SearchBuilder LastHostSearch; + protected SearchBuilder HostUpSearch; + protected SearchBuilder ZoneSearch; + protected SearchBuilder StateChangeSearch; + protected SearchBuilder InstanceSearch; + + protected final Attribute _updateTimeAttr; + + public SecondaryStorageVmDaoImpl() { + DataCenterStatusSearch = createSearchBuilder(); + DataCenterStatusSearch.and("dc", DataCenterStatusSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + DataCenterStatusSearch.and("states", DataCenterStatusSearch.entity().getState(), SearchCriteria.Op.IN); + DataCenterStatusSearch.and("role", DataCenterStatusSearch.entity().getRole(), SearchCriteria.Op.EQ); + DataCenterStatusSearch.done(); + + StateSearch = createSearchBuilder(); + StateSearch.and("states", StateSearch.entity().getState(), SearchCriteria.Op.IN); + StateSearch.and("role", StateSearch.entity().getRole(), SearchCriteria.Op.EQ); + StateSearch.done(); + + HostSearch = createSearchBuilder(); + HostSearch.and("host", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); + HostSearch.and("role", HostSearch.entity().getRole(), SearchCriteria.Op.EQ); + HostSearch.done(); + + InstanceSearch = createSearchBuilder(); + InstanceSearch.and("instanceName", InstanceSearch.entity().getInstanceName(), SearchCriteria.Op.EQ); + InstanceSearch.done(); + + LastHostSearch = createSearchBuilder(); + LastHostSearch.and("lastHost", LastHostSearch.entity().getLastHostId(), SearchCriteria.Op.EQ); + LastHostSearch.and("state", LastHostSearch.entity().getState(), SearchCriteria.Op.EQ); + LastHostSearch.and("role", LastHostSearch.entity().getRole(), SearchCriteria.Op.EQ); + LastHostSearch.done(); + + HostUpSearch = createSearchBuilder(); + HostUpSearch.and("host", HostUpSearch.entity().getHostId(), SearchCriteria.Op.EQ); + HostUpSearch.and("states", HostUpSearch.entity().getState(), SearchCriteria.Op.NIN); + HostUpSearch.and("role", HostUpSearch.entity().getRole(), SearchCriteria.Op.EQ); + HostUpSearch.done(); + + ZoneSearch = createSearchBuilder(); + ZoneSearch.and("zone", ZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + ZoneSearch.and("role", ZoneSearch.entity().getRole(), SearchCriteria.Op.EQ); + ZoneSearch.done(); + + StateChangeSearch = createSearchBuilder(); + StateChangeSearch.and("id", StateChangeSearch.entity().getId(), SearchCriteria.Op.EQ); + StateChangeSearch.and("states", StateChangeSearch.entity().getState(), SearchCriteria.Op.EQ); + StateChangeSearch.and("host", StateChangeSearch.entity().getHostId(), SearchCriteria.Op.EQ); + StateChangeSearch.and("update", StateChangeSearch.entity().getUpdated(), SearchCriteria.Op.EQ); + StateChangeSearch.and("role", StateChangeSearch.entity().getUpdated(), SearchCriteria.Op.EQ); + StateChangeSearch.done(); + + _updateTimeAttr = _allAttributes.get("updateTime"); + assert _updateTimeAttr != null : "Couldn't get this updateTime attribute"; + } + + @Override + public boolean remove(Long id) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + SecondaryStorageVmVO proxy = createForUpdate(); + proxy.setPublicIpAddress(null); + proxy.setPrivateIpAddress(null); + + UpdateBuilder ub = getUpdateBuilder(proxy); + ub.set(proxy, "state", State.Destroyed); + ub.set(proxy, "privateIpAddress", null); + update(id, ub, proxy); + + boolean result = super.remove(id); + txn.commit(); + return result; + } + + @Override + public List getSecStorageVmListInStates(SecondaryStorageVm.Role role, long dataCenterId, State... states) { + SearchCriteria sc = DataCenterStatusSearch.create(); + sc.setParameters("states", (Object[])states); + sc.setParameters("dc", dataCenterId); + if(role != null) { + sc.setParameters("role", role); + } + return listBy(sc); + } + + @Override + public List getSecStorageVmListInStates(SecondaryStorageVm.Role role, State... states) { + SearchCriteria sc = StateSearch.create(); + sc.setParameters("states", (Object[])states); + if(role != null) { + sc.setParameters("role", role); + } + + return listBy(sc); + } + + @Override + public List listByHostId(SecondaryStorageVm.Role role, long hostId) { + SearchCriteria sc = HostSearch.create(); + sc.setParameters("host", hostId); + if(role != null) { + sc.setParameters("role", role); + } + return listBy(sc); + } + + @Override + public List listUpByHostId(SecondaryStorageVm.Role role, long hostId) { + SearchCriteria sc = HostUpSearch.create(); + sc.setParameters("host", hostId); + sc.setParameters("states", new Object[] {State.Destroyed, State.Stopped, State.Expunging}); + if(role != null) { + sc.setParameters("role", role); + } + return listBy(sc); + } + + @Override + public List getRunningSecStorageVmListByMsid(SecondaryStorageVm.Role role, long msid) { + List l = new ArrayList(); + Transaction txn = Transaction.currentTxn();; + PreparedStatement pstmt = null; + try { + String sql; + if(role == null) { + sql = "SELECT s.id FROM secondary_storage_vm s, vm_instance v, host h " + + "WHERE s.id=v.id AND v.state='Running' AND v.host_id=h.id AND h.mgmt_server_id=?"; + } else { + sql = "SELECT s.id FROM secondary_storage_vm s, vm_instance v, host h " + + "WHERE s.id=v.id AND v.state='Running' AND s.role=? AND v.host_id=h.id AND h.mgmt_server_id=?"; + } + + pstmt = txn.prepareAutoCloseStatement(sql); + + if(role == null) { + pstmt.setLong(1, msid); + } else { + pstmt.setString(1, role.toString()); + pstmt.setLong(2, msid); + } + + ResultSet rs = pstmt.executeQuery(); + while(rs.next()) { + l.add(rs.getLong(1)); + } + } catch (SQLException e) { + } catch (Throwable e) { + } + return l; + } + + + @Override + public SecondaryStorageVmVO findByInstanceName(String instanceName) { + SearchCriteria sc = InstanceSearch.create(); + sc.setParameters("instanceName", instanceName); + List list = listBy(sc); + if( list == null || list.size() == 0 ) { + return null; + } else { + return list.get(0); + } + } + + @Override + public List listByZoneId(SecondaryStorageVm.Role role, long zoneId) { + SearchCriteria sc = ZoneSearch.create(); + sc.setParameters("zone", zoneId); + if(role != null) { + sc.setParameters("role", role); + } + return listBy(sc); + } + + @Override + public List listByLastHostId(SecondaryStorageVm.Role role, long hostId) { + SearchCriteria sc = LastHostSearch.create(); + sc.setParameters("lastHost", hostId); + sc.setParameters("state", State.Stopped); + if(role != null) { + sc.setParameters("role", role); + } + + return listBy(sc); + } + + @Override + public List listRunningSecStorageOrderByLoad(SecondaryStorageVm.Role role, long zoneId) { + + List l = new ArrayList(); + Transaction txn = Transaction.currentTxn();; + PreparedStatement pstmt = null; + try { + String sql; + if(role == null) { + sql = "SELECT s.id, count(l.id) as count FROM secondary_storage_vm s INNER JOIN vm_instance v ON s.id=v.id LEFT JOIN cmd_exec_log l ON s.id=l.instance_id WHERE v.state='Running' AND v.data_center_id=? GROUP BY s.id ORDER BY count"; + } else { + sql = "SELECT s.id, count(l.id) as count FROM secondary_storage_vm s INNER JOIN vm_instance v ON s.id=v.id LEFT JOIN cmd_exec_log l ON s.id=l.instance_id WHERE v.state='Running' AND v.data_center_id=? AND s.role=? GROUP BY s.id ORDER BY count"; + } + + pstmt = txn.prepareAutoCloseStatement(sql); + + if(role == null) { + pstmt.setLong(1, zoneId); + } else { + pstmt.setLong(1, zoneId); + pstmt.setString(2, role.toString()); + } + + ResultSet rs = pstmt.executeQuery(); + while(rs.next()) { + l.add(rs.getLong(1)); + } + } catch (SQLException e) { + s_logger.error("Unexpected exception ", e); + } + + return l; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/UserVmCloneSettingDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/UserVmCloneSettingDao.java b/engine/schema/src/com/cloud/vm/dao/UserVmCloneSettingDao.java new file mode 100644 index 0000000..44a1bf3 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/UserVmCloneSettingDao.java @@ -0,0 +1,37 @@ +// 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.utils.db.GenericDao; +import com.cloud.vm.UserVmCloneSettingVO; + +public interface UserVmCloneSettingDao extends GenericDao { + + /* + * Returns a User VM clone type record by vm id. + */ + UserVmCloneSettingVO findByVmId(long id); + + /* + * Returns a list of VMs by clone type. + * cloneType can be full/linked. + */ + List listByCloneType(String cloneType); + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/UserVmCloneSettingDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/UserVmCloneSettingDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/UserVmCloneSettingDaoImpl.java new file mode 100644 index 0000000..174f283 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/UserVmCloneSettingDaoImpl.java @@ -0,0 +1,74 @@ +// 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.annotation.PostConstruct; +import javax.ejb.Local; + +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.vm.UserVmCloneSettingVO; +import com.cloud.utils.db.DB; + + +@Component +@Local(value= { UserVmCloneSettingDao.class }) +@DB(txn = false) +public class UserVmCloneSettingDaoImpl extends GenericDaoBase implements UserVmCloneSettingDao { + public static final Logger s_logger = Logger.getLogger(UserVmCloneSettingDaoImpl.class); + + protected SearchBuilder vmIdSearch; + protected SearchBuilder cloneTypeSearch; + + public UserVmCloneSettingDaoImpl() { + } + + @PostConstruct + public void init() { + // Initialize the search builders. + vmIdSearch = createSearchBuilder(); + vmIdSearch.and("vmId", vmIdSearch.entity().getCloneType(), Op.EQ); + vmIdSearch.done(); + + cloneTypeSearch = createSearchBuilder(); + cloneTypeSearch.and("cloneType", cloneTypeSearch.entity().getCloneType(), Op.EQ); + cloneTypeSearch.done(); + } + + @Override + public UserVmCloneSettingVO findByVmId(long vmId) { + SearchCriteria sc = vmIdSearch.create(); + sc.setParameters("vmId", vmId); + return findOneBy(sc); + } + + @Override + public List listByCloneType(String cloneType) { + SearchCriteria sc = cloneTypeSearch.create(); + sc.setParameters("cloneType", cloneType); + return search(sc, null); + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/vm/dao/UserVmDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/UserVmDao.java b/engine/schema/src/com/cloud/vm/dao/UserVmDao.java new file mode 100755 index 0000000..81d13cd --- /dev/null +++ b/engine/schema/src/com/cloud/vm/dao/UserVmDao.java @@ -0,0 +1,76 @@ +// 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.Date; +import java.util.Hashtable; +import java.util.List; + +import com.cloud.utils.db.GenericDao; +import com.cloud.vm.UserVmVO; +import com.cloud.vm.VirtualMachine.State; + +public interface UserVmDao extends GenericDao { + List listByAccountId(long id); + + List listByAccountAndPod(long accountId, long podId); + List listByAccountAndDataCenter(long accountId, long dcId); + List listByHostId(Long hostId); + List listByLastHostId(Long hostId); + List listUpByHostId(Long hostId); + + /** + * Updates display name and group for vm; enables/disables ha + * @param id vm id. + * @param displan name and enable for ha + * @param userData updates the userData of the vm + */ + void updateVM(long id, String displayName, boolean enable, Long osTypeId, String userData); + + List findDestroyedVms(Date date); + + /** + * List running VMs on the specified host + * @param id + * @return + */ + public List listRunningByHostId(long hostId); + + /** + * List user vm instances with virtualized networking (i.e. not direct attached networking) for the given account and datacenter + * @param accountId will search for vm instances belonging to this account + * @param dcId will search for vm instances in this zone + * @return the list of vm instances owned by the account in the given data center that have virtualized networking (not direct attached networking) + */ + List listVirtualNetworkInstancesByAcctAndZone(long accountId, long dcId, long networkId); + + List listByNetworkIdAndStates(long networkId, State... states); + + List listByAccountIdAndHostId(long accountId, long hostId); + + void loadDetails(UserVmVO vm); + + void saveDetails(UserVmVO vm); + + List listPodIdsHavingVmsforAccount(long zoneId, long accountId); + public Long countAllocatedVMsForAccount(long accountId); + + Hashtable listVmDetails(Hashtable userVmData); + + List listByIsoId(Long isoId); + +}