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