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;
}
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();
}
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);
}
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);
}
Aggregations