Jackie-Jiang commented on a change in pull request #6842:
URL: https://github.com/apache/incubator-pinot/pull/6842#discussion_r630577925



##########
File path: 
pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
##########
@@ -665,4 +731,4 @@ public static void main(String[] args)
       throws Exception {
     startDefault();
   }
-}
+}

Review comment:
       Revert

##########
File path: 
pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
##########
@@ -118,6 +120,7 @@
   private AdminApiApplication _adminApiApplication;
   private ServerQueriesDisabledTracker _serverQueriesDisabledTracker;
   private RealtimeLuceneIndexRefreshState _realtimeLuceneIndexRefreshState;
+  private static Map<String, Map<String, String>> environmentSpecificMapFields 
= new HashMap<>();

Review comment:
       This should not be static.
   We don't need to keep a map of map
   ```suggestion
     private Map<String, String> environmentProperties;
   ```

##########
File path: 
pinot-plugins/pinot-environment/pinot-azure/src/main/java/org/apache/pinot/plugin/provider/AzureEnvironmentProvider.java
##########
@@ -0,0 +1,172 @@
+/**
+ * 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.pinot.plugin.provider;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.net.ssl.SSLException;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpStatus;
+import org.apache.http.StatusLine;
+import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.environmentprovider.PinotEnvironmentProvider;
+import org.apache.pinot.spi.utils.CommonConstants;
+
+
+/**
+ * Azure Environment Provider used to retrieve azure cloud specific instance 
configuration.
+ */
+public class AzureEnvironmentProvider implements PinotEnvironmentProvider {
+  protected static final String MAX_RETRY = "maxRetry";
+  protected static final String IMDS_ENDPOINT = "imdsEndpoint";
+  protected static final String CONNECTION_TIMEOUT = "connectionTimeout";
+  protected static final String REQUEST_TIMEOUT = "requestTimeout";
+  private static final String COMPUTE = "compute";
+  private static final String METADATA = "Metadata";
+  private static final String PLATFORM_FAULT_DOMAIN = "platformFaultDomain";
+  private int _maxRetry;
+  private String _imdsEndpoint;
+  private CloseableHttpClient _closeableHttpClient;
+  private PinotConfiguration _serverConfigs;
+
+  public AzureEnvironmentProvider() {
+  }
+
+  public void init(PinotConfiguration pinotConfiguration) {
+    _serverConfigs = pinotConfiguration;
+    Preconditions.checkArgument(0 < 
Integer.parseInt(_serverConfigs.getProperty(MAX_RETRY)),
+         "[AzureEnvironmentProvider]: " + MAX_RETRY + " cannot be less than or 
equal to 0");
+    
Preconditions.checkArgument(!StringUtils.isBlank(_serverConfigs.getProperty(IMDS_ENDPOINT)),
+        "[AzureEnvironmentProvider]: " + IMDS_ENDPOINT + " should not be null 
or empty");
+
+    _maxRetry = Integer.parseInt(_serverConfigs.getProperty(MAX_RETRY));
+    _imdsEndpoint = _serverConfigs.getProperty(IMDS_ENDPOINT);
+    int connectionTimeout = 
Integer.parseInt(_serverConfigs.getProperty(CONNECTION_TIMEOUT));
+    int requestTimeout = 
Integer.parseInt(_serverConfigs.getProperty(REQUEST_TIMEOUT));
+
+    final RequestConfig requestConfig = RequestConfig.custom()
+        .setConnectTimeout(connectionTimeout)
+        .setConnectionRequestTimeout(requestTimeout)
+        .build();
+
+    final HttpRequestRetryHandler httpRequestRetryHandler = (iOException, 
executionCount, httpContext) ->
+        !(executionCount >= _maxRetry
+            || iOException instanceof InterruptedIOException
+            || iOException instanceof UnknownHostException
+            || iOException instanceof SSLException
+            || HttpClientContext.adapt(httpContext).getRequest() instanceof 
HttpEntityEnclosingRequest);
+
+    _closeableHttpClient =
+        
HttpClients.custom().setDefaultRequestConfig(requestConfig).setRetryHandler(httpRequestRetryHandler).build();
+  }
+
+  // Constructor for test purposes.
+  @VisibleForTesting
+  public AzureEnvironmentProvider(int maxRetry, String imdsEndpoint, 
CloseableHttpClient closeableHttpClient) {
+    _maxRetry = maxRetry;
+    _imdsEndpoint = imdsEndpoint;
+    _closeableHttpClient = Preconditions.checkNotNull(closeableHttpClient,
+        "[AzureEnvironmentProvider]: Closeable Http Client cannot be null");
+  }
+
+  /**
+   *
+   * Method for constructing custom pinot configuration used by the 
HelixServerStarter to update
+   * zookeeper node with custom instance configs.
+   * @return custom pinot configuration map
+   */
+  @Override
+  public Map<String, Object> getEnvironment() {
+    Map<String, Object> customPinotConfiguration = new 
HashMap<>(_serverConfigs.toMap());

Review comment:
       Any specific reason why we put all server configs into the environment? 
This would include configs such as `maxRetry`, `connectionTimeout` which are 
not related to environment.
   If we only put properties that we want to store in helix, in the 
`HelixServerStarter` we can simply put the whole map as the environment. This 
way is more generic, and works if we add more properties in the future.

##########
File path: 
pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
##########
@@ -261,6 +308,22 @@ private void updateInstanceConfigIfNeeded(String host, int 
port) {
         "Failed to update instance config");
   }
 
+  // Update instance configs with environment specific properties
+  private void updateInstanceConfigWithEnvironmentSpecificConfigs() {

Review comment:
       Suggest merging this into the `updateInstanceConfigIfNeeded`




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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to