You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2017/04/17 20:22:16 UTC

[1/2] incubator-trafficcontrol git commit: This closes #385

Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/master 65db0fe51 -> 3ae527925


This closes #385


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

Branch: refs/heads/master
Commit: 3ae527925d4cabd53d159c846051673c75c674b4
Parents: 3010343
Author: Dewayne Richardson <de...@apache.org>
Authored: Mon Apr 17 14:22:05 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Mon Apr 17 14:22:05 2017 -0600

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

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



[2/2] incubator-trafficcontrol git commit: adds parent tenant name

Posted by de...@apache.org.
adds parent tenant name


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

Branch: refs/heads/master
Commit: 30103432b06c1fe82cc7d8d668f970f4a0c2be87
Parents: 65db0fe
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Mon Mar 20 21:37:59 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Mon Apr 17 14:22:05 2017 -0600

----------------------------------------------------------------------
 .../development/traffic_ops_api/v12/tenant.rst  | 21 ++++++++---
 traffic_ops/app/lib/API/Tenant.pm               | 37 ++++++++++++++++++--
 2 files changed, 51 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/30103432/docs/source/development/traffic_ops_api/v12/tenant.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/tenant.rst b/docs/source/development/traffic_ops_api/v12/tenant.rst
index afdcaa7..f75868e 100644
--- a/docs/source/development/traffic_ops_api/v12/tenant.rst
+++ b/docs/source/development/traffic_ops_api/v12/tenant.rst
@@ -42,7 +42,9 @@ Tenants
   +----------------------+--------+-------------------------------------------------+
   |``active``            |  bool  | Active or inactive                              |
   +----------------------+--------+-------------------------------------------------+
-  |``parentId``          |  int   | Parent tenant                                   |
+  |``parentId``          |  int   | Parent tenant ID                                |
+  +----------------------+--------+-------------------------------------------------+
+  |``parentName``        | string | Parent tenant name                              |
   +----------------------+--------+-------------------------------------------------+
 
   **Response Example** ::
@@ -54,12 +56,14 @@ Tenants
            "name": "root",
            "active": true,
            "parentId": null,
+           "parentName": null,
         },
         {
            "id": 2
            "name": "tenant-a",
            "active": true,
            "parentId": 1
+           "parentName": "root"
         }
      ]
     }
@@ -86,7 +90,9 @@ Tenants
   +----------------------+--------+-------------------------------------------------+
   |``active``            |  bool  | Active or inactive                              |
   +----------------------+--------+-------------------------------------------------+
-  |``parentId``          |  int   | Parent tenant                                   |
+  |``parentId``          |  int   | Parent tenant ID                                |
+  +----------------------+--------+-------------------------------------------------+
+  |``parentName``        | string | Parent tenant name                              |
   +----------------------+--------+-------------------------------------------------+
 
   **Response Example** ::
@@ -98,6 +104,7 @@ Tenants
            "name": "tenant-a",
            "active": true,
            "parentId": 1,
+           "parentName": "root"
         }
      ]
     }
@@ -154,7 +161,9 @@ Tenants
   +----------------------+--------+-------------------------------------------------+
   |``active``            |  bool  | Active or inactive                              |
   +----------------------+--------+-------------------------------------------------+
-  |``parentId``          |  int   | Parent tenant                                   |
+  |``parentId``          |  int   | Parent tenant ID                                |
+  +----------------------+--------+-------------------------------------------------+
+  |``parentName``        | string | Parent tenant name                              |
   +----------------------+--------+-------------------------------------------------+
 
   **Response Example** ::
@@ -165,6 +174,7 @@ Tenants
 			"name": "my-tenant",
 			"active": true,
 			"parentId": 1,
