mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Remove VMTemplateHostDao reference from VolumeManagerImpl,
StorageManagerImpl and SecondaryStorageManagerImpl.
This commit is contained in:
parent
4cd3903c9d
commit
06b3092083
@ -23,7 +23,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
|
||||
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.fsm.StateDao;
|
||||
|
||||
@ -40,7 +40,11 @@ public interface TemplateDataStoreDao extends GenericDao<TemplateDataStoreVO, Lo
|
||||
|
||||
List<TemplateDataStoreVO> listByTemplateStoreStatus(long templateId, long storeId, State... states);
|
||||
|
||||
List<TemplateDataStoreVO> listByTemplateStoreDownloadStatus(long templateId, long storeId, Status... status);
|
||||
List<TemplateDataStoreVO> listByTemplateStoreDownloadStatus(long templateId, long storeId, VMTemplateStorageResourceAssoc.Status... status);
|
||||
|
||||
List<TemplateDataStoreVO> listByTemplateZoneDownloadStatus(long templateId, Long zoneId, VMTemplateStorageResourceAssoc.Status... status);
|
||||
|
||||
TemplateDataStoreVO findByTemplateZoneDownloadStatus(long templateId, Long zoneId, VMTemplateStorageResourceAssoc.Status... status);
|
||||
|
||||
TemplateDataStoreVO findByStoreTemplate(long storeId, long templateId);
|
||||
|
||||
|
||||
@ -15,21 +15,26 @@
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
@ -38,6 +43,8 @@ import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.Collections;
|
||||
|
||||
@Component
|
||||
public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO, Long> implements TemplateDataStoreDao {
|
||||
private static final Logger s_logger = Logger.getLogger(TemplateDataStoreDaoImpl.class);
|
||||
@ -49,6 +56,8 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
|
||||
private SearchBuilder<TemplateDataStoreVO> storeTemplateDownloadStatusSearch;
|
||||
|
||||
|
||||
@Inject private DataStoreManager _storeMgr;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
@ -197,6 +206,41 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
|
||||
return search(sc, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<TemplateDataStoreVO> listByTemplateZoneDownloadStatus(long templateId, Long zoneId, Status... status) {
|
||||
// get all elgible image stores
|
||||
List<DataStore> imgStores = this._storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
|
||||
if ( imgStores != null ){
|
||||
List<TemplateDataStoreVO> result = new ArrayList<TemplateDataStoreVO>();
|
||||
for (DataStore store : imgStores){
|
||||
List<TemplateDataStoreVO> sRes = this.listByTemplateStoreDownloadStatus(templateId, store.getId(), status);
|
||||
if ( sRes != null && sRes.size() > 0){
|
||||
result.addAll(sRes);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TemplateDataStoreVO findByTemplateZoneDownloadStatus(long templateId, Long zoneId, Status... status) {
|
||||
// get all elgible image stores
|
||||
List<DataStore> imgStores = this._storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
|
||||
if ( imgStores != null ){
|
||||
for (DataStore store : imgStores){
|
||||
List<TemplateDataStoreVO> sRes = this.listByTemplateStoreDownloadStatus(templateId, store.getId(), status);
|
||||
if ( sRes != null && sRes.size() > 0){
|
||||
Collections.shuffle(sRes);
|
||||
return sRes.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateDataStoreVO findByStoreTemplate(long storeId, long templateId) {
|
||||
SearchCriteria<TemplateDataStoreVO> sc = storeTemplateSearch.create();
|
||||
|
||||
@ -84,18 +84,14 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.BackupSnapshotCommand;
|
||||
import com.cloud.agent.api.CleanupSnapshotBackupCommand;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.ManageSnapshotCommand;
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
import com.cloud.agent.api.storage.DeleteTemplateCommand;
|
||||
import com.cloud.agent.api.storage.DeleteVolumeCommand;
|
||||
import com.cloud.agent.manager.AgentAttache;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.capacity.Capacity;
|
||||
import com.cloud.capacity.CapacityManager;
|
||||
import com.cloud.capacity.CapacityState;
|
||||
@ -106,7 +102,6 @@ import com.cloud.cluster.ManagementServerHostVO;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.consoleproxy.ConsoleProxyManager;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
@ -134,12 +129,9 @@ import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.HypervisorGuruManager;
|
||||
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
|
||||
import com.cloud.network.NetworkModel;
|
||||
import com.cloud.org.Grouping;
|
||||
import com.cloud.org.Grouping.AllocationState;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.resource.ResourceState;
|
||||
import com.cloud.resource.ResourceStateAdapter;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.server.StatsCollector;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
@ -152,25 +144,20 @@ import com.cloud.storage.dao.SnapshotPolicyDao;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.storage.dao.StoragePoolWorkDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
import com.cloud.storage.dao.VMTemplatePoolDao;
|
||||
import com.cloud.storage.dao.VMTemplateS3Dao;
|
||||
import com.cloud.storage.dao.VMTemplateSwiftDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.dao.VolumeHostDao;
|
||||
import com.cloud.storage.download.DownloadMonitor;
|
||||
import com.cloud.storage.listener.StoragePoolMonitor;
|
||||
import com.cloud.storage.listener.VolumeStateListener;
|
||||
import com.cloud.storage.s3.S3Manager;
|
||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
import com.cloud.storage.snapshot.SnapshotManager;
|
||||
import com.cloud.storage.snapshot.SnapshotScheduler;
|
||||
import com.cloud.tags.dao.ResourceTagDao;
|
||||
import com.cloud.template.TemplateManager;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.ResourceLimitService;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
@ -191,17 +178,13 @@ import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
import com.cloud.vm.DiskProfile;
|
||||
import com.cloud.vm.UserVmManager;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachineProfileImpl;
|
||||
import com.cloud.vm.dao.ConsoleProxyDao;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.SecondaryStorageVmDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
@ -238,8 +221,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
@Inject
|
||||
protected AlertManager _alertMgr;
|
||||
@Inject
|
||||
protected VMTemplateHostDao _vmTemplateHostDao = null;
|
||||
@Inject
|
||||
protected VMTemplatePoolDao _vmTemplatePoolDao = null;
|
||||
@Inject
|
||||
protected VMTemplateSwiftDao _vmTemplateSwiftDao = null;
|
||||
@ -286,8 +267,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
@Inject
|
||||
protected VMTemplateDao _templateDao;
|
||||
@Inject
|
||||
protected VMTemplateHostDao _templateHostDao;
|
||||
@Inject
|
||||
protected ServiceOfferingDao _offeringDao;
|
||||
@Inject
|
||||
protected DomainDao _domainDao;
|
||||
@ -1291,14 +1270,14 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
+ ((answer == null) ? "answer is null"
|
||||
: answer.getDetails()));
|
||||
} else {
|
||||
_vmTemplateHostDao
|
||||
_templateStoreDao
|
||||
.remove(destroyedTemplateStoreVO.getId());
|
||||
s_logger.debug("Deleted template at: "
|
||||
+ destroyedTemplateStoreVO
|
||||
.getInstallPath());
|
||||
}
|
||||
} else {
|
||||
_vmTemplateHostDao.remove(destroyedTemplateStoreVO
|
||||
_templateStoreDao.remove(destroyedTemplateStoreVO
|
||||
.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,6 +59,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeAp
|
||||
import org.apache.cloudstack.framework.async.AsyncCallFuture;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -215,7 +217,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
@Inject
|
||||
protected AlertManager _alertMgr;
|
||||
@Inject
|
||||
protected VMTemplateHostDao _vmTemplateHostDao = null;
|
||||
protected TemplateDataStoreDao _vmTemplateStoreDao = null;
|
||||
@Inject
|
||||
protected VMTemplatePoolDao _vmTemplatePoolDao = null;
|
||||
@Inject
|
||||
@ -253,8 +255,6 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
@Inject
|
||||
protected VMTemplateDao _templateDao;
|
||||
@Inject
|
||||
protected VMTemplateHostDao _templateHostDao;
|
||||
@Inject
|
||||
protected ServiceOfferingDao _offeringDao;
|
||||
@Inject
|
||||
protected DomainDao _domainDao;
|
||||
@ -318,12 +318,11 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
private int _customDiskOfferingMaxSize = 1024;
|
||||
private long _maxVolumeSizeInGb;
|
||||
private boolean _recreateSystemVmEnabled;
|
||||
protected SearchBuilder<VMTemplateHostVO> HostTemplateStatesSearch;
|
||||
|
||||
|
||||
public VolumeManagerImpl() {
|
||||
_volStateMachine = Volume.State.getStateMachine();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId,
|
||||
Long destPoolPodId, Long destPoolClusterId,
|
||||
@ -341,7 +340,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
dskCh.setHyperType(dataDiskHyperType);
|
||||
DataCenterVO destPoolDataCenter = _dcDao.findById(destPoolDcId);
|
||||
HostPodVO destPoolPod = _podDao.findById(destPoolPodId);
|
||||
|
||||
|
||||
StoragePool destPool = storageMgr.findStoragePool(dskCh,
|
||||
destPoolDataCenter, destPoolPod, destPoolClusterId, null, null,
|
||||
new HashSet<StoragePool>());
|
||||
@ -350,7 +349,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
throw new CloudRuntimeException(
|
||||
"Failed to find a storage pool with enough capacity to move the volume to.");
|
||||
}
|
||||
|
||||
|
||||
Volume newVol = migrateVolume(volume, destPool);
|
||||
return this.volFactory.getVolume(newVol.getId());
|
||||
}
|
||||
@ -373,16 +372,16 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
DataStore store = this._tmpltMgr.getImageStore(imageStoreUuid, zoneId);
|
||||
|
||||
validateVolume(caller, ownerId, zoneId, volumeName, url, format);
|
||||
|
||||
|
||||
VolumeVO volume = persistVolume(caller, ownerId, zoneId, volumeName,
|
||||
url, cmd.getFormat());
|
||||
|
||||
|
||||
VolumeInfo vol = this.volFactory.getVolume(volume.getId());
|
||||
|
||||
|
||||
RegisterVolumePayload payload = new RegisterVolumePayload(cmd.getUrl(), cmd.getChecksum(),
|
||||
cmd.getFormat());
|
||||
vol.addPayload(payload);
|
||||
|
||||
|
||||
this.volService.registerVolume(vol, store);
|
||||
return volume;
|
||||
}
|
||||
@ -478,7 +477,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VolumeVO allocateDuplicateVolume(VolumeVO oldVol, Long templateId) {
|
||||
VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(),
|
||||
@ -495,7 +494,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
newVol.setRecreatable(oldVol.isRecreatable());
|
||||
return _volsDao.persist(newVol);
|
||||
}
|
||||
|
||||
|
||||
@DB
|
||||
protected VolumeInfo createVolumeFromSnapshot(VolumeVO volume,
|
||||
SnapshotVO snapshot) {
|
||||
@ -522,10 +521,10 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
while ((pool = storageMgr.findStoragePool(dskCh, dc, pod.first(), null, null,
|
||||
null, poolsToAvoid)) != null) {
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VolumeInfo vol = this.volFactory.getVolume(volume.getId());
|
||||
DataStore store = this.dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
|
||||
SnapshotInfo snapInfo = this.snapshotFactory.getSnapshot(snapshot.getId());
|
||||
@ -551,22 +550,14 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
VMTemplateVO template, DataCenterVO dc, DiskOfferingVO diskOffering) {
|
||||
if (volume.getVolumeType() == Type.ROOT
|
||||
&& Storage.ImageFormat.ISO != template.getFormat()) {
|
||||
SearchCriteria<VMTemplateHostVO> sc = HostTemplateStatesSearch
|
||||
.create();
|
||||
sc.setParameters("id", template.getId());
|
||||
sc.setParameters(
|
||||
"state",
|
||||
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
sc.setJoinParameters("host", "dcId", dc.getId());
|
||||
|
||||
List<VMTemplateHostVO> sss = _vmTemplateHostDao.search(sc, null);
|
||||
if (sss.size() == 0) {
|
||||
TemplateDataStoreVO ss = this._vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dc.getId(),
|
||||
VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
if (ss == null) {
|
||||
throw new CloudRuntimeException("Template "
|
||||
+ template.getName()
|
||||
+ " has not been completely downloaded to zone "
|
||||
+ dc.getId());
|
||||
}
|
||||
VMTemplateHostVO ss = sss.get(0);
|
||||
|
||||
return new DiskProfile(volume.getId(), volume.getVolumeType(),
|
||||
volume.getName(), diskOffering.getId(), ss.getSize(),
|
||||
@ -586,7 +577,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
|
||||
protected VolumeVO createVolumeFromSnapshot(VolumeVO volume, long snapshotId) {
|
||||
VolumeInfo createdVolume = null;
|
||||
SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
|
||||
SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
|
||||
createdVolume = createVolumeFromSnapshot(volume,
|
||||
snapshot);
|
||||
|
||||
@ -624,7 +615,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
if (result.isFailed()) {
|
||||
s_logger.debug("copy volume failed: " + result.getResult());
|
||||
throw new CloudRuntimeException("copy volume failed: " + result.getResult());
|
||||
}
|
||||
}
|
||||
return result.getVolume();
|
||||
} catch (InterruptedException e) {
|
||||
s_logger.debug("Failed to copy volume: " + volume.getId(), e);
|
||||
@ -642,11 +633,11 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
DiskOfferingVO diskOffering, List<StoragePool> avoids,
|
||||
long size, HypervisorType hyperType) {
|
||||
StoragePool pool = null;
|
||||
|
||||
|
||||
if (diskOffering != null && diskOffering.isCustomized()) {
|
||||
diskOffering.setDiskSize(size);
|
||||
}
|
||||
|
||||
|
||||
DiskProfile dskCh = null;
|
||||
if (volume.getVolumeType() == Type.ROOT
|
||||
&& Storage.ImageFormat.ISO != template.getFormat()) {
|
||||
@ -657,7 +648,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
}
|
||||
|
||||
dskCh.setHyperType(hyperType);
|
||||
|
||||
|
||||
final HashSet<StoragePool> avoidPools = new HashSet<StoragePool>(
|
||||
avoids);
|
||||
|
||||
@ -702,11 +693,11 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getRandomVolumeName() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
|
||||
private VolumeVO persistVolume(Account caller, long ownerId, Long zoneId,
|
||||
String volumeName, String url, String format) {
|
||||
|
||||
@ -749,7 +740,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
txn.commit();
|
||||
return volume;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean volumeOnSharedStoragePool(VolumeVO volume) {
|
||||
Long poolId = volume.getPoolId();
|
||||
@ -1034,12 +1025,12 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
throws ResourceAllocationException {
|
||||
Long newSize = null;
|
||||
boolean shrinkOk = cmd.getShrinkOk();
|
||||
|
||||
|
||||
VolumeVO volume = _volsDao.findById(cmd.getEntityId());
|
||||
if (volume == null) {
|
||||
throw new InvalidParameterValueException("No such volume");
|
||||
}
|
||||
|
||||
|
||||
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume
|
||||
.getDiskOfferingId());
|
||||
DiskOfferingVO newDiskOffering = null;
|
||||
@ -1196,9 +1187,9 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
"VM must be stopped or disk detached in order to resize with the Xen HV");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ResizeVolumePayload payload = new ResizeVolumePayload(newSize, shrinkOk, instanceName, hosts);
|
||||
|
||||
|
||||
try {
|
||||
VolumeInfo vol = this.volFactory.getVolume(volume.getId());
|
||||
vol.addPayload(payload);
|
||||
@ -1231,7 +1222,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_DELETE, eventDescription = "deleting volume")
|
||||
@ -1271,7 +1262,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
if (!this.volService.destroyVolume(volume.getId())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
VMInstanceVO vmInstance = this._vmInstanceDao.findById(instanceId);
|
||||
if (instanceId == null
|
||||
|| (vmInstance.getType().equals(VirtualMachine.Type.User))) {
|
||||
@ -1297,7 +1288,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
}
|
||||
AsyncCallFuture<VolumeApiResult> future = this.volService.expungeVolumeAsync(this.volFactory.getVolume(volume.getId()));
|
||||
future.get();
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Failed to expunge volume:", e);
|
||||
return false;
|
||||
@ -1413,7 +1404,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
}
|
||||
return toDiskProfile(vol, offering);
|
||||
}
|
||||
|
||||
|
||||
private String getSupportedImageFormatForCluster(Long clusterId) {
|
||||
ClusterVO cluster = ApiDBUtils.findClusterById(clusterId);
|
||||
|
||||
@ -1429,7 +1420,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private VolumeInfo copyVolume(StoragePoolVO rootDiskPool
|
||||
, VolumeInfo volume, VMInstanceVO vm, VMTemplateVO rootDiskTmplt, DataCenterVO dcVO,
|
||||
HostPodVO pod, DiskOfferingVO diskVO, ServiceOfferingVO svo, HypervisorType rootDiskHyperType) throws NoTransitionException {
|
||||
@ -1495,28 +1486,28 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
private boolean needMoveVolume(VolumeVO rootVolumeOfVm, VolumeInfo volume) {
|
||||
DataStore storeForRootVol = this.dataStoreMgr.getPrimaryDataStore(rootVolumeOfVm.getPoolId());
|
||||
DataStore storeForDataVol = this.dataStoreMgr.getPrimaryDataStore(volume.getPoolId());
|
||||
|
||||
|
||||
Scope storeForRootStoreScope = storeForRootVol.getScope();
|
||||
if (storeForRootStoreScope == null) {
|
||||
throw new CloudRuntimeException("Can't get scope of data store: " + storeForRootVol.getId());
|
||||
}
|
||||
|
||||
|
||||
Scope storeForDataStoreScope = storeForDataVol.getScope();
|
||||
if (storeForDataStoreScope == null) {
|
||||
throw new CloudRuntimeException("Can't get scope of data store: " + storeForDataVol.getId());
|
||||
}
|
||||
|
||||
|
||||
if (storeForDataStoreScope.getScopeType() == ScopeType.ZONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (storeForRootStoreScope.getScopeType() != storeForDataStoreScope.getScopeType()) {
|
||||
throw new CloudRuntimeException("Can't move volume between scope: " + storeForDataStoreScope.getScopeType() + " and " + storeForRootStoreScope.getScopeType());
|
||||
}
|
||||
|
||||
|
||||
return !storeForRootStoreScope.isSameScope(storeForDataStoreScope);
|
||||
}
|
||||
|
||||
|
||||
private VolumeVO sendAttachVolumeCommand(UserVmVO vm, VolumeVO volume, Long deviceId) {
|
||||
String errorMsg = "Failed to attach volume: " + volume.getName()
|
||||
+ " to VM: " + vm.getHostName();
|
||||
@ -1568,7 +1559,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
throw new CloudRuntimeException(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getMaxDataVolumesSupported(UserVmVO vm) {
|
||||
Long hostId = vm.getHostId();
|
||||
if (hostId == null) {
|
||||
@ -1590,7 +1581,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
|
||||
return maxDataVolumesSupported.intValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_ATTACH, eventDescription = "attaching volume", async = true)
|
||||
public Volume attachVolumeToVM(AttachVolumeCmd command) {
|
||||
@ -1675,9 +1666,9 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
|
||||
if(vmSnapshots.size() > 0){
|
||||
throw new InvalidParameterValueException(
|
||||
"Unable to attach volume, please specify a VM that does not have VM snapshots");
|
||||
"Unable to attach volume, please specify a VM that does not have VM snapshots");
|
||||
}
|
||||
|
||||
|
||||
// permission check
|
||||
_accountMgr.checkAccess(caller, null, true, volume, vm);
|
||||
|
||||
@ -1711,7 +1702,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
+ " to a " + rootDiskHyperType + " vm");
|
||||
}
|
||||
|
||||
|
||||
|
||||
deviceId = getDeviceId(vmId, deviceId);
|
||||
VolumeInfo volumeOnPrimaryStorage = volume;
|
||||
if (volume.getState().equals(Volume.State.Allocated)
|
||||
@ -1839,7 +1830,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
|
||||
if(vmSnapshots.size() > 0){
|
||||
throw new InvalidParameterValueException(
|
||||
"Unable to detach volume, the specified volume is attached to a VM that has VM snapshots.");
|
||||
"Unable to detach volume, the specified volume is attached to a VM that has VM snapshots.");
|
||||
}
|
||||
|
||||
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor
|
||||
@ -1906,10 +1897,10 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@DB
|
||||
protected VolumeVO switchVolume(VolumeVO existingVolume,
|
||||
@ -1950,13 +1941,13 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void release(VirtualMachineProfile<? extends VMInstanceVO> profile) {
|
||||
// add code here
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public void cleanupVolumes(long vmId) throws ConcurrentOperationException {
|
||||
@ -2001,7 +1992,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
public Volume migrateVolume(MigrateVolumeCmd cmd) {
|
||||
Long volumeId = cmd.getVolumeId();
|
||||
Long storagePoolId = cmd.getStoragePoolId();
|
||||
|
||||
|
||||
VolumeVO vol = _volsDao.findById(volumeId);
|
||||
if (vol == null) {
|
||||
throw new InvalidParameterValueException(
|
||||
@ -2034,8 +2025,8 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
return newVol;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@DB
|
||||
protected Volume migrateVolume(Volume volume, StoragePool destPool) {
|
||||
VolumeInfo vol = this.volFactory.getVolume(volume.getId());
|
||||
@ -2093,7 +2084,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void prepareForMigration(
|
||||
VirtualMachineProfile<? extends VirtualMachine> vm,
|
||||
@ -2124,7 +2115,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static enum VolumeTaskType {
|
||||
RECREATE,
|
||||
@ -2141,7 +2132,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
this.volume = volume;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<VolumeTask> getTasks(List<VolumeVO> vols, Map<Volume, StoragePool> destVols) throws StorageUnavailableException {
|
||||
boolean recreate = _recreateSystemVmEnabled;
|
||||
List<VolumeTask> tasks = new ArrayList<VolumeTask>();
|
||||
@ -2229,11 +2220,11 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
tasks.add(task);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return tasks;
|
||||
}
|
||||
|
||||
private Pair<VolumeVO, DataStore> recreateVolume(VolumeVO vol, VirtualMachineProfile<? extends VirtualMachine> vm,
|
||||
|
||||
private Pair<VolumeVO, DataStore> recreateVolume(VolumeVO vol, VirtualMachineProfile<? extends VirtualMachine> vm,
|
||||
DeployDestination dest) throws StorageUnavailableException {
|
||||
VolumeVO newVol;
|
||||
boolean recreate = _recreateSystemVmEnabled;
|
||||
@ -2295,15 +2286,15 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
throw new StorageUnavailableException("Unable to create "
|
||||
+ newVol + ":" + e.toString(), destPool.getId());
|
||||
}
|
||||
|
||||
|
||||
return new Pair<VolumeVO, DataStore>(newVol, destPool);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void prepare(VirtualMachineProfile<? extends VirtualMachine> vm,
|
||||
DeployDestination dest) throws StorageUnavailableException,
|
||||
InsufficientStorageCapacityException, ConcurrentOperationException {
|
||||
|
||||
|
||||
if (dest == null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("DeployDestination cannot be null, cannot prepare Volumes for the vm: "
|
||||
@ -2338,7 +2329,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
vm.addDisk(new VolumeTO(vol, pool));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Long getDeviceId(long vmId, Long deviceId) {
|
||||
// allocate deviceId
|
||||
List<VolumeVO> vols = _volsDao.findByInstance(vmId);
|
||||
@ -2365,16 +2356,16 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
}
|
||||
deviceId = Long.parseLong(devIds.iterator().next());
|
||||
}
|
||||
|
||||
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
||||
private boolean stateTransitTo(Volume vol, Volume.Event event)
|
||||
throws NoTransitionException {
|
||||
return _volStateMachine.transitTo(vol, event, null, _volsDao);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String validateUrl(String url) {
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
@ -2416,7 +2407,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canVmRestartOnAnotherServer(long vmId) {
|
||||
List<VolumeVO> vols = _volsDao.findCreatedByInstance(vmId);
|
||||
@ -2427,7 +2418,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
@ -2448,21 +2439,6 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
_copyvolumewait = NumbersUtil.parseInt(value,
|
||||
Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
|
||||
|
||||
HostTemplateStatesSearch = _vmTemplateHostDao.createSearchBuilder();
|
||||
HostTemplateStatesSearch.and("id", HostTemplateStatesSearch.entity()
|
||||
.getTemplateId(), SearchCriteria.Op.EQ);
|
||||
HostTemplateStatesSearch.and("state", HostTemplateStatesSearch.entity()
|
||||
.getDownloadState(), SearchCriteria.Op.EQ);
|
||||
|
||||
SearchBuilder<HostVO> HostSearch = _hostDao.createSearchBuilder();
|
||||
HostSearch.and("dcId", HostSearch.entity().getDataCenterId(),
|
||||
SearchCriteria.Op.EQ);
|
||||
|
||||
HostTemplateStatesSearch.join("host", HostSearch, HostSearch.entity()
|
||||
.getId(), HostTemplateStatesSearch.entity().getHostId(),
|
||||
JoinBuilder.JoinType.INNER);
|
||||
HostSearch.done();
|
||||
HostTemplateStatesSearch.done();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2480,7 +2456,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
||||
public String getName() {
|
||||
return "Volume Manager";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroyVolume(VolumeVO volume) {
|
||||
try {
|
||||
|
||||
@ -31,14 +31,10 @@ import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
@ -101,19 +97,12 @@ import com.cloud.resource.ServerResource;
|
||||
import com.cloud.resource.UnableDeleteHostException;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.dao.SnapshotDao;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
import com.cloud.storage.resource.DummySecondaryStorageResource;
|
||||
import com.cloud.storage.swift.SwiftManager;
|
||||
import com.cloud.storage.template.TemplateConstants;
|
||||
import com.cloud.template.TemplateManager;
|
||||
import com.cloud.user.Account;
|
||||
@ -194,21 +183,14 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
||||
private HostDao _hostDao;
|
||||
@Inject
|
||||
private StoragePoolHostDao _storagePoolHostDao;
|
||||
|
||||
@Inject
|
||||
private VMTemplateHostDao _vmTemplateHostDao;
|
||||
|
||||
@Inject
|
||||
private AgentManager _agentMgr;
|
||||
@Inject
|
||||
protected SwiftManager _swiftMgr;
|
||||
@Inject
|
||||
protected NetworkManager _networkMgr;
|
||||
@Inject
|
||||
protected NetworkModel _networkModel;
|
||||
@Inject
|
||||
protected SnapshotDao _snapshotDao;
|
||||
|
||||
@Inject
|
||||
private ClusterManager _clusterMgr;
|
||||
|
||||
@ -242,7 +224,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
||||
protected IPAddressDao _ipAddressDao = null;
|
||||
@Inject
|
||||
protected RulesManager _rulesMgr;
|
||||
@Inject
|
||||
@Inject
|
||||
TemplateManager templateMgr;
|
||||
|
||||
@Inject
|
||||
@ -367,6 +349,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public boolean deleteHost(Long hostId) {
|
||||
List<SnapshotVO> snapshots = _snapshotDao.listByHostId(hostId);
|
||||
@ -387,6 +370,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean generateVMSetupCommand(Long ssAHostId) {
|
||||
@ -746,13 +730,13 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
||||
s_logger.debug("No hypervisor host added in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
List<DataStore> stores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(dataCenterId));
|
||||
if (stores.size() < 1) {
|
||||
s_logger.debug("No image store added in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
DataStore store = templateMgr.getImageStore(dataCenterId, template.getId());
|
||||
if (store == null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@ -1390,10 +1374,11 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
||||
|
||||
@Override
|
||||
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
|
||||
if (host.getType() == Host.Type.SecondaryStorage) {
|
||||
deleteHost(host.getId());
|
||||
return new DeleteHostAnswer(false);
|
||||
}
|
||||
// Since secondary storage is moved out of host table, this class should not handle delete secondary storage anymore.
|
||||
//if (host.getType() == Host.Type.SecondaryStorage) {
|
||||
// deleteHost(host.getId());
|
||||
// return new DeleteHostAnswer(false);
|
||||
//}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ public interface SecondaryStorageVmManager extends Manager {
|
||||
|
||||
public Pair<HostVO, SecondaryStorageVmVO> assignSecStorageVm(long zoneId, Command cmd);
|
||||
boolean generateSetupCommand(Long hostId);
|
||||
boolean deleteHost(Long hostId);
|
||||
//boolean deleteHost(Long hostId);
|
||||
public HostVO findSecondaryStorageHost(long dcId);
|
||||
public List<HostVO> listSecondaryStorageHostsInAllZones();
|
||||
public List<HostVO> listSecondaryStorageHostsInOneZone(long dataCenterId);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user