You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2017/07/20 19:30:23 UTC
[1/2] incubator-trafficcontrol git commit: accounts for scenario
where no servers exist
Repository: incubator-trafficcontrol
Updated Branches:
refs/heads/master 64f61dde0 -> 10cf361b3
accounts for scenario where no servers exist
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/86d13014
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/86d13014
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/86d13014
Branch: refs/heads/master
Commit: 86d130141be4de19926e2a1b9e87a4e4e6927f31
Parents: 64f61dd
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Thu Jul 20 10:40:59 2017 -0600
Committer: David Neuman <da...@gmail.com>
Committed: Thu Jul 20 13:30:07 2017 -0600
----------------------------------------------------------------------
traffic_ops/app/lib/API/Server.pm | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/86d13014/traffic_ops/app/lib/API/Server.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Server.pm b/traffic_ops/app/lib/API/Server.pm
index 8423fa1..119af51 100644
--- a/traffic_ops/app/lib/API/Server.pm
+++ b/traffic_ops/app/lib/API/Server.pm
@@ -785,20 +785,29 @@ sub totals {
sub status_count {
my $self = shift;
-
- my $rs = $self->db->resultset('Server')->search(
- undef,
- {
- join => [qw/ status /],
- select => [ 'status.name', { count => 'me.id' } ],
- as => [qw/ status_name server_count /],
- group_by => [qw/ status.id /]
+ my $response = {};
+
+ my $server_count = $self->db->resultset('Server')->search()->count();
+ if ($server_count == 0) {
+ # if there are no servers, just return 0 for all statuses
+ my $statuses = $self->db->resultset('Status')->search();
+ while ( my $status = $statuses->next ) {
+ $response->{ $status->name } = 0;
}
- );
+ } else {
+ my $rs = $self->db->resultset('Server')->search(
+ undef,
+ {
+ join => [qw/ status /],
+ select => [ 'status.name', { count => 'me.id' } ],
+ as => [qw/ status_name server_count /],
+ group_by => [qw/ status.id /]
+ }
+ );
- my $response;
- while ( my $row = $rs->next ) {
- $response->{ $row->{'_column_data'}->{'status_name'} } = $row->{'_column_data'}->{'server_count'};
+ while ( my $row = $rs->next ) {
+ $response->{ $row->{'_column_data'}->{'status_name'} } = $row->{'_column_data'}->{'server_count'};
+ }
}
return $self->success( $response );
[2/2] incubator-trafficcontrol git commit: This closes #744
Posted by ne...@apache.org.
This closes #744
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/10cf361b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/10cf361b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/10cf361b
Branch: refs/heads/master
Commit: 10cf361b38ca9653c1c460f02ed908ec71f6f686
Parents: 86d1301
Author: David Neuman <da...@gmail.com>
Authored: Thu Jul 20 13:30:09 2017 -0600
Committer: David Neuman <da...@gmail.com>
Committed: Thu Jul 20 13:30:09 2017 -0600
----------------------------------------------------------------------
----------------------------------------------------------------------