Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hadoop.classification.VisibleForTesting;

/**
* The {@link Router} periodically checks the state of a Namenode (usually on
* the same server) and reports their high availability (HA) state and
Expand Down Expand Up @@ -346,7 +348,8 @@ protected NamenodeStatusReport getNamenodeStatusReport() {
// Determine if NN is active
// TODO: dynamic timeout
if (localTargetHAProtocol == null) {
localTargetHAProtocol = localTarget.getProxy(conf, 30*1000);
localTargetHAProtocol = localTarget.getHealthMonitorProxy(conf, 30*1000);
LOG.debug("Get HA status with address {}", lifelineAddress);
}
HAServiceStatus status = localTargetHAProtocol.getServiceStatus();
report.setHAServiceState(status.getState());
Expand All @@ -373,6 +376,11 @@ protected NamenodeStatusReport getNamenodeStatusReport() {
return report;
}

@VisibleForTesting
NNHAServiceTarget getLocalTarget(){
return this.localTarget;
}

/**
* Get the description of the Namenode to monitor.
* @return Description of the Namenode to monitor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Test the service that heartbeats the state of the namenodes to the State
* Store.
*/
public class TestRouterNamenodeHeartbeat {

private static final Logger LOG =
LoggerFactory.getLogger(TestRouterNamenodeHeartbeat.class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The space doesn't look correct.


private static MiniRouterDFSCluster cluster;
private static ActiveNamenodeResolver namenodeResolver;
private static List<NamenodeHeartbeatService> services;
Expand Down Expand Up @@ -211,6 +216,54 @@ public void testHearbeat() throws InterruptedException, IOException {
assertEquals(NAMENODES[1], standby.getNamenodeId());
}

@Test
public void testNamenodeHeartbeatServiceHAServiceProtocolProxy(){
testNamenodeHeartbeatServiceHAServiceProtocol(
"test-ns", "nn", 1000, -1, -1, 1003,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing doesn't look correct.

"host01.test:1000", "host02.test:1000");
testNamenodeHeartbeatServiceHAServiceProtocol(
"test-ns", "nn", 1000, 1001, -1, 1003,
"host01.test:1001", "host02.test:1001");
testNamenodeHeartbeatServiceHAServiceProtocol(
"test-ns", "nn", 1000, -1, 1002, 1003,
"host01.test:1002", "host02.test:1002");
testNamenodeHeartbeatServiceHAServiceProtocol(
"test-ns", "nn", 1000, 1001, 1002, 1003,
"host01.test:1002", "host02.test:1002");
}

private void testNamenodeHeartbeatServiceHAServiceProtocol(
String nsId, String nnId,
int rpcPort, int servicePort,
int lifelinePort, int webAddressPort,
String expected1, String expected2) {
Configuration conf = generateNamenodeConfiguration(nsId, nnId,
rpcPort, servicePort, lifelinePort, webAddressPort);

Router testRouter = new Router();
testRouter.setConf(conf);

Collection<NamenodeHeartbeatService> heartbeatServices =
testRouter.createNamenodeHeartbeatServices();

assertEquals(2, heartbeatServices.size());

Iterator<NamenodeHeartbeatService> iterator = heartbeatServices.iterator();
NamenodeHeartbeatService service = iterator.next();
service.init(conf);
assertNotNull(service.getLocalTarget());
LOG.info("NamenodeHeartbeatService HealthMonitorAddress {}",
service.getLocalTarget().getHealthMonitorAddress().toString());
assertEquals(expected1, service.getLocalTarget().getHealthMonitorAddress().toString());

service = iterator.next();
Comment thread
goiri marked this conversation as resolved.
Outdated
service.init(conf);
assertNotNull(service.getLocalTarget());
LOG.info("NamenodeHeartbeatService HealthMonitorAddress {}",
service.getLocalTarget().getHealthMonitorAddress().toString());
assertEquals(expected2, service.getLocalTarget().getHealthMonitorAddress().toString());
}

@Test
public void testNamenodeHeartbeatServiceNNResolution() {
String nsId = "test-ns";
Expand Down Expand Up @@ -261,10 +314,14 @@ private Configuration generateNamenodeConfiguration(

conf.set(DFS_NAMENODE_RPC_ADDRESS_KEY + "." + suffix,
MockDomainNameResolver.DOMAIN + ":" + rpcPort);
conf.set(DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY + "." + suffix,
MockDomainNameResolver.DOMAIN + ":" + servicePort);
conf.set(DFS_NAMENODE_LIFELINE_RPC_ADDRESS_KEY + "." + suffix,
MockDomainNameResolver.DOMAIN + ":" + lifelinePort);
if (servicePort >= 0){
conf.set(DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY + "." + suffix,
MockDomainNameResolver.DOMAIN + ":" + servicePort);
}
if (lifelinePort >= 0){
conf.set(DFS_NAMENODE_LIFELINE_RPC_ADDRESS_KEY + "." + suffix,
MockDomainNameResolver.DOMAIN + ":" + lifelinePort);
}
conf.set(DFS_NAMENODE_HTTP_ADDRESS_KEY + "." + suffix,
MockDomainNameResolver.DOMAIN + ":" + webAddressPort);

Expand Down