Skip to content

Commit

Permalink
Merge pull request #392 from GoogleCloudPlatform/tswast-gcloud
Browse files Browse the repository at this point in the history
Remove references to gcloud-java.
  • Loading branch information
tswast committed Oct 28, 2016
2 parents 2e3f285 + bd13489 commit 8506f03
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bigquery/cloud-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ These sample Java applications demonstrate how to access the BigQuery API using
the [Google Cloud Client Library for Java][google-cloud-java].

[BigQuery]: https://cloud.google.com/bigquery/
[google-cloud-java]: https://github.com/GoogleCloudPlatform/gcloud-java
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java

## Quickstart

Expand Down
4 changes: 2 additions & 2 deletions bigquery/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>gcloud-java</artifactId>
<version>0.2.8</version>
<artifactId>google-cloud-bigquery</artifactId>
<version>0.4.0</version>
</dependency>

<!-- Test dependencies -->
Expand Down
4 changes: 2 additions & 2 deletions datastore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>gcloud-java-datastore</artifactId>
<version>0.2.8</version>
<artifactId>google-cloud-datastore</artifactId>
<version>0.4.0</version>
</dependency>

<!-- Test dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ public void testTransactionalRetry() {
--retries;
}
}
// Retry handling can also be configured and automatically applied using gcloud-java.
// Retry handling can also be configured and automatically applied using google-cloud-java.
// [END transactional_retry]
assertSuccessfulTransfer(keys.get(0), keys.get(1));
}
Expand Down
4 changes: 2 additions & 2 deletions flexible/cloudstorage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<!-- [START dependencies] -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>gcloud-java-storage</artifactId>
<version>0.2.8</version>
<artifactId>google-cloud-storage</artifactId>
<version>0.4.0</version>
</dependency>
<!-- [END dependencies] -->
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions flexible/datastore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<!-- [START dependencies] -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>gcloud-java-datastore</artifactId>
<version>0.2.8</version>
<artifactId>google-cloud-datastore</artifactId>
<version>0.4.0</version>
</dependency>
<!-- [END dependencies] -->
</dependencies>
Expand Down
96 changes: 79 additions & 17 deletions flexible/sparkjava/README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,110 @@
# SparkJava on App Engine Flexible Environment

