Skip to content

Commit 6be47a8

Browse files
Query State Preview API implementation.
Signed-off-by: Mukundan Sundararajan <[email protected]>
1 parent 4c077e1 commit 6be47a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2285
-155
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
matrix:
2121
java: [ 11, 13, 15, 16 ]
2222
env:
23-
GOVER: 1.15.0
23+
GOVER: 1.17.7
2424
GOOS: linux
2525
GOARCH: amd64
2626
GOPROXY: https://proxy.golang.org
@@ -29,7 +29,7 @@ jobs:
2929
DAPR_RUNTIME_VER: 1.6.0-rc.2
3030
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.6.0-rc.1/install/install.sh
3131
DAPR_CLI_REF:
32-
DAPR_REF:
32+
DAPR_REF: 69b8536b8a4b09c981822d8332068bf29a3866d5
3333
steps:
3434
- uses: actions/checkout@v2
3535
- name: Set up OpenJDK ${{ env.JDK_VER }}
@@ -91,6 +91,10 @@ jobs:
9191
run: |
9292
docker-compose -f ./sdk-tests/deploy/local-test-vault.yml up -d
9393
docker ps
94+
- name: Install Local mongo database using docker-compose
95+
run: |
96+
docker-compose -f ./sdk-tests/deploy/local-test-mongo.yml up -d
97+
docker ps
9498
- name: Clean up files
9599
run: mvn clean
96100
- name: Build sdk

.github/workflows/validate.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
matrix:
3232
java: [ 11, 13, 15, 16 ]
3333
env:
34-
GOVER: 1.15.0
34+
GOVER: 1.17.7
3535
GOOS: linux
3636
GOARCH: amd64
3737
GOPROXY: https://proxy.golang.org
@@ -40,7 +40,7 @@ jobs:
4040
DAPR_RUNTIME_VER: 1.6.0-rc.2
4141
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.6.0-rc.1/install/install.sh
4242
DAPR_CLI_REF:
43-
DAPR_REF:
43+
DAPR_REF: 69b8536b8a4b09c981822d8332068bf29a3866d5
4444
steps:
4545
- uses: actions/checkout@v2
4646
- name: Set up OpenJDK ${{ env.JDK_VER }}
@@ -108,6 +108,10 @@ jobs:
108108
sudo apt-get install vault
109109
# Verify vault is installed
110110
vault -h
111+
- name: Install Local mongo database using docker-compose
112+
run: |
113+
docker-compose -f ./sdk-tests/deploy/local-test-mongo.yml up -d
114+
docker ps
111115
- name: Clean up files
112116
run: mvn clean
113117
- name: Build sdk
@@ -153,4 +157,8 @@ jobs:
153157
- name: Validate Configuration API example
154158
working-directory: ./examples
155159
run: |
156-
mm.py ./src/main/java/io/dapr/examples/configuration/grpc/README.md
160+
mm.py ./src/main/java/io/dapr/examples/configuration/grpc/README.md
161+
- name: Validate query state HTTP example
162+
working-directory: ./examples
163+
run: |
164+
mm.py ./src/main/java/io/dapr/examples/querystate/README.md
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: mongo-statestore
5+
spec:
6+
type: state.mongodb
7+
version: v1
8+
metadata:
9+
- name: host
10+
value: localhost:27017
11+
- name: databaseName
12+
value: local
13+
- name: collectionName
14+
value: testCollection

