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 2017/01/03 19:28:16 UTC
[06/13] incubator-trafficcontrol git commit: provides the ability to
retrieve all profiles assigned to a parameter
provides the ability to retrieve all profiles assigned to a parameter
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/b2cc48a2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/b2cc48a2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/b2cc48a2
Branch: refs/heads/master
Commit: b2cc48a25f790efe8fe998fa6a335ca89ba35bf1
Parents: 28f732f
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Thu Dec 29 11:29:26 2016 -0700
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Thu Dec 29 11:29:26 2016 -0700
----------------------------------------------------------------------
.../traffic_ops_api/v12/parameter.rst | 46 ++++++++++++++++++++
traffic_ops/app/lib/API/Profile.pm | 27 ++++++++++++
traffic_ops/app/lib/TrafficOpsRoutes.pm | 3 ++
3 files changed, 76 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/b2cc48a2/docs/source/development/traffic_ops_api/v12/parameter.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/parameter.rst b/docs/source/development/traffic_ops_api/v12/parameter.rst
index 9de8451..569cb85 100644
--- a/docs/source/development/traffic_ops_api/v12/parameter.rst
+++ b/docs/source/development/traffic_ops_api/v12/parameter.rst
@@ -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
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/b2cc48a2/traffic_ops/app/lib/API/Profile.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Profile.pm b/traffic_ops/app/lib/API/Profile.pm
index 34b4a02..68fffb5 100644
--- a/traffic_ops/app/lib/API/Profile.pm
+++ b/traffic_ops/app/lib/API/Profile.pm
@@ -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');
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/b2cc48a2/traffic_ops/app/lib/TrafficOpsRoutes.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/TrafficOpsRoutes.pm b/traffic_ops/app/lib/TrafficOpsRoutes.pm
index 53b9fc7..9fc7d09 100644
--- a/traffic_ops/app/lib/TrafficOpsRoutes.pm
+++ b/traffic_ops/app/lib/TrafficOpsRoutes.pm
@@ -579,6 +579,9 @@ sub api_routes {
$r->delete("/api/$version/parameters/:id")->over( authenticated => 1 )->to( 'Parameter#delete', namespace => $namespace );
$r->post("/api/$version/parameters/validate")->over( authenticated => 1 )->to( 'Parameter#validate', namespace => $namespace );
+ # get all profiles associated with a parameter (from profile_parameter table)
+ $r->get( "/api/$version/parameters/:id/profiles")->over( authenticated => 1 )->to( 'Profile#get_profiles_by_paramId', namespace => $namespace );
+
# parameters for a profile
$r->get( "/api/$version/profiles/:id/parameters" => [ id => qr/\d+/ ] )->over( authenticated => 1 )->to( 'Parameter#get_profile_params', namespace => $namespace );
$r->get("/api/$version/profiles/name/:name/parameters")->over( authenticated => 1 )->to( 'Parameter#get_profile_params', namespace => $namespace );