use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ApplicationClient method listPrograms.
/**
* Lists all programs belonging to an application.
*
* @param app the application
* @return List of all {@link ProgramRecord}s
* @throws ApplicationNotFoundException if the application with the given ID was not found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<ProgramRecord> listPrograms(ApplicationId app) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s", app.getApplication(), app.getVersion());
URL url = config.resolveNamespacedURLV3(app.getParent(), path);
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ApplicationNotFoundException(app);
}
return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject().getPrograms();
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ApplicationClient method listAllPrograms.
/**
* Lists all programs of a type.
*
* @param programType type of the programs to list
* @return list of {@link ProgramRecord}s
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<ProgramRecord> listAllPrograms(NamespaceId namespace, ProgramType programType) throws IOException, UnauthenticatedException, UnauthorizedException {
Preconditions.checkArgument(programType.isListable());
String path = programType.getCategoryName();
URL url = config.resolveNamespacedURLV3(namespace, path);
HttpRequest request = HttpRequest.get(url).build();
ObjectResponse<List<ProgramRecord>> response = ObjectResponse.fromJsonBody(restClient.execute(request, config.getAccessToken()), new TypeToken<List<ProgramRecord>>() {
});
return response.getResponseObject();
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ApplicationClient method listAppVersions.
/**
* Lists all applications currently deployed, optionally filtering to only include applications that use one of
* the specified artifact names and the specified artifact version.
*
* @param namespace the namespace to list application versions from
* @param appName the application name to list versions for
* @return list of {@link String} application versions.
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<String> listAppVersions(NamespaceId namespace, String appName) throws IOException, UnauthenticatedException, UnauthorizedException, ApplicationNotFoundException {
String path = String.format("apps/%s/versions", appName);
URL url = config.resolveNamespacedURLV3(namespace, path);
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ApplicationNotFoundException(namespace.app(appName));
}
return ObjectResponse.fromJsonBody(response, new TypeToken<List<String>>() {
}).getResponseObject();
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ApplicationClient method deployApp.
private void deployApp(NamespaceId namespace, File jarFile, Map<String, String> headers) throws IOException, UnauthenticatedException {
URL url = config.resolveNamespacedURLV3(namespace, "apps");
HttpRequest request = HttpRequest.post(url).addHeaders(headers).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM).withBody(jarFile).build();
restClient.upload(request, config.getAccessToken());
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class AuthorizationClient method addRoleToPrincipal.
@Override
public void addRoleToPrincipal(Role role, Principal principal) throws IOException, FeatureDisabledException, UnauthenticatedException, UnauthorizedException, RoleNotFoundException, NotFoundException {
URL url = config.resolveURLV3(String.format(AUTHORIZATION_BASE + "%s/%s/roles/%s", principal.getType(), principal.getName(), role.getName()));
HttpRequest request = HttpRequest.put(url).build();
executeExistingRolesRequest(role, request);
}
Aggregations