if object is already stored in cache store, don't download again

This commit is contained in:
Edison Su 2013-05-16 14:33:36 -07:00
parent cd318661d2
commit 389d7c1fa0
3 changed files with 13 additions and 7 deletions

View File

@ -28,7 +28,9 @@ import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService; import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
import org.apache.cloudstack.engine.subsystem.api.storage.Scope; import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
import org.apache.cloudstack.engine.subsystem.api.storage.StorageCacheManager; import org.apache.cloudstack.engine.subsystem.api.storage.StorageCacheManager;
@ -51,6 +53,8 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
List<StorageCacheAllocator> storageCacheAllocator; List<StorageCacheAllocator> storageCacheAllocator;
@Inject @Inject
DataMotionService dataMotionSvr; DataMotionService dataMotionSvr;
@Inject
ObjectInDataStoreManager objectInStoreMgr;
@Override @Override
public DataStore getCacheStorage(Scope scope) { public DataStore getCacheStorage(Scope scope) {
@ -133,6 +137,12 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
@Override @Override
public DataObject createCacheObject(DataObject data, Scope scope) { public DataObject createCacheObject(DataObject data, Scope scope) {
DataStore cacheStore = this.getCacheStorage(scope); DataStore cacheStore = this.getCacheStorage(scope);
DataObjectInStore obj = objectInStoreMgr.findObject(data, cacheStore);
if (obj != null && obj.getState() == ObjectInDataStoreStateMachine.State.Ready) {
s_logger.debug("there is already one in the cache store");
return objectInStoreMgr.get(data, cacheStore);
}
//TODO: consider multiple thread to create //TODO: consider multiple thread to create
DataObject objOnCacheStore = cacheStore.create(data); DataObject objOnCacheStore = cacheStore.create(data);

View File

@ -131,7 +131,6 @@ import com.cloud.vm.DiskProfile;
import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachine.State;
import com.trilead.ssh2.SCPClient; import com.trilead.ssh2.SCPClient;
import com.xensource.xenapi.Types.XenAPIException;
public class OvmResourceBase implements ServerResource, HypervisorResource { public class OvmResourceBase implements ServerResource, HypervisorResource {
private static final Logger s_logger = Logger.getLogger(OvmResourceBase.class); private static final Logger s_logger = Logger.getLogger(OvmResourceBase.class);

View File

@ -19,6 +19,7 @@
#Import Local Modules #Import Local Modules
import marvin import marvin
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import *
from marvin.cloudstackException import *
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import *
from marvin.remoteSSHClient import remoteSSHClient from marvin.remoteSSHClient import remoteSSHClient
from marvin.integration.lib.utils import * from marvin.integration.lib.utils import *
@ -449,12 +450,8 @@ class TestVolumes(cloudstackTestCase):
cmd.id = self.volume.id cmd.id = self.volume.id
#Proper exception should be raised; deleting attach VM is not allowed #Proper exception should be raised; deleting attach VM is not allowed
#with self.assertRaises(Exception): #with self.assertRaises(Exception):
result = self.apiClient.deleteVolume(cmd) with self.assertRaises(cloudstackAPIException):
self.assertEqual( self.apiClient.deleteVolume(cmd)
result,
None,
"Check for delete download error while volume is attached"
)
@attr(tags = ["advanced", "advancedns", "smoke"]) @attr(tags = ["advanced", "advancedns", "smoke"])
def test_05_detach_volume(self): def test_05_detach_volume(self):