use of io.hops.hopsworks.exceptions.PythonException in project hopsworks by logicalclocks.
the class EnvironmentController method createProjectDockerImageFromImport.
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public String createProjectDockerImageFromImport(String importPath, boolean installJupyter, Users user, Project project) throws PythonException, ServiceException {
if (project.getPythonEnvironment() != null) {
throw new PythonException(RESTCodes.PythonErrorCode.ANACONDA_ENVIRONMENT_ALREADY_INITIALIZED, Level.FINE);
}
String username = hdfsUsersController.getHdfsUserName(project, user);
String importContent = validateImportFile(new Path(importPath), username);
if (!importPath.endsWith(".yml") && !importPath.endsWith("/requirements.txt")) {
throw new PythonException(RESTCodes.PythonErrorCode.ANACONDA_ENVIRONMENT_FILE_INVALID, Level.FINE);
}
String pythonVersion = findPythonVersion(importContent);
if (Strings.isNullOrEmpty(pythonVersion)) {
pythonVersion = settings.getDockerBaseImagePythonVersion();
}
condaEnvironmentOp(CondaOp.IMPORT, pythonVersion, project, user, pythonVersion, importPath, installJupyter);
PythonEnvironment pythonEnvironment = new PythonEnvironment();
pythonEnvironment.setPythonVersion(pythonVersion);
pythonEnvironment.setProjectId(project.getId());
project.setPythonEnvironment(pythonEnvironment);
projectFacade.update(project);
return pythonVersion;
}
use of io.hops.hopsworks.exceptions.PythonException 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.exceptions.PythonException in project hopsworks by logicalclocks.
the class EnvironmentController method getPipConflicts.
public String getPipConflicts(Project project) throws ServiceDiscoveryException, IOException, PythonException {
String prog = settings.getSudoersDir() + "/dockerImage.sh";
ProcessDescriptor processDescriptor = new ProcessDescriptor.Builder().addCommand("/usr/bin/sudo").addCommand(prog).addCommand("check").addCommand(projectUtils.getFullDockerImageName(project, false)).redirectErrorStream(true).setWaitTimeout(300L, TimeUnit.SECONDS).build();
ProcessResult processResult = osProcessExecutor.execute(processDescriptor);
// From https://github.com/pypa/pip/blob/27d8687144bf38cdaeeb1d81aa72c892b1d0ab88/src/pip/_internal/commands/check.py#L35
if (processResult.getExitCode() == 0) {
return null;
} else {
if (processResult.getStdout() != null && (processResult.getStdout().contains("which is not installed") || processResult.getStdout().contains("has requirement"))) {
return processResult.getStdout();
} else {
throw new PythonException(RESTCodes.PythonErrorCode.ANACONDA_PIP_CHECK_FAILED, Level.SEVERE, "Failed to run pip check: " + (Strings.isNullOrEmpty(processResult.getStdout()) ? "" : processResult.getStdout()));
}
}
}
use of io.hops.hopsworks.exceptions.PythonException 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);
}
use of io.hops.hopsworks.exceptions.PythonException in project hopsworks by logicalclocks.
the class LibraryResource method validateBundledDependency.
private void validateBundledDependency(Users user, LibrarySpecification librarySpecification) throws DatasetException, PythonException {
String dependencyUrl = librarySpecification.getDependencyUrl();
PackageSource packageSource = librarySpecification.getPackageSource();
datasetController.checkFileExists(new org.apache.hadoop.fs.Path(dependencyUrl), hdfsUsersController.getHdfsUserName(project, user));
if (packageSource.equals(PackageSource.EGG) && !dependencyUrl.endsWith(".egg")) {
throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not an .egg file: " + dependencyUrl);
} else if (packageSource.equals(PackageSource.WHEEL) && !dependencyUrl.endsWith(".whl")) {
throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not a .whl file: " + dependencyUrl);
} else if (packageSource.equals(PackageSource.REQUIREMENTS_TXT) && !dependencyUrl.endsWith("/requirements.txt")) {
throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not a requirements.txt file: " + dependencyUrl);
} else if (packageSource.equals(PackageSource.ENVIRONMENT_YAML) && !dependencyUrl.endsWith(".yml")) {
throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not a conda environment.yml file: " + dependencyUrl);
}
}
Aggregations