use of com.hortonworks.streamline.streams.cluster.catalog.Service 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.Service 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);
}
use of com.hortonworks.streamline.streams.cluster.catalog.Service in project streamline by hortonworks.
the class ServiceCatalogResource method removeService.
@DELETE
@Path("/clusters/{clusterId}/services/{id}")
@Timed
public Response removeService(@PathParam("clusterId") Long clusterId, @PathParam("id") Long serviceId, @Context SecurityContext securityContext) {
SecurityUtil.checkPermissions(authorizer, securityContext, Cluster.NAMESPACE, clusterId, WRITE);
Service removedService = environmentService.removeService(serviceId);
if (removedService != null) {
return WSUtils.respondEntity(removedService, OK);
}
throw EntityNotFoundException.byId(serviceId.toString());
}
use of com.hortonworks.streamline.streams.cluster.catalog.Service in project streamline by hortonworks.
the class ServiceCatalogResource method getServiceById.
@GET
@Path("/clusters/{clusterId}/services/{id}")
@Timed
public Response getServiceById(@PathParam("clusterId") Long clusterId, @PathParam("id") Long serviceId, @Context SecurityContext securityContext) {
SecurityUtil.checkPermissions(authorizer, securityContext, Cluster.NAMESPACE, clusterId, READ);
Service result = environmentService.getService(serviceId);
if (result != null) {
if (result.getClusterId() == null || !result.getClusterId().equals(clusterId)) {
throw EntityNotFoundException.byId("cluster: " + clusterId.toString());
}
return WSUtils.respondEntity(result, OK);
}
throw EntityNotFoundException.byId(buildMessageForCompositeId(clusterId, serviceId));
}
use of com.hortonworks.streamline.streams.cluster.catalog.Service in project streamline by hortonworks.
the class EnvironmentService method getService.
public Service getService(Long serviceId) {
Service service = new Service();
service.setId(serviceId);
return this.dao.get(new StorableKey(SERVICE_NAMESPACE, service.getPrimaryKey()));
}
Aggregations