CLOUDSTACK-3493: [storage ref] Attach volume to VM is failing in case of Primary-Localstorage .

Some existing scenarios for root and data volume combination was not working. These are
a. Local root + Shared data
b. Shared root + Local data

Enabled these scenarios as part of this fix
This commit is contained in:
Koushik Das 2013-07-25 17:10:20 +05:30
parent 76e283687f
commit deb701b7e0
5 changed files with 25 additions and 8 deletions

View File

@ -22,11 +22,13 @@ import com.cloud.storage.ScopeType;
public class HostScope extends AbstractScope {
private Long hostId;
private Long clusterId;
private Long zoneId;
public HostScope(Long hostId, Long zoneId) {
public HostScope(Long hostId, Long clusterId, Long zoneId) {
super();
this.hostId = hostId;
this.clusterId = clusterId;
this.zoneId = zoneId;
}
@ -40,8 +42,11 @@ public class HostScope extends AbstractScope {
return this.hostId;
}
public Long getClusterId() {
return clusterId;
}
public Long getZoneId() {
return zoneId;
}
}

View File

@ -48,9 +48,9 @@ public class ScopeTest {
@Test
public void testHostScope() {
HostScope hostScope = new HostScope(1L, 1L);
HostScope hostScope2 = new HostScope(1L, 1L);
HostScope hostScope3 = new HostScope(2L, 1L);
HostScope hostScope = new HostScope(1L, 1L, 1L);
HostScope hostScope2 = new HostScope(1L, 1L, 1L);
HostScope hostScope3 = new HostScope(2L, 1L, 1L);
Assert.assertTrue(hostScope.isSameScope(hostScope2));
Assert.assertFalse(hostScope.isSameScope(hostScope3));

View File

@ -159,7 +159,7 @@ public class PrimaryDataStoreImpl implements PrimaryDataStore {
} else if (vo.getScope() == ScopeType.HOST) {
List<StoragePoolHostVO> poolHosts = poolHostDao.listByPoolId(vo.getId());
if (poolHosts.size() > 0) {
return new HostScope(poolHosts.get(0).getHostId(), vo.getDataCenterId());
return new HostScope(poolHosts.get(0).getHostId(), vo.getClusterId(), vo.getDataCenterId());
}
s_logger.debug("can't find a local storage in pool host table: " + vo.getId());
}

View File

@ -625,7 +625,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
}
HostScope scope = new HostScope(host.getId(), host.getDataCenterId());
HostScope scope = new HostScope(host.getId(), host.getClusterId(), host.getDataCenterId());
lifeCycle.attachHost(store, scope, pInfo);
} catch (Exception e) {
s_logger.warn("Unable to setup the local storage pool for " + host, e);

View File

@ -34,7 +34,6 @@ import javax.naming.ConfigurationException;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
@ -49,6 +48,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
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.DataStoreProviderManager;
import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
@ -1589,6 +1589,18 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
}
if (storeForRootStoreScope.getScopeType() != storeForDataStoreScope.getScopeType()) {
if (storeForDataStoreScope.getScopeType() == ScopeType.CLUSTER && storeForRootStoreScope.getScopeType() == ScopeType.HOST) {
HostScope hs = (HostScope)storeForRootStoreScope;
if (storeForDataStoreScope.getScopeId().equals(hs.getClusterId())) {
return false;
}
}
if (storeForRootStoreScope.getScopeType() == ScopeType.CLUSTER && storeForDataStoreScope.getScopeType() == ScopeType.HOST) {
HostScope hs = (HostScope)storeForDataStoreScope;
if (storeForRootStoreScope.getScopeId().equals(hs.getClusterId())) {
return false;
}
}
throw new CloudRuntimeException("Can't move volume between scope: " + storeForDataStoreScope.getScopeType() + " and " + storeForRootStoreScope.getScopeType());
}