Search in sources :

Example 1 with PropertyChange

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

the class ReconfigurationProtocolServerSideUtils method getReconfigurationStatus.

public static GetReconfigurationStatusResponseProto getReconfigurationStatus(ReconfigurationTaskStatus status) {
    GetReconfigurationStatusResponseProto.Builder builder = GetReconfigurationStatusResponseProto.newBuilder();
    builder.setStartTime(status.getStartTime());
    if (status.stopped()) {
        builder.setEndTime(status.getEndTime());
        assert status.getStatus() != null;
        for (Map.Entry<PropertyChange, Optional<String>> result : status.getStatus().entrySet()) {
            GetReconfigurationStatusConfigChangeProto.Builder changeBuilder = GetReconfigurationStatusConfigChangeProto.newBuilder();
            PropertyChange change = result.getKey();
            changeBuilder.setName(change.prop);
            changeBuilder.setOldValue(change.oldVal != null ? change.oldVal : "");
            if (change.newVal != null) {
                changeBuilder.setNewValue(change.newVal);
            }
            if (result.getValue().isPresent()) {
                // Get full stack trace.
                changeBuilder.setErrorMessage(result.getValue().get());
            }
            builder.addChanges(changeBuilder);
        }
    }
    return builder.build();
}
Also used : PropertyChange(org.apache.hadoop.conf.ReconfigurationUtil.PropertyChange) Optional(com.google.common.base.Optional) GetReconfigurationStatusResponseProto(org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.GetReconfigurationStatusResponseProto) Map(java.util.Map) GetReconfigurationStatusConfigChangeProto(org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.GetReconfigurationStatusConfigChangeProto)

Example 2 with PropertyChange

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

the class DFSAdmin method getReconfigurationStatus.

int getReconfigurationStatus(final String nodeType, final String address, final PrintStream out, final PrintStream err) throws IOException {
    String outMsg = null;
    String errMsg = null;
    ReconfigurationTaskStatus status = null;
    try {
        status = getReconfigurationStatusDispatch(nodeType, address, out, err);
        outMsg = String.format("Reconfiguring status for node [%s]: ", address);
    } catch (IOException e) {
        errMsg = String.format("Node [%s] reloading configuration: %s.", address, e.toString());
    }
    if (errMsg != null) {
        err.println(errMsg);
        return 1;
    } else {
        out.print(outMsg);
    }
    if (status != null) {
        if (!status.hasTask()) {
            out.println("no task was found.");
            return 0;
        }
        out.print("started at " + new Date(status.getStartTime()));
        if (!status.stopped()) {
            out.println(" and is still running.");
            return 0;
        }
        out.println(" and finished at " + new Date(status.getEndTime()).toString() + ".");
        if (status.getStatus() == null) {
            // Nothing to report.
            return 0;
        }
        for (Map.Entry<PropertyChange, Optional<String>> result : status.getStatus().entrySet()) {
            if (!result.getValue().isPresent()) {
                out.printf("SUCCESS: Changed property %s%n\tFrom: \"%s\"%n\tTo: \"%s\"%n", result.getKey().prop, result.getKey().oldVal, result.getKey().newVal);
            } else {
                final String errorMsg = result.getValue().get();
                out.printf("FAILED: Change property %s%n\tFrom: \"%s\"%n\tTo: \"%s\"%n", result.getKey().prop, result.getKey().oldVal, result.getKey().newVal);
                out.println("\tError: " + errorMsg + ".");
            }
        }
    } else {
        return 1;
    }
    return 0;
}
Also used : ReconfigurationTaskStatus(org.apache.hadoop.conf.ReconfigurationTaskStatus) PropertyChange(org.apache.hadoop.conf.ReconfigurationUtil.PropertyChange) Optional(com.google.common.base.Optional) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) Date(java.util.Date)

Example 3 with PropertyChange

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

the class TestReconfiguration method testAsyncReconfigure.

@Test
public void testAsyncReconfigure() throws ReconfigurationException, IOException, InterruptedException {
    AsyncReconfigurableDummy dummy = spy(new AsyncReconfigurableDummy(conf1));
    List<PropertyChange> changes = Lists.newArrayList();
    changes.add(new PropertyChange("name1", "new1", "old1"));
    changes.add(new PropertyChange("name2", "new2", "old2"));
    changes.add(new PropertyChange("name3", "new3", "old3"));
    doReturn(changes).when(dummy).getChangedProperties(any(Configuration.class), any(Configuration.class));
    doReturn(true).when(dummy).isPropertyReconfigurable(eq("name1"));
    doReturn(false).when(dummy).isPropertyReconfigurable(eq("name2"));
    doReturn(true).when(dummy).isPropertyReconfigurable(eq("name3"));
    doReturn("dummy").when(dummy).reconfigurePropertyImpl(eq("name1"), anyString());
    doReturn("dummy").when(dummy).reconfigurePropertyImpl(eq("name2"), anyString());
    doThrow(new ReconfigurationException("NAME3", "NEW3", "OLD3", new IOException("io exception"))).when(dummy).reconfigurePropertyImpl(eq("name3"), anyString());
    dummy.startReconfigurationTask();
    waitAsyncReconfigureTaskFinish(dummy);
    ReconfigurationTaskStatus status = dummy.getReconfigurationTaskStatus();
    assertEquals(2, status.getStatus().size());
    for (Map.Entry<PropertyChange, Optional<String>> result : status.getStatus().entrySet()) {
        PropertyChange change = result.getKey();
        if (change.prop.equals("name1")) {
            assertFalse(result.getValue().isPresent());
        } else if (change.prop.equals("name2")) {
            assertThat(result.getValue().get(), containsString("Property name2 is not reconfigurable"));
        } else if (change.prop.equals("name3")) {
            assertThat(result.getValue().get(), containsString("io exception"));
        } else {
            fail("Unknown property: " + change.prop);
        }
    }
}
Also used : PropertyChange(org.apache.hadoop.conf.ReconfigurationUtil.PropertyChange) Optional(com.google.common.base.Optional) IOException(java.io.IOException) Map(java.util.Map) Test(org.junit.Test)