+			"parentName": "root",
 			"lastUpdated": "2014-03-18 08:57:39"
 		},
 		"alerts": [
@@ -218,7 +228,9 @@ Tenants
   +----------------------+--------+-------------------------------------------------+
   |``active``            |  bool  | Active or inactive                              |
   +----------------------+--------+-------------------------------------------------+
-  |``parentId``          |  int   | Parent tenant                                   |
+  |``parentId``          |  int   | Parent tenant ID                                |
+  +----------------------+--------+-------------------------------------------------+
+  |``parentName``        | string | Parent tenant name                              |
   +----------------------+--------+-------------------------------------------------+
 
   **Response Example** ::
@@ -229,6 +241,7 @@ Tenants
 			"name": "your-tenant",
 			"active": false,
 			"parentId": 2,
+			"parentName": "my-tenant",
 			"lastUpdated": "2014-03-18 08:57:39"
 		},
 		"alerts": [

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/30103432/traffic_ops/app/lib/API/Tenant.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Tenant.pm b/traffic_ops/app/lib/API/Tenant.pm
index d630146..c09df37 100644
--- a/traffic_ops/app/lib/API/Tenant.pm
+++ b/traffic_ops/app/lib/API/Tenant.pm
@@ -39,9 +39,15 @@ sub isRootTenant {
 
 sub index {
 	my $self 	= shift;
-
-	my @data;
+	my @data = ();
+	my %idnames;
 	my $orderby = $self->param('orderby') || "name";
+
+	my $rs_data = $self->db->resultset("Tenant")->search();
+	while ( my $row = $rs_data->next ) {
+		$idnames{ $row->id } = $row->name;
+	}
+
 	my $rs_data = $self->db->resultset("Tenant")->search( undef, {order_by => 'me.' . $orderby } );
 	while ( my $row = $rs_data->next ) {
 		push(
@@ -50,6 +56,7 @@ sub index {
 				"name"         => $row->name,
 				"active"       => \$row->active,
 				"parentId"     => $row->parent_id,
+				"parentName"   => ( defined $row->parent_id ) ? $idnames{ $row->parent_id } : undef,
 			}
 		);
 	}
@@ -61,8 +68,15 @@ sub show {
 	my $self = shift;
 	my $id   = $self->param('id');
 
-	my $rs_data = $self->db->resultset("Tenant")->search( { 'me.id' => $id });
 	my @data = ();
+	my %idnames;
+
+	my $rs_idnames = $self->db->resultset("Tenant")->search( undef, { columns => [qw/id name/] } );
+	while ( my $row = $rs_idnames->next ) {
+		$idnames{ $row->id } = $row->name;
+	}
+
+	my $rs_data = $self->db->resultset("Tenant")->search( { 'me.id' => $id });
 	while ( my $row = $rs_data->next ) {
 		push(
 			@data, {
@@ -70,6 +84,7 @@ sub show {
 				"name"         => $row->name,
 				"active"       => \$row->active,
 				"parentId"     => $row->parent_id,
+				"parentName"   => ( defined $row->parent_id ) ? $idnames{ $row->parent_id } : undef,
 			}
 		);
 	}
@@ -133,11 +148,19 @@ sub update {
 
 	my $rs = $tenant->update($values);
 	if ($rs) {
+		my %idnames;
 		my $response;
+
+		my $rs_idnames = $self->db->resultset("Tenant")->search( undef, { columns => [qw/id name/] } );
+		while ( my $row = $rs_idnames->next ) {
+			$idnames{ $row->id } = $row->name;
+		}
+
 		$response->{id}          = $rs->id;
 		$response->{name}        = $rs->name;
 		$response->{active}      = $rs->active;
 		$response->{parentId}    = $rs->parent_id;
+		$response->{parentName}  = ( defined $rs->parent_id ) ? $idnames{ $rs->parent_id } : undef;
 		$response->{lastUpdated} = $rs->last_updated;
 		&log( $self, "Updated Tenant name '" . $rs->name . "' for id: " . $rs->id, "APICHANGE" );
 		return $self->success( $response, "Tenant update was successful." );
@@ -187,11 +210,19 @@ sub create {
 	my $insert = $self->db->resultset('Tenant')->create($values);
 	my $rs = $insert->insert();
 	if ($rs) {
+		my %idnames;
 		my $response;
+
+		my $rs_idnames = $self->db->resultset("Tenant")->search( undef, { columns => [qw/id name/] } );
+		while ( my $row = $rs_idnames->next ) {
+			$idnames{ $row->id } = $row->name;
+		}
+
 		$response->{id}          	= $rs->id;
 		$response->{name}        	= $rs->name;
 		$response->{active}        	= $rs->active;
 		$response->{parentId}		= $rs->parent_id;
+		$response->{parentName}  	= ( defined $rs->parent_id ) ? $idnames{ $rs->parent_id } : undef;
 		$response->{lastUpdated} 	= $rs->last_updated;
 
 		&log( $self, "Created Tenant name '" . $rs->name . "' for id: " . $rs->id, "APICHANGE" );