Skip to content
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

S3 feature range #351

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
/0.3.0.9
/META-INF
/OSGI-INF
/release/archive/
/release/log/
/release/start
/release/stop
32 changes: 29 additions & 3 deletions dev/cosbench-s3/src/com/intel/cosbench/api/S3Stor/S3Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.intel.cosbench.client.S3Stor.S3Constants.*;

import java.io.*;
import java.util.Random;

import org.apache.http.HttpStatus;

Expand All @@ -24,6 +25,10 @@ public class S3Storage extends NoneStorage {
private String endpoint;

private AmazonS3 client;

private boolean isRangeRequest ;
private int rangeStart ;
private int rangeEnd ;

@Override
public void init(Config config, Logger logger) {
Expand All @@ -41,6 +46,11 @@ public void init(Config config, Logger logger) {

String proxyHost = config.get(PROXY_HOST_KEY, "");
String proxyPort = config.get(PROXY_PORT_KEY, "");

isRangeRequest = config.getBoolean("is_range_request", false);
rangeStart = config.getInt("range_start", 0);
rangeEnd = config.getInt("range_end", 4048);


parms.put(ENDPOINT_KEY, endpoint);
parms.put(AUTH_USERNAME_KEY, accessKey);
Expand Down Expand Up @@ -92,9 +102,25 @@ public InputStream getObject(String container, String object, Config config) {
super.getObject(container, object, config);
InputStream stream;
try {

S3Object s3Obj = client.getObject(container, object);
stream = s3Obj.getObjectContent();
if(isRangeRequest)
{
GetObjectRequest rangeObjectRequest = new GetObjectRequest(container, object);
Random rand = new Random();

int randNumber1 = rand.nextInt(rangeEnd - rangeStart + 1) + rangeStart;
int randNumber2 = rand.nextInt(rangeEnd - rangeStart + 1) + rangeStart;
int start = Math.min(randNumber1, randNumber2) ;
int end = Math.max(randNumber1, randNumber2) ;

rangeObjectRequest.setRange(start, end);
S3Object objectPortion = client.getObject(rangeObjectRequest);
stream = objectPortion.getObjectContent();
}
else
{
S3Object s3Obj = client.getObject(container, object);
stream = s3Obj.getObjectContent();
}

} catch (Exception e) {
throw new StorageException(e);
Expand Down
2 changes: 1 addition & 1 deletion ext/adaptor/abc-auth/src/com/abc/api/abcAuth/AbcAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public AuthContext login() {
}

private AuthContext createContext() {
AuthContext context = new AuthContext();
AuthContext context = new DefaultAuthContext();
context.put(AUTH_TOKEN_KEY, client.getAuthToken());
return context;
}
Expand Down