Skip to content

Added support for retrieving the data from a data store#29

Merged
orpiske merged 1 commit intowanaku-ai:mainfrom
orpiske:ci-issue-637-add-data-store
Nov 20, 2025
Merged

Added support for retrieving the data from a data store#29
orpiske merged 1 commit intowanaku-ai:mainfrom
orpiske:ci-issue-637-add-data-store

Conversation

@orpiske
Copy link
Copy Markdown
Contributor

@orpiske orpiske commented Nov 20, 2025

Added support for running callbacks after registration, ping and deregistration

Ref: wanaku-ai/wanaku#637

Summary by Sourcery

Add DataStore API operations and callback support in discovery registration while refining HTTP error handling.

New Features:

  • Add DataStore CRUD methods to ServicesHttpClient for managing data store entries.
  • Implement callback mechanism in ZeroDepRegistrationManager to invoke DiscoveryCallback on registration, ping, and deregistration.
  • Provide DiscoveryLogCallback as a default callback implementation for logging discovery events.

Enhancements:

  • Introduce WanakuWebException for HTTP errors to include status codes and replace generic WanakuException in HTTP client methods.

Added support for running callbacks after registration, ping and deregistration

Ref: wanaku-ai/wanaku#637
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Nov 20, 2025

Reviewer's Guide

This PR extends HTTP client error handling with a new status-aware exception, adds full DataStore CRUD endpoints in ServicesHttpClient, and enhances the discovery registration manager with a pluggable callback mechanism (including a default DiscoveryLogCallback) for registration, ping, and deregistration events.

Sequence diagram for registration, ping, and deregistration callbacks

sequenceDiagram
participant "ZeroDepRegistrationManager"
participant "DiscoveryCallback"
participant "ServiceTarget"

"ZeroDepRegistrationManager"->>"ServiceTarget": register()
"ZeroDepRegistrationManager"->>"DiscoveryCallback": onRegistration(manager, target)

"ZeroDepRegistrationManager"->>"ServiceTarget": ping()
"ZeroDepRegistrationManager"->>"DiscoveryCallback": onPing(manager, target, status)

"ZeroDepRegistrationManager"->>"ServiceTarget": deregister()
"ZeroDepRegistrationManager"->>"DiscoveryCallback": onDeregistration(manager, target, status)
Loading

Class diagram for new and updated exception handling

classDiagram
WanakuException <|-- WanakuWebException
WanakuWebException : - int statusCode
WanakuWebException : +WanakuWebException(int statusCode)
WanakuWebException : +WanakuWebException(String message, int statusCode)
WanakuWebException : +WanakuWebException(String message, Throwable cause, int statusCode)
WanakuWebException : +WanakuWebException(Throwable cause, int statusCode)
WanakuWebException : +WanakuWebException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, int statusCode)
WanakuWebException : +int getStatusCode()
Loading

Class diagram for DataStore CRUD in ServicesHttpClient

classDiagram
class ServicesHttpClient {
  +WanakuResponse<DataStore> addDataStore(DataStore dataStore)
  +WanakuResponse<List<DataStore>> listDataStores()
  +WanakuResponse<DataStore> getDataStoreById(String id)
  +WanakuResponse<List<DataStore>> getDataStoresByName(String name)
  +void removeDataStore(String id)
  +void removeDataStoresByName(String name)
}
ServicesHttpClient --> DataStore
Loading

Class diagram for DiscoveryCallback integration in ZeroDepRegistrationManager

classDiagram
class ZeroDepRegistrationManager {
  -List<DiscoveryCallback> callbacks
  +void addCallBack(DiscoveryCallback callback)
  +void runCallBack(Consumer<DiscoveryCallback> registrationManagerConsumer)
}
ZeroDepRegistrationManager --> DiscoveryCallback
ZeroDepRegistrationManager --> DiscoveryLogCallback
DiscoveryLogCallback ..|> DiscoveryCallback
Loading

Class diagram for DiscoveryLogCallback

