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