private boolean isNoEnabledHost() { return !candidates.stream().anyMatch(vo -> HostState.Enabled == vo.getState()); }
private boolean hostOutOfMaintenance(HostStateEvent stateEvent) { HostState origState = self.getState(); HostState state = changeState(stateEvent); return origState == HostState.Maintenance && state != HostState.Maintenance; }
private List<HostVO> allocate(List<HostVO> vos, String hypervisorType) { List<HostVO> lst = new ArrayList<HostVO>(vos.size()); for (HostVO vo : vos) { if (hypervisorType != null && !hypervisorType.equals(vo.getHypervisorType())) { continue; } if (vo.getState() == HostState.Enabled && vo.getStatus() == HostStatus.Connected) { lst.add(vo); } } return lst; }
protected HostState changeState(HostStateEvent event) { HostState currentState = self.getState(); HostState next = currentState.nextState(event); changeStateHook(currentState, event, next); extpEmitter.beforeChange(self, event); self.setState(next); self = dbf.updateAndRefresh(self); extpEmitter.afterChange(self, event, currentState); logger.debug(String.format("Host[%s]'s state changed from %s to %s", self.getUuid(), currentState, self.getState())); return self.getState(); }
public void beforeChange(HostVO vo, final HostStateEvent event) { final HostInventory hinv = HostInventory.valueOf(vo); final HostState next = vo.getState().nextState(event); CollectionUtils.safeForEach(changeStateExts, new ForEachFunction<HostChangeStateExtensionPoint>() { @Override public void run(HostChangeStateExtensionPoint extp) { extp.beforeChangeHostState(hinv, event, next); } }); }
public void preChange(HostVO vo, HostStateEvent event) throws HostException { HostState next = vo.getState().nextState(event); HostInventory hinv = HostInventory.valueOf(vo); for (HostChangeStateExtensionPoint extp : changeStateExts) { extp.preChangeHostState(hinv, event, next); } }
@Override public void beforeChangeClusterState(ClusterInventory inventory, ClusterStateEvent event, ClusterState nextState) { /* * given changing cluster state is working simultaneously, we change host state one by one * in order to avoid thread pool exhausted */ if (!event.toString().equals(ClusterStateEvent.disable.toString()) && !event.toString().equals(ClusterStateEvent.enable.toString())) { logger.debug("Unsupport ClusterStateEvent: " + event + ", won't propgate to extensions of host"); return; } HostStateEvent hostEvent = HostStateEvent.valueOf(event.toString()); List<HostVO> vos = findHostUnderClusterByUuid(inventory.getUuid()); if (!vos.isEmpty()) { for (HostVO h : vos) { if (h.getState() == HostState.Maintenance || h.getState() == HostState.PreMaintenance) { continue; } ChangeHostStateMsg msg = new ChangeHostStateMsg(h.getUuid(), hostEvent.toString()); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, h.getUuid()); ChangeHostStateReply r = (ChangeHostStateReply) bus.call(msg); if (!r.isSuccess()) { logger.warn(String.format("Failed to change host[uuid: %s] state(%s) by event(%s), %s", h.getUuid(), h.getState(), hostEvent, r.getError())); } else { logger.debug(String.format("Successfully changed host[uuid: %s] state(%s) by event(%s), new state is %s", h.getUuid(), h.getState(), hostEvent, r.getInventory().getState())); } } } }
final List<HostInventory> ctx = Arrays.asList(HostInventory.valueOf(self)); if (self.getState() == HostState.Enabled) { changeState(HostStateEvent.disable);
protected HostVO(HostVO vo) { this.setClusterUuid(vo.getClusterUuid()); this.setStatus(vo.getStatus()); this.setCreateDate(vo.getCreateDate()); this.setDescription(vo.getDescription()); this.setHypervisorType(vo.getHypervisorType()); this.setLastOpDate(vo.getLastOpDate()); this.setManagementIp(vo.getManagementIp()); this.setName(vo.getName()); this.setState(vo.getState()); this.setUuid(vo.getUuid()); this.setZoneUuid(vo.getZoneUuid()); this.setCapacity(vo.getCapacity()); } }
HostState originState = self.getState(); changeState(HostStateEvent.preMaintain); maintenanceHook(new Completion(msg, chain) {
protected HostInventory(HostVO vo) { this.setStatus(vo.getStatus().toString()); this.setCreateDate(vo.getCreateDate()); this.setDescription(vo.getDescription()); this.setHypervisorType(vo.getHypervisorType()); this.setLastOpDate(vo.getLastOpDate()); this.setManagementIp(vo.getManagementIp()); this.setName(vo.getName()); this.setState(vo.getState().toString()); this.setUuid(vo.getUuid()); this.setZoneUuid(vo.getZoneUuid()); this.setClusterUuid(vo.getClusterUuid()); if (vo.getCapacity() != null) { this.setTotalCpuCapacity(vo.getCapacity().getTotalCpu()); this.setAvailableCpuCapacity(vo.getCapacity().getAvailableCpu()); this.setTotalMemoryCapacity(vo.getCapacity().getTotalMemory()); this.setAvailableMemoryCapacity(vo.getCapacity().getAvailableMemory()); this.setCpuSockets(vo.getCapacity().getCpuSockets()); this.setCpuNum(vo.getCapacity().getCpuNum()); } }