Search in sources :

Example 11 with ProjectTopics

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

the class KafkaController method unshareTopic.

public void unshareTopic(Project requesterProject, String topicName, String destProjectName) throws ProjectException, KafkaException {
    List<SharedTopics> list = new ArrayList<>();
    Project destProject = projectFacade.findByName(destProjectName);
    // check if topic exists
    ProjectTopics topic = projectTopicsFacade.findTopicByName(topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "Topic:" + topicName));
    // check if requesterProject is the owner of the topic
    if (topic.getProject().equals(requesterProject)) {
        if (destProject == null) {
            list.addAll(sharedTopicsFacade.findSharedTopicsByTopicName(topicName));
        } else {
            SharedTopics st = sharedTopicsFacade.findSharedTopicByProjectAndTopic(destProject.getId(), topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_SHARED, Level.FINE, "topic: " + topicName + ", project: " + destProject.getName()));
            list.add(st);
        }
    } else {
        if (destProject == null) {
            SharedTopics st = sharedTopicsFacade.findSharedTopicByProjectAndTopic(requesterProject.getId(), topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_SHARED, Level.FINE, "topic: " + topicName + ", project: " + requesterProject.getId()));
            list.add(st);
        }
    }
    for (SharedTopics st : list) {
        sharedTopicsFacade.remove(st);
        Project projectACLs = projectFacade.findById(st.getSharedTopicsPK().getProjectId()).orElseThrow(() -> new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "project: " + st.getSharedTopicsPK().getProjectId()));
        topicAclsFacade.removeAclFromTopic(topicName, projectACLs);
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) ArrayList(java.util.ArrayList) KafkaException(io.hops.hopsworks.exceptions.KafkaException)

Example 12 with ProjectTopics

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

the class KafkaController method updateTopicSchemaVersion.

public void updateTopicSchemaVersion(Project project, String topicName, Integer schemaVersion) throws KafkaException {
    ProjectTopics pt = projectTopicsFacade.findTopicByNameAndProject(project, topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "topic: " + topicName));
    String schemaName = pt.getSubjects().getSubject();
    Subjects st = subjectsFacade.findSubjectByNameAndVersion(project, schemaName, schemaVersion).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.SCHEMA_VERSION_NOT_FOUND, Level.FINE, "schema: " + schemaName + ", version: " + schemaVersion));
    projectTopicsFacade.updateTopicSchemaVersion(pt, st);
}
Also used : ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) KafkaException(io.hops.hopsworks.exceptions.KafkaException) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)

Example 13 with ProjectTopics

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

the class KafkaController method createTopicInProject.

public ProjectTopics createTopicInProject(Project project, TopicDTO topicDto) throws KafkaException {
    Subjects schema = subjectsFacade.findSubjectByNameAndVersion(project, topicDto.getSchemaName(), topicDto.getSchemaVersion()).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.SCHEMA_NOT_FOUND, Level.FINE, "topic: " + topicDto.getName()));
    // create the topic in kafka
    try {
        if (createTopicInKafka(topicDto).get(3000, TimeUnit.MILLISECONDS) == null) {
            throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_ALREADY_EXISTS_IN_ZOOKEEPER, Level.INFO, "topic name: " + topicDto.getName());
        }
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_FETCH_FAILED, Level.WARNING, "Topic name: " + topicDto.getName(), e.getMessage(), e);
    }
    /*
     * What is the possibility of the program failing here? The topic is created
     * on
     * zookeeper, but not persisted onto db. User cannot access the topic,
     * cannot
     * create a topic of the same name. In such scenario, the zk timer should
     * remove the topic from zk.
     *
     * One possibility is: schema has a global name space, it is not project
     * specific.
     * While the schema is selected by this topic, it could be deleted by
     * another
     * user. Hence the above schema query will be empty.
     */
    ProjectTopics pt = new ProjectTopics(topicDto.getName(), project, schema);
    projectTopicsFacade.save(pt);
    return pt;
}
Also used : ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) KafkaException(io.hops.hopsworks.exceptions.KafkaException) ExecutionException(java.util.concurrent.ExecutionException) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects) TimeoutException(java.util.concurrent.TimeoutException)

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