Search in sources :

Example 1 with Cluster

use of com.hortonworks.streamline.streams.cluster.catalog.Cluster in project streamline by hortonworks.

the class AbstractBundleHintProvider method provide.

@Override
public Map<Long, BundleHintsResponse> provide(Namespace namespace, SecurityContext securityContext, Subject subject) {
    Map<Long, BundleHintsResponse> hintMap = new HashMap<>();
    Collection<NamespaceServiceClusterMap> serviceMappings = environmentService.listServiceClusterMapping(namespace.getId(), getServiceName());
    for (NamespaceServiceClusterMap mapping : serviceMappings) {
        Long clusterId = mapping.getClusterId();
        Cluster cluster = environmentService.getCluster(clusterId);
        if (cluster == null) {
            throw new RuntimeException(new ClusterNotFoundException(clusterId));
        }
        BundleHintsResponse response = new BundleHintsResponse(cluster, getHintsOnCluster(cluster, securityContext, subject));
        hintMap.put(clusterId, response);
    }
    return hintMap;
}
Also used : ClusterNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ClusterNotFoundException) HashMap(java.util.HashMap) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)

Example 2 with Cluster

use of com.hortonworks.streamline.streams.cluster.catalog.Cluster in project streamline by hortonworks.

the class AbstractSecureBundleHintProvider method provide.

@Override
public Map<Long, BundleHintsResponse> provide(Namespace namespace, SecurityContext securityContext, Subject subject) {
    Map<Long, BundleHintsResponse> hintMap = new HashMap<>();
    Collection<NamespaceServiceClusterMap> serviceMappings = environmentService.listServiceClusterMapping(namespace.getId(), getServiceName());
    for (NamespaceServiceClusterMap mapping : serviceMappings) {
        Long clusterId = mapping.getClusterId();
        Cluster cluster = environmentService.getCluster(clusterId);
        if (cluster == null) {
            throw new RuntimeException(new ClusterNotFoundException(clusterId));
        }
        BundleHintsResponse response = new SecureBundleHintsResponse(cluster, getSecurity(cluster, securityContext, subject), getHintsOnCluster(cluster, securityContext, subject));
        hintMap.put(clusterId, response);
    }
    return hintMap;
}
Also used : ClusterNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ClusterNotFoundException) HashMap(java.util.HashMap) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)

Example 3 with Cluster

use of com.hortonworks.streamline.streams.cluster.catalog.Cluster in project streamline by hortonworks.

the class NamespaceAwareContainer method getServiceForNamespace.

protected Collection<Service> getServiceForNamespace(Namespace namespace, String serviceName) {
    Collection<NamespaceServiceClusterMap> serviceClusterMappings = environmentService.listServiceClusterMapping(namespace.getId(), serviceName);
    if (serviceClusterMappings == null) {
        throw new RuntimeException("Service name " + serviceName + " is not set in namespace " + namespace.getName() + "(" + namespace.getId() + ")");
    }
    Collection<Service> services = new ArrayList<>(serviceClusterMappings.size());
    for (NamespaceServiceClusterMap mapping : serviceClusterMappings) {
        Long clusterId = mapping.getClusterId();
        Cluster cluster = environmentService.getCluster(clusterId);
        if (cluster == null) {
            throw new RuntimeException("Cluster " + clusterId + " is not found");
        }
        Service service = environmentService.getServiceByName(clusterId, serviceName);
        if (service == null) {
            throw new RuntimeException("Service name " + serviceName + " is not found in Cluster " + clusterId);
        }
        services.add(service);
    }
    return services;
}
Also used : ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)

Example 4 with Cluster

use of com.hortonworks.streamline.streams.cluster.catalog.Cluster in project streamline by hortonworks.

