use of com.logicalclocks.servicediscoverclient.service.Service 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.service.Service in project hopsworks by logicalclocks.
the class PushgatewayMonitor method scrapeMetrics.
private PushgatewayResults scrapeMetrics() throws ServiceDiscoveryException, IOException {
Service pushgatewayService = serviceDiscoveryController.getAnyAddressOfServiceWithDNS(ServiceDiscoveryController.HopsworksService.PUSHGATEWAY);
HttpHost pushgatewayHost = new HttpHost(pushgatewayService.getAddress(), pushgatewayService.getPort());
return httpClient.execute(pushgatewayHost, new HttpGet(METRICS_ENDPOINT), new HttpClient.ObjectResponseHandler<>(PushgatewayResults.class, httpClient.getObjectMapper()));
}
use of com.logicalclocks.servicediscoverclient.service.Service in project hopsworks by logicalclocks.
the class ServiceDiscoveryController method getAnyAddressOfServiceWithDNSSRVOnly.
@Lock(LockType.READ)
public Service getAnyAddressOfServiceWithDNSSRVOnly(HopsworksService serviceName) throws ServiceDiscoveryException {
ServiceQuery serviceQuery = ServiceQuery.of(constructServiceFQDN(serviceName), Collections.emptySet());
DnsResolver client = (DnsResolver) getClient(Type.DNS);
Optional<Service> serviceOpt = client.getServiceSRVOnly(serviceQuery).findAny();
return serviceOpt.orElseThrow(() -> new ServiceNotFoundException("Could not find service with: " + serviceQuery));
}
use of com.logicalclocks.servicediscoverclient.service.Service 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.service.Service 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();
}
Aggregations