Skip to content

Commit e4c3b60

Browse files
committed
Adding in more metrics to internal endpoint, fixing logging issues,
changing wiring in of external nodes to reading in from JSON file as inspired by Jules Jacobsen strategy of using a YAML file for this. For now using JSON for ease, can swtich to YAML if needed later
1 parent f009cc7 commit e4c3b60

File tree

7 files changed

+96
-25
lines changed

7 files changed

+96
-25
lines changed

Diff for: config/nodes.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"token" : "abcd",
55
"url" : "https://localhost:8443/match",
66
"contentTypeHeader" : "application/vnd.ga4gh.matchmaker.v1.0+json",
7-
"contentLanguage" : "application/vnd.ga4gh.matchmaker.v1.0+json",
8-
"acceptHeader" : "en-US",
7+
"contentLanguage" : "en-US",
8+
"acceptHeader" : "application/vnd.ga4gh.matchmaker.v1.0+json",
99
"selfSignedCertificate": true
1010
}]
1111
}

Diff for: src/main/java/org/broadinstitute/macarthurlab/matchbox/authentication/AuthenticationFilter.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public AuthenticationFilter(){
4646
String configFile = "file:" + System.getProperty("user.dir") + "/config/config.xml";
4747
ApplicationContext context = new ClassPathXmlApplicationContext(configFile);
4848
this.accessAuthorizedNode = context.getBean("accessAuthorizedNode", AccessAuthorizedNode.class);
49-
50-
System.out.println(this.getAccessAuthorizedNode());
49+
5150
Map<String,String> tokenToMMECenterMapping = new HashMap<String,String>();
5251
List<String> authorizedTokes=new ArrayList<String>();
5352
for(AuthorizedToken authorizeNode : this.getAccessAuthorizedNode().getAccessAuthorizedNodes()){
@@ -71,25 +70,28 @@ public void doFilter(ServletRequest req, ServletResponse res,
7170
HttpServletResponse response = (HttpServletResponse) res;
7271

7372
//----extract and validate headers from request----
74-
75-
//Unauthorized
73+
74+
//if Unauthorized, kick back immediately
7675
Map<String,String> validationResult=validateXAuthToken(request.getHeader(AuthenticationFilter.getxAuthTokenHeader()));
7776
if (validationResult.get("validated").equals("no")){
78-
this.getLogger().warn("authentication failed for: "+req.getServerName());
77+
this.getLogger().warn("authentication failed for: "+req.getServerName() + ": from node: " + validationResult.get("originMatchmakerNodeName"));
7978
response.sendError(401,"authentication failed");
8079
}
8180
//if authorized append the name of the center the match request came in from
8281
if (validationResult.get("validated").equals("yes")){
83-
request.setAttribute("originMatchmakerNodeName",validationResult.get("originMatchmakerNodeName"));
84-
}
85-
86-
87-
//unsupported API version
88-
if (!validateAcceptHeader(request.getHeader(AuthenticationFilter.getAcceptHeader()))){
89-
this.getLogger().warn("Accept header validation failed for: "+req.getServerName());
90-
response.sendError(406,"unsupported API version, supported versions=[1.0]");
82+
request.setAttribute("originMatchmakerNodeName",validationResult.get("originMatchmakerNodeName"));
83+
//then check if API version is supported
84+
if (!validateAcceptHeader(request.getHeader(AuthenticationFilter.getAcceptHeader()))){
85+
this.getLogger().warn("Accept header validation failed for: "+req.getServerName());
86+
this.getLogger().warn("This accept header provided is wrong: "+ request.getHeader(AuthenticationFilter.getAcceptHeader()));
87+
response.sendError(406,"unsupported API version, supported versions=[1.0]");
88+
}
89+
//OK everything looks good, move forward with this request
90+
else{
91+
this.getLogger().info("request passes access criteria, processing: " + validationResult.get("originMatchmakerNodeName"));
92+
chain.doFilter(request, response);
93+
}
9194
}
92-
chain.doFilter(request, response);
9395
}
9496

9597

Diff for: src/main/java/org/broadinstitute/macarthurlab/matchbox/entities/MatchmakerNode.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ public String getUrl() {
5353
}
5454

5555

56+
57+
5658
/* (non-Javadoc)
5759
* @see java.lang.Object#toString()
5860
*/
5961
@Override
6062
public String toString() {
6163
return "MatchmakerNode [name=" + name + ", token=" + token + ", url=" + url + ", acceptHeader=" + acceptHeader
62-
+ ", contentHeader=" + contentTypeHeader + ", contentLanguage=" + contentLanguage + "]";
64+
+ ", contentTypeHeader=" + contentTypeHeader + ", contentLanguage=" + contentLanguage
65+
+ ", selfSignedCertificate=" + selfSignedCertificate + "]";
6366
}
6467

6568

Diff for: src/main/java/org/broadinstitute/macarthurlab/matchbox/entities/PrivilegedMetric.java

+68-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
*/
88
package org.broadinstitute.macarthurlab.matchbox.entities;
99

10+
11+
import java.util.Map;
12+
1013
/**
1114
* @author harindra
1215
*
1316
*/
1417
public class PrivilegedMetric extends PublicMetric{
18+
19+
private Map<String,Integer> geneCounts;
20+
private Map<String,Integer> phenotypeCounts;
1521

1622
/**
1723
* default constructor
@@ -20,17 +26,76 @@ public PrivilegedMetric() {
2026
super();
2127
}
2228

23-
/**
24-
* Primary constructor
29+
30+
/**
31+
* @param numberOfSubmitters
32+
* @param numberOfUniqueGenes
33+
* @param numberOfUniqueFeatures
34+
* @param numberOfCasesWithDiagnosis
35+
* @param numberOfCases
36+
* @param percentageOfGenesThatMatch
37+
* @param meanNumberOfGenesPerCase
38+
* @param meanNumberOfVariantsPerCase
39+
* @param meanNumberOfPhenotypesPerCase
40+
* @param numberOfRequestsReceived
41+
* @param numberOfPotentialMatchesSent
42+
* @param geneCounts
2543
*/
2644
public PrivilegedMetric(int numberOfSubmitters, int numberOfUniqueGenes, int numberOfUniqueFeatures,
2745
int numberOfCasesWithDiagnosis, int numberOfCases, double percentageOfGenesThatMatch,
2846
double meanNumberOfGenesPerCase, double meanNumberOfVariantsPerCase, double meanNumberOfPhenotypesPerCase,
29-
int numberOfRequestsReceived, int numberOfPotentialMatchesSent) {
47+
int numberOfRequestsReceived, int numberOfPotentialMatchesSent,
48+
Map<String,Integer> geneCounts,
49+
Map<String,Integer> phenotypeCounts) {
50+
3051
super(numberOfSubmitters, numberOfUniqueGenes, numberOfUniqueFeatures, numberOfCasesWithDiagnosis, numberOfCases,
3152
percentageOfGenesThatMatch, meanNumberOfGenesPerCase, meanNumberOfVariantsPerCase,
3253
meanNumberOfPhenotypesPerCase, numberOfRequestsReceived, numberOfPotentialMatchesSent);
54+
55+
this.geneCounts = geneCounts;
56+
this.phenotypeCounts = phenotypeCounts;
57+
}
58+
59+
60+
61+
62+
63+
64+
/**
65+
* @return the geneCounts
66+
*/
67+
public Map<String, Integer> getGeneCounts() {
68+
return geneCounts;
69+
}
70+
71+
/**
72+
* @param geneCounts the geneCounts to set
73+
*/
74+
public void setGeneCounts(Map<String, Integer> geneCounts) {
75+
this.geneCounts = geneCounts;
3376
}
77+
78+
79+
/**
80+
* @return the phenotypeCounts
81+
*/
82+
public Map<String, Integer> getPhenotypeCounts() {
83+
return phenotypeCounts;
84+
}
85+
86+
87+
/**
88+
* @param phenotypeCounts the phenotypeCounts to set
89+
*/
90+
public void setPhenotypeCounts(Map<String, Integer> phenotypeCounts) {
91+
this.phenotypeCounts = phenotypeCounts;
92+
}
93+
94+
95+
96+
97+
98+
3499

35100

36101
}

Diff for: src/main/java/org/broadinstitute/macarthurlab/matchbox/metrics/PrivilegedMetricServiceImpl.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public Metric getMetrics() {
6363
this.getMeanNumberOfVariantsPerCase(allPatients),
6464
this.getMeanNumberOfPhenotypesPerCase(allPatients),
6565
this.getNumOfIncomingMatchRequests(),
66-
this.getNumOfMatches());
66+
this.getNumOfMatches(),
67+
this.countGenesInSystem(allPatients),
68+
this.countPhenotypesInSystem(allPatients));
6769
}
6870

