You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2017/01/03 19:28:14 UTC

[04/13] incubator-trafficcontrol git commit: provides the ability to retrieve all edge servers by delivery service

provides the ability to retrieve all edge servers by delivery service


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

Branch: refs/heads/master
Commit: 9422ee6d4024432d7299a6cdf193cfd925284d35
Parents: 4899817
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Thu Dec 29 10:50:05 2016 -0700
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Thu Dec 29 10:50:05 2016 -0700

----------------------------------------------------------------------
 .../traffic_ops_api/v12/deliveryservice.rst     | 164 +++++++++++++++++++
 traffic_ops/app/lib/API/Server.pm               |  71 ++++++++
 traffic_ops/app/lib/TrafficOpsRoutes.pm         |   3 +
 3 files changed, 238 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9422ee6d/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/deliveryservice.rst b/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
index 75c26dd..27930c6 100644
--- a/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
+++ b/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
@@ -264,6 +264,14 @@ Delivery Service
 
   Role(s) Required: None
 
+  **Request Route Parameters**
+
+  +-----------------+----------+---------------------------------------------------+
+  | Name            | Required | Description                                       |
+  +=================+==========+===================================================+
+  | ``id``          | yes      | Delivery service ID.                              |
+  +-----------------+----------+---------------------------------------------------+
+
   **Response Properties**
 
   +--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
@@ -480,6 +488,162 @@ Delivery Service
 
 |
 
