private EmoApiKey getApiKeyFromResponse(EmoResponse response) { if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.getEntity(EmoApiKey.class); } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) { return null; } throw convertException(new EmoClientException(response)); }
@Override public boolean isRetriableException(Exception e) { return (e instanceof EmoClientException && ((EmoClientException) e).getResponse().getStatus() >= 500) || e instanceof JsonStreamingEOFException; }
@Override public BlobMetadata getMetadata(String apiKey, String table, String blobId) throws BlobNotFoundException { checkNotNull(table, "table"); checkNotNull(blobId, "blobId"); try { EmoResponse response = _client.resource(toUri(table, blobId)) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && BlobNotFoundException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { throw new BlobNotFoundException(blobId, new EmoClientException(response)); } else if (response.getStatus() != Response.Status.OK.getStatusCode()) { throw new EmoClientException(response); } return parseMetadataHeaders(blobId, response); } catch (EmoClientException e) { throw convertException(e); } }
@Override public boolean isRetriableException(Exception e) { return (e instanceof EmoClientException && ((EmoClientException) e).getResponse().getStatus() >= 500); }
@Override public BlobMetadata getMetadata(String apiKey, String table, String blobId) throws BlobNotFoundException { checkNotNull(table, "table"); checkNotNull(blobId, "blobId"); try { EmoResponse response = _client.resource(toUri(table, blobId)) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && BlobNotFoundException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { throw new BlobNotFoundException(blobId, new EmoClientException(response)); } else if (response.getStatus() != Response.Status.OK.getStatusCode()) { throw new EmoClientException(response); } return parseMetadataHeaders(blobId, response); } catch (EmoClientException e) { throw convertException(e); } }
@Override public boolean isRetriableException(Exception e) { return (e instanceof EmoClientException && ((EmoClientException) e).getResponse().getStatus() >= 500) || e instanceof JsonStreamingEOFException; }
/** Returns an EmoClientException with a thin wrapper around the Jersey exception response. */ private EmoClientException asEmoClientException(UniformInterfaceException e) throws EmoClientException { throw new EmoClientException(e.getMessage(), e, toEmoResponse(e.getResponse())); }
@Override public boolean isRetriableException(Exception e) { return (e instanceof EmoClientException && ((EmoClientException) e).getResponse().getStatus() >= 500) || e instanceof JsonStreamingEOFException; }
/** Returns an EmoClientException with a thin wrapper around the Jersey exception response. */ private EmoClientException asEmoClientException(UniformInterfaceException e) throws EmoClientException { throw new EmoClientException(e.getMessage(), e, toEmoResponse(e.getResponse())); }
@Override public boolean isRetriableException(Exception e) { return (e instanceof EmoClientException && ((EmoClientException) e).getResponse().getStatus() >= 500) || e instanceof JsonStreamingEOFException; }
/** Returns an EmoClientException with a thin wrapper around the Jersey exception response. */ private EmoClientException asEmoClientException(UniformInterfaceException e) throws EmoClientException { throw new EmoClientException(e.getMessage(), e, toEmoResponse(e.getResponse())); }
@Override public boolean isRetriableException(Exception e) { return (e instanceof EmoClientException && ((EmoClientException) e).getResponse().getStatus() >= 500) || e instanceof JsonStreamingEOFException; }
@Override public boolean getTableExists(String apiKey, String table) { checkNotNull(table, "table"); URI uri = _blobStore.clone() .segment("_table", table) .build(); EmoResponse response = _client.resource(uri) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return true; } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { return false; } else { throw convertException(new EmoClientException(response)); } }
@Override public boolean isRetriableException(Exception e) { return (e instanceof EmoClientException && ((EmoClientException) e).getResponse().getStatus() >= 500); }
@Override public boolean getTableExists(String apiKey, String table) { checkNotNull(table, "table"); URI uri = _dataStore.clone() .segment("_table", table) .build(); EmoResponse response = _client.resource(uri) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return true; } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { return false; } else { throw convertException(new EmoClientException(response)); } }
@Override public void createTable(String apiKey, String table, TableOptions options, Map<String, ?> template, Audit audit) throws TableExistsException { checkNotNull(table, "table"); checkNotNull(options, "options"); checkNotNull(template, "template"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_table", table) .queryParam("options", RisonHelper.asORison(options)) .queryParam("audit", RisonHelper.asORison(audit)) .build(); for (int attempt = 0; ; attempt++) { try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(template); return; } catch (EmoClientException e) { // The SoR returns a 301 response when we need to make this request against a different data center. // Follow the redirect a few times but don't loop forever. if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) { uri = e.getResponse().getLocation(); continue; } throw convertException(e); } } }
@Override public boolean getTableExists(String apiKey, String table) { checkNotNull(table, "table"); URI uri = _dataStore.clone() .segment("_table", table) .build(); EmoResponse response = _client.resource(uri) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return true; } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { return false; } else { throw convertException(new EmoClientException(response)); } }
@Override public void createTable(String apiKey, String table, TableOptions options, Map<String, ?> template, Audit audit) throws TableExistsException { checkNotNull(table, "table"); checkNotNull(options, "options"); checkNotNull(template, "template"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_table", table) .queryParam("options", RisonHelper.asORison(options)) .queryParam("audit", RisonHelper.asORison(audit)) .build(); for (int attempt = 0; ; attempt++) { try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(template); return; } catch (EmoClientException e) { // The SoR returns a 301 response when we need to make this request against a different data center. // Follow the redirect a few times but don't loop forever. if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) { uri = e.getResponse().getLocation(); continue; } throw convertException(e); } } }
@Override public boolean getTableExists(String apiKey, String table) { checkNotNull(table, "table"); URI uri = _blobStore.clone() .segment("_table", table) .build(); EmoResponse response = _client.resource(uri) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return true; } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { return false; } else { throw convertException(new EmoClientException(response)); } }
@Override public void setTableTemplate(String apiKey, String table, Map<String, ?> template, Audit audit) { checkNotNull(table, "table"); checkNotNull(template, "template"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_table", table, "template") .queryParam("audit", RisonHelper.asORison(audit)) .build(); for (int attempt = 0; ; attempt++) { try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(template); return; } catch (EmoClientException e) { // The SoR returns a 301 response when we need to make this request against a different data center. // Follow the redirect a few times but don't loop forever. if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) { uri = e.getResponse().getLocation(); continue; } throw convertException(e); } } }