[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r188317346 ## File path: traffic_ops/app/db/migrations/2018032100_cache_group_fallback.sql ## @@ -0,0 +1,38 @@ +/* + Review comment: this migration won't work. the date is too old. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r188315094 ## File path: traffic_ops/app/lib/UI/Topology.pm ## @@ -250,6 +250,15 @@ sub gen_crconfig_json { if ( $row->type->name =~ m/^EDGE/ ) { $data_obj->{'edgeLocations'}->{ $row->cachegroup->name }->{'latitude'} = $row->cachegroup->latitude + 0; $data_obj->{'edgeLocations'}->{ $row->cachegroup->name }->{'longitude'} = $row->cachegroup->longitude + 0; +$data_obj->{'edgeLocations'}->{ $row->cachegroup->name }->{'backupLocations'}->{'fallbackToClosest'} = $row->cachegroup->fallback_to_closest ? "true" : "false"; + +my $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $row->cachegroup->id}, {order_by => 'set_order'}); Review comment: gen_crconfig_json was rewritten in Golang so this logic will need to be added there as well otherwise it will be lost. You might want to reach out to @rob05c This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r186729232 ## File path: traffic_ops/app/lib/API/CachegroupFallback.pm ## @@ -0,0 +1,283 @@ +package API::CachegroupFallback; +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# a note about locations and cachegroups. This used to be "Location", before we had physical locations in 12M. Very confusing. +# What used to be called a location is now called a "cache group" and location is now a physical address, not a group of caches working together. +# + +# JvD Note: you always want to put Utils as the first use. Sh*t don't work if it's after the Mojo lines. +use UI::Utils; +use Mojo::Base 'Mojolicious::Controller'; +use Data::Dumper; +use JSON; +use MojoPlugins::Response; +use Validate::Tiny ':all'; + +sub delete { + my $self = shift; + my $cache_id = $self->param('cacheGroupId'); + my $fallback_id = $self->param('fallbackId'); + my $params = $self->req->json; + my $rs_backups = undef; + + if ( !_oper($self) ) { + return $self->forbidden(); + } + + if ( defined ($cache_id) && defined($fallback_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id , backup_cg => $fallback_id} ); + } elsif (defined ($cache_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id} ); + } elsif (defined ($fallback_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { backup_cg => $fallback_id} ); + } + + if ( ($rs_backups->count > 0) ) { + my $del_records = $rs_backups->delete(); + if ($del_records) { + ( $self, "Backup configuration DELETED", "APICHANGE"); + return $self->success_message("Backup configuration DELETED"); + } else { + return $self->alert( "Backup configuration DELETED." ); + } + } else { + ( $self, "No backup Cachegroups found"); + return $self->not_found(); + } +} + +sub show { + my $self = shift; + my $cache_id = $self->param("cacheGroupId"); + my $fallback_id = $self->param("fallbackId"); + my $id = $cache_id ? $cache_id : $fallback_id; + + #only integers + if ( $id !~ /^\d+?$/ ) { + ( $self, "No such Cachegroup id $id"); + return $self->not_found(); + } + + my $cachegroup = $self->db->resultset('Cachegroup')->search( { id => $id } )->single(); + if ( !defined($cachegroup) ) { + ( $self, "No such Cachegroup $id"); + return $self->not_found(); + } + + if ( ($cachegroup->type->name ne "EDGE_LOC") ) { + return $self->alert("cachegroup should be type EDGE_LOC."); + } + + my $rs_backups = undef; + + if ( defined ($cache_id) && defined ($fallback_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $cache_id, backup_cg => $fallback_id}, {order_by => 'set_order'}); + } elsif ( defined ($cache_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $cache_id}, {order_by => 'set_order'}); + } elsif ( defined ($fallback_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ backup_cg => $fallback_id}, {order_by => 'set_order'}); + } + + if ( defined ($rs_backups) && ($rs_backups->count > 0) ) { Review comment: to ensure we have a consistent API, you need to follow the examples of the other apis. If you ask for a list of resources and there are none, an empty array is returned instead of a 404 for example, GET /api/foos?active=true - if there are no active foos, then [] is returned and not 404. 404 implies an invalid resource path. /api/foos?active=true is a valid resource path, there just happens to be no active foos. this on the other hand would result in a 404: GET /api/foos/777/bars <-- in this case there is no foo with id=777, so 404 would be valid. This is an
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r186728056 ## File path: traffic_ops/app/lib/API/CachegroupFallback.pm ## @@ -0,0 +1,283 @@ +package API::CachegroupFallback; +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# a note about locations and cachegroups. This used to be "Location", before we had physical locations in 12M. Very confusing. +# What used to be called a location is now called a "cache group" and location is now a physical address, not a group of caches working together. +# + +# JvD Note: you always want to put Utils as the first use. Sh*t don't work if it's after the Mojo lines. +use UI::Utils; +use Mojo::Base 'Mojolicious::Controller'; +use Data::Dumper; +use JSON; +use MojoPlugins::Response; +use Validate::Tiny ':all'; + +sub delete { + my $self = shift; + my $cache_id = $self->param('cacheGroupId'); + my $fallback_id = $self->param('fallbackId'); + my $params = $self->req->json; + my $rs_backups = undef; + + if ( !_oper($self) ) { + return $self->forbidden(); + } + + if ( defined ($cache_id) && defined($fallback_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id , backup_cg => $fallback_id} ); + } elsif (defined ($cache_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id} ); + } elsif (defined ($fallback_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { backup_cg => $fallback_id} ); + } + + if ( ($rs_backups->count > 0) ) { + my $del_records = $rs_backups->delete(); + if ($del_records) { + ( $self, "Backup configuration DELETED", "APICHANGE"); + return $self->success_message("Backup configuration DELETED"); + } else { + return $self->alert( "Backup configuration DELETED." ); + } + } else { + ( $self, "No backup Cachegroups found"); + return $self->not_found(); + } +} + +sub show { + my $self = shift; + my $cache_id = $self->param("cacheGroupId"); + my $fallback_id = $self->param("fallbackId"); + my $id = $cache_id ? $cache_id : $fallback_id; + + #only integers + if ( $id !~ /^\d+?$/ ) { + ( $self, "No such Cachegroup id $id"); + return $self->not_found(); + } + + my $cachegroup = $self->db->resultset('Cachegroup')->search( { id => $id } )->single(); + if ( !defined($cachegroup) ) { + ( $self, "No such Cachegroup $id"); + return $self->not_found(); + } + + if ( ($cachegroup->type->name ne "EDGE_LOC") ) { + return $self->alert("cachegroup should be type EDGE_LOC."); + } + + my $rs_backups = undef; + + if ( defined ($cache_id) && defined ($fallback_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $cache_id, backup_cg => $fallback_id}, {order_by => 'set_order'}); + } elsif ( defined ($cache_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $cache_id}, {order_by => 'set_order'}); + } elsif ( defined ($fallback_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ backup_cg => $fallback_id}, {order_by => 'set_order'}); + } + + if ( defined ($rs_backups) && ($rs_backups->count > 0) ) { + my $response; + my $backup_cnt = 0; + while ( my $row = $rs_backups->next ) { + $response->[$backup_cnt]{"cacheGroupId"} = $row->primary_cg->id; + $response->[$backup_cnt]{"cacheGroupName"} = $row->primary_cg->name; + $response->[$backup_cnt]{"fallbackName"} = $row->backup_cg->name; + $response->[$backup_cnt]{"fallbackId"} = $row->backup_cg->id; + $response->[$backup_cnt]{"fallbackOrder"} = $row->set_order; + $backup_cnt++; + } + return $self->success( $response ); + } else { +
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r186530252 ## File path: traffic_ops/app/lib/API/CachegroupFallback.pm ## @@ -0,0 +1,283 @@ +package API::CachegroupFallback; +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# a note about locations and cachegroups. This used to be "Location", before we had physical locations in 12M. Very confusing. +# What used to be called a location is now called a "cache group" and location is now a physical address, not a group of caches working together. +# + +# JvD Note: you always want to put Utils as the first use. Sh*t don't work if it's after the Mojo lines. +use UI::Utils; +use Mojo::Base 'Mojolicious::Controller'; +use Data::Dumper; +use JSON; +use MojoPlugins::Response; +use Validate::Tiny ':all'; + +sub delete { + my $self = shift; + my $cache_id = $self->param('cacheGroupId'); + my $fallback_id = $self->param('fallbackId'); + my $params = $self->req->json; + my $rs_backups = undef; + + if ( !_oper($self) ) { + return $self->forbidden(); + } + + if ( defined ($cache_id) && defined($fallback_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id , backup_cg => $fallback_id} ); + } elsif (defined ($cache_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id} ); + } elsif (defined ($fallback_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { backup_cg => $fallback_id} ); + } + + if ( ($rs_backups->count > 0) ) { + my $del_records = $rs_backups->delete(); + if ($del_records) { + ( $self, "Backup configuration DELETED", "APICHANGE"); + return $self->success_message("Backup configuration DELETED"); + } else { + return $self->alert( "Backup configuration DELETED." ); + } + } else { + ( $self, "No backup Cachegroups found"); + return $self->not_found(); + } +} + +sub show { + my $self = shift; + my $cache_id = $self->param("cacheGroupId"); + my $fallback_id = $self->param("fallbackId"); + my $id = $cache_id ? $cache_id : $fallback_id; + + #only integers + if ( $id !~ /^\d+?$/ ) { + ( $self, "No such Cachegroup id $id"); + return $self->not_found(); + } + + my $cachegroup = $self->db->resultset('Cachegroup')->search( { id => $id } )->single(); + if ( !defined($cachegroup) ) { + ( $self, "No such Cachegroup $id"); + return $self->not_found(); + } + + if ( ($cachegroup->type->name ne "EDGE_LOC") ) { + return $self->alert("cachegroup should be type EDGE_LOC."); + } + + my $rs_backups = undef; + + if ( defined ($cache_id) && defined ($fallback_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $cache_id, backup_cg => $fallback_id}, {order_by => 'set_order'}); + } elsif ( defined ($cache_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $cache_id}, {order_by => 'set_order'}); + } elsif ( defined ($fallback_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ backup_cg => $fallback_id}, {order_by => 'set_order'}); + } + + if ( defined ($rs_backups) && ($rs_backups->count > 0) ) { Review comment: just return an empty array if count=0. don't return a 404 ($self->not_found()) This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r186530205 ## File path: traffic_ops/app/lib/API/CachegroupFallback.pm ## @@ -0,0 +1,283 @@ +package API::CachegroupFallback; +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# a note about locations and cachegroups. This used to be "Location", before we had physical locations in 12M. Very confusing. +# What used to be called a location is now called a "cache group" and location is now a physical address, not a group of caches working together. +# + +# JvD Note: you always want to put Utils as the first use. Sh*t don't work if it's after the Mojo lines. +use UI::Utils; +use Mojo::Base 'Mojolicious::Controller'; +use Data::Dumper; +use JSON; +use MojoPlugins::Response; +use Validate::Tiny ':all'; + +sub delete { + my $self = shift; + my $cache_id = $self->param('cacheGroupId'); + my $fallback_id = $self->param('fallbackId'); + my $params = $self->req->json; + my $rs_backups = undef; + + if ( !_oper($self) ) { + return $self->forbidden(); + } + + if ( defined ($cache_id) && defined($fallback_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id , backup_cg => $fallback_id} ); + } elsif (defined ($cache_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id} ); + } elsif (defined ($fallback_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search( { backup_cg => $fallback_id} ); + } + + if ( ($rs_backups->count > 0) ) { + my $del_records = $rs_backups->delete(); + if ($del_records) { + ( $self, "Backup configuration DELETED", "APICHANGE"); + return $self->success_message("Backup configuration DELETED"); + } else { + return $self->alert( "Backup configuration DELETED." ); + } + } else { + ( $self, "No backup Cachegroups found"); + return $self->not_found(); + } +} + +sub show { + my $self = shift; + my $cache_id = $self->param("cacheGroupId"); + my $fallback_id = $self->param("fallbackId"); + my $id = $cache_id ? $cache_id : $fallback_id; + + #only integers + if ( $id !~ /^\d+?$/ ) { + ( $self, "No such Cachegroup id $id"); + return $self->not_found(); + } + + my $cachegroup = $self->db->resultset('Cachegroup')->search( { id => $id } )->single(); + if ( !defined($cachegroup) ) { + ( $self, "No such Cachegroup $id"); + return $self->not_found(); + } + + if ( ($cachegroup->type->name ne "EDGE_LOC") ) { + return $self->alert("cachegroup should be type EDGE_LOC."); + } + + my $rs_backups = undef; + + if ( defined ($cache_id) && defined ($fallback_id)) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $cache_id, backup_cg => $fallback_id}, {order_by => 'set_order'}); + } elsif ( defined ($cache_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $cache_id}, {order_by => 'set_order'}); + } elsif ( defined ($fallback_id) ) { + $rs_backups = $self->db->resultset('CachegroupFallback')->search({ backup_cg => $fallback_id}, {order_by => 'set_order'}); + } + + if ( defined ($rs_backups) && ($rs_backups->count > 0) ) { + my $response; + my $backup_cnt = 0; + while ( my $row = $rs_backups->next ) { + $response->[$backup_cnt]{"cacheGroupId"} = $row->primary_cg->id; + $response->[$backup_cnt]{"cacheGroupName"} = $row->primary_cg->name; + $response->[$backup_cnt]{"fallbackName"} = $row->backup_cg->name; + $response->[$backup_cnt]{"fallbackId"} = $row->backup_cg->id; + $response->[$backup_cnt]{"fallbackOrder"} = $row->set_order; + $backup_cnt++; + } + return $self->success( $response ); + } else { +
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r184154970 ## File path: traffic_ops/app/lib/API/CachegroupFallback.pm ## @@ -0,0 +1,208 @@ +package API::CachegroupFallback; +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# a note about locations and cachegroups. This used to be "Location", before we had physical locations in 12M. Very confusing. +# What used to be called a location is now called a "cache group" and location is now a physical address, not a group of caches working together. +# + +# JvD Note: you always want to put Utils as the first use. Sh*t don't work if it's after the Mojo lines. +use UI::Utils; +use Mojo::Base 'Mojolicious::Controller'; +use Data::Dumper; +use JSON; +use MojoPlugins::Response; +use Validate::Tiny ':all'; + +sub delete { + my $self = shift; + my $cache_id = $self->param('cacheGroupId'); + my $params = $self->req->json; + + if ( !_oper($self) ) { + return $self->forbidden(); + } + + #only integers + if ( $cache_id !~ /^\d+?$/ ) { + ( $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) ) { + ( $self, "No such Cachegroup $cache_id"); + return $self->not_found(); + } + + if ( ($cachegroup->type->name ne "EDGE_LOC") ) { + return $self->alert("cachegroup should be type EDGE_LOC."); + } + + my $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id } ); + if ( ($rs_backups->count > 0) ) { + my $del_records = $rs_backups->delete(); + if ($del_records) { + ( $self, "Backup configuration for cache group $cache_id DELETED", "APICHANGE"); + return $self->success_message("Backup configuration for cache group $cache_id DELETED"); + } else { + return $self->alert( "Backup configuration for cache group $cache_id DELETED." ); + } + } else { + ( $self, "No backup Cachegroups for $cache_id"); + return $self->not_found(); + } +} + +sub show { + my $self = shift; + my $cache_id = $self->param("cacheGroupId"); + my $fallback_id = $self->param("fallbackId"); + my $id = $cache_id ? $cache_id : $fallback_id; + + #only integers + if ( $id !~ /^\d+?$/ ) { + ( $self, "No such Cachegroup id $id"); + return $self->not_found(); + } + + my $cachegroup = $self->db->resultset('Cachegroup')->search( { id => $id } )->single(); + if ( !defined($cachegroup) ) { + ( $self, "No such Cachegroup $id"); + return $self->not_found(); + } + + if ( ($cachegroup->type->name ne "EDGE_LOC") ) { + return $self->alert("cachegroup should be type EDGE_LOC."); + } + + if ( defined ($cache_id) ) { + my $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $cache_id}, {order_by => 'set_order'}); + if ( ($rs_backups->count > 0) ) { + my $response; + my $backup_cnt = 0; + while ( my $row = $rs_backups->next ) { + $response->[$backup_cnt]{"cacheGroupId"} = $cache_id; + $response->[$backup_cnt]{"cacheGroupName"} = $row->primary_cg->name; + $response->[$backup_cnt]{"fallbackName"} = $row->backup_cg->name; + $response->[$backup_cnt]{"fallbackId"} = $row->backup_cg->id; + $response->[$backup_cnt]{"fallbackOrder"} = $row->set_order; + $backup_cnt++; + } + return $self->success( $response ); + } else { + ( $self, "No backup Cachegroups for $cache_id"); + return
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r184150958 ## File path: docs/source/development/traffic_ops_api/v12/cachegroup_fallbacks.rst ## @@ -0,0 +1,209 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +.. _to-api-v12-cachegroupfallbacks: + +Cache Group Fallback + + +.. _to-api-v12-cachegroupfallbacks-route: + +/api/1.2/cachegroup_fallbacks +++ + +**GET /api/1.2/cachegroup_fallbacks** + + Retrieve fallback related configurations for a cache group. + + Authentication Required: Yes + + Role(s) Required: None + + **Request Query Parameters** + + Query parameter is mandatory. Either one of the parameters must be used. Both cant be used simultaneously. Review comment: Can i send through both query params to fetch ONE record? the ability to fetch one record is something all our other endpoints support. I.e. GET /api/1.2/cachegroup_fallbacks?cacheGroupId== This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r184154970 ## File path: traffic_ops/app/lib/API/CachegroupFallback.pm ## @@ -0,0 +1,208 @@ +package API::CachegroupFallback; +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# a note about locations and cachegroups. This used to be "Location", before we had physical locations in 12M. Very confusing. +# What used to be called a location is now called a "cache group" and location is now a physical address, not a group of caches working together. +# + +# JvD Note: you always want to put Utils as the first use. Sh*t don't work if it's after the Mojo lines. +use UI::Utils; +use Mojo::Base 'Mojolicious::Controller'; +use Data::Dumper; +use JSON; +use MojoPlugins::Response; +use Validate::Tiny ':all'; + +sub delete { + my $self = shift; + my $cache_id = $self->param('cacheGroupId'); + my $params = $self->req->json; + + if ( !_oper($self) ) { + return $self->forbidden(); + } + + #only integers + if ( $cache_id !~ /^\d+?$/ ) { + ( $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) ) { + ( $self, "No such Cachegroup $cache_id"); + return $self->not_found(); + } + + if ( ($cachegroup->type->name ne "EDGE_LOC") ) { + return $self->alert("cachegroup should be type EDGE_LOC."); + } + + my $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id } ); + if ( ($rs_backups->count > 0) ) { + my $del_records = $rs_backups->delete(); + if ($del_records) { + ( $self, "Backup configuration for cache group $cache_id DELETED", "APICHANGE"); + return $self->success_message("Backup configuration for cache group $cache_id DELETED"); + } else { + return $self->alert( "Backup configuration for cache group $cache_id DELETED." ); + } + } else { + ( $self, "No backup Cachegroups for $cache_id"); + return $self->not_found(); + } +} + +sub show { + my $self = shift; + my $cache_id = $self->param("cacheGroupId"); + my $fallback_id = $self->param("fallbackId"); + my $id = $cache_id ? $cache_id : $fallback_id; + + #only integers + if ( $id !~ /^\d+?$/ ) { + ( $self, "No such Cachegroup id $id"); + return $self->not_found(); + } + + my $cachegroup = $self->db->resultset('Cachegroup')->search( { id => $id } )->single(); + if ( !defined($cachegroup) ) { + ( $self, "No such Cachegroup $id"); + return $self->not_found(); + } + + if ( ($cachegroup->type->name ne "EDGE_LOC") ) { + return $self->alert("cachegroup should be type EDGE_LOC."); + } + + if ( defined ($cache_id) ) { + my $rs_backups = $self->db->resultset('CachegroupFallback')->search({ primary_cg => $cache_id}, {order_by => 'set_order'}); + if ( ($rs_backups->count > 0) ) { + my $response; + my $backup_cnt = 0; + while ( my $row = $rs_backups->next ) { + $response->[$backup_cnt]{"cacheGroupId"} = $cache_id; + $response->[$backup_cnt]{"cacheGroupName"} = $row->primary_cg->name; + $response->[$backup_cnt]{"fallbackName"} = $row->backup_cg->name; + $response->[$backup_cnt]{"fallbackId"} = $row->backup_cg->id; + $response->[$backup_cnt]{"fallbackOrder"} = $row->set_order; + $backup_cnt++; + } + return $self->success( $response ); + } else { + ( $self, "No backup Cachegroups for $cache_id"); + return
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r184152943 ## File path: traffic_ops/app/lib/API/Cachegroup.pm ## @@ -164,6 +166,7 @@ sub update { latitude => $params->{latitude}, longitude => $params->{longitude}, parent_cachegroup_id => $params->{parentCachegroupId}, + fallback_to_closest=> $params->{fallbackToClosest}, Review comment: fallbackToClosest needs to be added to the Traffic Portal form.cacheGroup.tpl.html This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r184152042 ## File path: docs/source/development/traffic_ops_api/v12/cachegroup_fallbacks.rst ## @@ -0,0 +1,209 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +.. _to-api-v12-cachegroupfallbacks: + +Cache Group Fallback + + +.. _to-api-v12-cachegroupfallbacks-route: + +/api/1.2/cachegroup_fallbacks +++ + +**GET /api/1.2/cachegroup_fallbacks** + + Retrieve fallback related configurations for a cache group. + + Authentication Required: Yes + + Role(s) Required: None + + **Request Query Parameters** + + Query parameter is mandatory. Either one of the parameters must be used. Both cant be used simultaneously. + + +-+---+ + | Name| Description | + +=+===+ + | cacheGroupId| The id of the cache group whose backup configurations has to be retrieved | + +-+---+ + | fallbackId | The id of the fallback cache group associated with a cache group | + +-+---+ + + **Response Properties** + + +---++--+ + | Parameter | Type | Description | + +===++==+ + | | array | parameters array | + +---++--+ + | ``>cacheGroupId`` | int| Cache group id | + +---++--+ + | ``>fallbackId`` | int| fallback cache group id | + +---++--+ + | ``>cacheGroupName`` | string | Cache group name | + +---++--+ + | ``>fallbackName`` | string | Fallback cache group name | + +---++--+ + | ``>fallbackOrder``| int| Ordering list in the list of backups | + +---++--+ + + **Response Example** :: + +{ + "response": [ + { + "cacheGroupId":1, + "cacheGroupName":"GROUP1", + "fallbackId":2, + "fallbackOrder":10, + "fallbackName":"GROUP2" + } + ] +} + +| + +**POST /api/1.2/cachegroup_fallbacks** + + Creates/ Updates fallback list for the cache group. + + Authentication Required: Yes + + Role(s) Required: admin or oper + + **Request Query Parameters** + + + +-+--+-+ + | Name| Required | Description | + +=+==+=+ + | cacheGroupId| Yes | The id of the cache group for which backup configurations has to be updated | +
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r184151465 ## File path: docs/source/development/traffic_ops_api/v12/cachegroup_fallbacks.rst ## @@ -0,0 +1,209 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +.. _to-api-v12-cachegroupfallbacks: + +Cache Group Fallback + + +.. _to-api-v12-cachegroupfallbacks-route: + +/api/1.2/cachegroup_fallbacks +++ + +**GET /api/1.2/cachegroup_fallbacks** + + Retrieve fallback related configurations for a cache group. + + Authentication Required: Yes + + Role(s) Required: None + + **Request Query Parameters** + + Query parameter is mandatory. Either one of the parameters must be used. Both cant be used simultaneously. + + +-+---+ + | Name| Description | + +=+===+ + | cacheGroupId| The id of the cache group whose backup configurations has to be retrieved | + +-+---+ + | fallbackId | The id of the fallback cache group associated with a cache group | + +-+---+ + + **Response Properties** + + +---++--+ + | Parameter | Type | Description | + +===++==+ + | | array | parameters array | + +---++--+ + | ``>cacheGroupId`` | int| Cache group id | + +---++--+ + | ``>fallbackId`` | int| fallback cache group id | + +---++--+ + | ``>cacheGroupName`` | string | Cache group name | + +---++--+ + | ``>fallbackName`` | string | Fallback cache group name | + +---++--+ + | ``>fallbackOrder``| int| Ordering list in the list of backups | + +---++--+ + + **Response Example** :: + +{ + "response": [ + { + "cacheGroupId":1, + "cacheGroupName":"GROUP1", + "fallbackId":2, + "fallbackOrder":10, + "fallbackName":"GROUP2" + } + ] +} + +| + +**POST /api/1.2/cachegroup_fallbacks** + + Creates/ Updates fallback list for the cache group. Review comment: Can you add a little more detail here. How does this work exactly? Send in an array to the POST. for each item in the array, if doesn't exist, create it. if exists, update it? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r184154400 ## File path: traffic_ops/app/lib/API/CachegroupFallback.pm ## @@ -0,0 +1,208 @@ +package API::CachegroupFallback; +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# a note about locations and cachegroups. This used to be "Location", before we had physical locations in 12M. Very confusing. +# What used to be called a location is now called a "cache group" and location is now a physical address, not a group of caches working together. +# + +# JvD Note: you always want to put Utils as the first use. Sh*t don't work if it's after the Mojo lines. +use UI::Utils; +use Mojo::Base 'Mojolicious::Controller'; +use Data::Dumper; +use JSON; +use MojoPlugins::Response; +use Validate::Tiny ':all'; + +sub delete { + my $self = shift; + my $cache_id = $self->param('cacheGroupId'); + my $params = $self->req->json; + + if ( !_oper($self) ) { + return $self->forbidden(); + } + + #only integers + if ( $cache_id !~ /^\d+?$/ ) { + ( $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) ) { + ( $self, "No such Cachegroup $cache_id"); + return $self->not_found(); + } + + if ( ($cachegroup->type->name ne "EDGE_LOC") ) { + return $self->alert("cachegroup should be type EDGE_LOC."); + } + + my $rs_backups = $self->db->resultset('CachegroupFallback')->search( { primary_cg => $cache_id } ); + if ( ($rs_backups->count > 0) ) { + my $del_records = $rs_backups->delete(); + if ($del_records) { + ( $self, "Backup configuration for cache group $cache_id DELETED", "APICHANGE"); + return $self->success_message("Backup configuration for cache group $cache_id DELETED"); + } else { + return $self->alert( "Backup configuration for cache group $cache_id DELETED." ); + } + } else { + ( $self, "No backup Cachegroups for $cache_id"); + return $self->not_found(); + } +} + +sub show { Review comment: how can i fetch just one row? like this GET /api/1.2/cachegroup_fallbacks?cacheGroupId== This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r181814989 ## File path: docs/source/development/traffic_ops_api/v12/cachegroup_fallbacks.rst ## @@ -0,0 +1,209 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +.. _to-api-v12-cachegroupfallbacks: + +Cache Group Fallback + + +.. _to-api-v12-cachegroupfallbacks-route: + +/api/1.2/cachegroup_fallbacks +++ + +**GET /api/1.2/cachegroup_fallbacks** + + Retrieve fallback related configurations for a cache group. + + Authentication Required: Yes + + Role(s) Required: None + + **Request Query Parameters** + + Query parameter is mandatory. Either one of the parameters must be used. Both cant be used simultaneously. + + +-+---+ + | Name| Description | + +=+===+ + | cacheGroupId| The id of the cache group whose backup configurations has to be retrieved | + +-+---+ + | fallbackId | The id of the fallback cache group associated with a cache group | + +-+---+ + + **Response Properties** + + +---++--+ + | Parameter | Type | Description | + +===++==+ + | | array | parameters array | + +---++--+ + | ``>cacheGroupId`` | int| Cache group id | + +---++--+ + | ``>fallbackId`` | int| fallback cache group id | + +---++--+ + | ``>cacheGroupName`` | string | Cache group name | + +---++--+ + | ``>fallbackName`` | string | Fallback cache group name | + +---++--+ + | ``>fallbackOrder``| int| Ordering list in the list of backups | + +---++--+ + + **Response Example** :: + +{ + "response": [ + { + "cacheGroupId":1, + "cacheGroupName":"GROUP1", + "fallbackId":2, + "fallbackOrder":10, + "fallbackName":"GROUP2" + } + ] +} + +| + +**POST /api/1.2/cachegroup_fallbacks** + + Creates/ Updates fallback list for the cache group. + + Authentication Required: Yes + + Role(s) Required: admin or oper + + **Request Query Parameters** + + + +-+--+-+ + | Name| Required | Description | + +=+==+=+ + | cacheGroupId| Yes | The id of the cache group for which backup configurations has to be updated | +
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r181815969 ## File path: traffic_ops/app/lib/API/Cachegroup.pm ## @@ -164,6 +166,7 @@ sub update { latitude => $params->{latitude}, longitude => $params->{longitude}, parent_cachegroup_id => $params->{parentCachegroupId}, + fallback_to_closest=> $params->{fallbackToClosest}, Review comment: Because this field was not added to Traffic Portal, users of the TP will always be setting this to null when they update a cache group. Is that OK? I think you need to add this field to the Traffic Portal - form.cacheGroup.tpl.html This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r181814018 ## File path: docs/source/development/traffic_ops_api/v12/cachegroup_fallbacks.rst ## @@ -0,0 +1,209 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +.. _to-api-v12-cachegroupfallbacks: + +Cache Group Fallback + + +.. _to-api-v12-cachegroupfallbacks-route: + +/api/1.2/cachegroup_fallbacks +++ + +**GET /api/1.2/cachegroup_fallbacks** + + Retrieve fallback related configurations for a cache group. + + Authentication Required: Yes + + Role(s) Required: None + + **Request Query Parameters** + + Query parameter is mandatory. Either one of the parameters must be used. Both cant be used simultaneously. + + +-+---+ + | Name| Description | + +=+===+ + | cacheGroupId| The id of the cache group whose backup configurations has to be retrieved | + +-+---+ + | fallbackId | The id of the fallback cache group associated with a cache group | + +-+---+ + + **Response Properties** + + +---++--+ + | Parameter | Type | Description | + +===++==+ + | | array | parameters array | + +---++--+ + | ``>cacheGroupId`` | int| Cache group id | + +---++--+ + | ``>fallbackId`` | int| fallback cache group id | + +---++--+ + | ``>cacheGroupName`` | string | Cache group name | + +---++--+ + | ``>fallbackName`` | string | Fallback cache group name | + +---++--+ + | ``>fallbackOrder``| int| Ordering list in the list of backups | + +---++--+ + + **Response Example** :: + +{ + "response": [ + { + "cacheGroupId":1, + "cacheGroupName":"GROUP1", + "fallbackId":2, + "fallbackOrder":10, + "fallbackName":"GROUP2" + } + ] +} + +| + +**POST /api/1.2/cachegroup_fallbacks** + + Creates/ Updates fallback list for the cache group. + + Authentication Required: Yes + + Role(s) Required: admin or oper + + **Request Query Parameters** + + + +-+--+-+ + | Name| Required | Description | + +=+==+=+ + | cacheGroupId| Yes | The id of the cache group for which backup configurations has to be updated | +
[GitHub] mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup
mitchell852 commented on a change in pull request #2029: [Issue 1907] TO API for backup edge cachegroup URL: https://github.com/apache/incubator-trafficcontrol/pull/2029#discussion_r177815754 ## File path: docs/source/development/traffic_ops_api/v12/cachegroup_fallbacks.rst ## @@ -0,0 +1,266 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +.. _to-api-v12-cachegroupfallbacks: + +Cache Group Fallback + + +.. _to-api-v12-cachegroupfallbacks-route: + +/api/1.2/cachegroups/fallbacks +++ + +**GET /api/1.2/cachegroups/:id/fallbacks** + + Authentication Required: Yes + + Role(s) Required: None + + **Response Properties** + + +---++--+ + | Parameter | Type | Description | + +===++==+ + | ``fallbacks`` | string | JSON key to parse fallback list | + +---++--+ + | ``name`` | string | Fallback cache group name | + +---++--+ + | ``order`` | int| Ordering list in the list of backups | + +---++--+ + + **Response Example** :: + +{ + "alerts": [ Review comment: no need for alerts from a GET This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services