trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dang...@apache.org
Subject [1/2] incubator-trafficcontrol git commit: adds api/*/servers/status api endpoint to show a count of servers in each status. also fixed broken asn tests.
Date Fri, 12 May 2017 04:33:45 GMT
Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/master 4e35ed15e -> 0ecd27651


adds api/*/servers/status api endpoint to show a count of servers in each status. also fixed
broken asn tests.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/2cf7f464
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/2cf7f464
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/2cf7f464

Branch: refs/heads/master
Commit: 2cf7f46466869f4085a4547a34808f4af6373509
Parents: 4e35ed1
Author: Jeremy Mitchell <mitchell852@gmail.com>
Authored: Thu May 11 14:48:25 2017 -0600
Committer: Jeremy Mitchell <mitchell852@gmail.com>
Committed: Thu May 11 14:48:25 2017 -0600

----------------------------------------------------------------------
 .../development/traffic_ops_api/v12/server.rst  | 45 +++++++++++++++++++-
 traffic_ops/app/lib/API/Server.pm               | 21 +++++++++
 traffic_ops/app/lib/TrafficOpsRoutes.pm         |  5 ++-
 traffic_ops/app/t/api/1.1/asn.t                 | 12 +++---
 traffic_ops/app/t/api/1.2/server.t              |  5 +++
 5 files changed, 80 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2cf7f464/docs/source/development/traffic_ops_api/v12/server.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/server.rst b/docs/source/development/traffic_ops_api/v12/server.rst
index d49fc75..0296e30 100644
--- a/docs/source/development/traffic_ops_api/v12/server.rst
+++ b/docs/source/development/traffic_ops_api/v12/server.rst
@@ -576,7 +576,7 @@ Server
 |
 
 
-**GET /api/1.2/servers/summary**
+**GET /api/1.2/servers/totals**
 
   Retrieves a count of CDN servers by type.
 
@@ -622,6 +622,49 @@ Server
 
 |
 
+**GET /api/1.2/servers/status**
+
+  Retrieves a count of CDN servers by status.
+
+  Authentication Required: Yes
+
+  Role(s) Required: None
+
+  **Response Properties**
+
+  +-----------------+--------+-----------------------------------------------------------------------------------------------------------------------+
+  | Parameter       |  Type  |                             Description                  
                                                            |
+  +=================+========+=======================================================================================================================+
+  | ``ONLINE``      | int    | The number of ONLINE servers. Traffic Monitor will not monitor
the state of ONLINE servers. True health is unknown.   |
+  +-----------------+--------+-----------------------------------------------------------------------------------------------------------------------+
+  | ``REPORTED``    | int    | The number of REPORTED servers. Traffic Monitor monitors the
state of REPORTED servers and removes them if unhealthy. |
+  +-----------------+--------+-----------------------------------------------------------------------------------------------------------------------+
+  | ``OFFLINE``     | int    | The number of OFFLINE servers. Used for longer-term maintenance.
These servers are excluded from CRConfig.json.       |
+  +-----------------+--------+-----------------------------------------------------------------------------------------------------------------------+
+  | ``ADMIN_DOWN``  | int    | The number of ADMIN_DOWN servers. Used for short-term maintenance.
These servers are included in CRConfig.json.       |
+  +-----------------+--------+-----------------------------------------------------------------------------------------------------------------------+
+  | ``CCR_IGNORE``  | int    | The number of CCR_IGNORE servers. These servers are excluded
from CRConfig.json.                                      |
+  +-----------------+--------+-----------------------------------------------------------------------------------------------------------------------+
+  | ``PRE_PROD``    | int    | The number of PRE_PROD servers. Used for servers to be deployed.
These servers are excluded from CRConfig.json.       |
+  +-----------------+--------+-----------------------------------------------------------------------------------------------------------------------+
+
+  **Response Example** ::
+
+    {
+      "response":
+        {
+          "ONLINE": 100,
+          "OFFLINE": 23,
+          "REPORTED": 45,
+          "ADMIN_DOWN": 4,
+          "CCR_IGNORE": 1,
+          "PRE_PROD": 0,
+        }
+    }
+
+|
+
+
 **GET /api/1.2/servers/hostname/:name/details**
 
   Retrieves the details of a server.

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2cf7f464/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 a623913..a593553 100644
--- a/traffic_ops/app/lib/API/Server.pm
+++ b/traffic_ops/app/lib/API/Server.pm
@@ -621,6 +621,27 @@ sub totals {
 
 }
 
