Skip to content
Snippets Groups Projects
Commit db2e3dfb authored by haih-g's avatar haih-g Committed by Sean Busbey
Browse files

[googledatastore] Google Datastore to use default credentials. (#984)

* Google Datastore to use default credentials.

* Google Datastore to skip Index.
parent 0d17403b
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# LICENSE file. # LICENSE file.
# #
# Sample property file for Google Cloud Datastore DB client # Sample property file for Google Cloud Datastore DB client
## Mandatory parameters ## Mandatory parameters
# #
...@@ -39,12 +39,12 @@ readallfields = true ...@@ -39,12 +39,12 @@ readallfields = true
# #
# googledatastore.readConsistency=STRONG # googledatastore.readConsistency=STRONG
# Decides how we group entities into entity groups. # Decides how we group entities into entity groups.
# (See the details section in README.md for documentation) # (See the details section in README.md for documentation)
# #
# googledatastore.entityGroupingMode=ONE_ENTITY_PER_GROUP # googledatastore.entityGroupingMode=ONE_ENTITY_PER_GROUP
# If you set the googledatastore.entityGroupingMode property to # If you set the googledatastore.entityGroupingMode property to
# MULTI_ENTITY_PER_GROUP, you can optionally specify the name of the root entity # MULTI_ENTITY_PER_GROUP, you can optionally specify the name of the root entity
# #
# googledatastore.rootEntityName="YCSB_ROOT_ENTITY" # googledatastore.rootEntityName="YCSB_ROOT_ENTITY"
...@@ -53,4 +53,7 @@ readallfields = true ...@@ -53,4 +53,7 @@ readallfields = true
# requestdistribution = uniform # requestdistribution = uniform
# Enable/disable debug message, default is false. # Enable/disable debug message, default is false.
# googledatastore.debug = false # googledatastore.debug = false
\ No newline at end of file
# Skip indexes, default is true.
# googledatastore.skipIndex = true
\ No newline at end of file
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package com.yahoo.ycsb.db; package com.yahoo.ycsb.db;
import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.datastore.v1.*; import com.google.datastore.v1.*;
import com.google.datastore.v1.CommitRequest.Mode; import com.google.datastore.v1.CommitRequest.Mode;
import com.google.datastore.v1.ReadOptions.ReadConsistency; import com.google.datastore.v1.ReadOptions.ReadConsistency;
...@@ -82,6 +83,8 @@ public class GoogleDatastoreClient extends DB { ...@@ -82,6 +83,8 @@ public class GoogleDatastoreClient extends DB {
private Datastore datastore = null; private Datastore datastore = null;
private static boolean skipIndex = true;
/** /**
* Initialize any state for this DB. Called once per DB instance; there is * Initialize any state for this DB. Called once per DB instance; there is
* one DB instance per client thread. * one DB instance per client thread.
...@@ -93,6 +96,12 @@ public class GoogleDatastoreClient extends DB { ...@@ -93,6 +96,12 @@ public class GoogleDatastoreClient extends DB {
logger.setLevel(Level.DEBUG); logger.setLevel(Level.DEBUG);
} }
String skipIndexString = getProperties().getProperty(
"googledatastore.skipIndex", null);
if (null != skipIndexString && "false".equalsIgnoreCase(skipIndexString)) {
skipIndex = false;
}
// We need the following 3 essential properties to initialize datastore: // We need the following 3 essential properties to initialize datastore:
// //
// - DatasetId, // - DatasetId,
...@@ -107,17 +116,8 @@ public class GoogleDatastoreClient extends DB { ...@@ -107,17 +116,8 @@ public class GoogleDatastoreClient extends DB {
String privateKeyFile = getProperties().getProperty( String privateKeyFile = getProperties().getProperty(
"googledatastore.privateKeyFile", null); "googledatastore.privateKeyFile", null);
if (privateKeyFile == null) {
throw new DBException(
"Required property \"privateKeyFile\" missing.");
}
String serviceAccountEmail = getProperties().getProperty( String serviceAccountEmail = getProperties().getProperty(
"googledatastore.serviceAccountEmail", null); "googledatastore.serviceAccountEmail", null);
if (serviceAccountEmail == null) {
throw new DBException(
"Required property \"serviceAccountEmail\" missing.");
}
// Below are properties related to benchmarking. // Below are properties related to benchmarking.
...@@ -157,11 +157,18 @@ public class GoogleDatastoreClient extends DB { ...@@ -157,11 +157,18 @@ public class GoogleDatastoreClient extends DB {
// Setup the connection to Google Cloud Datastore with the credentials // Setup the connection to Google Cloud Datastore with the credentials
// obtained from the configure. // obtained from the configure.
DatastoreOptions.Builder options = new DatastoreOptions.Builder(); DatastoreOptions.Builder options = new DatastoreOptions.Builder();
Credential credential = DatastoreHelper.getServiceAccountCredential( Credential credential = GoogleCredential.getApplicationDefault();
serviceAccountEmail, privateKeyFile); if (serviceAccountEmail != null && privateKeyFile != null) {
logger.info("Using JWT Service Account credential."); credential = DatastoreHelper.getServiceAccountCredential(
logger.info("DatasetID: " + datasetId + ", Service Account Email: " + serviceAccountEmail, privateKeyFile);
serviceAccountEmail + ", Private Key File Path: " + privateKeyFile); logger.info("Using JWT Service Account credential.");
logger.info("DatasetID: " + datasetId + ", Service Account Email: " +
serviceAccountEmail + ", Private Key File Path: " + privateKeyFile);
} else {
logger.info("Using default gcloud credential.");
logger.info("DatasetID: " + datasetId
+ ", Service Account Email: " + ((GoogleCredential) credential).getServiceAccountId());
}
datastore = DatastoreFactory.get().create( datastore = DatastoreFactory.get().create(
options.credential(credential).projectId(datasetId).build()); options.credential(credential).projectId(datasetId).build());
...@@ -298,7 +305,8 @@ public class GoogleDatastoreClient extends DB { ...@@ -298,7 +305,8 @@ public class GoogleDatastoreClient extends DB {
entityBuilder.getMutableProperties() entityBuilder.getMutableProperties()
.put(val.getKey(), .put(val.getKey(),
Value.newBuilder() Value.newBuilder()
.setStringValue(val.getValue().toString()).build()); .setStringValue(val.getValue().toString())
.setExcludeFromIndexes(skipIndex).build());
} }
Entity entity = entityBuilder.build(); Entity entity = entityBuilder.build();
logger.debug("entity built as: " + entity.toString()); logger.debug("entity built as: " + entity.toString());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment