Permalink
Browse files

Moving to V1 of the API, updating all deps

  • Loading branch information...
1 parent e07025a commit 33ad437bd9f7b00c03da35e4f73c9f8fb4911938 @iliat iliat committed Jul 25, 2016
Binary file not shown.
View
19 pom.xml
@@ -7,7 +7,7 @@
<name>Google Genomics Utils for GATK</name>
<description>Common Java files for Google Genomics integrations with GATK/Picard/HTSJDK</description>
<url>https://github.com/googlegenomics/gatk-tools-java</url>
- <version>1.5-SNAPSHOT</version>
+ <version>v1-0.6-SNAPSHOT</version>
<organization>
<name>Google</name>
@@ -55,7 +55,7 @@
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
-
+
<dependencies>
<!-- Google client dependencies -->
<dependency>
@@ -96,10 +96,11 @@
<artifactId>google-http-client-jackson2</artifactId>
<version>${google.api.version}</version>
</dependency>
+
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-genomics</artifactId>
- <version>v1beta2-rev9-1.19.0</version>
+ <version>${google.api.genomics.version}</version>
<exclusions>
<!-- Exclude an old version of guava which is being pulled
in by a transitive dependency google-api-client 1.19.0 -->
@@ -112,7 +113,7 @@
<dependency>
<groupId>com.google.cloud.genomics</groupId>
<artifactId>google-genomics-utils</artifactId>
- <version>v1beta2-0.31</version>
+ <version>v1-0.6</version>
<exclusions>
<!-- Exclude an old version of guava which is being pulled
in by a transitive dependency google-api-client 1.19.0 -->
@@ -195,6 +196,11 @@
<artifactId>jcommander</artifactId>
<version>${jcommander.version}</version>
</dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-all</artifactId>
+ <version>${io.grpc.version}</version>
+ </dependency>
</dependencies>
<profiles>
@@ -357,8 +363,9 @@
<jetty.version>6.1.26</jetty.version>
<jackson.version>2.4.2</jackson.version>
<junit.version>4.11</junit.version>
- <google.api.version>1.19.0</google.api.version>
- <google.api.genomics.version>v1beta2-rev7-1.19.0</google.api.genomics.version>
+ <google.api.version>1.22.0</google.api.version>
+ <google.api.genomics.version>v1-rev87-1.22.0</google.api.genomics.version>
+ <io.grpc.version>0.15.0</io.grpc.version>
<mockito.version>1.10.8</mockito.version>
<jcommander.version>1.35</jcommander.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -21,7 +21,7 @@
/**
* Represents a GA4GH reads resource as a URL in the form of
* ga4gh://<base api path>/readsets/<readgroupset>/<sequence>/[start-end],
- * e.g. ga4gh://www.googleapis.com/genomics/v1beta2/readgroupsets/CMvnhpKTFhD04eLE-q2yxnU/1/
+ * e.g. ga4gh://genomics.googleapis.com/v1/readgroupsets/CMvnhpKTFhD04eLE-q2yxnU/1/
*/
public class GA4GHUrl {
int rangeStart = 0;
@@ -23,6 +23,8 @@
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.security.GeneralSecurityException;
import java.util.logging.Logger;
@@ -53,22 +55,30 @@ public GenomicsDataSourceBase(String rootUrl,
this.rootUrl = rootUrl;
}
- protected GenomicsFactory getFactory() throws GeneralSecurityException, IOException {
+ protected GenomicsFactory getFactory() {
if (factory == null) {
factory = initGenomicsFactory();
}
return factory;
}
- protected GenomicsFactory initGenomicsFactory() throws GeneralSecurityException, IOException {
- VerificationCodeReceiver receiver = noLocalServer ?
- new GooglePromptReceiver() : new LocalServerReceiver();
- return GenomicsFactory
- .builder("genomics_java_client")
- .setRootUrl(rootUrl)
- .setServicePath("/")
- .setVerificationCodeReceiver(Suppliers.ofInstance(receiver))
- .build();
+ protected GenomicsFactory initGenomicsFactory() {
+ // Remove any path component from the root url - the code expects
+ // e.g. https://genomics.googleapis.com
+ URL url = null;
+ try {
+ url = new URL(rootUrl);
+ } catch (MalformedURLException e) {
+ // Will not set url
+ }
+ GenomicsFactory.Builder builder = GenomicsFactory
+ .builder("genomics_java_client");
+ if (url != null) {
+ String rootUrlString = url.getProtocol() + "://" + url.getHost();
+ LOG.info("Initializing genomics factory with root url " + rootUrlString);
+ builder.setRootUrl(rootUrlString);
+ }
+ return builder.build();
}
static final String CLIENT_SECRETS_INSTRUCTIONS =
@@ -20,7 +20,7 @@
/**
* Creates GenomicsApiDataSource objects, one per each root url
- * (e.g. https://www.googleapis.com/genomics/v1beta2).
+ * (e.g. https://genomics.googleapis.com/v1).
* Allows configuring settings such as client secrets file on a per
* root url basis.
* This class is abstract and is later specialized for API vs. GRPC.
@@ -15,11 +15,11 @@
*/
package com.google.cloud.genomics.gatk.common.grpc;
-import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
-import com.google.api.client.googleapis.util.Utils;
-import com.google.auth.oauth2.UserCredentials;
import com.google.cloud.genomics.gatk.common.GenomicsDataSourceBase;
-import com.google.cloud.genomics.utils.GenomicsFactory.OfflineAuth;
+import com.google.cloud.genomics.utils.CredentialFactory;
+import com.google.cloud.genomics.utils.OfflineAuth;
+import com.google.cloud.genomics.utils.grpc.GenomicsChannel;
+import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@@ -39,25 +39,14 @@
import com.google.genomics.v1.StreamReadsResponse;
import com.google.genomics.v1.StreamingReadServiceGrpc;
import com.google.genomics.v1.StreamingReadServiceGrpc.StreamingReadServiceBlockingStub;
-
import io.grpc.Channel;
-import io.grpc.ChannelImpl;
-import io.grpc.ClientInterceptors;
-import io.grpc.auth.ClientAuthInterceptor;
-import io.grpc.transport.netty.GrpcSslContexts;
-import io.grpc.transport.netty.NegotiationType;
-import io.grpc.transport.netty.NettyChannelBuilder;
-
+import io.grpc.ManagedChannel;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
import java.security.GeneralSecurityException;
-import java.util.ArrayList;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.Executors;
/**
* Manages Genomics GRPC Api initialization and provides Read iterator based
@@ -66,8 +55,7 @@
public class GenomicsDataSource
extends GenomicsDataSourceBase<Read, ReadGroupSet, Reference> {
/** gRPC channel used for faster access to Genomics API */
- private Channel channel;
- private ChannelImpl channelImpl;
+ private ManagedChannel channel;
public GenomicsDataSource(String rootUrl,
String clientSecretsFilename,
@@ -83,41 +71,19 @@ private Channel getChannel() throws FileNotFoundException, IOException, GeneralS
return channel;
}
- private Channel initGenomicsChannel() throws FileNotFoundException, IOException, GeneralSecurityException {
- checkParamsForAuth(AUTH_REQUIREMENTS.CLIENT_SECRETS_ONLY);
- final GoogleClientSecrets secrets = GoogleClientSecrets.load(
- Utils.getDefaultJsonFactory(),
- new FileReader(clientSecretsFilename));
- final OfflineAuth auth = getFactory()
- .getOfflineAuthFromClientSecretsFile(clientSecretsFilename);
- final UserCredentials userCredentials = new UserCredentials(
- secrets.getInstalled().getClientId(),
- secrets.getInstalled().getClientSecret(),
- auth.refreshToken);
-
- // Java 8's implementation of GCM ciphers is extremely slow. Therefore we disable
- // them here.
- List<String> defaultCiphers =
- GrpcSslContexts.forClient().ciphers(null).build().cipherSuites();
- List<String> performantCiphers = new ArrayList<>();
- for (String cipher : defaultCiphers) {
- if (!cipher.contains("GCM")) {
- performantCiphers.add(cipher);
- }
+ private ManagedChannel initGenomicsChannel() throws FileNotFoundException, IOException, GeneralSecurityException {
+ if (clientSecretsFilename != null && clientSecretsFilename.length() > 0) {
+ return GenomicsChannel.fromOfflineAuth(
+ new OfflineAuth(
+ CredentialFactory.getCredentialFromClientSecrets(
+ clientSecretsFilename,
+ "genomics_java_client")));
}
- channelImpl = NettyChannelBuilder.forAddress("genomics.googleapis.com", 443)
- .negotiationType(NegotiationType.TLS)
- .streamWindowSize(1000000)
- .sslContext(GrpcSslContexts.forClient().ciphers(performantCiphers).build())
- .build();
- /*userCredentials = userCredentials.createScoped(
- Arrays.asList("https://www.googleapis.com/auth/genomics"));*/
- ClientAuthInterceptor interceptor = new ClientAuthInterceptor(userCredentials,
- Executors.newSingleThreadExecutor());
- return ClientInterceptors.intercept(channelImpl, interceptor);
+ // API Key is not sufficient for StreamReads request.
+ // TODO: All support for non default credentials will be removed in a subsequent PR.
+ return GenomicsChannel.fromDefaultCreds();
}
-
@Override
public ReadIteratorResource getReads(
@@ -183,15 +149,15 @@ public ReadIteratorResource getReads(
private Map<String, Reference> getReferences(ReadGroupSet readGroupSet)
throws IOException, GeneralSecurityException {
Set<String> referenceSetIds = Sets.newHashSet();
- if (readGroupSet.getReferenceSetId() != null && !readGroupSet.getReferenceSetId().isEmpty()) {
+ if (!Strings.isNullOrEmpty(readGroupSet.getReferenceSetId())) {
LOG.info("Found reference set from read group set " +
readGroupSet.getReferenceSetId());
referenceSetIds.add(readGroupSet.getReferenceSetId());
}
if (readGroupSet.getReadGroupsCount() > 0) {
LOG.info("Found read groups");
for (ReadGroup readGroup : readGroupSet.getReadGroupsList()) {
- if (readGroup.getReferenceSetId() != null && !readGroup.getReferenceSetId().isEmpty()) {
+ if (!Strings.isNullOrEmpty(readGroup.getReferenceSetId())) {
LOG.info("Found reference set from read group: " +
readGroup.getReferenceSetId());
referenceSetIds.add(readGroup.getReferenceSetId());
@@ -217,7 +183,7 @@ public ReadIteratorResource getReads(
GetReferenceRequest getReferenceRequest = GetReferenceRequest
.newBuilder().setReferenceId(referenceId).build();
Reference reference = referenceSetStub.getReference(getReferenceRequest);
- if (reference.getName() != null && !reference.getName().isEmpty()) {
+ if (!Strings.isNullOrEmpty(reference.getName())) {
references.put(reference.getName(), reference);
LOG.fine("Adding reference " + reference.getName());
}
@@ -316,9 +282,8 @@ public void remove() {
@Override
public void close() {
- if (channelImpl != null ) {
- channelImpl.shutdown();
- channelImpl = null;
+ if (channel != null ) {
+ channel.shutdown();
}
channel = null;
}
@@ -15,12 +15,9 @@
*/
package com.google.cloud.genomics.gatk.common.rest;
-import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
-import com.google.api.client.http.HttpRequest;
-import com.google.api.client.http.HttpRequestInitializer;
-import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.genomics.Genomics;
+import com.google.api.services.genomics.model.Program;
import com.google.api.services.genomics.model.Read;
import com.google.api.services.genomics.model.ReadGroup;
import com.google.api.services.genomics.model.ReadGroupSet;
@@ -29,11 +26,11 @@
import com.google.api.services.genomics.model.SearchReadsRequest;
import com.google.cloud.genomics.gatk.common.GenomicsDataSourceBase;
import com.google.cloud.genomics.utils.Paginator;
-import com.google.cloud.genomics.utils.Paginator.ShardBoundary;
+import com.google.cloud.genomics.utils.ShardBoundary;
+import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-
import java.io.File;
import java.io.IOException;
import java.security.GeneralSecurityException;
@@ -76,22 +73,8 @@ private Genomics initGenomicsApi() throws GeneralSecurityException, IOException
LOG.info("Using API key");
return getFactory().fromApiKey(apiKey);
}
- } else {
- final Genomics.Builder builder = new Genomics
- .Builder(
- GoogleNetHttpTransport.newTrustedTransport(),
- JacksonFactory.getDefaultInstance(),
- new HttpRequestInitializer() {
- @Override public void initialize(HttpRequest httpRequest) throws IOException {
- httpRequest.setReadTimeout(20000);
- httpRequest.setConnectTimeout(20000);
- }
- })
- .setApplicationName("genomics_java_client")
- .setRootUrl(rootUrl)
- .setServicePath("/");
- return builder.build();
- }
+ }
+ return getFactory().fromApplicationDefaultCredential();
}
@Override
@@ -106,6 +89,19 @@ public ReadIteratorResource getReads(String readsetId,
ReadGroupSet readGroupSet = stub.readgroupsets().get(readsetId).execute();
String datasetId = readGroupSet.getDatasetId();
LOG.info("Found readset " + readsetId + ", dataset " + datasetId);
+ // Fix up PP in Programs
+
+ if (readGroupSet.getReadGroups() != null) {
+ for (ReadGroup readGroup : readGroupSet.getReadGroups()) {
+ if (readGroup.getPrograms() != null) {
+ for (Program PG : readGroup.getPrograms()) {
+ if (PG.getPrevProgramId() != null && PG.getPrevProgramId().length() == 0) {
+ PG.setPrevProgramId(null);
+ }
+ }
+ }
+ }
+ }
final Map<String, Reference> references = getReferences(readGroupSet);
final Reference reference = references.get(sequenceName);
@@ -121,7 +117,7 @@ public ReadIteratorResource getReads(String readsetId,
if (sequenceName.isEmpty()) {
unmappedReads = getUnmappedMatesOfMappedReads(readsetId);
}
- Paginator.Reads searchReads = Paginator.Reads.create(stub, ShardBoundary.OVERLAPS);
+ Paginator.Reads searchReads = Paginator.Reads.create(stub, ShardBoundary.Requirement.OVERLAPS);
SearchReadsRequest readRequest = new SearchReadsRequest()
.setReadGroupSetIds(Arrays.asList(readsetId))
.setReferenceName(sequenceName)
@@ -153,15 +149,15 @@ public ReadIteratorResource getReads(String readsetId,
private Map<String, Reference> getReferences(ReadGroupSet readGroupSet)
throws IOException, GeneralSecurityException {
Set<String> referenceSetIds = Sets.newHashSet();
- if (readGroupSet.getReferenceSetId() != null) {
- LOG.info("Found reference set from read group set " +
+ if (!Strings.isNullOrEmpty(readGroupSet.getReferenceSetId())) {
+ LOG.info("Found reference set from read group set: " +
readGroupSet.getReferenceSetId());
referenceSetIds.add(readGroupSet.getReferenceSetId());
}
if (readGroupSet.getReadGroups() != null) {
LOG.info("Found read groups");
for (ReadGroup readGroup : readGroupSet.getReadGroups()) {
- if (readGroup.getReferenceSetId() != null) {
+ if (!Strings.isNullOrEmpty(readGroup.getReferenceSetId())) {
LOG.info("Found reference set from read group: " +
readGroup.getReferenceSetId());
referenceSetIds.add(readGroup.getReferenceSetId());
@@ -179,7 +175,7 @@ public ReadIteratorResource getReads(String readsetId,
for (String referenceId : referenceSet.getReferenceIds()) {
LOG.fine("Getting reference " + referenceId);
Reference reference = getApi().references().get(referenceId).execute();
- if (reference.getName() != null) {
+ if (!Strings.isNullOrEmpty(reference.getName())) {
references.put(reference.getName(), reference);
LOG.fine("Adding reference " + reference.getName());
}
@@ -196,7 +192,7 @@ protected UnmappedReads createUnmappedReads() {
@Override
protected Iterable<Read> getUnmappedReadsIterator(String readsetId) throws GeneralSecurityException, IOException {
final Paginator.Reads searchUnmappedReads =
- Paginator.Reads.create(getApi(), ShardBoundary.OVERLAPS);
+ Paginator.Reads.create(getApi(), ShardBoundary.Requirement.OVERLAPS);
final SearchReadsRequest unmappedReadRequest = new SearchReadsRequest()
.setReadGroupSetIds(Arrays.asList(readsetId))
.setReferenceName("*");
Oops, something went wrong.

0 comments on commit 33ad437

Please sign in to comment.