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 8042C10344 for ; Tue, 7 May 2013 22:01:21 +0000 (UTC) Received: (qmail 54789 invoked by uid 500); 7 May 2013 22:01:18 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 54733 invoked by uid 500); 7 May 2013 22:01:18 -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 54689 invoked by uid 99); 7 May 2013 22:01:17 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 May 2013 22:01:17 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A4701888EAB; Tue, 7 May 2013 22:01:17 +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: Tue, 07 May 2013 22:01:20 -0000 Message-Id: <1b5f8d53fbb6455b9bfc88fe2349bd5d@git.apache.org> In-Reply-To: <3e79178248384d298e6dc53296a07b1f@git.apache.org> References: <3e79178248384d298e6dc53296a07b1f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [04/72] [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/d015fb35/server/src/com/cloud/storage/dao/SnapshotDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/SnapshotDao.java b/server/src/com/cloud/storage/dao/SnapshotDao.java deleted file mode 100644 index 3ac9e77..0000000 --- a/server/src/com/cloud/storage/dao/SnapshotDao.java +++ /dev/null @@ -1,54 +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.storage.dao; - -import com.cloud.storage.Snapshot; -import com.cloud.storage.Snapshot.Type; -import com.cloud.storage.SnapshotVO; -import com.cloud.utils.db.Filter; -import com.cloud.utils.db.GenericDao; -import com.cloud.utils.fsm.StateDao; - -import java.util.List; - -public interface SnapshotDao extends GenericDao, StateDao { - List listByVolumeId(long volumeId); - List listByVolumeId(Filter filter, long volumeId); - SnapshotVO findNextSnapshot(long parentSnapId); - long getLastSnapshot(long volumeId, long snapId); - List listByVolumeIdType(long volumeId, Type type); - List listByVolumeIdIncludingRemoved(long volumeId); - List listByBackupUuid(long volumeId, String backupUuid); - long updateSnapshotVersion(long volumeId, String from, String to); - List listByVolumeIdVersion(long volumeId, String version); - Long getSecHostId(long volumeId); - long updateSnapshotSecHost(long dcId, long secHostId); - List listByHostId(Filter filter, long hostId); - List listByHostId(long hostId); - public Long countSnapshotsForAccount(long accountId); - List listByInstanceId(long instanceId, Snapshot.State... status); - List listByStatus(long volumeId, Snapshot.State... status); - List listAllByStatus(Snapshot.State... status); - /** - * Gets the Total Secondary Storage space (in bytes) used by snapshots allocated for an account - * - * @param account - * @return total Secondary Storage space allocated - */ - long secondaryStorageUsedForAccount(long accountId); - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java b/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java deleted file mode 100644 index f55663f..0000000 --- a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java +++ /dev/null @@ -1,357 +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.storage.dao; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.List; - -import javax.annotation.PostConstruct; -import javax.ejb.Local; -import javax.inject.Inject; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import com.cloud.server.ResourceTag.TaggedResourceType; -import com.cloud.storage.Snapshot; -import com.cloud.storage.Snapshot.Event; -import com.cloud.storage.Snapshot.State; -import com.cloud.storage.Snapshot.Type; -import com.cloud.storage.SnapshotVO; -import com.cloud.storage.Volume; -import com.cloud.storage.VolumeVO; -import com.cloud.storage.dao.VolumeDaoImpl.SumCount; -import com.cloud.tags.dao.ResourceTagDao; -import com.cloud.utils.db.DB; -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.SearchCriteria.Op; -import com.cloud.utils.db.Transaction; -import com.cloud.vm.VMInstanceVO; -import com.cloud.vm.dao.VMInstanceDao; - -@Component -@Local (value={SnapshotDao.class}) -public class SnapshotDaoImpl extends GenericDaoBase implements SnapshotDao { - public static final Logger s_logger = Logger.getLogger(SnapshotDaoImpl.class.getName()); - private static final String GET_LAST_SNAPSHOT = "SELECT id FROM snapshots where volume_id = ? AND id != ? AND path IS NOT NULL ORDER BY created DESC"; - private static final String UPDATE_SNAPSHOT_VERSION = "UPDATE snapshots SET version = ? WHERE volume_id = ? AND version = ?"; - private static final String GET_SECHOST_ID = "SELECT sechost_id FROM snapshots where volume_id = ? AND backup_snap_id IS NOT NULL AND sechost_id IS NOT NULL LIMIT 1"; - private static final String UPDATE_SECHOST_ID = "UPDATE snapshots SET sechost_id = ? WHERE data_center_id = ?"; - - private SearchBuilder VolumeIdSearch; - private SearchBuilder VolumeIdTypeSearch; - private SearchBuilder ParentIdSearch; - private SearchBuilder backupUuidSearch; - private SearchBuilder VolumeIdVersionSearch; - private SearchBuilder HostIdSearch; - private SearchBuilder AccountIdSearch; - private SearchBuilder InstanceIdSearch; - private SearchBuilder StatusSearch; - private GenericSearchBuilder CountSnapshotsByAccount; - private GenericSearchBuilder secondaryStorageSearch; - @Inject ResourceTagDao _tagsDao; - @Inject protected VMInstanceDao _instanceDao; - @Inject protected VolumeDao _volumeDao; - - @Override - public SnapshotVO findNextSnapshot(long snapshotId) { - SearchCriteria sc = ParentIdSearch.create(); - sc.setParameters("prevSnapshotId", snapshotId); - return findOneIncludingRemovedBy(sc); - } - - @Override - public List listByBackupUuid(long volumeId, String backupUuid) { - SearchCriteria sc = backupUuidSearch.create(); - sc.setParameters("backupUuid", backupUuid); - return listBy(sc, null); - } - - @Override - public List listByVolumeIdType(long volumeId, Type type ) { - return listByVolumeIdType(null, volumeId, type); - } - - - @Override - public List listByVolumeIdVersion(long volumeId, String version ) { - return listByVolumeIdVersion(null, volumeId, version); - } - - @Override - public List listByVolumeId(long volumeId) { - return listByVolumeId(null, volumeId); - } - - @Override - public List listByVolumeId(Filter filter, long volumeId ) { - SearchCriteria sc = VolumeIdSearch.create(); - sc.setParameters("volumeId", volumeId); - return listBy(sc, filter); - } - - @Override - public List listByHostId(long hostId) { - return listByHostId(null, hostId); - } - - @Override - public List listByHostId(Filter filter, long hostId ) { - SearchCriteria sc = HostIdSearch.create(); - sc.setParameters("hostId", hostId); - sc.setParameters("status", Snapshot.State.BackedUp); - return listBy(sc, filter); - } - - @Override - public List listByVolumeIdIncludingRemoved(long volumeId) { - SearchCriteria sc = VolumeIdSearch.create(); - sc.setParameters("volumeId", volumeId); - return listIncludingRemovedBy(sc, null); - } - - public List listByVolumeIdType(Filter filter, long volumeId, Type type ) { - SearchCriteria sc = VolumeIdTypeSearch.create(); - sc.setParameters("volumeId", volumeId); - sc.setParameters("type", type.ordinal()); - return listBy(sc, filter); - } - - public List listByVolumeIdVersion(Filter filter, long volumeId, String version ) { - SearchCriteria sc = VolumeIdVersionSearch.create(); - sc.setParameters("volumeId", volumeId); - sc.setParameters("version", version); - return listBy(sc, filter); - } - - public SnapshotDaoImpl() { - } - - @PostConstruct - protected void init() { - VolumeIdSearch = createSearchBuilder(); - VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - VolumeIdSearch.done(); - - HostIdSearch = createSearchBuilder(); - HostIdSearch.and("hostId", HostIdSearch.entity().getSecHostId(), SearchCriteria.Op.EQ); - HostIdSearch.and("status", HostIdSearch.entity().getState(), SearchCriteria.Op.EQ); - HostIdSearch.done(); - - VolumeIdTypeSearch = createSearchBuilder(); - VolumeIdTypeSearch.and("volumeId", VolumeIdTypeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - VolumeIdTypeSearch.and("type", VolumeIdTypeSearch.entity().getsnapshotType(), SearchCriteria.Op.EQ); - VolumeIdTypeSearch.done(); - - VolumeIdVersionSearch = createSearchBuilder(); - VolumeIdVersionSearch.and("volumeId", VolumeIdVersionSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - VolumeIdVersionSearch.and("version", VolumeIdVersionSearch.entity().getVersion(), SearchCriteria.Op.EQ); - VolumeIdVersionSearch.done(); - - ParentIdSearch = createSearchBuilder(); - ParentIdSearch.and("prevSnapshotId", ParentIdSearch.entity().getPrevSnapshotId(), SearchCriteria.Op.EQ); - ParentIdSearch.done(); - - backupUuidSearch = createSearchBuilder(); - backupUuidSearch.and("backupUuid", backupUuidSearch.entity().getBackupSnapshotId(), SearchCriteria.Op.EQ); - backupUuidSearch.done(); - - AccountIdSearch = createSearchBuilder(); - AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); - AccountIdSearch.done(); - - StatusSearch = createSearchBuilder(); - StatusSearch.and("volumeId", StatusSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - StatusSearch.and("status", StatusSearch.entity().getState(), SearchCriteria.Op.IN); - StatusSearch.done(); - - CountSnapshotsByAccount = createSearchBuilder(Long.class); - CountSnapshotsByAccount.select(null, Func.COUNT, null); - CountSnapshotsByAccount.and("account", CountSnapshotsByAccount.entity().getAccountId(), SearchCriteria.Op.EQ); - CountSnapshotsByAccount.and("removed", CountSnapshotsByAccount.entity().getRemoved(), SearchCriteria.Op.NULL); - CountSnapshotsByAccount.done(); - - InstanceIdSearch = createSearchBuilder(); - InstanceIdSearch.and("status", InstanceIdSearch.entity().getState(), SearchCriteria.Op.IN); - - SearchBuilder instanceSearch = _instanceDao.createSearchBuilder(); - instanceSearch.and("instanceId", instanceSearch.entity().getId(), SearchCriteria.Op.EQ); - - SearchBuilder volumeSearch = _volumeDao.createSearchBuilder(); - volumeSearch.and("state", volumeSearch.entity().getState(), SearchCriteria.Op.EQ); - volumeSearch.join("instanceVolumes", instanceSearch, instanceSearch.entity().getId(), volumeSearch.entity().getInstanceId(), JoinType.INNER); - - InstanceIdSearch.join("instanceSnapshots", volumeSearch, volumeSearch.entity().getId(), InstanceIdSearch.entity().getVolumeId(), JoinType.INNER); - InstanceIdSearch.done(); - - secondaryStorageSearch = createSearchBuilder(SumCount.class); - secondaryStorageSearch.select("sum", Func.SUM, secondaryStorageSearch.entity().getSize()); - secondaryStorageSearch.and("accountId", secondaryStorageSearch.entity().getAccountId(), Op.EQ); - secondaryStorageSearch.and("isRemoved", secondaryStorageSearch.entity().getRemoved(), Op.NULL); - secondaryStorageSearch.done(); - } - - @Override - public Long getSecHostId(long volumeId) { - - Transaction txn = Transaction.currentTxn(); - PreparedStatement pstmt = null; - String sql = GET_SECHOST_ID; - try { - pstmt = txn.prepareAutoCloseStatement(sql); - pstmt.setLong(1, volumeId); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) { - return rs.getLong(1); - } - } catch (Exception ex) { - } - return null; - } - @Override - public long getLastSnapshot(long volumeId, long snapId) { - Transaction txn = Transaction.currentTxn(); - PreparedStatement pstmt = null; - String sql = GET_LAST_SNAPSHOT; - try { - pstmt = txn.prepareAutoCloseStatement(sql); - pstmt.setLong(1, volumeId); - pstmt.setLong(2, snapId); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) { - return rs.getLong(1); - } - } catch (Exception ex) { - s_logger.error("error getting last snapshot", ex); - } - return 0; - } - - @Override - public long updateSnapshotVersion(long volumeId, String from, String to) { - Transaction txn = Transaction.currentTxn(); - PreparedStatement pstmt = null; - String sql = UPDATE_SNAPSHOT_VERSION; - try { - pstmt = txn.prepareAutoCloseStatement(sql); - pstmt.setString(1, to); - pstmt.setLong(2, volumeId); - pstmt.setString(3, from); - pstmt.executeUpdate(); - return 1; - } catch (Exception ex) { - s_logger.error("error getting last snapshot", ex); - } - return 0; - } - - @Override - public long updateSnapshotSecHost(long dcId, long secHostId) { - Transaction txn = Transaction.currentTxn(); - PreparedStatement pstmt = null; - String sql = UPDATE_SECHOST_ID; - try { - pstmt = txn.prepareAutoCloseStatement(sql); - pstmt.setLong(1, secHostId); - pstmt.setLong(2, dcId); - pstmt.executeUpdate(); - return 1; - } catch (Exception ex) { - s_logger.error("error set secondary storage host id", ex); - } - return 0; - } - - @Override - public Long countSnapshotsForAccount(long accountId) { - SearchCriteria sc = CountSnapshotsByAccount.create(); - sc.setParameters("account", accountId); - return customSearch(sc, null).get(0); - } - - @Override - public List listByInstanceId(long instanceId, Snapshot.State... status) { - SearchCriteria sc = this.InstanceIdSearch.create(); - - if (status != null && status.length != 0) { - sc.setParameters("status", (Object[])status); - } - - sc.setJoinParameters("instanceSnapshots", "state", Volume.State.Ready); - sc.setJoinParameters("instanceVolumes", "instanceId", instanceId); - return listBy(sc, null); - } - - @Override - public List listByStatus(long volumeId, Snapshot.State... status) { - SearchCriteria sc = this.StatusSearch.create(); - sc.setParameters("volumeId", volumeId); - sc.setParameters("status", (Object[])status); - return listBy(sc, null); - } - - @Override - @DB - public boolean remove(Long id) { - Transaction txn = Transaction.currentTxn(); - txn.start(); - SnapshotVO entry = findById(id); - if (entry != null) { - _tagsDao.removeByIdAndType(id, TaggedResourceType.Snapshot); - } - boolean result = super.remove(id); - txn.commit(); - return result; - } - - @Override - public List listAllByStatus(Snapshot.State... status) { - SearchCriteria sc = this.StatusSearch.create(); - sc.setParameters("status", (Object[])status); - return listBy(sc, null); - } - - @Override - public boolean updateState(State currentState, Event event, State nextState, SnapshotVO snapshot, Object data) { - Transaction txn = Transaction.currentTxn(); - txn.start(); - SnapshotVO snapshotVO = (SnapshotVO)snapshot; - snapshotVO.setState(nextState); - super.update(snapshotVO.getId(), snapshotVO); - txn.commit(); - return true; - } - - @Override - public long secondaryStorageUsedForAccount(long accountId) { - SearchCriteria sc = secondaryStorageSearch.create(); - sc.setParameters("accountId", accountId); - List storageSpace = customSearch(sc, null); - if (storageSpace != null) { - return storageSpace.get(0).sum; - } else { - return 0; - } - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/SnapshotPolicyDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/SnapshotPolicyDao.java b/server/src/com/cloud/storage/dao/SnapshotPolicyDao.java deleted file mode 100644 index 467d491..0000000 --- a/server/src/com/cloud/storage/dao/SnapshotPolicyDao.java +++ /dev/null @@ -1,38 +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.storage.dao; - -import java.util.List; - -import com.cloud.storage.SnapshotPolicyVO; -import com.cloud.utils.DateUtil.IntervalType; -import com.cloud.utils.Pair; -import com.cloud.utils.db.Filter; -import com.cloud.utils.db.GenericDao; - -/* - * Data Access Object for snapshot_policy table - */ -public interface SnapshotPolicyDao extends GenericDao { - List listByVolumeId(long volumeId); - List listByVolumeId(long volumeId, Filter filter); - Pair, Integer> listAndCountByVolumeId(long volumeId); - Pair, Integer> listAndCountByVolumeId(long volumeId, Filter filter); - SnapshotPolicyVO findOneByVolumeInterval(long volumeId, IntervalType intvType); - List listActivePolicies(); - SnapshotPolicyVO findOneByVolume(long volumeId); -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java b/server/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java deleted file mode 100644 index 3f894a2..0000000 --- a/server/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java +++ /dev/null @@ -1,105 +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.storage.dao; - - -import java.util.List; - -import javax.ejb.Local; - -import org.springframework.stereotype.Component; - -import com.cloud.storage.SnapshotPolicyVO; -import com.cloud.utils.DateUtil.IntervalType; -import com.cloud.utils.Pair; -import com.cloud.utils.db.Filter; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; - -@Component -@Local (value={SnapshotPolicyDao.class}) -public class SnapshotPolicyDaoImpl extends GenericDaoBase implements SnapshotPolicyDao { - private final SearchBuilder VolumeIdSearch; - private final SearchBuilder VolumeIdIntervalSearch; - private final SearchBuilder ActivePolicySearch; - - @Override - public SnapshotPolicyVO findOneByVolumeInterval(long volumeId, IntervalType intvType) { - SearchCriteria sc = VolumeIdIntervalSearch.create(); - sc.setParameters("volumeId", volumeId); - sc.setParameters("interval", intvType.ordinal()); - return findOneBy(sc); - } - - @Override - public SnapshotPolicyVO findOneByVolume(long volumeId) { - SearchCriteria sc = VolumeIdSearch.create(); - sc.setParameters("volumeId", volumeId); - sc.setParameters("active", true); - return findOneBy(sc); - } - - @Override - public List listByVolumeId(long volumeId) { - return listByVolumeId(volumeId, null); - } - - @Override - public List listByVolumeId(long volumeId, Filter filter) { - SearchCriteria sc = VolumeIdSearch.create(); - sc.setParameters("volumeId", volumeId); - sc.setParameters("active", true); - return listBy(sc, filter); - } - - @Override - public Pair, Integer> listAndCountByVolumeId(long volumeId) { - return listAndCountByVolumeId(volumeId, null); - } - - @Override - public Pair, Integer> listAndCountByVolumeId(long volumeId, Filter filter) { - SearchCriteria sc = VolumeIdSearch.create(); - sc.setParameters("volumeId", volumeId); - sc.setParameters("active", true); - return searchAndCount(sc, filter); - } - - protected SnapshotPolicyDaoImpl() { - VolumeIdSearch = createSearchBuilder(); - VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - VolumeIdSearch.and("active", VolumeIdSearch.entity().isActive(), SearchCriteria.Op.EQ); - VolumeIdSearch.done(); - - VolumeIdIntervalSearch = createSearchBuilder(); - VolumeIdIntervalSearch.and("volumeId", VolumeIdIntervalSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - VolumeIdIntervalSearch.and("interval", VolumeIdIntervalSearch.entity().getInterval(), SearchCriteria.Op.EQ); - VolumeIdIntervalSearch.done(); - - ActivePolicySearch = createSearchBuilder(); - ActivePolicySearch.and("active", ActivePolicySearch.entity().isActive(), SearchCriteria.Op.EQ); - ActivePolicySearch.done(); - } - - @Override - public List listActivePolicies() { - SearchCriteria sc = ActivePolicySearch.create(); - sc.setParameters("active", true); - return listIncludingRemovedBy(sc); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/SnapshotScheduleDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/SnapshotScheduleDao.java b/server/src/com/cloud/storage/dao/SnapshotScheduleDao.java deleted file mode 100644 index 0419e28..0000000 --- a/server/src/com/cloud/storage/dao/SnapshotScheduleDao.java +++ /dev/null @@ -1,41 +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.storage.dao; - - -import java.util.Date; -import java.util.List; -import com.cloud.storage.SnapshotPolicyVO; -import com.cloud.storage.SnapshotScheduleVO; -import com.cloud.utils.db.GenericDao; - -/* - * Data Access Object for snapshot_schedule table - */ -public interface SnapshotScheduleDao extends GenericDao { - - List getCoincidingSnapshotSchedules(long volumeId, Date date); - - List getSchedulesToExecute(Date currentTimestamp); - - SnapshotScheduleVO getCurrentSchedule(Long volumeId, Long policyId, boolean executing); - - SnapshotScheduleVO findOneByVolume(long volumeId); - - SnapshotScheduleVO findOneByVolumePolicy(long volumeId, long policyId); - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/SnapshotScheduleDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/SnapshotScheduleDaoImpl.java b/server/src/com/cloud/storage/dao/SnapshotScheduleDaoImpl.java deleted file mode 100644 index c01644e..0000000 --- a/server/src/com/cloud/storage/dao/SnapshotScheduleDaoImpl.java +++ /dev/null @@ -1,134 +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.storage.dao; - -import java.util.Date; -import java.util.List; - -import javax.ejb.Local; - -import org.springframework.stereotype.Component; - -import com.cloud.storage.Snapshot; -import com.cloud.storage.SnapshotScheduleVO; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; - -@Component -@Local (value={SnapshotScheduleDao.class}) -public class SnapshotScheduleDaoImpl extends GenericDaoBase implements SnapshotScheduleDao { - protected final SearchBuilder executableSchedulesSearch; - protected final SearchBuilder coincidingSchedulesSearch; - private final SearchBuilder VolumeIdSearch; - private final SearchBuilder VolumeIdPolicyIdSearch; - - - protected SnapshotScheduleDaoImpl() { - - executableSchedulesSearch = createSearchBuilder(); - executableSchedulesSearch.and("scheduledTimestamp", executableSchedulesSearch.entity().getScheduledTimestamp(), SearchCriteria.Op.LT); - executableSchedulesSearch.and("asyncJobId", executableSchedulesSearch.entity().getAsyncJobId(), SearchCriteria.Op.NULL); - executableSchedulesSearch.done(); - - coincidingSchedulesSearch = createSearchBuilder(); - coincidingSchedulesSearch.and("volumeId", coincidingSchedulesSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - coincidingSchedulesSearch.and("scheduledTimestamp", coincidingSchedulesSearch.entity().getScheduledTimestamp(), SearchCriteria.Op.LT); - coincidingSchedulesSearch.and("asyncJobId", coincidingSchedulesSearch.entity().getAsyncJobId(), SearchCriteria.Op.NULL); - coincidingSchedulesSearch.done(); - - VolumeIdSearch = createSearchBuilder(); - VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - VolumeIdSearch.done(); - - VolumeIdPolicyIdSearch = createSearchBuilder(); - VolumeIdPolicyIdSearch.and("volumeId", VolumeIdPolicyIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - VolumeIdPolicyIdSearch.and("policyId", VolumeIdPolicyIdSearch.entity().getPolicyId(), SearchCriteria.Op.EQ); - VolumeIdPolicyIdSearch.done(); - - } - - /** - * {@inheritDoc} - */ - @Override - public List getCoincidingSnapshotSchedules(long volumeId, Date date) { - SearchCriteria sc = coincidingSchedulesSearch.create(); - sc.setParameters("volumeId", volumeId); - sc.setParameters("scheduledTimestamp", date); - // Don't return manual snapshots. They will be executed through another code path. - sc.addAnd("policyId", SearchCriteria.Op.NEQ, 1L); - return listBy(sc); - } - - - @Override - public SnapshotScheduleVO findOneByVolume(long volumeId) { - SearchCriteria sc = VolumeIdSearch.create(); - sc.setParameters("volumeId", volumeId); - return findOneBy(sc); - } - - - @Override - public SnapshotScheduleVO findOneByVolumePolicy(long volumeId, long policyId) { - SearchCriteria sc = VolumeIdPolicyIdSearch.create(); - sc.setParameters("volumeId", volumeId); - sc.setParameters("policyId", policyId); - return findOneBy(sc); - } - /** - * {@inheritDoc} - */ - @Override - public List getSchedulesToExecute(Date currentTimestamp) { - SearchCriteria sc = executableSchedulesSearch.create(); - sc.setParameters("scheduledTimestamp", currentTimestamp); - return listBy(sc); - } - - /** - * {@inheritDoc} - */ - @Override - public SnapshotScheduleVO getCurrentSchedule(Long volumeId, Long policyId, boolean executing) { - assert volumeId != null; - SearchCriteria sc = createSearchCriteria(); - SearchCriteria.Op op = executing ? SearchCriteria.Op.NNULL : SearchCriteria.Op.NULL; - sc.addAnd("volumeId", SearchCriteria.Op.EQ, volumeId); - if (policyId != null) { - sc.addAnd("policyId", SearchCriteria.Op.EQ, policyId); - if (policyId != Snapshot.MANUAL_POLICY_ID) { - // manual policies aren't scheduled by the snapshot poller, so don't look for the jobId here - sc.addAnd("asyncJobId", op); - } - } else { - sc.addAnd("asyncJobId", op); - } - - List snapshotSchedules = listBy(sc); - // This will return only one schedule because of a DB uniqueness constraint. - assert (snapshotSchedules.size() <= 1); - if (snapshotSchedules.isEmpty()) { - return null; - } - else { - return snapshotSchedules.get(0); - } - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java b/server/src/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java deleted file mode 100644 index 38b5253..0000000 --- a/server/src/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java +++ /dev/null @@ -1,85 +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.storage.dao; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.ejb.Local; - -import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; -import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; -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.Transaction; - -@Component -@Local(value=StoragePoolDetailsDao.class) -public class StoragePoolDetailsDaoImpl extends GenericDaoBase implements StoragePoolDetailsDao { - - protected final SearchBuilder PoolSearch; - - protected StoragePoolDetailsDaoImpl() { - super(); - PoolSearch = createSearchBuilder(); - PoolSearch.and("pool", PoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ); - PoolSearch.and("name", PoolSearch.entity().getName(), SearchCriteria.Op.EQ); - PoolSearch.done(); - } - - @Override - public void update(long poolId, Map details) { - Transaction txn = Transaction.currentTxn(); - SearchCriteria sc = PoolSearch.create(); - sc.setParameters("pool", poolId); - - txn.start(); - expunge(sc); - for (Map.Entry entry : details.entrySet()) { - StoragePoolDetailVO detail = new StoragePoolDetailVO(poolId, entry.getKey(), entry.getValue()); - persist(detail); - } - txn.commit(); - } - - @Override - public Map getDetails(long poolId) { - SearchCriteria sc = PoolSearch.create(); - sc.setParameters("pool", poolId); - - List details = listBy(sc); - Map detailsMap = new HashMap(); - for (StoragePoolDetailVO detail : details) { - detailsMap.put(detail.getName(), detail.getValue()); - } - - return detailsMap; - } - - @Override - public StoragePoolDetailVO findDetail(long poolId, String name) { - SearchCriteria sc = PoolSearch.create(); - sc.setParameters("pool", poolId); - sc.setParameters("name", name); - - return findOneIncludingRemovedBy(sc); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/StoragePoolHostDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/StoragePoolHostDao.java b/server/src/com/cloud/storage/dao/StoragePoolHostDao.java deleted file mode 100644 index 8dd10a7..0000000 --- a/server/src/com/cloud/storage/dao/StoragePoolHostDao.java +++ /dev/null @@ -1,42 +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.storage.dao; - -import java.util.List; - -import com.cloud.host.Status; -import com.cloud.storage.StoragePoolHostVO; -import com.cloud.utils.Pair; -import com.cloud.utils.db.GenericDao; - -public interface StoragePoolHostDao extends GenericDao { - public List listByPoolId(long id); - - public List listByHostIdIncludingRemoved(long hostId); - - public StoragePoolHostVO findByPoolHost(long poolId, long hostId); - - List listByHostStatus(long poolId, Status hostStatus); - - List> getDatacenterStoragePoolHostInfo(long dcId, boolean sharedOnly); - - public void deletePrimaryRecordsForHost(long hostId); - - public void deleteStoragePoolHostDetails(long hostId, long poolId); - - List listByHostId(long hostId); -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/StoragePoolHostDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/StoragePoolHostDaoImpl.java b/server/src/com/cloud/storage/dao/StoragePoolHostDaoImpl.java deleted file mode 100644 index 4f509d1..0000000 --- a/server/src/com/cloud/storage/dao/StoragePoolHostDaoImpl.java +++ /dev/null @@ -1,184 +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.storage.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.host.Status; -import com.cloud.storage.StoragePoolHostVO; -import com.cloud.utils.Pair; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.Transaction; - -@Component -@Local(value = { StoragePoolHostDao.class }) -public class StoragePoolHostDaoImpl extends GenericDaoBase implements StoragePoolHostDao { - public static final Logger s_logger = Logger.getLogger(StoragePoolHostDaoImpl.class.getName()); - - protected final SearchBuilder PoolSearch; - protected final SearchBuilder HostSearch; - protected final SearchBuilder PoolHostSearch; - - protected static final String HOST_FOR_POOL_SEARCH = "SELECT * FROM storage_pool_host_ref ph, host h where ph.host_id = h.id and ph.pool_id=? and h.status=? "; - - protected static final String STORAGE_POOL_HOST_INFO = "SELECT p.data_center_id, count(ph.host_id) " + " FROM storage_pool p, storage_pool_host_ref ph " - + " WHERE p.id = ph.pool_id AND p.data_center_id = ? " + " GROUP by p.data_center_id"; - - protected static final String SHARED_STORAGE_POOL_HOST_INFO = "SELECT p.data_center_id, count(ph.host_id) " + " FROM storage_pool p, storage_pool_host_ref ph " - + " WHERE p.id = ph.pool_id AND p.data_center_id = ? " + " AND p.pool_type NOT IN ('LVM', 'Filesystem')" + " GROUP by p.data_center_id"; - - protected static final String DELETE_PRIMARY_RECORDS = "DELETE " + "FROM storage_pool_host_ref " + "WHERE host_id = ?"; - - public StoragePoolHostDaoImpl() { - PoolSearch = createSearchBuilder(); - PoolSearch.and("pool_id", PoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ); - PoolSearch.done(); - - HostSearch = createSearchBuilder(); - HostSearch.and("host_id", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); - HostSearch.done(); - - PoolHostSearch = createSearchBuilder(); - PoolHostSearch.and("pool_id", PoolHostSearch.entity().getPoolId(), SearchCriteria.Op.EQ); - PoolHostSearch.and("host_id", PoolHostSearch.entity().getHostId(), SearchCriteria.Op.EQ); - PoolHostSearch.done(); - - } - - @Override - public List listByPoolId(long id) { - SearchCriteria sc = PoolSearch.create(); - sc.setParameters("pool_id", id); - return listIncludingRemovedBy(sc); - } - - @Override - public List listByHostIdIncludingRemoved(long hostId) { - SearchCriteria sc = HostSearch.create(); - sc.setParameters("host_id", hostId); - return listIncludingRemovedBy(sc); - } - - @Override - public List listByHostId(long hostId) { - SearchCriteria sc = HostSearch.create(); - sc.setParameters("host_id", hostId); - return listBy(sc); - } - - @Override - public StoragePoolHostVO findByPoolHost(long poolId, long hostId) { - SearchCriteria sc = PoolHostSearch.create(); - sc.setParameters("pool_id", poolId); - sc.setParameters("host_id", hostId); - return findOneIncludingRemovedBy(sc); - } - - @Override - public List listByHostStatus(long poolId, Status hostStatus) { - Transaction txn = Transaction.currentTxn(); - PreparedStatement pstmt = null; - List result = new ArrayList(); - ResultSet rs = null; - try { - String sql = HOST_FOR_POOL_SEARCH; - pstmt = txn.prepareStatement(sql); - - pstmt.setLong(1, poolId); - pstmt.setString(2, hostStatus.toString()); - rs = pstmt.executeQuery(); - while (rs.next()) { - // result.add(toEntityBean(rs, false)); TODO: this is buggy in GenericDaoBase for hand constructed queries - long id = rs.getLong(1); // ID column - result.add(findById(id)); - } - } catch (Exception e) { - s_logger.warn("Exception: ", e); - } finally { - try { - if (rs != null) { - rs.close(); - } - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - } - } - return result; - - } - - @Override - public List> getDatacenterStoragePoolHostInfo(long dcId, boolean sharedOnly) { - ArrayList> l = new ArrayList>(); - String sql = sharedOnly ? SHARED_STORAGE_POOL_HOST_INFO : STORAGE_POOL_HOST_INFO; - Transaction txn = Transaction.currentTxn(); - ; - PreparedStatement pstmt = null; - try { - pstmt = txn.prepareAutoCloseStatement(sql); - pstmt.setLong(1, dcId); - - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - l.add(new Pair(rs.getLong(1), rs.getInt(2))); - } - } catch (SQLException e) { - } catch (Throwable e) { - } - return l; - } - - /** - * This method deletes the primary records from the host - * - * @param hostId - * -- id of the host - */ - @Override - public void deletePrimaryRecordsForHost(long hostId) { - SearchCriteria sc = HostSearch.create(); - sc.setParameters("host_id", hostId); - Transaction txn = Transaction.currentTxn(); - txn.start(); - remove(sc); - txn.commit(); - } - - @Override - public void deleteStoragePoolHostDetails(long hostId, long poolId) { - SearchCriteria sc = PoolHostSearch.create(); - sc.setParameters("host_id", hostId); - sc.setParameters("pool_id", poolId); - Transaction txn = Transaction.currentTxn(); - txn.start(); - remove(sc); - txn.commit(); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/StoragePoolWorkDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/StoragePoolWorkDao.java b/server/src/com/cloud/storage/dao/StoragePoolWorkDao.java deleted file mode 100644 index c05abf5..0000000 --- a/server/src/com/cloud/storage/dao/StoragePoolWorkDao.java +++ /dev/null @@ -1,38 +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.storage.dao; - -import java.util.List; - -import com.cloud.storage.StoragePoolWorkVO; -import com.cloud.utils.db.GenericDao; -/** - * Data Access Object for storage_pool table - */ -public interface StoragePoolWorkDao extends GenericDao { - - List listPendingWorkForPrepareForMaintenanceByPoolId(long poolId); - - List listPendingWorkForCancelMaintenanceByPoolId(long poolId); - - StoragePoolWorkVO findByPoolIdAndVmId(long poolId, long vmId); - - void removePendingJobsOnMsRestart(long msId, long poolId); - - List searchForPoolIdsForPendingWorkJobs(long msId); - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/StoragePoolWorkDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/StoragePoolWorkDaoImpl.java b/server/src/com/cloud/storage/dao/StoragePoolWorkDaoImpl.java deleted file mode 100644 index 360a814..0000000 --- a/server/src/com/cloud/storage/dao/StoragePoolWorkDaoImpl.java +++ /dev/null @@ -1,136 +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.storage.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.springframework.stereotype.Component; - -import com.cloud.storage.StoragePoolWorkVO; -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 com.cloud.utils.db.Transaction; -import com.cloud.utils.exception.CloudRuntimeException; - -@Component -@Local(value={StoragePoolWorkDao.class}) @DB(txn=false) -public class StoragePoolWorkDaoImpl extends GenericDaoBase implements StoragePoolWorkDao { - - protected final SearchBuilder PendingWorkForPrepareForMaintenanceSearch; - protected final SearchBuilder PendingWorkForCancelMaintenanceSearch; - protected final SearchBuilder PoolAndVmIdSearch; - protected final SearchBuilder PendingJobsForDeadMs; - - private final String FindPoolIds = "SELECT distinct storage_pool_work.pool_id FROM storage_pool_work WHERE mgmt_server_id = ?"; - - protected StoragePoolWorkDaoImpl() { - PendingWorkForPrepareForMaintenanceSearch = createSearchBuilder(); - PendingWorkForPrepareForMaintenanceSearch.and("poolId", PendingWorkForPrepareForMaintenanceSearch.entity().getPoolId(), SearchCriteria.Op.EQ); - PendingWorkForPrepareForMaintenanceSearch.and("stoppedForMaintenance", PendingWorkForPrepareForMaintenanceSearch.entity().isStoppedForMaintenance(), SearchCriteria.Op.EQ); - PendingWorkForPrepareForMaintenanceSearch.and("startedAfterMaintenance", PendingWorkForPrepareForMaintenanceSearch.entity().isStartedAfterMaintenance(), SearchCriteria.Op.EQ); - PendingWorkForPrepareForMaintenanceSearch.done(); - - PendingWorkForCancelMaintenanceSearch = createSearchBuilder(); - PendingWorkForCancelMaintenanceSearch.and("poolId", PendingWorkForCancelMaintenanceSearch.entity().getPoolId(), SearchCriteria.Op.EQ); - PendingWorkForCancelMaintenanceSearch.and("stoppedForMaintenance", PendingWorkForCancelMaintenanceSearch.entity().isStoppedForMaintenance(), SearchCriteria.Op.EQ); - PendingWorkForCancelMaintenanceSearch.and("startedAfterMaintenance", PendingWorkForCancelMaintenanceSearch.entity().isStartedAfterMaintenance(), SearchCriteria.Op.EQ); - PendingWorkForCancelMaintenanceSearch.done(); - - PoolAndVmIdSearch = createSearchBuilder(); - PoolAndVmIdSearch.and("poolId", PoolAndVmIdSearch.entity().getPoolId(), SearchCriteria.Op.EQ); - PoolAndVmIdSearch.and("vmId", PoolAndVmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ); - PoolAndVmIdSearch.done(); - - PendingJobsForDeadMs = createSearchBuilder(); - PendingJobsForDeadMs.and("managementServerId", PendingJobsForDeadMs.entity().getManagementServerId(), SearchCriteria.Op.EQ); - PendingJobsForDeadMs.and("poolId", PendingJobsForDeadMs.entity().getPoolId(), SearchCriteria.Op.EQ); - PendingJobsForDeadMs.and("stoppedForMaintenance", PendingJobsForDeadMs.entity().isStoppedForMaintenance(), SearchCriteria.Op.EQ); - PendingJobsForDeadMs.and("startedAfterMaintenance", PendingJobsForDeadMs.entity().isStartedAfterMaintenance(), SearchCriteria.Op.EQ); - PendingJobsForDeadMs.done(); - - } - - @Override - public List listPendingWorkForPrepareForMaintenanceByPoolId(long poolId) { - SearchCriteria sc = PendingWorkForPrepareForMaintenanceSearch.create(); - sc.setParameters("poolId", poolId); - sc.setParameters("stoppedForMaintenance", false); - sc.setParameters("startedAfterMaintenance", false); - return listBy(sc); - } - - @Override - public List listPendingWorkForCancelMaintenanceByPoolId(long poolId) { - SearchCriteria sc = PendingWorkForCancelMaintenanceSearch.create(); - sc.setParameters("poolId", poolId); - sc.setParameters("stoppedForMaintenance", true); - sc.setParameters("startedAfterMaintenance", false); - return listBy(sc); - } - - @Override - public StoragePoolWorkVO findByPoolIdAndVmId(long poolId, long vmId) { - SearchCriteria sc = PoolAndVmIdSearch.create(); - sc.setParameters("poolId", poolId); - sc.setParameters("vmId", vmId); - return listBy(sc).get(0); - } - - @Override - public void removePendingJobsOnMsRestart(long msId, long poolId) { - //hung jobs are those which are stopped, but never started - SearchCriteria sc = PendingJobsForDeadMs.create(); - sc.setParameters("managementServerId", msId); - sc.setParameters("poolId", poolId); - sc.setParameters("stoppedForMaintenance", true); - sc.setParameters("startedAfterMaintenance", false); - remove(sc); - } - - @Override - @DB - public List searchForPoolIdsForPendingWorkJobs(long msId){ - - StringBuilder sql = new StringBuilder(FindPoolIds); - - Transaction txn = Transaction.currentTxn(); - PreparedStatement pstmt = null; - try { - pstmt = txn.prepareAutoCloseStatement(sql.toString()); - pstmt.setLong(1, msId); - - ResultSet rs = pstmt.executeQuery(); - List poolIds = new ArrayList(); - - while (rs.next()) { - poolIds.add(rs.getLong("pool_id")); - } - return poolIds; - } catch (SQLException e) { - throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e); - } - - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/SwiftDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/SwiftDao.java b/server/src/com/cloud/storage/dao/SwiftDao.java deleted file mode 100644 index 72c5219..0000000 --- a/server/src/com/cloud/storage/dao/SwiftDao.java +++ /dev/null @@ -1,31 +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.storage.dao; - -import com.cloud.agent.api.to.SwiftTO; -import com.cloud.storage.SwiftVO; -import com.cloud.utils.db.GenericDao; - -/** - * - * - */ - -public interface SwiftDao extends GenericDao { - - SwiftTO getSwiftTO(Long swiftId); -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/SwiftDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/SwiftDaoImpl.java b/server/src/com/cloud/storage/dao/SwiftDaoImpl.java deleted file mode 100644 index 19e5a85..0000000 --- a/server/src/com/cloud/storage/dao/SwiftDaoImpl.java +++ /dev/null @@ -1,58 +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.storage.dao; - -import java.util.Collections; -import java.util.List; - -import javax.ejb.Local; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import com.cloud.agent.api.to.SwiftTO; -import com.cloud.storage.SwiftVO; -import com.cloud.utils.db.GenericDaoBase; - -/** - * - * - */ -@Component -@Local (value={SwiftDao.class}) -public class SwiftDaoImpl extends GenericDaoBase implements SwiftDao { - public static final Logger s_logger = Logger.getLogger(SwiftDaoImpl.class.getName()); - - @Override - public SwiftTO getSwiftTO(Long swiftId) { - if (swiftId != null) { - SwiftVO swift = findById(swiftId); - if (swift != null) { - return swift.toSwiftTO(); - } - return null; - } - - List swiftVOs = listAll(); - if (swiftVOs == null || swiftVOs.size() < 1) { - return null; - } else { - Collections.shuffle(swiftVOs); - return swiftVOs.get(0).toSwiftTO(); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/UploadDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/UploadDao.java b/server/src/com/cloud/storage/dao/UploadDao.java deleted file mode 100755 index 06336ae..0000000 --- a/server/src/com/cloud/storage/dao/UploadDao.java +++ /dev/null @@ -1,36 +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.storage.dao; - -import java.util.List; - -import com.cloud.storage.UploadVO; -import com.cloud.storage.Upload.Status; -import com.cloud.storage.Upload.Type; -import com.cloud.storage.Upload.Mode; -import com.cloud.utils.db.GenericDao; - -public interface UploadDao extends GenericDao { - - List listByTypeUploadStatus(long typeId, Type type, - Status uploadState); - - List listByHostAndUploadStatus(long sserverId, Status uploadInProgress); - - List listByModeAndStatus(Mode mode, Status uploadState); - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/UploadDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/UploadDaoImpl.java b/server/src/com/cloud/storage/dao/UploadDaoImpl.java deleted file mode 100755 index 31fad43..0000000 --- a/server/src/com/cloud/storage/dao/UploadDaoImpl.java +++ /dev/null @@ -1,92 +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.storage.dao; -import java.util.List; -import javax.ejb.Local; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import com.cloud.storage.UploadVO; -import com.cloud.storage.Upload.Status; -import com.cloud.storage.Upload.Mode; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; - -@Component -@Local(value={UploadDao.class}) -public class UploadDaoImpl extends GenericDaoBase implements UploadDao { - public static final Logger s_logger = Logger.getLogger(UploadDaoImpl.class.getName()); - protected final SearchBuilder typeUploadStatusSearch; - protected final SearchBuilder typeHostAndUploadStatusSearch; - protected final SearchBuilder typeModeAndStatusSearch; - - protected static final String UPDATE_UPLOAD_INFO = - "UPDATE upload SET upload_state = ?, upload_pct= ?, last_updated = ? " - + ", upload_error_str = ?, upload_job_id = ? " - + "WHERE host_id = ? and type_id = ? and type = ?"; - - protected static final String UPLOADS_STATE_DC= - "SELECT * FROM upload t, host h where t.host_id = h.id and h.data_center_id=? " - + " and t.type_id=? and t.upload_state = ?" ; - - - public UploadDaoImpl() { - typeUploadStatusSearch = createSearchBuilder(); - typeUploadStatusSearch.and("type_id", typeUploadStatusSearch.entity().getTypeId(), SearchCriteria.Op.EQ); - typeUploadStatusSearch.and("upload_state", typeUploadStatusSearch.entity().getUploadState(), SearchCriteria.Op.EQ); - typeUploadStatusSearch.and("type", typeUploadStatusSearch.entity().getType(), SearchCriteria.Op.EQ); - typeUploadStatusSearch.done(); - - typeHostAndUploadStatusSearch = createSearchBuilder(); - typeHostAndUploadStatusSearch.and("host_id", typeHostAndUploadStatusSearch.entity().getHostId(), SearchCriteria.Op.EQ); - typeHostAndUploadStatusSearch.and("upload_state", typeHostAndUploadStatusSearch.entity().getUploadState(), SearchCriteria.Op.EQ); - typeHostAndUploadStatusSearch.done(); - - typeModeAndStatusSearch = createSearchBuilder(); - typeModeAndStatusSearch.and("mode", typeModeAndStatusSearch.entity().getMode(), SearchCriteria.Op.EQ); - typeModeAndStatusSearch.and("upload_state", typeModeAndStatusSearch.entity().getUploadState(), SearchCriteria.Op.EQ); - typeModeAndStatusSearch.done(); - - } - - @Override - public List listByTypeUploadStatus(long typeId, UploadVO.Type type, UploadVO.Status uploadState) { - SearchCriteria sc = typeUploadStatusSearch.create(); - sc.setParameters("type_id", typeId); - sc.setParameters("type", type); - sc.setParameters("upload_state", uploadState.toString()); - return listBy(sc); - } - - @Override - public List listByHostAndUploadStatus(long sserverId, Status uploadState){ - SearchCriteria sc = typeHostAndUploadStatusSearch.create(); - sc.setParameters("host_id", sserverId); - sc.setParameters("upload_state", uploadState.toString()); - return listBy(sc); - } - - @Override - public List listByModeAndStatus(Mode mode, Status uploadState){ - SearchCriteria sc = typeModeAndStatusSearch.create(); - sc.setParameters("mode", mode.toString()); - sc.setParameters("upload_state", uploadState.toString()); - return listBy(sc); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/server/src/com/cloud/storage/dao/VMTemplateDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/dao/VMTemplateDao.java b/server/src/com/cloud/storage/dao/VMTemplateDao.java deleted file mode 100755 index 8520757..0000000 --- a/server/src/com/cloud/storage/dao/VMTemplateDao.java +++ /dev/null @@ -1,84 +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.storage.dao; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.cloudstack.engine.subsystem.api.storage.TemplateEvent; -import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState; - -import com.cloud.domain.DomainVO; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.projects.Project.ListProjectResourcesCriteria; -import com.cloud.storage.VMTemplateVO; -import com.cloud.template.VirtualMachineTemplate.TemplateFilter; -import com.cloud.user.Account; -import com.cloud.utils.Pair; -import com.cloud.utils.db.GenericDao; -import com.cloud.utils.fsm.StateDao; - -/* - * Data Access Object for vm_templates table - */ -public interface VMTemplateDao extends GenericDao, StateDao { - - - public List listByPublic(); - public VMTemplateVO findByName(String templateName); - public VMTemplateVO findByTemplateName(String templateName); - - //public void update(VMTemplateVO template); - - - public List listAllSystemVMTemplates(); - - public List listDefaultBuiltinTemplates(); - public String getRoutingTemplateUniqueName(); - public List findIsosByIdAndPath(Long domainId, Long accountId, String path); - public List listReadyTemplates(); - public List listByAccountId(long accountId); - public Set> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, - List hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, Long zoneId, - HypervisorType hyperType, boolean onlyReady, boolean showDomr, List permittedAccounts, Account caller, - ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags, String zoneType); - - public Set> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter, - boolean isIso, List hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, - Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List permittedAccounts, Account caller, Map tags); - - public Set> searchS3Templates(String name, String keyword, TemplateFilter templateFilter, - boolean isIso, List hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, - Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List permittedAccounts, Account caller, Map tags); - - public long addTemplateToZone(VMTemplateVO tmplt, long zoneId); - public List listAllInZone(long dataCenterId); - - public List listByHypervisorType(List hyperTypes); - public List publicIsoSearch(Boolean bootable, boolean listRemoved, Map tags); - public List userIsoSearch(boolean listRemoved); - VMTemplateVO findSystemVMTemplate(long zoneId); - VMTemplateVO findSystemVMTemplate(long zoneId, HypervisorType hType); - - VMTemplateVO findRoutingTemplate(HypervisorType type, String templateName); - List listPrivateTemplatesByHost(Long hostId); - public Long countTemplatesForAccount(long accountId); - - List findTemplatesToSyncToS3(); - -}