List<Long> getOrderedHostIdList(final Long dcId) { final List<Long> hostIdList = new ArrayList<>(); for (final Host host : getAllAgentBasedHosts()) { if (host.getDataCenterId() == dcId) { hostIdList.add(host.getId()); } } Collections.sort(hostIdList, new Comparator<Long>() { @Override public int compare(Long x, Long y) { return Long.compare(x,y); } }); return hostIdList; }
public boolean shouldAvoid(Host host) { if (_dcIds != null && _dcIds.contains(host.getDataCenterId())) { return true; } if (_podIds != null && _podIds.contains(host.getPodId())) { return true; } if (_clusterIds != null && _clusterIds.contains(host.getClusterId())) { return true; } if (_hostIds != null && _hostIds.contains(host.getId())) { return true; } return false; }
@Override public void sendAlert(final Host host, final HAConfig.HAState nextState) { String subject = "HA operation performed for host"; String body = subject; if (HAConfig.HAState.Fencing.equals(nextState)) { subject = String.format("HA Fencing of host id=%d, in dc id=%d performed", host.getId(), host.getDataCenterId()); body = String.format("HA Fencing has been performed for host id=%d, uuid=%s in datacenter id=%d", host.getId(), host.getUuid(), host.getDataCenterId()); } else if (HAConfig.HAState.Recovering.equals(nextState)) { subject = String.format("HA Recovery of host id=%d, in dc id=%d performed", host.getId(), host.getDataCenterId()); body = String.format("HA Recovery has been performed for host id=%d, uuid=%s in datacenter id=%d", host.getId(), host.getUuid(), host.getDataCenterId()); } alertManager.sendAlert(AlertService.AlertType.ALERT_TYPE_HA_ACTION, host.getDataCenterId(), host.getPodId(), subject, body); }
@Override public void sendAlert(final Host host, final String subject, final String message) { if (host == null) { return; } alertManager.sendAlert(AlertManager.AlertType.ALERT_TYPE_CA_CERT, host.getDataCenterId(), host.getPodId(), subject, message); }
private void sendAuthError(final Host host, final String message) { try { hostAlertCache.asMap().putIfAbsent(host.getId(), 0L); Long sentCount = hostAlertCache.asMap().get(host.getId()); if (sentCount != null && sentCount <= 0) { boolean concurrentUpdateResult = hostAlertCache.asMap().replace(host.getId(), sentCount, sentCount+1L); if (concurrentUpdateResult) { final String subject = String.format("Out-of-band management auth-error detected for host:%d in cluster:%d, zone:%d", host.getId(), host.getClusterId(), host.getDataCenterId()); LOG.error(subject + ": " + message); alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR, host.getDataCenterId(), host.getPodId(), subject, message); } } } catch (Exception ignored) { } }
@Override public void processConnect(Host server, StartupCommand startup, boolean forRebalance) throws ConnectionException { if (!(startup instanceof StartupStorageCommand)) { return; } StartupStorageCommand ssCmd = (StartupStorageCommand)startup; if (ssCmd.getResourceType() == Storage.StorageResourceType.STORAGE_HOST) { BigDecimal overProvFactor = BigDecimal.valueOf(CapacityManager.StorageOverprovisioningFactor.value()); CapacityVO capacity = new CapacityVO(server.getId(), server.getDataCenterId(), server.getPodId(), server.getClusterId(), 0L, (overProvFactor.multiply(new BigDecimal( server.getTotalSize()))).longValue(), Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED); _capacityDao.persist(capacity); } }
@Override public void processConnect(Host agent, StartupCommand cmd, boolean forRebalance) throws ConnectionException { if (cmd instanceof StartupRoutingCommand) { List<HypervisorType> hypers = _resourceMgr.listAvailHypervisorInZone(agent.getId(), agent.getDataCenterId()); HypervisorType hostHyper = agent.getHypervisorType(); if (hypers.contains(hostHyper)) { return; _imageSrv.handleSysTemplateDownload(hostHyper, agent.getDataCenterId()); _imageSrv.associateCrosszoneTemplatesToZone(agent.getDataCenterId()); List<DataStore> imageStores = _storeMgr.getImageStoresByScope(new ZoneScope(agent.getDataCenterId())); for (DataStore store : imageStores) { _volumeSrv.handleVolumeSync(store);
private void propagateMSListToAgents() { LOG.debug("Propagating management server list update to agents"); final String lbAlgorithm = getLBAlgorithmName(); final Map<Long, List<Long>> dcOrderedHostsMap = new HashMap<>(); for (final Host host : getAllAgentBasedHosts()) { final Long dcId = host.getDataCenterId(); if (!dcOrderedHostsMap.containsKey(dcId)) { dcOrderedHostsMap.put(dcId, getOrderedHostIdList(dcId)); } final List<String> msList = getManagementServerList(host.getId(), host.getDataCenterId(), dcOrderedHostsMap.get(dcId)); final Long lbCheckInterval = getLBPreferredHostCheckInterval(host.getClusterId()); final SetupMSListCommand cmd = new SetupMSListCommand(msList, lbAlgorithm, lbCheckInterval); final Answer answer = agentManager.easySend(host.getId(), cmd); if (answer == null || !answer.getResult()) { LOG.warn("Failed to setup management servers list to the agent of host id=" + host.getId()); } } }
public boolean isOutOfBandManagementEnabled(final Host host) { return host != null && isOutOfBandManagementEnabledForZone(host.getDataCenterId()) && isOutOfBandManagementEnabledForCluster(host.getClusterId()) && isOutOfBandManagementEnabledForHost(host.getId()); }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { CapacityVO capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId(), usedCpuCoreFinal, host.getCpus().longValue(), CapacityVO.CAPACITY_TYPE_CPU_CORE); capacity.setReservedCapacity(reservedCpuCoreFinal); capacity.setCapacityState(capacityState); _capacityDao.persist(capacity); } });
@Override public List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long vmId) { UserVm vm = findUserVmById(vmId); Long hostId = (vm.getHostId() == null ? vm.getLastHostId() : vm.getHostId()); Host host = findHostById(hostId); return createTemplateResponses(view, templateId, host.getDataCenterId(), true); }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { CapacityVO capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId(), usedMemoryFinal, host.getTotalMemory(), Capacity.CAPACITY_TYPE_MEMORY); capacity.setReservedCapacity(reservedMemoryFinal); capacity.setCapacityState(capacityState); _capacityDao.persist(capacity); capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId(), usedCpuFinal, host.getCpus().longValue() * host.getSpeed().longValue(), Capacity.CAPACITY_TYPE_CPU); capacity.setReservedCapacity(reservedCpuFinal); capacity.setCapacityState(capacityState); _capacityDao.persist(capacity); } });
@Override public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException { if (!(cmd instanceof StartupRoutingCommand)) { return; } PlannerHostReservationVO reservationEntry = _plannerHostReserveDao.findByHostId(host.getId()); if (reservationEntry == null) { // record the host in this table PlannerHostReservationVO newHost = new PlannerHostReservationVO(host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId()); _plannerHostReserveDao.persist(newHost); } }
@Override public void processDeletHostEventAfter(Host host) { String errMsg = String.format("Prepare OCFS2 nodes failed after delete host %1$s (zone:%2$s, pod:%3$s, cluster:%4$s", host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId()); if (host.getHypervisorType() != HypervisorType.Ovm) { return; } boolean hasOcfs2 = false; List<StoragePoolHostVO> poolRefs = _poolHostDao.listByHostId(host.getId()); for (StoragePoolHostVO poolRef : poolRefs) { StoragePoolVO pool = _poolDao.findById(poolRef.getPoolId()); if (pool.getPoolType() == StoragePoolType.OCFS2) { hasOcfs2 = true; break; } } if (hasOcfs2) { try { if (!prepareNodes(host.getClusterId())) { s_logger.warn(errMsg); } } catch (Exception e) { s_logger.error(errMsg, e); } } }
private boolean hasSuitablePoolsForVolume(final VolumeVO volume, final Host host, final VirtualMachineProfile vmProfile) { final DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); final DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType()); final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null); final ExcludeList avoid = new ExcludeList(); for (final StoragePoolAllocator allocator : _storagePoolAllocators) { final List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, 1); if (poolList != null && !poolList.isEmpty()) { return true; } } return false; }
@Override public void processConnect(Host agent, StartupCommand cmd, boolean forRebalance) { if ((cmd instanceof StartupStorageCommand)) { StartupStorageCommand scmd = (StartupStorageCommand)cmd; if (scmd.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE) { _ssVmMgr.generateSetupCommand(agent.getId()); return; } } else if (cmd instanceof StartupSecondaryStorageCommand) { if (s_logger.isInfoEnabled()) { s_logger.info("Received a host startup notification " + cmd); } _ssVmMgr.onAgentConnect(agent.getDataCenterId(), cmd); _ssVmMgr.generateSetupCommand(agent.getId()); _ssVmMgr.generateFirewallConfiguration(agent.getId()); _ssVmMgr.generateVMSetupCommand(agent.getId()); return; } return; }
scCmd.getHypervisorType() == HypervisorType.Ovm || scCmd.getHypervisorType() == HypervisorType.Hyperv || scCmd.getHypervisorType() == HypervisorType.LXC || scCmd.getHypervisorType() == HypervisorType.Ovm3) { List<StoragePoolVO> pools = _poolDao.listBy(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER); List<StoragePoolVO> zoneStoragePoolsByTags = _poolDao.findZoneWideStoragePoolsByTags(host.getDataCenterId(), null); List<StoragePoolVO> zoneStoragePoolsByHypervisor = _poolDao.findZoneWideStoragePoolsByHypervisor(host.getDataCenterId(), scCmd.getHypervisorType()); zoneStoragePoolsByTags.retainAll(zoneStoragePoolsByHypervisor); pools.addAll(zoneStoragePoolsByTags); List<StoragePoolVO> zoneStoragePoolsByAnyHypervisor = _poolDao.findZoneWideStoragePoolsByHypervisor(host.getDataCenterId(), HypervisorType.Any); pools.addAll(zoneStoragePoolsByAnyHypervisor);
private void checkOutOfBandManagementEnabledByZoneClusterHost(final Host host) { if (!isOutOfBandManagementEnabledForZone(host.getDataCenterId())) { throw new CloudRuntimeException("Out-of-band management is disabled for the host's zone. Aborting Operation."); } if (!isOutOfBandManagementEnabledForCluster(host.getClusterId())) { throw new CloudRuntimeException("Out-of-band management is disabled for the host's cluster. Aborting Operation."); } if (!isOutOfBandManagementEnabledForHost(host.getId())) { throw new CloudRuntimeException("Out-of-band management is disabled or not configured for the host. Aborting Operation."); } }
/** * We use {@link StoragePoolAllocator} objects to find storage pools connected to the targetHost where we would be able to allocate the given volume. */ protected List<StoragePool> getCandidateStoragePoolsToMigrateLocalVolume(VirtualMachineProfile profile, Host targetHost, Volume volume) { List<StoragePool> poolList = new ArrayList<>(); DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); DiskProfile diskProfile = new DiskProfile(volume, diskOffering, profile.getHypervisorType()); DataCenterDeployment plan = new DataCenterDeployment(targetHost.getDataCenterId(), targetHost.getPodId(), targetHost.getClusterId(), targetHost.getId(), null, null); ExcludeList avoid = new ExcludeList(); StoragePoolVO volumeStoragePool = _storagePoolDao.findById(volume.getPoolId()); if (volumeStoragePool.isLocal()) { diskProfile.setUseLocalStorage(true); } for (StoragePoolAllocator allocator : _storagePoolAllocators) { List<StoragePool> poolListFromAllocator = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL); if (CollectionUtils.isEmpty(poolListFromAllocator)) { continue; } for (StoragePool pool : poolListFromAllocator) { if (pool.isLocal() || isStorageCrossClusterMigration(targetHost, volumeStoragePool)) { poolList.add(pool); } } } return poolList; }
boolean computeSupportsVolumeClone = computeSupportsVolumeClone(destHost.getDataCenterId(), destHost.getHypervisorType());