Search in sources :

Example 1 with HAServiceTarget

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;
        }
    };
}
Also used : AddToClusterNodeLabelsResponse(org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsResponse) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) HAServiceTarget(org.apache.hadoop.ha.HAServiceTarget) IOException(java.io.IOException) ResourceManagerAdministrationProtocol(org.apache.hadoop.yarn.server.api.ResourceManagerAdministrationProtocol) HAServiceProtocol(org.apache.hadoop.ha.HAServiceProtocol) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AddToClusterNodeLabelsRequest(org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsRequest) HAServiceStatus(org.apache.hadoop.ha.HAServiceStatus) Before(org.junit.Before)

Example 2 with HAServiceTarget

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;
}
Also used : RMHAServiceTarget(org.apache.hadoop.yarn.client.RMHAServiceTarget) HAServiceProtocol(org.apache.hadoop.ha.HAServiceProtocol) HAServiceState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState) HAServiceTarget(org.apache.hadoop.ha.HAServiceTarget) RMHAServiceTarget(org.apache.hadoop.yarn.client.RMHAServiceTarget)

Example 3 with HAServiceTarget

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));
}
Also used : ZKFCProtocol(org.apache.hadoop.ha.ZKFCProtocol) PrintStream(java.io.PrintStream) HAServiceProtocol(org.apache.hadoop.ha.HAServiceProtocol) Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) HAServiceTarget(org.apache.hadoop.ha.HAServiceTarget) IOException(java.io.IOException) Before(org.junit.Before)

Example 4 with HAServiceTarget

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));
}
Also used : HAServiceProtocol(org.apache.hadoop.ha.HAServiceProtocol) NNHAServiceTarget(org.apache.hadoop.hdfs.tools.NNHAServiceTarget) HAServiceStatus(org.apache.hadoop.ha.HAServiceStatus) NNHAServiceTarget(org.apache.hadoop.hdfs.tools.NNHAServiceTarget) HAServiceTarget(org.apache.hadoop.ha.HAServiceTarget) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Nullable(javax.annotation.Nullable)

Aggregations

HAServiceProtocol (org.apache.hadoop.ha.HAServiceProtocol)4 HAServiceTarget (org.apache.hadoop.ha.HAServiceTarget)4 IOException (java.io.IOException)2 Configuration (org.apache.hadoop.conf.Configuration)2 HAServiceStatus (org.apache.hadoop.ha.HAServiceStatus)2 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)2 Before (org.junit.Before)2 PrintStream (java.io.PrintStream)1 Nullable (javax.annotation.Nullable)1 HAServiceState (org.apache.hadoop.ha.HAServiceProtocol.HAServiceState)1 ZKFCProtocol (org.apache.hadoop.ha.ZKFCProtocol)1 NNHAServiceTarget (org.apache.hadoop.hdfs.tools.NNHAServiceTarget)1 RMHAServiceTarget (org.apache.hadoop.yarn.client.RMHAServiceTarget)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 ResourceManagerAdministrationProtocol (org.apache.hadoop.yarn.server.api.ResourceManagerAdministrationProtocol)1 AddToClusterNodeLabelsRequest (org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsRequest)1 AddToClusterNodeLabelsResponse (org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsResponse)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1