starting unit test

This commit is contained in:
Edison Su 2012-11-19 17:59:50 -08:00
parent d62da2a7b5
commit 573d13dd7c
124 changed files with 4822 additions and 4524 deletions

View File

@ -1,34 +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 org.apache.cloudstack.engine.subsystem.api.storage;
import java.util.List;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
public interface PrimaryDataStore {
VolumeEntity getVolume(String id);
List<VolumeEntity> getVolumes();
boolean deleteVolume(VolumeEntity id);
VolumeEntity createVolume(String id, VolumeDiskType diskType);
List<EndPoint> getEndPoints();
PrimaryDataStoreInfo getDataStoreInfo();
}

View File

@ -19,22 +19,22 @@
package org.apache.cloudstack.storage; package org.apache.cloudstack.storage;
public abstract class BaseType { public abstract class BaseType {
public boolean equals(Object that) { public boolean equals(Object that) {
if (this == that) { if (this == that) {
return true; return true;
} }
if (that instanceof String) { if (that instanceof String) {
if (this.toString().equalsIgnoreCase((String)that)) { if (this.toString().equalsIgnoreCase((String) that)) {
return true; return true;
} }
} else if (that instanceof BaseType) { } else if (that instanceof BaseType) {
BaseType th = (BaseType)that; BaseType th = (BaseType) that;
if (this.toString().equalsIgnoreCase(th.toString())) { if (this.toString().equalsIgnoreCase(th.toString())) {
return true; return true;
} }
} else { } else {
return false; return false;
} }
return false; return false;
} }
} }

View File

@ -30,27 +30,28 @@ import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.OperationTimedoutException;
public class HypervisorHostEndPoint implements EndPoint { public class HypervisorHostEndPoint implements EndPoint {
private static final Logger s_logger = Logger.getLogger(HypervisorHostEndPoint.class); private static final Logger s_logger = Logger.getLogger(HypervisorHostEndPoint.class);
private long hostId; private long hostId;
@Inject @Inject
AgentManager agentMgr; AgentManager agentMgr;
public HypervisorHostEndPoint(long hostId) {
this.hostId = hostId;
}
@Override public HypervisorHostEndPoint(long hostId) {
public Answer sendMessage(Command cmd) { this.hostId = hostId;
Answer answer = null; }
try {
answer = agentMgr.send(hostId, cmd); @Override
} catch (AgentUnavailableException e) { public Answer sendMessage(Command cmd) {
s_logger.debug("Unable to send command:" + cmd + ", due to: " + e.toString()); Answer answer = null;
} catch (OperationTimedoutException e) { try {
s_logger.debug("Unable to send command:" + cmd + ", due to: " + e.toString()); answer = agentMgr.send(hostId, cmd);
} catch (Exception e) { } catch (AgentUnavailableException e) {
s_logger.debug("Unable to send command:" + cmd + ", due to: " + e.toString()); s_logger.debug("Unable to send command:" + cmd + ", due to: " + e.toString());
} } catch (OperationTimedoutException e) {
return answer; s_logger.debug("Unable to send command:" + cmd + ", due to: " + e.toString());
} } catch (Exception e) {
s_logger.debug("Unable to send command:" + cmd + ", due to: " + e.toString());
}
return answer;
}
} }

View File

@ -72,295 +72,290 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.dao.VMInstanceDao; import com.cloud.vm.dao.VMInstanceDao;
public class StorageOrchestratorImpl implements StorageOrchestrator { public class StorageOrchestratorImpl implements StorageOrchestrator {
private static final Logger s_logger = Logger.getLogger(StorageOrchestratorImpl.class); private static final Logger s_logger = Logger.getLogger(StorageOrchestratorImpl.class);
@Inject @Inject
StoragePoolDao _storagePoolDao; StoragePoolDao _storagePoolDao;
@Inject @Inject
StorageProviderManager _spManager; StorageProviderManager _spManager;
@Inject @Inject
VolumeDao _volumeDao; VolumeDao _volumeDao;
@Inject @Inject
VMInstanceDao _vmDao; VMInstanceDao _vmDao;
@Inject @Inject
DiskOfferingDao _diskOfferingDao; DiskOfferingDao _diskOfferingDao;
@Inject @Inject
VolumeHostDao _volumeHostDao; VolumeHostDao _volumeHostDao;
@Inject @Inject
StorageProviderManager _storageProviderMgr; StorageProviderManager _storageProviderMgr;
@Inject @Inject
VolumeManager _volumeMgr; VolumeManager _volumeMgr;
@Inject @Inject
SecondaryStorageManager _secondaryStorageMgr; SecondaryStorageManager _secondaryStorageMgr;
@Inject @Inject
ImageManager _templateMgr; ImageManager _templateMgr;
@Inject @Inject
VMTemplateDao _templateDao; VMTemplateDao _templateDao;
@Inject @Inject
VolumeService volumeService; VolumeService volumeService;
@Inject @Inject
ImageMotionService imageMotionService; ImageMotionService imageMotionService;
@Inject @Inject
ImageService imageService; ImageService imageService;
@Inject @Inject
PrimaryDataStoreManager primaryStorageMgr; PrimaryDataStoreManager primaryStorageMgr;
@DB @DB
protected Volume copyVolumeFromBackupStorage(VolumeVO volume, DataStore destStore, String reservationId) throws NoTransitionException { protected Volume copyVolumeFromBackupStorage(VolumeVO volume, DataStore destStore, String reservationId) throws NoTransitionException {
DataStore ds = _secondaryStorageMgr.getStore(volume); DataStore ds = _secondaryStorageMgr.getStore(volume);
if (!ds.contains(volume)) { if (!ds.contains(volume)) {
throw new CloudRuntimeException("volume: " + volume + "doesn't exist on backup storage"); throw new CloudRuntimeException("volume: " + volume + "doesn't exist on backup storage");
} }
VolumeProfile vp = ds.prepareVolume(volume, destStore); VolumeProfile vp = ds.prepareVolume(volume, destStore);
VolumeStrategy vs = destStore.getVolumeStrategy(); VolumeStrategy vs = destStore.getVolumeStrategy();
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
volume.setReservationId(reservationId); volume.setReservationId(reservationId);
_volumeMgr.processEvent(volume, Volume.Event.CopyRequested); _volumeMgr.processEvent(volume, Volume.Event.CopyRequested);
VolumeVO destVolume = _volumeMgr.allocateDuplicateVolume(volume); VolumeVO destVolume = _volumeMgr.allocateDuplicateVolume(volume);
destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.CreateRequested); destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.CreateRequested);
txn.commit(); txn.commit();
vs.copyVolumeFromBackup(vp, destVolume); vs.copyVolumeFromBackup(vp, destVolume);
txn.start(); txn.start();
volume = _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded); volume = _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded);
destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.OperationSucceeded); destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.OperationSucceeded);
txn.commit(); txn.commit();
return destVolume; return destVolume;
} }
@DB @DB
protected Volume migrateVolume(VolumeVO volume, DataStore srcStore, DataStore destStore, String reservationId) throws NoTransitionException { protected Volume migrateVolume(VolumeVO volume, DataStore srcStore, DataStore destStore, String reservationId) throws NoTransitionException {
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
txn.start(); txn.start();
volume.setReservationId(reservationId); volume.setReservationId(reservationId);
volume = _volumeMgr.processEvent(volume, Volume.Event.MigrationRequested); volume = _volumeMgr.processEvent(volume, Volume.Event.MigrationRequested);
Volume destVolume = _volumeMgr.allocateDuplicateVolume(volume); Volume destVolume = _volumeMgr.allocateDuplicateVolume(volume);
destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.CreateRequested); destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.CreateRequested);
txn.commit(); txn.commit();
VolumeStrategy vs = srcStore.getVolumeStrategy(); VolumeStrategy vs = srcStore.getVolumeStrategy();
vs.migrateVolume(volume, destVolume, destStore); vs.migrateVolume(volume, destVolume, destStore);
txn.start(); txn.start();
volume = _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded); volume = _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded);
destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.OperationSucceeded); destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.OperationSucceeded);
txn.commit(); txn.commit();
volume = _volumeMgr.processEvent(volume, Volume.Event.DestroyRequested); volume = _volumeMgr.processEvent(volume, Volume.Event.DestroyRequested);
vs.deleteVolume(volume); vs.deleteVolume(volume);
_volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded); _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded);
return destVolume; return destVolume;
} }
@DB @DB
protected Volume recreateVolume(VolumeVO srcVolume, DataStore destStore, String reservationId) throws NoTransitionException { protected Volume recreateVolume(VolumeVO srcVolume, DataStore destStore, String reservationId) throws NoTransitionException {
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
txn.start(); txn.start();
srcVolume.setReservationId(reservationId); srcVolume.setReservationId(reservationId);
srcVolume = _volumeMgr.processEvent(srcVolume, Volume.Event.CopyRequested); srcVolume = _volumeMgr.processEvent(srcVolume, Volume.Event.CopyRequested);
Volume destVolume = _volumeMgr.allocateDuplicateVolume(srcVolume); Volume destVolume = _volumeMgr.allocateDuplicateVolume(srcVolume);
destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.CreateRequested); destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.CreateRequested);
txn.commit(); txn.commit();
DataStore srcStore = _storageProviderMgr.getDataStore(srcVolume.getPoolId()); DataStore srcStore = _storageProviderMgr.getDataStore(srcVolume.getPoolId());
VolumeStrategy vs = srcStore.getVolumeStrategy(); VolumeStrategy vs = srcStore.getVolumeStrategy();
vs.migrateVolume(srcVolume, destVolume, destStore); vs.migrateVolume(srcVolume, destVolume, destStore);
txn.start(); txn.start();
srcVolume = _volumeMgr.processEvent(srcVolume, Volume.Event.OperationSucceeded); srcVolume = _volumeMgr.processEvent(srcVolume, Volume.Event.OperationSucceeded);
destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.OperationSucceeded); destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.OperationSucceeded);
txn.commit(); txn.commit();
srcVolume = _volumeMgr.processEvent(srcVolume, Volume.Event.DestroyRequested); srcVolume = _volumeMgr.processEvent(srcVolume, Volume.Event.DestroyRequested);
vs.deleteVolume(srcVolume); vs.deleteVolume(srcVolume);
_volumeMgr.processEvent(srcVolume, Volume.Event.OperationSucceeded); _volumeMgr.processEvent(srcVolume, Volume.Event.OperationSucceeded);
return destVolume; return destVolume;
} }
protected Volume createVolumeOnStorage(Volume volume, DataStore destStore, String reservationId) throws NoTransitionException { protected Volume createVolumeOnStorage(Volume volume, DataStore destStore, String reservationId) throws NoTransitionException {
VolumeStrategy vs = destStore.getVolumeStrategy(); VolumeStrategy vs = destStore.getVolumeStrategy();
volume.setReservationId(reservationId); volume.setReservationId(reservationId);
volume = _volumeMgr.processEvent(volume, Volume.Event.CreateRequested); volume = _volumeMgr.processEvent(volume, Volume.Event.CreateRequested);
if (volume.getTemplateId() != null) { if (volume.getTemplateId() != null) {
DataStore ds = _secondaryStorageMgr.getImageStore(destStore); DataStore ds = _secondaryStorageMgr.getImageStore(destStore);
TemplateProfile tp = ds.prepareTemplate(volume.getTemplateId(), destStore); TemplateProfile tp = ds.prepareTemplate(volume.getTemplateId(), destStore);
if (!destStore.contains(tp)) { if (!destStore.contains(tp)) {
tp = _templateMgr.AssociateTemplateStoragePool(tp, destStore); tp = _templateMgr.AssociateTemplateStoragePool(tp, destStore);
tp = destStore.getTemplateStrategy().install(tp); tp = destStore.getTemplateStrategy().install(tp);
} else { } else {
tp = destStore.getTemplateStrategy().get(tp.getId()); tp = destStore.getTemplateStrategy().get(tp.getId());
} }
volume = vs.createVolumeFromBaseTemplate(volume, tp); volume = vs.createVolumeFromBaseTemplate(volume, tp);
} else { } else {
volume = vs.createDataVolume(volume); volume = vs.createDataVolume(volume);
} }
volume = _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded); volume = _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded);
return volume; return volume;
} }
@DB @DB
protected void prepareVolumes(List<VolumeVO> vols, Long destPoolId, String reservationId) throws NoTransitionException { protected void prepareVolumes(List<VolumeVO> vols, Long destPoolId, String reservationId) throws NoTransitionException {
DataStore destStore = null; DataStore destStore = null;
if (destPoolId != null) { if (destPoolId != null) {
destStore = _storageProviderMgr.getDataStore(destPoolId); destStore = _storageProviderMgr.getDataStore(destPoolId);
} }
for (VolumeVO volume : vols) { for (VolumeVO volume : vols) {
if (volume.getPoolId() == null && destStore == null) { if (volume.getPoolId() == null && destStore == null) {
throw new CloudRuntimeException("Volume has no pool associate and also no storage pool assigned in DeployDestination, Unable to create."); throw new CloudRuntimeException("Volume has no pool associate and also no storage pool assigned in DeployDestination, Unable to create.");
} }
if (destStore == null) { if (destStore == null) {
continue; continue;
} }
DataStore srcStore = _storageProviderMgr.getDataStore(volume.getPoolId()); DataStore srcStore = _storageProviderMgr.getDataStore(volume.getPoolId());
boolean needToCreateVolume = false; boolean needToCreateVolume = false;
boolean needToRecreateVolume = false; boolean needToRecreateVolume = false;
boolean needToMigrateVolume = false; boolean needToMigrateVolume = false;
boolean needToCopyFromSec = false; boolean needToCopyFromSec = false;
Volume.State state = volume.getState(); Volume.State state = volume.getState();
if (state == Volume.State.Allocated) { if (state == Volume.State.Allocated) {
needToCreateVolume = true; needToCreateVolume = true;
} else if (state == Volume.State.UploadOp) { } else if (state == Volume.State.UploadOp) {
needToCopyFromSec = true; needToCopyFromSec = true;
} else if (destStore.getId() != srcStore.getId()) { } else if (destStore.getId() != srcStore.getId()) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Mismatch in storage pool " + destStore.getId() + " assigned by deploymentPlanner and the one associated with volume " + volume); s_logger.debug("Mismatch in storage pool " + destStore.getId() + " assigned by deploymentPlanner and the one associated with volume " + volume);
} }
if (volume.isRecreatable()) { if (volume.isRecreatable()) {
needToRecreateVolume = true; needToRecreateVolume = true;
} else { } else {
if (Volume.Type.ROOT == volume.getVolumeType()) { if (Volume.Type.ROOT == volume.getVolumeType()) {
needToMigrateVolume = true; needToMigrateVolume = true;
} else { } else {
if (destStore.getCluterId() != srcStore.getCluterId()) { if (destStore.getCluterId() != srcStore.getCluterId()) {
needToMigrateVolume = true; needToMigrateVolume = true;
} else if (!srcStore.isSharedStorage() && srcStore.getId() != destStore.getId()) { } else if (!srcStore.isSharedStorage() && srcStore.getId() != destStore.getId()) {
needToMigrateVolume = true; needToMigrateVolume = true;
} else { } else {
continue; continue;
} }
} }
} }
} else { } else {
continue; continue;
} }
if (needToCreateVolume) {
createVolumeOnStorage(volume, destStore, reservationId);
} else if (needToMigrateVolume) {
migrateVolume(volume, srcStore, destStore, reservationId);
} else if (needToCopyFromSec) {
copyVolumeFromBackupStorage(volume, destStore, reservationId);
} else if (needToRecreateVolume) {
recreateVolume(volume, destStore, reservationId);
}
}
}
if (needToCreateVolume) { public void prepare(long vmId, DeploymentPlan plan, String reservationId) {
createVolumeOnStorage(volume, destStore, reservationId);
} else if (needToMigrateVolume) {
migrateVolume(volume, srcStore, destStore, reservationId);
} else if (needToCopyFromSec) {
copyVolumeFromBackupStorage(volume, destStore, reservationId);
} else if (needToRecreateVolume) {
recreateVolume(volume, destStore, reservationId);
}
}
}
public void prepare(long vmId, DeploymentPlan plan, String reservationId) {
VirtualMachine vm = _vmDao.findById(vmId); VirtualMachine vm = _vmDao.findById(vmId);
List<VolumeVO> vols = _volumeDao.findUsableVolumesForInstance(vm.getId()); List<VolumeVO> vols = _volumeDao.findUsableVolumesForInstance(vm.getId());
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Prepare " + vols.size() + " volumes for " + vm.getInstanceName()); s_logger.debug("Prepare " + vols.size() + " volumes for " + vm.getInstanceName());
} }
try { try {
prepareVolumes(vols, plan.getPoolId(), reservationId); prepareVolumes(vols, plan.getPoolId(), reservationId);
} catch (NoTransitionException e) { } catch (NoTransitionException e) {
s_logger.debug("Failed to prepare volume: " + e.toString()); s_logger.debug("Failed to prepare volume: " + e.toString());
} }
} }
public void release(long vmId, String reservationId) {
// TODO Auto-generated method stub
public void release(long vmId, String reservationId) { }
// TODO Auto-generated method stub
} public void destroy(List<Long> disks, String reservationId) {
// TODO Auto-generated method stub
public void destroy(List<Long> disks, String reservationId) { }
// TODO Auto-generated method stub
} public void cancel(String reservationId) {
// TODO Auto-generated method stub
public void cancel(String reservationId) { }
// TODO Auto-generated method stub
} public void prepareAttachDiskToVM(long diskId, long vmId, String reservationId) {
VirtualMachine vm = _vmDao.findById(vmId);
public void prepareAttachDiskToVM(long diskId, long vmId, String reservationId) { if (vm == null || vm.getState() != VirtualMachine.State.Running) {
VirtualMachine vm = _vmDao.findById(vmId); return;
}
if (vm == null || vm.getState() != VirtualMachine.State.Running) { VolumeVO volume = _volumeDao.findById(diskId);
return; if (volume.getInstanceId() != null) {
} if (volume.getInstanceId() != vmId) {
throw new InvalidParameterValueException("Volume " + volume + "already attached to " + volume.getInstanceId());
} else {
return;
}
}
VolumeVO volume = _volumeDao.findById(diskId); List<VolumeVO> vols = new ArrayList<VolumeVO>();
if (volume.getInstanceId() != null) { vols.add(volume);
if (volume.getInstanceId() != vmId) {
throw new InvalidParameterValueException("Volume " + volume + "already attached to " + volume.getInstanceId());
} else {
return;
}
}
List<VolumeVO> vols = new ArrayList<VolumeVO>(); List<VolumeVO> rootDisks = _volumeDao.findByInstanceAndType(vmId, Volume.Type.ROOT);
vols.add(volume); VolumeVO rootDisk = rootDisks.get(0);
try {
prepareVolumes(vols, rootDisk.getPoolId(), reservationId);
} catch (NoTransitionException e) {
s_logger.debug("Failed to prepare volume: " + volume + ", due to" + e.toString());
throw new CloudRuntimeException(e.toString());
}
List<VolumeVO> rootDisks = _volumeDao.findByInstanceAndType(vmId, Volume.Type.ROOT); volume = _volumeDao.findById(diskId);
VolumeVO rootDisk = rootDisks.get(0); volume.setInstanceId(vmId);
try { _volumeDao.update(volume.getId(), volume);
prepareVolumes(vols, rootDisk.getPoolId(), reservationId); }
} catch (NoTransitionException e) {
s_logger.debug("Failed to prepare volume: " + volume + ", due to" + e.toString());
throw new CloudRuntimeException(e.toString());
}
volume = _volumeDao.findById(diskId); @Override
volume.setInstanceId(vmId); public boolean createVolume(VolumeEntity volume, long dataStoreId, VolumeDiskType diskType) {
_volumeDao.update(volume.getId(), volume); VolumeEntityImpl vei = ((VolumeEntityImpl) volume);
} VolumeInfo vi = volumeService.createVolume(vei.getVolumeInfo(), dataStoreId, diskType);
vei.setVolumeInfo(vi);
return true;
}
@Override
public VolumeEntity allocateVolumeInDb(long size, VolumeType type, String volName, Long templateId) {
return volumeService.allocateVolumeInDb(size, type, volName, templateId);
}
protected VolumeInfo getVolumeInfo(VolumeEntity volume) {
VolumeEntityImpl vei = (VolumeEntityImpl) volume;
return vei.getVolumeInfo();
}
@Override @Override
public boolean createVolume(VolumeEntity volume, long dataStoreId, VolumeDiskType diskType) { public boolean createVolumeFromTemplate(VolumeEntity volume, long dataStoreId, VolumeDiskType diskType, TemplateEntity template) {
VolumeEntityImpl vei = ((VolumeEntityImpl)volume);
VolumeInfo vi = volumeService.createVolume(vei.getVolumeInfo(), dataStoreId, diskType);
vei.setVolumeInfo(vi);
return true;
}
@Override return false;
public VolumeEntity allocateVolumeInDb(long size, VolumeType type, String volName, Long templateId) { }
return volumeService.allocateVolumeInDb(size, type, volName, templateId);
}
protected VolumeInfo getVolumeInfo(VolumeEntity volume) {
VolumeEntityImpl vei = (VolumeEntityImpl)volume;
return vei.getVolumeInfo();
}
@Override
public boolean createVolumeFromTemplate(VolumeEntity volume, long dataStoreId, VolumeDiskType diskType, TemplateEntity template) {
return false;
}
} }

View File

@ -4,8 +4,11 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.StorageProvider; import org.apache.cloudstack.engine.subsystem.api.storage.StorageProvider;
public interface StorageProviderManager { public interface StorageProviderManager {
StorageProvider getProvider(String uuid); StorageProvider getProvider(String uuid);
StorageProvider getProvider(long poolId);
StorageProvider getBackupStorageProvider(long zoneId); StorageProvider getProvider(long poolId);
DataStore getDataStore(long poolId);
StorageProvider getBackupStorageProvider(long zoneId);
DataStore getDataStore(long poolId);
} }

View File

