Skip to content

Commit

Permalink
add manta, openio, gcs adaptor
Browse files Browse the repository at this point in the history
Signed-off-by: ywang19 <[email protected]>
  • Loading branch information
ywang19 committed Jun 14, 2016
1 parent 392591a commit ad7a90c
Show file tree
Hide file tree
Showing 83 changed files with 2,472 additions and 8 deletions.
20 changes: 20 additions & 0 deletions dev/cosbench-gcs/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="google-api-client-1.19.0.jar"/>
<classpathentry exported="true" kind="lib" path="google-api-services-storage-v1-rev18-1.19.0.jar"/>
<classpathentry exported="true" kind="lib" path="google-http-client-1.19.0.jar"/>
<classpathentry exported="true" kind="lib" path="google-http-client-jackson2-1.19.0.jar"/>
<classpathentry exported="true" kind="lib" path="google-oauth-client-1.19.0.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="commons-codec-1.3.jar"/>
<classpathentry exported="true" kind="lib" path="commons-logging-1.1.1.jar"/>
<classpathentry exported="true" kind="lib" path="guava-jdk5-13.0.jar"/>
<classpathentry exported="true" kind="lib" path="hamcrest-core-1.1.jar"/>
<classpathentry exported="true" kind="lib" path="httpclient-4.0.1.jar"/>
<classpathentry exported="true" kind="lib" path="httpcore-4.0.1.jar"/>
<classpathentry exported="true" kind="lib" path="jackson-core-2.1.3.jar"/>
<classpathentry exported="true" kind="lib" path="jsr305-1.3.9.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions dev/cosbench-gcs/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cosbench-gcs</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
37 changes: 37 additions & 0 deletions dev/cosbench-gcs/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Google Cloud Storage Client Bundle
Bundle-SymbolicName: cosbench-gcs
Bundle-Version: 0.4.1.0
Bundle-Vendor: Intel
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: com.intel.cosbench.api.auth,
com.intel.cosbench.api.context,
com.intel.cosbench.api.storage,
com.intel.cosbench.client.http,
com.intel.cosbench.config,
com.intel.cosbench.log,
org.apache.commons.codec;version="[1.3.0,2.0.0)",
org.apache.commons.codec.net;version="[1.3.0,2.0.0)",
org.apache.http;version="[4.1.4,5.0.0)",
org.apache.http.client;version="[4.1.3,5.0.0)",
org.apache.http.client.methods;version="[4.1.3,5.0.0)",
org.apache.http.conn;version="[4.1.3,5.0.0)",
org.apache.http.entity;version="[4.1.4,5.0.0)",
org.apache.http.message;version="[4.1.4,5.0.0)",
org.apache.http.params;version="[4.1.4,5.0.0)",
org.apache.http.util;version="[4.1.4,5.0.0)"
Bundle-ClassPath: .,
google-api-client-1.19.0.jar,
google-api-services-storage-v1-rev18-1.19.0.jar,
google-http-client-1.19.0.jar,
google-http-client-jackson2-1.19.0.jar,
google-oauth-client-1.19.0.jar,
commons-codec-1.3.jar,
commons-logging-1.1.1.jar,
guava-jdk5-13.0.jar,
hamcrest-core-1.1.jar,
httpclient-4.0.1.jar,
httpcore-4.0.1.jar,
jackson-core-2.1.3.jar,
jsr305-1.3.9.jar
17 changes: 17 additions & 0 deletions dev/cosbench-gcs/META-INF/spring/plugin-context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">

<bean name="storageFactory" class="com.intel.cosbench.api.GcsStor.GcsStorageFactory" />

<osgi:service ref="storageFactory" context-class-loader="service-provider"
interface="com.intel.cosbench.api.storage.StorageAPIFactory">
</osgi:service>

</beans>
18 changes: 18 additions & 0 deletions dev/cosbench-gcs/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
google-api-client-1.19.0.jar,\
google-api-services-storage-v1-rev18-1.19.0.jar,\
google-http-client-1.19.0.jar,\
google-http-client-jackson2-1.19.0.jar,\
google-oauth-client-1.19.0.jar,\
guava-jdk5-13.0.jar,\
hamcrest-core-1.1.jar,\
httpclient-4.0.1.jar,\
httpcore-4.0.1.jar,\
jackson-core-2.1.3.jar,\
jsr305-1.3.9.jar,\
commons-codec-1.3.jar,\
commons-logging-1.1.1.jar

Binary file added dev/cosbench-gcs/commons-codec-1.3.jar
Binary file not shown.
Binary file added dev/cosbench-gcs/commons-logging-1.1.1.jar
Binary file not shown.
Binary file added dev/cosbench-gcs/google-api-client-1.19.0.jar
Binary file not shown.
Binary file not shown.
Binary file added dev/cosbench-gcs/google-http-client-1.19.0.jar
Binary file not shown.
Binary file not shown.
Binary file added dev/cosbench-gcs/google-oauth-client-1.19.0.jar
Binary file not shown.
Binary file added dev/cosbench-gcs/guava-jdk5-13.0.jar
Binary file not shown.
Binary file added dev/cosbench-gcs/hamcrest-core-1.1.jar
Binary file not shown.
Binary file added dev/cosbench-gcs/httpclient-4.0.1.jar
Binary file not shown.
Binary file added dev/cosbench-gcs/httpcore-4.0.1.jar
Binary file not shown.
Binary file added dev/cosbench-gcs/jackson-core-2.1.3.jar
Binary file not shown.
Binary file added dev/cosbench-gcs/jsr305-1.3.9.jar
Binary file not shown.
147 changes: 147 additions & 0 deletions dev/cosbench-gcs/src/com/intel/cosbench/api/GcsStor/GcsStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.intel.cosbench.api.GcsStor;

