0

I have a very simple hello world application on Google Cloud with objectify.

I am using the latest Google Cloud Tools (1.6.1) for eclipse (Oxygen 4.7.3a), Java 8, and running the datastore emulator (as described in Elliotte's answer)

I was able to save some entities and I can tell they are persisted because I can retrieve them after restart the emulator and I know they are stored under: "C:\Users\XXXX\AppData\Roaming\gcloud\emulators\datastore\WEB-INF\appengine-generated"

BUT I couldn't find these entities in the datastore view under any namespace. Any idea what am I missing here?

The empty datastore view: enter image description here

The code:


  public void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws IOException {

      Car porsche = new Car("2FAST", 4);
      ofy().save().entity(porsche).now();    // async without the now()

      assert porsche.id != null;    // id was autogenerated

      Car fetched2 = ofy().load().type(Car.class).id(porsche.id).now();

      Query cars = ofy().load().type(Car.class).chunkAll();

    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");

    response.getWriter().print("Hello App Engine!\r\n");

    response.getWriter().print(fetched2.id + " " + fetched2.license);


    response.getWriter().print("\ncars.count():" + cars.count() + "\n");
    List carsList = cars.list();
    for(Car c :carsList) {
        response.getWriter().println(c.id + " " + c.license);
    }


    String namespace = NamespaceManager.get();
    response.getWriter().println();
    response.getWriter().println("namespace: ");

  }

Running the emulator: enter image description here

The run configuration:

enter image description here

Yoram
  • 572
  • 6
  • 21

1 Answers1

1

The local admin datastore page is provided by the local development server and it seems it will only show valid information when the development server itself performs the datastore emulation, in standalone mode. That is without connecting to a datastore emulator, which happens if you don't set the environment required to connect to the emulator. This used to be the only mode of operation before the datastore emulator came to life.

I didn't find a way to access the equivalent/similar information when using the datastore emulator, no such capability is mentioned in Running the Cloud Datastore Emulator. Only the datastore emulator can reliably provide such info, since it can serve multiple development servers/apps (oblivious about each-other's existence) at the same time.

If you don't have a need to run multiple development servers sharing the same datastore (the reverse of Is it possible to start two dev_appserver.py connecting to the same google cloud datastore emulator?) then you could simply not set the DATASTORE_EMULATOR_HOST environment variable before starting the development server and not pass the --support_datastore_emulator=true to it - then the development server will use its own datastore emulation and you should see the information in its admin page.

Note that datastore emulator may have used a different internal format for the data than the development server which may cause problems if you go back, you may need to clean out the C:\Users\XXXX\AppData\Roaming\gcloud\emulators\datastore storage dir, restore the previous format or use an alternate dir. From Migrating to the Cloud Datastore Emulator:

Currently, the local Datastore emulator stores data in sqlite3 while the Cloud Datastore Emulator stores data as Java objects.

When dev_appserver is launched with legacy sqlite3 data, the data will be converted to Java objects. The original data is backed up with the filename {original-data-filename}.sqlitestub.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • I am confused. I am running the datastore emulator manually to make things works but will love to use the development server datastore emulation (just like it used to be with old good plugin to eclipse). Is there a way to do it and to benefit from the datastore viewer? – Yoram Jun 14 '18 at 20:48
  • Sorry If I am not understanding correctly, you want to use the datastore emulator with the dev_app server emulator? Maybe you just need to run both processes in your local machine? – Ggrimaldo Jun 26 '18 at 12:34
  • I don't really care for the emulator. I just want to be able to test my app locally just like it used to be with old good plugin to eclipse. Taking your advice and remove the DATASTORE_EMULATOR_HOST setting did help and now I can see the data in the local dev datastore console. But only for the low level API. I still can't see it for Objectify. Well, I guess this is an issue for another question... – Yoram Jun 28 '18 at 22:22
  • The embedded Datastore emulator in the development server and the gcloud emulator are two different emulators that are independent of each other. Seems like you are using Objectify 6. Objectify 6 requires you to use the gcloud Datastore emulator. If you still want to use the emulator embedded in the dev server, I think your choice is to downgrade to Objectify 5. It doesn't matter if you use the Google Plugin for Eclipse (the deprecated plugin) or the Cloud Tools for Eclipse when using Objectify 5. You may also want to check https://github.com/objectify/objectify/wiki/UpgradeVersion5ToVersion6 – Chanseok Oh Jul 02 '18 at 14:05