From 858742470679b7666e542fd20c2e13607b992e6e Mon Sep 17 00:00:00 2001 From: Jonathan Simon Date: Wed, 27 Apr 2016 16:58:36 -0700 Subject: [PATCH 1/5] Replaced queue.xml with queue.yaml --- .../pull/src/main/webapp/WEB-INF/queue.xml | 10 ---------- .../pull/src/main/webapp/WEB-INF/queue.yaml | 7 +++++++ taskqueue/pull/README.md | 14 ++++++-------- 3 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml create mode 100644 appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml diff --git a/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml b/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml deleted file mode 100644 index 6653b5ad7c7..00000000000 --- a/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - pull-queue - pull - - bar@foo.com - bar@foo.com - - - diff --git a/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml b/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml new file mode 100644 index 00000000000..e0c1aadd10b --- /dev/null +++ b/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml @@ -0,0 +1,7 @@ +queue: +- name: pull-queue + mode: pull + acl: + - user_email: bar@foo.com # can list, get, lease, delete, and update tasks + - writer_email: user@gmail.com # can insert tasks + - writer_email: bar@foo.com # can insert tasks, in addition to rights granted by being a user_email above diff --git a/taskqueue/pull/README.md b/taskqueue/pull/README.md index 8abbe8f34ed..9837eed8785 100644 --- a/taskqueue/pull/README.md +++ b/taskqueue/pull/README.md @@ -14,26 +14,24 @@ to create one first and then come back and run this sample. reuse an existing project by clicking on it. 1. Note: You will need to enable billing for the project to use Compute Engine. - 1. Click "Overview" in the left-side navigation menu and copy your Project ID - for use in step 3.3 below. 1. Authentication instructions to run the sample (on your local machine or on a Compute Engine VM): * Running the sample locally on your development machine: 1. Install [Google Cloud SDK](https://cloud.google.com/sdk/) 1. Run the following command to authorize the Cloud SDK and configure your project:
gcloud init
- 1. Add your authenticated email account as <user-email> and <writer-email> elements to the queue.xml file of the App Engine app that created the pull queue task you're trying to access. For more details, please see - [Defining Pull Queues](https://cloud.google.com/appengine/docs/java/config/queue#Defining_Pull_Queues) - on the Task Queue configuration page. + 1. Add your authenticated email account as 'user_email' and 'writer_email' elements to the queue.yaml + file of the App Engine app that created the pull queue task you're trying to access. For more details, please see + [Defining Pull Queues](https://cloud.google.com/appengine/docs/java/taskqueue/overview-pull#Java_Defining_pull_queues). * Running the sample on a Google Compute Engine VM using Default Application Credentials: 1. Create a service account and add it to queue.xml 1. In the API Manager > [Credentials](https://pantheon.corp.google.com/apis/credentials) section click "Create credentials" and choose "Service account key". 1. On the "Create service account key" page, select "Compute Engine default service account" from the "Service Account" drop-down menu. Leave the Key type set to JSON and click the "Create" button. 1. Once the service account is created, click the "Manage service accounts" link and copy the "Service account ID" of the "Compute Engine default service account". - 1. Add the "Service account ID" as <user-email> and <writer-email> elements to the queue.xml file of the App Engine app that created the pull queue task you're trying to access. For more details, please see - [Defining Pull Queues](https://cloud.google.com/appengine/docs/java/config/queue#Defining_Pull_Queues) - on the Task Queue configuration page. + 1. Add the "Service account ID" as 'user_email' and 'writer_email' elements to the queue.yaml file of the + App Engine app that created the pull queue task you're trying to access. For more details, please see + [Defining Pull Queues](https://cloud.google.com/appengine/docs/java/taskqueue/overview-pull#Java_Defining_pull_queues). 1. Create a Compute Engine VM Instance. 1. In the [Cloud Console](https://console.cloud.google.com/project) From c8f8a7a81a7972932200c2d1ed4feb7e740f4130 Mon Sep 17 00:00:00 2001 From: Jonathan Simon Date: Thu, 28 Apr 2016 10:28:45 -0700 Subject: [PATCH 2/5] Add block to handle null payload --- taskqueue/pull/src/main/java/TaskQueueSample.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/taskqueue/pull/src/main/java/TaskQueueSample.java b/taskqueue/pull/src/main/java/TaskQueueSample.java index a13f03f62b4..5268df52a67 100644 --- a/taskqueue/pull/src/main/java/TaskQueueSample.java +++ b/taskqueue/pull/src/main/java/TaskQueueSample.java @@ -172,8 +172,12 @@ private static Tasks getLeasedTasks(Taskqueue taskQueue) throws IOException { */ private static void processTask(Task task) { byte[] payload = Base64.decodeBase64(task.getPayloadBase64()); - System.out.println("Payload for the task:"); - System.out.println(new String(payload)); + if (payload != null) { + System.out.println("Payload for the task:"); + System.out.println(new String(payload)); + } else { + System.out.println("This task has no payload."); + } } /** * Method that sends a delete request for the specified task object to the taskqueue service. From 57f35e2afb19b0b03c74e11594caf784943c7184 Mon Sep 17 00:00:00 2001 From: Jonathan Simon Date: Fri, 29 Apr 2016 15:48:11 -0700 Subject: [PATCH 3/5] Add queue.xml in place of queue.yaml --- .../taskqueue/pull/src/main/webapp/WEB-INF/queue.xml | 11 +++++++++++ .../taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml | 7 ------- 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml delete mode 100644 appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml diff --git a/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml b/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml new file mode 100644 index 00000000000..2b384b4fd7c --- /dev/null +++ b/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml @@ -0,0 +1,11 @@ + + + pull-queue + pull + + bar@foo.com + user@gmail.com + bar@foo.com + + + diff --git a/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml b/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml deleted file mode 100644 index e0c1aadd10b..00000000000 --- a/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml +++ /dev/null @@ -1,7 +0,0 @@ -queue: -- name: pull-queue - mode: pull - acl: - - user_email: bar@foo.com # can list, get, lease, delete, and update tasks - - writer_email: user@gmail.com # can insert tasks - - writer_email: bar@foo.com # can insert tasks, in addition to rights granted by being a user_email above From b3fcef878fa725385d5614ca62f370d0f28e1465 Mon Sep 17 00:00:00 2001 From: Jonathan Simon Date: Fri, 29 Apr 2016 15:54:52 -0700 Subject: [PATCH 4/5] Updating README.md to reference queue.xml --- taskqueue/pull/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taskqueue/pull/README.md b/taskqueue/pull/README.md index 9837eed8785..ce77b24924e 100644 --- a/taskqueue/pull/README.md +++ b/taskqueue/pull/README.md @@ -20,7 +20,7 @@ reuse an existing project by clicking on it. 1. Install [Google Cloud SDK](https://cloud.google.com/sdk/) 1. Run the following command to authorize the Cloud SDK and configure your project:
gcloud init
- 1. Add your authenticated email account as 'user_email' and 'writer_email' elements to the queue.yaml + 1. Add your authenticated email account as '<user-email>' and '<writer-email>' elements to the queue.xml file of the App Engine app that created the pull queue task you're trying to access. For more details, please see [Defining Pull Queues](https://cloud.google.com/appengine/docs/java/taskqueue/overview-pull#Java_Defining_pull_queues). * Running the sample on a Google Compute Engine VM using Default Application Credentials: @@ -29,7 +29,7 @@ reuse an existing project by clicking on it. section click "Create credentials" and choose "Service account key". 1. On the "Create service account key" page, select "Compute Engine default service account" from the "Service Account" drop-down menu. Leave the Key type set to JSON and click the "Create" button. 1. Once the service account is created, click the "Manage service accounts" link and copy the "Service account ID" of the "Compute Engine default service account". - 1. Add the "Service account ID" as 'user_email' and 'writer_email' elements to the queue.yaml file of the + 1. Add the "Service account ID" as '<user-email>' and '<writer-email>' elements to the queue.xml file of the App Engine app that created the pull queue task you're trying to access. For more details, please see [Defining Pull Queues](https://cloud.google.com/appengine/docs/java/taskqueue/overview-pull#Java_Defining_pull_queues). From 2b38ff9dd8f694ea06daae0d6bbe375b181fba27 Mon Sep 17 00:00:00 2001 From: Jonathan Simon Date: Fri, 29 Apr 2016 17:13:14 -0700 Subject: [PATCH 5/5] Updating to use queue.xml instead of queue.yaml --- .../pull/src/main/webapp/WEB-INF/queue.xml | 11 +++ .../pull/src/main/webapp/WEB-INF/queue.yaml | 7 -- taskqueue/pull/README.md | 95 +++++++++++++++++++ 3 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml delete mode 100644 appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml create mode 100644 taskqueue/pull/README.md diff --git a/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml b/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml new file mode 100644 index 00000000000..2b384b4fd7c --- /dev/null +++ b/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.xml @@ -0,0 +1,11 @@ + + + pull-queue + pull + + bar@foo.com + user@gmail.com + bar@foo.com + + + diff --git a/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml b/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml deleted file mode 100644 index e0c1aadd10b..00000000000 --- a/appengine/taskqueue/pull/src/main/webapp/WEB-INF/queue.yaml +++ /dev/null @@ -1,7 +0,0 @@ -queue: -- name: pull-queue - mode: pull - acl: - - user_email: bar@foo.com # can list, get, lease, delete, and update tasks - - writer_email: user@gmail.com # can insert tasks - - writer_email: bar@foo.com # can insert tasks, in addition to rights granted by being a user_email above diff --git a/taskqueue/pull/README.md b/taskqueue/pull/README.md new file mode 100644 index 00000000000..ce77b24924e --- /dev/null +++ b/taskqueue/pull/README.md @@ -0,0 +1,95 @@ +# Pull Task Queue REST API sample +This sample command line application demonstrates how to access App Engine pull task queues using the Task +Queue REST API and the Google Java API Client Library. + +Important Note: This sample requires an existing App Engine Pull Task Queue. +Deploy this +[sample App Engine pull task queue app](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appengine/taskqueue/pull) +to create one first and then come back and run this sample. + +## Setup Instructions +1. Create or select a project in the Google Cloud Console: + 1. Visit the [Cloud Console][2] + 1. If this is your first time then click "Create Project," otherwise you can +reuse an existing project by clicking on it. + 1. Note: You will need to enable billing for the project to use Compute + Engine. + +1. Authentication instructions to run the sample (on your local machine or on a Compute Engine VM): + * Running the sample locally on your development machine: + 1. Install [Google Cloud SDK](https://cloud.google.com/sdk/) + 1. Run the following command to authorize the Cloud SDK and configure your project: +
gcloud init
+ 1. Add your authenticated email account as '<user-email>' and '<writer-email>' elements to the queue.xml + file of the App Engine app that created the pull queue task you're trying to access. For more details, please see + [Defining Pull Queues](https://cloud.google.com/appengine/docs/java/taskqueue/overview-pull#Java_Defining_pull_queues). + * Running the sample on a Google Compute Engine VM using Default Application Credentials: + 1. Create a service account and add it to queue.xml + 1. In the API Manager > [Credentials](https://pantheon.corp.google.com/apis/credentials) + section click "Create credentials" and choose "Service account key". + 1. On the "Create service account key" page, select "Compute Engine default service account" from the "Service Account" drop-down menu. Leave the Key type set to JSON and click the "Create" button. + 1. Once the service account is created, click the "Manage service accounts" link and copy the "Service account ID" of the "Compute Engine default service account". + 1. Add the "Service account ID" as '<user-email>' and '<writer-email>' elements to the queue.xml file of the + App Engine app that created the pull queue task you're trying to access. For more details, please see + [Defining Pull Queues](https://cloud.google.com/appengine/docs/java/taskqueue/overview-pull#Java_Defining_pull_queues). + + 1. Create a Compute Engine VM Instance. + 1. In the [Cloud Console](https://console.cloud.google.com/project) + go to the Compute > Compute Engine section. + 1. Click the "Create instance" button. + 1. For the 'Boot Disk' select a Linux machine image like Debian or Ubuntu. + 1. In the "Indentity API and Access" section, select "Set access for each API" under the "Access Scopes" subsection and then select the + "Task queue" drop-down menu to set its scope. + * Set the "Task queue" access scope to be "Enabled". + 1. Click the "Create" button. + 1. Once the VM is created click the VM instance's "SSH" button to ssh in to the newly created VM instance. + +1. Code checkout instructions: + 1. Prerequisites: install [Java 7 or Java 8 JDK][1], [Git][3], and [Maven][4]. +You may need to set your `JAVA_HOME` environment variable as well. + * To install these prerequisites on a Linux (Debian or Ubuntu) based Compute Engine VM + instance, run these commands: +
+    sudo apt-get update
+    sudo apt-get install git maven openjdk-7-jdk -y
+    
+ 1. Download the sample code by running the following commands: +
mkdir some_directory
+  cd some_directory
+  git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
+  cd java-docs-samples/taskqueue/cmdline
+  
+ In a text editor open the `TaskQueueSample.java` file. For example, to edit the file with nano: +
nano src/main/java/TaskQueueSample.java
+ + 1. Specify an 'Application Name' for your app by updating the following line of code: +
private static final String APPLICATION_NAME = "";
+ 1. Save the changes to the file and exit the text editor. + +1. Compile and run the sample: + 1. Compile the sample code using Maven by running the following command: +
mvn compile
+ 1. Execute the sample code using Maven by running the following command, + entering your specific values for the placeholder arguments: +
mvn -q exec:java -Dexec.args="<ProjectId> <TaskQueueName> <LeaseSeconds> <NumberOfTasksToLease>"
+ 1. Running the sample will first list the pull task queue details and then it will lease, process and delete the number of tasks you specified. + + You can verify the details of the pull task queue and the leased tasks by visiting the [App Engine > Task queues](https://pantheon.corp.google.com/appengine/taskqueues) + section of the Developers Console. +1. Importing the code into Eclipse and running it from there: + 1. Prerequisites: install [Eclipse][5] and the [Maven plugin for Eclipse][6]. + 1. Download code as specified above. + 1. File -> Import -> Maven -> Existing Maven Projects -> Next. + 1. Select your project directory as your "Root Directory," and click "Finish." + 1. Right-click on project task-queue-rest-sample. + 1. Run As > Java Application. + 1. If asked, type or select "TaskQueueSample" and click OK. + 1. Application output will display in the Eclipse Console. + +[1]: http://java.com/en/download/faq/develop.xml +[2]: https://console.cloud.google.com/project +[3]: http://git-scm.com/downloads +[4]: http://maven.apache.org/download.html +[5]: http://www.eclipse.org/downloads/ +[6]: http://download.eclipse.org/technology/m2e/releases/ +