Search in sources :

Example 11 with CondaCommands

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

the class CommandsController method updateCondaCommandStatus.

public void updateCondaCommandStatus(int commandId, CondaStatus condaStatus, String arg, CondaOp opType, String errorMessage) throws ServiceException, ProjectException {
    CondaCommands cc = condaCommandFacade.findCondaCommand(commandId);
    if (cc != null) {
        if (condaStatus == CondaStatus.SUCCESS) {
            // remove completed commands
            condaCommandFacade.remove(cc);
            // returned => CondaEnv operation is finished).
            if (CondaOp.isLibraryOp(opType)) {
                Project project = projectFacade.findById(cc.getProjectId().getId()).orElseThrow(() -> new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "projectId: " + cc.getProjectId().getId()));
                PythonDep dep = libraryFacade.getOrCreateDep(libraryFacade.getRepo(cc.getChannelUrl(), false), cc.getInstallType(), cc.getLib(), cc.getVersion(), true, false);
                Collection<PythonDep> deps = project.getPythonDepCollection();
                if (isPlaceholderDep(cc, opType) || opType.equals(CondaOp.UNINSTALL)) {
                    deps.remove(dep);
                }
                project.setPythonDepCollection(deps);
                projectFacade.update(project);
                projectFacade.flushEm();
            }
        } else if (condaStatus == CondaStatus.FAILED) {
            cc.setStatus(condaStatus);
            cc.setArg(arg);
            cc.setErrorMsg(errorMessage);
            condaCommandFacade.update(cc);
        } else if (condaStatus == CondaStatus.ONGOING) {
            cc.setStatus(condaStatus);
            condaCommandFacade.update(cc);
        }
    } else {
        LOGGER.log(Level.FINE, "Could not remove CondaCommand with id: {0}", commandId);
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) CondaCommands(io.hops.hopsworks.persistence.entity.python.CondaCommands) PythonDep(io.hops.hopsworks.persistence.entity.python.PythonDep)

Example 12 with CondaCommands

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

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