Since: 5.11.9 (05.02.2016)
Author: Andrii Penchuk (a.penchuk@scalr.com)
Inheritance: extends Scalr\Api\DataType\ApiEntityAdapter
コード例 #1
0
ファイル: ScalingRuleAdapter.php プロジェクト: scalr/scalr
 public function _name($from, $to, $action)
 {
     switch ($action) {
         case static::ACT_CONVERT_TO_OBJECT:
             /* @var $from Entity\FarmRoleScalingMetric */
             $to->name = ScalingMetricAdapter::metricNameToData($from->metric->name);
             break;
         case static::ACT_CONVERT_TO_ENTITY:
             $this->validateString($from->name, 'Property name contains invalid characters');
             /* @var $metric Entity\ScalingMetric */
             $metric = Entity\ScalingMetric::findOne([['name' => ScalingMetricAdapter::metricNameToEntity($from->name)]]);
             if (empty($metric)) {
                 throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, sprintf('Scaling metric with name %s does not exist', $from->name));
             }
             /* @var $to Entity\FarmRoleScalingMetric */
             $to->metricId = $metric->id;
             $to->metric = $metric;
             break;
         case static::ACT_GET_FILTER_CRITERIA:
             return [[]];
     }
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  * @see ScalingRuleAdapter::validateEntity()
  */
 public function validateEntity($entity)
 {
     parent::validateEntity($entity);
     if (!$entity->getFarmRole()->getRole()->isScalarized) {
         throw new ApiErrorException(409, ErrorMessage::ERR_CONFIGURATION_MISMATCH, sprintf('Can not add %s Scaling metric to the agentless Role', ScalingMetricAdapter::metricNameToData($entity->metric->name)));
     }
     $criteria[] = ['farmRoleId' => $entity->farmRoleId];
     $criteria[] = ['metricId' => ScalingMetric::METRIC_DATE_AND_TIME_ID];
     if (!empty(FarmRoleScalingMetric::findOne($criteria))) {
         throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, 'DateAndTime metric cannot be used with others');
     }
     $settings = $entity->settings;
     if ($entity->metric->isInvert) {
         $this->validateNumericSetting($settings, FarmRoleScalingMetric::MIN, 'scaleUp');
         $this->validateNumericSetting($settings, FarmRoleScalingMetric::MAX, 'scaleDown');
     } else {
         $this->validateNumericSetting($settings, FarmRoleScalingMetric::MIN, 'scaleDown');
         $this->validateNumericSetting($settings, FarmRoleScalingMetric::MAX, 'scaleUp');
     }
     if ($entity->metricId != ScalingMetric::METRIC_SQS_QUEUE_SIZE_ID && $entity->settings[FarmRoleScalingMetric::MIN] >= $entity->settings[FarmRoleScalingMetric::MAX]) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, sprintf('Scale up value must be %s than Scale down value', $entity->metric->isInvert ? 'less' : 'greater'));
     }
 }
コード例 #3
0
ファイル: FarmRoles.php プロジェクト: scalr/scalr
 /**
  * Gets specified farm role scaling metric entity
  *
  * @param int    $farmRoleId      Unique farm-role identifier
  * @param string $scalingRuleName Scaling metric's name.
  * @param bool   $modify          optional Flag checking write permissions
  * @return FarmRoleScalingMetric
  * @throws ApiErrorException
  */
 public function getScalingRule($farmRoleId, $scalingRuleName, $modify = false)
 {
     $farmRole = $this->getFarmRole($farmRoleId, null, $modify);
     $scalingRuleName = ScalingMetricAdapter::metricNameToEntity($scalingRuleName);
     if (empty($farmRole->farmRoleMetrics[$scalingRuleName])) {
         throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, 'Requested Scaling Metric does not exist.');
     }
     return $farmRole->farmRoleMetrics[$scalingRuleName];
 }
コード例 #4
0
ファイル: FarmRoleAdapter.php プロジェクト: scalr/scalr
 /**
  * Gets scaling configuration data
  *
  * @param   FarmRole    $role FarmRole entity
  *
  * @return array ScalingConfiguration representation
  *
  * @see <need link to public API documentation>
  */
 public static function getScalingConfiguration(FarmRole $role)
 {
     $configuration = [];
     if (!empty($role->settings[FarmRoleSetting::SCALING_ENABLED])) {
         $configuration['enabled'] = !!$role->settings[FarmRoleSetting::SCALING_ENABLED];
     }
     if (!empty($role->settings[FarmRoleSetting::SCALING_MIN_INSTANCES])) {
         $configuration['minInstances'] = $role->settings[FarmRoleSetting::SCALING_MIN_INSTANCES];
     }
     if (!empty($role->settings[FarmRoleSetting::SCALING_MAX_INSTANCES])) {
         $configuration['maxInstances'] = $role->settings[FarmRoleSetting::SCALING_MAX_INSTANCES];
     }
     $configuration['rules'] = ScalingMetricAdapter::metricNameToData(FarmRole::listFarmRoleMetric($role->id));
     return $configuration;
 }