You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/05/07 19:55:10 UTC

[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 ( !&is_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) {
+			&log( $self, "Backup configuration DELETED", "APICHANGE");
+			return $self->success_message("Backup configuration DELETED");
+		} else {
+			return $self->alert( "Backup configuration DELETED." );
+		}
+	} else {
+		&log( $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+?$/ ) {
+		&log( $self, "No such Cachegroup id $id");
+		return $self->not_found();
+	}
+
+	my $cachegroup = $self->db->resultset('Cachegroup')->search( { id => $id } )->single();
+	if ( !defined($cachegroup) ) {
+		&log( $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:
users@infra.apache.org


With regards,
Apache Git Services