Since: 5.11.7 (25.01.2016)
Author: Andrii Penchuk (a.penchuk@scalr.com)
Inheritance: extends Scalr\Api\DataType\ApiEntityAdapter
Esempio n. 1
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'));
     }
 }
 /**
  * {@inheritdoc}
  * @see BasicScalingRuleAdapter::validateEntity()
  */
 public function validateEntity($entity)
 {
     parent::validateEntity($entity);
     if (!empty(Entity\FarmRoleScalingMetric::findOne([['farmRoleId' => $entity->farmRoleId], ['id' => ['$ne' => $entity->id]]]))) {
         throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, 'DateAndTime metric cannot be used with others');
     }
     if ($entity->settings->count() === 0) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, 'Missed property schedule');
     }
 }