ashishkumar50 commented on code in PR #4540:
URL: https://github.com/apache/ozone/pull/4540#discussion_r1187033227


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/handlers/BucketHandler.java:
##########
@@ -196,8 +197,12 @@ public static BucketHandler getBucketHandler(
       String volumeName, String bucketName) throws IOException {
 
     String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
-    OmBucketInfo bucketInfo = omMetadataManager
-        .getBucketTable().getSkipCache(bucketKey);
+    Table<String, OmBucketInfo> bucketTable =
+        omMetadataManager.getBucketTable();
+    OmBucketInfo bucketInfo = null;
+    if (null != bucketTable) {
+      bucketInfo = bucketTable.getSkipCache(bucketKey);
+    }
 
     return getBucketHandler(reconNamespaceSummaryManager,
         omMetadataManager, reconSCM, bucketInfo);

Review Comment:
   We can move getBucketHandler call also inside if (null != bucketTable), so 
that no need to call getBucketHandler if bucketInfo is null.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/http/SolrHttpClient.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.http;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.NameValuePair;
+import org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.client.config.AuthSchemes;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.config.Lookup;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.TrustStrategy;
+import org.apache.http.impl.auth.SPNegoSchemeFactory;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Singleton;
+import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Principal;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.List;
+
+/**
+ * This class is used to make http
+ * GET and POST requests to Apache Solr.
+ */
+@Singleton
+public class SolrHttpClient {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(SolrHttpClient.class);
+
+  private static CloseableHttpClient httpClient;
+  private static HttpClientContext context;
+
+  public static CloseableHttpClient getCloseableHttpClient() {
+    if (null != httpClient) {
+      return httpClient;
+    }
+    try {
+      System.setProperty("sun.security.krb5.debug", "true");
+      System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
+      Lookup<AuthSchemeProvider> authSchemeRegistry =
+          RegistryBuilder.<AuthSchemeProvider>create()
+              .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true))
+              .build();
+      httpClient = HttpClients.custom()
+          .setSSLHostnameVerifier(
+              NoopHostnameVerifier.INSTANCE)
+          .setSSLContext(new SSLContextBuilder().loadTrustMaterial(
+              null, new TrustStrategy() {
+                public boolean isTrusted(X509Certificate[] arg0, String arg1)
+                    throws CertificateException {
+                  return true;
+                }
+              }).build())
+          .setDefaultAuthSchemeRegistry(authSchemeRegistry).build();
+    } catch (KeyManagementException e) {
+      LOG.error("KeyManagementException in creating http client instance", e);
+    } catch (NoSuchAlgorithmException e) {
+      LOG.error("NoSuchAlgorithmException in creating http client instance", 
e);
+    } catch (KeyStoreException e) {
+      LOG.error("KeyStoreException in creating http client instance", e);
+    }
+    return httpClient;

Review Comment:
   httpClient can be null when above exceptions are thrown and catch , which 
in-turn will throw NPE in caller httpClient.execute(), better to propagate 
exception or handle NULL cases to avoid calling http execute method.



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java:
##########
@@ -350,6 +352,52 @@ public static InetSocketAddress getReconAddresses(
     return NetUtils.createSocketAddr(hostname.get(), port);
   }
 
+  /**
+   * Retrieve the socket addresses of Apache Solr Server.
+   *
+   * @return Apache Solr server address
+   * @throws IllegalArgumentException If the configuration is invalid
+   */
+  public static InetSocketAddress getSolrAddress(
+      ConfigurationSource conf) {
+    String solrAddresses = conf.get(OZONE_SOLR_ADDRESS_KEY);
+    LOG.info("Solr Live Host Addresses: {}", solrAddresses);
+    if (StringUtils.isEmpty(solrAddresses)) {
+      throw new IllegalArgumentException(String.format("For heatmap " +
+              "feature Solr host and port configuration must be provided " +
+              "for config key %s. Example format -> <Host>:<Port>",
+          OZONE_SOLR_ADDRESS_KEY));
+    }
+    String[] splitAddresses = solrAddresses.split(",");
+    if (solrAddresses.length() > 0) {
+      String name = splitAddresses[0];
+      if (StringUtils.isEmpty(name)) {
+        return null;
+      }
+      Optional<String> hostname = getHostName(name);
+      if (!hostname.isPresent()) {
+        throw new IllegalArgumentException("Invalid hostname for Solr Server: "

Review Comment:
   If multiple solr addresses are configured then we are considering only first.
   If first address is not valid, can we try with next one? Or we need to just 
consider first one?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to