HoustonPutman commented on a change in pull request #120:
URL: https://github.com/apache/solr/pull/120#discussion_r674134226



##########
File path: 
solr/contrib/s3-repository/src/java/org/apache/solr/s3/S3StorageClient.java
##########
@@ -0,0 +1,491 @@
+/*
+ * 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.solr.s3;
+
+import com.amazonaws.AmazonClientException;
+import com.amazonaws.AmazonServiceException;
+import com.amazonaws.ClientConfiguration;
+import com.amazonaws.Protocol;
+import com.amazonaws.client.builder.AwsClientBuilder;
+import com.amazonaws.services.s3.AmazonS3;
+import com.amazonaws.services.s3.AmazonS3ClientBuilder;
+import com.amazonaws.services.s3.model.DeleteObjectsRequest;
+import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion;
+import com.amazonaws.services.s3.model.DeleteObjectsResult;
+import com.amazonaws.services.s3.model.ListObjectsRequest;
+import com.amazonaws.services.s3.model.ObjectListing;
+import com.amazonaws.services.s3.model.ObjectMetadata;
+import com.amazonaws.services.s3.model.PutObjectRequest;
+import com.amazonaws.services.s3.model.S3Object;
+import com.amazonaws.services.s3.model.S3ObjectSummary;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
+import org.apache.commons.io.input.ClosedInputStream;
+import org.apache.solr.common.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+
+/**
+ * Creates a {@link AmazonS3} for communicating with AWS S3. Utilizes the 
default credential provider chain;
+ * reference <a 
href="https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html";>AWS
 SDK docs</a> for
+ * details on where this client will fetch credentials from, and the order of 
precedence.
+ */
+class S3StorageClient {
+
+    private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+    static final String BLOB_FILE_PATH_DELIMITER = "/";
+
+    // S3 has a hard limit of 1000 keys per batch delete request
+    private static final int MAX_KEYS_PER_BATCH_DELETE = 1000;
+
+    // Metadata name used to identify flag directory entries in S3
+    private static final String BLOB_DIR_HEADER = "x_is_directory";
+
+    // Error messages returned by S3 for a key not found.
+    private static final Set<String> NOT_FOUND_CODES = Set.of("NoSuchKey", 
"404 Not Found");
+
+    private final AmazonS3 s3Client;
+
+    /**
+     * The S3 bucket where we write all of our blobs to.
+     */
+    private final String bucketName;
+
+    S3StorageClient(String bucketName, String region, String proxyHost, int 
proxyPort, String endpoint) {
+        this(createInternalClient(region, proxyHost, proxyPort, endpoint), 
bucketName);
+    }
+
+    @VisibleForTesting
+    S3StorageClient(AmazonS3 s3Client, String bucketName) {
+        this.s3Client = s3Client;
+        this.bucketName = bucketName;
+    }
+
+    private static AmazonS3 createInternalClient(String region, String 
proxyHost, int proxyPort, String endpoint) {
+        ClientConfiguration clientConfig = new ClientConfiguration()
+            .withProtocol(Protocol.HTTPS);
+
+        // If configured, add proxy
+        if (!StringUtils.isEmpty(proxyHost)) {
+            clientConfig.setProxyHost(proxyHost);
+            if (proxyPort > 0) {
+                clientConfig.setProxyPort(proxyPort);
+            }
+        }
+
+        /*
+         * Default s3 client builder loads credentials from disk and handles 
token refreshes
+         */
+        AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard()
+            .enablePathStyleAccess()
+            .withClientConfiguration(clientConfig);
+
+        if (!StringUtils.isEmpty(endpoint)) {
+            clientBuilder.setEndpointConfiguration(
+                new AwsClientBuilder.EndpointConfiguration(endpoint, region)
+            );
+        } else {
+            clientBuilder.setRegion(region);

Review comment:
       I left this as a string, because the SDK will convert it to a Region 
object itself. Easier for us to not think about 🙂 




-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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

Reply via email to