Search in sources :

Example 1 with KafkaEndpoint

use of io.hops.hopsworks.dela.old_dto.KafkaEndpoint in project hopsworks by logicalclocks.

the class DelaProjectService method downloadDatasetKafka.

@POST
@Path("/downloads/{publicDSId}/kafka")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response downloadDatasetKafka(@Context HttpServletRequest req, @Context SecurityContext sc, @PathParam("publicDSId") String publicDSId, HopsworksTransferDTO.Download downloadDTO) throws DelaException, ServiceException {
    Users user = jWTHelper.getUserPrincipal(sc);
    Dataset dataset = getDatasetByPublicId(publicDSId);
    String certPath = kafkaController.getKafkaCertPaths(project);
    Optional<String> kafkaBrokerOpt = kafkaBrokers.getAnyKafkaBroker();
    String brokerEndpoint = kafkaBrokerOpt.orElseThrow(() -> new DelaException(RESTCodes.DelaErrorCode.MISCONFIGURED, Level.WARNING, DelaException.Source.KAFKA, "Could not find any active Kafka broker"));
    String restEndpoint;
    try {
        restEndpoint = "https://" + serviceDiscoveryController.constructServiceFQDNWithPort(ServiceDiscoveryController.HopsworksService.HOPSWORKS_APP);
    } catch (ServiceDiscoveryException e) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.SERVICE_NOT_FOUND, Level.SEVERE, "Could not find Hopsworks service");
    }
    String keyStore = certPath + "/keystore.jks";
    String trustStore = certPath + "/truststore.jks";
    KafkaEndpoint kafkaEndpoint = new KafkaEndpoint(brokerEndpoint, restEndpoint, settings.getDELA_DOMAIN(), "" + project.getId(), keyStore, trustStore);
    delaWorkerCtrl.advanceDownload(project, dataset, user, downloadDTO, req.getSession().getId(), kafkaEndpoint);
    return successResponse(new SuccessJSON(""));
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) SuccessJSON(io.hops.hopsworks.dela.old_dto.SuccessJSON) KafkaEndpoint(io.hops.hopsworks.dela.old_dto.KafkaEndpoint) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) Users(io.hops.hopsworks.persistence.entity.user.Users) DelaException(io.hops.hopsworks.exceptions.DelaException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)1 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)1 KafkaEndpoint (io.hops.hopsworks.dela.old_dto.KafkaEndpoint)1 SuccessJSON (io.hops.hopsworks.dela.old_dto.SuccessJSON)1 DelaException (io.hops.hopsworks.exceptions.DelaException)1 ServiceException (io.hops.hopsworks.exceptions.ServiceException)1 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)1 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)1 Users (io.hops.hopsworks.persistence.entity.user.Users)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1