Java Code Examples for org.apache.hadoop.ha.HAServiceProtocol.HAServiceState

The following examples show how to use org.apache.hadoop.ha.HAServiceProtocol.HAServiceState. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: big-c   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFailbackToFaultyServiceFails() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  Mockito.doThrow(new ServiceFailedException("Failed!"))
      .when(svc1.proxy).transitionToActive(anyReqInfo());
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  Mockito.doThrow(new ServiceFailedException("Failed!"))
      .when(svc2.proxy).transitionToActive(anyReqInfo());

  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, false, false);
    fail("Failover to already active service");
  } catch (FailoverFailedException ffe) {
    // Expected
  }

  assertEquals(HAServiceState.STANDBY, svc1.state);
  assertEquals(HAServiceState.STANDBY, svc2.state);
}
 
Example 2
Source Project: big-c   Source File: TestBackupNode.java    License: Apache License 2.0 6 votes vote down vote up
BackupNode startBackupNode(Configuration conf,
                           StartupOption startupOpt,
                           int idx) throws IOException {
  Configuration c = new HdfsConfiguration(conf);
  String dirs = getBackupNodeDir(startupOpt, idx);
  c.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, dirs);
  c.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY,
      "${" + DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY + "}");
  c.set(DFSConfigKeys.DFS_NAMENODE_BACKUP_ADDRESS_KEY,
      "127.0.0.1:0");
  c.set(DFSConfigKeys.DFS_NAMENODE_BACKUP_HTTP_ADDRESS_KEY,
          "127.0.0.1:0");

  BackupNode bn = (BackupNode)NameNode.createNameNode(
      new String[]{startupOpt.getName()}, c);
  assertTrue(bn.getRole() + " must be in SafeMode.", bn.isInSafeMode());
  assertTrue(bn.getRole() + " must be in StandbyState",
             bn.getNamesystem().getHAState()
               .equalsIgnoreCase(HAServiceState.STANDBY.name()));
  return bn;
}
 
Example 3
Source Project: big-c   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFailureToFenceOnFailbackFailsTheFailback() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  Mockito.doThrow(new IOException("Failed!"))
      .when(svc2.proxy).transitionToActive(anyReqInfo());
  svc1.fencer = svc2.fencer = setupFencer(AlwaysFailFencer.class.getName());
  AlwaysFailFencer.fenceCalled = 0;

  try {
    doFailover(svc1, svc2, false, false);
    fail("Failed over to service that won't transition to active");
  } catch (FailoverFailedException ffe) {
    // Expected
  }

  // We did not fence svc1 because it cooperated and we didn't force it, 
  // we failed to failover so we fenced svc2, we failed to fence svc2
  // so we did not failback to svc1, ie it's still standby.
  assertEquals(HAServiceState.STANDBY, svc1.state);
  assertEquals(1, AlwaysFailFencer.fenceCalled);
  assertSame(svc2, AlwaysFailFencer.fencedSvc);
}
 
Example 4
Source Project: hadoop   Source File: ResourceManager.java    License: Apache License 2.0 6 votes vote down vote up
synchronized void transitionToStandby(boolean initialize)
    throws Exception {
  if (rmContext.getHAServiceState() ==
      HAServiceProtocol.HAServiceState.STANDBY) {
    LOG.info("Already in standby state");
    return;
  }

  LOG.info("Transitioning to standby state");
  if (rmContext.getHAServiceState() ==
      HAServiceProtocol.HAServiceState.ACTIVE) {
    stopActiveServices();
    reinitialize(initialize);
  }
  rmContext.setHAServiceState(HAServiceProtocol.HAServiceState.STANDBY);
  LOG.info("Transitioned to standby state");
}
 
Example 5
Source Project: hadoop   Source File: RMHATestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected void startRMs(MockRM rm1, Configuration confForRM1, MockRM rm2,
    Configuration confForRM2) throws IOException {
  rm1.init(confForRM1);
  rm1.start();
  Assert.assertTrue(rm1.getRMContext().getHAServiceState()
      == HAServiceState.STANDBY);

  rm2.init(confForRM2);
  rm2.start();
  Assert.assertTrue(rm2.getRMContext().getHAServiceState()
      == HAServiceState.STANDBY);

  rm1.adminService.transitionToActive(requestInfo);
  Assert.assertTrue(rm1.getRMContext().getHAServiceState()
      == HAServiceState.ACTIVE);
}
 
