metricNameToEntity() public static method

Get metrics name used in API to internal representation If metric name exist in nameMapping function will return changed name
public static metricNameToEntity ( string $name ) : string
$name string Metric's name
return string
Ejemplo n.º 1
0
 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 [[]];
     }
 }
Ejemplo n.º 2
0
 /**
  * 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];
 }