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)));
}
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);
}
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);
}
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);
}
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);
}
Aggregations