Example 6
Source Project: big-c   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFailoverWithoutPermission() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  Mockito.doThrow(new AccessControlException("Access denied"))
      .when(svc1.proxy).getServiceStatus();
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  Mockito.doThrow(new AccessControlException("Access denied"))
      .when(svc2.proxy).getServiceStatus();
  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, false, false);
    fail("Can't failover when access is denied");
  } catch (FailoverFailedException ffe) {
    assertTrue(ffe.getCause().getMessage().contains("Access denied"));
  }
}
 
Example 7
Source Project: hadoop   Source File: TestBackupNode.java    License: Apache License 2.0 6 votes vote down vote up
BackupNode startBackupNode(Configuration conf,
                           StartupOption startupOpt,
                           int idx) throws IOException {
  Configuration c = new HdfsConfiguration(conf);
  String dirs = getBackupNodeDir(startupOpt, idx);
  c.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, dirs);
  c.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY,
      "${" + DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY + "}");
  c.set(DFSConfigKeys.DFS_NAMENODE_BACKUP_ADDRESS_KEY,
      "127.0.0.1:0");
  c.set(DFSConfigKeys.DFS_NAMENODE_BACKUP_HTTP_ADDRESS_KEY,
          "127.0.0.1:0");

  BackupNode bn = (BackupNode)NameNode.createNameNode(
      new String[]{startupOpt.getName()}, c);
  assertTrue(bn.getRole() + " must be in SafeMode.", bn.isInSafeMode());
  assertTrue(bn.getRole() + " must be in StandbyState",
             bn.getNamesystem().getHAState()
               .equalsIgnoreCase(HAServiceState.STANDBY.name()));
  return bn;
}
 
Example 8
Source Project: hadoop   Source File: TestBPOfferService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set up a mock NN with the bare minimum for a DN to register to it.
 */
private DatanodeProtocolClientSideTranslatorPB setupNNMock(int nnIdx)
    throws Exception {
  DatanodeProtocolClientSideTranslatorPB mock =
      Mockito.mock(DatanodeProtocolClientSideTranslatorPB.class);
  Mockito.doReturn(new NamespaceInfo(1, FAKE_CLUSTERID, FAKE_BPID, 0))
      .when(mock).versionRequest();
  
  Mockito.doReturn(DFSTestUtil.getLocalDatanodeRegistration())
    .when(mock).registerDatanode(Mockito.any(DatanodeRegistration.class));
  
  Mockito.doAnswer(new HeartbeatAnswer(nnIdx))
    .when(mock).sendHeartbeat(
        Mockito.any(DatanodeRegistration.class),
        Mockito.any(StorageReport[].class),
        Mockito.anyLong(),
        Mockito.anyLong(),
        Mockito.anyInt(),
        Mockito.anyInt(),
        Mockito.anyInt(),
        Mockito.any(VolumeFailureSummary.class));
  mockHaStatuses[nnIdx] = new NNHAStatusHeartbeat(HAServiceState.STANDBY, 0);
  return mock;
}
 
Example 9
Source Project: big-c   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFencingFailureDuringFailover() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  svc1.fencer = svc2.fencer = setupFencer(AlwaysFailFencer.class.getName());

  AlwaysFailFencer.fenceCalled = 0;
  try {
    doFailover(svc1, svc2, true, false);
    fail("Failed over even though fencing requested and failed");
  } catch (FailoverFailedException ffe) {
    // Expected
  }

  // If fencing was requested and it failed we don't try to make
  // svc2 active anyway, and we don't failback to svc1.
  assertEquals(1, AlwaysFailFencer.fenceCalled);
  assertSame(svc1, AlwaysFailFencer.fencedSvc);
  assertEquals(HAServiceState.STANDBY, svc1.state);
  assertEquals(HAServiceState.STANDBY, svc2.state);
}
 
