|
@@ -1,22 +1,44 @@
|
|
|
+/**
|
|
|
+ * 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.container.metrics;
|
|
|
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
+import org.apache.hadoop.hdds.client.ReplicationFactor;
|
|
|
+import org.apache.hadoop.hdds.client.ReplicationType;
|
|
|
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
|
|
|
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
|
|
|
-import org.apache.hadoop.hdds.scm.XceiverClientManager;
|
|
|
import org.apache.hadoop.hdds.scm.container.ContainerID;
|
|
|
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.metrics2.MetricsRecordBuilder;
|
|
|
import org.apache.hadoop.ozone.MiniOzoneCluster;
|
|
|
+import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
|
|
|
+import org.apache.hadoop.test.GenericTestUtils;
|
|
|
import org.junit.After;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
|
|
|
+import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_CONTAINER_REPORT_INTERVAL;
|
|
|
import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
|
|
|
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
|
|
|
import static org.junit.Assert.fail;
|
|
@@ -28,16 +50,15 @@ public class TestSCMContainerManagerMetrics {
|
|
|
|
|
|
private MiniOzoneCluster cluster;
|
|
|
private StorageContainerManager scm;
|
|
|
- private XceiverClientManager xceiverClientManager;
|
|
|
private String containerOwner = "OZONE";
|
|
|
|
|
|
@Before
|
|
|
public void setup() throws Exception {
|
|
|
OzoneConfiguration conf = new OzoneConfiguration();
|
|
|
+ conf.set(HDDS_CONTAINER_REPORT_INTERVAL, "3000s");
|
|
|
cluster = MiniOzoneCluster.newBuilder(conf).setNumDatanodes(1).build();
|
|
|
cluster.waitForClusterToBeReady();
|
|
|
scm = cluster.getStorageContainerManager();
|
|
|
- xceiverClientManager = new XceiverClientManager(conf);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -51,7 +72,6 @@ public class TestSCMContainerManagerMetrics {
|
|
|
MetricsRecordBuilder metrics;
|
|
|
ContainerManager containerManager = scm.getContainerManager();
|
|
|
metrics = getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
|
|
|
-
|
|
|
long numSuccessfulCreateContainers = getLongCounter(
|
|
|
"NumSuccessfulCreateContainers", metrics);
|
|
|
|
|
@@ -108,5 +128,40 @@ public class TestSCMContainerManagerMetrics {
|
|
|
metrics = getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
|
|
|
Assert.assertEquals(getLongCounter("NumListContainerOps",
|
|
|
metrics), 1);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testReportProcessingMetrics() throws Exception {
|
|
|
+ String volumeName = "vol1";
|
|
|
+ String bucketName = "bucket1";
|
|
|
+ String key = "key1";
|
|
|
+
|
|
|
+ MetricsRecordBuilder metrics =
|
|
|
+ getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
|
|
|
+ Assert.assertEquals(getLongCounter("NumContainerReportsProcessedSuccessful",
|
|
|
+ metrics), 1);
|
|
|
+
|
|
|
+ // Create key should create container on DN.
|
|
|
+ cluster.getRpcClient().getObjectStore().getClientProxy()
|
|
|
+ .createVolume(volumeName);
|
|
|
+ cluster.getRpcClient().getObjectStore().getClientProxy()
|
|
|
+ .createBucket(volumeName, bucketName);
|
|
|
+ OzoneOutputStream ozoneOutputStream = cluster.getRpcClient()
|
|
|
+ .getObjectStore().getClientProxy().createKey(volumeName, bucketName,
|
|
|
+ key, 0, ReplicationType.RATIS, ReplicationFactor.ONE,
|
|
|
+ new HashMap<>());
|
|
|
+
|
|
|
+ String data = "file data";
|
|
|
+ ozoneOutputStream.write(data.getBytes(), 0, data.length());
|
|
|
+ ozoneOutputStream.close();
|
|
|
+
|
|
|
+
|
|
|
+ GenericTestUtils.waitFor(() -> {
|
|
|
+ final MetricsRecordBuilder scmMetrics =
|
|
|
+ getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
|
|
|
+ return getLongCounter("NumICRReportsProcessedSuccessful",
|
|
|
+ scmMetrics) == 1;
|
|
|
+ }, 1000, 500000);
|
|
|
}
|
|
|
}
|