import static com.intel.cosbench.client.GcsStor.GcsStorConstants.CONN_TIMEOUT_KEY;
import static com.intel.cosbench.client.GcsStor.GcsStorConstants.CONN_TIMEOUT_DEFAULT;
import static com.intel.cosbench.client.GcsStor.GcsStorConstants.JSON_KEY_FILE;
import static com.intel.cosbench.client.GcsStor.GcsStorConstants.JSON_KEY_FILE_DEFAULT;
import static com.intel.cosbench.client.GcsStor.GcsStorConstants.PROJECT_ID;
import static com.intel.cosbench.client.GcsStor.GcsStorConstants.PROJECT_ID_DEFAULT;

import java.io.*;

import com.intel.cosbench.api.storage.*;
import com.intel.cosbench.api.context.*;
import com.intel.cosbench.config.Config;
import com.intel.cosbench.log.Logger;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.InputStreamContent;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.storage.Storage;
import com.google.api.services.storage.StorageScopes;
import com.google.api.services.storage.model.Bucket;
import com.google.api.services.storage.model.StorageObject;

public class GcsStorage extends NoneStorage {
private int timeout;
private String jsonKeyFile;
private String projectId;
private static Storage client;

private static final JsonFactory JSON_FACTORY = JacksonFactory
.getDefaultInstance();

@Override
public void init(Config config, Logger logger) {
super.init(config, logger);
initParms(config);
try {
InputStream input = new FileInputStream(jsonKeyFile);
GoogleCredential credential = GoogleCredential.fromStream(input);
if (credential.createScopedRequired()) {
credential = credential.createScoped(StorageScopes.all());
}
HttpTransport httpTransport = GoogleNetHttpTransport
.newTrustedTransport();
client = new Storage.Builder(httpTransport, JSON_FACTORY,
credential).build();
logger.debug("GCS client has been initialized");
} catch (Exception e) {
throw new StorageException(e);
}
}

private void initParms(Config config) {
timeout = config.getInt(CONN_TIMEOUT_KEY, CONN_TIMEOUT_DEFAULT);
parms.put(CONN_TIMEOUT_KEY, timeout);

jsonKeyFile = config.get(JSON_KEY_FILE, JSON_KEY_FILE_DEFAULT);
parms.put(JSON_KEY_FILE, jsonKeyFile);

projectId = config.get(PROJECT_ID, PROJECT_ID_DEFAULT);
parms.put(PROJECT_ID, projectId);

logger.debug("using storage config: {}", parms);
}

@Override
public void setAuthContext(AuthContext info) {
super.setAuthContext(info);
}

@Override
public void dispose() {
super.dispose();
client = null;
}

@Override
public InputStream getObject(String container, String object, Config config) {
super.getObject(container, object, config);
InputStream stream;
try {
Storage.Objects.Get getRequest = client.objects().get(container,
object);
stream = getRequest.executeMediaAsInputStream();
} catch (IOException e) {
throw new StorageException(e);
}
return stream;
}

@Override
public void createContainer(String container, Config config) {
super.createContainer(container, config);
Bucket newBucket = new Bucket();
newBucket.setName(container);
try {
Storage.Buckets.Insert bucketInsertRequest = client.buckets()
.insert(projectId, newBucket);
bucketInsertRequest.execute();
} catch (IOException e) {
throw new StorageException(e);
}
}

@Override
public void createObject(String container, String object, InputStream data,
long length, Config config) {
super.createObject(container, object, data, length, config);
InputStreamContent contentStream = new InputStreamContent(
"application/octet-stream", data);
StorageObject objectMetadata = new StorageObject().setName(object);
try {
Storage.Objects.Insert insertRequest = client.objects().insert(
container, objectMetadata, contentStream);
insertRequest.execute();
} catch (IOException e) {
throw new StorageException(e);
}

}

@Override
public void deleteContainer(String container, Config config) {
super.deleteContainer(container, config);
try {
Storage.Buckets.Delete bucketDeleteRequest = client.buckets()
.delete(container);
bucketDeleteRequest.execute();
} catch (IOException e) {
throw new StorageException(e);
}
}

@Override
public void deleteObject(String container, String object, Config config) {
super.deleteObject(container, object, config);
try {
client.objects().delete(container, object).execute();
} catch (Exception e) {
throw new StorageException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.intel.cosbench.api.GcsStor;

import com.intel.cosbench.api.storage.*;

public class GcsStorageFactory implements StorageAPIFactory {

@Override
public String getStorageName() {
return "gcs";
}

@Override
public StorageAPI getStorageAPI() {
return new GcsStorage();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.intel.cosbench.client.GcsStor;

public interface GcsStorConstants {

// --------------------------------------------------------------------------
// CONNECTION
// --------------------------------------------------------------------------

String CONN_TIMEOUT_KEY = "timeout";
int CONN_TIMEOUT_DEFAULT = 30000;

// --------------------------------------------------------------------------
// PROJECT_ID
// --------------------------------------------------------------------------
String PROJECT_ID = "projectid";
String PROJECT_ID_DEFAULT = "xxxxx-xxxx";

// --------------------------------------------------------------------------
// JSON_KEY_FILE
// --------------------------------------------------------------------------
String JSON_KEY_FILE = "jsonkeyfile";
String JSON_KEY_FILE_DEFAULT = "/path/to/json/key/file";

}
Loading

0 comments on commit ad7a90c

Please sign in to comment.