diff --git a/googledatastore/conf/googledatastore.properties b/googledatastore/conf/googledatastore.properties index ac95b570c4ec4f469d6d6ceda0c6c13b3bdd9d29..408acf0d0d025f1dc419fa404633ea60f88ea133 100644 --- a/googledatastore/conf/googledatastore.properties +++ b/googledatastore/conf/googledatastore.properties @@ -26,7 +26,7 @@ # Google Cloud Datastore's read and update APIs do not support # reading or updating a select subset of properties for an entity. -# (as of version v1beta2-rev1-3.0.2) +# (as of version v1beta3) # Therefore, it's recommended that you set writeallfields and readallfields # to true to get stable and comparable performance numbers. writeallfields = true diff --git a/googledatastore/pom.xml b/googledatastore/pom.xml index 57db3505c288e6d27c309dbd19a0bcf1ba1fbd2e..8ddd1d9c5a599813ddcfdf620d54c0648a8951af 100644 --- a/googledatastore/pom.xml +++ b/googledatastore/pom.xml @@ -29,11 +29,26 @@ LICENSE file. <name>Google Cloud Datastore Binding</name> <url>https://github.com/GoogleCloudPlatform/google-cloud-datastore</url> + <repositories> + <repository> + <id>sonatype-snapshots</id> + <name>sonatype-snapshots</name> + <url>https://oss.sonatype.org/content/repositories/snapshots/</url> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> <dependencies> <dependency> - <groupId>com.google.apis</groupId> - <artifactId>google-api-services-datastore-protobuf</artifactId> - <version>v1beta2-rev1-3.0.2</version> + <groupId>com.google.cloud.datastore</groupId> + <artifactId>datastore-v1beta3-proto-client</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>com.google.cloud.datastore</groupId> + <artifactId>datastore-v1beta3-protos</artifactId> + <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>log4j</groupId> @@ -47,4 +62,28 @@ LICENSE file. <scope>provided</scope> </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <version>2.15</version> + <configuration> + <consoleOutput>true</consoleOutput> + <configLocation>../checkstyle.xml</configLocation> + <failOnViolation>true</failOnViolation> + <failsOnError>false</failsOnError> + </configuration> + <executions> + <execution> + <id>validate</id> + <phase>validate</phase> + <goals> + <goal>checkstyle</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/googledatastore/src/main/java/com/yahoo/ycsb/db/GoogleDatastoreClient.java b/googledatastore/src/main/java/com/yahoo/ycsb/db/GoogleDatastoreClient.java index 12fc0fac96ab0b442d4e1710160ab0fadb2d8842..7077455d26a7a84a0f6c0410cab4bef6e6a52e84 100644 --- a/googledatastore/src/main/java/com/yahoo/ycsb/db/GoogleDatastoreClient.java +++ b/googledatastore/src/main/java/com/yahoo/ycsb/db/GoogleDatastoreClient.java @@ -18,15 +18,14 @@ package com.yahoo.ycsb.db; import com.google.api.client.auth.oauth2.Credential; -import com.google.api.services.datastore.DatastoreV1.*; -import com.google.api.services.datastore.DatastoreV1.CommitRequest.Mode; -import com.google.api.services.datastore.DatastoreV1.ReadOptions - .ReadConsistency; -import com.google.api.services.datastore.client.Datastore; -import com.google.api.services.datastore.client.DatastoreException; -import com.google.api.services.datastore.client.DatastoreFactory; -import com.google.api.services.datastore.client.DatastoreHelper; -import com.google.api.services.datastore.client.DatastoreOptions; +import com.google.datastore.v1beta3.*; +import com.google.datastore.v1beta3.CommitRequest.Mode; +import com.google.datastore.v1beta3.ReadOptions.ReadConsistency; +import com.google.datastore.v1beta3.client.Datastore; +import com.google.datastore.v1beta3.client.DatastoreException; +import com.google.datastore.v1beta3.client.DatastoreFactory; +import com.google.datastore.v1beta3.client.DatastoreHelper; +import com.google.datastore.v1beta3.client.DatastoreOptions; import com.yahoo.ycsb.ByteIterator; import com.yahoo.ycsb.DB; @@ -165,7 +164,7 @@ public class GoogleDatastoreClient extends DB { serviceAccountEmail + ", Private Key File Path: " + privateKeyFile); datastore = DatastoreFactory.get().create( - options.credential(credential).dataset(datasetId).build()); + options.credential(credential).projectId(datasetId).build()); } catch (GeneralSecurityException exception) { throw new DBException("Security error connecting to the datastore: " + @@ -184,7 +183,7 @@ public class GoogleDatastoreClient extends DB { public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) { LookupRequest.Builder lookupRequest = LookupRequest.newBuilder(); - lookupRequest.addKey(buildPrimaryKey(table, key)); + lookupRequest.addKeys(buildPrimaryKey(table, key)); lookupRequest.getReadOptionsBuilder().setReadConsistency( this.readConsistency); // Note above, datastore lookupRequest always reads the entire entity, it @@ -219,7 +218,7 @@ public class GoogleDatastoreClient extends DB { Entity entity = response.getFound(0).getEntity(); logger.debug("Read entity: " + entity.toString()); - Map<String, Value> properties = DatastoreHelper.getPropertyMap(entity); + Map<String, Value> properties = entity.getProperties(); Set<String> propertiesToReturn = (fields == null ? properties.keySet() : fields); @@ -243,7 +242,6 @@ public class GoogleDatastoreClient extends DB { @Override public Status update(String table, String key, HashMap<String, ByteIterator> values) { - return doSingleItemMutation(table, key, values, MutationType.UPDATE); } @@ -267,11 +265,11 @@ public class GoogleDatastoreClient extends DB { if (this.entityGroupingMode == EntityGroupingMode.MULTI_ENTITY_PER_GROUP) { // All entities are in side the same group when we are in this mode. - result.addPathElement(Key.PathElement.newBuilder().setKind(table). + result.addPath(Key.PathElement.newBuilder().setKind(table). setName(rootEntityName)); } - return result.addPathElement(Key.PathElement.newBuilder().setKind(table) + return result.addPath(Key.PathElement.newBuilder().setKind(table) .setName(key)); } @@ -287,27 +285,25 @@ public class GoogleDatastoreClient extends DB { // for multi-item mutation, or Read-modify-write operation. CommitRequest.Builder commitRequest = CommitRequest.newBuilder(); commitRequest.setMode(Mode.NON_TRANSACTIONAL); - if (mutationType == MutationType.DELETE) { - commitRequest.getMutationBuilder().addDelete(datastoreKey); - + commitRequest.addMutationsBuilder().setDelete(datastoreKey); } else { // If this is not for delete, build the entity. Entity.Builder entityBuilder = Entity.newBuilder(); entityBuilder.setKey(datastoreKey); for (Entry<String, ByteIterator> val : values.entrySet()) { - entityBuilder.addProperty(Property.newBuilder() - .setName(val.getKey()) - .setValue(Value.newBuilder() - .setStringValue(val.getValue().toString()))); + entityBuilder.getMutableProperties() + .put(val.getKey(), + Value.newBuilder() + .setStringValue(val.getValue().toString()).build()); } Entity entity = entityBuilder.build(); logger.debug("entity built as: " + entity.toString()); if (mutationType == MutationType.UPSERT) { - commitRequest.getMutationBuilder().addUpsert(entity); + commitRequest.addMutationsBuilder().setUpsert(entity); } else if (mutationType == MutationType.UPDATE){ - commitRequest.getMutationBuilder().addUpdate(entity); + commitRequest.addMutationsBuilder().setUpdate(entity); } else { throw new RuntimeException("Impossible MutationType, code bug."); }