fix data motion

This commit is contained in:
Edison Su 2013-05-01 14:00:53 -07:00
parent 3c6b7c2a01
commit 52799f46a4
3 changed files with 53 additions and 20 deletions

View File

@ -26,6 +26,5 @@ public interface SnapshotInfo extends DataObject, Snapshot {
public VolumeInfo getBaseVolume();
public void addPayload(Object data);
Long getDataCenterId();
public Long getPrevSnapshotId();
ObjectInDataStoreStateMachine.State getStatus();
}

View File

@ -29,6 +29,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
@ -136,6 +137,21 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
// TODO Auto-generated method stub
return true;
}
protected boolean needCacheStorage(DataObject srcData, DataObject destData) {
DataTO srcTO = srcData.getTO();
DataTO destTO = destData.getTO();
DataStoreTO srcStoreTO = srcTO.getDataStore();
DataStoreTO destStoreTO = destTO.getDataStore();
if (srcStoreTO instanceof NfsTO || srcStoreTO.getRole() == DataStoreRole.ImageCache) {
return false;
}
if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) {
return false;
}
return true;
}
@DB
protected Answer copyVolumeFromImage(DataObject srcData, DataObject destData) {
@ -143,7 +159,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
int _copyvolumewait = NumbersUtil.parseInt(value,
Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
if (srcData.getDataStore().getRole() != DataStoreRole.ImageCache && destData.getDataStore().getRole() != DataStoreRole.ImageCache) {
if (needCacheStorage(srcData, destData)) {
//need to copy it to image cache store
DataObject cacheData = cacheMgr.createCacheObject(srcData, destData.getDataStore().getScope());
CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _copyvolumewait);
@ -162,7 +178,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
private Answer copyTemplate(DataObject srcData, DataObject destData) {
String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
if (srcData.getDataStore().getRole() != DataStoreRole.ImageCache && destData.getDataStore().getRole() != DataStoreRole.ImageCache) {
if (needCacheStorage(srcData, destData)) {
//need to copy it to image cache store
DataObject cacheData = cacheMgr.createCacheObject(srcData, destData.getDataStore().getScope());
CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _primaryStorageDownloadWait);
@ -330,7 +346,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
Integer.parseInt(Config.CreatePrivateTemplateFromVolumeWait
.getDefaultValue()));
if (srcData.getDataStore().getRole() != DataStoreRole.ImageCache && destData.getDataStore().getRole() != DataStoreRole.ImageCache) {
if (needCacheStorage(srcData, destData)) {
//need to copy it to image cache store
DataObject cacheData = cacheMgr.createCacheObject(srcData, destData.getDataStore().getScope());
CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _createprivatetemplatefromvolumewait);

View File

@ -26,6 +26,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
@ -45,6 +46,9 @@ import com.cloud.storage.SnapshotVO;
import com.cloud.storage.dao.SnapshotDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.fsm.NoTransitionException;
@ -59,9 +63,11 @@ public class SnapshotObject implements SnapshotInfo {
@Inject protected VolumeDataFactory volFactory;
@Inject protected SnapshotStateMachineManager stateMachineMgr;
@Inject
SnapshotDataFactory snapshotFactory;
@Inject
ObjectInDataStoreManager ojbectInStoreMgr;
@Inject
SnapshotDataStoreDao snapshotStore;
SnapshotDataStoreDao snapshotStoreDao;
public SnapshotObject() {
}
@ -83,15 +89,30 @@ public class SnapshotObject implements SnapshotInfo {
@Override
public SnapshotInfo getParent() {
SnapshotDataStoreVO snapStoreVO = this.snapshotStoreDao.findByStoreSnapshot(this.store.getRole(), this.store.getId(), this.snapshot.getId());
if (snapStoreVO == null) {
return null;
}
// TODO Auto-generated method stub
return null;
long parentId = snapStoreVO.getParentSnapshotId();
if (parentId == 0) {
return null;
}
return this.snapshotFactory.getSnapshot(parentId, store);
}
@Override
public SnapshotInfo getChild() {
// TODO Auto-generated method stub
return null;
SearchCriteriaService<SnapshotDataStoreVO, SnapshotDataStoreVO> sc = SearchCriteria2.create(SnapshotDataStoreVO.class);
sc.addAnd(sc.getEntity().getDataStoreId(), Op.EQ, this.store.getId());
sc.addAnd(sc.getEntity().getRole(), Op.EQ, this.store.getRole());
sc.addAnd(sc.getEntity().getParentSnapshotId(), Op.EQ, this.getId());
SnapshotDataStoreVO vo = sc.find();
if (vo == null) {
return null;
}
return this.snapshotFactory.getSnapshot(vo.getId(), store);
}
@Override
@ -211,37 +232,34 @@ public class SnapshotObject implements SnapshotInfo {
stateMachineMgr.processEvent(this.snapshot, event);
}
@Override
public Long getPrevSnapshotId() {
SnapshotDataStoreVO snapshotStoreVO = this.snapshotStore.findBySnapshot(this.getId(), this.getDataStore().getRole());
return snapshotStoreVO.getParentSnapshotId();
}
public SnapshotVO getSnapshotVO(){
return this.snapshot;
}
@Override
public DataTO getTO() {
// TODO Auto-generated method stub
return null;
DataTO to = this.store.getDriver().getTO(this);
if (to == null) {
return new SnapshotObjectTO(this);
}
return to;
}
@Override
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
SnapshotDataStoreVO snapshotStore = this.snapshotStore.findByStoreSnapshot(this.getDataStore().getRole(),
SnapshotDataStoreVO snapshotStore = this.snapshotStoreDao.findByStoreSnapshot(this.getDataStore().getRole(),
this.getDataStore().getId(), this.getId());
if (answer instanceof CreateObjectAnswer) {
SnapshotObjectTO snapshotTO = (SnapshotObjectTO)((CreateObjectAnswer) answer).getData();
snapshotStore.setInstallPath(snapshotTO.getPath());
this.snapshotStore.update(snapshotStore.getId(), snapshotStore);
this.snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
} else if (answer instanceof CopyCmdAnswer) {
SnapshotObjectTO snapshotTO = (SnapshotObjectTO)((CopyCmdAnswer) answer).getNewData();
snapshotStore.setInstallPath(snapshotTO.getPath());
if (snapshotTO.getParentSnapshotPath() == null) {
snapshotStore.setParentSnapshotId(0L);
}
this.snapshotStore.update(snapshotStore.getId(), snapshotStore);
this.snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
} else {
throw new CloudRuntimeException("Unknown answer: " + answer.getClass());
}