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);
}
}
}
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;
}
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);
}
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();
}
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);
}
}
Aggregations