Search in sources :

Example 11 with Featurestore

use of io.hops.hopsworks.persistence.entity.featurestore.Featurestore in project hopsworks by logicalclocks.

the class ProjectController method addServiceFeaturestore.

/**
 * Add the featurestore service to the project,
 * 1. create the hive database for the featurestore
 * 2. insert featurestore metadata in the hopsworks db
 * 3. create a hopsworks dataset for the featurestore
 * 4. create a directory in resources to store json configurations for feature import jobs.
 *
 * @param project the project to add the featurestore service for
 * @param user the user adding the service
 * @param dfso dfso
 */
private void addServiceFeaturestore(Project project, Users user, DistributedFileSystemOps dfso, ProvTypeDTO datasetProvCore) throws FeaturestoreException, ProjectException, UserException {
    String featurestoreName = featurestoreController.getOfflineFeaturestoreDbName(project);
    try {
        // Create HiveDB for the featurestore
        hiveController.createDatabase(featurestoreName, "Featurestore database for project: " + project.getName());
        // Store featurestore metadata in Hopsworks
        Dataset trainingDatasets = datasetController.getByProjectAndDsName(project, null, project.getName() + "_" + Settings.ServiceDataset.TRAININGDATASETS.getName());
        Featurestore featurestore = featurestoreController.createProjectFeatureStore(project, user, featurestoreName, trainingDatasets);
        // Create Hopsworks Dataset of the HiveDb
        hiveController.createDatasetDb(project, user, dfso, featurestoreName, DatasetType.FEATURESTORE, featurestore, datasetProvCore);
        // Register built-in transformation function.
        transformationFunctionController.registerBuiltInTransformationFunctions(user, project, featurestore);
    } catch (SQLException | IOException | ServiceDiscoveryException ex) {
        LOGGER.log(Level.SEVERE, RESTCodes.FeaturestoreErrorCode.COULD_NOT_CREATE_FEATURESTORE.getMessage(), ex);
        throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.COULD_NOT_CREATE_FEATURESTORE, Level.SEVERE, "project: " + project.getName(), ex.getMessage(), ex);
    }
}
Also used : Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) SQLException(java.sql.SQLException) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) IOException(java.io.IOException) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException)

Example 12 with Featurestore

use of io.hops.hopsworks.persistence.entity.featurestore.Featurestore in project hopsworks by logicalclocks.

the class ProjectController method removeMemberFromTeam.

public void removeMemberFromTeam(Project project, Users userToBeRemoved) throws ProjectException, ServiceException, IOException, GenericException, JobException, HopsSecurityException, TensorBoardException, FeaturestoreException {
    ProjectTeam projectTeam = projectTeamFacade.findProjectTeam(project, userToBeRemoved);
    if (projectTeam == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.TEAM_MEMBER_NOT_FOUND, Level.FINE, "project: " + project + ", user: " + userToBeRemoved.getEmail());
    }
    // Not able to remove project owner regardless of who is trying to remove the member
    if (project.getOwner().equals(userToBeRemoved)) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_OWNER_NOT_ALLOWED, Level.FINE);
    }
    projectTeamFacade.removeProjectTeam(project, userToBeRemoved);
    String hdfsUser = hdfsUsersController.getHdfsUserName(project, userToBeRemoved);
    YarnClientWrapper yarnClientWrapper = ycs.getYarnClientSuper(settings.getConfiguration());
    YarnClient client = yarnClientWrapper.getYarnClient();
    try {
        Set<String> hdfsUsers = new HashSet<>();
        hdfsUsers.add(hdfsUser);
        List<ApplicationReport> projectsApps = client.getApplications(null, hdfsUsers, null, EnumSet.of(YarnApplicationState.ACCEPTED, YarnApplicationState.NEW, YarnApplicationState.NEW_SAVING, YarnApplicationState.RUNNING, YarnApplicationState.SUBMITTED));
        // kill jupyter for this user
        JupyterProject jupyterProject = jupyterFacade.findByUser(hdfsUser);
        if (jupyterProject != null) {
            jupyterController.shutdown(project, hdfsUser, userToBeRemoved, jupyterProject.getSecret(), jupyterProject.getCid(), jupyterProject.getPort());
        }
        // kill running TB if any
        tensorBoardController.cleanup(project, userToBeRemoved);
        // kill all jobs run by this user.
        // kill jobs
        List<Jobs> running = jobFacade.getRunningJobs(project, hdfsUser);
        if (running != null && !running.isEmpty()) {
            for (Jobs job : running) {
                executionController.stop(job);
            }
        }
        // wait that log aggregation for the jobs finish
        for (ApplicationReport appReport : projectsApps) {
            FinalApplicationStatus finalState = appReport.getFinalApplicationStatus();
            while (finalState.equals(FinalApplicationStatus.UNDEFINED)) {
                client.killApplication(appReport.getApplicationId());
                appReport = client.getApplicationReport(appReport.getApplicationId());
                finalState = appReport.getFinalApplicationStatus();
            }
            YarnLogUtil.waitForLogAggregation(client, appReport.getApplicationId());
        }
    } catch (YarnException | IOException | InterruptedException e) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.KILL_MEMBER_JOBS, Level.SEVERE, "project: " + project + ", user: " + userToBeRemoved, e.getMessage(), e);
    } finally {
        ycs.closeYarnClient(yarnClientWrapper);
    }
    // trigger project team role remove handlers
    ProjectTeamRoleHandler.runProjectTeamRoleRemoveMembersHandlers(projectTeamRoleHandlers, project, Collections.singletonList(userToBeRemoved));
    // Revoke privileges for online feature store
    if (projectServiceFacade.isServiceEnabledForProject(project, ProjectServiceEnum.FEATURESTORE)) {
        Featurestore featurestore = featurestoreController.getProjectFeaturestore(project);
        onlineFeaturestoreController.removeOnlineFeaturestoreUser(featurestore, userToBeRemoved);
    }
    kafkaController.removeProjectMemberFromTopics(project, userToBeRemoved);
    certificateMaterializer.forceRemoveLocalMaterial(userToBeRemoved.getUsername(), project.getName(), null, false);
    try {
        certificatesController.revokeUserSpecificCertificates(project, userToBeRemoved);
    } catch (HopsSecurityException ex) {
        if (ex.getErrorCode() != RESTCodes.SecurityErrorCode.CERTIFICATE_NOT_FOUND) {
            LOGGER.log(Level.SEVERE, "Could not delete certificates when removing member " + userToBeRemoved.getUsername() + " from project " + project.getName() + ". Manual cleanup is needed!!!", ex);
            throw ex;
        }
    } catch (IOException | GenericException ex) {
        LOGGER.log(Level.SEVERE, "Could not delete certificates when removing member " + userToBeRemoved.getUsername() + " from project " + project.getName() + ". Manual cleanup is needed!!!", ex);
        throw ex;
    }
    // TODO: projectTeam might be null?
    hdfsUsersController.removeMember(projectTeam);
}
Also used : FinalApplicationStatus(org.apache.hadoop.yarn.api.records.FinalApplicationStatus) JupyterProject(io.hops.hopsworks.persistence.entity.jupyter.JupyterProject) IOException(java.io.IOException) GenericException(io.hops.hopsworks.exceptions.GenericException) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) ProjectException(io.hops.hopsworks.exceptions.ProjectException) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) Jobs(io.hops.hopsworks.persistence.entity.jobs.description.Jobs) YarnClientWrapper(io.hops.hopsworks.common.yarn.YarnClientWrapper) HashSet(java.util.HashSet)

