Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/master 12e6c826f -> ebaa01425


Tenant col in DS - tenant name in API


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

Branch: refs/heads/master
Commit: 793495361e90a742f0af33920e7fe4056255d5a9
Parents: 12e6c82
Author: nir-sopher <n...@qwilt.com>
Authored: Mon Jun 26 06:17:53 2017 +0300
Committer: Jeremy Mitchell <mitchell...@gmail.com>
Committed: Thu Jul 13 14:32:09 2017 -0600

----------------------------------------------------------------------
 .../traffic_ops_api/v12/deliveryservice.rst           |  6 ++++++
 .../source/development/traffic_ops_api/v12/server.rst |  3 +++
 docs/source/development/traffic_ops_api/v12/user.rst  |  5 +++--
 traffic_ops/app/lib/API/Deliveryservice.pm            | 14 +++++++++-----
 traffic_ops/app/lib/API/Deliveryservice2.pm           | 11 ++++++-----
 traffic_ops/app/t/api/1.2/deliveryservice.t           |  1 +
 traffic_ops/app/t/api/1.2/deliveryservice_crud.t      |  3 ++-
 7 files changed, 30 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/79349536/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 2d04604..ecb17bc 100644
--- a/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
+++ b/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
@@ -174,6 +174,8 @@ Delivery Service
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``sslKeyVersion``        |  int   |                                        
                                                                                
              |
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
+  | ``tenant``               | string | Owning tenant name                     
                                                                                
              |
+  
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``tenantId``             | int    | Owning tenant ID                       
                                                                                
              |
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``trRequestHeaders``     | string |                                        
                                                                                
              |
@@ -240,6 +242,7 @@ Delivery Service
             "remapText": null,
             "signed": false,
             "sslKeyVersion": "0",
+            "tenant": "root",
             "tenantId": 1,
             "trRequestHeaders": null,
             "trResponseHeaders": "Access-Control-Allow-Origin: *",
@@ -406,6 +409,8 @@ Delivery Service
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``sslKeyVersion``        |  int   |                                        
                                                                                
              |
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
+  | ``tenant``               | string | Owning tenant name                     
                                                                                
              |
+  
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``tenantId``             | int    | Owning tenant ID                       
                                                                                
              |
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``trRequestHeaders``     | string |                                        
                                                                                
              |
@@ -479,6 +484,7 @@ Delivery Service
             "remapText": null,
             "signed": false,
             "sslKeyVersion": "0",
+            "tenant": "root",
             "tenantId": 1,
             "trRequestHeaders": null,
             "trResponseHeaders": "Access-Control-Allow-Origin: *",

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/79349536/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 3e47dcc..c5df386 100644
--- a/docs/source/development/traffic_ops_api/v12/server.rst
+++ b/docs/source/development/traffic_ops_api/v12/server.rst
@@ -488,6 +488,8 @@ Server
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``sslKeyVersion``        | string |                                        
                                                                                
              |
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
+  | ``tenant``               | string | Owning tenant name                     
                                                                                
              |
+  
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``tenantId``             | int    | Owning tenant ID.                      
                                                                                
              |
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``trRequestHeaders``     | string |                                        
                                                                                
              |
@@ -564,6 +566,7 @@ Server
             "remapText": null,
             "signed": false,
             "sslKeyVersion": "0",
+            "tenant": "root",
             "tenantId": 1,
             "trRequestHeaders": null,
             "trResponseHeaders": "Access-Control-Allow-Origin: *",

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/79349536/docs/source/development/traffic_ops_api/v12/user.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/user.rst 
b/docs/source/development/traffic_ops_api/v12/user.rst
index 8681dca..b51291f 100644
--- a/docs/source/development/traffic_ops_api/v12/user.rst
+++ b/docs/source/development/traffic_ops_api/v12/user.rst
@@ -511,6 +511,8 @@ Users
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``sslKeyVersion``        | string |                                        
                                                                                
              |
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
+  | ``tenant``               | string | Owning tenant name                     
                                                                                
              |
+  
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``tenantId``             | int    | Owning tenant ID.                      
                                                                                
              |
   
