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/06/07 22:33:24 UTC

[1/4] incubator-trafficcontrol git commit: checks the count of eligible servers that can be assigned to a ds 100

Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/master f0f3758c5 -> 17b3176a8


checks the count of eligible servers that can be assigned to a ds 100


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

Branch: refs/heads/master
Commit: 97914a3f54c3207f44cc3920aa6ce0978e244146
Parents: 31fbe2d
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Wed Jun 7 15:52:51 2017 -0600
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Wed Jun 7 16:32:32 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/t/api/1.2/deliveryservice.t | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/97914a3f/traffic_ops/app/t/api/1.2/deliveryservice.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/deliveryservice.t b/traffic_ops/app/t/api/1.2/deliveryservice.t
index ca106f7..58134af 100644
--- a/traffic_ops/app/t/api/1.2/deliveryservice.t
+++ b/traffic_ops/app/t/api/1.2/deliveryservice.t
@@ -66,6 +66,10 @@ ok $t->post_ok('/api/1.2/deliveryserviceserver' => {Accept => 'application/json'
 $t->get_ok('/api/1.2/deliveryservices/100/servers/unassigned')->status_is(200)->$count_response(2)
 	->or( sub { diag $t->tx->res->content->asset->{content}; } );
 
+# there are currently 6 servers of type EDGE or ORG that can be assigned to ds 100
+$t->get_ok('/api/1.2/deliveryservices/100/servers/eligible')->status_is(200)->$count_response(6)
+	->or( sub { diag $t->tx->res->content->asset->{content}; } );
+
 # It gets existing delivery services
 ok $t->get_ok("/api/1.2/deliveryservices/list")->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content} } )
 		->json_is( "/response/0/xmlId", "steering-ds1" )


[3/4] incubator-trafficcontrol git commit: adds api to get eligible servers for ds

Posted by da...@apache.org.
adds api to get eligible servers for ds


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

Branch: refs/heads/master
Commit: 8045eaa509509753f9b3d817328b1feb697a6eb7
Parents: f0f3758
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Wed Jun 7 14:59:47 2017 -0600
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Wed Jun 7 16:32:32 2017 -0600

----------------------------------------------------------------------
 .../traffic_ops_api/v12/deliveryservice.rst     | 164 ++++++++++++++++++-
 .../app/lib/API/DeliveryServiceServer.pm        |  11 +-
 traffic_ops/app/lib/API/Server.pm               |  78 +++++++++
 traffic_ops/app/lib/TrafficOpsRoutes.pm         |   3 +-
 traffic_ops/app/t/api/1.2/deliveryservice.t     |   4 +-
 5 files changed, 254 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/8045eaa5/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 df674fa..da17b7b 100644
--- a/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
+++ b/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
@@ -641,7 +641,7 @@ Delivery Service
 
 |
 
-**GET /api/1.2/deliveryservices/:id/unassigned_servers**
+**GET /api/1.2/deliveryservices/:id/servers/unassigned**
 
   Retrieves properties of CDN EDGE or ORG servers not assigned to a delivery service.
 
@@ -797,6 +797,162 @@ Delivery Service
 
 |
 
+**GET /api/1.2/deliveryservices/:id/servers/eligible**
+
+  Retrieves properties of CDN EDGE or ORG servers not eligible for assignment to a delivery service.
+
+  Authentication Required: Yes
+
+  Role(s) Required: Admin or Operations or delivery service must be assigned to user
+
+  **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:
 
@@ -1082,12 +1238,15 @@ Delivery Service Server
   +---------------------------------+----------+-------------------------------------------------------------------+
   | ``servers``                     | yes      | An array of server IDs.                                           |
   +---------------------------------+----------+-------------------------------------------------------------------+
+  | ``replace``                     | no       | Replace existing ds/server assignments? (true|false)              |
+  +---------------------------------+----------+-------------------------------------------------------------------+
 
   **Request Example** ::
 
     {
         "dsId": 246,
-        "servers": [ 2, 3, 4, 5, 6 ]
+        "servers": [ 2, 3, 4, 5, 6 ],
+        "replace": true
     }
 
   **Response Properties**
