Search in sources :

Example 26 with Cluster

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);
}
Also used : Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 27 with Cluster

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;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) HashSet(java.util.HashSet)

Example 28 with Cluster

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());
}
Also used : Service(com.hortonworks.streamline.streams.cluster.catalog.Service) StormMetadataService(com.hortonworks.streamline.streams.cluster.service.metadata.StormMetadataService) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) Component(com.hortonworks.streamline.streams.cluster.catalog.Component) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) DELETE(com.hortonworks.streamline.streams.security.Permission.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 29 with Cluster

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);
}
Also used : Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 30 with Cluster

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

Cluster (com.hortonworks.streamline.streams.cluster.catalog.Cluster)49 Service (com.hortonworks.streamline.streams.cluster.catalog.Service)31 Test (org.junit.Test)30 Config (com.hortonworks.streamline.common.Config)25 ServiceConfiguration (com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration)15 ManualServiceRegistrar (com.hortonworks.streamline.streams.cluster.register.ManualServiceRegistrar)9 InputStream (java.io.InputStream)9 Timed (com.codahale.metrics.annotation.Timed)8 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)8 Path (javax.ws.rs.Path)8 Expectations (mockit.Expectations)8 NamespaceServiceClusterMap (com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)7 Component (com.hortonworks.streamline.streams.cluster.catalog.Component)6 HashMap (java.util.HashMap)5 ComponentProcess (com.hortonworks.streamline.streams.cluster.catalog.ComponentProcess)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Map (java.util.Map)4 POST (javax.ws.rs.POST)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3