You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jclouds.apache.org by Jeremy Daggett <no...@github.com> on 2014/06/09 23:27:07 UTC

[jclouds-examples] Updated Cloud Files examples (#50)

This PR updates the Rackspace Cloud Files examples to use the updated 1.7.3 APIs/release.

`SmokeTest` was run against the examples.
You can merge this Pull Request by running:

  git pull https://github.com/rackerlabs/jclouds-examples cloudfiles-1.7.3

Or you can view, comment on it, or merge it online at:

  https://github.com/jclouds/jclouds-examples/pull/50

-- Commit Summary --

  * Updated Cloud Files examples for 1.7.3

-- File Changes --

    M rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/CloudFilesPublish.java (23)
    M rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/CreateContainer.java (2)
    M rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/CrossOriginResourceSharingContainer.java (10)
    M rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/DeleteObjectsAndContainer.java (6)
    M rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/GenerateTempURL.java (12)
    A rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/GetContainer.java (82)
    M rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/GetObject.java (2)
    M rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/ListContainers.java (2)
    M rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/ListObjects.java (4)
    M rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/UploadDirectoryToCDN.java (23)
    M rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/UploadObjects.java (8)

-- Patch Links --

https://github.com/jclouds/jclouds-examples/pull/50.patch
https://github.com/jclouds/jclouds-examples/pull/50.diff

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Andrew Phillips <no...@github.com>.
> @@ -83,8 +85,13 @@ public CloudFilesPublish(String username, String apiKey) {
>      */
>     private void createContainer() {
>        System.out.format("Create Container%n");
> -
> -      cloudFiles.containerApiInRegion(REGION).createIfAbsent(CONTAINER_PUBLISH, CreateContainerOptions.NONE);
> +      // create a Multimap for the static web headers

Don't need the comment - the next line of code says it all?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13566541

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Everett Toews <no...@github.com>.
@jdaggett UploadDirectoryToCDN doesn't work for me as is. Can you please try it to see if it works for you and verify it by trying to go to the "Go to" URL.

This is what I had to change to get it to work.

    public UploadDirectoryToCDN(String username, String apiKey) {
      RegionScopedBlobStoreContext context = ContextBuilder.newBuilder(PROVIDER)
            .credentials(username, apiKey)
            .buildView(RegionScopedBlobStoreContext.class);
      blobStore = context.blobStoreInRegion(REGION);
      cloudFiles = blobStore.getContext().unwrapApi(CloudFilesApi.class);
    }

and

    private void uploadDirectory(String dirPath, String container) throws InterruptedException, ExecutionException {
      File dir = new File(dirPath);
      checkArgument(dir.isDirectory(), "%s is not a directory", dirPath);
      
      System.out.format("Uploading %s to %s", dirPath, container);

      Location location = Iterables.find(blobStore.listAssignableLocations(), new Predicate<Location>() {
         public boolean apply(Location input) {
            return REGION.equals(input.getId());
         }
      });

      blobStore.createContainerInLocation(location, container);

      List<BlobDetail> blobDetails = Lists.newArrayList();
      generateFileList(dir, "", blobDetails);
      uploadFiles(container, blobDetails);
    }

Try it with those changes and see if it works for you.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50#issuecomment-45549723

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Andrew Phillips <no...@github.com>.
>  
> -      CDNApi cdnApi = cloudFiles.cdnApiInRegion(REGION);
> -      URI cdnURI = cdnApi.enable(container);
> +      System.out.format("Enable CDN%n");
> +      // create a Multimap for the static web headers

Don't need the comment - the next line of code says it all?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13566537

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Jeremy Daggett <no...@github.com>.
>  
> -      CDNApi cdnApi = cloudFiles.cdnApiInRegion(REGION);
> -      URI cdnURI = cdnApi.enable(container);
> +      System.out.format("Enable CDN%n");
> +      // create a Multimap for the static web headers

OK. Nuked it.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13567122

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Everett Toews <no...@github.com>.
> @@ -83,8 +85,13 @@ public CloudFilesPublish(String username, String apiKey) {
>      */
>     private void createContainer() {
>        System.out.format("Create Container%n");
> -
> -      cloudFiles.containerApiInRegion(REGION).createIfAbsent(CONTAINER_PUBLISH, CreateContainerOptions.NONE);
> +      // create a Multimap for the static web headers

Fixed in #51 

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13614153

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Everett Toews <no...@github.com>.
Closed #50.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50#event-129866756

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Everett Toews <no...@github.com>.
Merged.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50#issuecomment-45637152

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Andrew Gaul <no...@github.com>.
> @@ -128,10 +128,14 @@ private void generateGetTempURL() throws IOException {
>        
>        // GET the file using jclouds
>        File file = File.createTempFile(FILENAME, ".tmp");
> -      String content = Strings2.toString(blobStoreContext.utils().http().invoke(request).getPayload());
> -      Files.write(content, file, Charsets.UTF_8);
> -      
> -      System.out.format("  GET Success (%s)%n", file.getAbsolutePath());
> +      try {
> +         String content = Strings2.toString(blobStoreContext.utils().http().invoke(request).getPayload());

You can avoid the conversion to and from a String with:

```
Payload payload = blobStoreContext.utils().http().invoke(request).getPayload();
Files.write(payload, file);
```

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13604968

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Andrew Gaul <no...@github.com>.
> +   private final CloudFilesApi cloudFiles;
> +
> +   /**
> +    * To get a username and API key see http://jclouds.apache.org/guides/rackspace/
> +    * 
> +    * The first argument (args[0]) must be your username
> +    * The second argument (args[1]) must be your API key
> +    */
> +   public static void main(String[] args) throws IOException {
> +      GetContainer getContainer = new GetContainer(args[0], args[1]);
> +
> +      try {
> +         getContainer.getContainer();
> +      }
> +      catch (Exception e) {
> +         e.printStackTrace();

Why not let this propagate outwards?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13605000

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Andrew Phillips <no...@github.com>.
> +      finally {
> +         getContainer.close();
> +      }
> +   }
> +
> +   public GetContainer(String username, String apiKey) {
> +      cloudFiles = ContextBuilder.newBuilder(PROVIDER)
> +            .credentials(username, apiKey)
> +            .buildApi(CloudFilesApi.class);
> +   }
> +
> +   private void getContainer() {
> +      System.out.format("Get Container%n");
> +
> +      Container container = cloudFiles.getContainerApiForRegion(REGION).get(CONTAINER);
> +      System.out.format("  %s%n", container);

What will this print, by the way? Is there something _in_ the container we want to get and demonstrate here?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13566512

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Andrew Phillips <no...@github.com>.
> You're going to need to update the jclouds.version in the pom.xml file for these changes to work.

Thanks, @everett-toews - good catch! Forget to check that - assumed that had already happened. Whoops...

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50#issuecomment-45549023

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Jeremy Daggett <no...@github.com>.
> +      finally {
> +         getContainer.close();
> +      }
> +   }
> +
> +   public GetContainer(String username, String apiKey) {
> +      cloudFiles = ContextBuilder.newBuilder(PROVIDER)
> +            .credentials(username, apiKey)
> +            .buildApi(CloudFilesApi.class);
> +   }
> +
> +   private void getContainer() {
> +      System.out.format("Get Container%n");
> +
> +      Container container = cloudFiles.getContainerApiForRegion(REGION).get(CONTAINER);
> +      System.out.format("  %s%n", container);

@demobox It just prints out the `Container` along with its information, nothing more.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13567105

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Everett Toews <no...@github.com>.
@jdaggett I need this stuff right now so I'm going to merge it and make the updates.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50#issuecomment-45636902

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Everett Toews <no...@github.com>.
> +   private final CloudFilesApi cloudFiles;
> +
> +   /**
> +    * To get a username and API key see http://jclouds.apache.org/guides/rackspace/
> +    * 
> +    * The first argument (args[0]) must be your username
> +    * The second argument (args[1]) must be your API key
> +    */
> +   public static void main(String[] args) throws IOException {
> +      GetContainer getContainer = new GetContainer(args[0], args[1]);
> +
> +      try {
> +         getContainer.getContainer();
> +      }
> +      catch (Exception e) {
> +         e.printStackTrace();

These examples run as part of a larger nightly [SmokeTest](https://github.com/jclouds/jclouds-examples/blob/master/rackspace/src/main/java/org/jclouds/examples/rackspace/SmokeTest.java) to ensure the examples are always in good working condition. I don't want the whole SmokeTest to die just because one example failed.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13607203

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Jeremy Daggett <no...@github.com>.
@everett-toews Whoops, I had it changed in my working copy but didn't commit it. Updating now, thx!

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50#issuecomment-45548928

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Andrew Phillips <no...@github.com>.
Just a couple of minor comments, but am also fine with this as-is. +1 - looks good to me.

Thanks, @jdaggett!

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50#issuecomment-45547764

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Everett Toews <no...@github.com>.
You're going to need to update the `jclouds.version` in the pom.xml file for these changes to work.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50#issuecomment-45548007

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Everett Toews <no...@github.com>.
> @@ -128,10 +128,14 @@ private void generateGetTempURL() throws IOException {
>        
>        // GET the file using jclouds
>        File file = File.createTempFile(FILENAME, ".tmp");
> -      String content = Strings2.toString(blobStoreContext.utils().http().invoke(request).getPayload());
> -      Files.write(content, file, Charsets.UTF_8);
> -      
> -      System.out.format("  GET Success (%s)%n", file.getAbsolutePath());
> +      try {
> +         String content = Strings2.toString(blobStoreContext.utils().http().invoke(request).getPayload());

I'll update that in my new (pending) PR.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13607116

Re: [jclouds-examples] Updated Cloud Files examples (#50)

Posted by Everett Toews <no...@github.com>.
> @@ -128,10 +128,14 @@ private void generateGetTempURL() throws IOException {
>        
>        // GET the file using jclouds
>        File file = File.createTempFile(FILENAME, ".tmp");
> -      String content = Strings2.toString(blobStoreContext.utils().http().invoke(request).getPayload());
> -      Files.write(content, file, Charsets.UTF_8);
> -      
> -      System.out.format("  GET Success (%s)%n", file.getAbsolutePath());
> +      try {
> +         String content = Strings2.toString(blobStoreContext.utils().http().invoke(request).getPayload());

Fixed in #51 

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/50/files#r13614170