+**GET /api/1.2/deliveryservices/:id/servers**
+
+  Retrieves properties of CDN Edge servers assigned to a delivery service.
+
+  Authentication Required: Yes
+
+  Role(s) Required: None
+
+  **Request Route Parameters**
+
+  +-----------------+----------+---------------------------------------------------+
+  | Name            | Required | Description                                       |
+  +=================+==========+===================================================+
+  | ``id``          | yes      | Delivery service ID.                              |
+  +-----------------+----------+---------------------------------------------------+
+
+  **Response Properties**
+
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  |     Parameter      |  Type  |                                                Description                                                 |
+  +====================+========+============================================================================================================+
+  | ``cachegroup``     | string | The cache group name (see :ref:`to-api-v11-cachegroup`).                                                   |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``cachegroupId``   | string | The cache group id.                                                                                        |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``cdnId``          | string | Id of the CDN to which the server belongs to.                                                              |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``cdnName``        | string | Name of the CDN to which the server belongs to.                                                            |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``domainName``     | string | The domain name part of the FQDN of the cache.                                                             |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``guid``           | string | An identifier used to uniquely identify the server.                                                        |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``hostName``       | string | The host name part of the cache.                                                                           |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``httpsPort``      | string | The HTTPS port on which the main application listens (443 in most cases).                                  |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``id``             | string | The server id (database row number).                                                                       |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``iloIpAddress``   | string | The IPv4 address of the lights-out-management port.                                                        |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``iloIpGateway``   | string | The IPv4 gateway address of the lights-out-management port.                                                |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``iloIpNetmask``   | string | The IPv4 netmask of the lights-out-management port.                                                        |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``iloPassword``    | string | The password of the of the lights-out-management user (displays as ****** unless you are an 'admin' user). |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``iloUsername``    | string | The user name for lights-out-management.                                                                   |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``interfaceMtu``   | string | The Maximum Transmission Unit (MTU) to configure for ``interfaceName``.                                    |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``interfaceName``  | string | The network interface name used for serving traffic.                                                       |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``ip6Address``     | string | The IPv6 address/netmask for ``interfaceName``.                                                            |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``ip6Gateway``     | string | The IPv6 gateway for ``interfaceName``.                                                                    |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``ipAddress``      | string | The IPv4 address for ``interfaceName``.                                                                    |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``ipGateway``      | string | The IPv4 gateway for ``interfaceName``.                                                                    |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``ipNetmask``      | string | The IPv4 netmask for ``interfaceName``.                                                                    |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``lastUpdated``    | string | The Time and Date for the last update for this server.                                                     |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``mgmtIpAddress``  | string | The IPv4 address of the management port (optional).                                                        |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``mgmtIpGateway``  | string | The IPv4 gateway of the management port (optional).                                                        |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``mgmtIpNetmask``  | string | The IPv4 netmask of the management port (optional).                                                        |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``offlineReason``  | string | A user-entered reason why the server is in ADMIN_DOWN or OFFLINE status.                                   |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``physLocation``   | string | The physical location name (see :ref:`to-api-v11-phys-loc`).                                               |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``physLocationId`` | string | The physical location id (see :ref:`to-api-v11-phys-loc`).                                                 |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``profile``        | string | The assigned profile name (see :ref:`to-api-v11-profile`).                                                 |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``profileDesc``    | string | The assigned profile description (see :ref:`to-api-v11-profile`).                                          |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``profileId``      | string | The assigned profile Id (see :ref:`to-api-v11-profile`).                                                   |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``rack``           | string | A string indicating rack location.                                                                         |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``routerHostName`` | string | The human readable name of the router.                                                                     |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``routerPortName`` | string | The human readable name of the router port.                                                                |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``status``         | string | The Status string (See :ref:`to-api-v11-status`).                                                          |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``statusId``       | string | The Status id (See :ref:`to-api-v11-status`).                                                              |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``tcpPort``        | string | The default TCP port on which the main application listens (80 for a cache in most cases).                 |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``type``           | string | The name of the type of this server (see :ref:`to-api-v11-type`).                                          |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``typeId``         | string | The id of the type of this server (see :ref:`to-api-v11-type`).                                            |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+  | ``updPending``     |  bool  |                                                                                                            |
+  +--------------------+--------+------------------------------------------------------------------------------------------------------------+
+
+  **Response Example** ::
+
+   {
+      "response": [
+          {
+              "cachegroup": "us-il-chicago",
+              "cachegroupId": "3",
+              "cdnId": "3",
+              "cdnName": "CDN-1",
+              "domainName": "chi.kabletown.net",
+              "guid": null,
+              "hostName": "atsec-chi-00",
+              "id": "19",
+              "iloIpAddress": "172.16.2.6",
+              "iloIpGateway": "172.16.2.1",
+              "iloIpNetmask": "255.255.255.0",
+              "iloPassword": "********",
+              "iloUsername": "",
+              "interfaceMtu": "9000",
+              "interfaceName": "bond0",
+              "ip6Address": "2033:D0D0:3300::2:2/64",
+              "ip6Gateway": "2033:D0D0:3300::2:1",
+              "ipAddress": "10.10.2.2",
+              "ipGateway": "10.10.2.1",
+              "ipNetmask": "255.255.255.0",
+              "lastUpdated": "2015-03-08 15:57:32",
+              "mgmtIpAddress": "",
+              "mgmtIpGateway": "",
+              "mgmtIpNetmask": "",
+              "offlineReason": "N/A",
+              "physLocation": "plocation-chi-1",
+              "physLocationId": "9",
+              "profile": "EDGE1_CDN1_421_SSL",
+              "profileDesc": "EDGE1_CDN1_421_SSL profile",
+              "profileId": "12",
+              "rack": "RR 119.02",
+              "routerHostName": "rtr-chi.kabletown.net",
+              "routerPortName": "2",
+              "status": "ONLINE",
+              "statusId": "6",
+              "tcpPort": "80",
+              "httpsPort": "443",
+              "type": "EDGE",
+              "typeId": "3",
+              "updPending": false
+          },
+          {
+          ... more server data
+          }
+        ]
+    }
+
+|
+
 
 .. _to-api-v12-ds-health:
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9422ee6d/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 90ab79e..e9522a1 100644
--- a/traffic_ops/app/lib/API/Server.pm
+++ b/traffic_ops/app/lib/API/Server.pm
@@ -488,6 +488,77 @@ sub get_servers_by_dsid {
 	return ( $forbidden, $servers );
 }
 
