Search in sources :

Example 1 with ClusterImportAlreadyInProgressException

use of com.hortonworks.streamline.common.exception.service.exception.request.ClusterImportAlreadyInProgressException 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)1 ClusterImportAlreadyInProgressException (com.hortonworks.streamline.common.exception.service.exception.request.ClusterImportAlreadyInProgressException)1 Cluster (com.hortonworks.streamline.streams.cluster.catalog.Cluster)1 AmbariServiceNodeDiscoverer (com.hortonworks.streamline.streams.cluster.discovery.ambari.AmbariServiceNodeDiscoverer)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1