| 1150 | } |
| 1151 | |
| 1152 | void CatalogServer::CatalogUrlCallback(const Webserver::WebRequest& req, |
| 1153 | Document* document) { |
| 1154 | GetCatalogUsage(document); |
| 1155 | TGetDbsResult get_dbs_result; |
| 1156 | Status status = catalog_->GetDbs(NULL, &get_dbs_result); |
| 1157 | if (!status.ok()) { |
| 1158 | Value error(status.GetDetail(), document->GetAllocator()); |
| 1159 | document->AddMember("error", error, document->GetAllocator()); |
| 1160 | return; |
| 1161 | } |
| 1162 | long current_catalog_version; |
| 1163 | status = catalog_->GetCatalogVersion(¤t_catalog_version); |
| 1164 | if (status.ok()) { |
| 1165 | Value version_value; |
| 1166 | version_value.SetInt(current_catalog_version); |
| 1167 | document->AddMember("version", version_value, document->GetAllocator()); |
| 1168 | } else { |
| 1169 | Value error(status.GetDetail(), document->GetAllocator()); |
| 1170 | document->AddMember("versionError", error, document->GetAllocator()); |
| 1171 | } |
| 1172 | Value databases(kArrayType); |
| 1173 | for (const TDatabase& db: get_dbs_result.dbs) { |
| 1174 | Value database(kObjectType); |
| 1175 | Value str(db.db_name, document->GetAllocator()); |
| 1176 | database.AddMember("name", str, document->GetAllocator()); |
| 1177 | |
| 1178 | TGetTablesResult get_table_results; |
| 1179 | Status status = catalog_->GetTableNames(db.db_name, NULL, &get_table_results); |
| 1180 | if (!status.ok()) { |
| 1181 | Value error(status.GetDetail(), document->GetAllocator()); |
| 1182 | database.AddMember("error", error, document->GetAllocator()); |
| 1183 | continue; |
| 1184 | } |
| 1185 | |
| 1186 | Value table_array(kArrayType); |
| 1187 | for (const string& table: get_table_results.tables) { |
| 1188 | Value table_obj(kObjectType); |
| 1189 | Value fq_name(Substitute("$0.$1", db.db_name, table), |
| 1190 | document->GetAllocator()); |
| 1191 | table_obj.AddMember("fqtn", fq_name, document->GetAllocator()); |
| 1192 | Value table_name(table, document->GetAllocator()); |
| 1193 | table_obj.AddMember("name", table_name, document->GetAllocator()); |
| 1194 | Value has_metrics; |
| 1195 | has_metrics.SetBool(true); |
| 1196 | table_obj.AddMember("has_metrics", has_metrics, document->GetAllocator()); |
| 1197 | table_array.PushBack(table_obj, document->GetAllocator()); |
| 1198 | } |
| 1199 | database.AddMember("num_tables", table_array.Size(), document->GetAllocator()); |
| 1200 | database.AddMember("tables", table_array, document->GetAllocator()); |
| 1201 | Value has_metrics; |
| 1202 | has_metrics.SetBool(true); |
| 1203 | database.AddMember("has_metrics", has_metrics, document->GetAllocator()); |
| 1204 | databases.PushBack(database, document->GetAllocator()); |
| 1205 | } |
| 1206 | document->AddMember("databases", databases, document->GetAllocator()); |
| 1207 | } |
| 1208 | |
| 1209 | void CatalogServer::GetCatalogUsage(Document* document) { |
no test coverage detected