use of com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException in project hopsworks by logicalclocks.
the class ProjectController method addServiceFeaturestore.
/**
* Add the featurestore service to the project,
* 1. create the hive database for the featurestore
* 2. insert featurestore metadata in the hopsworks db
* 3. create a hopsworks dataset for the featurestore
* 4. create a directory in resources to store json configurations for feature import jobs.
*
* @param project the project to add the featurestore service for
* @param user the user adding the service
* @param dfso dfso
*/
private void addServiceFeaturestore(Project project, Users user, DistributedFileSystemOps dfso, ProvTypeDTO datasetProvCore) throws FeaturestoreException, ProjectException, UserException {
String featurestoreName = featurestoreController.getOfflineFeaturestoreDbName(project);
try {
// Create HiveDB for the featurestore
hiveController.createDatabase(featurestoreName, "Featurestore database for project: " + project.getName());
// Store featurestore metadata in Hopsworks
Dataset trainingDatasets = datasetController.getByProjectAndDsName(project, null, project.getName() + "_" + Settings.ServiceDataset.TRAININGDATASETS.getName());
Featurestore featurestore = featurestoreController.createProjectFeatureStore(project, user, featurestoreName, trainingDatasets);
// Create Hopsworks Dataset of the HiveDb
hiveController.createDatasetDb(project, user, dfso, featurestoreName, DatasetType.FEATURESTORE, featurestore, datasetProvCore);
// Register built-in transformation function.
transformationFunctionController.registerBuiltInTransformationFunctions(user, project, featurestore);
} catch (SQLException | IOException | ServiceDiscoveryException ex) {
LOGGER.log(Level.SEVERE, RESTCodes.FeaturestoreErrorCode.COULD_NOT_CREATE_FEATURESTORE.getMessage(), ex);
throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.COULD_NOT_CREATE_FEATURESTORE, Level.SEVERE, "project: " + project.getName(), ex.getMessage(), ex);
}
}
use of com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException in project hopsworks by logicalclocks.
the class JupyterController method convertIPythonNotebook.
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public String convertIPythonNotebook(String hdfsUsername, String notebookPath, Project project, String pyPath, NotebookConversion notebookConversion) throws ServiceException {
File baseDir = new File(settings.getStagingDir() + settings.CONVERSION_DIR);
if (!baseDir.exists()) {
baseDir.mkdir();
}
File conversionDir = new File(baseDir, DigestUtils.sha256Hex(Integer.toString(ThreadLocalRandom.current().nextInt())));
conversionDir.mkdir();
HdfsUsers user = hdfsUsersFacade.findByName(hdfsUsername);
try {
String prog = settings.getSudoersDir() + "/convert-ipython-notebook.sh";
ProcessDescriptor processDescriptor = new ProcessDescriptor.Builder().addCommand("/usr/bin/sudo").addCommand(prog).addCommand(notebookPath).addCommand(hdfsUsername).addCommand(settings.getAnacondaProjectDir()).addCommand(pyPath).addCommand(conversionDir.getAbsolutePath()).addCommand(notebookConversion.name()).addCommand(projectUtils.getFullDockerImageName(project, true)).setWaitTimeout(60l, // on a TLS VM the timeout needs to be greater than 20s
TimeUnit.SECONDS).redirectErrorStream(true).build();
LOGGER.log(Level.FINE, processDescriptor.toString());
certificateMaterializer.materializeCertificatesLocalCustomDir(user.getUsername(), project.getName(), conversionDir.getAbsolutePath());
ProcessResult processResult = osProcessExecutor.execute(processDescriptor);
if (!processResult.processExited() || processResult.getExitCode() != 0) {
LOGGER.log(Level.WARNING, "error code: " + processResult.getExitCode(), "Failed to convert " + notebookPath + "\nstderr: " + processResult.getStderr() + "\nstdout: " + processResult.getStdout());
throw new ServiceException(RESTCodes.ServiceErrorCode.IPYTHON_CONVERT_ERROR, Level.SEVERE, "error code: " + processResult.getExitCode(), "Failed to convert " + notebookPath + "\nstderr: " + processResult.getStderr() + "\nstdout: " + processResult.getStdout());
}
String stdOut = processResult.getStdout();
if (!Strings.isNullOrEmpty(stdOut) && notebookConversion.equals(NotebookConversion.HTML)) {
StringBuilder renderedNotebookSB = new StringBuilder(stdOut);
int startIndex = renderedNotebookSB.indexOf("<html>");
int stopIndex = renderedNotebookSB.length();
return renderedNotebookSB.substring(startIndex, stopIndex);
}
return null;
} catch (IOException | ServiceDiscoveryException ex) {
throw new ServiceException(RESTCodes.ServiceErrorCode.IPYTHON_CONVERT_ERROR, Level.SEVERE, null, ex.getMessage(), ex);
} finally {
certificateMaterializer.removeCertificatesLocalCustomDir(user.getUsername(), project.getName(), conversionDir.getAbsolutePath());
}
}
use of com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException in project hopsworks by logicalclocks.
the class ProjectController method addServiceHive.
private void addServiceHive(Project project, Users user, DistributedFileSystemOps dfso, ProvTypeDTO datasetProvCore) throws ProjectException {
try {
hiveController.createDatabase(project.getName(), "Project general-purpose Hive database");
hiveController.createDatasetDb(project, user, dfso, project.getName(), datasetProvCore);
} catch (SQLException | IOException | ServiceDiscoveryException ex) {
throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_HIVEDB_CREATE_ERROR, Level.SEVERE, "project: " + project.getName(), ex.getMessage(), ex);
}
}
use of com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException in project hopsworks by logicalclocks.
the class KafkaBrokers method getBrokerEndpoints.
@Lock(LockType.READ)
public Set<String> getBrokerEndpoints() throws IOException, KeeperException, InterruptedException {
try {
String zkConnectionString = getZookeeperConnectionString();
final ZooKeeper zk = new ZooKeeper(zkConnectionString, Settings.ZOOKEEPER_SESSION_TIMEOUT_MS, new Watcher() {
@Override
public void process(WatchedEvent watchedEvent) {
// NOOP
}
});
try {
return zk.getChildren("/brokers/ids", false).stream().map(bi -> getBrokerInfo(zk, bi)).filter(StringUtils::isNoneEmpty).map(bi -> bi.split(KafkaConst.DLIMITER)).flatMap(Arrays::stream).filter(this::isValidBrokerInfo).collect(Collectors.toSet());
} finally {
zk.close();
}
} catch (ServiceDiscoveryException ex) {
throw new IOException(ex);
} catch (RuntimeException ex) {
if (ex.getCause() instanceof KeeperException) {
throw (KeeperException) ex.getCause();
}
if (ex.getCause() instanceof InterruptedException) {
throw (InterruptedException) ex.getCause();
}
throw ex;
}
}
use of com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException in project hopsworks by logicalclocks.
the class LivyController method deleteLivySession.
/**
* Delete livy session with given id
*
* @param sessionId
* @return
*/
public int deleteLivySession(int sessionId) {
Client client = ClientBuilder.newClient();
Response res;
try {
WebTarget target = client.target(getLivyURL()).path("/sessions/" + sessionId);
res = target.request().delete();
} catch (ServiceDiscoveryException ex) {
LOGGER.log(Level.SEVERE, null, ex);
return Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
} catch (NotFoundException e) {
return Response.Status.NOT_FOUND.getStatusCode();
} finally {
client.close();
}
return res.getStatus();
}
Aggregations