Skip to content

Commit a7d671c

Browse files
authored
Merge pull request #76 from conductor-oss/feature/schema-client
Added a SchemaClient for API operations to with schemas (/api/schema).
2 parents 023ee79 + 67917b5 commit a7d671c

File tree

8 files changed

+379
-0
lines changed

8 files changed

+379
-0
lines changed

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
# allow this workflow to update the status of the PR that triggered it
1010
permissions:
1111
statuses: write
12+
checks: write
1213

1314
jobs:
1415
integration-tests:

conductor-client/src/main/java/io/orkes/conductor/client/OrkesClients.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ public PromptClient getPromptClient() {
7171
public EnvironmentClient getEnvironmentClient() {
7272
return new OrkesEnvironmentClient(client);
7373
}
74+
75+
public OrkesSchemaClient getSchemaClient() {
76+
return new OrkesSchemaClient(client);
77+
}
7478
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2022 Conductor Authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package io.orkes.conductor.client;
14+
15+
import java.util.List;
16+
17+
import com.netflix.conductor.common.metadata.SchemaDef;
18+
19+
public interface SchemaClient {
20+
21+
void saveSchema(SchemaDef schemaDef);
22+
23+
void saveSchemas(List<SchemaDef> schemaDefs);
24+
25+
List<SchemaDef> getAllSchemas(Boolean shortFormat);
26+
27+
SchemaDef getSchema(String name);
28+
29+
SchemaDef getSchema(String name, int version);
30+
31+
void deleteSchema(String name);
32+
33+
void deleteSchema(String name, int version);
34+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2022 Conductor Authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package io.orkes.conductor.client.http;
14+
15+
import java.util.List;
16+
17+
import com.netflix.conductor.client.http.ConductorClient;
18+
import com.netflix.conductor.common.metadata.SchemaDef;
19+
20+
import io.orkes.conductor.client.SchemaClient;
21+
22+
public class OrkesSchemaClient implements SchemaClient {
23+
24+
private final SchemaResource schemaResource;
25+
26+
public OrkesSchemaClient(ConductorClient client) {
27+
this.schemaResource = new SchemaResource(client);
28+
}
29+
30+
@Override
31+
public void saveSchema(SchemaDef schemaDef) {
32+
schemaResource.saveSchemas(List.of(schemaDef));
33+
}
34+
35+
@Override
36+
public void saveSchemas(List<SchemaDef> schemaDefs) {
37+
schemaResource.saveSchemas(schemaDefs);
38+
}
39+
40+
@Override
41+
public List<SchemaDef> getAllSchemas(Boolean shortFormat) {
42+
return schemaResource.getAllSchemas(shortFormat);
43+
}
44+
45+
@Override
46+
public SchemaDef getSchema(String name) {
47+
return schemaResource.getSchema(name);
48+
}
49+
50+
@Override
51+
public SchemaDef getSchema(String name, int version) {
52+
return schemaResource.getSchema(name, version);
53+
}
54+
55+
@Override
56+
public void deleteSchema(String name) {
57+
schemaResource.deleteSchema(name);
58+
}
59+
60+
@Override
61+
public void deleteSchema(String name, int version) {
62+
schemaResource.deleteSchema(name, version);
63+
}
64+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2022 Conductor Authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package io.orkes.conductor.client.http;
14+
15+
import java.util.List;
16+
17+
import com.netflix.conductor.client.http.ConductorClient;
18+
import com.netflix.conductor.client.http.ConductorClientRequest;
19+
import com.netflix.conductor.client.http.ConductorClientRequest.Method;
20+
import com.netflix.conductor.client.http.ConductorClientResponse;
21+
import com.netflix.conductor.common.metadata.SchemaDef;
22+
23+
import com.fasterxml.jackson.core.type.TypeReference;
24+
25+
class SchemaResource {
26+
27+
private final ConductorClient client;
28+
29+
SchemaResource(ConductorClient client) {
30+
this.client = client;
31+
}
32+
33+
void saveSchemas(List<SchemaDef> schemaDefs) {
34+
ConductorClientRequest request = ConductorClientRequest.builder()
35+
.method(Method.POST)
36+
.path("/schema")
37+
.body(schemaDefs)
38+
.build();
39+
client.execute(request);
40+
}
41+
42+
List<SchemaDef> getAllSchemas(Boolean shortFormat) {
43+
ConductorClientRequest request = ConductorClientRequest.builder()
44+
.method(Method.GET)
45+
.path("/schema")
46+
.addQueryParam("short", shortFormat)
47+
.build();
48+
ConductorClientResponse<List<SchemaDef>> resp = client.execute(request, new TypeReference<>() {});
49+
return resp.getData();
50+
}
51+
52+
SchemaDef getSchema(String name) {
53+
ConductorClientRequest request = ConductorClientRequest.builder()
54+
.method(Method.GET)
55+
.path("/schema/{name}")
56+
.addPathParam("name", name)
57+
.build();
58+
ConductorClientResponse<SchemaDef> resp = client.execute(request, new TypeReference<>() {});
59+
return resp.getData();
60+
}
61+
62+
SchemaDef getSchema(String name, int version) {
63+
ConductorClientRequest request = ConductorClientRequest.builder()
64+
.method(Method.GET)
65+
.path("/schema/{name}/{version}")
66+
.addPathParam("name", name)
67+
.addPathParam("version", version)
68+
.build();
69+
ConductorClientResponse<SchemaDef> resp = client.execute(request, new TypeReference<>() {});
70+
return resp.getData();
71+
}
72+
73+
void deleteSchema(String name) {
74+
ConductorClientRequest request = ConductorClientRequest.builder()
75+
.method(Method.DELETE)
76+
.path("/schema/{name}")
77+
.addPathParam("name", name)
78+
.build();
79+
client.execute(request);
80+
}
81+
82+
void deleteSchema(String name, int version) {
83+
ConductorClientRequest request = ConductorClientRequest.builder()
84+
.method(Method.DELETE)
85+
.path("/schema/{name}/{version}")
86+
.addPathParam("name", name)
87+
.addPathParam("version", version)
88+
.build();
89+
client.execute(request);
90+
}
91+
}

docs/SchemaClient.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# SchemaClient
2+
3+
The `SchemaClient` provides operations to manage schemas in Conductor. Schemas define the structure of workflow inputs, outputs, and task data using JSON Schema, Avro, or Protobuf formats.
4+
5+
## Setup
6+
7+
```java
8+
import com.netflix.conductor.client.http.ConductorClient;
9+
import io.orkes.conductor.client.OrkesClients;
10+
import io.orkes.conductor.client.SchemaClient;
11+
12+
ConductorClient client = new ConductorClient("https://your-conductor-server/api");
13+
OrkesClients orkesClients = new OrkesClients(client);
14+
SchemaClient schemaClient = orkesClients.getSchemaClient();
15+
```
16+
17+
## Save a Schema
18+
19+
```java
20+
import com.netflix.conductor.common.metadata.SchemaDef;
21+
import java.util.Map;
22+
23+
SchemaDef schema = SchemaDef.builder()
24+
.name("my-schema")
25+
.version(1)
26+
.type(SchemaDef.Type.JSON)
27+
.data(Map.of(
28+
"type", "object",
29+
"properties", Map.of(
30+
"id", Map.of("type", "string"),
31+
"name", Map.of("type", "string")
32+
)
33+
))
34+
.build();
35+
36+
schemaClient.saveSchema(schema);
37+
```
38+
39+
## Save Multiple Schemas (bulk)
40+
41+
```java
42+
schemaClient.saveSchemas(List.of(schemaA, schemaB));
43+
```
44+
45+
## Get a Schema (latest version)
46+
47+
```java
48+
SchemaDef schema = schemaClient.getSchema("my-schema");
49+
```
50+
51+
## Get a Specific Version
52+
53+
```java
54+
SchemaDef schema = schemaClient.getSchema("my-schema", 2);
55+
```
56+
57+
## List All Schemas
58+
59+
```java
60+
// Full details
61+
List<SchemaDef> all = schemaClient.getAllSchemas(false);
62+
63+
// Short format (name + version only)
64+
List<SchemaDef> summary = schemaClient.getAllSchemas(true);
65+
```
66+
67+
## Delete a Schema
68+
69+
```java
70+
// Delete all versions
71+
schemaClient.deleteSchema("my-schema");
72+
73+
// Delete a specific version
74+
schemaClient.deleteSchema("my-schema", 2);
75+
```
76+
77+
## Versioning
78+
79+
Every `SchemaDef` carries an integer `version` field (default `1`). To create a new version of an existing schema, save a `SchemaDef` with the same `name` and an incremented `version`.
80+
81+
```java
82+
SchemaDef v2 = SchemaDef.builder()
83+
.name("my-schema")
84+
.version(2)
85+
.type(SchemaDef.Type.JSON)
86+
.data(updatedData)
87+
.build();
88+
89+
schemaClient.saveSchema(v2);
90+
```
91+
92+
## Schema Types
93+
94+
| Type | Description |
95+
|------|-------------|
96+
| `JSON` | JSON Schema format |
97+
| `AVRO` | Apache Avro schema |
98+
| `PROTOBUF` | Protocol Buffers schema |

tests/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies {
2222

2323
test {
2424
useJUnitPlatform()
25+
jvmArgs '-Xmx768m'
2526
finalizedBy jacocoTestReport // report is always generated after tests run
2627
testLogging {
2728
events = ["SKIPPED", "FAILED"]

0 commit comments

Comments
 (0)