From 99d391244b2129f4c1ac27d9288f0974b53bab16 Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Fri, 31 Aug 2018 16:11:44 -0700 Subject: [PATCH 1/5] update sample --- appengine-java8/tasks/README.md | 2 +- .../java/com/example/task/CreateTask.java | 28 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/appengine-java8/tasks/README.md b/appengine-java8/tasks/README.md index adc934dc74b..a582cecfa98 100644 --- a/appengine-java8/tasks/README.md +++ b/appengine-java8/tasks/README.md @@ -48,7 +48,7 @@ mvn appengine:run mvn appengine:deploy ``` -## Running the Sample +## Run the Sample Using the Command Line Set environment variables: diff --git a/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java b/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java index 3a0f340d07e..62712a9dd55 100644 --- a/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java +++ b/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java @@ -16,11 +16,11 @@ package com.example.task; -import com.google.cloud.tasks.v2beta2.AppEngineHttpRequest; -import com.google.cloud.tasks.v2beta2.CloudTasksClient; -import com.google.cloud.tasks.v2beta2.HttpMethod; -import com.google.cloud.tasks.v2beta2.QueueName; -import com.google.cloud.tasks.v2beta2.Task; +import com.google.cloud.tasks.v2beta3.AppEngineHttpRequest; +import com.google.cloud.tasks.v2beta3.CloudTasksClient; +import com.google.cloud.tasks.v2beta3.HttpMethod; +import com.google.cloud.tasks.v2beta3.QueueName; +import com.google.cloud.tasks.v2beta3.Task; import com.google.common.base.Strings; import com.google.protobuf.ByteString; import com.google.protobuf.Timestamp; @@ -121,7 +121,18 @@ public static void main(String... args) throws Exception { String payload = params.getOptionValue(PAYLOAD_OPTION.getOpt(), "default payload"); // [START cloud_tasks_appengine_create_task] + // Instantiates a client. try (CloudTasksClient client = CloudTasksClient.create()) { + + // TODO(developer): Uncomment these lines and replace with your values. + // String project = "my-project-id"; + // String queue = "my-appengine-queue"; + // String location = "us-central1"; + // String payload = "hello"; + + // Construct the fully qualified queue name. + String queueName = QueueName.of(projectId, location, queueName).toString(); + // Construct the task body. Task.Builder taskBuilder = Task .newBuilder() .setAppEngineHttpRequest(AppEngineHttpRequest.newBuilder() @@ -129,14 +140,17 @@ public static void main(String... args) throws Exception { .setRelativeUrl("/tasks/create") .setHttpMethod(HttpMethod.POST) .build()); + if (params.hasOption(IN_SECONDS_OPTION.getOpt())) { + // Add the scheduled time to the request. int seconds = Integer.parseInt(params.getOptionValue(IN_SECONDS_OPTION.getOpt())); taskBuilder.setScheduleTime(Timestamp .newBuilder() .setSeconds(Instant.now(Clock.systemUTC()).plusSeconds(seconds).getEpochSecond())); } - Task task = client.createTask( - QueueName.of(projectId, location, queueName).toString(), taskBuilder.build()); + + // Send create task request. + Task task = client.createTask(queueName, taskBuilder.build()); System.out.println("Task created: " + task.getName()); } // [END cloud_tasks_appengine_create_task] From 73abaeecf2304f7a6745926e120b112ca1cf369f Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Mon, 10 Sep 2018 14:45:55 -0700 Subject: [PATCH 2/5] remove pull queues --- tasks/README.md | 66 ------- tasks/pom.xml | 91 --------- .../src/main/java/com/example/Quickstart.java | 175 ------------------ .../test/java/com/example/QuickstartIT.java | 82 -------- 4 files changed, 414 deletions(-) delete mode 100644 tasks/README.md delete mode 100644 tasks/pom.xml delete mode 100644 tasks/src/main/java/com/example/Quickstart.java delete mode 100644 tasks/src/test/java/com/example/QuickstartIT.java diff --git a/tasks/README.md b/tasks/README.md deleted file mode 100644 index 975fa73d16a..00000000000 --- a/tasks/README.md +++ /dev/null @@ -1,66 +0,0 @@ -# Google Cloud Tasks Pull Queue Samples - - -Open in Cloud Shell - -Sample command-line program for interacting with the Google Cloud Tasks -API using pull queues. - -Pull queues let you add tasks to a queue, then programatically remove -and interact with them. Tasks can be added or processed in any -environment, such as on Google App Engine or Google Compute Engine. - -`Quickstart.java` is a simple command-line program to demonstrate listing -queues, creating tasks, and pulling and acknowledging tasks. - -## Initial Setup - - * Set up a Google Cloud Project and enable billing. - * Enable the - [Cloud Tasks API](https://console.cloud.google.com/launcher/details/google/cloudtasks.googleapis.com). - * Download and install the [Cloud SDK](https://cloud.google.com/sdk). - * Download and install [Maven](http://maven.apache.org/install.html). - - -## Creating a queue - -To create a queue using the Cloud SDK, use the following gcloud command: - -``` -gcloud beta tasks queues create-pull-queue my-pull-queue -``` - -In this example, the queue will be named `my-pull-queue`. - -## Running the Samples - -From the project folder, build your project with: - -``` -mvn clean install -``` - -Optionally, you can set up your settings as environment variables: - -``` -export GOOGLE_CLOUD_PROJECT= -export LOCATION_ID= -export QUEUE_ID=my-pull-queue -``` - -Next, create a task for a queue: - -``` -mvn exec:java -Dexec.mainClass="com.example.Quickstart" \ - -Dexec.args="create-task \ - --project $GOOGLE_CLOUD_PROJECT --queue $QUEUE_ID --location $LOCATION_ID" -``` - -Finally, pull and acknowledge a task: - -``` -mvn exec:java -Dexec.mainClass="com.example.task.Quickstart" \ - -Dexec.args="lease-and-ack-task \ - --project $GOOGLE_CLOUD_PROJECT --queue $QUEUE_ID --location $LOCATION_ID" -``` -Note that usually, there would be a processing step in between pulling a task and acknowledging it. diff --git a/tasks/pom.xml b/tasks/pom.xml deleted file mode 100644 index 32ae73617ad..00000000000 --- a/tasks/pom.xml +++ /dev/null @@ -1,91 +0,0 @@ - - - 4.0.0 - com.example - tasks-samples - jar - 1.0 - - - - com.google.cloud.samples - shared-configuration - 1.0.10 - - - - - UTF-8 - 1.8 - 1.8 - - - - - com.google.cloud - google-cloud-tasks - 0.54.0-beta - - - - - junit - junit - 4.12 - test - - - com.google.truth - truth - 0.41 - test - - - com.google.api-client - google-api-client - 1.23.0 - compile - - - commons-cli - commons-cli - 1.4 - compile - - - - - src/main/java - - - org.codehaus.mojo - exec-maven-plugin - 1.6.0 - - com.example.Quickstart - false - - - - - - diff --git a/tasks/src/main/java/com/example/Quickstart.java b/tasks/src/main/java/com/example/Quickstart.java deleted file mode 100644 index 77040ef8285..00000000000 --- a/tasks/src/main/java/com/example/Quickstart.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example; - -// [START tasks_quickstart] - -import com.google.cloud.tasks.v2beta2.AcknowledgeTaskRequest; -import com.google.cloud.tasks.v2beta2.CloudTasksClient; -import com.google.cloud.tasks.v2beta2.CreateTaskRequest; -import com.google.cloud.tasks.v2beta2.LeaseTasksRequest; -import com.google.cloud.tasks.v2beta2.LeaseTasksResponse; -import com.google.cloud.tasks.v2beta2.PullMessage; -import com.google.cloud.tasks.v2beta2.QueueName; -import com.google.cloud.tasks.v2beta2.Task; -import com.google.common.base.Strings; -import com.google.protobuf.ByteString; -import com.google.protobuf.Duration; - -import java.io.IOException; -import java.nio.charset.Charset; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; - -public class Quickstart { - private static String GGOGLE_CLOUD_PROJECT_KEY = "GOOGLE_CLOUD_PROJECT"; - - private static Option PROJECT_ID_OPTION = Option.builder("project") - .longOpt("project-id") - .desc("The Google Cloud Project, if not set as GOOGLE_CLOUD_PROJECT env var.") - .hasArg() - .argName("project-id") - .type(String.class) - .build(); - - private static Option QUEUE_OPTION = Option.builder("queue") - .required() - .longOpt("queue") - .desc("The Cloud Tasks queue.") - .hasArg() - .argName("queue") - .type(String.class) - .build(); - - private static Option LOCATION_OPTION = Option.builder("location") - .required() - .longOpt("location") - .desc("The region in which your queue is running.") - .hasArg() - .argName("location") - .type(String.class) - .build(); - - public static void main(String... args) throws Exception { - Options options = new Options(); - options.addOption(PROJECT_ID_OPTION); - options.addOption(QUEUE_OPTION); - options.addOption(LOCATION_OPTION); - - if (args.length == 0) { - printUsage(options); - return; - } - - CommandLineParser parser = new DefaultParser(); - CommandLine params; - try { - params = parser.parse(options, args); - } catch (ParseException e) { - System.err.println("Invalid command line: " + e.getMessage()); - printUsage(options); - return; - } - - String projectId; - if (params.hasOption("project-id")) { - projectId = params.getOptionValue("project-id"); - } else { - projectId = System.getenv(GGOGLE_CLOUD_PROJECT_KEY); - } - if (Strings.isNullOrEmpty(projectId)) { - printUsage(options); - return; - } - - String queue = params.getOptionValue(QUEUE_OPTION.getOpt()); - String location = params.getOptionValue(LOCATION_OPTION.getOpt()); - - switch (args[0]) { - default: - printUsage(options); - break; - case "create-task": - createTask(projectId, queue, location); - break; - case "lease-and-ack-task": - pullAndAckTask(projectId, queue, location); - break; - } - } - - // [START cloud_tasks_create_task] - private static void createTask(String projectId, String queueName, String location) - throws IOException { - try (CloudTasksClient client = CloudTasksClient.create()) { - Task.Builder taskBuilder = Task - .newBuilder() - .setPullMessage(PullMessage.newBuilder().setPayload( - ByteString.copyFrom("a message for recipient", Charset.defaultCharset()))); - - Task newTask = client.createTask(CreateTaskRequest - .newBuilder() - .setParent(QueueName.of(projectId, location, queueName).toString()) - .setTask(taskBuilder) - .build()); - System.out.println("Task created: " + newTask.getName()); - } - } - // [END cloud_tasks_create_task] - - // [START cloud_tasks_lease_and_acknowledge_task] - private static void pullAndAckTask(String projectId, String queueName, String location) { - try (CloudTasksClient client = CloudTasksClient.create()) { - LeaseTasksRequest leaseReq = LeaseTasksRequest.newBuilder() - .setParent(QueueName.of(projectId, location, queueName).toString()) - .setLeaseDuration(Duration.newBuilder().setSeconds(600)) - .setMaxTasks(1) - .setResponseView(Task.View.FULL) - .build(); - LeaseTasksResponse response = client.leaseTasks(leaseReq); - if (response.getTasksCount() == 0) { - System.out.println("No tasks found in queue."); - return; - } - Task task = response.getTasksList().get(0); - System.out.println("Leased task: " + task.getName()); - AcknowledgeTaskRequest ackRequest = AcknowledgeTaskRequest - .newBuilder() - .setName(task.getName()) - .setScheduleTime(task.getScheduleTime()) - .build(); - client.acknowledgeTask(ackRequest); - System.out.println("Acknowledged task: " + task.getName()); - } catch (Exception e) { - System.out.println("Exception during PullAndAckTask: " + e.getMessage()); - } - } - // [END cloud_tasks_lease_and_acknowledge_task] - - private static void printUsage(Options options) { - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("client", - "A simple Cloud Tasks command line client.", options, "", true); - } -} -// [END tasks_quickstart] diff --git a/tasks/src/test/java/com/example/QuickstartIT.java b/tasks/src/test/java/com/example/QuickstartIT.java deleted file mode 100644 index d0e21e076b0..00000000000 --- a/tasks/src/test/java/com/example/QuickstartIT.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertTrue; - -import com.google.cloud.tasks.v2beta2.CloudTasksClient; -import com.google.cloud.tasks.v2beta2.QueueName; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; - -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Integration (system) tests for {@link Quickstart}. - */ -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class QuickstartIT { - private static String queue_name = "my-pull-queue"; - private static String location = "us-east1"; - private ByteArrayOutputStream bout; - private PrintStream out; - - @BeforeClass - public static void setUpClass() throws Exception { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - PrintStream out = new PrintStream(bout); - System.setOut(out); - } - - // Purge the task queue when tests done. - @AfterClass - public static void tearDownClass() throws IOException { - try (CloudTasksClient client = CloudTasksClient.create()) { - client.purgeQueue(QueueName.of(System.getenv("GOOGLE_CLOUD_PROJECT"), location, queue_name)); - } - } - - @Before - public void setUp() throws Exception { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - } - - @Test - public void createTaskTest() throws Exception { - Quickstart.main("create-task", "--queue", queue_name, "--location", location); - assertThat(bout.toString()).contains("Task created: "); - } - - @Test - public void leaseAndAcknowledge() throws Exception { - Quickstart.main("lease-and-ack-task", "--queue", queue_name, "--location", location); - assertThat(bout.toString()).contains("Leased task: "); - assertThat(bout.toString()).contains("Acknowledged task: "); - } -} From 3b226e7e87a647ea6ab6f15bafce9326539ef7d7 Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Tue, 11 Sep 2018 17:24:15 -0700 Subject: [PATCH 3/5] updates for beta --- appengine-java8/tasks/README.md | 20 +++++-------------- appengine-java8/tasks/pom.xml | 5 +++-- .../java/com/example/task/CreateTask.java | 14 ++++++------- .../java/com/example/task/TaskServlet.java | 11 ++++++---- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/appengine-java8/tasks/README.md b/appengine-java8/tasks/README.md index a582cecfa98..5cab181bc17 100644 --- a/appengine-java8/tasks/README.md +++ b/appengine-java8/tasks/README.md @@ -21,6 +21,7 @@ App Engine task attempts. [Cloud Tasks API](https://console.cloud.google.com/launcher/details/google/cloudtasks.googleapis.com). * Download and install the [Cloud SDK](https://cloud.google.com/sdk). * Download and install [Maven](http://maven.apache.org/install.html). + * Set up [Google Application Credentials](https://cloud.google.com/docs/authentication/getting-started). ## Creating a queue @@ -37,13 +38,6 @@ version unless configured to do otherwise. [Using Maven and the App Engine Plugin](https://cloud.google.com/appengine/docs/flexible/java/using-maven) & [Maven Plugin Goals and Parameters](https://cloud.google.com/appengine/docs/flexible/java/maven-reference) -### Running locally - -``` -mvn appengine:run -``` -### Deploying - ``` mvn appengine:deploy ``` @@ -55,7 +49,7 @@ Set environment variables: First, your project ID: ``` -export GOOGLE_CLOUD_PROJECT= +export PROJECT_ID= ``` Then the queue ID, as specified at queue creation time. Queue IDs already @@ -79,23 +73,19 @@ Create a task, targeted at the `/tasks/create` endpoint, with a payload specifie ``` mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \ - -Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \ + -Dexec.args="--project-id $PROJECT_ID \ --queue $QUEUE_ID --location $LOCATION_ID --payload hello" ``` The App Engine app serves as a target for the push requests. It has an endpoint `/tasks/create` that reads the payload (i.e., the request body) of the -HTTP POST request and logs it. The log output can be viewed with: - -``` -gcloud app logs read -``` +HTTP POST request and logs it. The log output can be viewed with [Stackdriver Logging](https://console.cloud.google.com/logs/viewer?minLogLevel=0). Create a task that will be scheduled for a time in the future using the `--in-seconds` flag: ``` mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \ - -Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \ + -Dexec.args="--project-id $PROJECT_ID \ --queue $QUEUE_ID --location $LOCATION_ID --payload hello --in-seconds 30" ``` diff --git a/appengine-java8/tasks/pom.xml b/appengine-java8/tasks/pom.xml index 51d5211a9b7..d7d2a980b61 100644 --- a/appengine-java8/tasks/pom.xml +++ b/appengine-java8/tasks/pom.xml @@ -37,6 +37,7 @@ Copyright 2018 Google LLC 1.8 1.8 + false @@ -51,7 +52,7 @@ Copyright 2018 Google LLC com.google.cloud google-cloud-tasks - 0.54.0-beta + 0.61.0-beta commons-cli @@ -69,7 +70,7 @@ Copyright 2018 Google LLC com.google.cloud.tools appengine-maven-plugin - 1.3.1 + 1.3.2 true true diff --git a/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java b/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java index 62712a9dd55..5299681b651 100644 --- a/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java +++ b/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java @@ -38,11 +38,11 @@ import org.apache.commons.cli.ParseException; public class CreateTask { - private static String GGOGLE_CLOUD_PROJECT_KEY = "GOOGLE_CLOUD_PROJECT"; + private static String GOOGLE_CLOUD_PROJECT_KEY = "PROJECT_ID"; private static Option PROJECT_ID_OPTION = Option.builder("pid") .longOpt("project-id") - .desc("The Google Cloud Project, if not set as GOOGLE_CLOUD_PROJECT env var.") + .desc("The Google Cloud Project, if not set as PROJECT_ID env var.") .hasArg() .argName("project-id") .type(String.class) @@ -109,7 +109,7 @@ public static void main(String... args) throws Exception { if (params.hasOption("project-id")) { projectId = params.getOptionValue("project-id"); } else { - projectId = System.getenv(GGOGLE_CLOUD_PROJECT_KEY); + projectId = System.getenv(GOOGLE_CLOUD_PROJECT_KEY); } if (Strings.isNullOrEmpty(projectId)) { printUsage(options); @@ -131,13 +131,13 @@ public static void main(String... args) throws Exception { // String payload = "hello"; // Construct the fully qualified queue name. - String queueName = QueueName.of(projectId, location, queueName).toString(); + String queuePath = QueueName.of(projectId, location, queueName).toString(); // Construct the task body. Task.Builder taskBuilder = Task .newBuilder() .setAppEngineHttpRequest(AppEngineHttpRequest.newBuilder() - .setPayload(ByteString.copyFrom(payload, Charset.defaultCharset())) - .setRelativeUrl("/tasks/create") + .setBody(ByteString.copyFrom(payload, Charset.defaultCharset())) + .setRelativeUri("/tasks/create") .setHttpMethod(HttpMethod.POST) .build()); @@ -150,7 +150,7 @@ public static void main(String... args) throws Exception { } // Send create task request. - Task task = client.createTask(queueName, taskBuilder.build()); + Task task = client.createTask(queuePath, taskBuilder.build()); System.out.println("Task created: " + task.getName()); } // [END cloud_tasks_appengine_create_task] diff --git a/appengine-java8/tasks/src/main/java/com/example/task/TaskServlet.java b/appengine-java8/tasks/src/main/java/com/example/task/TaskServlet.java index a95de4f85c5..141f9264047 100644 --- a/appengine-java8/tasks/src/main/java/com/example/task/TaskServlet.java +++ b/appengine-java8/tasks/src/main/java/com/example/task/TaskServlet.java @@ -35,10 +35,13 @@ public class TaskServlet extends HttpServlet { @Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { log.info("Received task request: " + req.getServletPath()); - if (req.getParameter("payload") != null) { - String payload = req.getParameter("payload"); - log.info("Request payload: " + payload); - String output = String.format("Received task with payload %s", payload); + String body = req.getReader() + .lines() + .reduce("", (accumulator, actual) -> accumulator + actual); + + if (!body.isEmpty()) { + log.info("Request payload: " + body); + String output = String.format("Received task with payload %s", body); resp.getOutputStream().write(output.getBytes()); log.info("Sending response: " + output); resp.setStatus(HttpServletResponse.SC_OK); From d45b01d5acdb5bc2f7b8f421fe148f116b4c9825 Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Wed, 12 Sep 2018 12:43:02 -0700 Subject: [PATCH 4/5] Change comment --- .../src/main/java/com/example/task/CreateTask.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java b/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java index 5299681b651..c787404fc10 100644 --- a/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java +++ b/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java @@ -124,14 +124,15 @@ public static void main(String... args) throws Exception { // Instantiates a client. try (CloudTasksClient client = CloudTasksClient.create()) { - // TODO(developer): Uncomment these lines and replace with your values. - // String project = "my-project-id"; - // String queue = "my-appengine-queue"; - // String location = "us-central1"; - // String payload = "hello"; + // Variables provided by the CLI. + // projectId = "my-project-id"; + // queueName = "my-appengine-queue"; + // location = "us-central1"; + // payload = "hello"; // Construct the fully qualified queue name. String queuePath = QueueName.of(projectId, location, queueName).toString(); + // Construct the task body. Task.Builder taskBuilder = Task .newBuilder() From 15625a2b13b135467743fb9191a026f026ae253a Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Wed, 12 Sep 2018 14:42:17 -0700 Subject: [PATCH 5/5] revert env var name --- appengine-java8/tasks/README.md | 6 +++--- .../tasks/src/main/java/com/example/task/CreateTask.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/appengine-java8/tasks/README.md b/appengine-java8/tasks/README.md index 5cab181bc17..00aee8be961 100644 --- a/appengine-java8/tasks/README.md +++ b/appengine-java8/tasks/README.md @@ -49,7 +49,7 @@ Set environment variables: First, your project ID: ``` -export PROJECT_ID= +export GOOGLE_CLOUD_PROJECT= ``` Then the queue ID, as specified at queue creation time. Queue IDs already @@ -73,7 +73,7 @@ Create a task, targeted at the `/tasks/create` endpoint, with a payload specifie ``` mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \ - -Dexec.args="--project-id $PROJECT_ID \ + -Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \ --queue $QUEUE_ID --location $LOCATION_ID --payload hello" ``` @@ -86,6 +86,6 @@ Create a task that will be scheduled for a time in the future using the ``` mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \ - -Dexec.args="--project-id $PROJECT_ID \ + -Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \ --queue $QUEUE_ID --location $LOCATION_ID --payload hello --in-seconds 30" ``` diff --git a/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java b/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java index c787404fc10..e66c7c6bfd6 100644 --- a/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java +++ b/appengine-java8/tasks/src/main/java/com/example/task/CreateTask.java @@ -38,11 +38,11 @@ import org.apache.commons.cli.ParseException; public class CreateTask { - private static String GOOGLE_CLOUD_PROJECT_KEY = "PROJECT_ID"; + private static String GOOGLE_CLOUD_PROJECT_KEY = "GOOGLE_CLOUD_PROJECT"; private static Option PROJECT_ID_OPTION = Option.builder("pid") .longOpt("project-id") - .desc("The Google Cloud Project, if not set as PROJECT_ID env var.") + .desc("The Google Cloud Project, if not set as GOOGLE_CLOUD_PROJECT env var.") .hasArg() .argName("project-id") .type(String.class)