Search in sources :

Example 6 with ServiceDiscoveryException

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

the class PushgatewayMonitor method removeActiveApplications.

private void removeActiveApplications(PushgatewayResults pushgatewayResults, List<String> applications) throws ServiceDiscoveryException {
    Set<Map<String, String>> groupsToRemove = new HashSet<>();
    // Get unique group information (labels) containing the application id to remove
    for (String application : applications) {
        groupsToRemove.addAll(pushgatewayResults.getData().stream().flatMap(m -> m.values().stream()).filter(serie -> serie.getMetrics() != null).map(PushgatewaySerie::getMetrics).map(metric -> metric.get(0).getLabels()).filter(labels -> labels.get("job").equalsIgnoreCase(application)).collect(Collectors.toSet()));
    }
    // For each group send a request to pushgateway to remove the group
    Service pushgatewayService = serviceDiscoveryController.getAnyAddressOfServiceWithDNS(ServiceDiscoveryController.HopsworksService.PUSHGATEWAY);
    HttpHost pushgatewayHost = new HttpHost(pushgatewayService.getAddress(), pushgatewayService.getPort());
    String groupPath = "";
    for (Map<String, String> group : groupsToRemove) {
        // Job has to go first
        String job = group.remove("job");
        groupPath = "/metrics/job/" + job + "/" + group.entrySet().stream().map(e -> e.getKey() + "/" + e.getValue()).collect(Collectors.joining("/"));
        HttpDelete httpDelete = new HttpDelete(groupPath);
        try {
            httpClient.execute(pushgatewayHost, httpDelete, new HttpClient.NoBodyResponseHandler<>());
        } catch (IOException e) {
            // Keep iterating if there is an issue with a group
            LOGGER.log(Level.SEVERE, "Error deleting group: " + groupPath, e);
        }
    }
}
Also used : YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) YarnClientService(io.hops.hopsworks.common.yarn.YarnClientService) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) HttpDelete(org.apache.http.client.methods.HttpDelete) DependsOn(javax.ejb.DependsOn) Timer(javax.ejb.Timer) Service(com.logicalclocks.servicediscoverclient.service.Service) ServiceDiscoveryController(io.hops.hopsworks.common.hosts.ServiceDiscoveryController) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) Map(java.util.Map) Schedule(javax.ejb.Schedule) EJB(javax.ejb.EJB) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) Collectors(java.util.stream.Collectors) YarnClientWrapper(io.hops.hopsworks.common.yarn.YarnClientWrapper) List(java.util.List) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) HttpClient(io.hops.hopsworks.common.proxies.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) Singleton(javax.ejb.Singleton) FinalApplicationStatus(org.apache.hadoop.yarn.api.records.FinalApplicationStatus) Pattern(java.util.regex.Pattern) HttpHost(org.apache.http.HttpHost) HttpDelete(org.apache.http.client.methods.HttpDelete) YarnClientService(io.hops.hopsworks.common.yarn.YarnClientService) Service(com.logicalclocks.servicediscoverclient.service.Service) IOException(java.io.IOException) HttpHost(org.apache.http.HttpHost) HttpClient(io.hops.hopsworks.common.proxies.client.HttpClient) Map(java.util.Map) HashSet(java.util.HashSet)

Example 7 with ServiceDiscoveryException

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

the class LocalhostServingController method getServingInternal.

/**
 * Gets the internal representation of a serving. The internal represenation contains extra information that
 * is not exposed to the user, such as status, available replicas, nodeport, and extended kafka details
 *
 * @param serving the serving to get the internal representation for
 * @return internal representation of the serving
 */
private ServingWrapper getServingInternal(Serving serving) throws ServingException {
    ServingWrapper servingWrapper = new ServingWrapper(serving);
    ServingStatusEnum status = getServingStatus(serving);
    servingWrapper.setStatus(status);
    switch(status) {
        case STOPPED:
        case STARTING:
        case UPDATING:
            servingWrapper.setAvailableReplicas(0);
            servingWrapper.setInternalPort(null);
            break;
        case RUNNING:
            servingWrapper.setAvailableReplicas(1);
            servingWrapper.setInternalPort(serving.getLocalPort());
    }
    String internalIP;
    try {
        internalIP = serviceDiscoveryController.getAnyAddressOfServiceWithDNS(ServiceDiscoveryController.HopsworksService.HOPSWORKS_APP).getAddress();
    } catch (ServiceDiscoveryException e) {
        String userMsg = "Could not find internal host for serving instance '" + serving.getName() + "'";
        throw new ServingException(RESTCodes.ServingErrorCode.STATUSERROR, Level.FINE, userMsg);
    }
    servingWrapper.setInternalIPs(Collections.singletonList(internalIP));
    String path;
    if (serving.getModelServer() == ModelServer.TENSORFLOW_SERVING) {
        path = localhostTfInferenceUtils.getPath(serving.getName(), serving.getModelVersion(), null);
    } else if (serving.getModelServer() == ModelServer.PYTHON) {
        path = localhostSkLearnInferenceUtils.getPath(null);
    } else {
        throw new UnsupportedOperationException("Model server not supported as local serving");
    }
    servingWrapper.setInternalPath(path);
    // These values will be fetched from the location href in the UI (client-side). By doing this, we make sure
    // that we display the correct host and port to reach Hopsworks. For instance, using proxies or SSH
    // tunneling, the port might differ from the default 80 or 443 on the client side.
    servingWrapper.setExternalIP(null);
    servingWrapper.setExternalPort(null);
    servingWrapper.setKafkaTopicDTO(kafkaServingHelper.buildTopicDTO(serving));
    return servingWrapper;
}
Also used : ServingException(io.hops.hopsworks.exceptions.ServingException) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)