@@ -1112,6 +1271,7 @@ Delivery Service Server
         "response": {
             "dsId" : 246,
             "servers" : [ 2, 3, 4, 5, 6 ],
+            "replace" : true
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/8045eaa5/traffic_ops/app/lib/API/DeliveryServiceServer.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/DeliveryServiceServer.pm b/traffic_ops/app/lib/API/DeliveryServiceServer.pm
index c07be67..7d4bb1c 100644
--- a/traffic_ops/app/lib/API/DeliveryServiceServer.pm
+++ b/traffic_ops/app/lib/API/DeliveryServiceServer.pm
@@ -73,6 +73,8 @@ sub assign_servers_to_ds {
 	my $params 		= $self->req->json;
 	my $ds_id 		= $params->{dsId};
 	my $servers 	= $params->{servers};
+	my $replace 	= $params->{replace};
+	my $count		= 0;
 
 	if ( !&is_oper($self) ) {
 		return $self->forbidden();
@@ -87,6 +89,12 @@ sub assign_servers_to_ds {
 		return $self->not_found();
 	}
 
+	if ( $replace ) {
+		# start fresh and delete existing deliveryservice/server associations
+		my $delete = $self->db->resultset('DeliveryserviceServer')->search( { deliveryservice => $ds_id } );
+		$delete->delete();
+	}
+
 	$self->db->txn_begin();
 	foreach my $server (@{ $servers }) {
 		my $server_exist = $self->db->resultset('Server')->find( { id => $server } );
@@ -97,11 +105,12 @@ sub assign_servers_to_ds {
 		my $ds_server_exist = $self->db->resultset('DeliveryserviceServer')->find( { deliveryservice => $ds_id, server => $server } );
 		if ( !defined($ds_server_exist) ) {
 			$self->db->resultset('DeliveryserviceServer')->create( { deliveryservice => $ds_id, server => $server } )->insert();
+			$count++;
 		}
 	}
 	$self->db->txn_commit();
 
-	&log( $self, "Servers were assigned to " . $ds->xml_id, "APICHANGE" );
+	&log( $self, $count . " servers were assigned to " . $ds->xml_id, "APICHANGE" );
 
 	my $response = $params;
 	return $self->success($response, "Server assignments complete.");

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/8045eaa5/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 68c7273..8423fa1 100644
--- a/traffic_ops/app/lib/API/Server.pm
+++ b/traffic_ops/app/lib/API/Server.pm
@@ -639,6 +639,84 @@ sub get_unassigned_servers_by_dsid {
 
 	return $self->success( \@data );
 }
+sub get_eligible_servers_by_dsid {
+	my $self    = shift;
+	my $ds_id   = $self->param('id');
+
+	my $ds = $self->db->resultset('Deliveryservice')->search( { id => $ds_id } )->single();
+	if ( !defined($ds) ) {
+		return $self->not_found();
+	}
+
+	my %ds_server_criteria;
+	$ds_server_criteria{'deliveryservice.id'} = $ds_id;
+
+	if ( !&is_privileged($self) && !$self->is_delivery_service_assigned($ds_id) ) {
+		return $self->alert("Forbidden. Delivery service not assigned to user.");
+	}
+
+	my %server_criteria; # please fetch the following...
+	$server_criteria{'type.name'} = [ { -like => 'EDGE%' }, { -like => 'ORG' } ]; # ...of type EDGE% or ORG...
+	$server_criteria{'cdn.id'} = $ds->cdn_id; # ...that belongs to the same cdn as the ds...
+
+	my $servers = $self->db->resultset('Server')->search(
+		\%server_criteria,
+		{ 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;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/8045eaa5/traffic_ops/app/lib/TrafficOpsRoutes.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/TrafficOpsRoutes.pm b/traffic_ops/app/lib/TrafficOpsRoutes.pm
index e4db8f2..0b58483 100644
--- a/traffic_ops/app/lib/TrafficOpsRoutes.pm
+++ b/traffic_ops/app/lib/TrafficOpsRoutes.pm
@@ -705,7 +705,8 @@ sub api_routes {
 
 	# get all edge servers associated with a delivery service (from deliveryservice_server table)
 	$r->get( "/api/$version/deliveryservices/:id/servers" => [ id => qr/\d+/ ] )->over( authenticated => 1 )->to( 'Server#get_edge_servers_by_dsid', namespace => $namespace );
-	$r->get( "/api/$version/deliveryservices/:id/unassigned_servers" => [ id => qr/\d+/ ] )->over( authenticated => 1 )->to( 'Server#get_unassigned_servers_by_dsid', namespace => $namespace );
+	$r->get( "/api/$version/deliveryservices/:id/servers/unassigned" => [ id => qr/\d+/ ] )->over( authenticated => 1 )->to( 'Server#get_unassigned_servers_by_dsid', namespace => $namespace );
+	$r->get( "/api/$version/deliveryservices/:id/servers/eligible" => [ id => qr/\d+/ ] )->over( authenticated => 1 )->to( 'Server#get_eligible_servers_by_dsid', namespace => $namespace );
 
 	# alternate server routes
 	$r->post("/api/$version/servers/create")->over( authenticated => 1 )->to( 'Server2#create', namespace => $namespace );

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/8045eaa5/traffic_ops/app/t/api/1.2/deliveryservice.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/deliveryservice.t b/traffic_ops/app/t/api/1.2/deliveryservice.t
index 0f23e71..ca106f7 100644
--- a/traffic_ops/app/t/api/1.2/deliveryservice.t
+++ b/traffic_ops/app/t/api/1.2/deliveryservice.t
@@ -49,7 +49,7 @@ my $count_response = sub {
 };
 
 # there are currently 3 servers of type EDGE or ORG where server.cdn == ds.cdn not assigned to ds 100
-$t->get_ok('/api/1.2/deliveryservices/100/unassigned_servers')->status_is(200)->$count_response(4)
+$t->get_ok('/api/1.2/deliveryservices/100/servers/unassigned')->status_is(200)->$count_response(4)
 	->or( sub { diag $t->tx->res->content->asset->{content}; } );
 
 # we will assign 2 more servers to ds 100
@@ -63,7 +63,7 @@ ok $t->post_ok('/api/1.2/deliveryserviceserver' => {Accept => 'application/json'
 	, 'Are the servers assigned to the delivery service?';
 
 # there are now 2 servers of type EDGE or ORG where server.cdn == ds.cdn not assigned to ds 100
-$t->get_ok('/api/1.2/deliveryservices/100/unassigned_servers')->status_is(200)->$count_response(2)
+$t->get_ok('/api/1.2/deliveryservices/100/servers/unassigned')->status_is(200)->$count_response(2)
 	->or( sub { diag $t->tx->res->content->asset->{content}; } );
 
 # It gets existing delivery services


[2/4] incubator-trafficcontrol git commit: changes the way servers are assigned to ds's. always shows all servers and puts a checkmark next to currently assigned servers

Posted by da...@apache.org.
changes the way servers are assigned to ds's. always shows all servers and puts a checkmark next to currently assigned servers


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

Branch: refs/heads/master
Commit: 31fbe2d679a64ec0a3e0687340101475b49a2cf6
Parents: 8045eaa
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Wed Jun 7 15:18:24 2017 -0600
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Wed Jun 7 16:32:32 2017 -0600

----------------------------------------------------------------------
 .../src/common/api/DeliveryServiceService.js    |  4 +-
 .../ui/app/src/common/api/ServerService.js      |  6 +-
 .../TableDSServersUnassignedController.js       | 59 ++++++++++++++++----
 .../TableDeliveryServiceServersController.js    | 10 ++--
 .../table.dsServersUnassigned.tpl.html          |  6 +-
 5 files changed, 64 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/31fbe2d6/traffic_ops/experimental/ui/app/src/common/api/DeliveryServiceService.js
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/app/src/common/api/DeliveryServiceService.js b/traffic_ops/experimental/ui/app/src/common/api/DeliveryServiceService.js
index 7c35224..165d320 100644
--- a/traffic_ops/experimental/ui/app/src/common/api/DeliveryServiceService.js
+++ b/traffic_ops/experimental/ui/app/src/common/api/DeliveryServiceService.js
@@ -84,8 +84,8 @@ var DeliveryServiceService = function(Restangular, locationUtils, httpService, m
             );
     };
 
-    this.assignDeliveryServiceServers = function(dsServerMappings) {
-        return Restangular.service('deliveryserviceserver').post(dsServerMappings)
+    this.assignDeliveryServiceServers = function(dsId, servers) {
+        return Restangular.service('deliveryserviceserver').post( { dsId: dsId, servers: servers, replace: true })
             .then(
                 function() {
                     messageModel.setMessages([ { level: 'success', text: 'Servers linked to delivery service' } ], false);

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/31fbe2d6/traffic_ops/experimental/ui/app/src/common/api/ServerService.js
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/app/src/common/api/ServerService.js b/traffic_ops/experimental/ui/app/src/common/api/ServerService.js
index de05a0e..3aaffed 100644
--- a/traffic_ops/experimental/ui/app/src/common/api/ServerService.js
+++ b/traffic_ops/experimental/ui/app/src/common/api/ServerService.js
@@ -69,7 +69,11 @@ var ServerService = function($http, $q, Restangular, locationUtils, messageModel
     };
 
     this.getUnassignedDeliveryServiceServers = function(dsId) {
-        return Restangular.one('deliveryservices', dsId).getList('unassigned_servers');
+        return Restangular.one('deliveryservices', dsId).getList('servers/unassigned');
+    };
+
+    this.getEligibleDeliveryServiceServers = function(dsId) {
+        return Restangular.one('deliveryservices', dsId).getList('servers/eligible');
     };
 
     this.queueServerUpdates = function(id) {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/31fbe2d6/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/TableDSServersUnassignedController.js
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/TableDSServersUnassignedController.js b/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/TableDSServersUnassignedController.js
index a73059c..ac7c42f 100644
--- a/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/TableDSServersUnassignedController.js
+++ b/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/TableDSServersUnassignedController.js
@@ -17,22 +17,59 @@
  * under the License.
  */
 
-var TableDSServersUnassignedController = function(deliveryService, servers, $scope, $uibModalInstance) {
+var TableDSServersUnassignedController = function(deliveryService, eligibleServers, assignedServers, $scope, $uibModalInstance) {
 
-	var selectedServers = [];
-
-	$scope.deliveryService = deliveryService;
-
-	$scope.unassignedServers = servers;
+	var selectedServerIds = [];
 
 	var addServer = function(serverId) {
-		if (_.indexOf(selectedServers, serverId) == -1) {
-			selectedServers.push(serverId);
+		if (_.indexOf(selectedServerIds, serverId) == -1) {
+			selectedServerIds.push(serverId);
 		}
 	};
 
 	var removeServer = function(serverId) {
-		selectedServers = _.without(selectedServers, serverId);
+		selectedServerIds = _.without(selectedServerIds, serverId);
+	};
+
+	var addAll = function() {
+		markServers(true);
+		selectedServerIds = _.pluck(eligibleServers, 'id');
+	};
+
+	var removeAll = function() {
+		markServers(false);
+		selectedServerIds = [];
+	};
+
+	var markServers = function(selected) {
+		$scope.selectedServers = _.map(eligibleServers, function(server) {
+			server['selected'] = selected;
+			return server;
+		});
+	};
+
+	$scope.deliveryService = deliveryService;
+
+	$scope.selectedServers = _.map(eligibleServers, function(eligibleServer) {
+		var isAssigned = _.find(assignedServers, function(assignedServer) { return assignedServer.id == eligibleServer.id });
+		if (isAssigned) {
+			eligibleServer['selected'] = true; // so the checkbox will be checked
+			selectedServerIds.push(eligibleServer.id); // so the server is added to selected servers
+		}
+		return eligibleServer;
+	});
+
+	$scope.allSelected = function() {
+		return eligibleServers.length == selectedServerIds.length;
+	};
+
+	$scope.selectAll = function($event) {
+		var checkbox = $event.target;
+		if (checkbox.checked) {
+			addAll();
+		} else {
+			removeAll();
+		}
 	};
 
 	$scope.updateServers = function($event, serverId) {
@@ -45,7 +82,7 @@ var TableDSServersUnassignedController = function(deliveryService, servers, $sco
 	};
 
 	$scope.submit = function() {
-		$uibModalInstance.close(selectedServers);
+		$uibModalInstance.close(selectedServerIds);
 	};
 
 	$scope.cancel = function () {
@@ -66,5 +103,5 @@ var TableDSServersUnassignedController = function(deliveryService, servers, $sco
 
 };
 
-TableDSServersUnassignedController.$inject = ['deliveryService', 'servers', '$scope', '$uibModalInstance'];
+TableDSServersUnassignedController.$inject = ['deliveryService', 'eligibleServers', 'assignedServers', '$scope', '$uibModalInstance'];
 module.exports = TableDSServersUnassignedController;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/31fbe2d6/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/TableDeliveryServiceServersController.js
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/TableDeliveryServiceServersController.js b/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/TableDeliveryServiceServersController.js
index ec56313..f27aaad 100644
--- a/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/TableDeliveryServiceServersController.js
+++ b/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/TableDeliveryServiceServersController.js
@@ -45,14 +45,16 @@ var TableDeliveryServiceServersController = function(deliveryService, servers, $
 				deliveryService: function() {
 					return deliveryService;
 				},
-				servers: function(serverService) {
-					return serverService.getUnassignedDeliveryServiceServers(deliveryService.id);
+				eligibleServers: function(serverService) {
+					return serverService.getEligibleDeliveryServiceServers(deliveryService.id);
+				},
+				assignedServers: function() {
+					return servers;
 				}
 			}
 		});
 		modalInstance.result.then(function(selectedServerIds) {
-			var serverAssignments = { dsId: deliveryService.id, servers: selectedServerIds };
-			deliveryServiceService.assignDeliveryServiceServers(serverAssignments)
+			deliveryServiceService.assignDeliveryServiceServers(deliveryService.id, selectedServerIds)
 				.then(
 					function() {
 						$scope.refresh();

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/31fbe2d6/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/table.dsServersUnassigned.tpl.html
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/table.dsServersUnassigned.tpl.html b/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/table.dsServersUnassigned.tpl.html
index 0e43889..7c15cf1 100644
--- a/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/table.dsServersUnassigned.tpl.html
+++ b/traffic_ops/experimental/ui/app/src/common/modules/table/deliveryServiceServers/table.dsServersUnassigned.tpl.html
@@ -27,15 +27,15 @@ under the License.
     <table id="dsServersUnassignedTable" class="table responsive-utilities jambo_table" style="table-layout:fixed; width:100%;">
         <thead>
         <tr class="headings">
-            <th></th>
+            <th style="padding-left: 10px;"><input type="checkbox" ng-click="selectAll($event)" ng-checked="allSelected()"></th>
             <th>hostName</th>
             <th>cachegroup</th>
             <th>profile</th>
         </tr>
         </thead>
         <tbody>
-        <tr ng-repeat="server in ::unassignedServers">
-            <td><input type="checkbox" ng-click="updateServers($event, server.id)"></td>
+        <tr ng-repeat="server in ::selectedServers">
+            <td><input type="checkbox" ng-click="updateServers($event, server.id)" ng-checked="server.selected"></td>
             <td>{{::server.hostName}}</td>
             <td>{{::server.cachegroup}}</td>
             <td>{{::server.profile}}</td>


[4/4] incubator-trafficcontrol git commit: This closes #655.

Posted by da...@apache.org.
This closes #655.


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

Branch: refs/heads/master
Commit: 17b3176a812a8e100edb64f16dd373eea0c37864
Parents: 97914a3
Author: Dan Kirkwood <da...@gmail.com>
Authored: Wed Jun 7 16:33:08 2017 -0600
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Wed Jun 7 16:33:08 2017 -0600

----------------------------------------------------------------------

----------------------------------------------------------------------