Search in sources :

Example 21 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 22 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)

Example 23 with ServiceDiscoveryException

use of com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException in project hopsworks by logicalclocks.

the class FeaturestoreController method createOfflineJdbcConnector.

public FeaturestoreStorageConnectorDTO createOfflineJdbcConnector(String databaseName) throws FeaturestoreException {
    String hiveEndpoint = "";
    try {
        hiveEndpoint = serviceDiscoveryController.constructServiceFQDNWithPort(ServiceDiscoveryController.HopsworksService.HIVE_SERVER_TLS);
    } catch (ServiceDiscoveryException e) {
        throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.CONNECTOR_NOT_FOUND, Level.SEVERE, "Could not create Hive connection string", e.getMessage(), e);
    }
    String connectionString = HiveController.HIVE_JDBC_PREFIX + hiveEndpoint + "/" + databaseName + ";auth=noSasl;ssl=true;twoWay=true;";
    List<OptionDTO> arguments = FeaturestoreConstants.OFFLINE_JDBC_CONNECTOR_ARGS.stream().map(arg -> new OptionDTO(arg, null)).collect(Collectors.toList());
    FeaturestoreJdbcConnectorDTO featurestoreJdbcConnectorDTO = new FeaturestoreJdbcConnectorDTO();
    featurestoreJdbcConnectorDTO.setStorageConnectorType(FeaturestoreConnectorType.JDBC);
    featurestoreJdbcConnectorDTO.setName(databaseName);
    featurestoreJdbcConnectorDTO.setDescription("JDBC connector for the Offline Feature Store");
    featurestoreJdbcConnectorDTO.setConnectionString(connectionString);
    featurestoreJdbcConnectorDTO.setArguments(arguments);
    return featurestoreJdbcConnectorDTO;
}
Also used : ActivityFlag(io.hops.hopsworks.persistence.entity.user.activity.ActivityFlag) InodeController(io.hops.hopsworks.common.hdfs.inode.InodeController) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) DatasetController(io.hops.hopsworks.common.dataset.DatasetController) FeaturestoreJdbcConnectorDTO(io.hops.hopsworks.common.featurestore.storageconnectors.jdbc.FeaturestoreJdbcConnectorDTO) Date(java.util.Date) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) FeaturegroupFacade(io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupFacade) FeaturestoreConnectorType(io.hops.hopsworks.persistence.entity.featurestore.storageconnector.FeaturestoreConnectorType) OnlineFeaturestoreController(io.hops.hopsworks.common.featurestore.online.OnlineFeaturestoreController) Project(io.hops.hopsworks.persistence.entity.project.Project) Level(java.util.logging.Level) Settings(io.hops.hopsworks.common.util.Settings) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException) TransactionAttributeType(javax.ejb.TransactionAttributeType) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) ServiceDiscoveryController(io.hops.hopsworks.common.hosts.ServiceDiscoveryController) TransactionAttribute(javax.ejb.TransactionAttribute) HdfsUsersController(io.hops.hopsworks.common.hdfs.HdfsUsersController) Path(org.apache.hadoop.fs.Path) ProjectException(io.hops.hopsworks.exceptions.ProjectException) FeaturestoreStorageConnectorController(io.hops.hopsworks.common.featurestore.storageconnectors.FeaturestoreStorageConnectorController) EJB(javax.ejb.EJB) HiveController(io.hops.hopsworks.common.hive.HiveController) Stateless(javax.ejb.Stateless) TrainingDatasetFacade(io.hops.hopsworks.common.featurestore.trainingdatasets.TrainingDatasetFacade) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) Collection(java.util.Collection) DatasetException(io.hops.hopsworks.exceptions.DatasetException) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) ActivityFacade(io.hops.hopsworks.common.dao.user.activity.ActivityFacade) FeaturestoreConnectorFacade(io.hops.hopsworks.common.featurestore.storageconnectors.FeaturestoreConnectorFacade) DatasetType(io.hops.hopsworks.persistence.entity.dataset.DatasetType) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) Collectors(java.util.stream.Collectors) FeaturestoreStorageConnectorDTO(io.hops.hopsworks.common.featurestore.storageconnectors.FeaturestoreStorageConnectorDTO) FeaturestoreHopsfsConnectorDTO(io.hops.hopsworks.common.featurestore.storageconnectors.hopsfs.FeaturestoreHopsfsConnectorDTO) UserException(io.hops.hopsworks.exceptions.UserException) ProjectTeamFacade(io.hops.hopsworks.common.dao.project.team.ProjectTeamFacade) List(java.util.List) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) Users(io.hops.hopsworks.persistence.entity.user.Users) DistributedFsService(io.hops.hopsworks.common.hdfs.DistributedFsService) FeaturestoreJdbcConnectorDTO(io.hops.hopsworks.common.featurestore.storageconnectors.jdbc.FeaturestoreJdbcConnectorDTO) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException)

Example 24 with ServiceDiscoveryException

use of com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException in project hopsworks by logicalclocks.

the class SparkController method createSparkJob.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private SparkJob createSparkJob(String username, Jobs job, Users user) throws JobException, GenericException, ServiceException {
    SparkJob sparkjob = null;
    try {
        // Set Hopsworks consul service domain, don't use the address, use the name
        String hopsworksRestEndpoint = "https://" + serviceDiscoveryController.constructServiceFQDNWithPort(ServiceDiscoveryController.HopsworksService.HOPSWORKS_APP);
        UserGroupInformation proxyUser = ugiService.getProxyUser(username);
        try {
            sparkjob = proxyUser.doAs((PrivilegedExceptionAction<SparkJob>) () -> new SparkJob(job, submitter, user, settings.getHadoopSymbolicLinkDir(), hdfsUsersBean.getHdfsUserName(job.getProject(), user), settings, kafkaBrokers.getKafkaBrokersString(), hopsworksRestEndpoint, servingConfig, serviceDiscoveryController));
        } catch (InterruptedException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }
    } catch (IOException ex) {
        throw new JobException(RESTCodes.JobErrorCode.PROXY_ERROR, Level.SEVERE, "job: " + job.getId() + ", user:" + user.getUsername(), ex.getMessage(), ex);
    } catch (ServiceDiscoveryException ex) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.SERVICE_NOT_FOUND, Level.SEVERE, "job: " + job.getId() + ", user:" + user.getUsername(), ex.getMessage(), ex);
    }
    if (sparkjob == null) {
        throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ERROR, Level.WARNING, "Could not instantiate job with name: " + job.getName() + " and id: " + job.getId(), "sparkjob object was null");
    }
    return sparkjob;
}
Also used : JobException(io.hops.hopsworks.exceptions.JobException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) GenericException(io.hops.hopsworks.exceptions.GenericException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 25 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)

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 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 Level (java.util.logging.Level)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