Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TC-81] Add additional filters to collection apis #154

Merged
merged 12 commits into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/source/development/traffic_ops_api/v12/cachegroup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ Cache Group

Role(s) Required: None

**Request Query Parameters**

+-----------------+----------+---------------------------------------------------+
| Name | Required | Description |
+=================+==========+===================================================+
| ``type`` | no | Filter cache groups by Type ID. |
+-----------------+----------+---------------------------------------------------+

**Response Properties**

+-----------------------------------+--------+--------------------------------------------------------------------------+
Expand Down
175 changes: 175 additions & 0 deletions docs/source/development/traffic_ops_api/v12/deliveryservice.rst

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions docs/source/development/traffic_ops_api/v12/parameter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,52 @@ Parameter

|

**GET /api/1.2/parameters/:id/profiles**

Retrieves all profiles assigned to the parameter.

Authentication Required: Yes

Role(s) Required: None

**Request Route Parameters**

+---------------+----------+----------------------------------------------------+
| Name | Required | Description |
+===============+==========+====================================================+
| ``id`` | yes | Parameter ID. |
+---------------+----------+----------------------------------------------------+

**Response Properties**

+-----------------+--------+----------------------------------------------------+
| Parameter | Type | Description |
+=================+========+====================================================+
| ``lastUpdated`` | array | The Time / Date this server entry was last updated |
+-----------------+--------+----------------------------------------------------+
| ``name`` | string | The name for the profile |
+-----------------+--------+----------------------------------------------------+
| ``id`` | string | Primary key |
+-----------------+--------+----------------------------------------------------+
| ``description`` | string | The description for the profile |
+-----------------+--------+----------------------------------------------------+

**Response Example** ::

{
"response": [
{
"lastUpdated": "2012-10-08 19:34:45",
"name": "CCR_TOP",
"id": "8",
"description": "Content Router for top.foobar.net"
}
]
}

|


**GET /api/1.2/profiles/:id/parameters**

Authentication Required: Yes
Expand Down
8 changes: 8 additions & 0 deletions docs/source/development/traffic_ops_api/v12/region.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ Regions

Role(s) Required: None

**Request Route Parameters**

+---------------+----------+---------------------------------------------+
| Name | Required | Description |
+===============+==========+=============================================+
| ``division`` | no | Filter regions by Division ID. |
+---------------+----------+---------------------------------------------+

**Response Properties**

+----------------------+--------+------------------------------------------------+
Expand Down
233 changes: 233 additions & 0 deletions docs/source/development/traffic_ops_api/v12/server.rst

Large diffs are not rendered by default.

231 changes: 231 additions & 0 deletions docs/source/development/traffic_ops_api/v12/user.rst

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion traffic_ops/app/lib/API/Cachegroup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ sub index {
my @data;
my %idnames;
my $orderby = $self->param('orderby') || "name";
my $type_id = $self->param('type');

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 } );
my %criteria;
if ( defined $type_id ) {
$criteria{'type'} = $type_id;
}

my $rs_data = $self->db->resultset("Cachegroup")->search( \%criteria, { prefetch => [ { 'type' => undef, } ], order_by => 'me.' . $orderby } );
while ( my $row = $rs_data->next ) {
push(
@data, {
Expand Down
159 changes: 159 additions & 0 deletions traffic_ops/app/lib/API/Deliveryservice.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ use Validate::Tiny ':all';
sub index {
my $self = shift;
my $orderby = $self->param('orderby') || "xml_id";
my $cdn_id = $self->param('cdn');
my $type_id = $self->param('type');
my $logs_enabled = $self->param('logsEnabled');
my $current_user = $self->current_user()->{username};
my @data;

my %criteria;
if ( defined $cdn_id ) {
$criteria{'cdn_id'} = $cdn_id;
}
if ( defined $type_id ) {
$criteria{'type'} = $type_id;
}
if ( defined $logs_enabled ) {
$criteria{'logs_enabled'} = $logs_enabled ? 1 : 0; # converts bool to 0|1
}
Expand Down Expand Up @@ -534,6 +542,157 @@ sub delete {
return $self->success_message("Delivery service was deleted.");
}

sub get_deliveryservices_by_serverId {
my $self = shift;
my $server_id = $self->param('id');

my $server_ds_ids = $self->db->resultset('DeliveryserviceServer')->search( { server => $server_id } );

my $deliveryservices = $self->db->resultset('Deliveryservice')->search(
{ 'me.id' => { -in => $server_ds_ids->get_column('deliveryservice')->as_query } }
);

my @data;
if ( defined($deliveryservices) ) {
while ( my $row = $deliveryservices->next ) {
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,
"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,
"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,
"trRequestHeaders" => $row->tr_request_headers,
"trResponseHeaders" => $row->tr_response_headers,
"type" => $row->type->name,
"typeId" => $row->type->id,
"xmlId" => $row->xml_id
}
);
}
}

return $self->success( \@data );
}
sub get_deliveryservices_by_userId {
my $self = shift;
my $user_id = $self->param('id');

my $user_ds_ids = $self->db->resultset('DeliveryserviceTmuser')->search( { tm_user_id => $user_id } );

my $deliveryservices = $self->db->resultset('Deliveryservice')->search(
{ 'me.id' => { -in => $user_ds_ids->get_column('deliveryservice')->as_query } }
);

my @data;
if ( defined($deliveryservices) ) {
while ( my $row = $deliveryservices->next ) {
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,
"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,
"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,
"trRequestHeaders" => $row->tr_request_headers,
"trResponseHeaders" => $row->tr_response_headers,
"type" => $row->type->name,
"typeId" => $row->type->id,
"xmlId" => $row->xml_id
}
);
}
}

return $self->success( \@data );
}

sub routing {
my $self = shift;

Expand Down
27 changes: 27 additions & 0 deletions traffic_ops/app/lib/API/Profile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ sub index_trimmed {
$self->render( json => \@data );
}

sub get_profiles_by_paramId {
my $self = shift;
my $param_id = $self->param('id');

my $param_profiles = $self->db->resultset('ProfileParameter')->search( { parameter => $param_id } );

my $profiles = $self->db->resultset('Profile')->search(
{ 'me.id' => { -in => $param_profiles->get_column('profile')->as_query } }
);

my @data;
if ( defined($profiles) ) {
while ( my $row = $profiles->next ) {
push(
@data, {
"id" => $row->id,
"name" => $row->name,
"description" => $row->description,
"lastUpdated" => $row->last_updated
}
);
}
}

return $self->success( \@data );
}

sub show {
my $self = shift;
my $id = $self->param('id');
Expand Down
11 changes: 9 additions & 2 deletions traffic_ops/app/lib/API/Region.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ use MojoPlugins::Response;
my $finfo = __FILE__ . ":";

sub index {
my $self = shift;
my $self = shift;
my $division_id = $self->param('division');

my %criteria;
if ( defined $division_id ) {
$criteria{'division'} = $division_id;
}

my @data;
my $orderby = $self->param('orderby') || "name";
my $rs_data = $self->db->resultset("Region")->search( undef, { prefetch => ['division'], order_by => 'me.' . $orderby } );
my $rs_data = $self->db->resultset("Region")->search( \%criteria, { prefetch => ['division'], order_by => 'me.' . $orderby } );
while ( my $row = $rs_data->next ) {
push(
@data, {
Expand Down
Loading