Skip to content
This repository has been archived by the owner on Feb 4, 2019. It is now read-only.

Commit

Permalink
Update examples to 1.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
etoews committed Jan 16, 2015
1 parent ac12a07 commit 18fd5f0
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 36 deletions.
4 changes: 2 additions & 2 deletions rackspace/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.jclouds.examples</groupId>
<artifactId>rackspace-examples</artifactId>
<version>1.8.0</version>
<version>1.8.1</version>
<name>rackspace-examples</name>

<properties>
<jclouds.version>1.8.0</jclouds.version>
<jclouds.version>1.8.1</jclouds.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private void smokeTest(String[] args) throws IOException {
GenerateTempURL.main(args);
UploadObjects.main(args);
ListObjects.main(args);
GetObject.main(args);
CrossOriginResourceSharingContainer.main(args);
DeleteObjectsAndContainer.main(args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ public interface Constants {
public static final String ZONE = System.getProperty("zone", "DFW");

public static final String NAME = "jclouds-example";
public static final String SERVICE_NET = "11111111-1111-1111-1111-111111111111";
public static final String PUBLIC_NET = "00000000-0000-0000-0000-000000000000";
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import static org.jclouds.examples.rackspace.autoscale.Constants.NAME;
import static org.jclouds.examples.rackspace.autoscale.Constants.PROVIDER;
import static org.jclouds.examples.rackspace.autoscale.Constants.PUBLIC_NET;
import static org.jclouds.examples.rackspace.autoscale.Constants.SERVICE_NET;
import static org.jclouds.examples.rackspace.autoscale.Constants.ZONE;

import java.io.Closeable;
Expand Down Expand Up @@ -101,8 +103,8 @@ private void createPolicy() {
.serverImageRef("0d589460-f177-4b0f-81c1-8ab8903ac7d8")
.serverFlavorRef("2")
.serverDiskConfig("AUTO")
.serverMetadata(ImmutableMap.of("notes","Server examples notes"))
.networks(ImmutableList.<String>of("internal", "public"))
.serverMetadata(ImmutableMap.of("notes", "Server examples notes"))
.networks(ImmutableList.of(SERVICE_NET, PUBLIC_NET))
.personalities(ImmutableList.of(Personality.builder().path("filepath").contents("VGhpcyBpcyBhIHRlc3QgZmlsZS4=").build()))
.type(LaunchConfigurationType.LAUNCH_SERVER)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void createContainer() {
STATIC_WEB_ERROR, "error.html");

CreateContainerOptions opts = new CreateContainerOptions().headers(enableStaticWebHeaders);
cloudFiles.getContainerApiForRegion(REGION).create(CONTAINER_PUBLISH, opts);
cloudFiles.getContainerApi(REGION).create(CONTAINER_PUBLISH, opts);

System.out.format(" %s%n", CONTAINER_PUBLISH);
}
Expand All @@ -108,7 +108,7 @@ private void createObjectFromFile() throws IOException {
try {
Files.write("Hello Cloud Files", tempFile, Charsets.UTF_8);

ObjectApi objectApi = cloudFiles.getObjectApiForRegionAndContainer(REGION, CONTAINER_PUBLISH);
ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER_PUBLISH);

ByteSource byteSource = Files.asByteSource(tempFile);
Payload payload = Payloads.newByteSourcePayload(byteSource);
Expand All @@ -126,7 +126,7 @@ private void createObjectFromFile() throws IOException {
private void enableCdnContainer() {
System.out.format("Enable CDN Container%n");

CDNApi cdnApi = cloudFiles.getCDNApiForRegion(REGION);
CDNApi cdnApi = cloudFiles.getCDNApi(REGION);
URI cdnURI = cdnApi.enable(CONTAINER_PUBLISH);

System.out.format(" Go to %s/%s%s%n", cdnURI, FILENAME, SUFFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void createContainer() {
CreateContainerOptions options = CreateContainerOptions.Builder
.metadata(ImmutableMap.of("key1", "value1", "key2", "value2"));

cloudFiles.getContainerApiForRegion(REGION).create(CONTAINER, options);
cloudFiles.getContainerApi(REGION).create(CONTAINER, options);

System.out.format(" %s%n", CONTAINER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public CrossOriginResourceSharingContainer(String username, String apiKey) {
cloudFiles = ContextBuilder.newBuilder(PROVIDER)
.credentials(username, apiKey)
.buildApi(CloudFilesApi.class);
containerApi = cloudFiles.getContainerApiForRegion(REGION);
containerApi = cloudFiles.getContainerApi(REGION);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ public DeleteObjectsAndContainer(String username, String apiKey) {
private void deleteObjectsAndContainer() {
System.out.format("Delete Container%n");

List<Container> containers = cloudFiles.getContainerApiForRegion(REGION)
List<Container> containers = cloudFiles.getContainerApi(REGION)
.list(ListContainerOptions.Builder.prefix(CONTAINER)).toList();

for (Container container: containers) {
System.out.format(" %s%n", container.getName());

ObjectApi objectApi = cloudFiles.getObjectApiForRegionAndContainer(REGION, container.getName());
ObjectList objects = objectApi.list(ListContainerOptions.NONE);
ObjectApi objectApi = cloudFiles.getObjectApi(REGION, container.getName());
ObjectList objects = objectApi.list();

for (SwiftObject object: objects) {
System.out.format(" %s%n", object.getName());
objectApi.delete(object.getName());
}

cloudFiles.getContainerApiForRegion(REGION).deleteIfEmpty(container.getName());
cloudFiles.getContainerApi(REGION).deleteIfEmpty(container.getName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public GetContainer(String username, String apiKey) {
private void getContainer() {
System.out.format("Get Container%n");

Container container = cloudFiles.getContainerApiForRegion(REGION).get(CONTAINER);
Container container = cloudFiles.getContainerApi(REGION).get(CONTAINER);
System.out.format(" %s%n", container);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@
*/
package org.jclouds.examples.rackspace.cloudfiles;

import static org.jclouds.examples.rackspace.cloudfiles.Constants.CONTAINER;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION;

import java.io.Closeable;
import java.io.IOException;

import com.google.common.io.ByteStreams;
import com.google.common.io.Closeables;
import org.jclouds.ContextBuilder;
import org.jclouds.http.options.GetOptions;
import org.jclouds.openstack.swift.v1.domain.SwiftObject;
import org.jclouds.openstack.swift.v1.features.ObjectApi;
import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi;

import com.google.common.io.Closeables;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import static org.jclouds.examples.rackspace.cloudfiles.Constants.CONTAINER;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION;

/**
* Gets an object from a container and displays the results.
Expand All @@ -52,7 +55,8 @@ public static void main(String[] args) throws IOException {
GetObject getObject = new GetObject(args[0], args[1]);

try {
getObject.getObject();
SwiftObject swiftObject = getObject.getObject();
getObject.writeObject(swiftObject);
}
catch (Exception e) {
e.printStackTrace();
Expand All @@ -69,13 +73,33 @@ public GetObject(String username, String apiKey) {

}

private void getObject() {
private SwiftObject getObject() {
System.out.format("Get Object%n");

ObjectApi objectApi = cloudFiles.getObjectApiForRegionAndContainer(REGION, CONTAINER);
SwiftObject object = objectApi.get("uploadObjectFromFile.txt", GetOptions.NONE);
ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER);
SwiftObject swiftObject = objectApi.get("uploadObjectFromFile.txt");

System.out.format(" %s%n", swiftObject);

return swiftObject;
}

private void writeObject(SwiftObject swiftObject) throws IOException {
System.out.format("Write Object%n");

InputStream inputStream = swiftObject.getPayload().openStream();
File file = File.createTempFile("uploadObjectFromFile", ".txt");
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));

try {
ByteStreams.copy(inputStream, outputStream);
}
finally {
inputStream.close();
outputStream.close();
}

System.out.format(" %s%n", object);
System.out.format(" %s%n", file.getAbsolutePath());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ListContainers(String username, String apiKey) {
private void listContainers() {
System.out.format("List Containers%n");

List<Container> containers = cloudFiles.getContainerApiForRegion(REGION).list().toList();
List<Container> containers = cloudFiles.getContainerApi(REGION).list().toList();
for (Container container: containers) {
System.out.format(" %s%n", container);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public ListObjects(String username, String apiKey) {
private void listObjects() {
System.out.format("List Objects%n");

ObjectApi objectApi = cloudFiles.getObjectApiForRegionAndContainer(REGION, CONTAINER);
ObjectList objects = objectApi.list(ListContainerOptions.NONE);
ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER);
ObjectList objects = objectApi.list();

for (SwiftObject object: objects) {
System.out.format(" %s%n", object);
Expand All @@ -82,7 +82,7 @@ private void listObjects() {
private void listObjectsWithFiltering() {
System.out.format("List Objects With Filtering%n");

ObjectApi objectApi = cloudFiles.getObjectApiForRegionAndContainer(REGION, CONTAINER);
ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER);

ListContainerOptions filter = ListContainerOptions.Builder.prefix("createObjectFromString");
ObjectList objects = objectApi.list(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ private void enableCdnContainer(String container) {
STATIC_WEB_ERROR, "error.html");

UpdateContainerOptions opts = new UpdateContainerOptions().headers(enableStaticWebHeaders);
cloudFiles.getContainerApiForRegion(REGION).update(container, opts);
cloudFiles.getContainerApi(REGION).update(container, opts);

// enable the CDN container
URI cdnURI = cloudFiles.getCDNApiForRegion(REGION).enable(container);
URI cdnURI = cloudFiles.getCDNApi(REGION).enable(container);
System.out.format(" Go to %s/%n", cdnURI);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void uploadObjectFromFile() throws IOException {
ByteSource byteSource = Files.asByteSource(tempFile);
Payload payload = Payloads.newByteSourcePayload(byteSource);

cloudFiles.getObjectApiForRegionAndContainer(REGION, CONTAINER)
cloudFiles.getObjectApi(REGION, CONTAINER)
.put(filename + suffix, payload);

System.out.format(" %s%s%n", filename, suffix);
Expand All @@ -115,7 +115,7 @@ private void uploadObjectFromString() {
ByteSource source = ByteSource.wrap("uploadObjectFromString".getBytes());
Payload payload = Payloads.newByteSourcePayload(source);

cloudFiles.getObjectApiForRegionAndContainer(REGION, CONTAINER).put(filename, payload);
cloudFiles.getObjectApi(REGION, CONTAINER).put(filename, payload);

System.out.format(" %s%n", filename);
}
Expand Down

0 comments on commit 18fd5f0

Please sign in to comment.