This app demonstrates how to use [`gcloud-java`'s Datastore client](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-datastore#google-cloud-java-client-for-datastore) from within an [App Engine flexible environment](https://cloud.google.com/appengine/docs/flexible/java/hello-world) project using [SparkJava](http://sparkjava.com/). The app allows you to create and modify a database of "users", which contains their ID, name, and email information.

`gcloud-java` is an idiomatic Java client for [Google Cloud Platform](https://cloud.google.com/) services. Read more about the library [here](https://github.com/GoogleCloudPlatform/gcloud-java#google-cloud-java-client).
This app demonstrates how to use [Datastore with the Google Cloud client
library](https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-datastore)
from within an [App Engine flexible
environment](https://cloud.google.com/appengine/docs/flexible/java/hello-world)
project using [SparkJava](http://sparkjava.com/). The app allows you to create
and modify a database of "users", which contains their ID, name, and email
information.

The Google Cloud client library is an idiomatic Java client for [Google Cloud
Platform](https://cloud.google.com/) services. Read more about the library
[here](https://github.com/GoogleCloudPlatform/google-cloud-java).

Setup
-----

1. Create a Google Developers Console project with the Datastore API enabled. [Follow these instructions](https://cloud.google.com/docs/authentication#preparation) to get your project set up. If you wish to deploy this application, you will also need to [enable billing](https://support.google.com/cloud/?rd=2#topic=6288636).
1. Create a Google Cloud project with the Datastore API enabled.
[Follow these
instructions](https://cloud.google.com/docs/authentication#preparation) to
get your project set up. If you wish to deploy this application, you will
also need to [enable
billing](https://support.google.com/cloud/?rd=2#topic=6288636).

2. Set up the local development environment by [installing the Google Cloud SDK](https://cloud.google.com/sdk/) and running the following commands in command line: `gcloud auth login` and `gcloud config set project [YOUR PROJECT ID]`.
2. Set up the local development environment by [installing the Google Cloud
SDK](https://cloud.google.com/sdk/) and running the following commands in
command line: `gcloud auth login` and `gcloud config set project [YOUR
PROJECT ID]`.

3. Ensure that you have Maven installed and configured to use Java 8. See installation instructions [here](https://maven.apache.org/install.html).
3. Ensure that you have Maven installed and configured to use Java 8. See
installation instructions [here](https://maven.apache.org/install.html).

Running locally
---------------

Run the application on your local machine by typing the following into your command line from the `sparkjava` directory: `mvn clean package exec:java`. Navigate to `localhost:8080` to view and interact with the application.
Run the application on your local machine by typing the following into your
command line from the `sparkjava` directory: `mvn clean package exec:java`.
Navigate to `localhost:8080` to view and interact with the application.

Deploying
---------

If you've enabled billing (step 1 in [Setup](#Setup)), you can deploy the application to the web by running `mvn gcloud:deploy` from your command line (from the `sparkjava` directory).
If you've enabled billing (step 1 in [Setup](#Setup)), you can deploy the
application to the web by running `mvn gcloud:deploy` from your command line
(from the `sparkjava` directory).

How does it work?
-----------------

You'll notice that the source code is split into three folders: `appengine`, `java/com/google/appengine/sparkdemo`, and `resource/public`. The `appengine` folder contains a `Dockerfile` and an `app.yaml`, necessary files to [configure the VM environment](https://cloud.google.com/appengine/docs/managed-vms/config). The `java/com/google/appengine/sparkdemo` folder contains the controller code, which uses the `gcloud-java` library to modify the records in the Google Cloud Datastore. Finally, the `resource/public` folder contains the home webpage, which uses jQuery to send HTTP requests to create, remove, and update records.

Spark runs the [`main` method](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/managedvms/sparkjava-demo/src/main/java/com/google/appengine/sparkdemo/Main.java) upon server startup. The `main` method creates the controller, [`UserController`](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/managedvms/sparkjava-demo/src/main/java/com/google/appengine/sparkdemo/UserController.java). The URIs used to send HTTP requests in the [home page](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/managedvms/sparkjava-demo/src/main/resources/public/index.html) correspond to methods in the `UserController` class. For example, the `index.html` code for `create` makes a `POST` request to the path `/api/users` with a body containing the name and email of a user to add. `UserController` contains the following code to process that request:
You'll notice that the source code is split into three folders: `appengine`,
`java/com/google/appengine/sparkdemo`, and `resource/public`. The `appengine`
folder contains a `Dockerfile` and an `app.yaml`, necessary files to [configure
the VM
environment](https://cloud.google.com/appengine/docs/managed-vms/config). The
`java/com/google/appengine/sparkdemo` folder contains the controller code,
which uses the Google Cloud client library to modify the records in the Google Cloud
Datastore. Finally, the `resource/public` folder contains the home webpage,
which uses jQuery to send HTTP requests to create, remove, and update records.

Spark runs the [`main`
method](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/managedvms/sparkjava-demo/src/main/java/com/google/appengine/sparkdemo/Main.java)
upon server startup. The `main` method creates the controller,
[`UserController`](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/managedvms/sparkjava-demo/src/main/java/com/google/appengine/sparkdemo/UserController.java).
The URIs used to send HTTP requests in the [home
page](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/managedvms/sparkjava-demo/src/main/resources/public/index.html)
correspond to methods in the `UserController` class. For example, the
`index.html` code for `create` makes a `POST` request to the path `/api/users`
with a body containing the name and email of a user to add. `UserController`
contains the following code to process that request:

```java
post("/api/users", (req, res) -> userService.createUser(
req.queryParams("name"),
req.queryParams("email),
), json());
```
This code snippet gets the name and email of the user from the POST request and passes it to `createUser` (in [`UserService.java`](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/managedvms/sparkjava-demo/src/main/java/com/google/appengine/sparkdemo/UserService.java)) to create a database record using `gcloud-java`. If you want a more in-depth tutorial on using `gcloud-java` Datastore client, see the [Getting Started](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-datastore#getting-started) section in the `gcloud-java-datastore` documentation.
Communication with the Google Cloud Datastore requires authentication and setting a project ID. When running locally, `gcloud-java` automatically detects your credentials and project ID because you logged into the Google Cloud SDK and set your project ID. There are also many other options for authenticating and setting a project ID. To read more, see the [Authentication](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) and [Specifying a Project ID](https://github.com/GoogleCloudPlatform/gcloud-java#specifying-a-project-id) sections of the `gcloud-java` documentation.
You built and ran this application using Maven. To read more about using Maven with Managed VMs, see the [Using Apache Maven documentation](https://cloud.google.com/appengine/docs/java/managed-vms/maven). While this particular project uses Maven, `gcloud-java` can also be accessed using Gradle and SBT. See how to obtain the dependency in the [Quickstart section](https://github.com/GoogleCloudPlatform/gcloud-java#quickstart) of the `gcloud-java` documentation.
This code snippet gets the name and email of the user from the POST request and
passes it to `createUser` (in
[`UserService.java`](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/managedvms/sparkjava-demo/src/main/java/com/google/appengine/sparkdemo/UserService.java))
to create a database record using the Google Cloud client library. If you want
a more in-depth tutorial on using Google Cloud client library Datastore client,
see the [Getting
Started](https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-datastore#getting-started)
section of the client library documentation.
Communication with the Google Cloud Datastore requires authentication and
setting a project ID. When running locally, the Google Cloud client library
automatically detects your credentials and project ID because you logged into
the Google Cloud SDK and set your project ID. There are also many other options
for authenticating and setting a project ID. To read more, see the
[Authentication](https://github.com/GoogleCloudPlatform/google-cloud-java#authentication)
and [Specifying a Project
ID](https://github.com/GoogleCloudPlatform/google-cloud-java#specifying-a-project-id)
sections of the client library documentation.
You built and ran this application using Maven. To read more about using Maven
with App Engine flexible environment, see the [Using Apache Maven
documentation](https://cloud.google.com/appengine/docs/flexible/java/using-maven).
While this particular project uses Maven, the Google Cloud client library
packages can also be accessed using Gradle and SBT. See how to obtain the
dependency in the [Quickstart
section](https://github.com/GoogleCloudPlatform/google-cloud-java#quickstart)
of the client library documentation.
License
-------
Apache 2.0 - See [LICENSE](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/LICENSE) for more information.
Apache 2.0 - See
[LICENSE](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/LICENSE)
for more information.
4 changes: 2 additions & 2 deletions flexible/sparkjava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>gcloud-java</artifactId>
<version>0.2.7</version>
<artifactId>google-cloud</artifactId>
<version>0.4.0</version>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class UserController {

/**
* Creates a controller that maps requests to gcloud-java functions.
* Creates a controller that maps requests to actions.
*/
public UserController(final UserService userService) {
Spark.staticFileLocation("/public");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class UserService {
/**
* Constructor for UserService.
*
* @param datastore gcloud-java Datastore service object to execute requests
* @param datastore service object to execute requests
* @param kind the kind for the Datastore entities in this demo
*/
public UserService(Datastore datastore, String kind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ public StreamingRecognizeClient(ManagedChannel channel, String file, int samplin

speechClient = SpeechGrpc.newStub(channel);

//Send log4j logs to Console
//If you are going to run this on GCE, you might wish to integrate with gcloud-java logging.
//See https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/README.md#stackdriver-logging-alpha
// Send log4j logs to Console
// If you are going to run this on GCE, you might wish to integrate with
// google-cloud-java logging. See:
// https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/README.md#stackdriver-logging-alpha

ConsoleAppender appender = new ConsoleAppender(new SimpleLayout(), SYSTEM_OUT);
logger.addAppender(appender);
Expand Down

0 comments on commit 8506f03

Please sign in to comment.