0
votes

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

1

1 Answers

1
votes

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.