Search in sources :

Example 1 with PythonEnvironment

use of io.hops.hopsworks.persistence.entity.python.PythonEnvironment in project hopsworks by logicalclocks.

the class EnvironmentController method createProjectDockerImage.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void createProjectDockerImage(Project project, Users user) {
    // Check if there is no pending CREATE op for this project
    List<CondaStatus> statuses = new ArrayList<>();
    statuses.add(CondaStatus.NEW);
    statuses.add(CondaStatus.ONGOING);
    if (!condaCommandFacade.findByStatusAndCondaOpAndProject(statuses, CondaOp.CREATE, project).isEmpty()) {
        LOGGER.log(Level.INFO, "There is already a " + CondaOp.CREATE.name() + " operation for this project.");
        return;
    }
    condaEnvironmentOp(CondaOp.CREATE, project.getPythonEnvironment().getPythonVersion(), project, user, project.getPythonEnvironment().getPythonVersion(), null, false);
    if (project.getPythonEnvironment() == null) {
        PythonEnvironment pythonEnvironment = new PythonEnvironment();
        pythonEnvironment.setPythonVersion(settings.getDockerBaseImagePythonVersion());
        pythonEnvironment.setProjectId(project.getId());
        project.setPythonEnvironment(pythonEnvironment);
    }
    project.setDockerImage(settings.getBaseDockerImagePythonName());
    projectFacade.update(project);
    projectFacade.flushEm();
}
Also used : ArrayList(java.util.ArrayList) PythonEnvironment(io.hops.hopsworks.persistence.entity.python.PythonEnvironment) CondaStatus(io.hops.hopsworks.persistence.entity.python.CondaStatus) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 2 with PythonEnvironment

use of io.hops.hopsworks.persistence.entity.python.PythonEnvironment in project hopsworks by logicalclocks.

the class EnvironmentController method createProjectDockerImageFromImport.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public String createProjectDockerImageFromImport(String importPath, boolean installJupyter, Users user, Project project) throws PythonException, ServiceException {
    if (project.getPythonEnvironment() != null) {
        throw new PythonException(RESTCodes.PythonErrorCode.ANACONDA_ENVIRONMENT_ALREADY_INITIALIZED, Level.FINE);
    }
    String username = hdfsUsersController.getHdfsUserName(project, user);
    String importContent = validateImportFile(new Path(importPath), username);
    if (!importPath.endsWith(".yml") && !importPath.endsWith("/requirements.txt")) {
        throw new PythonException(RESTCodes.PythonErrorCode.ANACONDA_ENVIRONMENT_FILE_INVALID, Level.FINE);
    }
    String pythonVersion = findPythonVersion(importContent);
    if (Strings.isNullOrEmpty(pythonVersion)) {
        pythonVersion = settings.getDockerBaseImagePythonVersion();
    }
    condaEnvironmentOp(CondaOp.IMPORT, pythonVersion, project, user, pythonVersion, importPath, installJupyter);
    PythonEnvironment pythonEnvironment = new PythonEnvironment();
    pythonEnvironment.setPythonVersion(pythonVersion);
    pythonEnvironment.setProjectId(project.getId());
    project.setPythonEnvironment(pythonEnvironment);
    projectFacade.update(project);
    return pythonVersion;
}
Also used : Path(org.apache.hadoop.fs.Path) PythonException(io.hops.hopsworks.exceptions.PythonException) PythonEnvironment(io.hops.hopsworks.persistence.entity.python.PythonEnvironment) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 3 with PythonEnvironment

use of io.hops.hopsworks.persistence.entity.python.PythonEnvironment in project hopsworks by logicalclocks.

the class EnvironmentController method createEnv.

public Project createEnv(Project project, Users user) throws PythonException {
    List<CondaStatus> statuses = new ArrayList<>();
    statuses.add(CondaStatus.NEW);
    statuses.add(CondaStatus.ONGOING);
    if (!condaCommandFacade.findByStatusAndCondaOpAndProject(statuses, CondaOp.CREATE, project).isEmpty()) {
        throw new PythonException(RESTCodes.PythonErrorCode.ANACONDA_ENVIRONMENT_INITIALIZING, Level.INFO);
    }
    if (project.getPythonEnvironment() != null) {
        throw new PythonException(RESTCodes.PythonErrorCode.ANACONDA_ENVIRONMENT_ALREADY_INITIALIZED, Level.FINE);
    }
    PythonEnvironment pythonEnvironment = new PythonEnvironment();
    pythonEnvironment.setPythonVersion(settings.getDockerBaseImagePythonVersion());
    pythonEnvironment.setProjectId(project.getId());
    project.setPythonEnvironment(pythonEnvironment);
    project.setDockerImage(settings.getBaseDockerImagePythonName());
    CondaCommands cc = new CondaCommands(user, CondaOp.SYNC_BASE_ENV, CondaStatus.NEW, CondaInstallType.ENVIRONMENT, project, settings.getDockerBaseImagePythonVersion(), null, null, new Date(), null, null, false);
    condaCommandFacade.save(cc);
    return projectFacade.update(project);
}
Also used : CondaCommands(io.hops.hopsworks.persistence.entity.python.CondaCommands) ArrayList(java.util.ArrayList) PythonException(io.hops.hopsworks.exceptions.PythonException) PythonEnvironment(io.hops.hopsworks.persistence.entity.python.PythonEnvironment) CondaStatus(io.hops.hopsworks.persistence.entity.python.CondaStatus) Date(java.util.Date)

Aggregations

PythonEnvironment (io.hops.hopsworks.persistence.entity.python.PythonEnvironment)3 PythonException (io.hops.hopsworks.exceptions.PythonException)2 CondaStatus (io.hops.hopsworks.persistence.entity.python.CondaStatus)2 ArrayList (java.util.ArrayList)2 TransactionAttribute (javax.ejb.TransactionAttribute)2 CondaCommands (io.hops.hopsworks.persistence.entity.python.CondaCommands)1 Date (java.util.Date)1 Path (org.apache.hadoop.fs.Path)1