Skip to content
Merged
Show file tree
Hide file tree
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 @@ -18,6 +18,7 @@

package org.apache.hadoop.hdds.scm;

import org.apache.ozone.test.NonHATests;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hdds.client.StandaloneReplicationConfig;
Expand All @@ -27,22 +28,18 @@
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.container.ContainerManager;
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.Timeout;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.TimeoutException;

import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;
Expand All @@ -56,35 +53,20 @@
*
* This class is to test JMX management interface for scm information.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Timeout(300)
public class TestSCMMXBean {
public abstract class TestSCMMXBean implements NonHATests.TestCase {

public static final Logger LOG = LoggerFactory.getLogger(TestSCMMXBean.class);
private static int numOfDatanodes = 3;
private static MiniOzoneCluster cluster;
private static OzoneConfiguration conf;
private static StorageContainerManager scm;
private static MBeanServer mbs;
private StorageContainerManager scm;
private MBeanServer mbs;

@BeforeAll
public static void init() throws IOException, TimeoutException,
InterruptedException {
conf = new OzoneConfiguration();
cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(numOfDatanodes)
.build();
cluster.waitForClusterToBeReady();
scm = cluster.getStorageContainerManager();
void init() {
scm = cluster().getStorageContainerManager();
mbs = ManagementFactory.getPlatformMBeanServer();
}

@AfterAll
public static void shutdown() {
if (cluster != null) {
cluster.shutdown();
}
}

@Test
public void testSCMMXBean() throws Exception {
ObjectName bean = new ObjectName(
Expand Down Expand Up @@ -119,8 +101,8 @@ public void testSCMContainerStateCount() throws Exception {
+ "component=ServerRuntime");
TabularData data = (TabularData) mbs.getAttribute(
bean, "ContainerStateCount");
Map<String, Integer> containerStateCount = scm.getContainerStateCount();
verifyEquals(data, containerStateCount);
final Map<String, Integer> originalContainerStateCount = scm.getContainerStateCount();
verifyEquals(data, originalContainerStateCount);

// Do some changes like allocate containers and change the container states
ContainerManager scmContainerManager = scm.getContainerManager();
Expand Down Expand Up @@ -154,23 +136,16 @@ public void testSCMContainerStateCount() throws Exception {

}

final String closing = HddsProtos.LifeCycleState.CLOSING.name();
final String closed = HddsProtos.LifeCycleState.CLOSED.name();
final Map<String, Integer> containerStateCount = scm.getContainerStateCount();
assertThat(containerStateCount.get(closing))
.isGreaterThanOrEqualTo(originalContainerStateCount.getOrDefault(closing, 0) + 5);
assertThat(containerStateCount.get(closed))
.isGreaterThanOrEqualTo(originalContainerStateCount.getOrDefault(closed, 0) + 5);
data = (TabularData) mbs.getAttribute(
bean, "ContainerStateCount");
containerStateCount = scm.getContainerStateCount();

containerStateCount.forEach((k, v) -> {
if (k.equals(HddsProtos.LifeCycleState.CLOSING.toString())) {
assertEquals(5, (int)v);
} else if (k.equals(HddsProtos.LifeCycleState.CLOSED.toString())) {
assertEquals(5, (int)v);
} else {
// Remaining all container state count should be zero.
assertEquals(0, (int)v);
}
});

verifyEquals(data, containerStateCount);

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,27 @@
*/
package org.apache.hadoop.hdds.scm.container;

import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ContainerInfoProto;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.hdds.scm.exceptions.SCMException;
import org.apache.hadoop.hdds.scm.pipeline.DuplicatedPipelineIdException;
import org.apache.hadoop.hdds.scm.pipeline.InvalidPipelineStateException;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline.PipelineState;
import org.apache.hadoop.hdds.scm.pipeline.PipelineManagerImpl;
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.util.Time;
import org.apache.ozone.test.HATests;
import org.apache.ratis.protocol.exceptions.StateMachineException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.Timeout;

import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.apache.hadoop.ozone.ClientVersion.CURRENT_VERSION;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
Expand All @@ -51,41 +47,20 @@
/**
* Test-cases to verify SCMStateMachine.applyTransaction failure scenarios.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Timeout(300)
public class TestScmApplyTransactionFailure {

private static MiniOzoneCluster cluster;
private static OzoneConfiguration conf;
private static StorageContainerManager scm;
private static ContainerManager containerManager;
private static PipelineManagerImpl pipelineManager;
public abstract class TestScmApplyTransactionFailure implements HATests.TestCase {

private ContainerManager containerManager;
private PipelineManagerImpl pipelineManager;

@BeforeAll
public static void init() throws Exception {
conf = new OzoneConfiguration();
cluster = MiniOzoneCluster.newHABuilder(conf).setSCMServiceId("test")
.setNumDatanodes(3).build();
conf.setTimeDuration(HddsConfigKeys.HDDS_HEARTBEAT_INTERVAL, 1000,
TimeUnit.MILLISECONDS);
conf.setTimeDuration(ScmConfigKeys.OZONE_SCM_PIPELINE_DESTROY_TIMEOUT,
1000, TimeUnit.MILLISECONDS);
cluster.waitForClusterToBeReady();
scm = cluster.getStorageContainerManager();
public void init() throws Exception {
StorageContainerManager scm = cluster().getScmLeader();
containerManager = scm.getContainerManager();
pipelineManager = (PipelineManagerImpl) scm.getPipelineManager();
}

/**
* Shutdown MiniDFSCluster.
*/
@AfterAll
public static void shutdown() {
if (cluster != null) {
cluster.shutdown();
}
}

@Test
public void testAddContainerToClosedPipeline() throws Exception {
RatisReplicationConfig replication =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
Expand All @@ -29,9 +28,8 @@
import org.apache.hadoop.hdds.scm.container.ContainerManager;
import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException;
import org.junit.jupiter.api.AfterEach;
import org.apache.ozone.test.NonHATests;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand All @@ -46,26 +44,16 @@
* Test for the Node2Pipeline map.
*/
@Timeout(300)
public class TestNode2PipelineMap {
public abstract class TestNode2PipelineMap implements NonHATests.TestCase {

private MiniOzoneCluster cluster;
private OzoneConfiguration conf;
private StorageContainerManager scm;
private ContainerWithPipeline ratisContainer;
private ContainerManager containerManager;
private PipelineManager pipelineManager;

/**
* Create a MiniDFSCluster for testing.
*
* @throws IOException
*/
@BeforeEach
public void init() throws Exception {
conf = new OzoneConfiguration();
cluster = MiniOzoneCluster.newBuilder(conf).setNumDatanodes(5).build();
cluster.waitForClusterToBeReady();
scm = cluster.getStorageContainerManager();
scm = cluster().getStorageContainerManager();
containerManager = scm.getContainerManager();
pipelineManager = scm.getPipelineManager();
ContainerInfo containerInfo = containerManager.allocateContainer(
Expand All @@ -76,16 +64,6 @@ public void init() throws Exception {
pipelineManager = scm.getPipelineManager();
}

/**
* Shutdown MiniDFSCluster.
*/
@AfterEach
public void shutdown() {
if (cluster != null) {
cluster.shutdown();
}
}

@Test
public void testPipelineMap() throws IOException,
InvalidStateTransitionException, TimeoutException {
Expand All @@ -94,8 +72,8 @@ public void testPipelineMap() throws IOException,
.getContainersInPipeline(ratisContainer.getPipeline().getId());

ContainerID cId = ratisContainer.getContainerInfo().containerID();
assertEquals(1, set.size());
set.forEach(containerID -> assertEquals(containerID, cId));
assertThat(set).contains(cId);
final int size = set.size();

List<DatanodeDetails> dns = ratisContainer.getPipeline().getNodes();
assertEquals(3, dns.size());
Expand All @@ -113,7 +91,7 @@ public void testPipelineMap() throws IOException,
.updateContainerState(cId, HddsProtos.LifeCycleEvent.CLOSE);
Set<ContainerID> set2 = pipelineManager.getContainersInPipeline(
ratisContainer.getPipeline().getId());
assertEquals(0, set2.size());
assertEquals(size - 1, set2.size());

pipelineManager.closePipeline(ratisContainer.getPipeline().getId());
pipelineManager.deletePipeline(ratisContainer.getPipeline().getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@

package org.apache.hadoop.hdds.scm.pipeline;

import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
import org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock;
import org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList;
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import org.apache.hadoop.ozone.MiniOzoneCluster;

import org.junit.jupiter.api.AfterEach;
import org.apache.ozone.test.NonHATests;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.Timeout;

import java.io.IOException;
Expand All @@ -41,27 +40,21 @@
import static org.apache.ozone.test.MetricsAsserts.getMetrics;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Test cases to verify the metrics exposed by SCMPipelineManager.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Timeout(300)
public class TestSCMPipelineMetrics {
public abstract class TestSCMPipelineMetrics implements NonHATests.TestCase {

private MiniOzoneCluster cluster;

@BeforeEach
public void setup() throws Exception {
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(HddsConfigKeys.HDDS_SCM_SAFEMODE_PIPELINE_AVAILABILITY_CHECK,
Boolean.TRUE.toString());
cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(3)
.build();
cluster.waitForClusterToBeReady();
cluster = cluster();
}

/**
Expand All @@ -82,6 +75,9 @@ public void testPipelineCreation() {
*/
@Test
public void testPipelineDestroy() {
final String sourceName = SCMPipelineMetrics.class.getSimpleName();
final String metricName = "NumPipelineDestroyed";
final long initialDestroyed = getLongCounter(metricName, getMetrics(sourceName));
PipelineManager pipelineManager = cluster
.getStorageContainerManager().getPipelineManager();
Optional<Pipeline> pipeline = pipelineManager
Expand All @@ -93,9 +89,7 @@ public void testPipelineDestroy() {
pm.closePipeline(pipeline.get().getId());
pm.deletePipeline(pipeline.get().getId());
});
MetricsRecordBuilder metrics = getMetrics(
SCMPipelineMetrics.class.getSimpleName());
assertCounter("NumPipelineDestroyed", 1L, metrics);
assertCounter(metricName, initialDestroyed + 1, getMetrics(sourceName));
}

@Test
Expand All @@ -110,7 +104,7 @@ public void testNumBlocksAllocated() throws IOException, TimeoutException {
Pipeline pipeline = block.getPipeline();
final String metricName = SCMPipelineMetrics.getBlockAllocationMetricName(pipeline);
long numBlocksAllocated = getLongCounter(metricName, metrics);
assertEquals(1, numBlocksAllocated);
assertThat(numBlocksAllocated).isPositive();

// destroy the pipeline
assertDoesNotThrow(() ->
Expand All @@ -123,9 +117,4 @@ public void testNumBlocksAllocated() throws IOException, TimeoutException {
getLongCounter(metricName, finalMetrics));
assertThat(t).hasMessageContaining(metricName);
}

@AfterEach
public void teardown() {
cluster.shutdown();
}
}
Loading