Example 10
Source Project: big-c   Source File: DummyHAService.java    License: Apache License 2.0 6 votes vote down vote up
DummyHAService(HAServiceState state, InetSocketAddress address,
    boolean testWithProtoBufRPC) {
  this.state = state;
  this.testWithProtoBufRPC = testWithProtoBufRPC;
  if (testWithProtoBufRPC) {
    this.address = startAndGetRPCServerAddress(address);
  } else {
    this.address = address;
  }
  Configuration conf = new Configuration();
  this.proxy = makeMock(conf, HA_HM_RPC_TIMEOUT_DEFAULT);
  try {
    conf.set(DUMMY_FENCE_KEY, DummyFencer.class.getName());
    this.fencer = Mockito.spy(
        NodeFencer.create(conf, DUMMY_FENCE_KEY));
  } catch (BadFencingConfigurationException e) {
    throw new RuntimeException(e);
  }
  synchronized (instances) {
    instances.add(this);
    this.index = instances.size();
  }
}
 
Example 11
Source Project: big-c   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFailoverToUnreadyService() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  Mockito.doReturn(STATE_NOT_READY).when(svc2.proxy)
      .getServiceStatus();
  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, false, false);
    fail("Can't failover to a service that's not ready");
  } catch (FailoverFailedException ffe) {
    // Expected
    if (!ffe.getMessage().contains("injected not ready")) {
      throw ffe;
    }
  }

  assertEquals(HAServiceState.ACTIVE, svc1.state);
  assertEquals(HAServiceState.STANDBY, svc2.state);

  // Forcing it means we ignore readyToBecomeActive
  doFailover(svc1, svc2, false, true);
  assertEquals(HAServiceState.STANDBY, svc1.state);
  assertEquals(HAServiceState.ACTIVE, svc2.state);
}
 
Example 12
Source Project: hadoop   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFailoverFromActiveToActive() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  DummyHAService svc2 = new DummyHAService(HAServiceState.ACTIVE, svc2Addr);
  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, false, false);
    fail("Can't failover to an already active service");
  } catch (FailoverFailedException ffe) {
    // Expected
  }

  assertEquals(HAServiceState.ACTIVE, svc1.state);
  assertEquals(HAServiceState.ACTIVE, svc2.state);
}
 
Example 13
Source Project: hadoop   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFailoverWithoutPermission() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  Mockito.doThrow(new AccessControlException("Access denied"))
      .when(svc1.proxy).getServiceStatus();
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  Mockito.doThrow(new AccessControlException("Access denied"))
      .when(svc2.proxy).getServiceStatus();
  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, false, false);
    fail("Can't failover when access is denied");
  } catch (FailoverFailedException ffe) {
    assertTrue(ffe.getCause().getMessage().contains("Access denied"));
  }
}
 
Example 14
Source Project: hadoop   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFailoverToUnreadyService() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  Mockito.doReturn(STATE_NOT_READY).when(svc2.proxy)
      .getServiceStatus();
  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, false, false);
    fail("Can't failover to a service that's not ready");
  } catch (FailoverFailedException ffe) {
    // Expected
    if (!ffe.getMessage().contains("injected not ready")) {
      throw ffe;
    }
  }

  assertEquals(HAServiceState.ACTIVE, svc1.state);
  assertEquals(HAServiceState.STANDBY, svc2.state);

  // Forcing it means we ignore readyToBecomeActive
  doFailover(svc1, svc2, false, true);
  assertEquals(HAServiceState.STANDBY, svc1.state);
  assertEquals(HAServiceState.ACTIVE, svc2.state);
}
 
Example 15
Source Project: hadoop   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFailoverToUnhealthyServiceFailsAndFailsback() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  Mockito.doThrow(new HealthCheckFailedException("Failed!"))
      .when(svc2.proxy).monitorHealth();
  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, false, false);
    fail("Failover to unhealthy service");
  } catch (FailoverFailedException ffe) {
    // Expected
  }
  assertEquals(HAServiceState.ACTIVE, svc1.state);
  assertEquals(HAServiceState.STANDBY, svc2.state);
}
 
Example 16
Source Project: hadoop   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFailoverToNonExistantServiceFails() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  DummyHAService svc2 = spy(new DummyHAService(null, svc2Addr));
  Mockito.doThrow(new IOException("Failed to connect"))
    .when(svc2).getProxy(Mockito.<Configuration>any(),
        Mockito.anyInt());
  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, false, false);
    fail("Failed over to a non-existant standby");
  } catch (FailoverFailedException ffe) {
    // Expected
  }

  assertEquals(HAServiceState.ACTIVE, svc1.state);
}
 
