Changeset 25419
- Timestamp:
- Sep 16, 2009, 9:47:16 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 1 deleted
- 14 edited
-
ippTasks/Makefile.am (modified) (1 diff)
-
ippTasks/destreak.pro (added)
-
ippTasks/magic.pro (modified) (6 diffs)
-
ippTools/share/Makefile.am (modified) (2 diffs)
-
ippTools/share/magicdstool_completedrevert.sql (added)
-
ippTools/share/magicdstool_todestreak.sql (deleted)
-
ippTools/share/magicdstool_todestreak_camera.sql (added)
-
ippTools/share/magicdstool_todestreak_chip.sql (added)
-
ippTools/share/magicdstool_todestreak_diff.sql (added)
-
ippTools/share/magicdstool_todestreak_raw.sql (added)
-
ippTools/share/magicdstool_todestreak_warp.sql (added)
-
ippTools/share/magicdstool_torevert_camera.sql (modified) (1 diff)
-
ippTools/share/magicdstool_torevert_chip.sql (modified) (1 diff)
-
ippTools/share/magicdstool_torevert_diff.sql (modified) (1 diff)
-
ippTools/share/magicdstool_torevert_raw.sql (modified) (1 diff)
-
ippTools/share/magicdstool_torevert_warp.sql (modified) (1 diff)
-
ippTools/share/magictool_censor_chip.sql (modified) (1 diff)
-
ippTools/share/magictool_censor_diff.sql (modified) (1 diff)
-
ippTools/share/magictool_censor_raw.sql (modified) (1 diff)
-
ippTools/src/magicdstool.c (modified) (13 diffs)
-
ippTools/src/magicdstool.h (modified) (1 diff)
-
ippTools/src/magicdstoolConfig.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTasks/Makefile.am
r25324 r25419 17 17 warp.pro \ 18 18 magic.pro \ 19 destreak.pro \ 19 20 diff.pro \ 20 21 stack.pro \ -
trunk/ippTasks/magic.pro
r25021 r25419 10 10 book init magicToTree 11 11 book init magicToProcess 12 book init magicToDS13 book init magicDSToRevert14 12 15 13 ### Database lists 16 14 $magicToTree_DB = 0 17 15 $magicToProcess_DB = 0 18 $magicToDS_DB = 019 $magicDSToRevert_DB = 020 21 #list of stages22 $STAGE:n = 023 list STAGE -add "raw"24 list STAGE -add "chip"25 list STAGE -add "camera"26 list STAGE -add "warp"27 list STAGE -add "diff"28 $magicDSRevertStage = 029 16 30 17 ### Check status of tasks … … 32 19 book listbook magicToTree 33 20 book listbook magicToProcess 34 book listbook magicToDS35 book listbook magicDSToRevert36 21 end 37 22 … … 40 25 book init magicToTree 41 26 book init magicToProcess 42 book init magicToDS43 book init magicDSToRevert44 27 end 45 28 … … 58 41 active true 59 42 end 60 task magic.destreak.load 61 active true 62 end 63 task magic.destreak.run 64 active true 65 end 66 end 67 68 macro magic.ds.revert.on 69 task magic.ds.revert.load 70 active true 71 end 72 task magic.ds.revert.run 73 active true 74 end 75 end 43 end 44 76 45 ### Turn tasks off 77 46 macro magic.off … … 88 57 active false 89 58 end 90 task magic.destreak.load 91 active false 92 end 93 task magic.destreak.run 94 active false 95 end 96 end 97 98 macro magic.ds.revert.off 99 task magic.ds.revert.load 100 active false 101 end 102 task magic.ds.revert.run 103 active false 104 end 105 end 106 macro magic.ds.off 107 task magic.destreak.load 108 active false 109 end 110 task magic.destreak.run 111 active false 112 end 113 end 114 macro magic.ds.on 115 task magic.destreak.load 116 active true 117 end 118 task magic.destreak.run 119 active true 120 end 121 end 122 123 macro magic.ds.status 124 echo magicToDS 125 book listbook magicToDS 126 echo "" 127 echo magicDSToRevert 128 book listbook magicDSToRevert 129 end 130 131 59 end 132 60 133 61 task magic.tree.load … … 400 328 end 401 329 end 402 403 task magic.destreak.load404 host local405 406 periods -poll $LOADPOLL407 # this query can take a long time408 periods -exec 10409 periods -timeout 120410 npending 1411 412 stdout NULL413 stderr $LOGDIR/magic.destreak.log414 415 task.exec416 $run = magicdstool -todestreak -limit 120417 if ($DB:n == 0)418 option DEFAULT419 else420 # save the DB name for the exit tasks421 option $DB:$magicToDS_DB422 $run = $run -dbname $DB:$magicToDS_DB423 $magicToDS_DB ++424 if ($magicToDS_DB >= $DB:n) set magicToDS_DB = 0425 end426 add_poll_args run427 add_poll_labels run428 command $run429 end430 431 # success432 task.exit 0433 # convert 'stdout' to book format434 ipptool2book stdout magicToDS -key magic_ds_id:component -uniq -setword dbname $options:0 -setword pantaskState INIT435 if ($VERBOSE > 2)436 book listbook magicToDS437 end438 439 # delete existing entries in the appropriate pantaskStates440 process_cleanup magicToDS441 end442 443 # locked list444 task.exit default445 showcommand failure446 end447 448 task.exit crash449 showcommand crash450 end451 452 # operation times out?453 task.exit timeout454 showcommand timeout455 end456 end457 458 task magic.destreak.run459 periods -poll $RUNPOLL460 periods -exec $RUNEXEC461 periods -timeout 60462 463 task.exec464 book npages magicToDS -var N465 if ($N == 0) break466 if ($NETWORK == 0) break467 468 # look for new images (pantaskState == INIT)469 book getpage magicToDS 0 -var pageName -key pantaskState INIT470 if ("$pageName" == "NULL") break471 472 book setword magicToDS $pageName pantaskState RUN473 book getword magicToDS $pageName exp_id -var EXP_ID474 book getword magicToDS $pageName magic_ds_id -var MAGIC_DS_ID475 book getword magicToDS $pageName camera -var CAMERA476 book getword magicToDS $pageName streaks_uri -var STREAKS477 book getword magicToDS $pageName inv_streaks_uri -var INV_STREAKS478 book getword magicToDS $pageName stage -var STAGE479 book getword magicToDS $pageName stage_id -var STAGE_ID480 book getword magicToDS $pageName component -var COMPONENT481 book getword magicToDS $pageName uri -var URI482 book getword magicToDS $pageName path_base -var PATH_BASE483 book getword magicToDS $pageName cam_path_base -var CAM_PATH_BASE484 book getword magicToDS $pageName outroot -var OUTROOT485 book getword magicToDS $pageName recoveryroot -var RECROOT486 book getword magicToDS $pageName re_place -var REPLACE487 book getword magicToDS $pageName dbname -var DBNAME488 489 sprintf logfile "%s/%s.mds.%s.%s.%s.log" $OUTROOT $EXP_ID $MAGIC_DS_ID $STAGE_ID $COMPONENT490 491 substr $COMPONENT 0 3 COMP_HEAD492 if ("$COMP_HEAD" == "sky")493 set.host.for.skycell $COMPONENT494 else495 # assume component is a class_id, if not we will default to anyhost496 set.host.for.camera $CAMERA $COMPONENT497 end498 499 # TODO: do not add recoveryroot or replace if they are null or zero500 501 $run = magic_destreak.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --streaks $STREAKS --inv_streaks $INV_STREAKS --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --uri $URI --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --outroot $OUTROOT --logfile $logfile --recoveryroot $RECROOT --replace $REPLACE502 503 add_standard_args run504 505 # save the pageName for future reference below506 options $pageName507 508 # create the command line509 if ($VERBOSE > 1)510 echo command $run511 end512 command $run513 end514 515 # default exit status516 task.exit 0517 process_exit magicToDS $options:0 $JOB_STATUS518 end519 520 # locked list521 task.exit default522 showcommand failure523 process_exit magicToDS $options:0 $JOB_STATUS524 end525 526 task.exit crash527 showcommand crash528 book setword magicToDS $options:0 pantaskState CRASH529 end530 531 # operation timed out?532 task.exit timeout533 showcommand timeout534 book setword magicToDS $options:0 pantaskState TIMEOUT535 end536 end537 538 task magic.ds.revert.load539 host local540 541 periods -poll $LOADPOLL542 periods -exec $LOADEXEC543 periods -timeout 20544 npending 1545 active false546 547 stdout NULL548 stderr $LOGDIR/magic.ds.revert.log549 550 task.exec551 $run = magicdstool -torevert -stage $STAGE:$magicDSRevertStage552 $magicDSRevertStage ++553 if ($magicDSRevertStage >= $STAGE:n) set magicDSRevertStage = 0554 555 if ($DB:n == 0)556 option DEFAULT557 else558 559 # save the DB name for the exit tasks560 option $DB:$magicDSToRevert_DB561 $run = $run -dbname $DB:$magicDSToRevert_DB562 563 # only bump database number after we have gone through all of the stages564 if ($magicDSRevertStage == 0)565 $magicDSToRevert_DB ++566 end567 if ($magicDSToRevert_DB >= $DB:n) set magicDSToRevert_DB = 0568 end569 add_poll_args run570 add_poll_labels run571 command $run572 end573 574 # success575 task.exit 0576 # convert 'stdout' to book format577 ipptool2book stdout magicDSToRevert -key magic_ds_id:component -uniq -setword dbname $options:0 -setword pantaskState INIT578 if ($VERBOSE > 2)579 book listbook magicDSToRevert580 end581 582 # delete existing entries in the appropriate pantaskStates583 process_cleanup magicDSToRevert584 end585 586 # locked list587 task.exit default588 showcommand failure589 end590 591 task.exit crash592 showcommand crash593 end594 595 # operation times out?596 task.exit timeout597 showcommand timeout598 end599 end600 601 task magic.ds.revert.run602 periods -poll $RUNPOLL603 periods -exec $RUNEXEC604 periods -timeout 60605 active false606 607 task.exec608 book npages magicDSToRevert -var N609 if ($N == 0) break610 if ($NETWORK == 0) break611 612 # look for new images (pantaskState == INIT)613 book getpage magicDSToRevert 0 -var pageName -key pantaskState INIT614 if ("$pageName" == "NULL") break615 616 book setword magicDSToRevert $pageName pantaskState RUN617 book getword magicDSToRevert $pageName exp_id -var EXP_ID618 book getword magicDSToRevert $pageName magic_ds_id -var MAGIC_DS_ID619 book getword magicDSToRevert $pageName camera -var CAMERA620 book getword magicDSToRevert $pageName stage -var STAGE621 book getword magicDSToRevert $pageName stage_id -var STAGE_ID622 book getword magicDSToRevert $pageName component -var COMPONENT623 book getword magicDSToRevert $pageName path_base -var PATH_BASE624 book getword magicDSToRevert $pageName cam_path_base -var CAM_PATH_BASE625 book getword magicDSToRevert $pageName outroot -var OUTROOT626 book getword magciDSToRevert $pageName bytes -var BYTES627 book getword magciDSToRevert $pageName md5sum -var md5sum628 # book getword magicDSToRevert $pageName recoveryroot -var RECROOT629 book getword magicDSToRevert $pageName re_place -var REPLACE630 book getword magicDSToRevert $pageName dbname -var DBNAME631 632 sprintf logfile "%s/%s.mds.revert.%s.%s.%s.log" $OUTROOT $EXP_ID $MAGIC_DS_ID $STAGE_ID $COMPONENT633 634 substr $COMPONENT 0 3 COMP_HEAD635 if ("$COMP_HEAD" == "sky")636 set.host.for.skycell $COMPONENT637 else638 # assume component is a class_id, if not we will default to anyhost639 set.host.for.camera $CAMERA $COMPONENT640 end641 642 $run = magic_destreak_revert.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --outroot $OUTROOT --logfile $logfile --replace $REPLACE643 644 add_standard_args run645 646 # save the pageName for future reference below647 options $pageName648 649 # create the command line650 if ($VERBOSE > 1)651 echo command $run652 end653 command $run654 end655 656 # default exit status657 task.exit 0658 process_exit magicDSToRevert $options:0 $JOB_STATUS659 end660 661 # locked list662 task.exit default663 showcommand failure664 process_exit magicDSToRevert $options:0 $JOB_STATUS665 end666 667 task.exit crash668 showcommand crash669 book setword magicDSToRevert $options:0 pantaskState CRASH670 end671 672 # operation timed out?673 task.exit timeout674 showcommand timeout675 book setword magicDSToRevert $options:0 pantaskState TIMEOUT676 end677 end678 -
trunk/ippTools/share/Makefile.am
r25324 r25419 165 165 magictool_revertnode.sql \ 166 166 magicdstool_completed_runs.sql \ 167 magicdstool_completedrevert.sql \ 167 168 magicdstool_definebyquery_raw.sql \ 168 169 magicdstool_definebyquery_chip.sql \ … … 172 173 magicdstool_getrunids.sql \ 173 174 magicdstool_getskycells.sql \ 174 magicdstool_todestreak.sql \ 175 magicdstool_todestreak_camera.sql \ 176 magicdstool_todestreak_chip.sql \ 177 magicdstool_todestreak_diff.sql \ 178 magicdstool_todestreak_raw.sql \ 179 magicdstool_todestreak_warp.sql \ 175 180 magicdstool_toremove.sql \ 176 181 magicdstool_torestore.sql \ -
trunk/ippTools/share/magicdstool_torevert_camera.sql
r24883 r25419 19 19 JOIN rawExp using(exp_id) 20 20 WHERE magicDSRun.stage = 'camera' 21 AND (magicDSRun.state = 'new' OR magicDSRun.state = 'censored') 22 AND magicDSFile.fault > 0 21 AND ((magicDSRun.state = 'new' AND magicDSFile.fault > 0) 22 OR magicDSRun.state = 'goto_censored' 23 OR magicDSRun.state = 'goto_restored') -
trunk/ippTools/share/magicdstool_torevert_chip.sql
r24883 r25419 18 18 JOIN rawExp using(exp_id) 19 19 WHERE magicDSRun.stage = 'chip' 20 AND (magicDSRun.state = 'new' OR magicDSRun.state = 'censored') 21 AND magicDSFile.fault > 0 20 AND ((magicDSRun.state = 'new' AND magicDSFile.fault > 0) 21 OR magicDSRun.state = 'goto_censored' 22 OR magicDSRun.state = 'goto_restored') -
trunk/ippTools/share/magicdstool_torevert_diff.sql
r24883 r25419 18 18 JOIN rawExp USING(exp_id) 19 19 WHERE magicDSRun.stage = 'diff' 20 AND (magicDSRun.state = 'new' OR magicDSRun.state = 'censored') 21 AND magicDSFile.fault > 0 20 AND ((magicDSRun.state = 'new' AND magicDSFile.fault > 0) 21 OR magicDSRun.state = 'goto_censored' 22 OR magicDSRun.state = 'goto_restored') -
trunk/ippTools/share/magicdstool_torevert_raw.sql
r24883 r25419 18 18 AND rawImfile.tmp_class_id = summitImfile.class_id) 19 19 WHERE magicDSRun.stage = 'raw' 20 AND (magicDSRun.state = 'new' OR magicDSRun.state = 'censored') 21 AND magicDSFile.fault > 0 20 AND ((magicDSRun.state = 'new' AND magicDSFile.fault > 0) 21 OR magicDSRun.state = 'goto_censored' 22 OR magicDSRun.state = 'goto_restored') -
trunk/ippTools/share/magicdstool_torevert_warp.sql
r24883 r25419 21 21 JOIN rawExp USING(exp_id) 22 22 WHERE magicDSRun.stage = 'warp' 23 AND (magicDSRun.state = 'new' OR magicDSRun.state = 'censored') 24 AND magicDSFile.fault > 0 23 AND ((magicDSRun.state = 'new' AND magicDSFile.fault > 0) 24 OR magicDSRun.state = 'goto_censored' 25 OR magicDSRun.state = 'goto_restored') -
trunk/ippTools/share/magictool_censor_chip.sql
r24883 r25419 1 1 UPDATE chipRun 2 2 JOIN chipProcessedImfile USING(chip_id, exp_id) 3 JOIN magicDSRun ON chipRun.magicked = magicDSRun.magic_ds_id3 JOIN magicDSRun ON stage_id = chip_id AND stage = 'chip' AND re_place 4 4 JOIN magicDSFile USING(magic_ds_id) 5 JOIN magicRun USING(magic_id, exp_id)5 JOIN magicRun using(magic_id) 6 6 SET chipProcessedImfile.magicked = 0, 7 7 chipRun.magicked = 0, -
trunk/ippTools/share/magictool_censor_diff.sql
r24883 r25419 1 UPDATE magicRun 2 JOIN magicDSRun USING(magic_id) 1 UPDATE diffRun 2 JOIN diffSkyfile USING(diff_id) 3 JOIN magicRun USING(diff_id) 4 JOIN magicDSRun ON stage = 'diff' AND stage_id = diff_id AND re_place 3 5 JOIN magicDSFile USING(magic_ds_id) 4 JOIN diffRun ON magic_ds_id = magicked5 JOIN diffSkyfile ON diffRun.diff_id = diffSkyfile.diff_id6 6 SET diffRun.magicked = 0, 7 7 diffSkyfile.magicked = 0, -
trunk/ippTools/share/magictool_censor_raw.sql
r24885 r25419 2 2 JOIN magicDSRun USING(magic_id) 3 3 JOIN magicDSFile USING(magic_ds_id) 4 JOIN raw Exp ON rawExp.magicked = magic_ds_id5 JOIN rawImfile ON rawExp.exp_id = rawImfile.exp_id4 JOIN rawImfile ON rawImfile.magicked = magic_ds_id 5 -- JOIN rawExp ON rawExp.magicked = magic_ds_id 6 6 SET rawImfile.magicked = 0, 7 rawExp.magicked = 0,8 magicDSRun.state = 'censored',7 -- rawExp.magicked = 0, 8 -- magicDSRun.state = 'censored', 9 9 magicDSFile.fault = 42 10 10 -
trunk/ippTools/src/magicdstool.c
r25015 r25419 42 42 static bool torestoreMode(pxConfig *config); 43 43 static bool torevertMode(pxConfig *config); 44 static bool completedrevertMode(pxConfig *config); 44 45 45 46 static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, const char *state); … … 75 76 MODECASE(MAGICDSTOOL_MODE_TORESTORE, torestoreMode); 76 77 MODECASE(MAGICDSTOOL_MODE_TOREVERT, torevertMode); 78 MODECASE(MAGICDSTOOL_MODE_COMPLETEDREVERT, completedrevertMode); 77 79 default: 78 80 psAbort("invalid option (this should not happen)"); … … 396 398 PS_ASSERT_PTR_NON_NULL(config, false); 397 399 400 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 401 398 402 psMetadata *where = psMetadataAlloc(); 399 403 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "=="); 400 404 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 401 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 402 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 405 pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "=="); 403 406 404 407 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 405 408 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 406 409 407 // look for "inputs" that need to processed 408 psString query = pxDataGet("magicdstool_todestreak.sql"); 410 psString sql_file = NULL; 411 psStringAppend(&sql_file, "magicdstool_todestreak_%s.sql", stage); 412 413 psString query = pxDataGet(sql_file); 409 414 if (!query) { 410 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 411 return false; 412 } 415 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", sql_file); 416 psFree(sql_file); 417 return false; 418 } 419 psFree(sql_file); 413 420 414 421 if (psListLength(where->list)) { 415 422 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 416 psStringAppend(&query, " WHERE%s", whereClause);423 psStringAppend(&query, " AND %s", whereClause); 417 424 psFree(whereClause); 418 425 } … … 817 824 return true; 818 825 } 819 820 static bool getskycellsMode(pxConfig *config) 821 { 822 // required 823 PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false); 826 static bool completedrevertMode(pxConfig *config) 827 { 828 PS_ASSERT_PTR_NON_NULL(config, false); 824 829 825 830 psMetadata *where = psMetadataAlloc(); 826 PXOPT_COPY_STR(config->args, where, "-class_id", "warpSkyCellMap.class_id", "=="); 827 PXOPT_COPY_STR(config->args, where, "-skycell_id", "warpSkyCellMap.skycell_id", "=="); 828 829 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 830 831 psString query = pxDataGet("magicdstool_getskycells.sql"); 832 if (!query) { 833 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 834 return false; 835 } 836 831 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magicDSRun.magic_ds_id", "=="); 832 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 833 834 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 835 836 psString query = pxDataGet("magicdstool_completedrevert.sql"); 837 // treat limit == 0 as "no limit" 838 if (limit) { 839 psString limitString = psDBGenerateLimitSQL(limit); 840 psStringAppend(&query, " %s", limitString); 841 psFree(limitString); 842 } 843 844 psString whereString = NULL; 837 845 if (psListLength(where->list)) { 838 846 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 839 psStringAppend(& query, "AND %s", whereClause);847 psStringAppend(&whereString, "\nAND %s", whereClause); 840 848 psFree(whereClause); 841 849 } 842 850 psFree(where); 843 851 844 if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id)) { 845 psError(PS_ERR_UNKNOWN, false, "database error"); 846 psFree(query); 847 return false; 848 } 852 if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString : "")) { 853 psFree(whereString); 854 psError(PS_ERR_UNKNOWN, false, "failed to revert"); 855 return false; 856 } 857 psFree(whereString); 849 858 psFree(query); 850 851 859 psArray *output = p_psDBFetchResult(config->dbh); 852 860 if (!output) { … … 868 876 return true; 869 877 } 870 871 if (psArrayLength(output)) { 872 // negative simple so the default is true 873 if (!ippdbPrintMetadatas(stdout, output, "magicDiffSkyfile", !simple)) { 874 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 878 for (int i=0; i<psArrayLength(output); i++) { 879 psMetadata *row = output->data[i]; 880 psS64 magic_ds_id = psMetadataLookupS64(NULL, row, "magic_ds_id"); 881 psString old_state = psMetadataLookupStr(NULL, row, "state"); 882 psString new_state; 883 if (!strcmp(old_state, "goto_censored")) { 884 new_state = "censored"; 885 } else if (!strcmp(old_state, "goto_restored")) { 886 new_state = "restored"; 887 } else { 888 psError(PXTOOLS_ERR_PROG, true, "unexpected state found: %s", old_state); 875 889 psFree(output); 876 890 return false; 877 891 } 878 } 879 892 char *query2 = "UPDATE magicDSRun SET state = '%s' WHERE magic_ds_id = %" PRId64; 893 if (!p_psDBRunQueryF(config->dbh, query2, magic_ds_id, new_state)) { 894 psError(PS_ERR_UNKNOWN, false, "failed to set run magicDSRun.state to %s", new_state); 895 return false; 896 } 897 } 880 898 psFree(output); 881 899 … … 883 901 } 884 902 885 static bool setmagicDSRunState(pxConfig *config, psS64 magic_ds_id, const char *state) 886 { 887 PS_ASSERT_PTR_NON_NULL(state, false); 888 889 // check that state is a valid string value 890 if (!( 891 (strncmp(state, "new", 4) == 0) 892 || (strncmp(state, "full", 5) == 0) 893 ) 894 ) { 895 psError(PS_ERR_UNKNOWN, false, 896 "invalid magicDSRun state: %s", state); 897 return false; 898 } 899 900 char *query = "UPDATE magicDSRun SET state = '%s' WHERE magic_ds_id = %" PRId64; 901 if (!p_psDBRunQueryF(config->dbh, query, state, magic_ds_id)) { 902 psError(PS_ERR_UNKNOWN, false, 903 "failed to change state for magic_id %" PRId64, magic_ds_id); 904 return false; 905 } 906 907 return true; 908 } 909 910 static bool toremoveMode(pxConfig *config) 911 { 912 PS_ASSERT_PTR_NON_NULL(config, false); 903 static bool getskycellsMode(pxConfig *config) 904 { 905 // required 906 PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false); 913 907 914 908 psMetadata *where = psMetadataAlloc(); 915 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "=="); 916 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 917 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 918 919 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 909 PXOPT_COPY_STR(config->args, where, "-class_id", "warpSkyCellMap.class_id", "=="); 910 PXOPT_COPY_STR(config->args, where, "-skycell_id", "warpSkyCellMap.skycell_id", "=="); 911 920 912 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 921 913 922 // look for "inputs" that need to processed 923 psString query = pxDataGet("magicdstool_toremove.sql"); 914 psString query = pxDataGet("magicdstool_getskycells.sql"); 924 915 if (!query) { 925 916 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 929 920 if (psListLength(where->list)) { 930 921 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 931 psStringAppend(&query, " WHERE%s", whereClause);922 psStringAppend(&query, " AND %s", whereClause); 932 923 psFree(whereClause); 933 924 } 934 925 psFree(where); 935 926 936 // treat limit == 0 as "no limit" 937 if (limit) { 938 psString limitString = psDBGenerateLimitSQL(limit); 939 psStringAppend(&query, " %s", limitString); 940 psFree(limitString); 941 } 942 943 if (!p_psDBRunQuery(config->dbh, query)) { 927 if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id)) { 944 928 psError(PS_ERR_UNKNOWN, false, "database error"); 945 929 psFree(query); … … 970 954 if (psArrayLength(output)) { 971 955 // negative simple so the default is true 972 if (!ippdbPrintMetadatas(stdout, output, " toremove", !simple)) {956 if (!ippdbPrintMetadatas(stdout, output, "magicDiffSkyfile", !simple)) { 973 957 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 974 958 psFree(output); … … 981 965 return true; 982 966 } 983 static bool torestoreMode(pxConfig *config) 967 968 static bool setmagicDSRunState(pxConfig *config, psS64 magic_ds_id, const char *state) 969 { 970 PS_ASSERT_PTR_NON_NULL(state, false); 971 972 // check that state is a valid string value 973 if (!( 974 (strncmp(state, "new", 4) == 0) 975 || (strncmp(state, "full", 5) == 0) 976 ) 977 ) { 978 psError(PS_ERR_UNKNOWN, false, 979 "invalid magicDSRun state: %s", state); 980 return false; 981 } 982 983 char *query = "UPDATE magicDSRun SET state = '%s' WHERE magic_ds_id = %" PRId64; 984 if (!p_psDBRunQueryF(config->dbh, query, state, magic_ds_id)) { 985 psError(PS_ERR_UNKNOWN, false, 986 "failed to change state for magic_id %" PRId64, magic_ds_id); 987 return false; 988 } 989 990 return true; 991 } 992 993 static bool toremoveMode(pxConfig *config) 984 994 { 985 995 PS_ASSERT_PTR_NON_NULL(config, false); … … 994 1004 995 1005 // look for "inputs" that need to processed 996 psString query = pxDataGet("magicdstool_tore store.sql");1006 psString query = pxDataGet("magicdstool_toremove.sql"); 997 1007 if (!query) { 998 1008 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 1043 1053 if (psArrayLength(output)) { 1044 1054 // negative simple so the default is true 1045 if (!ippdbPrintMetadatas(stdout, output, "tore store", !simple)) {1055 if (!ippdbPrintMetadatas(stdout, output, "toremove", !simple)) { 1046 1056 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1047 1057 psFree(output); … … 1054 1064 return true; 1055 1065 } 1056 1057 1058 static bool torevertMode(pxConfig *config) 1066 static bool torestoreMode(pxConfig *config) 1059 1067 { 1060 1068 PS_ASSERT_PTR_NON_NULL(config, false); 1061 1069 1062 1070 psMetadata *where = psMetadataAlloc(); 1063 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);1064 1065 1071 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "=="); 1066 1072 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 1067 pxAddLabelSearchArgs (config, where, "-label", " magicDSRun.label", "==");1073 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 1068 1074 1069 1075 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1070 1076 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1071 1077 1072 psString sql_file = NULL; 1073 psStringAppend(&sql_file, "magicdstool_torevert_%s.sql", stage); 1074 1075 psString query = pxDataGet(sql_file); 1078 // look for "inputs" that need to processed 1079 psString query = pxDataGet("magicdstool_torestore.sql"); 1076 1080 if (!query) { 1077 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", sql_file); 1078 psFree(sql_file); 1079 return false; 1080 } 1081 psFree(sql_file); 1081 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1082 return false; 1083 } 1082 1084 1083 1085 if (psListLength(where->list)) { 1084 1086 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1085 psStringAppend(&query, " AND%s", whereClause);1087 psStringAppend(&query, " WHERE %s", whereClause); 1086 1088 psFree(whereClause); 1087 1089 } … … 1124 1126 if (psArrayLength(output)) { 1125 1127 // negative simple so the default is true 1128 if (!ippdbPrintMetadatas(stdout, output, "torestore", !simple)) { 1129 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1130 psFree(output); 1131 return false; 1132 } 1133 } 1134 1135 psFree(output); 1136 1137 return true; 1138 } 1139 1140 1141 static bool torevertMode(pxConfig *config) 1142 { 1143 PS_ASSERT_PTR_NON_NULL(config, false); 1144 1145 psMetadata *where = psMetadataAlloc(); 1146 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 1147 1148 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "=="); 1149 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 1150 pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "=="); 1151 1152 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1153 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1154 1155 psString sql_file = NULL; 1156 psStringAppend(&sql_file, "magicdstool_torevert_%s.sql", stage); 1157 1158 psString query = pxDataGet(sql_file); 1159 if (!query) { 1160 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", sql_file); 1161 psFree(sql_file); 1162 return false; 1163 } 1164 psFree(sql_file); 1165 1166 if (psListLength(where->list)) { 1167 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1168 psStringAppend(&query, " AND %s", whereClause); 1169 psFree(whereClause); 1170 } 1171 psFree(where); 1172 1173 // treat limit == 0 as "no limit" 1174 if (limit) { 1175 psString limitString = psDBGenerateLimitSQL(limit); 1176 psStringAppend(&query, " %s", limitString); 1177 psFree(limitString); 1178 } 1179 1180 if (!p_psDBRunQuery(config->dbh, query)) { 1181 psError(PS_ERR_UNKNOWN, false, "database error"); 1182 psFree(query); 1183 return false; 1184 } 1185 psFree(query); 1186 1187 psArray *output = p_psDBFetchResult(config->dbh); 1188 if (!output) { 1189 psErrorCode err = psErrorCodeLast(); 1190 switch (err) { 1191 case PS_ERR_DB_CLIENT: 1192 psError(PXTOOLS_ERR_SYS, false, "database error"); 1193 case PS_ERR_DB_SERVER: 1194 psError(PXTOOLS_ERR_PROG, false, "database error"); 1195 default: 1196 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1197 } 1198 1199 return false; 1200 } 1201 if (!psArrayLength(output)) { 1202 psTrace("magicdstool", PS_LOG_INFO, "no rows found"); 1203 psFree(output); 1204 return true; 1205 } 1206 1207 if (psArrayLength(output)) { 1208 // negative simple so the default is true 1126 1209 if (!ippdbPrintMetadatas(stdout, output, "torevert", !simple)) { 1127 1210 psError(PS_ERR_UNKNOWN, false, "failed to print array"); -
trunk/ippTools/src/magicdstool.h
r24683 r25419 35 35 MAGICDSTOOL_MODE_TORESTORE, 36 36 MAGICDSTOOL_MODE_TOREVERT, 37 MAGICDSTOOL_MODE_COMPLETEDREVERT, 37 38 } MAGICDStoolMode; 38 39 -
trunk/ippTools/src/magicdstoolConfig.c
r24937 r25419 93 93 // -todestreak 94 94 psMetadata *todestreakArgs = psMetadataAlloc(); 95 psMetadataAddStr(todestreakArgs, PS_LIST_TAIL, "-stage", 0, "limit query to stage (required)", NULL); 95 96 psMetadataAddS64(todestreakArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "search by magic Destreak ID", 0); 96 97 psMetadataAddS64(todestreakArgs, PS_LIST_TAIL, "-magic_id", 0, "search by magic ID", 0); 97 98 psMetadataAddStr(todestreakArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "define label", NULL); 98 psMetadataAddStr(todestreakArgs, PS_LIST_TAIL, "-stage", 0, "limit query to stage", NULL);99 99 psMetadataAddU64(todestreakArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 100 100 psMetadataAddBool(todestreakArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); … … 147 147 psMetadataAddU64(torevertArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 148 148 psMetadataAddBool(torevertArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 149 150 // -completedrevert 151 psMetadata *completedrevertArgs = psMetadataAlloc(); 152 psMetadataAddS64(completedrevertArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "search by magic Destreak ID", 0); 153 psMetadataAddStr(completedrevertArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "define label", NULL); 154 psMetadataAddU64(completedrevertArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 149 155 150 156 psFree(now); … … 174 180 MAGICDSTOOL_MODE_TOREVERT, torevertArgs); 175 181 182 PXOPT_ADD_MODE("-completedrevert", "change state for runs that have finished reverting", 183 MAGICDSTOOL_MODE_COMPLETEDREVERT, completedrevertArgs); 184 176 185 if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) { 177 186 psError(PS_ERR_UNKNOWN, true, "option parsing failed");
Note:
See TracChangeset
for help on using the changeset viewer.
