private Long getClusterId(Long hostId) { if (hostId == null) { return null; } HostVO hostVO = hostDao.findById(hostId); if (hostVO == null) { return null; } return hostVO.getClusterId(); }
/** * Set retries for transiting the host into Maintenance */ protected void setHostMaintenanceRetries(HostVO host) { Integer retries = HostMaintenanceRetries.valueIn(host.getClusterId()); retryHostMaintenance.put(host.getId(), retries); s_logger.debug(String.format("Setting the host %s (%s) retries for Maintenance mode: %s", host.getId(), host.getName(), retries)); }
@Override public boolean hostAdded(long hostId) { HostVO host = hostDao.findById(hostId); if (host == null) { LOGGER.error("Failed to add host by SolidFireHostListener as host was not found with id = " + hostId); return false; } SolidFireUtil.hostAddedToCluster(hostId, host.getClusterId(), SolidFireUtil.PROVIDER_NAME, clusterDao, hostDao, storagePoolDao, storagePoolDetailsDao); handleVMware(host, true, ModifyTargetsCommand.TargetTypeToRemove.NEITHER); return true; }
@Override public boolean hostAdded(long hostId) { HostVO host = hostDao.findById(hostId); if (host == null) { LOGGER.error("Failed to add host by SolidFireSharedHostListener as host was not found with id = " + hostId); return false; } SolidFireUtil.hostAddedToCluster(hostId, host.getClusterId(), SolidFireUtil.SHARED_PROVIDER_NAME, clusterDao, hostDao, storagePoolDao, storagePoolDetailsDao); handleVMware(host, true, ModifyTargetsCommand.TargetTypeToRemove.NEITHER); return true; }
@Override public boolean hostAboutToBeRemoved(long hostId) { HostVO host = hostDao.findById(hostId); SolidFireUtil.hostRemovedFromCluster(hostId, host.getClusterId(), SolidFireUtil.PROVIDER_NAME, clusterDao, hostDao, storagePoolDao, storagePoolDetailsDao); handleVMware(host, false, ModifyTargetsCommand.TargetTypeToRemove.BOTH); return true; }
@Override public boolean hostAboutToBeRemoved(long hostId) { HostVO host = hostDao.findById(hostId); SolidFireUtil.hostRemovedFromCluster(hostId, host.getClusterId(), SolidFireUtil.SHARED_PROVIDER_NAME, clusterDao, hostDao, storagePoolDao, storagePoolDetailsDao); handleVMware(host, false, ModifyTargetsCommand.TargetTypeToRemove.BOTH); return true; }
/** * Get running host IDs within the same hypervisor, cluster and datacenter than hostId. ID hostId is not included on the returned list */ protected List<Long> getRunningHostIdsInTheSameCluster(Long clusterId, long dataCenterId, HypervisorType hypervisorType, long hostId) { List<Long> list = hostDao.listByDataCenterIdAndHypervisorType(dataCenterId, hypervisorType) .stream() .filter(x -> x.getHypervisorType().equals(hypervisorType) && x.getStatus().equals(Status.Up) && x.getType().equals(Host.Type.Routing) && x.getClusterId().equals(clusterId) && x.getId() != hostId) .map(x -> x.getId()) .collect(Collectors.toList()); Collections.shuffle(list); return list; }
private boolean isFirstHostInCluster(final HostVO host) { boolean isFirstHost = true; if (host.getClusterId() != null) { final SearchBuilder<HostVO> sb = _hostDao.createSearchBuilder(); sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NULL); sb.and("cluster", sb.entity().getClusterId(), SearchCriteria.Op.EQ); sb.done(); final SearchCriteria<HostVO> sc = sb.create(); sc.setParameters("cluster", host.getClusterId()); final List<HostVO> hosts = _hostDao.search(sc, null); if (hosts != null && hosts.size() > 1) { isFirstHost = false; } } return isFirstHost; }
@Override public List<HostVO> listAllHostsInCluster(final long clusterId) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getClusterId(), Op.EQ, clusterId); return sc.list(); }
private boolean checkIfHostIsDedicated(HostVO host) { long hostId = host.getId(); DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId); DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId()); DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId()); if (dedicatedHost != null || dedicatedClusterOfHost != null || dedicatedPodOfHost != null) { return true; } else { return false; } }
private void handleVMware(HostVO host, boolean add, ModifyTargetsCommand.TargetTypeToRemove targetTypeToRemove) { if (host != null && HypervisorType.VMware.equals(host.getHypervisorType())) { List<StoragePoolVO> storagePools = storagePoolDao.findPoolsByProvider(SolidFireUtil.PROVIDER_NAME); if (storagePools != null && storagePools.size() > 0) { List<Map<String, String>> targets = new ArrayList<>(); for (StoragePoolVO storagePool : storagePools) { List<Map<String, String>> targetsForClusterAndStoragePool = getTargets(host.getClusterId(), storagePool.getId()); targets.addAll(targetsForClusterAndStoragePool); } ModifyTargetsCommand cmd = new ModifyTargetsCommand(); cmd.setTargets(targets); cmd.setAdd(add); cmd.setTargetTypeToRemove(targetTypeToRemove); cmd.setRemoveAsync(true); sendModifyTargetsCommand(cmd, host.getId()); } } }
@Override public List<HostVO> listHostsInClusterByStatus(final long clusterId, final Status status) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getClusterId(), Op.EQ, clusterId); sc.and(sc.entity().getStatus(), Op.EQ, status); return sc.list(); }
private void verifyManagedStorage(Long storagePoolId, Long hostId) { if (storagePoolId == null || hostId == null) { return; } StoragePoolVO storagePoolVO = _storagePoolDao.findById(storagePoolId); if (storagePoolVO == null || !storagePoolVO.isManaged()) { return; } HostVO hostVO = _hostDao.findById(hostId); if (hostVO == null) { return; } if (!storageUtil.managedStoragePoolCanScale(storagePoolVO, hostVO.getClusterId(), hostVO.getId())) { throw new CloudRuntimeException("Insufficient number of available " + getNameOfClusteredFileSystem(hostVO)); } }
private Long accountOfDedicatedHost(HostVO host) { long hostId = host.getId(); DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId); DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId()); DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId()); if (dedicatedHost != null) { return dedicatedHost.getAccountId(); } if (dedicatedClusterOfHost != null) { return dedicatedClusterOfHost.getAccountId(); } if (dedicatedPodOfHost != null) { return dedicatedPodOfHost.getAccountId(); } return null; }
private Long domainOfDedicatedHost(HostVO host) { long hostId = host.getId(); DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId); DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId()); DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId()); if (dedicatedHost != null) { return dedicatedHost.getDomainId(); } if (dedicatedClusterOfHost != null) { return dedicatedClusterOfHost.getDomainId(); } if (dedicatedPodOfHost != null) { return dedicatedPodOfHost.getDomainId(); } return null; }
@Override public boolean prepareNodes(Long clusterId) { ClusterVO cluster = _clusterDao.findById(clusterId); if (cluster == null) { throw new CloudRuntimeException("Cannot find cluster for ID " + clusterId); } QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getClusterId(), Op.EQ, clusterId); sc.and(sc.entity().getPodId(), Op.EQ, cluster.getPodId()); sc.and(sc.entity().getDataCenterId(), Op.EQ, cluster.getDataCenterId()); sc.and(sc.entity().getType(), Op.EQ, Host.Type.Routing); List<HostVO> hosts = sc.list(); if (hosts.isEmpty()) { s_logger.debug("There is no host in cluster " + clusterId + ", no need to prepare OCFS2 nodes"); return true; } return prepareNodes(getClusterName(clusterId), hosts); }
@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 List<HostVO> listAllHosts(final Type type, final Long clusterId, final Long podId, final long dcId) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); if (type != null) { sc.and(sc.entity().getType(), Op.EQ, type); } if (clusterId != null) { sc.and(sc.entity().getClusterId(), Op.EQ, clusterId); } if (podId != null) { sc.and(sc.entity().getPodId(), Op.EQ, podId); } sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId); return sc.list(); }
@Override public List<HostVO> listAllUpHosts(Type type, Long clusterId, Long podId, long dcId) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); if (type != null) { sc.and(sc.entity().getType(), Op.EQ, type); } if (clusterId != null) { sc.and(sc.entity().getClusterId(), Op.EQ, clusterId); } if (podId != null) { sc.and(sc.entity().getPodId(), Op.EQ, podId); } sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId); sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); return sc.list(); }
@Override public List<HostVO> listAllUpAndEnabledHosts(final Type type, final Long clusterId, final Long podId, final long dcId) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); if (type != null) { sc.and(sc.entity().getType(), Op.EQ, type); } if (clusterId != null) { sc.and(sc.entity().getClusterId(), Op.EQ, clusterId); } if (podId != null) { sc.and(sc.entity().getPodId(), Op.EQ, podId); } sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId); sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); sc.and(sc.entity().getResourceState(), Op.EQ, ResourceState.Enabled); return sc.list(); }