Skip to content

Commit 6d7af97

Browse files
Merge pull request #150 from SpineEventEngine/add-pubsub-module
Add pubsub module
2 parents 10804c6 + 430dbee commit 6d7af97

File tree

11 files changed

+612
-67
lines changed

11 files changed

+612
-67
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
!/.idea/codeStyleSettings.xml
88

99
# Gradle interim configs
10-
.gradle/*
10+
*/.gradle/*
1111

1212
# Generated source code
1313
*/generated/*

README.md

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
# gcloud-java
22

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

5+
[codecov]: https://codecov.io/gh/SpineEventEngine/gcloud-java
6+
[codecov-badge]: https://codecov.io/gh/SpineEventEngine/gcloud-java/branch/master/graph/badge.svg
7+
[travis]: https://travis-ci.com/SpineEventEngine/gcloud-java
8+
[travis-badge]: https://travis-ci.com/SpineEventEngine/gcloud-java.svg?branch=master
9+
610
Support for Spine-based Java apps running at Google Cloud.
711

812
### Artifacts
913

1014
Gradle:
1115

12-
```groovy
16+
```kotlin
1317
dependencies {
14-
implementation (
15-
16-
// Datastore Storage support library.
17-
"io.spine.gcloud:spine-datastore:1.5.0",
18-
19-
// Stackdriver Trace support library.
20-
"io.spine.gcloud:spine-stackdriver-trace:1.5.0",
21-
22-
// Datastore-related test utilities (if needed).
23-
"io.spine.gcloud:testutil-gcloud:1.5.0"
24-
)
18+
// Datastore Storage support library.
19+
implementation("io.spine.gcloud:spine-datastore:1.5.22")
20+
21+
// Pub/Sub messaging support library.
22+
implementation("io.spine.gcloud:spine-pubsub:1.5.22")
23+
24+
// Stackdriver Trace support library.
25+
implementation("io.spine.gcloud:spine-stackdriver-trace:1.5.22")
26+
27+
// Datastore-related test utilities (if needed).
28+
implementation("io.spine.gcloud:testutil-gcloud:1.5.22")
2529
}
2630
```
2731

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

30-
For the details on setting up the server environment please refer to [Spine Bootstrap Gradle plugin](https://github.com/SpineEventEngine/bootstrap/)
31-
and [Spine `core` modules](https://github.com/SpineEventEngine/core-java/) documentation.
34+
For the details on setting up the server environment please refer to
35+
[Spine Bootstrap Gradle plugin][bootstrap] and [Spine `core` modules][core-java] documentation.
36+
37+
[bootstrap]: https://github.com/SpineEventEngine/bootstrap/
38+
[core-java]: https://github.com/SpineEventEngine/core-java/
3239

3340
### Configuring Datastore
3441

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

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

43-
Please see the [Google Cloud Platform documentation](https://cloud.google.com/datastore/docs/tools/indexconfig)
44-
for the details.
50+
Please see the [Google Cloud Platform documentation][datastore-index] for the details.
51+
52+
[datastore-index]: https://cloud.google.com/datastore/docs/tools/indexconfig
4553

4654
##### Custom indexes
4755

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

5260
__Example:__
5361
Assuming you have a Projection type called `CustomerProjection`. Its state is declared in
54-
the Protobuf type `my.company.Customer`. It has Entity Columns `country` and
55-
`companySize`. Once you try to make a query in those Columns, the Datastore will fail with
62+
the Protobuf type `my.company.Customer`. It has Entity Columns `country` and `companySize`.
63+
Once you try to make a query in those Columns, the Datastore will fail with
5664
an internal Exception. To prevent this, you should create an index for your `CustomerProjection`:
65+
5766
```yaml
5867
- kind: my.company.Customer
5968
ancestor: no
@@ -69,11 +78,12 @@ This section describes testing the `gcloud-java` library itself.
6978
##### Preconditions
7079

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

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

7888
##### Running the tests
7989

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

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

86-
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).
96+
To stop the Datastore emulator, just terminate the emulator process (e.g. `kill -9 $(lsof -i:8080)`
97+
or just close the terminal window on Windows).
8798

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

91102
The datastore is cleaned up after each test.
92-
See test classes under `./datastore/src/test/java/...` and `io.spine.server.storage.datastore.TestDatastoreStorageFactory#clear`.
103+
See test classes under `./datastore/src/test/java/...` and
104+
`io.spine.server.storage.datastore.TestDatastoreStorageFactory#clear`.
93105

94106
*Stackdriver-Trace*
95107

96-
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`.
108+
The test are launched in a scope of Gradle `test` phase. However, they rely on a Google Cloud
109+
credentials file located at `<project root>/stackdriver-trace/src/test/resources/spine-dev.json`.
97110

98-
To run the tests, obtain the service account file for your environment and make it available to the test code in the specified location.
111+
To run the tests, obtain the service account file for your environment and make it available
112+
to the test code in the specified location.

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ allprojects {
6363
}
6464

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

6868
subprojects {
6969
apply {

buildSrc/src/main/kotlin/io/spine/gradle/internal/CheckVersionIncrement.kt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.gradle.api.GradleException
2727
import org.gradle.api.Project
2828
import org.gradle.api.tasks.Input
2929
import org.gradle.api.tasks.TaskAction
30+
import java.io.FileNotFoundException
3031
import java.net.URL
3132

3233
/**
@@ -52,21 +53,21 @@ open class CheckVersionIncrement : DefaultTask() {
5253
val artifact = "${project.artifactPath()}/${MavenMetadata.FILE_NAME}"
5354
val repoUrl = repository.releases
5455
val metadata = fetch(repoUrl, artifact)
55-
val versions = metadata.versioning.versions
56-
val versionExists = versions.contains(version)
56+
val versions = metadata?.versioning?.versions
57+
val versionExists = versions?.contains(version) ?: false
5758
if (versionExists) {
5859
throw GradleException("""
5960
Version `$version` is already published to maven repository `$repoUrl`.
6061
Try incrementing the library version.
61-
All available versions are: ${versions.joinToString(separator = ", ")}.
62+
All available versions are: ${versions?.joinToString(separator = ", ")}.
6263
6364
To disable this check, run Gradle with `-x $name`.
6465
""".trimIndent()
6566
)
6667
}
6768
}
6869

69-
private fun fetch(repository: String, artifact: String): MavenMetadata {
70+
private fun fetch(repository: String, artifact: String): MavenMetadata? {
7071
val url = URL("$repository/$artifact")
7172
return MavenMetadata.fetchAndParse(url)
7273
}
@@ -94,9 +95,19 @@ private data class MavenMetadata(var versioning: Versioning = Versioning()) {
9495
mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
9596
}
9697

97-
fun fetchAndParse(url: URL): MavenMetadata {
98-
val metadata = mapper.readValue(url, MavenMetadata::class.java)
99-
return metadata
98+
/**
99+
* Fetches the metadata for the repository and parses the document.
100+
*
101+
* <p>If the document could not be found, assumes that the module was never
102+
* released and thus has no metadata.
103+
*/
104+
fun fetchAndParse(url: URL): MavenMetadata? {
105+
return try {
106+
val metadata = mapper.readValue(url, MavenMetadata::class.java)
107+
metadata
108+
} catch (e: FileNotFoundException) {
109+
null
110+
}
100111
}
101112
}
102113
}

0 commit comments

Comments
 (0)