import v1.1.0_RC2 | 2009-09-20
This commit is contained in:
@ -17,7 +17,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Abstract.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Abstract.php';
|
||||
@ -29,7 +29,7 @@ require_once 'Zend/Service/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Service_Amazon_Abstract extends Zend_Service_Abstract
|
||||
@ -164,4 +164,4 @@ abstract class Zend_Service_Amazon_Abstract extends Zend_Service_Abstract
|
||||
{
|
||||
return $this->_secretKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Accessories.php 12662 2008-11-15 15:29:58Z beberlei $
|
||||
* @version $Id: Accessories.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Accessories
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: CustomerReview.php 12662 2008-11-15 15:29:58Z beberlei $
|
||||
* @version $Id: CustomerReview.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_CustomerReview
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Ec2.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -26,7 +26,7 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Abstract.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Abstract.php';
|
||||
@ -32,7 +32,7 @@ require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Service_Amazon_Ec2_Abstract extends Zend_Service_Amazon_Abstract
|
||||
@ -40,27 +40,27 @@ abstract class Zend_Service_Amazon_Ec2_Abstract extends Zend_Service_Amazon_Abst
|
||||
/**
|
||||
* The HTTP query server
|
||||
*/
|
||||
const EC2_ENDPOINT = 'ec2.amazonaws.com';
|
||||
protected $_ec2Endpoint = 'ec2.amazonaws.com';
|
||||
|
||||
/**
|
||||
* The API version to use
|
||||
*/
|
||||
const EC2_API_VERSION = '2008-12-01';
|
||||
protected $_ec2ApiVersion = '2009-04-04';
|
||||
|
||||
/**
|
||||
* Signature Version
|
||||
*/
|
||||
const EC2_SIGNATURE_VERSION = '2';
|
||||
protected $_ec2SignatureVersion = '2';
|
||||
|
||||
/**
|
||||
* Signature Encoding Method
|
||||
*/
|
||||
const EC2_SIGNATURE_METHOD = 'HmacSHA256';
|
||||
protected $_ec2SignatureMethod = 'HmacSHA256';
|
||||
|
||||
/**
|
||||
* Period after which HTTP request will timeout in seconds
|
||||
*/
|
||||
const HTTP_TIMEOUT = 10;
|
||||
protected $_httpTimeout = 10;
|
||||
|
||||
/**
|
||||
* Sends a HTTP request to the queue service using Zend_Http_Client
|
||||
@ -71,17 +71,17 @@ abstract class Zend_Service_Amazon_Ec2_Abstract extends Zend_Service_Amazon_Abst
|
||||
*/
|
||||
protected function sendRequest(array $params = array())
|
||||
{
|
||||
$url = 'https://' . $this->_getRegion() . self::EC2_ENDPOINT . '/';
|
||||
$url = 'https://' . $this->_getRegion() . $this->_ec2Endpoint . '/';
|
||||
|
||||
$params = $this->addRequiredParameters($params);
|
||||
|
||||
try {
|
||||
/* @var $request Zend_Http_Client */
|
||||
$request = self::getHttpClient();
|
||||
$request->resetParameters();
|
||||
$request->resetParameters();
|
||||
|
||||
$request->setConfig(array(
|
||||
'timeout' => self::HTTP_TIMEOUT
|
||||
'timeout' => $this->_httpTimeout
|
||||
));
|
||||
|
||||
$request->setUri($url);
|
||||
@ -95,7 +95,6 @@ abstract class Zend_Service_Amazon_Ec2_Abstract extends Zend_Service_Amazon_Abst
|
||||
$message = 'Error in request to AWS service: ' . $zhce->getMessage();
|
||||
throw new Zend_Service_Amazon_Ec2_Exception($message, $zhce->getCode());
|
||||
}
|
||||
|
||||
$response = new Zend_Service_Amazon_Ec2_Response($httpResponse);
|
||||
$this->checkForErrors($response);
|
||||
|
||||
@ -124,10 +123,10 @@ abstract class Zend_Service_Amazon_Ec2_Abstract extends Zend_Service_Amazon_Abst
|
||||
protected function addRequiredParameters(array $parameters)
|
||||
{
|
||||
$parameters['AWSAccessKeyId'] = $this->_getAccessKey();
|
||||
$parameters['SignatureVersion'] = self::EC2_SIGNATURE_VERSION;
|
||||
$parameters['Expires'] = gmdate('c');
|
||||
$parameters['Version'] = self::EC2_API_VERSION;
|
||||
$parameters['SignatureMethod'] = self::EC2_SIGNATURE_METHOD;
|
||||
$parameters['SignatureVersion'] = $this->_ec2SignatureVersion;
|
||||
$parameters['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
|
||||
$parameters['Version'] = $this->_ec2ApiVersion;
|
||||
$parameters['SignatureMethod'] = $this->_ec2SignatureMethod;
|
||||
$parameters['Signature'] = $this->signParameters($parameters);
|
||||
|
||||
return $parameters;
|
||||
@ -156,7 +155,7 @@ abstract class Zend_Service_Amazon_Ec2_Abstract extends Zend_Service_Amazon_Abst
|
||||
protected function signParameters(array $paramaters)
|
||||
{
|
||||
$data = "POST\n";
|
||||
$data .= $this->_getRegion() . self::EC2_ENDPOINT . "\n";
|
||||
$data .= $this->_getRegion() . $this->_ec2Endpoint . "\n";
|
||||
$data .= "/\n";
|
||||
|
||||
uksort($paramaters, 'strcmp');
|
||||
@ -198,4 +197,4 @@ abstract class Zend_Service_Amazon_Ec2_Abstract extends Zend_Service_Amazon_Abst
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Availabilityzones.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
@ -28,7 +28,7 @@ require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Availabilityzones extends Zend_Service_Amazon_Ec2_Abstract
|
||||
|
350
libs/Zend/Service/Amazon/Ec2/CloudWatch.php
Normal file
350
libs/Zend/Service/Amazon/Ec2/CloudWatch.php
Normal file
@ -0,0 +1,350 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: CloudWatch.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface that allows yout to run, terminate, reboot and describe Amazon
|
||||
* Ec2 Instances.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_CloudWatch extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* The HTTP query server
|
||||
*/
|
||||
protected $_ec2Endpoint = 'monitoring.amazonaws.com';
|
||||
|
||||
/**
|
||||
* The API version to use
|
||||
*/
|
||||
protected $_ec2ApiVersion = '2009-05-15';
|
||||
|
||||
/**
|
||||
* XML Namespace for the CloudWatch Stuff
|
||||
*/
|
||||
protected $_xmlNamespace = 'http://monitoring.amazonaws.com/doc/2009-05-15/';
|
||||
|
||||
/**
|
||||
* The following metrics are available from each EC2 instance.
|
||||
*
|
||||
* CPUUtilization: The percentage of allocated EC2 compute units that are
|
||||
* currently in use on the instance. This metric identifies the processing
|
||||
* power required to run an application upon a selected instance.
|
||||
*
|
||||
* NetworkIn: The number of bytes received on all network interfaces by
|
||||
* the instance. This metric identifies the volume of incoming network
|
||||
* traffic to an application on a single instance.
|
||||
*
|
||||
* NetworkOut: The number of bytes sent out on all network interfaces
|
||||
* by the instance. This metric identifies the volume of outgoing network
|
||||
* traffic to an application on a single instance.
|
||||
*
|
||||
* DiskWriteOps: Completed write operations to all hard disks available to
|
||||
* the instance. This metric identifies the rate at which an application
|
||||
* writes to a hard disk. This can be used to determine the speed in which
|
||||
* an application saves data to a hard disk.
|
||||
*
|
||||
* DiskReadBytes: Bytes read from all disks available to the instance. This
|
||||
* metric is used to determine the volume of the data the application reads
|
||||
* from the hard disk of the instance. This can be used to determine the
|
||||
* speed of the application for the customer.
|
||||
*
|
||||
* DiskReadOps: Completed read operations from all disks available to the
|
||||
* instances. This metric identifies the rate at which an application reads
|
||||
* a disk. This can be used to determine the speed in which an application
|
||||
* reads data from a hard disk.
|
||||
*
|
||||
* DiskWriteBytes: Bytes written to all disks available to the instance. This
|
||||
* metric is used to determine the volume of the data the application writes
|
||||
* onto the hard disk of the instance. This can be used to determine the speed
|
||||
* of the application for the customer.
|
||||
*
|
||||
* Latency: Time taken between a request and the corresponding response as seen
|
||||
* by the load balancer.
|
||||
*
|
||||
* RequestCount: The number of requests processed by the LoadBalancer.
|
||||
*
|
||||
* HealthyHostCount: The number of healthy instances. Both Load Balancing dimensions,
|
||||
* LoadBalancerName and AvailabilityZone, should be specified when retreiving
|
||||
* HealthyHostCount.
|
||||
*
|
||||
* UnHealthyHostCount: The number of unhealthy instances. Both Load Balancing dimensions,
|
||||
* LoadBalancerName and AvailabilityZone, should be specified when retreiving
|
||||
* UnHealthyHostCount.
|
||||
*
|
||||
* Amazon CloudWatch data for a new EC2 instance becomes available typically
|
||||
* within one minute of the end of the first aggregation period for the new
|
||||
* instance. You can use the currently available dimensions for EC2 instances
|
||||
* along with these metrics in order to refine the slice of data you want returned,
|
||||
* such as metric CPUUtilization and dimension ImageId to get all CPUUtilization
|
||||
* data for instances using the specified AMI.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_validMetrics = array('CPUUtilization', 'NetworkIn', 'NetworkOut',
|
||||
'DiskWriteOps', 'DiskReadBytes', 'DiskReadOps',
|
||||
'DiskWriteBytes', 'Latency', 'RequestCount',
|
||||
'HealthyHostCount', 'UnHealthyHostCount');
|
||||
|
||||
/**
|
||||
* Amazon CloudWatch not only aggregates the raw data coming in, it also computes
|
||||
* several statistics on the data. The following table lists the statistics that you can request:
|
||||
*
|
||||
* Minimum: The lowest value observed during the specified period. This can be used to
|
||||
* determine low volumes of activity for your application.
|
||||
*
|
||||
* Maximum: The highest value observed during the specified period. You can use this to
|
||||
* determine high volumes of activity for your application.
|
||||
*
|
||||
* Sum: The sum of all values received (if appropriate, for example a rate would not be
|
||||
* summed, but a number of items would be). This statistic is useful for determining
|
||||
* the total volume of a metric.
|
||||
*
|
||||
* Average: The Average of all values received during the specified period. By comparing
|
||||
* this statistic with the minimum and maximum statistics, you can determine the full
|
||||
* scope of a metric and how close the average use is to the minimum and the maximum.
|
||||
* This will allow you to increase or decrease your resources as needed.
|
||||
*
|
||||
* Samples: The count (number) of measures used. This statistic is always returned to
|
||||
* show the user the size of the dataset collected. This will allow the user to properly
|
||||
* weight the data.
|
||||
*
|
||||
* Statistics are computed within a period you specify, such as all CPUUtilization within a
|
||||
* five minute period. At a minimum, all data is aggregated into one minute intervals. This
|
||||
* is the minimum resolution of the data. It is this data that can be aggregated into larger
|
||||
* periods of time that you request.
|
||||
*
|
||||
* Aggregate data is generally available from the service within one minute from the end of the
|
||||
* aggregation period. Delays in data propagation might cause late or partially late data in
|
||||
* some cases. If your data is delayed, you should check the service’s Health Dashboard for
|
||||
* any current operational issues with either Amazon CloudWatch or the services collecting
|
||||
* the data, such as EC2 or Elastic Load Balancing.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_validStatistics = array('Average', 'Maximum', 'Minimum', 'Samples', 'Sum');
|
||||
|
||||
/**
|
||||
* Valid Dimention Keys for getMetricStatistics
|
||||
*
|
||||
* ImageId: This dimension filters the data you request for all instances running
|
||||
* this EC2 Amazon Machine Image (AMI).
|
||||
*
|
||||
* AvailabilityZone: This dimension filters the data you request for all instances
|
||||
* running in that EC2 Availability Zone.
|
||||
*
|
||||
* AutoScalingGroupName: This dimension filters the data you request for all instances
|
||||
* in a specified capacity group. An AutoScalingGroup is a collection of instances
|
||||
* defined by customers of the Auto Scaling service. This dimension is only available
|
||||
* for EC2 metrics when the instances are in such an AutoScalingGroup.
|
||||
*
|
||||
* InstanceId: This dimension filters the data you request for only the identified
|
||||
* instance. This allows a user to pinpoint an exact instance from which to monitor data.
|
||||
*
|
||||
* InstanceType: This dimension filters the data you request for all instances running
|
||||
* with this specified instance type. This allows a user to catagorize his data by the
|
||||
* type of instance running. For example, a user might compare data from an m1.small instance
|
||||
* and an m1.large instance to determine which has the better business value for his application.
|
||||
*
|
||||
* LoadBalancerName: This dimension filters the data you request for the specified LoadBalancer
|
||||
* name. A LoadBalancer is represented by a DNS name and provides the single destination to
|
||||
* which all requests intended for your application should be directed. This metric allows
|
||||
* you to examine data from all instances connected to a single LoadBalancer.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_validDimensionsKeys = array('ImageId', 'AvailabilityZone', 'AutoScalingGroupName',
|
||||
'InstanceId', 'InstanceType', 'LoadBalancerName');
|
||||
|
||||
/**
|
||||
* Returns data for one or more statistics of given a metric
|
||||
*
|
||||
* Note:
|
||||
* The maximum number of datapoints that the Amazon CloudWatch service will
|
||||
* return in a single GetMetricStatistics request is 1,440. If a request is
|
||||
* made that would generate more datapoints than this amount, Amazon CloudWatch
|
||||
* will return an error. You can alter your request by narrowing the time range
|
||||
* (StartTime, EndTime) or increasing the Period in your single request. You may
|
||||
* also get all of the data at the granularity you originally asked for by making
|
||||
* multiple requests with adjacent time ranges.
|
||||
*
|
||||
* @param array $options The options you want to get statistics for:
|
||||
* ** Required **
|
||||
* MeasureName: The measure name that corresponds to
|
||||
* the measure for the gathered metric. Valid EC2 Values are
|
||||
* CPUUtilization, NetworkIn, NetworkOut, DiskWriteOps
|
||||
* DiskReadBytes, DiskReadOps, DiskWriteBytes. Valid Elastic
|
||||
* Load Balancing Metrics are Latency, RequestCount, HealthyHostCount
|
||||
* UnHealthyHostCount
|
||||
* Statistics: The statistics to be returned for the given metric. Valid
|
||||
* values are Average, Maximum, Minimum, Samples, Sum. You can specify
|
||||
* this as a string or as an array of values. If you don't specify one
|
||||
* it will default to Average instead of failing out. If you specify an incorrect
|
||||
* option it will just skip it.
|
||||
* ** Optional **
|
||||
* Dimensions: Amazon CloudWatch allows you to specify one Dimension to further filter
|
||||
* metric data on. If you don't specify a dimension, the service returns the aggregate
|
||||
* of all the measures with the given measure name and time range.
|
||||
* Unit: The standard unit of Measurement for a given Measure. Valid Values: Seconds,
|
||||
* Percent, Bytes, Bits, Count, Bytes/Second, Bits/Second, Count/Second, and None
|
||||
* Constraints: When using count/second as the unit, you should use Sum as the statistic
|
||||
* instead of Average. Otherwise, the sample returns as equal to the number of requests
|
||||
* instead of the number of 60-second intervals. This will cause the Average to
|
||||
* always equals one when the unit is count/second.
|
||||
* StartTime: The timestamp of the first datapoint to return, inclusive. For example,
|
||||
* 2008-02-26T19:00:00+00:00. We round your value down to the nearest minute.
|
||||
* You can set your start time for more than two weeks in the past. However,
|
||||
* you will only get data for the past two weeks. (in ISO 8601 format)
|
||||
* Constraints: Must be before EndTime
|
||||
* EndTime: The timestamp to use for determining the last datapoint to return. This is
|
||||
* the last datapoint to fetch, exclusive. For example, 2008-02-26T20:00:00+00:00.
|
||||
* (in ISO 8601 format)
|
||||
*/
|
||||
public function getMetricStatistics(array $options)
|
||||
{
|
||||
$_usedStatistics = array();
|
||||
|
||||
$params = array();
|
||||
$params['Action'] = 'GetMetricStatistics';
|
||||
|
||||
if (!isset($options['Period'])) {
|
||||
$options['Period'] = 60;
|
||||
}
|
||||
if (!isset($options['Namespace'])) {
|
||||
$options['Namespace'] = 'AWS/EC2';
|
||||
}
|
||||
|
||||
if (!isset($options['MeasureName']) || !in_array($options['MeasureName'], $this->_validMetrics, true)) {
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('Invalid Metric Type: ' . $options['MeasureName']);
|
||||
}
|
||||
|
||||
if(!isset($options['Statistics'])) {
|
||||
$options['Statistics'][] = 'Average';
|
||||
} elseif(!is_array($options['Statistics'])) {
|
||||
$options['Statistics'][] = $options['Statistics'];
|
||||
}
|
||||
|
||||
foreach($options['Statistics'] as $k=>$s) {
|
||||
if(!in_array($s, $this->_validStatistics, true)) continue;
|
||||
$options['Statistics.member.' . ($k+1)] = $s;
|
||||
$_usedStatistics[] = $s;
|
||||
}
|
||||
unset($options['Statistics']);
|
||||
|
||||
if(isset($options['StartTime'])) {
|
||||
if(!is_numeric($options['StartTime'])) $options['StartTime'] = strtotime($options['StartTime']);
|
||||
$options['StartTime'] = gmdate('c', $options['StartTime']);
|
||||
} else {
|
||||
$options['StartTime'] = gmdate('c', strtotime('-1 hour'));
|
||||
}
|
||||
|
||||
if(isset($options['EndTime'])) {
|
||||
if(!is_numeric($options['EndTime'])) $options['EndTime'] = strtotime($options['EndTime']);
|
||||
$options['EndTime'] = gmdate('c', $options['EndTime']);
|
||||
} else {
|
||||
$options['EndTime'] = gmdate('c');
|
||||
}
|
||||
|
||||
if(isset($options['Dimensions'])) {
|
||||
$x = 1;
|
||||
foreach($options['Dimensions'] as $dimKey=>$dimVal) {
|
||||
if(!in_array($dimKey, $this->_validDimensionsKeys, true)) continue;
|
||||
$options[$dimKey . '.member.' . $x++] = $dimVal;
|
||||
}
|
||||
}
|
||||
|
||||
$params = array_merge($params, $options);
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$response->setNamespace($this->_xmlNamespace);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:GetMetricStatisticsResult/ec2:Datapoints/ec2:member');
|
||||
|
||||
$return = array();
|
||||
$return['label'] = $xpath->evaluate('string(//ec2:GetMetricStatisticsResult/ec2:Label/text())');
|
||||
foreach ( $nodes as $node ) {
|
||||
$item = array();
|
||||
|
||||
$item['Timestamp'] = $xpath->evaluate('string(ec2:Timestamp/text())', $node);
|
||||
$item['Unit'] = $xpath->evaluate('string(ec2:Unit/text())', $node);
|
||||
$item['Samples'] = $xpath->evaluate('string(ec2:Samples/text())', $node);
|
||||
foreach($_usedStatistics as $us) {
|
||||
$item[$us] = $xpath->evaluate('string(ec2:' . $us . '/text())', $node);
|
||||
}
|
||||
|
||||
$return['datapoints'][] = $item;
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Metrics that are aviable for your current monitored instances
|
||||
*
|
||||
* @param string $nextToken The NextToken parameter is an optional parameter
|
||||
* that allows you to retrieve the next set of results
|
||||
* for your ListMetrics query.
|
||||
* @return array
|
||||
*/
|
||||
public function listMetrics($nextToken = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'ListMetrics';
|
||||
if (!empty($nextToken)) {
|
||||
$params['NextToken'] = $nextToken;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$response->setNamespace($this->_xmlNamespace);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:ListMetricsResult/ec2:Metrics/ec2:member');
|
||||
|
||||
$return = array();
|
||||
foreach ( $nodes as $node ) {
|
||||
$item = array();
|
||||
|
||||
$item['MeasureName'] = $xpath->evaluate('string(ec2:MeasureName/text())', $node);
|
||||
$item['Namespace'] = $xpath->evaluate('string(ec2:Namespace/text())', $node);
|
||||
$item['Deminsions']['name'] = $xpath->evaluate('string(ec2:Dimensions/ec2:member/ec2:Name/text())', $node);
|
||||
$item['Deminsions']['value'] = $xpath->evaluate('string(ec2:Dimensions/ec2:member/ec2:Value/text())', $node);
|
||||
|
||||
if (empty($item['Deminsions']['name'])) {
|
||||
$item['Deminsions'] = array();
|
||||
}
|
||||
|
||||
$return[] = $item;
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Ebs.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
@ -30,7 +30,7 @@ require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Ebs extends Zend_Service_Amazon_Ec2_Abstract
|
||||
@ -212,9 +212,9 @@ class Zend_Service_Amazon_Ec2_Ebs extends Zend_Service_Amazon_Ec2_Abstract
|
||||
$params = array();
|
||||
$params['Action'] = 'DetachVolume';
|
||||
$params['VolumeId'] = $volumeId;
|
||||
$params['InstanceId'] = $instanceId;
|
||||
$params['Device'] = $device;
|
||||
$params['Force'] = $force;
|
||||
$params['InstanceId'] = strval($instanceId);
|
||||
$params['Device'] = strval($device);
|
||||
$params['Force'] = strval($force);
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Elasticip.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
@ -29,7 +29,7 @@ require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Elasticip extends Zend_Service_Amazon_Ec2_Abstract
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Exception.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Exception.php';
|
||||
@ -28,7 +28,7 @@ require_once 'Zend/Service/Amazon/Exception.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Exception extends Zend_Service_Amazon_Exception
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Image.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
@ -28,7 +28,7 @@ require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Image extends Zend_Service_Amazon_Ec2_Abstract
|
||||
@ -241,7 +241,7 @@ class Zend_Service_Amazon_Ec2_Image extends Zend_Service_Amazon_Ec2_Abstract
|
||||
// break left out
|
||||
case 'productcodes':
|
||||
$params['Attribute'] = 'productCodes';
|
||||
$parmas['ProductCode.1'] = $productCode;
|
||||
$params['ProductCode.1'] = $productCode;
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Instance.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
@ -29,7 +29,7 @@ require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Instance extends Zend_Service_Amazon_Ec2_Abstract
|
||||
@ -99,6 +99,7 @@ class Zend_Service_Amazon_Ec2_Instance extends Zend_Service_Amazon_Ec2_Abstract
|
||||
* ramdiskId string The ID of the RAM disk with which to launch the instance.
|
||||
* blockDeviceVirtualName string Specifies the virtual name to map to the corresponding device name. For example: instancestore0
|
||||
* blockDeviceName string Specifies the device to which you are mapping a virtual name. For example: sdb
|
||||
* monitor boolean Turn on CloudWatch Monitoring for an instance.
|
||||
* @return array
|
||||
*/
|
||||
public function run(array $options)
|
||||
@ -161,6 +162,10 @@ class Zend_Service_Amazon_Ec2_Instance extends Zend_Service_Amazon_Ec2_Abstract
|
||||
$params['BlockDeviceMapping.n.DeviceName'] = $options['blockDeviceName'];
|
||||
}
|
||||
|
||||
if(isset($options['monitor']) && $options['monitor'] === true) {
|
||||
$params['Monitoring.Enabled'] = true;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
@ -232,29 +237,31 @@ class Zend_Service_Amazon_Ec2_Instance extends Zend_Service_Amazon_Ec2_Abstract
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$nodes = $xpath->query('//ec2:reservationSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
$return['instances'] = array();
|
||||
|
||||
foreach($nodes as $node) {
|
||||
$return['reservationId'] = $xpath->evaluate('string(ec2:reservationId/text())', $node);
|
||||
$return['ownerId'] = $xpath->evaluate('string(ec2:ownerId/text())', $node);
|
||||
if($xpath->evaluate('string(ec2:instancesSet/ec2:item/ec2:instanceState/ec2:code/text())', $node) == 48 && $ignoreTerminated) continue;
|
||||
$item = array();
|
||||
|
||||
$item['reservationId'] = $xpath->evaluate('string(ec2:reservationId/text())', $node);
|
||||
$item['ownerId'] = $xpath->evaluate('string(ec2:ownerId/text())', $node);
|
||||
|
||||
$gs = $xpath->query('ec2:groupSet/ec2:item', $node);
|
||||
foreach($gs as $gs_node) {
|
||||
$return['groupSet'][] = $xpath->evaluate('string(ec2:groupId/text())', $gs_node);
|
||||
$item['groupSet'][] = $xpath->evaluate('string(ec2:groupId/text())', $gs_node);
|
||||
unset($gs_node);
|
||||
}
|
||||
unset($gs);
|
||||
|
||||
$is = $xpath->query('ec2:instancesSet/ec2:item', $node);
|
||||
$return['instances'] = array();
|
||||
foreach($is as $is_node) {
|
||||
if($xpath->evaluate('string(ec2:instanceState/ec2:code/text())', $is_node) == 48 && $ignoreTerminated) continue;
|
||||
|
||||
$item = array();
|
||||
foreach($is as $is_node) {
|
||||
|
||||
$item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $is_node);
|
||||
$item['imageId'] = $xpath->evaluate('string(ec2:imageId/text())', $is_node);
|
||||
@ -269,11 +276,13 @@ class Zend_Service_Amazon_Ec2_Instance extends Zend_Service_Amazon_Ec2_Abstract
|
||||
$item['availabilityZone'] = $xpath->evaluate('string(ec2:placement/ec2:availabilityZone/text())', $is_node);
|
||||
$item['kernelId'] = $xpath->evaluate('string(ec2:kernelId/text())', $is_node);
|
||||
$item['ramediskId'] = $xpath->evaluate('string(ec2:ramediskId/text())', $is_node);
|
||||
$item['amiLaunchIndex'] = $xpath->evaluate('string(ec2:amiLaunchIndex/text())', $is_node);
|
||||
$item['monitoringState'] = $xpath->evaluate('string(ec2:monitoring/ec2:state/text())', $is_node);
|
||||
|
||||
$return['instances'][] = $item;
|
||||
unset($item);
|
||||
unset($is_node);
|
||||
}
|
||||
$return['instances'][] = $item;
|
||||
unset($item);
|
||||
unset($is);
|
||||
}
|
||||
|
||||
@ -297,9 +306,8 @@ class Zend_Service_Amazon_Ec2_Instance extends Zend_Service_Amazon_Ec2_Abstract
|
||||
|
||||
$return = array();
|
||||
|
||||
foreach($arrInstances['instances'] as $k => $instance) {
|
||||
foreach($arrInstances['instances'] as $instance) {
|
||||
if($instance['imageId'] !== $imageId) continue;
|
||||
$instance['groupSet'] = $arrInstances['groupSet'][$k];
|
||||
$return[] = $instance;
|
||||
}
|
||||
|
||||
@ -441,4 +449,78 @@ class Zend_Service_Amazon_Ec2_Instance extends Zend_Service_Amazon_Ec2_Abstract
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on Amazon CloudWatch Monitoring for an instance or a list of instances
|
||||
*
|
||||
* @param array|string $instanceId The instance or list of instances you want to enable monitoring for
|
||||
* @return array
|
||||
*/
|
||||
public function monitor($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'MonitorInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['InstanceId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['InstanceId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
|
||||
$items = $xpath->query('//ec2:instancesSet/ec2:item');
|
||||
|
||||
$arrReturn = array();
|
||||
foreach($items as $item) {
|
||||
$i = array();
|
||||
$i['instanceid'] = $xpath->evaluate('string(//ec2:instanceId/text())', $item);
|
||||
$i['monitorstate'] = $xpath->evaluate('string(//ec2:monitoring/ec2:state/text())');
|
||||
$arrReturn[] = $i;
|
||||
unset($i);
|
||||
}
|
||||
|
||||
return $arrReturn;
|
||||
}
|
||||
/**
|
||||
* Turn off Amazon CloudWatch Monitoring for an instance or a list of instances
|
||||
*
|
||||
* @param array|string $instanceId The instance or list of instances you want to disable monitoring for
|
||||
* @return array
|
||||
*/
|
||||
public function unmonitor($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'UnmonitorInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['InstanceId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['InstanceId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
|
||||
$items = $xpath->query('//ec2:instancesSet/ec2:item');
|
||||
|
||||
$arrReturn = array();
|
||||
foreach($items as $item) {
|
||||
$i = array();
|
||||
$i['instanceid'] = $xpath->evaluate('string(//ec2:instanceId/text())', $item);
|
||||
$i['monitorstate'] = $xpath->evaluate('string(//ec2:monitoring/ec2:state/text())');
|
||||
$arrReturn[] = $i;
|
||||
unset($i);
|
||||
}
|
||||
|
||||
return $arrReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
140
libs/Zend/Service/Amazon/Ec2/Instance/Reserved.php
Normal file
140
libs/Zend/Service/Amazon/Ec2/Instance/Reserved.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Reserved.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* Allows you to interface with the reserved instances on Amazon Ec2
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Instance_Reserved extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Describes Reserved Instances that you purchased.
|
||||
*
|
||||
* @param string|array $instanceId IDs of the Reserved Instance to describe.
|
||||
* @return array
|
||||
*/
|
||||
public function describeInstances($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeReservedInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['ReservedInstancesId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['ReservedInstancesId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$items = $xpath->query('//ec2:reservedInstancesSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach($items as $item) {
|
||||
$i = array();
|
||||
$i['reservedInstancesId'] = $xpath->evaluate('string(ec2:reservedInstancesId/text())', $item);
|
||||
$i['instanceType'] = $xpath->evaluate('string(ec2:instanceType/text())', $item);
|
||||
$i['availabilityZone'] = $xpath->evaluate('string(ec2:availabilityZone/text())', $item);
|
||||
$i['duration'] = $xpath->evaluate('string(ec2:duration/text())', $item);
|
||||
$i['fixedPrice'] = $xpath->evaluate('string(ec2:fixedPrice/text())', $item);
|
||||
$i['usagePrice'] = $xpath->evaluate('string(ec2:usagePrice/text())', $item);
|
||||
$i['productDescription'] = $xpath->evaluate('string(ec2:productDescription/text())', $item);
|
||||
$i['instanceCount'] = $xpath->evaluate('string(ec2:instanceCount/text())', $item);
|
||||
$i['state'] = $xpath->evaluate('string(ec2:state/text())', $item);
|
||||
|
||||
$return[] = $i;
|
||||
unset($i);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes Reserved Instance offerings that are available for purchase.
|
||||
* With Amazon EC2 Reserved Instances, you purchase the right to launch Amazon
|
||||
* EC2 instances for a period of time (without getting insufficient capacity
|
||||
* errors) and pay a lower usage rate for the actual time used.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function describeOfferings()
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeReservedInstancesOfferings';
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$items = $xpath->query('//ec2:reservedInstancesOfferingsSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach($items as $item) {
|
||||
$i = array();
|
||||
$i['reservedInstancesOfferingId'] = $xpath->evaluate('string(ec2:reservedInstancesOfferingId/text())', $item);
|
||||
$i['instanceType'] = $xpath->evaluate('string(ec2:instanceType/text())', $item);
|
||||
$i['availabilityZone'] = $xpath->evaluate('string(ec2:availabilityZone/text())', $item);
|
||||
$i['duration'] = $xpath->evaluate('string(ec2:duration/text())', $item);
|
||||
$i['fixedPrice'] = $xpath->evaluate('string(ec2:fixedPrice/text())', $item);
|
||||
$i['usagePrice'] = $xpath->evaluate('string(ec2:usagePrice/text())', $item);
|
||||
$i['productDescription'] = $xpath->evaluate('string(ec2:productDescription/text())', $item);
|
||||
|
||||
$return[] = $i;
|
||||
unset($i);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purchases a Reserved Instance for use with your account. With Amazon EC2
|
||||
* Reserved Instances, you purchase the right to launch Amazon EC2 instances
|
||||
* for a period of time (without getting insufficient capacity errors) and
|
||||
* pay a lower usage rate for the actual time used.
|
||||
*
|
||||
* @param string $offeringId The offering ID of the Reserved Instance to purchase
|
||||
* @param integer $intanceCount The number of Reserved Instances to purchase.
|
||||
* @return string The ID of the purchased Reserved Instances.
|
||||
*/
|
||||
public function purchaseOffering($offeringId, $intanceCount = 1)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'PurchaseReservedInstancesOffering';
|
||||
$params['OfferingId.1'] = $offeringId;
|
||||
$params['instanceCount.1'] = intval($intanceCount);
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$reservedInstancesId = $xpath->evaluate('string(//ec2:reservedInstancesId/text())');
|
||||
|
||||
return $reservedInstancesId;
|
||||
}
|
||||
}
|
192
libs/Zend/Service/Amazon/Ec2/Instance/Windows.php
Normal file
192
libs/Zend/Service/Amazon/Ec2/Instance/Windows.php
Normal file
@ -0,0 +1,192 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Windows.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* Zend_Crypt_Hmac
|
||||
*/
|
||||
require_once 'Zend/Crypt/Hmac.php';
|
||||
|
||||
/**
|
||||
* Zend_Json
|
||||
*/
|
||||
require_once 'Zend/Json.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface that allows yout to run, terminate, reboot and describe Amazon
|
||||
* Ec2 Instances.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Instance_Windows extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Bundles an Amazon EC2 instance running Windows
|
||||
*
|
||||
* @param string $instanceId The instance you want to bundle
|
||||
* @param string $s3Bucket Where you want the ami to live on S3
|
||||
* @param string $s3Prefix The prefix you want to assign to the AMI on S3
|
||||
* @param integer $uploadExpiration The expiration of the upload policy. Amazon recommends 12 hours or longer.
|
||||
* This is based in nubmer of minutes. Default is 1440 minutes (24 hours)
|
||||
* @return array containing the information on the new bundle operation
|
||||
*/
|
||||
public function bundle($instanceId, $s3Bucket, $s3Prefix, $uploadExpiration = 1440)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'BundleInstance';
|
||||
$params['InstanceId'] = $instanceId;
|
||||
$params['Storage.S3.AWSAccessKeyId'] = $this->_getAccessKey();
|
||||
$params['Storage.S3.Bucket'] = $s3Bucket;
|
||||
$params['Storage.S3.Prefix'] = $s3Prefix;
|
||||
$uploadPolicy = $this->_getS3UploadPolicy($s3Bucket, $s3Prefix, $uploadExpiration);
|
||||
$params['Storage.S3.UploadPolicy'] = $uploadPolicy;
|
||||
$params['Storage.S3.UploadPolicySignature'] = $this->_signS3UploadPolicy($uploadPolicy);
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['instanceId'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:instanceId/text())');
|
||||
$return['bundleId'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:bundleId/text())');
|
||||
$return['state'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:state/text())');
|
||||
$return['startTime'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:startTime/text())');
|
||||
$return['updateTime'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:updateTime/text())');
|
||||
$return['progress'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:progress/text())');
|
||||
$return['storage']['s3']['bucket'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:storage/ec2:S3/ec2:bucket/text())');
|
||||
$return['storage']['s3']['prefix'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:storage/ec2:S3/ec2:prefix/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels an Amazon EC2 bundling operation
|
||||
*
|
||||
* @param string $bundleId The ID of the bundle task to cancel
|
||||
* @return array Information on the bundle task
|
||||
*/
|
||||
public function cancelBundle($bundleId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'CancelBundleTask';
|
||||
$params['BundleId'] = $bundleId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['instanceId'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:instanceId/text())');
|
||||
$return['bundleId'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:bundleId/text())');
|
||||
$return['state'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:state/text())');
|
||||
$return['startTime'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:startTime/text())');
|
||||
$return['updateTime'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:updateTime/text())');
|
||||
$return['progress'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:progress/text())');
|
||||
$return['storage']['s3']['bucket'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:storage/ec2:S3/ec2:bucket/text())');
|
||||
$return['storage']['s3']['prefix'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:storage/ec2:S3/ec2:prefix/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes current bundling tasks
|
||||
*
|
||||
* @param string|array $bundleId A single or a list of bundle tasks that you want
|
||||
* to find information for.
|
||||
* @return array Information for the task that you requested
|
||||
*/
|
||||
public function describeBundle($bundleId = '')
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeBundleTasks';
|
||||
|
||||
if(is_array($bundleId) && !empty($bundleId)) {
|
||||
foreach($bundleId as $k=>$name) {
|
||||
$params['bundleId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif(!empty($bundleId)) {
|
||||
$params['bundleId.1'] = $bundleId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$items = $xpath->evaluate('//ec2:bundleInstanceTasksSet/ec2:item');
|
||||
$return = array();
|
||||
|
||||
foreach($items as $item) {
|
||||
$i = array();
|
||||
$i['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $item);
|
||||
$i['bundleId'] = $xpath->evaluate('string(ec2:bundleId/text())', $item);
|
||||
$i['state'] = $xpath->evaluate('string(ec2:state/text())', $item);
|
||||
$i['startTime'] = $xpath->evaluate('string(ec2:startTime/text())', $item);
|
||||
$i['updateTime'] = $xpath->evaluate('string(ec2:updateTime/text())', $item);
|
||||
$i['progress'] = $xpath->evaluate('string(ec2:progress/text())', $item);
|
||||
$i['storage']['s3']['bucket'] = $xpath->evaluate('string(ec2:storage/ec2:S3/ec2:bucket/text())', $item);
|
||||
$i['storage']['s3']['prefix'] = $xpath->evaluate('string(ec2:storage/ec2:S3/ec2:prefix/text())', $item);
|
||||
|
||||
$return[] = $i;
|
||||
unset($i);
|
||||
}
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the S3 Upload Policy Information
|
||||
*
|
||||
* @param string $bucketName Which bucket you want the ami to live in on S3
|
||||
* @param string $prefix The prefix you want to assign to the AMI on S3
|
||||
* @param integer $expireInMinutes The expiration of the upload policy. Amazon recommends 12 hours or longer.
|
||||
* This is based in nubmer of minutes. Default is 1440 minutes (24 hours)
|
||||
* @return string Base64 encoded string that is the upload policy
|
||||
*/
|
||||
protected function _getS3UploadPolicy($bucketName, $prefix, $expireInMinutes = 1440)
|
||||
{
|
||||
$arrParams = array();
|
||||
$arrParams['expiration'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", (time() + ($expireInMinutes * 60)));
|
||||
$arrParams['conditions'][] = array('bucket' => $bucketName);
|
||||
$arrParams['conditions'][] = array('acl' => 'ec2-bundle-read');
|
||||
$arrParams['conditions'][] = array('starts-with', '$key', $prefix);
|
||||
|
||||
return base64_encode(Zend_Json::encode($arrParams));
|
||||
}
|
||||
|
||||
/**
|
||||
* Signed S3 Upload Policy
|
||||
*
|
||||
* @param string $policy Base64 Encoded string that is the upload policy
|
||||
* @return string SHA1 encoded S3 Upload Policy
|
||||
*/
|
||||
protected function _signS3UploadPolicy($policy)
|
||||
{
|
||||
$hmac = Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'SHA1', $policy, Zend_Crypt_Hmac::BINARY);
|
||||
return $hmac;
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Keypair.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
@ -28,7 +28,7 @@ require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Keypair extends Zend_Service_Amazon_Ec2_Abstract
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Region.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
@ -27,7 +27,7 @@ require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Region extends Zend_Service_Amazon_Ec2_Abstract
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Response.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Http/Response.php';
|
||||
@ -33,7 +33,7 @@ class Zend_Service_Amazon_Ec2_Response {
|
||||
/**
|
||||
* XML namespace used for EC2 responses.
|
||||
*/
|
||||
const XML_NAMESPACE = 'http://ec2.amazonaws.com/doc/2008-12-01/';
|
||||
protected $_xmlNamespace = 'http://ec2.amazonaws.com/doc/2009-04-04/';
|
||||
|
||||
/**
|
||||
* The original HTTP response
|
||||
@ -96,7 +96,7 @@ class Zend_Service_Amazon_Ec2_Response {
|
||||
} else {
|
||||
$this->_xpath = new DOMXPath($document);
|
||||
$this->_xpath->registerNamespace('ec2',
|
||||
self::XML_NAMESPACE);
|
||||
$this->getNamespace());
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,4 +136,25 @@ class Zend_Service_Amazon_Ec2_Response {
|
||||
|
||||
return $this->_document;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current set XML Namespace.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->_xmlNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new XML Namespace
|
||||
*
|
||||
* @param string $namespace
|
||||
*/
|
||||
public function setNamespace($namespace)
|
||||
{
|
||||
$this->_xmlNamespace = $namespace;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
* @version $Id: Securitygroups.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
@ -28,7 +28,7 @@ require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Securitygroups extends Zend_Service_Amazon_Ec2_Abstract
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: EditorialReview.php 12662 2008-11-15 15:29:58Z beberlei $
|
||||
* @version $Id: EditorialReview.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_EditorialReview
|
||||
|
@ -15,9 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Exception.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -28,7 +28,7 @@ require_once 'Zend/Service/Exception.php';
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Exception extends Zend_Service_Exception
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Image.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Image.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Image
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Item.php 12666 2008-11-15 16:41:02Z beberlei $
|
||||
* @version $Id: Item.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Item
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ListmaniaList.php 12662 2008-11-15 15:29:58Z beberlei $
|
||||
* @version $Id: ListmaniaList.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_ListmaniaList
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Offer.php 14534 2009-03-30 11:14:53Z yoshida@zend.co.jp $
|
||||
* @version $Id: Offer.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Offer
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: OfferSet.php 12662 2008-11-15 15:29:58Z beberlei $
|
||||
* @version $Id: OfferSet.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_OfferSet
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Query.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Query.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ require_once 'Zend/Service/Amazon.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Query extends Zend_Service_Amazon
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ResultSet.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: ResultSet.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ require_once 'Zend/Service/Amazon/Item.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_ResultSet implements SeekableIterator
|
||||
|
@ -15,9 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon_S3
|
||||
* @copyright Copyright (c) 2009, Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: S3.php 14190 2009-02-28 04:32:18Z jplock $
|
||||
* @version $Id: S3.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -36,9 +36,9 @@ require_once 'Zend/Crypt/Hmac.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon_S3
|
||||
* @copyright Copyright (c) 2005-2008, Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/
|
||||
* @see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/
|
||||
*/
|
||||
class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
|
||||
{
|
||||
@ -48,13 +48,14 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
|
||||
* @var array
|
||||
*/
|
||||
protected static $_wrapperClients = array();
|
||||
/**
|
||||
* Endpoint for the service
|
||||
*
|
||||
* @var Zend_Uri_Http
|
||||
*/
|
||||
protected $_endpoint;
|
||||
|
||||
|
||||
/**
|
||||
* Endpoint for the service
|
||||
*
|
||||
* @var Zend_Uri_Http
|
||||
*/
|
||||
protected $_endpoint;
|
||||
|
||||
const S3_ENDPOINT = 's3.amazonaws.com';
|
||||
|
||||
const S3_ACL_PRIVATE = 'private';
|
||||
@ -65,42 +66,53 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
|
||||
const S3_REQUESTPAY_HEADER = 'x-amz-request-payer';
|
||||
const S3_ACL_HEADER = 'x-amz-acl';
|
||||
const S3_CONTENT_TYPE_HEADER = 'Content-Type';
|
||||
|
||||
|
||||
/**
|
||||
* Set S3 endpoint to use
|
||||
*
|
||||
* @param string|Zend_Uri_Http $endpoint
|
||||
* @return Zend_Service_Amazon_S3
|
||||
*/
|
||||
public function setEndpoint($endpoint)
|
||||
public function setEndpoint($endpoint)
|
||||
{
|
||||
if(!($endpoint instanceof Zend_Uri_Http)) {
|
||||
$endpoint = Zend_Uri::factory($endpoint);
|
||||
}
|
||||
if(!$endpoint->valid()) {
|
||||
require_once 'Zend/Service/Amazon/S3/Exception.php';
|
||||
throw new Zend_Service_Amazon_S3_Exception("Invalid endpoint supplied");
|
||||
}
|
||||
$this->_endpoint = $endpoint;
|
||||
return $this;
|
||||
if (!($endpoint instanceof Zend_Uri_Http)) {
|
||||
$endpoint = Zend_Uri::factory($endpoint);
|
||||
}
|
||||
if (!$endpoint->valid()) {
|
||||
/**
|
||||
* @see Zend_Service_Amazon_S3_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/S3/Exception.php';
|
||||
throw new Zend_Service_Amazon_S3_Exception('Invalid endpoint supplied');
|
||||
}
|
||||
$this->_endpoint = $endpoint;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get current S3 endpoint
|
||||
*
|
||||
* @return Zend_Uri_Http
|
||||
*/
|
||||
public function getEndpoint()
|
||||
public function getEndpoint()
|
||||
{
|
||||
return $this->_endpoint;
|
||||
return $this->_endpoint;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $accessKey
|
||||
* @param string $secretKey
|
||||
* @param string $region
|
||||
*/
|
||||
public function __construct($accessKey=null, $secretKey=null, $region=null)
|
||||
{
|
||||
parent::__construct($accessKey, $secretKey, $region);
|
||||
$this->setEndpoint("http://".self::S3_ENDPOINT);
|
||||
parent::__construct($accessKey, $secretKey, $region);
|
||||
|
||||
$this->setEndpoint('http://'.self::S3_ENDPOINT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verify if the bucket name is valid
|
||||
*
|
||||
@ -133,10 +145,10 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
|
||||
require_once 'Zend/Service/Amazon/S3/Exception.php';
|
||||
throw new Zend_Service_Amazon_S3_Exception("Bucket name \"$bucket\" cannot be an IP address");
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add a new bucket
|
||||
*
|
||||
* @param string $bucket
|
||||
@ -144,19 +156,20 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
|
||||
*/
|
||||
public function createBucket($bucket, $location = null)
|
||||
{
|
||||
$this->_validBucketName($bucket);
|
||||
|
||||
$this->_validBucketName($bucket);
|
||||
|
||||
if($location) {
|
||||
$data = "<CreateBucketConfiguration><LocationConstraint>$location</LocationConstraint></CreateBucketConfiguration>";
|
||||
} else {
|
||||
$data = null;
|
||||
$data = '<CreateBucketConfiguration><LocationConstraint>'.$location.'</LocationConstraint></CreateBucketConfiguration>';
|
||||
}
|
||||
else {
|
||||
$data = null;
|
||||
}
|
||||
$response = $this->_makeRequest('PUT', $bucket, null, array(), $data);
|
||||
|
||||
return ($response->getStatus() == 200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Checks if a given bucket name is available
|
||||
*
|
||||
* @param string $bucket
|
||||
@ -295,6 +308,12 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the object name is valid
|
||||
*
|
||||
* @param string $object
|
||||
* @return string
|
||||
*/
|
||||
protected function _fixupObjectName($object)
|
||||
{
|
||||
$nameparts = explode('/', $object);
|
||||
@ -302,27 +321,28 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
|
||||
$this->_validBucketName($nameparts[0]);
|
||||
|
||||
$firstpart = array_shift($nameparts);
|
||||
if(count($nameparts) == 0) {
|
||||
if (count($nameparts) == 0) {
|
||||
return $firstpart;
|
||||
}
|
||||
|
||||
return $firstpart.'/'.join("/", array_map('rawurlencode',$nameparts));
|
||||
return $firstpart.'/'.join('/', array_map('rawurlencode', $nameparts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an object
|
||||
*
|
||||
* @param string $object
|
||||
* @param bool $paidobject This is "requestor pays" object
|
||||
* @param bool $paidobject This is "requestor pays" object
|
||||
* @return string|false
|
||||
*/
|
||||
public function getObject($object, $paidobject = false)
|
||||
public function getObject($object, $paidobject=false)
|
||||
{
|
||||
$object = $this->_fixupObjectName($object);
|
||||
if($paidobject) {
|
||||
$response = $this->_makeRequest('GET', $object, null, array(self::S3_REQUESTPAY_HEADER => "requester"));
|
||||
} else {
|
||||
$response = $this->_makeRequest('GET', $object);
|
||||
if ($paidobject) {
|
||||
$response = $this->_makeRequest('GET', $object, null, array(self::S3_REQUESTPAY_HEADER => 'requester'));
|
||||
}
|
||||
else {
|
||||
$response = $this->_makeRequest('GET', $object);
|
||||
}
|
||||
|
||||
if ($response->getStatus() != 200) {
|
||||
@ -435,24 +455,26 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
|
||||
// build the end point out
|
||||
$parts = explode('/', $path, 2);
|
||||
$endpoint = clone($this->_endpoint);
|
||||
if($parts[0]) {
|
||||
// prepend bucket name to the hostname
|
||||
$endpoint->setHost($parts[0].".".$endpoint->getHost());
|
||||
if ($parts[0]) {
|
||||
// prepend bucket name to the hostname
|
||||
$endpoint->setHost($parts[0].'.'.$endpoint->getHost());
|
||||
}
|
||||
if(!empty($parts[1])) {
|
||||
$endpoint->setPath('/'.$parts[1]);
|
||||
} else {
|
||||
$endpoint->setPath('/');
|
||||
if($parts[0]) {
|
||||
$path = $parts[0]."/";
|
||||
}
|
||||
if (!empty($parts[1])) {
|
||||
$endpoint->setPath('/'.$parts[1]);
|
||||
}
|
||||
|
||||
else {
|
||||
$endpoint->setPath('/');
|
||||
if ($parts[0]) {
|
||||
$path = $parts[0].'/';
|
||||
}
|
||||
}
|
||||
|
||||
self::addSignature($method, $path, $headers);
|
||||
|
||||
|
||||
$client = self::getHttpClient();
|
||||
|
||||
$client->resetParameters();
|
||||
$client->setAuth(false);
|
||||
// Work around buglet in HTTP client - it doesn't clean headers
|
||||
// Remove when ZHC is fixed
|
||||
$client->setHeaders(array('Content-MD5' => null,
|
||||
@ -460,7 +482,7 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
|
||||
'Range' => null,
|
||||
'x-amz-acl' => null));
|
||||
|
||||
$client->setUri($endpoint);
|
||||
$client->setUri($endpoint);
|
||||
$client->setHeaders($headers);
|
||||
|
||||
if (is_array($params)) {
|
||||
|
@ -15,9 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon_S3
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Exception.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ require_once 'Zend/Service/Amazon/Exception.php';
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_S3_Exception extends Zend_Service_Amazon_Exception
|
||||
|
@ -15,9 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon_S3
|
||||
* @copyright Copyright (c) 2005-2008, Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: S3.php 9786 2008-06-24 23:50:25Z jplock $
|
||||
* @version $Id: Stream.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -31,7 +31,7 @@ require_once 'Zend/Service/Amazon/S3.php';
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon_S3
|
||||
* @copyright Copyright (c) 2005-2008, Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_S3_Stream
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: SimilarProduct.php 12667 2008-11-15 16:51:39Z beberlei $
|
||||
* @version $Id: SimilarProduct.php 16211 2009-06-21 19:23:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_SimilarProduct
|
||||
|
436
libs/Zend/Service/Amazon/Sqs.php
Normal file
436
libs/Zend/Service/Amazon/Sqs.php
Normal file
@ -0,0 +1,436 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Service
|
||||
* @subpackage Amazon_Sqs
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Sqs.php 16590 2009-07-09 20:04:16Z matthew $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Hmac
|
||||
*/
|
||||
require_once 'Zend/Crypt/Hmac.php';
|
||||
|
||||
/**
|
||||
* Class for connecting to the Amazon Simple Queue Service (SQS)
|
||||
*
|
||||
* @category Zend
|
||||
* @package Service
|
||||
* @subpackage Amazon_Sqs
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see http://aws.amazon.com/sqs/ Amazon Simple Queue Service
|
||||
*/
|
||||
class Zend_Service_Amazon_Sqs extends Zend_Service_Amazon_Abstract
|
||||
{
|
||||
/**
|
||||
* Default timeout for createQueue() function
|
||||
*/
|
||||
const CREATE_TIMEOUT_DEFAULT = 30;
|
||||
|
||||
/**
|
||||
* HTTP end point for the Amazon SQS service
|
||||
*/
|
||||
protected $_sqsEndpoint = 'queue.amazonaws.com';
|
||||
|
||||
/**
|
||||
* The API version to use
|
||||
*/
|
||||
protected $_sqsApiVersion = '2009-02-01';
|
||||
|
||||
/**
|
||||
* Signature Version
|
||||
*/
|
||||
protected $_sqsSignatureVersion = '2';
|
||||
|
||||
/**
|
||||
* Signature Encoding Method
|
||||
*/
|
||||
protected $_sqsSignatureMethod = 'HmacSHA256';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $accessKey
|
||||
* @param string $secretKey
|
||||
* @param string $region
|
||||
*/
|
||||
public function __construct($accessKey = null, $secretKey = null, $region = null)
|
||||
{
|
||||
parent::__construct($accessKey, $secretKey, $region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new queue
|
||||
*
|
||||
* Visibility timeout is how long a message is left in the queue "invisible"
|
||||
* to other readers. If the message is acknowleged (deleted) before the
|
||||
* timeout, then the message is deleted. However, if the timeout expires
|
||||
* then the message will be made available to other queue readers.
|
||||
*
|
||||
* @param string $queue_name queue name
|
||||
* @param integer $timeout default visibility timeout
|
||||
* @return string|boolean
|
||||
* @throws Zend_Service_Amazon_Sqs_Exception
|
||||
*/
|
||||
public function create($queue_name, $timeout = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['QueueName'] = $queue_name;
|
||||
$timeout = ($timeout === null) ? self::CREATE_TIMEOUT_DEFAULT : (int)$timeout;
|
||||
$params['DefaultVisibilityTimeout'] = $timeout;
|
||||
|
||||
$retry_count = 0;
|
||||
|
||||
do {
|
||||
$retry = false;
|
||||
$result = $this->_makeRequest(null, 'CreateQueue', $params);
|
||||
|
||||
if ($result->CreateQueueResult->QueueUrl === null) {
|
||||
if ($result->Error->Code == 'AWS.SimpleQueueService.QueueNameExists') {
|
||||
return false;
|
||||
} elseif ($result->Error->Code == 'AWS.SimpleQueueService.QueueDeletedRecently') {
|
||||
// Must sleep for 60 seconds, then try re-creating the queue
|
||||
sleep(60);
|
||||
$retry = true;
|
||||
$retry_count++;
|
||||
} else {
|
||||
require_once 'Zend/Service/Amazon/Sqs/Exception.php';
|
||||
throw new Zend_Service_Amazon_Sqs_Exception($result->Error->Code);
|
||||
}
|
||||
} else {
|
||||
return (string) $result->CreateQueueResult->QueueUrl;
|
||||
}
|
||||
|
||||
} while ($retry);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a queue and all of it's messages
|
||||
*
|
||||
* Returns false if the queue is not found, true if the queue exists
|
||||
*
|
||||
* @param string $queue_url queue URL
|
||||
* @return boolean
|
||||
* @throws Zend_Service_Amazon_Sqs_Exception
|
||||
*/
|
||||
public function delete($queue_url)
|
||||
{
|
||||
$result = $this->_makeRequest($queue_url, 'DeleteQueue');
|
||||
|
||||
if ($result->Error->Code !== null) {
|
||||
require_once 'Zend/Service/Amazon/Sqs/Exception.php';
|
||||
throw new Zend_Service_Amazon_Sqs_Exception($result->Error->Code);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of all available queues
|
||||
*
|
||||
* @return array
|
||||
* @throws Zend_Service_Amazon_Sqs_Exception
|
||||
*/
|
||||
public function getQueues()
|
||||
{
|
||||
$result = $this->_makeRequest(null, 'ListQueues');
|
||||
|
||||
if ($result->ListQueuesResult->QueueUrl === null) {
|
||||
require_once 'Zend/Service/Amazon/Sqs/Exception.php';
|
||||
throw new Zend_Service_Amazon_Sqs_Exception($result->Error->Code);
|
||||
}
|
||||
|
||||
$queues = array();
|
||||
foreach ($result->ListQueuesResult->QueueUrl as $queue_url) {
|
||||
$queues[] = (string)$queue_url;
|
||||
}
|
||||
|
||||
return $queues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the approximate number of messages in the queue
|
||||
*
|
||||
* @param string $queue_url Queue URL
|
||||
* @return integer
|
||||
* @throws Zend_Service_Amazon_Sqs_Exception
|
||||
*/
|
||||
public function count($queue_url)
|
||||
{
|
||||
return (int)$this->getAttribute($queue_url, 'ApproximateNumberOfMessages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the queue
|
||||
*
|
||||
* @param string $queue_url Queue URL
|
||||
* @param string $message Message to send to the queue
|
||||
* @return string Message ID
|
||||
* @throws Zend_Service_Amazon_Sqs_Exception
|
||||
*/
|
||||
public function send($queue_url, $message)
|
||||
{
|
||||
$params = array();
|
||||
$params['MessageBody'] = urlencode($message);
|
||||
|
||||
$checksum = md5($params['MessageBody']);
|
||||
|
||||
$result = $this->_makeRequest($queue_url, 'SendMessage', $params);
|
||||
|
||||
if ($result->SendMessageResult->MessageId === null) {
|
||||
require_once 'Zend/Service/Amazon/Sqs/Exception.php';
|
||||
throw new Zend_Service_Amazon_Sqs_Exception($result->Error->Code);
|
||||
} else if ((string) $result->SendMessageResult->MD5OfMessageBody != $checksum) {
|
||||
require_once 'Zend/Service/Amazon/Sqs/Exception.php';
|
||||
throw new Zend_Service_Amazon_Sqs_Exception('MD5 of body does not match message sent');
|
||||
}
|
||||
|
||||
return (string) $result->SendMessageResult->MessageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get messages in the queue
|
||||
*
|
||||
* @param string $queue_url Queue name
|
||||
* @param integer $max_messages Maximum number of messages to return
|
||||
* @param integer $timeout Visibility timeout for these messages
|
||||
* @return array
|
||||
* @throws Zend_Service_Amazon_Sqs_Exception
|
||||
*/
|
||||
public function receive($queue_url, $max_messages = null, $timeout = null)
|
||||
{
|
||||
$params = array();
|
||||
|
||||
// If not set, the visibility timeout on the queue is used
|
||||
if ($timeout !== null) {
|
||||
$params['VisibilityTimeout'] = (int)$timeout;
|
||||
}
|
||||
|
||||
// SQS will default to only returning one message
|
||||
if ($max_messages !== null) {
|
||||
$params['MaxNumberOfMessages'] = (int)$max_messages;
|
||||
}
|
||||
|
||||
$result = $this->_makeRequest($queue_url, 'ReceiveMessage', $params);
|
||||
|
||||
if ($result->ReceiveMessageResult->Message === null) {
|
||||
require_once 'Zend/Service/Amazon/Sqs/Exception.php';
|
||||
throw new Zend_Service_Amazon_Sqs_Exception($result->Error->Code);
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($result->ReceiveMessageResult->Message as $message) {
|
||||
$data[] = array(
|
||||
'message_id' => (string)$message->MessageId,
|
||||
'handle' => (string)$message->ReceiptHandle,
|
||||
'md5' => (string)$message->MD5OfBody,
|
||||
'body' => urldecode((string)$message->Body),
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a message from the queue
|
||||
*
|
||||
* Returns true if the message is deleted, false if the deletion is
|
||||
* unsuccessful.
|
||||
*
|
||||
* @param string $queue_url Queue URL
|
||||
* @param string $handle Message handle as returned by SQS
|
||||
* @return boolean
|
||||
* @throws Zend_Service_Amazon_Sqs_Exception
|
||||
*/
|
||||
public function deleteMessage($queue_url, $handle)
|
||||
{
|
||||
$params = array();
|
||||
$params['ReceiptHandle'] = (string)$handle;
|
||||
|
||||
$result = $this->_makeRequest($queue_url, 'DeleteMessage', $params);
|
||||
|
||||
if ($result->Error->Code !== null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Will always return true unless ReceiptHandle is malformed
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes for the queue
|
||||
*
|
||||
* @param string $queue_url Queue URL
|
||||
* @param string $attribute
|
||||
* @return string
|
||||
* @throws Zend_Service_Amazon_Sqs_Exception
|
||||
*/
|
||||
public function getAttribute($queue_url, $attribute = 'All')
|
||||
{
|
||||
$params = array();
|
||||
$params['AttributeName'] = $attribute;
|
||||
|
||||
$result = $this->_makeRequest($queue_url, 'GetQueueAttributes', $params);
|
||||
|
||||
if ($result->GetQueueAttributesResult->Attribute === null) {
|
||||
require_once 'Zend/Service/Amazon/Sqs/Exception.php';
|
||||
throw new Zend_Service_Amazon_Sqs_Exception($result->Error->Code);
|
||||
}
|
||||
|
||||
return (string) $result->GetQueueAttributesResult->Attribute->Value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a request to Amazon SQS
|
||||
*
|
||||
* @param string $queue Queue Name
|
||||
* @param string $action SQS action
|
||||
* @param array $params
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
private function _makeRequest($queue_url, $action, $params = array())
|
||||
{
|
||||
$params['Action'] = $action;
|
||||
$params = $this->addRequiredParameters($queue_url, $params);
|
||||
|
||||
if ($queue_url === null) {
|
||||
$queue_url = '/';
|
||||
}
|
||||
|
||||
$client = self::getHttpClient();
|
||||
|
||||
switch ($action) {
|
||||
case 'ListQueues':
|
||||
case 'CreateQueue':
|
||||
$client->setUri('http://'.$this->_sqsEndpoint);
|
||||
break;
|
||||
default:
|
||||
$client->setUri($queue_url);
|
||||
break;
|
||||
}
|
||||
|
||||
$retry_count = 0;
|
||||
|
||||
do {
|
||||
$retry = false;
|
||||
|
||||
$client->resetParameters();
|
||||
$client->setParameterGet($params);
|
||||
|
||||
$response = $client->request('GET');
|
||||
|
||||
$response_code = $response->getStatus();
|
||||
|
||||
// Some 5xx errors are expected, so retry automatically
|
||||
if ($response_code >= 500 && $response_code < 600 && $retry_count <= 5) {
|
||||
$retry = true;
|
||||
$retry_count++;
|
||||
sleep($retry_count / 4 * $retry_count);
|
||||
}
|
||||
} while ($retry);
|
||||
|
||||
unset($client);
|
||||
|
||||
return new SimpleXMLElement($response->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds required authentication and version parameters to an array of
|
||||
* parameters
|
||||
*
|
||||
* The required parameters are:
|
||||
* - AWSAccessKey
|
||||
* - SignatureVersion
|
||||
* - Timestamp
|
||||
* - Version and
|
||||
* - Signature
|
||||
*
|
||||
* If a required parameter is already set in the <tt>$parameters</tt> array,
|
||||
* it is overwritten.
|
||||
*
|
||||
* @param string $queue_url Queue URL
|
||||
* @param array $parameters the array to which to add the required
|
||||
* parameters.
|
||||
* @return array
|
||||
*/
|
||||
protected function addRequiredParameters($queue_url, array $parameters)
|
||||
{
|
||||
$parameters['AWSAccessKeyId'] = $this->_getAccessKey();
|
||||
$parameters['SignatureVersion'] = $this->_sqsSignatureVersion;
|
||||
$parameters['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z', time()+10);
|
||||
$parameters['Version'] = $this->_sqsApiVersion;
|
||||
$parameters['SignatureMethod'] = $this->_sqsSignatureMethod;
|
||||
$parameters['Signature'] = $this->_signParameters($queue_url, $parameters);
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the RFC 2104-compliant HMAC signature for request parameters
|
||||
*
|
||||
* This implements the Amazon Web Services signature, as per the following
|
||||
* specification:
|
||||
*
|
||||
* 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
|
||||
* excluding <tt>Signature</tt>, the value of which is being created),
|
||||
* ignoring case.
|
||||
*
|
||||
* 2. Iterate over the sorted list and append the parameter name (in its
|
||||
* original case) and then its value. Do not URL-encode the parameter
|
||||
* values before constructing this string. Do not use any separator
|
||||
* characters when appending strings.
|
||||
*
|
||||
* @param string $queue_url Queue URL
|
||||
* @param array $parameters the parameters for which to get the signature.
|
||||
*
|
||||
* @return string the signed data.
|
||||
*/
|
||||
protected function _signParameters($queue_url, array $paramaters)
|
||||
{
|
||||
$data = "GET\n";
|
||||
$data .= $this->_sqsEndpoint . "\n";
|
||||
if ($queue_url !== null) {
|
||||
$data .= parse_url($queue_url, PHP_URL_PATH);
|
||||
}
|
||||
else {
|
||||
$data .= '/';
|
||||
}
|
||||
$data .= "\n";
|
||||
|
||||
uksort($paramaters, 'strcmp');
|
||||
unset($paramaters['Signature']);
|
||||
|
||||
$arrData = array();
|
||||
foreach($paramaters as $key => $value) {
|
||||
$arrData[] = $key . '=' . str_replace('%7E', '~', urlencode($value));
|
||||
}
|
||||
|
||||
$data .= implode('&', $arrData);
|
||||
|
||||
$hmac = Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'SHA256', $data, Zend_Crypt_Hmac::BINARY);
|
||||
|
||||
return base64_encode($hmac);
|
||||
}
|
||||
}
|
38
libs/Zend/Service/Amazon/Sqs/Exception.php
Normal file
38
libs/Zend/Service/Amazon/Sqs/Exception.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon_Sqs
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Service_Amazon/Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon_Sqs
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Sqs_Exception extends Zend_Service_Amazon_Exception
|
||||
{}
|
Reference in New Issue
Block a user