From 9ce1c9681eaf69bd9cc8c813b5ac806584b88fdd Mon Sep 17 00:00:00 2001 From: averikitsch Date: Fri, 15 Mar 2019 09:48:35 -0700 Subject: [PATCH 1/7] Add HTTP sample --- appengine-java8/tasks/README.md | 25 ++- appengine-java8/tasks/pom.xml | 3 +- .../java/com/example/task/CreateHttpTask.java | 182 ++++++++++++++++++ .../java/com/example/task/CreateTask.java | 4 +- .../java/com/example/task/TaskServlet.java | 2 +- 5 files changed, 210 insertions(+), 6 deletions(-) create mode 100644 appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java diff --git a/appengine-java8/tasks/README.md b/appengine-java8/tasks/README.md index 00aee8be961..f010a6e8b1f 100644 --- a/appengine-java8/tasks/README.md +++ b/appengine-java8/tasks/README.md @@ -69,12 +69,15 @@ location is "us-central1"). export LOCATION_ID= ``` +### Using App Engine Queues Create a task, targeted at the `/tasks/create` endpoint, with a payload specified: ``` mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \ -Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \ - --queue $QUEUE_ID --location $LOCATION_ID --payload hello" + --queue $QUEUE_ID \ + --location $LOCATION_ID \ + --payload hello" ``` The App Engine app serves as a target for the push requests. It has an @@ -89,3 +92,23 @@ mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \ -Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \ --queue $QUEUE_ID --location $LOCATION_ID --payload hello --in-seconds 30" ``` + +### Using HTTP Push Queues + +Set an environment variable for the endpoint to your task handler. This is an +example url to send requests to the App Engine task handler: +``` +export URL=https://${PROJECT_ID}.appspot.com/tasks/create +``` + +Running the sample will create a task and send the task to the specific URL +endpoint, with a payload specified: + +``` +mvn exec:java -Dexec.mainClass="com.example.task.CreateHttpTask" \ + -Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \ + --url $URL \ + --queue $QUEUE_ID \ + --location $LOCATION_ID \ + --payload hello" +``` diff --git a/appengine-java8/tasks/pom.xml b/appengine-java8/tasks/pom.xml index 7d14c1d93bd..4a8b9c67b56 100644 --- a/appengine-java8/tasks/pom.xml +++ b/appengine-java8/tasks/pom.xml @@ -52,7 +52,7 @@ Copyright 2018 Google LLC com.google.cloud google-cloud-tasks - 0.63.0-beta + 0.83.0-beta commons-cli @@ -88,7 +88,6 @@ Copyright 2018 Google LLC exec-maven-plugin 1.6.0 - com.example.task.CreateTask false diff --git a/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java b/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java new file mode 100644 index 00000000000..96e9eee92e0 --- /dev/null +++ b/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java @@ -0,0 +1,182 @@ +/* + * 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.task; + +import com.google.cloud.tasks.v2beta3.HttpRequest; +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; + +import java.nio.charset.Charset; +import java.time.Clock; +import java.time.Instant; + +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 CreateHttpTask { + 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 GOOGLE_CLOUD_PROJECT env var.") + .hasArg() + .argName("project-id") + .type(String.class) + .build(); + + private static Option QUEUE_OPTION = Option.builder("q") + .required() + .longOpt("queue") + .desc("The Cloud Tasks queue.") + .hasArg() + .argName("queue") + .type(String.class) + .build(); + + private static Option LOCATION_OPTION = Option.builder("l") + .required() + .longOpt("location") + .desc("The region in which your queue is running.") + .hasArg() + .argName("location") + .type(String.class) + .build(); + + private static Option URL_OPTION = Option.builder("u") + .required() + .longOpt("url") + .desc("The full url path that the request will be sent to.") + .hasArg() + .argName("url") + .type(String.class) + .build(); + + private static Option PAYLOAD_OPTION = Option.builder("p") + .longOpt("payload") + .desc("The payload string for the task.") + .hasArg() + .argName("payload") + .type(String.class) + .build(); + + private static Option IN_SECONDS_OPTION = Option.builder("s") + .longOpt("in-seconds") + .desc("Schedule time for the task to create.") + .hasArg() + .argName("in-seconds") + .type(int.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); + options.addOption(URL_OPTION); + options.addOption(PAYLOAD_OPTION); + options.addOption(IN_SECONDS_OPTION); + + if (args.length == 0) { + printUsage(options); + return; + } + + CommandLineParser parser = new DefaultParser(); + CommandLine params = null; + 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(GOOGLE_CLOUD_PROJECT_KEY); + } + if (Strings.isNullOrEmpty(projectId)) { + printUsage(options); + return; + } + + String queueName = params.getOptionValue(QUEUE_OPTION.getOpt()); + String location = params.getOptionValue(LOCATION_OPTION.getOpt()); + String url = params.getOptionValue(URL_OPTION.getOpt()); + String payload = params.getOptionValue(PAYLOAD_OPTION.getOpt(), "default payload"); + + // [START cloud_tasks_create_http_task] + // Instantiates a client. + try (CloudTasksClient client = CloudTasksClient.create()) { + + // Variables provided by the CLI. + // projectId = "my-project-id"; + // queueName = "my-appengine-queue"; + // location = "us-central1"; + // url = "https://.appspot.com/tasks/create"; + // 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() + .setHttpRequest(HttpRequest.newBuilder() + .setBody(ByteString.copyFrom(payload, Charset.defaultCharset())) + .setUrl(url) + .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())); + } + + // Send create task request. + Task task = client.createTask(queuePath, taskBuilder.build()); + System.out.println("Task created: " + task.getName()); + } + // [END cloud_tasks_create_http_task] + } + + private static void printUsage(Options options) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp( + "client", + "A simple Cloud Tasks command line client that creates a task with an " + + "HTTP endpoint.", + options, "", true); + throw new RuntimeException(); + } + +} 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 e66c7c6bfd6..4863d103366 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 @@ -161,8 +161,8 @@ private static void printUsage(Options options) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "client", - "A simple Cloud Tasks command line client that triggers a call to an AppEngine " - + "endpoint.", + "A simple Cloud Tasks command line client that creates a task with an " + + "App Engine endpoint.", options, "", true); throw new RuntimeException(); } 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 141f9264047..adbef6c37c7 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 @@ -38,7 +38,7 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOEx 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); From 81002990e490882cb58b6ea40540fc02f1415aaa Mon Sep 17 00:00:00 2001 From: averikitsch Date: Fri, 15 Mar 2019 10:11:56 -0700 Subject: [PATCH 2/7] Fix linting --- .../tasks/src/main/java/com/example/task/CreateHttpTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java b/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java index 96e9eee92e0..676494cd6c5 100644 --- a/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java +++ b/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java @@ -16,9 +16,9 @@ package com.example.task; -import com.google.cloud.tasks.v2beta3.HttpRequest; import com.google.cloud.tasks.v2beta3.CloudTasksClient; import com.google.cloud.tasks.v2beta3.HttpMethod; +import com.google.cloud.tasks.v2beta3.HttpRequest; import com.google.cloud.tasks.v2beta3.QueueName; import com.google.cloud.tasks.v2beta3.Task; import com.google.common.base.Strings; From cf9160208cd32c6eab51746dbed7a34d2dcd700c Mon Sep 17 00:00:00 2001 From: averikitsch Date: Mon, 15 Apr 2019 13:40:37 -0700 Subject: [PATCH 3/7] remove CLI --- appengine-java8/tasks/README.md | 7 +- .../java/com/example/task/CreateHttpTask.java | 117 +----------------- 2 files changed, 7 insertions(+), 117 deletions(-) diff --git a/appengine-java8/tasks/README.md b/appengine-java8/tasks/README.md index f010a6e8b1f..1aed7c51557 100644 --- a/appengine-java8/tasks/README.md +++ b/appengine-java8/tasks/README.md @@ -105,10 +105,5 @@ Running the sample will create a task and send the task to the specific URL endpoint, with a payload specified: ``` -mvn exec:java -Dexec.mainClass="com.example.task.CreateHttpTask" \ - -Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \ - --url $URL \ - --queue $QUEUE_ID \ - --location $LOCATION_ID \ - --payload hello" +mvn exec:java -Dexec.mainClass="com.example.task.CreateHttpTask" ``` diff --git a/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java b/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java index 676494cd6c5..9334322a0a7 100644 --- a/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java +++ b/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java @@ -38,98 +38,12 @@ import org.apache.commons.cli.ParseException; public class CreateHttpTask { - 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 GOOGLE_CLOUD_PROJECT env var.") - .hasArg() - .argName("project-id") - .type(String.class) - .build(); - - private static Option QUEUE_OPTION = Option.builder("q") - .required() - .longOpt("queue") - .desc("The Cloud Tasks queue.") - .hasArg() - .argName("queue") - .type(String.class) - .build(); - - private static Option LOCATION_OPTION = Option.builder("l") - .required() - .longOpt("location") - .desc("The region in which your queue is running.") - .hasArg() - .argName("location") - .type(String.class) - .build(); - - private static Option URL_OPTION = Option.builder("u") - .required() - .longOpt("url") - .desc("The full url path that the request will be sent to.") - .hasArg() - .argName("url") - .type(String.class) - .build(); - - private static Option PAYLOAD_OPTION = Option.builder("p") - .longOpt("payload") - .desc("The payload string for the task.") - .hasArg() - .argName("payload") - .type(String.class) - .build(); - - private static Option IN_SECONDS_OPTION = Option.builder("s") - .longOpt("in-seconds") - .desc("Schedule time for the task to create.") - .hasArg() - .argName("in-seconds") - .type(int.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); - options.addOption(URL_OPTION); - options.addOption(PAYLOAD_OPTION); - options.addOption(IN_SECONDS_OPTION); - - if (args.length == 0) { - printUsage(options); - return; - } - - CommandLineParser parser = new DefaultParser(); - CommandLine params = null; - 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(GOOGLE_CLOUD_PROJECT_KEY); - } - if (Strings.isNullOrEmpty(projectId)) { - printUsage(options); - return; - } - - String queueName = params.getOptionValue(QUEUE_OPTION.getOpt()); - String location = params.getOptionValue(LOCATION_OPTION.getOpt()); - String url = params.getOptionValue(URL_OPTION.getOpt()); - String payload = params.getOptionValue(PAYLOAD_OPTION.getOpt(), "default payload"); + public static void main(String[] args) throws Exception { + String projectId = System.getenv("PROJECT_ID"); + String queueName = System.getenv("QUEUE_ID"); + String location = System.getenv("LOCATION_ID"); + String url = System.getenv("URL"); // [START cloud_tasks_create_http_task] // Instantiates a client. @@ -140,7 +54,7 @@ public static void main(String... args) throws Exception { // queueName = "my-appengine-queue"; // location = "us-central1"; // url = "https://.appspot.com/tasks/create"; - // payload = "hello"; + String payload = "hello"; // Construct the fully qualified queue name. String queuePath = QueueName.of(projectId, location, queueName).toString(); @@ -154,29 +68,10 @@ public static void main(String... args) throws Exception { .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())); - } - // Send create task request. Task task = client.createTask(queuePath, taskBuilder.build()); System.out.println("Task created: " + task.getName()); } // [END cloud_tasks_create_http_task] } - - private static void printUsage(Options options) { - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp( - "client", - "A simple Cloud Tasks command line client that creates a task with an " - + "HTTP endpoint.", - options, "", true); - throw new RuntimeException(); - } - } From 70b0fe6044ad42f2303eb761437d1b93da48970a Mon Sep 17 00:00:00 2001 From: averikitsch Date: Tue, 16 Apr 2019 15:55:15 -0700 Subject: [PATCH 4/7] Move http sample --- appengine-java8/tasks/README.md | 15 ---- tasks/README.md | 85 +++++++++++++++++++ tasks/pom.xml | 64 ++++++++++++++ .../java/com/example/task/CreateHttpTask.java | 14 +-- 4 files changed, 152 insertions(+), 26 deletions(-) create mode 100644 tasks/README.md create mode 100644 tasks/pom.xml rename {appengine-java8/tasks => tasks}/src/main/java/com/example/task/CreateHttpTask.java (84%) diff --git a/appengine-java8/tasks/README.md b/appengine-java8/tasks/README.md index 1aed7c51557..8fc7231896c 100644 --- a/appengine-java8/tasks/README.md +++ b/appengine-java8/tasks/README.md @@ -92,18 +92,3 @@ mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \ -Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \ --queue $QUEUE_ID --location $LOCATION_ID --payload hello --in-seconds 30" ``` - -### Using HTTP Push Queues - -Set an environment variable for the endpoint to your task handler. This is an -example url to send requests to the App Engine task handler: -``` -export URL=https://${PROJECT_ID}.appspot.com/tasks/create -``` - -Running the sample will create a task and send the task to the specific URL -endpoint, with a payload specified: - -``` -mvn exec:java -Dexec.mainClass="com.example.task.CreateHttpTask" -``` diff --git a/tasks/README.md b/tasks/README.md new file mode 100644 index 00000000000..760a0ba6605 --- /dev/null +++ b/tasks/README.md @@ -0,0 +1,85 @@ +# Google Cloud Tasks App Engine Queue Samples + +Sample command-line program for interacting with the Cloud Tasks API +using App Engine queues. + +App Engine queues push tasks to an App Engine HTTP target. This directory +contains both the App Engine app to deploy, as well as the snippets to run +locally to push tasks to it, which could also be called on App Engine. + +`CreateTask.java` is a simple command-line program to create +tasks to be pushed to the App Engine app. + +`TaskServlet.java` is the main App Engine app. This app serves as an endpoint to receive +App Engine task attempts. + + +## 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). + * Set up [Google Application Credentials](https://cloud.google.com/docs/authentication/getting-started). + +## Creating a queue + +To create a queue using the Cloud SDK, use the following gcloud command: + +``` +gcloud beta tasks queues create-app-engine-queue my-appengine-queue +``` + +Note: A newly created queue will route to the default App Engine service and +version unless configured to do otherwise. + +## Deploying the App Engine app +[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) + +``` +mvn appengine:deploy +``` + +## Run the Sample Using the Command Line + +Set environment variables: + +First, your project ID: + +``` +export GOOGLE_CLOUD_PROJECT= +``` + +Then the queue ID, as specified at queue creation time. Queue IDs already +created can be listed with `gcloud beta tasks queues list`. + +``` +export QUEUE_ID=my-appengine-queue +``` + +And finally the location ID, which can be discovered with +`gcloud beta tasks queues describe $QUEUE_ID`, with the location embedded in +the "name" value (for instance, if the name is +"projects/my-project/locations/us-central1/queues/my-appengine-queue", then the +location is "us-central1"). + +``` +export LOCATION_ID= +``` + +### Using HTTP Push Queues + +Set an environment variable for the endpoint to your task handler. This is an +example url to send requests to the App Engine task handler: +``` +export URL=https://${PROJECT_ID}.appspot.com/tasks/create +``` + +Running the sample will create a task and send the task to the specific URL +endpoint, with a payload specified: + +``` +mvn exec:java -Dexec.mainClass="com.example.task.CreateHttpTask" +``` diff --git a/tasks/pom.xml b/tasks/pom.xml new file mode 100644 index 00000000000..db06d0f5b8c --- /dev/null +++ b/tasks/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + war + 1.0-SNAPSHOT + com.example.task + tasks-samples + + + + com.google.cloud.samples + shared-configuration + 1.0.10 + + + + + 1.8 + 1.8 + false + + + + + + com.google.cloud + google-cloud-tasks + 0.87.0-beta + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.4.0 + + com.example.task.CreateHttpTask + false + + + + + diff --git a/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java b/tasks/src/main/java/com/example/task/CreateHttpTask.java similarity index 84% rename from appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java rename to tasks/src/main/java/com/example/task/CreateHttpTask.java index 9334322a0a7..90a54d5fe94 100644 --- a/appengine-java8/tasks/src/main/java/com/example/task/CreateHttpTask.java +++ b/tasks/src/main/java/com/example/task/CreateHttpTask.java @@ -16,6 +16,7 @@ package com.example.task; +// [START cloud_tasks_create_http_task] import com.google.cloud.tasks.v2beta3.CloudTasksClient; import com.google.cloud.tasks.v2beta3.HttpMethod; import com.google.cloud.tasks.v2beta3.HttpRequest; @@ -29,14 +30,6 @@ import java.time.Clock; import java.time.Instant; -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 CreateHttpTask { public static void main(String[] args) throws Exception { @@ -45,11 +38,10 @@ public static void main(String[] args) throws Exception { String location = System.getenv("LOCATION_ID"); String url = System.getenv("URL"); - // [START cloud_tasks_create_http_task] // Instantiates a client. try (CloudTasksClient client = CloudTasksClient.create()) { - // Variables provided by the CLI. + // Variables provided by the system variables. // projectId = "my-project-id"; // queueName = "my-appengine-queue"; // location = "us-central1"; @@ -72,6 +64,6 @@ public static void main(String[] args) throws Exception { Task task = client.createTask(queuePath, taskBuilder.build()); System.out.println("Task created: " + task.getName()); } - // [END cloud_tasks_create_http_task] } } +// [END cloud_tasks_create_http_task] From 8e8e534672a091d37f1f4099deaeb31ba3e52441 Mon Sep 17 00:00:00 2001 From: averikitsch Date: Tue, 16 Apr 2019 15:56:43 -0700 Subject: [PATCH 5/7] Fix pom.xml --- appengine-java8/tasks/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/appengine-java8/tasks/pom.xml b/appengine-java8/tasks/pom.xml index 5a78a135cf8..2f5ba869b8a 100644 --- a/appengine-java8/tasks/pom.xml +++ b/appengine-java8/tasks/pom.xml @@ -88,6 +88,7 @@ Copyright 2018 Google LLC exec-maven-plugin 1.6.0 + com.example.task.CreateTask false From 464f71060cc397eb8e2ddec88aff2fabc04acad6 Mon Sep 17 00:00:00 2001 From: averikitsch Date: Thu, 18 Apr 2019 12:50:24 -0700 Subject: [PATCH 6/7] Update pom and linting --- tasks/pom.xml | 2 +- .../java/com/example/task/CreateHttpTask.java | 21 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/tasks/pom.xml b/tasks/pom.xml index db06d0f5b8c..2f7fadae430 100644 --- a/tasks/pom.xml +++ b/tasks/pom.xml @@ -30,7 +30,7 @@ Copyright 2018 Google LLC com.google.cloud.samples shared-configuration - 1.0.10 + 1.0.11 diff --git a/tasks/src/main/java/com/example/task/CreateHttpTask.java b/tasks/src/main/java/com/example/task/CreateHttpTask.java index 90a54d5fe94..9b4a1ac23d6 100644 --- a/tasks/src/main/java/com/example/task/CreateHttpTask.java +++ b/tasks/src/main/java/com/example/task/CreateHttpTask.java @@ -22,13 +22,8 @@ import com.google.cloud.tasks.v2beta3.HttpRequest; 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; - import java.nio.charset.Charset; -import java.time.Clock; -import java.time.Instant; public class CreateHttpTask { @@ -40,7 +35,6 @@ public static void main(String[] args) throws Exception { // Instantiates a client. try (CloudTasksClient client = CloudTasksClient.create()) { - // Variables provided by the system variables. // projectId = "my-project-id"; // queueName = "my-appengine-queue"; @@ -52,13 +46,14 @@ public static void main(String[] args) throws Exception { String queuePath = QueueName.of(projectId, location, queueName).toString(); // Construct the task body. - Task.Builder taskBuilder = Task - .newBuilder() - .setHttpRequest(HttpRequest.newBuilder() - .setBody(ByteString.copyFrom(payload, Charset.defaultCharset())) - .setUrl(url) - .setHttpMethod(HttpMethod.POST) - .build()); + Task.Builder taskBuilder = + Task.newBuilder() + .setHttpRequest( + HttpRequest.newBuilder() + .setBody(ByteString.copyFrom(payload, Charset.defaultCharset())) + .setUrl(url) + .setHttpMethod(HttpMethod.POST) + .build()); // Send create task request. Task task = client.createTask(queuePath, taskBuilder.build()); From c88de0b15144636cfae1458f902847223ad29f90 Mon Sep 17 00:00:00 2001 From: averikitsch Date: Thu, 18 Apr 2019 14:00:18 -0700 Subject: [PATCH 7/7] Update tasks version --- appengine-java8/tasks/pom.xml | 2 +- tasks/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appengine-java8/tasks/pom.xml b/appengine-java8/tasks/pom.xml index 2f5ba869b8a..ba427ae32bb 100644 --- a/appengine-java8/tasks/pom.xml +++ b/appengine-java8/tasks/pom.xml @@ -52,7 +52,7 @@ Copyright 2018 Google LLC com.google.cloud google-cloud-tasks - 0.86.0-beta + 0.88.0-beta commons-cli diff --git a/tasks/pom.xml b/tasks/pom.xml index 2f7fadae430..5151ee378c0 100644 --- a/tasks/pom.xml +++ b/tasks/pom.xml @@ -45,7 +45,7 @@ Copyright 2018 Google LLC com.google.cloud google-cloud-tasks - 0.87.0-beta + 0.88.0-beta