Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
Expand Down Expand Up @@ -135,6 +138,7 @@ private void testSafeMode(int numContainers) throws Exception {
serviceManager, scmContext);

assertTrue(scmSafeModeManager.getInSafeMode());
validateRuleStatus("DatanodeSafeModeRule", "registered datanodes 0");
queue.fireEvent(SCMEvents.NODE_REGISTRATION_CONT_REPORT,
HddsTestUtils.createNodeRegistrationContainerReport(containers));

Expand Down Expand Up @@ -176,7 +180,8 @@ public void testSafeModeExitRule() throws Exception {
.getNumContainerWithOneReplicaReportedThreshold().value());

assertTrue(scmSafeModeManager.getInSafeMode());

validateRuleStatus("ContainerSafeModeRule",
"% of containers with at least one reported");
testContainerThreshold(containers.subList(0, 25), 0.25);
assertEquals(25, scmSafeModeManager.getSafeModeMetrics()
.getCurrentContainersWithOneReplicaReportedCount().value());
Expand Down Expand Up @@ -316,6 +321,13 @@ public void testSafeModeExitRuleWithPipelineAvailabilityCheck(
scmContext);

assertTrue(scmSafeModeManager.getInSafeMode());
if (healthyPipelinePercent > 0) {
validateRuleStatus("HealthyPipelineSafeModeRule",
"healthy Ratis/THREE pipelines");
}
validateRuleStatus("OneReplicaPipelineSafeModeRule",
"reported Ratis/THREE pipelines with at least one datanode");

testContainerThreshold(containers, 1.0);

List<Pipeline> pipelines = pipelineManager.getPipelines();
Expand Down Expand Up @@ -374,6 +386,22 @@ public void testSafeModeExitRuleWithPipelineAvailabilityCheck(
100, 1000 * 5);
}

/**
* @param safeModeRule verify that this rule is not satisfied
* @param stringToMatch string to match in the rule status.
*/
private void validateRuleStatus(String safeModeRule, String stringToMatch) {
Set<Map.Entry<String, Pair<Boolean, String>>> ruleStatuses =
scmSafeModeManager.getRuleStatus().entrySet();
for (Map.Entry<String, Pair<Boolean, String>> entry : ruleStatuses) {
if (entry.getKey().equals(safeModeRule)) {
Pair<Boolean, String> value = entry.getValue();
assertEquals(false, value.getLeft());
assertTrue(value.getRight().contains(stringToMatch));
}
}
}

private void checkHealthy(int expectedCount) throws Exception {
GenericTestUtils.waitFor(() -> scmSafeModeManager
.getHealthyPipelineSafeModeRule()
Expand Down