Changeset 29671 for trunk/ippTools/src/bgtool.c
- Timestamp:
- Nov 4, 2010, 1:42:23 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/bgtool.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/bgtool.c
r29493 r29671 49 49 static bool revertwarpMode(pxConfig *config); 50 50 static bool listwarpMode(pxConfig *config); 51 static bool tocleanchipMode(pxConfig *config); 52 static bool cleanedchipMode(pxConfig *config); 53 static bool tocleanwarpMode(pxConfig *config); 54 static bool cleanedwarpMode(pxConfig *config); 51 52 static bool pendingcleanupchiprunMode(pxConfig *config); 53 static bool pendingcleanupchipimfileMode(pxConfig *config); 54 static bool tocleanedchipimfileMode(pxConfig *config); 55 static bool updatechipimfileMode(pxConfig *config); 56 57 static bool pendingcleanupwarprunMode(pxConfig *config); 58 static bool pendingcleanupwarpskyfileMode(pxConfig *config); 59 static bool tocleanedwarpskyfileMode(pxConfig *config); 60 55 61 static bool exportchipMode(pxConfig *config); 56 62 static bool importchipMode(pxConfig *config); 57 63 static bool exportwarpMode(pxConfig *config); 58 64 static bool importwarpMode(pxConfig *config); 65 66 static bool validDataState(psString data_state); 59 67 60 68 // Tables to import/export … … 112 120 MODECASE(BGTOOL_MODE_REVERTWARP, revertwarpMode); 113 121 MODECASE(BGTOOL_MODE_LISTWARP, listwarpMode); 114 MODECASE(BGTOOL_MODE_TOCLEANCHIP, tocleanchipMode); 115 MODECASE(BGTOOL_MODE_CLEANEDCHIP, cleanedchipMode); 116 MODECASE(BGTOOL_MODE_TOCLEANWARP, tocleanwarpMode); 117 MODECASE(BGTOOL_MODE_CLEANEDWARP, cleanedwarpMode); 122 MODECASE(BGTOOL_MODE_PENDINGCLEANUPCHIPRUN, pendingcleanupchiprunMode); 123 MODECASE(BGTOOL_MODE_PENDINGCLEANUPCHIPIMFILE, pendingcleanupchipimfileMode); 124 MODECASE(BGTOOL_MODE_TOCLEANEDCHIPIMFILE, tocleanedchipimfileMode); 125 MODECASE(BGTOOL_MODE_UPDATECHIPIMFILE, updatechipimfileMode); 126 MODECASE(BGTOOL_MODE_PENDINGCLEANUPWARPRUN, pendingcleanupwarprunMode); 127 MODECASE(BGTOOL_MODE_PENDINGCLEANUPWARPSKYFILE, pendingcleanupwarpskyfileMode); 128 MODECASE(BGTOOL_MODE_TOCLEANEDWARPSKYFILE, tocleanedwarpskyfileMode); 118 129 MODECASE(BGTOOL_MODE_EXPORTCHIP, exportchipMode); 119 130 MODECASE(BGTOOL_MODE_IMPORTCHIP, importchipMode); … … 914 925 return true; 915 926 } 927 916 928 static bool listchipMode(pxConfig *config) 917 929 { … … 978 990 } 979 991 980 static bool tocleanchipMode(pxConfig *config)992 static bool pendingcleanupchiprunMode(pxConfig *config) 981 993 { 982 994 PS_ASSERT_PTR_NON_NULL(config, NULL); … … 987 999 psMetadata *where = psMetadataAlloc(); 988 1000 pxAddLabelSearchArgs(config, where, "-label", "chipBackgroundRun.label", "=="); 989 990 psString query = pxDataGet("bgtool_tocleanchip.sql"); 1001 pxAddLabelSearchArgs(config, where, "-data_group", "chipBackgroundRun.data_group", "=="); 1002 1003 psString query = pxDataGet("bgtool_pendingcleanupchiprun.sql"); 991 1004 if (!query) { 992 1005 psError(psErrorCodeLast(), false, "failed to retreive SQL statement"); … … 1035 1048 return true; 1036 1049 } 1037 1038 static bool cleanedchipMode(pxConfig *config) 1039 { 1040 PS_ASSERT_PTR_NON_NULL(config, false); 1041 1042 psMetadata *where = psMetadataAlloc(); 1050 static bool pendingcleanupchipimfileMode(pxConfig *config) 1051 { 1052 PS_ASSERT_PTR_NON_NULL(config, NULL); 1053 1054 PXOPT_LOOKUP_S64(chip_bg_id, config->args, "-chip_bg_id", true, false); 1055 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1056 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1057 1058 psMetadata *where = psMetadataAlloc(); 1059 1043 1060 PXOPT_COPY_S64(config->args, where, "-chip_bg_id", "chipBackgroundRun.chip_bg_id", "=="); 1044 1061 1045 PXOPT_LOOKUP_STR(state, config->args, "-state", true, false); 1046 if (!pxIsValidCleanedState(state)) { 1047 psError(PXTOOLS_ERR_CONFIG, true, "Invalid state: %s", state); 1048 return false; 1049 } 1050 1051 if (!psListLength(where->list)) { 1052 psError(PXTOOLS_ERR_CONFIG, true, "No search restrictions set."); 1053 return false; 1054 } 1055 1056 psString query = pxDataGet("bgtool_cleanedchip.sql"); 1062 psString query = pxDataGet("bgtool_pendingcleanupchipimfile.sql"); 1057 1063 if (!query) { 1058 1064 psError(psErrorCodeLast(), false, "failed to retreive SQL statement"); … … 1060 1066 } 1061 1067 1062 {1068 if (where && psListLength(where->list)) { 1063 1069 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1064 1070 psStringAppend(&query, " AND %s", whereClause); … … 1067 1073 psFree(where); 1068 1074 1069 if (!p_psDBRunQueryF(config->dbh, query, state)) { 1070 psError(psErrorCodeLast(), false, "database error"); 1075 if (limit) { 1076 psString limitString = psDBGenerateLimitSQL(limit); 1077 psStringAppend(&query, " %s", limitString); 1078 psFree(limitString); 1079 } 1080 1081 if (!p_psDBRunQuery(config->dbh, query)) { 1082 psError(psErrorCodeLast(), false, "database error"); 1083 psFree(query); 1084 return false; 1085 } 1086 psFree(query); 1087 1088 psArray *output = p_psDBFetchResult(config->dbh); 1089 if (!output) { 1090 psError(psErrorCodeLast(), false, "database error"); 1091 return false; 1092 } 1093 if (!psArrayLength(output)) { 1094 psTrace("bgtool", PS_LOG_INFO, "no rows found"); 1095 psFree(output); 1096 return true; 1097 } 1098 1099 // negative simple so the default is true 1100 if (!ippdbPrintMetadatas(stdout, output, "chipBackgroundImfile", !simple)) { 1101 psError(psErrorCodeLast(), false, "failed to print array"); 1102 psFree(output); 1103 return false; 1104 } 1105 psFree(output); 1106 1107 return true; 1108 } 1109 1110 static bool change_imfile_data_state(pxConfig *config, psString data_state) 1111 { 1112 PS_ASSERT_PTR_NON_NULL(config, false); 1113 1114 // chip_id, class_id are required 1115 PXOPT_LOOKUP_S64(chip_bg_id, config->args, "-chip_bg_id", true, false); 1116 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); 1117 1118 psString query = pxDataGet("bgtool_change_imfile_data_state.sql"); 1119 1120 if (!psDBTransaction(config->dbh)) { 1121 psError(PS_ERR_UNKNOWN, false, "database error"); 1122 return false; 1123 } 1124 1125 if (!p_psDBRunQueryF(config->dbh, query, data_state, chip_bg_id, class_id)) { 1126 psFree(query); 1127 psError(PS_ERR_UNKNOWN, false, "database error"); 1128 // rollback 1129 if (!psDBRollback(config->dbh)) { 1130 psError(PS_ERR_UNKNOWN, false, "database error"); 1131 } 1132 psError(PS_ERR_UNKNOWN, false, "database error"); 1133 return false; 1134 } 1135 psFree(query); 1136 if (psDBAffectedRows(config->dbh) < 1) { 1137 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 1138 return false; 1139 } 1140 1141 query = pxDataGet("bgtool_change_chiprun_state.sql"); 1142 if (!p_psDBRunQueryF(config->dbh, query, data_state, chip_bg_id, data_state)) { 1143 psFree(query); 1144 // rollback 1145 if (!psDBRollback(config->dbh)) { 1146 psError(PS_ERR_UNKNOWN, false, "database error"); 1147 } 1148 psError(PS_ERR_UNKNOWN, false, "database error"); 1149 return false; 1150 } 1151 psFree(query); 1152 1153 if (!psDBCommit(config->dbh)) { 1154 psError(PS_ERR_UNKNOWN, false, "database error"); 1155 return false; 1156 } 1157 1158 return true; 1159 } 1160 1161 static bool tocleanedchipimfileMode(pxConfig *config) 1162 { 1163 return change_imfile_data_state(config, "cleaned"); 1164 } 1165 1166 static bool updatechipimfileMode(pxConfig *config) 1167 { 1168 PS_ASSERT_PTR_NON_NULL(config, false); 1169 1170 // required 1171 PXOPT_LOOKUP_S64(chip_bg_id, config->args, "-chip_bg_id", true, false); 1172 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); 1173 1174 psMetadata *where = psMetadataAlloc(); 1175 1176 PXOPT_COPY_S64(config->args, where, "-chip_bg_id", "chipBackgroundImfile.chip_bg_id", "=="); 1177 PXOPT_COPY_S64(config->args, where, "-class_id", "chipBackgroundImfile.class_id", "=="); 1178 1179 // optional 1180 1181 PXOPT_LOOKUP_STR(data_state, config->args, "-set_data_state", false, false); 1182 PXOPT_LOOKUP_S16(fault, config->args, "-set_fault", false, false); 1183 if (!data_state && !fault) { 1184 psError(PS_ERR_UNKNOWN, true, "must supply either -set_fault or -set_data_state"); 1185 return false; 1186 } 1187 char *sep = ""; 1188 psString query = psStringCopy("UPDATE chipBackgroundImfile SET "); 1189 if (data_state) { 1190 if (!validDataState(data_state)) { 1191 return false; 1192 } 1193 psStringAppend(&query, "%s data_state = '%s'", sep, data_state); 1194 sep = ", "; 1195 } 1196 if (fault) { 1197 psStringAppend(&query, "%s fault = %d", sep, fault); 1198 sep = ", "; 1199 } 1200 if (psListLength(where->list)) { 1201 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1202 psStringAppend(&query, " WHERE %s", whereClause); 1203 psFree(whereClause); 1204 } else { 1205 psFree(where); 1206 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1207 return false; 1208 } 1209 psFree(where); 1210 if (!p_psDBRunQuery(config->dbh, query)) { 1211 psError(psErrorCodeLast(), false, "database error"); 1212 psFree(query); 1071 1213 return false; 1072 1214 } … … 1449 1591 return true; 1450 1592 } 1451 if (!ippdbPrintMetadatas(stdout, output, " chipBackgroundSkyfile", !simple)) {1593 if (!ippdbPrintMetadatas(stdout, output, "warpBackgroundSkyfile", !simple)) { 1452 1594 psError(psErrorCodeLast(), false, "failed to print array"); 1453 1595 psFree(output); … … 1814 1956 } 1815 1957 1816 static bool tocleanwarpMode(pxConfig *config)1958 static bool pendingcleanupwarprunMode(pxConfig *config) 1817 1959 { 1818 1960 PS_ASSERT_PTR_NON_NULL(config, NULL); … … 1824 1966 pxAddLabelSearchArgs(config, where, "-label", "warpBackgroundRun.label", "=="); 1825 1967 1826 psString query = pxDataGet("bgtool_ tocleanwarp.sql");1968 psString query = pxDataGet("bgtool_pendingcleanupwarprun.sql"); 1827 1969 if (!query) { 1828 1970 psError(psErrorCodeLast(), false, "failed to retreive SQL statement"); … … 1871 2013 return true; 1872 2014 } 1873 1874 static bool cleanedwarpMode(pxConfig *config) 1875 { 1876 PS_ASSERT_PTR_NON_NULL(config, false); 1877 1878 psMetadata *where = psMetadataAlloc(); 2015 static bool pendingcleanupwarpskyfileMode(pxConfig *config) 2016 { 2017 PS_ASSERT_PTR_NON_NULL(config, NULL); 2018 2019 PXOPT_LOOKUP_S64(warp_bg_id, config->args, "-warp_bg_id", true, false); 2020 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2021 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2022 2023 psMetadata *where = psMetadataAlloc(); 2024 1879 2025 PXOPT_COPY_S64(config->args, where, "-warp_bg_id", "warpBackgroundRun.warp_bg_id", "=="); 1880 2026 1881 PXOPT_LOOKUP_STR(state, config->args, "-state", true, false); 1882 if (!pxIsValidCleanedState(state)) { 1883 psError(PXTOOLS_ERR_CONFIG, true, "Invalid state: %s", state); 1884 return false; 1885 } 1886 1887 if (!psListLength(where->list)) { 1888 psError(PXTOOLS_ERR_CONFIG, true, "No search restrictions set."); 1889 return false; 1890 } 1891 1892 psString query = pxDataGet("bgtool_cleanedwarp.sql"); 2027 psString query = pxDataGet("bgtool_pendingcleanupwarpskyfile.sql"); 1893 2028 if (!query) { 1894 2029 psError(psErrorCodeLast(), false, "failed to retreive SQL statement"); … … 1896 2031 } 1897 2032 1898 {2033 if (where && psListLength(where->list)) { 1899 2034 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1900 2035 psStringAppend(&query, " AND %s", whereClause); … … 1903 2038 psFree(where); 1904 2039 1905 if (!p_psDBRunQueryF(config->dbh, query, state)) { 1906 psError(psErrorCodeLast(), false, "database error"); 1907 return false; 1908 } 1909 psFree(query); 1910 1911 return true; 2040 if (limit) { 2041 psString limitString = psDBGenerateLimitSQL(limit); 2042 psStringAppend(&query, " %s", limitString); 2043 psFree(limitString); 2044 } 2045 2046 if (!p_psDBRunQuery(config->dbh, query)) { 2047 psError(psErrorCodeLast(), false, "database error"); 2048 psFree(query); 2049 return false; 2050 } 2051 psFree(query); 2052 2053 psArray *output = p_psDBFetchResult(config->dbh); 2054 if (!output) { 2055 psError(psErrorCodeLast(), false, "database error"); 2056 return false; 2057 } 2058 if (!psArrayLength(output)) { 2059 psTrace("bgtool", PS_LOG_INFO, "no rows found"); 2060 psFree(output); 2061 return true; 2062 } 2063 2064 // negative simple so the default is true 2065 if (!ippdbPrintMetadatas(stdout, output, "warpBackgroundSkyfile", !simple)) { 2066 psError(psErrorCodeLast(), false, "failed to print array"); 2067 psFree(output); 2068 return false; 2069 } 2070 psFree(output); 2071 2072 return true; 2073 } 2074 2075 static bool change_skyfile_data_state(pxConfig *config, psString data_state) 2076 { 2077 PS_ASSERT_PTR_NON_NULL(config, false); 2078 2079 // warp_id, skycell_id are required 2080 PXOPT_LOOKUP_S64(warp_bg_id, config->args, "-warp_bg_id", true, false); 2081 PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false); 2082 2083 psString query = pxDataGet("bgtool_change_skyfile_data_state.sql"); 2084 2085 if (!psDBTransaction(config->dbh)) { 2086 psError(PS_ERR_UNKNOWN, false, "database error"); 2087 return false; 2088 } 2089 2090 if (!p_psDBRunQueryF(config->dbh, query, data_state, warp_bg_id, skycell_id)) { 2091 psFree(query); 2092 psError(PS_ERR_UNKNOWN, false, "database error"); 2093 // rollback 2094 if (!psDBRollback(config->dbh)) { 2095 psError(PS_ERR_UNKNOWN, false, "database error"); 2096 } 2097 psError(PS_ERR_UNKNOWN, false, "database error"); 2098 return false; 2099 } 2100 psFree(query); 2101 if (psDBAffectedRows(config->dbh) < 1) { 2102 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 2103 return false; 2104 } 2105 2106 query = pxDataGet("bgtool_change_warprun_state.sql"); 2107 if (!p_psDBRunQueryF(config->dbh, query, data_state, warp_bg_id, data_state)) { 2108 psFree(query); 2109 // rollback 2110 if (!psDBRollback(config->dbh)) { 2111 psError(PS_ERR_UNKNOWN, false, "database error"); 2112 } 2113 psError(PS_ERR_UNKNOWN, false, "database error"); 2114 return false; 2115 } 2116 psFree(query); 2117 2118 if (!psDBCommit(config->dbh)) { 2119 psError(PS_ERR_UNKNOWN, false, "database error"); 2120 return false; 2121 } 2122 2123 return true; 2124 } 2125 2126 static bool tocleanedwarpskyfileMode(pxConfig *config) 2127 { 2128 return change_skyfile_data_state(config, "cleaned"); 1912 2129 } 1913 2130 … … 1935 2152 return importTables(config, infile, warpTables); 1936 2153 } 2154 2155 static bool validDataState(psString data_state) 2156 { 2157 // NOTE: can't use pxIsValidState because 2158 // update, scrubbed and purged are not supported for the backround stages (yet?) 2159 if (!strcmp(data_state, "new") || 2160 !strcmp(data_state, "full") || 2161 !strcmp(data_state, "drop") || 2162 !strcmp(data_state, "cleaned") || 2163 !strcmp(data_state, "goto_cleaned") || 2164 !strcmp(data_state, "error_cleaned")) { 2165 return true; 2166 } else { 2167 psError(PS_ERR_UNKNOWN, true, "%s is not a valid value data_state", data_state); 2168 return false; 2169 } 2170 }
Note:
See TracChangeset
for help on using the changeset viewer.
