Handles CRUD calls to individual UIDMeta data entries @param tsdb The TSDB from the RPC router @param query The query for this request
(final TSDB tsdb, final HttpQuery query)
| 158 | * @param query The query for this request |
| 159 | */ |
| 160 | private void handleUIDMeta(final TSDB tsdb, final HttpQuery query) { |
| 161 | |
| 162 | final HttpMethod method = query.getAPIMethod(); |
| 163 | // GET |
| 164 | if (method == HttpMethod.GET) { |
| 165 | |
| 166 | final String uid = query.getRequiredQueryStringParam("uid"); |
| 167 | final UniqueIdType type = UniqueId.stringToUniqueIdType( |
| 168 | query.getRequiredQueryStringParam("type")); |
| 169 | try { |
| 170 | final UIDMeta meta = UIDMeta.getUIDMeta(tsdb, type, uid) |
| 171 | .joinUninterruptibly(); |
| 172 | query.sendReply(query.serializer().formatUidMetaV1(meta)); |
| 173 | } catch (NoSuchUniqueId e) { |
| 174 | throw new BadRequestException(HttpResponseStatus.NOT_FOUND, |
| 175 | "Could not find the requested UID", e); |
| 176 | } catch (Exception e) { |
| 177 | throw new RuntimeException(e); |
| 178 | } |
| 179 | // POST |
| 180 | } else if (method == HttpMethod.POST || method == HttpMethod.PUT) { |
| 181 | |
| 182 | final UIDMeta meta; |
| 183 | if (query.hasContent()) { |
| 184 | meta = query.serializer().parseUidMetaV1(); |
| 185 | } else { |
| 186 | meta = this.parseUIDMetaQS(query); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Storage callback used to determine if the storage call was successful |
| 191 | * or not. Also returns the updated object from storage. |
| 192 | */ |
| 193 | class SyncCB implements Callback<Deferred<UIDMeta>, Boolean> { |
| 194 | |
| 195 | @Override |
| 196 | public Deferred<UIDMeta> call(Boolean success) throws Exception { |
| 197 | if (!success) { |
| 198 | throw new BadRequestException( |
| 199 | HttpResponseStatus.INTERNAL_SERVER_ERROR, |
| 200 | "Failed to save the UIDMeta to storage", |
| 201 | "This may be caused by another process modifying storage data"); |
| 202 | } |
| 203 | |
| 204 | return UIDMeta.getUIDMeta(tsdb, meta.getType(), meta.getUID()); |
| 205 | } |
| 206 | |
| 207 | } |
| 208 | |
| 209 | try { |
| 210 | final Deferred<UIDMeta> process_meta = meta.syncToStorage(tsdb, |
| 211 | method == HttpMethod.PUT).addCallbackDeferring(new SyncCB()); |
| 212 | final UIDMeta updated_meta = process_meta.joinUninterruptibly(); |
| 213 | tsdb.indexUIDMeta(updated_meta); |
| 214 | query.sendReply(query.serializer().formatUidMetaV1(updated_meta)); |
| 215 | } catch (IllegalStateException e) { |
| 216 | query.sendStatusOnly(HttpResponseStatus.NOT_MODIFIED); |
| 217 | } catch (IllegalArgumentException e) { |
no test coverage detected