use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class StreamClient method setDescription.
/**
* Sets the description of a stream.
*
* @param stream ID of the stream
* @param description description of the stream
* @throws IOException if a network error occurred
* @throws StreamNotFoundException if the stream with the specified ID was not found
*/
public void setDescription(StreamId stream, String description) throws IOException, StreamNotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(stream.getParent(), String.format("streams/%s/properties", stream.getStream()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(ImmutableMap.of("description", description))).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new StreamNotFoundException(stream);
}
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class StreamViewClient method createOrUpdate.
/**
* Creates or updates a view.
*
* @param id the view
* @param viewSpecification the view config
* @return true if a view was created, false if updated
*/
public boolean createOrUpdate(StreamViewId id, ViewSpecification viewSpecification) throws NotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(id.getParent().getParent(), String.format("streams/%s/views/%s", id.getStream(), id.getView()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(viewSpecification)).build();
HttpResponse response = restClient.execute(request, config.getAccessToken());
return response.getResponseCode() == 201;
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ProgramClient method setWorkerInstances.
/**
* Sets the number of instances that a worker will run on.
*
* @param instances number of instances for the worker to run on
* @throws IOException if a network error occurred
* @throws NotFoundException if the application or worker could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void setWorkerInstances(ProgramId worker, int instances) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(worker.getNamespaceId(), String.format("apps/%s/workers/%s/instances", worker.getApplication(), worker.getProgram()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(new Instances(instances))).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(worker);
}
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ProgramClient method start.
/**
* Starts a batch of programs in the same call.
*
* @param namespace the namespace of the programs
* @param programs the programs to start, including any runtime arguments to start them with
* @return the result of starting each program
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<BatchProgramResult> start(NamespaceId namespace, List<BatchProgramStart> programs) throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(namespace, "start");
HttpRequest request = HttpRequest.builder(HttpMethod.POST, url).withBody(GSON.toJson(programs), Charsets.UTF_8).build();
HttpResponse response = restClient.execute(request, config.getAccessToken());
return ObjectResponse.<List<BatchProgramResult>>fromJsonBody(response, BATCH_RESULTS_TYPE, GSON).getResponseObject();
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class StreamHandlerTest method listStreams.
private List<StreamDetail> listStreams(NamespaceId namespaceId) throws Exception {
URL url = createURL(namespaceId.getNamespace(), "streams");
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = HttpRequests.execute(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NamespaceNotFoundException(namespaceId);
}
Assert.assertEquals(200, response.getResponseCode());
return GSON.fromJson(response.getResponseBodyAsString(), new TypeToken<List<StreamDetail>>() {
}.getType());
}
Aggregations