You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by el...@apache.org on 2018/06/14 17:10:19 UTC
[trafficcontrol] 04/08: Addressing Rawlin's comment on;
1. Updating the document for cachegroup APIs 2. Validating fallback
inputs
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 91a1ef7a04cfcc847232855240f2a43474aa3c1f
Author: Vijayanand Subramanian <vi...@gmail.com>
AuthorDate: Fri May 25 07:29:11 2018 -0400
Addressing Rawlin's comment on; 1. Updating the document for cachegroup APIs 2. Validating fallback inputs
---
docs/source/api/v12/cachegroup.rst | 35 ++++++++---
traffic_ops/app/lib/API/CachegroupFallback.pm | 83 +++++++++++++++------------
2 files changed, 73 insertions(+), 45 deletions(-)
diff --git a/docs/source/api/v12/cachegroup.rst b/docs/source/api/v12/cachegroup.rst
index 1831f49..2c6d8f9 100644
--- a/docs/source/api/v12/cachegroup.rst
+++ b/docs/source/api/v12/cachegroup.rst
@@ -23,7 +23,7 @@ Cache Group
/api/1.2/cachegroups
++++++++++++++++++++
-**GET /api/1.1/cachegroups**
+**GET /api/1.2/cachegroups**
Authentication Required: Yes
@@ -66,6 +66,8 @@ Cache Group
+-----------------------------------+--------+--------------------------------------------------------------------------+
| ``typeName`` | string | The name of the type of Cache Group entry |
+-----------------------------------+--------+--------------------------------------------------------------------------+
+ | ``fallbackToClosest`` | bool | Behaviour during non-availability/ failure of configured fallbacks |
+ +-----------------------------------+--------+--------------------------------------------------------------------------+
**Response Example** ::
@@ -83,7 +85,8 @@ Cache Group
"secondaryParentCachegroupName": null,
"shortName": "dcchi",
"typeName": "MID_LOC",
- "typeId": "4"
+ "typeId": "4",
+ "fallbackToClosest":true
},
{
"id": "22",
@@ -97,7 +100,8 @@ Cache Group
"secondaryParentCachegroupName": null,
"shortName": "dcchi",
"typeName": "MID_LOC",
- "typeId": "4"
+ "typeId": "4",
+ "fallbackToClosest":false
}
],
}
@@ -168,6 +172,8 @@ Cache Group
+-----------------------------------+--------+--------------------------------------------------------------------------+
| ``typeName`` | string | The name of the type of Cache Group entry |
+-----------------------------------+--------+--------------------------------------------------------------------------+
+ | ``fallbackToClosest`` | bool | Behaviour during non-availability/ failure of configured fallbacks |
+ +-----------------------------------+--------+--------------------------------------------------------------------------+
**Response Example** ::
@@ -185,7 +191,8 @@ Cache Group
"secondaryParentCachegroupName": null,
"shortName": "dcchi",
"typeName": "MID_LOC",
- "typeId": "4"
+ "typeId": "4",
+ "fallbackToClosest":true
}
],
}
@@ -448,6 +455,8 @@ Cache Group
+---------------------------------+----------+-------------------------------------------------------------------+
| ``typeId`` | yes | The type of Cache Group entry, "EDGE_LOC", "MID_LOC" or "ORG_LOC" |
+---------------------------------+----------+-------------------------------------------------------------------+
+ | ``fallbackToClosest`` | no | Behaviour on configured fallbacks failure, true / false |
+ +---------------------------------+----------+-------------------------------------------------------------------+
**Request Example** ::
@@ -457,7 +466,8 @@ Cache Group
"latitude": 12,
"longitude": 45,
"parentCachegroup": "cache_group_mid",
- "typeId": 6
+ "typeId": 6,
+ "fallbackToClosest":true
}
**Response Properties**
@@ -485,6 +495,8 @@ Cache Group
+------------------------------------+--------+-------------------------------------------------------------------+
| ``typeName`` | string | The type of Cache Group entry, "EDGE_LOC", "MID_LOC" or "ORG_LOC" |
+------------------------------------+--------+-------------------------------------------------------------------+
+ | ``fallbackToClosest`` | bool | Behaviour during non-availability/failure of configured fallbacks |
+ +------------------------------------+--------+-------------------------------------------------------------------+
| ``lastUpdated`` | string | The Time / Date this entry was last updated |
+------------------------------------+--------+-------------------------------------------------------------------+
| ``alerts`` | array | A collection of alert messages. |
@@ -514,7 +526,8 @@ Cache Group
'typeName' : 'EDGE_LOC',
'id' : '104',
'parentCachegroupId' : '103',
- 'secondaryParentCachegroupId' : null
+ 'secondaryParentCachegroupId' : null,
+ 'fallbackToClosest':true
}
}
@@ -555,6 +568,8 @@ Cache Group
+---------------------------------+----------+-------------------------------------------------------------------+
| ``typeName`` | yes | The type of Cache Group entry, "EDGE_LOC", "MID_LOC" or "ORG_LOC" |
+---------------------------------+----------+-------------------------------------------------------------------+
+ | ``fallbackToClosest`` | no | Behaviour on configured fallbacks failure, true / false |
+ +---------------------------------+----------+-------------------------------------------------------------------+
**Request Example** ::
@@ -564,7 +579,8 @@ Cache Group
"latitude": 12,
"longitude": 45,
"parentCachegroup": "cache_group_mid",
- "typeName": "EDGE_LOC"
+ "typeName": "EDGE_LOC",
+ "fallbackToClosest":true
}
**Response Properties**
@@ -592,6 +608,8 @@ Cache Group
+------------------------------------+--------+-------------------------------------------------------------------+
| ``typeName`` | string | The type of Cache Group entry, "EDGE_LOC", "MID_LOC" or "ORG_LOC" |
+------------------------------------+--------+-------------------------------------------------------------------+
+ | ``fallbackToClosest`` | bool | Behaviour during non-availability/failure of configured fallbacks |
+ +------------------------------------+--------+-------------------------------------------------------------------+
| ``lastUpdated`` | string | The Time / Date this entry was last updated |
+------------------------------------+--------+-------------------------------------------------------------------+
| ``alerts`` | array | A collection of alert messages. |
@@ -621,7 +639,8 @@ Cache Group
'typeName' : 'EDGE_LOC',
'id' : '104',
'parentCachegroupId' : '103',
- 'secondaryParentCachegroupId' : null
+ 'secondaryParentCachegroupId' : null,
+ 'fallbackToClosest':true
}
}
diff --git a/traffic_ops/app/lib/API/CachegroupFallback.pm b/traffic_ops/app/lib/API/CachegroupFallback.pm
index e0a831f..0dfde46 100644
--- a/traffic_ops/app/lib/API/CachegroupFallback.pm
+++ b/traffic_ops/app/lib/API/CachegroupFallback.pm
@@ -116,32 +116,23 @@ sub create {
my $cache_id = $self->param('cacheGroupId');
my $params = $self->req->json;
- if ( !defined($cache_id)) {
- my @param_array = @{$params};
- $cache_id = $param_array[0]{cacheGroupId};
+ if ( !&is_oper($self) ) {
+ return $self->forbidden();
}
if ( !defined($params) ) {
return $self->alert("parameters must be in JSON format, please check!");
}
- if ( !&is_oper($self) ) {
- return $self->forbidden();
- }
-
- #only integers
- if ( $cache_id !~ /^\d+?$/ ) {
- &log( $self, "No such Cachegroup id $cache_id");
- return $self->not_found();
+ if ( !defined($cache_id)) {
+ my @param_array = @{$params};
+ $cache_id = $param_array[0]{cacheGroupId};
}
- my $cachegroup = $self->db->resultset('Cachegroup')->search( { id => $cache_id } )->single();
- if ( !defined($cachegroup) ) {
- return $self->not_found();
- }
+ my ( $is_valid, $result ) = $self->is_valid_cachegroup_fallback($params, $cache_id);
- if ( ($cachegroup->type->name ne "EDGE_LOC") ) {
- return $self->alert("cachegroup should be type EDGE_LOC.");
+ if ( !$is_valid ) {
+ return $self->alert($result);
}
foreach my $config (@{ $params }) {
@@ -198,32 +189,17 @@ sub update {
my $cache_id = $self->param('cacheGroupId');
my $params = $self->req->json;
- if ( !defined($cache_id)) {
- my @param_array = @{$params};
- $cache_id = $param_array[0]{cacheGroupId};
- }
-
- if ( !defined($params) ) {
- return $self->alert("parameters must be in JSON format, please check!");
- }
-
if ( !&is_oper($self) ) {
return $self->forbidden();
}
- #only integers
- if ( $cache_id !~ /^\d+?$/ ) {
- &log( $self, "No such Cachegroup id $cache_id");
- return $self->not_found();
- }
-
- my $cachegroup = $self->db->resultset('Cachegroup')->search( { id => $cache_id } )->single();
- if ( !defined($cachegroup) ) {
- return $self->not_found();
+ if ( !defined($params) ) {
+ return $self->alert("parameters must be in JSON format, please check!");
}
- if ( ($cachegroup->type->name ne "EDGE_LOC") ) {
- return $self->alert("cachegroup should be type EDGE_LOC.");
+ if ( !defined($cache_id)) {
+ my @param_array = @{$params};
+ $cache_id = $param_array[0]{cacheGroupId};
}
my $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id } );
@@ -231,6 +207,12 @@ sub update {
return $self->alert( "Backup list not configured for $cache_id, create and update" );
}
+ my ( $is_valid, $result ) = $self->is_valid_cachegroup_fallback($params, $cache_id);
+
+ if ( !$is_valid ) {
+ return $self->alert($result);
+ }
+
foreach my $config (@{ $params }) {
my $rs_backup = $self->db->resultset('Cachegroup')->search( { id => $config->{fallbackId} } )->single();
if ( !defined($rs_backup) ) {
@@ -275,4 +257,31 @@ sub update {
}
}
+sub is_valid_cachegroup_fallback {
+ my $self = shift;
+ my $params = shift;
+ my $cache_id = shift;
+
+ if ( $cache_id !~ /^\d+?$/ ) {
+ return ( 0, "Invalid cachegroup id" );
+ }
+
+ my $cachegroup = $self->db->resultset('Cachegroup')->search( { id => $cache_id } )->single();
+ if ( !defined($cachegroup) ) {
+ return ( 0, "Invalid cachegroup id, should be an integer" );
+ }
+
+ if ( ($cachegroup->type->name ne "EDGE_LOC") ) {
+ return ( 0, "cachegroup is not of type EDGE_LOC" );
+ }
+
+ foreach my $config (@{ $params }) {
+ if ( $config->{fallbackId} !~ /^\d+?$/ ) {
+ return ( 0, "Invalid cachegroup specified as fallback, should be an integer" );
+ }
+ }
+
+ return ( 1, "success" );
+}
+
1;
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.