forked from apache/ozone
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDDS-9645. Recon should exclude out-of-service nodes when checking fo…
…r healthy containers (apache#5651)
- Loading branch information
Showing
13 changed files
with
1,138 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...op-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/node/TestNodeUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.apache.hadoop.hdds.scm.node; | ||
|
||
import org.apache.hadoop.hdds.protocol.DatanodeDetails; | ||
import org.apache.hadoop.hdds.protocol.proto.HddsProtos; | ||
import org.apache.ozone.test.GenericTestUtils; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
import java.util.concurrent.TimeoutException; | ||
|
||
/** | ||
* Utility class with helper methods for testing node state and status. | ||
*/ | ||
public final class TestNodeUtil { | ||
|
||
private TestNodeUtil() { | ||
} | ||
|
||
/** | ||
* Wait for the given datanode to reach the given operational state. | ||
* @param dn Datanode for which to check the state | ||
* @param state The state to wait for. | ||
* @throws TimeoutException | ||
* @throws InterruptedException | ||
*/ | ||
public static void waitForDnToReachOpState(NodeManager nodeManager, | ||
DatanodeDetails dn, HddsProtos.NodeOperationalState state) | ||
throws TimeoutException, InterruptedException { | ||
GenericTestUtils.waitFor( | ||
() -> getNodeStatus(nodeManager, dn) | ||
.getOperationalState().equals(state), | ||
200, 30000); | ||
} | ||
|
||
/** | ||
* Wait for the given datanode to reach the given Health state. | ||
* @param dn Datanode for which to check the state | ||
* @param state The state to wait for. | ||
* @throws TimeoutException | ||
* @throws InterruptedException | ||
*/ | ||
public static void waitForDnToReachHealthState(NodeManager nodeManager, | ||
DatanodeDetails dn, HddsProtos.NodeState state) | ||
throws TimeoutException, InterruptedException { | ||
GenericTestUtils.waitFor( | ||
() -> getNodeStatus(nodeManager, dn).getHealth().equals(state), | ||
200, 30000); | ||
} | ||
|
||
/** | ||
* Retrieves the NodeStatus for the given DN or fails the test if the | ||
* Node cannot be found. This is a helper method to allow the nodeStatus to be | ||
* checked in lambda expressions. | ||
* @param dn Datanode for which to retrieve the NodeStatus. | ||
*/ | ||
public static NodeStatus getNodeStatus(NodeManager nodeManager, | ||
DatanodeDetails dn) { | ||
return Assertions.assertDoesNotThrow( | ||
() -> nodeManager.getNodeStatus(dn), | ||
"Unexpected exception getting the nodeState"); | ||
} | ||
|
||
/** | ||
* Given a Datanode, return a string consisting of the hostname and one of its | ||
* ports in the for host:post. | ||
* @param dn Datanode for which to retrieve the host:post string | ||
* @return host:port for the given DN. | ||
*/ | ||
public static String getDNHostAndPort(DatanodeDetails dn) { | ||
return dn.getHostName() + ":" + dn.getPorts().get(0).getValue(); | ||
} | ||
|
||
/** | ||
* Wait for the given datanode to reach the given persisted state. | ||
* @param dn Datanode for which to check the state | ||
* @param state The state to wait for. | ||
* @throws TimeoutException | ||
* @throws InterruptedException | ||
*/ | ||
public static void waitForDnToReachPersistedOpState(DatanodeDetails dn, | ||
HddsProtos.NodeOperationalState state) | ||
throws TimeoutException, InterruptedException { | ||
GenericTestUtils.waitFor( | ||
() -> dn.getPersistedOpState().equals(state), | ||
200, 30000); | ||
} | ||
} |
Oops, something went wrong.