Example 17
Source Project: hadoop   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFailoverToFaultyServiceFailsbackOK() throws Exception {
  DummyHAService svc1 = spy(new DummyHAService(HAServiceState.ACTIVE, svc1Addr));
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  Mockito.doThrow(new ServiceFailedException("Failed!"))
      .when(svc2.proxy).transitionToActive(anyReqInfo());
  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, false, false);
    fail("Failover to already active service");
  } catch (FailoverFailedException ffe) {
    // Expected
  }

  // svc1 went standby then back to active
  verify(svc1.proxy).transitionToStandby(anyReqInfo());
  verify(svc1.proxy).transitionToActive(anyReqInfo());
  assertEquals(HAServiceState.ACTIVE, svc1.state);
  assertEquals(HAServiceState.STANDBY, svc2.state);
}
 
Example 18
Source Project: hadoop   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWeDontFailbackIfActiveWasFenced() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  Mockito.doThrow(new ServiceFailedException("Failed!"))
      .when(svc2.proxy).transitionToActive(anyReqInfo());
  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, true, false);
    fail("Failed over to service that won't transition to active");
  } catch (FailoverFailedException ffe) {
    // Expected
  }

  // We failed to failover and did not failback because we fenced
  // svc1 (we forced it), therefore svc1 and svc2 should be standby.
  assertEquals(HAServiceState.STANDBY, svc1.state);
  assertEquals(HAServiceState.STANDBY, svc2.state);
}
 
Example 19
Source Project: big-c   Source File: TestFailoverController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWeDontFailbackIfActiveWasFenced() throws Exception {
  DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
  DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
  Mockito.doThrow(new ServiceFailedException("Failed!"))
      .when(svc2.proxy).transitionToActive(anyReqInfo());
  svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());

  try {
    doFailover(svc1, svc2, true, false);
    fail("Failed over to service that won't transition to active");
  } catch (FailoverFailedException ffe) {
    // Expected
  }

  // We failed to failover and did not failback because we fenced
  // svc1 (we forced it), therefore svc1 and svc2 should be standby.
  assertEquals(HAServiceState.STANDBY, svc1.state);
  assertEquals(HAServiceState.STANDBY, svc2.state);
}
 
Example 20
Source Project: big-c   Source File: MiniZKFCCluster.java    License: Apache License 2.0 6 votes vote down vote up
public MiniZKFCCluster(Configuration conf, ZooKeeperServer zks) {
  this.conf = conf;
  // Fast check interval so tests run faster
  conf.setInt(CommonConfigurationKeys.HA_HM_CHECK_INTERVAL_KEY, 50);
  conf.setInt(CommonConfigurationKeys.HA_HM_CONNECT_RETRY_INTERVAL_KEY, 50);
  conf.setInt(CommonConfigurationKeys.HA_HM_SLEEP_AFTER_DISCONNECT_KEY, 50);
  svcs = new DummyHAService[2];
  svcs[0] = new DummyHAService(HAServiceState.INITIALIZING,
      new InetSocketAddress("svc1", 1234));
  svcs[0].setSharedResource(sharedResource);
  svcs[1] = new DummyHAService(HAServiceState.INITIALIZING,
      new InetSocketAddress("svc2", 1234));
  svcs[1].setSharedResource(sharedResource);
  
  this.ctx = new TestContext();
  this.zks = zks;
}
 
Example 21
Source Project: hadoop   Source File: MiniZKFCCluster.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set up two services and their failover controllers. svc1 is started
 * first, so that it enters ACTIVE state, and then svc2 is started,
 * which enters STANDBY
 */
public void start() throws Exception {
  // Format the base dir, should succeed
  thrs = new DummyZKFCThread[2];
  thrs[0] = new DummyZKFCThread(ctx, svcs[0]);
  assertEquals(0, thrs[0].zkfc.run(new String[]{"-formatZK"}));
  ctx.addThread(thrs[0]);
  thrs[0].start();
  
  LOG.info("Waiting for svc0 to enter active state");
  waitForHAState(0, HAServiceState.ACTIVE);
  
  LOG.info("Adding svc1");
  thrs[1] = new DummyZKFCThread(ctx, svcs[1]);
  thrs[1].start();
  waitForHAState(1, HAServiceState.STANDBY);
}
 
