Changeset 28375 for trunk/ippTools/src/stacktool.c
- Timestamp:
- Jun 16, 2010, 5:30:27 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippTools/src/stacktool.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/czw_branch/20100519 (added) merged: 28044-28045,28164,28245,28304,28334,28338
- Property svn:mergeinfo changed
-
trunk/ippTools/src/stacktool.c
r28043 r28375 39 39 static bool addsumskyfileMode(pxConfig *config); 40 40 static bool sumskyfileMode(pxConfig *config); 41 static bool sassskyfileMode(pxConfig *config); 41 42 static bool revertsumskyfileMode(pxConfig *config); 43 static bool tosummaryMode(pxConfig *config); 44 static bool addsummaryMode(pxConfig *config); 42 45 static bool pendingcleanuprunMode(pxConfig *config); 43 46 static bool pendingcleanupskyfileMode(pxConfig *config); … … 75 78 MODECASE(STACKTOOL_MODE_ADDSUMSKYFILE, addsumskyfileMode); 76 79 MODECASE(STACKTOOL_MODE_SUMSKYFILE, sumskyfileMode); 80 MODECASE(STACKTOOL_MODE_SASSSKYFILE, sassskyfileMode); 77 81 MODECASE(STACKTOOL_MODE_REVERTSUMSKYFILE, revertsumskyfileMode); 82 MODECASE(STACKTOOL_MODE_TOSUMMARY, tosummaryMode); 83 MODECASE(STACKTOOL_MODE_ADDSUMMARY, addsummaryMode); 78 84 MODECASE(STACKTOOL_MODE_PENDINGCLEANUPRUN, pendingcleanuprunMode); 79 85 MODECASE(STACKTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupskyfileMode); … … 102 108 exit(exit_status); 103 109 } 110 //stackAssociationRow *association = pxStackAssociationDefine(data_group,tess_id,filter,skycell_id); 111 stackAssociationRow *pxStackAssociationDefine(pxConfig *config, psS64 stack_id) { 112 psString select = pxDataGet("stacktool_associationdefine_select.sql"); 113 if (!select) { 114 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 115 return false; 116 } 117 118 psString idString = NULL; 119 psStringAppend(&idString, "%" PRId64, stack_id); 120 // Copy string to get around the issue with psStringSubstitute not believing 121 // that select is a psString. 122 psString rep = psStringCopy(select); 123 psFree(select); 124 select = rep; 125 psStringSubstitute(&select, idString, "@STACK_ID@"); 126 psFree(idString); 127 128 if (!p_psDBRunQuery(config->dbh, select)) { 129 psError(PS_ERR_UNKNOWN,false, "database error"); 130 psFree(select); 131 return(NULL); 132 } 133 psFree(select); 134 psArray *output = p_psDBFetchResult(config->dbh); 135 if (!output) { 136 psErrorCode err = psErrorCodeLast(); 137 switch (err) { 138 case PS_ERR_DB_CLIENT: 139 psError(PXTOOLS_ERR_SYS, false, "database error"); 140 case PS_ERR_DB_SERVER: 141 psError(PXTOOLS_ERR_PROG, false, "database error"); 142 default: 143 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 144 } 145 return(NULL); 146 } 147 if (psArrayLength(output) != 1) { 148 psWarning("stacktool: incorrect number of rows found"); 149 psFree(output); 150 return(NULL); 151 } 152 psMetadata *outrow = psMetadataAlloc(); 153 for (long i = 0; i < output->n; i++) { 154 psMetadata *row = output->data[i]; 155 156 printf("%" PRId64 " %s %s %s %s\n",psMetadataLookupS64(NULL,row,"sass_id"), 157 psMetadataLookupStr(NULL,row,"data_group"), 158 psMetadataLookupStr(NULL,row,"tess_id"), 159 psMetadataLookupStr(NULL,row,"filter"), 160 psMetadataLookupStr(NULL,row,"projection_cell")); 161 162 if (psMetadataLookupS64(NULL,row,"sass_id") == PS_MAX_S64) { 163 psMetadataAddS64(outrow,PS_LIST_TAIL,"sass_id",PS_META_REPLACE,"",0); 164 } 165 else { 166 psMetadataAddS64(outrow,PS_LIST_TAIL,"sass_id",PS_META_REPLACE,"",psMetadataLookupS64(NULL,row,"sass_id")); 167 } 168 psMetadataAddStr(outrow,PS_LIST_TAIL,"data_group",PS_META_REPLACE,"",psMetadataLookupStr(NULL,row,"data_group")); 169 psMetadataAddStr(outrow,PS_LIST_TAIL,"tess_id",PS_META_REPLACE,"",psMetadataLookupStr(NULL,row,"tess_id")); 170 psMetadataAddStr(outrow,PS_LIST_TAIL,"filter",PS_META_REPLACE,"",psMetadataLookupStr(NULL,row,"filter")); 171 psMetadataAddStr(outrow,PS_LIST_TAIL,"projection_cell",PS_META_REPLACE,"", 172 psMetadataLookupStr(NULL,row,"projection_cell")); 173 } 174 printf("%" PRId64 " %s %s %s %s\n",psMetadataLookupS64(NULL,outrow,"sass_id"), 175 psMetadataLookupStr(NULL,outrow,"data_group"), 176 psMetadataLookupStr(NULL,outrow,"tess_id"), 177 psMetadataLookupStr(NULL,outrow,"filter"), 178 psMetadataLookupStr(NULL,outrow,"projection_cell")); 179 180 181 psFree(output); 182 stackAssociationRow *sassRow = stackAssociationObjectFromMetadata(outrow); 183 psFree(outrow); 184 return(sassRow); 185 } 186 187 188 189 104 190 105 191 … … 395 481 psFree(run); 396 482 483 //CZW Add an association entry here. 484 // Define the requested association, and insert it if it doesn't already exist 485 stackAssociationRow *association = pxStackAssociationDefine(config,stack_id); 486 psS64 sass_id; 487 if (!association->sass_id) { 488 psTrace("stacktool.association",2,"No required Association found. Adding."); 489 490 if (!stackAssociationInsertObject(config->dbh,association)) { 491 if (!psDBRollback(config->dbh)) { 492 psError(PS_ERR_UNKNOWN, false, "database error"); 493 } 494 psError(PS_ERR_UNKNOWN, false, "database error"); 495 psFree(output); 496 psFree(run); 497 psFree(insert); 498 psFree(list); 499 psFree(association); 500 if (!psDBRollback(config->dbh)) { 501 psError(PS_ERR_UNKNOWN, false, "database error"); 502 } 503 return(false); 504 } 505 sass_id = psDBLastInsertID(config->dbh); 506 association->sass_id = sass_id; 507 } 508 // Insert the map entry for this row. 509 stackAssociationMapRow *maprow = stackAssociationMapRowAlloc(sass_id,stack_id); 510 if (!stackAssociationMapInsertObject(config->dbh,maprow)) { 511 if (!psDBRollback(config->dbh)) { 512 psError(PS_ERR_UNKNOWN, false, "database error"); 513 } 514 psError(PS_ERR_UNKNOWN, false, "database error"); 515 psFree(output); 516 psFree(run); 517 psFree(insert); 518 psFree(list); 519 psFree(association); 520 if (!psDBRollback(config->dbh)) { 521 psError(PS_ERR_UNKNOWN, false, "database error"); 522 } 523 return(false); 524 } 525 526 397 527 // Create a suitable insertion query for this run 398 528 psString thisInsert = psStringCopy(insert); … … 552 682 run->stack_id = psDBLastInsertID(config->dbh); 553 683 684 //CZW Add an association entry here. 685 554 686 // insert the stackInputSkyfile rows 555 687 psListIterator *iter = psListIteratorAlloc(warp_ids->data.list, 0, false); … … 603 735 #endif 604 736 psMetadata *where = psMetadataAlloc(); 605 PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "=="); 606 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 607 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 737 PXOPT_COPY_S64(config->args, where, "-stack_id", "stackRun.stack_id", "=="); 738 PXOPT_COPY_STR(config->args, where, "-label", "stackRun.label", "=="); 739 PXOPT_COPY_STR(config->args, where, "-state", "stackRun.state", "=="); 740 PXOPT_COPY_STR(config->args, where, "-sass_id", "stackAssociationMap.sass_id", "=="); 608 741 if (!psListLength(where->list)) { 609 742 psFree(where); … … 612 745 } 613 746 747 //CZW join against stackAssociationMap 614 748 psString query = psStringCopy("UPDATE stackRun"); 615 749 … … 1038 1172 } 1039 1173 1040 1041 static bool revertsumskyfileMode(pxConfig *config) 1174 static bool sassskyfileMode(pxConfig *config) 1042 1175 { 1043 1176 PS_ASSERT_PTR_NON_NULL(config, false); 1044 1177 1045 1178 psMetadata *where = psMetadataAlloc(); 1046 PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.stack_id", "=="); 1047 pxAddLabelSearchArgs(config, where, "-label", "stackRun.label", "=="); 1048 PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "=="); 1049 1050 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 1051 psFree(where); 1052 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1053 return false; 1054 } 1055 1056 // Delete product 1057 psString delete = pxDataGet("stacktool_revertsumskyfile_delete.sql"); 1058 if (!delete) { 1179 PXOPT_COPY_S64(config->args, where, "-sass_id", "stackAssociation.sass_id", "=="); 1180 PXOPT_COPY_STR(config->args, where, "-tess_id", "stackAssociation.tess_id", "=="); 1181 PXOPT_COPY_STR(config->args, where, "-projection_cell", "stackAssociation.projection_cell", "=="); 1182 PXOPT_COPY_STR(config->args, where, "-filter", "stackAssociation.filter", "LIKE"); 1183 PXOPT_COPY_STR(config->args, where, "-data_group", "stackAssociation.data_group", "LIKE"); 1184 1185 // The following three selectors are incompatible with the sql so omit them 1186 // PXOPT_COPY_S64(config->args, where, "-warp_id", "warpRun.warp_id", "=="); 1187 // PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "=="); 1188 // PXOPT_COPY_STR(config->args, where, "-exp_name", "rawExp.exp_name", "=="); 1189 1190 PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); 1191 1192 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1193 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1194 1195 psString query = pxDataGet("stacktool_sassskyfile.sql"); 1196 if (!query) { 1059 1197 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1060 1198 return false; … … 1063 1201 if (psListLength(where->list)) { 1064 1202 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1065 psStringAppend(& delete, " AND%s", whereClause);1203 psStringAppend(&query, " WHERE %s", whereClause); 1066 1204 psFree(whereClause); 1067 } 1068 1069 if (!p_psDBRunQuery(config->dbh, delete)) { 1070 psError(PS_ERR_UNKNOWN, false, "database error"); 1071 psFree(delete); 1072 psFree(where); 1073 return false; 1074 } 1075 psFree(delete); 1076 1077 int numRows = psDBAffectedRows(config->dbh); // Number of row affected 1078 psLogMsg("stacktool", PS_LOG_INFO, "Deleted %d rows", numRows); 1079 1080 psFree(where); 1081 1082 return true; 1083 } 1084 1085 1086 static bool setstackRunState(pxConfig *config, psS64 stack_id, const char *state) 1087 { 1088 PS_ASSERT_PTR_NON_NULL(state, false); 1089 1090 // check that state is a valid string value 1091 if (!pxIsValidState(state)) { 1092 psError(PS_ERR_UNKNOWN, false, "invalid stackRun state: %s", state); 1093 return false; 1094 } 1095 1096 char *query = "UPDATE stackRun SET state = '%s' WHERE stack_id = %"PRId64; 1097 if (!p_psDBRunQueryF(config->dbh, query, state, stack_id)) { 1098 psError(PS_ERR_UNKNOWN, false, 1099 "failed to change state for stack_id %"PRId64, stack_id); 1100 return false; 1101 } 1102 1103 return true; 1104 } 1105 1106 #ifdef notdef 1107 static bool setstackRunStateByLabel(pxConfig *config, const char *label, const char *state) 1108 { 1109 PS_ASSERT_PTR_NON_NULL(state, false); 1110 1111 // check that state is a valid string value 1112 if (!pxIsValidState(state)) { 1113 psError(PS_ERR_UNKNOWN, false, "invalid stackRun state: %s", state); 1114 return false; 1115 } 1116 1117 char *query = "UPDATE stackRun SET state = '%s' WHERE label = '%s'"; 1118 if (!p_psDBRunQueryF(config->dbh, query, state, label)) { 1119 psError(PS_ERR_UNKNOWN, false, 1120 "failed to change state for label %s", label); 1121 return false; 1122 } 1123 1124 return true; 1125 } 1126 #endif 1127 1128 static bool pendingcleanuprunMode(pxConfig *config) 1129 { 1130 PS_ASSERT_PTR_NON_NULL(config, NULL); 1131 1132 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1133 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1134 1135 psMetadata *where = psMetadataAlloc(); 1136 pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "=="); 1137 1138 psString query = pxDataGet("stacktool_pendingcleanuprun.sql"); 1139 if (!query) { 1140 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1141 return false; 1142 } 1143 1144 if (where && psListLength(where->list)) { 1145 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1146 psStringAppend(&query, " AND %s", whereClause); 1147 psFree(whereClause); 1148 } 1205 } else if (!all) { 1206 psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required"); 1207 return false; 1208 } 1209 1149 1210 psFree(where); 1150 1211 … … 1165 1226 psArray *output = p_psDBFetchResult(config->dbh); 1166 1227 if (!output) { 1167 psError(PS_ERR_UNKNOWN, false, "database error"); 1228 psErrorCode err = psErrorCodeLast(); 1229 switch (err) { 1230 case PS_ERR_DB_CLIENT: 1231 psError(PXTOOLS_ERR_SYS, false, "database error"); 1232 case PS_ERR_DB_SERVER: 1233 psError(PXTOOLS_ERR_PROG, false, "database error"); 1234 default: 1235 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1236 } 1237 1168 1238 return false; 1169 1239 } … … 1174 1244 } 1175 1245 1246 if (psArrayLength(output)) { 1247 if (!ippdbPrintMetadatas(stdout, output, "stackSumSkyfile", !simple)) { 1248 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1249 psFree(output); 1250 return false; 1251 } 1252 } 1253 1254 psFree(output); 1255 1256 return true; 1257 } 1258 1259 1260 static bool revertsumskyfileMode(pxConfig *config) 1261 { 1262 PS_ASSERT_PTR_NON_NULL(config, false); 1263 1264 psMetadata *where = psMetadataAlloc(); 1265 PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.stack_id", "=="); 1266 pxAddLabelSearchArgs(config, where, "-label", "stackRun.label", "=="); 1267 PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "=="); 1268 1269 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 1270 psFree(where); 1271 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1272 return false; 1273 } 1274 1275 // Delete product 1276 psString delete = pxDataGet("stacktool_revertsumskyfile_delete.sql"); 1277 if (!delete) { 1278 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1279 return false; 1280 } 1281 1282 if (psListLength(where->list)) { 1283 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1284 psStringAppend(&delete, " AND %s", whereClause); 1285 psFree(whereClause); 1286 } 1287 1288 if (!p_psDBRunQuery(config->dbh, delete)) { 1289 psError(PS_ERR_UNKNOWN, false, "database error"); 1290 psFree(delete); 1291 psFree(where); 1292 return false; 1293 } 1294 psFree(delete); 1295 1296 int numRows = psDBAffectedRows(config->dbh); // Number of row affected 1297 psLogMsg("stacktool", PS_LOG_INFO, "Deleted %d rows", numRows); 1298 1299 psFree(where); 1300 1301 return true; 1302 } 1303 1304 1305 static bool setstackRunState(pxConfig *config, psS64 stack_id, const char *state) 1306 { 1307 PS_ASSERT_PTR_NON_NULL(state, false); 1308 1309 // check that state is a valid string value 1310 if (!pxIsValidState(state)) { 1311 psError(PS_ERR_UNKNOWN, false, "invalid stackRun state: %s", state); 1312 return false; 1313 } 1314 1315 char *query = "UPDATE stackRun SET state = '%s' WHERE stack_id = %"PRId64; 1316 if (!p_psDBRunQueryF(config->dbh, query, state, stack_id)) { 1317 psError(PS_ERR_UNKNOWN, false, 1318 "failed to change state for stack_id %"PRId64, stack_id); 1319 return false; 1320 } 1321 1322 return true; 1323 } 1324 1325 #ifdef notdef 1326 static bool setstackRunStateByLabel(pxConfig *config, const char *label, const char *state) 1327 { 1328 PS_ASSERT_PTR_NON_NULL(state, false); 1329 1330 // check that state is a valid string value 1331 if (!pxIsValidState(state)) { 1332 psError(PS_ERR_UNKNOWN, false, "invalid stackRun state: %s", state); 1333 return false; 1334 } 1335 1336 char *query = "UPDATE stackRun SET state = '%s' WHERE label = '%s'"; 1337 if (!p_psDBRunQueryF(config->dbh, query, state, label)) { 1338 psError(PS_ERR_UNKNOWN, false, 1339 "failed to change state for label %s", label); 1340 return false; 1341 } 1342 1343 return true; 1344 } 1345 #endif 1346 static bool tosummaryMode(pxConfig *config) { 1347 PS_ASSERT_PTR_NON_NULL(config, NULL); 1348 1349 psMetadata *where = psMetadataAlloc(); 1350 PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.warp_id", "=="); 1351 PXOPT_COPY_S64(config->args, where, "-sass_id", "stackAssociationMap.sass_id", "=="); 1352 PXOPT_COPY_STR(config->args, where, "-tess_id", "stackSumSkyfile.tess_id", "=="); 1353 PXOPT_COPY_STR(config->args, where, "-state", "stackRun.state", "=="); 1354 PXOPT_COPY_STR(config->args, where, "-filter", "stackRun.filter", "LIKE"); 1355 pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "LIKE"); 1356 pxAddLabelSearchArgs (config, where, "-data_group", "stackRun.data_group", "LIKE"); 1357 1358 PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); 1359 1360 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1361 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1362 1363 // find all rawImfiles matching the default query 1364 psString query = pxDataGet("stacktool_tosummary.sql"); 1365 if (!query) { 1366 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1367 return false; 1368 } 1369 1370 // generate where strings for arguments that require extra processing 1371 // beyond PXOPT_COPY* 1372 if (psListLength(where->list)) { 1373 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1374 psStringAppend(&query, " AND %s", whereClause); 1375 psFree(whereClause); 1376 } else if (!all) { 1377 psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required"); 1378 return false; 1379 } 1380 1381 psFree(where); 1382 1383 // treat limit == 0 as "no limit" 1384 if (limit) { 1385 psString limitString = psDBGenerateLimitSQL(limit); 1386 psStringAppend(&query, " %s", limitString); 1387 psFree(limitString); 1388 } 1389 1390 if (!p_psDBRunQuery(config->dbh, query)) { 1391 psError(PS_ERR_UNKNOWN, false, "database error"); 1392 psFree(query); 1393 return false; 1394 } 1395 psFree(query); 1396 1397 psArray *output = p_psDBFetchResult(config->dbh); 1398 if (!output) { 1399 psErrorCode err = psErrorCodeLast(); 1400 switch (err) { 1401 case PS_ERR_DB_CLIENT: 1402 psError(PXTOOLS_ERR_SYS, false, "database error"); 1403 case PS_ERR_DB_SERVER: 1404 psError(PXTOOLS_ERR_PROG, false, "database error"); 1405 default: 1406 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1407 } 1408 1409 return false; 1410 } 1411 if (!psArrayLength(output)) { 1412 psTrace("stacktool", PS_LOG_INFO, "no rows found"); 1413 psFree(output); 1414 return true; 1415 } 1416 1417 if (psArrayLength(output)) { 1176 1418 // negative simple so the default is true 1177 if (!ippdbPrintMetadatas(stdout, output, "stackPendingCleanupRun", !simple)) { 1178 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1179 psFree(output); 1180 return false; 1181 } 1182 1183 psFree(output); 1184 1185 return true; 1186 } 1187 1188 static bool pendingcleanupskyfileMode(pxConfig *config) 1419 if (!ippdbPrintMetadatas(stdout, output, "stackRun", !simple)) { 1420 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1421 psFree(output); 1422 return false; 1423 } 1424 } 1425 1426 psFree(output); 1427 return(true); 1428 } 1429 static bool addsummaryMode(pxConfig *config) { 1430 PS_ASSERT_PTR_NON_NULL(config, NULL); 1431 1432 PXOPT_LOOKUP_S64(sass_id, config->args, "-sass_id", true, false); 1433 PXOPT_LOOKUP_STR(projection_cell, config->args, "-projection_cell", true, false); 1434 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", true, false); 1435 1436 psString query = pxDataGet("stacktool_addsummary.sql"); 1437 if (!query) { 1438 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1439 return(false); 1440 } 1441 if (!p_psDBRunQueryF(config->dbh, query, sass_id, projection_cell, path_base)) { 1442 psError(PS_ERR_UNKNOWN, false, "database error"); 1443 psFree(query); 1444 return(false); 1445 } 1446 psS64 numUpdated = psDBAffectedRows(config->dbh); 1447 1448 if (numUpdated != 1) { 1449 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row"); 1450 psFree(query); 1451 return false; 1452 } 1453 1454 psFree(query); 1455 1456 // Print anything here? 1457 1458 return(true); 1459 } 1460 1461 static bool pendingcleanuprunMode(pxConfig *config) 1189 1462 { 1190 1463 PS_ASSERT_PTR_NON_NULL(config, NULL); 1191 1464 1192 PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", false, false);1193 1465 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1194 1466 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1195 1467 1196 1468 psMetadata *where = psMetadataAlloc(); 1197 if (stack_id) {1198 PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "==");1199 }1469 PXOPT_COPY_S64(config->args, where, "-stack_id", "stackRun.stack_id", "=="); 1470 PXOPT_COPY_S64(config->args, where, "-sass_id", "stackAssociationMap.sass_id", "=="); 1471 1200 1472 pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "=="); 1201 1473 1202 psString query = pxDataGet("stacktool_pendingcleanup skyfile.sql");1474 psString query = pxDataGet("stacktool_pendingcleanuprun.sql"); 1203 1475 if (!query) { 1204 1476 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); … … 1239 1511 1240 1512 // negative simple so the default is true 1241 if (!ippdbPrintMetadatas(stdout, output, "stackPendingCleanup Skyfile", !simple)) {1513 if (!ippdbPrintMetadatas(stdout, output, "stackPendingCleanupRun", !simple)) { 1242 1514 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1243 1515 psFree(output); … … 1250 1522 } 1251 1523 1252 1253 static bool donecleanupMode(pxConfig *config) 1524 static bool pendingcleanupskyfileMode(pxConfig *config) 1254 1525 { 1255 1526 PS_ASSERT_PTR_NON_NULL(config, NULL); 1256 1527 1528 PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", false, false); 1257 1529 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1258 1530 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1259 1531 1260 1532 psMetadata *where = psMetadataAlloc(); 1261 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1262 1263 psString query = pxDataGet("stacktool_donecleanup.sql"); 1533 if (stack_id) { 1534 PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "=="); 1535 } 1536 pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "=="); 1537 1538 psString query = pxDataGet("stacktool_pendingcleanupskyfile.sql"); 1264 1539 if (!query) { 1265 1540 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); … … 1300 1575 1301 1576 // negative simple so the default is true 1577 if (!ippdbPrintMetadatas(stdout, output, "stackPendingCleanupSkyfile", !simple)) { 1578 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1579 psFree(output); 1580 return false; 1581 } 1582 1583 psFree(output); 1584 1585 return true; 1586 } 1587 1588 1589 static bool donecleanupMode(pxConfig *config) 1590 { 1591 PS_ASSERT_PTR_NON_NULL(config, NULL); 1592 1593 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1594 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1595 1596 psMetadata *where = psMetadataAlloc(); 1597 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1598 PXOPT_COPY_STR(config->args, where, "-sass_id", "sass_id", "=="); 1599 1600 psString query = pxDataGet("stacktool_donecleanup.sql"); 1601 if (!query) { 1602 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1603 return false; 1604 } 1605 1606 if (where && psListLength(where->list)) { 1607 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1608 psStringAppend(&query, " AND %s", whereClause); 1609 psFree(whereClause); 1610 } 1611 psFree(where); 1612 1613 // treat limit == 0 as "no limit" 1614 if (limit) { 1615 psString limitString = psDBGenerateLimitSQL(limit); 1616 psStringAppend(&query, " %s", limitString); 1617 psFree(limitString); 1618 } 1619 1620 if (!p_psDBRunQuery(config->dbh, query)) { 1621 psError(PS_ERR_UNKNOWN, false, "database error"); 1622 psFree(query); 1623 return false; 1624 } 1625 psFree(query); 1626 1627 psArray *output = p_psDBFetchResult(config->dbh); 1628 if (!output) { 1629 psError(PS_ERR_UNKNOWN, false, "database error"); 1630 return false; 1631 } 1632 if (!psArrayLength(output)) { 1633 psTrace("stacktool", PS_LOG_INFO, "no rows found"); 1634 psFree(output); 1635 return true; 1636 } 1637 1638 // negative simple so the default is true 1302 1639 if (!ippdbPrintMetadatas(stdout, output, "stackDoneCleanup", !simple)) { 1303 1640 psError(PS_ERR_UNKNOWN, false, "failed to print array"); … … 1329 1666 } 1330 1667 1668 //CZW I have not added sass information to the export/import run modes yet. 1331 1669 bool exportrunMode(pxConfig *config) 1332 1670 {
Note:
See TracChangeset
for help on using the changeset viewer.
