Search in sources :

Example 21 with HttpResponder

use of io.cdap.http.HttpResponder in project cdap by caskdata.

the class AppLifecycleHttpHandlerInternal method getAllAppDetails.

/**
 * Get a list of {@link ApplicationDetail} for all applications in the given namespace
 *
 * @param request   {@link HttpRequest}
 * @param responder {@link HttpResponse}
 * @param namespace the namespace to get all application details
 * @throws Exception if namespace doesn't exists or failed to get all application details
 */
@GET
@Path("/apps")
public void getAllAppDetails(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception {
    NamespaceId namespaceId = new NamespaceId(namespace);
    if (!namespaceQueryAdmin.exists(namespaceId)) {
        throw new NamespaceNotFoundException(namespaceId);
    }
    ScanApplicationsRequest scanApplicationsRequest = ScanApplicationsRequest.builder().setNamespaceId(namespaceId).build();
    JsonWholeListResponder.respond(GSON, responder, jsonListResponder -> applicationLifecycleService.scanApplications(scanApplicationsRequest, d -> jsonListResponder.send(d)));
}
Also used : ScanApplicationsRequest(io.cdap.cdap.app.store.ScanApplicationsRequest) NamespaceQueryAdmin(io.cdap.cdap.common.namespace.NamespaceQueryAdmin) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) PathParam(javax.ws.rs.PathParam) HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpResponder(io.cdap.http.HttpResponder) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) GET(javax.ws.rs.GET) Inject(com.google.inject.Inject) Path(javax.ws.rs.Path) ApplicationLifecycleService(io.cdap.cdap.internal.app.services.ApplicationLifecycleService) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) ProgramRuntimeService(io.cdap.cdap.app.runtime.ProgramRuntimeService) File(java.io.File) HttpHandler(io.cdap.http.HttpHandler) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) ScanApplicationsRequest(io.cdap.cdap.app.store.ScanApplicationsRequest) Gson(com.google.gson.Gson) NamespacePathLocator(io.cdap.cdap.common.namespace.NamespacePathLocator) Constants(io.cdap.cdap.common.conf.Constants) HttpResponse(io.netty.handler.codec.http.HttpResponse) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Singleton(com.google.inject.Singleton) AbstractAppFabricHttpHandler(io.cdap.cdap.gateway.handlers.util.AbstractAppFabricHttpHandler) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 22 with HttpResponder

use of io.cdap.http.HttpResponder in project cdap by caskdata.

the class MonitorHandlerAuthorizationTest method testUpdateServiceLogLevelsAuthorization.

@Test
public void testUpdateServiceLogLevelsAuthorization() throws Exception {
    SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
    MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(StandardPermission.UPDATE));
    Map<String, String> bodyArgs = new HashMap<>();
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "/system/services/service/loglevels", Unpooled.copiedBuffer(GSON.toJson(bodyArgs), StandardCharsets.UTF_8));
    HttpResponder responder = mock(HttpResponder.class);
    AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
    try {
        handler.updateServiceLogLevels(request, responder, SERVICE_NAME);
    } catch (UnauthorizedException e) {
    // expected
    }
    AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
    handler.updateServiceLogLevels(request, responder, SERVICE_NAME);
}
Also used : SystemServiceId(io.cdap.cdap.proto.id.SystemServiceId) HttpResponder(io.cdap.http.HttpResponder) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) MonitorHandler(io.cdap.cdap.gateway.handlers.MonitorHandler) HashMap(java.util.HashMap) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) Test(org.junit.Test)

Example 23 with HttpResponder

use of io.cdap.http.HttpResponder in project cdap by caskdata.

the class MonitorHandlerAuthorizationTest method testResetServiceLogLevelsAuthorization.

@Test
public void testResetServiceLogLevelsAuthorization() throws Exception {
    SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
    MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(StandardPermission.UPDATE));
    List<String> bodyArgs = new ArrayList<>();
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "system/services/service/resetloglevels", Unpooled.copiedBuffer(GSON.toJson(bodyArgs), StandardCharsets.UTF_8));
    HttpResponder responder = mock(HttpResponder.class);
    AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
    try {
        handler.resetServiceLogLevels(request, responder, SERVICE_NAME);
    } catch (UnauthorizedException e) {
    // expected
    }
    AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
    handler.resetServiceLogLevels(request, responder, SERVICE_NAME);
}
Also used : SystemServiceId(io.cdap.cdap.proto.id.SystemServiceId) HttpResponder(io.cdap.http.HttpResponder) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) MonitorHandler(io.cdap.cdap.gateway.handlers.MonitorHandler) ArrayList(java.util.ArrayList) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) Test(org.junit.Test)

Example 24 with HttpResponder

use of io.cdap.http.HttpResponder in project cdap by caskdata.

the class MonitorHandlerAuthorizationTest method testRestartServiceInstanceAuthorization.

@Test
public void testRestartServiceInstanceAuthorization() throws Exception {
    SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
    MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(ApplicationPermission.EXECUTE));
    FullHttpRequest request = mock(FullHttpRequest.class);
    HttpResponder responder = mock(HttpResponder.class);
    AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
    try {
        handler.restartServiceInstance(request, responder, SERVICE_NAME, 0);
    } catch (UnauthorizedException e) {
    // expected
    }
    AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
    handler.restartServiceInstance(request, responder, SERVICE_NAME, 0);
}
Also used : SystemServiceId(io.cdap.cdap.proto.id.SystemServiceId) HttpResponder(io.cdap.http.HttpResponder) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) MonitorHandler(io.cdap.cdap.gateway.handlers.MonitorHandler) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) Test(org.junit.Test)

Example 25 with HttpResponder

use of io.cdap.http.HttpResponder in project cdap by caskdata.

the class MonitorHandlerAuthorizationTest method testRestartAllServiceInstancesAuthorization.

@Test
public void testRestartAllServiceInstancesAuthorization() throws Exception {
    SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
    MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(ApplicationPermission.EXECUTE));
    FullHttpRequest request = mock(FullHttpRequest.class);
    HttpResponder responder = mock(HttpResponder.class);
    AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
    try {
        handler.restartAllServiceInstances(request, responder, SERVICE_NAME);
    } catch (UnauthorizedException e) {
    // expected
    }
    AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
    handler.restartAllServiceInstances(request, responder, SERVICE_NAME);
}
Also used : SystemServiceId(io.cdap.cdap.proto.id.SystemServiceId) HttpResponder(io.cdap.http.HttpResponder) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) MonitorHandler(io.cdap.cdap.gateway.handlers.MonitorHandler) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) Test(org.junit.Test)

Aggregations

HttpResponder (io.cdap.http.HttpResponder)28 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)19 BadRequestException (io.cdap.cdap.common.BadRequestException)14 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)14 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)13 IOException (java.io.IOException)13 Path (javax.ws.rs.Path)13 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)12 HttpRequest (io.netty.handler.codec.http.HttpRequest)12 POST (javax.ws.rs.POST)12 Test (org.junit.Test)12 Gson (com.google.gson.Gson)11 JsonObject (com.google.gson.JsonObject)10 JsonSyntaxException (com.google.gson.JsonSyntaxException)10 ConflictException (io.cdap.cdap.common.ConflictException)10 NotFoundException (io.cdap.cdap.common.NotFoundException)10 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)10 NotImplementedException (io.cdap.cdap.common.NotImplementedException)9 MonitorHandler (io.cdap.cdap.gateway.handlers.MonitorHandler)9 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)9