@ -11,45 +11,44 @@ import com.cloud.utils.component.Manager;
public class StorageProviderManagerImpl implements StorageProviderManager, Manager { public class StorageProviderManagerImpl implements StorageProviderManager, Manager {
public StorageProvider getProvider(String uuid) { public StorageProvider getProvider(String uuid) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public boolean configure(String name, Map<String, Object> params) public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
throws ConfigurationException { // TODO Auto-generated method stub
// TODO Auto-generated method stub return false;
return false; }
}
public boolean start() { public boolean start() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public boolean stop() { public boolean stop() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public String getName() { public String getName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public StorageProvider getProvider(long poolId) { public StorageProvider getProvider(long poolId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public StorageProvider getBackupStorageProvider(long zoneId) { public StorageProvider getBackupStorageProvider(long zoneId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataStore getDataStore(long poolId) { public DataStore getDataStore(long poolId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -28,39 +28,39 @@ import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
public interface VolumeBackupRef { public interface VolumeBackupRef {
public DataObjectBackupStorageOperationState getOperationState(); public DataObjectBackupStorageOperationState getOperationState();
public String getInstallPath(); public String getInstallPath();
public long getHostId(); public long getHostId();
public long getVolumeId(); public long getVolumeId();
public long getZoneId(); public long getZoneId();
public int getDownloadPercent(); public int getDownloadPercent();
public long getVolumeSize(); public long getVolumeSize();
public Storage.ImageFormat getFormat(); public Storage.ImageFormat getFormat();
public String getDownloadUrl(); public String getDownloadUrl();
public boolean getDestroyed(); public boolean getDestroyed();
public long getPhysicalSize(); public long getPhysicalSize();
public long getSize(); public long getSize();
public String getLocalDownloadPath(); public String getLocalDownloadPath();
public String getChecksum(); public String getChecksum();
public Status getDownloadState(); public Status getDownloadState();
public Date getLastUpdated(); public Date getLastUpdated();
public Date getCreated(); public Date getCreated();
public long getId(); public long getId();
} }

View File

@ -19,5 +19,5 @@
package org.apache.cloudstack.storage.backup; package org.apache.cloudstack.storage.backup;
public interface BackupMotionService { public interface BackupMotionService {
boolean copySnapshot(String snapshotUri, String destSnapshotUri); boolean copySnapshot(String snapshotUri, String destSnapshotUri);
} }

View File

@ -19,6 +19,7 @@
package org.apache.cloudstack.storage.backup; package org.apache.cloudstack.storage.backup;
public interface BackupService { public interface BackupService {
String grantAccessSnapshot(long snapshotId, long endpointId); String grantAccessSnapshot(long snapshotId, long endpointId);
boolean revokeAccessSnapshot(long snapshotId, long endpointId);
boolean revokeAccessSnapshot(long snapshotId, long endpointId);
} }

View File

@ -8,21 +8,21 @@ import com.cloud.agent.api.Command;
public class CopyTemplateToPrimaryStorage extends Command { public class CopyTemplateToPrimaryStorage extends Command {
private ImageOnPrimayDataStoreTO imageTO; private ImageOnPrimayDataStoreTO imageTO;
protected CopyTemplateToPrimaryStorage() { protected CopyTemplateToPrimaryStorage() {
super(); super();
} }
public CopyTemplateToPrimaryStorage(ImageOnPrimayDataStoreTO image) { public CopyTemplateToPrimaryStorage(ImageOnPrimayDataStoreTO image) {
super(); super();
this.imageTO = image; this.imageTO = image;
} }
@Override @Override
public boolean executeInSequence() { public boolean executeInSequence() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
} }

View File

@ -21,16 +21,17 @@ package org.apache.cloudstack.storage.command;
import com.cloud.agent.api.Answer; import com.cloud.agent.api.Answer;
public class CreateVolumeAnswer extends Answer { public class CreateVolumeAnswer extends Answer {
private String volumeUuid; private String volumeUuid;
protected CreateVolumeAnswer() {
super();
}
public CreateVolumeAnswer(String volumeUuid) { protected CreateVolumeAnswer() {
this.volumeUuid = volumeUuid; super();
} }
public String getVolumeUuid() { public CreateVolumeAnswer(String volumeUuid) {
return this.volumeUuid; this.volumeUuid = volumeUuid;
} }
public String getVolumeUuid() {
return this.volumeUuid;
}
} }

View File

@ -23,20 +23,21 @@ import org.apache.cloudstack.storage.to.VolumeTO;
import com.cloud.agent.api.Command; import com.cloud.agent.api.Command;
public class CreateVolumeCommand extends Command { public class CreateVolumeCommand extends Command {
protected VolumeTO volumeInfo; protected VolumeTO volumeInfo;
public CreateVolumeCommand(VolumeTO volumeInfo) {
super();
this.volumeInfo = volumeInfo;
}
protected CreateVolumeCommand() { public CreateVolumeCommand(VolumeTO volumeInfo) {
super(); super();
} this.volumeInfo = volumeInfo;
}
@Override protected CreateVolumeCommand() {
public boolean executeInSequence() { super();
// TODO Auto-generated method stub }
return false;
} @Override
public boolean executeInSequence() {
// TODO Auto-generated method stub
return false;
}
} }

View File

@ -24,16 +24,18 @@ import org.apache.cloudstack.storage.to.VolumeTO;
import com.cloud.agent.api.Command; import com.cloud.agent.api.Command;
public class CreateVolumeFromBaseImageCommand extends Command { public class CreateVolumeFromBaseImageCommand extends Command {
private VolumeTO volume; private VolumeTO volume;
private ImageOnPrimayDataStoreTO image; private ImageOnPrimayDataStoreTO image;
public CreateVolumeFromBaseImageCommand(VolumeTO volume, ImageOnPrimayDataStoreTO image) {
this.volume = volume; public CreateVolumeFromBaseImageCommand(VolumeTO volume, ImageOnPrimayDataStoreTO image) {
this.image = image; this.volume = volume;
} this.image = image;
@Override }
public boolean executeInSequence() {
// TODO Auto-generated method stub @Override
return false; public boolean executeInSequence() {
} // TODO Auto-generated method stub
return false;
}
} }

View File

@ -19,11 +19,5 @@
package org.apache.cloudstack.storage.datastore; package org.apache.cloudstack.storage.datastore;
public enum DataStoreStatus { public enum DataStoreStatus {
Creating, Creating, Up, PrepareForMaintenance, ErrorInMaintenance, CancelMaintenance, Maintenance, Removed;
Up,
PrepareForMaintenance,
ErrorInMaintenance,
CancelMaintenance,
Maintenance,
Removed;
} }

View File

@ -20,210 +20,209 @@ import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.Volume; import com.cloud.storage.Volume;
public class DefaultDataStore implements DataStore { public class DefaultDataStore implements DataStore {
protected VolumeStrategy _volumeStrategy; protected VolumeStrategy _volumeStrategy;
protected SnapshotStrategy _snapshotStrategy; protected SnapshotStrategy _snapshotStrategy;
protected BackupStrategy _backupStrategy; protected BackupStrategy _backupStrategy;
protected TemplateStrategy _templateStrategy; protected TemplateStrategy _templateStrategy;
protected String _uri; protected String _uri;
protected String _uuid; protected String _uuid;
protected StoreType _type; protected StoreType _type;
protected StoreScope _scope; protected StoreScope _scope;
protected long _poolId; protected long _poolId;
protected DataStoreDriver _driverRef; protected DataStoreDriver _driverRef;
protected DataStoreEndPointSelector _selector; protected DataStoreEndPointSelector _selector;
protected FileSystem _fs; protected FileSystem _fs;
protected VolumeStrategy _volumeSt; protected VolumeStrategy _volumeSt;
protected SnapshotStrategy _snapshotSt; protected SnapshotStrategy _snapshotSt;
protected BackupStrategy _backupSt; protected BackupStrategy _backupSt;
protected long _id; protected long _id;
protected DataStoreLifeCycle _dslf; protected DataStoreLifeCycle _dslf;
public DefaultDataStore( public DefaultDataStore() {
) { }
}
public String getURI() { public String getURI() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public void setURI(String uri) { public void setURI(String uri) {
this._uri = uri; this._uri = uri;
} }
public String getUUID() { public String getUUID() {
return this._uuid; return this._uuid;
} }
public void setUUID(String uuid) { public void setUUID(String uuid) {
this._uuid = uuid; this._uuid = uuid;
} }
public StoreType getType() { public StoreType getType() {
return this._type; return this._type;
} }
public void setType(StoreType type) { public void setType(StoreType type) {
this._type = type; this._type = type;
} }
public StoreScope getScope() { public StoreScope getScope() {
return this._scope; return this._scope;
} }
public void setScope(StoreScope scope) { public void setScope(StoreScope scope) {
this._scope = scope; this._scope = scope;
} }
public Long getId() { public Long getId() {
return this._id; return this._id;
} }
public void setId(long id) { public void setId(long id) {
this._id = id; this._id = id;
} }
public DataStoreDriver getDataStoreDriver() { public DataStoreDriver getDataStoreDriver() {
return this._driverRef; return this._driverRef;
} }
public void setDataStoreDriver(DataStoreDriver drv) { public void setDataStoreDriver(DataStoreDriver drv) {
this._driverRef = drv; this._driverRef = drv;
} }
public void setEndPointSelector(DataStoreEndPointSelector selector) { public void setEndPointSelector(DataStoreEndPointSelector selector) {
this._selector = selector; this._selector = selector;
} }
public DataStoreEndPointSelector getSelector() { public DataStoreEndPointSelector getSelector() {
return this._selector; return this._selector;
} }
public FileSystem getFileSystem() { public FileSystem getFileSystem() {
return this._fs; return this._fs;
} }
public void setFileSystem(FileSystem fs) { public void setFileSystem(FileSystem fs) {
this._fs = fs; this._fs = fs;
} }
public VolumeStrategy getVolumeStrategy() { public VolumeStrategy getVolumeStrategy() {
return this._volumeSt; return this._volumeSt;
} }
public void setVolumeStrategy(VolumeStrategy vs) { public void setVolumeStrategy(VolumeStrategy vs) {
this._volumeSt = vs; this._volumeSt = vs;
} }
public SnapshotStrategy getSnapshotStrategy() { public SnapshotStrategy getSnapshotStrategy() {
return this._snapshotSt; return this._snapshotSt;
} }
public void setSnapshotStrategy(SnapshotStrategy ss) { public void setSnapshotStrategy(SnapshotStrategy ss) {
this._snapshotSt = ss; this._snapshotSt = ss;
} }
public BackupStrategy getBackupStrategy() { public BackupStrategy getBackupStrategy() {
return this._backupSt; return this._backupSt;
} }
public void setBackupStrategy(BackupStrategy bs) { public void setBackupStrategy(BackupStrategy bs) {
this._backupSt = bs; this._backupSt = bs;
} }
public TemplateStrategy getTemplateStrategy() { public TemplateStrategy getTemplateStrategy() {
return this._templateStrategy; return this._templateStrategy;
} }
public void setTemplateStrategy(TemplateStrategy ts) { public void setTemplateStrategy(TemplateStrategy ts) {
this._templateStrategy = ts; this._templateStrategy = ts;
} }
public DataStoreLifeCycle getLifeCycle() { public DataStoreLifeCycle getLifeCycle() {
return this._dslf; return this._dslf;
} }
public void setLifeCycle(DataStoreLifeCycle lf) { public void setLifeCycle(DataStoreLifeCycle lf) {
this._dslf = lf; this._dslf = lf;
} }
public long getCluterId() { public long getCluterId() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }
public long getPodId() { public long getPodId() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }
public long getZoneId() { public long getZoneId() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }
public String getPath() { public String getPath() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public StoragePoolType getPoolType() { public StoragePoolType getPoolType() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public boolean isSharedStorage() { public boolean isSharedStorage() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public StorageProvider getProvider() { public StorageProvider getProvider() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataStoreEndPointSelector getEndPointSelector() { public DataStoreEndPointSelector getEndPointSelector() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public VolumeProfile prepareVolume(Volume volume, DataStore destStore) { public VolumeProfile prepareVolume(Volume volume, DataStore destStore) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public SnapshotProfile prepareSnapshot(Snapshot snapshot, DataStore destStore) { public SnapshotProfile prepareSnapshot(Snapshot snapshot, DataStore destStore) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public TemplateProfile prepareTemplate(long templateId, DataStore destStore) { public TemplateProfile prepareTemplate(long templateId, DataStore destStore) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public boolean contains(Volume volume) { public boolean contains(Volume volume) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public boolean contains(Snapshot snapshot) { public boolean contains(Snapshot snapshot) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public boolean contains(TemplateProfile template) { public boolean contains(TemplateProfile template) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public TemplateProfile get(TemplateProfile template) { public TemplateProfile get(TemplateProfile template) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public StorageFilerTO getTO() { public StorageFilerTO getTO() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -36,144 +36,145 @@ import com.cloud.utils.exception.CloudRuntimeException;
import edu.emory.mathcs.backport.java.util.Collections; import edu.emory.mathcs.backport.java.util.Collections;
public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore { public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreImpl.class); private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreImpl.class);
protected PrimaryDataStoreDriver driver; protected PrimaryDataStoreDriver driver;
protected DataStoreVO pdsv; protected DataStoreVO pdsv;
protected PrimaryDataStoreInfo pdsInfo; protected PrimaryDataStoreInfo pdsInfo;
@Inject @Inject
private VolumeDao volumeDao; private VolumeDao volumeDao;
@Inject @Inject
private HostDao hostDao; private HostDao hostDao;
@Inject @Inject
TemplatePrimaryDataStoreManager templatePrimaryStoreMgr; TemplatePrimaryDataStoreManager templatePrimaryStoreMgr;
public DefaultPrimaryDataStoreImpl(PrimaryDataStoreDriver driver, DataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) {
this.driver = driver;
this.pdsv = pdsv;
this.pdsInfo = pdsInfo;
}
@Override public DefaultPrimaryDataStoreImpl(PrimaryDataStoreDriver driver, DataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) {
public VolumeInfo getVolume(long id) { this.driver = driver;
VolumeVO volumeVO = volumeDao.findById(id); this.pdsv = pdsv;
VolumeObject vol = new VolumeObject(this, volumeVO); this.pdsInfo = pdsInfo;
return vol; }
}
@Override @Override
public List<VolumeInfo> getVolumes() { public VolumeInfo getVolume(long id) {
// TODO Auto-generated method stub VolumeVO volumeVO = volumeDao.findById(id);
return null; VolumeObject vol = new VolumeObject(this, volumeVO);
} return vol;
}
@Override @Override
public boolean deleteVolume(long id) { public List<VolumeInfo> getVolumes() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return null;
} }
@Override @Override
public List<EndPoint> getEndPoints() { public boolean deleteVolume(long id) {
Long clusterId = pdsv.getClusterId(); // TODO Auto-generated method stub
if (clusterId == null) { return false;
return null; }
}
List<EndPoint> endpoints = new ArrayList<EndPoint>();
List<HostVO> hosts = hostDao.findHypervisorHostInCluster(clusterId);
for (HostVO host : hosts) {
HypervisorHostEndPoint ep = new HypervisorHostEndPoint(host.getId());
ComponentInject.inject(ep);
endpoints.add(ep);
}
Collections.shuffle(endpoints);
return endpoints;
}
@Override @Override
public PrimaryDataStoreInfo getDataStoreInfo() { public List<EndPoint> getEndPoints() {
// TODO Auto-generated method stub Long clusterId = pdsv.getClusterId();
return null; if (clusterId == null) {
} return null;
}
List<EndPoint> endpoints = new ArrayList<EndPoint>();
List<HostVO> hosts = hostDao.findHypervisorHostInCluster(clusterId);
for (HostVO host : hosts) {
HypervisorHostEndPoint ep = new HypervisorHostEndPoint(host.getId());
ComponentInject.inject(ep);
endpoints.add(ep);
}
Collections.shuffle(endpoints);
return endpoints;
}
@Override @Override
public boolean isHypervisorSupported(HypervisorType hypervisor) { public PrimaryDataStoreInfo getDataStoreInfo() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return null;
} }
@Override @Override
public boolean isLocalStorageSupported() { public boolean isHypervisorSupported(HypervisorType hypervisor) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean isVolumeDiskTypeSupported(VolumeDiskType diskType) { public boolean isLocalStorageSupported() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public long getCapacity() { public boolean isVolumeDiskTypeSupported(VolumeDiskType diskType) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return false;
} }
@Override @Override
public long getAvailableCapacity() { public long getCapacity() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }
@Override @Override
public VolumeObject createVolume(VolumeInfo vi, VolumeDiskType diskType) { public long getAvailableCapacity() {
if (!pdsInfo.isVolumeDiskTypeSupported(diskType)) { // TODO Auto-generated method stub
return null; return 0;
} }
VolumeObject vo = (VolumeObject)vi;
vo.setVolumeDiskType(diskType);
this.driver.createVolume(vo);
return vo;
}
@Override @Override
public boolean exists(VolumeInfo vi) { public VolumeObject createVolume(VolumeInfo vi, VolumeDiskType diskType) {
// TODO Auto-generated method stub if (!pdsInfo.isVolumeDiskTypeSupported(diskType)) {
return false; return null;
} }
VolumeObject vo = (VolumeObject) vi;
vo.setVolumeDiskType(diskType);
this.driver.createVolume(vo);
return vo;
}
@Override @Override
public boolean templateExists(TemplateInfo template) { public boolean exists(VolumeInfo vi) {
return (templatePrimaryStoreMgr.findTemplateOnPrimaryDataStore(template, this) != null) ? true : false; // TODO Auto-generated method stub
} return false;
}
@Override @Override
public VolumeDiskType getDefaultDiskType() { public boolean templateExists(TemplateInfo template) {
// TODO Auto-generated method stub return (templatePrimaryStoreMgr.findTemplateOnPrimaryDataStore(template, this) != null) ? true : false;
return null; }
}
@Override @Override
public long getId() { public VolumeDiskType getDefaultDiskType() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return null;
} }
@Override @Override
public TemplateOnPrimaryDataStoreInfo getTemplate(TemplateInfo template) { public long getId() {
return templatePrimaryStoreMgr.findTemplateOnPrimaryDataStore(template, this); // TODO Auto-generated method stub
} return 0;
}
@Override @Override
public VolumeInfo createVoluemFromBaseImage(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo template) { public TemplateOnPrimaryDataStoreInfo getTemplate(TemplateInfo template) {
VolumeObject vo = (VolumeObject)volume; return templatePrimaryStoreMgr.findTemplateOnPrimaryDataStore(template, this);
vo.setVolumeDiskType(template.getTemplate().getDiskType()); }
this.driver.createVolumeFromBaseImage(vo, template);
return volume;
}
@Override @Override
public boolean installTemplate(TemplateOnPrimaryDataStoreInfo template) { public VolumeInfo createVoluemFromBaseImage(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo template) {
// TODO Auto-generated method stub VolumeObject vo = (VolumeObject) volume;
return true; vo.setVolumeDiskType(template.getTemplate().getDiskType());
} this.driver.createVolumeFromBaseImage(vo, template);
return volume;
}
@Override
public boolean installTemplate(TemplateOnPrimaryDataStoreInfo template) {
// TODO Auto-generated method stub
return true;
}
} }

View File

@ -30,19 +30,29 @@ import org.apache.cloudstack.storage.image.TemplateObject;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo; import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
import org.apache.cloudstack.storage.volume.VolumeObject; import org.apache.cloudstack.storage.volume.VolumeObject;
public interface PrimaryDataStore extends PrimaryDataStoreInfo { public interface PrimaryDataStore extends PrimaryDataStoreInfo {
VolumeInfo getVolume(long id); VolumeInfo getVolume(long id);
List<VolumeInfo> getVolumes();
boolean deleteVolume(long id); List<VolumeInfo> getVolumes();
VolumeInfo createVolume(VolumeInfo vo, VolumeDiskType diskType);
VolumeInfo createVoluemFromBaseImage(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo templateStore); boolean deleteVolume(long id);
List<EndPoint> getEndPoints();
PrimaryDataStoreInfo getDataStoreInfo(); VolumeInfo createVolume(VolumeInfo vo, VolumeDiskType diskType);
boolean exists(VolumeInfo vi);
boolean templateExists(TemplateInfo template); VolumeInfo createVoluemFromBaseImage(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo templateStore);
TemplateOnPrimaryDataStoreInfo getTemplate(TemplateInfo template);
boolean installTemplate(TemplateOnPrimaryDataStoreInfo template); List<EndPoint> getEndPoints();
VolumeDiskType getDefaultDiskType();
PrimaryDataStoreInfo getDataStoreInfo();
boolean exists(VolumeInfo vi);
boolean templateExists(TemplateInfo template);
TemplateOnPrimaryDataStoreInfo getTemplate(TemplateInfo template);
boolean installTemplate(TemplateOnPrimaryDataStoreInfo template);
VolumeDiskType getDefaultDiskType();
} }

View File

@ -27,55 +27,54 @@ import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTyp
import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.Hypervisor.HypervisorType;
public class PrimaryDataStoreInfoImpl implements PrimaryDataStoreInfo { public class PrimaryDataStoreInfoImpl implements PrimaryDataStoreInfo {
protected List<HypervisorType> supportedHypervs; protected List<HypervisorType> supportedHypervs;
protected List<VolumeDiskType> supportedDiskTypes; protected List<VolumeDiskType> supportedDiskTypes;
protected long caapcity; protected long caapcity;
protected long avail; protected long avail;
protected boolean localStorage; protected boolean localStorage;
public PrimaryDataStoreInfoImpl(List<HypervisorType> hypers, List<VolumeDiskType> diskTypes, public PrimaryDataStoreInfoImpl(List<HypervisorType> hypers, List<VolumeDiskType> diskTypes, long capacity, long avail, boolean localStorage) {
long capacity, long avail, boolean localStorage) { this.avail = avail;
this.avail = avail; this.caapcity = capacity;
this.caapcity = capacity; this.localStorage = localStorage;
this.localStorage = localStorage; this.supportedDiskTypes = diskTypes;
this.supportedDiskTypes = diskTypes; this.supportedHypervs = hypers;
this.supportedHypervs = hypers; }
}
@Override @Override
public boolean isHypervisorSupported(HypervisorType hypervisor) { public boolean isHypervisorSupported(HypervisorType hypervisor) {
return this.supportedHypervs.contains(hypervisor) ? true : false; return this.supportedHypervs.contains(hypervisor) ? true : false;
} }
@Override @Override
public boolean isLocalStorageSupported() { public boolean isLocalStorageSupported() {
return this.localStorage; return this.localStorage;
} }
@Override @Override
public boolean isVolumeDiskTypeSupported(VolumeDiskType diskType) { public boolean isVolumeDiskTypeSupported(VolumeDiskType diskType) {
return this.supportedDiskTypes.contains(diskType) ? true : false; return this.supportedDiskTypes.contains(diskType) ? true : false;
} }
@Override @Override
public long getCapacity() { public long getCapacity() {
return this.caapcity; return this.caapcity;
} }
@Override @Override
public long getAvailableCapacity() { public long getAvailableCapacity() {
return this.avail; return this.avail;
} }
@Override @Override
public List<EndPoint> getEndPoints() { public List<EndPoint> getEndPoints() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public long getId() { public long getId() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }
} }

View File

@ -39,142 +39,140 @@ import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
@Entity @Entity
@Table(name="storage_pool") @Table(name = "storage_pool")
public class DataStoreVO implements Identity { public class DataStoreVO implements Identity {
@Id @Id
@TableGenerator(name="storage_pool_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="storage_pool_seq", allocationSize=1) @TableGenerator(name = "storage_pool_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "storage_pool_seq", allocationSize = 1)
@Column(name="id", updatable=false, nullable = false) @Column(name = "id", updatable = false, nullable = false)
private long id; private long id;
@Column(name="name", updatable=false, nullable=false, length=255) @Column(name = "name", updatable = false, nullable = false, length = 255)
private String name = null; private String name = null;
@Column(name="uuid", length=255) @Column(name = "uuid", length = 255)
private String uuid = null; private String uuid = null;
@Column(name="pool_type", updatable=false, nullable=false, length=32) @Column(name = "pool_type", updatable = false, nullable = false, length = 32)
private String protocol; private String protocol;
@Column(name=GenericDao.CREATED_COLUMN) @Column(name = GenericDao.CREATED_COLUMN)
Date created; Date created;
@Column(name=GenericDao.REMOVED_COLUMN) @Column(name = GenericDao.REMOVED_COLUMN)
private Date removed; private Date removed;
@Column(name="update_time", updatable=true) @Column(name = "update_time", updatable = true)
@Temporal(value=TemporalType.TIMESTAMP) @Temporal(value = TemporalType.TIMESTAMP)
private Date updateTime; private Date updateTime;
@Column(name="data_center_id", updatable=true, nullable=false) @Column(name = "data_center_id", updatable = true, nullable = false)
private long dataCenterId; private long dataCenterId;
@Column(name="pod_id", updatable=true) @Column(name = "pod_id", updatable = true)
private Long podId; private Long podId;
@Column(name="available_bytes", updatable=true, nullable=true) @Column(name = "available_bytes", updatable = true, nullable = true)
private long availableBytes; private long availableBytes;
@Column(name="capacity_bytes", updatable=true, nullable=true) @Column(name = "capacity_bytes", updatable = true, nullable = true)
private long capacityBytes; private long capacityBytes;
@Column(name="status", updatable=true, nullable=false) @Column(name = "status", updatable = true, nullable = false)
@Enumerated(value=EnumType.STRING) @Enumerated(value = EnumType.STRING)
private DataStoreStatus status; private DataStoreStatus status;
@Column(name="storage_provider", updatable=true, nullable=false) @Column(name = "storage_provider", updatable = true, nullable = false)
private Long storageProvider; private Long storageProvider;
@Column(name="storage_type", nullable=false) @Column(name = "storage_type", nullable = false)
private String storageType; private String storageType;
@Column(name="host_address") @Column(name = "host_address")
private String hostAddress; private String hostAddress;
@Column(name="path") @Column(name = "path")
private String path; private String path;
@Column(name="port") @Column(name = "port")
private int port; private int port;
@Column(name="user_info") @Column(name = "user_info")
private String userInfo; private String userInfo;
@Column(name="cluster_id") @Column(name = "cluster_id")
private Long clusterId; private Long clusterId;
public long getId() { public long getId() {
return id; return id;
} }
public DataStoreStatus getStatus() { public DataStoreStatus getStatus() {
return status; return status;
} }
public DataStoreVO() { public DataStoreVO() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public String getName() { public String getName() {
return name; return name;
} }
public String getUuid() { public String getUuid() {
return uuid; return uuid;
} }
public String getPoolType() { public String getPoolType() {
return protocol; return protocol;
} }
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
public Date getRemoved() { public Date getRemoved() {
return removed; return removed;
} }
public Date getUpdateTime() { public Date getUpdateTime() {
return updateTime; return updateTime;
} }
public long getDataCenterId() { public long getDataCenterId() {
return dataCenterId; return dataCenterId;
} }
public long getAvailableBytes() { public long getAvailableBytes() {
return availableBytes; return availableBytes;
} }
public Long getStorageProviderId() { public Long getStorageProviderId() {
return storageProvider; return storageProvider;
} }
public void setStorageProviderId(Long provider) { public void setStorageProviderId(Long provider) {
storageProvider = provider; storageProvider = provider;
} }
public String getStorageType() { public String getStorageType() {
return storageType; return storageType;
} }
public void setStorageType(String type) { public void setStorageType(String type) {
storageType = type; storageType = type;
} }
public long getCapacityBytes() { public long getCapacityBytes() {
return capacityBytes; return capacityBytes;
} }
public void setAvailableBytes(long available) { public void setAvailableBytes(long available) {
availableBytes = available; availableBytes = available;
} }
public void setCapacityBytes(long capacity) {
capacityBytes = capacity;
}
public void setCapacityBytes(long capacity) {
capacityBytes = capacity;
}
public Long getClusterId() { public Long getClusterId() {
return clusterId; return clusterId;
@ -196,9 +194,8 @@ public class DataStoreVO implements Identity {
return userInfo; return userInfo;
} }
public void setStatus(DataStoreStatus status) public void setStatus(DataStoreStatus status) {
{ this.status = status;
this.status = status;
} }
public void setId(long id) { public void setId(long id) {
@ -218,7 +215,7 @@ public class DataStoreVO implements Identity {
} }
public void setPath(String path) { public void setPath(String path) {
this.path = path; this.path = path;
} }
public void setUserInfo(String userInfo) { public void setUserInfo(String userInfo) {
@ -230,26 +227,26 @@ public class DataStoreVO implements Identity {
} }
public Long getPodId() { public Long getPodId() {
return podId; return podId;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof DataStoreVO) || obj == null) { if (!(obj instanceof DataStoreVO) || obj == null) {
return false; return false;
} }
DataStoreVO that = (DataStoreVO)obj; DataStoreVO that = (DataStoreVO) obj;
return this.id == that.id; return this.id == that.id;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return new Long(id).hashCode(); return new Long(id).hashCode();
} }
@Override @Override
public String toString() { public String toString() {

View File

@ -25,49 +25,58 @@ import org.apache.cloudstack.storage.datastore.DataStoreStatus;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> { public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
/** /**
* @param datacenterId -- the id of the datacenter (availability zone) * @param datacenterId
*/ * -- the id of the datacenter (availability zone)
List<DataStoreVO> listByDataCenterId(long datacenterId); */
List<DataStoreVO> listByDataCenterId(long datacenterId);
/** /**
* @param datacenterId -- the id of the datacenter (availability zone) * @param datacenterId
*/ * -- the id of the datacenter (availability zone)
List<DataStoreVO> listBy(long datacenterId, long podId, Long clusterId); */
List<DataStoreVO> listBy(long datacenterId, long podId, Long clusterId);
/** /**
* Set capacity of storage pool in bytes * Set capacity of storage pool in bytes
* @param id pool id. *
* @param capacity capacity in bytes * @param id
*/ * pool id.
* @param capacity
* capacity in bytes
*/
void updateCapacity(long id, long capacity); void updateCapacity(long id, long capacity);
/** /**
* Set available bytes of storage pool in bytes * Set available bytes of storage pool in bytes
* @param id pool id. *
* @param available available capacity in bytes * @param id
*/ * pool id.
* @param available
* available capacity in bytes
*/
void updateAvailable(long id, long available); void updateAvailable(long id, long available);
DataStoreVO persist(DataStoreVO pool, Map<String, String> details); DataStoreVO persist(DataStoreVO pool, Map<String, String> details);
/** /**
* Find pool by name. * Find pool by name.
* *
* @param name name of pool. * @param name
* @return the single StoragePoolVO * name of pool.
* @return the single StoragePoolVO
*/ */
List<DataStoreVO> findPoolByName(String name); List<DataStoreVO> findPoolByName(String name);
/** /**
* Find pools by the pod that matches the details. * Find pools by the pod that matches the details.
* *
* @param podId pod id to find the pools in. * @param podId
* @param details details to match. All must match for the pool to be returned. * pod id to find the pools in.
* @param details
* details to match. All must match for the pool to be returned.
* @return List of StoragePoolVO * @return List of StoragePoolVO
*/ */
List<DataStoreVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details); List<DataStoreVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details);
@ -77,8 +86,9 @@ public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
/** /**
* Find pool by UUID. * Find pool by UUID.
* *
* @param uuid uuid of pool. * @param uuid
* @return the single StoragePoolVO * uuid of pool.
* @return the single StoragePoolVO
*/ */
DataStoreVO findPoolByUUID(String uuid); DataStoreVO findPoolByUUID(String uuid);
@ -92,15 +102,15 @@ public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
Map<String, String> getDetails(long poolId); Map<String, String> getDetails(long poolId);
List<String> searchForStoragePoolDetails(long poolId, String value); List<String> searchForStoragePoolDetails(long poolId, String value);
List<DataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid); List<DataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid);
List<DataStoreVO> listByStatus(DataStoreStatus status); List<DataStoreVO> listByStatus(DataStoreStatus status);
long countPoolsByStatus(DataStoreStatus... statuses); long countPoolsByStatus(DataStoreStatus... statuses);
List<DataStoreVO> listByStatusInZone(long dcId, DataStoreStatus status); List<DataStoreVO> listByStatusInZone(long dcId, DataStoreStatus status);
List<DataStoreVO> listPoolsByCluster(long clusterId); List<DataStoreVO> listPoolsByCluster(long clusterId);
} }

View File

@ -34,6 +34,7 @@ import org.springframework.stereotype.Component;
import com.cloud.storage.StoragePoolDetailVO; import com.cloud.storage.StoragePoolDetailVO;
import com.cloud.storage.dao.StoragePoolDetailsDao; import com.cloud.storage.dao.StoragePoolDetailsDao;
import com.cloud.storage.dao.StoragePoolDetailsDaoImpl; import com.cloud.storage.dao.StoragePoolDetailsDaoImpl;
import com.cloud.utils.component.ComponentInject;
import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericDaoBase;
@ -46,20 +47,18 @@ import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
@Component @Component
public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> implements PrimaryDataStoreDao { public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> implements PrimaryDataStoreDao {
protected final SearchBuilder<DataStoreVO> AllFieldSearch; protected final SearchBuilder<DataStoreVO> AllFieldSearch;
protected final SearchBuilder<DataStoreVO> DcPodSearch; protected final SearchBuilder<DataStoreVO> DcPodSearch;
protected final SearchBuilder<DataStoreVO> DcPodAnyClusterSearch; protected final SearchBuilder<DataStoreVO> DcPodAnyClusterSearch;
protected final SearchBuilder<DataStoreVO> DeleteLvmSearch; protected final SearchBuilder<DataStoreVO> DeleteLvmSearch;
protected final GenericSearchBuilder<DataStoreVO, Long> StatusCountSearch; protected final GenericSearchBuilder<DataStoreVO, Long> StatusCountSearch;
protected final PrimaryDataStoreDetailsDao _detailsDao = null;
protected final StoragePoolDetailsDao _detailsDao;
private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and ("; private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and (";
private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?"; private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?";
private final String FindPoolTagDetails = "SELECT storage_pool_details.name FROM storage_pool_details WHERE pool_id = ? and value = ?"; private final String FindPoolTagDetails = "SELECT storage_pool_details.name FROM storage_pool_details WHERE pool_id = ? and value = ?";
protected PrimaryDataStoreDaoImpl() { protected PrimaryDataStoreDaoImpl() {
AllFieldSearch = createSearchBuilder(); AllFieldSearch = createSearchBuilder();
@ -67,23 +66,23 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
AllFieldSearch.and("uuid", AllFieldSearch.entity().getUuid(), SearchCriteria.Op.EQ); AllFieldSearch.and("uuid", AllFieldSearch.entity().getUuid(), SearchCriteria.Op.EQ);
AllFieldSearch.and("datacenterId", AllFieldSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); AllFieldSearch.and("datacenterId", AllFieldSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
AllFieldSearch.and("hostAddress", AllFieldSearch.entity().getHostAddress(), SearchCriteria.Op.EQ); AllFieldSearch.and("hostAddress", AllFieldSearch.entity().getHostAddress(), SearchCriteria.Op.EQ);
AllFieldSearch.and("status",AllFieldSearch.entity().getStatus(),SearchCriteria.Op.EQ); AllFieldSearch.and("status", AllFieldSearch.entity().getStatus(), SearchCriteria.Op.EQ);
AllFieldSearch.and("path", AllFieldSearch.entity().getPath(), SearchCriteria.Op.EQ); AllFieldSearch.and("path", AllFieldSearch.entity().getPath(), SearchCriteria.Op.EQ);
AllFieldSearch.and("podId", AllFieldSearch.entity().getPodId(), Op.EQ); AllFieldSearch.and("podId", AllFieldSearch.entity().getPodId(), Op.EQ);
AllFieldSearch.and("clusterId", AllFieldSearch.entity().getClusterId(), Op.EQ); AllFieldSearch.and("clusterId", AllFieldSearch.entity().getClusterId(), Op.EQ);
AllFieldSearch.done(); AllFieldSearch.done();
DcPodSearch = createSearchBuilder(); DcPodSearch = createSearchBuilder();
DcPodSearch.and("datacenterId", DcPodSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); DcPodSearch.and("datacenterId", DcPodSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
DcPodSearch.and().op("nullpod", DcPodSearch.entity().getPodId(), SearchCriteria.Op.NULL); DcPodSearch.and().op("nullpod", DcPodSearch.entity().getPodId(), SearchCriteria.Op.NULL);
DcPodSearch.or("podId", DcPodSearch.entity().getPodId(), SearchCriteria.Op.EQ); DcPodSearch.or("podId", DcPodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
DcPodSearch.cp(); DcPodSearch.cp();
DcPodSearch.and().op("nullcluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.NULL); DcPodSearch.and().op("nullcluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.NULL);
DcPodSearch.or("cluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.EQ); DcPodSearch.or("cluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
DcPodSearch.cp(); DcPodSearch.cp();
DcPodSearch.done(); DcPodSearch.done();
DcPodAnyClusterSearch = createSearchBuilder(); DcPodAnyClusterSearch = createSearchBuilder();
DcPodAnyClusterSearch.and("datacenterId", DcPodAnyClusterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); DcPodAnyClusterSearch.and("datacenterId", DcPodAnyClusterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
DcPodAnyClusterSearch.and().op("nullpod", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.NULL); DcPodAnyClusterSearch.and().op("nullpod", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.NULL);
DcPodAnyClusterSearch.or("podId", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.EQ); DcPodAnyClusterSearch.or("podId", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.EQ);
@ -97,64 +96,56 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
DeleteLvmSearch.cp(); DeleteLvmSearch.cp();
DeleteLvmSearch.done(); DeleteLvmSearch.done();
StatusCountSearch = createSearchBuilder(Long.class); StatusCountSearch = createSearchBuilder(Long.class);
StatusCountSearch.and("status", StatusCountSearch.entity().getStatus(), SearchCriteria.Op.IN); StatusCountSearch.and("status", StatusCountSearch.entity().getStatus(), SearchCriteria.Op.IN);
StatusCountSearch.select(null, Func.COUNT, null); StatusCountSearch.select(null, Func.COUNT, null);
StatusCountSearch.done(); StatusCountSearch.done();
_detailsDao = ComponentLocator.inject(StoragePoolDetailsDaoImpl.class); // _detailsDao = ComponentInject.inject(PrimaryDataStoreDetailsDaoImpl.class);
} }
@Override @Override
public List<DataStoreVO> findPoolByName(String name) { public List<DataStoreVO> findPoolByName(String name) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create(); SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("name", name); sc.setParameters("name", name);
return listIncludingRemovedBy(sc); return listIncludingRemovedBy(sc);
} }
@Override
@Override public DataStoreVO findPoolByUUID(String uuid) {
public DataStoreVO findPoolByUUID(String uuid) { SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("uuid", uuid); sc.setParameters("uuid", uuid);
return findOneIncludingRemovedBy(sc); return findOneIncludingRemovedBy(sc);
} }
@Override
public List<DataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid) {
@Override SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public List<DataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("uuid", uuid); sc.setParameters("uuid", uuid);
return listBy(sc); return listBy(sc);
} }
@Override
@Override public List<DataStoreVO> listByDataCenterId(long datacenterId) {
public List<DataStoreVO> listByDataCenterId(long datacenterId) { SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("datacenterId", datacenterId); sc.setParameters("datacenterId", datacenterId);
return listBy(sc); return listBy(sc);
} }
@Override
public void updateAvailable(long id, long available) {
DataStoreVO pool = createForUpdate(id);
pool.setAvailableBytes(available);
update(id, pool);
}
@Override @Override
public void updateAvailable(long id, long available) { public void updateCapacity(long id, long capacity) {
DataStoreVO pool = createForUpdate(id); DataStoreVO pool = createForUpdate(id);
pool.setAvailableBytes(available); pool.setCapacityBytes(capacity);
update(id, pool); update(id, pool);
}
}
@Override
public void updateCapacity(long id, long capacity) {
DataStoreVO pool = createForUpdate(id);
pool.setCapacityBytes(capacity);
update(id, pool);
}
@Override @Override
public List<DataStoreVO> listByStorageHost(String hostFqdnOrIp) { public List<DataStoreVO> listByStorageHost(String hostFqdnOrIp) {
@ -164,18 +155,18 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
} }
@Override @Override
public List<DataStoreVO> listByStatus(DataStoreStatus status){ public List<DataStoreVO> listByStatus(DataStoreStatus status) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create(); SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("status", status); sc.setParameters("status", status);
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<DataStoreVO> listByStatusInZone(long dcId, DataStoreStatus status){ public List<DataStoreVO> listByStatusInZone(long dcId, DataStoreStatus status) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create(); SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("status", status); sc.setParameters("status", status);
sc.setParameters("datacenterId", dcId); sc.setParameters("datacenterId", dcId);
return listBy(sc); return listBy(sc);
} }
@Override @Override
@ -190,174 +181,172 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long>
return findOneBy(sc); return findOneBy(sc);
} }
@Override @Override
public List<DataStoreVO> listBy(long datacenterId, long podId, Long clusterId) { public List<DataStoreVO> listBy(long datacenterId, long podId, Long clusterId) {
if (clusterId != null) { if (clusterId != null) {
SearchCriteria<DataStoreVO> sc = DcPodSearch.create(); SearchCriteria<DataStoreVO> sc = DcPodSearch.create();
sc.setParameters("datacenterId", datacenterId); sc.setParameters("datacenterId", datacenterId);
sc.setParameters("podId", podId); sc.setParameters("podId", podId);
sc.setParameters("cluster", clusterId); sc.setParameters("cluster", clusterId);
return listBy(sc); return listBy(sc);
} else { } else {
SearchCriteria<DataStoreVO> sc = DcPodAnyClusterSearch.create(); SearchCriteria<DataStoreVO> sc = DcPodAnyClusterSearch.create();
sc.setParameters("datacenterId", datacenterId); sc.setParameters("datacenterId", datacenterId);
sc.setParameters("podId", podId); sc.setParameters("podId", podId);
return listBy(sc); return listBy(sc);
} }
} }
@Override @Override
public List<DataStoreVO> listPoolByHostPath(String host, String path) { public List<DataStoreVO> listPoolByHostPath(String host, String path) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create(); SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("hostAddress", host); sc.setParameters("hostAddress", host);
sc.setParameters("path", path); sc.setParameters("path", path);
return listBy(sc); return listBy(sc);
} }
public DataStoreVO listById(Integer id) public DataStoreVO listById(Integer id) {
{
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create(); SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("id", id); sc.setParameters("id", id);
return findOneIncludingRemovedBy(sc); return findOneIncludingRemovedBy(sc);
}
@Override @DB
public DataStoreVO persist(DataStoreVO pool, Map<String, String> details) {
Transaction txn = Transaction.currentTxn();
txn.start();
pool = super.persist(pool);
if (details != null) {
for (Map.Entry<String, String> detail : details.entrySet()) {
StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue());
_detailsDao.persist(vo);
}
}
txn.commit();
return pool;
}
@DB
@Override
public List<DataStoreVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details) {
StringBuilder sql = new StringBuilder(DetailsSqlPrefix);
if (clusterId != null) {
sql.append("storage_pool.cluster_id = ? OR storage_pool.cluster_id IS NULL) AND (");
}
for (Map.Entry<String, String> detail : details.entrySet()) {
sql.append("((storage_pool_details.name='").append(detail.getKey()).append("') AND (storage_pool_details.value='").append(detail.getValue()).append("')) OR ");
}
sql.delete(sql.length() - 4, sql.length());
sql.append(DetailsSqlSuffix);
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
int i = 1;
pstmt.setLong(i++, dcId);
pstmt.setLong(i++, podId);
if (clusterId != null) {
pstmt.setLong(i++, clusterId);
}
pstmt.setInt(i++, details.size());
ResultSet rs = pstmt.executeQuery();
List<DataStoreVO> pools = new ArrayList<DataStoreVO>();
while (rs.next()) {
pools.add(toEntityBean(rs, false));
}
return pools;
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt, e);
}
}
protected Map<String, String> tagsToDetails(String[] tags) {
Map<String, String> details = new HashMap<String, String>(tags.length);
for (String tag: tags) {
details.put(tag, "true");
}
return details;
}
@Override
public List<DataStoreVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) {
List<DataStoreVO> storagePools = null;
if (tags == null || tags.length == 0) {
storagePools = listBy(dcId, podId, clusterId);
} else {
Map<String, String> details = tagsToDetails(tags);
storagePools = findPoolsByDetails(dcId, podId, clusterId, details);
}
if (shared == null) {
return storagePools;
} else {
List<DataStoreVO> filteredStoragePools = new ArrayList<DataStoreVO>(storagePools);
for (DataStoreVO pool : storagePools) {
/*
if (shared != pool.isShared()) {
filteredStoragePools.remove(pool);
}*/
}
return filteredStoragePools;
}
}
@Override
@DB
public List<String> searchForStoragePoolDetails(long poolId, String value){
StringBuilder sql = new StringBuilder(FindPoolTagDetails);
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, poolId);
pstmt.setString(2, value);
ResultSet rs = pstmt.executeQuery();
List<String> tags = new ArrayList<String>();
while (rs.next()) {
tags.add(rs.getString("name"));
}
return tags;
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e);
}
}
@Override
public void updateDetails(long poolId, Map<String, String> details) {
if (details != null) {
_detailsDao.update(poolId, details);
}
} }
@Override @Override
public Map<String, String> getDetails(long poolId) { @DB
return _detailsDao.getDetails(poolId); public DataStoreVO persist(DataStoreVO pool, Map<String, String> details) {
} Transaction txn = Transaction.currentTxn();
txn.start();
@Override pool = super.persist(pool);
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { if (details != null) {
super.configure(name, params); for (Map.Entry<String, String> detail : details.entrySet()) {
_detailsDao.configure("DetailsDao", params); PrimaryDataStoreDetailVO vo = new PrimaryDataStoreDetailVO(pool.getId(), detail.getKey(), detail.getValue());
return true; _detailsDao.persist(vo);
} }
}
txn.commit();
return pool;
}
@DB
@Override
public List<DataStoreVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details) {
StringBuilder sql = new StringBuilder(DetailsSqlPrefix);
if (clusterId != null) {
sql.append("storage_pool.cluster_id = ? OR storage_pool.cluster_id IS NULL) AND (");
}
for (Map.Entry<String, String> detail : details.entrySet()) {
sql.append("((storage_pool_details.name='").append(detail.getKey()).append("') AND (storage_pool_details.value='").append(detail.getValue()).append("')) OR ");
}
sql.delete(sql.length() - 4, sql.length());
sql.append(DetailsSqlSuffix);
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
int i = 1;
pstmt.setLong(i++, dcId);
pstmt.setLong(i++, podId);
if (clusterId != null) {
pstmt.setLong(i++, clusterId);
}
pstmt.setInt(i++, details.size());
ResultSet rs = pstmt.executeQuery();
List<DataStoreVO> pools = new ArrayList<DataStoreVO>();
while (rs.next()) {
pools.add(toEntityBean(rs, false));
}
return pools;
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt, e);
}
}
protected Map<String, String> tagsToDetails(String[] tags) {
Map<String, String> details = new HashMap<String, String>(tags.length);
for (String tag : tags) {
details.put(tag, "true");
}
return details;
}
@Override @Override
public long countPoolsByStatus( DataStoreStatus... statuses) { public List<DataStoreVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) {
List<DataStoreVO> storagePools = null;
if (tags == null || tags.length == 0) {
storagePools = listBy(dcId, podId, clusterId);
} else {
Map<String, String> details = tagsToDetails(tags);
storagePools = findPoolsByDetails(dcId, podId, clusterId, details);
}
if (shared == null) {
return storagePools;
} else {
List<DataStoreVO> filteredStoragePools = new ArrayList<DataStoreVO>(storagePools);
for (DataStoreVO pool : storagePools) {
/*
* if (shared != pool.isShared()) {
* filteredStoragePools.remove(pool); }
*/
}
return filteredStoragePools;
}
}
@Override
@DB
public List<String> searchForStoragePoolDetails(long poolId, String value) {
StringBuilder sql = new StringBuilder(FindPoolTagDetails);
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, poolId);
pstmt.setString(2, value);
ResultSet rs = pstmt.executeQuery();
List<String> tags = new ArrayList<String>();
while (rs.next()) {
tags.add(rs.getString("name"));
}
return tags;
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e);
}
}
@Override
public void updateDetails(long poolId, Map<String, String> details) {
if (details != null) {
_detailsDao.update(poolId, details);
}
}
@Override
public Map<String, String> getDetails(long poolId) {
return _detailsDao.getDetails(poolId);
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
_detailsDao.configure("DetailsDao", params);
return true;
}
@Override
public long countPoolsByStatus(DataStoreStatus... statuses) {
SearchCriteria<Long> sc = StatusCountSearch.create(); SearchCriteria<Long> sc = StatusCountSearch.create();
sc.setParameters("status", (Object[])statuses); sc.setParameters("status", (Object[]) statuses);
List<Long> rs = customSearchIncludingRemoved(sc, null); List<Long> rs = customSearchIncludingRemoved(sc, null);
if (rs.size() == 0) { if (rs.size() == 0) {

View File

@ -0,0 +1,79 @@
// 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 org.apache.cloudstack.storage.datastore.db;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="storage_pool_details")
public class PrimaryDataStoreDetailVO {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
long id;
@Column(name="pool_id")
long poolId;
@Column(name="name")
String name;
@Column(name="value")
String value;
public PrimaryDataStoreDetailVO(long poolId, String name, String value) {
this.poolId = poolId;
this.name = name;
this.value = value;
}
public long getId() {
return id;
}
public long getPoolId() {
return poolId;
}
public void setPoolId(long poolId) {
this.poolId = poolId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
protected PrimaryDataStoreDetailVO() {
}
}

View File

@ -0,0 +1,28 @@
// 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 org.apache.cloudstack.storage.datastore.db;
import java.util.Map;
import com.cloud.storage.StoragePoolDetailVO;
import com.cloud.utils.db.GenericDao;
public interface PrimaryDataStoreDetailsDao extends GenericDao<PrimaryDataStoreDetailVO, Long> {
void update(long poolId, Map<String, String> details);
Map<String, String> getDetails(long poolId);
}

View File

@ -0,0 +1,71 @@
// 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 org.apache.cloudstack.storage.datastore.db;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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
public class PrimaryDataStoreDetailsDaoImpl extends GenericDaoBase<PrimaryDataStoreDetailVO, Long> implements PrimaryDataStoreDetailsDao {
protected final SearchBuilder<PrimaryDataStoreDetailVO> PoolSearch = null;
protected PrimaryDataStoreDetailsDaoImpl() {
/*
super();
PoolSearch = createSearchBuilder();
PoolSearch.and("pool", PoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
PoolSearch.done();
*/
}
@Override
public void update(long poolId, Map<String, String> details) {
Transaction txn = Transaction.currentTxn();
SearchCriteria<PrimaryDataStoreDetailVO> sc = PoolSearch.create();
sc.setParameters("pool", poolId);
txn.start();
expunge(sc);
for (Map.Entry<String, String> entry : details.entrySet()) {
PrimaryDataStoreDetailVO detail = new PrimaryDataStoreDetailVO(poolId, entry.getKey(), entry.getValue());
persist(detail);
}
txn.commit();
}
@Override
public Map<String, String> getDetails(long poolId) {
SearchCriteria<PrimaryDataStoreDetailVO> sc = PoolSearch.create();
sc.setParameters("pool", poolId);
List<PrimaryDataStoreDetailVO> details = listBy(sc);
Map<String, String> detailsMap = new HashMap<String, String>();
for (PrimaryDataStoreDetailVO detail : details) {
detailsMap.put(detail.getName(), detail.getValue());
}
return detailsMap;
}
}

View File

@ -25,14 +25,14 @@ import javax.persistence.Table;
import javax.persistence.TableGenerator; import javax.persistence.TableGenerator;
@Entity @Entity
@Table(name="data_store_provider") @Table(name = "data_store_provider")
public class PrimaryDataStoreProviderVO { public class PrimaryDataStoreProviderVO {
@Id @Id
@TableGenerator(name="data_store_provider_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="data_store_provider_seq", allocationSize=1) @TableGenerator(name = "data_store_provider_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "data_store_provider_seq", allocationSize = 1)
@Column(name="id", updatable=false, nullable = false) @Column(name = "id", updatable = false, nullable = false)
private long id; private long id;
public long getId() { public long getId() {
return id; return id;
} }
} }

View File

@ -20,92 +20,93 @@ import com.cloud.agent.api.Command;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
@Component @Component
public class DefaultPrimaryDataStoreDriverImpl implements public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver {
PrimaryDataStoreDriver { private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreDriverImpl.class);
private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreDriverImpl.class);
@Override
public boolean createVolume(VolumeObject vol) {
//The default driver will send createvolume command to one of hosts which can access its datastore
List<EndPoint> endPoints = vol.getDataStore().getEndPoints();
int retries = 3;
VolumeInfo volInfo = vol;
CreateVolumeCommand createCmd = new CreateVolumeCommand(new VolumeTO(volInfo));
Answer answer = null;
int i = 0;
boolean result = false;
for (EndPoint ep : endPoints) { @Override
answer = ep.sendMessage(createCmd); public boolean createVolume(VolumeObject vol) {
if (answer == null) { // The default driver will send createvolume command to one of hosts
if (i < retries) { // which can access its datastore
s_logger.debug("create volume failed, retrying: " + i); List<EndPoint> endPoints = vol.getDataStore().getEndPoints();
} int retries = 3;
i++; VolumeInfo volInfo = vol;
} else { CreateVolumeCommand createCmd = new CreateVolumeCommand(new VolumeTO(volInfo));
CreateVolumeAnswer volAnswer = (CreateVolumeAnswer)answer; Answer answer = null;
vol.setPath(volAnswer.getVolumeUuid()); int i = 0;
result = true; boolean result = false;
}
}
return result; for (EndPoint ep : endPoints) {
} answer = ep.sendMessage(createCmd);
if (answer == null) {
if (i < retries) {
s_logger.debug("create volume failed, retrying: " + i);
}
i++;
} else {
CreateVolumeAnswer volAnswer = (CreateVolumeAnswer) answer;
vol.setPath(volAnswer.getVolumeUuid());
result = true;
}
}
@Override return result;
public boolean deleteVolume(VolumeObject vo) { }
// TODO Auto-generated method stub
return false;
}
@Override @Override
public String grantAccess(VolumeObject vol, EndPoint ep) { public boolean deleteVolume(VolumeObject vo) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
@Override @Override
public boolean revokeAccess(VolumeObject vol, EndPoint ep) { public String grantAccess(VolumeObject vol, EndPoint ep) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return null;
} }
protected Answer sendOutCommand(Command cmd, List<EndPoint> endPoints) { @Override
Answer answer = null; public boolean revokeAccess(VolumeObject vol, EndPoint ep) {
int retries = 3; // TODO Auto-generated method stub
int i = 0; return false;
for (EndPoint ep : endPoints) { }
answer = ep.sendMessage(cmd);
if (answer == null || answer.getDetails() != null) {
if (i < retries) {
s_logger.debug("create volume failed, retrying: " + i);
}
i++;
} else {
break;
}
}
return answer;
}
@Override protected Answer sendOutCommand(Command cmd, List<EndPoint> endPoints) {
public boolean createVolumeFromBaseImage(VolumeObject volume, TemplateOnPrimaryDataStoreInfo template) { Answer answer = null;
VolumeTO vol = new VolumeTO(volume); int retries = 3;
ImageOnPrimayDataStoreTO image = new ImageOnPrimayDataStoreTO(template); int i = 0;
CreateVolumeFromBaseImageCommand cmd = new CreateVolumeFromBaseImageCommand(vol, image); for (EndPoint ep : endPoints) {
List<EndPoint> endPoints = volume.getDataStore().getEndPoints(); answer = ep.sendMessage(cmd);
if (answer == null || answer.getDetails() != null) {
if (i < retries) {
s_logger.debug("create volume failed, retrying: " + i);
}
i++;
} else {
break;
}
}
return answer;
}
Answer answer = sendOutCommand(cmd, endPoints); @Override
public boolean createVolumeFromBaseImage(VolumeObject volume, TemplateOnPrimaryDataStoreInfo template) {
VolumeTO vol = new VolumeTO(volume);
ImageOnPrimayDataStoreTO image = new ImageOnPrimayDataStoreTO(template);
CreateVolumeFromBaseImageCommand cmd = new CreateVolumeFromBaseImageCommand(vol, image);
List<EndPoint> endPoints = volume.getDataStore().getEndPoints();
if (answer == null || answer.getDetails() != null) { Answer answer = sendOutCommand(cmd, endPoints);
if (answer == null) {
throw new CloudRuntimeException("Failed to created volume"); if (answer == null || answer.getDetails() != null) {
} else { if (answer == null) {
throw new CloudRuntimeException(answer.getDetails()); throw new CloudRuntimeException("Failed to created volume");
} } else {
} else { throw new CloudRuntimeException(answer.getDetails());
CreateVolumeAnswer volAnswer = (CreateVolumeAnswer)answer; }
volume.setPath(volAnswer.getVolumeUuid()); } else {
return true; CreateVolumeAnswer volAnswer = (CreateVolumeAnswer) answer;
} volume.setPath(volAnswer.getVolumeUuid());
} return true;
}
}
} }

View File

@ -4,11 +4,14 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo; import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
import org.apache.cloudstack.storage.volume.VolumeObject; import org.apache.cloudstack.storage.volume.VolumeObject;
public interface PrimaryDataStoreDriver { public interface PrimaryDataStoreDriver {
boolean createVolume(VolumeObject vol); boolean createVolume(VolumeObject vol);
boolean createVolumeFromBaseImage(VolumeObject volume, TemplateOnPrimaryDataStoreInfo template);
boolean deleteVolume(VolumeObject vo); boolean createVolumeFromBaseImage(VolumeObject volume, TemplateOnPrimaryDataStoreInfo template);
String grantAccess(VolumeObject vol, EndPoint ep);
boolean revokeAccess(VolumeObject vol, EndPoint ep); boolean deleteVolume(VolumeObject vo);
String grantAccess(VolumeObject vol, EndPoint ep);
boolean revokeAccess(VolumeObject vol, EndPoint ep);
} }

View File

@ -25,46 +25,46 @@ import org.springframework.stereotype.Component;
@Component @Component
public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle { public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle {
@Override @Override
public boolean registerDataStore(Map<String, String> dsInfos) { public boolean registerDataStore(Map<String, String> dsInfos) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean attach(long scope) { public boolean attach(long scope) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean dettach(long dataStoreId) { public boolean dettach(long dataStoreId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean unmanaged(long dataStoreId) { public boolean unmanaged(long dataStoreId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean maintain(long dataStoreId) { public boolean maintain(long dataStoreId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean cancelMaintain(long dataStoreId) { public boolean cancelMaintain(long dataStoreId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean deleteDataStore(long dataStoreId) { public boolean deleteDataStore(long dataStoreId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
} }

View File

@ -21,11 +21,17 @@ package org.apache.cloudstack.storage.datastore.lifecycle;
import java.util.Map; import java.util.Map;
public interface PrimaryDataStoreLifeCycle { public interface PrimaryDataStoreLifeCycle {
public boolean registerDataStore(Map<String, String> dsInfos); public boolean registerDataStore(Map<String, String> dsInfos);
public boolean attach(long scope);
public boolean dettach(long dataStoreId); public boolean attach(long scope);
public boolean unmanaged(long dataStoreId);
public boolean maintain(long dataStoreId); public boolean dettach(long dataStoreId);
public boolean cancelMaintain(long dataStoreId);
public boolean deleteDataStore(long dataStoreId); public boolean unmanaged(long dataStoreId);
public boolean maintain(long dataStoreId);
public boolean cancelMaintain(long dataStoreId);
public boolean deleteDataStore(long dataStoreId);
} }

View File

@ -31,25 +31,26 @@ import org.springframework.stereotype.Component;
@Component @Component
public class DefaultPrimaryDataStoreManagerImpl implements PrimaryDataStoreManager { public class DefaultPrimaryDataStoreManagerImpl implements PrimaryDataStoreManager {
@Inject @Inject
PrimaryDataStoreProviderDao dataStoreProviderDao; PrimaryDataStoreProviderDao dataStoreProviderDao;
@Inject @Inject
PrimaryDataStoreProviderManager providerManager; PrimaryDataStoreProviderManager providerManager;
@Inject @Inject
PrimaryDataStoreDao dataStoreDao; PrimaryDataStoreDao dataStoreDao;
@Override
public PrimaryDataStore getPrimaryDataStore(long dataStoreId) {
DataStoreVO dataStoreVO = dataStoreDao.findById(dataStoreId);
Long providerId = dataStoreVO.getStorageProviderId();
PrimaryDataStoreProvider provider = providerManager.getDataStoreProvider(providerId);
PrimaryDataStore dataStore = provider.getDataStore(dataStoreId);
return dataStore;
}
@Override @Override
public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId) { public PrimaryDataStore getPrimaryDataStore(long dataStoreId) {
// TODO Auto-generated method stub DataStoreVO dataStoreVO = dataStoreDao.findById(dataStoreId);
return null; Long providerId = dataStoreVO.getStorageProviderId();
} PrimaryDataStoreProvider provider = providerManager.getDataStoreProvider(providerId);
PrimaryDataStore dataStore = provider.getDataStore(dataStoreId);
return dataStore;
}
@Override
public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId) {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -22,6 +22,7 @@ import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle; import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
public interface PrimaryDataStoreManager { public interface PrimaryDataStoreManager {
public PrimaryDataStore getPrimaryDataStore(long dataStoreId); public PrimaryDataStore getPrimaryDataStore(long dataStoreId);
public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId);
public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId);
} }

View File

@ -14,31 +14,31 @@ import org.springframework.stereotype.Component;
import com.cloud.utils.component.ComponentInject; import com.cloud.utils.component.ComponentInject;
@Component @Component
public class DefaultPrimaryDatastoreProviderImpl implements public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProvider {
PrimaryDataStoreProvider { protected PrimaryDataStoreDriver driver;
protected PrimaryDataStoreDriver driver; @Inject
@Inject public PrimaryDataStoreDao dataStoreDao;
public PrimaryDataStoreDao dataStoreDao;
public DefaultPrimaryDatastoreProviderImpl() { public DefaultPrimaryDatastoreProviderImpl() {
this.driver = new DefaultPrimaryDataStoreDriverImpl(); this.driver = new DefaultPrimaryDataStoreDriverImpl();
} }
@Override
public PrimaryDataStore getDataStore(long dataStoreId) {
DataStoreVO dsv = dataStoreDao.findById(dataStoreId);
if (dsv == null) {
return null;
}
PrimaryDataStore pds = new DefaultPrimaryDataStoreImpl(driver, dsv, null); @Override
pds = ComponentInject.inject(pds); public PrimaryDataStore getDataStore(long dataStoreId) {
return pds; DataStoreVO dsv = dataStoreDao.findById(dataStoreId);
} if (dsv == null) {
return null;
}
@Override PrimaryDataStore pds = new DefaultPrimaryDataStoreImpl(driver, dsv, null);
public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId) { pds = ComponentInject.inject(pds);
// TODO Auto-generated method stub return pds;
return null; }
}
@Override
public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId) {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -3,9 +3,8 @@ package org.apache.cloudstack.storage.datastore.provider;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore; import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
public interface PrimaryDataStoreProvider { public interface PrimaryDataStoreProvider {
public PrimaryDataStore getDataStore(long dataStoreId); public PrimaryDataStore getDataStore(long dataStoreId);
public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId);
public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId);
} }

View File

@ -1,6 +1,5 @@
package org.apache.cloudstack.storage.datastore.provider; package org.apache.cloudstack.storage.datastore.provider;
public interface PrimaryDataStoreProviderManager { public interface PrimaryDataStoreProviderManager {
public PrimaryDataStoreProvider getDataStoreProvider(Long providerId); public PrimaryDataStoreProvider getDataStoreProvider(Long providerId);
} }

View File

@ -23,10 +23,10 @@ import org.springframework.stereotype.Component;
@Component @Component
public class PrimaryDataStoreProviderManagerImpl implements PrimaryDataStoreProviderManager { public class PrimaryDataStoreProviderManagerImpl implements PrimaryDataStoreProviderManager {
@Override @Override
public PrimaryDataStoreProvider getDataStoreProvider(Long providerId) { public PrimaryDataStoreProvider getDataStoreProvider(Long providerId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -23,9 +23,10 @@ import org.springframework.stereotype.Component;
@Component @Component
public class ISCSI extends BaseType implements DataStoreType { public class ISCSI extends BaseType implements DataStoreType {
private final String type = "iscsi"; private final String type = "iscsi";
@Override
public String toString() { @Override
return type; public String toString() {
} return type;
}
} }

View File

@ -23,9 +23,10 @@ import org.springframework.stereotype.Component;
@Component @Component
public class NetworkFileSystem extends BaseType implements DataStoreType { public class NetworkFileSystem extends BaseType implements DataStoreType {
private final String type = "nfs"; private final String type = "nfs";
@Override
public String toString() { @Override
return type; public String toString() {
} return type;
}
} }

View File

@ -21,9 +21,10 @@ package org.apache.cloudstack.storage.datastore.type;
import org.apache.cloudstack.storage.BaseType; import org.apache.cloudstack.storage.BaseType;
public class SharedMount extends BaseType implements DataStoreType { public class SharedMount extends BaseType implements DataStoreType {
private final String type = "SharedMountPoint"; private final String type = "SharedMountPoint";
@Override
public String toString() { @Override
return type; public String toString() {
} return type;
}
} }

View File

@ -31,46 +31,43 @@ import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
public abstract class AbstractStorageDriver implements DataStoreDriver { public abstract class AbstractStorageDriver implements DataStoreDriver {
protected DataStore _ds; protected DataStore _ds;
protected TemplateStrategy _ts; protected TemplateStrategy _ts;
public AbstractStorageDriver(DataStore ds) { public AbstractStorageDriver(DataStore ds) {
_ds = ds; _ds = ds;
_ts = ds.getTemplateStrategy(); _ts = ds.getTemplateStrategy();
} }
public TemplateProfile install(TemplateProfile tp, DataStoreEndPoint ep) { public TemplateProfile install(TemplateProfile tp, DataStoreEndPoint ep) {
PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(tp.getName(), tp.getUrl(), tp.getFormat(), PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(tp.getName(), tp.getUrl(), tp.getFormat(), 0, _ds.getId(), _ds.getUUID(), _ts.getDownloadWait());
0, _ds.getId(), _ds.getUUID(), _ts.getDownloadWait()); dcmd.setSecondaryStorageUrl(tp.getImageStorageUri());
dcmd.setSecondaryStorageUrl(tp.getImageStorageUri()); dcmd.setPrimaryStorageUrl(_ds.getURI());
dcmd.setPrimaryStorageUrl(_ds.getURI()); PrimaryStorageDownloadAnswer asw = (PrimaryStorageDownloadAnswer) ep.sendCommand(dcmd);
PrimaryStorageDownloadAnswer asw = (PrimaryStorageDownloadAnswer)ep.sendCommand(dcmd);
tp.setLocalPath(asw.getInstallPath()); tp.setLocalPath(asw.getInstallPath());
return tp; return tp;
} }
public TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep, boolean freshDownload) { public TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep, boolean freshDownload) {
DownloadCommand dcmd = DownloadCommand dcmd = new DownloadCommand(_ds.getURI(), tp.getTemplate(), _ts.getMaxTemplateSizeInBytes());
new DownloadCommand(_ds.getURI(), tp.getTemplate(), _ts.getMaxTemplateSizeInBytes()); dcmd.setProxy(_ts.getHttpProxy());
dcmd.setProxy(_ts.getHttpProxy()); if (!freshDownload) {
if (!freshDownload) { dcmd = new DownloadProgressCommand(dcmd, tp.getJobId(), RequestType.GET_OR_RESTART);
dcmd = new DownloadProgressCommand(dcmd, tp.getJobId(), RequestType.GET_OR_RESTART); }
}
ep.sendCommand(dcmd); ep.sendCommand(dcmd);
return tp; return tp;
} }
/* /*
public VolumeProfile createVolumeFromTemplate(VolumeProfile volProfile, TemplateProfile tp, DataStoreEndPoint ep) { * public VolumeProfile createVolumeFromTemplate(VolumeProfile volProfile,
CreateCommand cmd = new CreateCommand(volProfile, tp.getLocalPath(), _ds.getTO()); * TemplateProfile tp, DataStoreEndPoint ep) { CreateCommand cmd = new
CreateAnswer ans = (CreateAnswer)ep.sendCommand(cmd); * CreateCommand(volProfile, tp.getLocalPath(), _ds.getTO()); CreateAnswer
VolumeTO created = ans.getVolume(); * ans = (CreateAnswer)ep.sendCommand(cmd); VolumeTO created =
DiskProfile diskProfile = new VolumeProfile(volProfile); * ans.getVolume(); DiskProfile diskProfile = new VolumeProfile(volProfile);
diskProfile.setPath(created.getPath()); * diskProfile.setPath(created.getPath());
diskProfile.setSize(created.getSize()); * diskProfile.setSize(created.getSize()); return diskProfile; return null;
return diskProfile; * }
return null; */
}*/
} }

View File

@ -29,62 +29,62 @@ import com.cloud.storage.TemplateProfile;
public class DefaultNfsSecondaryDriver extends AbstractStorageDriver { public class DefaultNfsSecondaryDriver extends AbstractStorageDriver {
/** /**
* @param ds * @param ds
*/ */
public DefaultNfsSecondaryDriver(DataStore ds) { public DefaultNfsSecondaryDriver(DataStore ds) {
super(ds); super(ds);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public String getDriverType() { public String getDriverType() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep) { public TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataObject create(DataObject obj) { public DataObject create(DataObject obj) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataObject copy(DataObject src, DataStore dest) { public DataObject copy(DataObject src, DataStore dest) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataObject copy(DataObject src, DataObject dest) { public DataObject copy(DataObject src, DataObject dest) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataObject move(DataObject src, DataObject dest) { public DataObject move(DataObject src, DataObject dest) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public Answer sendMessage(DataStoreEndPoint dsep, Command cmd) { public Answer sendMessage(DataStoreEndPoint dsep, Command cmd) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public boolean delete(DataObject obj) { public boolean delete(DataObject obj) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile register(org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint ep) { public org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile register(org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint ep) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public VolumeProfile createVolumeFromTemplate(VolumeProfile vol, org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint dp) { public VolumeProfile createVolumeFromTemplate(VolumeProfile vol, org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint dp) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -26,56 +26,56 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeProfile;
import com.cloud.agent.api.Answer; import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command; import com.cloud.agent.api.Command;
public class XenServerStorageDriver extends AbstractStorageDriver { public class XenServerStorageDriver extends AbstractStorageDriver {
protected DataStore _ds; protected DataStore _ds;
public XenServerStorageDriver(DataStore ds) {
super(ds);
_ds = ds;
}
public String getDriverType() { public XenServerStorageDriver(DataStore ds) {
// TODO Auto-generated method stub super(ds);
return null; _ds = ds;
} }
public DataObject create(DataObject obj) { public String getDriverType() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataObject copy(DataObject src, DataStore dest) { public DataObject create(DataObject obj) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataObject copy(DataObject src, DataObject dest) { public DataObject copy(DataObject src, DataStore dest) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataObject move(DataObject src, DataObject dest) { public DataObject copy(DataObject src, DataObject dest) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public Answer sendMessage(DataStoreEndPoint dsep, Command cmd) { public DataObject move(DataObject src, DataObject dest) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public boolean delete(DataObject obj) { public Answer sendMessage(DataStoreEndPoint dsep, Command cmd) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return null;
} }
public org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile register(org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint ep) { public boolean delete(DataObject obj) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
public VolumeProfile createVolumeFromTemplate(VolumeProfile vol, org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint dp) { public org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile register(org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint ep) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public VolumeProfile createVolumeFromTemplate(VolumeProfile vol, org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint dp) {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -21,12 +21,12 @@ package org.apache.cloudstack.storage.image;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile; import org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile;
import com.cloud.api.commands.RegisterTemplateCmd; import com.cloud.api.commands.RegisterTemplateCmd;
public interface ImageManager { public interface ImageManager {
TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds); TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds);
TemplateProfile getProfile(long templateId);
TemplateProfile allocateTemplateInDB(RegisterTemplateCmd cmd); TemplateProfile getProfile(long templateId);
TemplateProfile allocateTemplateInDB(RegisterTemplateCmd cmd);
} }

View File

@ -41,112 +41,110 @@ import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
public class ImageManagerImpl implements ImageManager { public class ImageManagerImpl implements ImageManager {
private static final Logger s_logger = Logger.getLogger(ImageManagerImpl.class); private static final Logger s_logger = Logger.getLogger(ImageManagerImpl.class);
@Inject @Inject
VMTemplateDao _templateDao; VMTemplateDao _templateDao;
@Inject @Inject
VMTemplatePoolDao _templatePoolDao; VMTemplatePoolDao _templatePoolDao;
@Inject @Inject
DataCenterDao _dcDao; DataCenterDao _dcDao;
public boolean contains(VirtualMachineTemplate template, DataStore ds) { public boolean contains(VirtualMachineTemplate template, DataStore ds) {
long templateId = template.getId(); long templateId = template.getId();
long poolId = ds.getId(); long poolId = ds.getId();
VMTemplateStoragePoolVO templateStoragePoolRef = null; VMTemplateStoragePoolVO templateStoragePoolRef = null;
templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId); templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId);
return templateStoragePoolRef == null ? false : true; return templateStoragePoolRef == null ? false : true;
} }
public TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds) { public TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds) {
long templateId = tp.getTemplateId(); long templateId = tp.getTemplateId();
long poolId = ds.getId(); long poolId = ds.getId();
VMTemplateStoragePoolVO templateStoragePoolRef = null; VMTemplateStoragePoolVO templateStoragePoolRef = null;
long templateStoragePoolRefId; long templateStoragePoolRefId;
templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId); templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId);
if (templateStoragePoolRef != null) { if (templateStoragePoolRef != null) {
templateStoragePoolRef.setMarkedForGC(false); templateStoragePoolRef.setMarkedForGC(false);
_templatePoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef); _templatePoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
if (templateStoragePoolRef.getDownloadState() == Status.DOWNLOADED) { if (templateStoragePoolRef.getDownloadState() == Status.DOWNLOADED) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Template " + templateId + " has already been downloaded to pool " + poolId); s_logger.debug("Template " + templateId + " has already been downloaded to pool " + poolId);
} }
tp.setLocalPath(templateStoragePoolRef.getInstallPath()); tp.setLocalPath(templateStoragePoolRef.getInstallPath());
tp.setTemplatePoolRefId(templateStoragePoolRef.getId()); tp.setTemplatePoolRefId(templateStoragePoolRef.getId());
return tp; return tp;
} }
} }
if (templateStoragePoolRef == null) { if (templateStoragePoolRef == null) {
templateStoragePoolRef = new VMTemplateStoragePoolVO(poolId, templateId); templateStoragePoolRef = new VMTemplateStoragePoolVO(poolId, templateId);
try { try {
templateStoragePoolRef = _templatePoolDao.persist(templateStoragePoolRef); templateStoragePoolRef = _templatePoolDao.persist(templateStoragePoolRef);
templateStoragePoolRefId = templateStoragePoolRef.getId(); templateStoragePoolRefId = templateStoragePoolRef.getId();
} catch (Exception e) { } catch (Exception e) {
s_logger.debug("Assuming we're in a race condition: " + e.getMessage()); s_logger.debug("Assuming we're in a race condition: " + e.getMessage());
templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId); templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId);
if (templateStoragePoolRef == null) { if (templateStoragePoolRef == null) {
throw new CloudRuntimeException("Unable to persist a reference for pool " + poolId + " and template " + templateId); throw new CloudRuntimeException("Unable to persist a reference for pool " + poolId + " and template " + templateId);
} }
templateStoragePoolRefId = templateStoragePoolRef.getId(); templateStoragePoolRefId = templateStoragePoolRef.getId();
} }
} else { } else {
templateStoragePoolRefId = templateStoragePoolRef.getId(); templateStoragePoolRefId = templateStoragePoolRef.getId();
} }
tp.setTemplatePoolRefId(templateStoragePoolRefId); tp.setTemplatePoolRefId(templateStoragePoolRefId);
return tp; return tp;
} }
public TemplateProfile getProfile(long templateId) { public TemplateProfile getProfile(long templateId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
protected TemplateProfile persistTemplate(TemplateProfile profile) { protected TemplateProfile persistTemplate(TemplateProfile profile) {
Long zoneId = profile.getZoneId(); Long zoneId = profile.getZoneId();
VMTemplateVO template = new VMTemplateVO(profile.getTemplateId(), profile.getName(), profile.getFormat(), profile.getIsPublic(), VMTemplateVO template = new VMTemplateVO(profile.getTemplateId(), profile.getName(), profile.getFormat(), profile.getIsPublic(), profile.getFeatured(), profile.getIsExtractable(),
profile.getFeatured(), profile.getIsExtractable(), TemplateType.USER, profile.getUrl(), profile.getRequiresHVM(), TemplateType.USER, profile.getUrl(), profile.getRequiresHVM(), profile.getBits(), profile.getAccountId(), profile.getCheckSum(), profile.getDisplayText(),
profile.getBits(), profile.getAccountId(), profile.getCheckSum(), profile.getDisplayText(), profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(), profile.getDetails(), profile.getSshKeyEnabled());
profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(),
profile.getDetails(), profile.getSshKeyEnabled());
if (zoneId == null || zoneId.longValue() == -1) { if (zoneId == null || zoneId.longValue() == -1) {
List<DataCenterVO> dcs = _dcDao.listAll(); List<DataCenterVO> dcs = _dcDao.listAll();
if (dcs.isEmpty()) { if (dcs.isEmpty()) {
throw new CloudRuntimeException("No zones are present in the system, can't add template"); throw new CloudRuntimeException("No zones are present in the system, can't add template");
} }
template.setCrossZones(true); template.setCrossZones(true);
for (DataCenterVO dc: dcs) { for (DataCenterVO dc : dcs) {
_templateDao.addTemplateToZone(template, dc.getId()); _templateDao.addTemplateToZone(template, dc.getId());
} }
} else { } else {
_templateDao.addTemplateToZone(template, zoneId); _templateDao.addTemplateToZone(template, zoneId);
} }
return getProfile(template.getId()); return getProfile(template.getId());
} }
protected boolean parameterCheck(RegisterTemplateCmd cmd) { protected boolean parameterCheck(RegisterTemplateCmd cmd) {
Long zoneId = cmd.getZoneId(); Long zoneId = cmd.getZoneId();
if (zoneId == -1) { if (zoneId == -1) {
zoneId = null; zoneId = null;
} }
ImageFormat imgfmt = ImageFormat.valueOf(cmd.getFormat().toUpperCase()); ImageFormat imgfmt = ImageFormat.valueOf(cmd.getFormat().toUpperCase());
if (imgfmt == null) { if (imgfmt == null) {
throw new IllegalArgumentException("Image format is incorrect " + cmd.getFormat() + ". Supported formats are " + EnumUtils.listValues(ImageFormat.values())); throw new IllegalArgumentException("Image format is incorrect " + cmd.getFormat() + ". Supported formats are " + EnumUtils.listValues(ImageFormat.values()));
} }
// If a zoneId is specified, make sure it is valid // If a zoneId is specified, make sure it is valid
if (zoneId != null) { if (zoneId != null) {
DataCenterVO zone = _dcDao.findById(zoneId); DataCenterVO zone = _dcDao.findById(zoneId);
if (zone == null) { if (zone == null) {
throw new IllegalArgumentException("Please specify a valid zone."); throw new IllegalArgumentException("Please specify a valid zone.");
} }
} }
List<VMTemplateVO> systemvmTmplts = _templateDao.listAllSystemVMTemplates(); List<VMTemplateVO> systemvmTmplts = _templateDao.listAllSystemVMTemplates();
@ -157,11 +155,11 @@ public class ImageManagerImpl implements ImageManager {
} }
return true; return true;
} }
public TemplateProfile allocateTemplateInDB(RegisterTemplateCmd cmd) { public TemplateProfile allocateTemplateInDB(RegisterTemplateCmd cmd) {
parameterCheck(cmd); parameterCheck(cmd);
//TemplateProfile tp = new TemplateProfile(cmd); // TemplateProfile tp = new TemplateProfile(cmd);
return persistTemplate(null); return persistTemplate(null);
} }
} }

View File

@ -19,8 +19,11 @@
package org.apache.cloudstack.storage.image; package org.apache.cloudstack.storage.image;
public interface ImageOrchestrator { public interface ImageOrchestrator {
void registerTemplate(long templateId); void registerTemplate(long templateId);
void registerSnapshot(long snapshotId);
void registerVolume(long volumeId); void registerSnapshot(long snapshotId);
void registerIso(long isoId);
void registerVolume(long volumeId);
void registerIso(long isoId);
} }

View File

@ -32,47 +32,47 @@ import com.cloud.storage.dao.VMTemplateZoneDao;
import com.cloud.utils.component.Inject; import com.cloud.utils.component.Inject;
public class ImageOrchestratorImpl implements ImageOrchestrator { public class ImageOrchestratorImpl implements ImageOrchestrator {
@Inject @Inject
SecondaryStorageManager _secStorageMgr; SecondaryStorageManager _secStorageMgr;
@Inject @Inject
VMTemplateZoneDao _templateZoneDao; VMTemplateZoneDao _templateZoneDao;
public void registerTemplate(long templateId) {
List<VMTemplateZoneVO> tpZones = _templateZoneDao.listByTemplateId(templateId);
for (VMTemplateZoneVO tpZone : tpZones) { public void registerTemplate(long templateId) {
DataStore imageStore = null; List<VMTemplateZoneVO> tpZones = _templateZoneDao.listByTemplateId(templateId);
List<DataStore> imageStores = _secStorageMgr.getImageStores(tpZone.getZoneId());
for (DataStore imgStore : imageStores) {
TemplateStrategy ts = imgStore.getTemplateStrategy();
if (ts.canRegister(templateId)) {
imageStore = imgStore;
break;
}
}
if (imageStore == null) { for (VMTemplateZoneVO tpZone : tpZones) {
continue; DataStore imageStore = null;
} List<DataStore> imageStores = _secStorageMgr.getImageStores(tpZone.getZoneId());
for (DataStore imgStore : imageStores) {
TemplateStrategy ts = imgStore.getTemplateStrategy();
if (ts.canRegister(templateId)) {
imageStore = imgStore;
break;
}
}
TemplateStrategy ts = imageStore.getTemplateStrategy(); if (imageStore == null) {
ts.register(ts.get(templateId)); continue;
} }
}
public void registerSnapshot(long snapshotId) { TemplateStrategy ts = imageStore.getTemplateStrategy();
// TODO Auto-generated method stub ts.register(ts.get(templateId));
}
}
} public void registerSnapshot(long snapshotId) {
// TODO Auto-generated method stub
public void registerVolume(long volumeId) { }
// TODO Auto-generated method stub
} public void registerVolume(long volumeId) {
// TODO Auto-generated method stub
public void registerIso(long isoId) { }
// TODO Auto-generated method stub
} public void registerIso(long isoId) {
// TODO Auto-generated method stub
}
} }

View File

@ -21,15 +21,22 @@ package org.apache.cloudstack.storage.image;
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity; import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
public interface ImageService { public interface ImageService {
boolean registerTemplate(long templateId, long imageStoreId); TemplateEntity registerTemplate(long templateId, long imageStoreId);
boolean deleteTemplate(long templateId);
long registerIso(String isoUrl, long accountId); boolean deleteTemplate(long templateId);
boolean deleteIso(long isoId);
TemplateInfo grantTemplateAccess(TemplateInfo template, EndPoint endpointId); long registerIso(String isoUrl, long accountId);
boolean revokeTemplateAccess(long templateId, long endpointId);
String grantIsoAccess(long isoId, long endpointId); boolean deleteIso(long isoId);
boolean revokeIsoAccess(long isoId, long endpointId);
TemplateEntity getTemplateEntity(long templateId); boolean grantTemplateAccess(TemplateInfo template, EndPoint endpointId);
boolean revokeTemplateAccess(long templateId, long endpointId);
String grantIsoAccess(long isoId, long endpointId);
boolean revokeIsoAccess(long isoId, long endpointId);
TemplateEntity getTemplateEntity(long templateId);
} }

View File

@ -26,69 +26,66 @@ import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
import org.apache.cloudstack.storage.image.manager.ImageDataStoreManager; import org.apache.cloudstack.storage.image.manager.ImageDataStoreManager;
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager; import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
import org.apache.cloudstack.storage.image.store.ImageDataStore; import org.apache.cloudstack.storage.image.store.ImageDataStore;
import org.springframework.stereotype.Component;
@Component
public class ImageServiceImpl implements ImageService { public class ImageServiceImpl implements ImageService {
@Inject
ImageDataStoreProviderManager imageStoreProviderMgr;
@Inject @Override
ImageDataStoreProviderManager imageStoreProviderMgr; public TemplateEntity registerTemplate(long templateId, long imageStoreId) {
@Inject ImageDataStore ids = imageStoreProviderMgr.getDataStore(imageStoreId);
TemplateObject to = ids.registerTemplate(templateId);
return new TemplateEntityImpl(to);
}
@Override @Override
public boolean registerTemplate(long templateId, long imageStoreId) { public boolean deleteTemplate(long templateId) {
ImageDataStore ids = imageStoreProviderMgr.getDataStore(imageStoreId); // TODO Auto-generated method stub
TemplateInfo template = ids.registerTemplate(templateId); return false;
if (ids.needDownloadToCacheStorage()) { }
ImageDownloader imageDl = ids.getImageDownloader();
imageDl.downloadImage(template);
}
return true;
}
@Override @Override
public boolean deleteTemplate(long templateId) { public long registerIso(String isoUrl, long accountId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return 0;
} }
@Override @Override
public long registerIso(String isoUrl, long accountId) { public boolean deleteIso(long isoId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return false;
} }
@Override @Override
public boolean deleteIso(long isoId) { public boolean revokeTemplateAccess(long templateId, long endpointId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean revokeTemplateAccess(long templateId, long endpointId) { public String grantIsoAccess(long isoId, long endpointId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return null;
} }
@Override @Override
public String grantIsoAccess(long isoId, long endpointId) { public boolean revokeIsoAccess(long isoId, long endpointId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
@Override @Override
public boolean revokeIsoAccess(long isoId, long endpointId) { public TemplateEntity getTemplateEntity(long templateId) {
// TODO Auto-generated method stub ImageDataStore dataStore = imageStoreProviderMgr.getDataStoreFromTemplateId(templateId);
return false; TemplateObject to = dataStore.getTemplate(templateId);
} return new TemplateEntityImpl(to);
}
@Override @Override
public TemplateEntity getTemplateEntity(long templateId) { public boolean grantTemplateAccess(TemplateInfo template, EndPoint endpointId) {
TemplateObject to = imageStoreProviderMgr.getTemplate(templateId); // TODO Auto-generated method stub
return new TemplateEntityImpl(to); return true;
} }
@Override
public TemplateInfo grantTemplateAccess(TemplateInfo template, EndPoint endpointId) {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -32,6 +32,7 @@ import com.cloud.storage.Storage.TemplateType;
public class TemplateEntityImpl implements TemplateEntity { public class TemplateEntityImpl implements TemplateEntity {
protected TemplateInfo templateInfo; protected TemplateInfo templateInfo;
public TemplateEntityImpl(TemplateInfo templateInfo) { public TemplateEntityImpl(TemplateInfo templateInfo) {
this.templateInfo = templateInfo; this.templateInfo = templateInfo;
} }
@ -40,7 +41,6 @@ public class TemplateEntityImpl implements TemplateEntity {
return templateInfo.getImageDataStore(); return templateInfo.getImageDataStore();
} }
public long getImageDataStoreId() { public long getImageDataStoreId() {
return getImageDataStore().getImageDataStoreId(); return getImageDataStore().getImageDataStoreId();
} }
@ -51,14 +51,18 @@ public class TemplateEntityImpl implements TemplateEntity {
@Override @Override
public String getUuid() { public String getUuid() {
// TODO Auto-generated method stub return this.templateInfo.getUuid();
return null;
} }
@Override @Override
public long getId() { public long getId() {
return this.templateInfo.getId();
}
@Override
public String getExternalId() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return null;
} }
@Override @Override

View File

@ -22,7 +22,13 @@ import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTyp
import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo; import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
public interface TemplateInfo { public interface TemplateInfo {
ImageDataStoreInfo getImageDataStore(); ImageDataStoreInfo getImageDataStore();
long getId();
VolumeDiskType getDiskType(); long getId();
VolumeDiskType getDiskType();
String getPath();
String getUuid();
} }

View File

@ -24,24 +24,38 @@ import org.apache.cloudstack.storage.image.db.ImageDataVO;
import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo; import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
public class TemplateObject implements TemplateInfo { public class TemplateObject implements TemplateInfo {
private ImageDataVO imageVO; private ImageDataVO imageVO;
public TemplateObject(ImageDataVO template) { private ImageDataStoreInfo dataStore;
this.imageVO = template;
}
@Override
public ImageDataStoreInfo getImageDataStore() {
// TODO Auto-generated method stub
return null;
}
@Override public TemplateObject(ImageDataVO template, ImageDataStoreInfo dataStore) {
public long getId() { this.imageVO = template;
// TODO Auto-generated method stub this.dataStore = dataStore;
return 0; }
}
@Override @Override
public VolumeDiskType getDiskType() { public ImageDataStoreInfo getImageDataStore() {
return VolumeDiskTypeHelper.getDiskType(imageVO.getFormat()); return this.dataStore;
} }
@Override
public long getId() {
return this.imageVO.getId();
}
@Override
public VolumeDiskType getDiskType() {
return VolumeDiskTypeHelper.getDiskType(imageVO.getFormat());
}
@Override
public String getPath() {
//TODO: add installation path if it's downloaded to cache storage already
return this.imageVO.getUrl();
}
@Override
public String getUuid() {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -21,6 +21,7 @@ package org.apache.cloudstack.storage.image.db;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericDaoBase;
@Component @Component
public class ImageDaoStoreDaoImpl extends GenericDaoBase<ImageDataStoreVO, Long> implements ImageDataStoreDao { public class ImageDaoStoreDaoImpl extends GenericDaoBase<ImageDataStoreVO, Long> implements ImageDataStoreDao {

View File

@ -31,41 +31,51 @@ import com.cloud.utils.Pair;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
public interface ImageDataDao extends GenericDao<ImageDataVO, Long> { public interface ImageDataDao extends GenericDao<ImageDataVO, Long> {
public List<ImageDataVO> listByPublic(); public List<ImageDataVO> listByPublic();
public ImageDataVO findByName(String templateName);
public ImageDataVO findByTemplateName(String templateName);
//public void update(ImageDataVO template); public ImageDataVO findByName(String templateName);
public ImageDataVO findByTemplateName(String templateName);
public List<ImageDataVO> listAllSystemVMTemplates(); // public void update(ImageDataVO template);
public List<ImageDataVO> listDefaultBuiltinTemplates(); public List<ImageDataVO> listAllSystemVMTemplates();
public String getRoutingTemplateUniqueName();
public List<ImageDataVO> findIsosByIdAndPath(Long domainId, Long accountId, String path);
public List<ImageDataVO> listReadyTemplates();
public List<ImageDataVO> listByAccountId(long accountId);
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso,
List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, Long zoneId,
HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,
ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags);
public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter, public List<ImageDataVO> listDefaultBuiltinTemplates();
boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex,
Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller, Map<String, String> tags);
public long addTemplateToZone(ImageDataVO tmplt, long zoneId); public String getRoutingTemplateUniqueName();
public List<ImageDataVO> listAllInZone(long dataCenterId);
public List<ImageDataVO> findIsosByIdAndPath(Long domainId, Long accountId, String path);
public List<ImageDataVO> listReadyTemplates();
public List<ImageDataVO> listByAccountId(long accountId);
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain,
Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,
ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags);
public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain,
Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller, Map<String, String> tags);
public long addTemplateToZone(ImageDataVO tmplt, long zoneId);
public List<ImageDataVO> listAllInZone(long dataCenterId);
public List<ImageDataVO> listByHypervisorType(List<HypervisorType> hyperTypes); public List<ImageDataVO> listByHypervisorType(List<HypervisorType> hyperTypes);
public List<ImageDataVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String, String> tags);
public List<ImageDataVO> userIsoSearch(boolean listRemoved); public List<ImageDataVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String, String> tags);
public List<ImageDataVO> userIsoSearch(boolean listRemoved);
ImageDataVO findSystemVMTemplate(long zoneId); ImageDataVO findSystemVMTemplate(long zoneId);
ImageDataVO findSystemVMTemplate(long zoneId, HypervisorType hType); ImageDataVO findSystemVMTemplate(long zoneId, HypervisorType hType);
ImageDataVO findRoutingTemplate(HypervisorType type); ImageDataVO findRoutingTemplate(HypervisorType type);
List<Long> listPrivateTemplatesByHost(Long hostId); List<Long> listPrivateTemplatesByHost(Long hostId);
public Long countTemplatesForAccount(long accountId); public Long countTemplatesForAccount(long accountId);
} }

View File

@ -21,5 +21,4 @@ package org.apache.cloudstack.storage.image.db;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
public interface ImageDataStoreProviderDao extends GenericDao<ImageDataStoreProviderVO, Long> { public interface ImageDataStoreProviderDao extends GenericDao<ImageDataStoreProviderVO, Long> {
} }

View File

@ -25,25 +25,25 @@ import javax.persistence.Table;
import javax.persistence.TableGenerator; import javax.persistence.TableGenerator;
@Entity @Entity
@Table(name="image_data_store_provider") @Table(name = "image_data_store_provider")
public class ImageDataStoreProviderVO { public class ImageDataStoreProviderVO {
@Id @Id
@TableGenerator(name="image_data_store_provider_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="image_data_store_provider_seq", allocationSize=1) @TableGenerator(name = "image_data_store_provider_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "image_data_store_provider_seq", allocationSize = 1)
@Column(name="id", nullable = false) @Column(name = "id", nullable = false)
private long id; private long id;
@Column(name="name", nullable = false) @Column(name = "name", nullable = false)
private String name; private String name;
public long getId() { public long getId() {
return this.id; return this.id;
} }
public String getName() { public String getName() {
return this.name; return this.name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
} }

View File

@ -25,36 +25,36 @@ import javax.persistence.Table;
import javax.persistence.TableGenerator; import javax.persistence.TableGenerator;
@Entity @Entity
@Table(name="image_data_store") @Table(name = "image_data_store")
public class ImageDataStoreVO { public class ImageDataStoreVO {
@Id @Id
@TableGenerator(name="image_data_store_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="image_data_store_seq", allocationSize=1) @TableGenerator(name = "image_data_store_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "image_data_store_seq", allocationSize = 1)
@Column(name="id", nullable = false) @Column(name = "id", nullable = false)
private long id; private long id;
@Column(name="name", nullable = false) @Column(name = "name", nullable = false)
private String name; private String name;
@Column(name="image_provider", nullable = false) @Column(name = "image_provider", nullable = false)
private long provider; private long provider;
public long getId() { public long getId() {
return this.id; return this.id;
} }
public String getName() { public String getName() {
return this.name; return this.name;
} }
public long getProvider() { public long getProvider() {
return this.provider; return this.provider;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public void setProvider(long provider) { public void setProvider(long provider) {
this.provider = provider; this.provider = provider;
} }
} }

View File

@ -41,101 +41,100 @@ import com.cloud.storage.Storage.TemplateType;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
@Entity @Entity
@Table(name="vm_template") @Table(name = "vm_template")
public class ImageDataVO implements Identity { public class ImageDataVO implements Identity {
@Id @Id
@TableGenerator(name="vm_template_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="vm_template_seq", allocationSize=1) @TableGenerator(name = "vm_template_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "vm_template_seq", allocationSize = 1)
@Column(name="id", nullable = false) @Column(name = "id", nullable = false)
private long id; private long id;
@Column(name="format") @Column(name = "format")
private String format; private String format;
@Column(name="unique_name") @Column(name = "unique_name")
private String uniqueName; private String uniqueName;
@Column(name="name") @Column(name = "name")
private String name = null; private String name = null;
@Column(name="public") @Column(name = "public")
private boolean publicTemplate = true; private boolean publicTemplate = true;
@Column(name="featured") @Column(name = "featured")
private boolean featured; private boolean featured;
@Column(name="type") @Column(name = "type")
private Storage.TemplateType templateType; private Storage.TemplateType templateType;
@Column(name="url") @Column(name = "url")
private String url = null; private String url = null;
@Column(name="hvm") @Column(name = "hvm")
private boolean requiresHvm; private boolean requiresHvm;
@Column(name="bits") @Column(name = "bits")
private int bits; private int bits;
@Temporal(value=TemporalType.TIMESTAMP) @Temporal(value = TemporalType.TIMESTAMP)
@Column(name=GenericDao.CREATED_COLUMN) @Column(name = GenericDao.CREATED_COLUMN)
private Date created = null; private Date created = null;
@Column(name=GenericDao.REMOVED) @Column(name = GenericDao.REMOVED)
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date removed; private Date removed;
@Column(name="account_id") @Column(name = "account_id")
private long accountId; private long accountId;
@Column(name="checksum") @Column(name = "checksum")
private String checksum; private String checksum;
@Column(name="display_text", length=4096) @Column(name = "display_text", length = 4096)
private String displayText; private String displayText;
@Column(name="enable_password") @Column(name = "enable_password")
private boolean enablePassword; private boolean enablePassword;
@Column(name="guest_os_id") @Column(name = "guest_os_id")
private long guestOSId; private long guestOSId;
@Column(name="bootable") @Column(name = "bootable")
private boolean bootable = true; private boolean bootable = true;
@Column(name="prepopulate") @Column(name = "prepopulate")
private boolean prepopulate = false; private boolean prepopulate = false;
@Column(name="cross_zones") @Column(name = "cross_zones")
private boolean crossZones = false; private boolean crossZones = false;
@Column(name="hypervisor_type") @Column(name = "hypervisor_type")
@Enumerated(value=EnumType.STRING) @Enumerated(value = EnumType.STRING)
private HypervisorType hypervisorType; private HypervisorType hypervisorType;
@Column(name="extractable") @Column(name = "extractable")
private boolean extractable = true; private boolean extractable = true;
@Column(name="source_template_id") @Column(name = "source_template_id")
private Long sourceTemplateId; private Long sourceTemplateId;
@Column(name="template_tag") @Column(name = "template_tag")
private String templateTag; private String templateTag;
@Column(name="uuid") @Column(name = "uuid")
private String uuid; private String uuid;
@Column(name="sort_key") @Column(name = "sort_key")
private int sortKey; private int sortKey;
@Column(name="enable_sshkey") @Column(name = "enable_sshkey")
private boolean enableSshKey; private boolean enableSshKey;
@Column(name="image_data_store_id") @Column(name = "image_data_store_id")
private long imageDataStoreId; private long imageDataStoreId;
@Transient @Transient
Map details; Map details;
public String getUniqueName() { public String getUniqueName() {
return uniqueName; return uniqueName;
} }
@ -145,7 +144,7 @@ public class ImageDataVO implements Identity {
} }
protected ImageDataVO() { protected ImageDataVO() {
this.uuid = UUID.randomUUID().toString(); this.uuid = UUID.randomUUID().toString();
} }
public boolean getEnablePassword() { public boolean getEnablePassword() {
@ -318,30 +317,30 @@ public class ImageDataVO implements Identity {
@Override @Override
public String getUuid() { public String getUuid() {
return this.uuid; return this.uuid;
} }
public void setUuid(String uuid) { public void setUuid(String uuid) {
this.uuid = uuid; this.uuid = uuid;
} }
public Map getDetails() { public Map getDetails() {
return this.details; return this.details;
} }
public void setDetails(Map details) { public void setDetails(Map details) {
this.details = details; this.details = details;
} }
@Override @Override
public boolean equals(Object that) { public boolean equals(Object that) {
if (this == that ) { if (this == that) {
return true; return true;
} }
if (!(that instanceof VMTemplateVO)){ if (!(that instanceof VMTemplateVO)) {
return false; return false;
} }
VMTemplateVO other = (VMTemplateVO)that; VMTemplateVO other = (VMTemplateVO) that;
return ((this.getUniqueName().equals(other.getUniqueName()))); return ((this.getUniqueName().equals(other.getUniqueName())));
} }
@ -353,6 +352,7 @@ public class ImageDataVO implements Identity {
@Transient @Transient
String toString; String toString;
@Override @Override
public String toString() { public String toString() {
if (toString == null) { if (toString == null) {
@ -366,27 +366,27 @@ public class ImageDataVO implements Identity {
} }
public void setSortKey(int key) { public void setSortKey(int key) {
sortKey = key; sortKey = key;
} }
public int getSortKey() { public int getSortKey() {
return sortKey; return sortKey;
} }
public boolean getEnableSshKey() { public boolean getEnableSshKey() {
return enableSshKey; return enableSshKey;
} }
public void setEnableSshKey(boolean enable) { public void setEnableSshKey(boolean enable) {
enableSshKey = enable; enableSshKey = enable;
} }
public long getImageDataStoreId() { public Long getImageDataStoreId() {
return this.imageDataStoreId; return this.imageDataStoreId;
} }
public void setImageDataStoreId(long dataStoreId) { public void setImageDataStoreId(long dataStoreId) {
this.imageDataStoreId = dataStoreId; this.imageDataStoreId = dataStoreId;
} }
} }

View File

@ -21,5 +21,5 @@ package org.apache.cloudstack.storage.image.downloader;
import org.apache.cloudstack.storage.image.TemplateInfo; import org.apache.cloudstack.storage.image.TemplateInfo;
public interface ImageDownloader { public interface ImageDownloader {
public void downloadImage(TemplateInfo template); public void downloadImage(TemplateInfo template);
} }

View File

@ -21,8 +21,11 @@ package org.apache.cloudstack.storage.image.driver;
import org.apache.cloudstack.storage.image.TemplateInfo; import org.apache.cloudstack.storage.image.TemplateInfo;
public interface ImageDataStoreDriver { public interface ImageDataStoreDriver {
boolean registerTemplate(TemplateInfo template); boolean registerTemplate(TemplateInfo template);
String grantAccess(long templateId, long endPointId);
boolean revokeAccess(long templateId, long endPointId); String grantAccess(long templateId, long endPointId);
boolean deleteTemplate(TemplateInfo template);
boolean revokeAccess(long templateId, long endPointId);
boolean deleteTemplate(TemplateInfo template);
} }

View File

@ -22,32 +22,31 @@ import org.apache.cloudstack.storage.image.TemplateInfo;
public class ImageDataStoreDriverImpl implements ImageDataStoreDriver { public class ImageDataStoreDriverImpl implements ImageDataStoreDriver {
public ImageDataStoreDriverImpl() { public ImageDataStoreDriverImpl() {
} }
@Override
public boolean registerTemplate(TemplateInfo template) {
//TODO: check the availability of template
return true;
}
@Override @Override
public String grantAccess(long templateId, long endPointId) { public boolean registerTemplate(TemplateInfo template) {
// TODO Auto-generated method stub // TODO: check the availability of template
return null; return true;
} }
@Override @Override
public boolean revokeAccess(long templateId, long endPointId) { public String grantAccess(long templateId, long endPointId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return null;
} }
@Override
public boolean deleteTemplate(TemplateInfo template) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean revokeAccess(long templateId, long endPointId) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean deleteTemplate(TemplateInfo template) {
// TODO Auto-generated method stub
return false;
}
} }

View File

@ -23,9 +23,10 @@ import org.springframework.stereotype.Component;
@Component @Component
public class BAREMETAL extends BaseType implements ImageFormat { public class BAREMETAL extends BaseType implements ImageFormat {
private final String type = "BAREMETAL"; private final String type = "BAREMETAL";
@Override
public String toString() { @Override
return type; public String toString() {
} return type;
}
} }

View File

@ -23,9 +23,10 @@ import org.springframework.stereotype.Component;
@Component @Component
public class ISO extends BaseType implements ImageFormat { public class ISO extends BaseType implements ImageFormat {
private final String type = "ISO"; private final String type = "ISO";
@Override
public String toString() { @Override
return type; public String toString() {
} return type;
}
} }

View File

@ -26,19 +26,20 @@ import org.springframework.stereotype.Component;
@Component @Component
public class ImageFormatHelper { public class ImageFormatHelper {
private static List<ImageFormat> formats; private static List<ImageFormat> formats;
private static final ImageFormat defaultFormat = new Unknown(); private static final ImageFormat defaultFormat = new Unknown();
@Inject
public void setFormats(List<ImageFormat> formats) {
ImageFormatHelper.formats = formats;
}
public static ImageFormat getFormat(String format) { @Inject
for(ImageFormat fm : formats) { public void setFormats(List<ImageFormat> formats) {
if (fm.equals(format)) { ImageFormatHelper.formats = formats;
return fm; }
}
} public static ImageFormat getFormat(String format) {
return ImageFormatHelper.defaultFormat; for (ImageFormat fm : formats) {
} if (fm.equals(format)) {
return fm;
}
}
return ImageFormatHelper.defaultFormat;
}
} }

View File

@ -23,9 +23,10 @@ import org.springframework.stereotype.Component;
@Component @Component
public class OVA extends BaseType implements ImageFormat { public class OVA extends BaseType implements ImageFormat {
private final String type = "OVA"; private final String type = "OVA";
@Override
public String toString() { @Override
return type; public String toString() {
} return type;
}
} }

View File

@ -23,9 +23,10 @@ import org.springframework.stereotype.Component;
@Component("imageformat_qcow2") @Component("imageformat_qcow2")
public class QCOW2 extends BaseType implements ImageFormat { public class QCOW2 extends BaseType implements ImageFormat {
private final String type = "QCOW2"; private final String type = "QCOW2";
@Override
public String toString() { @Override
return type; public String toString() {
} return type;
}
} }

View File

@ -23,10 +23,10 @@ import org.springframework.stereotype.Component;
@Component @Component
public class Unknown extends BaseType implements ImageFormat { public class Unknown extends BaseType implements ImageFormat {
private final String type = "Unknown"; private final String type = "Unknown";
@Override @Override
public String toString() { public String toString() {
return type; return type;
} }
} }

View File

@ -19,11 +19,14 @@
package org.apache.cloudstack.storage.image.format; package org.apache.cloudstack.storage.image.format;
import org.apache.cloudstack.storage.BaseType; import org.apache.cloudstack.storage.BaseType;
import org.springframework.stereotype.Component;
@Component
public class VHD extends BaseType implements ImageFormat { public class VHD extends BaseType implements ImageFormat {
private final String type = "VHD"; private final String type = "VHD";
@Override
public String toString() { @Override
return type; public String toString() {
} return type;
}
} }

View File

@ -21,5 +21,5 @@ package org.apache.cloudstack.storage.image.manager;
import org.apache.cloudstack.storage.image.store.ImageDataStore; import org.apache.cloudstack.storage.image.store.ImageDataStore;
public interface ImageDataStoreManager { public interface ImageDataStoreManager {
ImageDataStore getImageDataStore(long dataStoreId); ImageDataStore getImageDataStore(long dataStoreId);
} }

View File

@ -27,15 +27,16 @@ import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
import org.apache.cloudstack.storage.image.store.ImageDataStore; import org.apache.cloudstack.storage.image.store.ImageDataStore;
public class ImageDataStoreManagerImpl implements ImageDataStoreManager { public class ImageDataStoreManagerImpl implements ImageDataStoreManager {
@Inject @Inject
ImageDataStoreDao dataStoreDao; ImageDataStoreDao dataStoreDao;
@Inject @Inject
ImageDataDao imageDataDao; ImageDataDao imageDataDao;
@Override
public ImageDataStore getImageDataStore(long dataStoreId) { @Override
ImageDataStoreVO dataStore = dataStoreDao.findById(dataStoreId); public ImageDataStore getImageDataStore(long dataStoreId) {
// TODO Auto-generated method stub ImageDataStoreVO dataStore = dataStoreDao.findById(dataStoreId);
return null; // TODO Auto-generated method stub
} return null;
}
} }

View File

@ -29,27 +29,29 @@ import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
import org.apache.cloudstack.storage.to.TemplateTO; import org.apache.cloudstack.storage.to.TemplateTO;
import org.apache.cloudstack.storage.to.VolumeTO; import org.apache.cloudstack.storage.to.VolumeTO;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo; import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
import org.springframework.stereotype.Component;
@Component
public class DefaultImageMotionStrategy implements ImageMotionStrategy { public class DefaultImageMotionStrategy implements ImageMotionStrategy {
@Override @Override
public boolean canHandle(TemplateOnPrimaryDataStoreInfo templateStore) { public boolean canHandle(TemplateOnPrimaryDataStoreInfo templateStore) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return true; return true;
} }
@Override @Override
public EndPoint getEndPoint(TemplateOnPrimaryDataStoreInfo templateStore) { public EndPoint getEndPoint(TemplateOnPrimaryDataStoreInfo templateStore) {
PrimaryDataStoreInfo pdi = templateStore.getPrimaryDataStore(); PrimaryDataStoreInfo pdi = templateStore.getPrimaryDataStore();
return pdi.getEndPoints().get(0); return pdi.getEndPoints().get(0);
} }
@Override @Override
public boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore, EndPoint ep) { public boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore, EndPoint ep) {
ImageOnPrimayDataStoreTO imageTo = new ImageOnPrimayDataStoreTO(templateStore); ImageOnPrimayDataStoreTO imageTo = new ImageOnPrimayDataStoreTO(templateStore);
CopyTemplateToPrimaryStorage copyCommand = new CopyTemplateToPrimaryStorage(imageTo); CopyTemplateToPrimaryStorage copyCommand = new CopyTemplateToPrimaryStorage(imageTo);
ep.sendMessage(copyCommand); ep.sendMessage(copyCommand);
return true; return true;
} }
} }

View File

@ -21,6 +21,7 @@ package org.apache.cloudstack.storage.image.motion;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo; import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
public interface ImageMotionService { public interface ImageMotionService {
boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore); boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore);
boolean copyIso(String isoUri, String destIsoUri);
boolean copyIso(String isoUri, String destIsoUri);
} }

View File

@ -31,41 +31,44 @@ import org.apache.cloudstack.storage.image.ImageService;
import org.apache.cloudstack.storage.image.TemplateInfo; import org.apache.cloudstack.storage.image.TemplateInfo;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo; import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
import org.apache.cloudstack.storage.volume.VolumeService; import org.apache.cloudstack.storage.volume.VolumeService;
import org.springframework.stereotype.Component;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
@Component
public class ImageMotionServiceImpl implements ImageMotionService { public class ImageMotionServiceImpl implements ImageMotionService {
@Inject @Inject
List<ImageMotionStrategy> motionStrategies; List<ImageMotionStrategy> motionStrategies;
@Inject @Inject
VolumeService volumeService; VolumeService volumeService;
@Inject @Inject
ImageService imageService; ImageService imageService;
@Override
public boolean copyIso(String isoUri, String destIsoUri) {
// TODO Auto-generated method stub
return false;
}
@Override @Override
public boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore) { public boolean copyIso(String isoUri, String destIsoUri) {
ImageMotionStrategy ims = null; // TODO Auto-generated method stub
for (ImageMotionStrategy strategy : motionStrategies) { return false;
if (strategy.canHandle(templateStore)) { }
ims = strategy;
break;
}
}
if (ims == null) { @Override
throw new CloudRuntimeException("Can't find proper image motion strategy"); public boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore) {
} ImageMotionStrategy ims = null;
for (ImageMotionStrategy strategy : motionStrategies) {
if (strategy.canHandle(templateStore)) {
ims = strategy;
break;
}
}
EndPoint ep = ims.getEndPoint(templateStore); if (ims == null) {
throw new CloudRuntimeException("Can't find proper image motion strategy");
}
volumeService.grantAccess(templateStore, ep); EndPoint ep = ims.getEndPoint(templateStore);
TemplateInfo template = templateStore.getTemplate();
imageService.grantTemplateAccess(template, ep); volumeService.grantAccess(templateStore, ep);
return ims.copyTemplate(templateStore, ep); TemplateInfo template = templateStore.getTemplate();
} imageService.grantTemplateAccess(template, ep);
return ims.copyTemplate(templateStore, ep);
}
} }

View File

@ -22,7 +22,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo; import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
public interface ImageMotionStrategy { public interface ImageMotionStrategy {
public boolean canHandle(TemplateOnPrimaryDataStoreInfo templateStore); public boolean canHandle(TemplateOnPrimaryDataStoreInfo templateStore);
public EndPoint getEndPoint(TemplateOnPrimaryDataStoreInfo templateStore);
public boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore, EndPoint ep); public EndPoint getEndPoint(TemplateOnPrimaryDataStoreInfo templateStore);
public boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore, EndPoint ep);
} }

View File

@ -31,23 +31,29 @@ import org.springframework.stereotype.Component;
@Component @Component
public class DefaultImageDataStoreProvider implements ImageDataStoreProvider { public class DefaultImageDataStoreProvider implements ImageDataStoreProvider {
private final String providerName = "DefaultProvider"; private final String providerName = "DefaultProvider";
@Inject @Inject
ImageDataStoreProviderDao providerDao; ImageDataStoreProviderDao providerDao;
@Inject @Inject
ImageDataStoreDao imageStoreDao; ImageDataStoreDao imageStoreDao;
@Override @Override
public ImageDataStore getImageDataStore(long imageStoreId) { public ImageDataStore getImageDataStore(long imageStoreId) {
ImageDataStoreVO idsv = imageStoreDao.findById(imageStoreId); ImageDataStoreVO idsv = imageStoreDao.findById(imageStoreId);
ImageDataStoreDriver driver = new ImageDataStoreDriverImpl(); ImageDataStoreDriver driver = new ImageDataStoreDriverImpl();
ImageDataStore ids = new ImageDataStoreImpl(idsv, driver, false, null); ImageDataStore ids = new ImageDataStoreImpl(idsv, driver, false, null);
return ids; return ids;
} }
@Override @Override
public String getName() { public String getName() {
return providerName; return providerName;
} }
@Override
public boolean register(long providerId) {
// TODO Auto-generated method stub
return true;
}
} }

View File

@ -21,6 +21,7 @@ package org.apache.cloudstack.storage.image.provider;
import org.apache.cloudstack.storage.image.store.ImageDataStore; import org.apache.cloudstack.storage.image.store.ImageDataStore;
public interface ImageDataStoreProvider { public interface ImageDataStoreProvider {
ImageDataStore getImageDataStore(long imageStoreId); ImageDataStore getImageDataStore(long imageStoreId);
public String getName(); boolean register(long providerId);
public String getName();
} }

View File

@ -21,9 +21,12 @@ package org.apache.cloudstack.storage.image.provider;
import org.apache.cloudstack.storage.image.TemplateObject; import org.apache.cloudstack.storage.image.TemplateObject;
import org.apache.cloudstack.storage.image.store.ImageDataStore; import org.apache.cloudstack.storage.image.store.ImageDataStore;
public interface ImageDataStoreProviderManager { import com.cloud.utils.component.Manager;
public ImageDataStoreProvider getProvider(long providerId);
public ImageDataStore getDataStore(long dataStoreId); public interface ImageDataStoreProviderManager extends Manager {
public ImageDataStore getDataStoreFromTemplateId(long templateId); public ImageDataStoreProvider getProvider(long providerId);
public TemplateObject getTemplate(long templateId);
public ImageDataStore getDataStore(Long dataStoreId);
public ImageDataStore getDataStoreFromTemplateId(long templateId);
} }

View File

@ -19,8 +19,10 @@
package org.apache.cloudstack.storage.image.provider; package org.apache.cloudstack.storage.image.provider;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.storage.image.TemplateObject; import org.apache.cloudstack.storage.image.TemplateObject;
import org.apache.cloudstack.storage.image.db.ImageDataDao; import org.apache.cloudstack.storage.image.db.ImageDataDao;
@ -34,47 +36,94 @@ import org.springframework.stereotype.Component;
@Component @Component
public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProviderManager { public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProviderManager {
@Inject @Inject
ImageDataStoreProviderDao providerDao; ImageDataStoreProviderDao providerDao;
@Inject @Inject
ImageDataStoreDao dataStoreDao; ImageDataStoreDao dataStoreDao;
@Inject @Inject
ImageDataDao imageDataDao; ImageDataDao imageDataDao;
@Inject @Inject
List<ImageDataStoreProvider> providers; List<ImageDataStoreProvider> providers;
@Override
public ImageDataStoreProvider getProvider(long providerId) {
return null; @Override
} public ImageDataStoreProvider getProvider(long providerId) {
protected ImageDataStoreProvider getProvider(String name) { return null;
for (ImageDataStoreProvider provider : providers) { }
if (provider.getName().equalsIgnoreCase(name)) {
return provider;
}
}
return null;
}
@Override protected ImageDataStoreProvider getProvider(String name) {
public ImageDataStore getDataStore(long dataStoreId) { for (ImageDataStoreProvider provider : providers) {
ImageDataStoreVO idsv = dataStoreDao.findById(dataStoreId); if (provider.getName().equalsIgnoreCase(name)) {
long providerId = idsv.getProvider(); return provider;
ImageDataStoreProviderVO idspv = providerDao.findById(providerId); }
ImageDataStoreProvider provider = getProvider(idspv.getName()); }
return provider.getImageDataStore(dataStoreId); return null;
} }
@Override @Override
public ImageDataStore getDataStoreFromTemplateId(long templateId) { public ImageDataStore getDataStore(Long dataStoreId) {
ImageDataVO iddv = imageDataDao.findById(templateId); if (dataStoreId == null) {
return getDataStore(iddv.getId()); return null;
} }
@Override ImageDataStoreVO idsv = dataStoreDao.findById(dataStoreId);
public TemplateObject getTemplate(long templateId) { if (idsv == null) {
// TODO Auto-generated method stub return null;
return null; }
}
long providerId = idsv.getProvider();
ImageDataStoreProviderVO idspv = providerDao.findById(providerId);
ImageDataStoreProvider provider = getProvider(idspv.getName());
return provider.getImageDataStore(dataStoreId);
}
@Override
public ImageDataStore getDataStoreFromTemplateId(long templateId) {
ImageDataVO iddv = imageDataDao.findById(templateId);
return getDataStore(iddv.getImageDataStoreId());
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
List<ImageDataStoreProviderVO> existingProviders = providerDao.listAll();
//TODO: hold global lock
boolean foundExistingProvider = false;
for (ImageDataStoreProvider provider : providers) {
foundExistingProvider = false;
for (ImageDataStoreProviderVO existingProvider : existingProviders) {
if (provider.getName().equalsIgnoreCase(existingProvider.getName())) {
foundExistingProvider = true;
break;
}
}
if (!foundExistingProvider) {
//add a new provider into db
ImageDataStoreProviderVO nProvider = new ImageDataStoreProviderVO();
nProvider.setName(provider.getName());
nProvider = providerDao.persist(nProvider);
provider.register(nProvider.getId());
}
}
return true;
}
@Override
public boolean start() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean stop() {
// TODO Auto-generated method stub
return false;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -19,14 +19,21 @@
package org.apache.cloudstack.storage.image.store; package org.apache.cloudstack.storage.image.store;
import org.apache.cloudstack.storage.image.TemplateInfo; import org.apache.cloudstack.storage.image.TemplateInfo;
import org.apache.cloudstack.storage.image.TemplateObject;
import org.apache.cloudstack.storage.image.downloader.ImageDownloader; import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
public interface ImageDataStore extends ImageDataStoreInfo { public interface ImageDataStore extends ImageDataStoreInfo {
TemplateInfo registerTemplate(long templateId); TemplateObject registerTemplate(long templateId);
String grantAccess(long templateId, long endPointId);
boolean revokeAccess(long templateId, long endPointId);
boolean deleteTemplate(long templateId);
boolean needDownloadToCacheStorage();
ImageDownloader getImageDownloader(); String grantAccess(long templateId, long endPointId);
boolean revokeAccess(long templateId, long endPointId);
boolean deleteTemplate(long templateId);
boolean needDownloadToCacheStorage();
ImageDownloader getImageDownloader();
TemplateObject getTemplate(long templateId);
} }

View File

@ -21,6 +21,7 @@ package org.apache.cloudstack.storage.image.store;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.cloudstack.storage.image.TemplateInfo; import org.apache.cloudstack.storage.image.TemplateInfo;
import org.apache.cloudstack.storage.image.TemplateObject;
import org.apache.cloudstack.storage.image.db.ImageDataDao; import org.apache.cloudstack.storage.image.db.ImageDataDao;
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao; import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO; import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
@ -29,72 +30,76 @@ import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver; import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver;
public class ImageDataStoreImpl implements ImageDataStore { public class ImageDataStoreImpl implements ImageDataStore {
@Inject @Inject
ImageDataDao imageDao; ImageDataDao imageDao;
ImageDataStoreDriver driver; ImageDataStoreDriver driver;
ImageDownloader downloader; ImageDownloader downloader;
ImageDataStoreVO imageDataStoreVO; ImageDataStoreVO imageDataStoreVO;
boolean needDownloadToCacheStorage = false; boolean needDownloadToCacheStorage = false;
public ImageDataStoreImpl(ImageDataStoreVO dataStoreVO, ImageDataStoreDriver driver, boolean needDownloadToCacheStorage, ImageDownloader downloader) {
this.driver = driver;
this.needDownloadToCacheStorage = needDownloadToCacheStorage;
this.downloader = downloader;
this.imageDataStoreVO = dataStoreVO;
}
public ImageDataStoreImpl(ImageDataStoreVO dataStoreVO, ImageDataStoreDriver driver, boolean needDownloadToCacheStorage, ImageDownloader downloader) { /*
this.driver = driver; * @Override public TemplateInfo registerTemplate(long templateId) {
this.needDownloadToCacheStorage = needDownloadToCacheStorage; * ImageDataVO idv = imageDao.findById(templateId); TemplateInfo template =
this.downloader = downloader; * new TemplateInfo(this, idv); if (driver.registerTemplate(template)) {
this.imageDataStoreVO = dataStoreVO; * template.setImageDataStoreId(imageDataStoreVO.getId()); return template;
} * } else { return null; } }
/* */
@Override
public TemplateInfo registerTemplate(long templateId) {
ImageDataVO idv = imageDao.findById(templateId);
TemplateInfo template = new TemplateInfo(this, idv);
if (driver.registerTemplate(template)) {
template.setImageDataStoreId(imageDataStoreVO.getId());
return template;
} else {
return null;
}
}*/
@Override @Override
public String grantAccess(long templateId, long endPointId) { public String grantAccess(long templateId, long endPointId) {
ImageDataVO idv = imageDao.findById(templateId); ImageDataVO idv = imageDao.findById(templateId);
return idv.getUrl(); return idv.getUrl();
} }
@Override @Override
public boolean revokeAccess(long templateId, long endPointId) { public boolean revokeAccess(long templateId, long endPointId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean deleteTemplate(long templateId) { public boolean deleteTemplate(long templateId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean needDownloadToCacheStorage() { public boolean needDownloadToCacheStorage() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public ImageDownloader getImageDownloader() { public ImageDownloader getImageDownloader() {
return this.downloader; return this.downloader;
} }
@Override @Override
public long getImageDataStoreId() { public long getImageDataStoreId() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }
@Override @Override
public TemplateInfo registerTemplate(long templateId) { public TemplateObject registerTemplate(long templateId) {
// TODO Auto-generated method stub ImageDataVO image = imageDao.findById(templateId);
return null; image.setImageDataStoreId(this.getImageDataStoreId());
} imageDao.update(templateId, image);
return getTemplate(templateId);
}
@Override
public TemplateObject getTemplate(long templateId) {
ImageDataVO image = imageDao.findById(templateId);
TemplateObject to = new TemplateObject(image, this);
return to;
}
} }

View File

@ -19,5 +19,5 @@
package org.apache.cloudstack.storage.image.store; package org.apache.cloudstack.storage.image.store;
public interface ImageDataStoreInfo { public interface ImageDataStoreInfo {
public long getImageDataStoreId(); public long getImageDataStoreId();
} }

View File

@ -22,33 +22,35 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
public class DefaultNfsSecondaryLifeCycle implements DataStoreLifeCycle { public class DefaultNfsSecondaryLifeCycle implements DataStoreLifeCycle {
protected DataStore _ds; protected DataStore _ds;
public DefaultNfsSecondaryLifeCycle(DataStore ds) {
_ds = ds;
}
public void add() {
// TODO Auto-generated method stub
} public DefaultNfsSecondaryLifeCycle(DataStore ds) {
_ds = ds;
}
public void delete() { public void add() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void enable() { public void delete() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void disable() { public void enable() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void processEvent(DataStoreEvent event, Object... objs) { public void disable() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void processEvent(DataStoreEvent event, Object... objs) {
// TODO Auto-generated method stub
}
} }

View File

@ -26,98 +26,98 @@ import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
public class DefaultPrimaryDataStoreLifeCycle implements DataStoreLifeCycle { public class DefaultPrimaryDataStoreLifeCycle implements DataStoreLifeCycle {
private static final Logger s_logger = Logger.getLogger(DataStoreLifeCycle.class); private static final Logger s_logger = Logger.getLogger(DataStoreLifeCycle.class);
private DataStore _ds; private DataStore _ds;
@Inject @Inject
StoragePoolDao _storagePoolDao; StoragePoolDao _storagePoolDao;
@Inject @Inject
StoragePoolHostDao _poolHostDao; StoragePoolHostDao _poolHostDao;
public DefaultPrimaryDataStoreLifeCycle(DataStore ds) {
this._ds = ds;
}
public DefaultPrimaryDataStoreLifeCycle(DataStore ds) {
this._ds = ds;
}
protected boolean createStoragePool(DataStoreEndPoint ep, StoragePoolVO pool) { protected boolean createStoragePool(DataStoreEndPoint ep, StoragePoolVO pool) {
DataStoreDriver dsDriver = _ds.getDataStoreDriver(); DataStoreDriver dsDriver = _ds.getDataStoreDriver();
CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool); CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool);
final Answer answer = dsDriver.sendMessage(ep, cmd); final Answer answer = dsDriver.sendMessage(ep, cmd);
if (answer != null && answer.getResult()) { if (answer != null && answer.getResult()) {
return true; return true;
} else { } else {
throw new CloudRuntimeException(answer.getDetails()); throw new CloudRuntimeException(answer.getDetails());
} }
} }
protected void connectHostToSharedPool(DataStoreEndPoint ep, StoragePoolVO pool) throws StorageUnavailableException { protected void connectHostToSharedPool(DataStoreEndPoint ep, StoragePoolVO pool) throws StorageUnavailableException {
DataStoreDriver dsDriver = _ds.getDataStoreDriver(); DataStoreDriver dsDriver = _ds.getDataStoreDriver();
long hostId = ep.getHostId(); long hostId = ep.getHostId();
ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool); ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
final Answer answer = dsDriver.sendMessage(ep, cmd); final Answer answer = dsDriver.sendMessage(ep, cmd);
if (answer == null) { if (answer == null) {
throw new StorageUnavailableException("Unable to get an answer to the modify storage pool command", pool.getId()); throw new StorageUnavailableException("Unable to get an answer to the modify storage pool command", pool.getId());
} }
if (!answer.getResult()) { if (!answer.getResult()) {
throw new StorageUnavailableException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails(), pool.getId()); throw new StorageUnavailableException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails(), pool.getId());
} }
assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId(); assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId();
ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer; ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
StoragePoolHostVO poolHost = _poolHostDao.findByPoolHost(pool.getId(), hostId); StoragePoolHostVO poolHost = _poolHostDao.findByPoolHost(pool.getId(), hostId);
if (poolHost == null) { if (poolHost == null) {
poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/")); poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
_poolHostDao.persist(poolHost); _poolHostDao.persist(poolHost);
} else { } else {
poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/")); poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
} }
pool.setAvailableBytes(mspAnswer.getPoolInfo().getAvailableBytes()); pool.setAvailableBytes(mspAnswer.getPoolInfo().getAvailableBytes());
pool.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes()); pool.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes());
_storagePoolDao.update(pool.getId(), pool); _storagePoolDao.update(pool.getId(), pool);
} }
public void add() { public void add() {
DataStoreEndPointSelector dseps = _ds.getEndPointSelector(); DataStoreEndPointSelector dseps = _ds.getEndPointSelector();
List<DataStoreEndPoint> dsep = dseps.getEndPoints(null); List<DataStoreEndPoint> dsep = dseps.getEndPoints(null);
boolean success = false; boolean success = false;
StoragePoolVO spool = _storagePoolDao.findById(_ds.getId()); StoragePoolVO spool = _storagePoolDao.findById(_ds.getId());
for (DataStoreEndPoint ep : dsep) { for (DataStoreEndPoint ep : dsep) {
success = createStoragePool(ep, spool); success = createStoragePool(ep, spool);
if (success) { if (success) {
break; break;
} }
} }
List<DataStoreEndPoint> poolHosts = new ArrayList<DataStoreEndPoint>(); List<DataStoreEndPoint> poolHosts = new ArrayList<DataStoreEndPoint>();
for (DataStoreEndPoint ep : dsep) { for (DataStoreEndPoint ep : dsep) {
try { try {
connectHostToSharedPool(ep, spool); connectHostToSharedPool(ep, spool);
poolHosts.add(ep); poolHosts.add(ep);
} catch (Exception e) { } catch (Exception e) {
s_logger.debug("Failed to add storage on this ep: " + ep.getHostId()); s_logger.debug("Failed to add storage on this ep: " + ep.getHostId());
} }
} }
} }
public void delete() { public void delete() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void enable() { public void enable() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void disable() { public void disable() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void processEvent(DataStoreEvent event, Object... objs) { public void processEvent(DataStoreEvent event, Object... objs) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
} }

View File

@ -27,13 +27,17 @@ import com.cloud.template.VirtualMachineTemplate;
import com.cloud.utils.fsm.NoTransitionException; import com.cloud.utils.fsm.NoTransitionException;
public interface BackupStorageManager { public interface BackupStorageManager {
boolean contains(Volume vol); boolean contains(Volume vol);
boolean contains(Snapshot snapshot);
boolean contains(VirtualMachineTemplate template);
DataStore getBackupDataStore(Volume vol); boolean contains(Snapshot snapshot);
DataStore getBackupDataStore(Snapshot snapshot);
DataStore getBackupDataStore(VirtualMachineTemplate template);
boolean updateOperationState(Volume vol, DataObjectBackupStorageOperationState.Event event) throws NoTransitionException; boolean contains(VirtualMachineTemplate template);
DataStore getBackupDataStore(Volume vol);
DataStore getBackupDataStore(Snapshot snapshot);
DataStore getBackupDataStore(VirtualMachineTemplate template);
boolean updateOperationState(Volume vol, DataObjectBackupStorageOperationState.Event event) throws NoTransitionException;
} }

View File

@ -28,39 +28,39 @@ import com.cloud.utils.fsm.NoTransitionException;
public class BackupStorageManagerImpl implements BackupStorageManager { public class BackupStorageManagerImpl implements BackupStorageManager {
public boolean contains(Volume vol) { public boolean contains(Volume vol) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public boolean contains(Snapshot snapshot) { public boolean contains(Snapshot snapshot) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public boolean contains(VirtualMachineTemplate template) { public boolean contains(VirtualMachineTemplate template) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public DataStore getBackupDataStore(Volume vol) { public DataStore getBackupDataStore(Volume vol) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataStore getBackupDataStore(Snapshot snapshot) { public DataStore getBackupDataStore(Snapshot snapshot) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataStore getBackupDataStore(VirtualMachineTemplate template) { public DataStore getBackupDataStore(VirtualMachineTemplate template) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public boolean updateOperationState(Volume vol, Event event) throws NoTransitionException { public boolean updateOperationState(Volume vol, Event event) throws NoTransitionException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
} }

View File

@ -27,16 +27,17 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.StoragePool; import com.cloud.storage.StoragePool;
public interface PrimaryDataStoreManager { public interface PrimaryDataStoreManager {
PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId, PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map<String, String> params);
String URI,
String storageType, void deleteStoragePool(long poolId);
String poolName,
String storageProviderName, void enableStoragePool(long poolId);
Map<String, String> params);
void deleteStoragePool(long poolId); void disableStoragePool(long poolId);
void enableStoragePool(long poolId);
void disableStoragePool(long poolId); Map<String, List<String>> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor);
Map<String, List<String>> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor);
Map<String, List<String>> getSupportedSecondaryStorages(long zoneId); Map<String, List<String>> getSupportedSecondaryStorages(long zoneId);
PrimaryDataStore getDataStore(String id);
PrimaryDataStore getDataStore(String id);
} }

View File

@ -43,61 +43,61 @@ import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
public class PrimaryDataStoreManagerImpl implements PrimaryDataStoreManager { public class PrimaryDataStoreManagerImpl implements PrimaryDataStoreManager {
@Inject(adapter = StorageProvider.class) @Inject(adapter = StorageProvider.class)
protected Adapters<StorageProvider> _storageProviders; protected Adapters<StorageProvider> _storageProviders;
@Inject @Inject
protected DataCenterDao _dcDao; protected DataCenterDao _dcDao;
@Inject @Inject
protected HostPodDao _podDao; protected HostPodDao _podDao;
@Inject @Inject
protected ClusterDao _clusterDao; protected ClusterDao _clusterDao;
@Inject @Inject
protected StoragePoolDao _storagePoolDao; protected StoragePoolDao _storagePoolDao;
public void deleteStoragePool(long poolId) { public void deleteStoragePool(long poolId) {
StoragePool spool = _storagePoolDao.findById(poolId); StoragePool spool = _storagePoolDao.findById(poolId);
StorageProvider sp = findStorageProvider(spool.getStorageProvider()); StorageProvider sp = findStorageProvider(spool.getStorageProvider());
DataStore ds = sp.getDataStore(spool); DataStore ds = sp.getDataStore(spool);
DataStoreLifeCycle dslc = ds.getLifeCycle(); DataStoreLifeCycle dslc = ds.getLifeCycle();
dslc.delete(); dslc.delete();
} }
public void enableStoragePool(long poolId) { public void enableStoragePool(long poolId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void disableStoragePool(long poolId) { public void disableStoragePool(long poolId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public Map<String, List<String>> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor) { public Map<String, List<String>> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public Map<String, List<String>> getSupportedSecondaryStorages(long zoneId) { public Map<String, List<String>> getSupportedSecondaryStorages(long zoneId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
protected StorageProvider findStorageProvider(String name) { protected StorageProvider findStorageProvider(String name) {
Iterator<StorageProvider> spIter = _storageProviders.iterator(); Iterator<StorageProvider> spIter = _storageProviders.iterator();
StorageProvider sp = null; StorageProvider sp = null;
while (spIter.hasNext()) { while (spIter.hasNext()) {
sp = spIter.next(); sp = spIter.next();
if (sp.getProviderName().equalsIgnoreCase(name)) { if (sp.getProviderName().equalsIgnoreCase(name)) {
break; break;
} }
} }
return sp; return sp;
} }
public StoragePool addStoragePool(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map<String, String> params) { public StoragePool addStoragePool(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map<String, String> params) {
StoragePoolVO spool = new StoragePoolVO(); StoragePoolVO spool = new StoragePoolVO();
long poolId = _storagePoolDao.getNextInSequence(Long.class, "id"); long poolId = _storagePoolDao.getNextInSequence(Long.class, "id");
spool.setId(poolId); spool.setId(poolId);
spool.setDataCenterId(zoneId); spool.setDataCenterId(zoneId);
spool.setPodId(podId); spool.setPodId(podId);
@ -109,14 +109,14 @@ public class PrimaryDataStoreManagerImpl implements PrimaryDataStoreManager {
spool = _storagePoolDao.persist(spool); spool = _storagePoolDao.persist(spool);
StorageProvider sp = findStorageProvider(storageProviderName); StorageProvider sp = findStorageProvider(storageProviderName);
DataStore ds = sp.addDataStore((StoragePool)spool, URI, params); DataStore ds = sp.addDataStore((StoragePool) spool, URI, params);
DataStoreLifeCycle dslc = ds.getLifeCycle(); DataStoreLifeCycle dslc = ds.getLifeCycle();
try { try {
dslc.add(); dslc.add();
} catch (CloudRuntimeException e) { } catch (CloudRuntimeException e) {
_storagePoolDao.remove(spool.getId()); _storagePoolDao.remove(spool.getId());
throw e; throw e;
} }
spool.setPath(ds.getURI()); spool.setPath(ds.getURI());
@ -125,18 +125,18 @@ public class PrimaryDataStoreManagerImpl implements PrimaryDataStoreManager {
_storagePoolDao.update(spool.getId(), spool); _storagePoolDao.update(spool.getId(), spool);
spool = _storagePoolDao.findById(spool.getId()); spool = _storagePoolDao.findById(spool.getId());
return spool; return spool;
} }
@Override @Override
public PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map<String, String> params) { public PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map<String, String> params) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public PrimaryDataStore getDataStore(String id) { public PrimaryDataStore getDataStore(String id) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -27,8 +27,11 @@ import com.cloud.storage.Volume;
import com.cloud.template.VirtualMachineTemplate; import com.cloud.template.VirtualMachineTemplate;
public interface SecondaryStorageManager { public interface SecondaryStorageManager {
DataStore getStore(Volume volume); DataStore getStore(Volume volume);
DataStore getImageStore(DataStore destStore);
List<DataStore> getImageStores(long zoneId); DataStore getImageStore(DataStore destStore);
DataStore getStore(Snapshot snapshot);
List<DataStore> getImageStores(long zoneId);
DataStore getStore(Snapshot snapshot);
} }

View File

@ -27,29 +27,29 @@ import com.cloud.storage.Volume;
import com.cloud.storage.dao.VMTemplateZoneDao; import com.cloud.storage.dao.VMTemplateZoneDao;
public class SecondaryStorageManagerImpl implements SecondaryStorageManager { public class SecondaryStorageManagerImpl implements SecondaryStorageManager {
public DataStore getStore(Volume volume) { public DataStore getStore(Volume volume) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataStore getImageStore(DataStore destStore) { public DataStore getImageStore(DataStore destStore) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public List<DataStore> getImageStores() { public List<DataStore> getImageStores() {
return null; return null;
} }
public DataStore getStore(Snapshot snapshot) { public DataStore getStore(Snapshot snapshot) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public List<DataStore> getImageStores(long zoneId) { public List<DataStore> getImageStores(long zoneId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -39,91 +39,92 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.StoragePool; import com.cloud.storage.StoragePool;
public class DefaultNfsSecondaryStorageProvider implements StorageProvider { public class DefaultNfsSecondaryStorageProvider implements StorageProvider {
private String _name = DefaultPrimaryStorageProvider.class.toString(); private String _name = DefaultPrimaryStorageProvider.class.toString();
protected Map<HypervisorType, Map<String, DataStoreConfigurator>> _supportedProtocols; protected Map<HypervisorType, Map<String, DataStoreConfigurator>> _supportedProtocols;
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
Map<String, DataStoreConfigurator> dscs = new HashMap<String, DataStoreConfigurator>();
DataStoreConfigurator nfsdc = null;
dscs.put(nfsdc.getProtocol(), nfsdc);
_supportedProtocols.put(HypervisorType.XenServer, dscs); public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_supportedProtocols.put(HypervisorType.KVM, dscs); Map<String, DataStoreConfigurator> dscs = new HashMap<String, DataStoreConfigurator>();
_supportedProtocols.put(HypervisorType.VMware, dscs); DataStoreConfigurator nfsdc = null;
_supportedProtocols.put(HypervisorType.Ovm, dscs); dscs.put(nfsdc.getProtocol(), nfsdc);
return true;
}
public String getName() { _supportedProtocols.put(HypervisorType.XenServer, dscs);
// TODO Auto-generated method stub _supportedProtocols.put(HypervisorType.KVM, dscs);
return null; _supportedProtocols.put(HypervisorType.VMware, dscs);
} _supportedProtocols.put(HypervisorType.Ovm, dscs);
return true;
}
public boolean start() { public String getName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return null;
} }
public boolean stop() { public boolean start() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public List<HypervisorType> supportedHypervisors() { public boolean stop() {
List<HypervisorType> hypervisors = new ArrayList<HypervisorType>(); // TODO Auto-generated method stub
Set<HypervisorType> hyps = _supportedProtocols.keySet(); return false;
}
for (HypervisorType hy : hyps) { public List<HypervisorType> supportedHypervisors() {
hypervisors.add(hy); List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
} Set<HypervisorType> hyps = _supportedProtocols.keySet();
return hypervisors; for (HypervisorType hy : hyps) {
} hypervisors.add(hy);
}
public String getProviderName() { return hypervisors;
// TODO Auto-generated method stub }
return null;
}
public void configure(Map<String, String> storeProviderInfo) { public String getProviderName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null;
}
} public void configure(Map<String, String> storeProviderInfo) {
// TODO Auto-generated method stub
public DataStore addDataStore(StoragePool sp, String url, Map<String, String> params) { }
URI uri;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
throw new InvalidParameterValueException("invalide url" + url);
}
String protocol = uri.getScheme(); public DataStore addDataStore(StoragePool sp, String url, Map<String, String> params) {
if (protocol == null) { URI uri;
throw new InvalidParameterValueException("the protocol can't be null"); try {
} uri = new URI(url);
} catch (URISyntaxException e) {
throw new InvalidParameterValueException("invalide url" + url);
}
DataStoreConfigurator dscf = _supportedProtocols.get(HypervisorType.XenServer).get(protocol); String protocol = uri.getScheme();
Map<String, String> configs = dscf.getConfigs(uri, params); if (protocol == null) {
dscf.validate(configs); throw new InvalidParameterValueException("the protocol can't be null");
DataStore ds = dscf.getDataStore(sp); }
return ds;
}
public DataStore getDataStore(StoragePool pool) { DataStoreConfigurator dscf = _supportedProtocols.get(HypervisorType.XenServer).get(protocol);
// TODO Auto-generated method stub Map<String, String> configs = dscf.getConfigs(uri, params);
return null; dscf.validate(configs);
} DataStore ds = dscf.getDataStore(sp);
return ds;
}
public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() { public DataStore getDataStore(StoragePool pool) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public List<StoreType> supportedStoreTypes() { public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
List<StoreType> types = new ArrayList<StoreType>(); // TODO Auto-generated method stub
types.add(StoreType.Image); return null;
types.add(StoreType.Backup); }
return types;
} public List<StoreType> supportedStoreTypes() {
List<StoreType> types = new ArrayList<StoreType>();
types.add(StoreType.Image);
types.add(StoreType.Backup);
return types;
}
} }

View File

@ -30,113 +30,112 @@ import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.StoragePoolDao;
public class DefaultPrimaryStorageProvider implements StorageProvider { public class DefaultPrimaryStorageProvider implements StorageProvider {
private String _name = DefaultPrimaryStorageProvider.class.toString(); private String _name = DefaultPrimaryStorageProvider.class.toString();
static Map<HypervisorType, Map<String, DataStoreConfigurator>> _supportedProtocols; static Map<HypervisorType, Map<String, DataStoreConfigurator>> _supportedProtocols;
@Inject @Inject
protected ClusterDao _clusterDao; protected ClusterDao _clusterDao;
public List<HypervisorType> supportedHypervisors() { public List<HypervisorType> supportedHypervisors() {
List<HypervisorType> hypervisors = new ArrayList<HypervisorType>(); List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
hypervisors.add(Hypervisor.HypervisorType.XenServer); hypervisors.add(Hypervisor.HypervisorType.XenServer);
return hypervisors; return hypervisors;
} }
public DefaultPrimaryStorageProvider() { public DefaultPrimaryStorageProvider() {
Map<String, DataStoreConfigurator> dscs = new HashMap<String, DataStoreConfigurator>(); Map<String, DataStoreConfigurator> dscs = new HashMap<String, DataStoreConfigurator>();
DataStoreConfigurator nfsdc = null; DataStoreConfigurator nfsdc = null;
dscs.put(nfsdc.getProtocol(), nfsdc); dscs.put(nfsdc.getProtocol(), nfsdc);
_supportedProtocols.put(HypervisorType.XenServer, dscs); _supportedProtocols.put(HypervisorType.XenServer, dscs);
} }
public List<StoreType> supportedStoreType() { public List<StoreType> supportedStoreType() {
List<StoreType> type = new ArrayList<StoreType>(); List<StoreType> type = new ArrayList<StoreType>();
type.add(StoreType.Primary); type.add(StoreType.Primary);
return type; return type;
} }
public void configure(Map<String, String> storeProviderInfo) { public void configure(Map<String, String> storeProviderInfo) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public Map<HypervisorType, Map<String,DataStoreConfigurator>> getDataStoreConfigs() { public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
return _supportedProtocols; return _supportedProtocols;
} }
public String getProviderName() { public String getProviderName() {
return _name; return _name;
} }
public DataStore createDataStore(HypervisorType hypervisor, public DataStore createDataStore(HypervisorType hypervisor, DataStoreConfigurator dsc) {
DataStoreConfigurator dsc) { // TODO Auto-generated method stub
// TODO Auto-generated method stub return null;
return null; }
}
public DataStore getDataStore(StoragePool pool) { public DataStore getDataStore(StoragePool pool) {
ClusterVO clu = _clusterDao.findById(pool.getClusterId()); ClusterVO clu = _clusterDao.findById(pool.getClusterId());
HypervisorType hy = clu.getHypervisorType(); HypervisorType hy = clu.getHypervisorType();
Map<String, DataStoreConfigurator> dscs = _supportedProtocols.get(hy); Map<String, DataStoreConfigurator> dscs = _supportedProtocols.get(hy);
DataStoreConfigurator dsc = dscs.get(pool.getPoolType().toString()); DataStoreConfigurator dsc = dscs.get(pool.getPoolType().toString());
return dsc.getDataStore(pool); return dsc.getDataStore(pool);
} }
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public String getName() { public String getName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public boolean start() { public boolean start() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public boolean stop() { public boolean stop() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public DataStore addDataStore(StoragePool spool, String url, Map<String, String> params) { public DataStore addDataStore(StoragePool spool, String url, Map<String, String> params) {
URI uri; URI uri;
try { try {
uri = new URI(url); uri = new URI(url);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new InvalidParameterValueException("invalide url" + url); throw new InvalidParameterValueException("invalide url" + url);
} }
String protocol = uri.getScheme(); String protocol = uri.getScheme();
if (protocol == null) { if (protocol == null) {
throw new InvalidParameterValueException("the protocol can't be null"); throw new InvalidParameterValueException("the protocol can't be null");
} }
ClusterVO cluster = _clusterDao.findById(spool.getClusterId()); ClusterVO cluster = _clusterDao.findById(spool.getClusterId());
Map<String, DataStoreConfigurator> dscs = _supportedProtocols.get(cluster.getHypervisorType()); Map<String, DataStoreConfigurator> dscs = _supportedProtocols.get(cluster.getHypervisorType());
if (dscs.isEmpty()) { if (dscs.isEmpty()) {
throw new InvalidParameterValueException("Doesn't support this hypervisor"); throw new InvalidParameterValueException("Doesn't support this hypervisor");
} }
DataStoreConfigurator dsc = dscs.get(protocol); DataStoreConfigurator dsc = dscs.get(protocol);
if (dsc == null) { if (dsc == null) {
throw new InvalidParameterValueException("Doesn't support this protocol"); throw new InvalidParameterValueException("Doesn't support this protocol");
} }
Map<String, String> configs = dsc.getConfigs(uri, params); Map<String, String> configs = dsc.getConfigs(uri, params);
dsc.validate(configs); dsc.validate(configs);
DataStore ds = dsc.getDataStore(spool); DataStore ds = dsc.getDataStore(spool);
return ds; return ds;
} }
public List<StoreType> supportedStoreTypes() { public List<StoreType> supportedStoreTypes() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -33,59 +33,59 @@ import com.cloud.storage.StoragePool;
public class HttpImageStoreProvider implements StorageProvider { public class HttpImageStoreProvider implements StorageProvider {
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public String getName() { public String getName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public boolean start() { public boolean start() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public boolean stop() { public boolean stop() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public List<HypervisorType> supportedHypervisors() { public List<HypervisorType> supportedHypervisors() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public String getProviderName() { public String getProviderName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public List<StoreType> supportedStoreTypes() { public List<StoreType> supportedStoreTypes() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public void configure(Map<String, String> storeProviderInfo) { public void configure(Map<String, String> storeProviderInfo) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) { public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataStore getDataStore(StoragePool pool) { public DataStore getDataStore(StoragePool pool) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() { public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -33,59 +33,59 @@ import com.cloud.storage.StoragePool;
public class S3SecondaryStorageProvider implements StorageProvider { public class S3SecondaryStorageProvider implements StorageProvider {
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public String getName() { public String getName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public boolean start() { public boolean start() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public boolean stop() { public boolean stop() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public List<HypervisorType> supportedHypervisors() { public List<HypervisorType> supportedHypervisors() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public String getProviderName() { public String getProviderName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public List<StoreType> supportedStoreTypes() { public List<StoreType> supportedStoreTypes() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public void configure(Map<String, String> storeProviderInfo) { public void configure(Map<String, String> storeProviderInfo) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) { public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataStore getDataStore(StoragePool pool) { public DataStore getDataStore(StoragePool pool) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() { public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -33,59 +33,59 @@ import com.cloud.storage.StoragePool;
public class SwiftSecondaryStorageProvider implements StorageProvider { public class SwiftSecondaryStorageProvider implements StorageProvider {
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public String getName() { public String getName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public boolean start() { public boolean start() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public boolean stop() { public boolean stop() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
public List<HypervisorType> supportedHypervisors() { public List<HypervisorType> supportedHypervisors() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public String getProviderName() { public String getProviderName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public List<StoreType> supportedStoreTypes() { public List<StoreType> supportedStoreTypes() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public void configure(Map<String, String> storeProviderInfo) { public void configure(Map<String, String> storeProviderInfo) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) { public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public DataStore getDataStore(StoragePool pool) { public DataStore getDataStore(StoragePool pool) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() { public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -19,6 +19,7 @@
package org.apache.cloudstack.storage.snapshot; package org.apache.cloudstack.storage.snapshot;
public interface SnapshotService { public interface SnapshotService {
long takeSnapshot(long volumeId); long takeSnapshot(long volumeId);
boolean deleteSnapshot(long snapshotId);
boolean deleteSnapshot(long snapshotId);
} }

View File

@ -47,11 +47,11 @@ import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
public class DefaultTemplateStratey implements TemplateStrategy { public class DefaultTemplateStratey implements TemplateStrategy {
private static final Logger s_logger = Logger.getLogger(DefaultTemplateStratey.class); private static final Logger s_logger = Logger.getLogger(DefaultTemplateStratey.class);
protected DataStore _ds; protected DataStore _ds;
protected DataStoreDriver _driver; protected DataStoreDriver _driver;
protected int _primaryStorageDownloadWait; protected int _primaryStorageDownloadWait;
protected int _installTries = 3; protected int _installTries = 3;
protected int _storagePoolMaxWaitSeconds = 3600; protected int _storagePoolMaxWaitSeconds = 3600;
@Inject @Inject
VMTemplatePoolDao _templatePoolDao; VMTemplatePoolDao _templatePoolDao;
@ -61,131 +61,131 @@ public class DefaultTemplateStratey implements TemplateStrategy {
ImageManager _templateMgr; ImageManager _templateMgr;
public DefaultTemplateStratey(DataStore ds) { public DefaultTemplateStratey(DataStore ds) {
_ds = ds; _ds = ds;
} }
public TemplateProfile get(long templateId) { public TemplateProfile get(long templateId) {
return _templateMgr.getProfile(templateId); return _templateMgr.getProfile(templateId);
} }
public TemplateProfile install(TemplateProfile tp) { public TemplateProfile install(TemplateProfile tp) {
DataStoreEndPointSelector dseps = _ds.getEndPointSelector(); DataStoreEndPointSelector dseps = _ds.getEndPointSelector();
List<DataStoreEndPoint> eps = dseps.getEndPoints(StorageEvent.DownloadTemplateToPrimary); List<DataStoreEndPoint> eps = dseps.getEndPoints(StorageEvent.DownloadTemplateToPrimary);
int tries = Math.min(eps.size(), _installTries); int tries = Math.min(eps.size(), _installTries);
VMTemplateStoragePoolVO templateStoragePoolRef = _templatePoolDao.acquireInLockTable(tp.getTemplatePoolRefId(), _storagePoolMaxWaitSeconds); VMTemplateStoragePoolVO templateStoragePoolRef = _templatePoolDao.acquireInLockTable(tp.getTemplatePoolRefId(), _storagePoolMaxWaitSeconds);
if (templateStoragePoolRef == null) { if (templateStoragePoolRef == null) {
throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + tp.getTemplatePoolRefId()); throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + tp.getTemplatePoolRefId());
} }
try { try {
for (int retry = 0; retry < tries; retry++) { for (int retry = 0; retry < tries; retry++) {
Collections.shuffle(eps); Collections.shuffle(eps);
DataStoreEndPoint ep = eps.get(0); DataStoreEndPoint ep = eps.get(0);
try { try {
tp = _driver.install(tp, ep); tp = _driver.install(tp, ep);
templateStoragePoolRef.setDownloadPercent(100); templateStoragePoolRef.setDownloadPercent(100);
templateStoragePoolRef.setDownloadState(Status.DOWNLOADED); templateStoragePoolRef.setDownloadState(Status.DOWNLOADED);
templateStoragePoolRef.setLocalDownloadPath(tp.getLocalPath()); templateStoragePoolRef.setLocalDownloadPath(tp.getLocalPath());
templateStoragePoolRef.setInstallPath(tp.getLocalPath()); templateStoragePoolRef.setInstallPath(tp.getLocalPath());
templateStoragePoolRef.setTemplateSize(tp.getSize()); templateStoragePoolRef.setTemplateSize(tp.getSize());
_templatePoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef); _templatePoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Template " + tp.getTemplateId() + " is installed via " + ep.getHostId()); s_logger.debug("Template " + tp.getTemplateId() + " is installed via " + ep.getHostId());
} }
return get(tp.getTemplateId()); return get(tp.getTemplateId());
} catch (CloudRuntimeException e) { } catch (CloudRuntimeException e) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Template " + tp.getTemplateId() + " download to pool " + _ds.getId() + " failed due to " + e.toString()); s_logger.debug("Template " + tp.getTemplateId() + " download to pool " + _ds.getId() + " failed due to " + e.toString());
} }
} }
} }
} finally { } finally {
_templatePoolDao.releaseFromLockTable(tp.getTemplatePoolRefId()); _templatePoolDao.releaseFromLockTable(tp.getTemplatePoolRefId());
} }
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Template " + tp.getTemplateId() + " is not found on and can not be downloaded to pool " + _ds.getId()); s_logger.debug("Template " + tp.getTemplateId() + " is not found on and can not be downloaded to pool " + _ds.getId());
} }
return null; return null;
} }
public TemplateProfile register(TemplateProfile tp) { public TemplateProfile register(TemplateProfile tp) {
VMTemplateHostVO vmTemplateHost = _templateImageStoreDao.findByHostTemplate(_ds.getId(), tp.getTemplateId()); VMTemplateHostVO vmTemplateHost = _templateImageStoreDao.findByHostTemplate(_ds.getId(), tp.getTemplateId());
if (vmTemplateHost == null) { if (vmTemplateHost == null) {
vmTemplateHost = new VMTemplateHostVO(_ds.getId(), tp.getTemplateId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null, "jobid0000", null, tp.getUrl()); vmTemplateHost = new VMTemplateHostVO(_ds.getId(), tp.getTemplateId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null, "jobid0000", null, tp.getUrl());
_templateImageStoreDao.persist(vmTemplateHost); _templateImageStoreDao.persist(vmTemplateHost);
} }
DataStoreEndPointSelector dseps = _ds.getEndPointSelector(); DataStoreEndPointSelector dseps = _ds.getEndPointSelector();
List<DataStoreEndPoint> eps = dseps.getEndPoints(StorageEvent.RegisterTemplate); List<DataStoreEndPoint> eps = dseps.getEndPoints(StorageEvent.RegisterTemplate);
Collections.shuffle(eps); Collections.shuffle(eps);
DataStoreEndPoint ep = eps.get(0); DataStoreEndPoint ep = eps.get(0);
_driver.register(tp, ep); _driver.register(tp, ep);
return null; return null;
} }
protected boolean checkHypervisor(HypervisorType hypervisor) { protected boolean checkHypervisor(HypervisorType hypervisor) {
StorageProvider sp = _ds.getProvider(); StorageProvider sp = _ds.getProvider();
List<HypervisorType> spHys = sp.supportedHypervisors(); List<HypervisorType> spHys = sp.supportedHypervisors();
boolean checkHypervisor = false; boolean checkHypervisor = false;
for (HypervisorType hy : spHys) { for (HypervisorType hy : spHys) {
if (hy == hypervisor) { if (hy == hypervisor) {
checkHypervisor = true; checkHypervisor = true;
} }
} }
return checkHypervisor; return checkHypervisor;
} }
protected boolean checkFormat(String url, String format) { protected boolean checkFormat(String url, String format) {
if ((!url.toLowerCase().endsWith("vhd")) && (!url.toLowerCase().endsWith("vhd.zip")) && (!url.toLowerCase().endsWith("vhd.bz2")) && (!url.toLowerCase().endsWith("vhd.gz")) if ((!url.toLowerCase().endsWith("vhd")) && (!url.toLowerCase().endsWith("vhd.zip")) && (!url.toLowerCase().endsWith("vhd.bz2")) && (!url.toLowerCase().endsWith("vhd.gz"))
&& (!url.toLowerCase().endsWith("qcow2")) && (!url.toLowerCase().endsWith("qcow2.zip")) && (!url.toLowerCase().endsWith("qcow2.bz2")) && (!url.toLowerCase().endsWith("qcow2.gz")) && (!url.toLowerCase().endsWith("qcow2")) && (!url.toLowerCase().endsWith("qcow2.zip")) && (!url.toLowerCase().endsWith("qcow2.bz2")) && (!url.toLowerCase().endsWith("qcow2.gz"))
&& (!url.toLowerCase().endsWith("ova")) && (!url.toLowerCase().endsWith("ova.zip")) && (!url.toLowerCase().endsWith("ova.bz2")) && (!url.toLowerCase().endsWith("ova.gz")) && (!url.toLowerCase().endsWith("ova")) && (!url.toLowerCase().endsWith("ova.zip")) && (!url.toLowerCase().endsWith("ova.bz2")) && (!url.toLowerCase().endsWith("ova.gz"))
&& (!url.toLowerCase().endsWith("img")) && (!url.toLowerCase().endsWith("raw"))) { && (!url.toLowerCase().endsWith("img")) && (!url.toLowerCase().endsWith("raw"))) {
throw new InvalidParameterValueException("Please specify a valid " + format.toLowerCase()); throw new InvalidParameterValueException("Please specify a valid " + format.toLowerCase());
} }
if ((format.equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith("vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith( if ((format.equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith("vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith(
"vhd.gz"))) "vhd.gz")))
|| (format.equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url || (format.equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url
.toLowerCase().endsWith("qcow2.gz"))) .toLowerCase().endsWith("qcow2.gz")))
|| (format.equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase() || (format.equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase()
.endsWith("ova.gz"))) || (format.equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase().endsWith("raw")))) { .endsWith("ova.gz"))) || (format.equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase().endsWith("raw")))) {
throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + format.toLowerCase()); throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + format.toLowerCase());
} }
return true; return true;
} }
public boolean canRegister(long templateId) { public boolean canRegister(long templateId) {
TemplateProfile tp = get(templateId); TemplateProfile tp = get(templateId);
if (!checkHypervisor(tp.getHypervisorType())) { if (!checkHypervisor(tp.getHypervisorType())) {
return false; return false;
} }
if (!checkFormat(tp.getUrl(), tp.getFormat().toString())) { if (!checkFormat(tp.getUrl(), tp.getFormat().toString())) {
return false; return false;
} }
return true; return true;
} }
public int getDownloadWait() { public int getDownloadWait() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }
public long getMaxTemplateSizeInBytes() { public long getMaxTemplateSizeInBytes() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }
public Proxy getHttpProxy() { public Proxy getHttpProxy() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -16,75 +16,77 @@ import org.apache.cloudstack.storage.volume.VolumeManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.storage.Volume; import com.cloud.storage.Volume;
import com.cloud.storage.VolumeVO; import com.cloud.storage.VolumeVO;
import com.cloud.utils.component.Inject; import com.cloud.utils.component.Inject;
public class DefaultVolumeStrategy implements VolumeStrategy { public class DefaultVolumeStrategy implements VolumeStrategy {
private static final Logger s_logger = Logger.getLogger(DefaultVolumeStrategy.class); private static final Logger s_logger = Logger.getLogger(DefaultVolumeStrategy.class);
protected DataStore _ds; protected DataStore _ds;
protected DataStoreDriver _driver; protected DataStoreDriver _driver;
@Inject @Inject
VolumeManager _volumeMgr; VolumeManager _volumeMgr;
public VolumeProfile get(long volumeId) { public VolumeProfile get(long volumeId) {
return _volumeMgr.getProfile(volumeId); return _volumeMgr.getProfile(volumeId);
} }
public DefaultVolumeStrategy(DataStore ds) { public DefaultVolumeStrategy(DataStore ds) {
_ds = ds; _ds = ds;
} }
public Volume createVolume(Volume vol) {
// TODO Auto-generated method stub
return null;
}
public Volume createDataVolume(Volume vol) {
// TODO Auto-generated method stub
return null;
}
public Volume copyVolumeFromBackup(VolumeProfile srcVol, Volume destVol) {
// TODO Auto-generated method stub
return null;
}
public Volume createVolumeFromSnapshot(SnapshotProfile snapshot, Volume vol) {
// TODO Auto-generated method stub
return null;
}
public Volume createVolumeFromTemplate(TemplateProfile template, Volume vol) {
// TODO Auto-generated method stub
return null;
}
public Volume migrateVolume(Volume srcVol, Volume destVol, DataStore destStore) {
// TODO Auto-generated method stub
return null;
}
public Volume createVolumeFromBaseTemplate(Volume volume, TemplateProfile tp) { public Volume createVolume(Volume vol) {
DataStoreEndPointSelector dsep = _ds.getEndPointSelector(); // TODO Auto-generated method stub
List<DataStoreEndPoint> dseps = dsep.getEndPoints(StorageEvent.CreateVolumeFromTemplate); return null;
DataStoreEndPoint dp = dseps.get(0); }
VolumeProfile vp = _driver.createVolumeFromTemplate(get(volume.getId()), tp, dp); public Volume createDataVolume(Volume vol) {
// TODO Auto-generated method stub
return null;
}
VolumeVO vlvo = _volumeMgr.getVolume(volume.getId()); public Volume copyVolumeFromBackup(VolumeProfile srcVol, Volume destVol) {
// TODO Auto-generated method stub
return null;
}
vlvo.setFolder(_ds.getPath()); public Volume createVolumeFromSnapshot(SnapshotProfile snapshot, Volume vol) {
vlvo.setPath(vp.getPath()); // TODO Auto-generated method stub
vlvo.setSize(vp.getSize()); return null;
vlvo.setPoolType(_ds.getPoolType()); }
vlvo.setPoolId(_ds.getId());
vlvo.setPodId(_ds.getPodId());
return _volumeMgr.updateVolume(vlvo); public Volume createVolumeFromTemplate(TemplateProfile template, Volume vol) {
} // TODO Auto-generated method stub
public boolean deleteVolume(Volume vol) { return null;
// TODO Auto-generated method stub }
return false;
}
public Volume migrateVolume(Volume srcVol, Volume destVol, DataStore destStore) {
// TODO Auto-generated method stub
return null;
}
public Volume createVolumeFromBaseTemplate(Volume volume, TemplateProfile tp) {
DataStoreEndPointSelector dsep = _ds.getEndPointSelector();
List<DataStoreEndPoint> dseps = dsep.getEndPoints(StorageEvent.CreateVolumeFromTemplate);
DataStoreEndPoint dp = dseps.get(0);
VolumeProfile vp = _driver.createVolumeFromTemplate(get(volume.getId()), tp, dp);
VolumeVO vlvo = _volumeMgr.getVolume(volume.getId());
vlvo.setFolder(_ds.getPath());
vlvo.setPath(vp.getPath());
vlvo.setSize(vp.getSize());
vlvo.setPoolType(_ds.getPoolType());
vlvo.setPoolId(_ds.getId());
vlvo.setPodId(_ds.getPodId());
return _volumeMgr.updateVolume(vlvo);
}
public boolean deleteVolume(Volume vol) {
// TODO Auto-generated method stub
return false;
}
} }

View File

@ -4,8 +4,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.BackupStrategy;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
public class XenBackupStrategy implements BackupStrategy { public class XenBackupStrategy implements BackupStrategy {
protected DataStore _ds; protected DataStore _ds;
public XenBackupStrategy(DataStore ds) {
_ds = ds; public XenBackupStrategy(DataStore ds) {
} _ds = ds;
}
} }

View File

@ -4,8 +4,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy;
public class XenSnapshotStrategy implements SnapshotStrategy { public class XenSnapshotStrategy implements SnapshotStrategy {
protected DataStore _ds; protected DataStore _ds;
public XenSnapshotStrategy(DataStore ds) {
_ds = ds; public XenSnapshotStrategy(DataStore ds) {
} _ds = ds;
}
} }

View File

@ -3,7 +3,7 @@ package org.apache.cloudstack.storage.to;
import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo; import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
public class ImageDataStoreTO { public class ImageDataStoreTO {
public ImageDataStoreTO(ImageDataStoreInfo dataStore) { public ImageDataStoreTO(ImageDataStoreInfo dataStore) {
} }
} }

View File

@ -21,7 +21,7 @@ package org.apache.cloudstack.storage.to;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo; import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
public class ImageOnPrimayDataStoreTO { public class ImageOnPrimayDataStoreTO {
public ImageOnPrimayDataStoreTO(TemplateOnPrimaryDataStoreInfo template) { public ImageOnPrimayDataStoreTO(TemplateOnPrimaryDataStoreInfo template) {
} }
} }

Some files were not shown because too many files have changed in this diff Show More