classDiagram
class DiscoveryLogCallback {
  +void onPing(RegistrationManager manager, ServiceTarget target, int status)
  +void onRegistration(RegistrationManager manager, ServiceTarget target)
  +void onDeregistration(RegistrationManager manager, ServiceTarget target, int status)
}
DiscoveryLogCallback ..|> DiscoveryCallback
Loading

File-Level Changes

Change Details Files
Use WanakuWebException for HTTP error handling
  • Replace throw in executePost with WanakuWebException including status code
  • Replace throw in executePut with WanakuWebException including status code
  • Replace throw in executeGet with WanakuWebException including status code
  • Introduce WanakuWebException class capturing HTTP status codes
capabilities-services-client/src/main/java/ai/wanaku/capabilities/sdk/services/ServicesHttpClient.java
capabilities-common/src/main/java/ai/wanaku/capabilities/sdk/common/exceptions/WanakuWebException.java
Add DataStore CRUD API methods
  • Add addDataStore, listDataStores, getDataStoreById, getDataStoresByName methods
  • Add removeDataStore and removeDataStoresByName methods
capabilities-services-client/src/main/java/ai/wanaku/capabilities/sdk/services/ServicesHttpClient.java
Introduce callback mechanism in ZeroDepRegistrationManager
  • Add callbacks list field and addCallBack method
  • Register default DiscoveryLogCallback in constructor
  • Replace inline logs in tryRegistering, ping, and tryDeregistering with runCallBack calls
  • Implement runCallBack helper to invoke callbacks safely
capabilities-discovery/src/main/java/ai/wanaku/capabilities/sdk/discovery/ZeroDepRegistrationManager.java
Add default DiscoveryLogCallback implementation
  • Implement DiscoveryCallback for logging ping, registration, and deregistration statuses
capabilities-discovery/src/main/java/ai/wanaku/capabilities/sdk/discovery/DiscoveryLogCallback.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `capabilities-services-client/src/main/java/ai/wanaku/capabilities/sdk/services/ServicesHttpClient.java:408` </location>
<code_context>
+     * @throws WanakuException If an error occurs during the request.
+     */
+    public WanakuResponse<DataStore> getDataStoreById(String id) {
+        return executeGet("/api/v1/data-store/get?id=" + id, new TypeReference<WanakuResponse<DataStore>>() {});
+    }
+
</code_context>

<issue_to_address>
**suggestion:** Consider URL encoding the 'id' parameter in the request.

If 'id' contains special characters, the request may fail or behave unexpectedly. Encoding the parameter will ensure correct handling.

Suggested implementation:

```java
import ai.wanaku.api.types.io.ToolPayload;
import ai.wanaku.capabilities.sdk.common.exceptions.WanakuWebException;
import ai.wanaku.capabilities.sdk.common.serializer.Serializer;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

```

```java
    public WanakuResponse<DataStore> getDataStoreById(String id) {
        String encodedId = URLEncoder.encode(id, StandardCharsets.UTF_8);
        return executeGet("/api/v1/data-store/get?id=" + encodedId, new TypeReference<WanakuResponse<DataStore>>() {});
    }

```
</issue_to_address>

### Comment 2
<location> `capabilities-services-client/src/main/java/ai/wanaku/capabilities/sdk/services/ServicesHttpClient.java:419` </location>
<code_context>
+     * @throws WanakuException If an error occurs during the request.
+     */
+    public WanakuResponse<List<DataStore>> getDataStoresByName(String name) {
+        return executeGet("/api/v1/data-store/get?name=" + name, new TypeReference<WanakuResponse<List<DataStore>>>() {});
+    }
+
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Consider URL encoding the 'name' parameter in the request.

Encoding ensures the request works correctly with names containing spaces or special characters.

Suggested implementation:

```java
import ai.wanaku.api.exceptions.WanakuException;
import ai.wanaku.api.types.DataStore;
import ai.wanaku.api.types.ForwardReference;
import ai.wanaku.api.types.Namespace;
import ai.wanaku.api.types.ResourceReference;
import ai.wanaku.api.types.WanakuResponse;
import ai.wanaku.api.types.io.ResourcePayload;
import ai.wanaku.api.types.io.ToolPayload;
import ai.wanaku.capabilities.sdk.common.exceptions.WanakuWebException;
import ai.wanaku.capabilities.sdk.common.serializer.Serializer;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

```