the class ServiceCatalogResource method registerService.

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/clusters/{clusterId}/services/register/{serviceName}")
@Timed
public Response registerService(@PathParam("clusterId") Long clusterId, @PathParam("serviceName") String serviceName, FormDataMultiPart form) {
    ServiceBundle serviceBundle = environmentService.getServiceBundleByName(serviceName);
    if (serviceBundle == null) {
        throw BadRequestException.message("Not supported service: " + serviceName);
    }
    ManualServiceRegistrar registrar;
    try {
        Class<?> clazz = Class.forName(serviceBundle.getRegisterClass());
        registrar = (ManualServiceRegistrar) clazz.newInstance();
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
        throw new RuntimeException(e);
    }
    Cluster cluster = environmentService.getCluster(clusterId);
    if (cluster == null) {
        throw EntityNotFoundException.byId("Cluster " + clusterId);
    }
    Service service = environmentService.getServiceByName(clusterId, serviceName);
    if (service != null) {
        throw EntityAlreadyExistsException.byName("Service " + serviceName + " is already exist in Cluster " + clusterId);
    }
    registrar.init(environmentService);
    ComponentUISpecification specification = serviceBundle.getServiceUISpecification();
    List<String> fileFieldNames = specification.getFields().stream().filter(uiField -> uiField.getType().equals(ComponentUISpecification.UIFieldType.FILE)).map(uiField -> uiField.getFieldName()).collect(toList());
    Map<String, List<FormDataBodyPart>> fields = form.getFields();
    List<FormDataBodyPart> cfgFormList = fields.getOrDefault("config", Collections.emptyList());
    Config config;
    if (!cfgFormList.isEmpty()) {
        String jsonConfig = cfgFormList.get(0).getEntityAs(String.class);
        try {
            config = objectMapper.readValue(jsonConfig, Config.class);
        } catch (IOException e) {
            throw BadRequestException.message("config is missing");
        }
    } else {
        config = new Config();
    }
    List<ManualServiceRegistrar.ConfigFileInfo> configFileInfos = fields.entrySet().stream().filter(entry -> fileFieldNames.contains(entry.getKey())).flatMap(entry -> {
        String key = entry.getKey();
        List<FormDataBodyPart> values = entry.getValue();
        return values.stream().map(val -> new ManualServiceRegistrar.ConfigFileInfo(key, val.getEntityAs(InputStream.class)));
    }).collect(toList());
    try {
        Service registeredService = registrar.register(cluster, config, configFileInfos);
        return WSUtils.respondEntity(buildManualServiceRegisterResult(registeredService), CREATED);
    } catch (IllegalArgumentException e) {
        throw BadRequestException.message(e.getMessage());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Produces(javax.ws.rs.Produces) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) QueryParam(com.hortonworks.registries.common.QueryParam) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ComponentUISpecification(com.hortonworks.streamline.common.ComponentUISpecification) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) WSUtils(com.hortonworks.streamline.common.util.WSUtils) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) READ(com.hortonworks.streamline.streams.security.Permission.READ) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) DELETE(javax.ws.rs.DELETE) Config(com.hortonworks.streamline.common.Config) SecurityUtil(com.hortonworks.streamline.streams.security.SecurityUtil) Context(javax.ws.rs.core.Context) ServiceWithComponents(com.hortonworks.streamline.streams.cluster.model.ServiceWithComponents) OK(javax.ws.rs.core.Response.Status.OK) Collection(java.util.Collection) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) CREATED(javax.ws.rs.core.Response.Status.CREATED) PathParam(javax.ws.rs.PathParam) EntityNotFoundException(com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException) GET(javax.ws.rs.GET) ServiceBundle(com.hortonworks.streamline.streams.cluster.catalog.ServiceBundle) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) WRITE(com.hortonworks.streamline.streams.security.Permission.WRITE) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) EntityAlreadyExistsException(com.hortonworks.streamline.common.exception.service.exception.request.EntityAlreadyExistsException) Component(com.hortonworks.streamline.streams.cluster.catalog.Component) ManualServiceRegistrar(com.hortonworks.streamline.streams.cluster.register.ManualServiceRegistrar) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Collectors.toList(java.util.stream.Collectors.toList) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) InputStream(java.io.InputStream) Config(com.hortonworks.streamline.common.Config) InputStream(java.io.InputStream) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) IOException(java.io.IOException) ManualServiceRegistrar(com.hortonworks.streamline.streams.cluster.register.ManualServiceRegistrar) ServiceBundle(com.hortonworks.streamline.streams.cluster.catalog.ServiceBundle) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) ComponentUISpecification(com.hortonworks.streamline.common.ComponentUISpecification) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed)

Example 5 with Cluster

use of com.hortonworks.streamline.streams.cluster.catalog.Cluster in project streamline by hortonworks.

the class ServiceCatalogResource method addService.

@Timed
@POST
@Path("/clusters/{clusterId}/services")
public Response addService(@PathParam("clusterId") Long clusterId, 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());
    }
    String serviceName = service.getName();
    Service result = environmentService.getServiceByName(clusterId, serviceName);
    if (result != null) {
        throw EntityAlreadyExistsException.byName("cluster id " + clusterId + " and service name " + serviceName);
    }
    Service createdService = environmentService.addService(service);
    return WSUtils.respondEntity(createdService, CREATED);
}
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) 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