// dbConsolePodHeartbeat will update the heartbeat for all nodes assigned
// to this console pod and remove the node from the ncis list.
// Any nodes not assigned to the console pod will remain in ncis.
// Any error(s) will be returned.
dbConsolePodHeartbeat will update the heartbeat for all nodes assigned
to this console pod and remove the node from the ncis list.
Any nodes not assigned to the console pod will remain in ncis.
Any error(s) will be returned.
// dbConsolePodHeartbeat will update the heartbeat for all nodes assigned // to this console pod and remove the node from the ncis list . // Any nodes not assigned to the console pod will remain in ncis . // Any error ( s ) will be returned .
func dbConsolePodHeartbeat(pod_id string, ncis *[]NodeConsoleInfo) (rowsAffected int64, notUpdated []NodeConsoleInfo, err error) {
	mu.Lock()
	defer mu.Unlock()
	var errList []string
	rowsAffected = 0
	notUpdated = []NodeConsoleInfo{}
	sqlStmt := `
		update ownership set heartbeat=now()
		where node_name = $1 and console_pod_id = $2
	`
	for _, nci := range *ncis {
		result, err := DB.Exec(sqlStmt, nci.NodeName, pod_id)
		if err != nil {
			errMsg := fmt.Sprintf("WARN: dbConsolePodHeartbeat: There is an UPDATE error: %s", err)
			log.Printf(errMsg)
			errList = append(errList, errMsg)
		}
		if result != nil {
			ra, _ := result.RowsAffected()
			debugLog.Println(fmt.Sprintf("result.RowsAffected %d", ra))
			if ra == 0 {
				notUpdated = append(notUpdated, nci)
			} else {
				rowsAffected += ra
			}
		}
	}
	for _, nci := range notUpdated {
		log.Printf("nci not updaed: %s", nci.NodeName)
	}
	if len(errList) > 0 {
		var errStr string
		for _, e := range errList {
			errStr += fmt.Sprintf("%s\n", e)
		}
		return rowsAffected, notUpdated, errors.New(errStr)
	} else {
		return rowsAffected, notUpdated, nil
	}
}
func dbConsolePodHeartbeat ( pod_id string , ncis * [ ] NodeConsoleInfo ) ( rowsAffected int64 , notUpdated [ ] NodeConsoleInfo , err error ) { mu . Lock ( ) defer mu . Unlock ( ) var errList [ ] string rowsAffected = 0 notUpdated = [ ] NodeConsoleInfo { } sqlStmt := `
		update ownership set heartbeat=now()
		where node_name = $1 and console_pod_id = $2
	` for _ , nci := range * ncis { result , err := DB . Exec ( sqlStmt , nci . NodeName , pod_id ) if err != nil { errMsg := fmt . Sprintf ( " " , err ) log . Printf ( errMsg ) errList = append ( errList , errMsg ) } if result != nil { ra , _ := result . RowsAffected ( ) debugLog . Println ( fmt . Sprintf ( " " , ra ) ) if ra == 0 { notUpdated = append ( notUpdated , nci ) } else { rowsAffected += ra } } } for _ , nci := range notUpdated { log . Printf ( " " , nci . NodeName ) } if len ( errList ) > 0 { var errStr string for _ , e := range errList { errStr += fmt . Sprintf ( " \n " , e ) } return rowsAffected , notUpdated , errors . New ( errStr ) } else { return rowsAffected , notUpdated , nil } }
dbConsolePodHeartbeat will update the heartbeat for all nodes assigned
to this console pod and remove the node from the ncis list.
dbConsolePodHeartbeat will update the heartbeat for all nodes assigned to this console pod and remove the node from the ncis list .
// Update all pods found by name and console pod ID. // All errors are returned. // This first cut is non-transactional meaning that any // updates that can be completed will immediately complete. // On an update operation RowsAffected will be the count acually updated. // This node was not assigned to the pod. // Add the update count to the total. // Let the caller see the list that was not updated (if any).