6971

Diff for: src/main/java/org/broadinstitute/macarthurlab/matchbox/network/Communication.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public List<MatchmakerResult> callNode(Node matchmakerNode, Patient queryPatient
7171
connection.setRequestProperty("X-Auth-Token",matchmakerNode.getToken());
7272
connection.setRequestProperty("Content-Type",matchmakerNode.getContentTypeHeader());
7373
connection.setRequestProperty("Accept",matchmakerNode.getAcceptHeader());
74-
connection.setRequestProperty("Content-Language",matchmakerNode.getContentLanguage());
75-
74+
connection.setRequestProperty("Content-Language",matchmakerNode.getContentLanguage());
75+
7676
connection.setUseCaches(false);
7777
connection.setDoOutput(true);
7878

@@ -114,7 +114,6 @@ public List<MatchmakerResult> callNode(Node matchmakerNode, Patient queryPatient
114114

115115
}
116116
} catch (Exception e) {
117-
e.printStackTrace();
118117
this.getLogger().error("error connecting to: " + matchmakerNode.getName() + ", moving on.. : "+e.getMessage());
119118
} finally {
120119
if(connection != null) {

Diff for: src/main/java/org/broadinstitute/macarthurlab/matchbox/search/MatchmakerSearchImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public List<String> searchInLocalDatabaseOnly(Patient queryPatient, String hostN
179179
*/
180180
private List<MatchmakerResult> searchNode(Node matchmakerNode, Patient queryPatient) {
181181
this.getLogger().info("searching in external node: "+matchmakerNode.getName());
182-
return this.getHttpCommunication().callNode(matchmakerNode, queryPatient);
182+
return this.getHttpCommunication().callNode(matchmakerNode, queryPatient);
183183
}
184184

185185

0 commit comments

Comments
 (0)