public static APIChangeHostStateMsg __example__() { APIChangeHostStateMsg msg = new APIChangeHostStateMsg(); msg.setUuid(uuid()); msg.setStateEvent(HostStateEvent.enable.toString()); return msg; }
@Override public void preChangeClusterState(ClusterInventory inventory, ClusterStateEvent event, ClusterState nextState) throws ClusterException { if (!event.toString().equals(ClusterStateEvent.disable.toString()) && !event.toString().equals(ClusterStateEvent.enable.toString())) { logger.debug("Unsupported ClusterStateEvent: " + event + ", won't propgate to extensions of host"); return; } HostStateEvent hostEvent = HostStateEvent.valueOf(event.toString()); List<HostVO> vos = findHostUnderClusterByUuid(inventory.getUuid()); try { extpEmitter.preChange(vos, hostEvent); } catch (HostException e) { throw new ClusterException(e.getMessage(), e); } }
@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())); } } } }
private void validate(APIChangeHostStateMsg msg){ HostStatus hostStatus = Q.New(HostVO.class) .select(HostVO_.status) .eq(HostVO_.uuid,msg.getHostUuid()) .findValue(); if (hostStatus != HostStatus.Connected && msg.getStateEvent().equals(HostStateEvent.maintain.toString())){ throw new ApiMessageInterceptionException(operr("can not maintain host[uuid:%s, status:%s]which is not Connected", msg.getHostUuid(), hostStatus)); } } }
@Override public void run(final SyncTaskChain chain) { final APIChangeHostStateEvent evt = new APIChangeHostStateEvent(msg.getId()); HostStateEvent stateEvent = HostStateEvent.valueOf(msg.getStateEvent()); stateEvent = stateEvent == HostStateEvent.maintain ? HostStateEvent.preMaintain : stateEvent; try {