Changeset 23912 for trunk/ippTools/src/disttool.c
- Timestamp:
- Apr 17, 2009, 3:58:46 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/disttool.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/disttool.c
r23864 r23912 45 45 static bool updatercrunMode(pxConfig *config); 46 46 static bool revertrcrunMode(pxConfig *config); 47 static bool pendingd atastoresMode(pxConfig *config);47 static bool pendingdestMode(pxConfig *config); 48 48 49 49 # define MODECASE(caseName, func) \ … … 80 80 MODECASE(DISTTOOL_MODE_UPDATERCRUN, updatercrunMode); 81 81 MODECASE(DISTTOOL_MODE_REVERTRCRUN, revertrcrunMode); 82 MODECASE(DISTTOOL_MODE_PENDINGD ATASTORES, pendingdatastoresMode);82 MODECASE(DISTTOOL_MODE_PENDINGDEST, pendingdestMode); 83 83 default: 84 84 psAbort("invalid option (this should not happen)"); … … 952 952 } 953 953 954 static bool pendingd atastoresMode(pxConfig *config)954 static bool pendingdestMode(pxConfig *config) 955 955 { 956 956 PS_ASSERT_PTR_NON_NULL(config, false); 957 #ifdef notyet958 957 959 958 psMetadata *where = psMetadataAlloc(); 960 PXOPT_COPY_S64(config->args, where, "-d ist_id", "dist_id", "==");961 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");959 PXOPT_COPY_S64(config->args, where, "-dest_id", "dist_id", "=="); 960 // PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 962 961 963 962 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 965 964 966 965 // look for "inputs" that need to processed 967 psString query = pxDataGet("disttool_pending fileset.sql");966 psString query = pxDataGet("disttool_pendingdest.sql"); 968 967 if (!query) { 969 968 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 971 970 } 972 971 972 psString whereString = NULL; 973 973 if (psListLength(where->list)) { 974 974 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 975 psStringAppend(&query, " AND %s", whereClause); 975 // where string gets added by hook, not at the end of the query 976 psStringAppend(&whereString, "\n AND %s", whereClause); 976 977 psFree(whereClause); 977 978 } … … 985 986 } 986 987 987 if (!p_psDBRunQuery(config->dbh, query)) { 988 psError(PS_ERR_UNKNOWN, false, "database error"); 988 if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString : "")) { 989 psError(PS_ERR_UNKNOWN, false, "database error"); 990 psFree(whereString); 989 991 psFree(query); 990 992 return false; … … 1022 1024 1023 1025 psFree(output); 1024 # endif // notdef 1026 1025 1027 return true; 1026 1028 } … … 1029 1031 { 1030 1032 PS_ASSERT_PTR_NON_NULL(config, false); 1031 return true; 1032 } 1033 psMetadata *where = psMetadataAlloc(); 1034 1035 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 1036 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1037 PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "=="); 1038 PXOPT_COPY_S64(config->args, where, "-target_id","target_id", "=="); 1039 PXOPT_COPY_S64(config->args, where, "-fs_id", "fs_id", "=="); 1040 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");; 1041 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 1042 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1043 1044 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1045 1046 psString query = pxDataGet("disttool_queuercrun.sql"); 1047 if (!query) { 1048 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1049 return false; 1050 } 1051 1052 if (psListLength(where->list)) { 1053 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1054 psStringAppend(&query, " AND %s", whereClause); 1055 psFree(whereClause); 1056 } 1057 psFree(where); 1058 1059 // treat limit == 0 as "no limit" 1060 if (limit) { 1061 psString limitString = psDBGenerateLimitSQL(limit); 1062 psStringAppend(&query, " %s", limitString); 1063 psFree(limitString); 1064 } 1065 1066 if (!p_psDBRunQuery(config->dbh, query)) { 1067 psError(PS_ERR_UNKNOWN, false, "database error"); 1068 psFree(query); 1069 return false; 1070 } 1071 psFree(query); 1072 1073 long numUpdated = psDBAffectedRows(config->dbh); 1074 1075 psLogMsg("disttool", PS_LOG_INFO, "Inserted %ld rcRuns", numUpdated); 1076 1077 return true; 1078 } 1079 1080 1033 1081 static bool updatercrunMode(pxConfig *config) 1034 1082 { 1035 1083 PS_ASSERT_PTR_NON_NULL(config, false); 1036 return true; 1037 } 1084 1085 psMetadata *where = psMetadataAlloc(); 1086 1087 PXOPT_LOOKUP_S64(rc_id, config->args, "-rc_id", false, false); 1088 PXOPT_LOOKUP_STR(fs_name, config->args, "-fs_name", false, false); 1089 PXOPT_LOOKUP_STR(status_fs_name, config->args, "-status_fs_name", false, false); 1090 PXOPT_LOOKUP_S64(dest_id, config->args, "-dest_id", false, false); 1091 1092 // We either need rc_id or (dest_id and fs_name) to identifiy the rcRun 1093 if ((!rc_id) && !(dest_id && fs_name)) { 1094 psError(PXTOOLS_ERR_DATA, true, "either -rc_id or (-fs_name and -dest_id) are required"); 1095 return false; 1096 } 1097 1098 // now that we have done the argument checking 1099 PXOPT_COPY_S64(config->args, where, "-rc_id", "rc_id", "=="); 1100 PXOPT_COPY_STR(config->args, where, "-fs_name", "rcDSFileset.name", "=="); 1101 PXOPT_COPY_S64(config->args, where, "-dest_id", "rcRun.dest_id", "=="); 1102 1103 if (!psListLength(where->list)) { 1104 // this can't happen because we checked above 1105 psFree(where); 1106 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 1107 return false; 1108 } 1109 1110 1111 PXOPT_LOOKUP_STR(last_fileset, config->args, "-last_fileset", false, false); 1112 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1113 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 1114 1115 if (!state && (fault < 0)) { 1116 psError(PXTOOLS_ERR_DATA, false, "parameters (-fault or -set_state) are required"); 1117 psFree(where); 1118 return false; 1119 } 1120 1121 psString query = pxDataGet("disttool_updatercrun.sql"); 1122 if (!query) { 1123 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1124 return false; 1125 } 1126 1127 psString setString = psStringCopy("\n"); 1128 psString separator = ""; 1129 if (state) { 1130 psStringAppend(&setString, " rcRun.state = '%s'", state); 1131 separator = ","; 1132 } 1133 1134 // default for fault is -1, so set it if it's zero or higher. This allows clearing fault 1135 // without forcing revert first 1136 if (fault >= 0) { 1137 psStringAppend(&setString, "%s rcRun.fault = %d", separator, fault); 1138 } 1139 1140 if (status_fs_name) { 1141 psStringAppend(&setString, ", rcRun.status_fs_name = '%s'", status_fs_name); 1142 } 1143 1144 if (last_fileset) { 1145 psStringAppend(&setString, ", rcDestination.last_fileset = '%s'", last_fileset); 1146 } 1147 1148 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1149 psStringAppend(&query, " AND %s", whereClause); 1150 psFree(whereClause); 1151 psFree(where); 1152 1153 if (!p_psDBRunQueryF(config->dbh, query, setString)) { 1154 psError(PS_ERR_UNKNOWN, false, "database error"); 1155 psFree(setString); 1156 psFree(query); 1157 return false; 1158 } 1159 psFree(setString); 1160 psFree(query); 1161 1162 long numUpdated = psDBAffectedRows(config->dbh); 1163 1164 psLogMsg("disttool", PS_LOG_INFO, "Updated %ld rows", numUpdated); 1165 1166 return true; 1167 } 1168 1038 1169 static bool revertrcrunMode(pxConfig *config) 1039 1170 { 1040 1171 PS_ASSERT_PTR_NON_NULL(config, false); 1041 return true; 1042 } 1172 psMetadata *where = psMetadataAlloc(); 1173 PXOPT_COPY_S64(config->args, where, "-rc_id", "rc_id", "=="); 1174 PXOPT_COPY_S64(config->args, where, "-fs_id", "fs_id", "=="); 1175 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1176 PXOPT_COPY_S64(config->args, where, "-fault", "fault", "=="); 1177 1178 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 1179 psFree(where); 1180 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 1181 return false; 1182 } 1183 1184 psString query = pxDataGet("disttool_revertrcrun.sql"); 1185 if (!query) { 1186 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1187 if (!psDBRollback(config->dbh)) { 1188 psError(PS_ERR_UNKNOWN, false, "database error"); 1189 } 1190 return false; 1191 } 1192 1193 if (psListLength(where->list)) { 1194 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1195 psStringAppend(&query, " AND %s", whereClause); 1196 psFree(whereClause); 1197 } 1198 1199 if (!p_psDBRunQuery(config->dbh, query)) { 1200 psError(PS_ERR_UNKNOWN, false, "database error"); 1201 psFree(query); 1202 if (!psDBRollback(config->dbh)) { 1203 psError(PS_ERR_UNKNOWN, false, "database error"); 1204 } 1205 return false; 1206 } 1207 psFree(query); 1208 1209 long numUpdated = psDBAffectedRows(config->dbh); 1210 1211 psLogMsg("disttool", PS_LOG_INFO, "Updated %ld rcRuns", numUpdated); 1212 1213 return true; 1214 }
Note:
See TracChangeset
for help on using the changeset viewer.
