automating your php infrastructure with the zend server api

47
Psst! Check this out: Soon in this room: Automating Infrastructure with ZS6.2 WebAPI

Upload: yonni-mendes

Post on 14-Jul-2015

344 views

Category:

Technology


1 download

TRANSCRIPT

Psst! Check this out:

Soon in this room:

Automating Infrastructure

with ZS6.2 WebAPI

Automating your PHP Infrastructure with

Zend Server API

What's new in WebAPI 1.6 on Zend Server 6.2

Is this the right room?

• What is Zend Server 6?

• What is the Zend Server WebAPI?

• Why does Zend Server have a WebAPI?

• How is this related to the Cloud?

Excuse me, is this the right room for an

argument?

I told you once

No you didn’t

Yes I did

No you did not

Is this a five minutes argument? Or the full

half an hour?

Still not sure …

In this very room we are going to answer the following:

● Why we should use the WebAPI

● How we use the WebAPI

● What we can do with the WebAPI

And also:

● Just how big is “Extensive”?

● What is my favorite color?

● Is there a red ElePHPant hiding in the room?

• API centric architecture

• A secure way to access all of Zend Server's functionality

• A uniform way to control a distributed, scaling, elastic environment

• Securely retrieve data and state information from Zend server

• Single-step actions to use the major features of Zend server

Yes, but what does WebAPI ... do?

In more techno-speak

• RESTfull gateway

• Crypto-Signatures based authentication

• JSON or XML output

• Backwards compatibility, versioning

• Smart Version Negotiation

• Uniform errorhandling

ZS6 WebAPIIn a nutshell

Brief tour of the ZS WebAPI

WebAPI Authentication

• WebAPI Keyso Est. WebAPI 1.0 (Zend Server 5.1)

o Hash of Date, Host, Uri, User agent and secret key

o X-ZendServer-Signature header

o Server side comparison

Signature

Generator

Date Host URI User Agent

Generate key (sha256) Signature hash

Secret key

Request headers

json 1.2

1.1

1.0

• Methodso Read/Write differentiation

o Exceptions to the rule

• Accept headero Type part

o Output format

o Version

Accept: application/vnd.zend.serverapi+xml;version=1.6

WebAPI Request structure

WebAPI output

• XML conventionso <zendServerAPIResponsexmlns="http://...

/server/api/1.6">

o <requestData>, <responseData>

o CDATA'd information

• JSON conventionso Direct conversion from xml to json

• Error outputo <errorData><errorCode><errorMessage>

• Dateso Timestamp

o ISO6801: 2007-04-05T14:30+02

WebAPI behavior guidelines

● Immediate response

● Atomic action

● Stateless

● Disjoint parameters

● Cluster agnostic

● Return meaningful information

● Return complete information

Demo: Script review, Restart ZS, UI visualization

ZS6 WebAPI actions

Capabilities and what to expect

WebAPI actions: Server & Cluster

• Add/remove servers, Enable/disable serverso Asynchronous action

o Parallel execution, to a point

• Cluster monitoring

• Restart PHP (Selective, force)

• Restart/Reload individual daemons

• Server bootstrap

Available in Zend cli-tools

Spotlight: Server & Cluster actions

● bootstrapSingleServer○ Passwords, initial webapi key

○ Accessible

● serverAddToCluster vs. clusterAddServer○ Server-centric vs. Cluster-centric

○ Different parameters

○ Demo soon

● daemonProbe

● tasksComplete

WebAPI actions: Configuration

• Turn Extensions on/offo Still requires a restart

o Asynchronous operations

• Validate and store directives' values

• Export/Import configuration blueprint

• Reset configuration

• Handle configuration mismatches

WebAPI actions: Monitor

• List and filter issues and eventso Predefined and custom filters

o Modified filters

• Issue details with paginated eventsGroup

• Export events to studio

• Delete events by id or by filter

• Manage Monitor Rules

• Export/Import monitor ruleso Global, per application

o For deployment

o For fun

WebAPI actions: Deployment

• Single-action application deployment

• Define application

• Manage applicationso Redeploy

o Single-action Update

o Rollback

• Manage code libraries

• Cluster distribution management

WebAPI actions: Vhosts

● Vhosts management for webservers

● Supports Apache and nginx on all operating systems

● Supports SSL vhosts for secured applications

● Cluster distributed

● Cluster distribution management

WebAPI actions, many more!

• Code-tracing

• JobQueue

• Page-cache

• Audit trail

• Statistics

• Studio integration

• Filters' management

• and much more...

A word about documentation

“Extensive”6 WebAPI versions16 modules50 data type elements68 error codes125 webapi actionswith examples, etc

Documentation bad?

Tell us what you think about our docs:

@ZendDocs, @ZendSui

[email protected]

[email protected]

Particularly if you founda mistake!

ZS6 WebAPIBasic Use Cases

Your wish is our WebAPI

Use cases: Bootstrap a server WebAPI action: bootstrapSingleServer

Programmatically make a server available after its initial installation

What you'll need:

• A newly installed server

• Willing to accept EULA - ah, yeah

• License key, order number

