Skip to content
Merged
Show file tree
Hide file tree
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 Oct 25, 2021
e1eea69
Add unit test with client-side mock.
wang-x-xia Oct 26, 2021
af7e750
1. Fix the copyright.
wang-x-xia Oct 26, 2021
ba9dcc3
1. Separate EcsFile to EcsInputFile and EcsOutputFile.
wang-x-xia Oct 27, 2021
c9b785a
Fix Copyright.
wang-x-xia Oct 27, 2021
96f85a1
Fix checkStyle.
wang-x-xia Oct 27, 2021
aaacceb
1. Create factory method for EcsAppendOutputStream.
wang-x-xia Nov 4, 2021
ba7beb0
Rename factory methods of EcsAppendOutputStream.
wang-x-xia Nov 4, 2021
3a21b44
Replace IOUtils to Guava ByteStreams.
wang-x-xia Nov 4, 2021
d79d2b0
Remove closed flag in EcsFileIO.
wang-x-xia Nov 4, 2021
ef996a0
1. Move EcsURI to package-private.
wang-x-xia Nov 5, 2021
ab0e5b0
1. Fix checkstyle.
wang-x-xia Nov 5, 2021
aa9c843
Use AssertHelpers.assertThrows.
wang-x-xia Nov 5, 2021
7a5dce3
Merge branch 'master' into feature-ecs-fileio
wang-x-xia Jan 11, 2022
7eff9a6
Unify with existed codes.
wang-x-xia Jan 11, 2022
d1f6128
Check code style of test code.
wang-x-xia Jan 12, 2022
a751aa3
Add prefix for properties' keys.
wang-x-xia Jan 12, 2022
ef7e267
Merge branch 'master' into feature-ecs-fileio
wang-x-xia Feb 14, 2022
1e8419b
Fix the class name.
wang-x-xia Feb 16, 2022
57978d8
Merge remote-tracking branch 'github/master' into feature-ecs-fileio
wang-x-xia Feb 16, 2022
48807d8
Merge remote-tracking branch 'github/master' into feature-ecs-fileio
wang-x-xia Feb 16, 2022
4a1b982
1. Fix the fields' name and comment.
wang-x-xia Feb 17, 2022
54f369f
Remove unused imports.
wang-x-xia Feb 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,24 @@ project(':iceberg-nessie') {
}
}

project(':iceberg-dell') {
dependencies {
implementation project(':iceberg-core')
implementation project(':iceberg-common')
implementation project(path: ':iceberg-bundled-guava', configuration: 'shadow')
compileOnly 'com.emc.ecs:object-client-bundle'

testImplementation project(path: ':iceberg-api', configuration: 'testArtifacts')
testImplementation("org.apache.hadoop:hadoop-common") {
exclude group: 'org.apache.avro', module: 'avro'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
}
testImplementation "javax.xml.bind:jaxb-api"
testImplementation "javax.activation:activation"
testImplementation "org.glassfish.jaxb:jaxb-runtime"
}
}

@Memoized
boolean versionFileExists() {
return file('version.txt').exists()
Expand Down
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 dell/src/main/java/org/apache/iceberg/dell/DellClientFactory.java
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 dell/src/main/java/org/apache/iceberg/dell/DellProperties.java
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) {
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 dell/src/main/java/org/apache/iceberg/dell/ecs/BaseEcsFile.java
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();
}
}
Loading