Search in sources :

Example 1 with KafkaException

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

the class ProjectService method example.

@POST
@Path("starterProject/{type}")
@Produces(MediaType.APPLICATION_JSON)
public Response example(@PathParam("type") String type, @Context HttpServletRequest req, @Context SecurityContext sc) throws DatasetException, GenericException, KafkaException, ProjectException, UserException, ServiceException, HopsSecurityException, FeaturestoreException, JobException, IOException, ElasticException, SchemaException, ProvenanceException {
    TourProjectType demoType;
    try {
        demoType = TourProjectType.fromString(type);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Type must be one of: " + Arrays.toString(TourProjectType.values()));
    }
    ProjectDTO projectDTO = new ProjectDTO();
    Project project = null;
    projectDTO.setDescription("A demo project for getting started with " + demoType.getDescription());
    Users user = jWTHelper.getUserPrincipal(sc);
    String username = user.getUsername();
    List<String> projectServices = new ArrayList<>();
    // save the project
    String readMeMessage = null;
    switch(demoType) {
        case KAFKA:
            // It's a Kafka guide
            projectDTO.setProjectName("demo_" + TourProjectType.KAFKA.getTourName() + "_" + username);
            populateActiveServices(projectServices, TourProjectType.KAFKA);
            readMeMessage = "jar file to demonstrate Kafka streaming";
            break;
        case SPARK:
            // It's a Spark guide
            projectDTO.setProjectName("demo_" + TourProjectType.SPARK.getTourName() + "_" + username);
            populateActiveServices(projectServices, TourProjectType.SPARK);
            readMeMessage = "jar file to demonstrate the creation of a spark batch job";
            break;
        case FS:
            // It's a Featurestore guide
            projectDTO.setProjectName("demo_" + TourProjectType.FS.getTourName() + "_" + username);
            populateActiveServices(projectServices, TourProjectType.FS);
            readMeMessage = "Dataset containing a jar file and data that can be used to run a sample spark-job for " + "inserting data in the feature store.";
            break;
        case ML:
            // It's a TensorFlow guide
            projectDTO.setProjectName("demo_" + TourProjectType.ML.getTourName() + "_" + username);
            populateActiveServices(projectServices, TourProjectType.ML);
            readMeMessage = "Jupyter notebooks and training data for demonstrating how to run Deep Learning";
            break;
        default:
            throw new IllegalArgumentException("Type must be one of: " + Arrays.toString(TourProjectType.values()));
    }
    projectDTO.setServices(projectServices);
    DistributedFileSystemOps dfso = null;
    DistributedFileSystemOps udfso = null;
    try {
        project = projectController.createProject(projectDTO, user, req.getSession().getId());
        dfso = dfs.getDfsOps();
        username = hdfsUsersBean.getHdfsUserName(project, user);
        udfso = dfs.getDfsOps(username);
        ProvTypeDTO projectMetaStatus = fsProvenanceController.getProjectProvType(user, project);
        String tourFilesDataset = projectController.addTourFilesToProject(user.getEmail(), project, dfso, dfso, demoType, projectMetaStatus);
        // TestJob dataset
        datasetController.generateReadme(udfso, tourFilesDataset, readMeMessage, project.getName());
    } catch (Exception ex) {
        projectController.cleanup(project, req.getSession().getId());
        throw ex;
    } finally {
        if (dfso != null) {
            dfso.close();
        }
        if (udfso != null) {
            dfs.closeDfsClient(udfso);
        }
    }
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.CREATED).entity(project).build();
}
Also used : TourProjectType(io.hops.hopsworks.common.project.TourProjectType) ProjectDTO(io.hops.hopsworks.common.project.ProjectDTO) Project(io.hops.hopsworks.persistence.entity.project.Project) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) ArrayList(java.util.ArrayList) Users(io.hops.hopsworks.persistence.entity.user.Users) ProvTypeDTO(io.hops.hopsworks.common.provenance.core.dto.ProvTypeDTO) DatasetException(io.hops.hopsworks.exceptions.DatasetException) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException) ElasticException(io.hops.hopsworks.exceptions.ElasticException) IOException(java.io.IOException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) UserException(io.hops.hopsworks.exceptions.UserException) ExecutionException(java.util.concurrent.ExecutionException) ProjectException(io.hops.hopsworks.exceptions.ProjectException) JobException(io.hops.hopsworks.exceptions.JobException) GenericException(io.hops.hopsworks.exceptions.GenericException) KafkaException(io.hops.hopsworks.exceptions.KafkaException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) SchemaException(io.hops.hopsworks.exceptions.SchemaException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 2 with KafkaException

use of io.hops.hopsworks.exceptions.KafkaException 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 3 with KafkaException

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

the class KafkaController method removeAclFromTopic.

public void removeAclFromTopic(String topicName, Integer aclId) throws KafkaException {
    TopicAcls ta = topicAclsFacade.find(aclId);
    if (ta == null) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.ACL_NOT_FOUND, Level.FINE, "topic: " + topicName);
    }
    if (!ta.getProjectTopics().getTopicName().equals(topicName)) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.ACL_NOT_FOR_TOPIC, Level.FINE, "topic: " + topicName);
    }
    topicAclsFacade.remove(ta);
}
Also used : TopicAcls(io.hops.hopsworks.persistence.entity.kafka.TopicAcls) KafkaException(io.hops.hopsworks.exceptions.KafkaException)

Example 4 with KafkaException

use of io.hops.hopsworks.exceptions.KafkaException 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 5 with KafkaException

use of io.hops.hopsworks.exceptions.KafkaException 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

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