[JAVA] I tried using Remote API on GAE / J

I wanted to import production environment data locally with GAE / J, so I tried using the Remote API. This section describes how to retrieve data by remote access from GAE in the local environment to production and save the retrieved data in the local Datastore.

Premise

It is implemented in the following versions.

Preparation

Enable Remote API

Add the following to the project web.xml.

web.xml


<servlet>
  <display-name>Remote API Servlet</display-name>
  <servlet-name>RemoteApiServlet</servlet-name>
  <servlet-class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>RemoteApiServlet</servlet-name>
  <url-pattern>/remote_api</url-pattern>
</servlet-mapping>

Add appengine-remote-api.jar

Add $ {JAVA-SDK-ROOT} /lib/appengine-remote-api.jar to the WEB-INF / lib directory and put it in your classpath to take advantage of the Remote API client components.

Implementation

Import the data of Kind name "book" locally.

import com.google.appengine.tools.remoteapi.RemoteApiInstaller;
import com.google.appengine.tools.remoteapi.RemoteApiOptions;

// ...
		RemoteApiOptions options = new RemoteApiOptions()
			.server("your_app_id.appspot.com", 443)				
			.useApplicationDefaultCredential();
		RemoteApiInstaller installer = new RemoteApiInstaller();
		DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
		List<Entity> books;
		try {
			installer.install(options);
			Query q = new Query("book");
			books = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
		} finally {
			installer.uninstall();
		}
		
		//Migrate data for local storage
		List<Entity> devBooks = new ArrayList<>();
		for (Entity book : books) {
			Entity devBook = new Entity(book.getKind(), book.getKey().getName());
			devBook.setPropertiesFrom(book);
			devBooks.add(devBook);
		}
		datastore.put(devBooks);

It didn't work if I just used datastore.put () to get the data from production, but I was able to get it locally using the above method.

Recommended Posts

I tried using Remote API on GAE / J
I tried LINE Message API (line-bot-sdk-python) on GAE
I tried APN (remote notification) using Parse.com REST API
I tried using the checkio API
I tried using Twitter api and Line api
I tried using YOUTUBE Data API V3
I tried using UnityCloudBuild API from Python
I tried using the BigQuery Storage API
I tried using the COTOHA API (there is code on GitHub)
I tried using parameterized
I tried using AWS Rekognition's Detect Labels API
I tried using mimesis
I tried using anytree
I tried using aiomysql
I tried using Summpy
I tried using coturn
I tried using Pipenv
I tried using the Google Cloud Vision API
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
[Pythonocc] I tried using CAD on jupyter notebook
I tried using Ipython
I tried using PyCaret
I tried using cron
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using PyCaret
I tried using Heapq
I tried using doctest
I tried using folium
I tried using jinja2
I tried using folium
I tried using time-window
I tried using the API of the salmon data project
I tried using PySpark from Jupyter 4.x on EMR
[I tried using Pythonista 3] Introduction
I tried using easydict (memo).
I tried face recognition using Face ++
I tried using Random Forest
I tried using BigQuery ML
I tried using Amazon Glacier
I tried using git inspector
[Python] I tried using OpenPose
I tried using magenta / TensorFlow
I tried MLflow on Databricks
I tried using AWS Chalice
I tried using Slack emojinator
I tried tensorflow's new Object Detection API on macOS Sierra
I tried to search videos using Youtube Data API (beginner)
[Images available] I tried using neofetch on various operating systems!
I tried using Microsoft's Cognitive Services facial expression recognition API
I tried using "Syncthing" to synchronize files on multiple PCs
[Python] I tried collecting data using the API of wikipedia
[For beginners] I tried using the Tensorflow Object Detection API
I tried AdaNet on table data
I tried using Rotrics Dex Arm # 2
I tried to create Quip API