Simple Cloud Storage API

41
© All rights reserved. Zend Technologies, Inc. Jan Burkl System Engineer, Zend Technologies Simple Cloud Storage API

Transcript of Simple Cloud Storage API

Page 1: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Jan Burkl

System Engineer, Zend Technologies

Simple Cloud Storage API

Page 2: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Agenda

• Einleitung / Zend Framework

• Basic Functions / Metadaten

• Eigener Adapter

Page 3: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Die Simple Cloud API

simplecloud.org / framework.zend.com

Page 4: Simple Cloud Storage API

© 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

Page 5: Simple Cloud Storage API

© 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

Page 6: Simple Cloud Storage API

© 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”

Page 7: Simple Cloud Storage 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

Page 8: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Getting started

Page 9: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Page 10: Simple Cloud Storage API

© 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

Page 11: Simple Cloud Storage API

© 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

Page 12: Simple Cloud Storage API

© 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 = "..."

Page 13: Simple Cloud Storage API

© 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"

Page 14: Simple Cloud Storage API

© 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..."

Page 15: Simple Cloud Storage API

© 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

);

Page 16: Simple Cloud Storage API

© 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);

Page 17: Simple Cloud Storage API

© 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);

Page 18: Simple Cloud Storage API

© 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();

Page 19: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Basic Operations /

Metadata

Page 20: Simple Cloud Storage API

© 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()

Page 21: Simple Cloud Storage API

© 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

Page 22: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Metadata

• Die fetchMetadata() Methode gibt

Metadaten eines entsprechenden Objekts

zurück

$metadata = $sc->fetchMetadata();

Page 23: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Page 24: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Über die Basics hinaus…

Page 25: Simple Cloud Storage API

© 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]();

}

Page 26: Simple Cloud Storage API

© 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!

Page 27: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Einen eigenen

Adapter bauen

Page 28: Simple Cloud Storage API

© 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:

Page 29: Simple Cloud Storage API

© 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

Page 30: Simple Cloud Storage API

© 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

Page 31: Simple Cloud Storage API

© 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

Page 32: Simple Cloud Storage API

© 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()

Page 33: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Mapping the API

listItems() =

storeItem() =

fetchItem() =

deleteItem() =

list_objects()

create_object()

get_object()

delete_object()

Page 34: Simple Cloud Storage API

© 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

Page 35: Simple Cloud Storage API

© 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..."

Page 36: Simple Cloud Storage API

© 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

Page 37: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Page 38: Simple Cloud Storage API

© All rights reserved. Zend Technologies, Inc.

Summary

Page 39: Simple Cloud Storage API

© 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

Page 40: Simple Cloud Storage API

© 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