Author: N.V.
Inheritance: extends Scalr\Api\DataType\ApiEntityAdapter
Ejemplo n.º 1
0
 /**
  * Add new scaling metric configuration for farm-role
  *
  * @param int $farmRoleId  Unique farm-role identifier
  * @return ResultEnvelope
  * @throws ApiErrorException
  * @throws ModelException
  */
 public function createScalingRuleAction($farmRoleId)
 {
     $farmRole = $this->getFarmRole($farmRoleId, null, true);
     $object = $this->request->getJsonBody();
     if (!is_object($object)) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Invalid body");
     }
     /* @var $scalingRuleAdapter ScalingRuleAdapter */
     $scalingRuleAdapter = $this->adapter($object);
     //Pre validates the request object
     $scalingRuleAdapter->validateObject($object, Request::METHOD_POST);
     /* @var $scalingRule FarmRoleScalingMetric */
     $scalingRule = $scalingRuleAdapter->toEntity($object);
     $scalingRule->farmRoleId = $farmRoleId;
     $scalingRuleAdapter->validateEntity($scalingRule);
     $scalingRule->save();
     //Responds with 201 Created status
     $this->response->setStatus(201);
     return $this->result(FarmRoleAdapter::getScalingConfiguration($farmRole));
 }
Ejemplo n.º 2
0
 /**
  * Change scaling configuration of farm-role
  *
  * @param   int $farmRoleId Unique farm-role identifier
  *
  * @return  ResultEnvelope
  * @throws  ApiErrorException
  */
 public function modifyScalingAction($farmRoleId)
 {
     $this->checkPermissions(Acl::RESOURCE_ROLES_ENVIRONMENT, Acl::PERM_ROLES_ENVIRONMENT_MANAGE);
     $role = $this->getFarmRole($farmRoleId, null, true);
     FarmRoleAdapter::setupScalingConfiguration($role, $this->request->getJsonBody());
     /* @var $farmRoleAdapter FarmRoleAdapter */
     $farmRoleAdapter = $this->adapter('farmRole');
     $farmRoleAdapter->validateEntity($role);
     $role->save();
     return $this->result(FarmRoleAdapter::getScalingConfiguration($role));
 }