Search in sources :

Example 6 with CondaCommands

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

the class LibraryInstaller method getCondaCommandsByProject.

private Map<Project, List<CondaCommands>> getCondaCommandsByProject(List<CondaCommands> condaCommands) {
    Map<Project, List<CondaCommands>> condaCommandsByProject = new HashMap<>();
    for (CondaCommands condacommand : condaCommands) {
        // "REMOVE" command as it needs to be processed even after the project has been deleted
        if (condacommand.getOp() != CondaOp.REMOVE && (condacommand.getProjectId() == null || condacommand.getProjectId().getPythonEnvironment() == null)) {
            LOG.log(Level.FINEST, "Removing condacommand: " + condacommand);
            condaCommandFacade.remove(condacommand);
        } else {
            Project project = condacommand.getProjectId();
            if (!condaCommandsByProject.containsKey(project)) {
                condaCommandsByProject.put(project, new ArrayList<>());
            }
            condaCommandsByProject.get(project).add(condacommand);
        }
    }
    return condaCommandsByProject;
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) CondaCommands(io.hops.hopsworks.persistence.entity.python.CondaCommands) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with CondaCommands

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

the class LibraryInstaller method isAlive.

@Timeout
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void isAlive() {
    try {
        LOG.log(Level.FINE, "isAlive-start: " + System.currentTimeMillis());
        registryGCCycles.incrementAndGet();
        final List<CondaCommands> allCondaCommandsOngoing = condaCommandFacade.findByStatus(CondaStatus.ONGOING);
        // other conda ops
        if (registryGCCycles.get() % 10 == 0 && allCondaCommandsOngoing.isEmpty()) {
            registryGCCycles.set(0);
            // Run registry GC
            try {
                LOG.log(Level.FINE, "registryGC-start: " + System.currentTimeMillis());
                registry.gc();
                LOG.log(Level.FINE, "registryGC-stop: " + System.currentTimeMillis());
            } catch (Exception ex) {
                LOG.log(Level.WARNING, "Could not run conda remove commands", ex);
            }
        } else {
            // Group new commands by project and run in parallel
            Map<Project, List<CondaCommands>> allCondaCommandsNewByProject = getCondaCommandsByProject(condaCommandFacade.findByStatus(CondaStatus.NEW));
            Map<Project, List<CondaCommands>> allCondaCommandsOngoingByProject = getCondaCommandsByProject(condaCommandFacade.findByStatus(CondaStatus.ONGOING));
            LOG.log(Level.FINE, "allCondaCommandsOngoingByProject:" + allCondaCommandsOngoingByProject);
            for (Project project : allCondaCommandsNewByProject.keySet()) {
                if (!allCondaCommandsOngoingByProject.containsKey(project)) {
                    try {
                        executorService.submit(() -> condaCommandHandler(allCondaCommandsNewByProject.get(project)));
                    } catch (Exception ex) {
                        LOG.log(Level.WARNING, "Could not run conda commands for project: " + project, ex);
                    }
                } else {
                    LOG.log(Level.FINE, "Project " + project.getName() + " is already processing a conda command, skipping...");
                }
            }
        }
    } finally {
        LOG.log(Level.FINE, "isAlive-stop: " + System.currentTimeMillis());
        schedule();
    }
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) CondaCommands(io.hops.hopsworks.persistence.entity.python.CondaCommands) List(java.util.List) ArrayList(java.util.ArrayList) ProjectException(io.hops.hopsworks.exceptions.ProjectException) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) PythonException(io.hops.hopsworks.exceptions.PythonException) IOException(java.io.IOException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) UserException(io.hops.hopsworks.exceptions.UserException) TransactionAttribute(javax.ejb.TransactionAttribute) Timeout(javax.ejb.Timeout)

Example 8 with CondaCommands

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

the class EnvironmentController method condaEnvironmentOp.

/**
 * Asynchronous execution of conda operations
 *
 * @param op
 * @param proj
 * @param pythonVersion
 * @param arg
 */
private void condaEnvironmentOp(CondaOp op, String pythonVersion, Project proj, Users user, String arg, String environmentFile, Boolean installJupyter) {
    if (projectUtils.isReservedProjectName(proj.getName())) {
        throw new IllegalStateException("Tried to execute a conda env op on a reserved project name");
    }
    CondaCommands cc = new CondaCommands(user, op, CondaStatus.NEW, CondaInstallType.ENVIRONMENT, proj, pythonVersion, "", "defaults", new Date(), arg, environmentFile, installJupyter);
    condaCommandFacade.save(cc);
}
Also used : CondaCommands(io.hops.hopsworks.persistence.entity.python.CondaCommands) Date(java.util.Date)

Example 9 with CondaCommands

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

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

the class CondaCommandFacade method removeCondaCommand.

public void removeCondaCommand(int commandId) {
    CondaCommands cc = findCondaCommand(commandId);
    if (cc != null) {
        em.remove(cc);
        em.flush();
    } else {
        LOGGER.log(Level.FINE, "Could not remove CondaCommand with id: {0}", commandId);
    }
}
Also used : CondaCommands(io.hops.hopsworks.persistence.entity.python.CondaCommands)

Aggregations

CondaCommands (io.hops.hopsworks.persistence.entity.python.CondaCommands)12 ProjectException (io.hops.hopsworks.exceptions.ProjectException)4 Project (io.hops.hopsworks.persistence.entity.project.Project)4 ArrayList (java.util.ArrayList)4 ServiceException (io.hops.hopsworks.exceptions.ServiceException)3 PythonDep (io.hops.hopsworks.persistence.entity.python.PythonDep)3 Date (java.util.Date)3 List (java.util.List)3 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)2 PythonException (io.hops.hopsworks.exceptions.PythonException)2 AnacondaRepo (io.hops.hopsworks.persistence.entity.python.AnacondaRepo)2 CondaStatus (io.hops.hopsworks.persistence.entity.python.CondaStatus)2 IOException (java.io.IOException)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 Settings (io.hops.hopsworks.common.util.Settings)1 GenericException (io.hops.hopsworks.exceptions.GenericException)1