use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.
the class KafkaResource method addAclsToTopic.
@ApiOperation(value = "Add a new ACL for a specified topic.")
@POST
@Path("/topics/{topic}/acls")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response addAclsToTopic(@Context UriInfo uriInfo, @PathParam("topic") String topicName, AclDTO aclDto, @Context SecurityContext sc) throws KafkaException, ProjectException, UserException {
Pair<TopicAcls, Response.Status> aclTuple = kafkaController.addAclsToTopic(topicName, project.getId(), aclDto);
AclDTO dto = aclBuilder.build(uriInfo, aclTuple.getLeft());
return Response.status(aclTuple.getRight()).entity(dto).build();
}
use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.
the class AclBuilder method build.
public AclDTO build(UriInfo uriInfo, Project project, String topicName, ResourceRequest resourceRequest) {
AclDTO dto = new AclDTO();
aclUri(dto, uriInfo, project, topicName);
expand(dto, resourceRequest);
if (dto.isExpand()) {
AbstractFacade.CollectionInfo collectionInfo = topicAclsFacade.findByTopicName(resourceRequest.getOffset(), resourceRequest.getLimit(), resourceRequest.getFilter(), resourceRequest.getSort(), topicName);
dto.setCount(collectionInfo.getCount());
UriBuilder uriBuilder = getAclUri(uriInfo, project, topicName);
collectionInfo.getItems().forEach((acl) -> dto.addItem(build((TopicAcls) acl, uriBuilder)));
}
return dto;
}
use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.
the class AclBuilder method getAclByTopicAndId.
public AclDTO getAclByTopicAndId(UriInfo uriInfo, Project project, String topicName, Integer aclId) throws KafkaException {
AclDTO dto = new AclDTO();
URI uri = getAclUri(uriInfo, project, topicName, aclId).build();
dto.setHref(uri);
Optional<TopicAcls> aclsOptional = kafkaController.findAclByIdAndTopic(topicName, aclId);
if (aclsOptional.isPresent()) {
TopicAcls acl = aclsOptional.get();
dto.setId(acl.getId());
dto.setProjectName(KafkaConst.getProjectNameFromPrincipal(acl.getPrincipal()));
dto.setUserEmail(acl.getUser().getEmail());
dto.setPermissionType(acl.getPermissionType());
dto.setOperationType(acl.getOperationType());
dto.setHost(acl.getHost());
dto.setRole(acl.getRole());
}
return dto;
}
use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.
the class KafkaServingHelper method setupKafkaTopic.
private ProjectTopics setupKafkaTopic(Project project, ServingWrapper servingWrapper) throws KafkaException, UserException, ProjectException, InterruptedException, ExecutionException {
try {
// Check that the user is not trying to create a topic with more replicas than brokers.
if (servingWrapper.getKafkaTopicDTO().getNumOfReplicas() != null && (servingWrapper.getKafkaTopicDTO().getNumOfReplicas() <= 0 || servingWrapper.getKafkaTopicDTO().getNumOfReplicas() > kafkaBrokers.getBrokerEndpoints().size())) {
throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_REPLICATION_ERROR, Level.FINE);
} else if (servingWrapper.getKafkaTopicDTO().getNumOfReplicas() == null) {
// set default value
servingWrapper.getKafkaTopicDTO().setNumOfReplicas(settings.getKafkaDefaultNumReplicas());
}
} catch (IOException | KeeperException | InterruptedException e) {
throw new KafkaException(RESTCodes.KafkaErrorCode.BROKER_METADATA_ERROR, Level.SEVERE, "", e.getMessage(), e);
}
// Check that the user is not trying to create a topic with negative partitions
if (servingWrapper.getKafkaTopicDTO().getNumOfPartitions() != null && servingWrapper.getKafkaTopicDTO().getNumOfPartitions() <= 0) {
throw new KafkaException(RESTCodes.KafkaErrorCode.BAD_NUM_PARTITION, Level.FINE, "less than 0");
} else if (servingWrapper.getKafkaTopicDTO().getNumOfPartitions() == null) {
// set default value
servingWrapper.getKafkaTopicDTO().setNumOfPartitions(settings.getKafkaDefaultNumPartitions());
}
String servingTopicName = getServingTopicName(servingWrapper);
TopicDTO topicDTO = new TopicDTO(servingTopicName, servingWrapper.getKafkaTopicDTO().getNumOfReplicas(), servingWrapper.getKafkaTopicDTO().getNumOfPartitions(), Settings.INFERENCE_SCHEMANAME, Settings.INFERENCE_SCHEMAVERSION);
ProjectTopics pt = kafkaController.createTopicInProject(project, topicDTO);
// Add the ACLs for this topic. By default all users should be able to do everything
for (ProjectTeam projectTeam : project.getProjectTeamCollection()) {
AclDTO aclDto = new AclDTO(project.getName(), projectTeam.getUser().getEmail(), "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD);
kafkaController.addAclsToTopic(topicDTO.getName(), project.getId(), aclDto);
}
return pt;
}
Aggregations