wang-x-xia commented on a change in pull request #3376:
URL: https://github.com/apache/iceberg/pull/3376#discussion_r743434262



##########
File path: build.gradle
##########
@@ -566,6 +566,23 @@ project(':iceberg-nessie') {
   }
 }
 
+project(':iceberg-dell') {
+  dependencies {
+    implementation project(':iceberg-core')
+    implementation project(':iceberg-common')
+    implementation project(path: ':iceberg-bundled-guava', configuration: 
'shadow')
+    implementation 'com.emc.ecs:object-client-bundle'

Review comment:
       Done.

##########
File path: dell/src/main/java/org/apache/iceberg/dell/EcsClientFactory.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.iceberg.dell;
+
+import com.emc.object.s3.S3Client;
+import com.emc.object.s3.S3Config;
+import com.emc.object.s3.jersey.S3JerseyClient;
+import java.net.URI;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.iceberg.common.DynConstructors;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+public interface EcsClientFactory {
+
+  /**
+   * Create the ECS S3 Client from properties
+   */
+  static S3Client create(Map<String, String> properties) {
+    return createWithFactory(properties).orElseGet(() -> 
createDefault(properties));
+  }
+
+  /**
+   * Try to create the ECS S3 client from factory method.
+   */
+  static Optional<S3Client> createWithFactory(Map<String, String> properties) {
+    String factory = properties.get(EcsClientProperties.ECS_CLIENT_FACTORY);
+    if (factory == null || factory.isEmpty()) {
+      return Optional.empty();
+    }
+
+    DynConstructors.Ctor<EcsClientFactory> ctor;
+    try {
+      ctor = 
DynConstructors.builder(EcsClientFactory.class).impl(factory).buildChecked();
+    } catch (NoSuchMethodException e) {
+      throw new IllegalArgumentException(String.format(
+          "Cannot find EcsClientFactory implementation %s: %s", factory, 
e.getMessage()), e);
+    }
+
+    EcsClientFactory clientFactory;
+    try {
+      clientFactory = ctor.newInstance();
+    } catch (ClassCastException e) {
+      throw new IllegalArgumentException(
+          String.format("Cannot initialize Catalog, %s does not implement 
EcsClientFactory.", factory), e);

Review comment:
       Done.

##########
File path: dell/src/main/java/org/apache/iceberg/dell/EcsClientFactory.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.iceberg.dell;
+
+import com.emc.object.s3.S3Client;
+import com.emc.object.s3.S3Config;
+import com.emc.object.s3.jersey.S3JerseyClient;
+import java.net.URI;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.iceberg.common.DynConstructors;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+public interface EcsClientFactory {
+
+  /**
+   * Create the ECS S3 Client from properties
+   */
+  static S3Client create(Map<String, String> properties) {
+    return createWithFactory(properties).orElseGet(() -> 
createDefault(properties));
+  }
+
+  /**
+   * Try to create the ECS S3 client from factory method.
+   */
+  static Optional<S3Client> createWithFactory(Map<String, String> properties) {
+    String factory = properties.get(EcsClientProperties.ECS_CLIENT_FACTORY);
+    if (factory == null || factory.isEmpty()) {
+      return Optional.empty();
+    }
+
+    DynConstructors.Ctor<EcsClientFactory> ctor;
+    try {
+      ctor = 
DynConstructors.builder(EcsClientFactory.class).impl(factory).buildChecked();
+    } catch (NoSuchMethodException e) {
+      throw new IllegalArgumentException(String.format(
+          "Cannot find EcsClientFactory implementation %s: %s", factory, 
e.getMessage()), e);
+    }
+
+    EcsClientFactory clientFactory;
+    try {
+      clientFactory = ctor.newInstance();
+    } catch (ClassCastException e) {
+      throw new IllegalArgumentException(
+          String.format("Cannot initialize Catalog, %s does not implement 
EcsClientFactory.", factory), e);
+    }
+
+    S3Client client = clientFactory.createS3Client(properties);
+
+    if (client == null) {
+      throw new IllegalArgumentException(String.format(
+          "Invalid EcsClientFactory %s that return null client",
+          factory));
+    }
+
+    return Optional.of(client);
+  }
+
+  /**
+   * Get built-in ECS S3 client.
+   */
+  static S3Client createDefault(Map<String, String> properties) {
+    Preconditions.checkNotNull(properties.get(EcsClientProperties.ENDPOINT),
+        "Endpoint(%s) cannot be null", EcsClientProperties.ENDPOINT);

Review comment:
       Done.




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