Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
!/.idea/codeStyleSettings.xml

# Gradle interim configs
.gradle/*
*/.gradle/*

# Generated source code
*/generated/*
Expand Down
64 changes: 39 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
# gcloud-java

[![codecov](https://codecov.io/gh/SpineEventEngine/gcloud-java/branch/master/graph/badge.svg)](https://codecov.io/gh/SpineEventEngine/gcloud-java)
[![Build Status](https://travis-ci.com/SpineEventEngine/gcloud-java.svg?branch=master)](https://travis-ci.com/SpineEventEngine/gcloud-java)
[![codecov][codecov-badge]][codecov] [![Build Status][travis-badge]][travis]

[codecov]: https://codecov.io/gh/SpineEventEngine/gcloud-java
[codecov-badge]: https://codecov.io/gh/SpineEventEngine/gcloud-java/branch/master/graph/badge.svg
[travis]: https://travis-ci.com/SpineEventEngine/gcloud-java
[travis-badge]: https://travis-ci.com/SpineEventEngine/gcloud-java.svg?branch=master

Support for Spine-based Java apps running at Google Cloud.

### Artifacts

Gradle:

```groovy
```kotlin
dependencies {
implementation (

// Datastore Storage support library.
"io.spine.gcloud:spine-datastore:1.5.0",
// Stackdriver Trace support library.
"io.spine.gcloud:spine-stackdriver-trace:1.5.0",

// Datastore-related test utilities (if needed).
"io.spine.gcloud:testutil-gcloud:1.5.0"
)
// Datastore Storage support library.
implementation("io.spine.gcloud:spine-datastore:1.5.22")

// Pub/Sub messaging support library.
implementation("io.spine.gcloud:spine-pubsub:1.5.22")

// Stackdriver Trace support library.
implementation("io.spine.gcloud:spine-stackdriver-trace:1.5.22")

// Datastore-related test utilities (if needed).
implementation("io.spine.gcloud:testutil-gcloud:1.5.22")
}
```

These artifacts should be used as a part of the Spine server application.

For the details on setting up the server environment please refer to [Spine Bootstrap Gradle plugin](https://github.com/SpineEventEngine/bootstrap/)
and [Spine `core` modules](https://github.com/SpineEventEngine/core-java/) documentation.
For the details on setting up the server environment please refer to
[Spine Bootstrap Gradle plugin][bootstrap] and [Spine `core` modules][core-java] documentation.

[bootstrap]: https://github.com/SpineEventEngine/bootstrap/
[core-java]: https://github.com/SpineEventEngine/core-java/

### Configuring Datastore

Expand All @@ -40,8 +47,9 @@ be set. Please notice a special index configuration for your custom `Aggregate`

The configuration file is located at `./datastore/config/index.yaml`.

Please see the [Google Cloud Platform documentation](https://cloud.google.com/datastore/docs/tools/indexconfig)
for the details.
Please see the [Google Cloud Platform documentation][datastore-index] for the details.

[datastore-index]: https://cloud.google.com/datastore/docs/tools/indexconfig

##### Custom indexes

Expand All @@ -51,9 +59,10 @@ Such an approach is useful to optimize read-side querying. In this case more Dat

__Example:__
Assuming you have a Projection type called `CustomerProjection`. Its state is declared in
the Protobuf type `my.company.Customer`. It has Entity Columns `country` and
`companySize`. Once you try to make a query in those Columns, the Datastore will fail with
the Protobuf type `my.company.Customer`. It has Entity Columns `country` and `companySize`.
Once you try to make a query in those Columns, the Datastore will fail with
an internal Exception. To prevent this, you should create an index for your `CustomerProjection`:

```yaml
- kind: my.company.Customer
ancestor: no
Expand All @@ -69,11 +78,12 @@ This section describes testing the `gcloud-java` library itself.
##### Preconditions

To run the task successfully, you must have `gcloud` tool properly installed and configured:
- install gcloud of the last version;
- [install][gcloud-install] `gcloud` of the last version;
- login under a Google account when initializing the `gcloud`;
- to run tests you should select `spine-dev` Google Cloud Console project;
- skip Google App Engine setup if not required.

[gcloud-install]: https://cloud.google.com/sdk/docs/downloads-interactive

##### Running the tests

Expand All @@ -83,16 +93,20 @@ To start a local emulator and run test against it, run `./gradlew check`.

To start an emulator without running tests `./gradlew startDatastore`.

To stop the Datastore emulator, just terminate the emulator process (e.g. `kill -9 $(lsof -i:8080)` or just close the terminal window on Windows).
To stop the Datastore emulator, just terminate the emulator process (e.g. `kill -9 $(lsof -i:8080)`
or just close the terminal window on Windows).

The launched emulator will run at `localhost:8080` and will not have any persistence.
To change the configuration see `./scripts/start-datastore.*` scripts.

The datastore is cleaned up after each test.
See test classes under `./datastore/src/test/java/...` and `io.spine.server.storage.datastore.TestDatastoreStorageFactory#clear`.
See test classes under `./datastore/src/test/java/...` and
`io.spine.server.storage.datastore.TestDatastoreStorageFactory#clear`.

*Stackdriver-Trace*

The test are launched in a scope of Gradle `test` phase. However, they rely upon an Google Cloud credentials file located at `<project root>/stackdriver-trace/src/test/resources/spine-dev.json`.
The test are launched in a scope of Gradle `test` phase. However, they rely on a Google Cloud
credentials file located at `<project root>/stackdriver-trace/src/test/resources/spine-dev.json`.

To run the tests, obtain the service account file for your environment and make it available to the test code in the specified location.
To run the tests, obtain the service account file for your environment and make it available
to the test code in the specified location.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ allprojects {
}

extra["credentialsPropertyFile"] = PublishingRepos.cloudRepo.credentials
extra["projectsToPublish"] = listOf("datastore", "stackdriver-trace", "testutil-gcloud")
extra["projectsToPublish"] = listOf("datastore", "stackdriver-trace", "testutil-gcloud", "pubsub")

subprojects {
apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import java.io.FileNotFoundException
import java.net.URL

/**
Expand All @@ -52,21 +53,21 @@ open class CheckVersionIncrement : DefaultTask() {
val artifact = "${project.artifactPath()}/${MavenMetadata.FILE_NAME}"
val repoUrl = repository.releases
val metadata = fetch(repoUrl, artifact)
val versions = metadata.versioning.versions
val versionExists = versions.contains(version)
val versions = metadata?.versioning?.versions
val versionExists = versions?.contains(version) ?: false
if (versionExists) {
throw GradleException("""
Version `$version` is already published to maven repository `$repoUrl`.
Try incrementing the library version.
All available versions are: ${versions.joinToString(separator = ", ")}.
All available versions are: ${versions?.joinToString(separator = ", ")}.

To disable this check, run Gradle with `-x $name`.
""".trimIndent()
)
}
}

private fun fetch(repository: String, artifact: String): MavenMetadata {
private fun fetch(repository: String, artifact: String): MavenMetadata? {
val url = URL("$repository/$artifact")
return MavenMetadata.fetchAndParse(url)
}
Expand Down Expand Up @@ -94,9 +95,19 @@ private data class MavenMetadata(var versioning: Versioning = Versioning()) {
mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
}

fun fetchAndParse(url: URL): MavenMetadata {
val metadata = mapper.readValue(url, MavenMetadata::class.java)
return metadata
/**
* Fetches the metadata for the repository and parses the document.
*
* <p>If the document could not be found, assumes that the module was never
* released and thus has no metadata.
*/
fun fetchAndParse(url: URL): MavenMetadata? {
return try {
val metadata = mapper.readValue(url, MavenMetadata::class.java)
metadata
} catch (e: FileNotFoundException) {
null
}
}
}
}
Expand Down
Loading