• Administrator passwordThis action explicitly does not require a webapi key to be

used. May not be used once the server is bootstrapped.

Bootstrap a server, BtS

• License is set

• User "admin" is created

• User "developer" may be created

• A launch profile is selectedo zend_monitor.developer_mode = 1|0

• Configuration snapshot

• Add an "admin" webapi key

• Audit entry under user "Unknown"

Bootstrap a server, output

<responseData>

<bootstrap>

<success>true</success>

<apiKey>

<id>5</id>

<username>admin</username>

<name><![CDATA[MyKey]]></name>

<hash><![CDATA[f2a18541...e949ef]]></hash>

<creationTime>...</creationTime>

</apiKey>

</bootstrap>

</responseData>

Demo: Bootstrap a single server

Use cases: Join a cluster

WebAPI action: serverAddToCluster

Programmatically join a new or existing cluster

What you'll need:

• A bootstrapped server

• Server details

• Database - empty or with schema

• Database credentialso For a new cluster, a root-ish user

o For an existing one, the zend user credentials

Server details are used internally to communicate with cluster members.

Join a cluster, BtS

• Asynchronous action, Accepted 202

• Sets db credentials in zend_database.ini

• Bootstrap mysql schema using root-ish user

• Create a zend user, grant permissionso New credentials are returned in action output

• Copy/Apply blueprint

• Connect Session clustering

• Restart server and reload daemons

Join a cluster, output

<responseData>

<serverInfo>

<id>25</id>

<name>ubuntu1204-b</name>

<address>10.9.183.84</address>

<status>restarting</status>

<messageList />

</serverInfo>

</responseData>

Demo: Join a cluster

The red ElePHPant in the room!

Story time: ZS6 and theCluster Manager

Mythological creatures

Add a server to a cluster, ZS5 CM styleWebAPI action: clusterAddServer

Programmatically add a remote Zend Server to an existing cluster

What you'll need:

• A connected Zend Server

• A newly installed server

• Server details

• Database with schema

Add a server, ZS5 CM style, BtS• Asynchronous action, Accepted 202

• Uses local db credentials

• Nested WebAPI action, calls serverAddToCluster on the remote servero Any problems with this?

Add a server, ZS5 CM style, output<responseData>

<serverInfo>

<id>25</id>

<name>ubuntu1204-b</name>

<address>10.9.183.84</address>

<status>restarting</status>

<messageList />

</serverInfo>

</responseData>

Back to our regular programme

More WebAPI stuff

Use cases: Change directive values

WebAPI action: configurationStoreDirectives

Programmatically change directives' values

What you'll need:

• A bootstrapped Zend Server

• A list of directive names and values to change

You may change Zend daemons' directives

Change directive values, BtS

• Asynchronous call, Accepted 202

• Validation is performed for each directive during storage.

• Restart has to be explicitly called separatelyo DaemonProbe

o Selective restart

Demo: Change directive values

WebAPI based application

How would you build a custom developer dashboard

Requirements

● We do not allow a developer access to Zend Server at all

● Developers may access a dashboard that aggregates information from ZS

● Developers should see○ Deployment Audit Entries

○ Monitor issue entries

○ Codetracing archives related to new issue entries

○ Deployed application details

Requirement: Audit trail

Display 10 entries of deployment-only Audit trail events and their details

● auditGetList - retrieve audit entries

● filters[auditGroups][0]=AUDIT_GROUP_DEPLOYMENT

Response:"responseData":{"auditMessages":[{...

"auditTypeTranslated":"Application deployed",

"baseUrl":"http:\/\/myApplication\/",

"creationTime":"2013-10-08T17:19:03+03:00",

Requirement: Latest Issues

Display 10 entries of “Error Events” in user applications and scripts

● monitorGetIssuesByPredefinedFilter

● Filter: filterId=Errors%20Issues

Response:

"responseData":{"issues":[{"eventType":"0",

"count":"1",

"lastOccurance":"2013-10-08T19:58:32+03:00",

“codeTracingEventGroupId”:”16”,

Requirement: Codetracing

Retrieve codetracing archive relevant to the issues retrieved by monitorGetIssues...Filter

● codetracingDownloadTraceFile

● eventGroupId=<issue.codeTracingEventGroupId>

Response: AMF file with codetracing information for use in Zend Studio

(Import/Zend/Zend Server Event File)

Requirement: Apps details

Display details about deployed applications

● applicationGetStatus - retrieve app entries

Response:

"responseData":{"applicationsList":[{"baseUrl":"http://mine-app/",

"userAppName":"MyApp",

"status":"deployed",

"healthCheck":"ok",

Dashboard architecture

What you'll need

• A webserver … uh ...

• Deploy the developer dashboard application

How is it used?

• Developer goes to developer dashboard

• Dashboard retrieves data from webapi

• Dashboard displays the retrieved information in a formatted way

• Codetracing amf file retrieval from the dashboard acts as a proxy for the webapi call

Thank you!Ideas, feedback, advice: [email protected], @zendsui

</responseData>My favorite color: Blue

Comments & feedback

in joind.in/9345