Object storage lab
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.




This repository contains the fully implemented lab exercise for CCP1-STR2.

The lab consists of two parts:

  1. interactions with the Swift object storage system using the curl command line tool
  2. interactions with the Swift object storage using the openstack4j library

3rd party dependencies are local (avoid network issues) as well as specified in a maven pom file.

1. curl exercises

The swift API endpoint on ned is: https://ned.cloudlab.zhaw.ch:6780/swift/v1/

Source your OpenStack credentials

$ source my-credentials-openrc.sh

Get a keystone token

Need to access the swift API

This command should be given to the student as it is not the focus of the lab.

export TOKEN=`curl -si -X POST $OS_AUTH_URL/auth/tokens\?nocatalog   -H "Content-Type: application/json"   -d '{ "auth": { "identity": { "methods": ["password"],"password": {"user": {"domain": {"name": "'"$OS_USER_DOMAIN_NAME"'"},"name": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"} } }, "scope": { "project": { "domain": { "name": "'"$OS_PROJECT_DOMAIN_NAME"'" }, "name":  "'"$OS_PROJECT_NAME"'" } } }}' | awk '/X-Subject-Token:/ {print $2}'`

Subtask one

Explore the swift API with curl. Here you need to list containers, create a container, upload a plain text file as an object to the container and then delete the object and container.

list available containers

curl -v -X GET -H 'X-Auth-Token: $TOKEN' https://ned.cloudlab.zhaw.ch:6780/swift/v1/

next create a container

curl -v -X PUT -H 'X-Auth-Token: $TOKEN' https://ned.cloudlab.zhaw.ch:6780/swift/v1/boom

then upload an object (plain text) to the container

curl -X PUT -H 'X-Auth-Token: $TOKEN' -v -d "Hello! This is some content served from swift!" https://ned.cloudlab.zhaw.ch:6780/swift/v1/tank/helloworld.txt

get the contents of the object you just uploaded

curl -X GET -H 'X-Auth-Token: $TOKEN' https://ned.cloudlab.zhaw.ch:6780/swift/v1/tank/helloworld.txt

delete the object

curl -X DELETE -H 'X-Auth-Token: $TOKEN' https://ned.cloudlab.zhaw.ch:6780/swift/v1/tank/helloworld.txt

delete the container

curl -v -X DELETE -H 'X-Auth-Token: $TOKEN' https://ned.cloudlab.zhaw.ch:6780/swift/v1/tank

2. openstack4j exercises.

  • The complete answer to the exercise is given in the source file SwiftLabClient.java
  • The project is a maven based one. Students should use Eclipse to develop their parts. Eclipse needs to have the maven plugin installed. This will ensure all 3rd party dependencies are installed.
  • There is example content that students can upload to swift under the ./samples directory.

Expected output of the program

listContainers: Should be 0 containers....
Number of containers: 0

createContainer: Create the container....
Container created with name: swift

listContainers: Should be 1 container....
Number of containers: 1

uploadObjects: Upload the contents of the directory.... samples
Successfully uploaded file: /Users/andy/Source/eclipse-ws/str2-lab/samples/dog.jpg
File uploaded with etag: fb2580d7990d867e1a7742c2240eee63
Successfully uploaded file: /Users/andy/Source/eclipse-ws/str2-lab/samples/kitten.jpg
File uploaded with etag: 52ba4145e8834c15fdd203d8fc56dc47

getContainerContents: Get the contents of the container named: swift
File etag: fb2580d7990d867e1a7742c2240eee63
File last modified: Thu Nov 02 16:38:31 CET 2017
File mime type: application/octet-stream
File name: dog.jpg
File size in bytes: 561459
File's metadata: {Last-Mod=1509578106000, X-Object-Meta-Last-Mod=1509578106000, X-Timestamp=1509637111.56170, X-Trans-Id=tx000000000000000005b3b-0059fb3bf7-6acb19-default}
File has been downloaded successfully as: /Users/andy/Source/eclipse-ws/str2-lab/downloads/dog.jpg
File etag: 52ba4145e8834c15fdd203d8fc56dc47
File last modified: Thu Nov 02 16:38:31 CET 2017
File mime type: application/octet-stream
File name: kitten.jpg
File size in bytes: 307026
File's metadata: {Last-Mod=1509619543000, X-Object-Meta-Last-Mod=1509619543000, X-Timestamp=1509637111.64974, X-Trans-Id=tx000000000000000005b2e-0059fb3bf7-608ead-default}
File has been downloaded successfully as: /Users/andy/Source/eclipse-ws/str2-lab/downloads/kitten.jpg

removeAllContent: Remove objects and container that were created....
Sucessfully deleted object.
Sucessfully deleted object.
Sucessfully deleted container.
curl -v -X PUT -H 'X-Auth-Token: <YOUR_TOKEN>' -H ‘Content-Type: text/plain’ -d <CONTENT> <SWIFT_ENDPOINT><CONTAINER_NAME><OBJECT_NAME>
  • Content-Type header is optional
  • Same request formulation for container: URI differs
    • does not require content or a content-type header