@Override public boolean isDisabled() { return (getResourceState() == ResourceState.Disabled); }
@Override public boolean isInMaintenanceStates() { return (getResourceState() == ResourceState.Maintenance || getResourceState() == ResourceState.ErrorInMaintenance || getResourceState() == ResourceState.PrepareForMaintenance); }
private void checkIfHostOfVMIsInPrepareForMaintenanceState(Long hostId, Long vmId, String operation) { HostVO host = _hostDao.findById(hostId); if (host.getResourceState() != ResourceState.PrepareForMaintenance) { return; } s_logger.debug("Host is in PrepareForMaintenance state - " + operation + " VM operation on the VM id: " + vmId + " is not allowed"); throw new InvalidParameterValueException(operation + " VM operation on the VM id: " + vmId + " is not allowed as host is preparing for maintenance mode"); }
private HostVO getHostInCluster(long clusterId) { List<HostVO> hosts = _hostDao.findByClusterId(clusterId); if (hosts != null && hosts.size() > 0) { Collections.shuffle(hosts, RANDOM); for (HostVO host : hosts) { if (ResourceState.Enabled.equals(host.getResourceState())) { return host; } } } throw new CloudRuntimeException("Unable to locate a host"); }
@Override public boolean maintenanceFailed(final long hostId) { final HostVO host = _hostDao.findById(hostId); if (host == null) { if (s_logger.isDebugEnabled()) { s_logger.debug("Cant not find host " + hostId); } return false; } else { try { return resourceStateTransitTo(host, ResourceState.Event.UnableToMigrate, _nodeId); } catch (final NoTransitionException e) { s_logger.debug("No next resource state for host " + host.getId() + " while current state is " + host.getResourceState() + " with event " + ResourceState.Event.UnableToMigrate, e); return false; } } }
private HostVO getHost(long zoneId, Long hostId) { Optional<HostVO> optHostVO = getHost(zoneId, true); if (optHostVO.isPresent()) { return optHostVO.get(); } HostVO hostVO = hostDao.findById(hostId); if (hostVO != null && ResourceState.Enabled.equals(hostVO.getResourceState())) { return hostVO; } optHostVO = getHost(zoneId, false); if (optHostVO.isPresent()) { return optHostVO.get(); } throw new CloudRuntimeException("Unable to locate an applicable host"); }
if (!ResourceState.Enabled.equals(host.getResourceState())) { continue;
@Override public boolean agentStatusTransitTo(final HostVO host, final Status.Event e, final long msId) { try { _agentStatusLock.lock(); if (s_logger.isDebugEnabled()) { final ResourceState state = host.getResourceState(); final StringBuilder msg = new StringBuilder("Transition:"); msg.append("[Resource state = ").append(state); msg.append(", Agent event = ").append(e.toString()); msg.append(", Host id = ").append(host.getId()).append(", name = " + host.getName()).append("]"); s_logger.debug(msg); } host.setManagementServerId(msId); try { return _statusStateMachine.transitTo(host, e, host.getId(), _hostDao); } catch (final NoTransitionException e1) { s_logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() + ", mangement server id is " + msId); throw new CloudRuntimeException("Cannot transit agent status with event " + e + " for host " + host.getId() + ", mangement server id is " + msId + "," + e1.getMessage()); } } finally { _agentStatusLock.unlock(); } }
if (ResourceState.Enabled.equals(host.getResourceState())) { if (computeClusterMustSupportResign) { if (clusterDao.getSupportsResigning(cluster.getId())) {
if (host.getResourceState() == ResourceState.Enabled) { if (computeClusterMustSupportResign) { if (clusterDao.getSupportsResigning(cluster.getId())) {
@Override public HostVO findOneRandomRunningHostByHypervisor(HypervisorType type) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getHypervisorType(), Op.EQ, type); sc.and(sc.entity().getType(),Op.EQ, Type.Routing); sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); sc.and(sc.entity().getResourceState(), Op.EQ, ResourceState.Enabled); sc.and(sc.entity().getRemoved(), Op.NULL); List<HostVO> hosts = sc.list(); if (CollectionUtils.isEmpty(hosts)) { return null; } else { Collections.shuffle(hosts, new Random(System.currentTimeMillis())); return hosts.get(0); } }
@Override public List<HostVO> findDirectlyConnectedHosts() { /* The resource column is not null for direct connected resource */ final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getResource(), Op.NNULL); sc.and(sc.entity().getResourceState(), Op.NIN, ResourceState.Disabled); return sc.list(); }
@Override public List<HostVO> listAllUpAndEnabledHostsInOneZone(final long dcId) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); 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(); }
@Override public List<HostVO> listAllNotInMaintenanceHostsInOneZone(final Type type, final Long dcId) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); if (dcId != null) { sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId); } sc.and(sc.entity().getType(), Op.EQ, type); sc.and(sc.entity().getResourceState(), Op.NIN, ResourceState.Maintenance, ResourceState.ErrorInMaintenance, ResourceState.PrepareForMaintenance, ResourceState.Error); return sc.list(); }
@Override public List<HostVO> listAllUpAndEnabledHostsInOneZoneByType(final Type type, final long dcId) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getType(), Op.EQ, type); 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(); }
@Override public List<HostVO> listAllUpAndEnabledHostsInOneZoneByHypervisor(final HypervisorType type, final long dcId) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getHypervisorType(), Op.EQ, type); 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(); }
@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(); }
hostSearch.and("zoneId", hostSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); hostSearch.and("status", hostSearch.entity().getStatus(), SearchCriteria.Op.EQ); hostSearch.and("resourceState", hostSearch.entity().getResourceState(), SearchCriteria.Op.EQ);
@Override public List<HostVO> listByDataCenterIdAndHypervisorType(long zoneId, Hypervisor.HypervisorType hypervisorType) { SearchBuilder<ClusterVO> clusterSearch = _clusterDao.createSearchBuilder(); clusterSearch.and("allocationState", clusterSearch.entity().getAllocationState(), SearchCriteria.Op.EQ); clusterSearch.and("hypervisorType", clusterSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ); SearchBuilder<HostVO> hostSearch = createSearchBuilder(); hostSearch.and("dc", hostSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); hostSearch.and("type", hostSearch.entity().getType(), Op.EQ); hostSearch.and("status", hostSearch.entity().getStatus(), Op.EQ); hostSearch.and("resourceState", hostSearch.entity().getResourceState(), Op.EQ); hostSearch.join("clusterSearch", clusterSearch, hostSearch.entity().getClusterId(), clusterSearch.entity().getId(), JoinBuilder.JoinType.INNER); hostSearch.done(); SearchCriteria<HostVO> sc = hostSearch.create(); sc.setParameters("dc", zoneId); sc.setParameters("type", Host.Type.Routing); sc.setParameters("status", Status.Up); sc.setParameters("resourceState", ResourceState.Enabled); sc.setJoinParameters("clusterSearch", "allocationState", Grouping.AllocationState.Enabled); sc.setJoinParameters("clusterSearch", "hypervisorType", hypervisorType.toString()); return listBy(sc); }
@Override public List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag) { SearchBuilder<HostTagVO> hostTagSearch = _hostTagsDao.createSearchBuilder(); HostTagVO tagEntity = hostTagSearch.entity(); hostTagSearch.and("tag", tagEntity.getTag(), SearchCriteria.Op.EQ); SearchBuilder<HostVO> hostSearch = createSearchBuilder(); HostVO entity = hostSearch.entity(); hostSearch.and("type", entity.getType(), SearchCriteria.Op.EQ); hostSearch.and("pod", entity.getPodId(), SearchCriteria.Op.EQ); hostSearch.and("dc", entity.getDataCenterId(), SearchCriteria.Op.EQ); hostSearch.and("cluster", entity.getClusterId(), SearchCriteria.Op.EQ); hostSearch.and("status", entity.getStatus(), SearchCriteria.Op.EQ); hostSearch.and("resourceState", entity.getResourceState(), SearchCriteria.Op.EQ); hostSearch.join("hostTagSearch", hostTagSearch, entity.getId(), tagEntity.getHostId(), JoinBuilder.JoinType.INNER); SearchCriteria<HostVO> sc = hostSearch.create(); sc.setJoinParameters("hostTagSearch", "tag", hostTag); sc.setParameters("type", type.toString()); if (podId != null) { sc.setParameters("pod", podId); } if (clusterId != null) { sc.setParameters("cluster", clusterId); } sc.setParameters("dc", dcId); sc.setParameters("status", Status.Up.toString()); sc.setParameters("resourceState", ResourceState.Enabled.toString()); return listBy(sc); }