Search in sources :

Example 1 with AmbariServiceNodeDiscoverer

use of com.hortonworks.streamline.streams.cluster.discovery.ambari.AmbariServiceNodeDiscoverer 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)

Example 2 with AmbariServiceNodeDiscoverer

use of com.hortonworks.streamline.streams.cluster.discovery.ambari.AmbariServiceNodeDiscoverer in project streamline by hortonworks.

the class ClusterCatalogResource method importServicesFromAmbari.

@POST
@Path("/cluster/import/ambari")
@Timed
public Response importServicesFromAmbari(AmbariClusterImportParams params, @Context SecurityContext securityContext) throws Exception {
    Long clusterId = params.getClusterId();
    if (clusterId == null) {
        throw BadRequestException.missingParameter("clusterId");
    }
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_SERVICE_POOL_SUPER_ADMIN, NAMESPACE, clusterId, WRITE, EXECUTE);
    Cluster retrievedCluster = environmentService.getCluster(clusterId);
    if (retrievedCluster == null) {
        throw EntityNotFoundException.byId(String.valueOf(clusterId));
    }
    boolean acquired = false;
    try {
        synchronized (importInProgressCluster) {
            if (importInProgressCluster.contains(clusterId)) {
                throw new ClusterImportAlreadyInProgressException(String.valueOf(clusterId));
            }
            importInProgressCluster.add(clusterId);
            acquired = true;
        }
        // Not assigning to interface to apply a hack
        AmbariServiceNodeDiscoverer discoverer = new AmbariServiceNodeDiscoverer(params.getAmbariRestApiRootUrl(), params.getUsername(), params.getPassword());
        discoverer.init(null);
        retrievedCluster = environmentService.importClusterServices(discoverer, retrievedCluster);
        injectStormViewAsStormConfiguration(clusterId, discoverer);
        ClusterResourceUtil.ClusterServicesImportResult result = ClusterResourceUtil.enrichCluster(retrievedCluster, environmentService);
        return WSUtils.respondEntity(result, OK);
    } finally {
        if (acquired) {
            synchronized (importInProgressCluster) {
                importInProgressCluster.remove(clusterId);
            }
        }
    }
}
Also used : Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) ClusterImportAlreadyInProgressException(com.hortonworks.streamline.common.exception.service.exception.request.ClusterImportAlreadyInProgressException) 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)2 AmbariServiceNodeDiscoverer (com.hortonworks.streamline.streams.cluster.discovery.ambari.AmbariServiceNodeDiscoverer)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 WrappedWebApplicationException (com.hortonworks.streamline.common.exception.WrappedWebApplicationException)1 ClusterImportAlreadyInProgressException (com.hortonworks.streamline.common.exception.service.exception.request.ClusterImportAlreadyInProgressException)1 Cluster (com.hortonworks.streamline.streams.cluster.catalog.Cluster)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1