Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to access app engine datastore via Objectify on a local server

I am trying to run an app engine spring project on localhost using eclipse. I am getting the following error in the console.

Apr 23, 2018 4:01:04 PM com.google.auth.oauth2.ComputeEngineCredentials runningOnComputeEngine
WARNING: Failed to detect whether we are running on Google Compute Engine.
java.net.SocketException: Network is unreachable: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:357)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:104)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)
    at com.google.auth.oauth2.ComputeEngineCredentials.runningOnComputeEngine(ComputeEngineCredentials.java:191)
    at com.google.auth.oauth2.DefaultCredentialsProvider.tryGetComputeCredentials(DefaultCredentialsProvider.java:270)
    at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentialsUnsynchronized(DefaultCredentialsProvider.java:194)
    at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:112)
    at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:127)
    at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:100)
    at com.google.cloud.ServiceOptions.defaultCredentials(ServiceOptions.java:298)
    at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:272)
    at com.google.cloud.datastore.DatastoreOptions.<init>(DatastoreOptions.java:102)
    at com.google.cloud.datastore.DatastoreOptions.<init>(DatastoreOptions.java:35)
    ... 

How do I provide credentials to use the datastore in localhost? I get the following on the console when i access the datastore.

2018-04-23 17:22:05.849:WARN:oejs.ServletHandler:qtp152005629-14: org.spring.framework.web.util.NestedServletException: Request processing failed; nested exception is com.google.cloud.datastore.DatastoreException: Unauthenticated.
Caused by: 
com.google.cloud.datastore.DatastoreException: Unauthenticated
like image 221
Arun Muthuraman Avatar asked Dec 05 '25 04:12

Arun Muthuraman


1 Answers

Objectify v6 uses the Datastore SDK for Google Cloud Platform (which you could think of as GCP's "general purpose" SDK). That SDK makes actual API calls to the cloud service, even when it's being run locally. If you want to run tests/develop against a local datastore, you need to do one of two things.

Option One

Instead of using the GCP Datastore SDK, use the App Engine SDK’s Datastore bindings. Objectify has committed in v6 to using the GCP SDK, but v5 used the App Engine SDK. You can downgrade to v5 and everything will "just work".

Option Two

If you want to keep using Objectify v6, you need to install an extra gcloud component to run a local datastore emulator and you'll need to set some environment variables. More details here, but the short version goes:

Install and start the datastore emulator:

$ gcloud components install cloud-datastore-emulator
$ gcloud beta emulators datastore start

Then tell your application where to find it:

$ (gcloud beta emulators datastore env-init)

Or you can set the relevant env vars manually. On the machine that runs your application, set the environment variables and values as directed by the output of the env-init command. For example:

gcloud beta emulators datastore env-init
export DATASTORE_EMULATOR_HOST=localhost:8432
export DATASTORE_PROJECT_ID=my-project-id
like image 138
Venantius Avatar answered Dec 09 '25 21:12

Venantius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!