CLOUDSTACK-3110: [VMWARE]NPE while adding primary storage(scope=cluster) with Invalid hostname

Description:

    When retrieving primary datastore, handle case for non-existing datastores/hosts.
    Throw exception and handle the exception in datastore mgmt layer and pass onward
    to create storage pool API.
This commit is contained in:
Vijayendra Bhamidipati 2013-07-02 10:52:41 -07:00 committed by Chip Childers
parent 141fbc7ef7
commit 6bad34c509
2 changed files with 14 additions and 6 deletions

View File

@ -40,12 +40,16 @@ public class DataStoreManagerImpl implements DataStoreManager {
@Override
public DataStore getDataStore(long storeId, DataStoreRole role) {
if (role == DataStoreRole.Primary) {
return primaryStoreMgr.getPrimaryDataStore(storeId);
} else if (role == DataStoreRole.Image) {
return imageDataStoreMgr.getImageStore(storeId);
} else if (role == DataStoreRole.ImageCache) {
return imageDataStoreMgr.getImageStore(storeId);
try {
if (role == DataStoreRole.Primary) {
return primaryStoreMgr.getPrimaryDataStore(storeId);
} else if (role == DataStoreRole.Image) {
return imageDataStoreMgr.getImageStore(storeId);
} else if (role == DataStoreRole.ImageCache) {
return imageDataStoreMgr.getImageStore(storeId);
}
} catch (CloudRuntimeException e) {
throw e;
}
throw new CloudRuntimeException("un recognized type" + role);
}

View File

@ -36,6 +36,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.springframework.stereotype.Component;
import com.cloud.storage.StorageManager;
import com.cloud.utils.exception.CloudRuntimeException;
@Component
public class PrimaryDataStoreProviderManagerImpl implements PrimaryDataStoreProviderManager {
@ -55,6 +56,9 @@ public class PrimaryDataStoreProviderManagerImpl implements PrimaryDataStoreProv
@Override
public PrimaryDataStore getPrimaryDataStore(long dataStoreId) {
StoragePoolVO dataStoreVO = dataStoreDao.findById(dataStoreId);
if (dataStoreVO == null) {
throw new CloudRuntimeException("Unable to locate datastore with id " + dataStoreId);
}
String providerName = dataStoreVO.getStorageProviderName();
DataStoreProvider provider = providerManager.getDataStoreProvider(providerName);
PrimaryDataStoreImpl dataStore = PrimaryDataStoreImpl.createDataStore(dataStoreVO,