Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static org.apache.hadoop.ozone.s3.util.S3Consts.ENCODING_TYPE;
import static org.apache.hadoop.ozone.s3.util.S3Utils.wrapInQuotes;

import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
Expand All @@ -42,7 +41,6 @@
import java.util.Objects;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
Expand All @@ -53,12 +51,9 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.audit.S3GAction;
import org.apache.hadoop.ozone.client.OzoneBucket;
Expand Down Expand Up @@ -94,15 +89,9 @@ public class BucketEndpoint extends EndpointBase {
private static final Logger LOG =
LoggerFactory.getLogger(BucketEndpoint.class);

@Context
private HttpHeaders headers;

private boolean listKeysShallowEnabled;
private int maxKeysLimit = 1000;

@Inject
private OzoneConfiguration ozoneConfiguration;

/**
* Rest endpoint to list objects in a specific bucket.
* <p>
Expand Down Expand Up @@ -171,7 +160,7 @@ public Response get(
&& OZONE_URI_DELIMITER.equals(delimiter);

bucket = getBucket(bucketName);
S3Owner.verifyBucketOwnerCondition(headers, bucketName, bucket.getOwner());
S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName, bucket.getOwner());

ozoneKeyIterator = bucket.listKeys(prefix, prevKey, shallow);

Expand Down Expand Up @@ -369,7 +358,7 @@ public Response listMultipartUploads(
OzoneBucket bucket = getBucket(bucketName);

try {
S3Owner.verifyBucketOwnerCondition(headers, bucketName, bucket.getOwner());
S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName, bucket.getOwner());
OzoneMultipartUploadList ozoneMultipartUploadList =
bucket.listMultipartUploads(prefix, keyMarker, uploadIdMarker, maxUploads);

Expand Down Expand Up @@ -423,7 +412,7 @@ public Response head(@PathParam("bucket") String bucketName)
S3GAction s3GAction = S3GAction.HEAD_BUCKET;
try {
OzoneBucket bucket = getBucket(bucketName);
S3Owner.verifyBucketOwnerCondition(headers, bucketName, bucket.getOwner());
S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName, bucket.getOwner());
AUDIT.logReadSuccess(
buildAuditMessageForSuccess(s3GAction, getAuditParameters()));
getMetrics().updateHeadBucketSuccessStats(startNanos);
Expand All @@ -448,9 +437,9 @@ public Response delete(@PathParam("bucket") String bucketName)
S3GAction s3GAction = S3GAction.DELETE_BUCKET;

try {
if (S3Owner.hasBucketOwnershipVerificationConditions(headers)) {
if (S3Owner.hasBucketOwnershipVerificationConditions(getHeaders())) {
OzoneBucket bucket = getBucket(bucketName);
S3Owner.verifyBucketOwnerCondition(headers, bucketName, bucket.getOwner());
S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName, bucket.getOwner());
}
deleteS3Bucket(bucketName);
} catch (OMException ex) {
Expand Down Expand Up @@ -506,7 +495,7 @@ public MultiDeleteResponse multiDelete(@PathParam("bucket") String bucketName,
}
long startNanos = Time.monotonicNowNanos();
try {
S3Owner.verifyBucketOwnerCondition(headers, bucketName, bucket.getOwner());
S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName, bucket.getOwner());
undeletedKeyResultMap = bucket.deleteKeys(deleteKeys, true);
for (DeleteObject d : request.getObjects()) {
ErrorInfo error = undeletedKeyResultMap.get(d.getKey());
Expand Down Expand Up @@ -555,7 +544,7 @@ public S3BucketAcl getAcl(String bucketName)
S3BucketAcl result = new S3BucketAcl();
try {
OzoneBucket bucket = getBucket(bucketName);
S3Owner.verifyBucketOwnerCondition(headers, bucketName, bucket.getOwner());
S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName, bucket.getOwner());
S3Owner owner = S3Owner.of(bucket.getOwner());
result.setOwner(owner);

Expand Down Expand Up @@ -597,15 +586,15 @@ public S3BucketAcl getAcl(String bucketName)
public Response putAcl(String bucketName,
InputStream body) throws IOException, OS3Exception {
long startNanos = Time.monotonicNowNanos();
String grantReads = headers.getHeaderString(S3Acl.GRANT_READ);
String grantWrites = headers.getHeaderString(S3Acl.GRANT_WRITE);
String grantReadACP = headers.getHeaderString(S3Acl.GRANT_READ_CAP);
String grantWriteACP = headers.getHeaderString(S3Acl.GRANT_WRITE_CAP);
String grantFull = headers.getHeaderString(S3Acl.GRANT_FULL_CONTROL);
String grantReads = getHeaders().getHeaderString(S3Acl.GRANT_READ);
String grantWrites = getHeaders().getHeaderString(S3Acl.GRANT_WRITE);
String grantReadACP = getHeaders().getHeaderString(S3Acl.GRANT_READ_CAP);
String grantWriteACP = getHeaders().getHeaderString(S3Acl.GRANT_WRITE_CAP);
String grantFull = getHeaders().getHeaderString(S3Acl.GRANT_FULL_CONTROL);

try {
OzoneBucket bucket = getBucket(bucketName);
S3Owner.verifyBucketOwnerCondition(headers, bucketName, bucket.getOwner());
S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName, bucket.getOwner());
OzoneVolume volume = getVolume();

List<OzoneAcl> ozoneAclListOnBucket = new ArrayList<>();
Expand Down Expand Up @@ -774,28 +763,13 @@ private void addKey(ListObjectResponse response, OzoneKey next) {
response.addKey(keyMetadata);
}

@VisibleForTesting
public void setOzoneConfiguration(OzoneConfiguration config) {
this.ozoneConfiguration = config;
}

@VisibleForTesting
public OzoneConfiguration getOzoneConfiguration() {
return this.ozoneConfiguration;
}

@VisibleForTesting
public void setHeaders(HttpHeaders headers) {
this.headers = headers;
}

@Override
@PostConstruct
public void init() {
listKeysShallowEnabled = ozoneConfiguration.getBoolean(
listKeysShallowEnabled = getOzoneConfiguration().getBoolean(
OZONE_S3G_LIST_KEYS_SHALLOW_ENABLED,
OZONE_S3G_LIST_KEYS_SHALLOW_ENABLED_DEFAULT);
maxKeysLimit = ozoneConfiguration.getInt(
maxKeysLimit = getOzoneConfiguration().getInt(
OZONE_S3G_LIST_MAX_KEYS_LIMIT,
OZONE_S3G_LIST_MAX_KEYS_LIMIT_DEFAULT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.audit.AuditAction;
import org.apache.hadoop.ozone.audit.AuditEventStatus;
Expand Down Expand Up @@ -87,6 +88,9 @@ public abstract class EndpointBase implements Auditor {

protected static final String ETAG_CUSTOM = "etag-custom";

@Inject
private OzoneConfiguration ozoneConfiguration;

@Inject
private OzoneClient client;
@SuppressWarnings("checkstyle:VisibilityModifier")
Expand All @@ -96,9 +100,13 @@ public abstract class EndpointBase implements Auditor {
private RequestIdentifier requestIdentifier;

private S3Auth s3Auth;

@Context
private ContainerRequestContext context;

@Context
private HttpHeaders headers;

private Set<String> excludeMetadataFields =
new HashSet<>(Arrays.asList(OzoneConsts.GDPR_FLAG, STORAGE_CONFIG_HEADER));
private static final Logger LOG =
Expand Down Expand Up @@ -497,6 +505,22 @@ public void setClient(OzoneClient ozoneClient) {
this.client = ozoneClient;
}

protected ContainerRequestContext getContext() {
return context;
}

void setContext(ContainerRequestContext context) {
this.context = context;
}

protected HttpHeaders getHeaders() {
return headers;
}

void setHeaders(HttpHeaders headers) {
this.headers = headers;
}

@VisibleForTesting
public void setRequestIdentifier(RequestIdentifier requestIdentifier) {
this.requestIdentifier = requestIdentifier;
Expand All @@ -515,6 +539,14 @@ protected ClientProtocol getClientProtocol() {
return getClient().getProxy();
}

void setOzoneConfiguration(OzoneConfiguration conf) {
ozoneConfiguration = conf;
}

protected OzoneConfiguration getOzoneConfiguration() {
return ozoneConfiguration;
}

@VisibleForTesting
public S3GatewayMetrics getMetrics() {
return S3GatewayMetrics.getMetrics();
Expand All @@ -539,5 +571,4 @@ protected boolean isAccessDenied(OMException ex) {
return result == ResultCodes.PERMISSION_DENIED
|| result == ResultCodes.INVALID_TOKEN;
}

}
Loading