You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by el...@apache.org on 2018/06/05 16:36:09 UTC
[incubator-trafficcontrol] branch master updated: Add TO Go
cdns/id/queue_updates
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 97f4e14 Add TO Go cdns/id/queue_updates
97f4e14 is described below
commit 97f4e148dcc673df44702e2d8e326caec1755b9e
Author: Robert Butts <ro...@apache.org>
AuthorDate: Sat May 19 15:56:08 2018 -0600
Add TO Go cdns/id/queue_updates
---
traffic_ops/traffic_ops_golang/cdn/queue.go | 79 +++++++++++++++++++++++++++++
traffic_ops/traffic_ops_golang/routes.go | 2 +-
2 files changed, 80 insertions(+), 1 deletion(-)
diff --git a/traffic_ops/traffic_ops_golang/cdn/queue.go b/traffic_ops/traffic_ops_golang/cdn/queue.go
new file mode 100644
index 0000000..d3e0a36
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/cdn/queue.go
@@ -0,0 +1,79 @@
+package cdn
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+ "database/sql"
+ "encoding/json"
+ "errors"
+ "net/http"
+
+ "github.com/apache/incubator-trafficcontrol/lib/go-log"
+ "github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
+ "github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
+)
+
+type QueueReq struct {
+ Action string `json:"action"`
+}
+
+type QueueResp struct {
+ Action string `json:"action"`
+ CDNID int64 `json:"cdnId"`
+}
+
+func Queue(db *sql.DB) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ user, err := auth.GetCurrentUser(r.Context())
+ if err != nil {
+ api.HandleErr(w, r, http.StatusInternalServerError, nil, errors.New("getting user: "+err.Error()))
+ return
+ }
+ params, intParams, userErr, sysErr, errCode := api.AllParams(r, []string{"id"})
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, errCode, userErr, sysErr)
+ return
+ }
+ reqObj := QueueReq{}
+ if err := json.NewDecoder(r.Body).Decode(&reqObj); err != nil {
+ api.HandleErr(w, r, http.StatusBadRequest, errors.New("malformed JSON: "+err.Error()), nil)
+ return
+ }
+ if reqObj.Action != "queue" && reqObj.Action != "dequeue" {
+ api.HandleErr(w, r, http.StatusBadRequest, errors.New("action must be 'queue' or 'dequeue'"), nil)
+ return
+ }
+ if err := queueUpdates(db, int64(intParams["id"]), reqObj.Action == "queue"); err != nil {
+ api.HandleErr(w, r, http.StatusInternalServerError, nil, errors.New("CDN queueing updates: "+err.Error()))
+ return
+ }
+ api.WriteResp(w, r, QueueResp{Action: reqObj.Action, CDNID: int64(intParams["id"])})
+ if err := api.CreateChangeLogRaw(api.ApiChange, "Server updates "+reqObj.Action+"d for cdn "+params["id"], *user, db); err != nil {
+ log.Errorln("creating cdn queue updates changelog: " + err.Error())
+ }
+ }
+}
+
+func queueUpdates(db *sql.DB, cdnID int64, queue bool) error {
+ if _, err := db.Exec(`UPDATE server SET upd_pending = $1 WHERE server.cdn_id = $2`, queue, cdnID); err != nil {
+ return errors.New("querying queue updates: " + err.Error())
+ }
+ return nil
+}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 52509f5..0ae52c0 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -113,8 +113,8 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
{1.1, http.MethodPut, `cdns/{id}$`, api.UpdateHandler(cdn.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
{1.1, http.MethodPost, `cdns/?$`, api.CreateHandler(cdn.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
{1.1, http.MethodDelete, `cdns/{id}$`, api.DeleteHandler(cdn.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
-
{1.1, http.MethodDelete, `cdns/name/{name}$`, cdn.DeleteName(d.DB.DB), auth.PrivLevelOperations, Authenticated, nil},
+ {1.1, http.MethodPost, `cdns/{id}/queue_update$`, cdn.Queue(d.DB.DB), auth.PrivLevelOperations, Authenticated, nil},
//CDN: Monitoring: Traffic Monitor
{1.1, http.MethodGet, `cdns/{name}/configs/monitoring(\.json)?$`, monitoringHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.