Skip to content

Update task sample for java 11 #1382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 23, 2019
Merged

Update task sample for java 11 #1382

merged 18 commits into from
Apr 23, 2019

Conversation

averikitsch
Copy link
Contributor

No description provided.

@averikitsch averikitsch requested a review from a team April 12, 2019 15:42
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 12, 2019
@averikitsch averikitsch added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 12, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 12, 2019
@averikitsch averikitsch requested a review from lesv April 16, 2019 23:58
@@ -0,0 +1,49 @@
<!--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pom doesn't seem to do anything - it should be able to be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be removed.

First, your project ID:

```
export GOOGLE_CLOUD_PROJECT=<YOUR_GOOGLE_CLOUD_PROJECT>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best practice to escape variable contents with quotes in bash.

Suggested change
export GOOGLE_CLOUD_PROJECT=<YOUR_GOOGLE_CLOUD_PROJECT>
export GOOGLE_CLOUD_PROJECT="<YOUR_GOOGLE_CLOUD_PROJECT>"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

created can be listed with `gcloud beta tasks queues list`.

```
export QUEUE_ID=my-appengine-queue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export QUEUE_ID=my-appengine-queue
export QUEUE_ID="my-appengine-queue"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

location is "us-central1").

```
export LOCATION_ID=<YOUR_ZONE>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export LOCATION_ID=<YOUR_ZONE>
export LOCATION_ID="<YOUR_ZONE>"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<!-- <parent>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to uncomment this before submitting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks commented to me.


<dependencies>
<dependency>
<groupId>com.google.appengine.demo</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to have a comment or link to instructions on where the user can go to build this requirement, since it's unable to be pulled down from maven central.

A relative path might also work? Up to you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user comes to this sample from a link, it's unclear where they have to go for this (they may not realize the entire structure of the samples). Please expand either stating "from this repository" or add a full link so the user can take a look.

import java.time.Clock;
import java.time.Instant;

import org.apache.commons.cli.CommandLine;
Copy link
Contributor

@kurtisvg kurtisvg Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There has been a bunch of pushback on adding CLI's to samples (the new sample format mandates you don't unless it's an explicit requirement for the sample). This is because a) it ends up being a bunch of boilerplate code, b) everyone uses a different cli framework and so it becomes a pain to maintain or update future versions. (Java is also particularly painful since it's hard to remember the correct execution syntax.)

A better alternative would be to add an HTTP endpoint that covers the task creation instead, and provide the user with instructions using curl.

(This is up to you since there is no collective agreement on when the new samples format becomes mandatory)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the larger CLI; however still using main in order to be executable.

.longOpt("project-id")
.desc("The Google Cloud Project, if not set as GOOGLE_CLOUD_PROJECT env var.")
.hasArg()
.argName("project-id")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest something like the following to make it clear that the user needs to provide their own data:

Suggested change
.argName("project-id")
.argName("your-project-id")


// Instantiates a client.
try (CloudTasksClient client = CloudTasksClient.create()) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nix the newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

// Construct the task body.
Task.Builder taskBuilder = Task
.newBuilder()
.setAppEngineHttpRequest(AppEngineHttpRequest.newBuilder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line break looks like it might be a style violation (checkstyle should catch it when you get it added)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still seems wrong - see "Where to Line Break"

@kurtisvg kurtisvg removed the request for review from lesv April 17, 2019 01:42
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<!-- <parent>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks commented to me.

@@ -0,0 +1,49 @@
<!--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be removed.


<dependencies>
<dependency>
<groupId>com.google.appengine.demo</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user comes to this sample from a link, it's unclear where they have to go for this (they may not realize the entire structure of the samples). Please expand either stating "from this repository" or add a full link so the user can take a look.

// Construct the task body.
Task.Builder taskBuilder = Task
.newBuilder()
.setAppEngineHttpRequest(AppEngineHttpRequest.newBuilder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still seems wrong - see "Where to Line Break"

@averikitsch
Copy link
Contributor Author

@kurtisvg I updated the task handler to a Spring Boot app and moved it to a separate directory.

<artifactId>task-handler-j11</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you run a formatter on this POM? IntelliJ has on built in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the shared config parent - is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for Spring Boot. Adding the dependencies individually was making it more complicated but I can do that instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be fine if the shared-config work as a dependency instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured out how cleanly remove this.

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be an open/close tag?

@@ -0,0 +1,286 @@
#!/bin/sh
# ----------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to include a maven wrapper with this sample? The licensing may have ramifications.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a property? DPE bot is unable to update versions that use these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -0,0 +1,34 @@
/*
* Copyright 2017-2019 the original author or authors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This license header is incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -0,0 +1,41 @@
/*
* Copyright 2017-2019 the original author or authors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This license header is incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

<!--
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Indent this.

<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.0.11</version>
<relativePath></relativePath>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to specify a relative path - should pull from maven.

@averikitsch averikitsch merged commit f7ab04f into master Apr 23, 2019
@averikitsch averikitsch deleted the tasks-sample branch April 23, 2019 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants