remove snapshotpolicyRef

This commit is contained in:
anthony 2010-09-29 16:24:57 -07:00
parent 9b03017a07
commit be5fa82229
9 changed files with 9 additions and 223 deletions

View File

@ -1733,7 +1733,7 @@ public interface ManagementServer {
* @return list of snapshots
* @throws InvalidParameterValueException
*/
List<SnapshotVO> listSnapshots(Criteria c, String interval) throws InvalidParameterValueException;
List<SnapshotVO> listSnapshots(Criteria c) throws InvalidParameterValueException;
/**
* find a single snapshot by id

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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, Long> {
SnapshotPolicyRefVO findBySnapPolicy(long snapshotId, long policyId);
int removeSnapPolicy(long snapshotId, long policyId);
List<SnapshotPolicyRefVO> listByPolicyId(long policyId, long volumeId);
List<SnapshotPolicyRefVO> listBySnapshotId(long snapshotId);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<SnapshotPolicyRefVO, Long> implements SnapshotPolicyRefDao {
protected final SearchBuilder<SnapshotPolicyRefVO> snapPolicy;
protected final SearchBuilder<SnapshotPolicyRefVO> snapSearch;
protected final SearchBuilder<SnapshotPolicyRefVO> 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<SnapshotPolicyRefVO> sc = snapPolicy.create();
sc.setParameters("snapshotId", snapshotId);
sc.setParameters("policyId", policyId);
return findOneIncludingRemovedBy(sc);
}
@Override
public int removeSnapPolicy(long snapshotId, long policyId) {
SearchCriteria<SnapshotPolicyRefVO> sc = snapPolicy.create();
sc.setParameters("snapshotId", snapshotId);
sc.setParameters("policyId", policyId);
return expunge(sc);
}
@Override
public List<SnapshotPolicyRefVO> listBySnapshotId(long snapshotId) {
SearchCriteria<SnapshotPolicyRefVO> sc = snapSearch.create();
sc.setParameters("snapshotId", snapshotId);
return listIncludingRemovedBy(sc);
}
@Override
public List<SnapshotPolicyRefVO> listByPolicyId(long policyId, long volumeId) {
SearchCriteria<SnapshotPolicyRefVO> sc = policySearch.create();
sc.setParameters("policyId", policyId);
sc.setParameters("volumeId", volumeId);
return listIncludingRemovedBy(sc);
}
}

View File

@ -122,7 +122,7 @@ public class ListSnapshotsCmd extends BaseCmd {
List<SnapshotVO> snapshots = null;
try {
snapshots = getManagementServer().listSnapshots(c, interval);
snapshots = getManagementServer().listSnapshots(c);
} catch (InvalidParameterValueException e) {
throw new ServerApiException(SNAPSHOT_INVALID_PARAM_ERROR, e.getMessage());
}

View File

@ -6888,7 +6888,7 @@ public class ManagementServerImpl implements ManagementServer {
@Override
public List<SnapshotVO> listSnapshots(Criteria c, String interval) throws InvalidParameterValueException {
public List<SnapshotVO> listSnapshots(Criteria c) throws InvalidParameterValueException {
Filter searchFilter = new Filter(SnapshotVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());
SearchCriteria<SnapshotVO> 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<SnapshotVO>();
}
return _snapMgr.listSnapsforPolicy(snapPolicy.getId(), searchFilter);
}
return _snapshotDao.search(sc, searchFilter);
}

View File

@ -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<SnapshotVO> 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<SnapshotPolicyVO> listPoliciesforSnapshot(long snapshotId);
*/
/**
* List all snapshots for a specified volume irrespective of the policy which
* created the snapshot

View File

@ -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<SnapshotPolicyVO> listPoliciesforVolume(long volumeId) {
return _snapshotPolicyDao.listByVolumeId(volumeId);
}
/*
@Override
public List<SnapshotPolicyVO> listPoliciesforSnapshot(long snapshotId) {
SearchCriteria<SnapshotPolicyVO> 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<SnapshotVO> 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<SnapshotPolicyRefVO> 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<SnapshotPolicyRefVO> 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;

View File

@ -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;