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