Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #75 from deflaux/master
Browse files Browse the repository at this point in the history
Switch minimal gRPC example to Application Default Credentials.
  • Loading branch information
Dion Loy committed Dec 9, 2015
2 parents b322082 + 54cefdc commit 2230645
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ If you wish to modify this code while also modifying a project that depends upon
* Import the project via File > Open and then double-click on the pom.xml file.

##gRPC
This project now includes code for calling the Genomics API using <a href="http://www.grpc.io">gRPC</a>.
Calling the API with gRPC should greatly improve performance but is still experimental (alpha). To use
This project now includes code for calling the Genomics API using <a href="http://www.grpc.io">gRPC</a>. To use
gRPC, you'll need a version of ALPN that matches your JRE version. See the
<a href="http://www.eclipse.org/jetty/documentation/9.2.10.v20150310/alpn-chapter.html">ALPN documentation</a>
for a table of which ALPN JAR to use. The latest version (as of June 2015) is provided in the lib/
Expand All @@ -66,9 +65,6 @@ java -Xbootclasspath/p:lib/alpn-boot-8.1.3.v20150130.jar

See [Example.java](src/main/java/com/google/cloud/genomics/utils/grpc/Example.java) for some example code that uses gRPC. The protocol buffer schema for the API can be found in [src/main/proto/google/genomics/v1](src/main/proto/google/genomics/v1).

At the moment your project must be whitelisted to use gRPC. Please
<a href="mailto:google-genomics-contact@googlegroups.com">contact us</a> if you are interested in testing gRPC.

###Generating gRPC code
Users should typically **not** need to generate gRPC code themselves, as pre-generated code can be found
in [src/main/java/com/google/genomics/v1](src/main/java/com/google/genomics/v1). For developers, code can be generated with
Expand All @@ -93,7 +89,6 @@ in [src/main/java/com/google/genomics/v1](src/main/java/com/google/genomics/v1).
MAVEN_OPTS="-Xbootclasspath/p:./lib/alpn-boot-8.1.3.v20150130.jar" \
mvn exec:java -Dexec.mainClass=com.google.cloud.genomics.utils.grpc.Example
```
* If you see error `Caused by: io.grpc.StatusRuntimeException: NOT_FOUND: Method not found.` your project has not been whitelisted. See the above [grpc](#grpc) section for more detail.
* [proto](src/main/proto)
* [Protocol Buffer](http://www.grpc.io/docs/#working-with-protocol-buffers
) files defing the gRPC interface to the Genomics API.
Expand Down
24 changes: 5 additions & 19 deletions src/main/java/com/google/cloud/genomics/utils/grpc/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import io.grpc.ManagedChannel;

import java.io.FileNotFoundException;
import java.util.Iterator;

import com.google.cloud.genomics.utils.GenomicsFactory;
import com.google.cloud.genomics.utils.GenomicsFactory.Builder;
import com.google.genomics.v1.ReferenceServiceV1Grpc;
import com.google.genomics.v1.ReferenceServiceV1Grpc.ReferenceServiceV1BlockingStub;
import com.google.genomics.v1.ReferenceSet;
Expand All @@ -20,23 +17,12 @@
public class Example {

public static void main(String[] args) throws Exception {
final String clientSecretsJson = "client_secrets.json";
GenomicsFactory.OfflineAuth auth = null;
try {
Builder builder =
GenomicsFactory.builder("gRPCExample");
auth = builder.build().getOfflineAuthFromClientSecretsFile(clientSecretsJson);
} catch (FileNotFoundException fex) {
System.out.println("Expecting to find " + clientSecretsJson +
" file in " +
"this directory and use it for authentication.\n" +
"Please make sure your project is whitelisted for gRPC access and\n" +
"generate and download JSON key for your service account.\n" +
"You can do that in API & Auth section of the Developer Console.");
return;
ManagedChannel channel;
if(args.length == 1) {
channel = GenomicsChannel.fromApiKey(args[0]);
} else {
channel = GenomicsChannel.fromDefaultCreds();
}

ManagedChannel channel = GenomicsChannel.fromOfflineAuth(auth);

// Regular RPC example: list all reference set assembly ids.
ReferenceServiceV1BlockingStub refStub =
Expand Down

0 comments on commit 2230645

Please sign in to comment.