use of com.cloud.legacymodel.exceptions.StorageConflictException in project cosmic by MissionCriticalCloud.
the class DefaultHostListener method hostConnect.
@Override
public boolean hostConnect(final long hostId, final long poolId) throws StorageConflictException {
final StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
final ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
final Answer answer = agentMgr.easySend(hostId, cmd);
if (answer == null) {
throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command" + pool.getId());
}
if (!answer.getResult()) {
final String msg = "Unable to attach storage pool" + poolId + " to the host" + hostId;
alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
throw new CloudRuntimeException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails() + pool.getId());
}
assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId;
final ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
final String datastoreName = mspAnswer.getLocalDatastoreName();
final List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName);
for (final StoragePoolVO localStoragePool : localStoragePools) {
if (datastoreName.equals(localStoragePool.getPath())) {
s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName());
throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName());
}
}
}
StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(pool.getId(), hostId);
if (poolHost == null) {
poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
storagePoolHostDao.persist(poolHost);
} else {
poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
}
final StoragePoolVO poolVO = this.primaryStoreDao.findById(poolId);
poolVO.setUsedBytes(mspAnswer.getPoolInfo().getCapacityBytes() - mspAnswer.getPoolInfo().getAvailableBytes());
poolVO.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes());
primaryStoreDao.update(pool.getId(), poolVO);
s_logger.info("Connection established between storage pool " + pool + " and host " + hostId);
return true;
}
use of com.cloud.legacymodel.exceptions.StorageConflictException in project cosmic by MissionCriticalCloud.
the class CloudStackPrimaryDataStoreLifeCycleImpl method attachCluster.
@Override
public boolean attachCluster(final DataStore store, final ClusterScope scope) {
final PrimaryDataStoreInfo primarystore = (PrimaryDataStoreInfo) store;
// Check if there is host up in this cluster
final List<HostVO> allHosts = _resourceMgr.listAllUpAndEnabledHosts(HostType.Routing, primarystore.getClusterId(), primarystore.getPodId(), primarystore.getDataCenterId());
if (allHosts.isEmpty()) {
primaryDataStoreDao.expunge(primarystore.getId());
throw new CloudRuntimeException("No host up to associate a storage pool with in cluster " + primarystore.getClusterId());
}
if (primarystore.getPoolType() == StoragePoolType.OCFS2 && !_ocfs2Mgr.prepareNodes(allHosts, primarystore)) {
s_logger.warn("Can not create storage pool " + primarystore + " on cluster " + primarystore.getClusterId());
primaryDataStoreDao.expunge(primarystore.getId());
return false;
}
boolean success = false;
for (final HostVO h : allHosts) {
success = createStoragePool(h.getId(), primarystore);
if (success) {
break;
}
}
s_logger.debug("In createPool Adding the pool to each of the hosts");
final List<HostVO> poolHosts = new ArrayList<>();
for (final HostVO h : allHosts) {
try {
storageMgr.connectHostToSharedPool(h.getId(), primarystore.getId());
poolHosts.add(h);
} catch (final StorageConflictException se) {
primaryDataStoreDao.expunge(primarystore.getId());
throw new CloudRuntimeException("Storage has already been added as local storage");
} catch (final Exception e) {
s_logger.warn("Unable to establish a connection between " + h + " and " + primarystore, e);
}
}
if (poolHosts.isEmpty()) {
s_logger.warn("No host can access storage pool " + primarystore + " on cluster " + primarystore.getClusterId());
primaryDataStoreDao.expunge(primarystore.getId());
throw new CloudRuntimeException("Failed to access storage pool");
}
dataStoreHelper.attachCluster(store);
return true;
}
use of com.cloud.legacymodel.exceptions.StorageConflictException in project cosmic by MissionCriticalCloud.
the class CloudStackPrimaryDataStoreLifeCycleImpl method attachZone.
@Override
public boolean attachZone(final DataStore dataStore, final ZoneScope scope, final HypervisorType hypervisorType) {
final List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId());
s_logger.debug("In createPool. Attaching the pool to each of the hosts.");
final List<HostVO> poolHosts = new ArrayList<>();
for (final HostVO host : hosts) {
try {
storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId());
poolHosts.add(host);
} catch (final StorageConflictException se) {
primaryDataStoreDao.expunge(dataStore.getId());
throw new CloudRuntimeException("Storage has already been added as local storage to host: " + host.getName());
} catch (final Exception e) {
s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e);
}
}
if (poolHosts.isEmpty()) {
s_logger.warn("No host can access storage pool " + dataStore + " in this zone.");
primaryDataStoreDao.expunge(dataStore.getId());
throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts.");
}
dataStoreHelper.attachZone(dataStore, hypervisorType);
return true;
}
Aggregations