private synchronized void becomeStandby() { LOG.info("ZK Election indicated that " + localTarget + " should become standby"); try { int timeout = FailoverController.getGracefulFenceTimeout(conf); localTarget.getProxy(conf, timeout).transitionToStandby(createReqInfo()); LOG.info("Successfully transitioned " + localTarget + " to standby state"); } catch (Exception e) { LOG.error("Couldn't transition " + localTarget + " to standby state", e); // TODO handle this. It's a likely case since we probably got fenced // at the same time. } serviceState = HAServiceState.STANDBY; }
private int getServiceState(final CommandLine cmd) throws IOException, ServiceFailedException { String[] argv = cmd.getArgs(); if (argv.length != 1) { errOut.println("getServiceState: incorrect number of arguments"); printUsage(errOut, "-getServiceState"); return -1; } HAServiceProtocol proto = resolveTarget(argv[0]).getProxy( getConf(), rpcTimeoutForChecks); out.println(proto.getServiceStatus().getState()); return 0; }
protected int getAllServiceState() { Collection<String> targetIds = getTargetIds(null); if (targetIds.isEmpty()) { errOut.println("Failed to get service IDs"); return -1; } for (String targetId : targetIds) { HAServiceTarget target = resolveTarget(targetId); String address = target.getAddress().getHostName() + ":" + target.getAddress().getPort(); try { HAServiceProtocol proto = target.getProxy(getConf(), rpcTimeoutForChecks); out.println(String.format("%-50s %-10s", address, proto .getServiceStatus().getState())); } catch (IOException e) { out.println(String.format("%-50s %-10s", address, "Failed to connect: " + e.getMessage())); } } return 0; }
boolean needFence = false; try { localTarget.getProxy(conf, timeout).transitionToStandby(createReqInfo()); LOG.info("Successfully ensured local node is in standby mode"); } catch (IOException ioe) {
/** * Try to get the HA state of the node at the given address. This * function is guaranteed to be "quick" -- ie it has a short timeout * and no retries. Its only purpose is to avoid fencing a node that * has already restarted. */ boolean tryGracefulFence(HAServiceTarget svc) { HAServiceProtocol proxy = null; try { proxy = svc.getProxy(gracefulFenceConf, gracefulFenceTimeout); proxy.transitionToStandby(createReqInfo()); return true; } catch (ServiceFailedException sfe) { LOG.warn("Unable to gracefully make {} standby ({})", svc, sfe.getMessage()); } catch (IOException ioe) { LOG.warn("Unable to gracefully make {} standby (unable to connect)", svc, ioe); } finally { if (proxy != null) { RPC.stopProxy(proxy); } } return false; }
private int checkHealth(final CommandLine cmd) throws IOException, ServiceFailedException { String[] argv = cmd.getArgs(); if (argv.length != 1) { errOut.println("checkHealth: incorrect number of arguments"); printUsage(errOut, "-checkHealth"); return -1; } HAServiceProtocol proto = resolveTarget(argv[0]).getProxy( getConf(), rpcTimeoutForChecks); try { HAServiceProtocolHelper.monitorHealth(proto, createReqInfo()); } catch (HealthCheckFailedException e) { errOut.println("Health check failed: " + e.getLocalizedMessage()); return -1; } return 0; }
private int transitionToActive(final CommandLine cmd) throws IOException, ServiceFailedException { String[] argv = cmd.getArgs(); if (argv.length != 1) { errOut.println("transitionToActive: incorrect number of arguments"); printUsage(errOut, "-transitionToActive"); return -1; } /* returns true if other target node is active or some exception occurred and forceActive was not set */ if(!cmd.hasOption(FORCEACTIVE)) { if(isOtherTargetNodeActive(argv[0], cmd.hasOption(FORCEACTIVE))) { return -1; } } HAServiceTarget target = resolveTarget(argv[0]); if (!checkManualStateManagementOK(target)) { return -1; } HAServiceProtocol proto = target.getProxy( getConf(), 0); HAServiceProtocolHelper.transitionToActive(proto, createReqInfo()); return 0; }
private int transitionToStandby(final CommandLine cmd) throws IOException, ServiceFailedException { String[] argv = cmd.getArgs(); if (argv.length != 1) { errOut.println("transitionToStandby: incorrect number of arguments"); printUsage(errOut, "-transitionToStandby"); return -1; } HAServiceTarget target = resolveTarget(argv[0]); if (!checkManualStateManagementOK(target)) { return -1; } HAServiceProtocol proto = target.getProxy( getConf(), 0); HAServiceProtocolHelper.transitionToStandby(proto, createReqInfo()); return 0; } /**
HAServiceProtocol proto = target.getProxy(getConf(), 5000); if(proto.getServiceStatus().getState() == HAServiceState.ACTIVE) { errOut.println("transitionToActive: Node " + targetId +" is already active");
private synchronized void becomeActive() throws ServiceFailedException { LOG.info("Trying to make " + localTarget + " active..."); try { HAServiceProtocolHelper.transitionToActive(localTarget.getProxy( conf, FailoverController.getRpcTimeoutToNewActive(conf)), createReqInfo());
try { HAServiceProtocolHelper.transitionToActive( toSvc.getProxy(conf, rpcTimeoutToNewActive), createReqInfo()); } catch (ServiceFailedException sfe) {
toSvc = target.getProxy(conf, rpcTimeoutToNewActive); toSvcStatus = toSvc.getServiceStatus(); } catch (IOException e) {
/** * Connect to the service to be monitored. Stubbed out for easier testing. */ protected HAServiceProtocol createProxy() throws IOException { return targetToMonitor.getProxy(conf, rpcTimeout); }
/** * Connect to the service to be monitored. Stubbed out for easier testing. */ protected HAServiceProtocol createProxy() throws IOException { return targetToMonitor.getProxy(conf, rpcTimeout); }
/** * Connect to the service to be monitored. Stubbed out for easier testing. */ protected HAServiceProtocol createProxy() throws IOException { return targetToMonitor.getProxy(conf, rpcTimeout); }
private int getServiceState(final CommandLine cmd) throws IOException, ServiceFailedException { String[] argv = cmd.getArgs(); if (argv.length != 1) { errOut.println("getServiceState: incorrect number of arguments"); printUsage(errOut, "-getServiceState"); return -1; } HAServiceProtocol proto = resolveTarget(argv[0]).getProxy( getConf(), rpcTimeoutForChecks); out.println(proto.getServiceStatus().getState()); return 0; }
private int getServiceState(final CommandLine cmd) throws IOException, ServiceFailedException { String[] argv = cmd.getArgs(); if (argv.length != 1) { errOut.println("getServiceState: incorrect number of arguments"); printUsage(errOut, "-getServiceState"); return -1; } HAServiceProtocol proto = resolveTarget(argv[0]).getProxy( getConf(), rpcTimeoutForChecks); out.println(proto.getServiceStatus().getState()); return 0; }
private int getServiceState(final CommandLine cmd) throws IOException, ServiceFailedException { String[] argv = cmd.getArgs(); if (argv.length != 1) { errOut.println("getServiceState: incorrect number of arguments"); printUsage(errOut, "-getServiceState"); return -1; } HAServiceProtocol proto = resolveTarget(argv[0]).getProxy( getConf(), rpcTimeoutForChecks); out.println(proto.getServiceStatus().getState()); return 0; }
private HAServiceProtocol makeMock(Configuration conf, int timeoutMs) { HAServiceProtocol service; if (!testWithProtoBufRPC) { service = new MockHAProtocolImpl(); } else { try { service = super.getProxy(conf, timeoutMs); } catch (IOException e) { return null; } } return Mockito.spy(service); }
private HAServiceProtocol makeMock(Configuration conf, int timeoutMs) { HAServiceProtocol service; if (!testWithProtoBufRPC) { service = new MockHAProtocolImpl(); } else { try { service = super.getProxy(conf, timeoutMs); } catch (IOException e) { return null; } } return Mockito.spy(service); }