From be5fa8222949412e8169e32a9d134b84f1d44821 Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 29 Sep 2010 16:24:57 -0700 Subject: [PATCH] remove snapshotpolicyRef --- .../com/cloud/server/ManagementServer.java | 2 +- .../cloud/storage/SnapshotPolicyRefVO.java | 57 ------------- .../storage/dao/SnapshotPolicyRefDao.java | 35 -------- .../storage/dao/SnapshotPolicyRefDaoImpl.java | 83 ------------------- .../cloud/api/commands/ListSnapshotsCmd.java | 2 +- .../cloud/server/ManagementServerImpl.java | 14 +--- .../storage/snapshot/SnapshotManager.java | 6 +- .../storage/snapshot/SnapshotManagerImpl.java | 23 +---- .../snapshot/SnapshotSchedulerImpl.java | 10 --- 9 files changed, 9 insertions(+), 223 deletions(-) delete mode 100644 core/src/com/cloud/storage/SnapshotPolicyRefVO.java delete mode 100644 core/src/com/cloud/storage/dao/SnapshotPolicyRefDao.java delete mode 100644 core/src/com/cloud/storage/dao/SnapshotPolicyRefDaoImpl.java diff --git a/core/src/com/cloud/server/ManagementServer.java b/core/src/com/cloud/server/ManagementServer.java index 6aa4ff76b8a..75e4a19d5de 100755 --- a/core/src/com/cloud/server/ManagementServer.java +++ b/core/src/com/cloud/server/ManagementServer.java @@ -1733,7 +1733,7 @@ public interface ManagementServer { * @return list of snapshots * @throws InvalidParameterValueException */ - List listSnapshots(Criteria c, String interval) throws InvalidParameterValueException; + List listSnapshots(Criteria c) throws InvalidParameterValueException; /** * find a single snapshot by id diff --git a/core/src/com/cloud/storage/SnapshotPolicyRefVO.java b/core/src/com/cloud/storage/SnapshotPolicyRefVO.java deleted file mode 100644 index ab06e6796f9..00000000000 --- a/core/src/com/cloud/storage/SnapshotPolicyRefVO.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. - * - * This software is licensed under the GNU General Public License v3 or later. - * - * It is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package com.cloud.storage; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -@Entity -@Table(name="snapshot_policy_ref") -public class SnapshotPolicyRefVO { - - @Column(name="snap_id") - long snapshotId; - - @Column(name="volume_id") - long volumeId; - - @Column(name="policy_id") - long policyId; - - public SnapshotPolicyRefVO() { } - - public SnapshotPolicyRefVO(long snapshotId, long volumeId, long policyId) { - this.snapshotId = snapshotId; - this.volumeId = volumeId; - this.policyId = policyId; - } - - public long getSnapshotId() { - return snapshotId; - } - - public long getVolumeId() { - return snapshotId; - } - - public long getPolicyId() { - return policyId; - } -} diff --git a/core/src/com/cloud/storage/dao/SnapshotPolicyRefDao.java b/core/src/com/cloud/storage/dao/SnapshotPolicyRefDao.java deleted file mode 100644 index c2ed3056df8..00000000000 --- a/core/src/com/cloud/storage/dao/SnapshotPolicyRefDao.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. - * - * This software is licensed under the GNU General Public License v3 or later. - * - * It is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package com.cloud.storage.dao; - -import java.util.List; - -import com.cloud.storage.SnapshotPolicyRefVO; -import com.cloud.utils.db.GenericDao; - -public interface SnapshotPolicyRefDao extends GenericDao { - - SnapshotPolicyRefVO findBySnapPolicy(long snapshotId, long policyId); - - int removeSnapPolicy(long snapshotId, long policyId); - - List listByPolicyId(long policyId, long volumeId); - - List listBySnapshotId(long snapshotId); -} diff --git a/core/src/com/cloud/storage/dao/SnapshotPolicyRefDaoImpl.java b/core/src/com/cloud/storage/dao/SnapshotPolicyRefDaoImpl.java deleted file mode 100644 index 73479ad727e..00000000000 --- a/core/src/com/cloud/storage/dao/SnapshotPolicyRefDaoImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. - * - * This software is licensed under the GNU General Public License v3 or later. - * - * It is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package com.cloud.storage.dao; - - -import java.util.List; - -import javax.ejb.Local; - -import com.cloud.storage.SnapshotPolicyRefVO; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; - -@Local (value={SnapshotPolicyRefDao.class}) -public class SnapshotPolicyRefDaoImpl extends GenericDaoBase implements SnapshotPolicyRefDao { - protected final SearchBuilder snapPolicy; - protected final SearchBuilder snapSearch; - protected final SearchBuilder policySearch; - - protected SnapshotPolicyRefDaoImpl() { - snapPolicy = createSearchBuilder(); - snapPolicy.and("snapshotId", snapPolicy.entity().getSnapshotId(), SearchCriteria.Op.EQ); - snapPolicy.and("policyId", snapPolicy.entity().getPolicyId(), SearchCriteria.Op.EQ); - snapPolicy.done(); - - snapSearch = createSearchBuilder(); - snapSearch.and("snapshotId", snapSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); - snapSearch.done(); - - policySearch = createSearchBuilder(); - policySearch.and("policyId", policySearch.entity().getPolicyId(), SearchCriteria.Op.EQ); - policySearch.and("volumeId", policySearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - policySearch.done(); - } - - @Override - public SnapshotPolicyRefVO findBySnapPolicy(long snapshotId, long policyId) { - SearchCriteria sc = snapPolicy.create(); - sc.setParameters("snapshotId", snapshotId); - sc.setParameters("policyId", policyId); - return findOneIncludingRemovedBy(sc); - } - - @Override - public int removeSnapPolicy(long snapshotId, long policyId) { - SearchCriteria sc = snapPolicy.create(); - sc.setParameters("snapshotId", snapshotId); - sc.setParameters("policyId", policyId); - return expunge(sc); - } - - @Override - public List listBySnapshotId(long snapshotId) { - SearchCriteria sc = snapSearch.create(); - sc.setParameters("snapshotId", snapshotId); - return listIncludingRemovedBy(sc); - } - - @Override - public List listByPolicyId(long policyId, long volumeId) { - SearchCriteria sc = policySearch.create(); - sc.setParameters("policyId", policyId); - sc.setParameters("volumeId", volumeId); - return listIncludingRemovedBy(sc); - } -} \ No newline at end of file diff --git a/server/src/com/cloud/api/commands/ListSnapshotsCmd.java b/server/src/com/cloud/api/commands/ListSnapshotsCmd.java index 99f674276f3..e31de73034a 100644 --- a/server/src/com/cloud/api/commands/ListSnapshotsCmd.java +++ b/server/src/com/cloud/api/commands/ListSnapshotsCmd.java @@ -122,7 +122,7 @@ public class ListSnapshotsCmd extends BaseCmd { List snapshots = null; try { - snapshots = getManagementServer().listSnapshots(c, interval); + snapshots = getManagementServer().listSnapshots(c); } catch (InvalidParameterValueException e) { throw new ServerApiException(SNAPSHOT_INVALID_PARAM_ERROR, e.getMessage()); } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 3709aa406a8..0fefe15d245 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -6888,7 +6888,7 @@ public class ManagementServerImpl implements ManagementServer { @Override - public List listSnapshots(Criteria c, String interval) throws InvalidParameterValueException { + public List listSnapshots(Criteria c) throws InvalidParameterValueException { Filter searchFilter = new Filter(SnapshotVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit()); SearchCriteria sc = _snapshotDao.createSearchCriteria(); @@ -6935,18 +6935,6 @@ public class ManagementServerImpl implements ManagementServer { // Show only MANUAL and RECURRING snapshot types sc.addAnd("snapshotType", SearchCriteria.Op.NEQ, Snapshot.SnapshotType.TEMPLATE.ordinal()); } - if(interval != null && volumeId != null) { - IntervalType intervalType = DateUtil.IntervalType.getIntervalType(interval); - if(intervalType == null) { - throw new InvalidParameterValueException("Unsupported interval type " + intervalType); - } - SnapshotPolicyVO snapPolicy = _snapMgr.getPolicyForVolumeByInterval((Long)volumeId, (short)intervalType.ordinal()); - if (snapPolicy == null) { - s_logger.warn("Policy with interval "+ intervalType +" not assigned to volume: "+volumeId); - return new ArrayList(); - } - return _snapMgr.listSnapsforPolicy(snapPolicy.getId(), searchFilter); - } return _snapshotDao.search(sc, searchFilter); } diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManager.java b/server/src/com/cloud/storage/snapshot/SnapshotManager.java index 4b6d3c01cdc..04ca82ec7d6 100644 --- a/server/src/com/cloud/storage/snapshot/SnapshotManager.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManager.java @@ -114,8 +114,9 @@ public interface SnapshotManager extends Manager { /** * Lists all snapshots for the volume which are created using schedule of the specified policy */ + /* List listSnapsforPolicy(long policyId, Filter filter); - + */ /** * List all policies which are assigned to the specified volume */ @@ -125,8 +126,9 @@ public interface SnapshotManager extends Manager { * List all policies to which a specified snapshot belongs. For ex: A snapshot * may belong to a hourly snapshot and a daily snapshot run at the same time */ + /* List listPoliciesforSnapshot(long snapshotId); - + */ /** * List all snapshots for a specified volume irrespective of the policy which * created the snapshot diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 98356d4bc3a..f8c9dafb76e 100644 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -59,7 +59,6 @@ import com.cloud.host.dao.DetailsDao; import com.cloud.host.dao.HostDao; import com.cloud.serializer.GsonHelper; import com.cloud.storage.Snapshot; -import com.cloud.storage.SnapshotPolicyRefVO; import com.cloud.storage.SnapshotPolicyVO; import com.cloud.storage.SnapshotScheduleVO; import com.cloud.storage.SnapshotVO; @@ -74,7 +73,6 @@ import com.cloud.storage.Volume.VolumeType; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.SnapshotPolicyDao; -import com.cloud.storage.dao.SnapshotPolicyRefDao; import com.cloud.storage.dao.SnapshotScheduleDao; import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.VMTemplateDao; @@ -116,7 +114,6 @@ public class SnapshotManagerImpl implements SnapshotManager { @Inject protected StoragePoolDao _storagePoolDao; @Inject protected EventDao _eventDao; @Inject protected SnapshotPolicyDao _snapshotPolicyDao = null; - @Inject protected SnapshotPolicyRefDao _snapPolicyRefDao = null; @Inject protected SnapshotScheduleDao _snapshotScheduleDao; @Inject protected DetailsDao _detailsDao; @Inject protected VMTemplateDao _templateDao; @@ -915,7 +912,7 @@ public class SnapshotManagerImpl implements SnapshotManager { public List listPoliciesforVolume(long volumeId) { return _snapshotPolicyDao.listByVolumeId(volumeId); } - +/* @Override public List listPoliciesforSnapshot(long snapshotId) { SearchCriteria sc = PoliciesForSnapSearch.create(); @@ -929,7 +926,7 @@ public class SnapshotManagerImpl implements SnapshotManager { sc.setJoinParameters("policy", "policyId", policyId); return _snapshotDao.search(sc, filter); } - +*/ @Override public List listSnapsforVolume(long volumeId) { @@ -1009,22 +1006,6 @@ public class SnapshotManagerImpl implements SnapshotManager { _totalRetries = NumbersUtil.parseInt(configDao.getValue("total.retries"), 4); _pauseInterval = 2*NumbersUtil.parseInt(configDao.getValue("ping.interval"), 60); - SearchBuilder policySearch = _snapPolicyRefDao.createSearchBuilder(); - policySearch.and("policyId", policySearch.entity().getPolicyId(), SearchCriteria.Op.EQ); - - PolicySnapshotSearch = _snapshotDao.createSearchBuilder(); - PolicySnapshotSearch.join("policy", policySearch, policySearch.entity().getSnapshotId(), PolicySnapshotSearch.entity().getId(), JoinBuilder.JoinType.INNER); - policySearch.done(); - PolicySnapshotSearch.done(); - - PoliciesForSnapSearch = _snapshotPolicyDao.createSearchBuilder(); - - SearchBuilder policyRefSearch = _snapPolicyRefDao.createSearchBuilder(); - policyRefSearch.and("snapshotId", policyRefSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); - - PoliciesForSnapSearch.join("policyRef", policyRefSearch, policyRefSearch.entity().getPolicyId(), PoliciesForSnapSearch.entity().getId(), JoinBuilder.JoinType.INNER); - policyRefSearch.done(); - PoliciesForSnapSearch.done(); s_logger.info("Snapshot Manager is configured."); return true; diff --git a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java index de4d09af9bd..c3159c258cf 100644 --- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java @@ -17,33 +17,25 @@ */ package com.cloud.storage.snapshot; -import java.util.ArrayList; -import java.util.Calendar; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; - import javax.ejb.Local; import javax.naming.ConfigurationException; import javax.persistence.EntityExistsException; - import org.apache.log4j.Logger; - import com.cloud.async.AsyncJobResult; import com.cloud.async.AsyncJobVO; import com.cloud.async.dao.AsyncJobDao; import com.cloud.configuration.dao.ConfigurationDao; -import com.cloud.event.EventTypes; import com.cloud.storage.Snapshot; import com.cloud.storage.SnapshotPolicyVO; import com.cloud.storage.SnapshotScheduleVO; import com.cloud.storage.SnapshotVO; import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.SnapshotPolicyDao; -import com.cloud.storage.dao.SnapshotPolicyRefDao; import com.cloud.storage.dao.SnapshotScheduleDao; import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.utils.DateUtil; @@ -55,7 +47,6 @@ import com.cloud.utils.concurrency.TestClock; import com.cloud.utils.db.DB; import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.Transaction; /** * @@ -69,7 +60,6 @@ public class SnapshotSchedulerImpl implements SnapshotScheduler { @Inject protected SnapshotDao _snapshotDao; @Inject protected SnapshotScheduleDao _snapshotScheduleDao; @Inject protected SnapshotPolicyDao _snapshotPolicyDao; - @Inject protected SnapshotPolicyRefDao _snapshotPolicyRefDao; @Inject protected SnapshotManager _snapshotManager; @Inject protected StoragePoolHostDao _poolHostDao;