Search in sources :

Example 1 with SharedTopicsDTO

use of io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO in project hopsworks by logicalclocks.

the class KafkaResource method shareTopic.

@ApiOperation(value = "Share a Kafka topic with a project.")
@PUT
@Path("/topics/{topic}/shared/{destProjectName}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response shareTopic(@PathParam("topic") String topicName, @PathParam("destProjectName") String destProjectName, @Context UriInfo uriInfo, @Context SecurityContext sc) throws KafkaException, ProjectException, UserException {
    URI uri = topicsBuilder.sharedProjectUri(uriInfo, project, topicName).build();
    Integer destProjectId = projectFacade.findByName(destProjectName).getId();
    Optional<SharedTopics> st = sharedTopicsFacade.findSharedTopicByProjectAndTopic(destProjectId, topicName);
    SharedTopicsDTO dto;
    if (st.isPresent()) {
        dto = new SharedTopicsDTO(st.get().getProjectId(), st.get().getSharedTopicsPK());
        dto.setHref(uri);
        return Response.ok(uri).entity(dto).build();
    } else {
        dto = kafkaController.shareTopicWithProject(project, topicName, destProjectId);
        dto.setHref(uri);
        return Response.created(uri).entity(dto).build();
    }
}
Also used : SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) SharedTopicsDTO(io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 2 with SharedTopicsDTO

use of io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO in project hopsworks by logicalclocks.

the class KafkaController method shareTopicWithProject.

public SharedTopicsDTO shareTopicWithProject(Project project, String topicName, Integer destProjectId) throws ProjectException, KafkaException, UserException {
    if (project.getId().equals(destProjectId)) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.DESTINATION_PROJECT_IS_TOPIC_OWNER, Level.FINE);
    }
    if (!projectTopicsFacade.findTopicByNameAndProject(project, topicName).isPresent()) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.PROJECT_IS_NOT_THE_OWNER_OF_THE_TOPIC, Level.FINE);
    }
    if (!projectTopicsFacade.findTopicByNameAndProject(project, topicName).isPresent()) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "topic: " + topicName);
    }
    if (!Optional.ofNullable(projectFacade.find(destProjectId)).isPresent()) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "Could not find project: " + destProjectId);
    }
    sharedTopicsFacade.shareTopic(project, topicName, destProjectId);
    Optional<SharedTopics> optionalSt = sharedTopicsFacade.findSharedTopicByTopicAndProjectIds(topicName, project.getId(), destProjectId);
    SharedTopicsDTO dto = new SharedTopicsDTO();
    optionalSt.ifPresent(st -> {
        dto.setProjectId(st.getProjectId());
        dto.setSharedTopicsPK(st.getSharedTopicsPK());
    });
    return dto;
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) SharedTopicsDTO(io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO) KafkaException(io.hops.hopsworks.exceptions.KafkaException)

Aggregations

SharedTopicsDTO (io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO)2 SharedTopics (io.hops.hopsworks.persistence.entity.kafka.SharedTopics)2 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)1 KafkaException (io.hops.hopsworks.exceptions.KafkaException)1 ProjectException (io.hops.hopsworks.exceptions.ProjectException)1 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)1 ApiOperation (io.swagger.annotations.ApiOperation)1 URI (java.net.URI)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1