avijayanhwx commented on a change in pull request #356: HDDS-2590 Integration 
tests for Recon with Ozone Manager
URL: https://github.com/apache/hadoop-ozone/pull/356#discussion_r358513275
 
 

 ##########
 File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/recon/TestRecon.java
 ##########
 @@ -0,0 +1,385 @@
+/**
+ * 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.ozone.recon;
+
+import com.google.gson.Gson;
+import com.google.gson.internal.LinkedTreeMap;
+import org.apache.hadoop.hdds.HddsConfigKeys;
+import org.apache.hadoop.hdds.client.BlockID;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
+import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
+import org.apache.hadoop.hdds.utils.db.RDBStore;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.test.GenericTestUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import static java.net.HttpURLConnection.HTTP_CREATED;
+import static java.net.HttpURLConnection.HTTP_OK;
+import static 
org.apache.hadoop.ozone.recon.ReconConstants.RECON_OM_SNAPSHOT_DB;
+import static org.apache.hadoop.ozone.recon.
+    ReconServerConfigKeys.OZONE_RECON_OM_SNAPSHOT_DB_DIR;
+import static org.apache.hadoop.ozone.recon.
+    ReconServerConfigKeys.RECON_OM_SOCKET_TIMEOUT;
+import static org.apache.hadoop.ozone.recon.
+    ReconServerConfigKeys.RECON_OM_SOCKET_TIMEOUT_DEFAULT;
+import static org.apache.hadoop.ozone.recon.
+    ReconServerConfigKeys.OZONE_RECON_HTTP_ADDRESS_KEY;
+import static org.apache.hadoop.ozone.recon.
+    ReconServerConfigKeys.RECON_OM_CONNECTION_TIMEOUT;
+import static org.apache.hadoop.ozone.recon.
+    ReconServerConfigKeys.RECON_OM_CONNECTION_TIMEOUT_DEFAULT;
+import static org.apache.hadoop.ozone.recon.
+    ReconServerConfigKeys.RECON_OM_CONNECTION_REQUEST_TIMEOUT;
+import static org.apache.hadoop.ozone.recon.
+    ReconServerConfigKeys.RECON_OM_CONNECTION_REQUEST_TIMEOUT_DEFAULT;
+import static org.apache.hadoop.ozone.recon.
+    ReconServerConfigKeys.RECON_OM_SNAPSHOT_TASK_INTERVAL;
+import static org.apache.hadoop.ozone.recon.
+    ReconServerConfigKeys.RECON_OM_SNAPSHOT_TASK_INTERVAL_DEFAULT;
+
+/**
+ * Test Ozone Recon.
+ */
+public class TestRecon {
+  private static MiniOzoneCluster cluster = null;
+  private static OzoneConfiguration conf;
+  private static OMMetadataManager metadataManager;
+  private static File dir;
+  private static UserGroupInformation ugi;
+  private static CloseableHttpClient httpClient;
+  private static ReconUtils reconUtils;
+  private static long pauseInterval;
+  private String reconHTTPAddress = conf.get(OZONE_RECON_HTTP_ADDRESS_KEY);
+  private String containerKeyServiceURL = "http://"; + reconHTTPAddress
+      + "/api/containers";
+  private String fileSizeCountURL = "http://"; + reconHTTPAddress
+      + "/api/utilization";
+  private String taskStatusURL = "http://"; + reconHTTPAddress
+      + "/api/task/status";
+
+  @BeforeClass
+  public static void init() throws Exception {
+    dir = GenericTestUtils.getRandomizedTestDir();
+    conf = new OzoneConfiguration();
+    conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, dir.toString());
+    ugi = UserGroupInformation.getCurrentUser();
+
+
+    int socketTimeout = (int) conf.getTimeDuration(
+        RECON_OM_SOCKET_TIMEOUT, RECON_OM_SOCKET_TIMEOUT_DEFAULT,
+        TimeUnit.MILLISECONDS);
+    int connectionTimeout = (int) conf.getTimeDuration(
+        RECON_OM_CONNECTION_TIMEOUT,
+        RECON_OM_CONNECTION_TIMEOUT_DEFAULT, TimeUnit.MILLISECONDS);
+    int connectionRequestTimeout = (int)conf.getTimeDuration(
+        RECON_OM_CONNECTION_REQUEST_TIMEOUT,
+        RECON_OM_CONNECTION_REQUEST_TIMEOUT_DEFAULT, TimeUnit.MILLISECONDS);
+    RequestConfig config = RequestConfig.custom()
+        .setConnectTimeout(socketTimeout)
+        .setConnectionRequestTimeout(connectionTimeout)
+        .setSocketTimeout(connectionRequestTimeout).build();
+
+    cluster =  MiniOzoneCluster.newBuilder(conf).build();
+    cluster.waitForClusterToBeReady();
+    metadataManager = cluster.getOzoneManager().getMetadataManager();
+
+    cluster.getStorageContainerManager().exitSafeMode();
+    reconUtils = cluster.getReconServer().getInjector().getInstance(
+        ReconUtils.class);
+
+    // initialize HTTPClient
+    httpClient = HttpClientBuilder
+        .create()
+        .setDefaultRequestConfig(config)
+        .build();
+
+    pauseInterval = conf.getTimeDuration(
+        conf.get(RECON_OM_SNAPSHOT_TASK_INTERVAL),
+        conf.get(RECON_OM_SNAPSHOT_TASK_INTERVAL_DEFAULT),
+        TimeUnit.MILLISECONDS);
+  }
+
+  @AfterClass
+  public static void shutdown() {
+    if (cluster != null) {
+      cluster.shutdown();
+    }
+  }
+
+  /**
+   * Returns a {@link CloseableHttpClient} configured by given configuration.
+   * If conf is null, returns a default instance.
+   *
+   * @param url        URL
+   * @return a JSON String Response.
+   */
+  private String makeHttpCall(String url)
+      throws IOException {
+    HttpGet httpGet = new HttpGet(url);
+    HttpResponse response = httpClient.execute(httpGet);
+    int errorCode = response.getStatusLine().getStatusCode();
+    HttpEntity entity = response.getEntity();
+
+    if ((errorCode == HTTP_OK) || (errorCode == HTTP_CREATED)) {
+      return EntityUtils.toString(entity);
+    }
+
+    if (entity != null) {
+      throw new IOException("Unexpected exception when trying to reach Ozone " 
+
+          "Manager, " + EntityUtils.toString(entity));
+    } else {
+      throw new IOException("Unexpected null in http payload," +
+          " while processing request");
+    }
+  }
+
+  @Test
+  public void testReconServer() throws Exception {
+    //add a vol, bucket and key
+    addKeys(0, 1);
+
+    //check if OM metadata has vol0/bucket0/key0 info
+    String ozoneKey = metadataManager.getOzoneKey(
+        "vol0", "bucket0", "key0");
+    OmKeyInfo keyInfo1 = metadataManager.getKeyTable().get(ozoneKey);
+
+    TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>>
+        omKeyValueTableIterator = metadataManager.getKeyTable().iterator();
+
+    long omMetadataKeyCount = getTableKeyCount(omKeyValueTableIterator);
+
+    //verify if OM has /vol0/bucket0/key0
+    Assert.assertEquals("vol0", keyInfo1.getVolumeName());
+    Assert.assertEquals("bucket0", keyInfo1.getBucketName());
+
+    //pause to get the next snapshot from om
+    Thread.sleep(pauseInterval);
+
+    // HTTP call to /api/containers
+    String containerResponse = makeHttpCall(containerKeyServiceURL);
+    Map map = new Gson().fromJson(containerResponse, HashMap.class);
+    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) map.get("data");
+    long reconMetadataKeyCount = (long)(double)linkedTreeMap.get("totalCount");
+
+    //verify count of keys after full snapshot
+    Assert.assertEquals(omMetadataKeyCount, reconMetadataKeyCount);
+
+    //verify if Recon Metadata captures vol0/bucket0/key0 info in container0
+    ArrayList containers = (ArrayList) linkedTreeMap.get("containers");
+    LinkedTreeMap nestedContainerMap = (LinkedTreeMap)containers.get(0);
+    Assert.assertEquals(1.0, nestedContainerMap.get("NumberOfKeys"));
 
 Review comment:
   Can we also verify containerId if 0? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to