You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2016/11/14 17:07:47 UTC
[44/53] [abbrv] incubator-trafficcontrol git commit: Fix for #2006 to
include the primary keys in the group_by
Fix for #2006 to include the primary keys in the group_by
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/334a65d1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/334a65d1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/334a65d1
Branch: refs/heads/psql-rebase
Commit: 334a65d1f98a81f85f2cffb08567b611dfbebf8f
Parents: d0fe09a
Author: Dewayne Richardson <de...@gmail.com>
Authored: Wed Oct 12 11:13:07 2016 -0600
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Nov 11 14:22:40 2016 -0700
----------------------------------------------------------------------
traffic_ops/app/lib/MojoPlugins/Health.pm | 14 ++++---
traffic_ops/app/t/api/1.1/cdn.t | 51 ++++++++++++++++++++++++++
traffic_ops/app/t/api/1.2/cdn.t | 33 +++++------------
traffic_ops/app/t/health.t | 4 ++
4 files changed, 72 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/334a65d1/traffic_ops/app/lib/MojoPlugins/Health.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/MojoPlugins/Health.pm b/traffic_ops/app/lib/MojoPlugins/Health.pm
index ea2e1f0..cd2eda8 100755
--- a/traffic_ops/app/lib/MojoPlugins/Health.pm
+++ b/traffic_ops/app/lib/MojoPlugins/Health.pm
@@ -42,11 +42,13 @@ sub register {
my $rs_pp = $self->db->resultset('Server')->search(
{ 'cdn.name' => $cdn_name },
- { prefetch => ['cdn', 'profile', 'type'],
+ {
+ prefetch => [ 'cdn', 'profile', 'type' ],
select => 'me.profile',
- distinct => 1
+ group_by => [qw/cdn.id profile.id me.profile type.id/],
}
);
+
while ( my $row = $rs_pp->next ) {
if ( $row->profile->name =~ m/^RASCAL/ ) {
$rascal_profile = $row->profile->name;
@@ -59,7 +61,7 @@ sub register {
}
elsif ( $row->type->name =~ m/^EDGE/ || $row->type->name =~ m/^MID/ ) {
push( @cache_profiles, $row->profile->name );
- $profile_to_type->{$row->profile->name}->{$row->type->name} = $row->type->name;
+ $profile_to_type->{ $row->profile->name }->{ $row->type->name } = $row->type->name;
}
}
my %condition = ( 'parameter.config_file' => 'rascal-config.txt', 'profile.name' => $rascal_profile );
@@ -72,8 +74,8 @@ sub register {
%condition = ( 'parameter.config_file' => 'rascal.properties', 'profile.name' => { -in => \@cache_profiles } );
$rs_pp = $self->db->resultset('ProfileParameter')->search( \%condition, { prefetch => [ { 'parameter' => undef }, { 'profile' => undef } ] } );
while ( my $row = $rs_pp->next ) {
- if ( exists($profile_to_type->{$row->profile->name}) ) {
- for my $profile_type ( keys(%{$profile_to_type->{$row->profile->name}}) ) {
+ if ( exists( $profile_to_type->{ $row->profile->name } ) ) {
+ for my $profile_type ( keys( %{ $profile_to_type->{ $row->profile->name } } ) ) {
$data_obj->{'profiles'}->{$profile_type}->{ $row->profile->name }->{ $row->parameter->name } = $row->parameter->value;
}
}
@@ -123,7 +125,7 @@ sub register {
while ( my $row = $rs_data->next ) {
my $this_cdn_name = $row->cdn->name;
- if (!defined($this_cdn_name)) {
+ if ( !defined($this_cdn_name) ) {
print "cdn name not defined\n";
}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/334a65d1/traffic_ops/app/t/api/1.1/cdn.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.1/cdn.t b/traffic_ops/app/t/api/1.1/cdn.t
new file mode 100644
index 0000000..a3cf9ef
--- /dev/null
+++ b/traffic_ops/app/t/api/1.1/cdn.t
@@ -0,0 +1,51 @@
+package main;
+#
+# Copyright 2015 Comcast Cable Communications Management, LLC
+#
+# 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 Mojo::Base -strict;
+use Test::More;
+use Test::Mojo;
+use DBI;
+use strict;
+use warnings;
+use Test::TestHelper;
+
+#no_transactions=>1 ==> keep fixtures after every execution, beware of duplicate data!
+#no_transactions=>0 ==> delete fixtures after every execution
+
+BEGIN { $ENV{MOJO_MODE} = "test" }
+
+my $t = Test::Mojo->new('TrafficOps');
+my $dbh = Schema->database_handle;
+my $schema = Schema->connect_to_database;
+
+#unload data for a clean test
+Test::TestHelper->unload_core_data($schema);
+
+#load core test data
+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}; } );
+
+$t->get_ok("/api/1.1/cdns/capacity.json")->status_is(200)->json_is( "/response/unavailablePercent", "0" )->json_is( "/response/availablePercent", "0" )
+ ->json_is( "/response/utilizedPercent", "0" )->json_is( "/response/maintenancePercent", "0" )
+
+ ->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}; } );
+
+$dbh->disconnect();
+done_testing();
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/334a65d1/traffic_ops/app/t/api/1.2/cdn.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/cdn.t b/traffic_ops/app/t/api/1.2/cdn.t
index a357f03..1cd476b 100644
--- a/traffic_ops/app/t/api/1.2/cdn.t
+++ b/traffic_ops/app/t/api/1.2/cdn.t
@@ -19,8 +19,6 @@ use Test::Mojo;
use DBI;
use strict;
use warnings;
-no warnings 'once';
-use warnings 'all';
use Test::TestHelper;
#no_transactions=>1 ==> keep fixtures after every execution, beware of duplicate data!
@@ -28,24 +26,21 @@ use Test::TestHelper;
BEGIN { $ENV{MOJO_MODE} = "test" }
-my $schema = Schema->connect_to_database;
-my $dbh = Schema->database_handle;
my $t = Test::Mojo->new('TrafficOps');
+my $dbh = Schema->database_handle;
+my $schema = Schema->connect_to_database;
+#unload data for a clean test
Test::TestHelper->unload_core_data($schema);
+
+#load core test data
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?';
+ ->or( sub { diag $t->tx->res->content->asset->{content}; } );
-ok $t->post_ok('/api/1.2/cdns' => {Accept => 'application/json'} => json => {
- "name" => "cdn_test"
- })
- ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
- ->json_is( "/response/name" => "cdn_test" )
- ->json_is( "/alerts/0/level" => "success" )
- ->json_is( "/alerts/0/text" => "cdn was created." )
- , 'Does the cdn details return?';
+$t->get_ok("/api/1.2/cdns/capacity.json")->status_is(200)->json_is( "/response/unavailablePercent", "0" )->json_is( "/response/availablePercent", "0" )
+ ->json_is( "/response/utilizedPercent", "0" )->json_is( "/response/maintenancePercent", "0" )
my $cdn_id = &get_cdn_id('cdn_test');
@@ -65,16 +60,6 @@ ok $t->put_ok('/api/1.2/cdns/' . $cdn_id => {Accept => 'application/json'} => j
->status_is(404)->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}; } );
+
$dbh->disconnect();
done_testing();
-
-sub get_cdn_id {
- my $name = shift;
- my $q = "select id from cdn where name = \'$name\'";
- my $get_svr = $dbh->prepare($q);
- $get_svr->execute();
- my $p = $get_svr->fetchall_arrayref( {} );
- $get_svr->finish();
- my $id = $p->[0]->{id};
- return $id;
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/334a65d1/traffic_ops/app/t/health.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/health.t b/traffic_ops/app/t/health.t
index 14eb395..bb9ac6a 100644
--- a/traffic_ops/app/t/health.t
+++ b/traffic_ops/app/t/health.t
@@ -113,6 +113,10 @@ while ( my @row = $select->fetchrow_array ) {
push( @{ $lines->{ $row[0] } }, @row );
}
+$t->get_ok("/health/cdn1.json")->status_is(200)->json_is( "/profiles/MID/MID1/health.threshold.loadavg", "25.0" )
+ ->json_is( "/profiles/MID/MID1/history.count", "30" )->json_is( "/deliveryServices/test-ds1/status", "REPORTED" )
+ ->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}; } );
$dbh->disconnect;