use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.
the class DeploymentPlanningManagerImpl method findPotentialDeploymentResources.
protected Pair<Host, Map<Volume, StoragePool>> findPotentialDeploymentResources(final List<Host> suitableHosts, final Map<Volume, List<StoragePool>> suitableVolumeStoragePools, final ExcludeList avoid, final DeploymentPlanner.PlannerResourceUsage resourceUsageRequired, List<Volume> readyAndReusedVolumes) {
s_logger.debug("Trying to find a potenial host and associated storage pools from the suitable host/pool lists for this VM");
boolean hostCanAccessPool = false;
boolean haveEnoughSpace = false;
if (readyAndReusedVolumes == null) {
readyAndReusedVolumes = new ArrayList<>();
}
final Map<Volume, StoragePool> storage = new HashMap<>();
final TreeSet<Volume> volumesOrderBySizeDesc = new TreeSet<>(new Comparator<Volume>() {
@Override
public int compare(final Volume v1, final Volume v2) {
if (v1.getSize() < v2.getSize()) {
return 1;
} else {
return -1;
}
}
});
volumesOrderBySizeDesc.addAll(suitableVolumeStoragePools.keySet());
final boolean multipleVolume = volumesOrderBySizeDesc.size() > 1;
for (final Host potentialHost : suitableHosts) {
final Map<StoragePool, List<Volume>> volumeAllocationMap = new HashMap<>();
for (final Volume vol : volumesOrderBySizeDesc) {
haveEnoughSpace = false;
s_logger.debug("Checking if host: " + potentialHost.getId() + " can access any suitable storage pool for volume: " + vol.getVolumeType());
final List<StoragePool> volumePoolList = suitableVolumeStoragePools.get(vol);
hostCanAccessPool = false;
for (final StoragePool potentialSPool : volumePoolList) {
if (!_storageMgr.storagePoolHasEnoughIops(Collections.singletonList(vol), potentialSPool)) {
continue;
}
if (hostCanAccessSPool(potentialHost, potentialSPool)) {
hostCanAccessPool = true;
if (multipleVolume && !readyAndReusedVolumes.contains(vol)) {
List<Volume> requestVolumes = null;
if (volumeAllocationMap.containsKey(potentialSPool)) {
requestVolumes = volumeAllocationMap.get(potentialSPool);
} else {
requestVolumes = new ArrayList<>();
}
requestVolumes.add(vol);
if (!_storageMgr.storagePoolHasEnoughSpace(requestVolumes, potentialSPool)) {
continue;
}
volumeAllocationMap.put(potentialSPool, requestVolumes);
}
storage.put(vol, potentialSPool);
haveEnoughSpace = true;
break;
}
}
if (!hostCanAccessPool) {
break;
}
if (!haveEnoughSpace) {
s_logger.warn("insufficient capacity to allocate all volumes");
break;
}
}
if (hostCanAccessPool && haveEnoughSpace && checkIfHostFitsPlannerUsage(potentialHost.getId(), resourceUsageRequired)) {
s_logger.debug("Found a potential host " + "id: " + potentialHost.getId() + " name: " + potentialHost.getName() + " and associated storage pools for this VM");
return new Pair<>(potentialHost, storage);
} else {
avoid.addHost(potentialHost.getId());
}
}
s_logger.debug("Could not find a potential host that has associated storage pools from the suitable host/pool lists for this VM");
return null;
}
use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.
the class ConsoleProxyManagerImpl method isZoneReady.
public boolean isZoneReady(final Map<Long, ZoneHostInfo> zoneHostInfoMap, final long dataCenterId) {
final ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId);
if (zoneHostInfo != null && isZoneHostReady(zoneHostInfo)) {
final VMTemplateVO template = this._templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
if (template == null) {
logger.debug("System vm template is not ready at data center " + dataCenterId + ", wait until it is ready to launch console proxy vm");
return false;
}
final TemplateDataStoreVO templateHostRef = this._vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dataCenterId, VMTemplateStatus.DOWNLOADED);
if (templateHostRef != null) {
boolean useLocalStorage = false;
final Boolean useLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId);
if (useLocal != null) {
useLocalStorage = useLocal.booleanValue();
}
final List<Pair<Long, Integer>> l = this._consoleProxyDao.getDatacenterStoragePoolHostInfo(dataCenterId, useLocalStorage);
if (l != null && l.size() > 0 && l.get(0).second().intValue() > 0) {
return true;
} else {
logger.debug("Primary storage is not ready, wait until it is ready to launch console proxy");
}
} else {
logger.debug("Zone host is ready, but console proxy template: " + template.getId() + " is not ready on secondary storage.");
}
}
return false;
}
use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.
the class ConsoleProxyManagerImpl method assignProxyFromRunningPool.
public ConsoleProxyVO assignProxyFromRunningPool(final long dataCenterId) {
logger.trace("Assign console proxy from running pool for request from data center : " + dataCenterId);
final ConsoleProxyAllocator allocator = getCurrentAllocator();
assert (allocator != null);
final List<ConsoleProxyVO> runningList = this._consoleProxyDao.getProxyListInStates(dataCenterId, State.Running);
if (runningList != null && runningList.size() > 0) {
final Iterator<ConsoleProxyVO> it = runningList.iterator();
while (it.hasNext()) {
final ConsoleProxyVO proxy = it.next();
if (proxy.getActiveSession() >= this._capacityPerProxy) {
it.remove();
}
}
logger.trace("Running proxy pool size : " + runningList.size());
for (final ConsoleProxyVO proxy : runningList) {
logger.trace("Running proxy instance : " + proxy.getHostName());
}
final List<Pair<Long, Integer>> l = this._consoleProxyDao.getProxyLoadMatrix();
final Map<Long, Integer> loadInfo = new HashMap<>();
if (l != null) {
for (final Pair<Long, Integer> p : l) {
loadInfo.put(p.first(), p.second());
logger.trace("Running proxy instance allocation load { proxy id : " + p.first() + ", load : " + p.second() + "}");
}
}
final Long allocated = allocator.allocProxy(runningList, loadInfo, dataCenterId);
if (allocated == null) {
logger.debug("Unable to find a console proxy ");
return null;
}
return this._consoleProxyDao.findById(allocated);
} else {
logger.trace("Empty running proxy pool for now in data center : " + dataCenterId);
}
return null;
}
use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.
the class DedicatedResourceManagerImpl method listDedicatedClusters.
@Override
public Pair<List<? extends DedicatedResourceVO>, Integer> listDedicatedClusters(final ListDedicatedClustersCmd cmd) {
final Long clusterId = cmd.getClusterId();
final Long domainId = cmd.getDomainId();
final String accountName = cmd.getAccountName();
Long accountId = null;
final Long affinityGroupId = cmd.getAffinityGroupId();
if (accountName != null) {
if (domainId != null) {
final Account account = _accountDao.findActiveAccount(accountName, domainId);
if (account != null) {
accountId = account.getId();
}
} else {
throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName);
}
}
final Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedClusters(clusterId, domainId, accountId, affinityGroupId);
return new Pair<>(result.first(), result.second());
}
use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.
the class NetworkServiceImpl method listTrafficTypes.
@Override
public Pair<List<? extends PhysicalNetworkTrafficType>, Integer> listTrafficTypes(final Long physicalNetworkId) {
final PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
if (network == null) {
final InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
ex.addProxyObject(physicalNetworkId.toString(), "physicalNetworkId");
throw ex;
}
final Pair<List<PhysicalNetworkTrafficTypeVO>, Integer> result = _pNTrafficTypeDao.listAndCountBy(physicalNetworkId);
return new Pair<>(result.first(), result.second());
}
Aggregations