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