@Override public boolean hostDisconnected(long hostId, long storagePoolId) { StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId); if (storagePoolHost != null) { storagePoolHostDao.deleteStoragePoolHostDetails(hostId, storagePoolId); } return true; }
@Override public boolean hostDisconnected(long hostId, long storagePoolId) { StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId); if (storagePoolHost != null) { storagePoolHostDao.deleteStoragePoolHostDetails(hostId, storagePoolId); } return true; }
@Override public boolean hostDisconnected(long hostId, long poolId) { StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId); if (storagePoolHost != null) { storagePoolHostDao.deleteStoragePoolHostDetails(hostId, poolId); } return false; }
protected boolean hostCanAccessSPool(Host host, StoragePool pool) { boolean hostCanAccessSPool = false; StoragePoolHostVO hostPoolLinkage = _poolHostDao.findByPoolHost(pool.getId(), host.getId()); if (hostPoolLinkage != null) { hostCanAccessSPool = true; } s_logger.debug("Host: " + host.getId() + (hostCanAccessSPool ? " can" : " cannot") + " access pool: " + pool.getId()); return hostCanAccessSPool; }
/** * Executes the managed storage checks for the volumes that the user has not entered a mapping of <volume, storage pool>. The following checks are performed. * <ul> * <li> If the current storage pool is not a managed storage, we do not need to proceed with this method; * <li> We check if the target host has access to the current managed storage pool. If it does not have an exception will be thrown. * </ul> */ protected void executeManagedStorageChecksWhenTargetStoragePoolNotProvided(Host targetHost, StoragePoolVO currentPool, Volume volume) { if (!currentPool.isManaged()) { return; } if (_poolHostDao.findByPoolHost(currentPool.getId(), targetHost.getId()) == null) { throw new CloudRuntimeException(String.format("The target host does not have access to the volume's managed storage pool. [volumeId=%s, storageId=%s, targetHostId=%s].", volume.getUuid(), currentPool.getUuid(), targetHost.getUuid())); } }
/** * Builds the map of storage pools and volumes with the information entered by the user. Before creating the an entry we validate if the migration is feasible checking if the migration is allowed and if the target host can access the defined target storage pool. */ protected Map<Volume, StoragePool> buildMapUsingUserInformation(VirtualMachineProfile profile, Host targetHost, Map<Long, Long> userDefinedVolumeToStoragePoolMap) { Map<Volume, StoragePool> volumeToPoolObjectMap = new HashMap<>(); if (MapUtils.isEmpty(userDefinedVolumeToStoragePoolMap)) { return volumeToPoolObjectMap; } for(Long volumeId: userDefinedVolumeToStoragePoolMap.keySet()) { VolumeVO volume = _volsDao.findById(volumeId); Long poolId = userDefinedVolumeToStoragePoolMap.get(volumeId); StoragePoolVO targetPool = _storagePoolDao.findById(poolId); StoragePoolVO currentPool = _storagePoolDao.findById(volume.getPoolId()); executeManagedStorageChecksWhenTargetStoragePoolProvided(currentPool, volume, targetPool); if (_poolHostDao.findByPoolHost(targetPool.getId(), targetHost.getId()) == null) { throw new CloudRuntimeException( String.format("Cannot migrate the volume [%s] to the storage pool [%s] while migrating VM [%s] to target host [%s]. The host does not have access to the storage pool entered.", volume.getUuid(), targetPool.getUuid(), profile.getUuid(), targetHost.getUuid())); } if (currentPool.getId() == targetPool.getId()) { s_logger.info(String.format("The volume [%s] is already allocated in storage pool [%s].", volume.getUuid(), targetPool.getUuid())); } volumeToPoolObjectMap.put(volume, targetPool); } return volumeToPoolObjectMap; }
@Override public boolean hostConnect(long hostId, long storagePoolId) { HostVO host = hostDao.findById(hostId); StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId); if (storagePoolHost == null) { storagePoolHost = new StoragePoolHostVO(storagePoolId, hostId, ""); storagePoolHostDao.persist(storagePoolHost); } if (host.getHypervisorType().equals(HypervisorType.XenServer)) { handleXenServer(host.getClusterId(), host.getId(), storagePoolId); } else if (host.getHypervisorType().equals(HypervisorType.KVM)) { handleKVM(hostId, storagePoolId); } return true; }
@Override public boolean hostConnect(long hostId, long storagePoolId) { StoragePool storagePool = (StoragePool) dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary); ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, storagePool); ModifyStoragePoolAnswer answer = sendModifyStoragePoolCommand(cmd, storagePool, hostId); StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId); if (storagePoolHost != null) { storagePoolHost.setLocalPath(answer.getPoolInfo().getLocalPath().replaceAll("//", "/")); } else { storagePoolHost = new StoragePoolHostVO(storagePoolId, hostId, answer.getPoolInfo().getLocalPath().replaceAll("//", "/")); storagePoolHostDao.persist(storagePoolHost); } StoragePoolVO storagePoolVO = storagePoolDao.findById(storagePoolId); storagePoolVO.setCapacityBytes(answer.getPoolInfo().getCapacityBytes()); storagePoolVO.setUsedBytes(answer.getPoolInfo().getCapacityBytes() - answer.getPoolInfo().getAvailableBytes()); storagePoolDao.update(storagePoolId, storagePoolVO); return true; }
@Override public boolean hostConnect(long hostId, long poolId) { StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary); StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId); HostVO host = _hostDao.findById(hostId); if (storagePoolHost == null) { storagePoolHost = new StoragePoolHostVO(poolId, hostId, ""); storagePoolHostDao.persist(storagePoolHost); } StoragePoolVO poolVO = storagePoolDao.findById(pool.getId()); if(poolVO.isManaged() && (host.getHypervisorType() != HypervisorType.KVM)){ return true; } 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()) { 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; s_logger.info("Connection established between " + pool + " host + " + hostId); return true; }
StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(pool.getId(), hostId); if (poolHost == null) { poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
public DataStore attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(store.getId(), scope.getScopeId()); if (poolHost == null) { poolHost = new StoragePoolHostVO(store.getId(), scope.getScopeId(), existingInfo.getLocalPath()); storagePoolHostDao.persist(poolHost); } StoragePoolVO pool = this.dataStoreDao.findById(store.getId()); pool.setScope(scope.getScopeType()); pool.setUsedBytes(existingInfo.getCapacityBytes() - existingInfo.getAvailableBytes()); pool.setCapacityBytes(existingInfo.getCapacityBytes()); pool.setStatus(StoragePoolStatus.Up); this.dataStoreDao.update(pool.getId(), pool); this.storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, pool.getUsedBytes()); return dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); }