mitchell852 closed pull request #2069: Implemented the TO Client for the /servers endpoint URL: https://github.com/apache/incubator-trafficcontrol/pull/2069
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/lib/go-tc/v13/servers.go b/lib/go-tc/v13/servers.go new file mode 100644 index 000000000..b71adb1e1 --- /dev/null +++ b/lib/go-tc/v13/servers.go @@ -0,0 +1,143 @@ +package v13 + +import ( + "time" + + tc "github.com/apache/incubator-trafficcontrol/lib/go-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. + */ + +type ServersResponse struct { + Response []Server `json:"response"` +} + +// ServerDetailResponse is the JSON object returned for a single server +type ServersDetailResponse struct { + Response Server `json:"response"` +} + +type Server struct { + Cachegroup string `json:"cachegroup" db:"cachegroup"` + CachegroupID int `json:"cachegroupId" db:"cachegroup_id"` + CDNID int `json:"cdnId" db:"cdn_id"` + CDNName string `json:"cdnName" db:"cdn_name"` + DeliveryServices map[string][]string `json:"deliveryServices,omitempty"` + DomainName string `json:"domainName" db:"domain_name"` + FQDN *string `json:"fqdn,omitempty"` + FqdnTime time.Time `json:"-"` + GUID string `json:"guid" db:"guid"` + HostName string `json:"hostName" db:"host_name"` + HTTPSPort int `json:"httpsPort" db:"https_port"` + ID int `json:"id" db:"id"` + ILOIPAddress string `json:"iloIpAddress" db:"ilo_ip_address"` + ILOIPGateway string `json:"iloIpGateway" db:"ilo_ip_gateway"` + ILOIPNetmask string `json:"iloIpNetmask" db:"ilo_ip_netmask"` + ILOPassword string `json:"iloPassword" db:"ilo_password"` + ILOUsername string `json:"iloUsername" db:"ilo_username"` + InterfaceMtu int `json:"interfaceMtu" db:"interface_mtu"` + InterfaceName string `json:"interfaceName" db:"interface_name"` + IP6Address string `json:"ip6Address" db:"ip6_address"` + IP6Gateway string `json:"ip6Gateway" db:"ip6_gateway"` + IPAddress string `json:"ipAddress" db:"ip_address"` + IPGateway string `json:"ipGateway" db:"ip_gateway"` + IPNetmask string `json:"ipNetmask" db:"ip_netmask"` + LastUpdated tc.TimeNoMod `json:"lastUpdated" db:"last_updated"` + MgmtIPAddress string `json:"mgmtIpAddress" db:"mgmt_ip_address"` + MgmtIPGateway string `json:"mgmtIpGateway" db:"mgmt_ip_gateway"` + MgmtIPNetmask string `json:"mgmtIpNetmask" db:"mgmt_ip_netmask"` + OfflineReason string `json:"offlineReason" db:"offline_reason"` + PhysLocation string `json:"physLocation" db:"phys_location"` + PhysLocationID int `json:"physLocationId" db:"phys_location_id"` + Profile string `json:"profile" db:"profile"` + ProfileDesc string `json:"profileDesc" db:"profile_desc"` + ProfileID int `json:"profileId" db:"profile_id"` + Rack string `json:"rack" db:"rack"` + RevalPending bool `json:"revalPending" db:"reval_pending"` + RouterHostName string `json:"routerHostName" db:"router_host_name"` + RouterPortName string `json:"routerPortName" db:"router_port_name"` + Status string `json:"status" db:"status"` + StatusID int `json:"statusId" db:"status_id"` + TCPPort int `json:"tcpPort" db:"tcp_port"` + Type string `json:"type" db:"server_type"` + TypeID int `json:"typeId" db:"server_type_id"` + UpdPending bool `json:"updPending" db:"upd_pending"` + XMPPID string `json:"xmppId" db:"xmpp_id"` + XMPPPasswd string `json:"xmppPasswd" db:"xmpp_passwd"` +} + +type ServerNullable struct { + Cachegroup *string `json:"cachegroup" db:"cachegroup"` + CachegroupID *int `json:"cachegroupId" db:"cachegroup_id"` + CDNID *int `json:"cdnId" db:"cdn_id"` + CDNName *string `json:"cdnName" db:"cdn_name"` + DeliveryServices *map[string][]string `json:"deliveryServices,omitempty"` + DomainName *string `json:"domainName" db:"domain_name"` + FQDN *string `json:"fqdn,omitempty"` + FqdnTime time.Time `json:"-"` + GUID *string `json:"guid" db:"guid"` + HostName *string `json:"hostName" db:"host_name"` + HTTPSPort *int `json:"httpsPort" db:"https_port"` + ID *int `json:"id" db:"id"` + ILOIPAddress *string `json:"iloIpAddress" db:"ilo_ip_address"` + ILOIPGateway *string `json:"iloIpGateway" db:"ilo_ip_gateway"` + ILOIPNetmask *string `json:"iloIpNetmask" db:"ilo_ip_netmask"` + ILOPassword *string `json:"iloPassword" db:"ilo_password"` + ILOUsername *string `json:"iloUsername" db:"ilo_username"` + InterfaceMtu *int `json:"interfaceMtu" db:"interface_mtu"` + InterfaceName *string `json:"interfaceName" db:"interface_name"` + IP6Address *string `json:"ip6Address" db:"ip6_address"` + IP6Gateway *string `json:"ip6Gateway" db:"ip6_gateway"` + IPAddress *string `json:"ipAddress" db:"ip_address"` + IPGateway *string `json:"ipGateway" db:"ip_gateway"` + IPNetmask *string `json:"ipNetmask" db:"ip_netmask"` + LastUpdated *tc.TimeNoMod `json:"lastUpdated" db:"last_updated"` + MgmtIPAddress *string `json:"mgmtIpAddress" db:"mgmt_ip_address"` + MgmtIPGateway *string `json:"mgmtIpGateway" db:"mgmt_ip_gateway"` + MgmtIPNetmask *string `json:"mgmtIpNetmask" db:"mgmt_ip_netmask"` + OfflineReason *string `json:"offlineReason" db:"offline_reason"` + PhysLocation *string `json:"physLocation" db:"phys_location"` + PhysLocationID *int `json:"physLocationId" db:"phys_location_id"` + Profile *string `json:"profile" db:"profile"` + ProfileDesc *string `json:"profileDesc" db:"profile_desc"` + ProfileID *int `json:"profileId" db:"profile_id"` + Rack *string `json:"rack" db:"rack"` + RevalPending *bool `json:"revalPending" db:"reval_pending"` + RouterHostName *string `json:"routerHostName" db:"router_host_name"` + RouterPortName *string `json:"routerPortName" db:"router_port_name"` + Status *string `json:"status" db:"status"` + StatusID *int `json:"statusId" db:"status_id"` + TCPPort *int `json:"tcpPort" db:"tcp_port"` + Type string `json:"type" db:"server_type"` + TypeID *int `json:"typeId" db:"server_type_id"` + UpdPending *bool `json:"updPending" db:"upd_pending"` + XMPPID *string `json:"xmppId" db:"xmpp_id"` + XMPPPasswd *string `json:"xmppPasswd" db:"xmpp_passwd"` +} + +type ServerUpdateStatus struct { + HostName string `json:"host_name"` + UpdatePending bool `json:"upd_pending"` + RevalPending bool `json:"reval_pending"` + HostId int `json:"host_id"` + Status string `json:"status"` + ParentPending bool `json:"parent_pending"` + ParentRevalPending bool `json:"parent_reval_pending"` +} diff --git a/traffic_ops/client/v13/server.go b/traffic_ops/client/v13/server.go new file mode 100644 index 000000000..3f14f5c3c --- /dev/null +++ b/traffic_ops/client/v13/server.go @@ -0,0 +1,133 @@ +/* + + 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 v13 + +import ( + "encoding/json" + "fmt" + "net" + "net/http" + + "github.com/apache/incubator-trafficcontrol/lib/go-tc" + "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13" +) + +const ( + API_v13_Servers = "/api/1.3/servers" +) + +// Create a Server +func (to *Session) CreateServer(server v13.Server) (tc.Alerts, ReqInf, error) { + + var remoteAddr net.Addr + reqBody, err := json.Marshal(server) + reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr} + if err != nil { + return tc.Alerts{}, reqInf, err + } + resp, remoteAddr, err := to.request(http.MethodPost, API_v13_Servers, reqBody) + if err != nil { + return tc.Alerts{}, reqInf, err + } + defer resp.Body.Close() + var alerts tc.Alerts + err = json.NewDecoder(resp.Body).Decode(&alerts) + return alerts, reqInf, nil +} + +// Update a Server by ID +func (to *Session) UpdateServerByID(id int, server v13.Server) (tc.Alerts, ReqInf, error) { + + var remoteAddr net.Addr + reqBody, err := json.Marshal(server) + reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr} + if err != nil { + return tc.Alerts{}, reqInf, err + } + route := fmt.Sprintf("%s/%d", API_v13_Servers, id) + resp, remoteAddr, err := to.request(http.MethodPut, route, reqBody) + if err != nil { + return tc.Alerts{}, reqInf, err + } + defer resp.Body.Close() + var alerts tc.Alerts + err = json.NewDecoder(resp.Body).Decode(&alerts) + return alerts, reqInf, nil +} + +// Returns a list of Servers +func (to *Session) GetServers() ([]v13.Server, ReqInf, error) { + resp, remoteAddr, err := to.request(http.MethodGet, API_v13_Servers, nil) + reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr} + if err != nil { + return nil, reqInf, err + } + defer resp.Body.Close() + + var data v13.ServersResponse + err = json.NewDecoder(resp.Body).Decode(&data) + return data.Response, reqInf, nil +} + +// GET a Server by the Server ID +func (to *Session) GetServerByID(id int) ([]v13.Server, ReqInf, error) { + route := fmt.Sprintf("%s/%d", API_v13_Servers, id) + resp, remoteAddr, err := to.request(http.MethodGet, route, nil) + reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr} + if err != nil { + return nil, reqInf, err + } + defer resp.Body.Close() + + var data v13.ServersResponse + if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { + return nil, reqInf, err + } + + return data.Response, reqInf, nil +} + +// GET a Server by the Server hostname +func (to *Session) GetServerByHostName(hostName string) ([]v13.Server, ReqInf, error) { + url := fmt.Sprintf("%s?hostName=%s", API_v13_Servers, hostName) + resp, remoteAddr, err := to.request(http.MethodGet, url, nil) + reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr} + if err != nil { + return nil, reqInf, err + } + defer resp.Body.Close() + + var data v13.ServersResponse + if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { + return nil, reqInf, err + } + + return data.Response, reqInf, nil +} + +// DELETE a Server by ID +func (to *Session) DeleteServerByID(id int) (tc.Alerts, ReqInf, error) { + route := fmt.Sprintf("%s/%d", API_v13_Servers, id) + resp, remoteAddr, err := to.request(http.MethodDelete, route, nil) + reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr} + if err != nil { + return tc.Alerts{}, reqInf, err + } + defer resp.Body.Close() + var alerts tc.Alerts + err = json.NewDecoder(resp.Body).Decode(&alerts) + return alerts, reqInf, nil +} diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json index b5be3ec3a..27012b91f 100644 --- a/traffic_ops/testing/api/v13/tc-fixtures.json +++ b/traffic_ops/testing/api/v13/tc-fixtures.json @@ -60,6 +60,20 @@ "name": "cdn3" } ], + "deliveryServiceRequestComments": [ + { + "value": "this is comment one" + }, + { + "value": "this is comment two" + }, + { + "value": "this is comment three" + }, + { + "value": "this is comment four" + } + ], "deliveryServiceRequests": [ { "changeType": "create", @@ -148,20 +162,6 @@ "status": "draft" } ], - "deliveryServiceRequestComments": [ - { - "value": "this is comment one" - }, - { - "value": "this is comment two" - }, - { - "value": "this is comment three" - }, - { - "value": "this is comment four" - } - ], "deliveryServices": [ { "active": false, @@ -549,7 +549,7 @@ { "cdnName": "cdn1", "description": "edge description", - "last_updated": "2018-03-02T17:27:11.796899+00:00", + "lastUpdated": "2018-03-02T17:27:11.796899+00:00", "name": "EDGE1", "routing_disabled": true, "type": "ATS_PROFILE" @@ -557,7 +557,7 @@ { "cdnName": "cdn1", "description": "mid description", - "last_updated": "2018-03-02T17:27:11.80173+00:00", + "lastUpdated": "2018-03-02T17:27:11.80173+00:00", "name": "MID1", "routing_disabled": false, "type": "ATS_PROFILE" @@ -565,7 +565,7 @@ { "cdnName": "cdn1", "description": "cdn1 description", - "last_updated": "2018-03-02T17:27:11.80452+00:00", + "lastUpdated": "2018-03-02T17:27:11.80452+00:00", "name": "CCR1", "routing_disabled": false, "type": "TR_PROFILE" @@ -573,7 +573,7 @@ { "cdnName": "cdn2", "description": "cdn2 description", - "last_updated": "2018-03-02T17:27:11.807948+00:00", + "lastUpdated": "2018-03-02T17:27:11.807948+00:00", "name": "CCR2", "routing_disabled": false, "type": "TR_PROFILE" @@ -581,7 +581,7 @@ { "cdnName": "cdn1", "description": "rascal description", - "last_updated": "2018-03-02T17:27:11.813052+00:00", + "lastUpdated": "2018-03-02T17:27:11.813052+00:00", "name": "RASCAL1", "routing_disabled": false, "type": "TM_PROFILE" @@ -589,7 +589,7 @@ { "cdnName": "cdn2", "description": "edge2 description", - "last_updated": "2018-03-02T17:27:11.818418+00:00", + "lastUpdated": "2018-03-02T17:27:11.818418+00:00", "name": "EDGE2", "routing_disabled": false, "type": "ATS_PROFILE" @@ -605,6 +605,896 @@ "name": "region2" } ], + "servers": [ + { + "cachegroupId": 300, + "cdnId": 100, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-edge-01", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:8::2/64", + "ip6Gateway": "2345:1234:12:8::1", + "ipAddress": "127.0.0.1", + "ipGateway": "127.0.0.1", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 80, + "typeId": 1, + "updPending": true, + "xmppId": "atlanta-edge-01\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId": 100, + "cdnId": 100, + "domainName": "kabletown.net", + "guid": null, + "hostName": "influxdb02", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 1500, + "interfaceName": "eth1", + "ip6Address": "127.0.0.11", + "ip6Gateway": "127.0.0.11", + "ipAddress": "127.0.0.11", + "ipGateway": "127.0.0.11", + "ipNetmask": "255.255.252.0", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 300, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 8086, + "typeId": 32, + "updPending": true, + "xmppId": "", + "xmppPasswd": "" + }, + { + "cachegroupId": 300, + "cdnId": 100, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-router-01", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:8::10/64", + "ip6Gateway": "2345:1234:12:8::1", + "ipAddress": "127.0.0.12", + "ipGateway": "127.0.0.1", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 80, + "typeId": 4, + "updPending": true, + "xmppId": "atlanta-router-01\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId": 300, + "cdnId": 100, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-edge-03", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:2::2/64", + "ip6Gateway": "2345:1234:12:8::1", + "ipAddress": "127.0.0.13", + "ipGateway": "127.0.0.1", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 3, + "tcpPort": 80, + "typeId": 1, + "updPending": true, + "xmppId": "atlanta-edge-03\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId": 900, + "cdnId": 100, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-edge-14", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:8::14/64", + "ip6Gateway": "2345:1234:12:8::1", + "ipAddress": "127.0.0.14", + "ipGateway": "127.0.0.1", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 80, + "typeId": 1, + "updPending": true, + "xmppId": "atlanta-edge-14\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId": 900, + "cdnId": 100, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-edge-15", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:d::15/64", + "ip6Gateway": "2345:1234:12:d::1", + "ipAddress": "127.0.0.15", + "ipGateway": "127.0.0.7", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 80, + "typeId": 1, + "updPending": true, + "xmppId": "atlanta-edge-15\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId": 800, + "cdnId": 100, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-mid-16", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:d::16/64", + "ip6Gateway": "2345:1234:12:d::1", + "ipAddress": "127.0.0.16", + "ipGateway": "127.0.0.7", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 80, + "typeId": 2, + "updPending": true, + "xmppId": "atlanta-mid-16\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId" : 800, + "cdnId": 100, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-org-1", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:d::17/64", + "ip6Gateway": "2345:1234:12:d::1", + "ipAddress": "127.0.0.17", + "ipGateway": "127.0.0.17", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 80, + "typeId": 3, + "updPending": true, + "xmppId": "atlanta-org-1\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId" : 800, + "cdnId": 200, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-org-2", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:d::18/64", + "ip6Gateway": "2345:1234:12:d::1", + "ipAddress": "127.0.0.18", + "ipGateway": "127.0.0.18", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 80, + "typeId": 3, + "updPending": true, + "xmppId": "atlanta-org-1\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId" : 100, + "cdnId": 100, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-mid-01", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:9::2/64", + "ip6Gateway": "2345:1234:12:9::1", + "ipAddress": "127.0.0.2", + "ipGateway": "127.0.0.2", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 80, + "typeId": 2, + "updPending": true, + "xmppId": "atlanta-mid-01\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId" : 100, + "cdnId": 200, + "domainName": "kabletown.net", + "guid": null, + "hostName": "rascal01", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:b::2/64", + "ip6Gateway": "2345:1234:12:b::1", + "ipAddress": "127.0.0.4", + "ipGateway": "127.0.0.4", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 81, + "typeId": 4, + "updPending": true, + "xmppId": "rascal\\\\@kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId" : 100, + "cdnId": 100, + "domainName": "kabletown.net", + "guid": null, + "hostName": "riak01", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 1500, + "interfaceName": "eth1", + "ip6Address": "", + "ip6Gateway": "", + "ipAddress": "127.0.0.5", + "ipGateway": "127.0.0.5", + "ipNetmask": "255.255.252.0", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 8088, + "typeId": 31, + "updPending": true, + "xmppId": "", + "xmppPasswd": "" + }, + { + "cachegroupId" : 100, + "cdnId": 200, + "domainName": "kabletown.net", + "guid": null, + "hostName": "rascal02", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:c::2/64", + "ip6Gateway": "2345:1234:12:c::1", + "ipAddress": "127.0.0.6", + "ipGateway": "127.0.0.6", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.05", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 81, + "typeId": 4, + "updPending": true, + "xmppId": "rascal\\\\@kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId" : 300, + "cdnId": 100, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-edge-02", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:d::2/64", + "ip6Gateway": "2345:1234:12:d::1", + "ipAddress": "127.0.0.7", + "ipGateway": "127.0.0.7", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 80, + "typeId": 1, + "updPending": true, + "xmppId": "atlanta-edge-02\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId" : 200, + "cdnId": 200, + "domainName": "ga.atlanta.kabletown.net", + "guid": null, + "hostName": "atlanta-mid-02", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 9000, + "interfaceName": "bond0", + "ip6Address": "2345:1234:12:e::2/64", + "ip6Gateway": "2345:1234:12:e::1", + "ipAddress": "127.0.0.8", + "ipGateway": "127.0.0.8", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 200, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 80, + "typeId": 2, + "updPending": true, + "xmppId": "atlanta-mid-02\\\\@ocdn.kabletown.net", + "xmppPasswd": "X" + }, + { + "cachegroupId" : 100, + "cdnId": 100, + "domainName": "kabletown.net", + "guid": null, + "hostName": "riak02", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 1500, + "interfaceName": "eth1", + "ip6Address": "2345:1234:12:f::2/64", + "ip6Gateway": "2345:1234:12:f::1", + "ipAddress": "127.0.0.9", + "ipGateway": "127.0.0.9", + "ipNetmask": "255.255.252.0", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 200, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 8088, + "typeId": 31, + "updPending": true, + "xmppId": "", + "xmppPasswd": "" + }, + { + "cachegroupId" : 100, + "cdnId": 100, + "domainName": "kabletown.net", + "guid": null, + "hostName": "influxdb01", + "httpsPort": null, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 1500, + "interfaceName": "eth1", + "ip6Address": "127.0.0.10", + "ip6Gateway": "127.0.0.10", + "ipAddress": "127.0.0.10", + "ipGateway": "127.0.0.10", + "ipNetmask": "255.255.252.0", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": null, + "physLocationId": 300, + "profileId": 1, + "rack": "RR 119.02", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 2, + "tcpPort": 8086, + "typeId": 32, + "updPending": true, + "xmppId": "", + "xmppPasswd": "" + }, + { + "cachegroupId" : 1, + "cdnId": 100, + "domainName": "example-domain.com", + "guid": null, + "hostName": "server1", + "httpsPort": null, + "iloIpAddress": null, + "iloIpGateway": null, + "iloIpNetmask": null, + "iloPassword": null, + "iloUsername": null, + "interfaceMtu": 1500, + "interfaceName": "bond0", + "ip6Address": null, + "ip6Gateway": null, + "ipAddress": "10.74.27.194", + "ipGateway": "10.74.27.194", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": null, + "mgmtIpGateway": null, + "mgmtIpNetmask": null, + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": null, + "revalPending": false, + "routerHostName": null, + "routerPortName": null, + "statusId": 1, + "tcpPort": null, + "typeId": 1, + "updPending": true, + "xmppId": null, + "xmppPasswd": null + }, + { + "cachegroupId" : 1, + "cdnId": 100, + "domainName": "example-domain.com", + "guid": null, + "hostName": "server2", + "httpsPort": null, + "iloIpAddress": null, + "iloIpGateway": null, + "iloIpNetmask": null, + "iloPassword": null, + "iloUsername": null, + "interfaceMtu": 1500, + "interfaceName": "bond0", + "ip6Address": "2001:852:fe0f:27::2/64", + "ip6Gateway": "2001:852:fe0f:27::1", + "ipAddress": "10.74.27.85", + "ipGateway": "10.74.27.85", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": null, + "mgmtIpGateway": null, + "mgmtIpNetmask": null, + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": null, + "revalPending": false, + "routerHostName": null, + "routerPortName": null, + "statusId": 1, + "tcpPort": null, + "typeId": 1, + "updPending": true, + "xmppId": null, + "xmppPasswd": null + }, + { + "cachegroupId" : 300, + "cdnId": 100, + "domainName": "northbound.com", + "guid": null, + "hostName": "tc1_ats1", + "httpsPort": null, + "iloIpAddress": null, + "iloIpGateway": null, + "iloIpNetmask": null, + "iloPassword": null, + "iloUsername": null, + "interfaceMtu": 1500, + "interfaceName": "eth0", + "ip6Address": null, + "ip6Gateway": null, + "ipAddress": "10.74.27.184", + "ipGateway": "10.74.27.1", + "ipNetmask": "255.255.255.0", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": null, + "mgmtIpGateway": null, + "mgmtIpNetmask": null, + "offlineReason": null, + "physLocationId": 300, + "profileId": 1, + "rack": null, + "revalPending": false, + "routerHostName": null, + "routerPortName": null, + "statusId": 1, + "tcpPort": null, + "typeId": 1, + "updPending": true, + "xmppId": null, + "xmppPasswd": null + }, + { + "cachegroupId" : 300, + "cdnId": 100, + "domainName": "northbound.com", + "guid": null, + "hostName": "tc1_ats2", + "httpsPort": null, + "iloIpAddress": null, + "iloIpGateway": null, + "iloIpNetmask": null, + "iloPassword": null, + "iloUsername": null, + "interfaceMtu": 1500, + "interfaceName": "eth0", + "ip6Address": null, + "ip6Gateway": null, + "ipAddress": "10.74.27.187", + "ipGateway": "10.74.27.1", + "ipNetmask": "255.255.255.0", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": null, + "mgmtIpGateway": null, + "mgmtIpNetmask": null, + "offlineReason": null, + "physLocationId": 300, + "profileId": 1, + "rack": null, + "revalPending": false, + "routerHostName": null, + "routerPortName": null, + "statusId": 1, + "tcpPort": null, + "typeId": 1, + "updPending": true, + "xmppId": null, + "xmppPasswd": null + }, + { + "cachegroupId" : 300, + "cdnId": 100, + "domainName": "northbound.com", + "guid": null, + "hostName": "tc2_ats2", + "httpsPort": 443, + "iloIpAddress": "", + "iloIpGateway": "", + "iloIpNetmask": "", + "iloPassword": "", + "iloUsername": "", + "interfaceMtu": 1500, + "interfaceName": "eth0", + "ip6Address": null, + "ip6Gateway": "", + "ipAddress": "10.73.27.187", + "ipGateway": "10.73.27.1", + "ipNetmask": "255.255.255.0", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": "", + "mgmtIpGateway": "", + "mgmtIpNetmask": "", + "offlineReason": "", + "physLocationId": 300, + "profileId": 1, + "rack": "", + "revalPending": false, + "routerHostName": "", + "routerPortName": "", + "statusId": 1, + "tcpPort": 80, + "typeId": 2, + "updPending": true, + "xmppId": null, + "xmppPasswd": null + }, + { + "cachegroupId" : 200, + "cdnId": 100, + "domainName": "example-domain.com", + "guid": null, + "hostName": "my-server-host", + "httpsPort": null, + "iloIpAddress": null, + "iloIpGateway": null, + "iloIpNetmask": null, + "iloPassword": null, + "iloUsername": null, + "interfaceMtu": 1500, + "interfaceName": "bond0", + "ip6Address": null, + "ip6Gateway": null, + "ipAddress": "10.74.27.78", + "ipGateway": "10.74.27.78", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": null, + "mgmtIpGateway": null, + "mgmtIpNetmask": null, + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": null, + "revalPending": false, + "routerHostName": null, + "routerPortName": null, + "statusId": 1, + "tcpPort": null, + "typeId": 1, + "updPending": true, + "xmppId": null, + "xmppPasswd": null + }, + { + "cachegroupId" : 200, + "cdnId": 100, + "domainName": "example-domain.com", + "guid": null, + "hostName": "my-server-host-ip6", + "httpsPort": null, + "iloIpAddress": null, + "iloIpGateway": null, + "iloIpNetmask": null, + "iloPassword": null, + "iloUsername": null, + "interfaceMtu": 1500, + "interfaceName": "bond0", + "ip6Address": "2001:853:fe0f:27::2/64", + "ip6Gateway": "2001:853:fe0f:27::1", + "ipAddress": "10.74.27.80", + "ipGateway": "10.74.27.80", + "ipNetmask": "255.255.255.252", + "lastUpdated": "2018-03-28T17:30:00.220351+00:00", + "mgmtIpAddress": null, + "mgmtIpGateway": null, + "mgmtIpNetmask": null, + "offlineReason": null, + "physLocationId": 100, + "profileId": 1, + "rack": null, + "revalPending": false, + "routerHostName": null, + "routerPortName": null, + "statusId": 2, + "tcpPort": null, + "typeId": 1, + "updPending": true, + "xmppId": null, + "xmppPasswd": null + } + ], "statuses": [ { "description": "Edge: Puts server in CCR config file in this state, but CCR will never route traffic to it. Mid: Server will not be included in parent.config files for its edge caches", diff --git a/traffic_ops/testing/api/v13/traffic_control.go b/traffic_ops/testing/api/v13/traffic_control.go index d13f9986f..b804ca0a1 100644 --- a/traffic_ops/testing/api/v13/traffic_control.go +++ b/traffic_ops/testing/api/v13/traffic_control.go @@ -33,6 +33,7 @@ type TrafficControl struct { Parameters []tcapi.Parameter `json:"parameters"` PhysLocations []tcapi.PhysLocation `json:"physLocations"` Regions []tcapi.Region `json:"regions"` + Servers []v13.Server `json:"servers"` Statuses []tcapi.Status `json:"statuses"` Tenants []tcapi.Tenant `json:"tenants"` Types []tcapi.Type `json:"types"` diff --git a/traffic_ops/traffic_ops_golang/server/servers.go b/traffic_ops/traffic_ops_golang/server/servers.go index c73d6e15f..35bb845d3 100644 --- a/traffic_ops/traffic_ops_golang/server/servers.go +++ b/traffic_ops/traffic_ops_golang/server/servers.go @@ -26,6 +26,7 @@ import ( "github.com/apache/incubator-trafficcontrol/lib/go-log" "github.com/apache/incubator-trafficcontrol/lib/go-tc" + "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13" "github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api" "github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth" "github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers" @@ -38,10 +39,10 @@ import ( ) //we need a type alias to define functions on -type TOServer tc.ServerNullable +type TOServer v13.ServerNullable //the refType is passed into the handlers where a copy of its type is used to decode the json. -var refType = TOServer(tc.ServerNullable{}) +var refType = TOServer{} func GetRefType() *TOServer { return &refType @@ -311,6 +312,7 @@ func (server *TOServer) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap defer resultRows.Close() var lastUpdated tc.TimeNoMod + var id int rowsAffected := 0 for resultRows.Next() { rowsAffected++ @@ -319,15 +321,18 @@ func (server *TOServer) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap return tc.DBError, tc.SystemError } } - log.Debugf("lastUpdated: %++v", lastUpdated) - server.LastUpdated = lastUpdated - if rowsAffected != 1 { - if rowsAffected < 1 { - return errors.New("no cdn found with this id"), tc.DataMissingError - } else { - return fmt.Errorf("this update affected too many rows: %d", rowsAffected), tc.SystemError - } + + if rowsAffected == 0 { + err = errors.New("no server was inserted, no id was returned") + log.Errorln(err) + return tc.DBError, tc.SystemError + } else if rowsAffected > 1 { + err = errors.New("too many ids returned from server insert") + log.Errorln(err) + return tc.DBError, tc.SystemError } + server.SetID(id) + server.LastUpdated = &lastUpdated err = tx.Commit() if err != nil { log.Errorln("Could not commit transaction: ", err) @@ -437,7 +442,7 @@ func (server *TOServer) Create(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap return tc.DBError, tc.SystemError } server.SetID(id) - server.LastUpdated = lastUpdated + server.LastUpdated = &lastUpdated err = tx.Commit() if err != nil { log.Errorln("Could not commit transaction: ", err) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
