use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class ProgramClient method stop.
/**
* Stops a batch of programs in the same call.
*
* @param namespace the namespace of the programs
* @param programs the programs to stop
* @return the result of stopping 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> stop(NamespaceId namespace, List<BatchProgram> programs) throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(namespace, "stop");
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.HttpResponse in project cdap by caskdata.
the class ScheduleClient method getStatus.
public String getStatus(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s/schedules/%s/status", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
URL url = config.resolveNamespacedURLV3(scheduleId.getParent().getParent(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
throw new NotFoundException(scheduleId);
}
Map<String, String> responseObject = ObjectResponse.<Map<String, String>>fromJsonBody(response, MAP_STRING_STRING_TYPE, GSON).getResponseObject();
return responseObject.get("status");
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class ScheduleClient method resume.
public void resume(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s/schedules/%s/resume", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
URL url = config.resolveNamespacedURLV3(scheduleId.toId().getNamespace(), path);
HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
throw new NotFoundException(scheduleId);
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class PreferencesClient method deleteProgramPreferences.
/**
* Deletes Preferences at the Program Level.
*
* @param program Program Id
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ProgramNotFoundException if the requested program is not found
*/
public void deleteProgramPreferences(ProgramId program) throws IOException, UnauthenticatedException, ProgramNotFoundException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(program.getNamespaceId(), String.format("/apps/%s/%s/%s/preferences", program.getApplication(), program.getType().getCategoryName(), program.getProgram()));
HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ProgramNotFoundException(program);
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class PreferencesClient method getInstancePreferences.
/**
* Returns the Preferences stored at the Instance Level.
*
* @return map of key-value pairs
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public Map<String, String> getInstancePreferences() throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveURLV3("preferences");
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() {
}).getResponseObject();
}
Aggregations