@Override public RestResponse call() throws Exception { return toHttpResponse.apply(toWebResource(url).put(ClientResponse.class, body)); } });
@Nonnull public ClientResponse createDb( @Nonnull String dbName ) throws UniformInterfaceException, ClientHandlerException { return root.path( dbName ).put( ClientResponse.class ); } }
public void setData(Long id, String data) { getBaseWebResource("data", id).put(data); }
@Override public RestResponse call() throws Exception { return toHttpResponse.apply(toWebResource(url).put(ClientResponse.class, body)); } });
private JSONObject doHttpMethod(WebResource webResource, @Nullable JSONObject postEntity, Method method) { if (postEntity != null) { if (method == Method.POST) { return webResource.post(JSONObject.class, postEntity); } else { return webResource.put(JSONObject.class, postEntity); } } else { if (method == Method.POST) { return webResource.post(JSONObject.class); } else { return webResource.put(JSONObject.class); } } }
private JSONObject doHttpMethod(WebResource webResource, @Nullable JSONObject postEntity, Method method) { if (postEntity != null) { if (method == Method.POST) { return webResource.post(JSONObject.class, postEntity); } else { return webResource.put(JSONObject.class, postEntity); } } else { if (method == Method.POST) { return webResource.post(JSONObject.class); } else { return webResource.put(JSONObject.class); } } }
private void updateLastModified(ObjectType objectType) { WebResource wr = client.resource(UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}/o/{arg3}") .build(region, namespace, bucketName, objectType.group + "/last-modified.json")); wr.accept(MediaType.APPLICATION_JSON_TYPE); try { byte[] bytes = objectMapper.writeValueAsBytes(new LastModified()); wr.put(new String(bytes, StandardCharsets.UTF_8)); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public <T extends Timestamped> void storeObject(ObjectType objectType, String objectKey, T item) { WebResource wr = client.resource(UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}/o/{arg3}") .build(region, namespace, bucketName, buildOSSKey(objectType.group, objectKey, objectType.defaultMetadataFilename))); wr.accept(MediaType.APPLICATION_JSON_TYPE); try { byte[] bytes = objectMapper.writeValueAsBytes(item); wr.put(new String(bytes, StandardCharsets.UTF_8)); } catch (IOException e) { throw new RuntimeException(e); } updateLastModified(objectType); }
@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 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()); }
final WebResource resource = client.resource( url + service ); final ByteArrayInputStream stream = new ByteArrayInputStream( data ); final ClientResponse response = resource.put( ClientResponse.class, stream ); final int status = response.getStatus();
@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()); }
.path("entitylink").path(entityType.getName()).path(projectKey) .queryParam("reciprocate", "false") .put(new JSONObject(data).toString());
@Override public boolean delete( FileName name ) throws FileSystemException { boolean success = false; final RepositoryFileDto file = getFile( name ); try { final WebResource resource = client.resource( url + DELETE_FILE_OR_FOLDER ); final ClientResponse response = resource.put( ClientResponse.class, file.getId() ); if ( response != null && response.getStatus() == Response.Status.OK.getStatusCode() ) { refresh(); success = true; } else { throw new FileSystemException( "Failed with error-code " + response.getStatus() ); } } catch ( Exception e ) { throw new FileSystemException( "Failed", e ); } return success; }
ClientResponse response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); Assert.assertEquals(response.getEntity(String.class), 201, response.getStatus()); String jobId1 = response.getHeaders().getFirst("x-emc-job-id"); response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); Assert.assertEquals(response.getEntity(String.class), 201, response.getStatus()); String jobId2 = response.getHeaders().getFirst("x-emc-job-id"); response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); Assert.assertEquals(response.getEntity(String.class), 201, response.getStatus()); String jobId3 = response.getHeaders().getFirst("x-emc-job-id");
@Test public void testCreateDelete() throws Exception { SyncConfig syncConfig = new SyncConfig(); syncConfig.setSource(new TestConfig().withObjectCount(10).withMaxSize(10240).withDiscardData(false)); syncConfig.setTarget(new TestConfig().withReadData(true).withDiscardData(false)); // create sync job ClientResponse response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); String jobIdStr = response.getHeaders().getFirst("x-emc-job-id"); try { Assert.assertEquals(response.getEntity(String.class), 201, response.getStatus()); response.close(); // must close all responses Assert.assertNotNull(jobIdStr); int jobId = Integer.parseInt(jobIdStr); // wait for job to complete while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000); } // get status (should be complete) JobControl jobControl = client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class); Assert.assertNotNull(jobControl); Assert.assertEquals(JobControlStatus.Complete, jobControl.getStatus()); } finally { // delete job response = client.resource(endpoint).path("/job/" + jobIdStr).delete(ClientResponse.class); if (response.getStatus() != 200) log.warn("could not delete job: {}", response.getEntity(String.class)); response.close(); // must close all responses } }
@Test public void testGetJob() throws Exception { SyncConfig syncConfig = new SyncConfig(); syncConfig.setSource(new TestConfig().withObjectCount(10).withMaxSize(10240).withDiscardData(false)); syncConfig.setTarget(new TestConfig().withReadData(true).withDiscardData(false)); // create sync job ClientResponse response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); String jobId = response.getHeaders().getFirst("x-emc-job-id"); try { Assert.assertEquals(response.getEntity(String.class), 201, response.getStatus()); response.close(); // must close all responses // get job SyncConfig syncConfig2 = client.resource(endpoint).path("/job/" + jobId).get(SyncConfig.class); Assert.assertNotNull(syncConfig2); Assert.assertEquals(syncConfig, syncConfig2); // wait for job to complete while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000); } } finally { // delete job response = client.resource(endpoint).path("/job/" + jobId).delete(ClientResponse.class); if (response.getStatus() != 200) log.warn("could not delete job: {}", response.getEntity(String.class)); response.close(); // must close all responses } }
ClientResponse response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); String jobId = response.getHeaders().getFirst("x-emc-job-id"); try {
ClientResponse response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); String jobId = response.getHeaders().getFirst("x-emc-job-id"); try {
ClientResponse response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); String jobId = response.getHeaders().getFirst("x-emc-job-id");