You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by jh...@apache.org on 2019/08/12 15:22:21 UTC

[trafficcontrol] branch master updated: Add support for servercheck updates to go client (#3470)

This is an automated email from the ASF dual-hosted git repository.

jhg03a pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 41fd3d1  Add support for servercheck updates to go client (#3470)
41fd3d1 is described below

commit 41fd3d108d59e113aa38794cded3f0aa58afda99
Author: Jason Tucker <ja...@gmail.com>
AuthorDate: Mon Aug 12 15:22:15 2019 +0000

    Add support for servercheck updates to go client (#3470)
    
    * Add support for servercheck updates to go client
    
    * minor formatting
    
    * remove cruft
    
    * go fmt
    
    * satisfy ReqInf response requirement
    
    * add servercheck test
    
    * Add GetCheckData()
    
    Supports GET of servercheck data
---
 lib/go-tc/serverchecks.go                       | 144 ++++++++++++++++++++++++
 traffic_ops/client/servercheck.go               |  53 +++++++++
 traffic_ops/testing/api/v14/servercheck_test.go |  46 ++++++++
 3 files changed, 243 insertions(+)

diff --git a/lib/go-tc/serverchecks.go b/lib/go-tc/serverchecks.go
new file mode 100644
index 0000000..671028a
--- /dev/null
+++ b/lib/go-tc/serverchecks.go
@@ -0,0 +1,144 @@
+package tc
+
+/*
+ * 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.
+ */
+
+// Health monitor checks for servers
+// A Single Servercheck Response for Update and Create to depict what changed
+// swagger:response ServercheckResponse
+// in: body
+type ServercheckResponse struct {
+	// in: body
+	Response Servercheck `json:"response"`
+}
+
+// A list of Servercheck Responses
+// swagger:response ServerchecksResponse
+// in: body
+type ServerchecksResponse struct {
+	// in: body
+	Response []Servercheck `json:"response"`
+}
+
+// A Single Servercheck struct for GET response
+// swagger:model Servercheck
+type Servercheck struct {
+
+	// The Servercheck response data
+	//
+	// Admin state of the checked server
+	AdminState string `json:"adminState"`
+
+	// Cache group the checked server belongs to
+	CacheGroup string `json:"cacheGroup"`
+
+	// ID number of the checked server
+	ID int `json:"id"`
+
+	// Hostname of the checked server
+	HostName string `json:"hostName"`
+
+	// Reval pending flag for checked server
+	RevalPending bool `json:"revalPending"`
+
+	// Profile name of checked server
+	Profile string `json:"profile"`
+
+	// Traffic Control type of the checked server
+	Type string `json:"type"`
+
+	// Update pending flag for the checked server
+	UpdPending bool `json:"updPending"`
+
+	// Various check types
+	Checks struct {
+
+		// IPv4 production interface (legacy name)
+		Iface10G int `json:"10G"`
+
+		// IPv6 production interface (legacy name)
+		Iface10G6 int `json:"10G6"`
+
+		// Cache Disk Usage
+		CDU int `json:"CDU"`
+
+		// Cache Hit Ratio
+		CHR int `json:"CHR"`
+
+		// DSCP check
+		DSCP int `json:"DSCP"`
+
+		// DNS check
+		FQDN int `json:"FQDN"`
+
+		// Out-of-band (BMC) interface check
+		ILO int `json:"ILO"`
+
+		// IPv4 production interface (new name)
+		IPv4 int `json:"IPv4"`
+
+		// IPv6 production interface (new name)
+		IPv6 int `json:"IPv6"`
+
+		// MTU check
+		MTU int `json:"MTU"`
+
+		// ORT check
+		ORT int `json:"ORT"`
+
+		// Traffic Router status for checked server
+		RTR int `json:"RTR"`
+	} `json:"checks"`
+}
+
+// A Single Servercheck struct for Update and Create to depict what changed
+// swagger:model ServercheckPost
+type ServercheckPost struct {
+
+	// The Servercheck data to submit
+	//
+	// Name of the server check type
+	//
+	// required: true
+	Name string `json:"servercheck_short_name" db:"servercheck_short_name"`
+
+	// ID of the server
+	//
+	// required: true
+	ID int `json:"id" db:"id"`
+
+	// Name of the server
+	HostName string `json:"name" db:"name"`
+
+	// Value of the check result
+	//
+	// required: true
+	Value int `json:"value" db:"value"`
+}
+
+type ServercheckPostNullable struct {
+	Name  string `json:"servercheck_short_name" db:"servercheck_short_name"`
+	ID    int    `json:"id" db:"id"`
+	Value int    `json:"value" db:"value"`
+}
+
+type ServercheckPostResponse struct {
+	Alerts   []Alert                 `json:"alerts"`
+	Response DeliveryServiceUserPost `json:"response"`
+}
diff --git a/traffic_ops/client/servercheck.go b/traffic_ops/client/servercheck.go
new file mode 100644
index 0000000..d44e74a
--- /dev/null
+++ b/traffic_ops/client/servercheck.go
@@ -0,0 +1,53 @@
+/*
+   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.
+*/
+
+package client
+
+import (
+	"encoding/json"
+	"net"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+const API_V13_SERVERCHECK = "/api/1.3/servercheck"
+const API_V13_SERVERCHECK_GET = "/api/1.3/servers/checks"
+
+// Update a Server Check Status
+func (to *Session) UpdateCheckStatus(status tc.ServercheckPostNullable) (*tc.ServercheckPostResponse, ReqInf, error) {
+	uri := API_V13_SERVERCHECK
+	var remoteAddr net.Addr
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	jsonReq, err := json.Marshal(status)
+	if err != nil {
+		return nil, reqInf, err
+	}
+	resp := tc.ServercheckPostResponse{}
+	reqInf, err = post(to, uri, jsonReq, &resp)
+	if err != nil {
+		return nil, reqInf, err
+	}
+	return &resp, reqInf, nil
+}
+
+// Get Server Check Data
+func (to *Session) GetCheckData() (*tc.ServerchecksResponse, ReqInf, error) {
+	uri := API_V13_SERVERCHECK_GET
+	var remoteAddr net.Addr
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	resp := tc.ServerchecksResponse{}
+	reqInf, err := get(to, uri, &resp)
+	if err != nil {
+		return nil, reqInf, err
+	}
+	return &resp, reqInf, nil
+}
diff --git a/traffic_ops/testing/api/v14/servercheck_test.go b/traffic_ops/testing/api/v14/servercheck_test.go
new file mode 100644
index 0000000..1e77f61
--- /dev/null
+++ b/traffic_ops/testing/api/v14/servercheck_test.go
@@ -0,0 +1,46 @@
+package v14
+
+/*
+   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.
+*/
+
+import (
+	"testing"
+
+	"github.com/apache/trafficcontrol/lib/go-log"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+)
+
+func TestServerCheck(t *testing.T) {
+	WithObjs(t, []TCObj{Servers}, func() {
+		UpdateServerCheck(t)
+	})
+}
+
+const SessionUserName = "extension" // TODO make dynamic?
+
+func UpdateServerCheck(t *testing.T) {
+	var statusData tc.ServercheckNullable
+	for _, server := range testData.Servers {
+
+		statusData.ID = server.ID
+		statusData.Name = "DSCP"
+		statusData.Value = 1
+		resp, _, err := TOSession.UpdateCheckStatus(statusData)
+		if err != nil {
+			t.Errorf("could not set servercheck status user: %v\n", err)
+		}
+		log.Debugln("Response: ", resp.Alerts)
+	}
+}