Example 22
Source Project: big-c   Source File: TestHealthMonitor.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setupHM() throws InterruptedException, IOException {
  Configuration conf = new Configuration();
  conf.setInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1);
  conf.setInt(CommonConfigurationKeys.HA_HM_CHECK_INTERVAL_KEY, 50);
  conf.setInt(CommonConfigurationKeys.HA_HM_CONNECT_RETRY_INTERVAL_KEY, 50);
  conf.setInt(CommonConfigurationKeys.HA_HM_SLEEP_AFTER_DISCONNECT_KEY, 50);
  
  svc = new DummyHAService(HAServiceState.ACTIVE,
      new InetSocketAddress("0.0.0.0", 0), true);
  hm = new HealthMonitor(conf, svc) {
    @Override
    protected HAServiceProtocol createProxy() throws IOException {
      createProxyCount.incrementAndGet();
      if (throwOOMEOnCreate) {
        throw new OutOfMemoryError("oome");
      }
      return super.createProxy();
    }
  };
  LOG.info("Starting health monitor");
  hm.start();
  
  LOG.info("Waiting for HEALTHY signal");    
  waitForState(hm, HealthMonitor.State.SERVICE_HEALTHY);
}
 
Example 23
Source Project: big-c   Source File: RMHATestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected void startRMs(MockRM rm1, Configuration confForRM1, MockRM rm2,
    Configuration confForRM2) throws IOException {
  rm1.init(confForRM1);
  rm1.start();
  Assert.assertTrue(rm1.getRMContext().getHAServiceState()
      == HAServiceState.STANDBY);

  rm2.init(confForRM2);
  rm2.start();
  Assert.assertTrue(rm2.getRMContext().getHAServiceState()
      == HAServiceState.STANDBY);

  rm1.adminService.transitionToActive(requestInfo);
  Assert.assertTrue(rm1.getRMContext().getHAServiceState()
      == HAServiceState.ACTIVE);
}
 
Example 24
Source Project: hadoop   Source File: DummyHAService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void transitionToStandby(StateChangeRequestInfo req) throws ServiceFailedException,
    AccessControlException, IOException {
  checkUnreachable();
  if (failToBecomeStandby) {
    throw new ServiceFailedException("injected failure");
  }
  if (sharedResource != null) {
    sharedResource.release(DummyHAService.this);
  }
  state = HAServiceState.STANDBY;
}
 
Example 25
Source Project: big-c   Source File: DummyHAService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public HAServiceStatus getServiceStatus() throws IOException {
  checkUnreachable();
  HAServiceStatus ret = new HAServiceStatus(state);
  if (state == HAServiceState.STANDBY || state == HAServiceState.ACTIVE) {
    ret.setReadyToBecomeActive();
  }
  return ret;
}
 
Example 26
Source Project: hadoop   Source File: TestRMHA.java    License: Apache License 2.0 5 votes vote down vote up
private void checkStandbyRMFunctionality() throws IOException {
  assertEquals(STATE_ERR, HAServiceState.STANDBY,
      rm.adminService.getServiceStatus().getState());
  assertFalse("Active RM services are started",
      rm.areActiveServicesRunning());
  assertTrue("RM is not ready to become active",
      rm.adminService.getServiceStatus().isReadyToBecomeActive());
}
 
Example 27
Source Project: hadoop   Source File: TestRMFailover.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAutomaticFailover()
    throws YarnException, InterruptedException, IOException {
  conf.set(YarnConfiguration.RM_CLUSTER_ID, "yarn-test-cluster");
  conf.set(YarnConfiguration.RM_ZK_ADDRESS, hostPort);
  conf.setInt(YarnConfiguration.RM_ZK_TIMEOUT_MS, 2000);

  cluster.init(conf);
  cluster.start();
  assertFalse("RM never turned active", -1 == cluster.getActiveRMIndex());
  verifyConnections();

  failover();
  verifyConnections();

  failover();
  verifyConnections();

  // Make the current Active handle an RMFatalEvent,
  // so it transitions to standby.
  ResourceManager rm = cluster.getResourceManager(
      cluster.getActiveRMIndex());
  rm.handleTransitionToStandBy();
  int maxWaitingAttempts = 2000;
  while (maxWaitingAttempts-- > 0 ) {
    if (rm.getRMContext().getHAServiceState() == HAServiceState.STANDBY) {
      break;
    }
    Thread.sleep(1);
  }
  Assert.assertFalse("RM didn't transition to Standby ",
      maxWaitingAttempts == 0);
  verifyConnections();
}
 
