mirror of https://github.com/apache/cloudstack.git
delete secondary storage,
1. check if there are snapshotsin this secondary storage, if yes , fails 2. check if there are private templatesin this secondary storage , if yes, fails
This commit is contained in:
parent
8c4e831cfb
commit
fed7d1ebdb
|
|
@ -525,7 +525,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
}
|
||||
_accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), host.getDataCenterId());
|
||||
if (Host.Type.SecondaryStorage.equals(host.getType())) {
|
||||
return _secondaryStorageMgr.destroySecStorageVm(hostId);
|
||||
_secondaryStorageMgr.deleteHost(hostId);
|
||||
return true;
|
||||
} else {
|
||||
return _agentMgr.deleteHost(hostId, isForced, caller);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,5 +37,7 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long> {
|
|||
List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version);
|
||||
Long getSecHostId(long volumeId);
|
||||
long updateSnapshotSecHost(long dcId, long secHostId);
|
||||
List<SnapshotVO> listByHostId(Filter filter, long hostId);
|
||||
List<SnapshotVO> listByHostId(long hostId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
import com.cloud.storage.Snapshot.Type;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
|
|
@ -47,6 +48,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
|||
private final SearchBuilder<SnapshotVO> ParentIdSearch;
|
||||
private final SearchBuilder<SnapshotVO> backupUuidSearch;
|
||||
private final SearchBuilder<SnapshotVO> VolumeIdVersionSearch;
|
||||
private final SearchBuilder<SnapshotVO> HostIdSearch;
|
||||
|
||||
@Override
|
||||
public SnapshotVO findNextSnapshot(long snapshotId) {
|
||||
|
|
@ -85,6 +87,19 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
|||
return listBy(sc, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SnapshotVO> listByHostId(long hostId) {
|
||||
return listByHostId(null, hostId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SnapshotVO> listByHostId(Filter filter, long hostId ) {
|
||||
SearchCriteria<SnapshotVO> sc = HostIdSearch.create();
|
||||
sc.setParameters("hostId", hostId);
|
||||
sc.setParameters("status", Status.DOWNLOADED);
|
||||
return listBy(sc, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SnapshotVO> listByVolumeIdIncludingRemoved(long volumeId) {
|
||||
SearchCriteria<SnapshotVO> sc = VolumeIdSearch.create();
|
||||
|
|
@ -111,6 +126,11 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
|||
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().getStatus(), 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);
|
||||
|
|
|
|||
|
|
@ -71,5 +71,6 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long> {
|
|||
VMTemplateVO findSystemVMTemplate(long zoneId, HypervisorType hType);
|
||||
|
||||
VMTemplateVO findRoutingTemplate(HypervisorType type);
|
||||
List<Long> listPrivateTemplatesByHost(Long hostId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,13 @@ package com.cloud.storage.dao;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
|
@ -39,6 +41,7 @@ import com.cloud.host.HostVO;
|
|||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.info.RunningHostCountInfo;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
|
|
@ -46,6 +49,7 @@ import com.cloud.storage.VMTemplateVO;
|
|||
import com.cloud.storage.VMTemplateZoneVO;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.db.DB;
|
||||
|
|
@ -139,6 +143,30 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
|||
return listBy(sc, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> listPrivateTemplatesByHost(Long hostId) {
|
||||
|
||||
String sql = "select * from template_host_ref as thr INNER JOIN vm_template as t ON t.id=thr.template_id "
|
||||
+ "where thr.host_id=? and t.public=0 and t.featured=0 and t.type='USER' and t.removed is NULL";
|
||||
|
||||
List<Long> l = new ArrayList<Long>();
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||
pstmt.setLong(1, hostId);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
l.add(rs.getLong(1));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMTemplateVO> listReadyTemplates() {
|
||||
SearchCriteria<VMTemplateVO> sc = createSearchCriteria();
|
||||
|
|
|
|||
|
|
@ -57,5 +57,7 @@ public interface VMTemplateHostDao extends GenericDao<VMTemplateHostVO, Long> {
|
|||
boolean templateAvailable(long templateId, long hostId);
|
||||
|
||||
List<VMTemplateHostVO> listByZoneTemplate(long dcId, long templateId);
|
||||
|
||||
void deleteByHost(Long hostId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
|
|||
|
||||
|
||||
protected static final String UPDATE_TEMPLATE_HOST_REF =
|
||||
"UPDATE type_host_ref SET download_state = ?, download_pct= ?, last_updated = ? "
|
||||
"UPDATE template_host_ref SET download_state = ?, download_pct= ?, last_updated = ? "
|
||||
+ ", error_str = ?, local_path = ?, job_id = ? "
|
||||
+ "WHERE host_id = ? and type_id = ?";
|
||||
|
||||
|
|
@ -321,6 +321,14 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
|
|||
return findOneIncludingRemovedBy(sc);
|
||||
else
|
||||
return lockOneRandomRow(sc, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByHost(Long hostId) {
|
||||
List<VMTemplateHostVO> tmpltHosts = listByHostId(hostId);
|
||||
for (VMTemplateHostVO tmpltHost : tmpltHosts ) {
|
||||
remove(tmpltHost.getId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -539,7 +539,7 @@ public class DownloadMonitorImpl implements DownloadMonitor {
|
|||
for ( VMTemplateHostVO tmpltHost : tmpltHosts ) {
|
||||
if ( tmpltHost.getDownloadState() == Status.DOWNLOADED || tmpltHost.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
|
||||
iter.remove();
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,9 +71,11 @@ import com.cloud.network.Networks.TrafficType;
|
|||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.dao.SnapshotDao;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
|
|
@ -162,7 +164,9 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
|||
private AgentManager _agentMgr;
|
||||
@Inject
|
||||
private NetworkManager _networkMgr;
|
||||
|
||||
@Inject
|
||||
protected SnapshotDao _snapshotDao;
|
||||
|
||||
@Inject
|
||||
private ClusterManager _clusterMgr;
|
||||
|
||||
|
|
@ -282,6 +286,26 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean deleteHost(Long hostId) {
|
||||
List<SnapshotVO> snapshots = _snapshotDao.listByHostId(hostId);
|
||||
if( snapshots != null && !snapshots.isEmpty()) {
|
||||
throw new CloudRuntimeException("Can not delete this secondary storage due to there are still snapshots on it ");
|
||||
}
|
||||
List<Long> list = _templateDao.listPrivateTemplatesByHost(hostId);
|
||||
if( list != null && !list.isEmpty()) {
|
||||
throw new CloudRuntimeException("Can not delete this secondary storage due to there are still private template on it ");
|
||||
}
|
||||
_vmTemplateHostDao.deleteByHost(hostId);
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
host.setGuid(null);
|
||||
_hostDao.update(hostId, host);
|
||||
_hostDao.remove(hostId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateVMSetupCommand(Long ssAHostId) {
|
||||
HostVO ssAHost = _hostDao.findById(ssAHostId);
|
||||
|
|
|
|||
|
|
@ -43,5 +43,6 @@ public interface SecondaryStorageVmManager extends Manager {
|
|||
public boolean generateVMSetupCommand(Long hostId);
|
||||
|
||||
public Pair<HostVO, SecondaryStorageVmVO> assignSecStorageVm(long zoneId, Command cmd);
|
||||
boolean generateSetupCommand(Long hostId);
|
||||
boolean generateSetupCommand(Long hostId);
|
||||
boolean deleteHost(Long hostId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue