Search in sources :

Example 6 with PythonException

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

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

the class EnvironmentController method condaEnvironmentRemove.

public void condaEnvironmentRemove(Project project, Users user) throws PythonException {
    // Delete environment.yml from filesystem, new one will be created upon next environment creation
    DistributedFileSystemOps udfso = null;
    try {
        udfso = dfs.getDfsOps();
        udfso.rm(Utils.getProjectPath(project.getName()) + new Path(Settings.PROJECT_PYTHON_ENVIRONMENT_FILE), false);
    } catch (IOException ex) {
        throw new PythonException(RESTCodes.PythonErrorCode.ANACONDA_ENVIRONMENT_REMOVAL_FAILED, Level.SEVERE, "Failed to clean up environment yaml file on path: " + Settings.PROJECT_PYTHON_ENVIRONMENT_FILE, ex.getMessage(), ex);
    } finally {
        if (udfso != null) {
            dfs.closeDfsClient(udfso);
        }
    }
    // Do not remove conda env if project is using the base
    if (Strings.isNullOrEmpty(project.getDockerImage()) || projectUtils.dockerImageIsPreinstalled(project.getDockerImage())) {
        LOGGER.log(Level.INFO, "Will not remove conda env " + project.getDockerImage() + " for project: " + project.getName());
        return;
    }
    List<CondaStatus> statuses = new ArrayList<>();
    statuses.add(CondaStatus.NEW);
    statuses.add(CondaStatus.ONGOING);
    if (!condaCommandFacade.findByStatusAndCondaOpAndProject(statuses, CondaOp.REMOVE, project).isEmpty()) {
        LOGGER.log(Level.INFO, "There is already a " + CondaOp.REMOVE.name() + " operation for this project.");
        return;
    }
    condaEnvironmentOp(CondaOp.REMOVE, "", project, user, project.getDockerImage(), null, false);
}
Also used : Path(org.apache.hadoop.fs.Path) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) ArrayList(java.util.ArrayList) PythonException(io.hops.hopsworks.exceptions.PythonException) IOException(java.io.IOException) CondaStatus(io.hops.hopsworks.persistence.entity.python.CondaStatus)

Example 8 with PythonException

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

the class EnvironmentController method getPipConflicts.

public String getPipConflicts(Project project) throws ServiceDiscoveryException, IOException, PythonException {
    String prog = settings.getSudoersDir() + "/dockerImage.sh";
    ProcessDescriptor processDescriptor = new ProcessDescriptor.Builder().addCommand("/usr/bin/sudo").addCommand(prog).addCommand("check").addCommand(projectUtils.getFullDockerImageName(project, false)).redirectErrorStream(true).setWaitTimeout(300L, TimeUnit.SECONDS).build();
    ProcessResult processResult = osProcessExecutor.execute(processDescriptor);
    // From https://github.com/pypa/pip/blob/27d8687144bf38cdaeeb1d81aa72c892b1d0ab88/src/pip/_internal/commands/check.py#L35
    if (processResult.getExitCode() == 0) {
        return null;
    } else {
        if (processResult.getStdout() != null && (processResult.getStdout().contains("which is not installed") || processResult.getStdout().contains("has requirement"))) {
            return processResult.getStdout();
        } else {
            throw new PythonException(RESTCodes.PythonErrorCode.ANACONDA_PIP_CHECK_FAILED, Level.SEVERE, "Failed to run pip check: " + (Strings.isNullOrEmpty(processResult.getStdout()) ? "" : processResult.getStdout()));
        }
    }
}
Also used : ProcessResult(io.hops.hopsworks.common.util.ProcessResult) ProcessDescriptor(io.hops.hopsworks.common.util.ProcessDescriptor) PythonException(io.hops.hopsworks.exceptions.PythonException)

Example 9 with PythonException

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

Example 10 with PythonException

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

the class LibraryResource method validateBundledDependency.

private void validateBundledDependency(Users user, LibrarySpecification librarySpecification) throws DatasetException, PythonException {
    String dependencyUrl = librarySpecification.getDependencyUrl();
    PackageSource packageSource = librarySpecification.getPackageSource();
    datasetController.checkFileExists(new org.apache.hadoop.fs.Path(dependencyUrl), hdfsUsersController.getHdfsUserName(project, user));
    if (packageSource.equals(PackageSource.EGG) && !dependencyUrl.endsWith(".egg")) {
        throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not an .egg file: " + dependencyUrl);
    } else if (packageSource.equals(PackageSource.WHEEL) && !dependencyUrl.endsWith(".whl")) {
        throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not a .whl file: " + dependencyUrl);
    } else if (packageSource.equals(PackageSource.REQUIREMENTS_TXT) && !dependencyUrl.endsWith("/requirements.txt")) {
        throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not a requirements.txt file: " + dependencyUrl);
    } else if (packageSource.equals(PackageSource.ENVIRONMENT_YAML) && !dependencyUrl.endsWith(".yml")) {
        throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not a conda environment.yml file: " + dependencyUrl);
    }
}
Also used : PackageSource(io.hops.hopsworks.common.python.library.PackageSource) PythonException(io.hops.hopsworks.exceptions.PythonException)

Aggregations

PythonException (io.hops.hopsworks.exceptions.PythonException)11 PackageSource (io.hops.hopsworks.common.python.library.PackageSource)4 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)3 ProjectException (io.hops.hopsworks.exceptions.ProjectException)3 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)3 Project (io.hops.hopsworks.persistence.entity.project.Project)3 ApiOperation (io.swagger.annotations.ApiOperation)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Path (org.apache.hadoop.fs.Path)3 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)2 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)2 ProcessDescriptor (io.hops.hopsworks.common.util.ProcessDescriptor)2 ProcessResult (io.hops.hopsworks.common.util.ProcessResult)2 DatasetException (io.hops.hopsworks.exceptions.DatasetException)2 GenericException (io.hops.hopsworks.exceptions.GenericException)2 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)2 ServiceException (io.hops.hopsworks.exceptions.ServiceException)2