Overview

Namespaces

  • None
  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Exceptions
      • Log
      • Request
        • Response
    • Compute
    • Database
    • DNS
    • LoadBalancer
      • Resources
    • ObjectStore
      • Resource
    • Orchestration
    • Volume
  • PHP

Classes

  • AbstractResource
  • Group
  • GroupConfiguration
  • LaunchConfiguration
  • ScalingPolicy
  • Webhook
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
  1: <?php
  2: /**
  3:  * PHP OpenCloud library.
  4:  * 
  5:  * @copyright Copyright 2013 Rackspace US, Inc. See COPYING for licensing information.
  6:  * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
  7:  * @version   1.6.0
  8:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
  9:  */
 10: 
 11: namespace OpenCloud\Autoscale\Resource;
 12: 
 13: use OpenCloud\Common\Exceptions;
 14: 
 15: /**
 16:  * An autoscaling group is monitored by Rackspace Cloud Monitoring. When 
 17:  * Monitoring triggers an alarm for high utilization within the autoscaling 
 18:  * group, a webhook is triggered. The webhook stimulates the autoscale service 
 19:  * which consults a policy in accordance with the webhook. The policy determines 
 20:  * how many additional cloud servers should be added or removed in accordance 
 21:  * with the alarm.
 22:  * 
 23:  * There are three components to Autoscale:
 24:  * 
 25:  * - The Scaling Group Configuration ($this->groupConfiguration)
 26:  * - The Scaling Group's Launch Configuration ($this->launchConfiguration)
 27:  * - The Scaling Group's Policies ($this->scalingPolicies)
 28:  * 
 29:  * @link https://github.com/rackerlabs/otter/blob/master/doc/getting_started.rst
 30:  * @link http://docs.autoscale.apiary.io/
 31:  */
 32: class Group extends AbstractResource
 33: {
 34:     
 35:     public $id;
 36:     public $links;
 37:     public $groupConfiguration;
 38:     public $launchConfiguration;
 39:     public $scalingPolicies;
 40:     public $name;
 41:     public $metadata;
 42:     
 43:     public $active;
 44:     public $activeCapacity;
 45:     public $pendingCapacity;
 46:     public $desiredCapacity;
 47:     public $paused;
 48:     
 49:     protected static $json_name = 'group';
 50:     protected static $url_resource = 'groups';
 51:     protected static $json_collection_name = 'groups';
 52:     
 53:     /**
 54:      * {@inheritDoc}
 55:      */
 56:     public $createKeys = array(
 57:         'groupConfiguration',
 58:         'launchConfiguration',
 59:         'scalingPolicies'
 60:     );
 61:     
 62:     /**
 63:      * {@inheritDoc}
 64:      */
 65:     public $associatedResources = array(
 66:         'groupConfiguration'  => 'GroupConfiguration',
 67:         'launchConfiguration' => 'LaunchConfiguration',
 68:         
 69:     );
 70:     
 71:     /**
 72:      * {@inheritDoc}
 73:      */
 74:     public $associatedCollections = array(
 75:         'scalingPolicies' => 'ScalingPolicy'
 76:     );
 77:     
 78:     /**
 79:      * {@inheritDoc}
 80:      */
 81:     public function create($params = array())
 82:     {
 83:         if (is_string($params)) {
 84:             $params = json_decode($params);
 85:             $this->checkJsonError();
 86:         } elseif (!is_object($params) && !is_array($params)) {
 87:             throw new Exceptions\InvalidArgumentError(
 88:                 'You must provide either a string or an array/object'
 89:             );
 90:         }
 91: 
 92:         $this->populate($params, false);
 93:         
 94:         return parent::create();
 95:     }
 96:     
 97:     /**
 98:      * {@inheritDoc}
 99:      */
100:     public function update($params = array())
101:     {
102:         return $this->noUpdate();
103:     }
104:     
105:     /**
106:      * Get the current state of the scaling group, including the current set of 
107:      * active entities, the number of pending entities, and the desired number 
108:      * of entities.
109:      * 
110:      * @return object|boolean
111:      * @throws Exceptions\HttpError
112:      * @throws Exceptions\ServerActionError
113:      */
114:     public function getState()
115:     {
116:         $object = $this->customAction($this->url('state', true));
117:         
118:         return (!empty($object->group)) ? $object->group : false;
119:     }
120:     
121:     /**
122:      * Get the group configuration for this autoscale group.
123:      * 
124:      * @return GroupConfiguration
125:      */
126:     public function getGroupConfig()
127:     {
128:         if ($this->groupConfiguration instanceof GroupConfiguration) {
129:             return $this->groupConfiguration;
130:         }
131:         
132:         $config = $this->getService()->resource('GroupConfiguration');
133:         $config->setParent($this);
134:         if ($this->id) {
135:             $config->refresh(null, $config->url());
136:         }
137:         return $config;
138:     }
139:     
140:     /**
141:      * Get the launch configuration for this autoscale group.
142:      * 
143:      * @return LaunchConfiguration
144:      */
145:     public function getLaunchConfig()
146:     {
147:         if ($this->launchConfiguration instanceof LaunchConfiguration) {
148:             return $this->launchConfiguration;
149:         }
150:         
151:         $config = $this->getService()->resource('LaunchConfiguration');
152:         $config->setParent($this);
153:         if ($this->id) {
154:             $config->refresh(null, $config->url());
155:         }
156:         return $config;
157:     }
158:     
159:     /**
160:      * NB: NOT SUPPORTED YET.
161:      * 
162:      * @codeCoverageIgnore
163:      */
164:     public function pause()
165:     {
166:         return $this->customAction($this->url('pause', true), 'POST');
167:     }
168:     
169:     /**
170:      * NB: NOT SUPPORTED YET.
171:      * 
172:      * @codeCoverageIgnore
173:      */
174:     public function resume()
175:     {
176:         return $this->customAction($this->url('resume', true), 'POST');
177:     }
178:     
179:     /**
180:      * Get the scaling policies associated with this autoscale group.
181:      * 
182:      * @return Collection
183:      */
184:     public function getPolicies()
185:     {
186:         return $this->service()->resourceList('ScalingPolicy', null, $this);
187:     }
188:     
189:     /**
190:      * Get a particular scaling policy for this autoscale group.
191:      * 
192:      * @param  object|int $id
193:      * @return ScalingPolicy
194:      */
195:     public function getPolicy($id = null)
196:     {
197:         $config = $this->getService()->resource('ScalingPolicy');
198:         $config->setParent($this);
199:         if ($id) {
200:             $config->populate($id);
201:         }
202:         return $config;
203:     }
204:     
205: }
PHP OpenCloud API API documentation generated by ApiGen 2.8.0