You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/05/01 23:01:12 UTC
git commit: updated refs/heads/object_store to 52799f4
Updated Branches:
refs/heads/object_store 3c6b7c2a0 -> 52799f46a
fix data motion
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/52799f46
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/52799f46
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/52799f46
Branch: refs/heads/object_store
Commit: 52799f46a485c1a9fa8ed8e76b1cabd777583e40
Parents: 3c6b7c2
Author: Edison Su <su...@gmail.com>
Authored: Wed May 1 14:00:53 2013 -0700
Committer: Edison Su <su...@gmail.com>
Committed: Wed May 1 14:00:53 2013 -0700
----------------------------------------------------------------------
.../engine/subsystem/api/storage/SnapshotInfo.java | 1 -
.../storage/motion/AncientDataMotionStrategy.java | 22 ++++++-
.../storage/snapshot/SnapshotObject.java | 50 ++++++++++-----
3 files changed, 53 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/52799f46/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java
index 2973a54..41ea5f3 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java
@@ -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();
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/52799f46/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
index 2075ef6..5b8cbf6 100644
--- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
+++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/52799f46/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
index 6fddcda..c19efb0 100644
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
@@ -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());
}