```java
    public WanakuResponse<List<DataStore>> getDataStoresByName(String name) {
        String encodedName = URLEncoder.encode(name, StandardCharsets.UTF_8);
        return executeGet("/api/v1/data-store/get?name=" + encodedName, new TypeReference<WanakuResponse<List<DataStore>>>() {});
    }

```
</issue_to_address>

### Comment 3
<location> `capabilities-services-client/src/main/java/ai/wanaku/capabilities/sdk/services/ServicesHttpClient.java:428-430` </location>
<code_context>
+     * @throws WanakuException If an error occurs during the request.
+     */
+    public void removeDataStore(String id) {
+        executeDelete("/api/v1/data-store/remove?id=" + id);
+    }
+
</code_context>

<issue_to_address>
**suggestion (bug_risk):** URL encoding should be applied to the 'id' parameter in delete requests.

Encode the 'id' value before constructing the URL to ensure correct handling of special characters.

```suggestion
    public void removeDataStore(String id) {
        try {
            String encodedId = java.net.URLEncoder.encode(id, java.nio.charset.StandardCharsets.UTF_8.toString());
            executeDelete("/api/v1/data-store/remove?id=" + encodedId);
        } catch (java.io.UnsupportedEncodingException e) {
            throw new WanakuException("Failed to encode id parameter", e);
        }
    }
```
</issue_to_address>

### Comment 4
<location> `capabilities-services-client/src/main/java/ai/wanaku/capabilities/sdk/services/ServicesHttpClient.java:439` </location>
<code_context>
+     * @throws WanakuException If an error occurs during the request.
+     */
+    public void removeDataStoresByName(String name) {
+        executeDelete("/api/v1/data-store/remove?name=" + name);
+    }
 }
</code_context>

<issue_to_address>
**suggestion (bug_risk):** URL encoding should be applied to the 'name' parameter in delete requests.

This ensures the API correctly handles names containing spaces or special characters.

Suggested implementation:

```java
    public void removeDataStoresByName(String name) {

```

```java
        String encodedName = java.net.URLEncoder.encode(name, java.nio.charset.StandardCharsets.UTF_8);
        executeDelete("/api/v1/data-store/remove?name=" + encodedName);

```
</issue_to_address>