+--------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------+
   | ``trRequestHeaders``     | string |                                        
                                                                                
              |
@@ -587,6 +589,7 @@ Users
             "remapText": null,
             "signed": false,
             "sslKeyVersion": "0",
+            "tenant": "root",
             "tenantId": 1,
             "trRequestHeaders": null,
             "trResponseHeaders": "Access-Control-Allow-Origin: *",
@@ -730,8 +733,6 @@ Users
   
+----------------------+---------+------------------------------------------------+
   |``postalCode``        | string  |                                           
     |
   
+----------------------+---------+------------------------------------------------+
-  | ``tenant``           | string  | Owning tenant name                        
     |
-  
+----------------------+---------+------------------------------------------------+
   | ``tenantId``         | int     | Owning tenant ID                          
     |
   
+----------------------+---------+------------------------------------------------+
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/79349536/traffic_ops/app/lib/API/Deliveryservice.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Deliveryservice.pm 
b/traffic_ops/app/lib/API/Deliveryservice.pm
index 8d7f1cd..4cf567b 100644
--- a/traffic_ops/app/lib/API/Deliveryservice.pm
+++ b/traffic_ops/app/lib/API/Deliveryservice.pm
@@ -61,7 +61,7 @@ sub index {
 
        my $rs_data = $self->db->resultset("Deliveryservice")->search(
                \%criteria,
-               { prefetch => [ 'cdn', { 'deliveryservice_regexes' => { 'regex' 
=> 'type' } }, 'profile', 'type' ], order_by => 'me.' . $orderby }
+               { prefetch => [ 'cdn', { 'deliveryservice_regexes' => { 'regex' 
=> 'type' } }, 'profile', 'type', 'tenant' ], order_by => 'me.' . $orderby }
        );
 
        while ( my $row = $rs_data->next ) {
@@ -133,7 +133,8 @@ sub index {
                                "remapText"            => $row->remap_text,
                                "signed"               => \$row->signed,
                                "sslKeyVersion"        => $row->ssl_key_version,
-                               "tenantId"                 => $row->tenant_id,
+                               "tenantId"                     => 
$row->tenant_id,
+                               "tenant"               => defined( $row->tenant 
) ? $row->tenant->name : undef,
                                "trRequestHeaders"     => 
$row->tr_request_headers,
                                "trResponseHeaders"    => 
$row->tr_response_headers,
                                "type"                 => $row->type->name,
@@ -162,7 +163,7 @@ sub show {
 
        my $rs = $self->db->resultset("Deliveryservice")->search(
                { 'me.id' => $id },
-               { prefetch => [ 'cdn', { 'deliveryservice_regexes' => { 'regex' 
=> 'type' } }, 'profile', 'type' ] }
+               { prefetch => [ 'cdn', { 'deliveryservice_regexes' => { 'regex' 
=> 'type' } }, 'profile', 'type', 'tenant' ] }
        );
        while ( my $row = $rs->next ) {
 
@@ -250,6 +251,7 @@ sub show {
                                "signed"               => \$row->signed,
                                "sslKeyVersion"        => $row->ssl_key_version,
                                "tenantId"             => $row->tenant_id,
+                               "tenant"               => defined( $row->tenant 
) ? $row->tenant->name : undef,
                                "trRequestHeaders"     => 
$row->tr_request_headers,
                                "trResponseHeaders"    => 
$row->tr_response_headers,
                                "type"                 => $row->type->name,
@@ -662,7 +664,7 @@ sub get_deliveryservices_by_serverId {
        my $server_ds_ids = 
$self->db->resultset('DeliveryserviceServer')->search( { server => $server_id } 
);
 
        my $deliveryservices = $self->db->resultset('Deliveryservice')
-               ->search( { 'me.id' => { -in => 
$server_ds_ids->get_column('deliveryservice')->as_query } }, { prefetch => [ 
'cdn', 'profile', 'type' ] } );
+               ->search( { 'me.id' => { -in => 
$server_ds_ids->get_column('deliveryservice')->as_query } }, { prefetch => [ 
'cdn', 'profile', 'type', 'tenant' ] } );
 
        my @data;
        if ( defined($deliveryservices) ) {
@@ -717,6 +719,7 @@ sub get_deliveryservices_by_serverId {
                                        "signed"               => \$row->signed,
                                        "sslKeyVersion"        => 
$row->ssl_key_version,
                                        "tenantId"             => 
$row->tenant_id,
+                                       "tenant"               => defined( 
$row->tenant ) ? $row->tenant->name : undef,
                                        "trRequestHeaders"     => 
$row->tr_request_headers,
                                        "trResponseHeaders"    => 
$row->tr_response_headers,
                                        "type"                 => 
$row->type->name,
@@ -737,7 +740,7 @@ sub get_deliveryservices_by_userId {
        my $user_ds_ids = 
$self->db->resultset('DeliveryserviceTmuser')->search( { tm_user_id => $user_id 
} );
 
        my $deliveryservices = $self->db->resultset('Deliveryservice')
-               ->search( { 'me.id' => { -in => 
$user_ds_ids->get_column('deliveryservice')->as_query } }, { prefetch => [ 
'cdn', 'profile', 'type' ] } );
+               ->search( { 'me.id' => { -in => 
$user_ds_ids->get_column('deliveryservice')->as_query } }, { prefetch => [ 
'cdn', 'profile', 'type', 'tenant' ] } );
 
        my @data;
        if ( defined($deliveryservices) ) {
@@ -792,6 +795,7 @@ sub get_deliveryservices_by_userId {
                                        "signed"               => \$row->signed,
                                        "sslKeyVersion"        => 
$row->ssl_key_version,
                                        "tenantId"             => 
$row->tenant_id,
+                                       "tenant"               => defined( 
$row->tenant ) ? $row->tenant->name : undef,
                                        "trRequestHeaders"     => 
$row->tr_request_headers,
                                        "trResponseHeaders"    => 
$row->tr_response_headers,
                                        "type"                 => 
$row->type->name,

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/79349536/traffic_ops/app/lib/API/Deliveryservice2.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Deliveryservice2.pm 
b/traffic_ops/app/lib/API/Deliveryservice2.pm
index bce272a..e779080 100644
--- a/traffic_ops/app/lib/API/Deliveryservice2.pm
+++ b/traffic_ops/app/lib/API/Deliveryservice2.pm
@@ -130,7 +130,8 @@ sub delivery_services {
                                        "remapText"                => 
$row->remap_text,
                                        "signed"                   => 
\$row->signed,
                                        "sslKeyVersion"            => 
$row->ssl_key_version,
-                                       "tenantId"                 => 
$row->tenant_id,
+                                       "tenantId"                         => 
$row->tenant_id,
+                                       "tenant"                   => defined( 
$row->tenant ) ? $row->tenant->name : undef,
                                        "trRequestHeaders"         => 
$row->tr_request_headers,
                                        "trResponseHeaders"        => 
$row->tr_response_headers,
                                        "type"                     => 
$row->type->name,
@@ -151,7 +152,7 @@ sub get_delivery_services_by_user {
        my $tm_user_id;
        my $rs;
        if ( &is_privileged($self) ) {
-               $rs = $self->db->resultset('Deliveryservice')->search( undef, { 
prefetch => [ 'cdn', 'deliveryservice_regexes' ], order_by => 'xml_id' } );
+               $rs = $self->db->resultset('Deliveryservice')->search( undef, { 
prefetch => [ 'cdn', 'deliveryservice_regexes', 'tenant' ], order_by => 
'xml_id' } );
        }
        else {
                my $tm_user = $self->db->resultset('TmUser')->search( { 
username => $current_user } )->single();
@@ -159,7 +160,7 @@ sub get_delivery_services_by_user {
 
                my @ds_ids = 
$self->db->resultset('DeliveryserviceTmuser')->search( { tm_user_id => 
$tm_user_id } )->get_column('deliveryservice')->all();
                $rs = $self->db->resultset('Deliveryservice')
-                       ->search( { 'me.id' => { -in => \@ds_ids } }, { 
prefetch => [ 'cdn', 'deliveryservice_regexes' ], order_by => 'xml_id' } );
+                       ->search( { 'me.id' => { -in => \@ds_ids } }, { 
prefetch => [ 'cdn', 'deliveryservice_regexes', 'tenant' ], order_by => 
'xml_id' } );
        }
 
        return ( $rs, $tm_user_id );
@@ -186,7 +187,7 @@ sub get_delivery_service_params {
                        $condition = ( { 'me.logs_enabled' => $logs_enabled } );
                }
                $rs =
-                       $self->db->resultset('Deliveryservice')->search( 
$condition, { prefetch => [ 'cdn', 'deliveryservice_regexes' ], order_by => 
'xml_id' } );
+                       $self->db->resultset('Deliveryservice')->search( 
$condition, { prefetch => [ 'cdn', 'deliveryservice_regexes', 'tenant' ], 
order_by => 'xml_id' } );
        }
        elsif ( $self->is_delivery_service_assigned($id) ) {
                my $tm_user = $self->db->resultset('TmUser')->search( { 
username => $current_user } )->single();
@@ -197,7 +198,7 @@ sub get_delivery_service_params {
                        ->all();
                $rs =
                        $self->db->resultset('Deliveryservice')
-                       ->search( { 'me.id' => { -in => \@ds_ids } }, { 
prefetch => [ 'cdn', 'deliveryservice_regexes' ], order_by => 'xml_id' } );
+                       ->search( { 'me.id' => { -in => \@ds_ids } }, { 
prefetch => [ 'cdn', 'deliveryservice_regexes', 'tenant' ], order_by => 
'xml_id' } );
        }
        elsif ( !$self->is_delivery_service_assigned($id) ) {
                $forbidden = "true";

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/79349536/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 609718e..7226968 100644
--- a/traffic_ops/app/t/api/1.2/deliveryservice.t
+++ b/traffic_ops/app/t/api/1.2/deliveryservice.t
@@ -90,6 +90,7 @@ ok 
$t->get_ok("/api/1.2/deliveryservices/list?logsEnabled=true")->status_is(200)
                ->json_is( "/response/0/ipv6RoutingEnabled", 1 )
                ->json_is( "/response/1/xmlId", "test-ds1-root" )
                ->json_is( "/response/1/tenantId", 10**9 )
+               ->json_is( "/response/1/tenant", "root" )
                ->json_is( "/response/2/xmlId", "test-ds4" );
 
 # It creates new delivery services

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/79349536/traffic_ops/app/t/api/1.2/deliveryservice_crud.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/deliveryservice_crud.t 
b/traffic_ops/app/t/api/1.2/deliveryservice_crud.t
index dac05e9..b42f311 100644
--- a/traffic_ops/app/t/api/1.2/deliveryservice_crud.t
+++ b/traffic_ops/app/t/api/1.2/deliveryservice_crud.t
@@ -42,7 +42,7 @@ sub run_ut {
        Test::TestHelper->load_core_data($schema);
 
        my $tenant_id = $schema->resultset('TmUser')->find( { username => 
$login_user } )->get_column('tenant_id');
-       my $tenant_name = defined ($tenant_id) ? 
$schema->resultset('Tenant')->find( { id => $tenant_id } )->get_column('name') 
: "null";
+       my $tenant_name = defined ($tenant_id) ? 
$schema->resultset('Tenant')->find( { id => $tenant_id } )->get_column('name') 
: undef;
 
        ok $t->post_ok( '/login', => form => { u => $login_user, p => 
$login_password } )->status_is(302)
                ->or( sub { diag $t->tx->res->content->asset->{content}; } ), 
'Should login?';
@@ -101,6 +101,7 @@ sub run_ut {
            ->json_is( "/response/0/orgServerFqdn" => "http://10.75.168.91";)
            ->json_is( "/response/0/cdnId" => 100)
            ->json_is( "/response/0/tenantId" => $tenant_id)
+           ->json_is( "/response/0/tenant" => $tenant_name)
            ->json_is( "/response/0/profileId" => 300)
            ->json_is( "/response/0/protocol" => "1")
            ->json_is( "/response/0/typeId" => 36)

Reply via email to