Example 28
Source Project: big-c   Source File: TestRMFailover.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAutomaticFailover()
    throws YarnException, InterruptedException, IOException {
  conf.set(YarnConfiguration.RM_CLUSTER_ID, "yarn-test-cluster");
  conf.set(YarnConfiguration.RM_ZK_ADDRESS, hostPort);
  conf.setInt(YarnConfiguration.RM_ZK_TIMEOUT_MS, 2000);

  cluster.init(conf);
  cluster.start();
  assertFalse("RM never turned active", -1 == cluster.getActiveRMIndex());
  verifyConnections();

  failover();
  verifyConnections();

  failover();
  verifyConnections();

  // Make the current Active handle an RMFatalEvent,
  // so it transitions to standby.
  ResourceManager rm = cluster.getResourceManager(
      cluster.getActiveRMIndex());
  rm.handleTransitionToStandBy();
  int maxWaitingAttempts = 2000;
  while (maxWaitingAttempts-- > 0 ) {
    if (rm.getRMContext().getHAServiceState() == HAServiceState.STANDBY) {
      break;
    }
    Thread.sleep(1);
  }
  Assert.assertFalse("RM didn't transition to Standby ",
      maxWaitingAttempts == 0);
  verifyConnections();
}
 
Example 29
Source Project: hadoop   Source File: NameNode.java    License: Apache License 2.0 5 votes vote down vote up
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) {
    String safemodeTip = namesystem.getSafeModeTip();
    if (!safemodeTip.isEmpty()) {
      ret.setNotReadyToBecomeActive(
          "The NameNode is in safemode. " +
          safemodeTip);
    } else {
      ret.setReadyToBecomeActive();
    }
  } else if (retState == HAServiceState.ACTIVE) {
    ret.setReadyToBecomeActive();
  } else {
    ret.setNotReadyToBecomeActive("State is " + state);
  }
  return ret;
}
 
Example 30
Source Project: big-c   Source File: TestDFSHAAdminMiniCluster.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test case to check whether both the name node is active or not
 * @throws Exception
 */
@Test
public void testTransitionToActiveWhenOtherNamenodeisActive() 
    throws Exception {
  NameNode nn1 = cluster.getNameNode(0);
  NameNode nn2 = cluster.getNameNode(1);
  if(nn1.getState() != null && !nn1.getState().
      equals(HAServiceState.STANDBY.name()) ) {
    cluster.transitionToStandby(0);
  }
  if(nn2.getState() != null && !nn2.getState().
      equals(HAServiceState.STANDBY.name()) ) {
    cluster.transitionToStandby(1);
  }
  //Making sure both the namenode are in standby state
  assertTrue(nn1.isStandbyState());
  assertTrue(nn2.isStandbyState());
  // Triggering the transition for both namenode to Active
  runTool("-transitionToActive", "nn1");
  runTool("-transitionToActive", "nn2");

  assertFalse("Both namenodes cannot be active", nn1.isActiveState() 
      && nn2.isActiveState());
 
  /*  In this test case, we have deliberately shut down nn1 and this will
      cause HAAAdmin#isOtherTargetNodeActive to throw an Exception 
      and transitionToActive for nn2 with  forceActive switch will succeed 
      even with Exception  */
  cluster.shutdownNameNode(0);
  if(nn2.getState() != null && !nn2.getState().
      equals(HAServiceState.STANDBY.name()) ) {
    cluster.transitionToStandby(1);
  }
  //Making sure both the namenode (nn2) is in standby state
  assertTrue(nn2.isStandbyState());
  assertFalse(cluster.isNameNodeUp(0));
  
  runTool("-transitionToActive", "nn2", "--forceactive");
  assertTrue("Namenode nn2 should be active", nn2.isActiveState());
}