Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change adaptor-dev to ext

  • Loading branch information...
commit 32acfb13c6c93854dd8aa37789d75475cd018b04 1 parent 84ddaa9
@ywang19 ywang19 authored
Showing with 876 additions and 0 deletions.
  1. +7 −0 ext/adaptor/abc-auth/.classpath
  2. +28 −0 ext/adaptor/abc-auth/.project
  3. +7 −0 ext/adaptor/abc-auth/.settings/org.eclipse.jdt.core.prefs
  4. +22 −0 ext/adaptor/abc-auth/META-INF/MANIFEST.MF
  5. +17 −0 ext/adaptor/abc-auth/META-INF/spring/plugin-context.xml
  6. +4 −0 ext/adaptor/abc-auth/build.properties
  7. +94 −0 ext/adaptor/abc-auth/src/com/abc/api/abcAuth/AbcAuth.java
  8. +34 −0 ext/adaptor/abc-auth/src/com/abc/api/abcAuth/AbcAuthFactory.java
  9. +84 −0 ext/adaptor/abc-auth/src/com/abc/client/abcAuth/AbcAuthClient.java
  10. +50 −0 ext/adaptor/abc-auth/src/com/abc/client/abcAuth/AbcAuthClientException.java
  11. +58 −0 ext/adaptor/abc-auth/src/com/abc/client/abcAuth/AbcAuthConstants.java
  12. +7 −0 ext/adaptor/abc-stor/.classpath
  13. +28 −0 ext/adaptor/abc-stor/.project
  14. +7 −0 ext/adaptor/abc-stor/.settings/org.eclipse.jdt.core.prefs
  15. +23 −0 ext/adaptor/abc-stor/META-INF/MANIFEST.MF
  16. +17 −0 ext/adaptor/abc-stor/META-INF/spring/plugin-context.xml
  17. +4 −0 ext/adaptor/abc-stor/build.properties
  18. +173 −0 ext/adaptor/abc-stor/src/com/abc/api/abcStor/AbcStorage.java
  19. +34 −0 ext/adaptor/abc-stor/src/com/abc/api/abcStor/AbcStorageFactory.java
  20. +90 −0 ext/adaptor/abc-stor/src/com/abc/client/abcStor/AbcStorClient.java
  21. +50 −0 ext/adaptor/abc-stor/src/com/abc/client/abcStor/AbcStorClientException.java
  22. +38 −0 ext/adaptor/abc-stor/src/com/abc/client/abcStor/AbcStorConstants.java
  23. BIN  ext/libs/com.springsource.org.apache.commons.codec-1.3.0.jar
  24. BIN  ext/libs/org.apache.httpcomponents.httpclient_4.1.3.jar
  25. BIN  ext/libs/org.apache.httpcomponents.httpcore_4.1.4.jar
