You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by el...@apache.org on 2018/06/14 17:31:31 UTC
[trafficcontrol] 04/05: Populate coordinates in the steering API
results
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit a79293473944f26793f584bf1c6e76d933c8e694
Author: Rawlin Peters <ra...@comcast.com>
AuthorDate: Wed May 23 15:48:31 2018 -0600
Populate coordinates in the steering API results
---
.../app/lib/API/DeliveryService/Steering.pm | 31 +++++++++++++++++++---
.../app/lib/API/DeliveryService/SteeringTarget.pm | 16 ++++++-----
traffic_ops/app/lib/UI/Steering.pm | 1 -
3 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/traffic_ops/app/lib/API/DeliveryService/Steering.pm b/traffic_ops/app/lib/API/DeliveryService/Steering.pm
index 002a95a..3c79615 100644
--- a/traffic_ops/app/lib/API/DeliveryService/Steering.pm
+++ b/traffic_ops/app/lib/API/DeliveryService/Steering.pm
@@ -105,22 +105,24 @@ sub find_steering {
});
}
elsif ( $row->type eq "STEERING_GEO_ORDER" ) {
+ my $coords = get_primary_origin_coordinates($self, $row->target_id);
push(@{$targets},{
'deliveryService' => $row->target_xml_id,
'order' => 0,
'geoOrder' => $row->value,
- 'latitude' => 0, # TODO: fill these in w/ the DeliveryService Origin lat/lon
- 'longitude' => 0,
+ 'latitude' => $coords->{lat},
+ 'longitude' => $coords->{lon},
'weight' => 0
});
}
elsif ( $row->type eq "STEERING_GEO_WEIGHT" ) {
+ my $coords = get_primary_origin_coordinates($self, $row->target_id);
push(@{$targets},{
'deliveryService' => $row->target_xml_id,
'order' => 0,
'geoOrder' => 0,
- 'latitude' => 0, # TODO: fill these in w/ the DeliveryService Origin lat/lon
- 'longitude' => 0,
+ 'latitude' => $coords->{lat},
+ 'longitude' => $coords->{lon},
'weight' => $row->value
});
}
@@ -145,6 +147,27 @@ sub find_steering {
return $response;
}
+sub get_primary_origin_coordinates {
+ my $self = shift;
+ my $ds_id = shift;
+
+ my %coordinates = (lat => 0.0, lon => 0.0);
+
+ my $origin_rs = $self->db->resultset('Origin')->find(
+ { deliveryservice => $ds_id, is_primary => 1 },
+ { prefetch => 'coordinate' });
+
+ if ( !defined($origin_rs) || !defined($origin_rs->coordinate) ) {
+ return \%coordinates;
+ }
+
+ $coordinates{lat} = $origin_rs->coordinate->latitude;
+ $coordinates{lon} = $origin_rs->coordinate->longitude;
+
+ return \%coordinates;
+}
+
+
sub get_ds_id {
my $self = shift;
my $xml_id = shift;
diff --git a/traffic_ops/app/lib/API/DeliveryService/SteeringTarget.pm b/traffic_ops/app/lib/API/DeliveryService/SteeringTarget.pm
index 88bdb15..8e0c5f3 100644
--- a/traffic_ops/app/lib/API/DeliveryService/SteeringTarget.pm
+++ b/traffic_ops/app/lib/API/DeliveryService/SteeringTarget.pm
@@ -308,15 +308,17 @@ sub is_target_valid {
# Validate the input against the rules
my $result = validate( $params, $rules );
- # TODO: fix indentation below, validate GEO-types
- if ( $result->{success} ) {
- if ( ( $target_type eq "STEERING_WEIGHT" ) and ( $params->{value} < 0 ) ) {
- return ( 0, "Invalid value for target type STEERING_WEIGHT: can not be negative" );
- }
- return ( 1, $result->{data} );
+ if ($result->{success}) {
+ if (($target_type eq "STEERING_WEIGHT") and ($params->{value} < 0)) {
+ return(0, "Invalid value for target type STEERING_WEIGHT: cannot be negative");
+ }
+ elsif (($target_type eq "STEERING_GEO_WEIGHT") and ($params->{value} < 0)) {
+ return(0, "Invalid value for target type STEERING_GEO_WEIGHT: cannot be negative");
+ }
+ return(1, $result->{data});
}
else {
- return ( 0, $result->{error} );
+ return(0, $result->{error});
}
}
diff --git a/traffic_ops/app/lib/UI/Steering.pm b/traffic_ops/app/lib/UI/Steering.pm
index a69b375..4bfc87d 100644
--- a/traffic_ops/app/lib/UI/Steering.pm
+++ b/traffic_ops/app/lib/UI/Steering.pm
@@ -112,7 +112,6 @@ sub get_target_data {
@weight_steering = sort { $b->{target_value} <=> $a->{target_value} } @weight_steering;
@neg_order_steering = sort { $a->{target_value} <=> $b->{target_value} } @neg_order_steering;
@pos_order_steering = sort { $a->{target_value} <=> $b->{target_value} } @pos_order_steering;
- # TODO: group geo_steering targets by Origin lat/lon
#push everything into an a single array - negative order values 1st, geo 2nd, weights 3rd, positive order last.
push (@steering, @neg_order_steering, @geo_steering, @weight_steering, @pos_order_steering);
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.