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; }
/** * Return true if the VM migration is a cross cluster migration. To execute that, we check if the volume current storage pool cluster is different from the target host cluster. */ protected boolean isStorageCrossClusterMigration(Host targetHost, StoragePoolVO currentPool) { return ScopeType.CLUSTER.equals(currentPool.getScope()) && currentPool.getClusterId() != targetHost.getClusterId(); }
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) { } }
public long[] getNeighbors(Host agent) { List<Long> neighbors = new ArrayList<Long>(); List<HostVO> cluster_hosts = resourceManager.listHostsInClusterByStatus(agent.getClusterId(), Status.Up); for (HostVO host : cluster_hosts) { if (host.getId() == agent.getId() || (host.getHypervisorType() != Hypervisor.HypervisorType.KVM && host.getHypervisorType() != Hypervisor.HypervisorType.LXC)) { continue; } neighbors.add(host.getId()); } return ArrayUtils.toPrimitive(neighbors.toArray(new Long[neighbors.size()])); }
@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 copyAsync(Map<VolumeInfo, DataStore> volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback) { Answer answer = null; String errMsg = null; try { VMInstanceVO instance = instanceDao.findById(vmTo.getId()); if (instance != null) { if (srcHost.getClusterId().equals(destHost.getClusterId())) { answer = migrateVmWithVolumesWithinCluster(instance, vmTo, srcHost, destHost, volumeMap); } else { answer = migrateVmWithVolumesAcrossCluster(instance, vmTo, srcHost, destHost, volumeMap); } } else { throw new CloudRuntimeException("Unsupported operation requested for moving data."); } } catch (Exception e) { s_logger.error("copy failed", e); errMsg = e.toString(); } CopyCommandResult result = new CopyCommandResult(null, answer); result.setResult(errMsg); callback.complete(result); }
public boolean isOutOfBandManagementEnabled(final Host host) { return host != null && isOutOfBandManagementEnabledForZone(host.getDataCenterId()) && isOutOfBandManagementEnabledForCluster(host.getClusterId()) && isOutOfBandManagementEnabledForHost(host.getId()); }
@Override public void processConnect(final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException { if (!(cmd instanceof StartupRoutingCommand)) { return; } if(s_logger.isDebugEnabled()) { s_logger.debug("Received startup command from hypervisor host. host id: " + agent.getId()); } _syncMgr.resetHostSyncState(agent.getId()); if (forRebalance) { s_logger.debug("Not processing listener " + this + " as connect happens on rebalance process"); return; } final Long clusterId = agent.getClusterId(); final long agentId = agent.getId(); if (agent.getHypervisorType() == HypervisorType.XenServer) { // only for Xen // initiate the cron job final ClusterVMMetaDataSyncCommand syncVMMetaDataCmd = new ClusterVMMetaDataSyncCommand(ClusterVMMetaDataSyncInterval.value(), clusterId); try { final long seq_no = _agentMgr.send(agentId, new Commands(syncVMMetaDataCmd), this); s_logger.debug("Cluster VM metadata sync started with jobid " + seq_no); } catch (final AgentUnavailableException e) { s_logger.fatal("The Cluster VM metadata sync process failed for cluster id " + clusterId + " with ", e); } } }
private static SolidFireVag getVagForRandomHostInCluster(List<SolidFireUtil.SolidFireVag> sfVags, Host host, HostDao hostDao) { List<HostVO> hostVOs = hostDao.findByClusterId(host.getClusterId()); if (hostVOs != null) { Collections.shuffle(hostVOs, RANDOM); for (HostVO hostVO : hostVOs) { if (hostVO.getId() != host.getId() && hostSupports_iScsi(hostVO)) { SolidFireVag sfVag = getVolumeAccessGroup(hostVO.getStorageUrl(), sfVags); if (sfVag != null) { return sfVag; } } } } return null; }
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()); } } }
@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 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 boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore) { Preconditions.checkArgument(dataObject != null, "'dataObject' should not be 'null'"); Preconditions.checkArgument(host != null, "'host' should not be 'null'"); Preconditions.checkArgument(dataStore != null, "'dataStore' should not be 'null'"); long sfVolumeId = getSolidFireVolumeId(dataObject, true); long clusterId = host.getClusterId(); long storagePoolId = dataStore.getId(); ClusterVO cluster = clusterDao.findById(clusterId); GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid()); if (!lock.lock(SolidFireUtil.LOCK_TIME_IN_SECONDS)) { String errMsg = "Couldn't lock the DB (in grantAccess) on the following string: " + cluster.getUuid(); LOGGER.warn(errMsg); throw new CloudRuntimeException(errMsg); } try { List<HostVO> hosts = hostDao.findByClusterId(clusterId); SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao); SolidFireUtil.placeVolumeInVolumeAccessGroups(sfConnection, sfVolumeId, hosts); return true; } finally { lock.unlock(); lock.releaseRef(); } }
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; }
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."); } }
@Override public Status isAgentAlive(Host agent) { LOGGER.debug("isAgentAlive: " + agent.getName()); if (agent.getHypervisorType() != Hypervisor.HypervisorType.Ovm3) { return null; } CheckOnHostCommand cmd = new CheckOnHostCommand(agent); List<HostVO> neighbors = resourceMgr.listHostsInClusterByStatus(agent.getClusterId(), Status.Up); for (HostVO neighbor : neighbors) { if (neighbor.getId() == agent.getId() || neighbor.getHypervisorType() != Hypervisor.HypervisorType.Ovm3) { continue; } try { Answer answer = agentMgr.easySend(neighbor.getId(), cmd); if (answer != null) { return answer.getResult() ? Status.Down : Status.Up; } } catch (Exception e) { LOGGER.error("Failed to send command to host: " + neighbor.getId(), e); } } return null; } }
@Override public Status isAgentAlive(Host agent) { if (agent.getHypervisorType() != Hypervisor.HypervisorType.Hyperv) { return null; } CheckOnHostCommand cmd = new CheckOnHostCommand(agent); List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(agent.getClusterId(), Status.Up); for (HostVO neighbor : neighbors) { if (neighbor.getId() == agent.getId() || neighbor.getHypervisorType() != Hypervisor.HypervisorType.Hyperv) { continue; } try { Answer answer = _agentMgr.easySend(neighbor.getId(), cmd); if (answer != null) { return answer.getResult() ? Status.Down : Status.Up; } } catch (Exception e) { s_logger.debug("Failed to send command to host: " + neighbor.getId(), e); } } return null; } }
@Override public Status isAgentAlive(Host agent) { if (agent.getHypervisorType() != HypervisorType.XenServer) { return null; } CheckOnHostCommand cmd = new CheckOnHostCommand(agent); List<HostVO> neighbors = _resourceMgr.listAllHostsInCluster(agent.getClusterId()); for (HostVO neighbor : neighbors) { if (neighbor.getId() == agent.getId() || neighbor.getHypervisorType() != HypervisorType.XenServer) { continue; } Answer answer = _agentMgr.easySend(neighbor.getId(), cmd); if (answer != null && answer.getResult()) { CheckOnHostAnswer ans = (CheckOnHostAnswer)answer; if (!ans.isDetermined()) { s_logger.debug("Host " + neighbor + " couldn't determine the status of " + agent); continue; } // even it returns true, that means host is up, but XAPI may not work return ans.isAlive() ? null : Status.Down; } } return null; }
@Override public Object getConfigValue(final HAProviderConfig name, final Host host) { final Long clusterId = host.getClusterId(); switch (name) { case HealthCheckTimeout: return KVMHAConfig.KvmHAHealthCheckTimeout.valueIn(clusterId); case ActivityCheckTimeout: return KVMHAConfig.KvmHAActivityCheckTimeout.valueIn(clusterId); case MaxActivityCheckInterval: return KVMHAConfig.KvmHAActivityCheckInterval.valueIn(clusterId); case MaxActivityChecks: return KVMHAConfig.KvmHAActivityCheckMaxAttempts.valueIn(clusterId); case ActivityCheckFailureRatio: return KVMHAConfig.KvmHAActivityCheckFailureThreshold.valueIn(clusterId); case RecoveryWaitTimeout: return KVMHAConfig.KvmHARecoverWaitPeriod.valueIn(clusterId); case RecoveryTimeout: return KVMHAConfig.KvmHARecoverTimeout.valueIn(clusterId); case FenceTimeout: return KVMHAConfig.KvmHAFenceTimeout.valueIn(clusterId); case MaxRecoveryAttempts: return KVMHAConfig.KvmHARecoverAttemptThreshold.valueIn(clusterId); case MaxDegradedWaitTimeout: return KVMHAConfig.KvmHADegradedMaxPeriod.valueIn(clusterId); default: throw new InvalidParameterException("Unknown HAProviderConfig " + name.toString()); } }