Search in sources :

Example 16 with ProjectException

use of io.hops.hopsworks.exceptions.ProjectException in project hopsworks by logicalclocks.

the class DatasetController method updateSharePermission.

public void updateSharePermission(Dataset ds, DatasetAccessPermission datasetPermissions, Project project, String targetProjectName, Users user, DistributedFileSystemOps dfso) throws DatasetException, ProjectException {
    if (ds.isShared(project)) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_OWNER_ERROR, Level.FINE);
    }
    if (ds.isPublicDs()) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_PUBLIC_IMMUTABLE, Level.FINE);
    }
    Project targetProject = projectFacade.findByName(targetProjectName);
    if (targetProject == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "Target project not " + "found.");
    }
    DatasetSharedWith datasetSharedWith = datasetSharedWithFacade.findByProjectAndDataset(targetProject, ds);
    if (datasetSharedWith == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_SHARED_WITH_PROJECT, Level.FINE, "project: " + targetProject.getName());
    }
    PermissionTransition permissionTransition = PermissionTransition.valueOf(datasetSharedWith.getPermission(), datasetPermissions);
    updateSharePermission(datasetSharedWith, permissionTransition, project, user, dfso);
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) PermissionTransition(io.hops.hopsworks.persistence.entity.dataset.PermissionTransition) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 17 with ProjectException

use of io.hops.hopsworks.exceptions.ProjectException in project hopsworks by logicalclocks.

the class DatasetController method share.

public void share(String targetProjectName, String fullPath, DatasetAccessPermission permission, Project project, Users user) throws DatasetException, ProjectException {
    Project targetProject = projectFacade.findByName(targetProjectName);
    Dataset ds = getByProjectAndFullPath(project, fullPath);
    if (targetProject == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "Target project not found.");
    }
    DatasetSharedWith datasetSharedWith = shareInternal(targetProject, ds, user, permission);
    if (DatasetType.FEATURESTORE.equals(ds.getDsType()) && datasetSharedWith.getAccepted()) {
        Dataset trainingDataset = getTrainingDataset(project);
        if (trainingDataset != null) {
            try {
                shareInternal(targetProject, trainingDataset, user, permission);
            } catch (DatasetException de) {
            // Dataset already shared nothing to do
            }
        }
        // If we migrate Training Datasets to remove the project prefix, these methods can be reused
        shareFeatureStoreServiceDataset(user, project, targetProject, permission, Settings.ServiceDataset.STATISTICS);
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 18 with ProjectException

use of io.hops.hopsworks.exceptions.ProjectException in project hopsworks by logicalclocks.

the class KafkaController method addFullPermissionAclsToTopic.

private void addFullPermissionAclsToTopic(String aclProjectName, String topicName, Integer projectId) throws ProjectException, KafkaException, UserException {
    Project p = projectFacade.findByName(aclProjectName);
    if (p == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "Could not find project: " + aclProjectName);
    }
    List<AclDTO> acls = p.getProjectTeamCollection().stream().map(member -> member.getUser().getEmail()).map(email -> new AclDTO(p.getName(), email, "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD)).collect(Collectors.toList());
    for (AclDTO acl : acls) {
        addAclsToTopic(topicName, projectId, acl);
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) SubjectDTO(io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO) TimeoutException(java.util.concurrent.TimeoutException) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) Settings(io.hops.hopsworks.common.util.Settings) TransactionAttributeType(javax.ejb.TransactionAttributeType) Pair(org.apache.commons.lang3.tuple.Pair) SharedTopicsDTO(io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO) Map(java.util.Map) SubjectsFacade(io.hops.hopsworks.common.dao.kafka.schemas.SubjectsFacade) ProjectException(io.hops.hopsworks.exceptions.ProjectException) Stateless(javax.ejb.Stateless) Set(java.util.Set) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) KafkaFuture(org.apache.kafka.common.KafkaFuture) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) TopicAclsFacade(io.hops.hopsworks.common.dao.kafka.TopicAclsFacade) ProjectController(io.hops.hopsworks.common.project.ProjectController) HopsKafkaAdminClient(io.hops.hopsworks.common.dao.kafka.HopsKafkaAdminClient) TopicDefaultValueDTO(io.hops.hopsworks.common.dao.kafka.TopicDefaultValueDTO) List(java.util.List) Response(javax.ws.rs.core.Response) UserCerts(io.hops.hopsworks.persistence.entity.certificates.UserCerts) AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO) Optional(java.util.Optional) Node(org.apache.kafka.common.Node) KafkaException(io.hops.hopsworks.exceptions.KafkaException) ProjectFacade(io.hops.hopsworks.common.dao.project.ProjectFacade) SharedProjectDTO(io.hops.hopsworks.common.dao.kafka.SharedProjectDTO) UserFacade(io.hops.hopsworks.common.dao.user.UserFacade) AclUser(io.hops.hopsworks.common.dao.kafka.AclUser) HashMap(java.util.HashMap) CertsFacade(io.hops.hopsworks.common.dao.certificates.CertsFacade) Project(io.hops.hopsworks.persistence.entity.project.Project) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ProjectTopicsFacade(io.hops.hopsworks.common.dao.kafka.ProjectTopicsFacade) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) TransactionAttribute(javax.ejb.TransactionAttribute) CreateTopicsResult(org.apache.kafka.clients.admin.CreateTopicsResult) EJB(javax.ejb.EJB) TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) KeeperException(org.apache.zookeeper.KeeperException) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) KafkaConst(io.hops.hopsworks.common.dao.kafka.KafkaConst) TopicAcls(io.hops.hopsworks.persistence.entity.kafka.TopicAcls) NewTopic(org.apache.kafka.clients.admin.NewTopic) FileOutputStream(java.io.FileOutputStream) SchemaException(io.hops.hopsworks.exceptions.SchemaException) IOException(java.io.IOException) SharedTopicsFacade(io.hops.hopsworks.common.dao.kafka.SharedTopicsFacade) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) PartitionDetailsDTO(io.hops.hopsworks.common.dao.kafka.PartitionDetailsDTO) File(java.io.File) UserException(io.hops.hopsworks.exceptions.UserException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects) Users(io.hops.hopsworks.persistence.entity.user.Users) Comparator(java.util.Comparator) Collections(java.util.Collections) Project(io.hops.hopsworks.persistence.entity.project.Project) AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO)

