-
Notifications
You must be signed in to change notification settings - Fork 3k
Dell: Add Dell EMC EcsFileIO. #3376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c033947
Ecs File IO.
wang-x-xia e1eea69
Add unit test with client-side mock.
wang-x-xia af7e750
1. Fix the copyright.
wang-x-xia ba9dcc3
1. Separate EcsFile to EcsInputFile and EcsOutputFile.
wang-x-xia c9b785a
Fix Copyright.
wang-x-xia 96f85a1
Fix checkStyle.
wang-x-xia aaacceb
1. Create factory method for EcsAppendOutputStream.
wang-x-xia ba7beb0
Rename factory methods of EcsAppendOutputStream.
wang-x-xia 3a21b44
Replace IOUtils to Guava ByteStreams.
wang-x-xia d79d2b0
Remove closed flag in EcsFileIO.
wang-x-xia ef996a0
1. Move EcsURI to package-private.
wang-x-xia ab0e5b0
1. Fix checkstyle.
wang-x-xia aa9c843
Use AssertHelpers.assertThrows.
wang-x-xia 7a5dce3
Merge branch 'master' into feature-ecs-fileio
wang-x-xia 7eff9a6
Unify with existed codes.
wang-x-xia d1f6128
Check code style of test code.
wang-x-xia a751aa3
Add prefix for properties' keys.
wang-x-xia ef7e267
Merge branch 'master' into feature-ecs-fileio
wang-x-xia 1e8419b
Fix the class name.
wang-x-xia 57978d8
Merge remote-tracking branch 'github/master' into feature-ecs-fileio
wang-x-xia 48807d8
Merge remote-tracking branch 'github/master' into feature-ecs-fileio
wang-x-xia 4a1b982
1. Fix the fields' name and comment.
wang-x-xia 54f369f
Remove unused imports.
wang-x-xia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
dell/src/main/java/org/apache/iceberg/dell/DellClientFactories.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * 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 org.apache.iceberg.common.DynConstructors; | ||
| import org.apache.iceberg.util.PropertyUtil; | ||
|
|
||
| public class DellClientFactories { | ||
|
|
||
| private DellClientFactories() { | ||
| } | ||
|
|
||
| public static DellClientFactory from(Map<String, String> properties) { | ||
| String factoryImpl = PropertyUtil.propertyAsString( | ||
| properties, DellProperties.CLIENT_FACTORY, DefaultDellClientFactory.class.getName()); | ||
| return loadClientFactory(factoryImpl, properties); | ||
| } | ||
|
|
||
| private static DellClientFactory loadClientFactory(String impl, Map<String, String> properties) { | ||
| DynConstructors.Ctor<DellClientFactory> ctor; | ||
| try { | ||
| ctor = DynConstructors.builder(DellClientFactory.class).hiddenImpl(impl).buildChecked(); | ||
| } catch (NoSuchMethodException e) { | ||
| throw new IllegalArgumentException(String.format( | ||
| "Cannot initialize DellClientFactory, missing no-arg constructor: %s", impl), e); | ||
| } | ||
|
|
||
| DellClientFactory factory; | ||
| try { | ||
| factory = ctor.newInstance(); | ||
| } catch (ClassCastException e) { | ||
| throw new IllegalArgumentException( | ||
| String.format("Cannot initialize DellClientFactory, %s does not implement DellClientFactory.", impl), e); | ||
| } | ||
|
|
||
| factory.initialize(properties); | ||
| return factory; | ||
| } | ||
|
|
||
| static class DefaultDellClientFactory implements DellClientFactory { | ||
| private DellProperties dellProperties; | ||
|
|
||
| DefaultDellClientFactory() { | ||
| } | ||
|
|
||
| @Override | ||
| public S3Client ecsS3() { | ||
| S3Config config = new S3Config(URI.create(dellProperties.ecsS3Endpoint())); | ||
|
|
||
| config.withIdentity(dellProperties.ecsS3AccessKeyId()) | ||
| .withSecretKey(dellProperties.ecsS3SecretAccessKey()); | ||
|
|
||
| return new S3JerseyClient(config); | ||
| } | ||
|
|
||
| @Override | ||
| public void initialize(Map<String, String> properties) { | ||
| this.dellProperties = new DellProperties(properties); | ||
| } | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
dell/src/main/java/org/apache/iceberg/dell/DellClientFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * 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 java.util.Map; | ||
|
|
||
| public interface DellClientFactory { | ||
|
|
||
| /** | ||
| * Create a Dell EMC ECS S3 client | ||
| * | ||
| * @return Dell EMC ECS S3 client | ||
| */ | ||
| S3Client ecsS3(); | ||
|
|
||
| /** | ||
| * Initialize Dell EMC ECS client factory from catalog properties. | ||
| * | ||
| * @param properties catalog properties | ||
| */ | ||
| void initialize(Map<String, String> properties); | ||
| } |
84 changes: 84 additions & 0 deletions
84
dell/src/main/java/org/apache/iceberg/dell/DellProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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 java.io.Serializable; | ||
| import java.util.Map; | ||
|
|
||
| public class DellProperties implements Serializable { | ||
| /** | ||
| * S3 Access key id of Dell EMC ECS | ||
| */ | ||
| public static final String ECS_S3_ACCESS_KEY_ID = "ecs.s3.access-key-id"; | ||
|
|
||
| /** | ||
| * S3 Secret access key of Dell EMC ECS | ||
| */ | ||
| public static final String ECS_S3_SECRET_ACCESS_KEY = "ecs.s3.secret-access-key"; | ||
|
|
||
| /** | ||
| * S3 endpoint of Dell EMC ECS | ||
| */ | ||
| public static final String ECS_S3_ENDPOINT = "ecs.s3.endpoint"; | ||
|
|
||
| /** | ||
| * The implementation class of {@link DellClientFactory} to customize Dell client configurations. | ||
| * If set, all Dell clients will be initialized by the specified factory. | ||
| * If not set, {@link DellClientFactories.DefaultDellClientFactory} is used as default factory. | ||
| */ | ||
| public static final String CLIENT_FACTORY = "client.factory"; | ||
|
|
||
| private String ecsS3Endpoint; | ||
| private String ecsS3AccessKeyId; | ||
| private String ecsS3SecretAccessKey; | ||
|
|
||
| public DellProperties() { | ||
| } | ||
|
|
||
| public DellProperties(Map<String, String> properties) { | ||
| this.ecsS3AccessKeyId = properties.get(DellProperties.ECS_S3_ACCESS_KEY_ID); | ||
| this.ecsS3SecretAccessKey = properties.get(DellProperties.ECS_S3_SECRET_ACCESS_KEY); | ||
| this.ecsS3Endpoint = properties.get(DellProperties.ECS_S3_ENDPOINT); | ||
| } | ||
|
|
||
| public String ecsS3Endpoint() { | ||
| return ecsS3Endpoint; | ||
| } | ||
|
|
||
| public void setEcsS3Endpoint(String ecsS3Endpoint) { | ||
openinx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.ecsS3Endpoint = ecsS3Endpoint; | ||
| } | ||
|
|
||
| public String ecsS3AccessKeyId() { | ||
| return ecsS3AccessKeyId; | ||
| } | ||
|
|
||
| public void setEcsS3AccessKeyId(String ecsS3AccessKeyId) { | ||
| this.ecsS3AccessKeyId = ecsS3AccessKeyId; | ||
| } | ||
|
|
||
| public String ecsS3SecretAccessKey() { | ||
| return ecsS3SecretAccessKey; | ||
| } | ||
|
|
||
| public void setEcsS3SecretAccessKey(String ecsS3SecretAccessKey) { | ||
| this.ecsS3SecretAccessKey = ecsS3SecretAccessKey; | ||
| } | ||
| } | ||
86 changes: 86 additions & 0 deletions
86
dell/src/main/java/org/apache/iceberg/dell/ecs/BaseEcsFile.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * 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.ecs; | ||
|
|
||
| import com.emc.object.s3.S3Client; | ||
| import com.emc.object.s3.S3Exception; | ||
| import com.emc.object.s3.S3ObjectMetadata; | ||
| import org.apache.iceberg.dell.DellProperties; | ||
|
|
||
| abstract class BaseEcsFile { | ||
|
|
||
| private final S3Client client; | ||
| private final EcsURI uri; | ||
| private final DellProperties dellProperties; | ||
| private S3ObjectMetadata metadata; | ||
|
|
||
| BaseEcsFile(S3Client client, EcsURI uri, DellProperties dellProperties) { | ||
| this.client = client; | ||
| this.uri = uri; | ||
| this.dellProperties = dellProperties; | ||
| } | ||
|
|
||
| public String location() { | ||
| return uri.location(); | ||
| } | ||
|
|
||
| S3Client client() { | ||
| return client; | ||
| } | ||
|
|
||
| EcsURI uri() { | ||
| return uri; | ||
| } | ||
|
|
||
| public DellProperties dellProperties() { | ||
| return dellProperties; | ||
| } | ||
|
|
||
| /** | ||
| * Note: this may be stale if file was deleted since metadata is cached for size/existence checks. | ||
| * | ||
| * @return flag | ||
| */ | ||
| public boolean exists() { | ||
| try { | ||
| getObjectMetadata(); | ||
| return true; | ||
| } catch (S3Exception e) { | ||
| if (e.getHttpCode() == 404) { | ||
| return false; | ||
| } else { | ||
| throw e; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected S3ObjectMetadata getObjectMetadata() throws S3Exception { | ||
| if (metadata == null) { | ||
| metadata = client().getObjectMetadata(uri.bucket(), uri.name()); | ||
| } | ||
|
|
||
| return metadata; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return uri.toString(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.