use of com.hortonworks.streamline.common.exception.WrappedWebApplicationException in project streamline by hortonworks.
the class ClusterCatalogResource method verifyAmbariUrl.
@POST
@Path("/cluster/import/ambari/verify/url")
@Timed
public Response verifyAmbariUrl(AmbariClusterImportParams params, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_SERVICE_POOL_ADMIN);
// Not assigning to interface to apply a hack
AmbariServiceNodeDiscoverer discoverer = new AmbariServiceNodeDiscoverer(params.getAmbariRestApiRootUrl(), params.getUsername(), params.getPassword());
Map<String, Object> response;
try {
discoverer.init(null);
discoverer.validateApiUrl();
response = Collections.singletonMap(VERIFIED, true);
return WSUtils.respondEntity(response, OK);
} catch (WrappedWebApplicationException e) {
Response resp = e.getResponse();
Throwable cause = e.getCause();
if (cause == null || !(cause instanceof WebApplicationException)) {
response = Collections.singletonMap(RESPONSE_MESSAGE, e.getMessage());
} else {
String message = getMessageFromAmbariAPIResponse(cause);
response = Collections.singletonMap(RESPONSE_MESSAGE, message);
}
return WSUtils.respondEntity(response, Response.Status.fromStatusCode(resp.getStatus()));
} catch (Throwable e) {
// other exceptions
response = Collections.singletonMap(RESPONSE_MESSAGE, e.getMessage());
return WSUtils.respondEntity(response, INTERNAL_SERVER_ERROR);
}
}
Aggregations