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/05/30 17:13:43 UTC
[2/2] incubator-trafficcontrol git commit: adds apis to fetch current
and pending cdn snapshots
adds apis to fetch current and pending cdn snapshots
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/0a265b28
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/0a265b28
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/0a265b28
Branch: refs/heads/master
Commit: 0a265b283a076d3f7aa7753c942cd57ce6ac8862
Parents: cd65849
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Tue May 30 10:42:20 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Tue May 30 11:13:44 2017 -0600
----------------------------------------------------------------------
.../traffic_ops_api/v12/topology.rst | 100 ++++++++++++++++++-
traffic_ops/app/lib/API/Topology.pm | 39 ++++++++
traffic_ops/app/lib/TrafficOpsRoutes.pm | 5 +-
traffic_ops/app/t/api/1.2/cdn.t | 10 ++
4 files changed, 152 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0a265b28/docs/source/development/traffic_ops_api/v12/topology.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/topology.rst b/docs/source/development/traffic_ops_api/v12/topology.rst
index 89444f0..9b7cf9f 100644
--- a/docs/source/development/traffic_ops_api/v12/topology.rst
+++ b/docs/source/development/traffic_ops_api/v12/topology.rst
@@ -23,11 +23,109 @@ Snapshot CRConfig
/api/1.2/snapshot/{:cdn_name}
+++++++++++++++++++++++++++++
+**GET /api/1.2/cdns/{:cdn_name}/snapshot**
+
+ Retrieves the CURRENT snapshot for a CDN which doesn't necessarily represent the current state of the CDN. The contents of this snapshot are currently used by Traffic Monitor and Traffic Router.
+
+ Authentication Required: Yes
+
+ Role(s) Required: Admin or Operations
+
+ **Request Route Parameters**
+
+ +----------------+----------+---------------------------------------------+
+ | Name | Required | Description |
+ +================+==========+=============================================+
+ | ``cdn_name`` | yes | CDN name. |
+ +----------------+----------+---------------------------------------------+
+
+ **Response Properties**
+
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | Parameter | Type | Description |
+ +=======================+========+==============================================================================+
+ | ``config`` | hash | General CDN configuration settings. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | ``contentRouters`` | hash | A list of Traffic Routers. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | ``contentServers`` | hash | A list of Traffic Servers and the delivery services associated with each. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | ``deliveryServices`` | hash | A list of delivery services. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | ``edgeLocations`` | hash | A list of cache groups. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | ``stats`` | hash | Snapshot properties. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+
+ **Response Example** ::
+
+ {
+ "response": {
+ "config": { ... },
+ "contentRouters": { ... },
+ "contentServers": { ... },
+ "deliveryServices": { ... },
+ "edgeLocations": { ... },
+ "stats": { ... },
+ },
+ }
+
+|
+
+**GET /api/1.2/cdns/{:cdn_name}/snapshot/new**
+
+ Retrieves a PENDING snapshot for a CDN which represents the current state of the CDN. The contents of this snapshot are NOT currently used by Traffic Monitor and Traffic Router. Once a snapshot is performed, this snapshot will become the CURRENT snapshot and will be used by Traffic Monitor and Traffic Router.
+
+ Authentication Required: Yes
+
+ Role(s) Required: Admin or Operations
+
+ **Request Route Parameters**
+
+ +----------------+----------+---------------------------------------------+
+ | Name | Required | Description |
+ +================+==========+=============================================+
+ | ``cdn_name`` | yes | CDN name. |
+ +----------------+----------+---------------------------------------------+
+
+ **Response Properties**
+
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | Parameter | Type | Description |
+ +=======================+========+==============================================================================+
+ | ``config`` | hash | General CDN configuration settings. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | ``contentRouters`` | hash | A list of Traffic Routers. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | ``contentServers`` | hash | A list of Traffic Servers and the delivery services associated with each. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | ``deliveryServices`` | hash | A list of delivery services. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | ``edgeLocations`` | hash | A list of cache groups. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+ | ``stats`` | hash | Snapshot properties. |
+ +-----------------------+--------+------------------------------------------------------------------------------+
+
+ **Response Example** ::
+
+ {
+ "response": {
+ "config": { ... },
+ "contentRouters": { ... },
+ "contentServers": { ... },
+ "deliveryServices": { ... },
+ "edgeLocations": { ... },
+ "stats": { ... },
+ },
+ }
+
+|
+
**PUT /api/1.2/snapshot/{:cdn_name}**
Authentication Required: Yes
- Role(s) Required: admin or oper
+ Role(s) Required: Admin or Operations
**Request Route Parameters**
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0a265b28/traffic_ops/app/lib/API/Topology.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Topology.pm b/traffic_ops/app/lib/API/Topology.pm
index 6270ea8..4e55b1c 100644
--- a/traffic_ops/app/lib/API/Topology.pm
+++ b/traffic_ops/app/lib/API/Topology.pm
@@ -61,4 +61,43 @@ sub SnapshotCRConfig {
return $self->success("SUCCESS");
}
+sub get_snapshot {
+ my $self = shift;
+ my $cdn_name = $self->param('name');
+
+ if ( !&is_oper($self) ) {
+ return $self->forbidden();
+ }
+
+ my $cdn = $self->db->resultset('Cdn')->find( { name => $cdn_name } );
+ if ( !defined($cdn) ) {
+ return $self->not_found();
+ }
+
+ my $snapshot = $self->db->resultset('Snapshot')->search( { cdn => $cdn_name } )->get_column('content')->single();
+ if ( !defined($snapshot) ) {
+ return $self->success( {} );
+ }
+
+ $self->success( decode_json($snapshot) );
+}
+
+sub get_new_snapshot {
+ my $self = shift;
+ my $cdn_name = $self->param('name');
+
+ if ( !&is_oper($self) ) {
+ return $self->forbidden();
+ }
+
+ my $cdn = $self->db->resultset('Cdn')->find( { name => $cdn_name } );
+ if ( !defined($cdn) ) {
+ return $self->not_found();
+ }
+
+ my $json = &UI::Topology::gen_crconfig_json($self, $cdn_name);
+
+ $self->success( $json );
+}
+
1;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0a265b28/traffic_ops/app/lib/TrafficOpsRoutes.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/TrafficOpsRoutes.pm b/traffic_ops/app/lib/TrafficOpsRoutes.pm
index 4bcc514..c7fb983 100644
--- a/traffic_ops/app/lib/TrafficOpsRoutes.pm
+++ b/traffic_ops/app/lib/TrafficOpsRoutes.pm
@@ -436,10 +436,13 @@ sub api_routes {
$r->get("/api/$version/cdns/routing")->over( authenticated => 1 )->to( 'Cdn#routing', namespace => $namespace );
# -- CDNS: SNAPSHOT
+ $r->get("/api/$version/cdns/:name/snapshot")->over( authenticated => 1 )->to( 'Topology#get_snapshot', namespace => $namespace );
+ $r->get("/api/$version/cdns/:name/snapshot/new")->over( authenticated => 1 )->to( 'Topology#get_new_snapshot', namespace => $namespace );
$r->put( "/api/$version/cdns/:id/snapshot" => [ id => qr/\d+/ ] )->over( authenticated => 1 )
- ->to( 'Topology#SnapshotCRConfig', namespace => $namespace );
+ ->to( 'Topology#SnapshotCRConfig', namespace => $namespace );
$r->put("/api/$version/snapshot/:cdn_name")->over( authenticated => 1 )->to( 'Topology#SnapshotCRConfig', namespace => $namespace );
+
# -- CDNS: METRICS
#WARNING: this is an intentionally "unauthenticated" route.
$r->get("/api/$version/cdns/metric_types/:metric_type/start_date/:start_date/end_date/:end_date")->to( 'Cdn#metrics', namespace => $namespace );
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0a265b28/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 0dc5606..81094ec 100644
--- a/traffic_ops/app/t/api/1.2/cdn.t
+++ b/traffic_ops/app/t/api/1.2/cdn.t
@@ -44,6 +44,16 @@ $t->get_ok("/api/1.2/cdns")->status_is(200)->json_is( "/response/0/id", 100 )
$t->get_ok("/api/1.2/cdns/100")->status_is(200)->json_is( "/response/0/id", 100 )
->json_is( "/response/0/name", "cdn1" )->or( sub { diag $t->tx->res->content->asset->{content}; } );
+ok $t->put_ok('/api/1.2/cdns/100/snapshot')
+ ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ , 'Is the cdn snapshotted?';
+
+$t->get_ok("/api/1.2/cdns/cdn1/snapshot")->status_is(200)
+ ->or( sub { diag $t->tx->res->content->asset->{content}; } );
+
+$t->get_ok("/api/1.2/cdns/cdn1/snapshot/new")->status_is(200)
+ ->or( sub { diag $t->tx->res->content->asset->{content}; } );
+
ok $t->post_ok('/api/1.2/cdns/100/queue_update' => {Accept => 'application/json'} => json => {
"action" => "queue" })
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )