Search in sources :

Example 11 with KafkaException

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;
}
Also used : ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO) KafkaException(io.hops.hopsworks.exceptions.KafkaException) TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 12 with KafkaException

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();
}
Also used : TopicAcls(io.hops.hopsworks.persistence.entity.kafka.TopicAcls) KafkaException(io.hops.hopsworks.exceptions.KafkaException)

Example 13 with KafkaException

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());
}
Also used : ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) KafkaException(io.hops.hopsworks.exceptions.KafkaException)

Example 14 with KafkaException

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);
}
Also used : SchemaException(io.hops.hopsworks.exceptions.SchemaException) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) KafkaException(io.hops.hopsworks.exceptions.KafkaException) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)

Example 15 with KafkaException

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;
}
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

KafkaException (io.hops.hopsworks.exceptions.KafkaException)20 ProjectTopics (io.hops.hopsworks.persistence.entity.kafka.ProjectTopics)10 ProjectException (io.hops.hopsworks.exceptions.ProjectException)8 SchemaException (io.hops.hopsworks.exceptions.SchemaException)7 Project (io.hops.hopsworks.persistence.entity.project.Project)6 IOException (java.io.IOException)6 ExecutionException (java.util.concurrent.ExecutionException)6 UserException (io.hops.hopsworks.exceptions.UserException)5 Subjects (io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)5 SharedTopics (io.hops.hopsworks.persistence.entity.kafka.SharedTopics)4 TopicAcls (io.hops.hopsworks.persistence.entity.kafka.TopicAcls)4 ArrayList (java.util.ArrayList)4 DatasetException (io.hops.hopsworks.exceptions.DatasetException)3 ElasticException (io.hops.hopsworks.exceptions.ElasticException)3 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)3 GenericException (io.hops.hopsworks.exceptions.GenericException)3 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)3 JobException (io.hops.hopsworks.exceptions.JobException)3 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)3 ServiceException (io.hops.hopsworks.exceptions.ServiceException)3