Search in sources :

Example 1 with HAServiceStatus

use of org.apache.hadoop.ha.HAServiceStatus in project hadoop by apache.

the class AdminService method getServiceStatus.

/**
   * Return the HA status of this RM. This includes the current state and
   * whether the RM is ready to become active.
   *
   * @return {@link HAServiceStatus} of the current RM
   * @throws IOException if the caller does not have permissions
   */
@Override
public synchronized HAServiceStatus getServiceStatus() throws IOException {
    checkAccess("getServiceState");
    HAServiceState haState = rmContext.getHAServiceState();
    HAServiceStatus ret = new HAServiceStatus(haState);
    if (isRMActive() || haState == HAServiceProtocol.HAServiceState.STANDBY) {
        ret.setReadyToBecomeActive();
    } else {
        ret.setNotReadyToBecomeActive("State is " + haState);
    }
    return ret;
}
Also used : HAServiceStatus(org.apache.hadoop.ha.HAServiceStatus)

Example 2 with HAServiceStatus

use of org.apache.hadoop.ha.HAServiceStatus 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 3 with HAServiceStatus

use of org.apache.hadoop.ha.HAServiceStatus in project hadoop by apache.

the class TestRMAdminCLI method testGetAllServiceState.

@Test
public void testGetAllServiceState() throws Exception {
    HAServiceStatus standbyStatus = new HAServiceStatus(HAServiceState.STANDBY).setReadyToBecomeActive();
    Mockito.doReturn(standbyStatus).when(haadmin).getServiceStatus();
    ByteArrayOutputStream dataOut = new ByteArrayOutputStream();
    rmAdminCLIWithHAEnabled.setOut(new PrintStream(dataOut));
    String[] args = { "-getAllServiceState" };
    assertEquals(0, rmAdminCLIWithHAEnabled.run(args));
    assertTrue(dataOut.toString().contains(String.format("%-50s %-10s", (HOST_A + ":" + 12346), standbyStatus.getState())));
    assertTrue(dataOut.toString().contains(String.format("%-50s %-10s", (HOST_B + ":" + 12346), standbyStatus.getState())));
    rmAdminCLIWithHAEnabled.setOut(System.out);
}
Also used : PrintStream(java.io.PrintStream) HAServiceStatus(org.apache.hadoop.ha.HAServiceStatus) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 4 with HAServiceStatus

use of org.apache.hadoop.ha.HAServiceStatus in project hadoop by apache.

the class NameNode method getServiceStatus.

synchronized HAServiceStatus getServiceStatus() throws ServiceFailedException, AccessControlException {
    namesystem.checkSuperuserPrivilege();
    if (!haEnabled) {
        throw new ServiceFailedException("HA for namenode is not enabled");
    }
    if (state == null) {
        return new HAServiceStatus(HAServiceState.INITIALIZING);
    }
    HAServiceState retState = state.getServiceState();
    HAServiceStatus ret = new HAServiceStatus(retState);
    if (retState == HAServiceState.STANDBY) {
        if (namesystem.isInSafeMode()) {
            ret.setNotReadyToBecomeActive("The NameNode is in safemode. " + namesystem.getSafeModeTip());
        } else {
            ret.setReadyToBecomeActive();
        }
    } else if (retState == HAServiceState.ACTIVE) {
        ret.setReadyToBecomeActive();
    } else {
        ret.setNotReadyToBecomeActive("State is " + state);
    }
    return ret;
}
Also used : HAServiceState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState) HAServiceStatus(org.apache.hadoop.ha.HAServiceStatus) ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException)

Example 5 with HAServiceStatus

use of org.apache.hadoop.ha.HAServiceStatus in project cdap by caskdata.

the class YarnInfo method getHAWebURL.

/**
 * Should only be called when HA is enabled.
 */
private URL getHAWebURL() throws IOException {
    InetSocketAddress activeRM = null;
    Collection<String> rmIds = HAUtil.getRMHAIds(conf);
    if (rmIds.isEmpty()) {
        throw new IllegalStateException("Resource Manager HA web URL requested in non-HA mode.");
    }
    for (String rmId : rmIds) {
        try {
            YarnConfiguration yarnConf = new YarnConfiguration(conf);
            yarnConf.set(YarnConfiguration.RM_HA_ID, rmId);
            yarnConf.set(CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY, conf.get(YarnConfiguration.RM_PRINCIPAL, ""));
            RMHAServiceTarget rmhaServiceTarget = new RMHAServiceTarget(yarnConf);
            HAServiceProtocol proxy = rmhaServiceTarget.getProxy(yarnConf, 10000);
            HAServiceStatus serviceStatus = proxy.getServiceStatus();
            if (HAServiceProtocol.HAServiceState.ACTIVE != serviceStatus.getState()) {
                continue;
            }
            activeRM = rmhaServiceTarget.getAddress();
        } catch (ConnectException e) {
            LOG.trace("Connection refused when attempting to connect to ResourceManager {}. " + "Assuming that it is not available.", rmId);
        }
    }
    if (activeRM == null) {
        throw new IllegalStateException("Could not find an active resource manager");
    }
    return adminToWebappAddress(activeRM);
}
Also used : RMHAServiceTarget(org.apache.hadoop.yarn.client.RMHAServiceTarget) HAServiceProtocol(org.apache.hadoop.ha.HAServiceProtocol) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) InetSocketAddress(java.net.InetSocketAddress) HAServiceStatus(org.apache.hadoop.ha.HAServiceStatus) ConnectException(java.net.ConnectException)

Aggregations

HAServiceStatus (org.apache.hadoop.ha.HAServiceStatus)8 HAServiceProtocol (org.apache.hadoop.ha.HAServiceProtocol)3 ServiceException (com.google.protobuf.ServiceException)2 IOException (java.io.IOException)2 HAServiceTarget (org.apache.hadoop.ha.HAServiceTarget)2 GetServiceStatusResponseProto (org.apache.hadoop.ha.proto.HAServiceProtocolProtos.GetServiceStatusResponseProto)2 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 ConnectException (java.net.ConnectException)1 InetSocketAddress (java.net.InetSocketAddress)1 Nullable (javax.annotation.Nullable)1 Configuration (org.apache.hadoop.conf.Configuration)1 HAServiceState (org.apache.hadoop.ha.HAServiceProtocol.HAServiceState)1 ServiceFailedException (org.apache.hadoop.ha.ServiceFailedException)1 HAServiceStateProto (org.apache.hadoop.ha.proto.HAServiceProtocolProtos.HAServiceStateProto)1 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)1 NNHAServiceTarget (org.apache.hadoop.hdfs.tools.NNHAServiceTarget)1 RMHAServiceTarget (org.apache.hadoop.yarn.client.RMHAServiceTarget)1 ResourceManagerAdministrationProtocol (org.apache.hadoop.yarn.server.api.ResourceManagerAdministrationProtocol)1