use of com.hortonworks.streamline.streams.cluster.catalog.Cluster in project streamline by hortonworks.
the class ServiceCatalogResource method addOrUpdateService.
@PUT
@Path("/clusters/{clusterId}/services/{id}")
@Timed
public Response addOrUpdateService(@PathParam("clusterId") Long clusterId, @PathParam("id") Long serviceId, Service service, @Context SecurityContext securityContext) {
SecurityUtil.checkPermissions(authorizer, securityContext, Cluster.NAMESPACE, clusterId, WRITE);
// overwrite cluster id to given path param
service.setClusterId(clusterId);
Cluster cluster = environmentService.getCluster(clusterId);
if (cluster == null) {
throw EntityNotFoundException.byId("cluster: " + clusterId.toString());
}
Service newService = environmentService.addOrUpdateService(serviceId, service);
return WSUtils.respondEntity(newService, OK);
}
use of com.hortonworks.streamline.streams.cluster.catalog.Cluster in project streamline by hortonworks.
the class EnvironmentService method importClusterServices.
public Cluster importClusterServices(ServiceNodeDiscoverer serviceNodeDiscoverer, Cluster cluster) throws Exception {
Cluster newCluster = clusterImporter.importCluster(serviceNodeDiscoverer, cluster);
// invalidate all containers' elements which is associated to the cluster
Long clusterId = newCluster.getId();
List<QueryParam> queryParams = Collections.singletonList(new QueryParam("clusterId", String.valueOf(clusterId)));
Set<Long> namespaceIdSet = new HashSet<>();
for (NamespaceServiceClusterMap namespaceServiceClusterMapping : listServiceClusterMapping(queryParams)) {
Long namespaceId = namespaceServiceClusterMapping.getNamespaceId();
namespaceIdSet.add(namespaceId);
}
containers.forEach(container -> {
namespaceIdSet.forEach(container::invalidateInstance);
});
return newCluster;
}
use of com.hortonworks.streamline.streams.cluster.catalog.Cluster in project streamline by hortonworks.
the class ClusterCatalogResource method removeCluster.
@DELETE
@Path("/clusters/{id}")
@Timed
public Response removeCluster(@PathParam("id") Long clusterId, @Context SecurityContext securityContext) {
assertNoNamespaceRefersCluster(clusterId);
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_SERVICE_POOL_SUPER_ADMIN, NAMESPACE, clusterId, DELETE);
// remove all services / service configurations / components / component processes in this cluster
Collection<Service> services = environmentService.listServices(clusterId);
services.forEach(svc -> {
environmentService.listServiceConfigurations(svc.getId()).forEach(sc -> environmentService.removeServiceConfiguration(sc.getId()));
Collection<Component> components = environmentService.listComponents(svc.getId());
components.forEach(component -> {
environmentService.listComponentProcesses(component.getId()).forEach(componentProcess -> environmentService.removeComponentProcess(componentProcess.getId()));
environmentService.removeComponent(component.getId());
});
environmentService.removeService(svc.getId());
});
Cluster removedCluster = environmentService.removeCluster(clusterId);
if (removedCluster != null) {
SecurityUtil.removeAcl(authorizer, securityContext, NAMESPACE, clusterId);
return WSUtils.respondEntity(removedCluster, OK);
}
throw EntityNotFoundException.byId(clusterId.toString());
}
use of com.hortonworks.streamline.streams.cluster.catalog.Cluster in project streamline by hortonworks.
the class ClusterCatalogResource method addOrUpdateCluster.
@PUT
@Path("/clusters/{id}")
@Timed
public Response addOrUpdateCluster(@PathParam("id") Long clusterId, Cluster cluster, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_SERVICE_POOL_SUPER_ADMIN, NAMESPACE, clusterId, WRITE);
Cluster newCluster = environmentService.addOrUpdateCluster(clusterId, cluster);
return WSUtils.respondEntity(newCluster, CREATED);
}
use of com.hortonworks.streamline.streams.cluster.catalog.Cluster 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