Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

Commit

Permalink
244 peers (#247)
Browse files Browse the repository at this point in the history
* Peer service initial commit

* Change version

* Update client for when no ID is provided

* Add tests

* Fix comment, add newline

* 1kgenomes as default peer

* Change to url
  • Loading branch information
david4096 authored and ejacox committed Mar 6, 2017
1 parent 4eb7c6d commit 70aa3a8
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ctk-cli/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ctk.antfile=lib/antRunTests.xml
# which is already in "./lib"
# when run from command line (doesn't currently affect output when running maven)
# THIS IS A HACK FOR ANT, we should be scanning the lib dir (soon)
ctk.testjar=cts-java-0.6.0a7-tests.jar
ctk.testjar=cts-java-0.6.0a10-tests.jar

# this title (with ctk.tgt.urlRoot appended) goes on top of each HTML results page
# when run from command line (doesn't currently affect output when running maven)
Expand Down
2 changes: 1 addition & 1 deletion ctk-cli/src/main/resources/ctk
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CMD_DIR="$(cd "$(dirname "$CMD")" && pwd -P)"
# Defaults and command line options
[ "$VERBOSE" ] || VERBOSE=
[ "$DEBUG" ] || DEBUG=
[ "$CTKJAR" ] || CTKJAR="ctk-cli-0.6.0a7.jar"
[ "$CTKJAR" ] || CTKJAR="ctk-cli-0.6.0a10.jar"
[ "$TGTDIR" ] || TGTDIR="target"


Expand Down
2 changes: 1 addition & 1 deletion ctk-server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ctk.antfile=lib/antRunTests.xml
# which is already in "./lib"
# when run from command line (doesn't currently affect output when running maven)
# THIS IS A HACK FOR ANT, we should be scanning the lib dir (soon)
ctk.testjar=cts-java-0.6.0a7-tests.jar
ctk.testjar=cts-java-0.6.0a10-tests.jar

# this title (with ctk.tgt.urlRoot appended) goes on top of each HTML results page
# when run from command line (doesn't currently affect output when running maven)
Expand Down
2 changes: 1 addition & 1 deletion ctk-server/src/main/resources/ctk
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CMD_DIR="$(cd "$(dirname "$CMD")" && pwd -P)"
# Defaults and command line options
[ "$VERBOSE" ] || VERBOSE=
[ "$DEBUG" ] || DEBUG=
[ "$CTKJAR" ] || CTKJAR="ctk-server-0.6.0a7.jar"
[ "$CTKJAR" ] || CTKJAR="ctk-server-0.6.0a10.jar"
[ "$TGTDIR" ] || TGTDIR="target"


Expand Down
2 changes: 1 addition & 1 deletion ctk-testrunner/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ctk.antfile=lib/antRunTests.xml
# which is already in "./lib"
# when run from command line (doesn't currently affect output when running maven)
# THIS IS A HACK FOR ANT, we should be scanning the lib dir (soon)
ctk.testjar=cts-java-0.6.0a7-tests.jar
ctk.testjar=cts-java-0.6.0a10-tests.jar

# this title (with ctk.tgt.urlRoot appended) goes on top of each HTML results page
# when run from command line (doesn't currently affect output when running maven)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ public interface URLMAPPING {

void setGetExpressionLevel(String getExpressionLevel);

String getListPeers();

void setListPeers(String ListPeers);

String getAnnounce();

void setAnnounce(String getAnnounce);

String getInfo();

void setGetInfo(String getInfo);

Map<String, String> getEndpoints();

void setEndpoints(Map<String, String> endpoints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public class URLMAPPINGImpl implements URLMAPPING {
defaultEndpoints.put("ctk.tgt.searchGenotypePhenotype", "featurephenotypeassociations/search");
defaultEndpoints.put("ctk.tgt.searchPhenotypes", "phenotypes/search");

defaultEndpoints.put("ctk.tgt.listPeers", "peers/list");
defaultEndpoints.put("ctk.tgt.announce", "announce");
defaultEndpoints.put("ctk.tgt.getInfo", "info");

dumpToStdOut = Boolean.getBoolean("ctk.tgt.urlmapper.dump"); // so, -Dctk.tgt.urlmapper.dump=true

log.info("set default URLMAPPING urlRoot to " + defaultEndpoints.get("ctk.tgt.urlRoot"));
Expand Down Expand Up @@ -667,4 +671,31 @@ public void setSearchPhenotypeAssociationSets(String searchPhenotypeAssociationS
endpoints.put("ctk.tgt.searchPhenotypeAssociationSets", searchPhenotypeAssociationSets);
}

@Override
public String getListPeers() { return endpoints.get("ctk.tgt.listPeers"); }

@Override
public void setListPeers(String listPeers) {
assert(listPeers != null);
endpoints.put("ctk.tgt.listPeers", listPeers);
}

@Override
public String getAnnounce() { return endpoints.get("ctk.tgt.announce"); }

@Override
public void setAnnounce(String announce) {
assert(announce != null);
endpoints.put("ctk.tgt.announce", announce);
}

@Override
public String getInfo() { return endpoints.get("ctk.tgt.getInfo"); }

@Override
public void setGetInfo(String info) {
assert(info != null);
endpoints.put("ctk.tgt.getInfo", info);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ protected HttpResponse<JsonNode> queryServer(String url) throws UnirestException
if (log.isDebugEnabled()) {
log.debug("begin jsonGet to " + url + " id = " + id);
}
HttpResponse<JsonNode> response = Unirest.get(url)
.header("accept", "application/json")
.routeParam("id", id)
.queryString(queryParams)
.asJson();
HttpResponse<JsonNode> response;
if (id != null) {
response = Unirest.get(url)
.header("accept", "application/json")
.routeParam("id", id)
.queryString(queryParams)
.asJson();
} else {
response = Unirest.get(url)
.header("accept", "application/json")
.queryString(queryParams)
.asJson();
}
if (log.isDebugEnabled()) {
log.debug("exit jsonGet to " + url + " with status " + response.getStatusText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import ga4gh.BioMetadataServiceOuterClass.SearchBiosamplesResponse;
import ga4gh.BioMetadataServiceOuterClass.SearchIndividualsRequest;
import ga4gh.BioMetadataServiceOuterClass.SearchIndividualsResponse;
import ga4gh.PeerServiceOuterClass.Peer;
import ga4gh.PeerServiceOuterClass.*;
import org.ga4gh.ctk.transport.GAWrapperException;
import org.ga4gh.ctk.transport.URLMAPPING;
import org.ga4gh.ctk.transport.WireTracker;
Expand Down Expand Up @@ -149,6 +151,9 @@ public class Client {

public final BioMetadata bioMetadata = new BioMetadata();


public final Peers peers = new Peers();

/**
* Create a new client that can make requests on a GA4GH server.
*
Expand Down Expand Up @@ -807,4 +812,54 @@ public SearchPhenotypeAssociationSetsResponse searchPhenotypeAssociationSets(Sea
return builder.build();
}
}

/**
* Inner class holding all peer service related methods.
*/
public class Peers {
/**
* Lists available peers at the /peers/list endpoint using the given request.
* @param request A ListPeers request
* @return ListPeersResponse
* @throws GAWrapperException if the server finds the request invalid in some way
* @throws UnirestException if there's a problem speaking HTTP to the server
* @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
*/
public ListPeersResponse listPeers(ListPeersRequest request) throws InvalidProtocolBufferException, GAWrapperException, UnirestException {
String path = urls.getListPeers();
ListPeersResponse.Builder responseBuilder = ListPeersResponse.newBuilder();
new Post<>(urls.getUrlRoot(), path, request, responseBuilder, wireTracker).performQuery();
return responseBuilder.build();
}

/**
* Get info about the server at the /info endpoint.
* @return Info
* @throws GAWrapperException if the server finds the request invalid in some way
* @throws UnirestException if there's a problem speaking HTTP to the server
* @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
*/
public GetInfoResponse getInfo() throws InvalidProtocolBufferException, GAWrapperException, UnirestException {
String path = urls.getInfo();
GetInfoResponse.Builder builder = GetInfoResponse.newBuilder();
new Get<>(urls.getUrlRoot(), path, null, null, builder, wireTracker).performQuery();
return builder.build();
}

/**
* Announces a peer to the /announce endpoint.
* @param request A AnnouncePeer request
* @return AnnouncePeerResponse
* @throws GAWrapperException if the server finds the request invalid in some way
* @throws UnirestException if there's a problem speaking HTTP to the server
* @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
*/
public AnnouncePeerResponse announcePeer(AnnouncePeerRequest request) throws InvalidProtocolBufferException, GAWrapperException, UnirestException {
String path = urls.getAnnounce();
AnnouncePeerResponse.Builder responseBuilder = AnnouncePeerResponse.newBuilder();
new Post<>(urls.getUrlRoot(), path, request, responseBuilder, wireTracker).performQuery();
return responseBuilder.build();
}

}
}
3 changes: 3 additions & 0 deletions ctk-transport/src/main/resources/defaulttransport.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ ctk.tgt.searchFeatureSets=featuresets/search
ctk.tgt.searchContinuous=continuous/search
ctk.tgt.searchContinuousSets=continuoussets/search
ctk.tgt.searchPhenotypeAssociationSets=phenotypeassociationsets/search
ctk.tgt.listPeers=peers/list
ctk.tgt.getInfo=info
ctk.tgt.announce=announce
3 changes: 3 additions & 0 deletions cts-java/src/main/resources/defaulttransport.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ ctk.tgt.searchFeatureSets=featuresets/search
ctk.tgt.searchContinuous=continuous/search
ctk.tgt.searchContinuousSets=continuoussets/search
ctk.tgt.searchPhenotypeAssociationSets=phenotypeassociationsets/search
ctk.tgt.listPeers=peers/list
ctk.tgt.getInfo=info
ctk.tgt.announce=announce
80 changes: 80 additions & 0 deletions cts-java/src/test/java/org/ga4gh/cts/api/peers/PeersIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.ga4gh.cts.api.peers;

import com.google.protobuf.InvalidProtocolBufferException;
import com.mashape.unirest.http.exceptions.UnirestException;
import ga4gh.PeerServiceOuterClass;
import ga4gh.PeerServiceOuterClass.ListPeersRequest;
import ga4gh.PeerServiceOuterClass.ListPeersResponse;
import ga4gh.PeerServiceOuterClass.GetInfoResponse;
import ga4gh.PeerServiceOuterClass.GetInfoRequest;
import ga4gh.PeerServiceOuterClass.AnnouncePeerRequest;
import ga4gh.PeerServiceOuterClass.AnnouncePeerResponse;
import ga4gh.PeerServiceOuterClass.Peer;
import org.ga4gh.ctk.transport.GAWrapperException;
import org.ga4gh.ctk.transport.URLMAPPING;
import org.ga4gh.ctk.transport.protocols.Client;
import org.ga4gh.cts.api.TestData;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for the BioMetadata endpoints
*/
@Category(PeersTests.class)
public class PeersIT {

private static Client client = new Client(URLMAPPING.getInstance());

/**
* Tests the /peers/list endpoint to ensure a well formed peer (1kgenomes.ga4gh.org) is returned.
* @throws GAWrapperException if the server finds the request invalid in some way
* @throws UnirestException if there's a problem speaking HTTP to the server
* @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
*/
@Test
public void checkListPeers() throws InvalidProtocolBufferException, UnirestException, GAWrapperException {
final ListPeersRequest req =
ListPeersRequest.newBuilder()
.build();

final ListPeersResponse resp = client.peers.listPeers(req);
assertThat(resp.getPeersCount()).isGreaterThan(0);
final Peer peer = Peer.newBuilder().setUrl("http://1kgenomes.ga4gh.org").build();
assertThat(resp.getPeersList()).contains(peer);
}

/**
* Tests that the service will receive a well formed announce message without throwing an error.
* @throws GAWrapperException if the server finds the request invalid in some way
* @throws UnirestException if there's a problem speaking HTTP to the server
* @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
*/
@Test
public void checkValidAnnounce() throws InvalidProtocolBufferException, UnirestException, GAWrapperException {
final Peer peer = Peer.newBuilder().setUrl("http://1kgenomes.ga4gh.org").build();
final AnnouncePeerRequest req =
AnnouncePeerRequest.newBuilder()
.setPeer(peer)
.build();

final AnnouncePeerResponse resp = client.peers.announcePeer(req);
assertThat(resp).isNotNull();
assertThat(resp.getSuccess()).isTrue();
}

/**
* Tests that the service returns an expected info response at the /info endpoint including the protocol version.
* @throws GAWrapperException if the server finds the request invalid in some way
* @throws UnirestException if there's a problem speaking HTTP to the server
* @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
*/
@Test
public void checkGetInfo() throws InvalidProtocolBufferException, UnirestException, GAWrapperException {
final GetInfoResponse resp = client.peers.getInfo();
assertThat(resp).isNotNull();
assertThat(resp.getProtocolVersion()).isNotEmpty();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.ga4gh.cts.api.peers;


public interface PeersTests { /* category marker */
}
6 changes: 3 additions & 3 deletions docs/ConfigTheCTK.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can configure the CTK via the properties used by the:
If you're working with CTK/CTS source (in an IDE or for a Maven build) it's easiest to just edit `ctk-cli/src/main/resources/application.properties`, `ctk-server/src/main/resources/application.properties`, and `ctk-testrunner/src/main/resources/application.properties`, but these changes will have no effect until you rebuild (because the rebuild copies the files from `src/main/resources/` into `target/` which is where the code runs from). But, you can make temporary changes to the text properties files directly in the output build `target` tree.

If you're working with the CTK/CTS at the command line, you can extract that file from the packaged jar file and have it in the dir where the jar runs from
(`jar xvf ctk-cli-v.0.6.0a7.jar application.properties`) ... if you're using the ZIP distribution, it will already have extracted that properties file (and other control files) for you.
(`jar xvf ctk-cli-v.0.6.0a10.jar application.properties`) ... if you're using the ZIP distribution, it will already have extracted that properties file (and other control files) for you.

Note that individual test suites (`cts-java` etc) might have individual configuration mechanisms or properties files - refer to their documentation.

Expand All @@ -41,7 +41,7 @@ The Properties list is available by looking at the javadoc for the `ctk-testrunn

Because URLMAPPING initialization is a static action which might happen without logs being available, the URLMAPPING class has a special Java system property property to cause it to dump all the static initialization actions directly to stdout:

`java -Dctk.tgt.urlmapper.dump=true -jar ctk-cli-0.6.0a7.jar`
`java -Dctk.tgt.urlmapper.dump=true -jar ctk-cli-0.6.0a10.jar`

Note that many tests reinitialize the URLMAPPER in a @BeforeClass, so you may see the initialization get dumped multiple times!

Expand Down Expand Up @@ -70,7 +70,7 @@ To set properties as a command line variable (the highest priority) for a Maven
### Configuring a Command Line invocation
From the directory where the executable jar is, you can edit `application.properties`. The zip distribution has this file pre-extracted, but if you don't already have it, just extract it from the executable jar like this

jar xvf ctk-cli-0.6.0a7.jar application.properties
jar xvf ctk-cli-0.6.0a10.jar application.properties

Edit the properties file, and leave it in the launch directory or put it in a `config` subdirectory.

Expand Down
4 changes: 2 additions & 2 deletions docs/README-Server.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
This is an experimental web-server wrapper for the GA4GH Conformance Test Kit (CTK).

Run it using the included 'ctk' script, or simply as
java -jar ctk-server-0.6.0a7.jar
java -jar ctk-server-0.6.0a10.jar

Once it is running, it exposes a server at port 8080. (Being a Spring Boot app,
you can modify the port number with the normal --server.port= ... setting, like this:

./ctk --server.port=8088
or
java -jar ctk-server-0.6.0a7.jar --server.port=8088
java -jar ctk-server-0.6.0a10.jar --server.port=8088

To run the tests, you just browse to that server using a web browser; it
will run using the defaults and values set in the application properties file.
Expand Down
2 changes: 1 addition & 1 deletion docs/RunningTests_maven.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ processes):
2. edit `application-properties` (or set environment properties) to point to the in-source location of files, for example:
1. `ctk.antfile=../ctk-testrunner/src/main/resources/antRunTests.xml`
2. `ctk.defaulttransportfile=../ctk-transport/src/main/resources/defaulttransport.properties/defaulttransport.properties`
3. `ctk.testjar=../cts-java/target/cts-java-0.6.0a7-tests.jar`
3. `ctk.testjar=../cts-java/target/cts-java-0.6.0a10-tests.jar`
4. `ctk.testclassroots=../cts-java/target/test-classes`
5. `ctk.domaintypesfile=../ctk-domain/src/main/resources/avro-types.json`
2. manually create a `ctk-cli/lib` directory and copy into it the logging control file(s) from
Expand Down
8 changes: 4 additions & 4 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


<properties>
<compliance.version>0.6.0a7</compliance.version>
<compliance.version>0.6.0a10</compliance.version>
<!--
Use this section to indicate the repository and branch of schemas
your tests will be compiled against.
Expand All @@ -38,8 +38,8 @@
Then change the schemas.version to be the commit hash, release,
or branch snapshot you would like to test.
-->
<ga4gh.schemas.groupId>com.github.ga4gh</ga4gh.schemas.groupId>
<ga4gh.schemas.version>master-SNAPSHOT</ga4gh.schemas.version>
<ga4gh.schemas.groupId>com.github.david4096</ga4gh.schemas.groupId>
<ga4gh.schemas.version>760_peers-SNAPSHOT</ga4gh.schemas.version>
<ga4gh.schemas.artifactId>schemas</ga4gh.schemas.artifactId>
<ctk.tgt.urlRoot>http://localhost:8000</ctk.tgt.urlRoot>
<!-- Controls skipping of cts-java IT tests during build; skip the tests by passing
Expand Down Expand Up @@ -248,7 +248,7 @@

<!--Comment to use local schema build-->
<dependency>
<groupId>com.github.ga4gh</groupId>
<groupId>com.github.david4096</groupId>
<artifactId>schemas</artifactId>
<version>${ga4gh.schemas.version}</version>
</dependency>
Expand Down

0 comments on commit 70aa3a8

Please sign in to comment.