Example 19 with ProjectException

use of io.hops.hopsworks.exceptions.ProjectException in project hopsworks by logicalclocks.

the class KafkaController method getSubjectForTopic.

public SubjectDTO getSubjectForTopic(Project project, String topic) throws KafkaException, ProjectException {
    Optional<ProjectTopics> pt = projectTopicsFacade.findTopicByNameAndProject(project, topic);
    if (!pt.isPresent()) {
        SharedTopics sharedTopic = sharedTopicsFacade.findSharedTopicByProjectAndTopic(project.getId(), topic).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_SHARED, Level.FINE, "topic: " + topic + ", project: " + project.getName()));
        Project sharedWithProject = projectFacade.findById(sharedTopic.getProjectId()).orElseThrow(() -> new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "projectId: " + sharedTopic.getSharedTopicsPK().getProjectId()));
        pt = projectTopicsFacade.findTopicByNameAndProject(sharedWithProject, topic);
    }
    if (!pt.isPresent()) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "project=" + project.getName() + ", topic=" + topic);
    }
    return new SubjectDTO(pt.get().getSubjects());
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) SubjectDTO(io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) KafkaException(io.hops.hopsworks.exceptions.KafkaException)

Example 20 with ProjectException

use of io.hops.hopsworks.exceptions.ProjectException in project hopsworks by logicalclocks.

the class KafkaController method addAclsToTopic.

private Pair<TopicAcls, Response.Status> addAclsToTopic(String topicName, Integer projectId, String selectedProjectName, String userEmail, String permissionType, String operationType, String host, String role) throws ProjectException, KafkaException, UserException {
    if (Strings.isNullOrEmpty(topicName) || userEmail == null) {
        throw new IllegalArgumentException("Topic and userEmail must be provided.");
    }
    // get the project id
    Project topicOwnerProject = Optional.ofNullable(projectFacade.find(projectId)).orElseThrow(() -> new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "projectId: " + projectId));
    if (!topicOwnerProject.getName().equals(selectedProjectName)) {
        if (projectFacade.findByName(selectedProjectName) == null) {
            throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "The specified project " + "for the topic" + topicName + " was not found");
        }
    }
    ProjectTopics pt = projectTopicsFacade.findTopicByNameAndProject(topicOwnerProject, topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "Topic: " + topicName));
    // should not be able to create multiple ACLs at the same time
    if (userEmail.equals("*")) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.ACL_FOR_ANY_USER, Level.FINE, "topic: " + topicName);
    }
    // fetch the user name from database
    Users user = Optional.ofNullable(userFacade.findByEmail(userEmail)).orElseThrow(() -> new UserException(RESTCodes.UserErrorCode.USER_WAS_NOT_FOUND, Level.FINE, "user: " + userEmail));
    String principalName = KafkaConst.buildPrincipalName(selectedProjectName, user.getUsername());
    Optional<TopicAcls> optionalAcl = topicAclsFacade.getTopicAcls(topicName, principalName, permissionType, operationType, host, role);
    if (optionalAcl.isPresent()) {
        return Pair.of(optionalAcl.get(), Response.Status.OK);
    }
    TopicAcls acl = topicAclsFacade.addAclsToTopic(pt, user, permissionType, operationType, host, role, principalName);
    return Pair.of(acl, Response.Status.CREATED);
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) TopicAcls(io.hops.hopsworks.persistence.entity.kafka.TopicAcls) KafkaException(io.hops.hopsworks.exceptions.KafkaException) Users(io.hops.hopsworks.persistence.entity.user.Users) UserException(io.hops.hopsworks.exceptions.UserException)

Aggregations

ProjectException (io.hops.hopsworks.exceptions.ProjectException)62 Project (io.hops.hopsworks.persistence.entity.project.Project)43 IOException (java.io.IOException)19 Produces (javax.ws.rs.Produces)19 Users (io.hops.hopsworks.persistence.entity.user.Users)17 Path (javax.ws.rs.Path)17 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)12 DatasetException (io.hops.hopsworks.exceptions.DatasetException)12 GenericException (io.hops.hopsworks.exceptions.GenericException)12 ServiceException (io.hops.hopsworks.exceptions.ServiceException)11 JupyterProject (io.hops.hopsworks.persistence.entity.jupyter.JupyterProject)11 KafkaException (io.hops.hopsworks.exceptions.KafkaException)10 UserException (io.hops.hopsworks.exceptions.UserException)10 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)10 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)9 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)7 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)7 POST (javax.ws.rs.POST)7