Search in sources :

Example 1 with AnacondaRepo

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

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

the class LibraryController method addOngoingOperations.

public Project addOngoingOperations(Project project) throws ServiceException {
    Collection<CondaCommands> commands = project.getCondaCommandsCollection();
    for (CondaCommands condaCommand : commands) {
        if (condaCommand.getInstallType().equals(CondaInstallType.ENVIRONMENT))
            continue;
        PythonDep pythonDep = new PythonDep();
        pythonDep.setDependency(condaCommand.getLib());
        pythonDep.setInstallType(condaCommand.getInstallType());
        pythonDep.setPreinstalled(false);
        AnacondaRepo repo = libraryFacade.getRepo(condaCommand.getChannelUrl(), false);
        pythonDep.setRepoUrl(repo);
        pythonDep.setVersion(condaCommand.getVersion());
        pythonDep = libraryFacade.getOrCreateDep(pythonDep);
        if (!project.getPythonDepCollection().contains(pythonDep)) {
            project.getPythonDepCollection().add(pythonDep);
        }
    }
    return projectFacade.update(project);
}
Also used : AnacondaRepo(io.hops.hopsworks.persistence.entity.python.AnacondaRepo) CondaCommands(io.hops.hopsworks.persistence.entity.python.CondaCommands) PythonDep(io.hops.hopsworks.persistence.entity.python.PythonDep)

Example 3 with AnacondaRepo

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

the class LibraryFacade method getRepo.

public AnacondaRepo getRepo(String channelUrl, boolean create) throws ServiceException {
    TypedQuery<AnacondaRepo> query = em.createNamedQuery("AnacondaRepo.findByUrl", AnacondaRepo.class);
    query.setParameter("url", channelUrl);
    AnacondaRepo repo = null;
    try {
        repo = query.getSingleResult();
    } catch (NoResultException ex) {
        if (create) {
            repo = new AnacondaRepo();
            repo.setUrl(channelUrl);
            em.persist(repo);
            em.flush();
        }
    }
    if (repo == null) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.ANACONDA_REPO_ERROR, Level.SEVERE);
    }
    return repo;
}
Also used : AnacondaRepo(io.hops.hopsworks.persistence.entity.python.AnacondaRepo) ServiceException(io.hops.hopsworks.exceptions.ServiceException) NoResultException(javax.persistence.NoResultException)

Example 4 with AnacondaRepo

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

the class LibraryController method parseCondaList.

public Collection<PythonDep> parseCondaList(String condaListStr) throws ServiceException {
    Collection<PythonDep> deps = new ArrayList<>();
    String[] lines = condaListStr.split(System.getProperty("line.separator"));
    for (int i = 3; i < lines.length; i++) {
        String line = lines[i];
        String[] split = line.split(" +");
        String libraryName = split[0];
        String version = split[1];
        String channel = "conda";
        if (split.length > 3) {
            channel = split[3].trim().isEmpty() ? channel : split[3];
        }
        CondaInstallType installType = CondaInstallType.PIP;
        if (!(channel.equals("pypi"))) {
            installType = CondaInstallType.CONDA;
        }
        AnacondaRepo repo = libraryFacade.getRepo(channel, true);
        boolean cannotBeRemoved = channel.equals("default");
        PythonDep pyDep = libraryFacade.getOrCreateDep(repo, installType, libraryName, version, false, cannotBeRemoved);
        deps.add(pyDep);
    }
    return deps;
}
Also used : AnacondaRepo(io.hops.hopsworks.persistence.entity.python.AnacondaRepo) ArrayList(java.util.ArrayList) PythonDep(io.hops.hopsworks.persistence.entity.python.PythonDep) CondaInstallType(io.hops.hopsworks.persistence.entity.python.CondaInstallType)

Aggregations

AnacondaRepo (io.hops.hopsworks.persistence.entity.python.AnacondaRepo)4 PythonDep (io.hops.hopsworks.persistence.entity.python.PythonDep)3 ServiceException (io.hops.hopsworks.exceptions.ServiceException)2 CondaCommands (io.hops.hopsworks.persistence.entity.python.CondaCommands)2 CondaInstallType (io.hops.hopsworks.persistence.entity.python.CondaInstallType)2 ArrayList (java.util.ArrayList)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 Settings (io.hops.hopsworks.common.util.Settings)1 GenericException (io.hops.hopsworks.exceptions.GenericException)1 ProjectException (io.hops.hopsworks.exceptions.ProjectException)1 GitBackend (io.hops.hopsworks.persistence.entity.jupyter.config.GitBackend)1 Project (io.hops.hopsworks.persistence.entity.project.Project)1 CondaOp (io.hops.hopsworks.persistence.entity.python.CondaOp)1 CondaStatus (io.hops.hopsworks.persistence.entity.python.CondaStatus)1 Users (io.hops.hopsworks.persistence.entity.user.Users)1 RESTCodes (io.hops.hopsworks.restutils.RESTCodes)1 Collection (java.util.Collection)1