View
7 ext/adaptor/abc-auth/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <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 kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
28 ext/adaptor/abc-auth/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>abc-auth</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>
View
7 ext/adaptor/abc-auth/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
View
22 ext/adaptor/abc-auth/META-INF/MANIFEST.MF
@@ -0,0 +1,22 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Abc Auth Client Bundle
+Bundle-SymbolicName: cosbench-abcauth
+Bundle-Version: 0.3.1.0
+Bundle-Vendor: Abc Co.
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: com.intel.cosbench.api.auth,
+ com.intel.cosbench.api.context,
+ 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)"
View
17 ext/adaptor/abc-auth/META-INF/spring/plugin-context.xml
@@ -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="authFactory" class="com.abc.api.abcAuth.AbcAuthFactory" />
+
+ <osgi:service ref="authFactory" context-class-loader="service-provider"
+ interface="com.intel.cosbench.api.auth.AuthAPIFactory">
+ </osgi:service>
+
+</beans>
View
4 ext/adaptor/abc-auth/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
View
94 ext/adaptor/abc-auth/src/com/abc/api/abcAuth/AbcAuth.java
@@ -0,0 +1,94 @@
+/**
+
+Copyright 2013 Intel Corporation, All Rights Reserved.
+
+Licensed 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 com.abc.api.abcAuth;
+
+import static com.abc.client.abcAuth.AbcAuthConstants.*;
+
+import java.io.*;
+import java.net.SocketTimeoutException;
+
+import org.apache.http.client.HttpClient;
+
+import com.abc.client.abcAuth.*;
+import com.intel.cosbench.api.auth.*;
+import com.intel.cosbench.api.context.*;
+import com.intel.cosbench.client.http.*;
+import com.intel.cosbench.config.Config;
+import com.intel.cosbench.log.Logger;
+
+public class AbcAuth extends NoneAuth {
+
+ private AbcAuthClient client;
+
+ private String url;
+ private String username;
+ private String password;
+ private int timeout;
+
+ @Override
+ public void init(Config config, Logger logger) {
+ super.init(config, logger);
+ initParms(config);
+
+ HttpClient httpClient = HttpClientUtil.createHttpClient(timeout);
+ client = new AbcAuthClient(httpClient, url, username, password);
+ }
+
+ private void initParms(Config config) {
+ url = config.get(AUTH_URL_KEY, URL_DEFAULT);
+ username = config.get(AUTH_USERNAME_KEY, AUTH_USERNAME_DEFAULT);
+ password = config.get(AUTH_PASSWORD_KEY, AUTH_PASSWORD_DEFAULT);
+ timeout = config.getInt(CONN_TIMEOUT_KEY, CONN_TIMEOUT_DEFAULT);
+
+ parms.put(AUTH_URL_KEY, url);
+ parms.put(AUTH_USERNAME_KEY, username);
+ parms.put(AUTH_PASSWORD_KEY, password);
+ parms.put(CONN_TIMEOUT_KEY, timeout);
+
+ logger.debug("using storage config: {}", parms);
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ client.dispose();
+ }
+
+ @Override
+ public AuthContext login() {
+ super.login();
+ try {
+ client.login();
+ } catch (SocketTimeoutException te) {
+ throw new AuthTimeoutException(te);
+ } catch (InterruptedIOException ie) {
+ throw new AuthInterruptedException(ie);
+ } catch (AbcAuthClientException se) {
+ throw new AuthException(se.getMessage(), se);
+ } catch (Exception e) {
+ throw new AuthException(e);
+ }
+ return createContext();
+ }
+
+ private AuthContext createContext() {
+ AuthContext context = new AuthContext();
+ context.put(AUTH_TOKEN_KEY, client.getAuthToken());
+ return context;
+ }
+}
View
34 ext/adaptor/abc-auth/src/com/abc/api/abcAuth/AbcAuthFactory.java
@@ -0,0 +1,34 @@
+/**
+
+Copyright 2013 Intel Corporation, All Rights Reserved.
+
+Licensed 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 com.abc.api.abcAuth;
+
+import com.intel.cosbench.api.auth.*;
+
+public class AbcAuthFactory implements AuthAPIFactory {
+
+ @Override
+ public String getAuthName() {
+ return "abcauth";
+ }
+
+ @Override
+ public AuthAPI getAuthAPI() {
+ return new AbcAuth();
+ }
+
+}
View
84 ext/adaptor/abc-auth/src/com/abc/client/abcAuth/AbcAuthClient.java
@@ -0,0 +1,84 @@
+/**
+
+Copyright 2013 Intel Corporation, All Rights Reserved.
+
+Licensed 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 com.abc.client.abcAuth;
+
+import static com.abc.client.abcAuth.AbcAuthConstants.*;
+
+import java.io.*;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.HttpClient;
+//import org.apache.commons.codec.EncoderException;
+//import org.apache.commons.codec.net.URLCodec;
+//import org.apache.http.*;
+//import org.apache.http.client.methods.*;
+//import org.apache.http.entity.*;
+//import org.apache.http.util.*;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.util.EntityUtils;
+
+public class AbcAuthClient {
+
+ private String authURL;
+ private String username;
+ private String password;
+
+ private String authToken;
+
+ private HttpClient client;
+
+ public AbcAuthClient(HttpClient client, String authUrl, String username,
+ String password) {
+ this.client = client;
+ this.authURL = authUrl;
+ this.username = username;
+ this.password = password;
+ }
+
+ public String getAuthToken() {
+ return authToken;
+ }
+
+ public void init(String authToken) {
+ this.authToken = authToken;
+ }
+
+ public void dispose() {
+ client.getConnectionManager().shutdown();
+ }
+
+ public void login() throws IOException, AbcAuthClientException {
+ HttpResponse response = null;
+ try {
+ HttpGet method = new HttpGet(authURL);
+ method.setHeader(X_STORAGE_USER, username);
+ method.setHeader(X_STORAGE_PASS, password);
+ response = client.execute(method);
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+ authToken = response.getFirstHeader(X_AUTH_TOKEN) != null ? response.getFirstHeader(X_AUTH_TOKEN).getValue() : null;
+ return;
+ }
+ throw new AbcAuthClientException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
+ } finally {
+ if (response != null)
+ EntityUtils.consume(response.getEntity());
+ }
+ }
+
+}
View
50 ext/adaptor/abc-auth/src/com/abc/client/abcAuth/AbcAuthClientException.java
@@ -0,0 +1,50 @@
+/**
+
+Copyright 2013 Intel Corporation, All Rights Reserved.
+
+Licensed 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 com.abc.client.abcAuth;
+
+import org.apache.http.Header;
+import org.apache.http.StatusLine;
+import org.apache.http.client.HttpResponseException;
+
+
+public class AbcAuthClientException extends HttpResponseException {
+ private Header[] httpHeaders;
+ private StatusLine httpStatusLine;
+
+ public AbcAuthClientException(int code, String message) {
+ super(code, message);
+ }
+
+ public AbcAuthClientException(int code, String message, Header[] httpHeaders,
+ StatusLine httpStatusLine) {
+ super(code, message);
+ this.httpHeaders = httpHeaders;
+ this.httpStatusLine = httpStatusLine;
+ }
+
+ public Header[] getHttpHeaders() {
+ return httpHeaders;
+ }
+
+ public StatusLine getHttpStatusLine() {
+ return httpStatusLine;
+ }
+
+ private static final long serialVersionUID = 1L;
+
+}
View
58 ext/adaptor/abc-auth/src/com/abc/client/abcAuth/AbcAuthConstants.java
@@ -0,0 +1,58 @@
+/**
+
+Copyright 2013 Intel Corporation, All Rights Reserved.
+
+Licensed 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 com.abc.client.abcAuth;
+
+public interface AbcAuthConstants {
+
+ // --------------------------------------------------------------------------
+ // CONNECTION
+ // --------------------------------------------------------------------------
+
+ String CONN_TIMEOUT_KEY = "timeout";
+ int CONN_TIMEOUT_DEFAULT = 30000;
+
+ // --------------------------------------------------------------------------
+ // AUTH
+ // --------------------------------------------------------------------------
+
+ String AUTH_URL_KEY = "auth_url";
+ String URL_DEFAULT = "http://127.0.0.1:8080/auth/v1.0";
+
+ // --------------------------------------------------------------------------
+ // AUTHENTICATION
+ // --------------------------------------------------------------------------
+
+ String AUTH_USERNAME_KEY = "username";
+ String AUTH_USERNAME_DEFAULT = "";
+
+ String AUTH_PASSWORD_KEY = "password";
+ String AUTH_PASSWORD_DEFAULT = "";
+
+ // --------------------------------------------------------------------------
+ // CONTEXT NEEDS FROM AUTH MODULE
+ // --------------------------------------------------------------------------
+ String AUTH_TOKEN_KEY = "token";
+
+ // --------------------------------------------------------------------------
+ // Storage RESTful API
+ // --------------------------------------------------------------------------
+ String X_STORAGE_USER = "X-Auth-User";
+ String X_STORAGE_PASS = "X-Auth-Key";
+ String X_AUTH_TOKEN = "X-Auth-Token";
+
+}
View
7 ext/adaptor/abc-stor/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <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 kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
28 ext/adaptor/abc-stor/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>abc-stor</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>
View
7 ext/adaptor/abc-stor/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
View
23 ext/adaptor/abc-stor/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Abc Storage Client Bundle
+Bundle-SymbolicName: cosbench-abcstor
+Bundle-Version: 0.3.1.0
+Bundle-Vendor: Abc Co.
+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)"
View
17 ext/adaptor/abc-stor/META-INF/spring/plugin-context.xml
@@ -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.abc.api.abcStor.AbcStorageFactory" />
+
+ <osgi:service ref="storageFactory" context-class-loader="service-provider"
+ interface="com.intel.cosbench.api.storage.StorageAPIFactory">
+ </osgi:service>
+
+</beans>
View
4 ext/adaptor/abc-stor/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
View
173 ext/adaptor/abc-stor/src/com/abc/api/abcStor/AbcStorage.java
@@ -0,0 +1,173 @@
+/**
+
+Copyright 2013 Intel Corporation, All Rights Reserved.
+
+Licensed 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 com.abc.api.abcStor;
+
+import static com.abc.client.abcStor.AbcStorConstants.*;
+
+import java.io.*;
+import java.net.SocketTimeoutException;
+
+import org.apache.http.client.HttpClient;
+
+import com.abc.client.abcStor.*;
+import com.intel.cosbench.api.storage.*;
+import com.intel.cosbench.api.context.*;
+import com.intel.cosbench.client.http.HttpClientUtil;
+import com.intel.cosbench.config.Config;
+import com.intel.cosbench.log.Logger;
+
+public class AbcStorage extends NoneStorage {
+
+ private AbcStorClient client;
+ private int timeout;
+
+ @Override
+ public void init(Config config, Logger logger) {
+ super.init(config, logger);
+ initParms(config);
+
+ HttpClient httpClient = HttpClientUtil.createHttpClient(timeout);
+ client = new AbcStorClient(httpClient);
+ }
+
+ private void initParms(Config config) {
+ timeout = config.getInt(CONN_TIMEOUT_KEY, CONN_TIMEOUT_DEFAULT);
+
+ parms.put(CONN_TIMEOUT_KEY, timeout);
+
+ logger.debug("using storage config: {}", parms);
+ }
+
+ @Override
+ public void setAuthContext(AuthContext info) {
+ super.setAuthContext(info);
+ try {
+ String authToken = info.getStr(AUTH_TOKEN_KEY);
+ logger.debug("auth token=" + authToken);
+ client.init(authToken);
+ } catch (Exception e) {
+ throw new StorageException(e);
+ }
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ client.dispose();
+ }
+
+ @Override
+ public void abort() {
+ super.abort();
+ client.abort();
+ }
+
+ @Override
+ public InputStream getObject(String container, String object, Config config) {
+ super.getObject(container, object, config);
+ InputStream stream;
+ try {
+ logger.info("Retrieving " + container + "\\" + object);
+ stream = client.getObjectAsStream(container, object);
+ } catch (SocketTimeoutException te) {
+ throw new StorageTimeoutException(te);
+ } catch (InterruptedIOException ie) {
+ throw new StorageInterruptedException(ie);
+ } catch (AbcStorClientException se) {
+ String msg = se.getHttpStatusLine().toString();
+ throw new StorageException(msg, se);
+ } catch (Exception e) {
+ throw new StorageException(e);
+ }
+ return stream;
+ }
+
+ @Override
+ public void createContainer(String container, Config config) {
+ super.createContainer(container, config);
+ try {
+ logger.info("Creating " + container);
+ client.createContainer(container);
+ } catch (SocketTimeoutException te) {
+ throw new StorageTimeoutException(te);
+ } catch (InterruptedIOException ie) {
+ throw new StorageInterruptedException(ie);
+ } catch (AbcStorClientException se) {
+ String msg = se.getHttpStatusLine().toString();
+ throw new StorageException(msg, se);
+ } catch (Exception 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);
+ try {
+ logger.info("Creating " + container + "\\" + object + " with length=" + length + " Bytes");
+ client.storeStreamedObject(container, object, data, length);
+ } catch (SocketTimeoutException te) {
+ throw new StorageTimeoutException(te);
+ } catch (InterruptedIOException ie) {
+ throw new StorageInterruptedException(ie);
+ } catch (AbcStorClientException se) {
+ String msg = se.getHttpStatusLine().toString();
+ throw new StorageException(msg, se);
+ } catch (Exception e) {
+ throw new StorageException(e);
+ }
+ }
+
+ @Override
+ public void deleteContainer(String container, Config config) {
+ super.deleteContainer(container, config);
+ try {
+ logger.info("Deleting " + container);
+ client.deleteContainer(container);
+ } catch (SocketTimeoutException te) {
+ throw new StorageTimeoutException(te);
+ } catch (InterruptedIOException ie) {
+ throw new StorageInterruptedException(ie);
+ } catch (AbcStorClientException se) {
+ String msg = se.getHttpStatusLine().toString();
+ throw new StorageException(msg, se);
+ } catch (Exception e) {
+ throw new StorageException(e);
+ }
+ }
+
+ @Override
+ public void deleteObject(String container, String object, Config config) {
+ super.deleteObject(container, object, config);
+ try {
+ logger.info("Deleting " + container + "\\" + object);
+ client.deleteObject(container, object);
+ } catch (SocketTimeoutException te) {
+ throw new StorageTimeoutException(te);
+ } catch (InterruptedIOException ie) {
+ throw new StorageInterruptedException(ie);
+ } catch (AbcStorClientException se) {
+ String msg = se.getHttpStatusLine().toString();
+ throw new StorageException(msg, se);
+ } catch (Exception e) {
+ throw new StorageException(e);
+ }
+ }
+
+}
View
34 ext/adaptor/abc-stor/src/com/abc/api/abcStor/AbcStorageFactory.java
@@ -0,0 +1,34 @@
+/**
+
+Copyright 2013 Intel Corporation, All Rights Reserved.
+
+Licensed 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 com.abc.api.abcStor;
+
+import com.intel.cosbench.api.storage.*;
+
+public class AbcStorageFactory implements StorageAPIFactory {
+
+ @Override
+ public String getStorageName() {
+ return "abcstor";
+ }
+
+ @Override
+ public StorageAPI getStorageAPI() {
+ return new AbcStorage();
+ }
+
+}
View
90 ext/adaptor/abc-stor/src/com/abc/client/abcStor/AbcStorClient.java
@@ -0,0 +1,90 @@
+/**
+
+Copyright 2013 Intel Corporation, All Rights Reserved.
+
+Licensed 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 com.abc.client.abcStor;
+
+import java.io.*;
+
+import org.apache.http.client.HttpClient;
+//import org.apache.commons.codec.EncoderException;
+//import org.apache.commons.codec.net.URLCodec;
+//import org.apache.http.*;
+//import org.apache.http.client.methods.*;
+//import org.apache.http.entity.*;
+//import org.apache.http.util.*;
+import org.apache.http.client.methods.HttpUriRequest;
+
+public class AbcStorClient {
+
+ private String authToken;
+
+ private HttpClient client;
+ /* current operation */
+ private volatile HttpUriRequest request;
+
+ public AbcStorClient(HttpClient client) {
+ this.client = client;
+ }
+
+ public String getAuthToken() {
+ return authToken;
+ }
+
+ public void dispose() {
+ request = null;
+ client.getConnectionManager().shutdown();
+ }
+
+ public void init(String authToken) {
+ this.authToken = authToken;
+ }
+
+ public void abort() {
+ if (request != null)
+ request.abort();
+ request = null;
+ }
+
+ public void createContainer(String container) throws IOException,
+ AbcStorClientException {
+ // add storage access logic here.
+ }
+
+ public void deleteContainer(String container) throws IOException,
+ AbcStorClientException {
+ // add storage access logic here.
+ }
+
+ public InputStream getObjectAsStream(String container, String object)
+ throws IOException, AbcStorClientException {
+ // add storage access logic here.
+ byte[] buf = new byte[1024];
+ return new ByteArrayInputStream(buf);
+
+ }
+
+ public void storeStreamedObject(String container, String object,
+ InputStream data, long length) throws IOException, AbcStorClientException {
+ // add storage access logic here.
+ }
+
+ public void deleteObject(String container, String object)
+ throws IOException, AbcStorClientException {
+ // add storage access logic here.
+ }
+
+}
View
50 ext/adaptor/abc-stor/src/com/abc/client/abcStor/AbcStorClientException.java
@@ -0,0 +1,50 @@
+/**
+
+Copyright 2013 Intel Corporation, All Rights Reserved.
+
+Licensed 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 com.abc.client.abcStor;
+
+import org.apache.http.Header;
+import org.apache.http.StatusLine;
+import org.apache.http.client.HttpResponseException;
+
+
+public class AbcStorClientException extends HttpResponseException {
+ private Header[] httpHeaders;
+ private StatusLine httpStatusLine;
+
+ public AbcStorClientException(int code, String message) {
+ super(code, message);
+ }
+
+ public AbcStorClientException(int code, String message, Header[] httpHeaders,
+ StatusLine httpStatusLine) {
+ super(code, message);
+ this.httpHeaders = httpHeaders;
+ this.httpStatusLine = httpStatusLine;
+ }
+
+ public Header[] getHttpHeaders() {
+ return httpHeaders;
+ }
+
+ public StatusLine getHttpStatusLine() {
+ return httpStatusLine;
+ }
+
+ private static final long serialVersionUID = 1L;
+
+}
View
38 ext/adaptor/abc-stor/src/com/abc/client/abcStor/AbcStorConstants.java
@@ -0,0 +1,38 @@
+/**
+
+Copyright 2013 Intel Corporation, All Rights Reserved.
+
+Licensed 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 com.abc.client.abcStor;
+
+public interface AbcStorConstants {
+
+ // --------------------------------------------------------------------------
+ // CONNECTION
+ // --------------------------------------------------------------------------
+
+ String CONN_TIMEOUT_KEY = "timeout";
+ int CONN_TIMEOUT_DEFAULT = 30000;
+
+ // --------------------------------------------------------------------------
+ // CONTEXT NEEDS FROM AUTH MODULE
+ // --------------------------------------------------------------------------
+ String AUTH_TOKEN_KEY = "token";
+
+ // --------------------------------------------------------------------------
+ // Storage RESTful API
+ // --------------------------------------------------------------------------
+ String X_AUTH_TOKEN = "X-Auth-Token";
+}
View
BIN  ext/libs/com.springsource.org.apache.commons.codec-1.3.0.jar
Binary file not shown
View
BIN  ext/libs/org.apache.httpcomponents.httpclient_4.1.3.jar
Binary file not shown
View
BIN  ext/libs/org.apache.httpcomponents.httpcore_4.1.4.jar
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.