-
Notifications
You must be signed in to change notification settings - Fork 136
/
DiagnosticsAware.java
54 lines (46 loc) · 1.71 KB
/
DiagnosticsAware.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Copyright 2019 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD 2-Clause License. See the LICENSE file in the project root for license information.
* See the NOTICE file in the project root for additional information regarding copyright ownership.
*/
package com.linkedin.datastream.common;
import java.net.URI;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
/**
* Classes that implement DiagnosticsAware should return the status or any information of a host/instance,
* and be able to reduce all the responses across different hosts/instances.
* The Restli request will call process on each host/instances, then aggregate all
* the responses by calling reduce to return a merged response.
*/
public interface DiagnosticsAware {
// Commonly used key in diagnostics queries
String DATASTREAM_KEY = "datastream";
/**
* Process the query of a single host/instance
* @return response such as the status of the host
*/
String process(String query);
/**
* Reduce/Merge the responses of a collection of host/instance into one response
*/
String reduce(String query, Map<String, String> responses);
/**
* Returns the decoded path component of the URI in {@code query}
* @throws java.net.URISyntaxException if {@code query} is not a
* valid URI per {@link URI#URI(String)}
*/
default String getPath(String query, Logger logger) throws Exception {
URI uri = new URI(query);
String path = uri.getPath();
if (StringUtils.isEmpty(path)) {
logger.error("invalid query (empty path): " + query);
return null;
}
if (path.startsWith("/")) {
path = path.substring(1);
}
return path;
}
}