Example 8 with ServiceDiscoveryException

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

the class Settings method getAlertManagerAddress.

public static URI getAlertManagerAddress(String serviceFQDN, String scheme) throws ServiceDiscoveryException {
    serviceFQDN = Strings.isNullOrEmpty(serviceFQDN) ? DEFAULT_ALERTMANAGER_FQDN : serviceFQDN;
    if (alertManagerAddresses.get(serviceFQDN) == null) {
        Optional<Service> optionalService = getAlertManagerService(serviceFQDN);
        Service service = optionalService.orElseThrow(() -> new ServiceDiscoveryException("Service not found."));
        UriBuilder uriBuilder = UriBuilder.fromPath("").scheme(Strings.isNullOrEmpty(scheme) ? "http" : scheme).host(service.getName());
        if (service.getPort() != null && service.getPort() > 0) {
            uriBuilder.port(service.getPort());
        }
        URI alertManagerAddress = uriBuilder.build();
        alertManagerAddresses.put(serviceFQDN, alertManagerAddress);
    }
    return alertManagerAddresses.get(serviceFQDN);
}
Also used : Service(com.logicalclocks.servicediscoverclient.service.Service) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI)

Example 9 with ServiceDiscoveryException

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

the class ClusterUtilisationService method metrics.

@GET
@Path("/metrics")
@Produces(MediaType.APPLICATION_JSON)
public Response metrics() throws ServiceException {
    Service rm = null;
    try {
        rm = serviceDiscoveryController.getAnyAddressOfServiceWithDNS(ServiceDiscoveryController.HopsworksService.HTTPS_RESOURCEMANAGER);
    } catch (ServiceDiscoveryException e) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.SERVICE_DISCOVERY_ERROR, Level.FINE);
    }
    HttpHost rmHost = new HttpHost(rm.getAddress(), rm.getPort(), "https");
    HttpGet getRequest = new HttpGet(METRICS_ENDPOINT);
    // defined as string as we don't really need to look inside it
    String response = null;
    try {
        response = httpClient.execute(rmHost, getRequest, new HttpClient.StringResponseHandler());
    } catch (IOException e) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.RM_METRICS_ERROR, Level.FINE);
    }
    JSONObject jsonObject = new JSONObject(response);
    jsonObject.put("deploying", hostsFacade.countUnregistered());
    return Response.ok().entity(jsonObject.toString()).build();
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) JSONObject(org.json.JSONObject) HttpHost(org.apache.http.HttpHost) HttpGet(org.apache.http.client.methods.HttpGet) Service(com.logicalclocks.servicediscoverclient.service.Service) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with ServiceDiscoveryException

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

the class OnlineFeaturestoreController method initConnection.

/**
 * Initializes a JDBC connection MySQL Server using an online featurestore user and password
 *
 * @param databaseName name of the MySQL database to open a connection to
 * @param project      the project of the user making the request
 * @param user         the user making the request
 * @return conn the JDBC connection
 * @throws FeaturestoreException
 */
private Connection initConnection(String databaseName, Project project, Users user) throws FeaturestoreException {
    String jdbcString = "";
    String dbUsername = onlineDbUsername(project, user);
    String password = "";
    try {
        password = secretsController.get(user, dbUsername).getPlaintext();
    } catch (UserException e) {
        throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.FEATURESTORE_ONLINE_SECRETS_ERROR, Level.SEVERE, "Problem getting secrets for the JDBC connection to the online FS");
    }
    try {
        return DriverManager.getConnection(getJdbcURL(databaseName), dbUsername, password);
    } catch (SQLException | ServiceDiscoveryException e) {
        throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.COULD_NOT_INITIATE_MYSQL_CONNECTION_TO_ONLINE_FEATURESTORE, Level.SEVERE, "project: " + project.getName() + ", database: " + databaseName + ", db user:" + dbUsername + ", jdbcString: " + jdbcString, e.getMessage(), e);
    }
}
Also used : SQLException(java.sql.SQLException) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) UserException(io.hops.hopsworks.exceptions.UserException) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException)

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