/** * Hook to allow subclasses to add any parameters they would like to * expose to fencing implementations/scripts. Fencing methods are free * to use this map as they see fit -- notably, the shell script * implementation takes each entry, prepends 'target_', substitutes * '_' for '.', and adds it to the environment of the script. * * Subclass implementations should be sure to delegate to the superclass * implementation as well as adding their own keys. * * @param ret map which can be mutated to pass parameters to the fencer */ protected void addFencingParameters(Map<String, String> ret) { ret.put(ADDRESS_SUBST_KEY, String.valueOf(getAddress())); ret.put(HOST_SUBST_KEY, getAddress().getHostName()); ret.put(PORT_SUBST_KEY, String.valueOf(getAddress().getPort())); }
/** * @return a proxy to connect to the target HA Service. */ public HAServiceProtocol getProxy(Configuration conf, int timeoutMs) throws IOException { return getProxyForAddress(conf, timeoutMs, getAddress()); }
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; }
InetSocketAddress serviceAddr = target.getAddress(); String host = serviceAddr.getHostName();
/** * Returns a proxy to connect to the target HA service for health monitoring. * If {@link #getHealthMonitorAddress()} is implemented to return a non-null * address, then this proxy will connect to that address. Otherwise, the * returned proxy defaults to using {@link #getAddress()}, which means this * method's behavior is identical to {@link #getProxy(Configuration, int)}. * * @param conf Configuration * @param timeoutMs timeout in milliseconds * @return a proxy to connect to the target HA service for health monitoring * @throws IOException if there is an error */ public HAServiceProtocol getHealthMonitorProxy(Configuration conf, int timeoutMs) throws IOException { InetSocketAddress addr = getHealthMonitorAddress(); if (addr == null) { addr = getAddress(); } return getProxyForAddress(conf, timeoutMs, addr); }
InetSocketAddress serviceAddr = target.getAddress(); String hostname = serviceAddr.getHostName();
if (oldActive.getAddress().equals(localTarget.getAddress())) { LOG.info("Local node " + localTarget + " is already active. " + "No need to failover. Returning success."); for (HAServiceTarget remote : otherNodes) { if (remote.getAddress().equals(oldActive.getAddress())) { activeNode = remote; continue;
HAServiceProtocol toSvc; if (from.getAddress().equals(target.getAddress())) { throw new FailoverFailedException( "Can't failover a service to itself");
@Override protected InetSocketAddress getRpcAddressToBindTo() { int zkfcPort = getZkfcPort(conf); return new InetSocketAddress(localTarget.getAddress().getAddress(), zkfcPort); }
@Override protected byte[] targetToData(HAServiceTarget target) { InetSocketAddress addr = target.getAddress(); return ActiveNodeInfo.newBuilder() .setHostname(addr.getHostName()) .setPort(addr.getPort()) .setZkfcPort(target.getZKFCAddress().getPort()) .setNameserviceId(localNNTarget.getNameServiceId()) .setNamenodeId(localNNTarget.getNameNodeId()) .build() .toByteArray(); }
@Override protected InetSocketAddress getRpcAddressToBindTo() { int zkfcPort = getZkfcPort(conf); return new InetSocketAddress(localTarget.getAddress().getAddress(), zkfcPort); }
@Override protected InetSocketAddress getRpcAddressToBindTo() { int zkfcPort = getZkfcPort(conf); return new InetSocketAddress(localTarget.getAddress().getAddress(), zkfcPort); }
/** * @return a proxy to connect to the target HA Service. */ public HAServiceProtocol getProxy(Configuration conf, int timeoutMs) throws IOException { return getProxyForAddress(conf, timeoutMs, getAddress()); }
/** * @return a proxy to connect to the target HA Service. */ public HAServiceProtocol getProxy(Configuration conf, int timeoutMs) throws IOException { Configuration confCopy = new Configuration(conf); // Lower the timeout so we quickly fail to connect confCopy.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1); SocketFactory factory = NetUtils.getDefaultSocketFactory(confCopy); return new HAServiceProtocolClientSideTranslatorPB( getAddress(), confCopy, factory, timeoutMs); }
/** * @return a proxy to connect to the target HA Service. */ public HAServiceProtocol getProxy(Configuration conf, int timeoutMs) throws IOException { Configuration confCopy = new Configuration(conf); // Lower the timeout so we quickly fail to connect confCopy.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1); SocketFactory factory = NetUtils.getDefaultSocketFactory(confCopy); return new HAServiceProtocolClientSideTranslatorPB( getAddress(), confCopy, factory, timeoutMs); }
/** * @return a proxy to connect to the target HA Service. */ public HAServiceProtocol getProxy(Configuration conf, int timeoutMs) throws IOException { Configuration confCopy = new Configuration(conf); // Lower the timeout so we quickly fail to connect confCopy.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1); SocketFactory factory = NetUtils.getDefaultSocketFactory(confCopy); return new HAServiceProtocolClientSideTranslatorPB( getAddress(), confCopy, factory, timeoutMs); }
@Before public void clearMockState() { AlwaysSucceedFencer.fenceCalled = 0; AlwaysSucceedFencer.callArgs.clear(); AlwaysFailFencer.fenceCalled = 0; AlwaysFailFencer.callArgs.clear(); MOCK_TARGET = Mockito.mock(HAServiceTarget.class); Mockito.doReturn("my mock").when(MOCK_TARGET).toString(); Mockito.doReturn(new InetSocketAddress("host", 1234)) .when(MOCK_TARGET).getAddress(); }
@Before public void clearMockState() { AlwaysSucceedFencer.fenceCalled = 0; AlwaysSucceedFencer.callArgs.clear(); AlwaysFailFencer.fenceCalled = 0; AlwaysFailFencer.callArgs.clear(); MOCK_TARGET = Mockito.mock(HAServiceTarget.class); Mockito.doReturn("my mock").when(MOCK_TARGET).toString(); Mockito.doReturn(new InetSocketAddress("host", 1234)) .when(MOCK_TARGET).getAddress(); }
@Override protected byte[] targetToData(HAServiceTarget target) { InetSocketAddress addr = target.getAddress(); return ActiveNodeInfo.newBuilder() .setHostname(addr.getHostName()) .setPort(addr.getPort()) .setZkfcPort(target.getZKFCAddress().getPort()) .setNameserviceId(localNNTarget.getNameServiceId()) .setNamenodeId(localNNTarget.getNameNodeId()) .build() .toByteArray(); }
@Override protected byte[] targetToData(HAServiceTarget target) { InetSocketAddress addr = target.getAddress(); return ActiveNodeInfo.newBuilder() .setHostname(addr.getHostName()) .setPort(addr.getPort()) .setZkfcPort(target.getZKFCAddress().getPort()) .setNameserviceId(localNNTarget.getNameServiceId()) .setNamenodeId(localNNTarget.getNameNodeId()) .build() .toByteArray(); }