boolean isServing() { try { return HostState.SERVING.equals(host.getState()); } catch (IOException e) { return false; } }
@Override public void setState(HostState stateValue) throws IOException { try { if (stateValue == HostState.OFFLINE) { zk.deleteIfExists(state.getPath()); } else { zk.setOrCreate(state.getPath(), stateValue.toString(), CreateMode.EPHEMERAL); } } catch (Exception e) { throw new IOException(e); } }
boolean isOffline() { try { return HostState.OFFLINE.equals(host.getState()); } catch (IOException e) { return false; } }
public static boolean isIdle(Host host) throws IOException { return HostState.IDLE.equals(host.getState()); }
public static boolean isServing(Host host) throws IOException { return HostState.SERVING.equals(host.getState()); }
private void startShutDownCountdown(long units, TimeUnit unit) { try { unit.sleep(units); HostState state = getStateSafe(); if (state == null || HostState.OFFLINE.equals(state)) { LOG.error("Partition Server was OFFLINE for " + units + " " + unit.toString()); stopSynchronized(); }else{ LOG.error("Shutdown cancelled, state is currently: " + state); } } catch (InterruptedException e) { LOG.error("Interrupted while performing shutdown countdown", e); } } };
protected void waitUntilHost(final HostState state, final Host host) throws InterruptedException { WaitUntil.orDie(() -> { try { return state.equals(host.getState()); } catch (IOException e) { throw new RuntimeException(e); } }); }
@Override public void run() { //TODO make these configurable long units = 10L; TimeUnit unit = TimeUnit.MINUTES; try { while (true) { HostState state = getStateSafe(); LOG.info("Current state: "+state); if (state == null || HostState.OFFLINE.equals(state)) { LOG.info("OFFLINE. Starting shutdown countdown"); startShutDownCountdown(units, unit); } unit.sleep(units); } }catch (Exception e){ LOG.error("Watcher thread encountered an error - thread will stop for safety", e); } }
private static boolean isServingAndAboutToServe(Host host) throws IOException { return host.getState().equals(HostState.SERVING) && host.getCurrentCommand() == null && host.getCommandQueue().size() == 0; }