use of org.apache.hadoop.ha.HAServiceTarget in project hadoop by apache.
the class TestRMAdminCLI method configure.
@SuppressWarnings("static-access")
@Before
public void configure() throws IOException, YarnException {
remoteAdminServiceAccessed = false;
admin = mock(ResourceManagerAdministrationProtocol.class);
when(admin.addToClusterNodeLabels(any(AddToClusterNodeLabelsRequest.class))).thenAnswer(new Answer<AddToClusterNodeLabelsResponse>() {
@Override
public AddToClusterNodeLabelsResponse answer(InvocationOnMock invocation) throws Throwable {
remoteAdminServiceAccessed = true;
return AddToClusterNodeLabelsResponse.newInstance();
}
});
haadmin = mock(HAServiceProtocol.class);
when(haadmin.getServiceStatus()).thenReturn(new HAServiceStatus(HAServiceProtocol.HAServiceState.INITIALIZING));
final HAServiceTarget haServiceTarget = mock(HAServiceTarget.class);
when(haServiceTarget.getProxy(any(Configuration.class), anyInt())).thenReturn(haadmin);
rmAdminCLI = new RMAdminCLI(new Configuration()) {
@Override
protected ResourceManagerAdministrationProtocol createAdminProtocol() throws IOException {
return admin;
}
@Override
protected HAServiceTarget resolveTarget(String rmId) {
return haServiceTarget;
}
};
initDummyNodeLabelsManager();
rmAdminCLI.localNodeLabelsManager = dummyNodeLabelsManager;
YarnConfiguration conf = new YarnConfiguration();
conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
conf.set(YarnConfiguration.RM_HA_IDS, "rm1,rm2");
conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADDRESS, "rm1"), HOST_A + ":12345");
conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADMIN_ADDRESS, "rm1"), HOST_A + ":12346");
conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADDRESS, "rm2"), HOST_B + ":12345");
conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADMIN_ADDRESS, "rm2"), HOST_B + ":12346");
rmAdminCLIWithHAEnabled = new RMAdminCLI(conf) {
@Override
protected ResourceManagerAdministrationProtocol createAdminProtocol() throws IOException {
return admin;
}
@Override
protected HAServiceTarget resolveTarget(String rmId) {
HAServiceTarget target = super.resolveTarget(rmId);
HAServiceTarget spy = Mockito.spy(target);
// Override the target to return our mock protocol
try {
Mockito.doReturn(haadmin).when(spy).getProxy(Mockito.<Configuration>any(), Mockito.anyInt());
Mockito.doReturn(false).when(spy).isAutoFailoverEnabled();
} catch (IOException e) {
// mock setup doesn't really throw
throw new AssertionError(e);
}
return spy;
}
};
}
use of org.apache.hadoop.ha.HAServiceTarget in project hadoop by apache.
the class RMHAUtils method getHAState.
private static HAServiceState getHAState(YarnConfiguration yarnConf) throws Exception {
HAServiceTarget haServiceTarget;
int rpcTimeoutForChecks = yarnConf.getInt(CommonConfigurationKeys.HA_FC_CLI_CHECK_TIMEOUT_KEY, CommonConfigurationKeys.HA_FC_CLI_CHECK_TIMEOUT_DEFAULT);
yarnConf.set(CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY, yarnConf.get(YarnConfiguration.RM_PRINCIPAL, ""));
haServiceTarget = new RMHAServiceTarget(yarnConf);
HAServiceProtocol proto = haServiceTarget.getProxy(yarnConf, rpcTimeoutForChecks);
HAServiceState haState = proto.getServiceStatus().getState();
return haState;
}
use of org.apache.hadoop.ha.HAServiceTarget in project hadoop by apache.
the class TestDFSHAAdmin method setup.
@Before
public void setup() throws IOException {
mockProtocol = MockitoUtil.mockProtocol(HAServiceProtocol.class);
mockZkfcProtocol = MockitoUtil.mockProtocol(ZKFCProtocol.class);
tool = new DFSHAAdmin() {
@Override
protected HAServiceTarget resolveTarget(String nnId) {
HAServiceTarget target = super.resolveTarget(nnId);
HAServiceTarget spy = Mockito.spy(target);
// OVerride the target to return our mock protocol
try {
Mockito.doReturn(mockProtocol).when(spy).getProxy(Mockito.<Configuration>any(), Mockito.anyInt());
Mockito.doReturn(mockZkfcProtocol).when(spy).getZKFCProxy(Mockito.<Configuration>any(), Mockito.anyInt());
} catch (IOException e) {
// mock setup doesn't really throw
throw new AssertionError(e);
}
return spy;
}
};
tool.setConf(getHAConf());
tool.setErrOut(new PrintStream(errOutBytes));
tool.setOut(new PrintStream(outBytes));
}
use of org.apache.hadoop.ha.HAServiceTarget in project cdap by caskdata.
the class AbstractHDFSStats method getHAWebURL.
@Nullable
private URL getHAWebURL() throws IOException {
String activeNamenode = null;
String nameService = getNameService();
HdfsConfiguration hdfsConf = new HdfsConfiguration(conf);
String nameNodePrincipal = conf.get(DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY, "");
hdfsConf.set(CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY, nameNodePrincipal);
for (String nnId : DFSUtil.getNameNodeIds(conf, nameService)) {
HAServiceTarget haServiceTarget = new NNHAServiceTarget(hdfsConf, nameService, nnId);
HAServiceProtocol proxy = haServiceTarget.getProxy(hdfsConf, 10000);
HAServiceStatus serviceStatus = proxy.getServiceStatus();
if (HAServiceProtocol.HAServiceState.ACTIVE != serviceStatus.getState()) {
continue;
}
activeNamenode = DFSUtil.getNamenodeServiceAddr(hdfsConf, nameService, nnId);
}
if (activeNamenode == null) {
throw new IllegalStateException("Could not find an active namenode");
}
return rpcToHttpAddress(URI.create(activeNamenode));
}
Aggregations