Simple Cloud Storage API
Transcript of Simple Cloud Storage API
© All rights reserved. Zend Technologies, Inc.
Jan Burkl
System Engineer, Zend Technologies
Simple Cloud Storage API
© All rights reserved. Zend Technologies, Inc.
Agenda
• Einleitung / Zend Framework
• Basic Functions / Metadaten
• Eigener Adapter
© All rights reserved. Zend Technologies, Inc.
Die Simple Cloud API
simplecloud.org / framework.zend.com
© All rights reserved. Zend Technologies, Inc.
Die Simple Cloud API
• Eine gemeinschaftliche Arbeit von Zend, GoGrid, IBM,
Microsoft, Nirvanix und Rackspace
Eigene Librarys, um andere Cloud Provider zu unterstützen
• Das Ziel: Schreiben von portablen und interoperablen
Code, der mit verschiedenen Cloud Anbietern funktioniert
• Artikel über die SimpleCloud API: bit.ly/1bSkTx
DeveloperWorks Open Source Zone
© All rights reserved. Zend Technologies, Inc.
Die Simple Cloud API
• Behandelt drei Bereiche:
File Storage (S3, Nirvanix, Azure Blob Storage, Rackspace Cloud
Files)
Document Storage (SimpleDB, Azure Table Storage)
Simple Queues (SQS, Azure Table Storage)
• Benutzt Factory und Adapter Design Patterns
Eine Konfigurationsdatei teilt dem Factory Objekt mit, welcher
Adapter erstellt werden soll
© All rights reserved. Zend Technologies, Inc.
Zend Framework
“Zend Framework 1.11.0
marks the first official, stable release of
Zend_Cloud,
Zend Framework's PHP version of the SimpleCloud API”
© All rights reserved. Zend Technologies, Inc.
Zend Framework
• Queue Services:
Amazon Simple Queue Service
(SQS)
Windows Azure's Queue Service
Alle Adapter von Zend_Queue:
• Zend Platform JobQueue
• Memcacheq
• Relational Database
• ActiveMQ
• Document Services:
Amazon SimpleDB
Windows Azure's Table Storage
• Storage Services:
Amazon Simple Storage Service (S3)
Windows Azure's Blog Storage
Nirvanix
Lokales Filesystem
© All rights reserved. Zend Technologies, Inc.
Getting started
© All rights reserved. Zend Technologies, Inc.
© All rights reserved. Zend Technologies, Inc.
Getting started
• Für die Magie nutzt Simple
Cloud API Dependency
Injection.
• Wir erstellen einen Adapter
mit Hilfe eines Properties
Files
Dieses Konfigurationsfile
enthält alle Informationen,
die das Zend Framework
benötigt, um den Adapter zu
erstellen
Injection
© All rights reserved. Zend Technologies, Inc.
Getting started
• Erster Schritt: Properties File / Konfigurationsdatei
Zend_Config
• Zend_Config_Ini
• Zend_Config_Xml
• Zend_Config_Json
• Zend_Config_Yaml
Jeder Simple Cloud Adapter hat unterschiedliche Werte, aber alle haben den Parameter storage_adapter
© All rights reserved. Zend Technologies, Inc.
Getting started: Konfigurationsdatei
• s3.ini:
http_adapter = "Zend_Http_Client_Adapter_Socket"
storage_adapter = "Zend_Cloud_StorageService_Adapter_S3"
bucket_name = "zend-webinar-de-bucket"
aws_accesskey = "..."
aws_secretkey = "..."
© All rights reserved. Zend Technologies, Inc.
Getting started: Konfigurationsdatei
• nirvanix.ini:
storage_adapter = "Zend_Cloud_StorageService_Adapter_Nirvanix"
nirvanix.appName = "ZendCon"
auth_accesskey = "533a2...79ef10"
auth_username = "johndoe"
auth_password = "PD3x7Js/"
remote_directory = "/johndoe"
© All rights reserved. Zend Technologies, Inc.
Getting started: Konfigurationsdatei
• rackspace.ini / openstack.ini:
storage_adapter = "Zx_Cloud_StorageService_Adapter_Rackspace"
container = "zend-webinar"
api_access_key = "d9b67018f861f12b23379330a"
api_access_username = "johndoe"
auth_password = "Uk3XJkf0w"
local_url = "http://localhost..."
© All rights reserved. Zend Technologies, Inc.
Getting started:
• Storage Adapter erstellen:
• $sc ist jetzt Storage Adapter.
Welchen Typ die Klasse hat, wissen wir nicht (bzw. Es kümmert
uns nicht).
$credentials = new Zend_Config_Ini($configFile);
$sc = Zend_Cloud_StorageService_Factory::getAdapter(
$credentials
);
© All rights reserved. Zend Technologies, Inc.
Vendor-spezifische APIs
• Alle Items in Nirvanix Folder listen:
• Codezeilen sind spezifisch für Nirvanix
$auth = array(
'username' => 'your-username',
'password' => 'your-password',
'appKey' => 'your-appkey'
);
$nirvanix = new Zend_Service_Nirvanix($auth);
$imfs = $nirvanix->getService('IMFS');
$args = array(
'folderPath' => '/dougtidwell',
'pageNumber' => 1,
'pageSize' => 5
);
$stuff = $imfs->ListFolder($args);
© All rights reserved. Zend Technologies, Inc.
Vendor-spezifische APIs
• Alle Items eines S3 Buckets listen:
• Codezeilen sind spezifisch für S3.
$s3 = new Zend_Service_Amazon_S3(
$accessKey, $secretKey);
$stuff = $s3->getObjectsByBucket($bucketName);
© All rights reserved. Zend Technologies, Inc.
The Simple Cloud Storage API
• Alle Items eines Nirvanix Directorys oder eines S3
Buckets listen:
• Codezeilen funktionieren mit Nirvanix und S3 (und
Rackspace, etc.)
Von der Konfigurationsdatei hängt der zu erstellende
Adapter und der verwendete Storage Service ab
$credentials = new Zend_Config_Ini($configFile);
$stuff =
Zend_Cloud_StorageService_Factory::getAdapter($credentials)
->listItems();
© All rights reserved. Zend Technologies, Inc.
Basic Operations /
Metadata
© All rights reserved. Zend Technologies, Inc.
Methoden
• Storage API unterstützt verschiedene, allgemeingültige
Operationen:
• Nicht alle werden nativ unterstützt…
Storage
• storeItem()
• fetchItem()
• deleteItem()
Modify
• copyItem()
• moveItem()
• renameItem()
Listing
• listFolders()
• listItems()
Metadata
• storeMetadata(),
• fetchMetadata()
• deleteMetadata()
© All rights reserved. Zend Technologies, Inc.
Metadata
• Viele Features der Cloud Storage Services werden
administriert über Metadaten
• Z.B. der S3 Adapter, unterstützt vier Werte für
Zugriffskontrolle:
S3_ACL_PRIVATE
S3_ACL_PUBLIC_READ
S3_ACL_PUBLIC_WRITE
S3_ACL_AUTH_READ
© All rights reserved. Zend Technologies, Inc.
Metadata
• Die fetchMetadata() Methode gibt
Metadaten eines entsprechenden Objekts
zurück
$metadata = $sc->fetchMetadata();
© All rights reserved. Zend Technologies, Inc.
© All rights reserved. Zend Technologies, Inc.
Über die Basics hinaus…
© All rights reserved. Zend Technologies, Inc.
Über die Basics hinaus…
• Obwohl die Simple Cloud API viele nützliche Funktionen
liefert, braucht man manchmal welche, die es nicht gibt
if ($sc->getClient() instanceof Zend_Service_Nirvanix) {
$sc->getClient()->[CDN function]();
}
© All rights reserved. Zend Technologies, Inc.
Probleme
• Nicht alle Storage Services unterstützten “Rename”.
Man kann es hacken, aber …
• Nicht alle Storage Services unterstützen “Listing Containers”
• Die getClient() Methode als Workaround für
Inkonsistenzen
• Ansätze:
if ($sc->getClient()->supportsRenaming())
• Ihr Input ist gefragt!
© All rights reserved. Zend Technologies, Inc.
Einen eigenen
Adapter bauen
© All rights reserved. Zend Technologies, Inc.
Eigener Adapter
• Methoden des entsprechenden Interfaces
implementieren
Zend_Cloud_StorageService_Adapter
• Hat der entsprechende Cloud Anbieter schon eine
Library, hat man schon 80% geschafft:
© All rights reserved. Zend Technologies, Inc.
„ OpenStack is a collection of open source technology
products delivering a scalable, secure, standards-based
cloud computing software solution.”
“OpenStack Object Storage is software for creating
redundant, scalable object storage using clusters of
commodity servers to store terabytes or even petabytes of
data.”
OpenStack
© All rights reserved. Zend Technologies, Inc.
Ein Rackspace / OpenStack Adapter
1. Native PHP Cloud Klasse auf OpenStack API mappen
2. Welche Parameter braucht Adapter
3. Zusammenbauen
Mit ein wenig Glück ist der meiste
Code schon in der nativen Klasse
© All rights reserved. Zend Technologies, Inc.
Rackspace – PHP API
• https://github.com/rackspace/php-cloudfiles/tree
• http://www.compasswebpublisher.com/php/rackspace-
cloudfiles-php-api
• http://code.google.com/p/phprackcloud/
• https://github.com/pas256/Rackspace-Cloud-PHP-Library
© All rights reserved. Zend Technologies, Inc.
Mapping the API
• Die OpenStack API basiert auf der Rackspace API
• Einige Operationen, die durch die Rackspace API
unterstützt werden:
list_objects()
create_object()
get_object()
delete_object()
© All rights reserved. Zend Technologies, Inc.
Mapping the API
listItems() =
storeItem() =
fetchItem() =
deleteItem() =
list_objects()
create_object()
get_object()
delete_object()
© All rights reserved. Zend Technologies, Inc.
Handling Properties
• Rackspace braucht einen Username, ein API Key und ein
Remote Directory.
• Da OpenStack lokal / netzintern installiert wird, brauchen
wir die URL eines OpenStack Storage Server.
http://openstack.org/
http://wiki.openstack.org/SwiftInstall/Austin
http://swift.openstack.org/development_saio.html
© All rights reserved. Zend Technologies, Inc.
Getting started: Konfigurationsdatei
• rackspace.ini / openstack.ini:
storage_adapter = "Zx_Cloud_StorageService_Adapter_Rackspace"
container = "zend-webinar"
api_access_key = "d9b67018f861f12b23379330a"
api_access_username = "johndoe"
auth_password = "Uk3XJkf0w"
local_url = "http://localhost..."
© All rights reserved. Zend Technologies, Inc.
Writing the Code
• Instanz von CF_Authentication
• Wenn autentifiziert, ein CF_Connection Objekt erstellen
• Wenn Connection steht, den Container holen
© All rights reserved. Zend Technologies, Inc.
© All rights reserved. Zend Technologies, Inc.
Summary
© All rights reserved. Zend Technologies, Inc.
Mitmachen!
• Simple Cloud API
Code downloaden, Prototypen bauen, Requirements / neue
Adapter / Bug Reports zuschicken
simplecloud.org / framework.zend.com
• Auf weitere Simple Cloud Webinare freuen
© All rights reserved. Zend Technologies, Inc.
cloudusecases.org
• Die Cloud Computing Use Cases
Group fokussiert sich auf das
Dokumentieren von Customer
Requirements.
• Join!
• Cloud Computing wird die
größte Änderung in der IT seit
dem Wachstum des Webs sein
Aber: um das meiste
rauszuholen, müssen Dinge
offen gehalten werden
Und jeder kann dabei sein…
• Version 5 kommt bald
© All rights reserved. Zend Technologies, Inc.
Dankeschön!
http://github.com/burkl/Zend-Webinar-Simplecloud
http://www.zend.com/de/resources/webinars/