Example 13 with Featurestore

use of io.hops.hopsworks.persistence.entity.featurestore.Featurestore in project hopsworks by logicalclocks.

the class TestAlertManagerConfigTimer method createAlertReceiver.

private AlertReceiver createAlertReceiver(Integer id, Receiver receiver, AlertType alertType) throws JsonProcessingException {
    AlertReceiver alertReceiver = new AlertReceiver();
    alertReceiver.setId(id);
    alertReceiver.setName(receiver.getName());
    alertReceiver.setConfig(toJson(receiver));
    Project project = new Project("project1");
    Jobs job = new Jobs();
    job.setProject(project);
    job.setName("job1");
    Featurestore featurestore = new Featurestore();
    featurestore.setProject(project);
    Featuregroup featuregroup = new Featuregroup();
    featuregroup.setFeaturestore(featurestore);
    featuregroup.setName("fg1");
    List<JobAlert> jobAlerts = new ArrayList<>();
    jobAlerts.add(new JobAlert(random.nextInt(1000), JobAlertStatus.FAILED, alertType, AlertSeverity.CRITICAL, new Date(), job, alertReceiver));
    jobAlerts.add(new JobAlert(random.nextInt(1000), JobAlertStatus.KILLED, alertType, AlertSeverity.WARNING, new Date(), job, alertReceiver));
    alertReceiver.setJobAlertCollection(jobAlerts);
    List<FeatureGroupAlert> featureGroupAlerts = new ArrayList<>();
    featureGroupAlerts.add(new FeatureGroupAlert(random.nextInt(1000), ValidationRuleAlertStatus.FAILURE, alertType, AlertSeverity.CRITICAL, new Date(), featuregroup, alertReceiver));
    featureGroupAlerts.add(new FeatureGroupAlert(random.nextInt(1000), ValidationRuleAlertStatus.WARNING, alertType, AlertSeverity.WARNING, new Date(), featuregroup, alertReceiver));
    alertReceiver.setFeatureGroupAlertCollection(featureGroupAlerts);
    List<ProjectServiceAlert> projectServiceAlerts = new ArrayList<>();
    projectServiceAlerts.add(new ProjectServiceAlert(random.nextInt(1000), ProjectServiceEnum.FEATURESTORE, ProjectServiceAlertStatus.VALIDATION_FAILURE, alertType, AlertSeverity.WARNING, new Date(), project, alertReceiver));
    projectServiceAlerts.add(new ProjectServiceAlert(random.nextInt(1000), ProjectServiceEnum.JOBS, ProjectServiceAlertStatus.JOB_FAILED, alertType, AlertSeverity.WARNING, new Date(), project, alertReceiver));
    alertReceiver.setProjectServiceAlertCollection(projectServiceAlerts);
    return alertReceiver;
}
Also used : FeatureGroupAlert(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.FeatureGroupAlert) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) Featuregroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup) ArrayList(java.util.ArrayList) Date(java.util.Date) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) Project(io.hops.hopsworks.persistence.entity.project.Project) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) Jobs(io.hops.hopsworks.persistence.entity.jobs.description.Jobs)

