Search in sources :

Example 26 with ServiceDiscoveryException

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);
    }
}
Also used : Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) SQLException(java.sql.SQLException) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) IOException(java.io.IOException) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException)

Example 27 with ServiceDiscoveryException

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());
    }
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) ClientBuilder(javax.ws.rs.client.ClientBuilder) ProcessResult(io.hops.hopsworks.common.util.ProcessResult) ProcessDescriptor(io.hops.hopsworks.common.util.ProcessDescriptor) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) IOException(java.io.IOException) File(java.io.File) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 28 with ServiceDiscoveryException

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);
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) SQLException(java.sql.SQLException) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) IOException(java.io.IOException)

Example 29 with ServiceDiscoveryException

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;
    }
}
Also used : Arrays(java.util.Arrays) Lock(javax.ejb.Lock) StringUtils(org.apache.commons.lang3.StringUtils) Level(java.util.logging.Level) HashSet(java.util.HashSet) Settings(io.hops.hopsworks.common.util.Settings) TransactionAttributeType(javax.ejb.TransactionAttributeType) Type(com.logicalclocks.servicediscoverclient.resolvers.Type) ServiceDiscoveryController(io.hops.hopsworks.common.hosts.ServiceDiscoveryController) TransactionAttribute(javax.ejb.TransactionAttribute) EJB(javax.ejb.EJB) ZooKeeper(org.apache.zookeeper.ZooKeeper) KeeperException(org.apache.zookeeper.KeeperException) ServiceQuery(com.logicalclocks.servicediscoverclient.service.ServiceQuery) Watcher(org.apache.zookeeper.Watcher) KafkaConst(io.hops.hopsworks.common.dao.kafka.KafkaConst) Set(java.util.Set) IOException(java.io.IOException) WatchedEvent(org.apache.zookeeper.WatchedEvent) Logger(java.util.logging.Logger) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) Collectors(java.util.stream.Collectors) LockType(javax.ejb.LockType) Singleton(javax.ejb.Singleton) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Collections(java.util.Collections) Watcher(org.apache.zookeeper.Watcher) IOException(java.io.IOException) WatchedEvent(org.apache.zookeeper.WatchedEvent) ZooKeeper(org.apache.zookeeper.ZooKeeper) StringUtils(org.apache.commons.lang3.StringUtils) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) Arrays(java.util.Arrays) KeeperException(org.apache.zookeeper.KeeperException) Lock(javax.ejb.Lock)

Example 30 with ServiceDiscoveryException

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();
}
Also used : Response(javax.ws.rs.core.Response) NotFoundException(javax.ws.rs.NotFoundException) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Aggregations

ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)32 IOException (java.io.IOException)16 ServiceException (io.hops.hopsworks.exceptions.ServiceException)11 Service (com.logicalclocks.servicediscoverclient.service.Service)7 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)6 SQLException (java.sql.SQLException)4 Level (java.util.logging.Level)4 TransactionAttribute (javax.ejb.TransactionAttribute)4 FeaturestoreStorageConnectorDTO (io.hops.hopsworks.common.featurestore.storageconnectors.FeaturestoreStorageConnectorDTO)3 ServiceDiscoveryController (io.hops.hopsworks.common.hosts.ServiceDiscoveryController)3 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)3 Featurestore (io.hops.hopsworks.persistence.entity.featurestore.Featurestore)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 List (java.util.List)3 HttpHost (org.apache.http.HttpHost)3 TemplateException (freemarker.template.TemplateException)2 FeaturestoreHopsfsConnectorDTO (io.hops.hopsworks.common.featurestore.storageconnectors.hopsfs.FeaturestoreHopsfsConnectorDTO)2 Settings (io.hops.hopsworks.common.util.Settings)2 ProjectException (io.hops.hopsworks.exceptions.ProjectException)2