Skip to content
Permalink
Browse files
JCLOUDS-159: Removing async API from blobstore-largeblob
Also updating the jclouds version to 1.6.1-incubating
  • Loading branch information
demobox committed Jul 1, 2013
1 parent f9bb4b2 commit 11d7c538ab60ce605c60bcfffffb73dd17abd4b4
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 54 deletions.
@@ -28,55 +28,59 @@ under the License.
<name>blobstore-largeblob</name>
<description>jclouds blobstore example that creates a container, then uploads a large file using parallel multipart upload</description>

<properties>
<jclouds.version>1.6.1-incubating</jclouds.version>
</properties>

<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>1.5.0-beta.3</version>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-allblobstore</artifactId>
<version>1.5.0-beta.3</version>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-netty</artifactId>
<version>1.5.0-beta.3</version>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-apachehc</artifactId>
<version>1.5.0-beta.3</version>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>1.5.0-beta.3</version>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>1.5.0-beta.3</version>
<version>${jclouds.version}</version>
</dependency>
<!-- note that if you want a smaller distribution
remove the above dependency and place something
like below -->
remove the above dependency and place something
like below -->
<!--
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>hpcloud-objectstorage</artifactId>
<version>1.5.0-beta.3</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds.provider</groupId>
<artifactId>hpcloud-objectstorage</artifactId>
<version>${jclouds.version}</version>
</dependency>
-->
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
@@ -88,10 +92,13 @@ under the License.

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<descriptors>
<!-- unlike the "standard" jar-with-deps, includes
support for merging META-INF/services files -->
<descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>org.jclouds.examples.blobstore.largeblob.MainApp</mainClass>
@@ -109,7 +116,5 @@ under the License.
</executions>
</plugin>
</plugins>

</build>

</project>
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<!-- copied from jar-with-dependencies (http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies) -->
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<containerDescriptorHandlers>
<containerDescriptorHandler>
<handlerName>metaInf-services</handlerName>
</containerDescriptorHandler>
</containerDescriptorHandlers>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
@@ -19,33 +19,32 @@

package org.jclouds.examples.blobstore.largeblob;

import static com.google.common.collect.Iterables.transform;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.blobstore.options.PutOptions.Builder.multipart;
import static org.jclouds.location.reference.LocationConstants.ENDPOINT;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;

import java.io.File;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.concurrent.ExecutionException;

import javax.ws.rs.core.MediaType;

import org.jclouds.ContextBuilder;
import org.jclouds.aws.domain.Region;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.util.BlobStoreUtils;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.netty.config.NettyPayloadModule;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.Providers;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Module;

/**
@@ -120,10 +119,13 @@ public static void main(String[] args) throws IOException {

// Args

String provider = args[0];
if (!Iterables.contains(BlobStoreUtils.getSupportedProviders(), provider))
throw new IllegalArgumentException("provider " + provider + " not in supported list: "
+ BlobStoreUtils.getSupportedProviders());
String providerId = args[0];
ProviderMetadata provider = null;
try {
provider = Providers.withId(providerId);
} catch(NoSuchElementException exception) {
throw new IllegalArgumentException("provider " + providerId + " not in supported list: " + transform(Providers.all(), Providers.idFunction()));
}
String identity = args[1];
String credential = args[2];
String fileName = args[3];
@@ -139,37 +141,29 @@ public static void main(String[] args) throws IOException {
if (threadcount != null)
overrides.setProperty("jclouds.mpu.parallel.degree", threadcount); // without setting,
// default is 4 threads
overrides.setProperty(provider + ".identity", identity);
overrides.setProperty(provider + ".credential", credential);
BlobStoreContext context = new BlobStoreContextFactory().createContext(provider, MODULES, overrides);
overrides.setProperty(providerId + ".identity", identity);
overrides.setProperty(providerId + ".credential", credential);
BlobStoreContext context = ContextBuilder.newBuilder(provider).modules(MODULES).overrides(overrides).build(BlobStoreContext.class);

try {
long start = System.currentTimeMillis();
// Create Container
AsyncBlobStore blobStore = context.getAsyncBlobStore(); // it can be changed to sync
BlobStore blobStore = context.getBlobStore();
// BlobStore
ListenableFuture<Boolean> future = blobStore.createContainerInLocation(null, containerName);
future.get();
blobStore.createContainerInLocation(null, containerName);

File input = new File(fileName);
long length = input.length();
// Add a Blob
Blob blob = blobStore.blobBuilder(objectName).payload(input)
.contentType(MediaType.APPLICATION_OCTET_STREAM).contentDisposition(objectName).build();
// Upload a file
ListenableFuture<String> futureETag = blobStore.putBlob(containerName, blob, multipart());

// asynchronously wait for the upload
String eTag = futureETag.get();
String eTag = blobStore.putBlob(containerName, blob, multipart());

printSpeed("Sucessfully uploaded eTag(" + eTag + ")", start, length);

} catch (InterruptedException e) {
System.err.println(e.getMessage());
e.printStackTrace();
} catch (ExecutionException e) {
System.err.println(e.getMessage());
e.printStackTrace();
} catch(HttpResponseException exception) {
System.err.println(exception.getMessage());
exception.printStackTrace();
} finally {
// Close connecton
context.close();

0 comments on commit 11d7c53

Please sign in to comment.