8f9ff5aa8ae773623210d59999cd5d7d0cef4569
galt
  Tue Aug 13 12:46:26 2019 -0700
Added support for hgcentral.targetDb table so it can handle hgPcr support gfServers. Can now report obsolete entries and mismatch between targetDb.seqFile and gfServer filename

diff --git src/hg/utils/blatServersCheck/blatServersCheck.c src/hg/utils/blatServersCheck/blatServersCheck.c
index 29ade64..73061c6 100644
--- src/hg/utils/blatServersCheck/blatServersCheck.c
+++ src/hg/utils/blatServersCheck/blatServersCheck.c
@@ -139,90 +139,147 @@
 	    {
 	    if (!sameString(buf+strlen("port "), portName))
 		{
 		warn("port mismatch: gfServer says %s but db says port=%s", buf, portName);
 		ret = -5;  // port mismatch  // probably never happens.
 		break;
 		}
 	    }
 	}
     }
 close(sd);
 return(ret);
 }
 
 
-int getFileList(char *hostName, char *portName, char *db)
-/* Get and display input file list. */
+int getFileList(char *hostName, char *portName, char *db, struct hash *targetDbHash)
+/* Get and display input file list. 
+ * Returns -1 for 2bit name mismatch
+ * Returns -2 for name mot found in targetDb, probably obsolete
+ * Returns -3 for targetDb.seqFile does not match fileName on gfServer
+ */
 {
 char buf[256];
 int sd = 0;
 int fileCount;
 int i;
 int ret = 0;
 char twoBitName[256];
 
 safef(twoBitName, sizeof twoBitName, "%s.2bit", db);
 
 /* Put together command. */
 sd = netMustConnectTo(hostName, portName);
 sprintf(buf, "%sfiles", gfSignature());
 mustWriteFd(sd, buf, strlen(buf));
 
 /* Get count of files, and then each file name. */
 if (netGetString(sd, buf) != NULL)
     {
     fileCount = atoi(buf);
     for (i=0; i<fileCount; ++i) // could have multiples if .nib used?
 	{
 	char *fileName = netRecieveString(sd, buf);
 	//printf("%s\n", fileName);
 	verbose(2, "%s\n", fileName);
 	// if .nib or Kg genes for isPcr, cannot confirm the name.
-	if (!endsWith(fileName,".nib") && !strstr(db, "Kg"))  
+	if (endsWith(fileName,".nib"))
+            {
+	    // DO NOTHING FOR NIBS
+	    }
+        else if (strstr(db, "Kg"))
+	    {
+	    struct hashEl *hel = hashLookup(targetDbHash, db);
+	    if (hel == NULL)
+		{
+		warn("db %s not found in targetDb.name, probably obsolete", db);
+		ret = -2;  // name mot found in targetDb, probably obsolete
+		break;
+		}
+	    else
+		{
+		char *seqFile = hel->val;
+		if (!endsWith(seqFile, fileName))
+		    {
+		    warn("targetDb.seqFile %s does not match fileName=%s on gfServer", seqFile, twoBitName);
+		    ret = -3;  // targetSeq fileName mistmatch
+		    break;
+		    }
+		}
+	    }
+        else
 	    {
 	    if (!sameString(fileName, twoBitName))
 		{
 		warn("2bit name mismatch fileName=%s twoBitName=%s", fileName, twoBitName);
 		ret = -1;  // 2bit name mismatch
 		break;
 		}
 	    }
 	}
     }
 close(sd);
 return ret;
 }
 
+void getTargetDb(struct sqlConnection *conn, struct hash *targetDbHash)
+/* read targetDb table into hash */
+{
+struct sqlResult *sr;
+char **row;
+char query[256];
+
+sqlSafef(query,sizeof(query), "select name, seqFile from targetDb");
+sr = sqlGetResult(conn, query);
+while ((row = sqlNextRow(sr)) != NULL)
+    {
+    char *name    = row[0];
+    char *seqFile = row[1];
+    struct hashEl *hel = hashLookup(targetDbHash, name);
+    if (hel == NULL)
+	{
+	hashAdd(targetDbHash, name, cloneString(seqFile));
+	}
+    else
+	{
+	warn("duplicate targetDb.name found %s", name);
+	}
+    }
+
+sqlFreeResult(&sr);
+} 
 
 void blatServersCheck(char *config)
 /* Check blatServers table against running gfServers */
 {
 
 struct hash *hash = hashNew(12);
 struct hash *versionHash = hashNew(6);
+struct hash *targetDbHash = hashNew(6);
 
 char hashKey[256];
 
 /* get connection info */
 database = getCfgOption(config, "db"      );
 host     = getCfgOption(config, "host"    );
 user     = getCfgOption(config, "user"    );
 password = getCfgOption(config, "password");
 
 conn = sqlConnectRemote(host, user, password, database);
 
+getTargetDb(conn, targetDbHash);
+
 struct sqlResult *sr;
 char **row;
 char query[256];
 int totalRows = 0;
 
 verbose(1, "-------------------\n");
 verbose(1, "Reading table %s\n", blatServersTableName);
 
 
 totalRows = sqlTableSize(conn, blatServersTableName);
 verbose(1,"totalRows=%d\n", totalRows);
 
 if (totalRows==0)
     {
     errAbort("table %s is empty!", blatServersTableName);
@@ -233,31 +290,31 @@
 sqlSafef(query,sizeof(query), "select db, host, port, isTrans from %s", blatServersTableName);
 sr = sqlGetResult(conn, query);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     char *db      = row[0];
     char *host    = row[1];
     char *portStr = row[2];
     unsigned int port  = sqlUnsigned(portStr);
     unsigned int trans = sqlUnsigned(row[3]);
     boolean isTrans = (trans == 1);
 
     int res = statusServer(host, portStr, isTrans, versionHash);
     int res2 = 0;
     if (res != -1)  // if not a connection error, proceed.
 	{
-	res2 = getFileList(host, portStr, db);
+	res2 = getFileList(host, portStr, db, targetDbHash);
 	}
     safef(hashKey, sizeof hashKey, "%s:%s", host, portStr);
     struct hashEl *hel = hashLookup(hash, hashKey);
     if (hel == NULL)
 	{
 	hashAdd(hash, hashKey, NULL);
 	}
     else
 	{
 	warn("duplicate host:port %s found", hashKey);
 	}
 
     if ((res != 0) || (res2 != 0) || (hel != NULL))
 	{
 	++errCount;