+sub status {
+	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;
+	while ( my $row = $rs->next ) {
+		$response->{ $row->{'_column_data'}->{'status_name'} } = $row->{'_column_data'}->{'server_count'};
+	}
+
+	return $self->success( $response );
+}
+
 sub get_count_by_type {
 	my $self      = shift;
 	my $type_name = shift;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2cf7f464/traffic_ops/app/lib/TrafficOpsRoutes.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/TrafficOpsRoutes.pm b/traffic_ops/app/lib/TrafficOpsRoutes.pm
index 72b1f85..e4fa69e 100644
--- a/traffic_ops/app/lib/TrafficOpsRoutes.pm
+++ b/traffic_ops/app/lib/TrafficOpsRoutes.pm
@@ -694,9 +694,12 @@ sub api_routes {
 	$r->get("/api/$version/servers/details")->over( authenticated => 1 )->to( 'Server#details',
namespace => $namespace );
 	$r->get("/api/$version/servers/hostname/:name/details")->over( authenticated =>
1 )->to( 'Server#details_v11', namespace => $namespace );
 
-	# -- SERVERS: TOTALS
+	# -- SERVERS: COUNT BY TYPE
 	$r->get("/api/$version/servers/totals")->over( authenticated => 1 )->to( 'Server#totals',
namespace => $namespace );
 
+	# -- SERVERS: COUNT BY STATUS
+	$r->get("/api/$version/servers/status")->over( authenticated => 1 )->to( 'Server#status',
namespace => $namespace );
+
 	# -- SERVERS: QUEUE/DEQUEUE SERVER UPDATES
 	$r->post("/api/$version/servers/:id/queue_update" => [ id => qr/\d+/ ] )->over(
authenticated => 1 )->to( 'Server#postupdatequeue', namespace => $namespace );
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2cf7f464/traffic_ops/app/t/api/1.1/asn.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.1/asn.t b/traffic_ops/app/t/api/1.1/asn.t
index 4d5c3c8..72bd698 100644
--- a/traffic_ops/app/t/api/1.1/asn.t
+++ b/traffic_ops/app/t/api/1.1/asn.t
@@ -40,15 +40,15 @@ Test::TestHelper->load_core_data($schema);
 ok $t->post_ok( '/login', => form => { u => Test::TestHelper::ADMIN_USER, p =>
Test::TestHelper::ADMIN_USER_PASSWORD } )->status_is(302)
 	->or( sub { diag $t->tx->res->content->asset->{content}; } );
 
-$t->get_ok("/api/1.1/asns")->status_is(200)->json_is( "/response/0/id", 100 )->json_is(
"/response/0/cachegroup", "mid-northeast-group" )
-	->json_is( "/response/0/asn", 9939 )->or( sub { diag $t->tx->res->content->asset->{content};
} );
+$t->get_ok("/api/1.1/asns")->status_is(200)->json_is( "/response/asns/0/id", 100
)->json_is( "/response/asns/0/cachegroup", "mid-northeast-group" )
+	->json_is( "/response/asns/0/asn", 9939 )->or( sub { diag $t->tx->res->content->asset->{content};
} );
 
-$t->get_ok("/api/1.1/asns?orderby=id")->status_is(200)->json_is( "/response/0/id",
100 )
-	->json_is( "/response/0/cachegroup", "mid-northeast-group" )->json_is( "/response/0/asn",
9939 )
+$t->get_ok("/api/1.1/asns?orderby=id")->status_is(200)->json_is( "/response/asns/0/id",
100 )
+	->json_is( "/response/asns/0/cachegroup", "mid-northeast-group" )->json_is( "/response/asns/0/asn",
9939 )
 	->or( sub { diag $t->tx->res->content->asset->{content}; } );
 
-$t->get_ok("/api/1.1/asns?orderby=cachegroup")->status_is(200)->json_is( "/response/0/id",
100 )
-	->json_is( "/response/0/cachegroup", "mid-northeast-group" )->json_is( "/response/0/asn",
9939 )
+$t->get_ok("/api/1.1/asns?orderby=cachegroup")->status_is(200)->json_is( "/response/asns/0/id",
100 )
+	->json_is( "/response/asns/0/cachegroup", "mid-northeast-group" )->json_is( "/response/asns/0/asn",
9939 )
 	->or( sub { diag $t->tx->res->content->asset->{content}; } );
 
 ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content};
} );

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2cf7f464/traffic_ops/app/t/api/1.2/server.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/server.t b/traffic_ops/app/t/api/1.2/server.t
index 2ae3f72..cedbfec 100644
--- a/traffic_ops/app/t/api/1.2/server.t
+++ b/traffic_ops/app/t/api/1.2/server.t
@@ -526,6 +526,11 @@ ok $t->put_ok('/api/1.2/servers/' . $server_id => {Accept =>
'application/json'}
 		->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};
} )
 	, 'Does the server update succeed because ip6Address is already used by the profile but...by
this server?';
 
+ok $t->get_ok('/api/1.2/servers/status')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};
} )
+		->json_is( "/response/ONLINE", 15 )
+		->json_is( "/response/REPORTED", 5 )
+		->or( sub { diag $t->tx->res->content->asset->{content}; } );
+
 ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content};
} );
 $dbh->disconnect();
 done_testing();


Mime
View raw message