Example 4 with PropertyChange

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

the class ReconfigurationProtocolUtils method getReconfigurationStatus.

public static ReconfigurationTaskStatus getReconfigurationStatus(GetReconfigurationStatusResponseProto response) {
    Map<PropertyChange, Optional<String>> statusMap = null;
    long startTime;
    long endTime = 0;
    startTime = response.getStartTime();
    if (response.hasEndTime()) {
        endTime = response.getEndTime();
    }
    if (response.getChangesCount() > 0) {
        statusMap = Maps.newHashMap();
        for (GetReconfigurationStatusConfigChangeProto change : response.getChangesList()) {
            PropertyChange pc = new PropertyChange(change.getName(), change.getNewValue(), change.getOldValue());
            String errorMessage = null;
            if (change.hasErrorMessage()) {
                errorMessage = change.getErrorMessage();
            }
            statusMap.put(pc, Optional.fromNullable(errorMessage));
        }
    }
    return new ReconfigurationTaskStatus(startTime, endTime, statusMap);
}
Also used : ReconfigurationTaskStatus(org.apache.hadoop.conf.ReconfigurationTaskStatus) PropertyChange(org.apache.hadoop.conf.ReconfigurationUtil.PropertyChange) Optional(com.google.common.base.Optional) GetReconfigurationStatusConfigChangeProto(org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.GetReconfigurationStatusConfigChangeProto)

Example 5 with PropertyChange

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

the class TestReconfiguration method testStartReconfigurationFailureDueToExistingRunningTask.

@Test(timeout = 30000)
public void testStartReconfigurationFailureDueToExistingRunningTask() throws InterruptedException, IOException {
    AsyncReconfigurableDummy dummy = spy(new AsyncReconfigurableDummy(conf1));
    List<PropertyChange> changes = Lists.newArrayList(new PropertyChange(PROP1, "new1", "old1"));
    doReturn(changes).when(dummy).getChangedProperties(any(Configuration.class), any(Configuration.class));
    ReconfigurationTaskStatus status = dummy.getReconfigurationTaskStatus();
    assertFalse(status.hasTask());
    dummy.startReconfigurationTask();
    status = dummy.getReconfigurationTaskStatus();
    assertTrue(status.hasTask());
    assertFalse(status.stopped());
    // An active reconfiguration task is running.
    try {
        dummy.startReconfigurationTask();
        fail("Expect to throw IOException.");
    } catch (IOException e) {
        GenericTestUtils.assertExceptionContains("Another reconfiguration task is running", e);
    }
    status = dummy.getReconfigurationTaskStatus();
    assertTrue(status.hasTask());
    assertFalse(status.stopped());
    dummy.latch.countDown();
    waitAsyncReconfigureTaskFinish(dummy);
    status = dummy.getReconfigurationTaskStatus();
    assertTrue(status.hasTask());
    assertTrue(status.stopped());
    // The first task has finished.
    dummy.startReconfigurationTask();
    waitAsyncReconfigureTaskFinish(dummy);
    ReconfigurationTaskStatus status2 = dummy.getReconfigurationTaskStatus();
    assertTrue(status2.getStartTime() >= status.getEndTime());
    dummy.shutdownReconfigurationTask();
    try {
        dummy.startReconfigurationTask();
        fail("Expect to throw IOException");
    } catch (IOException e) {
        GenericTestUtils.assertExceptionContains("The server is stopped", e);
    }
}
Also used : PropertyChange(org.apache.hadoop.conf.ReconfigurationUtil.PropertyChange) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

PropertyChange (org.apache.hadoop.conf.ReconfigurationUtil.PropertyChange)5 Optional (com.google.common.base.Optional)4 IOException (java.io.IOException)3 Map (java.util.Map)3 ReconfigurationTaskStatus (org.apache.hadoop.conf.ReconfigurationTaskStatus)2 GetReconfigurationStatusConfigChangeProto (org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.GetReconfigurationStatusConfigChangeProto)2 Test (org.junit.Test)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 GetReconfigurationStatusResponseProto (org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.GetReconfigurationStatusResponseProto)1