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 6AD7F10543 for ; Wed, 8 May 2013 17:48:38 +0000 (UTC) Received: (qmail 41220 invoked by uid 500); 8 May 2013 17:48:27 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 41157 invoked by uid 500); 8 May 2013 17:48:27 -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 40459 invoked by uid 99); 8 May 2013 17:48:26 -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 17:48:26 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 31EAB889D91; Wed, 8 May 2013 17:48:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bfederle@apache.org To: commits@cloudstack.apache.org Date: Wed, 08 May 2013 17:48:44 -0000 Message-Id: <969c5ca7b652446e996548f195b6dea1@git.apache.org> In-Reply-To: <818559ec26454aa7b9803739214b1b22@git.apache.org> References: <818559ec26454aa7b9803739214b1b22@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [20/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/snapshot/dao/VMSnapshotDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java b/engine/schema/src/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java new file mode 100644 index 0000000..7d8ace7 --- /dev/null +++ b/engine/schema/src/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java @@ -0,0 +1,161 @@ +// 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.snapshot.dao; + +import java.util.Date; +import java.util.List; + +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.utils.db.UpdateBuilder; +import com.cloud.vm.snapshot.VMSnapshot; +import com.cloud.vm.snapshot.VMSnapshot.Event; +import com.cloud.vm.snapshot.VMSnapshot.State; +import com.cloud.vm.snapshot.VMSnapshotVO; +@Component +@Local(value = { VMSnapshotDao.class }) +public class VMSnapshotDaoImpl extends GenericDaoBase + implements VMSnapshotDao { + private static final Logger s_logger = Logger.getLogger(VMSnapshotDaoImpl.class); + private final SearchBuilder SnapshotSearch; + private final SearchBuilder ExpungingSnapshotSearch; + private final SearchBuilder SnapshotStatusSearch; + private final SearchBuilder AllFieldsSearch; + + protected VMSnapshotDaoImpl() { + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ); + AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), Op.EQ); + AllFieldsSearch.and("vm_id", AllFieldsSearch.entity().getVmId(), Op.EQ); + AllFieldsSearch.and("deviceId", AllFieldsSearch.entity().getVmId(), Op.EQ); + AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ); + AllFieldsSearch.and("removed", AllFieldsSearch.entity().getState(), Op.EQ); + AllFieldsSearch.and("parent", AllFieldsSearch.entity().getParent(), Op.EQ); + AllFieldsSearch.and("current", AllFieldsSearch.entity().getCurrent(), Op.EQ); + AllFieldsSearch.and("vm_snapshot_type", AllFieldsSearch.entity().getType(), Op.EQ); + AllFieldsSearch.and("updatedCount", AllFieldsSearch.entity().getUpdatedCount(), Op.EQ); + AllFieldsSearch.and("display_name", AllFieldsSearch.entity().getDisplayName(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), SearchCriteria.Op.EQ); + AllFieldsSearch.done(); + + SnapshotSearch = createSearchBuilder(); + SnapshotSearch.and("vm_id", SnapshotSearch.entity().getVmId(), + SearchCriteria.Op.EQ); + SnapshotSearch.done(); + + ExpungingSnapshotSearch = createSearchBuilder(); + ExpungingSnapshotSearch.and("state", ExpungingSnapshotSearch.entity() + .getState(), SearchCriteria.Op.EQ); + ExpungingSnapshotSearch.and("removed", ExpungingSnapshotSearch.entity() + .getRemoved(), SearchCriteria.Op.NULL); + ExpungingSnapshotSearch.done(); + + SnapshotStatusSearch = createSearchBuilder(); + SnapshotStatusSearch.and("vm_id", SnapshotStatusSearch.entity() + .getVmId(), SearchCriteria.Op.EQ); + SnapshotStatusSearch.and("state", SnapshotStatusSearch.entity() + .getState(), SearchCriteria.Op.IN); + SnapshotStatusSearch.done(); + } + + @Override + public List findByVm(Long vmId) { + SearchCriteria sc = SnapshotSearch.create(); + sc.setParameters("vm_id", vmId); + return listBy(sc, null); + } + + @Override + public List listExpungingSnapshot() { + SearchCriteria sc = ExpungingSnapshotSearch.create(); + sc.setParameters("state", State.Expunging); + return listBy(sc, null); + } + + @Override + public List listByInstanceId(Long vmId, State... status) { + SearchCriteria sc = SnapshotStatusSearch.create(); + sc.setParameters("vm_id", vmId); + sc.setParameters("state", (Object[]) status); + return listBy(sc, null); + } + + @Override + public VMSnapshotVO findCurrentSnapshotByVmId(Long vmId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("vm_id", vmId); + sc.setParameters("current", 1); + return findOneBy(sc); + } + + @Override + public List listByParent(Long vmSnapshotId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("parent", vmSnapshotId); + sc.setParameters("state", State.Ready ); + return listBy(sc, null); + } + + @Override + public VMSnapshotVO findByName(Long vm_id, String name) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("vm_id", vm_id); + sc.setParameters("display_name", name ); + return null; + } + + @Override + public boolean updateState(State currentState, Event event, State nextState, VMSnapshot vo, Object data) { + + Long oldUpdated = vo.getUpdatedCount(); + Date oldUpdatedTime = vo.getUpdated(); + + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("id", vo.getId()); + sc.setParameters("state", currentState); + sc.setParameters("updatedCount", vo.getUpdatedCount()); + + vo.incrUpdatedCount(); + + UpdateBuilder builder = getUpdateBuilder(vo); + builder.set(vo, "state", nextState); + builder.set(vo, "updated", new Date()); + + int rows = update((VMSnapshotVO)vo, sc); + if (rows == 0 && s_logger.isDebugEnabled()) { + VMSnapshotVO dbVol = findByIdIncludingRemoved(vo.getId()); + if (dbVol != null) { + StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); + str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=").append(dbVol.getUpdated()); + str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(vo.getUpdatedCount()).append("; updatedTime=").append(vo.getUpdated()); + str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime); + } else { + s_logger.debug("Unable to update VM snapshot: id=" + vo.getId() + ", as there is no such snapshot exists in the database anymore"); + } + } + return rows > 0; + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java b/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java new file mode 100644 index 0000000..f84e4c3 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java @@ -0,0 +1,66 @@ +// 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.affinity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.PrimaryKeyJoinColumn; +import javax.persistence.SecondaryTable; +import javax.persistence.SecondaryTables; +import javax.persistence.Table; + +import org.apache.cloudstack.api.InternalIdentity; + +@Entity +@Table(name = ("affinity_group_vm_map")) +public class AffinityGroupVMMapVO implements InternalIdentity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + @Column(name = "affinity_group_id") + private long affinityGroupId; + + @Column(name = "instance_id") + private long instanceId; + + public AffinityGroupVMMapVO() { + } + + public AffinityGroupVMMapVO(long affinityGroupId, long instanceId) { + this.affinityGroupId = affinityGroupId; + this.instanceId = instanceId; + } + + public long getId() { + return id; + } + + public long getAffinityGroupId() { + return affinityGroupId; + } + + + public long getInstanceId() { + return instanceId; + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVO.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVO.java b/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVO.java new file mode 100644 index 0000000..f418cef --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVO.java @@ -0,0 +1,114 @@ +// 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.affinity; + +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; + + +@Entity +@Table(name = ("affinity_group")) +public class AffinityGroupVO implements AffinityGroup { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "name") + private String name; + + @Column(name = "type") + private String type; + + @Column(name = "description") + private String description; + + @Column(name = "domain_id") + private long domainId; + + @Column(name = "account_id") + private long accountId; + + @Column(name = "uuid") + private String uuid; + + public AffinityGroupVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public AffinityGroupVO(String name, String type, String description, long domainId, long accountId) { + this.name = name; + this.description = description; + this.domainId = domainId; + this.accountId = accountId; + this.uuid = UUID.randomUUID().toString(); + this.type = type; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public long getDomainId() { + return domainId; + } + + @Override + public long getAccountId() { + return accountId; + } + + @Override + public String getUuid() { + return this.uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + @Override + public String getType() { + return type; + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder("AffinityGroup["); + buf.append(uuid).append("]"); + return buf.toString(); + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupDao.java b/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupDao.java new file mode 100644 index 0000000..296e7b1 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupDao.java @@ -0,0 +1,30 @@ +// 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.affinity.dao; + +import java.util.List; + +import org.apache.cloudstack.affinity.AffinityGroupVO; +import com.cloud.utils.db.GenericDao; + +public interface AffinityGroupDao extends GenericDao { + List listByAccountId(long accountId); + boolean isNameInUse(Long accountId, Long domainId, String name); + AffinityGroupVO findByAccountAndName(Long accountId, String name); + List findByAccountAndNames(Long accountId, String... names); + int removeByAccountId(long accountId); +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java b/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java new file mode 100644 index 0000000..d189d60 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java @@ -0,0 +1,102 @@ +// 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.affinity.dao; + +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.ejb.Local; +import org.apache.cloudstack.affinity.AffinityGroupVO; +import org.springframework.stereotype.Component; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@Local(value = { AffinityGroupDao.class }) +public class AffinityGroupDaoImpl extends GenericDaoBase implements AffinityGroupDao { + private SearchBuilder AccountIdSearch; + private SearchBuilder AccountIdNameSearch; + private SearchBuilder AccountIdNamesSearch; + + + public AffinityGroupDaoImpl() { + + } + + @PostConstruct + protected void init() { + AccountIdSearch = createSearchBuilder(); + AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + AccountIdSearch.done(); + + AccountIdNameSearch = createSearchBuilder(); + AccountIdNameSearch.and("accountId", AccountIdNameSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + AccountIdNameSearch.and("name", AccountIdNameSearch.entity().getName(), SearchCriteria.Op.EQ); + + AccountIdNamesSearch = createSearchBuilder(); + AccountIdNamesSearch.and("accountId", AccountIdNamesSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + AccountIdNamesSearch.and("groupNames", AccountIdNamesSearch.entity().getName(), SearchCriteria.Op.IN); + AccountIdNameSearch.done(); + } + + @Override + public List listByAccountId(long accountId) { + SearchCriteria sc = AccountIdSearch.create(); + sc.setParameters("accountId", accountId); + return listBy(sc); + } + + @Override + public boolean isNameInUse(Long accountId, Long domainId, String name) { + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("name", SearchCriteria.Op.EQ, name); + if (accountId != null) { + sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); + } else { + sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); + sc.addAnd("accountId", SearchCriteria.Op.NULL); + } + + List AffinityGroups = listBy(sc); + return ((AffinityGroups != null) && !AffinityGroups.isEmpty()); + } + + @Override + public AffinityGroupVO findByAccountAndName(Long accountId, String name) { + SearchCriteria sc = AccountIdNameSearch.create(); + sc.setParameters("accountId", accountId); + sc.setParameters("name", name); + + return findOneIncludingRemovedBy(sc); + } + + @Override + public List findByAccountAndNames(Long accountId, String... names) { + SearchCriteria sc = AccountIdNamesSearch.create(); + sc.setParameters("accountId", accountId); + + sc.setParameters("groupNames", (Object [])names); + + return listBy(sc); + } + @Override + public int removeByAccountId(long accountId) { + SearchCriteria sc = AccountIdSearch.create(); + sc.setParameters("accountId", accountId); + return expunge(sc); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java b/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java new file mode 100644 index 0000000..f2951bc --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java @@ -0,0 +1,47 @@ +// 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.affinity.dao; + +import java.util.List; + +import org.apache.cloudstack.affinity.AffinityGroupVMMapVO; + +import com.cloud.utils.Pair; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDao; +import com.cloud.vm.VirtualMachine.State; + +public interface AffinityGroupVMMapDao extends GenericDao { + + List listByInstanceId(long instanceId); + + Pair, Integer> listByInstanceId(long instanceId, Filter filter); + + List listByAffinityGroup(long affinityGroupId); + + List listVmIdsByAffinityGroup(long affinityGroupId); + + AffinityGroupVMMapVO findByVmIdGroupId(long instanceId, long affinityGroupId); + + long countAffinityGroupsForVm(long instanceId); + + int deleteVM(long instanceId); + + List findByVmIdType(long instanceId, String type); + + void updateMap(Long vmId, List affinityGroupIds); +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java b/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java new file mode 100644 index 0000000..e03e73c --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java @@ -0,0 +1,167 @@ +// 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.affinity.dao; + +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.ejb.Local; +import javax.inject.Inject; + +import org.apache.cloudstack.affinity.AffinityGroupVMMapVO; +import org.apache.cloudstack.affinity.AffinityGroupVO; +import org.springframework.stereotype.Component; + +import com.cloud.host.HostTagVO; +import com.cloud.utils.Pair; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; +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.Func; +import com.cloud.utils.db.Transaction; + +@Local(value = { AffinityGroupVMMapDao.class }) +public class AffinityGroupVMMapDaoImpl extends GenericDaoBase implements + AffinityGroupVMMapDao { + private SearchBuilder ListByVmId; + private SearchBuilder ListByVmIdGroupId; + protected GenericSearchBuilder CountSGForVm; + private GenericSearchBuilder ListVmIdByAffinityGroup; + private SearchBuilder ListByAffinityGroup; + private SearchBuilder ListByVmIdType; + + @Inject + protected AffinityGroupDao _affinityGroupDao; + + public AffinityGroupVMMapDaoImpl() { + } + + @PostConstruct + protected void init() { + ListVmIdByAffinityGroup = createSearchBuilder(Long.class); + ListVmIdByAffinityGroup.and("affinityGroupId", ListVmIdByAffinityGroup.entity().getAffinityGroupId(), + SearchCriteria.Op.EQ); + ListVmIdByAffinityGroup.selectField(ListVmIdByAffinityGroup.entity().getInstanceId()); + ListVmIdByAffinityGroup.done(); + + ListByAffinityGroup = createSearchBuilder(); + ListByAffinityGroup.and("affinityGroupId", ListByAffinityGroup.entity().getAffinityGroupId(), + SearchCriteria.Op.EQ); + ListByAffinityGroup.done(); + + ListByVmId = createSearchBuilder(); + ListByVmId.and("instanceId", ListByVmId.entity().getInstanceId(), SearchCriteria.Op.EQ); + ListByVmId.done(); + + ListByVmIdGroupId = createSearchBuilder(); + ListByVmIdGroupId.and("instanceId", ListByVmIdGroupId.entity().getInstanceId(), SearchCriteria.Op.EQ); + ListByVmIdGroupId.and("affinityGroupId", ListByVmIdGroupId.entity().getAffinityGroupId(), SearchCriteria.Op.EQ); + ListByVmIdGroupId.done(); + + SearchBuilder groupSearch = _affinityGroupDao.createSearchBuilder(); + groupSearch.and("type", groupSearch.entity().getType(), SearchCriteria.Op.EQ); + + ListByVmIdType = createSearchBuilder(); + ListByVmIdType.and("instanceId", ListByVmIdType.entity().getInstanceId(), SearchCriteria.Op.EQ); + ListByVmIdType.join("groupSearch", groupSearch, ListByVmIdType.entity().getAffinityGroupId(), groupSearch.entity().getId(), JoinType.INNER); + ListByVmIdType.done(); + + CountSGForVm = createSearchBuilder(Long.class); + CountSGForVm.select(null, Func.COUNT, null); + CountSGForVm.and("vmId", CountSGForVm.entity().getInstanceId(), SearchCriteria.Op.EQ); + CountSGForVm.done(); + } + + @Override + public List listByAffinityGroup(long affinityGroupId) { + SearchCriteria sc = ListByAffinityGroup.create(); + sc.setParameters("affinityGroupId", affinityGroupId); + return listBy(sc); + } + + @Override + public List listByInstanceId(long vmId) { + SearchCriteria sc = ListByVmId.create(); + sc.setParameters("instanceId", vmId); + return listBy(sc); + } + + @Override + public Pair, Integer> listByInstanceId(long instanceId, Filter filter) { + SearchCriteria sc = ListByVmId.create(); + sc.setParameters("instanceId", instanceId); + return this.searchAndCount(sc, filter); + } + + @Override + public int deleteVM(long instanceId) { + SearchCriteria sc = ListByVmId.create(); + sc.setParameters("instanceId", instanceId); + return super.expunge(sc); + } + + @Override + public List listVmIdsByAffinityGroup(long affinityGroupId) { + SearchCriteria sc = ListVmIdByAffinityGroup.create(); + sc.setParameters("affinityGroupId", affinityGroupId); + return customSearchIncludingRemoved(sc, null); + } + + @Override + public AffinityGroupVMMapVO findByVmIdGroupId(long instanceId, long affinityGroupId) { + SearchCriteria sc = ListByVmIdGroupId.create(); + sc.setParameters("affinityGroupId", affinityGroupId); + sc.setParameters("instanceId", instanceId); + return findOneIncludingRemovedBy(sc); + } + + @Override + public long countAffinityGroupsForVm(long instanceId) { + SearchCriteria sc = CountSGForVm.create(); + sc.setParameters("vmId", instanceId); + return customSearch(sc, null).get(0); + } + + @Override + public List findByVmIdType(long instanceId, String type) { + SearchCriteria sc = ListByVmIdType.create(); + sc.setParameters("instanceId", instanceId); + sc.setJoinParameters("groupSearch", "type", type); + return listBy(sc); + } + + @Override + public void updateMap(Long vmId, List affinityGroupIds) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("instanceId", SearchCriteria.Op.EQ, vmId); + expunge(sc); + + for (Long groupId : affinityGroupIds) { + AffinityGroupVMMapVO vo = new AffinityGroupVMMapVO(groupId, vmId); + persist(vo); + } + + txn.commit(); + + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/region/RegionSyncVO.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/region/RegionSyncVO.java b/engine/schema/src/org/apache/cloudstack/region/RegionSyncVO.java new file mode 100644 index 0000000..271f8e3 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/region/RegionSyncVO.java @@ -0,0 +1,93 @@ +// 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.region; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.utils.db.GenericDao; + + +@Entity +@Table(name="region_sync") +public class RegionSyncVO implements RegionSync { + + @Id + @Column(name="id") + private long id; + + @Column(name="region_id") + private int regionId; + + @Column(name="api") + private String api; + + @Column(name=GenericDao.CREATED_COLUMN) + private Date createDate; + + @Column(name="processed") + boolean processed; + + public RegionSyncVO() { + } + + public RegionSyncVO(int regionId, String api) { + this.regionId = regionId; + this.api = api; + } + + public int getRegionId() { + return regionId; + } + + public void setRegionId(int regionId) { + this.regionId = regionId; + } + + public String getApi() { + return api; + } + + public void setApi(String api) { + this.api = api; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public boolean isProcessed() { + return processed; + } + + public void setProcessed(boolean processed) { + this.processed = processed; + } + + public long getId() { + return id; + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/region/RegionVO.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/region/RegionVO.java b/engine/schema/src/org/apache/cloudstack/region/RegionVO.java new file mode 100644 index 0000000..6890bc8 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/region/RegionVO.java @@ -0,0 +1,87 @@ +// 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.region; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Entity +@Table(name="region") +public class RegionVO implements Region{ + + @Id + @Column(name="id") + private int id; + + @Column(name="name") + private String name; + + @Column(name="end_point") + private String endPoint; + + + public boolean getGslbEnabled() { + return gslbEnabled; + } + + public void setGslbEnabled(boolean gslbEnabled) { + this.gslbEnabled = gslbEnabled; + } + + @Column(name="gslb_service_enabled") + private boolean gslbEnabled; + + public RegionVO() { + } + + public RegionVO(int id, String name, String endPoint) { + this.id = id; + this.name = name; + this.endPoint = endPoint; + this.gslbEnabled = true; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEndPoint() { + return endPoint; + } + + public void setEndPoint(String endPoint) { + this.endPoint = endPoint; + } + + + @Override + public boolean checkIfServiceEnabled(Service service) { + return gslbEnabled; + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/region/dao/RegionDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/region/dao/RegionDao.java b/engine/schema/src/org/apache/cloudstack/region/dao/RegionDao.java new file mode 100644 index 0000000..91b51d3 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/region/dao/RegionDao.java @@ -0,0 +1,27 @@ +// 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.region.dao; + +import org.apache.cloudstack.region.RegionVO; + +import com.cloud.utils.db.GenericDao; + +public interface RegionDao extends GenericDao { + + RegionVO findByName(String name); + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java b/engine/schema/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java new file mode 100644 index 0000000..8f50f93 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java @@ -0,0 +1,48 @@ +// 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.region.dao; + +import javax.ejb.Local; + +import org.apache.cloudstack.region.RegionVO; +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; + +@Component +@Local(value={RegionDao.class}) +public class RegionDaoImpl extends GenericDaoBase implements RegionDao { + private static final Logger s_logger = Logger.getLogger(RegionDaoImpl.class); + protected SearchBuilder NameSearch; + protected SearchBuilder AllFieldsSearch; + + public RegionDaoImpl(){ + NameSearch = createSearchBuilder(); + NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ); + NameSearch.done(); + } + + @Override + public RegionVO findByName(String name) { + SearchCriteria sc = NameSearch.create(); + sc.setParameters("name", name); + return findOneBy(sc); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerDaoImpl.java b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerDaoImpl.java new file mode 100644 index 0000000..0020f5d --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerDaoImpl.java @@ -0,0 +1,58 @@ +// 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.region.gslb; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import org.springframework.stereotype.Component; + +import javax.ejb.Local; +import java.util.List; + +@Component +@Local(value={GlobalLoadBalancerRuleDao.class}) +public class GlobalLoadBalancerDaoImpl extends GenericDaoBase implements GlobalLoadBalancerRuleDao { + + private final SearchBuilder listByDomainSearch; + private final SearchBuilder listByRegionIDSearch; + + public GlobalLoadBalancerDaoImpl() { + listByDomainSearch = createSearchBuilder(); + listByDomainSearch.and("gslbDomain", listByDomainSearch.entity().getGslbDomain(), SearchCriteria.Op.EQ); + listByDomainSearch.done(); + + listByRegionIDSearch = createSearchBuilder(); + listByRegionIDSearch.and("region", listByRegionIDSearch.entity().getRegion(), SearchCriteria.Op.EQ); + listByRegionIDSearch.done(); + } + + @Override + public List listByRegionId(int regionId) { + SearchCriteria sc = listByRegionIDSearch.create(); + sc.setParameters("region", regionId); + return listBy(sc); + } + + @Override + public GlobalLoadBalancerRuleVO findByDomainName(String domainName) { + SearchCriteria sc = listByDomainSearch.create(); + sc.setParameters("gslbDomain", domainName); + return findOneBy(sc); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapDao.java b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapDao.java new file mode 100644 index 0000000..5ce0b40 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapDao.java @@ -0,0 +1,30 @@ +// 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.region.gslb; + +import com.cloud.utils.db.GenericDao; + +import java.util.List; + +public interface GlobalLoadBalancerLbRuleMapDao extends GenericDao { + + List listByGslbRuleId(long gslbRuleId); + + GlobalLoadBalancerLbRuleMapVO findByGslbRuleIdAndLbRuleId(long gslbRuleId, long lbRuleId); + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapDaoImpl.java b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapDaoImpl.java new file mode 100644 index 0000000..2a6e72b --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapDaoImpl.java @@ -0,0 +1,63 @@ +// 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.region.gslb; + +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import org.springframework.stereotype.Component; + +import javax.ejb.Local; +import java.util.List; + +@Component +@Local(value={GlobalLoadBalancerLbRuleMapDao.class}) +@DB(txn = false) +public class GlobalLoadBalancerLbRuleMapDaoImpl extends GenericDaoBase implements GlobalLoadBalancerLbRuleMapDao { + + private final SearchBuilder listByGslbRuleId; + private final SearchBuilder listByLbGslbRuleId; + + public GlobalLoadBalancerLbRuleMapDaoImpl() { + listByGslbRuleId = createSearchBuilder(); + listByGslbRuleId.and("gslbLoadBalancerId", listByGslbRuleId.entity().getGslbLoadBalancerId(), SearchCriteria.Op.EQ); + listByGslbRuleId.done(); + + listByLbGslbRuleId = createSearchBuilder(); + listByLbGslbRuleId.and("gslbLoadBalancerId", listByLbGslbRuleId.entity().getGslbLoadBalancerId(), SearchCriteria.Op.EQ); + listByLbGslbRuleId.and("loadBalancerId", listByLbGslbRuleId.entity().getLoadBalancerId(), SearchCriteria.Op.EQ); + listByLbGslbRuleId.done(); + } + + @Override + public List listByGslbRuleId(long gslbRuleId) { + SearchCriteria sc = listByGslbRuleId.create(); + sc.setParameters("gslbLoadBalancerId", gslbRuleId); + return listBy(sc); + } + + @Override + public GlobalLoadBalancerLbRuleMapVO findByGslbRuleIdAndLbRuleId(long gslbRuleId, long lbRuleId) { + SearchCriteria sc = listByLbGslbRuleId.create(); + sc.setParameters("gslbLoadBalancerId", gslbRuleId); + sc.setParameters("loadBalancerId", lbRuleId); + return findOneBy(sc); + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapVO.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapVO.java b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapVO.java new file mode 100644 index 0000000..6a1e17d --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerLbRuleMapVO.java @@ -0,0 +1,83 @@ +// 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.region.gslb; + +import org.apache.cloudstack.api.InternalIdentity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name=("global_load_balancer_lb_rule_map")) +public class GlobalLoadBalancerLbRuleMapVO implements InternalIdentity { + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id") + private long id; + + @Column(name="lb_rule_id") + private long loadBalancerId; + + @Column(name="gslb_rule_id") + private long gslbLoadBalancerId; + + @Column(name="revoke") + private boolean revoke = false; + + public GlobalLoadBalancerLbRuleMapVO() { + + } + + public GlobalLoadBalancerLbRuleMapVO(long loadBalancerId, long gslbLoadBalancerId) { + this.loadBalancerId = loadBalancerId; + this.gslbLoadBalancerId = gslbLoadBalancerId; + this.revoke = false; + } + + public long getId() { + return id; + } + + public long getLoadBalancerId() { + return loadBalancerId; + } + + public long getGslbLoadBalancerId() { + return gslbLoadBalancerId; + } + + public void setLoadBalancerId(long loadBalancerId) { + this.loadBalancerId = loadBalancerId; + } + + public void setGslbLoadBalancerId(long gslbLoadBalancerId) { + this.gslbLoadBalancerId = gslbLoadBalancerId; + } + + public boolean isRevoke() { + return revoke; + } + + public void setRevoke(boolean revoke) { + this.revoke = revoke; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleDao.java b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleDao.java new file mode 100644 index 0000000..1b44caa --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleDao.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 org.apache.cloudstack.region.gslb; + +import com.cloud.utils.db.GenericDao; + +import java.util.List; + +public interface GlobalLoadBalancerRuleDao extends GenericDao { + + List listByRegionId(int regionId); + GlobalLoadBalancerRuleVO findByDomainName(String domainName); +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleVO.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleVO.java b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleVO.java new file mode 100644 index 0000000..a70b305 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleVO.java @@ -0,0 +1,183 @@ +// 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.region.gslb; + +import com.cloud.region.ha.GlobalLoadBalancerRule; + +import javax.persistence.*; +import java.util.UUID; + +@Entity +@Table(name=("global_load_balancing_rules")) +public class GlobalLoadBalancerRuleVO implements GlobalLoadBalancerRule { + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id") + long id; + + @Column(name="name") + private String name; + + @Column(name="description", length=4096) + private String description; + + @Column(name="algorithm") + private String algorithm; + + @Column(name="persistence") + private String persistence; + + @Column(name="gslb_domain_name") + private String gslbDomain; + + @Column(name="service_type") + private String serviceType; + + @Column(name="region_id") + private int region; + + @Column(name="account_id") + long accountId; + + @Column(name="domain_id", updatable=false) + long domainId; + + @Column(name="uuid") + String uuid; + + @Enumerated(value=EnumType.STRING) + @Column(name="state") + GlobalLoadBalancerRule.State state; + + public GlobalLoadBalancerRuleVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public GlobalLoadBalancerRuleVO(String name, String description, String gslbDomain, String algorithm, + String persistence, String serviceType, int regionId, long accountId, + long domainId, State state) { + this.name =name; + this.description = description; + this.region = regionId; + this.algorithm = algorithm; + this.gslbDomain = gslbDomain; + this.persistence = persistence; + this.accountId = accountId; + this.domainId = domainId; + this.serviceType = serviceType; + this.uuid = UUID.randomUUID().toString(); + this.state = state; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getAlgorithm() { + return algorithm; + } + + @Override + public String getPersistence() { + return persistence; + } + + @Override + public int getRegion() { + return region; + } + + @Override + public long getAccountId() { + return accountId; + } + + @Override + public long getDomainId() { + return domainId; + } + + public void setName(String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setAlgorithm(String algorithm) { + this.algorithm = algorithm; + } + + public void setPersistence(String persistence) { + this.persistence = persistence; + } + + @Override + public String getGslbDomain() { + return gslbDomain; + } + + public void setGslbDomain(String gslbDomain) { + this.gslbDomain = gslbDomain; + } + + public void setRegion(int region) { + this.region =region; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return this.uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + @Override + public String getServiceType() { + return serviceType; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + public void setState(GlobalLoadBalancerRule.State state) { + this.state = state; + } + + @Override + public GlobalLoadBalancerRule.State getState() { + return state; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/alert/dao/AlertDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/alert/dao/AlertDao.java b/server/src/com/cloud/alert/dao/AlertDao.java deleted file mode 100755 index fda814d..0000000 --- a/server/src/com/cloud/alert/dao/AlertDao.java +++ /dev/null @@ -1,33 +0,0 @@ -// 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.alert.dao; - -import java.util.Date; -import java.util.List; - -import com.cloud.alert.AlertVO; -import com.cloud.utils.db.GenericDao; - -public interface AlertDao extends GenericDao { - AlertVO getLastAlert(short type, long dataCenterId, Long podId, Long clusterId); - // This is for backward compatibility - AlertVO getLastAlert(short type, long dataCenterId, Long podId); - - public boolean deleteAlert(List Ids, String type, Date olderThan, Long zoneId); - public boolean archiveAlert(List Ids, String type, Date olderThan, Long zoneId); - public List listOlderAlerts(Date oldTime); -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/alert/dao/AlertDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/alert/dao/AlertDaoImpl.java b/server/src/com/cloud/alert/dao/AlertDaoImpl.java deleted file mode 100755 index 4b9bc6a..0000000 --- a/server/src/com/cloud/alert/dao/AlertDaoImpl.java +++ /dev/null @@ -1,156 +0,0 @@ -// 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.alert.dao; - -import java.util.Date; -import java.util.List; - -import javax.ejb.Local; - -import org.springframework.stereotype.Component; - -import com.cloud.alert.AlertVO; -import com.cloud.utils.db.Filter; -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.utils.db.Transaction; - -@Component -@Local(value = { AlertDao.class }) -public class AlertDaoImpl extends GenericDaoBase implements AlertDao { - - protected final SearchBuilder AlertSearchByIdsAndType; - - public AlertDaoImpl() { - AlertSearchByIdsAndType = createSearchBuilder(); - AlertSearchByIdsAndType.and("id", AlertSearchByIdsAndType.entity().getId(), Op.IN); - AlertSearchByIdsAndType.and("type", AlertSearchByIdsAndType.entity().getType(), Op.EQ); - AlertSearchByIdsAndType.and("createdDateL", AlertSearchByIdsAndType.entity().getCreatedDate(), Op.LT); - AlertSearchByIdsAndType.and("data_center_id", AlertSearchByIdsAndType.entity().getDataCenterId(), Op.EQ); - AlertSearchByIdsAndType.done(); - } - - @Override - public AlertVO getLastAlert(short type, long dataCenterId, Long podId, Long clusterId) { - Filter searchFilter = new Filter(AlertVO.class, "createdDate", Boolean.FALSE, Long.valueOf(0), Long.valueOf(1)); - SearchCriteria sc = createSearchCriteria(); - - sc.addAnd("type", SearchCriteria.Op.EQ, Short.valueOf(type)); - sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, Long.valueOf(dataCenterId)); - if (podId != null) { - sc.addAnd("podId", SearchCriteria.Op.EQ, podId); - } - if (clusterId != null) { - sc.addAnd("clusterId", SearchCriteria.Op.EQ, clusterId); - } - - List alerts = listBy(sc, searchFilter); - if ((alerts != null) && !alerts.isEmpty()) { - return alerts.get(0); - } - return null; - } - - @Override - public AlertVO getLastAlert(short type, long dataCenterId, Long podId) { - Filter searchFilter = new Filter(AlertVO.class, "createdDate", Boolean.FALSE, Long.valueOf(0), Long.valueOf(1)); - SearchCriteria sc = createSearchCriteria(); - - sc.addAnd("type", SearchCriteria.Op.EQ, Short.valueOf(type)); - sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, Long.valueOf(dataCenterId)); - if (podId != null) { - sc.addAnd("podId", SearchCriteria.Op.EQ, podId); - } - - List alerts = listBy(sc, searchFilter); - if ((alerts != null) && !alerts.isEmpty()) { - return alerts.get(0); - } - return null; - } - - @Override - public boolean archiveAlert(List Ids, String type, Date olderThan, Long zoneId) { - SearchCriteria sc = AlertSearchByIdsAndType.create(); - - if (Ids != null) { - sc.setParameters("id", Ids.toArray(new Object[Ids.size()])); - } - if(type != null) { - sc.setParameters("type", type); - } - if(zoneId != null) { - sc.setParameters("data_center_id", zoneId); - } - if(olderThan != null) { - sc.setParameters("createdDateL", olderThan); - } - boolean result = true;; - List alerts = listBy(sc); - if (Ids != null && alerts.size() < Ids.size()) { - result = false; - return result; - } - Transaction txn = Transaction.currentTxn(); - txn.start(); - for (AlertVO alert : alerts) { - alert = lockRow(alert.getId(), true); - alert.setArchived(true); - update(alert.getId(), alert); - txn.commit(); - } - txn.close(); - return result; - } - - @Override - public boolean deleteAlert(List ids, String type, Date olderThan, Long zoneId) { - SearchCriteria sc = AlertSearchByIdsAndType.create(); - - if (ids != null) { - sc.setParameters("id", ids.toArray(new Object[ids.size()])); - } - if(type != null) { - sc.setParameters("type", type); - } - if(zoneId != null) { - sc.setParameters("data_center_id", zoneId); - } - if(olderThan != null) { - sc.setParameters("createdDateL", olderThan); - } - boolean result = true; - List alerts = listBy(sc); - if (ids != null && alerts.size() < ids.size()) { - result = false; - return result; - } - remove(sc); - return result; - } - - @Override - public List listOlderAlerts(Date oldTime) { - if (oldTime == null) return null; - SearchCriteria sc = createSearchCriteria(); - sc.addAnd("createDate", SearchCriteria.Op.LT, oldTime); - return listIncludingRemovedBy(sc, null); - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/capacity/dao/CapacityDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/capacity/dao/CapacityDao.java b/server/src/com/cloud/capacity/dao/CapacityDao.java deleted file mode 100755 index 04466f4..0000000 --- a/server/src/com/cloud/capacity/dao/CapacityDao.java +++ /dev/null @@ -1,45 +0,0 @@ -// 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.capacity.dao; - -import java.util.List; -import java.util.Map; - -import com.cloud.capacity.CapacityVO; -import com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity; -import com.cloud.utils.Pair; -import com.cloud.utils.db.GenericDao; - -public interface CapacityDao extends GenericDao { - CapacityVO findByHostIdType(Long hostId, short capacityType); - List listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone); - List listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType); - boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId, Long hostId); - List findByClusterPodZone(Long zoneId, Long podId, Long clusterId); - List findNonSharedStorageForClusterPodZone(Long zoneId,Long podId, Long clusterId); - Pair, Map> orderClustersByAggregateCapacity(long id, short capacityType, boolean isZone); - List findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId); - - List listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType); - Pair, Map> orderPodsByAggregateCapacity(long zoneId, short capacityType); - List findCapacityBy(Integer capacityType, Long zoneId, - Long podId, Long clusterId, String resourceState); - List listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, Long clusterId, int level, Long limit); - void updateCapacityState(Long dcId, Long podId, Long clusterId, - Long hostId, String capacityState); - List listClustersCrossingThreshold(short capacityType, Long zoneId, String ConfigName, long computeRequested); -}