+sub get_edge_servers_by_dsid {
+	my $self    = shift;
+	my $ds_id   = $self->param('id');
+
+	my $ds_servers;
+	if ( &is_privileged($self) || $self->is_delivery_service_assigned($ds_id) ) {
+		$ds_servers = $self->db->resultset('DeliveryserviceServer')->search( { deliveryservice => $ds_id } );
+	}
+	else {
+		return $self->alert("Forbidden. Delivery service not assigned to user.");
+	}
+
+	my $servers = $self->db->resultset('Server')->search(
+		{ 'me.id' => { -in => $ds_servers->get_column('server')->as_query } },
+		{ prefetch => [ 'cdn', 'cachegroup', 'type', 'profile', 'status', 'phys_location' ] }
+	);
+
+	my @data;
+	if ( defined($servers) ) {
+		my $is_admin = &is_admin($self);
+		while ( my $row = $servers->next ) {
+			push(
+				@data, {
+					"cachegroup"     => $row->cachegroup->name,
+					"cachegroupId"   => $row->cachegroup->id,
+					"cdnId"          => $row->cdn->id,
+					"cdnName"        => $row->cdn->name,
+					"domainName"     => $row->domain_name,
+					"guid"           => $row->guid,
+					"hostName"       => $row->host_name,
+					"httpsPort"      => $row->https_port,
+					"id"             => $row->id,
+					"iloIpAddress"   => $row->ilo_ip_address,
+					"iloIpNetmask"   => $row->ilo_ip_netmask,
+					"iloIpGateway"   => $row->ilo_ip_gateway,
+					"iloUsername"    => $row->ilo_username,
+					"iloPassword"    => $is_admin ? $row->ilo_password : "",
+					"interfaceMtu"   => $row->interface_mtu,
+					"interfaceName"  => $row->interface_name,
+					"ip6Address"     => $row->ip6_address,
+					"ip6Gateway"     => $row->ip6_gateway,
+					"ipAddress"      => $row->ip_address,
+					"ipNetmask"      => $row->ip_netmask,
+					"ipGateway"      => $row->ip_gateway,
+					"lastUpdated"    => $row->last_updated,
+					"mgmtIpAddress"  => $row->mgmt_ip_address,
+					"mgmtIpNetmask"  => $row->mgmt_ip_netmask,
+					"mgmtIpGateway"  => $row->mgmt_ip_gateway,
+					"offlineReason"  => $row->offline_reason,
+					"physLocation"   => $row->phys_location->name,
+					"physLocationId" => $row->phys_location->id,
+					"profile"        => $row->profile->name,
+					"profileId"      => $row->profile->id,
+					"profileDesc"    => $row->profile->description,
+					"rack"           => $row->rack,
+					"routerHostName" => $row->router_host_name,
+					"routerPortName" => $row->router_port_name,
+					"status"         => $row->status->name,
+					"statusId"       => $row->status->id,
+					"tcpPort"        => $row->tcp_port,
+					"type"           => $row->type->name,
+					"typeId"         => $row->type->id,
+					"updPending"     => \$row->upd_pending
+				}
+			);
+		}
+	}
+
+	return $self->success( \@data );
+}
+
 sub get_servers_by_type {
 	my $self              = shift;
 	my $current_user      = shift;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9422ee6d/traffic_ops/app/lib/TrafficOpsRoutes.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/TrafficOpsRoutes.pm b/traffic_ops/app/lib/TrafficOpsRoutes.pm
index 9d0e546..3fe1c14 100644
--- a/traffic_ops/app/lib/TrafficOpsRoutes.pm
+++ b/traffic_ops/app/lib/TrafficOpsRoutes.pm
@@ -482,6 +482,9 @@ sub api_routes {
 	$r->put("/api/$version/deliveryservices/:id")->over( authenticated => 1 )->to( 'Deliveryservice#update', namespace => $namespace );
 	$r->delete("/api/$version/deliveryservices/:id")->over( authenticated => 1 )->to( 'Deliveryservice#delete', namespace => $namespace );
 
+	# get all edge servers associated with a delivery service (from deliveryservice_server table)
+	$r->get( "/api/$version/deliveryservices/:id/servers")->over( authenticated => 1 )->to( 'Server#get_edge_servers_by_dsid', namespace => $namespace );
+
 	# alternate deliveryservice routes
 	$r->get("/api/$version/deliveryservices/list")->over( authenticated => 1 )->to( 'Deliveryservice2#delivery_services', namespace => $namespace );
 	$r->get( "/api/$version/deliveryservices/:id/get" => [ id => qr/\d+/ ] )->over( authenticated => 1 )