diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMDatanodeHeartbeatDispatcher.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMDatanodeHeartbeatDispatcher.java new file mode 100644 index 0000000000..36f10a93dc --- /dev/null +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMDatanodeHeartbeatDispatcher.java @@ -0,0 +1,126 @@ +/** + * 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 + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * 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.server;
+
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.protocol.proto
+ .StorageContainerDatanodeProtocolProtos.ContainerReportsProto;
+import org.apache.hadoop.hdds.protocol.proto
+ .StorageContainerDatanodeProtocolProtos.NodeReportProto;
+import org.apache.hadoop.hdds.protocol.proto
+ .StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto;
+import org.apache.hadoop.hdds.server.events.EventPublisher;
+import org.apache.hadoop.hdds.server.events.TypedEvent;
+
+import com.google.protobuf.GeneratedMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class is responsible for dispatching heartbeat from datanode to
+ * appropriate EventHandler at SCM.
+ */
+public final class SCMDatanodeHeartbeatDispatcher {
+
+ private static final Logger LOG =
+ LoggerFactory.getLogger(SCMDatanodeHeartbeatDispatcher.class);
+
+ private EventPublisher eventPublisher;
+
+ public static final TypedEvent
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-
-import org.apache.hadoop.hdds.protocol.DatanodeDetails;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.ContainerReportsProto;
-import org.apache.hadoop.hdds.scm.container.placement.metrics.ContainerStat;
-import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-
-/**
- * Handler for Datanode Container Report.
- */
-public class SCMDatanodeContainerReportHandler extends
- SCMDatanodeReportHandler
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import com.google.protobuf.GeneratedMessage;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hdds.protocol.DatanodeDetails;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto;
-import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
-import org.apache.hadoop.util.concurrent.HadoopExecutors;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-
-/**
- * This class is responsible for dispatching heartbeat from datanode to
- * appropriate ReportHandlers at SCM.
- * Only one handler per report is supported now, it's very easy to support
- * multiple handlers for a report.
- */
-public final class SCMDatanodeHeartbeatDispatcher {
-
- private static final Logger LOG = LoggerFactory.getLogger(
- SCMDatanodeHeartbeatDispatcher.class);
-
- /**
- * This stores Report to Handler mapping.
- */
- private final Map
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-
-import org.apache.hadoop.hdds.protocol.DatanodeDetails;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.NodeReportProto;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-
-/**
- * Handles Datanode Node Report.
- */
-public class SCMDatanodeNodeReportHandler extends
- SCMDatanodeReportHandler
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-
-import com.google.protobuf.GeneratedMessage;
-import org.apache.hadoop.conf.Configurable;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hdds.protocol.DatanodeDetails;
-import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
-
-import java.io.IOException;
-
-/**
- * Datanode Report handlers should implement this interface in order to get
- * call back whenever the report is received from datanode.
- *
- * @param
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-
-import com.google.protobuf.GeneratedMessage;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.ContainerReportsProto;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.NodeReportProto;
-import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
-import org.apache.hadoop.util.ReflectionUtils;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-/**
- * Factory class to construct {@link SCMDatanodeReportHandler} given a report.
- */
-public class SCMDatanodeReportHandlerFactory {
-
- private final Configuration conf;
- private final StorageContainerManager scm;
- private final Map
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-/**
- * Handling of all the datanode reports in SCM which are received through
- * heartbeat is done here.
- *
- * SCM Datanode Report Processing State Diagram:
- *
- * SCMDatanode SCMDatanodeHeartbeat SCMDatanodeReport
- * ProtocolServer Dispatcher Handler
- * | | |
- * | | |
- * | construct | |
- * |----------------------->| |
- * | | |
- * | | register |
- * | |<-----------------------|
- * | | |
- * +------------+------------------------+------------------------+--------+
- * | loop | | | |
- * | | | | |
- * | | | | |
- * | heartbeat | | | |
- * - +----------->| | | |
- * | from | heartbeat | | |
- * | Datanode |----------------------->| | |
- * | | | report | |
- * | | |----------------------->| |
- * | | | | |
- * | DN | | | |
- * <-+------------| | | |
- * | commands | | | |
- * | | | | |
- * +------------+------------------------+------------------------+--------+
- * | | |
- * | | |
- * | shutdown | |
- * |----------------------->| |
- * | | |
- * | | |
- * - - -
- */
\ No newline at end of file
diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/TestSCMDatanodeHeartbeatDispatcher.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/TestSCMDatanodeHeartbeatDispatcher.java
new file mode 100644
index 0000000000..326a34b792
--- /dev/null
+++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/TestSCMDatanodeHeartbeatDispatcher.java
@@ -0,0 +1,119 @@
+/**
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.server;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.protocol.proto
+ .StorageContainerDatanodeProtocolProtos.ContainerReportsProto;
+import org.apache.hadoop.hdds.protocol.proto
+ .StorageContainerDatanodeProtocolProtos.NodeReportProto;
+import org.apache.hadoop.hdds.protocol.proto
+ .StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto;
+import org.apache.hadoop.hdds.scm.TestUtils;
+import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher
+ .ContainerReportFromDatanode;
+import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher
+ .NodeReportFromDatanode;
+import org.apache.hadoop.hdds.server.events.Event;
+import org.apache.hadoop.hdds.server.events.EventPublisher;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * This class tests the behavior of SCMDatanodeHeartbeatDispatcher.
+ */
+public class TestSCMDatanodeHeartbeatDispatcher {
+
+
+ @Test
+ public void testNodeReportDispatcher() throws IOException {
+
+ Configuration conf = new OzoneConfiguration();
+
+ AtomicInteger eventReceived = new AtomicInteger();
+
+ NodeReportProto nodeReport = NodeReportProto.getDefaultInstance();
+
+ SCMDatanodeHeartbeatDispatcher dispatcher =
+ new SCMDatanodeHeartbeatDispatcher(new EventPublisher() {
+ @Override
+ public
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test cases to verify SCMDatanodeContainerReportHandler's behavior.
- */
-public class TestSCMDatanodeContainerReportHandler {
-
- //TODO: add test cases to verify SCMDatanodeContainerReportHandler.
-
- @Test
- public void dummyTest() {
- Assert.assertTrue(true);
- }
-}
diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/TestSCMDatanodeHeartbeatDispatcher.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/TestSCMDatanodeHeartbeatDispatcher.java
deleted file mode 100644
index 5d086471c1..0000000000
--- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/TestSCMDatanodeHeartbeatDispatcher.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hdds.conf.OzoneConfiguration;
-import org.apache.hadoop.hdds.protocol.DatanodeDetails;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.ContainerReportsProto;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.NodeReportProto;
-import org.apache.hadoop.hdds.scm.TestUtils;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import java.io.IOException;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-/**
- * This class tests the behavior of SCMDatanodeHeartbeatDispatcher.
- */
-public class TestSCMDatanodeHeartbeatDispatcher {
-
- @Test
- public void testSCMDatanodeHeartbeatDispatcherBuilder() {
- Configuration conf = new OzoneConfiguration();
- SCMDatanodeHeartbeatDispatcher dispatcher =
- SCMDatanodeHeartbeatDispatcher.newBuilder(conf, null)
- .addHandlerFor(NodeReportProto.class)
- .addHandlerFor(ContainerReportsProto.class)
- .build();
- Assert.assertNotNull(dispatcher);
- }
-
- @Test
- public void testNodeReportDispatcher() throws IOException {
- Configuration conf = new OzoneConfiguration();
- SCMDatanodeNodeReportHandler nodeReportHandler =
- Mockito.mock(SCMDatanodeNodeReportHandler.class);
- SCMDatanodeHeartbeatDispatcher dispatcher =
- SCMDatanodeHeartbeatDispatcher.newBuilder(conf, null)
- .addHandler(NodeReportProto.class, nodeReportHandler)
- .build();
-
- DatanodeDetails datanodeDetails = TestUtils.getDatanodeDetails();
- NodeReportProto nodeReport = NodeReportProto.getDefaultInstance();
- SCMHeartbeatRequestProto heartbeat =
- SCMHeartbeatRequestProto.newBuilder()
- .setDatanodeDetails(datanodeDetails.getProtoBufMessage())
- .setNodeReport(nodeReport)
- .build();
- dispatcher.dispatch(heartbeat);
- verify(nodeReportHandler,
- times(1))
- .processReport(any(DatanodeDetails.class), eq(nodeReport));
- }
-
- @Test
- public void testContainerReportDispatcher() throws IOException {
- Configuration conf = new OzoneConfiguration();
- SCMDatanodeContainerReportHandler containerReportHandler =
- Mockito.mock(SCMDatanodeContainerReportHandler.class);
- SCMDatanodeHeartbeatDispatcher dispatcher =
- SCMDatanodeHeartbeatDispatcher.newBuilder(conf, null)
- .addHandler(ContainerReportsProto.class, containerReportHandler)
- .build();
-
- DatanodeDetails datanodeDetails = TestUtils.getDatanodeDetails();
- ContainerReportsProto containerReport =
- ContainerReportsProto.getDefaultInstance();
- SCMHeartbeatRequestProto heartbeat =
- SCMHeartbeatRequestProto.newBuilder()
- .setDatanodeDetails(datanodeDetails.getProtoBufMessage())
- .setContainerReport(containerReport)
- .build();
- dispatcher.dispatch(heartbeat);
- verify(containerReportHandler,
- times(1))
- .processReport(any(DatanodeDetails.class),
- any(ContainerReportsProto.class));
- }
-
- @Test
- public void testNodeAndContainerReportDispatcher() throws IOException {
- Configuration conf = new OzoneConfiguration();
- SCMDatanodeNodeReportHandler nodeReportHandler =
- Mockito.mock(SCMDatanodeNodeReportHandler.class);
- SCMDatanodeContainerReportHandler containerReportHandler =
- Mockito.mock(SCMDatanodeContainerReportHandler.class);
- SCMDatanodeHeartbeatDispatcher dispatcher =
- SCMDatanodeHeartbeatDispatcher.newBuilder(conf, null)
- .addHandler(NodeReportProto.class, nodeReportHandler)
- .addHandler(ContainerReportsProto.class, containerReportHandler)
- .build();
-
- DatanodeDetails datanodeDetails = TestUtils.getDatanodeDetails();
- NodeReportProto nodeReport = NodeReportProto.getDefaultInstance();
- ContainerReportsProto containerReport =
- ContainerReportsProto.getDefaultInstance();
- SCMHeartbeatRequestProto heartbeat =
- SCMHeartbeatRequestProto.newBuilder()
- .setDatanodeDetails(datanodeDetails.getProtoBufMessage())
- .setNodeReport(nodeReport)
- .setContainerReport(containerReport)
- .build();
- dispatcher.dispatch(heartbeat);
- verify(nodeReportHandler,
- times(1))
- .processReport(any(DatanodeDetails.class), any(NodeReportProto.class));
- verify(containerReportHandler,
- times(1))
- .processReport(any(DatanodeDetails.class),
- any(ContainerReportsProto.class));
- }
-
-}
diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/TestSCMDatanodeNodeReportHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/TestSCMDatanodeNodeReportHandler.java
deleted file mode 100644
index 30a753c024..0000000000
--- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/TestSCMDatanodeNodeReportHandler.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test cases to verify TestSCMDatanodeNodeReportHandler's behavior.
- */
-public class TestSCMDatanodeNodeReportHandler {
-
-
- //TODO: add test cases to verify SCMDatanodeNodeReportHandler.
-
- @Test
- public void dummyTest() {
- Assert.assertTrue(true);
- }
-}
diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/TestSCMDatanodeReportHandlerFactory.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/TestSCMDatanodeReportHandlerFactory.java
deleted file mode 100644
index 4b918f76c7..0000000000
--- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/TestSCMDatanodeReportHandlerFactory.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hdds.conf.OzoneConfiguration;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.ContainerReportsProto;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.NodeReportProto;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test cases to verify the functionality of SCMDatanodeReportHandlerFactory.
- */
-public class TestSCMDatanodeReportHandlerFactory {
-
- @Test
- public void testNodeReportHandlerConstruction() {
- Configuration conf = new OzoneConfiguration();
- SCMDatanodeReportHandlerFactory factory =
- new SCMDatanodeReportHandlerFactory(conf, null);
- Assert.assertTrue(factory.getHandlerFor(NodeReportProto.class)
- instanceof SCMDatanodeNodeReportHandler);
- }
-
- @Test
- public void testContainerReporttHandlerConstruction() {
- Configuration conf = new OzoneConfiguration();
- SCMDatanodeReportHandlerFactory factory =
- new SCMDatanodeReportHandlerFactory(conf, null);
- Assert.assertTrue(factory.getHandlerFor(ContainerReportsProto.class)
- instanceof SCMDatanodeContainerReportHandler);
- }
-}
diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/package-info.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/package-info.java
deleted file mode 100644
index 4a3f59f016..0000000000
--- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/report/package-info.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.server.report;
-/**
- * Contains test-cases to test Datanode report handlers in SCM.
- */
\ No newline at end of file
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestSCMMetrics.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestSCMMetrics.java
deleted file mode 100644
index ecddf8eaca..0000000000
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestSCMMetrics.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/**
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.ozone.scm;
-
-import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
-import static org.apache.hadoop.test.MetricsAsserts.getLongGauge;
-import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
-import static org.junit.Assert.assertEquals;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang3.RandomUtils;
-import org.apache.hadoop.hdds.conf.OzoneConfiguration;
-import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
-import org.apache.hadoop.hdds.scm.TestUtils;
-import org.apache.hadoop.hdds.protocol.DatanodeDetails;
-import org.apache.hadoop.hdds.scm.server.report
- .SCMDatanodeContainerReportHandler;
-import org.apache.hadoop.metrics2.MetricsRecordBuilder;
-import org.apache.hadoop.ozone.MiniOzoneCluster;
-import org.apache.hadoop.ozone.OzoneConsts;
-import org.apache.hadoop.ozone.container.common.helpers.ContainerReport;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos;
-import org.apache.hadoop.hdds.protocol.proto
- .StorageContainerDatanodeProtocolProtos.ContainerReportsProto;
-import org.apache.hadoop.hdds.scm.container.placement.metrics.ContainerStat;
-import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMMetrics;
-import org.apache.hadoop.hdds.scm.node.SCMNodeManager;
-import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.Timeout;
-
-/**
- * This class tests the metrics of Storage Container Manager.
- */
-public class TestSCMMetrics {
- /**
- * Set the timeout for each test.
- */
- @Rule
- public Timeout testTimeout = new Timeout(90000);
-
- private static MiniOzoneCluster cluster = null;
-
- @Test
- public void testContainerMetrics() throws Exception {
- int nodeCount = 2;
- int numReport = 2;
- long size = OzoneConsts.GB * 5;
- long used = OzoneConsts.GB * 2;
- long readBytes = OzoneConsts.GB * 1;
- long writeBytes = OzoneConsts.GB * 2;
- int keyCount = 1000;
- int readCount = 100;
- int writeCount = 50;
- OzoneConfiguration conf = new OzoneConfiguration();
-
- try {
- cluster = MiniOzoneCluster.newBuilder(conf)
- .setNumDatanodes(nodeCount).build();
- cluster.waitForClusterToBeReady();
-
- ContainerStat stat = new ContainerStat(size, used, keyCount, readBytes,
- writeBytes, readCount, writeCount);
- StorageContainerManager scmManager = cluster.getStorageContainerManager();
- DatanodeDetails fstDatanodeDetails = TestUtils.getDatanodeDetails();
- ContainerReportsProto request = createContainerReport(numReport, stat);
- String fstDatanodeUuid = fstDatanodeDetails.getUuidString();
- SCMDatanodeContainerReportHandler containerReportHandler =
- new SCMDatanodeContainerReportHandler();
- containerReportHandler.setConf(conf);
- containerReportHandler.init(scmManager);
- containerReportHandler.processReport(
- fstDatanodeDetails, request);
-
- // verify container stat metrics
- MetricsRecordBuilder scmMetrics = getMetrics(SCMMetrics.SOURCE_NAME);
- assertEquals(size * numReport,
- getLongGauge("LastContainerReportSize", scmMetrics));
- assertEquals(used * numReport,
- getLongGauge("LastContainerReportUsed", scmMetrics));
- assertEquals(readBytes * numReport,
- getLongGauge("LastContainerReportReadBytes", scmMetrics));
- assertEquals(writeBytes * numReport,
- getLongGauge("LastContainerReportWriteBytes", scmMetrics));
-
- assertEquals(keyCount * numReport,
- getLongGauge("LastContainerReportKeyCount", scmMetrics));
- assertEquals(readCount * numReport,
- getLongGauge("LastContainerReportReadCount", scmMetrics));
- assertEquals(writeCount * numReport,
- getLongGauge("LastContainerReportWriteCount", scmMetrics));
-
- // add one new report
- DatanodeDetails sndDatanodeDetails = TestUtils.getDatanodeDetails();
- request = createContainerReport(1, stat);
- String sndDatanodeUuid = sndDatanodeDetails.getUuidString();
- containerReportHandler.processReport(
- sndDatanodeDetails, request);
-
- scmMetrics = getMetrics(SCMMetrics.SOURCE_NAME);
- assertEquals(size * (numReport + 1),
- getLongCounter("ContainerReportSize", scmMetrics));
- assertEquals(used * (numReport + 1),
- getLongCounter("ContainerReportUsed", scmMetrics));
- assertEquals(readBytes * (numReport + 1),
- getLongCounter("ContainerReportReadBytes", scmMetrics));
- assertEquals(writeBytes * (numReport + 1),
- getLongCounter("ContainerReportWriteBytes", scmMetrics));
-
- assertEquals(keyCount * (numReport + 1),
- getLongCounter("ContainerReportKeyCount", scmMetrics));
- assertEquals(readCount * (numReport + 1),
- getLongCounter("ContainerReportReadCount", scmMetrics));
- assertEquals(writeCount * (numReport + 1),
- getLongCounter("ContainerReportWriteCount", scmMetrics));
-
- // Re-send reports but with different value for validating
- // the aggregation.
- stat = new ContainerStat(100, 50, 3, 50, 60, 5, 6);
- containerReportHandler.processReport(
- fstDatanodeDetails, createContainerReport(1, stat));
-
- stat = new ContainerStat(1, 1, 1, 1, 1, 1, 1);
- containerReportHandler.processReport(
- sndDatanodeDetails, createContainerReport(1, stat));
-
- // the global container metrics value should be updated
- scmMetrics = getMetrics(SCMMetrics.SOURCE_NAME);
- assertEquals(101, getLongCounter("ContainerReportSize", scmMetrics));
- assertEquals(51, getLongCounter("ContainerReportUsed", scmMetrics));
- assertEquals(51, getLongCounter("ContainerReportReadBytes", scmMetrics));
- assertEquals(61, getLongCounter("ContainerReportWriteBytes", scmMetrics));
-
- assertEquals(4, getLongCounter("ContainerReportKeyCount", scmMetrics));
- assertEquals(6, getLongCounter("ContainerReportReadCount", scmMetrics));
- assertEquals(7, getLongCounter("ContainerReportWriteCount", scmMetrics));
- } finally {
- if (cluster != null) {
- cluster.shutdown();
- }
- }
- }
-
- @Test
- public void testStaleNodeContainerReport() throws Exception {
- int nodeCount = 2;
- int numReport = 2;
- long size = OzoneConsts.GB * 5;
- long used = OzoneConsts.GB * 2;
- long readBytes = OzoneConsts.GB * 1;
- long writeBytes = OzoneConsts.GB * 2;
- int keyCount = 1000;
- int readCount = 100;
- int writeCount = 50;
- OzoneConfiguration conf = new OzoneConfiguration();
-
- try {
- cluster = MiniOzoneCluster.newBuilder(conf)
- .setNumDatanodes(nodeCount).build();
- cluster.waitForClusterToBeReady();
-
- ContainerStat stat = new ContainerStat(size, used, keyCount, readBytes,
- writeBytes, readCount, writeCount);
- StorageContainerManager scmManager = cluster.getStorageContainerManager();
-
- DatanodeDetails datanodeDetails = cluster.getHddsDatanodes().get(0)
- .getDatanodeDetails();
- SCMDatanodeContainerReportHandler containerReportHandler =
- new SCMDatanodeContainerReportHandler();
- containerReportHandler.setConf(conf);
- containerReportHandler.init(scmManager);
- ContainerReportsProto request = createContainerReport(numReport, stat);
- containerReportHandler.processReport(
- datanodeDetails, request);
-
- MetricsRecordBuilder scmMetrics = getMetrics(SCMMetrics.SOURCE_NAME);
- assertEquals(size * numReport,
- getLongCounter("ContainerReportSize", scmMetrics));
- assertEquals(used * numReport,
- getLongCounter("ContainerReportUsed", scmMetrics));
- assertEquals(readBytes * numReport,
- getLongCounter("ContainerReportReadBytes", scmMetrics));
- assertEquals(writeBytes * numReport,
- getLongCounter("ContainerReportWriteBytes", scmMetrics));
-
- assertEquals(keyCount * numReport,
- getLongCounter("ContainerReportKeyCount", scmMetrics));
- assertEquals(readCount * numReport,
- getLongCounter("ContainerReportReadCount", scmMetrics));
- assertEquals(writeCount * numReport,
- getLongCounter("ContainerReportWriteCount", scmMetrics));
-
- // reset stale interval time to move node from healthy to stale
- SCMNodeManager nodeManager = (SCMNodeManager) cluster
- .getStorageContainerManager().getScmNodeManager();
- nodeManager.setStaleNodeIntervalMs(100);
-
- // verify the metrics when node becomes stale
- GenericTestUtils.waitFor(() -> {
- MetricsRecordBuilder metrics = getMetrics(SCMMetrics.SOURCE_NAME);
- return 0 == getLongCounter("ContainerReportSize", metrics)
- && 0 == getLongCounter("ContainerReportUsed", metrics)
- && 0 == getLongCounter("ContainerReportReadBytes", metrics)
- && 0 == getLongCounter("ContainerReportWriteBytes", metrics)
- && 0 == getLongCounter("ContainerReportKeyCount", metrics)
- && 0 == getLongCounter("ContainerReportReadCount", metrics)
- && 0 == getLongCounter("ContainerReportWriteCount", metrics);
- }, 1000, 60000);
- } finally {
- if (cluster != null) {
- cluster.shutdown();
- }
- }
- }
-
- private ContainerReportsProto createContainerReport(int numReport,
- ContainerStat stat) {
- StorageContainerDatanodeProtocolProtos.ContainerReportsProto.Builder
- reportsBuilder = StorageContainerDatanodeProtocolProtos
- .ContainerReportsProto.newBuilder();
-
- for (int i = 0; i < numReport; i++) {
- ContainerReport report = new ContainerReport(
- RandomUtils.nextLong(), DigestUtils.sha256Hex("Simulated"));
- report.setSize(stat.getSize().get());
- report.setBytesUsed(stat.getUsed().get());
- report.setReadCount(stat.getReadCount().get());
- report.setReadBytes(stat.getReadBytes().get());
- report.setKeyCount(stat.getKeyCount().get());
- report.setWriteCount(stat.getWriteCount().get());
- report.setWriteBytes(stat.getWriteBytes().get());
- reportsBuilder.addReports(report.getProtoBufMessage());
- }
- return reportsBuilder.build();
- }
-}