You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2017/07/13 20:58:48 UTC
[1/6] incubator-trafficcontrol git commit: This closes #486
Repository: incubator-trafficcontrol
Updated Branches:
refs/heads/master ebaa01425 -> 291cf29e5
This closes #486
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/291cf29e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/291cf29e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/291cf29e
Branch: refs/heads/master
Commit: 291cf29e55208df38047e3baaa84770f9fd629eb
Parents: 50bd139
Author: Dewayne Richardson <de...@apache.org>
Authored: Thu Jul 13 14:52:07 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Thu Jul 13 14:52:07 2017 -0600
----------------------------------------------------------------------
----------------------------------------------------------------------
[2/6] incubator-trafficcontrol git commit: fixes tests and fixes bad
merge
Posted by de...@apache.org.
fixes tests and fixes bad merge
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/da352d11
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/da352d11
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/da352d11
Branch: refs/heads/master
Commit: da352d116183fe0b6ba8eaa630cd9928cd5b9d72
Parents: 7130816
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Thu Jun 29 10:11:33 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Thu Jul 13 14:52:07 2017 -0600
----------------------------------------------------------------------
traffic_ops/app/lib/API/Deliveryservice.pm | 56 ------------------------
traffic_ops/app/t/api/1.2/deliveryservice.t | 4 +-
traffic_ops/app/t/api/1.2/server.t | 6 +--
3 files changed, 4 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/da352d11/traffic_ops/app/lib/API/Deliveryservice.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Deliveryservice.pm b/traffic_ops/app/lib/API/Deliveryservice.pm
index 0ac26f5..1587bed 100644
--- a/traffic_ops/app/lib/API/Deliveryservice.pm
+++ b/traffic_ops/app/lib/API/Deliveryservice.pm
@@ -1051,62 +1051,6 @@ sub request {
}
}
-sub assign_servers {
- my $self = shift;
- my $ds_xml_Id = $self->param('xml_id');
- my $params = $self->req->json;
-
- if ( !defined($params) ) {
- return $self->alert("parameters are JSON format, please check!");
- }
- if ( !&is_oper($self) ) {
- return $self->alert("You must be an ADMIN or OPER to perform this operation!");
- }
-
- if ( !exists( $params->{serverNames} ) ) {
- return $self->alert("Parameter 'serverNames' is required.");
- }
-
- my $dsid = $self->db->resultset('Deliveryservice')->search( { xml_id => $ds_xml_Id } )->get_column('id')->single();
- if ( !defined($dsid) ) {
- return $self->alert( "DeliveryService[" . $ds_xml_Id . "] is not found." );
- }
-
- my @server_ids;
- my $svrs = $params->{serverNames};
- foreach my $svr (@$svrs) {
- my $svr_id = $self->db->resultset('Server')->search( { host_name => $svr } )->get_column('id')->single();
- if ( !defined($svr_id) ) {
- return $self->alert( "Server[" . $svr . "] is not found in database." );
- }
- push( @server_ids, $svr_id );
- }
-
- # clean up
- my $delete = $self->db->resultset('DeliveryserviceServer')->search( { deliveryservice => $dsid } );
- $delete->delete();
-
- # assign servers
- foreach my $s_id (@server_ids) {
- my $insert = $self->db->resultset('DeliveryserviceServer')->create(
- {
- deliveryservice => $dsid,
- server => $s_id,
- }
- );
- $insert->insert();
- }
-
- my $ds = $self->db->resultset('Deliveryservice')->search( { id => $dsid } )->single();
- &UI::DeliveryService::header_rewrite( $self, $ds->id, $ds->profile, $ds->xml_id, $ds->edge_header_rewrite, "edge" );
-
- my $response;
- $response->{xmlId} = $ds->xml_id;
- $response->{'serverNames'} = \@$svrs;
-
- return $self->success($response);
-}
-
sub is_deliveryservice_request_valid {
my $self = shift;
my $details = shift;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/da352d11/traffic_ops/app/t/api/1.2/deliveryservice.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/deliveryservice.t b/traffic_ops/app/t/api/1.2/deliveryservice.t
index 2c42fed..00cb167 100644
--- a/traffic_ops/app/t/api/1.2/deliveryservice.t
+++ b/traffic_ops/app/t/api/1.2/deliveryservice.t
@@ -190,9 +190,7 @@ ok $t->get_ok("/api/1.2/deliveryservices")->status_is(200)->or( sub { diag $t->t
->json_is( "/response/0/xmlId", "steering-ds1" )->json_is( "/response/0/logsEnabled", 0 )->json_is( "/response/0/ipv6RoutingEnabled", 1 )
->json_is( "/response/1/xmlId", "steering-ds2" );
-$t->get_ok('/api/1.2/deliveryservices?logsEnabled=true')->status_is(200)->$count_response(2)
-$t->get_ok('/api/1.2/deliveryservices/list?logsEnabled=true')->status_is(200)->$count_response(2)
- ->or( sub { diag $t->tx->res->content->asset->{content}; } );
+$t->get_ok('/api/1.2/deliveryservices?logsEnabled=true')->status_is(200)->$count_response(2);
ok $t->put_ok('/api/1.2/snapshot/cdn1')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } );
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/da352d11/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 e034621..5591cb6 100644
--- a/traffic_ops/app/t/api/1.2/server.t
+++ b/traffic_ops/app/t/api/1.2/server.t
@@ -41,7 +41,7 @@ ok $t->post_ok( '/login', => form => { u => Test::TestHelper::ADMIN_USER, p => T
->or( sub { diag $t->tx->res->content->asset->{content}; } ), 'Should login?';
ok $t->get_ok('/api/1.2/servers/status')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/ONLINE", 14 )
+ ->json_is( "/response/ONLINE", 16 )
->json_is( "/response/REPORTED", 1 )
->or( sub { diag $t->tx->res->content->asset->{content}; } );
@@ -586,8 +586,8 @@ ok $t->put_ok('/api/1.2/servers/' . $server_id . '/status' => {Accept => 'applic
, 'Does the server status update succeed and updates are queued when the status is changed on an Edge server?';
ok $t->get_ok('/api/1.2/servers/status')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/ONLINE", 18 )
- ->json_is( "/response/REPORTED", 5 )
+ ->json_is( "/response/ONLINE", 17 )
+ ->json_is( "/response/REPORTED", 1 )
->or( sub { diag $t->tx->res->content->asset->{content}; } );
ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content}; } );
[5/6] incubator-trafficcontrol git commit: fixed broken tests
Posted by de...@apache.org.
fixed broken tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/50bd1396
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/50bd1396
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/50bd1396
Branch: refs/heads/master
Commit: 50bd1396f813f9833d97363612a6151332d80280
Parents: da352d1
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Thu Jul 13 14:21:33 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Thu Jul 13 14:52:07 2017 -0600
----------------------------------------------------------------------
traffic_ops/app/lib/TrafficOpsRoutes.pm | 2 +-
traffic_ops/app/t/api/1.2/cachegroup.t | 4 ++--
.../app/t/api/1.2/config_files_apache_traffic_server.t | 2 +-
traffic_ops/app/t/api/1.2/deliveryservice.t | 12 ++----------
traffic_ops/app/t/api/1.2/profile.t | 2 +-
5 files changed, 7 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/50bd1396/traffic_ops/app/lib/TrafficOpsRoutes.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/TrafficOpsRoutes.pm b/traffic_ops/app/lib/TrafficOpsRoutes.pm
index c48d740..03c6351 100644
--- a/traffic_ops/app/lib/TrafficOpsRoutes.pm
+++ b/traffic_ops/app/lib/TrafficOpsRoutes.pm
@@ -584,7 +584,7 @@ sub api_routes {
# -- DELIVERYSERVICES: SERVERS
# Supports ?orderby=key
$r->get("/api/$version/deliveryserviceserver")->over( authenticated => 1, not_ldap => 1 )->to( 'DeliveryServiceServer#index', namespace => $namespace );
- $r->post("/api/$version/deliveryserviceserver")->over( authenticated => 1, not_ldap => 1 )->to( 'DeliveryServiceServer#create', namespace => $namespace );
+ $r->post("/api/$version/deliveryserviceserver")->over( authenticated => 1, not_ldap => 1 )->to( 'DeliveryServiceServer#assign_servers_to_ds', namespace => $namespace );
# -- DIVISIONS
$r->get("/api/$version/divisions")->over( authenticated => 1, not_ldap => 1 )->to( 'Division#index', namespace => $namespace );
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/50bd1396/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 8b1225b..449f983 100644
--- a/traffic_ops/app/t/api/1.2/cachegroup.t
+++ b/traffic_ops/app/t/api/1.2/cachegroup.t
@@ -276,11 +276,11 @@ my $count_response = sub {
};
# there are currently 61 parameters not assigned to cachegroup 100
-$t->get_ok('/api/1.2/cachegroups/100/unassigned_parameters')->status_is(200)->$count_response(61)
+$t->get_ok('/api/1.2/cachegroups/100/unassigned_parameters')->status_is(200)->$count_response(62)
->or( sub { diag $t->tx->res->content->asset->{content}; } );
# there are currently 61 parameters not assigned to cachegroup 200
-$t->get_ok('/api/1.2/cachegroups/200/unassigned_parameters')->status_is(200)->$count_response(61)
+$t->get_ok('/api/1.2/cachegroups/200/unassigned_parameters')->status_is(200)->$count_response(62)
->or( sub { diag $t->tx->res->content->asset->{content}; } );
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/50bd1396/traffic_ops/app/t/api/1.2/config_files_apache_traffic_server.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/config_files_apache_traffic_server.t b/traffic_ops/app/t/api/1.2/config_files_apache_traffic_server.t
index 9ec9ecf..6017071 100644
--- a/traffic_ops/app/t/api/1.2/config_files_apache_traffic_server.t
+++ b/traffic_ops/app/t/api/1.2/config_files_apache_traffic_server.t
@@ -71,7 +71,7 @@ my $count_response = sub {
return $t->success( is( scalar(@$r), $count ) );
};
-$t->get_ok('/api/1.2/deliveryservices/list?logsEnabled=true')->status_is(200)->$count_response(3)
+$t->get_ok('/api/1.2/deliveryservices?logsEnabled=true')->status_is(200)->$count_response(3)
->or( sub { diag $t->tx->res->content->asset->{content}; } );
ok $t->put_ok('/api/1.2/snapshot/cdn1')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } );
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/50bd1396/traffic_ops/app/t/api/1.2/deliveryservice.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/deliveryservice.t b/traffic_ops/app/t/api/1.2/deliveryservice.t
index 00cb167..dba128d 100644
--- a/traffic_ops/app/t/api/1.2/deliveryservice.t
+++ b/traffic_ops/app/t/api/1.2/deliveryservice.t
@@ -48,10 +48,6 @@ my $count_response = sub {
return $t->success( is( scalar(@$r), $count ) );
};
-# there are currently 3 servers of type EDGE or ORG where server.cdn == ds.cdn not assigned to ds 100
-$t->get_ok('/api/1.2/deliveryservices/100/servers/unassigned')->status_is(200)->$count_response(4)
- ->or( sub { diag $t->tx->res->content->asset->{content}; } );
-
# we will assign 2 more servers to ds 100
ok $t->post_ok('/api/1.2/deliveryserviceserver' => {Accept => 'application/json'} => json => {
"dsId" => 100,
@@ -62,10 +58,6 @@ ok $t->post_ok('/api/1.2/deliveryserviceserver' => {Accept => 'application/json'
->json_is( "/alerts/0/text" => "Server assignments complete." )
, 'Are the servers assigned to the delivery service?';
-# there are now 2 servers of type EDGE or ORG where server.cdn == ds.cdn not assigned to ds 100
-$t->get_ok('/api/1.2/deliveryservices/100/servers/unassigned')->status_is(200)->$count_response(2)
- ->or( sub { diag $t->tx->res->content->asset->{content}; } );
-
# there are currently 6 servers of type EDGE or ORG that can be assigned to ds 100
$t->get_ok('/api/1.2/deliveryservices/100/servers/eligible')->status_is(200)->$count_response(6)
->or( sub { diag $t->tx->res->content->asset->{content}; } );
@@ -81,7 +73,7 @@ ok $t->get_ok("/api/1.2/deliveryservices?logsEnabled=true")->status_is(200)->or(
->json_is( "/response/0/xmlId", "test-ds1" )
->json_is( "/response/0/logsEnabled", 1 )
->json_is( "/response/0/ipv6RoutingEnabled", 1 )
- ->json_is( "/response/1/xmlId", "test-ds4" );
+ ->json_is( "/response/1/xmlId", "test-ds1-root" );
ok $t->post_ok('/api/1.2/deliveryservices' => {Accept => 'application/json'} => json => {
"active" => \0,
@@ -190,7 +182,7 @@ ok $t->get_ok("/api/1.2/deliveryservices")->status_is(200)->or( sub { diag $t->t
->json_is( "/response/0/xmlId", "steering-ds1" )->json_is( "/response/0/logsEnabled", 0 )->json_is( "/response/0/ipv6RoutingEnabled", 1 )
->json_is( "/response/1/xmlId", "steering-ds2" );
-$t->get_ok('/api/1.2/deliveryservices?logsEnabled=true')->status_is(200)->$count_response(2);
+$t->get_ok('/api/1.2/deliveryservices?logsEnabled=true')->status_is(200)->$count_response(3);
ok $t->put_ok('/api/1.2/snapshot/cdn1')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } );
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/50bd1396/traffic_ops/app/t/api/1.2/profile.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/profile.t b/traffic_ops/app/t/api/1.2/profile.t
index 37a2f2e..8ccb5bd 100644
--- a/traffic_ops/app/t/api/1.2/profile.t
+++ b/traffic_ops/app/t/api/1.2/profile.t
@@ -136,7 +136,7 @@ $t->get_ok('/api/1.2/profiles/100/unassigned_parameters')->status_is(200)->$coun
->or( sub { diag $t->tx->res->content->asset->{content}; } );
# there are currently 4 parameters not assigned to profile 200
-$t->get_ok('/api/1.2/profiles/200/unassigned_parameters')->status_is(200)->$count_response(3)
+$t->get_ok('/api/1.2/profiles/200/unassigned_parameters')->status_is(200)->$count_response(4)
->or( sub { diag $t->tx->res->content->asset->{content}; } );
# there are currently 7 profiles not assigned to parameter 4
[4/6] incubator-trafficcontrol git commit: removes duplicate server
apis
Posted by de...@apache.org.
removes duplicate server 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/eee9c2fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/eee9c2fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/eee9c2fc
Branch: refs/heads/master
Commit: eee9c2fc84511fe9161dbc387cf421ffa599ccb8
Parents: aed7f17
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Wed Apr 19 12:42:48 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Thu Jul 13 14:52:07 2017 -0600
----------------------------------------------------------------------
traffic_ops/app/lib/API/Server2.pm | 613 ----------------------------
traffic_ops/app/t/api/1.2/cachegroup.t | 67 +--
traffic_ops/app/t/api/1.2/server.t | 411 ++++++++++---------
3 files changed, 260 insertions(+), 831 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/eee9c2fc/traffic_ops/app/lib/API/Server2.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Server2.pm b/traffic_ops/app/lib/API/Server2.pm
deleted file mode 100644
index 7252e7f..0000000
--- a/traffic_ops/app/lib/API/Server2.pm
+++ /dev/null
@@ -1,613 +0,0 @@
-package API::Server2;
-#
-#
-# 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.
-#
-#
-#
-use UI::Utils;
-use Mojo::Base 'Mojolicious::Controller';
-use Data::Dumper;
-use POSIX qw(strftime);
-use Time::Local;
-use LWP;
-use UI::ConfigFiles;
-use UI::Tools;
-use MojoPlugins::Response;
-use MojoPlugins::Job;
-use Utils::Helper::ResponseHelper;
-use String::CamelCase qw(decamelize);
-
-
-sub check_server_params {
- my $self = shift;
- my $json = shift;
- my $update_base = shift;
- my %params = %{$json};
- my $err = undef;
- my %errFields = ();
-
- # Required field checks
- if ( !defined( $json->{'hostName'} ) ) {
- $errFields{'hostName'} = 'is required';
- }
- if ( !defined( $json->{'domainName'} ) ) {
- $errFields{'domainName'} = 'is required';
- }
- if ( !defined( $json->{'cachegroup'} ) ) {
- $errFields{'cachegroup'} = 'is required';
- }
- if ( !defined( $json->{'interfaceName'} ) ) {
- $errFields{'interfaceName'} = 'is required';
- }
- if ( !defined( $json->{'ipAddress'} ) ) {
- $errFields{'ipAddress'} = 'is required';
- }
- if ( !defined( $json->{'ipNetmask'} ) ) {
- $errFields{'ipNetmask'} = 'is required';
- }
- if ( !defined( $json->{'ipGateway'} ) ) {
- $errFields{'ipGateway'} = 'is required';
- }
- if ( !defined( $json->{'interfaceMtu'} ) ) {
- $errFields{'interfaceMtu'} = 'is required';
- }
- if ( !defined( $json->{'physLocation'} ) ) {
- $errFields{'physLocation'} = 'is required';
- }
- if ( !defined( $json->{'type'} ) ) {
- $errFields{'type'} = 'is required';
- }
- if ( !defined( $json->{'profile'} ) ) {
- $errFields{'profile'} = 'is required';
- }
- if ( !defined( $json->{'cdnName'} ) ) {
- $errFields{'cdnName'} = 'is required';
- }
- if (%errFields) {
- return ( \%params, \%errFields );
- }
-
- # Valid value checks
- if ( defined( $json->{'interfaceMtu'} ) ) {
- if ( $json->{'interfaceMtu'} != '1500' && $json->{'interfaceMtu'} != '9000' ) {
- return ( \%params, "'interfaceMtu' '$json->{'interfaceMtu'}' not equal to 1500 or 9000!" );
- }
- }
-
- if ( defined( $json->{'tcpPort'} ) ) {
- $params{'tcpPort'} = int( $json->{'tcpPort'} );
- }
- elsif ( !defined($update_base) ) {
- $params{'tcpPort'} = 80;
- }
- if ( defined( $json->{'httpsPort'} ) ) {
- $params{'httpsPort'} = int( $json->{'httpsPort'} );
- }
- elsif ( !defined($update_base) ) {
- $params{'httpsPort'} = 443;
- }
-
- eval { $params{'cachegroup'} = $self->db->resultset('Cachegroup')->search( { name => $json->{'cachegroup'} } )->get_column('id')->single(); };
- if ( $@ || ( !defined( $params{'cachegroup'} ) ) ) { # $@ holds Perl errors
- return ( \%params, "'cachegroup' $json->{'cachegroup'} not found!" );
- }
-
- eval { $params{'cdnId'} = $self->db->resultset('Cdn')->search( { name => $json->{'cdnName'} } )->get_column('id')->single(); };
-
- eval { $params{'type'} = &type_id( $self, $json->{'type'} ); };
- if ( $@ || ( !defined( $params{'type'} ) ) ) { # $@ holds Perl errors
- return ( \%params, "'type' $json->{'type'} not found!" );
- }
-
- if ( defined( $json->{'status'} ) ) {
- eval { $params{'status'} = &admin_status_id( $self, $json->{'status'} ); };
- if ( $@ || ( !defined( $params{'status'} ) ) ) {
- return ( \%params, "'status' $json->{'status'} not found!" );
- }
- }
-
- eval { $params{'profile'} = &profile_id( $self, $json->{'profile'} ); };
- if ( $@ || ( !defined( $params{'profile'} ) ) ) { # $@ holds Perl errors
- return ( \%params, "'profile' $json->{'profile'} not found!" );
- }
-
- eval { $params{'physLocation'} = $self->db->resultset('PhysLocation')->search( { name => $json->{'physLocation'} } )->get_column('id')->single(); };
- if ( $@ || ( !defined( $params{'physLocation'} ) ) ) { # $@ holds Perl errors
- return ( \%params, "'physLocation' $json->{'physLocation'} not found!" );
- }
-
- # IP address checks
- foreach my $ipstr (
- $json->{'ipAddress'}, $json->{'ipNetmask'}, $json->{'ipGateway'}, $json->{'iloIpAddress'}, $json->{'iloIpNetmask'},
- $json->{'iloIpGateway'}, $json->{'mgmtIpAddress'}, $json->{'mgmtIpNetmask'}, $json->{'mgmtIpGateway'}
- )
- {
- if ( !defined($ipstr) || $ipstr eq "" ) {
- next;
- } # already checked for mandatory.
- if ( !&is_ipaddress($ipstr) ) {
- return ( \%params, $ipstr . " is not a valid IPv4 address or netmask" );
- }
- }
-
- if ( defined( $json->{'ip6Address'} )
- && $json->{'ip6Address'} ne ""
- && !&is_ip6address( $json->{'ip6Address'} ) )
- {
- return ( \%params, "Address " . $json->{'ip6Address'} . " is not a valid IPv6 address " );
- }
- if ( defined( $json->{'ip6Gateway'} )
- && $json->{'ip6Gateway'} ne ""
- && !&is_ip6address( $json->{'ip6Gateway'} ) )
- {
- return ( \%params, "Address " . $json->{'ip6Address'} . " is not a valid IPv6 address " );
- }
-
- my $ip_used = $self->db->resultset('Server')->search(
- {
- -and => [
- 'me.ip_address' => $json->{'ipAddress'},
- 'profile.name' => $json->{'profile'},
- 'me.id' => { '!=' => ( defined($update_base) ) ? $update_base->id : 0 }
- ]
- }, {
- join => ['profile']
- }
- )->single();
- if ($ip_used) {
- return ( \%params, $json->{'ipAddress'} . " is already being used by a server with the same profile" );
- }
-
- if ( defined( $json->{'ip6Address'} ) && $json->{'ip6Address'} ne "" ) {
- my $ip6_used = $self->db->resultset('Server')->search(
- {
- -and => [
- 'me.ip6_address' => $json->{'ip6Address'},
- 'profile.name' => $json->{'profile'},
- 'me.id' => { '!=' => ( defined($update_base) ) ? $update_base->id : 0 }
- ]
- }, {
- join => ['profile']
- }
- )->single();
- if ($ip6_used) {
- return ( \%params, $json->{'ip6Address'} . " is already being used by a server with the same profile" );
- }
- }
-
- # Netmask checks
- if ( defined( $json->{'ipNetmask'} )
- && $json->{'mgmtIpNetmask'} ne ""
- && !&is_netmask( $json->{'ipNetmask'} ) )
- {
- return ( \%params, $json->{'ipNetmask'} . " is not a valid netmask" );
- }
- if ( defined( $json->{'iloIpNetmask'} )
- && $json->{'iloIpNetmask'} ne ""
- && !&is_netmask( $json->{'iloIpNetmask'} ) )
- {
- return ( \%params, $json->{'iloIpNetmask'} . " is not a valid netmask" );
- }
- if ( defined( $json->{'mgmtIpNetmask'} )
- && $json->{'mgmtIpNetmask'} ne ""
- && !&is_netmask( $json->{'mgmtIpNetmask'} ) )
- {
- return ( \%params, $json->{'mgmtIpNetmask'} . " is not a valid netmask" );
- }
-
- if ( ( defined( $json->{'ip6Address'} ) && $json->{'ip6Address'} ne "" )
- || ( defined( $json->{'ip6Gateway'} ) && $json->{'ip6Gateway'} ne "" ) )
- {
- if ( defined($update_base) ) {
- if ( !defined( $json->{'ip6Address'} ) ) {
- $json->{'ip6Address'} = $update_base->{'ip6_address'};
- }
- if ( !defined( $json->{'ip6Gateway'} ) ) {
- $json->{'ip6Gateway'} = $update_base->{'ip6_gateway'};
- }
- }
- }
-
- my $ipstr1;
- my $ipstr2;
- if ( ( defined( $json->{'ipAddress'} ) && $json->{'ipAddress'} ne "" )
- || ( defined( $json->{'ipNetmask'} ) && $json->{'ipNetmask'} ne "" )
- || ( defined( $json->{'ipGateway'} ) && $json->{'ipGateway'} ne "" ) )
- {
- if ( !defined( $json->{'ipAddress'} ) ) {
- return ( \%params, "ipAddress is not found" );
- }
- $ipstr1 = $json->{'ipAddress'} . "/" . $json->{'ipNetmask'};
- $ipstr2 = $json->{'ipGateway'} . "/" . $json->{'ipNetmask'};
- if ( defined( $json->{'ipNetmask'} ) && $json->{'ipNetmask'} ne "" && !&in_same_net( $ipstr1, $ipstr2 ) ) {
- return ( \%params, $json->{'ipAddress'} . " and " . $json->{'ipGateway'} . " are not in same network" );
- }
- }
-
- if ( ( defined( $json->{'iloIpAddress'} ) && $json->{'iloIpAddress'} ne "" )
- || ( defined( $json->{'iloIpNetmask'} ) && $json->{'iloIpNetmask'} ne "" )
- || ( defined( $json->{'iloIpGateway'} ) && $json->{'iloIpGateway'} ne "" ) )
- {
- if ( defined($update_base) ) {
- if ( !defined( $json->{'iloIpAddress'} ) ) {
- $json->{'iloIpAddress'} = $update_base->ilo_ip_address;
- }
- if ( !defined( $json->{'iloIpNetmask'} ) ) {
- $json->{'iloIpNetmask'} = $update_base->ilo_ip_netmask;
- }
- if ( !defined( $json->{'iloIpGateway'} ) ) {
- $json->{'iloIpGateway'} = $update_base->ilo_ip_gateway;
- }
- }
- $ipstr1 = $json->{'iloIpAddress'} . "/" . $json->{'iloIpNetmask'};
- $ipstr2 = $json->{'iloIpGateway'} . "/" . $json->{'iloIpNetmask'};
- if ( $json->{'iloIpGateway'} ne ""
- && !&in_same_net( $ipstr1, $ipstr2 ) )
- {
- return ( \%params, $json->{'iloIpAddress'} . " and " . $json->{'iloIpGateway'} . " are not in same network" );
- }
- }
-
- if ( ( defined( $json->{'mgmtIpAddress'} ) && $json->{'mgmtIpAddress'} ne "" )
- || ( defined( $json->{'mgmtIpNetmask'} ) && $json->{'mgmtIpNetmask'} ne "" )
- || ( defined( $json->{'mgmtIpGateway'} ) && $json->{'mgmtIpGateway'} ne "" ) )
- {
- if ( defined($update_base) ) {
- if ( !defined( $json->{'mgmtIpAddress'} ) ) {
- $json->{'mgmtIpAddress'} = $update_base->mgmt_ip_address;
- }
- if ( !defined( $json->{'mgmtIpNetmask'} ) ) {
- $json->{'mgmtIpNetmask'} = $update_base->mgmt_ip_netmask;
- }
- if ( !defined( $json->{'mgmtIpGateway'} ) ) {
- $json->{'mgmtIpGateway'} = $update_base->mgmt_ip_gateway;
- }
- }
- $ipstr1 = $json->{'mgmtIpAddress'} . "/" . $json->{'mgmtIpNetmask'};
- $ipstr2 = $json->{'mgmtIpGateway'} . "/" . $json->{'mgmtIpNetmask'};
- if ( $json->{'mgmtIpGateway'} ne ""
- && !&in_same_net( $ipstr1, $ipstr2 ) )
- {
- return ( \%params, $json->{'mgmtIpAddress'} . " and " . $json->{'mgmtIpGateway'} . " are not in same network" );
- }
- }
-
- if ( defined( $json->{'tcpPort'} ) && $json->{'tcpPort'} !~ /\d+/ ) {
- return ( \%params, $json->{'tcpPort'} . " is not a valid tcp port" );
- }
- if ( defined( $json->{'httpsPort'} ) && $json->{'httpsPort'} !~ /\d+/ ) {
- return ( \%params, $json->{'httpsPort'} . " is not a valid https port" );
- }
-
- return ( \%params, $err );
-}
-
-sub get_server_by_id {
- my $self = shift;
- my $id = shift;
- my $row;
- my $isadmin = &is_admin($self);
- eval { $row = $self->db->resultset('Server')->find( { id => $id } ); };
- if ($@) { # $@ holds Perl errors
- $self->app->log->error("Failed to get server id = $id: $@");
- return ( undef, "Failed to get server id = $id: $@" );
- }
- my $data = {
- "id" => $row->id,
- "hostName" => $row->host_name,
- "domainName" => $row->domain_name,
- "tcpPort" => $row->tcp_port,
- "httpsPort" => $row->https_port,
- "xmppId" => $row->xmpp_id,
- "xmppPasswd" => "**********",
- "interfaceName" => $row->interface_name,
- "ipAddress" => $row->ip_address,
- "ipNetmask" => $row->ip_netmask,
- "ipGateway" => $row->ip_gateway,
- "ip6Address" => $row->ip6_address,
- "ip6Gateway" => $row->ip6_gateway,
- "interfaceMtu" => $row->interface_mtu,
- "cachegroup" => $row->cachegroup->name,
- "cdn_id" => $row->cdn_id,
- "physLocation" => $row->phys_location->name,
- "guid" => $row->guid,
- "rack" => $row->rack,
- "type" => $row->type->name,
- "status" => $row->status->name,
- "offline_reason" => $row->offline_reason,
- "profile" => $row->profile->name,
- "profileDesc" => $row->profile->description,
- "mgmtIpAddress" => $row->mgmt_ip_address,
- "mgmtIpNetmask" => $row->mgmt_ip_netmask,
- "mgmtIpGateway" => $row->mgmt_ip_gateway,
- "iloIpAddress" => $row->ilo_ip_address,
- "iloIpNetmask" => $row->ilo_ip_netmask,
- "iloIpGateway" => $row->ilo_ip_gateway,
- "iloUsername" => $row->ilo_username,
- "iloPassword" => $isadmin ? $row->ilo_password : "********",
- "routerHostName" => $row->router_host_name,
- "routerPortName" => $row->router_port_name,
- "lastUpdated" => $row->last_updated,
-
- };
- return ( $data, undef );
-}
-
-sub create {
- my ( $params, $data, $err ) = ( undef, undef, undef );
- my $self = shift;
-
- my $json = $self->req->json;
- if ( !&is_oper($self) ) {
- return $self->forbidden("Forbidden. You must have the operations role to perform this operation.");
- }
-
- ( $params, $err ) = $self->check_server_params( $json, undef );
- if ( defined($err) ) {
- return $self->alert($err);
- }
-
- my $new_id = -1;
- my $xmpp_passwd = "BOOGER";
- my $insert;
- if ( defined( $json->{'ip6Address'} )
- && $json->{'ip6Address'} ne "" )
- {
- eval {
- $insert = $self->db->resultset('Server')->create(
- {
- host_name => $json->{'hostName'},
- domain_name => $json->{'domainName'},
- tcp_port => $params->{'tcpPort'},
- https_port => $params->{'httpsPort'},
- xmpp_id => $json->{'hostName'}, # TODO JvD remove me later.
- xmpp_passwd => $xmpp_passwd,
- interface_name => $json->{'interfaceName'},
- ip_address => $json->{'ipAddress'},
- ip_netmask => $json->{'ipNetmask'},
- ip_gateway => $json->{'ipGateway'},
- ip6_address => $json->{'ip6Address'},
- ip6_gateway => $json->{'ip6Gateway'},
- interface_mtu => $json->{'interfaceMtu'},
- cachegroup => $params->{'cachegroup'},
- cdn_id => $params->{'cdnId'},
- phys_location => $params->{'physLocation'},
- guid => $json->{'guid'},
- rack => $json->{'rack'},
- type => $params->{'type'},
- status => &admin_status_id( $self, $json->{'type'} eq "EDGE" ? "REPORTED" : "ONLINE" ),
- offline_reason => $json->{'offline_reason'},
- profile => $params->{'profile'},
- mgmt_ip_address => $json->{'mgmtIpAddress'},
- mgmt_ip_netmask => $json->{'mgmtIpNetmask'},
- mgmt_ip_gateway => $json->{'mgmtIpGateway'},
- ilo_ip_address => $json->{'iloIpAddress'},
- ilo_ip_netmask => $json->{'iloIpNetmask'},
- ilo_ip_gateway => $json->{'iloIpGateway'},
- ilo_username => $json->{'iloUsername'},
- ilo_password => $json->{'iloPassword'},
- router_host_name => $json->{'routerHostName'},
- router_port_name => $json->{'routerPortName'},
- }
- );
- };
- if ($@) { # $@ holds Perl errors
- $self->app->log->error("Failed to create server: $@");
- return $self->alert( { Error => "Failed to create server: $@" } );
- }
- }
- else {
- eval {
- $insert = $self->db->resultset('Server')->create(
- {
- host_name => $json->{'hostName'},
- domain_name => $json->{'domainName'},
- tcp_port => $params->{'tcpPort'},
- https_port => $params->{'httpsPort'},
- xmpp_id => $json->{'hostName'}, # TODO JvD remove me later.
- xmpp_passwd => $xmpp_passwd,
- interface_name => $json->{'interfaceName'},
- ip_address => $json->{'ipAddress'},
- ip_netmask => $json->{'ipNetmask'},
- ip_gateway => $json->{'ipGateway'},
- interface_mtu => $json->{'interfaceMtu'},
- cachegroup => $params->{'cachegroup'},
- cdn_id => $params->{'cdnId'},
- phys_location => $params->{'physLocation'},
- guid => $json->{'guid'},
- rack => $json->{'rack'},
- type => $params->{'type'},
- status => &admin_status_id( $self, $json->{'type'} eq "EDGE" ? "REPORTED" : "ONLINE" ),
- offline_reason => $json->{'offline_reason'},
- profile => $params->{'profile'},
- mgmt_ip_address => $json->{'mgmtIpAddress'},
- mgmt_ip_netmask => $json->{'mgmtIpNetmask'},
- mgmt_ip_gateway => $json->{'mgmtIpGateway'},
- ilo_ip_address => $json->{'iloIpAddress'},
- ilo_ip_netmask => $json->{'iloIpNetmask'},
- ilo_ip_gateway => $json->{'iloIpGateway'},
- ilo_username => $json->{'iloUsername'},
- ilo_password => $json->{'iloPassword'},
- router_host_name => $json->{'routerHostName'},
- router_port_name => $json->{'routerPortName'},
- }
- );
- };
- if ($@) { # $@ holds Perl errors
- $self->app->log->error("Failed to create server: $@");
- return $self->alert( { Error => "Failed to create server: $@" } );
- }
- }
- $insert->insert();
- $new_id = $insert->id;
- if ( $json->{'type'} eq "EDGE"
- || $json->{'type'} eq "MID" )
- {
- $insert = $self->db->resultset('Servercheck')->create( { server => $new_id, } );
- $insert->insert();
- }
-
- # if the insert has failed, we don't even get here, we go to the exception page.
- &log( $self, "Create server with hostname:" . $json->{'hostName'}, "APICHANGE" );
-
- ( $data, $err ) = $self->get_server_by_id($new_id);
- if ( defined($err) ) {
- return $self->alert( { Error => $err } );
- }
- $self->success( $data, "Server successfully created: " . $json->{'hostName'} );
-}
-
-sub update {
- my ( $params, $data, $err ) = ( undef, undef, undef );
- my $self = shift;
- my $json = $self->req->json;
- if ( !&is_oper($self) ) {
- return $self->forbidden("Forbidden. You must have the operations role to perform this operation.");
- }
-
- my $id = $self->param('id');
-
- # get resultset for original and one to be updated. Use to examine diffs to propagate the effects of the change.
- my $org_server = $self->db->resultset('Server')->find( { id => $id } );
- if ( !defined($org_server) ) {
- return $self->not_found();
- }
- ( $params, $err ) = $self->check_server_params( $json, $org_server );
- if ( defined($err) ) {
- return $self->alert($err);
- }
-
- my $update = $self->db->resultset('Server')->find( { id => $id } );
- eval {
- $update->update(
- {
- host_name => defined( $params->{'hostName'} ) ? $params->{'hostName'} : $update->host_name,
- domain_name => defined( $params->{'domainName'} ) ? $params->{'domainName'} : $update->domain_name,
- tcp_port => defined( $params->{'tcpPort'} ) ? $params->{'tcpPort'} : $update->tcp_port,
- https_port => defined( $params->{'httpsPort'} ) ? $params->{'httpsPort'} : $update->https_port,
- interface_name => defined( $params->{'interfaceName'} ) ? $params->{'interfaceName'} : $update->interface_name,
- ip_address => defined( $params->{'ipAddress'} ) ? $params->{'ipAddress'} : $update->ip_address,
- ip_netmask => defined( $params->{'ipNetmask'} ) ? $params->{'ipNetmask'} : $update->ip_netmask,
- ip_gateway => defined( $params->{'ipGateway'} ) ? $params->{'ipGateway'} : $update->ip_gateway,
- ip6_address => defined( $params->{'ip6Address'} ) && $params->{'ip6Address'} != "" ? $params->{'ip6Address'} : $update->ip6_address,
- ip6_gateway => defined( $params->{'ip6Gateway'} ) ? $params->{'ip6Gateway'} : $update->ip6_gateway,
- interface_mtu => defined( $params->{'interfaceMtu'} ) ? $params->{'interfaceMtu'} : $update->interface_mtu,
- cachegroup => defined( $params->{'cachegroup'} ) ? $params->{'cachegroup'} : $update->cachegroup->id,
- cdn_id => defined( $params->{'cdnId'} ) ? $params->{'cdnId'} : $update->cdn_id,
- phys_location => defined( $params->{'physLocation'} ) ? $params->{'physLocation'} : $update->phys_location->id,
- guid => defined( $params->{'guid'} ) ? $params->{'guid'} : $update->guid,
- rack => defined( $params->{'rack'} ) ? $params->{'rack'} : $update->rack,
- type => defined( $params->{'type'} ) ? $params->{'type'} : $update->type->id,
- status => defined( $params->{'status'} ) ? $params->{'status'} : $update->status->id,
- offline_reason => defined( $params->{'offline_reason'} ) ? $params->{'offline_reason'} : $update->offline_reason,
- profile => defined( $params->{'profile'} ) ? $params->{'profile'} : $update->profile->id,
- mgmt_ip_address => defined( $params->{'mgmtIpAddress'} ) ? $params->{'mgmtIpAddress'} : $update->mgmt_ip_address,
- mgmt_ip_netmask => defined( $params->{'mgmtIpNetmask'} ) ? $params->{'mgmtIpNetmask'} : $update->mgmt_ip_netmask,
- mgmt_ip_gateway => defined( $params->{'mgmtIpGateway'} ) ? $params->{'mgmtIpGateway'} : $update->mgmt_ip_gateway,
- ilo_ip_address => defined( $params->{'iloIpAddress'} ) ? $params->{'iloIpAddress'} : $update->ilo_ip_address,
- ilo_ip_netmask => defined( $params->{'iloIpNetmask'} ) ? $params->{'iloIpNetmask'} : $update->ilo_ip_netmask,
- ilo_ip_gateway => defined( $params->{'iloIpGateway'} ) ? $params->{'iloIpGateway'} : $update->ilo_ip_gateway,
- ilo_username => defined( $params->{'iloUsername'} ) ? $params->{'iloUsername'} : $update->ilo_username,
- ilo_password => defined( $params->{'iloPassword'} ) ? $params->{'iloPassword'} : $update->ilo_password,
- router_host_name => defined( $params->{'routerHostName'} ) ? $params->{'routerHostName'} : $update->router_host_name,
- router_port_name => defined( $params->{'routerPortName'} ) ? $params->{'routerPortName'} : $update->router_port_name,
- }
- );
- };
- if ($@) { # $@ holds Perl errors
- $self->app->log->error("Failed to update server id = $id: $@");
- return $self->alert( { Error => "Failed to update server: $@" } );
- }
- $update->update();
-
- if ( $org_server->profile->id != $update->profile->id ) {
- my $param =
- $self->db->resultset('ProfileParameter')
- ->search( { -and => [ profile => $org_server->profile->id, 'parameter.config_file' => 'rascal-config.txt', 'parameter.name' => 'CDN_name' ] },
- { prefetch => [ { parameter => undef }, { profile => undef } ] } )->single();
- my $org_cdn_name = "";
- if ( defined($param) ) {
- $org_cdn_name = $param->parameter->value;
- }
-
- $param =
- $self->db->resultset('ProfileParameter')
- ->search( { -and => [ profile => $update->profile->id, 'parameter.config_file' => 'rascal-config.txt', 'parameter.name' => 'CDN_name' ] },
- { prefetch => [ { parameter => undef }, { profile => undef } ] } )->single();
- my $upd_cdn_name = "";
- if ( defined($param) ) {
- $upd_cdn_name = $param->parameter->value;
- }
-
- if ( $upd_cdn_name ne $org_cdn_name ) {
- my $delete = $self->db->resultset('DeliveryserviceServer')->search( { server => $id } );
- $delete->delete();
- &log( $self, $update->host_name . " profile change assigns server to new CDN - deleting all DS assignments", "APICHANGE" );
- }
- if ( $org_server->type->id != $update->type->id ) {
- my $delete = $self->db->resultset('DeliveryserviceServer')->search( { server => $id } );
- $delete->delete();
- &log( $self, $update->host_name . " profile change changes cache type - deleting all DS assignments", "APICHANGE" );
- }
- }
-
- if ( $org_server->type->id != $update->type->id ) {
-
- # server type changed: servercheck entry required for EDGE and MID, but not others. Add or remove servercheck entry accordingly
- my %need_servercheck = map { &type_id( $self, $_ ) => 1 } qw{ EDGE MID };
- my $newtype_id = $update->type->id;
- my $servercheck = $self->db->resultset('Servercheck')->search( { server => $id } );
- if ( $servercheck != 0 && !$need_servercheck{$newtype_id} ) {
-
- # servercheck entry found but not needed -- delete it
- $servercheck->delete();
- &log( $self, $update->host_name . " cache type change - deleting servercheck", "APICHANGE" );
- }
- elsif ( $servercheck == 0 && $need_servercheck{$newtype_id} ) {
-
- # servercheck entry not found but needed -- insert it
- $servercheck = $self->db->resultset('Servercheck')->create( { server => $id } );
- $servercheck->insert();
- &log( $self, $update->host_name . " cache type changed - adding servercheck", "APICHANGE" );
- }
- }
-
- # this just creates the log string for the log table / tab.
- my $lstring = "Update server " . $update->host_name . " ";
- foreach my $col ( keys %{ $org_server->{_column_data} } ) {
- my $colParam = $col;
- $colParam =~ s/_(\w)/\U$1/g;
- if ( defined( $params->{$colParam} )
- && $params->{$colParam} ne ( $org_server->{_column_data}->{$col} // "" ) )
- {
- if ( $col eq 'ilo_password' || $col eq 'xmpp_passwd' ) {
- $lstring .= $col . "-> ***********";
- }
- else {
- $lstring .= $col . "->" . $params->{$colParam} . " ";
- }
- }
- }
-
- # if the update has failed, we don't even get here, we go to the exception page.
- &log( $self, $lstring, "APICHANGE" );
-
- ( $data, $err ) = $self->get_server_by_id($id);
- if ( defined($err) ) {
- return $self->alert( { Error => $err } );
- }
- $self->success( $data, "Server was updated: " . $update->host_name );
-}
-
-1;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/eee9c2fc/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 85a9a4e..8b1225b 100644
--- a/traffic_ops/app/t/api/1.2/cachegroup.t
+++ b/traffic_ops/app/t/api/1.2/cachegroup.t
@@ -116,21 +116,27 @@ ok $t->post_ok('/api/1.2/cachegroups' => {Accept => 'application/json'} => json
->json_is( "/response/secondaryParentCachegroupId" => undef)
, 'Does the cache group details return?';
-ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
- "hostName" => "tc1_ats2",
- "domainName" => "my.domain.com",
- "cachegroup" => "mid-northeast-group",
- "cdnName" => "cdn1",
- "interfaceName" => "eth0",
- "ipAddress" => "10.74.27.184",
- "ipNetmask" => "255.255.255.0",
- "ipGateway" => "10.74.27.1",
- "interfaceMtu" => "1500",
- "physLocation" => "HotAtlanta",
- "type" => "MID",
- "profile" => "MID1" })
+my $mid_northeast_group = &get_cg_id('mid-northeast-group');
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $mid_northeast_group,
+ "cdnId" => 100,
+ "domainName" => "northbound.com",
+ "hostName" => "tc1_ats2",
+ "interfaceMtu" => 1500,
+ "interfaceName" => "eth0",
+ "ipAddress" => "10.74.27.184",
+ "ipNetmask" => "255.255.255.0",
+ "ipGateway" => "10.74.27.1",
+ "ip6Address" => "2001:852:fe0f:27::2/64",
+ "ip6Gateway" => "2001:852:fe0f:27::1",
+ "physLocationId" => 300,
+ "profileId" => 200,
+ "statusId" => 1,
+ "typeId" => 2,
+ "updPending" => \0,
+ })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/hostName" => "tc1_ats2")
+ ->json_is( "/response/0/hostName" => "tc1_ats2")
, 'Does the server details return?';
my $necg_id = &get_cg_id('mid-northeast-group');
@@ -213,21 +219,26 @@ ok $t->put_ok('/api/1.2/cachegroups/' . $cg_id => {Accept => 'application/json'}
"parentCachegroup" => "cache_group_edge_2",
"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",
- "domainName" => "test.example.com",
- "cachegroup" => "cache_group_edge_2",
- "cdnName" => "cdn1",
- "interfaceName" => "eth0",
- "ipAddress" => "192.168.100.2",
- "ipNetmask" => "255.255.255.0",
- "ipGateway" => "192.168.100.1",
- "interfaceMtu" => "1500",
- "physLocation" => "HotAtlanta",
- "type" => "EDGE",
- "profile" => "EDGE1" })
+
+my $cache_group_edge_2_id = &get_cg_id('cache_group_edge_2');
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $cache_group_edge_2_id,
+ "cdnId" => 100,
+ "domainName" => "test.example.com",
+ "hostName" => "edge_streamer_1",
+ "interfaceMtu" => 1500,
+ "interfaceName" => "eth0",
+ "ipAddress" => "192.168.100.2",
+ "ipNetmask" => "255.255.255.0",
+ "ipGateway" => "192.168.100.1",
+ "physLocationId" => 300,
+ "profileId" => 100,
+ "statusId" => 1,
+ "typeId" => 1,
+ "updPending" => \0,
+ })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/hostName" => "edge_streamer_1")
+ ->json_is( "/response/0/hostName" => "edge_streamer_1")
, 'Does the server details return?';
ok $t->delete_ok('/api/1.2/cachegroups/' . $cg_id)->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } )
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/eee9c2fc/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 ad4a717..91bcb5b 100644
--- a/traffic_ops/app/t/api/1.2/server.t
+++ b/traffic_ops/app/t/api/1.2/server.t
@@ -113,189 +113,211 @@ ok $t->post_ok('/api/1.2/cachegroups' => {Accept => 'application/json'} => json
->json_is( "/response/secondaryParentCachegroupName" => undef)
, 'Does the cache group details return?';
-ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
- "hostName" => "server1",
+my $cg2_mid_northwest = &get_cg_id('cg2-mid-northwest');
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $cg2_mid_northwest,
+ "cdnId" => 100,
"domainName" => "example-domain.com",
- "cachegroup" => "cg2-mid-northwest",
- "cdnName" => "cdn1",
- "ipAddress" => "10.74.27.194",
+ "hostName" => "server1",
+ "interfaceMtu" => 1500,
"interfaceName" => "bond0",
+ "ipAddress" => "10.74.27.194",
"ipNetmask" => "255.255.255.252",
"ipGateway" => "10.74.27.194",
- "interfaceMtu" => "1500",
- "physLocation" => "Denver",
- "type" => "EDGE",
- "profile" => "EDGE1" })
+ "physLocationId" => 100,
+ "profileId" => 100,
+ "statusId" => 1,
+ "typeId" => 1,
+ "updPending" => \0,
+ })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
, 'Is a server created when all required fields are provided?';
-ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
- "hostName" => "server2",
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $cg2_mid_northwest,
+ "cdnId" => 100,
"domainName" => "example-domain.com",
- "cachegroup" => "cg2-mid-northwest",
- "cdnName" => "cdn1",
- "ipAddress" => "10.74.27.194",
+ "hostName" => "server2",
+ "interfaceMtu" => 1500,
"interfaceName" => "bond0",
+ "ipAddress" => "10.74.27.194",
"ipNetmask" => "255.255.255.252",
"ipGateway" => "10.74.27.194",
- "interfaceMtu" => "1500",
- "physLocation" => "Denver",
- "type" => "EDGE",
- "profile" => "EDGE1" })
+ "physLocationId" => 100,
+ "profileId" => 100,
+ "statusId" => 1,
+ "typeId" => 1,
+ "updPending" => \0,
+ })
->status_is(400)
, 'Does the server creation fail because ip address is already used for the profile?';
-ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
- "hostName" => "server3",
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $cg2_mid_northwest,
+ "cdnId" => 100,
"domainName" => "example-domain.com",
- "cachegroup" => "cg2-mid-northwest",
- "cdnName" => "cdn1",
- "ipAddress" => "10.74.27.85",
+ "hostName" => "server2",
+ "interfaceMtu" => 1500,
"interfaceName" => "bond0",
+ "ipAddress" => "10.74.27.85",
"ipNetmask" => "255.255.255.252",
"ipGateway" => "10.74.27.85",
"ip6Address" => "2001:852:fe0f:27::2/64",
"ip6Gateway" => "2001:852:fe0f:27::1",
- "interfaceMtu" => "1500",
- "physLocation" => "Denver",
- "type" => "EDGE",
- "profile" => "EDGE1" })
+ "physLocationId" => 100,
+ "profileId" => 100,
+ "statusId" => 1,
+ "typeId" => 1,
+ "updPending" => \0,
+ })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
, 'Is a server created when all required fields are provided plus an ip6 address?';
-ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
- "hostName" => "server3",
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $cg2_mid_northwest,
+ "cdnId" => 100,
"domainName" => "example-domain.com",
- "cachegroup" => "cg2-mid-northwest",
- "cdnName" => "cdn1",
- "ipAddress" => "10.74.27.77",
+ "hostName" => "server3",
+ "interfaceMtu" => 1500,
"interfaceName" => "bond0",
+ "ipAddress" => "10.74.27.77",
"ipNetmask" => "255.255.255.252",
"ipGateway" => "10.74.27.77",
"ip6Address" => "2001:852:fe0f:27::2/64",
"ip6Gateway" => "2001:852:fe0f:27::1",
- "interfaceMtu" => "1500",
- "physLocation" => "Denver",
- "type" => "EDGE",
- "profile" => "EDGE1" })
+ "physLocationId" => 100,
+ "profileId" => 100,
+ "statusId" => 1,
+ "typeId" => 1,
+ "updPending" => \0,
+ })
->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } )
, 'Does the server creation fail because ip6 address is already used for the profile?';
-ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
- "hostName" => "tc1_ats1",
- "domainName" => "northbound.com",
- "cachegroup" => "mid-northeast-group",
- "cdnName" => "cdn1",
- "interfaceName" => "eth0",
- "ipAddress" => "10.74.27.184",
- "ipNetmask" => "255.255.255.0",
- "ipGateway" => "10.74.27.1",
- "interfaceMtu" => "1500",
- "physLocation" => "HotAtlanta",
- "type" => "MID",
- "profile" => "MID1" })
- ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/hostName" => "tc1_ats1")
- ->json_is( "/response/domainName" => "northbound.com")
- ->json_is( "/response/cachegroup" => "mid-northeast-group")
- ->json_is( "/response/ipNetmask" => "255.255.255.0")
- ->json_is( "/response/interfaceName" => "eth0")
- ->json_is( "/response/ipAddress" => "10.74.27.184")
- ->json_is( "/response/ipGateway" => "10.74.27.1")
- ->json_is( "/response/interfaceMtu" => "1500")
- ->json_is( "/response/physLocation" => "HotAtlanta")
- ->json_is( "/response/type" => "MID")
- ->json_is( "/response/profile" => "MID1")
- , 'Does the server details return?';
-
-ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
- "hostName" => "tc1_ats1",
- "domainName" => "northbound.com",
- "cachegroup" => "edge_atl_group",
- "cdnName" => "cdn1",
- "interfaceName" => "eth0",
- "ipAddress" => "10.74.27.185",
- "ipNetmask" => "255.255.255.0",
- "ipGateway" => "10.74.27.1",
- "interfaceMtu" => "1500",
- "physLocation" => "HotAtlanta",
- "type" => "EDGE",
- "profile" => "EDGE1" })
+my $mid_northeast_group = &get_cg_id('mid-northeast-group');
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $mid_northeast_group,
+ "cdnId" => 100,
+ "domainName" => "northbound.com",
+ "hostName" => "tc1_ats1",
+ "interfaceMtu" => 1500,
+ "interfaceName" => "eth0",
+ "ipAddress" => "10.74.27.184",
+ "ipNetmask" => "255.255.255.0",
+ "ipGateway" => "10.74.27.1",
+ "ip6Address" => "2001:852:fe0f:27::2/64",
+ "ip6Gateway" => "2001:852:fe0f:27::1",
+ "physLocationId" => 300,
+ "profileId" => 200,
+ "statusId" => 1,
+ "typeId" => 2,
+ "updPending" => \0,
+ })
+ ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ ->json_is( "/response/0/hostName" => "tc1_ats1")
+ ->json_is( "/response/0/domainName" => "northbound.com")
+ ->json_is( "/response/0/cachegroup" => "mid-northeast-group")
+ ->json_is( "/response/0/ipNetmask" => "255.255.255.0")
+ ->json_is( "/response/0/interfaceName" => "eth0")
+ ->json_is( "/response/0/ipAddress" => "10.74.27.184")
+ ->json_is( "/response/0/ipGateway" => "10.74.27.1")
+ ->json_is( "/response/0/interfaceMtu" => "1500")
+ ->json_is( "/response/0/physLocation" => "HotAtlanta")
+ ->json_is( "/response/0/type" => "MID")
+ ->json_is( "/response/0/profile" => "MID1")
+ , 'Does the server details return?';
+
+my $edge_atl_group = &get_cg_id('edge_atl_group');
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $edge_atl_group,
+ "cdnId" => 100,
+ "domainName" => "northbound.com",
+ "hostName" => "tc1_ats1",
+ "interfaceMtu" => 1500,
+ "interfaceName" => "eth0",
+ "ipAddress" => "10.74.27.184",
+ "ipNetmask" => "255.255.255.0",
+ "ipGateway" => "10.74.27.1",
+ "physLocationId" => 300,
+ "profileId" => 100,
+ "statusId" => 1,
+ "typeId" => 1,
+ "updPending" => \0,
+ })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/hostName" => "tc1_ats1")
- ->json_is( "/response/domainName" => "northbound.com")
- ->json_is( "/response/cachegroup" => "edge_atl_group")
- ->json_is( "/response/ipNetmask" => "255.255.255.0")
- ->json_is( "/response/interfaceName" => "eth0")
- ->json_is( "/response/ipAddress" => "10.74.27.185")
- ->json_is( "/response/ipGateway" => "10.74.27.1")
- ->json_is( "/response/interfaceMtu" => "1500")
- ->json_is( "/response/physLocation" => "HotAtlanta")
- ->json_is( "/response/type" => "EDGE")
- ->json_is( "/response/profile" => "EDGE1")
+ ->json_is( "/response/0/hostName" => "tc1_ats1")
+ ->json_is( "/response/0/domainName" => "northbound.com")
+ ->json_is( "/response/0/cachegroup" => "edge_atl_group")
+ ->json_is( "/response/0/ipNetmask" => "255.255.255.0")
+ ->json_is( "/response/0/interfaceName" => "eth0")
+ ->json_is( "/response/0/ipAddress" => "10.74.27.184")
+ ->json_is( "/response/0/ipGateway" => "10.74.27.1")
+ ->json_is( "/response/0/interfaceMtu" => "1500")
+ ->json_is( "/response/0/physLocation" => "HotAtlanta")
+ ->json_is( "/response/0/type" => "EDGE")
+ ->json_is( "/response/0/profile" => "EDGE1")
, 'Does the server details return?';
-ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
- "hostName" => "tc1_ats2",
- "domainName" => "northbound.com",
- "cachegroup" => "edge_atl_group",
- "cdnName" => "cdn1",
- "interfaceName" => "eth0",
- "ipAddress" => "10.74.27.187",
- "ipNetmask" => "255.255.255.0",
- "ipGateway" => "10.74.27.1",
- "interfaceMtu" => "1500",
- "physLocation" => "HotAtlanta",
- "type" => "EDGE",
- "profile" => "EDGE1" })
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $edge_atl_group,
+ "cdnId" => 100,
+ "domainName" => "northbound.com",
+ "hostName" => "tc1_ats2",
+ "interfaceMtu" => 1500,
+ "interfaceName" => "eth0",
+ "ipAddress" => "10.74.27.187",
+ "ipNetmask" => "255.255.255.0",
+ "ipGateway" => "10.74.27.1",
+ "physLocationId" => 300,
+ "profileId" => 100,
+ "statusId" => 1,
+ "typeId" => 1,
+ "updPending" => \0,
+ })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/hostName" => "tc1_ats2")
- ->json_is( "/response/domainName" => "northbound.com")
- ->json_is( "/response/cachegroup" => "edge_atl_group")
- ->json_is( "/response/ipNetmask" => "255.255.255.0")
- ->json_is( "/response/interfaceName" => "eth0")
- ->json_is( "/response/ipAddress" => "10.74.27.187")
- ->json_is( "/response/ipGateway" => "10.74.27.1")
- ->json_is( "/response/interfaceMtu" => "1500")
- ->json_is( "/response/physLocation" => "HotAtlanta")
- ->json_is( "/response/type" => "EDGE")
- ->json_is( "/response/profile" => "EDGE1")
+ ->json_is( "/response/0/hostName" => "tc1_ats2")
+ ->json_is( "/response/0/domainName" => "northbound.com")
+ ->json_is( "/response/0/cachegroup" => "edge_atl_group")
+ ->json_is( "/response/0/ipNetmask" => "255.255.255.0")
+ ->json_is( "/response/0/interfaceName" => "eth0")
+ ->json_is( "/response/0/ipAddress" => "10.74.27.187")
+ ->json_is( "/response/0/ipGateway" => "10.74.27.1")
+ ->json_is( "/response/0/interfaceMtu" => "1500")
+ ->json_is( "/response/0/physLocation" => "HotAtlanta")
+ ->json_is( "/response/0/type" => "EDGE")
+ ->json_is( "/response/0/profile" => "EDGE1")
, 'Does the server details return?';
-ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
- "hostName" => "tc2_ats2",
- "domainName" => "northbound.com",
- "cachegroup" => "edge_atl_group",
- "cdnName" => "cdn1",
- "interfaceName" => "eth0",
- "ipAddress" => "10.73.27.187",
- "ipNetmask" => "255.255.255.0",
- "ipGateway" => "10.73.27.1",
- "interfaceMtu" => "1500",
- "physLocation" => "HotAtlanta",
- "type" => "MID",
- "profile" => "MID1" })
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $edge_atl_group,
+ "cdnId" => 100,
+ "domainName" => "northbound.com",
+ "hostName" => "tc2_ats2",
+ "interfaceMtu" => 1500,
+ "interfaceName" => "eth0",
+ "ipAddress" => "10.73.27.187",
+ "ipNetmask" => "255.255.255.0",
+ "ipGateway" => "10.73.27.1",
+ "physLocationId" => 300,
+ "profileId" => 200,
+ "statusId" => 1,
+ "typeId" => 2,
+ "updPending" => \0,
+ })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/hostName" => "tc2_ats2")
- ->json_is( "/response/domainName" => "northbound.com")
- ->json_is( "/response/cachegroup" => "edge_atl_group")
- ->json_is( "/response/ipNetmask" => "255.255.255.0")
- ->json_is( "/response/interfaceName" => "eth0")
- ->json_is( "/response/ipAddress" => "10.73.27.187")
- ->json_is( "/response/ipGateway" => "10.73.27.1")
- ->json_is( "/response/interfaceMtu" => "1500")
- ->json_is( "/response/physLocation" => "HotAtlanta")
- ->json_is( "/response/type" => "MID")
- ->json_is( "/response/profile" => "MID1")
+ ->json_is( "/response/0/hostName" => "tc2_ats2")
+ ->json_is( "/response/0/domainName" => "northbound.com")
+ ->json_is( "/response/0/cachegroup" => "edge_atl_group")
+ ->json_is( "/response/0/ipNetmask" => "255.255.255.0")
+ ->json_is( "/response/0/interfaceName" => "eth0")
+ ->json_is( "/response/0/ipAddress" => "10.73.27.187")
+ ->json_is( "/response/0/ipGateway" => "10.73.27.1")
+ ->json_is( "/response/0/interfaceMtu" => "1500")
+ ->json_is( "/response/0/physLocation" => "HotAtlanta")
+ ->json_is( "/response/0/type" => "MID")
+ ->json_is( "/response/0/profile" => "MID1")
, 'Does the server details return?';
-ok $t->post_ok('/api/1.2/deliveryservices/test-ds1/servers' => {Accept => 'application/json'} => json => { "serverNames" => [ 'server1', 'server3' ]})
- ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- , 'Assign the server to the delivery service?';
-
-ok $t->get_ok('/api/1.2/servers/details.json?hostName=server1')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/0/ipGateway", "10.74.27.194" )->json_is( "/response/0/deliveryservices/0", "100" ), 'Does the hostname details return?';
-
ok $t->get_ok('/api/1.2/servers/details')->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ),
'Does the validation error occur?';
ok $t->get_ok('/api/1.2/servers/details.json?orderby=hostName')->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } ),
@@ -323,59 +345,45 @@ 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}; } );
-# Count the 'response number'
-my $count_response = sub {
- my ( $t, $count ) = @_;
- my $json = decode_json( $t->tx->res->content->asset->slurp );
- my $r = $json->{response};
- return $t->success( is( scalar(@$r), $count ) );
-};
-
-# this is a dns delivery service with 2 edges and 1 mid and since dns ds's DO employ mids, 3 servers return
-$t->get_ok('/api/1.2/servers?dsId=100')->status_is(200)->$count_response(2)
- ->or( sub { diag $t->tx->res->content->asset->{content}; } );
-
-# this is a http_no_cache delivery service with 2 edges and 1 mid and since http_no_cache ds's DON'T employ mids, 2 servers return
-$t->get_ok('/api/1.2/servers?dsId=400')->status_is(200)->$count_response(2)
- ->or( sub { diag $t->tx->res->content->asset->{content}; } );
-
my $svr_id = &get_svr_id('tc1_ats1');
-
-ok $t->put_ok('/api/1.2/servers/' . $svr_id . '/update' => {Accept => 'application/json'} => json => {
- "hostName" => "tc1_ats3",
- "domainName" => "northbound.com",
- "cachegroup" => "edge_atl_group",
- "cdnName" => "cdn1",
- "interfaceName" => "eth0",
- "ipAddress" => "10.74.27.186",
- "ipNetmask" => "255.255.255.0",
- "ipGateway" => "10.74.27.1",
- "interfaceMtu" => "1500",
- "physLocation" => "Denver",
- "type" => "EDGE",
- "profile" => "EDGE1" })
+ok $t->put_ok('/api/1.2/servers/' . $svr_id => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $edge_atl_group,
+ "cdnId" => 100,
+ "domainName" => "northbound.com",
+ "hostName" => "tc1_ats3",
+ "interfaceMtu" => 1500,
+ "interfaceName" => "eth0",
+ "ipAddress" => "10.74.27.186",
+ "ipNetmask" => "255.255.255.0",
+ "ipGateway" => "10.74.27.1",
+ "physLocationId" => 100,
+ "profileId" => 100,
+ "statusId" => 1,
+ "typeId" => 1,
+ "updPending" => \0,
+ })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/hostName" => "tc1_ats3")
- ->json_is( "/response/domainName" => "northbound.com")
- ->json_is( "/response/cachegroup" => "edge_atl_group")
- ->json_is( "/response/ipNetmask" => "255.255.255.0")
- ->json_is( "/response/interfaceName" => "eth0")
- ->json_is( "/response/ipAddress" => "10.74.27.186")
- ->json_is( "/response/ipGateway" => "10.74.27.1")
- ->json_is( "/response/interfaceMtu" => "1500")
- ->json_is( "/response/physLocation" => "Denver")
- ->json_is( "/response/type" => "EDGE")
- ->json_is( "/response/profile" => "EDGE1")
+ ->json_is( "/response/0/hostName" => "tc1_ats3")
+ ->json_is( "/response/0/domainName" => "northbound.com")
+ ->json_is( "/response/0/cachegroup" => "edge_atl_group")
+ ->json_is( "/response/0/ipNetmask" => "255.255.255.0")
+ ->json_is( "/response/0/interfaceName" => "eth0")
+ ->json_is( "/response/0/ipAddress" => "10.74.27.186")
+ ->json_is( "/response/0/ipGateway" => "10.74.27.1")
+ ->json_is( "/response/0/interfaceMtu" => "1500")
+ ->json_is( "/response/0/physLocation" => "Denver")
+ ->json_is( "/response/0/type" => "EDGE")
+ ->json_is( "/response/0/profile" => "EDGE1")
, 'Does the server details return?';
-ok $t->put_ok('/api/1.2/servers/' . $svr_id . '/update' => {Accept => 'application/json'} => json => {
+ok $t->put_ok('/api/1.2/servers/' . $svr_id => {Accept => 'application/json'} => json => {
"ipAddress" => "10.10.10.220",
"ipGateway" => "111.222.111.1",
"ipNetmask" => "255.255.255.0" })
->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } )
, 'Does the server details return?';
-ok $t->put_ok('/api/1.2/servers/' . $svr_id . '/update' => {Accept => 'application/json'} => json => {
+ok $t->put_ok('/api/1.2/servers/' . $svr_id => {Accept => 'application/json'} => json => {
"ip6Address" => "ee80::1",
"ip6Gateway" => "fe80::1" })
->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } )
@@ -403,11 +411,22 @@ ok $t->delete_ok('/api/1.2/servers/' . $svr_id)
ok $t->delete_ok('/api/1.2/servers/' . $svr_id)
->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } );
-ok $t->put_ok('/api/1.2/servers/' . $svr_id . '/update' => {Accept => 'application/json'} => json => {
- "hostName" => "tc1_ats1",
- "domainName" => "northbound.com",
- "ipAddress" => "10.74.27.185",
- "physLocation" => "HotAtlanta" })
+ok $t->put_ok('/api/1.2/servers/' . $svr_id => {Accept => 'application/json'} => json => {
+ "cachegroupId" => $edge_atl_group,
+ "cdnId" => 100,
+ "domainName" => "northbound.com",
+ "hostName" => "tc1_ats3",
+ "interfaceMtu" => 1500,
+ "interfaceName" => "eth0",
+ "ipAddress" => "10.74.27.186",
+ "ipNetmask" => "255.255.255.0",
+ "ipGateway" => "10.74.27.1",
+ "physLocationId" => 100,
+ "profileId" => 100,
+ "statusId" => 1,
+ "typeId" => 1,
+ "updPending" => \0,
+ })
->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } );
ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
@@ -580,3 +599,15 @@ sub get_svr_id {
my $id = $p->[0]->{id};
return $id;
}
+
+sub get_cg_id {
+ my $cg_name = shift;
+ my $q = "select id from cachegroup where name = \'$cg_name\'";
+ my $get_cg = $dbh->prepare($q);
+ $get_cg->execute();
+ my $p = $get_cg->fetchall_arrayref( {} );
+ $get_cg->finish();
+ my $id = $p->[0]->{id};
+ return $id;
+}
+
[3/6] incubator-trafficcontrol git commit: removes duplicate
cachegroup apis
Posted by de...@apache.org.
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 <mi...@gmail.com>
Authored: Wed Apr 19 10:03:34 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
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 => {
[6/6] incubator-trafficcontrol git commit: removes duplicate
deliveryservice apis
Posted by de...@apache.org.
removes duplicate deliveryservice 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/7130816b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/7130816b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/7130816b
Branch: refs/heads/master
Commit: 7130816bba7569f1db8b908a5896912293ead6ee
Parents: eee9c2f
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Wed Apr 19 14:02:44 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Thu Jul 13 14:52:07 2017 -0600
----------------------------------------------------------------------
traffic_ops/app/lib/API/Deliveryservice.pm | 56 ++
traffic_ops/app/lib/API/Deliveryservice2.pm | 694 -----------------------
traffic_ops/app/t/api/1.2/deliveryservice.t | 451 ++++-----------
traffic_ops/app/t/api/1.2/server.t | 5 +
4 files changed, 158 insertions(+), 1048 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7130816b/traffic_ops/app/lib/API/Deliveryservice.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Deliveryservice.pm b/traffic_ops/app/lib/API/Deliveryservice.pm
index 4cf567b..0ac26f5 100644
--- a/traffic_ops/app/lib/API/Deliveryservice.pm
+++ b/traffic_ops/app/lib/API/Deliveryservice.pm
@@ -657,6 +657,62 @@ sub delete {
return $self->success_message("Delivery service was deleted.");
}
+sub assign_servers {
+ my $self = shift;
+ my $ds_xml_Id = $self->param('xml_id');
+ my $params = $self->req->json;
+
+ if ( !defined($params) ) {
+ return $self->alert("parameters are JSON format, please check!");
+ }
+ if ( !&is_oper($self) ) {
+ return $self->alert("You must be an ADMIN or OPER to perform this operation!");
+ }
+
+ if ( !exists( $params->{serverNames} ) ) {
+ return $self->alert("Parameter 'serverNames' is required.");
+ }
+
+ my $dsid = $self->db->resultset('Deliveryservice')->search( { xml_id => $ds_xml_Id } )->get_column('id')->single();
+ if ( !defined($dsid) ) {
+ return $self->alert( "DeliveryService[" . $ds_xml_Id . "] is not found." );
+ }
+
+ my @server_ids;
+ my $svrs = $params->{serverNames};
+ foreach my $svr (@$svrs) {
+ my $svr_id = $self->db->resultset('Server')->search( { host_name => $svr } )->get_column('id')->single();
+ if ( !defined($svr_id) ) {
+ return $self->alert( "Server[" . $svr . "] is not found in database." );
+ }
+ push( @server_ids, $svr_id );
+ }
+
+ # clean up
+ my $delete = $self->db->resultset('DeliveryserviceServer')->search( { deliveryservice => $dsid } );
+ $delete->delete();
+
+ # assign servers
+ foreach my $s_id (@server_ids) {
+ my $insert = $self->db->resultset('DeliveryserviceServer')->create(
+ {
+ deliveryservice => $dsid,
+ server => $s_id,
+ }
+ );
+ $insert->insert();
+ }
+
+ my $ds = $self->db->resultset('Deliveryservice')->search( { id => $dsid } )->single();
+ &UI::DeliveryService::header_rewrite( $self, $ds->id, $ds->profile, $ds->xml_id, $ds->edge_header_rewrite, "edge" );
+
+ my $response;
+ $response->{xmlId} = $ds->xml_id;
+ $response->{'serverNames'} = \@$svrs;
+
+ return $self->success($response);
+}
+
sub get_deliveryservices_by_serverId {
my $self = shift;
my $server_id = $self->param('id');
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7130816b/traffic_ops/app/lib/API/Deliveryservice2.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Deliveryservice2.pm b/traffic_ops/app/lib/API/Deliveryservice2.pm
deleted file mode 100644
index e779080..0000000
--- a/traffic_ops/app/lib/API/Deliveryservice2.pm
+++ /dev/null
@@ -1,694 +0,0 @@
-package API::Deliveryservice2;
-#
-#
-# 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.
-#
-#
-#
-
-# 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 UI::DeliveryService;
-use Mojo::Base 'Mojolicious::Controller';
-use Mojolicious::Validator;
-use Mojolicious::Validator::Validation;
-use Email::Valid;
-use Validate::Tiny ':all';
-use Data::Dumper;
-use Common::ReturnCodes qw(SUCCESS ERROR);
-use JSON;
-use MojoPlugins::Response;
-use UI::DeliveryService;
-use Scalar::Util qw(looks_like_number);
-
-my $valid_server_types = {
- edge => "EDGE",
- mid => "MID",
-};
-
-# this structure maps the above types to the allowed metrics below
-my $valid_metric_types = {
- origin_tps => "mid",
- ooff => "mid",
-};
-
-sub delivery_services {
- my $self = shift;
- my $id = $self->param('id');
- my $logs_enabled = $self->param('logsEnabled');
- my $current_user = $self->current_user()->{username};
-
- my $rs;
- my $tm_user_id;
- my $forbidden;
- if ( defined($id) || defined($logs_enabled) ) {
- ( $forbidden, $rs, $tm_user_id ) = $self->get_delivery_service_params( $current_user, $id, $logs_enabled );
- }
- else {
- ( $rs, $tm_user_id ) = $self->get_delivery_services_by_user($current_user);
- }
-
- my @data;
- if ( defined($rs) ) {
- while ( my $row = $rs->next ) {
- my $re_rs = $row->deliveryservice_regexes;
- my @matchlist = ();
-
- while ( my $re_row = $re_rs->next ) {
- push(
- @matchlist, {
- type => $re_row->regex->type->name,
- pattern => $re_row->regex->pattern,
- setNumber => $re_row->set_number,
- }
- );
- }
-
- my $cdn_domain = $self->get_cdn_domain_by_ds_id($row->id);
- my $regexp_set = &UI::DeliveryService::get_regexp_set( $self, $row->id );
- my @example_urls = &UI::DeliveryService::get_example_urls( $self, $row->id, $regexp_set, $row, $cdn_domain, $row->protocol );
-
- push(
- @data, {
- "active" => \$row->active,
- "cacheurl" => $row->cacheurl,
- "ccrDnsTtl" => $row->ccr_dns_ttl,
- "cdnId" => $row->cdn->id,
- "cdnName" => $row->cdn->name,
- "checkPath" => $row->check_path,
- "displayName" => $row->display_name,
- "dnsBypassCname" => $row->dns_bypass_cname,
- "dnsBypassIp" => $row->dns_bypass_ip,
- "dnsBypassIp6" => $row->dns_bypass_ip6,
- "dnsBypassTtl" => $row->dns_bypass_ttl,
- "dscp" => $row->dscp,
- "edgeHeaderRewrite" => $row->edge_header_rewrite,
- "exampleURLs" => \@example_urls,
- "geoLimitRedirectURL" => $row->geolimit_redirect_url,
- "geoLimit" => $row->geo_limit,
- "geoLimitCountries" => $row->geo_limit_countries,
- "geoProvider" => $row->geo_provider,
- "globalMaxMbps" => $row->global_max_mbps,
- "globalMaxTps" => $row->global_max_tps,
- "httpBypassFqdn" => $row->http_bypass_fqdn,
- "id" => $row->id,
- "infoUrl" => $row->info_url,
- "initialDispersion" => $row->initial_dispersion,
- "ipv6RoutingEnabled" => \$row->ipv6_routing_enabled,
- "lastUpdated" => $row->last_updated,
- "logsEnabled" => \$row->logs_enabled,
- "longDesc" => $row->long_desc,
- "longDesc1" => $row->long_desc_1,
- "longDesc2" => $row->long_desc_2,
- "matchList" => \@matchlist,
- "maxDnsAnswers" => $row->max_dns_answers,
- "midHeaderRewrite" => $row->mid_header_rewrite,
- "missLat" => $row->miss_lat,
- "missLong" => $row->miss_long,
- "multiSiteOrigin" => \$row->multi_site_origin,
- # "multiSiteOriginAlgorithm" => $row->multi_site_origin_algorithm,
- "orgServerFqdn" => $row->org_server_fqdn,
- "originShield" => $row->origin_shield,
- "profileId" => $row->profile->id,
- "profileName" => $row->profile->name,
- "profileDescription" => $row->profile->description,
- "protocol" => $row->protocol,
- "qstringIgnore" => $row->qstring_ignore,
- "rangeRequestHandling" => $row->range_request_handling,
- "regexRemap" => $row->regex_remap,
- "regionalGeoBlocking" => \$row->regional_geo_blocking,
- "remapText" => $row->remap_text,
- "signed" => \$row->signed,
- "sslKeyVersion" => $row->ssl_key_version,
- "tenantId" => $row->tenant_id,
- "tenant" => defined( $row->tenant ) ? $row->tenant->name : undef,
- "trRequestHeaders" => $row->tr_request_headers,
- "trResponseHeaders" => $row->tr_response_headers,
- "type" => $row->type->name,
- "typeId" => $row->type->id,
- "xmlId" => $row->xml_id
- }
- );
- }
- }
-
- return defined($forbidden) ? $self->forbidden() : $self->success( \@data );
-}
-
-sub get_delivery_services_by_user {
- my $self = shift;
- my $current_user = shift;
-
- my $tm_user_id;
- my $rs;
- if ( &is_privileged($self) ) {
- $rs = $self->db->resultset('Deliveryservice')->search( undef, { prefetch => [ 'cdn', 'deliveryservice_regexes', 'tenant' ], order_by => 'xml_id' } );
- }
- else {
- my $tm_user = $self->db->resultset('TmUser')->search( { username => $current_user } )->single();
- $tm_user_id = $tm_user->id;
-
- my @ds_ids = $self->db->resultset('DeliveryserviceTmuser')->search( { tm_user_id => $tm_user_id } )->get_column('deliveryservice')->all();
- $rs = $self->db->resultset('Deliveryservice')
- ->search( { 'me.id' => { -in => \@ds_ids } }, { prefetch => [ 'cdn', 'deliveryservice_regexes', 'tenant' ], order_by => 'xml_id' } );
- }
-
- return ( $rs, $tm_user_id );
-}
-
-sub get_delivery_service_params {
- my $self = shift;
- my $current_user = shift;
- my $id = shift;
- my $logs_enabled = shift;
-
- # Convert to 1 or 0
- $logs_enabled = $logs_enabled ? 1 : 0;
-
- my $tm_user_id;
- my $rs;
- my $forbidden;
- my $condition;
- if ( &is_privileged($self) ) {
- if ( defined($id) ) {
- $condition = ( { 'me.id' => $id } );
- }
- else {
- $condition = ( { 'me.logs_enabled' => $logs_enabled } );
- }
- $rs =
- $self->db->resultset('Deliveryservice')->search( $condition, { prefetch => [ 'cdn', 'deliveryservice_regexes', 'tenant' ], order_by => 'xml_id' } );
- }
- elsif ( $self->is_delivery_service_assigned($id) ) {
- my $tm_user = $self->db->resultset('TmUser')->search( { username => $current_user } )->single();
- $tm_user_id = $tm_user->id;
-
- my @ds_ids =
- $self->db->resultset('DeliveryserviceTmuser')->search( { tm_user_id => $tm_user_id, deliveryservice => $id } )->get_column('deliveryservice')
- ->all();
- $rs =
- $self->db->resultset('Deliveryservice')
- ->search( { 'me.id' => { -in => \@ds_ids } }, { prefetch => [ 'cdn', 'deliveryservice_regexes', 'tenant' ], order_by => 'xml_id' } );
- }
- elsif ( !$self->is_delivery_service_assigned($id) ) {
- $forbidden = "true";
- }
-
- return ( $forbidden, $rs, $tm_user_id );
-}
-
-sub update_profileparameter {
- my $self = shift;
- my $ds_id = shift;
- my $profile_id = shift;
- my $params = shift;
-
- &UI::DeliveryService::header_rewrite( $self, $ds_id, $profile_id, $params->{xmlId}, $params->{edgeHeaderRewrite}, "edge" );
- &UI::DeliveryService::header_rewrite( $self, $ds_id, $profile_id, $params->{xmlId}, $params->{midHeaderRewrite}, "mid" );
- &UI::DeliveryService::regex_remap( $self, $ds_id, $profile_id, $params->{xmlId}, $params->{regexRemap} );
- &UI::DeliveryService::cacheurl( $self, $ds_id, $profile_id, $params->{xmlId}, $params->{cacheurl} );
-}
-
-sub create {
- my $self = shift;
- my $params = $self->req->json;
-
- if ( !&is_oper($self) ) {
- return $self->forbidden();
- }
-
- my ($transformed_params, $err) = (undef, undef);
- ($transformed_params, $err) = $self->_check_params($params);
- if ( defined($err) ) {
- return $self->alert($err);
- }
-
- my $existing = $self->db->resultset('Deliveryservice')->search( { xml_id => $params->{xmlId} } )->get_column('xml_id')->single();
- if ( $existing ) {
- $self->alert("a delivery service with xmlId " . $params->{xmlId} . " already exists." );
- }
-
- my $value=$self->new_value($params, $transformed_params);
- my $insert = $self->db->resultset('Deliveryservice')->create($value);
- $insert->insert();
- my $new_id = $insert->id;
-
- if ( $new_id > 0 ) {
- my $patterns = $params->{matchList};
- foreach my $re (@$patterns) {
- my $type = $self->db->resultset('Type')->search( { name => $re->{type} } )->get_column('id')->single();
- my $regexp = $re->{pattern};
-
- my $insert = $self->db->resultset('Regex')->create(
- {
- pattern => $regexp,
- type => $type,
- }
- );
- $insert->insert();
- my $new_re_id = $insert->id;
-
- my $de_re_insert = $self->db->resultset('DeliveryserviceRegex')->create(
- {
- regex => $new_re_id,
- deliveryservice => $new_id,
- set_number => defined($re->{setNumber}) ? $re->{setNumber} : 0,
- }
- );
- $de_re_insert->insert();
- }
-
- my $profile_id=$transformed_params->{ profile_id };
- $self->update_profileparameter($new_id, $profile_id, $params);
-
- my $cdn_rs = $self->db->resultset('Cdn')->search( { id => $transformed_params->{cdn_id} } )->single();
- my $dnssec_enabled = $cdn_rs->dnssec_enabled;
- if ( $dnssec_enabled == 1 ) {
- $self->app->log->debug("dnssec is enabled, creating dnssec keys");
- &UI::DeliveryService::create_dnssec_keys( $self, $cdn_rs->name, $params->{xmlId}, $new_id );
- }
-
- &log( $self, "Create deliveryservice with xml_id: " . $params->{xmlId}, " APICHANGE" );
-
- my $response = $self->get_response($new_id);
- return $self->success($response, "Delivery service was created: " . $new_id);
- }
-
- my $r = "Create Delivery Service fail, insert to database failed.";
- return $self->alert($r);
-}
-
-sub nodef_to_default {
- my $self = shift;
- my $v = shift;
- my $default = shift;
-
- return $v || $default;
-}
-
-sub get_types {
- my $self = shift;
- my $use_in_table = shift;
- my $types;
- my $rs = $self->db->resultset('Type')->search( { use_in_table => $use_in_table } );
- while ( my $row = $rs->next ) {
- $types->{ $row->name } = $row->id;
- }
- return $types;
-}
-
-sub _check_params {
- my $self = shift;
- my $params = shift;
- my $ds_id = shift;
- my $transformed_params = undef;
-
- if ( !defined($params) ) {
- return (undef, "parameters should be in json format, please check!");
- }
-
- if ( !defined($params->{xmlId}) ) {
- return (undef, "parameter xmlId is must." );
- }
-
- if (!defined($params->{active})) {
- return (undef, "parameter active is must." );
- }
-
- if (looks_like_number($params->{active})) {
- if ($params->{active} == 1) {
- $transformed_params->{active} = 1;
- } elsif ($params->{active} == 0) {
- $transformed_params->{active} = 0;
- } else {
- return (undef, "active must be 1|0");
- }
- } else {
- if ($params->{active} eq "true") {
- $transformed_params->{active} = 1;
- } elsif ($params->{active} eq "false") {
- $transformed_params->{active} = 0;
- } else {
- return (undef, "active must be true|false");
- }
- }
-
- if ( defined($params->{type}) ) {
- my $rs = $self->get_types("deliveryservice");
- if ( !exists $rs->{ $params->{type} } ) {
- return (undef, "type (" . $params->{type} . ") must be deliveryservice type." );
- }
- else {
- $transformed_params->{type} = $rs->{ $params->{type} };
- }
- } else {
- return (undef, "parameter type is must." );
- }
-
- if (!defined($params->{protocol})) {
- return (undef, "parameter protocol is must." );
- }
-
- my $proto_num = $params->{protocol};
-
- if (!looks_like_number($proto_num) || $proto_num < 0 || $proto_num > 3) {
- return (undef, "protocol must be 0|1|2|3." );
- }
-
-
- if ( defined($params->{profileName}) ) {
- my $pname = $params->{profileName};
- my $profile = $self->db->resultset('Profile')->search( { 'me.name' => $pname }, { prefetch => ['cdn'] } )->single();
- if ( !defined($profile) || $profile->cdn->name ne $params->{cdnName} ) {
- return (undef, "profileName (" . $params->{profileName} . ") does not exist, or is not on the same CDN as " . $params->{cdnName} );
- }
- else {
- $transformed_params->{ profile_id } = $profile->id;
- }
- } else {
- return (undef, "parameter profileName is must." );
- }
-
-
- my $cdn_id = undef;
- if ( defined($params->{cdnName}) ) {
- $cdn_id = $self->db->resultset('Cdn')->search( { name => $params->{cdnName} } )->get_column('id')->single();
- if ( !defined $cdn_id ) {
- return (undef, "cdnName (" . $params->{cdnName} . ") does not exists." );
- } else {
- $transformed_params->{ cdn_id } = $cdn_id;
- }
- } else {
- return (undef, "parameter cdnName is must." );
- }
-
- if ( defined($params->{matchList}) ) {
- my $match_list = $params->{matchList};
-
- if ((scalar $match_list) == 0) {
- return (undef, "At least have 1 pattern in matchList.");
- }
-
- my $cdn_domain = undef;
-
- if (defined($ds_id)) {
- $cdn_domain = $self->get_cdn_domain_by_ds_id($ds_id);
- } else {
- my $profile_id = $self->get_profile_id_for_name($params->{profileName});
- $cdn_domain = $self->get_cdn_domain_by_profile_id($profile_id);
- }
-
- foreach my $match_item (@$match_list) {
- my $conflicting_regex = $self->find_existing_host_regex($match_item->{'type'}, $match_item->{'pattern'}, $cdn_domain, $cdn_id, $ds_id);
- if (defined($conflicting_regex)) {
- return(undef, "Another delivery service is already using host regex $conflicting_regex");
- }
- }
- } else {
- return (undef, "parameter matchList is must." );
- }
-
- if ( defined($params->{multiSiteOrigin}) ) {
- if ( !( ( $params->{multiSiteOrigin} eq "0" ) || ( $params->{multiSiteOrigin} eq "1" ) ) ) {
- return (undef, "multiSiteOrigin must be 0|1." );
- }
- } else {
- return (undef, "parameter multiSiteOrigin is must." );
- }
-
- if ( !defined($params->{displayName}) ) {
- return (undef, "parameter displayName is must." );
- }
-
- if ( defined($params->{orgServerFqdn}) ) {
- if ( $params->{orgServerFqdn} !~ /^https?:\/\// ) {
- return (undef, "orgServerFqdn must start with http(s)://" );
- }
- } else {
- return (undef, "parameter orgServerFqdn is must." );
- }
-
- if ( defined($params->{logsEnabled}) ) {
- if ( $params->{logsEnabled} eq "true" || $params->{logsEnabled} == 1 ) {
- $transformed_params->{logsEnabled} = 1;
- } elsif ( $params->{logsEnabled} eq "false" || $params->{logsEnabled} == 0 ) {
- $transformed_params->{logsEnabled} = 0;
- } else {
- return (undef, "logsEnabled must be true|false." );
- }
- } else {
- $transformed_params->{logsEnabled} = 0;
- }
-
- if (defined($ds_id)) {
- #update
- #setting tenant_id to undef if tenant is not set.
- $transformed_params->{tenantId} = exists($params->{tenantId}) ? $params->{tenantId} : undef;
- } else {
- #create
- #setting tenant_id to the runing user if tenant is not set.
- $transformed_params->{tenantId} = exists($params->{tenantId}) ? $params->{tenantId} : $self->current_user_tenant();
- }
-
- return ($transformed_params, undef);
-}
-
-sub new_value {
- my $self = shift;
- my $params = shift;
- my $transformed_params = shift;
-
- my $value = {
- xml_id => $params->{xmlId},
- display_name => $params->{displayName},
- dscp => $self->nodef_to_default( $params->{dscp}, 0 ),
- signed => $self->nodef_to_default( $params->{signed}, 0 ),
- qstring_ignore => $params->{qstringIgnore},
- geo_limit => $params->{geoLimit},
- geo_limit_countries => $params->{geoLimitCountries},
- geolimit_redirect_url => $params->{geoLimitRedirectURL},
- geo_provider => $params->{geoProvider},
- http_bypass_fqdn => $params->{httpBypassFqdn},
- dns_bypass_ip => $params->{dnsBypassIp},
- dns_bypass_ip6 => $params->{dnsBypassIp6},
- dns_bypass_cname => $params->{dnsBypassCname},
- dns_bypass_ttl => $params->{dnsBypassTtl},
- org_server_fqdn => $params->{orgServerFqdn},
- multi_site_origin => $params->{multiSiteOrigin},
- ccr_dns_ttl => $params->{ccrDnsTtl},
- type => $transformed_params->{type},
- profile => $transformed_params->{profile_id},
- cdn_id => $transformed_params->{cdn_id},
- global_max_mbps => $self->nodef_to_default( $params->{globalMaxMbps}, 0 ),
- global_max_tps => $self->nodef_to_default( $params->{globalMaxTps}, 0 ),
- miss_lat => $params->{missLat},
- miss_long => $params->{missLong},
- long_desc => $params->{longDesc},
- long_desc_1 => $params->{longDesc1},
- long_desc_2 => $params->{longDesc2},
- max_dns_answers => $self->nodef_to_default( $params->{maxDnsAnswers}, 0 ),
- info_url => $params->{infoUrl},
- check_path => $params->{checkPath},
- active => $transformed_params->{active},
- protocol => $params->{protocol},
- ipv6_routing_enabled => $params->{ipv6RoutingEnabled},
- range_request_handling => $params->{rangeRequestHandling},
- edge_header_rewrite => $params->{edgeHeaderRewrite},
- mid_header_rewrite => $params->{midHeaderRewrite},
- regex_remap => $params->{regexRemap},
- origin_shield => $params->{originShield},
- cacheurl => $params->{cacheurl},
- remap_text => $params->{remapText},
- initial_dispersion => $params->{initialDispersion},
- regional_geo_blocking => $self->nodef_to_default($params->{regionalGeoBlocking}, 0),
- ssl_key_version => $params->{sslKeyVersion},
- tr_request_headers => $params->{trRequestHeaders},
- tr_response_headers => $params->{trResponseHeaders},
- logs_enabled => $transformed_params->{logsEnabled},
- tenant_id => $transformed_params->{tenantId},
- };
-
- return $value;
-}
-
-sub get_response {
- my $self = shift;
- my $ds_id = shift;
-
- my $response;
- my $rs = $self->db->resultset('Deliveryservice')->find( { id => $ds_id } );
- if ( defined($rs) ) {
- my $cdn_name = $self->db->resultset('Cdn')->search( { id => $rs->cdn_id } )->get_column('name')->single();
-
- $response->{id} = $rs->id;
- $response->{xmlId} = $rs->xml_id;
- $response->{active} = $rs->active==1 ? "true" : "false";
- $response->{dscp} = $rs->dscp;
- $response->{signed} = $rs->signed;
- $response->{qstringIgnore} = $rs->qstring_ignore;
- $response->{geoLimit} = $rs->geo_limit;
- $response->{geoLimitCountries} = $rs->geo_limit_countries;
- $response->{geoLimitRedirectURL} = $rs->geolimit_redirect_url;
- $response->{geoProvider} = $rs->geo_provider;
- $response->{httpBypassFqdn} = $rs->http_bypass_fqdn;
- $response->{dnsBypassIp} = $rs->dns_bypass_ip;
- $response->{dnsBypassIp6} = $rs->dns_bypass_ip6;
- $response->{dnsBypassTtl} = $rs->dns_bypass_ttl;
- $response->{orgServerFqdn} = $rs->org_server_fqdn;
- $response->{type} = $rs->type->name;
- $response->{profileName} = $rs->profile->name;
- $response->{cdnName} = $cdn_name;
- $response->{ccrDnsTtl} = $rs->ccr_dns_ttl;
- $response->{globalMaxMbps} = $rs->global_max_mbps;
- $response->{globalMaxTps} = $rs->global_max_tps;
- $response->{longDesc} = $rs->long_desc;
- $response->{longDesc1} = $rs->long_desc_1;
- $response->{longDesc2} = $rs->long_desc_2;
- $response->{maxDnsAnswers} = $rs->max_dns_answers;
- $response->{infoUrl} = $rs->info_url;
- $response->{missLat} = $rs->miss_lat;
- $response->{missLong} = $rs->miss_long;
- $response->{checkPath} = $rs->check_path;
- $response->{protocol} = $rs->protocol;
- $response->{sslKeyVersion} = $rs->ssl_key_version;
- $response->{ipv6RoutingEnabled} = $rs->ipv6_routing_enabled;
- $response->{rangeRequestHandling} = $rs->range_request_handling;
- $response->{edgeHeaderRewrite} = $rs->edge_header_rewrite;
- $response->{originShield} = $rs->origin_shield;
- $response->{midHeaderRewrite} = $rs->mid_header_rewrite;
- $response->{regexRemap} = $rs->regex_remap;
- $response->{cacheurl} = $rs->cacheurl;
- $response->{remapText} = $rs->remap_text;
- $response->{multiSiteOrigin} = $rs->multi_site_origin;
- $response->{displayName} = $rs->display_name;
- $response->{trResponseHeaders} = $rs->tr_response_headers;
- $response->{initialDispersion} = $rs->initial_dispersion;
- $response->{dnsBypassCname} = $rs->dns_bypass_cname;
- $response->{regionalGeoBlocking} = $rs->regional_geo_blocking;
- $response->{tenantId} = $rs->tenant_id;
- $response->{trRequestHeaders} = $rs->tr_request_headers;
- $response->{logsEnabled} = $rs->logs_enabled==1 ? "true" : "false";
- }
-
- my @pats = ();
- $rs = $self->db->resultset('DeliveryserviceRegex')->search( { deliveryservice => $ds_id } );
- while ( my $row = $rs->next ) {
- push(
- @pats, {
- 'pattern' => $row->regex->pattern,
- 'type' => $row->regex->type->name,
- 'setNumber' => $row->set_number,
- }
- );
- }
- $response->{matchList} = \@pats;
-
- return $response;
-}
-
-sub update {
- my $self = shift;
- my $id = $self->param('id');
- my $params = $self->req->json;
-
- if ( !&is_oper($self) ) {
- return $self->forbidden();
- }
-
- my $ds = $self->db->resultset('Deliveryservice')->find( { id => $id } );
- if ( !defined($ds) ) {
- return $self->not_found();
- }
-
- my ($transformed_params, $err) = (undef, undef);
- ($transformed_params, $err) = $self->_check_params($params, $id);
- if ( defined($err) ) {
- return $self->alert($err);
- }
-
- my $existing = $self->db->resultset('Deliveryservice')->search( { xml_id => $params->{xmlId} } )->get_column('xml_id')->single();
- if ( $existing && $existing ne $ds->xml_id ) {
- $self->alert("a delivery service with xmlId " . $params->{xmlId} . " already exists." );
- }
- if ( $transformed_params->{ type } != $ds->type->id ) {
- return $self->alert("delivery service type can't be changed");
- }
-
- my $value=$self->new_value($params, $transformed_params);
- $ds->update($value);
-
- if ( defined($params->{matchList}) ) {
- my $patterns = $params->{matchList};
- my $patterns_len = @$patterns;
-
- my $rs = $self->db->resultset('RegexesForDeliveryService')->search( {}, { bind => [$id] } );
- my $last_number = $rs->count;
-
- my $row = $rs->next;
- my $update_number;
- my $re;
- for ( $update_number=0; $update_number < $last_number && $update_number < $patterns_len; $update_number++ ) {
- $re = @$patterns[$update_number];
- my $type = $self->db->resultset('Type')->search( { name => $re->{type} } )->get_column('id')->single();
- my $update = $self->db->resultset('Regex')->find( { id => $row->id } );
- $update->update(
- {
- pattern => $re->{pattern},
- type => $type,
- }
- );
- $update = $self->db->resultset('DeliveryserviceRegex')->find( { deliveryservice => $id, regex => $row->id } );
- $update->update( { set_number => defined($re->{setNumber}) ? $re->{setNumber} : 0 } );
- $row = $rs->next;
- }
-
- if ( $patterns_len > $last_number ) {
- for ( ; $update_number < $patterns_len; $update_number++ ) {
- $re = @$patterns[$update_number];
- my $type = $self->db->resultset('Type')->search( { name => $re->{type} } )->get_column('id')->single();
- my $insert = $self->db->resultset('Regex')->create(
- {
- pattern => $re->{pattern},
- type => $type,
- }
- );
- $insert->insert();
- my $new_re_id = $insert->id;
- my $de_re_insert = $self->db->resultset('DeliveryserviceRegex')->create(
- {
- regex => $new_re_id,
- deliveryservice => $id,
- set_number => defined($re->{setNumber}) ? $re->{setNumber} : 0,
- }
- );
- $de_re_insert->insert();
- }
- }
-
- while ( $row ) {
- my $delete_re = $self->db->resultset('Regex')->search( { id => $row->id } );
- $delete_re->delete();
- $row = $rs->next;
- }
- }
-
- my $profile_id=$transformed_params->{ profile_id };
- $self->update_profileparameter($id, $profile_id, $params);
-
- &log( $self, "Update deliveryservice with xml_id: " . $params->{xmlId}, " APICHANGE" );
-
- my $response = $self->get_response($id);
- return $self->success($response, "Delivery service was updated: " . $id);
-}
-
-1;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7130816b/traffic_ops/app/t/api/1.2/deliveryservice.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/deliveryservice.t b/traffic_ops/app/t/api/1.2/deliveryservice.t
index 7226968..2c42fed 100644
--- a/traffic_ops/app/t/api/1.2/deliveryservice.t
+++ b/traffic_ops/app/t/api/1.2/deliveryservice.t
@@ -30,21 +30,14 @@ use Test::TestHelper;
BEGIN { $ENV{MOJO_MODE} = "test" }
-
-sub run_ut {
-
-my $t = shift;
-my $schema = shift;
-my $login_user = shift;
-my $login_password = shift;
+my $schema = Schema->connect_to_database;
+my $dbh = Schema->database_handle;
+my $t = Test::Mojo->new('TrafficOps');
Test::TestHelper->unload_core_data($schema);
Test::TestHelper->load_core_data($schema);
-my $tenant_id = $schema->resultset('TmUser')->find( { username => $login_user } )->get_column('tenant_id');
-my $tenant_name = defined ($tenant_id) ? $schema->resultset('Tenant')->find( { id => $tenant_id } )->get_column('name') : "null";
-
-ok $t->post_ok( '/login', => form => { u => $login_user, p => $login_password } )->status_is(302)
+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?';
# Count the 'response number'
@@ -78,353 +71,112 @@ $t->get_ok('/api/1.2/deliveryservices/100/servers/eligible')->status_is(200)->$c
->or( sub { diag $t->tx->res->content->asset->{content}; } );
# It gets existing delivery services
-ok $t->get_ok("/api/1.2/deliveryservices/list")->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content} } )
+ok $t->get_ok("/api/1.2/deliveryservices")->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content} } )
->json_is( "/response/0/xmlId", "steering-ds1" )
->json_is( "/response/0/logsEnabled", 0 )
->json_is( "/response/0/ipv6RoutingEnabled", 1 )
->json_is( "/response/1/xmlId", "steering-ds2" );
-ok $t->get_ok("/api/1.2/deliveryservices/list?logsEnabled=true")->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content} } )
+ok $t->get_ok("/api/1.2/deliveryservices?logsEnabled=true")->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content} } )
->json_is( "/response/0/xmlId", "test-ds1" )
->json_is( "/response/0/logsEnabled", 1 )
->json_is( "/response/0/ipv6RoutingEnabled", 1 )
- ->json_is( "/response/1/xmlId", "test-ds1-root" )
- ->json_is( "/response/1/tenantId", 10**9 )
- ->json_is( "/response/1/tenant", "root" )
- ->json_is( "/response/2/xmlId", "test-ds4" );
-
-# It creates new delivery services
-ok $t->post_ok('/api/1.2/deliveryservices/create' => {Accept => 'application/json'} => json => {
- "xmlId" => "ds_1",
- "displayName" => "ds_displayname_1",
- "protocol" => "1",
- "orgServerFqdn" => "http://10.75.168.91",
- "cdnName" => "cdn1",
- "tenantId" => $tenant_id,
- "profileName" => "CCR1",
- "type" => "HTTP",
- "multiSiteOrigin" => "0",
- "regionalGeoBlocking" => "1",
- "active" => "false",
- "matchList" => [
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "0",
- "pattern" => ".*\\.ds_1\\..*"
- },
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "1",
- "pattern" => ".*\\.my_vod1\\..*"
- }
- ]})
- ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/xmlId" => "ds_1")
- ->json_is( "/response/displayName" => "ds_displayname_1")
- ->json_is( "/response/orgServerFqdn" => "http://10.75.168.91")
- ->json_is( "/response/cdnName" => "cdn1")
- ->json_is( "/response/tenantId" => $tenant_id)
- ->json_is( "/response/profileName" => "CCR1")
- ->json_is( "/response/protocol" => "1")
- ->json_is( "/response/type" => "HTTP")
- ->json_is( "/response/multiSiteOrigin" => "0")
- ->json_is( "/response/regionalGeoBlocking" => "1")
- ->json_is( "/response/active" => "false")
- ->json_is( "/response/matchList/0/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/0/setNumber" => "0")
- ->json_is( "/response/matchList/0/pattern" => ".*\\.ds_1\\..*")
- ->json_is( "/response/matchList/1/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/1/setNumber" => "1")
- ->json_is( "/response/matchList/1/pattern" => ".*\\.my_vod1\\..*")
- , 'Does the deliveryservice details return?';
-
-ok $t->post_ok('/api/1.2/deliveryservices/create' => {Accept => 'application/json'} => json => {
- "xmlId" => "ds_2",
- "displayName" => "ds_displayname_2",
- "protocol" => "1",
- "orgServerFqdn" => "http://10.75.168.91",
- "cdnName" => "cdn1",
- "profileName" => "CCR1",
- "type" => "HTTP",
- "multiSiteOrigin" => "0",
- "regionalGeoBlocking" => "1",
- "active" => "false",
- "matchList" => [
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "0",
- "pattern" => ".*\\.ds_2\\..*"
- },
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "1",
- "pattern" => ".*\\.my_vod2\\..*"
- }
- ]})
- ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/xmlId" => "ds_2")
- ->json_is( "/response/displayName" => "ds_displayname_2")
- ->json_is( "/response/orgServerFqdn" => "http://10.75.168.91")
- ->json_is( "/response/cdnName" => "cdn1")
- ->json_is( "/response/tenantId" => $tenant_id)#tenant id is derived from the current tenant
- ->json_is( "/response/profileName" => "CCR1")
- ->json_is( "/response/protocol" => "1")
- ->json_is( "/response/type" => "HTTP")
- ->json_is( "/response/multiSiteOrigin" => "0")
- ->json_is( "/response/regionalGeoBlocking" => "1")
- ->json_is( "/response/active" => "false")
- ->json_is( "/response/matchList/0/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/0/setNumber" => "0")
- ->json_is( "/response/matchList/0/pattern" => ".*\\.ds_2\\..*")
- ->json_is( "/response/matchList/1/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/1/setNumber" => "1")
- ->json_is( "/response/matchList/1/pattern" => ".*\\.my_vod2\\..*")
- , 'Does the deliveryservice details return?';
-
-# It allows adding a delivery service to a different CDN with a matching regex in another CDN's delivery service
-ok $t->post_ok('/api/1.2/deliveryservices/create' => {Accept => 'application/json'} => json => {
- "xmlId" => "ds_3",
- "displayName" => "ds_displayname_1",
- "protocol" => "1",
- "orgServerFqdn" => "http://10.75.168.91",
- "cdnName" => "cdn2",
- "profileName" => "CCR2",
- "tenantId" => $tenant_id,
- "type" => "HTTP",
- "multiSiteOrigin" => "0",
- "regionalGeoBlocking" => "1",
- "active" => "false",
- "matchList" => [
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "0",
- "pattern" => ".*\\.ds_1\\..*"
- },
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "1",
- "pattern" => ".*\\.my_vod2\\..*"
- }
- ]})
+ ->json_is( "/response/1/xmlId", "test-ds4" );
+
+ok $t->post_ok('/api/1.2/deliveryservices' => {Accept => 'application/json'} => json => {
+ "active" => \0,
+ "cdnId" => 100,
+ "displayName" => "ds_displayname_1",
+ "dscp" => 0,
+ "geoLimit" => 0,
+ "geoProvider" => 0,
+ "initialDispersion" => 1,
+ "ipv6RoutingEnabled" => 0,
+ "logsEnabled" => 0,
+ "missLat" => 45,
+ "missLong" => 45,
+ "multiSiteOrigin" => 0,
+ "orgServerFqdn" => "http://10.75.168.91",
+ "protocol" => 1,
+ "qstringIgnore" => 0,
+ "rangeRequestHandling" => 0,
+ "regionalGeoBlocking" => 0,
+ "signed" => 0,
+ "typeId" => 7,
+ "xmlId" => "ds_1",
+ })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/xmlId" => "ds_3")
- ->json_is( "/response/displayName" => "ds_displayname_1")
- ->json_is( "/response/orgServerFqdn" => "http://10.75.168.91")
- ->json_is( "/response/cdnName" => "cdn2")
- ->json_is( "/response/profileName" => "CCR2")
- ->json_is( "/response/tenantId" => $tenant_id)
- ->json_is( "/response/protocol" => "1")
- ->json_is( "/response/type" => "HTTP")
- ->json_is( "/response/multiSiteOrigin" => "0")
- ->json_is( "/response/regionalGeoBlocking" => "1")
- ->json_is( "/response/active" => "false")
- ->json_is( "/response/matchList/0/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/0/setNumber" => "0")
- ->json_is( "/response/matchList/0/pattern" => ".*\\.ds_1\\..*")
- ->json_is( "/response/matchList/1/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/1/setNumber" => "1")
- ->json_is( "/response/matchList/1/pattern" => ".*\\.my_vod2\\..*")
+ ->json_is( "/response/0/active" => 0)
+ ->json_is( "/response/0/cdnName" => "cdn1")
+ ->json_is( "/response/0/displayName" => "ds_displayname_1")
+ ->json_is( "/response/0/xmlId" => "ds_1")
+ ->json_is( "/response/0/multiSiteOrigin" => 0)
+ ->json_is( "/response/0/orgServerFqdn" => "http://10.75.168.91")
+ ->json_is( "/response/0/protocol" => 1)
+ ->json_is( "/response/0/regionalGeoBlocking" => 0)
+ ->json_is( "/response/0/type" => "DNS")
, 'Does the deliveryservice details return?';
my $ds_id = &get_ds_id('ds_1');
-
-ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id . '/update' => {Accept => 'application/json'} => json => {
- "xmlId" => "ds_1",
- "displayName" => "ds_displayname_11",
- "protocol" => "2",
- "orgServerFqdn" => "http://10.75.168.91",
- "cdnName" => "cdn1",
- "tenantId" => $tenant_id,
- "profileName" => "CCR1",
- "type" => "HTTP",
- "multiSiteOrigin" => "0",
- "regionalGeoBlocking" => "0",
- "active" => "true",
- "matchList" => [
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "0",
- "pattern" => ".*\\.my_vod1\\..*"
- }
- ]})
- ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/xmlId" => "ds_1")
- ->json_is( "/response/displayName" => "ds_displayname_11")
- ->json_is( "/response/orgServerFqdn" => "http://10.75.168.91")
- ->json_is( "/response/cdnName" => "cdn1")
- ->json_is( "/response/tenantId" => $tenant_id)
- ->json_is( "/response/profileName" => "CCR1")
- ->json_is( "/response/protocol" => "2")
- ->json_is( "/response/type" => "HTTP")
- ->json_is( "/response/multiSiteOrigin" => "0")
- ->json_is( "/response/regionalGeoBlocking" => "0")
- ->json_is( "/response/active" => "true")
- ->json_is( "/response/matchList/0/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/0/setNumber" => "0")
- ->json_is( "/response/matchList/0/pattern" => ".*\\.my_vod1\\..*")
- , 'Does the deliveryservice details return?';
-
-
-
-#removing tenancy when no set
-ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id . '/update' => {Accept => 'application/json'} => json => {
- "xmlId" => "ds_1",
- "displayName" => "ds_displayname_11",
- "protocol" => "2",
- "orgServerFqdn" => "http://10.75.168.91",
- "cdnName" => "cdn1",
- "profileName" => "CCR1",
- "type" => "HTTP",
- "multiSiteOrigin" => "0",
- "regionalGeoBlocking" => "0",
- "active" => "true",
- "matchList" => [
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "0",
- "pattern" => ".*\\.my_vod1\\..*"
- }
- ]})
- ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/xmlId" => "ds_1")
- ->json_is( "/response/displayName" => "ds_displayname_11")
- ->json_is( "/response/orgServerFqdn" => "http://10.75.168.91")
- ->json_is( "/response/cdnName" => "cdn1")
- ->json_is( "/response/tenantId" => undef)
- ->json_is( "/response/profileName" => "CCR1")
- ->json_is( "/response/protocol" => "2")
- ->json_is( "/response/type" => "HTTP")
- ->json_is( "/response/multiSiteOrigin" => "0")
- ->json_is( "/response/regionalGeoBlocking" => "0")
- ->json_is( "/response/active" => "true")
- ->json_is( "/response/matchList/0/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/0/setNumber" => "0")
- ->json_is( "/response/matchList/0/pattern" => ".*\\.my_vod1\\..*")
- , 'Does the deliveryservice details return?';
-
-
-#putting tenancy back
-ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id . '/update' => {Accept => 'application/json'} => json => {
- "xmlId" => "ds_1",
- "displayName" => "ds_displayname_11",
- "protocol" => "2",
- "orgServerFqdn" => "http://10.75.168.91",
- "cdnName" => "cdn1",
- "tenantId" => $tenant_id,
- "profileName" => "CCR1",
- "type" => "HTTP",
- "multiSiteOrigin" => "0",
- "regionalGeoBlocking" => "0",
- "active" => "true",
- "matchList" => [
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "0",
- "pattern" => ".*\\.my_vod1\\..*"
- }
- ]})
+ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id => {Accept => 'application/json'} => json => {
+ "active" => \1,
+ "cdnId" => 100,
+ "displayName" => "ds_displayname_11",
+ "dscp" => 1,
+ "geoLimit" => 1,
+ "geoProvider" => 1,
+ "initialDispersion" => 2,
+ "ipv6RoutingEnabled" => 1,
+ "logsEnabled" => 1,
+ "missLat" => 45,
+ "missLong" => 45,
+ "multiSiteOrigin" => 0,
+ "orgServerFqdn" => "http://10.75.168.91",
+ "protocol" => 2,
+ "qstringIgnore" => 1,
+ "rangeRequestHandling" => 1,
+ "regionalGeoBlocking" => 1,
+ "signed" => 1,
+ "typeId" => 7,
+ "xmlId" => "ds_1",
+ })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/xmlId" => "ds_1")
- ->json_is( "/response/displayName" => "ds_displayname_11")
- ->json_is( "/response/orgServerFqdn" => "http://10.75.168.91")
- ->json_is( "/response/cdnName" => "cdn1")
- ->json_is( "/response/tenantId" => $tenant_id)
- ->json_is( "/response/profileName" => "CCR1")
- ->json_is( "/response/protocol" => "2")
- ->json_is( "/response/type" => "HTTP")
- ->json_is( "/response/multiSiteOrigin" => "0")
- ->json_is( "/response/regionalGeoBlocking" => "0")
- ->json_is( "/response/active" => "true")
- ->json_is( "/response/matchList/0/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/0/setNumber" => "0")
- ->json_is( "/response/matchList/0/pattern" => ".*\\.my_vod1\\..*")
+ ->json_is( "/response/0/active" => 1)
+ ->json_is( "/response/0/cdnName" => "cdn1")
+ ->json_is( "/response/0/displayName" => "ds_displayname_11")
+ ->json_is( "/response/0/xmlId" => "ds_1")
+ ->json_is( "/response/0/multiSiteOrigin" => 0)
+ ->json_is( "/response/0/orgServerFqdn" => "http://10.75.168.91")
+ ->json_is( "/response/0/protocol" => 2)
+ ->json_is( "/response/0/regionalGeoBlocking" => 1)
+ ->json_is( "/response/0/type" => "DNS")
, 'Does the deliveryservice details return?';
-# It allows updating a delivery service in a CDN with a matching regex in another CDN's delivery service
-
-$ds_id = &get_ds_id('ds_3');
-
-ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id . '/update' => {Accept => 'application/json'} => json => {
- "xmlId" => "ds_3",
- "displayName" => "ds_displayname_1",
- "protocol" => "1",
- "orgServerFqdn" => "http://10.75.168.91",
- "cdnName" => "cdn2",
- "tenantId" => $tenant_id,
- "profileName" => "CCR2",
- "type" => "HTTP",
- "multiSiteOrigin" => "0",
- "regionalGeoBlocking" => "1",
- "active" => "false",
- "matchList" => [
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "0",
- "pattern" => ".*\\.ds_1\\..*"
- },
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "1",
- "pattern" => ".*\\.my_vod1\\..*"
- }
- ]})
- ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/xmlId" => "ds_3")
- ->json_is( "/response/displayName" => "ds_displayname_1")
- ->json_is( "/response/orgServerFqdn" => "http://10.75.168.91")
- ->json_is( "/response/cdnName" => "cdn2")
- ->json_is( "/response/tenantId" => $tenant_id)
- ->json_is( "/response/profileName" => "CCR2")
- ->json_is( "/response/protocol" => "1")
- ->json_is( "/response/type" => "HTTP")
- ->json_is( "/response/multiSiteOrigin" => "0")
- ->json_is( "/response/regionalGeoBlocking" => "1")
- ->json_is( "/response/active" => "false")
- ->json_is( "/response/matchList/0/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/0/setNumber" => "0")
- ->json_is( "/response/matchList/0/pattern" => ".*\\.ds_1\\..*")
- ->json_is( "/response/matchList/1/type" => "HOST_REGEXP")
- ->json_is( "/response/matchList/1/setNumber" => "1")
- ->json_is( "/response/matchList/1/pattern" => ".*\\.my_vod1\\..*")
- , 'Does the deliveryservice details return?';
-
-# It does not allow changing a regex to be the same as an existing one in another DS in the same CDN
-$ds_id = &get_ds_id('ds_1');
-ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id . '/update' => {Accept => 'application/json'} => json => {
- "xmlId" => "ds_1",
- "displayName" => "ds_displayname_2",
- "protocol" => "1",
- "orgServerFqdn" => "http://10.75.168.91",
- "cdnName" => "cdn1",
- "tenantId" => $tenant_id,
- "profileName" => "CCR1",
- "type" => "HTTP",
- "multiSiteOrigin" => "0",
- "regionalGeoBlocking" => "0",
- "active" => "true",
- "matchList" => [
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "0",
- "pattern" => ".*\\.ds_2\\..*"
- },
- {
- "type" => "HOST_REGEXP",
- "setNumber" => "1",
- "pattern" => ".*\\.my_vod2\\..*"
- }
- ]})
- ->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- , 'Does the deliveryservice details return?';
-
ok $t->delete_ok('/api/1.2/deliveryservices/' . $ds_id)->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } );
-ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id . '/update' => {Accept => 'application/json'} => json => {
- "xmlId" => "ds_1234"
-})
- ->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } );
+ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id => {Accept => 'application/json'} => json => {
+ "active" => \1,
+ "cdnId" => 100,
+ "displayName" => "ds_displayname_11",
+ "dscp" => 1,
+ "geoLimit" => 1,
+ "geoProvider" => 1,
+ "initialDispersion" => 2,
+ "ipv6RoutingEnabled" => 1,
+ "logsEnabled" => 1,
+ "missLat" => 45,
+ "missLong" => 45,
+ "multiSiteOrigin" => 0,
+ "orgServerFqdn" => "http://10.75.168.91",
+ "protocol" => 2,
+ "qstringIgnore" => 1,
+ "rangeRequestHandling" => 1,
+ "regionalGeoBlocking" => 1,
+ "signed" => 1,
+ "typeId" => 7,
+ "xmlId" => "ds_1",
+})->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } );
ok $t->post_ok(
'/api/1.2/deliveryservices/test-ds1/servers' => { Accept => 'application/json' } => json => {
@@ -434,26 +186,17 @@ ok $t->post_ok(
->json_is( "/response/serverNames/0" => "atlanta-edge-01" )->json_is( "/response/serverNames/1" => "atlanta-edge-02" ),
'Does the assigned servers return?';
-ok $t->get_ok("/api/1.2/deliveryservices.json")->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content} } )
- ->json_is( "/response/0/xmlId", "ds_2" )->json_is( "/response/0/logsEnabled", 0 )->json_is( "/response/0/ipv6RoutingEnabled", 0 )
- ->json_is( "/response/1/xmlId", "ds_3" );
+ok $t->get_ok("/api/1.2/deliveryservices")->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content} } )
+ ->json_is( "/response/0/xmlId", "steering-ds1" )->json_is( "/response/0/logsEnabled", 0 )->json_is( "/response/0/ipv6RoutingEnabled", 1 )
+ ->json_is( "/response/1/xmlId", "steering-ds2" );
-$t->get_ok('/api/1.2/deliveryservices/list?logsEnabled=true')->status_is(200)->$count_response(3)
+$t->get_ok('/api/1.2/deliveryservices?logsEnabled=true')->status_is(200)->$count_response(2)
+$t->get_ok('/api/1.2/deliveryservices/list?logsEnabled=true')->status_is(200)->$count_response(2)
->or( sub { diag $t->tx->res->content->asset->{content}; } );
ok $t->put_ok('/api/1.2/snapshot/cdn1')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } );
ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content}; } );
-
-}
-
-my $schema = Schema->connect_to_database;
-my $dbh = Schema->database_handle;
-my $t = Test::Mojo->new('TrafficOps');
-
-run_ut($t, $schema, Test::TestHelper::ADMIN_USER, Test::TestHelper::ADMIN_USER_PASSWORD);
-run_ut($t, $schema, Test::TestHelper::ADMIN_ROOT_USER, Test::TestHelper::ADMIN_ROOT_USER_PASSWORD);
-
$dbh->disconnect();
done_testing();
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7130816b/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 91bcb5b..e034621 100644
--- a/traffic_ops/app/t/api/1.2/server.t
+++ b/traffic_ops/app/t/api/1.2/server.t
@@ -40,6 +40,11 @@ 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->get_ok('/api/1.2/servers/status')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ ->json_is( "/response/ONLINE", 14 )
+ ->json_is( "/response/REPORTED", 1 )
+ ->or( sub { diag $t->tx->res->content->asset->{content}; } );
+
ok $t->post_ok('/api/1.2/cachegroups' => {Accept => 'application/json'} => json => {
"name" => "cg2-mid-northwest",
"shortName" => "cg2_mid",