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