Added support for retrieving the data from a data store#29
Added support for retrieving the data from a data store#29orpiske merged 1 commit intowanaku-ai:mainfrom
Conversation
Added support for running callbacks after registration, ping and deregistration Ref: wanaku-ai/wanaku#637
Reviewer's GuideThis 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 callbackssequenceDiagram
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)
Class diagram for new and updated exception handlingclassDiagram
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()
Class diagram for DataStore CRUD in ServicesHttpClientclassDiagram
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
Class diagram for DiscoveryCallback integration in ZeroDepRegistrationManagerclassDiagram
class ZeroDepRegistrationManager {
-List<DiscoveryCallback> callbacks
+void addCallBack(DiscoveryCallback callback)
+void runCallBack(Consumer<DiscoveryCallback> registrationManagerConsumer)
}
ZeroDepRegistrationManager --> DiscoveryCallback
ZeroDepRegistrationManager --> DiscoveryLogCallback
DiscoveryLogCallback ..|> DiscoveryCallback
Class diagram for DiscoveryLogCallbackclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>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>>() {}); |
There was a problem hiding this comment.
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>>>() {}); |
There was a problem hiding this comment.
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>>>() {});
}| public void removeDataStore(String id) { | ||
| executeDelete("/api/v1/data-store/remove?id=" + id); | ||
| } |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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);| @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"); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| @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); | |
| } | |
| } |
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:
Enhancements: