rimashah25 commented on code in PR #6544:
URL: https://github.com/apache/trafficcontrol/pull/6544#discussion_r848640255
##########
traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go:
##########
@@ -1788,3 +1788,102 @@ func GetRegionNameFromID(tx *sql.Tx, regionID int)
(string, bool, error) {
}
return regionName, true, nil
}
+
+// GetCommonServerPropertiesFromV4 converts CommonServerPropertiesV40 to
CommonServerProperties struct
+func GetCommonServerPropertiesFromV4(s tc.ServerV40, tx *sql.Tx)
(tc.CommonServerProperties, error) {
+ var id int
+ var desc string
+ rows, err := tx.Query("SELECT id, description from profile WHERE
name=$1", (s.ProfileNames)[0])
+ if err != nil {
+ return tc.CommonServerProperties{}, fmt.Errorf("querying
profile id and description by profile_name: " + err.Error())
+ }
+ defer log.Close(rows, "closing rows in GetCommonServerPropertiesFromV4")
+
+ for rows.Next() {
+ if err := rows.Scan(&id, &desc); err != nil {
+ return tc.CommonServerProperties{},
fmt.Errorf("scanning profile: " + err.Error())
+ }
+ }
+
+ return tc.CommonServerProperties{
+ Cachegroup: s.Cachegroup,
+ CachegroupID: s.CachegroupID,
+ CDNID: s.CDNID,
+ CDNName: s.CDNName,
+ DeliveryServices: s.DeliveryServices,
+ DomainName: s.DomainName,
+ FQDN: s.FQDN,
+ FqdnTime: s.FqdnTime,
+ GUID: s.GUID,
+ HostName: s.HostName,
+ HTTPSPort: s.HTTPSPort,
+ ID: s.ID,
+ ILOIPAddress: s.ILOIPAddress,
+ ILOIPGateway: s.ILOIPGateway,
+ ILOIPNetmask: s.ILOIPNetmask,
+ ILOPassword: s.ILOPassword,
+ ILOUsername: s.ILOUsername,
+ LastUpdated: s.LastUpdated,
+ MgmtIPAddress: s.MgmtIPAddress,
+ MgmtIPGateway: s.MgmtIPGateway,
+ MgmtIPNetmask: s.MgmtIPNetmask,
+ OfflineReason: s.OfflineReason,
+ Profile: &(s.ProfileNames)[0],
+ ProfileDesc: &desc,
+ ProfileID: &id,
+ PhysLocation: s.PhysLocation,
+ PhysLocationID: s.PhysLocationID,
+ Rack: s.Rack,
+ RevalPending: s.RevalPending,
+ Status: s.Status,
+ StatusID: s.StatusID,
+ TCPPort: s.TCPPort,
+ Type: s.Type,
+ TypeID: s.TypeID,
+ UpdPending: s.UpdPending,
+ XMPPID: s.XMPPID,
+ XMPPPasswd: s.XMPPPasswd,
+ }, nil
+}
+
+// UpdateServerProfilesForV4 updates server_profile table via update function
for APIv4
+func UpdateServerProfilesForV4(id *int, profile []string, tx *sql.Tx) error {
+ var profileNames []string
+
+ //Delete existing rows from server_profile to get the priority correct
for profile_name changes
+ _, err := tx.Exec("DELETE FROM server_profile WHERE server=$1", *id)
+ if err != nil {
+ return fmt.Errorf("updating server_profile by server id: %v" +
strconv.Itoa(*id) + ", error: " + err.Error())
+ }
+
+ for i, pName := range profile {
+ query := `INSERT INTO server_profile (server, profile_name,
priority) VALUES ($1, $2, $3)`
+ _, err := tx.Exec(query, *id, pName, i)
+ if err != nil {
+ return fmt.Errorf("error inserting into server_profile
table, %v", err)
+ }
+ }
+
+ err = tx.QueryRow("SELECT ARRAY_AGG(profile_name) FROM server_profile
WHERE server=$1", *id).Scan(pq.Array(&profileNames))
Review Comment:
`ORDER BY` didn't work but I used `GROUP BY`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]