removes duplicate cachegroup apis
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/aed7f17e Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/aed7f17e Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/aed7f17e Branch: refs/heads/master Commit: aed7f17e83c0d4b037958a0e5e0d54fc3a8a96e2 Parents: ebaa014 Author: Jeremy Mitchell <[email protected]> Authored: Wed Apr 19 10:03:34 2017 -0600 Committer: Dewayne Richardson <[email protected]> Committed: Thu Jul 13 14:52:07 2017 -0600 ---------------------------------------------------------------------- .../traffic_ops_api/v12/cachegroup.rst | 4 +- traffic_ops/app/lib/API/Cachegroup2.pm | 383 ------------------- traffic_ops/app/t/api/1.2/cachegroup.t | 175 ++++----- traffic_ops/app/t/api/1.2/server.t | 60 +-- 4 files changed, 110 insertions(+), 512 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/aed7f17e/docs/source/development/traffic_ops_api/v12/cachegroup.rst ---------------------------------------------------------------------- diff --git a/docs/source/development/traffic_ops_api/v12/cachegroup.rst b/docs/source/development/traffic_ops_api/v12/cachegroup.rst index aefc466..1831f49 100644 --- a/docs/source/development/traffic_ops_api/v12/cachegroup.rst +++ b/docs/source/development/traffic_ops_api/v12/cachegroup.rst @@ -446,7 +446,7 @@ Cache Group +---------------------------------+----------+-------------------------------------------------------------------+ | ``secondaryParentCachegroup`` | no | Name of Secondary Parent Cache Group entry. | +---------------------------------+----------+-------------------------------------------------------------------+ - | ``typeName`` | yes | The type of Cache Group entry, "EDGE_LOC", "MID_LOC" or "ORG_LOC" | + | ``typeId`` | yes | The type of Cache Group entry, "EDGE_LOC", "MID_LOC" or "ORG_LOC" | +---------------------------------+----------+-------------------------------------------------------------------+ **Request Example** :: @@ -457,7 +457,7 @@ Cache Group "latitude": 12, "longitude": 45, "parentCachegroup": "cache_group_mid", - "typeName": "EDGE_LOC" + "typeId": 6 } **Response Properties** http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/aed7f17e/traffic_ops/app/lib/API/Cachegroup2.pm ---------------------------------------------------------------------- diff --git a/traffic_ops/app/lib/API/Cachegroup2.pm b/traffic_ops/app/lib/API/Cachegroup2.pm deleted file mode 100644 index fa6b1ab..0000000 --- a/traffic_ops/app/lib/API/Cachegroup2.pm +++ /dev/null @@ -1,383 +0,0 @@ -package API::Cachegroup2; -# -# -# 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; - -# Read -sub index { - my $self = shift; - my @data; - my %idnames; - my $orderby = $self->param('orderby') || "name"; - - # Can't figure out how to do the join on the same table - my $rs_idnames = $self->db->resultset("Cachegroup")->search( undef, { columns => [qw/id name/] } ); - while ( my $row = $rs_idnames->next ) { - $idnames{ $row->id } = $row->name; - } - - my $rs_data = $self->db->resultset("Cachegroup")->search( undef, { prefetch => [ { 'type' => undef, } ], order_by => 'me.' . $orderby } ); - while ( my $row = $rs_data->next ) { - if ( defined $row->parent_cachegroup_id ) { - push( - @data, { - "id" => $row->id, - "name" => $row->name, - "shortName" => $row->short_name, - "latitude" => $row->latitude, - "longitude" => $row->longitude, - "lastUpdated" => $row->last_updated, - "parentCachegroupId" => $row->parent_cachegroup_id, - "parentCachegroupName" => $idnames{ $row->parent_cachegroup_id }, - "typeId" => $row->type->id, - "typeName" => $row->type->name, - } - ); - } - else { - push( - @data, { - "id" => $row->id, - "name" => $row->name, - "shortName" => $row->short_name, - "latitude" => $row->latitude, - "longitude" => $row->longitude, - "lastUpdated" => $row->last_updated, - "parentCachegroupId" => $row->parent_cachegroup_id, - "parentCachegroupName" => undef, - "typeId" => $row->type->id, - "typeName" => $row->type->name, - } - ); - } - } - $self->success( \@data ); -} - -sub get_cachegroups { - my $self = shift; - my %data; - my %cachegroups; - my %short_names; - my $rs = $self->db->resultset('Cachegroup'); - while ( my $cachegroup = $rs->next ) { - $cachegroups{ $cachegroup->name } = $cachegroup->id; - $short_names{ $cachegroup->short_name } = $cachegroup->id; - } - %data = ( cachegroups => \%cachegroups, short_names => \%short_names ); - return \%data; -} - -sub get_cachegroup_by_id { - my $self = shift; - my $id = shift; - my $row; - - eval { - $row = $self->db->resultset('Cachegroup')->find( { id => $id }, { prefetch => [ { 'type' => undef, } ]}); - }; - if ($@) { - $self->app->log->error( "Failed to get cachegroup id = $id: $@" ); - return (undef, "Failed to get cachegroup id = $id: $@") - } - - my $r; - eval { - $r = $self->db->resultset('Cachegroup')->find( { id => $row->parent_cachegroup_id } ); - }; - if ($@) { - $self->app->log->error( "Failed to get cachegroup id = $id: $@" ); - return (undef, "Failed to get cachegroup id = $id: $@") - } - my $parentCachegroup = defined($r) ? $r->name : ""; - eval { - $r = $self->db->resultset('Cachegroup')->find( { id => $row->secondary_parent_cachegroup_id } ); - }; - if ($@) { - $self->app->log->error( "Failed to get cachegroup id = $id: $@" ); - return (undef, "Failed to get cachegroup id = $id: $@") - } - my $secondaryParentCachegroup = defined($r) ? $r->name : ""; - - my $data = { - "id" => $row->id, - "name" => $row->name, - "shortName" => $row->short_name, - "latitude" => $row->latitude, - "longitude" => $row->longitude, - "parentCachegroup" => $parentCachegroup, - "parentCachegroupId" => $row->parent_cachegroup_id, - "secondaryParentCachegroup" => $secondaryParentCachegroup, - "secondaryParentCachegroupId" => $row->secondary_parent_cachegroup_id, - "typeName" => $row->type->name, - "lastUpdated" => $row->last_updated, - }; - return ($data, undef); -} - -sub isValidCachegroup { - my $self = shift; - my $params = shift; - my %errFields = (); - - if (!defined($params)) { - return "parameters must be in JSON format, please check!"; - } - - if (!defined($params->{'name'})) { - $errFields{'name'} = 'is required'; - } - if (!defined($params->{'shortName'})) { - $errFields{'shorName'} = 'is required'; - } - if (!defined($params->{typeName})){ - $errFields{'typeName'} = 'is required'; - } - if (%errFields) { - return \%errFields; - } - - if (!($params->{'name'} =~ /^[0-9a-zA-Z_\.\-]+$/)) { - return "Invalid name. Use alphanumeric . or _ ."; - } - if (!($params->{'shortName'} =~ /^[0-9a-zA-Z_\.\-]+$/)) { - return "Invalid shortName. Use alphanumeric . or _ ."; - } - my $typeName = $params->{typeName}; - my $type_id = $self->get_typeId($typeName); - if (!defined($type_id)) { - return "Type ". $typeName . " is not a valid Cache Group type"; - } - if (defined($params->{'latitude'})) { - if(!($params->{'latitude'} =~ /^[-]*[0-9]+[.]*[0-9]*/)) { - return "Invalid latitude entered. Must be a float number."; - } - if ( abs $params->{'latitude'} > 90 ) { - return "Invalid latitude entered. May not exceed +- 90.0."; - } - } - if (defined($params->{'longitude'})) { - if(!($params->{'longitude'} =~ /^[-]*[0-9]+[.]*[0-9]*/)) { - return "Invalid longitude entered. Must be a float number."; - } - if ( abs $params->{'longitude'} > 180 ) { - return "Invalid longitude entered. May not exceed +- 180.0."; - } - } - - return undef; -} - -sub create{ - my $self = shift; - my $params = $self->req->json; - if ( !&is_oper($self) ) { - return $self->forbidden(); - } - - my $err = $self->isValidCachegroup($params); - if (defined($err)) { - return $self->alert($err); - } - - my $cachegroups = $self->get_cachegroups(); - my $name = $params->{name}; - my $shortName = $params->{shortName}; - my $parentCachegroup = $params->{parentCachegroup}; - my $secondaryParentCachegroup = $params->{secondaryParentCachegroup}; - my $typeName = $params->{typeName}; - my $type_id = $self->get_typeId($typeName); - - if (exists $cachegroups->{'cachegroups'}->{$name}) { - return $self->internal_server_error("cache_group_name[".$name."] already exists."); - } - if (exists $cachegroups->{'short_names'}->{$shortName}) { - return $self->internal_server_error("cache_group_shortname[".$shortName."] already exists."); - } - - my $parentCachegroupId = $cachegroups->{'cachegroups'}->{$parentCachegroup}; - $self->app->log->debug("parentCachegroup[". $parentCachegroup . "]"); - if ( $parentCachegroup ne "" && !defined($parentCachegroupId) ) { - return $self->alert("parentCachegroup ". $parentCachegroup . " does not exist."); - } - my $secondaryParentCachegroupId = $cachegroups->{'cachegroups'}->{$secondaryParentCachegroup}; - if ( $secondaryParentCachegroup ne "" && !defined($secondaryParentCachegroupId) ) { - return $self->alert("secondaryParentCachegroup ". $secondaryParentCachegroup . " does not exist."); - } - my $insert = $self->db->resultset('Cachegroup')->create( - { - name => $name, - short_name => $shortName, - latitude => $params->{latitude}, - longitude => $params->{longitude}, - parent_cachegroup_id => $parentCachegroupId, - secondary_parent_cachegroup_id => $secondaryParentCachegroupId, - type => $type_id, - } - ); - $insert->insert(); - - &log( $self, "Create cachegroup with name:" . $name, "APICHANGE" ); - - my ($response, $err1) = $self->get_cachegroup_by_id($insert->id); - if( defined($err1) ) { - return $self->alert( - { Error => $err1 } - ); - } - return $self->success($response, "Cachegroup successfully created: " . $name); -} - -sub update{ - my $self = shift; - my $params = $self->req->json; - if ( !&is_oper($self) ) { - return $self->forbidden(); - } - - my $err = $self->isValidCachegroup($params); - if (defined($err)) { - return $self->alert($err); - } - - my $id = $self->param('id'); - my $update = $self->db->resultset('Cachegroup')->find( { id => $id } ); - if( !defined($update) ) { - return $self->not_found(); - } - - my $type_id = undef; - if (defined($params->{typeName})){ - my $typeName = $params->{typeName}; - $type_id = $self->get_typeId($typeName); - } - - my $cachegroups = $self->get_cachegroups(); - my $parentCachegroupId = undef; - if (defined($params->{parentCachegroup})){ - my $parentCachegroup = $params->{parentCachegroup}; - $parentCachegroupId = $cachegroups->{'cachegroups'}->{$parentCachegroup}; - if ( $parentCachegroup ne "" && !defined($parentCachegroupId) ) { - return $self->alert("parentCachegroup ". $parentCachegroup . " does not exist."); - } - if (defined($parentCachegroupId) && $parentCachegroupId == $id) { - return $self->alert("Could not set the Cache Group itself as parent."); - } - } - my $secondaryParentCachegroupId = undef; - if (defined($params->{secondaryParentCachegroup})){ - my $secondaryParentCachegroup = $params->{secondaryParentCachegroup}; - $secondaryParentCachegroupId = $cachegroups->{'cachegroups'}->{$secondaryParentCachegroup}; - if ( $secondaryParentCachegroup ne "" && !defined($secondaryParentCachegroupId) ) { - return $self->alert("secondaryParentCachegroup ". $secondaryParentCachegroup . " does not exist."); - } - if (defined($secondaryParentCachegroupId) && $secondaryParentCachegroupId == $id) { - return $self->alert("Could not set the Cache Group itself as secondary parent."); - } - } - - eval { - $update->update( - { - name => defined($params->{'name'}) ? $params->{'name'} : $update->name, - short_name => defined($params->{'shortName'}) ? $params->{'shortName'} : $update->short_name, - latitude => defined($params->{'latitude'}) ? $params->{'latitude'} : $update->latitude, - longitude => defined($params->{'longitude'}) ? $params->{'longitude'} : $update->longitude, - parent_cachegroup_id => defined($params->{parentCachegroup}) ? $parentCachegroupId : $update->parent_cachegroup_id, - secondary_parent_cachegroup_id => defined($params->{secondaryParentCachegroup}) ? $secondaryParentCachegroupId : $update->secondary_parent_cachegroup_id, - type => defined($type_id) ? $type_id : $update->type, - } - ); - }; - if ($@) { - $self->app->log->error( "Failed to update cachegroup id = $id: $@" ); - return $self->alert( - { Error => "Failed to update server: $@" } - ); - } - $update->update(); - - &log( $self, "Update cachegroup with name:" . $update->name, "APICHANGE" ); - - my ($response, $err1) = $self->get_cachegroup_by_id($id); - if( defined($err1) ) { - return $self->alert( - { Error => $err1 } - ); - } - return $self->success($response, "Cachegroup was updated: " . $update->name); -} - -sub delete{ - my $self = shift; - my $rs; - if ( !&is_oper($self) ) { - return $self->forbidden(); - } - - my $id = $self->param('id'); - my $cg = $self->db->resultset('Cachegroup')->find( { id => $id } ); - if ( !defined($cg) ) { - return $self->not_found(); - } - $rs = $self->db->resultset('Cachegroup')->search( { parent_cachegroup_id => $id } ); - if ($rs->count() > 0) { - $self->app->log->error( "Failed to delete cachegroup id = $id, which has children" ); - return $self->alert("Failed to delete cachegroup id = $id, which has children"); - } - $rs = $self->db->resultset('Cachegroup')->search( { secondary_parent_cachegroup_id => $id } ); - if ($rs->count() > 0) { - $self->app->log->error( "Failed to delete cachegroup id = $id, which has children" ); - return $self->alert("Failed to delete cachegroup id = $id, which has children"); - } - $rs = $self->db->resultset('Server')->search( { cachegroup => $id } ); - if ($rs->count() > 0) { - $self->app->log->error( "Failed to delete cachegroup id = $id has servers" ); - return $self->alert("Failed to delete cachegroup id = $id has servers"); - } - my $delete = $self->db->resultset('Cachegroup')->search( { id => $id } ); - my $name = $delete->get_column('name')->single(); - $delete->delete(); - - &log( $self, "Delete cachegroup " . $name, "APICHANGE" ); - - return $self->success_message("Cachegroup was deleted: ". $name); -} - -sub get_typeId { - my $self = shift; - my $typeName = shift; - - my $rs = $self->db->resultset("Type")->find( { name => $typeName } ); - my $type_id; - if (defined($rs) && ($rs->use_in_table eq "cachegroup")) { - $type_id = $rs->id; - } - return($type_id); -} - -1; http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/aed7f17e/traffic_ops/app/t/api/1.2/cachegroup.t ---------------------------------------------------------------------- diff --git a/traffic_ops/app/t/api/1.2/cachegroup.t b/traffic_ops/app/t/api/1.2/cachegroup.t index 5ef39a5..85a9a4e 100644 --- a/traffic_ops/app/t/api/1.2/cachegroup.t +++ b/traffic_ops/app/t/api/1.2/cachegroup.t @@ -54,88 +54,66 @@ Test::TestHelper->load_all_fixtures( Fixtures::Type->new($schema_values) ); ok $t->post_ok( '/login', => form => { u => Test::TestHelper::ADMIN_USER, p => Test::TestHelper::ADMIN_USER_PASSWORD } )->status_is(302) ->or( sub { diag $t->tx->res->content->asset->{content}; } ), 'Should login?'; -ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} => json => { +ok $t->post_ok('/api/1.2/cachegroups' => {Accept => 'application/json'} => json => { "name" => "cache_group_mid", "shortName" => "cg_mid", - "latitude" => "12", - "longitude" => "56", - "parentCachegroup" => "", - "secondaryParentCachegroup" => "", - "typeName" => "MID_LOC" })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + "latitude" => 12, + "longitude" => 56, + "typeId" => 6 })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/response/name" => "cache_group_mid" ) ->json_is( "/response/shortName" => "cg_mid") ->json_is( "/response/latitude" => "12") ->json_is( "/response/longitude" => "56") - ->json_is( "/response/parentCachegroup" => "") - ->json_is( "/response/secondaryParentCachegroup" => "") + ->json_is( "/response/parentCachegroupId" => undef) + ->json_is( "/response/secondaryParentCachegroupId" => undef) , 'Does the cache group details return?'; -ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} => json => { +ok $t->post_ok('/api/1.2/cachegroups' => {Accept => 'application/json'} => json => { "name" => "mid-northeast-group", "shortName" => "mid-ne-group", - "latitude" => "44", - "longitude" => "66", - "parentCachegroup" => "", - "secondaryParentCachegroup" => "", - "typeName" => "MID_LOC" })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + "latitude" => 44, + "longitude" => 66, + "typeId" => 6 })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/response/name" => "mid-northeast-group" ) ->json_is( "/response/shortName" => "mid-ne-group") - ->json_is( "/response/latitude" => "44") - ->json_is( "/response/longitude" => "66") - ->json_is( "/response/parentCachegroup" => "") - ->json_is( "/response/secondaryParentCachegroup" => "") + ->json_is( "/response/latitude" => 44) + ->json_is( "/response/longitude" => 66) + ->json_is( "/response/parentCachegroupId" => undef) + ->json_is( "/response/secondaryParentCachegroupId" => undef) , 'Does the cache group details return?'; - -ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} => json => { +my $cache_group_mid_id = &get_cg_id('cache_group_mid'); +my $mid_northeast_group_id = &get_cg_id('mid-northeast-group'); +ok $t->post_ok('/api/1.2/cachegroups' => {Accept => 'application/json'} => json => { "name" => "cache_group_edge", "shortName" => "cg_edge", - "latitude" => "12", - "longitude" => "56", - "parentCachegroup" => "cache_group_mid", - "secondaryParentCachegroup" => "mid-northeast-group", - "typeName" => "EDGE_LOC" })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + "latitude" => 12, + "longitude" => 56, + "parentCachegroupId" => $cache_group_mid_id, + "secondaryParentCachegroupId" => $mid_northeast_group_id, + "typeId" => 5 })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/response/name" => "cache_group_edge" ) ->json_is( "/response/shortName" => "cg_edge") - ->json_is( "/response/latitude" => "12") - ->json_is( "/response/longitude" => "56") - ->json_is( "/response/parentCachegroup" => "cache_group_mid") - ->json_is( "/response/secondaryParentCachegroup" => "mid-northeast-group") + ->json_is( "/response/latitude" => 12) + ->json_is( "/response/longitude" => 56) + ->json_is( "/response/parentCachegroupId" => $cache_group_mid_id) + ->json_is( "/response/parentCachegroupName" => "cache_group_mid") + ->json_is( "/response/secondaryParentCachegroupId" => $mid_northeast_group_id) + ->json_is( "/response/secondaryParentCachegroupName" => "mid-northeast-group") , 'Does the cache group details return?'; -ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} => json => { +ok $t->post_ok('/api/1.2/cachegroups' => {Accept => 'application/json'} => json => { "name" => "cache_group_edge1", "shortName" => "cg_edge1", - "latitude" => "23", - "longitude" => "45", - "parentCachegroup" => "", - "secondaryParentCachegroup" => "", - "typeName" => "EDGE_LOC" })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + "latitude" => 23, + "longitude" => 45, + "typeId" => 5 })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/response/name" => "cache_group_edge1" ) ->json_is( "/response/shortName" => "cg_edge1") - ->json_is( "/response/latitude" => "23") - ->json_is( "/response/longitude" => "45") - ->json_is( "/response/parentCachegroup" => "") - ->json_is( "/response/secondaryParentCachegroup" => "") - , 'Does the cache group details return?'; - -ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} => json => { - "name" => "cache_group_edge2", - "shortName" => "cg_edge2", - "latitude" => "23", - "longitude" => "45", - "parentCachegroup" => "notexist", - "secondaryParentCachegroup" => "", - "typeName" => "EDGE_LOC" })->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ) - , 'Does the cache group details return?'; - -ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} => json => { - "name" => "cache_group_edge3", - "shortName" => "cg_edge3", - "latitude" => "23", - "longitude" => "45", - "secondaryParentCachegroup" => "notexist", - "typeName" => "EDGE_LOC" })->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + ->json_is( "/response/latitude" => 23) + ->json_is( "/response/longitude" => 45) + ->json_is( "/response/parentCachegroupId" => undef) + ->json_is( "/response/secondaryParentCachegroupId" => undef) , 'Does the cache group details return?'; ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => { @@ -185,52 +163,55 @@ ok $t->post_ok('/api/1.2/cachegroups/9999/queue_update' => {Accept => 'applicat , 'Does the queue_update api return?'; my $cg_id = &get_cg_id('cache_group_edge'); +ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id => {Accept => 'application/json'} => json => { + "name" => "cache_group_edge_1", + "shortName" => "cg_edge_1", + "latitude" => 23, + "longitude" => 56, + "typeId" => 5 })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + ->json_is( "/response/name" => "cache_group_edge_1" ) + ->json_is( "/response/shortName" => "cg_edge_1") + ->json_is( "/response/latitude" => 23) + ->json_is( "/response/longitude" => 56) + ->json_is( "/response/parentCachegroupId" => undef) + ->json_is( "/response/parentCachegroupName" => undef) + ->json_is( "/response/secondaryParentCachegroupName" => undef) + ->json_is( "/response/secondaryParentCachegroupName" => undef) + , 'Does the cache group details return?'; -ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id . '/update' => {Accept => 'application/json'} => json => { - "name" => "cache_group_edge_1", - "shortName" => "cg_edge_1", - "latitude" => "23", - "longitude" => "56", - "typeName" => "EDGE_LOC" })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) - ->json_is( "/response/name" => "cache_group_edge_1" ) - ->json_is( "/response/shortName" => "cg_edge_1") - ->json_is( "/response/latitude" => "23") - ->json_is( "/response/longitude" => "56") - ->json_is( "/response/parentCachegroup" => "cache_group_mid") - ->json_is( "/response/secondaryParentCachegroup" => "mid-northeast-group") - , 'Does the cache group details return?'; - -ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id . '/update' => {Accept => 'application/json'} => json => { +ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id => {Accept => 'application/json'} => json => { "name" => "cache_group_edge_2", "shortName" => "cg_edge_2", - "parentCachegroup" => "", - "secondaryParentCachegroup" => "", - "typeName" => "EDGE_LOC" })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + "parentCachegroupId" => undef, + "secondaryParentCachegroupId" => undef, + "typeId" => 5 })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/response/name" => "cache_group_edge_2" ) ->json_is( "/response/shortName" => "cg_edge_2") - ->json_is( "/response/latitude" => "23") - ->json_is( "/response/longitude" => "56") - ->json_is( "/response/parentCachegroup" => "") - ->json_is( "/response/secondaryParentCachegroup" => "") + ->json_is( "/response/latitude" => 0) + ->json_is( "/response/longitude" => 0) + ->json_is( "/response/parentCachegroupId" => undef) + ->json_is( "/response/parentCachegroupName" => undef) + ->json_is( "/response/secondaryParentCachegroupId" => undef) + ->json_is( "/response/secondaryParentCachegroupName" => undef) , 'Does the cache group details return?'; -ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id . '/update' => {Accept => 'application/json'} => json => { +ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id => {Accept => 'application/json'} => json => { "name" => "cache_group_edge_2", "shortName" => "cg_edge_2", - "parentCachegroup" => "cache_group_mid", - "typeName" => "EDGE_LOC"})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) - ->json_is( "/response/parentCachegroup" => "cache_group_mid") + "parentCachegroupId" => $cache_group_mid_id, + "typeId" => 5})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + ->json_is( "/response/parentCachegroupId" => $cache_group_mid_id) + ->json_is( "/response/parentCachegroupName" => "cache_group_mid") , 'Does the cache group details return?'; -ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id . '/update' => {Accept => 'application/json'} => json => { +ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id => {Accept => 'application/json'} => json => { "name" => "cache_group_edge_1", - "typeName" => "EDGE_LOC"})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ); + "typeId" => 5})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ); ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id => {Accept => 'application/json'} => json => { "name" => "cache_group_edge_1", - "shortName" => "cg_edge_1", "parentCachegroup" => "cache_group_edge_2", - "typeName" => "EDGE_LOC"})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ); + "typeId" => 5})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ); ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => { "hostName" => "edge_streamer_1", @@ -249,28 +230,28 @@ ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => js ->json_is( "/response/hostName" => "edge_streamer_1") , 'Does the server details return?'; -ok $t->delete_ok('/api/1.2/cachegroups/' . $cg_id . '/delete')->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ) +ok $t->delete_ok('/api/1.2/cachegroups/' . $cg_id)->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/alerts/0/level", "error" ) - ->json_is( "/alerts/0/text", "Failed to delete cachegroup id = " . $cg_id . " has servers") + ->json_is( "/alerts/0/text", "This cachegroup is currently used by servers.") , "Is the Cachegroup id valid?"; my $midcg_id = &get_cg_id('cache_group_mid'); -ok $t->delete_ok('/api/1.2/cachegroups/' . $midcg_id . '/delete')->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ) +ok $t->delete_ok('/api/1.2/cachegroups/' . $midcg_id)->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/alerts/0/level", "error" ) - ->json_is( "/alerts/0/text", "Failed to delete cachegroup id = " . $midcg_id . ", which has children" ) + ->json_is( "/alerts/0/text", "This cachegroup is currently used as a parent cachegroup." ) , "Is the Cachegroup id valid?"; my $svr_id =&get_svr_id('edge_streamer_1'); ok $t->delete_ok('/api/1.2/servers/' . $svr_id)->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ); -ok $t->delete_ok('/api/1.2/cachegroups/' . $cg_id . '/delete')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) +ok $t->delete_ok('/api/1.2/cachegroups/' . $cg_id)->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/alerts/0/level", "success" ) - ->json_is( "/alerts/0/text", "Cachegroup was deleted: cache_group_edge_2" ) + ->json_is( "/alerts/0/text", "Cachegroup deleted." ) , "Is the Cachegroup id valid?"; -ok $t->delete_ok('/api/1.2/cachegroups/' . $cg_id . '/delete')->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } ); -ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id . '/update' => {Accept => 'application/json'} => json => { +ok $t->delete_ok('/api/1.2/cachegroups/' . $cg_id)->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } ); +ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id => {Accept => 'application/json'} => json => { "name" => "cache_group_edge_1", "shortName" => "cg_edge_1", - "typeName" => "EDGE_LOC"})->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } ); + "typeId" => 5})->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } ); Test::TestHelper->unload_core_data($schema); Test::TestHelper->load_core_data($schema); http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/aed7f17e/traffic_ops/app/t/api/1.2/server.t ---------------------------------------------------------------------- diff --git a/traffic_ops/app/t/api/1.2/server.t b/traffic_ops/app/t/api/1.2/server.t index 5f4062b..ad4a717 100644 --- a/traffic_ops/app/t/api/1.2/server.t +++ b/traffic_ops/app/t/api/1.2/server.t @@ -40,36 +40,36 @@ Test::TestHelper->load_core_data($schema); ok $t->post_ok( '/login', => form => { u => Test::TestHelper::ADMIN_USER, p => Test::TestHelper::ADMIN_USER_PASSWORD } )->status_is(302) ->or( sub { diag $t->tx->res->content->asset->{content}; } ), 'Should login?'; -ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} => json => { +ok $t->post_ok('/api/1.2/cachegroups' => {Accept => 'application/json'} => json => { "name" => "cg2-mid-northwest", "shortName" => "cg2_mid", - "latitude" => "12", - "longitude" => "56", - "parentCachegroup" => "", - "secondaryParentCachegroup" => "", - "typeName" => "MID_LOC" })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + "latitude" => 12, + "longitude" => 56, + "typeId" => 6 })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/response/name" => "cg2-mid-northwest" ) ->json_is( "/response/shortName" => "cg2_mid") - ->json_is( "/response/latitude" => "12") - ->json_is( "/response/longitude" => "56") - ->json_is( "/response/parentCachegroup" => "") - ->json_is( "/response/secondaryParentCachegroup" => "") + ->json_is( "/response/latitude" => 12) + ->json_is( "/response/longitude" => 56) + ->json_is( "/response/parentCachegroupId" => undef) + ->json_is( "/response/parentCachegroupName" => undef) + ->json_is( "/response/secondaryParentCachegroupId" => undef) + ->json_is( "/response/secondaryParentCachegroupName" => undef) , 'Does the cache group details return?'; -ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} => json => { +ok $t->post_ok('/api/1.2/cachegroups' => {Accept => 'application/json'} => json => { "name" => "cg-mid-northeast", "shortName" => "mneg", - "latitude" => "10", - "longitude" => "40", - "parentCachegroup" => "", - "secondaryParentCachegroup" => "", - "typeName" => "MID_LOC" })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + "latitude" => 10, + "longitude" => 40, + "typeId" => 6 })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/response/name" => "cg-mid-northeast" ) ->json_is( "/response/shortName" => "mneg") - ->json_is( "/response/latitude" => "10") - ->json_is( "/response/longitude" => "40") - ->json_is( "/response/parentCachegroup" => "") - ->json_is( "/response/secondaryParentCachegroup" => "") + ->json_is( "/response/latitude" => 10) + ->json_is( "/response/longitude" => 40) + ->json_is( "/response/parentCachegroupId" => undef) + ->json_is( "/response/parentCachegroupName" => undef) + ->json_is( "/response/secondaryParentCachegroupId" => undef) + ->json_is( "/response/secondaryParentCachegroupName" => undef) , 'Does the cache group details return?'; ok $t->get_ok('/api/1.2/servers?type=MID')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) @@ -97,20 +97,20 @@ ok $t->get_ok('/api/1.2/servers?type=MID&status=ONLINE')->status_is(200)->or( su ->json_is( "/response/0/status", "ONLINE" ) ->or( sub { diag $t->tx->res->content->asset->{content}; } ); -ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} => json => { +ok $t->post_ok('/api/1.2/cachegroups' => {Accept => 'application/json'} => json => { "name" => "edge_atl_group1", "shortName" => "eag1", - "latitude" => "22", - "longitude" => "55", - "parentCachegroup" => "", - "secondaryParentCachegroup" => "", - "typeName" => "MID_LOC" })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) + "latitude" => 22, + "longitude" => 55, + "typeId" => 6 })->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/response/name" => "edge_atl_group1" ) ->json_is( "/response/shortName" => "eag1") - ->json_is( "/response/latitude" => "22") - ->json_is( "/response/longitude" => "55") - ->json_is( "/response/parentCachegroup" => "") - ->json_is( "/response/secondaryParentCachegroup" => "") + ->json_is( "/response/latitude" => 22) + ->json_is( "/response/longitude" => 55) + ->json_is( "/response/parentCachegroupId" => undef) + ->json_is( "/response/parentCachegroupName" => undef) + ->json_is( "/response/secondaryParentCachegroupId" => undef) + ->json_is( "/response/secondaryParentCachegroupName" => undef) , 'Does the cache group details return?'; ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
