IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28102


Ignore:
Timestamp:
May 25, 2010, 3:53:52 PM (16 years ago)
Author:
heather
Message:

added -checkminidvodbaddrun option

Location:
branches/haf_branches/ipp.20100512/ippTools
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/haf_branches/ipp.20100512/ippTools/share/Makefile.am

    r27956 r28102  
    44
    55dist_pkgdata_DATA = \
     6     addtool_checkminidvodbaddrun.sql \
    67     addtool_donecleanup.sql \
    78     addtool_find_cam_id.sql \
     
    1112     addtool_find_minidvodbprocessed.sql \
    1213     addtool_find_minidvodbrun.sql \
    13      addtool_find_minidvodbrun2.sql \
    1414     addtool_pendingcleanupexp.sql \
    1515     addtool_pendingcleanuprun.sql \
  • branches/haf_branches/ipp.20100512/ippTools/src/addtool.c

    r28058 r28102  
    4444static bool listminidvodbrunMode(pxConfig *config);
    4545static bool flipminidvodbrunMode(pxConfig *config);
     46static bool checkminidvodbrunaddrunMode(pxConfig *config);
    4647static bool addminidvodbprocessedMode(pxConfig *config);
    4748static bool listminidvodbprocessedMode(pxConfig *config);
     
    8384        MODECASE(ADDTOOL_MODE_LISTMINIDVODBRUN,     listminidvodbrunMode);
    8485        MODECASE(ADDTOOL_MODE_FLIPMINIDVODBRUN,     flipminidvodbrunMode);
     86        MODECASE(ADDTOOL_MODE_CHECKMINIDVODBRUNADDRUN, checkminidvodbrunaddrunMode);
    8587        MODECASE(ADDTOOL_MODE_ADDMINIDVODBPROCESSED,addminidvodbprocessedMode);
    8688        MODECASE(ADDTOOL_MODE_LISTMINIDVODBPROCESSED,listminidvodbprocessedMode);
     
    771773  // required
    772774
     775  PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-set_minidvodb_group", true, false);
     776  PXOPT_LOOKUP_STR(mergedvodb_path, config->args, "-set_mergedvodb_path", true, false);
     777
     778
     779 PXOPT_LOOKUP_STR(minidvodb_name, config->args, "-set_minidvodb_name", false, false);
    773780 
    774 
    775   PXOPT_LOOKUP_STR(minidvodb_name, config->args, "-set_minidvodb_name", false, false);
    776   PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-set_minidvodb_group", true, false);
    777   PXOPT_LOOKUP_STR(minidvodb_path, config->args, "-set_minidvodb_path", false, false);
    778   PXOPT_LOOKUP_STR(mergedvodb_path, config->args, "-set_mergedvodb_path", true, false);
     781 PXOPT_LOOKUP_STR(minidvodb_path, config->args, "-set_minidvodb_path", false, false);
     782 
    779783  PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
    780   psMetadata *where = psMetadataAlloc();
    781 
    782   PXOPT_COPY_S64(config->args, where, "-set_minidvodb_name",  "minidvodb_name", "==");
    783   PXOPT_COPY_S64(config->args, where, "-set_minidvodb_path",  "minidvodb_path", "==");
    784   PXOPT_COPY_STR(config->args, where, "-set_mergedvodb_path",  "mergedvodb_path", "==");
    785   //PXOPT_COPY_S255(config->args, where, "-set_state",  "state", "==");
    786 
    787   //generate restrictions
    788   //psString query = pxDataGet("addtool_queue_minidvodbrun.sql");
    789   //if (!query) {
    790   //    psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    791   //    return false;
    792   // }
    793 
    794   //if ((!minidvodb_name) && (!minidvodb_path) && (!mergedvodb_path) ) {
    795   // psError(PXTOOLS_ERR_SYS, false, "need minidvodb_path, mergedvodb_path, and minidvodb_name");
    796   //}
    797 
    798     psString query =  NULL;
    799     psStringAppend(&query, "INSERT INTO minidvodbRun SET minidvodb_path = '%s' ,",minidvodb_path);
    800     if (minidvodb_name) {psStringAppend(&query, "minidvodb_name = '%s' ,",minidvodb_name);}
    801     psStringAppend(&query, "mergedvodb_path = '%s',",mergedvodb_path);
    802     if (minidvodb_path) {psStringAppend(&query, "minidvodb_group = '%s'",minidvodb_group);}
    803     if (state) {
    804       psStringAppend(&query, ",state = '%s';", state);
    805     } else {
    806       psStringAppend(&query, ",state = 'new';");
    807     }
    808    
    809    
    810 if (!query) {
    811       psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     784 
     785
     786    if (!psDBTransaction(config->dbh)) {
     787        psError(PS_ERR_UNKNOWN, false, "database error");
     788       
     789        return false;
     790    }
     791 //psMetadata *where = psMetadataAlloc();
     792
     793  //PXOPT_COPY_S64(config->args, where, "-set_minidvodb_name",  "minidvodb_name", "==");
     794  // PXOPT_COPY_S64(config->args, where, "-set_minidvodb_path",  "minidvodb_path", "==");
     795  //PXOPT_COPY_STR(config->args, where, "-set_mergedvodb_path",  "mergedvodb_path", "==");
     796 
     797
     798  //  psString query =  NULL;
     799  //   psStringAppend(&query, "INSERT INTO minidvodbRun SET minidvodb_path = '%s' ,",minidvodb_path);
     800  //  if (minidvodb_name) {psStringAppend(&query, "minidvodb_name = '%s' ,",minidvodb_name);}
     801  //   psStringAppend(&query, "mergedvodb_path = '%s',",mergedvodb_path);
     802  //   if (minidvodb_path) {psStringAppend(&query, "minidvodb_group = '%s'",minidvodb_group);}
     803  //   if (state) {
     804  //     psStringAppend(&query, ",state = '%s';", state);
     805  //   } else {
     806  //     psStringAppend(&query, ",state = 'new';");
     807      //     //   }
     808   
     809   
     810        //if (!query) {
     811      //     psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     812      //      return false;
     813  //  }
     814
     815  //if (!p_psDBRunQuery(config->dbh, query)) {
     816      //     psError(PS_ERR_UNKNOWN, false, "database error %s", query);
     817  //     psFree(query);
     818        //      return false;
     819        //  }
     820//  psFree(query);
     821
     822//psArray *output = p_psDBFetchResult(config->dbh);
     823  //   if (!output) {
     824      //        psError(PS_ERR_UNKNOWN, false, "database error");
     825  //       return false;
     826  //  }
     827//  if (!psArrayLength(output)) {
     828  //      psTrace("addtool", PS_LOG_INFO, "no rows found");
     829        //      psFree(output);
     830  //     return true;
     831        //  }
     832  //if (!psDBTransaction(config->dbh)) {
     833  //       psError(PS_ERR_UNKNOWN, false, "database error");
     834  //       psFree(output);
     835  //     return false;
     836        //      //  }
     837  psString minidvodbpath = "NULL";
     838
     839
     840  // I don't know how to get around the complaints of minidvodb_path can't be null. this 'fixes' it, but someone smarter can fix it properly.
     841  if (minidvodb_path) {
     842    minidvodbpath = minidvodb_path;
     843  }
     844
     845if (!minidvodbRunInsert(config->dbh,
     846            0, // job_id
     847            minidvodb_name,
     848            minidvodb_group,
     849            minidvodbpath,
     850            mergedvodb_path,
     851            "new"           
     852            )) {
     853        psError(PS_ERR_UNKNOWN, false, "database error");
     854        return false;
     855    }
     856 
     857    psU64 affected = psDBAffectedRows(config->dbh);
     858    if (affected != 1) {
     859      psError(PS_ERR_UNKNOWN, false,
     860            "should have affected one row but %" PRIu64 " rows were modified",
     861            affected);
    812862      return false;
    813    }
    814 
     863    }
     864
     865    psS64 minidvodb_id = psDBLastInsertID(config->dbh);
     866    printf("%" PRId64 "\n", minidvodb_id);
     867   
     868   
     869    if (!minidvodb_name) {
     870      psStringAppend(&minidvodb_name, "%s.%" PRIu64,minidvodb_group,minidvodb_id);
     871    }
     872
     873
     874
     875    if (!minidvodb_path) {
     876      psStringAppend(&minidvodb_path,"%s/%s",mergedvodb_path,minidvodb_name);
     877     
     878    }
     879
     880   
     881    psString query = NULL;
     882
     883    psStringAppend(&query, "UPDATE minidvodbRun SET minidvodb_path = '%s', minidvodb_name = '%s' where minidvodb_id = %" PRIu64";", minidvodb_path, minidvodb_name, minidvodb_id);
     884   
    815885    if (!p_psDBRunQuery(config->dbh, query)) {
    816       psError(PS_ERR_UNKNOWN, false, "database error %s", query);
    817         psFree(query);
    818         return false;
    819     }
    820     psFree(query);
    821 
    822 psArray *output = p_psDBFetchResult(config->dbh);
    823     if (!output) {
    824         psError(PS_ERR_UNKNOWN, false, "database error");
    825         return false;
    826     }
    827     if (!psArrayLength(output)) {
    828         psTrace("addtool", PS_LOG_INFO, "no rows found");
    829         psFree(output);
    830         return true;
    831     }
    832 if (!psDBTransaction(config->dbh)) {
    833         psError(PS_ERR_UNKNOWN, false, "database error");
    834         psFree(output);
    835         return false;
    836     }
    837 
    838 return true;
     886      psError(PS_ERR_UNKNOWN, false, "database error");
     887      psFree(query);
     888      return false;
     889    }
     890
     891   
     892
     893    if (!psDBCommit(config->dbh)) {
     894        psError(PS_ERR_UNKNOWN, false, "database error");
     895        return false;
     896    }
     897
     898
     899    return true;
    839900}
    840901
     
    9401001// and the active - > waiting in one action
    9411002
     1003
     1004// the first query looks to find things that are new and where all the fields are filled (ie, ready to be flipped to active)
    9421005 
    943  psString firstquery = psStringCopy("SELECT * from  minidvodbRun where state = 'new' ");
     1006// start a transaction eraly so it will contain any row level locks
     1007    if (!psDBTransaction(config->dbh)) {
     1008        psError(PS_ERR_UNKNOWN, false, "database error");
     1009        return false;
     1010    }
     1011
     1012
     1013
     1014
     1015
     1016 psString firstquery = psStringCopy("SELECT * from  minidvodbRun where state = 'new' and minidvodb_name is NOT NULL and minidvodb_group IS NOT NULL and minidvodb_path IS NOT NULL and mergedvodb_path IS NOT NULL");
    9441017
    9451018 psString firstwhereClause = psDBGenerateWhereConditionSQL(where, NULL);
     
    9491022
    9501023 if (!p_psDBRunQuery(config->dbh, firstquery)) {
    951       psError(PS_ERR_UNKNOWN, false, "database error ");
    952         psFree(firstquery);
    953         return false;
     1024   psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1025   if (!psDBRollback(config->dbh)) {
     1026     psError(PS_ERR_UNKNOWN, false, "database error");
     1027   }
     1028   return false;
     1029
    9541030    }
    9551031 psFree(firstquery);
     
    9851061
    9861062 if (!p_psDBRunQuery(config->dbh, query)) {
    987         psError(PS_ERR_UNKNOWN, false, "database error");
    988         psFree(query);
    989         return false;
    990     }
    991 
    992 if (!psDBTransaction(config->dbh)) {
    993         psError(PS_ERR_UNKNOWN, false, "database error");
    994         psFree(output);
    995         return false;
    996     }
    997 
    998 
    999 
    1000 
    1001 
    1002 psString query2 = psStringCopy("UPDATE minidvodbRun SET state = 'active' WHERE state = 'new' ");
     1063   psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1064   if (!psDBRollback(config->dbh)) {
     1065     psError(PS_ERR_UNKNOWN, false, "database error");
     1066   }
     1067   return false;
     1068
     1069   
     1070    }
     1071
     1072 //if (!psDBTransaction(config->dbh)) {
     1073 //      psError(PS_ERR_UNKNOWN, false, "database error");
     1074 //      psFree(output);
     1075 //     return false;
     1076 //  }
     1077
     1078
     1079
     1080
     1081
     1082psString query2 = psStringCopy("UPDATE minidvodbRun SET state = 'active' WHERE state = 'new' AND minidvodb_name is NOT NULL and minidvodb_group IS NOT NULL and minidvodb_path IS NOT NULL and mergedvodb_path IS NOT NULL ");
    10031083
    10041084
     
    10081088
    10091089 if (!p_psDBRunQuery(config->dbh, query2)) {
    1010         psError(PS_ERR_UNKNOWN, false, "database error");
    1011         psFree(query2);
    1012         return false;
    1013     }
    1014 
    1015 if (!psDBTransaction(config->dbh)) {
    1016         psError(PS_ERR_UNKNOWN, false, "database error");
    1017         psFree(output);
    1018         return false;
    1019     }
     1090   psError(PS_ERR_UNKNOWN, false, "database error");
     1091   if (!psDBRollback(config->dbh)) {
     1092        psError(PS_ERR_UNKNOWN, false, "database error");
     1093   }
     1094   psFree(query);
     1095   return false;
     1096
     1097    }
     1098
     1099
    10201100
    10211101
    10221102
    10231103if (!psDBCommit(config->dbh)) {
    1024         psError(PS_ERR_UNKNOWN, false, "database error");
    1025         return false;
     1104  psError(PS_ERR_UNKNOWN, false, "database error");
     1105  if (!psDBRollback(config->dbh)) {
     1106    psError(PS_ERR_UNKNOWN, false, "database error");
     1107  }
     1108  psFree(query);
     1109  return false;
    10261110    }
    10271111 psFree(query2);
     
    10311115
    10321116}
     1117
     1118
     1119static bool checkminidvodbrunaddrunMode(pxConfig *config) {
     1120  PS_ASSERT_PTR_NON_NULL(config, false);
     1121  psMetadata *where = psMetadataAlloc();
     1122  PXOPT_COPY_STR(config->args, where, "-minidvodb_group", "minidvodbRun.minidvodb_group", "==");
     1123  PXOPT_COPY_STR(config->args, where, "-minidvodb_name", "minidvodbRun.minidvodb_name", "==");
     1124  PXOPT_COPY_STR(config->args, where, "-state", "minidvodbRun.state", "==");
     1125 
     1126
     1127  PXOPT_LOOKUP_U64(limit,      config->args, "-limit", false, false);
     1128  PXOPT_LOOKUP_BOOL(all_addrun_states, config->args, "-all_addrun_states", false);
     1129  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1130 
     1131  if (!psListLength(where->list)) {
     1132        psFree(where);
     1133        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1134        return false;
     1135  }
     1136
     1137  psString query = pxDataGet("addtool_checkminidvodbaddrun.sql");
     1138 
     1139  if (!query) {
     1140        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1141        return false;
     1142  }
     1143 
     1144 
     1145  if (psListLength(where->list)) {
     1146        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1147        psStringAppend(&query, " WHERE %s", whereClause);
     1148        psFree(whereClause);
     1149  }
     1150
     1151  if (!all_addrun_states) {
     1152    psStringAppend(&query, " AND (cnt2 = cnt) ");
     1153  }
     1154 
     1155  if (limit) {
     1156    psString limitString = psDBGenerateLimitSQL(limit);
     1157    psStringAppend(&query, " %s", limitString);
     1158    psFree(limitString);
     1159  }
     1160
     1161
     1162
     1163
     1164
     1165if (!p_psDBRunQuery(config->dbh, query)) {
     1166  psError(PS_ERR_UNKNOWN, false, "database error");
     1167  psFree(query);
     1168  return false;
     1169 }
     1170psFree(query);
     1171psArray *output = p_psDBFetchResult(config->dbh);
     1172if (!output) {
     1173  psError(PS_ERR_UNKNOWN, false, "database error");
     1174  return false;
     1175    }
     1176if (!psArrayLength(output)) {
     1177  psTrace("addtool", PS_LOG_INFO, "no rows found");
     1178  psFree(output);
     1179  return true;
     1180 }
     1181
     1182 if (!ippdbPrintMetadatas(stdout, output, "addProcessedExp", !simple)) {
     1183   psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1184   psFree(output);
     1185   return false;
     1186 }
     1187
     1188 psFree(output);
     1189
     1190
     1191  return true;
     1192}
     1193
    10331194
    10341195
  • branches/haf_branches/ipp.20100512/ippTools/src/addtool.h

    r28058 r28102  
    4444    ADDTOOL_MODE_LISTMINIDVODBRUN,
    4545    ADDTOOL_MODE_FLIPMINIDVODBRUN,
     46    ADDTOOL_MODE_CHECKMINIDVODBRUNADDRUN,
    4647    ADDTOOL_MODE_ADDMINIDVODBPROCESSED,
    4748    ADDTOOL_MODE_LISTMINIDVODBPROCESSED,
  • branches/haf_branches/ipp.20100512/ippTools/src/addtoolConfig.c

    r28058 r28102  
    149149    psMetadataAddStr(addminidvodbrunArgs, PS_LIST_TAIL, "-set_minidvodb_name",        0, "define minidvodb_name", NULL);
    150150    psMetadataAddStr(addminidvodbrunArgs, PS_LIST_TAIL, "-set_minidvodb_group",        0, "define minidvodb_group (required)", NULL);
    151     psMetadataAddStr(addminidvodbrunArgs, PS_LIST_TAIL, "-set_minidvodb_path",        0, "define path for minidvodb (required)", NULL);
     151    psMetadataAddStr(addminidvodbrunArgs, PS_LIST_TAIL, "-set_minidvodb_path",        0, "define path for minidvodb", NULL);
    152152    psMetadataAddStr(addminidvodbrunArgs, PS_LIST_TAIL, "-set_mergedvodb_path",        0, "define path for the merged dvodb (required)", NULL);
    153153    psMetadataAddStr(addminidvodbrunArgs, PS_LIST_TAIL, "-set_state",        0, "define state", NULL);
     
    177177    //psMetadataAddBool(listminidvodbrunArgs, PS_LIST_TAIL, "-finished_addrun",        0, "limit to minidvodbs with completed addRuns (none in new state)", false);
    178178
    179 psMetadata *flipminidvodbrunArgs = psMetadataAlloc();
    180  psMetadataAddStr(flipminidvodbrunArgs, PS_LIST_TAIL, "-minidvodb_group",     0,    "for the supplied minidvodb_group (required): flip the current 'new' to 'active', the current 'active' to 'waiting'", NULL);
     179    psMetadata *flipminidvodbrunArgs = psMetadataAlloc();
     180    psMetadataAddStr(flipminidvodbrunArgs, PS_LIST_TAIL, "-minidvodb_group",     0,    "for the supplied minidvodb_group (required): flip the current 'new' to 'active', the current 'active' to 'waiting'", NULL);
     181   
     182    psMetadata *checkminidvodbrunaddrunArgs = psMetadataAlloc();
     183    psMetadataAddStr(checkminidvodbrunaddrunArgs, PS_LIST_TAIL, "-minidvodb_group",     0,    "for the supplied minidvodb_group (required): check if the addRun stage is complete (all in addRun.state = full) ", NULL);
     184    psMetadataAddStr(checkminidvodbrunaddrunArgs, PS_LIST_TAIL, "-minidvodb_name",     0,    "for the supplied minidvodb_name: check if the addRun stage is complete (all in addRun.state = full) ", NULL);
     185    psMetadataAddStr(checkminidvodbrunaddrunArgs, PS_LIST_TAIL, "-state",     0,    "limit by minidvodbRun state ", NULL);
     186    psMetadataAddU64(checkminidvodbrunaddrunArgs, PS_LIST_TAIL, "-limit",        0, "limit to N items", 0);
     187    psMetadataAddBool(checkminidvodbrunaddrunArgs, PS_LIST_TAIL, "-simple",        0, "simple output", false);
     188    psMetadataAddBool(checkminidvodbrunaddrunArgs, PS_LIST_TAIL, "-all_addrun_states",        0, "list all minidvodbRun.minidvodb_names, not just ones that have complete addRuns", false);
    181189
    182190    psMetadata *addminidvodbprocessedArgs = psMetadataAlloc();
     
    226234    PXOPT_ADD_MODE("-updateminidvodbrun",   "change minidvodb properties",          ADDTOOL_MODE_UPDATEMINIDVODBRUN,     updateminidvodbrunArgs);
    227235    PXOPT_ADD_MODE("-listminidvodbrun",     "list minidvodbs",                      ADDTOOL_MODE_LISTMINIDVODBRUN,       listminidvodbrunArgs);
    228 PXOPT_ADD_MODE("-flipminidvodbrun",     "flip minidvodbs",                      ADDTOOL_MODE_FLIPMINIDVODBRUN,       flipminidvodbrunArgs);
     236    PXOPT_ADD_MODE("-flipminidvodbrun",     "flip minidvodbs",                      ADDTOOL_MODE_FLIPMINIDVODBRUN,       flipminidvodbrunArgs);
     237    PXOPT_ADD_MODE("-checkminidvodbrunaddrun",     "check minidvodbs to see if addRuns are completed",                      ADDTOOL_MODE_CHECKMINIDVODBRUNADDRUN,       checkminidvodbrunaddrunArgs);
    229238    PXOPT_ADD_MODE("-addminidvodbprocessed","add a processed minidvodb",            ADDTOOL_MODE_ADDMINIDVODBPROCESSED,  addminidvodbprocessedArgs);
    230239    PXOPT_ADD_MODE("-listminidvodbprocessed","list processed minidvodbs",           ADDTOOL_MODE_LISTMINIDVODBPROCESSED, listminidvodbprocessedArgs);
Note: See TracChangeset for help on using the changeset viewer.