### Comment 5
<location> `capabilities-discovery/src/main/java/ai/wanaku/capabilities/sdk/discovery/DiscoveryLogCallback.java:12-19` </location>
<code_context>
+
+    @Override
+    public void onPing(RegistrationManager manager, ServiceTarget target, int status) {
+        if (status != 200) {
+            LOG.warn("Pinging router failed with status {}", status);
+        } else {
+            LOG.trace("Pinging router completed successfully");
+        }
</code_context>

<issue_to_address>
**suggestion:** Consider supporting additional HTTP status codes for success.

Some APIs indicate success with status codes like 201 or 204. Checking for status codes in the 2xx range will ensure all successful responses are handled.

```suggestion
    @Override
    public void onPing(RegistrationManager manager, ServiceTarget target, int status) {
        if (status < 200 || status >= 300) {
            LOG.warn("Pinging router failed with status {}", status);
        } else {
            LOG.trace("Pinging router completed successfully with status {}", status);
        }
    }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

* @throws WanakuException If an error occurs during the request.
*/
public WanakuResponse<DataStore> getDataStoreById(String id) {
return executeGet("/api/v1/data-store/get?id=" + id, new TypeReference<WanakuResponse<DataStore>>() {});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider URL encoding the 'id' parameter in the request.

If 'id' contains special characters, the request may fail or behave unexpectedly. Encoding the parameter will ensure correct handling.

Suggested implementation:

import ai.wanaku.api.types.io.ToolPayload;
import ai.wanaku.capabilities.sdk.common.exceptions.WanakuWebException;
import ai.wanaku.capabilities.sdk.common.serializer.Serializer;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
    public WanakuResponse<DataStore> getDataStoreById(String id) {
        String encodedId = URLEncoder.encode(id, StandardCharsets.UTF_8);
        return executeGet("/api/v1/data-store/get?id=" + encodedId, new TypeReference<WanakuResponse<DataStore>>() {});
    }

* @throws WanakuException If an error occurs during the request.
*/
public WanakuResponse<List<DataStore>> getDataStoresByName(String name) {
return executeGet("/api/v1/data-store/get?name=" + name, new TypeReference<WanakuResponse<List<DataStore>>>() {});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Consider URL encoding the 'name' parameter in the request.

Encoding ensures the request works correctly with names containing spaces or special characters.

Suggested implementation:

import ai.wanaku.api.exceptions.WanakuException;
import ai.wanaku.api.types.DataStore;
import ai.wanaku.api.types.ForwardReference;
import ai.wanaku.api.types.Namespace;
import ai.wanaku.api.types.ResourceReference;
import ai.wanaku.api.types.WanakuResponse;
import ai.wanaku.api.types.io.ResourcePayload;
import ai.wanaku.api.types.io.ToolPayload;
import ai.wanaku.capabilities.sdk.common.exceptions.WanakuWebException;
import ai.wanaku.capabilities.sdk.common.serializer.Serializer;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
    public WanakuResponse<List<DataStore>> getDataStoresByName(String name) {
        String encodedName = URLEncoder.encode(name, StandardCharsets.UTF_8);
        return executeGet("/api/v1/data-store/get?name=" + encodedName, new TypeReference<WanakuResponse<List<DataStore>>>() {});
    }

Comment on lines +428 to +430
public void removeDataStore(String id) {
executeDelete("/api/v1/data-store/remove?id=" + id);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): URL encoding should be applied to the 'id' parameter in delete requests.

Encode the 'id' value before constructing the URL to ensure correct handling of special characters.

Suggested change
public void removeDataStore(String id) {
executeDelete("/api/v1/data-store/remove?id=" + id);
}
public void removeDataStore(String id) {
try {
String encodedId = java.net.URLEncoder.encode(id, java.nio.charset.StandardCharsets.UTF_8.toString());
executeDelete("/api/v1/data-store/remove?id=" + encodedId);
} catch (java.io.UnsupportedEncodingException e) {
throw new WanakuException("Failed to encode id parameter", e);
}
}

* @throws WanakuException If an error occurs during the request.
*/
public void removeDataStoresByName(String name) {
executeDelete("/api/v1/data-store/remove?name=" + name);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): URL encoding should be applied to the 'name' parameter in delete requests.

This ensures the API correctly handles names containing spaces or special characters.

Suggested implementation:

    public void removeDataStoresByName(String name) {
        String encodedName = java.net.URLEncoder.encode(name, java.nio.charset.StandardCharsets.UTF_8);
        executeDelete("/api/v1/data-store/remove?name=" + encodedName);

Comment on lines +12 to +19
@Override
public void onPing(RegistrationManager manager, ServiceTarget target, int status) {
if (status != 200) {
LOG.warn("Pinging router failed with status {}", status);
} else {
LOG.trace("Pinging router completed successfully");
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider supporting additional HTTP status codes for success.

Some APIs indicate success with status codes like 201 or 204. Checking for status codes in the 2xx range will ensure all successful responses are handled.

Suggested change
@Override
public void onPing(RegistrationManager manager, ServiceTarget target, int status) {
if (status != 200) {
LOG.warn("Pinging router failed with status {}", status);
} else {
LOG.trace("Pinging router completed successfully");
}
}
@Override
public void onPing(RegistrationManager manager, ServiceTarget target, int status) {
if (status < 200 || status >= 300) {
LOG.warn("Pinging router failed with status {}", status);
} else {
LOG.trace("Pinging router completed successfully with status {}", status);
}
}

@orpiske orpiske merged commit 7d46cdb into wanaku-ai:main Nov 20, 2025
9 checks passed
@orpiske orpiske deleted the ci-issue-637-add-data-store branch November 20, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant