Search in sources :

Example 1 with CondaStatus

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

the class CommandsController method condaOp.

public PythonDep condaOp(CondaOp op, Users user, CondaInstallType installType, Project proj, String channelUrl, String lib, String version, String arg, GitBackend gitBackend, String apiKeyName) throws GenericException, ServiceException {
    if (Strings.isNullOrEmpty(version) && CondaOp.isLibraryOp(op)) {
        version = Settings.UNKNOWN_LIBRARY_VERSION;
    }
    // If there is an already ongoing command to uninstall the same library, allow the queuing of a new install op
    List<CondaStatus> statuses = new ArrayList<>();
    statuses.add(CondaStatus.NEW);
    statuses.add(CondaStatus.ONGOING);
    List<CondaCommands> uninstallCommands = condaCommandFacade.findByStatusAndCondaOpAndProject(statuses, CondaOp.UNINSTALL, proj);
    // Get current uninstall operations for this project
    List<CondaCommands> ongoingUninstall = uninstallCommands.stream().filter(c -> c.getLib().equalsIgnoreCase(lib) && c.getInstallType().equals(installType)).collect(Collectors.toList());
    // Get currently installed library with the same name and package manager if it exists
    Optional<PythonDep> installedDep = proj.getPythonDepCollection().stream().filter(d -> d.getDependency().equalsIgnoreCase(lib) && d.getInstallType().equals(installType)).findFirst();
    if (op == CondaOp.INSTALL && installedDep.isPresent() && ongoingUninstall.isEmpty()) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.ANACONDA_DEP_INSTALL_FORBIDDEN, Level.FINE, "dep: " + lib);
    }
    PythonDep dep;
    try {
        // 1. test if anacondaRepoUrl exists. If not, add it.
        AnacondaRepo repo = libraryFacade.getRepo(channelUrl, true);
        // 2. Test if pythonDep exists. If not, add it.
        dep = libraryFacade.getOrCreateDep(repo, installType, lib, version, true, false);
        Collection<PythonDep> depsInProj = proj.getPythonDepCollection();
        // 3. Add the python library to the join table for the project
        if (op == CondaOp.INSTALL) {
            // if upgrade
            depsInProj.remove(dep);
            depsInProj.add(dep);
        }
        proj.setPythonDepCollection(depsInProj);
        projectFacade.update(proj);
        CondaCommands cc = new CondaCommands(user, op, CondaStatus.NEW, installType, proj, lib, version, channelUrl, new Date(), arg, null, false, gitBackend, apiKeyName);
        condaCommandFacade.save(cc);
    } catch (Exception ex) {
        throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ERROR, Level.SEVERE, "condaOp failed", ex.getMessage(), ex);
    }
    return dep;
}
Also used : ProjectFacade(io.hops.hopsworks.common.dao.project.ProjectFacade) CondaOp(io.hops.hopsworks.persistence.entity.python.CondaOp) Date(java.util.Date) CondaCommands(io.hops.hopsworks.persistence.entity.python.CondaCommands) LibraryFacade(io.hops.hopsworks.common.dao.python.LibraryFacade) Project(io.hops.hopsworks.persistence.entity.project.Project) CondaInstallType(io.hops.hopsworks.persistence.entity.python.CondaInstallType) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Strings(com.google.common.base.Strings) Settings(io.hops.hopsworks.common.util.Settings) TransactionAttributeType(javax.ejb.TransactionAttributeType) Matcher(java.util.regex.Matcher) TransactionAttribute(javax.ejb.TransactionAttribute) ProjectException(io.hops.hopsworks.exceptions.ProjectException) PythonDep(io.hops.hopsworks.persistence.entity.python.PythonDep) GitBackend(io.hops.hopsworks.persistence.entity.jupyter.config.GitBackend) EJB(javax.ejb.EJB) Stateless(javax.ejb.Stateless) CondaStatus(io.hops.hopsworks.persistence.entity.python.CondaStatus) Collection(java.util.Collection) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) Logger(java.util.logging.Logger) AnacondaRepo(io.hops.hopsworks.persistence.entity.python.AnacondaRepo) Collectors(java.util.stream.Collectors) ServiceException(io.hops.hopsworks.exceptions.ServiceException) List(java.util.List) GenericException(io.hops.hopsworks.exceptions.GenericException) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) CondaCommandFacade(io.hops.hopsworks.common.dao.python.CondaCommandFacade) Users(io.hops.hopsworks.persistence.entity.user.Users) AnacondaRepo(io.hops.hopsworks.persistence.entity.python.AnacondaRepo) CondaCommands(io.hops.hopsworks.persistence.entity.python.CondaCommands) ArrayList(java.util.ArrayList) GenericException(io.hops.hopsworks.exceptions.GenericException) CondaStatus(io.hops.hopsworks.persistence.entity.python.CondaStatus) Date(java.util.Date) ProjectException(io.hops.hopsworks.exceptions.ProjectException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) GenericException(io.hops.hopsworks.exceptions.GenericException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) PythonDep(io.hops.hopsworks.persistence.entity.python.PythonDep)

Example 2 with CondaStatus

use of io.hops.hopsworks.persistence.entity.python.CondaStatus 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 3 with CondaStatus

use of io.hops.hopsworks.persistence.entity.python.CondaStatus 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 4 with CondaStatus

use of io.hops.hopsworks.persistence.entity.python.CondaStatus 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

CondaStatus (io.hops.hopsworks.persistence.entity.python.CondaStatus)4 ArrayList (java.util.ArrayList)4 PythonException (io.hops.hopsworks.exceptions.PythonException)2 CondaCommands (io.hops.hopsworks.persistence.entity.python.CondaCommands)2 PythonEnvironment (io.hops.hopsworks.persistence.entity.python.PythonEnvironment)2 Date (java.util.Date)2 TransactionAttribute (javax.ejb.TransactionAttribute)2 Strings (com.google.common.base.Strings)1 ProjectFacade (io.hops.hopsworks.common.dao.project.ProjectFacade)1 CondaCommandFacade (io.hops.hopsworks.common.dao.python.CondaCommandFacade)1 LibraryFacade (io.hops.hopsworks.common.dao.python.LibraryFacade)1 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)1 Settings (io.hops.hopsworks.common.util.Settings)1 GenericException (io.hops.hopsworks.exceptions.GenericException)1 ProjectException (io.hops.hopsworks.exceptions.ProjectException)1 ServiceException (io.hops.hopsworks.exceptions.ServiceException)1 GitBackend (io.hops.hopsworks.persistence.entity.jupyter.config.GitBackend)1 Project (io.hops.hopsworks.persistence.entity.project.Project)1 AnacondaRepo (io.hops.hopsworks.persistence.entity.python.AnacondaRepo)1 CondaInstallType (io.hops.hopsworks.persistence.entity.python.CondaInstallType)1