use of io.hops.hopsworks.exceptions.KafkaException 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;
}
use of io.hops.hopsworks.exceptions.KafkaException in project hopsworks by logicalclocks.
the class KafkaController method updateTopicAcl.
public Integer updateTopicAcl(Project project, String topicName, Integer aclId, AclDTO aclDto) throws KafkaException, ProjectException, UserException {
if (!projectTopicsFacade.findTopicByNameAndProject(project, topicName).isPresent()) {
throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, topicName);
}
TopicAcls ta = topicAclsFacade.find(aclId);
if (ta == null) {
throw new KafkaException(RESTCodes.KafkaErrorCode.ACL_NOT_FOUND, Level.FINE, "topic: " + topicName);
}
// remove previous acl
topicAclsFacade.remove(ta);
// add the new acls
Pair<TopicAcls, Response.Status> aclTuple = addAclsToTopic(topicName, project.getId(), aclDto);
return aclTuple.getLeft().getId();
}
use of io.hops.hopsworks.exceptions.KafkaException in project hopsworks by logicalclocks.
the class KafkaController method acceptSharedTopic.
public void acceptSharedTopic(Project project, String topicName) throws KafkaException, ProjectException, UserException {
ProjectTopics pt = projectTopicsFacade.findTopicByName(topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "topicName: " + topicName));
if (!sharedTopicsFacade.findSharedTopicByProjectAndTopic(project.getId(), topicName).isPresent()) {
throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_SHARED, Level.FINE, "topic: " + topicName + ", project: " + project.getName());
}
addFullPermissionAclsToTopic(project.getName(), topicName, pt.getProject().getId());
sharedTopicsFacade.acceptSharedTopic(pt.getProject().getId(), topicName, project.getId());
}
use of io.hops.hopsworks.exceptions.KafkaException in project hopsworks by logicalclocks.
the class KafkaController method updateTopicSubjectVersion.
public void updateTopicSubjectVersion(Project project, String topic, String subject, Integer version) throws KafkaException, SchemaException {
ProjectTopics pt = projectTopicsFacade.findTopicByNameAndProject(project, topic).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "topic: " + topic));
String topicSubject = pt.getSubjects().getSubject();
Subjects st = subjectsFacade.findSubjectByNameAndVersion(project, subject, version).orElseThrow(() -> new SchemaException(RESTCodes.SchemaRegistryErrorCode.VERSION_NOT_FOUND, Level.FINE, "schema: " + topicSubject + ", version: " + version));
projectTopicsFacade.updateTopicSchemaVersion(pt, st);
}
use of io.hops.hopsworks.exceptions.KafkaException 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