Search in sources :

Example 41 with HttpRequest

use of io.cdap.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();
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL)

Example 42 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class AuthorizationClient method removeRoleFromPrincipal.

@Override
public void removeRoleFromPrincipal(Role role, Principal principal) throws AccessException {
    URL url = resolveURL(String.format(AUTHORIZATION_BASE + "%s/%s/roles/%s", principal.getType(), principal.getName(), role.getName()));
    HttpRequest request = HttpRequest.delete(url).build();
    executeExistingRolesRequest(role, request);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) URL(java.net.URL)

Example 43 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class AuthorizationClient method listRolesHelper.

private Set<Role> listRolesHelper(@Nullable Principal principal) throws AccessException {
    URL url = principal == null ? resolveURL(AUTHORIZATION_BASE + "roles") : resolveURL(String.format(AUTHORIZATION_BASE + "%s/%s/roles", principal.getType(), principal.getName()));
    HttpRequest request = HttpRequest.get(url).build();
    HttpResponse response = doExecuteRequest(request);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return ObjectResponse.fromJsonBody(response, TYPE_OF_ROLE_SET).getResponseObject();
    }
    throw new AccessIOException(String.format("Cannot list roles. Reason: %s", response.getResponseBodyAsString()));
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) AccessIOException(io.cdap.cdap.security.spi.AccessIOException) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL)

Example 44 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class AuthorizationClient method dropRole.

@Override
public void dropRole(Role role) throws AccessException {
    URL url = resolveURL(String.format(AUTHORIZATION_BASE + "roles/%s", role.getName()));
    HttpRequest request = HttpRequest.delete(url).build();
    executeExistingRolesRequest(role, request);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) URL(java.net.URL)

Example 45 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class AuthorizationClient method revoke.

private void revoke(RevokeRequest revokeRequest) throws AccessException {
    URL url = resolveURL(AUTHORIZATION_BASE + "/privileges/revoke");
    HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(revokeRequest)).build();
    executePrivilegeRequest(request);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) URL(java.net.URL)

Aggregations

HttpRequest (io.cdap.common.http.HttpRequest)248 HttpResponse (io.cdap.common.http.HttpResponse)184 URL (java.net.URL)162 Test (org.junit.Test)66 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)28 IOException (java.io.IOException)28 AccessToken (io.cdap.cdap.security.authentication.client.AccessToken)26 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)20 BadRequestException (io.cdap.cdap.common.BadRequestException)18 NotFoundException (io.cdap.cdap.common.NotFoundException)16 TopicNotFoundException (io.cdap.cdap.api.messaging.TopicNotFoundException)10 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)10 ServiceManager (io.cdap.cdap.test.ServiceManager)10 ByteBuffer (java.nio.ByteBuffer)10 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)9 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)8 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)8 TopicId (io.cdap.cdap.proto.id.TopicId)8 ApplicationManager (io.cdap.cdap.test.ApplicationManager)8 HashMap (java.util.HashMap)8