Example 14 with Featurestore

use of io.hops.hopsworks.persistence.entity.featurestore.Featurestore in project hopsworks by logicalclocks.

the class FeatureStoreExpectationsResource method createExpectation.

@ApiOperation(value = "Create feature store expectation.", response = ExpectationDTO.class)
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response createExpectation(Expectation expectation, @Context SecurityContext sc, @Context UriInfo uriInfo) throws FeaturestoreException {
    // Workaround to ignore the list initialized from a json like {legalValues: null}
    if (expectation.getRules() != null && !expectation.getRules().isEmpty()) {
        expectation.getRules().stream().filter(rule -> rule.getLegalValues() != null && rule.getLegalValues().size() == 1 && rule.getLegalValues().get(0) == null).forEach(rule -> rule.setLegalValues(null));
    }
    FeatureStoreExpectation featureStoreExpectation = featureGroupValidationsController.createOrUpdateExpectation(featurestore, new io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.Expectation(expectation.getName(), expectation.getDescription(), expectation.getFeatures(), expectation.getRules()));
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.EXPECTATIONS);
    ExpectationDTO dto = featureStoreExpectationsBuilder.build(uriInfo, resourceRequest, project, featurestore, featureStoreExpectation);
    return Response.ok().entity(dto).build();
}
Also used : PathParam(javax.ws.rs.PathParam) Expectation(io.hops.hopsworks.common.featurestore.datavalidation.Expectation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) ExpectationDTO(io.hops.hopsworks.api.featurestore.datavalidation.expectations.ExpectationDTO) Project(io.hops.hopsworks.persistence.entity.project.Project) FeatureGroupValidationsController(io.hops.hopsworks.common.featurestore.datavalidation.FeatureGroupValidationsController) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) ApiOperation(io.swagger.annotations.ApiOperation) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException) MediaType(javax.ws.rs.core.MediaType) TransactionAttributeType(javax.ejb.TransactionAttributeType) Consumes(javax.ws.rs.Consumes) FeaturestoreController(io.hops.hopsworks.common.featurestore.FeaturestoreController) TransactionAttribute(javax.ejb.TransactionAttribute) ApiScope(io.hops.hopsworks.persistence.entity.user.security.apiKey.ApiScope) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) Api(io.swagger.annotations.Api) FeaturestoreDTO(io.hops.hopsworks.common.featurestore.FeaturestoreDTO) EJB(javax.ejb.EJB) DELETE(javax.ws.rs.DELETE) Audience(io.hops.hopsworks.api.filter.Audience) Context(javax.ws.rs.core.Context) Pagination(io.hops.hopsworks.api.util.Pagination) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) BeanParam(javax.ws.rs.BeanParam) Response(javax.ws.rs.core.Response) RequestScoped(javax.enterprise.context.RequestScoped) FeatureStoreExpectation(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) FeatureStoreExpectation(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ExpectationDTO(io.hops.hopsworks.api.featurestore.datavalidation.expectations.ExpectationDTO) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Aggregations

Featurestore (io.hops.hopsworks.persistence.entity.featurestore.Featurestore)14 Project (io.hops.hopsworks.persistence.entity.project.Project)10 Featuregroup (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup)8 Before (org.junit.Before)8 CachedFeaturegroup (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.cached.CachedFeaturegroup)6 FeaturestoreFacade (io.hops.hopsworks.common.featurestore.FeaturestoreFacade)3 FeaturegroupController (io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupController)3 FeaturegroupFacade (io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupFacade)3 CachedFeaturegroupController (io.hops.hopsworks.common.featurestore.featuregroup.cached.CachedFeaturegroupController)3 OnlineFeaturestoreController (io.hops.hopsworks.common.featurestore.online.OnlineFeaturestoreController)3 ConstructorController (io.hops.hopsworks.common.featurestore.query.ConstructorController)3 FilterController (io.hops.hopsworks.common.featurestore.query.filter.FilterController)3 JoinController (io.hops.hopsworks.common.featurestore.query.join.JoinController)3 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)3 Users (io.hops.hopsworks.persistence.entity.user.Users)3 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)2 FeatureGroupFeatureDTO (io.hops.hopsworks.common.featurestore.feature.FeatureGroupFeatureDTO)2 GenericException (io.hops.hopsworks.exceptions.GenericException)2 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)2 ProjectException (io.hops.hopsworks.exceptions.ProjectException)2