use of io.hops.hopsworks.common.dao.kafka.TopicDTO in project hopsworks by logicalclocks.
the class KafkaResource method getTopics.
@ApiOperation(value = "Retrieve Kafka topics metadata .")
@GET
@Path("/topics")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTopics(@Context UriInfo uriInfo, @BeanParam Pagination pagination, @BeanParam TopicsBeanParam topicsBeanParam, @Context SecurityContext sc) {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.KAFKA);
resourceRequest.setOffset(pagination.getOffset());
resourceRequest.setLimit(pagination.getLimit());
resourceRequest.setSort(topicsBeanParam.getSortBySet());
resourceRequest.setFilter(topicsBeanParam.getFilter());
TopicDTO dto = topicsBuilder.build(uriInfo, resourceRequest, project);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.dao.kafka.TopicDTO in project hopsworks by logicalclocks.
the class TopicsBuilder method build.
public TopicDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project project) {
URI href = uriInfo.getBaseUriBuilder().path(ResourceRequest.Name.KAFKA.toString().toLowerCase()).path(Integer.toString(project.getId())).path(ResourceRequest.Name.KAFKA.toString().toLowerCase()).path(ResourceRequest.Name.TOPICS.toString().toLowerCase()).build();
TopicDTO dto = new TopicDTO();
dto.setHref(href);
expand(dto, resourceRequest);
if (dto.isExpand()) {
List<TopicDTO> list = buildItems(project, resourceRequest);
dto.setCount(Integer.toUnsignedLong(list.size()));
list.forEach(topic -> dto.addItem(build(uriInfo, resourceRequest, topic, project)));
}
return dto;
}
use of io.hops.hopsworks.common.dao.kafka.TopicDTO in project hopsworks by logicalclocks.
the class KafkaController method addProjectMemberToTopics.
/**
* Add a new project member to all project's Kafka topics.
*
* @param project
* @param member
*/
public void addProjectMemberToTopics(Project project, String member) throws KafkaException, ProjectException, UserException {
// Get all topics (shared with project as well)
List<TopicDTO> topics = findTopicsByProject(project);
List<SharedTopics> sharedTopics = sharedTopicsFacade.findSharedTopicsByProject(project.getId());
// For every topic that has been shared with the current project, add the new member to its ACLs
for (SharedTopics sharedTopic : sharedTopics) {
addAclsToTopic(sharedTopic.getSharedTopicsPK().getTopicName(), sharedTopic.getProjectId(), new AclDTO(project.getName(), member, "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD));
}
// Iterate over topics and add user to ACLs
for (TopicDTO topic : topics) {
addAclsToTopic(topic.getName(), project.getId(), new AclDTO(project.getName(), member, "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD));
}
}
use of io.hops.hopsworks.common.dao.kafka.TopicDTO in project hopsworks by logicalclocks.
the class KafkaController method findTopicsByProject.
public List<TopicDTO> findTopicsByProject(Project project) {
List<ProjectTopics> ptList = projectTopicsFacade.findTopicsByProject(project);
List<TopicDTO> topics = new ArrayList<>();
for (ProjectTopics pt : ptList) {
topics.add(new TopicDTO(pt.getTopicName(), pt.getSubjects().getSubject(), pt.getSubjects().getVersion(), false));
}
return topics;
}
use of io.hops.hopsworks.common.dao.kafka.TopicDTO in project hopsworks by logicalclocks.
the class TopicsBuilder method sortTopics.
@Override
protected List<TopicDTO> sortTopics(List<TopicDTO> list, Set<? extends AbstractFacade.SortBy> sortBySet) {
Iterator<? extends AbstractFacade.SortBy> it = sortBySet.iterator();
Comparator<TopicDTO> comparator = null;
while (it.hasNext()) {
AbstractFacade.SortBy sort = it.next();
Comparator order = sort.getParam().getValue().equals("DESC") ? Comparator.reverseOrder() : Comparator.naturalOrder();
switch(ProjectTopicsFacade.TopicsSorts.valueOf(sort.getValue())) {
case NAME:
if (comparator == null) {
comparator = Comparator.comparing(TopicDTO::getName, order);
} else {
comparator = comparator.thenComparing(TopicDTO::getName, order);
}
break;
case SCHEMA_NAME:
if (comparator == null) {
comparator = Comparator.comparing(TopicDTO::getSchemaName, order);
} else {
comparator = comparator.thenComparing(TopicDTO::getSchemaName, order);
}
break;
}
}
if (comparator != null) {
list.sort(comparator);
}
return list;
}
Aggregations