Search in sources :

Example 6 with ProjectTopics

use of io.hops.hopsworks.persistence.entity.kafka.ProjectTopics in project hopsworks by logicalclocks.

the class KafkaServingHelper method setupKafkaServingTopic.

/**
 * Sets up the kafka topic for logging inference requests for models being served on Hopsworks. This kafka topic
 * for logging is setup automatically when updating or creating a model serving instance if the user have specified
 * that option in the configuration of the serving.
 *
 * @param project the project where the serving resides and where the kafka topic is to be created
 * @param servingWrapper the internal representation of the serving instance
 * @param newDbServing the new serving to save in the database (either a new insertion or an update)
 * @param oldDbServing the old serving in the database (in case of an update)
 * @throws KafkaException
 * @throws ProjectException
 * @throws UserException
 * @throws ServiceException
 * @throws ServingException
 */
public void setupKafkaServingTopic(Project project, ServingWrapper servingWrapper, Serving newDbServing, Serving oldDbServing) throws KafkaException, ProjectException, UserException, ServingException, InterruptedException, ExecutionException {
    if (servingWrapper.getKafkaTopicDTO() != null && servingWrapper.getKafkaTopicDTO().getName() != null && servingWrapper.getKafkaTopicDTO().getName().equalsIgnoreCase("NONE")) {
        // The User has decided to not log the serving requests
        newDbServing.setKafkaTopic(null);
    } else if (servingWrapper.getKafkaTopicDTO() != null && servingWrapper.getKafkaTopicDTO().getName() != null && servingWrapper.getKafkaTopicDTO().getName().equalsIgnoreCase("CREATE")) {
        // The user is creating a new Kafka Topic
        ProjectTopics topic = setupKafkaTopic(project, servingWrapper);
        newDbServing.setKafkaTopic(topic);
    } else if (servingWrapper.getKafkaTopicDTO() != null && servingWrapper.getKafkaTopicDTO().getName() != null && !(servingWrapper.getKafkaTopicDTO().getName().equalsIgnoreCase("CREATE") || servingWrapper.getKafkaTopicDTO().getName().equalsIgnoreCase("NONE"))) {
        if (oldDbServing != null && oldDbServing.getKafkaTopic() != null && oldDbServing.getKafkaTopic().getTopicName().equals(servingWrapper.getKafkaTopicDTO().getName())) {
            // This is an update and the topic name hasn't changed.
            newDbServing.setKafkaTopic(oldDbServing.getKafkaTopic());
        } else {
            // The user has selected a an already existing Kafka topic. Check that it matches the schema requirements
            ProjectTopics topic = checkSchemaRequirements(project, servingWrapper);
            newDbServing.setKafkaTopic(topic);
        }
    }
}
Also used : ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics)

Example 7 with ProjectTopics

use of io.hops.hopsworks.persistence.entity.kafka.ProjectTopics 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 8 with ProjectTopics

use of io.hops.hopsworks.persistence.entity.kafka.ProjectTopics 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 9 with ProjectTopics

use of io.hops.hopsworks.persistence.entity.kafka.ProjectTopics 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 10 with ProjectTopics

use of io.hops.hopsworks.persistence.entity.kafka.ProjectTopics in project hopsworks by logicalclocks.

the class KafkaController method removeTopicFromProject.

public void removeTopicFromProject(Project project, String topicName) throws KafkaException {
    ProjectTopics pt = projectTopicsFacade.findTopicByNameAndProject(project, topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "topic: " + topicName));
    // remove from database
    projectTopicsFacade.remove(pt);
    /*
     * What is the possibility of the program failing below? The topic is
     * removed from
     * db, but not yet from zk. *
     * Possibilities:
     * 1. ZkClient is unable to establish a connection, maybe due to timeouts.
     * 2. In case delete.topic.enable is not set to true in the Kafka server
     * configuration, delete topic marks a topic for deletion. Subsequent
     * topic (with the same name) create operation fails.
     */
    // remove from zookeeper
    hopsKafkaAdminClient.deleteTopics(Collections.singleton(pt.getTopicName()));
}
Also used : ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) KafkaException(io.hops.hopsworks.exceptions.KafkaException)

Aggregations

ProjectTopics (io.hops.hopsworks.persistence.entity.kafka.ProjectTopics)13 KafkaException (io.hops.hopsworks.exceptions.KafkaException)9 Subjects (io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)4 ProjectException (io.hops.hopsworks.exceptions.ProjectException)3 Project (io.hops.hopsworks.persistence.entity.project.Project)3 TopicDTO (io.hops.hopsworks.common.dao.kafka.TopicDTO)2 SharedTopics (io.hops.hopsworks.persistence.entity.kafka.SharedTopics)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 KeeperException (org.apache.zookeeper.KeeperException)2 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)1 AclDTO (io.hops.hopsworks.common.dao.kafka.AclDTO)1 SubjectDTO (io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO)1 SchemaException (io.hops.hopsworks.exceptions.SchemaException)1 ServingException (io.hops.hopsworks.exceptions.ServingException)1 UserException (io.hops.hopsworks.exceptions.UserException)1 TopicAcls (io.hops.hopsworks.persistence.entity.kafka.TopicAcls)1 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)1 Users (io.hops.hopsworks.persistence.entity.user.Users)1