Search in sources :

Example 1 with ReconfigurationUtil

use of org.apache.hadoop.conf.ReconfigurationUtil in project hadoop by apache.

the class TestDFSAdmin method testNameNodeGetReconfigurationStatus.

@Test(timeout = 30000)
public void testNameNodeGetReconfigurationStatus() throws IOException, InterruptedException, TimeoutException {
    ReconfigurationUtil ru = mock(ReconfigurationUtil.class);
    namenode.setReconfigurationUtil(ru);
    final String address = namenode.getHostAndPort();
    List<ReconfigurationUtil.PropertyChange> changes = new ArrayList<>();
    changes.add(new ReconfigurationUtil.PropertyChange(DFS_HEARTBEAT_INTERVAL_KEY, String.valueOf(6), namenode.getConf().get(DFS_HEARTBEAT_INTERVAL_KEY)));
    changes.add(new ReconfigurationUtil.PropertyChange("randomKey", "new123", "old456"));
    when(ru.parseChangedProperties(any(Configuration.class), any(Configuration.class))).thenReturn(changes);
    assertThat(admin.startReconfiguration("namenode", address), is(0));
    final List<String> outs = Lists.newArrayList();
    final List<String> errs = Lists.newArrayList();
    awaitReconfigurationFinished("namenode", address, outs, errs);
    // verify change
    assertEquals(DFS_HEARTBEAT_INTERVAL_KEY + " has wrong value", 6, namenode.getConf().getLong(DFS_HEARTBEAT_INTERVAL_KEY, DFS_HEARTBEAT_INTERVAL_DEFAULT));
    assertEquals(DFS_HEARTBEAT_INTERVAL_KEY + " has wrong value", 6, namenode.getNamesystem().getBlockManager().getDatanodeManager().getHeartbeatInterval());
    int offset = 1;
    assertThat(outs.get(offset), containsString("SUCCESS: Changed property " + DFS_HEARTBEAT_INTERVAL_KEY));
    assertThat(outs.get(offset + 1), is(allOf(containsString("From:"), containsString("3"))));
    assertThat(outs.get(offset + 2), is(allOf(containsString("To:"), containsString("6"))));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) ReconfigurationUtil(org.apache.hadoop.conf.ReconfigurationUtil) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 2 with ReconfigurationUtil

use of org.apache.hadoop.conf.ReconfigurationUtil in project hadoop by apache.

the class TestDFSAdmin method testDataNodeGetReconfigurationStatus.

/**
   * Test reconfiguration and check the status outputs.
   * @param expectedSuccuss set true if the reconfiguration task should success.
   * @throws IOException
   * @throws InterruptedException
   * @throws TimeoutException
   */
private void testDataNodeGetReconfigurationStatus(boolean expectedSuccuss) throws IOException, InterruptedException, TimeoutException {
    ReconfigurationUtil ru = mock(ReconfigurationUtil.class);
    datanode.setReconfigurationUtil(ru);
    List<ReconfigurationUtil.PropertyChange> changes = new ArrayList<>();
    File newDir = new File(cluster.getDataDirectory(), "data_new");
    if (expectedSuccuss) {
        newDir.mkdirs();
    } else {
        // Inject failure.
        newDir.createNewFile();
    }
    changes.add(new ReconfigurationUtil.PropertyChange(DFS_DATANODE_DATA_DIR_KEY, newDir.toString(), datanode.getConf().get(DFS_DATANODE_DATA_DIR_KEY)));
    changes.add(new ReconfigurationUtil.PropertyChange("randomKey", "new123", "old456"));
    when(ru.parseChangedProperties(any(Configuration.class), any(Configuration.class))).thenReturn(changes);
    final int port = datanode.getIpcPort();
    final String address = "localhost:" + port;
    assertThat(admin.startReconfiguration("datanode", address), is(0));
    final List<String> outs = Lists.newArrayList();
    final List<String> errs = Lists.newArrayList();
    awaitReconfigurationFinished("datanode", address, outs, errs);
    if (expectedSuccuss) {
        assertThat(outs.size(), is(4));
    } else {
        assertThat(outs.size(), is(6));
    }
    List<StorageLocation> locations = DataNode.getStorageLocations(datanode.getConf());
    if (expectedSuccuss) {
        assertThat(locations.size(), is(1));
        assertThat(new File(locations.get(0).getUri()), is(newDir));
        // Verify the directory is appropriately formatted.
        assertTrue(new File(newDir, Storage.STORAGE_DIR_CURRENT).isDirectory());
    } else {
        assertTrue(locations.isEmpty());
    }
    int offset = 1;
    if (expectedSuccuss) {
        assertThat(outs.get(offset), containsString("SUCCESS: Changed property " + DFS_DATANODE_DATA_DIR_KEY));
    } else {
        assertThat(outs.get(offset), containsString("FAILED: Change property " + DFS_DATANODE_DATA_DIR_KEY));
    }
    assertThat(outs.get(offset + 1), is(allOf(containsString("From:"), containsString("data1"), containsString("data2"))));
    assertThat(outs.get(offset + 2), is(not(anyOf(containsString("data1"), containsString("data2")))));
    assertThat(outs.get(offset + 2), is(allOf(containsString("To"), containsString("data_new"))));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) ReconfigurationUtil(org.apache.hadoop.conf.ReconfigurationUtil) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) StorageLocation(org.apache.hadoop.hdfs.server.datanode.StorageLocation) File(java.io.File)

Aggregations

ArrayList (java.util.ArrayList)2 Configuration (org.apache.hadoop.conf.Configuration)2 ReconfigurationUtil (org.apache.hadoop.conf.ReconfigurationUtil)2 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 File (java.io.File)1 StorageLocation (org.apache.hadoop.hdfs.server.datanode.StorageLocation)1 Test (org.junit.Test)1