public void init()

in googledatastore/src/main/java/site/ycsb/db/GoogleDatastoreClient.java [93:187]


  public void init() throws DBException {
    String debug = getProperties().getProperty("googledatastore.debug", null);
    if (null != debug && "true".equalsIgnoreCase(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:
    //
    // - DatasetId,
    // - Path to private key file,
    // - Service account email address.
    String datasetId = getProperties().getProperty(
        "googledatastore.datasetId", null);
    if (datasetId == null) {
      throw new DBException(
          "Required property \"datasetId\" missing.");
    }

    String privateKeyFile = getProperties().getProperty(
        "googledatastore.privateKeyFile", null);
    String serviceAccountEmail = getProperties().getProperty(
        "googledatastore.serviceAccountEmail", null);

    // Below are properties related to benchmarking.

    String readConsistencyConfig = getProperties().getProperty(
        "googledatastore.readConsistency", null);
    if (readConsistencyConfig != null) {
      try {
        this.readConsistency = ReadConsistency.valueOf(
            readConsistencyConfig.trim().toUpperCase());
      } catch (IllegalArgumentException e) {
        throw new DBException("Invalid read consistency specified: " +
            readConsistencyConfig + ". Expecting STRONG or EVENTUAL.");
      }
    }

    //
    // Entity Grouping Mode (googledatastore.entitygroupingmode), see
    // documentation in conf/googledatastore.properties.
    //
    String entityGroupingConfig = getProperties().getProperty(
        "googledatastore.entityGroupingMode", null);
    if (entityGroupingConfig != null) {
      try {
        this.entityGroupingMode = EntityGroupingMode.valueOf(
            entityGroupingConfig.trim().toUpperCase());
      } catch (IllegalArgumentException e) {
        throw new DBException("Invalid entity grouping mode specified: " +
            entityGroupingConfig + ". Expecting ONE_ENTITY_PER_GROUP or " +
            "MULTI_ENTITY_PER_GROUP.");
      }
    }

    this.rootEntityName = getProperties().getProperty(
        "googledatastore.rootEntityName", "YCSB_ROOT_ENTITY");

    try {
      // Setup the connection to Google Cloud Datastore with the credentials
      // obtained from the configure.
      DatastoreOptions.Builder options = new DatastoreOptions.Builder();
      Credential credential = GoogleCredential.getApplicationDefault();
      if (serviceAccountEmail != null && privateKeyFile != null) {
        credential = DatastoreHelper.getServiceAccountCredential(
            serviceAccountEmail, 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(
          options.credential(credential).projectId(datasetId).build());

    } catch (GeneralSecurityException exception) {
      throw new DBException("Security error connecting to the datastore: " +
          exception.getMessage(), exception);

    } catch (IOException exception) {
      throw new DBException("I/O error connecting to the datastore: " +
          exception.getMessage(), exception);
    }

    logger.info("Datastore client instance created: " +
        datastore.toString());
  }