// dbUpdateNodes will ensure that the list of node metadata exists in the database.
// Any error(s) will be returned.
dbUpdateNodes will ensure that the list of node metadata exists in the database.
Any error(s) will be returned.
// dbUpdateNodes will ensure that the list of node metadata exists in the database . // Any error ( s ) will be returned .
func dbUpdateNodes(ncis *[]NodeConsoleInfo) (rowsInserted int64, err error) {
	var errList []string
	rowsInserted = 0
	sql := `
        insert into ownership (node_name,
          node_bmc_name,
          node_bmc_fqdn,
          node_class,
          node_nid_number,
          node_role,
          console_pod_id,
          last_updated,
	      heartbeat)
        values
          ($1,
          $2,
          $3,
          $4,
          $5,
          $6,
          NULL,
          now(),
	      NULL)
        on conflict (node_name) do nothing
    `
	for _, nci := range *ncis {
		result, err := DB.Exec(sql,
			nci.NodeName,
			nci.BmcName,
			nci.BmcFqdn,
			nci.Class,
			nci.NID,
			nci.Role)
		if err != nil {
			errMsg := fmt.Sprintf("WARN: dbUpdateNodes: There is an INSERT error on node %s: %s", nci.NodeName, err)
			log.Printf(errMsg)
			errList = append(errList, errMsg)
		}
		if result != nil {
			i64, _ := result.RowsAffected()
			debugLog.Println(fmt.Sprintf("result.RowsAffected %d", i64))
			rowsInserted += i64
		}
	}
	if len(errList) > 0 {
		var errStr string
		for _, e := range errList {
			errStr += fmt.Sprintf("%s\n", e)
		}
		return rowsInserted, errors.New(errStr)
	} else {
		return rowsInserted, nil
	}
}
func dbUpdateNodes ( ncis * [ ] NodeConsoleInfo ) ( rowsInserted int64 , err error ) { var errList [ ] string rowsInserted = 0 sql := `
        insert into ownership (node_name,
          node_bmc_name,
          node_bmc_fqdn,
          node_class,
          node_nid_number,
          node_role,
          console_pod_id,
          last_updated,
	      heartbeat)
        values
          ($1,
          $2,
          $3,
          $4,
          $5,
          $6,
          NULL,
          now(),
	      NULL)
        on conflict (node_name) do nothing
    ` for _ , nci := range * ncis { result , err := DB . Exec ( sql , nci . NodeName , nci . BmcName , nci . BmcFqdn , nci . Class , nci . NID , nci . Role ) if err != nil { errMsg := fmt . Sprintf ( " " , nci . NodeName , err ) log . Printf ( errMsg ) errList = append ( errList , errMsg ) } if result != nil { i64 , _ := result . RowsAffected ( ) debugLog . Println ( fmt . Sprintf ( " " , i64 ) ) rowsInserted += i64 } } if len ( errList ) > 0 { var errStr string for _ , e := range errList { errStr += fmt . Sprintf ( " \n " , e ) } return rowsInserted , errors . New ( errStr ) } else { return rowsInserted , nil } }
dbUpdateNodes will ensure that the list of node metadata exists in the database.
dbUpdateNodes will ensure that the list of node metadata exists in the database .
// Insert each node.  Duplicates will be ignored. // Any errors will be logged and returned. // This first cut is non-transactional meaning that any // inserts that can be completed will immediately complete. // On an insert operation RowsAffected will be the count acually inserted. // This will be 1 for new records and 0 for a duplicate which is ignored or // in the case of a check constraint violation.