@Override public void putPartitionMapping(String graphId, int partitionId, URI location) { if (graphId == null) { throw new IllegalArgumentException(); } if (partitionId == Partition.INVALID_PARTITION) { throw new IllegalArgumentException(); } if (location == null) { throw new IllegalArgumentException(); } WebResource r = _baseResource.path(NameNodeServer.DIRECTORY).path(graphId).path(Integer.toString(partitionId)).queryParam(NameNodeServer.PUT_PARTITION_MAPPING_LOCATION_QP, location.toString()); ClientResponse response = r.put(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { return; } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); }
@Override public void addDataNode(URI dataNode) { if (dataNode == null) { throw new IllegalArgumentException(); } WebResource r = _baseResource.path(NameNodeServer.DATA_NODES).queryParam(NameNodeServer.ADD_DATA_NODE_DATANODE_QP, dataNode.toString()); ClientResponse response = r.put(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { return; } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); }
@Override public void removePartitionMapping(String graphId, int partitionId) { if (graphId == null) { throw new IllegalArgumentException(); } if (partitionId == Partition.INVALID_PARTITION) { throw new IllegalArgumentException(); } WebResource r = _baseResource.path(NameNodeServer.DIRECTORY).path(graphId).path(Integer.toString(partitionId)); ClientResponse response = r.delete(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { return; } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); } }
"Error connecting drill", response .getClientResponseStatus() .toString()))); } else {
"Error connecting drill", response .getClientResponseStatus() .toString())));
@Override public IntCollection getMatchingPartitions(String graphId, URI locationToMatch) { if (graphId == null) { throw new IllegalArgumentException(); } if (locationToMatch == null) { throw new IllegalArgumentException(); } WebResource r = _baseResource.path(NameNodeServer.DIRECTORY).path(graphId).queryParam(NameNodeServer.GET_GRAPH_PARTITIONS_LOCATIONTOMATCH_QP, locationToMatch.toString()); ClientResponse response = r.get(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { JSONArray array = response.getEntity(JSONArray.class); IntArrayList partitions = new IntArrayList(array.length()); try { for (int i = 0; i < array.length(); i++) { partitions.add(array.getInt(i)); } } catch (JSONException e) { throw new IllegalStateException(e); } return partitions; } else if (Status.NOT_FOUND.equals(status)) { return null; } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); }
@Override public IntCollection getPartitions(String graphId) { if (graphId == null) { throw new IllegalArgumentException(); } WebResource r = _baseResource.path(NameNodeServer.DIRECTORY).path(graphId); ClientResponse response = r.get(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { JSONArray array = response.getEntity(JSONArray.class); IntArrayList partitions = new IntArrayList(array.length()); try { for (int i = 0; i < array.length(); i++) { partitions.add(array.getInt(i)); } } catch (JSONException e) { throw new IllegalStateException(e); } return partitions; } else if (Status.NOT_FOUND.equals(status)) { return null; } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); }
@Override public Set<URI> getDataNodes() { WebResource r = _baseResource.path(NameNodeServer.DATA_NODES); ClientResponse response = r.get(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { JSONArray array = response.getEntity(JSONArray.class); try { HashSet<URI> uris = new HashSet<>(array.length(), 1f); for (int i = 0; i < array.length(); i++) { uris.add(URI.create(array.getString(i))); } return uris; } catch (JSONException e) { throw new IllegalStateException(e); } } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); }
@Override public boolean hasPartitionMapping(String graphId, int partitionId) { if (graphId == null) { throw new IllegalArgumentException(); } if (partitionId == Partition.INVALID_PARTITION) { throw new IllegalArgumentException(); } WebResource r = _baseResource.path(NameNodeServer.DIRECTORY).path(graphId).path(Integer.toString(partitionId)); ClientResponse response = r.get(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { return true; } else if (Status.NOT_FOUND.equals(status)) { return false; } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); }
@Override public Collection<String> getGraphs() { WebResource r = _baseResource.path(NameNodeServer.DIRECTORY); ClientResponse response = r.get(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { JSONArray array = response.getEntity(JSONArray.class); ArrayList<String> graphs = new ArrayList<>(array.length()); try { for (int i = 0; i < array.length(); i++) { graphs.add(array.getString(i)); } } catch (JSONException e) { throw new IllegalStateException(e); } return graphs; } throw new RuntimeException(status.toString()); }
@Override public URI getPartitionMapping(String graphId, int partitionId) { if (graphId == null) { throw new IllegalArgumentException(); } if (partitionId == Partition.INVALID_PARTITION) { throw new IllegalArgumentException(); } WebResource r = _baseResource.path(NameNodeServer.DIRECTORY).path(graphId).path(Integer.toString(partitionId)); ClientResponse response = r.get(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { return URI.create(response.getEntity(String.class)); } else if (Status.NOT_FOUND.equals(status)) { return null; } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); }
private synchronized Feed getFeed(URI uri) { WebResource.Builder builder = webResourceProvider.provide(getClient(), uri) .accept(MediaType.APPLICATION_ATOM_XML_TYPE); for (WebResourceBuilderExtension extension : this.extensions) { builder = extension.extend(builder); } ClientResponse clientResponse = builder.get(ClientResponse.class); ClientResponse.Status status = clientResponse.getClientResponseStatus(); switch (status) { case OK: Feed feed = clientResponse.getEntity(Feed.class); loadHRefsFromFeed(feed); return feed; case NO_CONTENT: return null; default: throw new IllegalStateException(status.toString()); } }
@Override public void setSerializer(Class<? extends ISliceSerializer> sliceSerializer) { if (sliceSerializer == null) { throw new IllegalArgumentException(); } WebResource r = _baseResource.path(NameNodeServer.SERIALIZER).queryParam(NameNodeServer.SET_SERIALIZER_SERIALIZERTYPE_QP, sliceSerializer.getName()); ClientResponse response = r.put(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { return; } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); }
private void logErrorMessage(ClientResponse response) throws IOException { LOG.error("Response status={}", response.getClientResponseStatus().toString()); LineIterator it = null; try { it = IOUtils.lineIterator(response.getEntityInputStream(), UTF8); while (it.hasNext()) { String line = it.nextLine(); LOG.error(line); } } finally { if (it != null) { it.close(); } } }
@Override public ISliceSerializer getSerializer() { WebResource r = _baseResource.path(NameNodeServer.SERIALIZER); ClientResponse response = r.get(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { String serializerTypeName = response.getEntity(String.class); try { return SliceSerializerProvider.loadSliceSerializer(serializerTypeName); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } } else if (Status.NOT_FOUND.equals(status)) { return null; } throw new RuntimeException(status.toString()); }
@Override public void clearDataNodes() { WebResource r = _baseResource.path(NameNodeServer.DATA_NODES); ClientResponse response = r.delete(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { return; } throw new RuntimeException(status.toString()); }
/** * Get the reason phrase. * * @return the reason phrase. */ public String getReasonPhrase() { return toString(); }
/** * Get the reason phrase. * * @return the reason phrase. */ public String getReasonPhrase() { return toString(); }
@Override public String getStatusLine() { return bcr.getClientResponseStatus().toString(); }