examples/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<dependency>
6262
<groupId>com.github.os72</groupId>
6363
<artifactId>protoc-jar-maven-plugin</artifactId>
64-
<version>3.10.1</version>
64+
<version>3.11.4</version>
6565
</dependency>
6666
<dependency>
6767
<groupId>org.springframework.boot</groupId>
@@ -130,7 +130,7 @@
130130
<plugin>
131131
<groupId>com.github.os72</groupId>
132132
<artifactId>protoc-jar-maven-plugin</artifactId>
133-
<version>3.10.1</version>
133+
<version>3.11.4</version>
134134
<executions>
135135
<execution>
136136
<phase>generate-sources</phase>
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright 2021 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.examples.querystate;
15+
16+
import io.dapr.client.DaprClient;
17+
import io.dapr.client.DaprClientBuilder;
18+
import io.dapr.client.DaprPreviewClient;
19+
import io.dapr.client.domain.QueryStateItem;
20+
import io.dapr.client.domain.QueryStateRequest;
21+
import io.dapr.client.domain.QueryStateResponse;
22+
import io.dapr.client.domain.State;
23+
import io.dapr.client.domain.TransactionalStateOperation;
24+
import io.dapr.client.domain.query.Query;
25+
import io.dapr.client.domain.query.Sorting;
26+
import io.dapr.client.domain.query.filters.EqFilter;
27+
import io.dapr.exceptions.DaprException;
28+
import io.grpc.Status;
29+
import reactor.core.publisher.Mono;
30+
31+
import java.util.ArrayList;
32+
import java.util.Arrays;
33+
import java.util.List;
34+
import java.util.Objects;
35+
36+
/**
37+
* 1. Build and install jars:
38+
* mvn clean install
39+
* 2. cd [repo root]/examples
40+
* 3. send a message to be saved as state:
41+
* dapr run --components-path ./components/state -- \
42+
* java -Ddapr.api.protocol=HTTP -jar target/dapr-java-sdk-examples-exec.jar \
43+
* io.dapr.examples.querystate.QuerySavedState 'my message'
44+
*/
45+
public class QuerySavedState {
46+
47+
public static class MyData {
48+
49+
/// Gets or sets the value for PropertyA.
50+
private String propertyA;
51+
52+
/// Gets or sets the value for PropertyB.
53+
private String propertyB;
54+
55+
public String getPropertyB() {
56+
return propertyB;
57+
}
58+
59+
public void setPropertyB(String propertyB) {
60+
this.propertyB = propertyB;
61+
}
62+
63+
public String getPropertyA() {
64+
return propertyA;
65+
}
66+
67+
public void setPropertyA(String propertyA) {
68+
this.propertyA = propertyA;
69+
}
70+
71+
@Override
72+
public String toString() {
73+
return "MyData{"
74+
+ "propertyA='" + propertyA + '\''
75+
+ ", propertyB='" + propertyB + '\'' + '}';
76+
}
77+
78+
@Override
79+
public boolean equals(Object o) {
80+
if (this == o) {
81+
return true;
82+
}
83+
if (o == null || getClass() != o.getClass()) {
84+
return false;
85+
}
86+
MyData myData = (MyData) o;
87+
return Objects.equals(propertyA, myData.propertyA)
88+
&& Objects.equals(propertyB, myData.propertyB);
89+
}
90+
91+
@Override
92+
public int hashCode() {
93+
return Objects.hash(propertyA, propertyB);
94+
}
95+
}
96+
97+
private static final String STATE_STORE_NAME = "mongo-statestore";
98+
99+
private static final String FIRST_KEY_NAME = "key1";
100+
101+
private static final String SECOND_KEY_NAME = "key2";
102+
103+
private static final String THIRD_KEY_NAME = "key3";
104+
105+
/**
106+
* Executes the sate actions.
107+
* @param args messages to be sent as state value.
108+
*/
109+
public static void main(String[] args) throws Exception {
110+
DaprClientBuilder builder = new DaprClientBuilder();
111+
try (DaprClient client = builder.build(); DaprPreviewClient previewClient = builder.buildPreviewClient()) {
112+
System.out.println("Waiting for Dapr sidecar ...");
113+
client.waitForSidecar(10000).block();
114+
System.out.println("Dapr sidecar is ready.");
115+
116+
String searchVal = args.length == 0 ? "searchValue" : args[0];
117+
118+
MyData dataQueried = new MyData();
119+
dataQueried.setPropertyA(searchVal);
120+
dataQueried.setPropertyB("query");
121+
MyData dataNotQueried = new MyData();
122+
dataNotQueried.setPropertyA("no query");
123+
dataNotQueried.setPropertyB("no query");
124+
125+
126+
System.out.println("Insert key: " + FIRST_KEY_NAME + ", data: " + dataQueried);
127+
client.saveState(STATE_STORE_NAME, FIRST_KEY_NAME, dataQueried).block();
128+
System.out.println("Insert key: " + SECOND_KEY_NAME + ", data: " + dataQueried);
129+
client.saveState(STATE_STORE_NAME, SECOND_KEY_NAME, dataQueried).block();
130+
System.out.println("Insert key: " + THIRD_KEY_NAME + ", data: " + dataNotQueried);
131+
client.saveState(STATE_STORE_NAME, THIRD_KEY_NAME, dataNotQueried).block();
132+
Query query = new Query().setFilter(new EqFilter<>("propertyA", searchVal))
133+
.setSort(Arrays.asList(new Sorting("propertyB", Sorting.Order.ASC)));
134+
135+
QueryStateRequest request = new QueryStateRequest(STATE_STORE_NAME)
136+
.setQuery(query);
137+
138+
139+
QueryStateResponse<MyData> result = previewClient.queryState(request, MyData.class).block();
140+
141+
System.out.println("Found " + result.getResults().size() + " items.");
142+
for (QueryStateItem<MyData> item : result.getResults()) {
143+
System.out.println("Key: " + item.getKey());
144+
System.out.println("Data: " + item.getValue());
145+
}
146+
147+
// This is an example, so for simplicity we are just exiting here.
148+
// Normally a dapr app would be a web service and not exit main.
149+
System.out.println("Done");
150+
System.exit(0);
151+
}
152+
}
153+
}

0 commit comments

Comments
 (0)