Search in sources :

Example 1 with WrappedWebApplicationException

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) WrappedWebApplicationException(com.hortonworks.streamline.common.exception.WrappedWebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) WrappedWebApplicationException(com.hortonworks.streamline.common.exception.WrappedWebApplicationException) AmbariServiceNodeDiscoverer(com.hortonworks.streamline.streams.cluster.discovery.ambari.AmbariServiceNodeDiscoverer) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)1 WrappedWebApplicationException (com.hortonworks.streamline.common.exception.WrappedWebApplicationException)1 AmbariServiceNodeDiscoverer (com.hortonworks.streamline.streams.cluster.discovery.ambari.AmbariServiceNodeDiscoverer)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1