Skip to content

Commit 0c800a1

Browse files
committed
Remove deprecated state update APIs
Ref: wanaku-ai/wanaku#847
1 parent 1b79aa3 commit 0c800a1

File tree

2 files changed

+7
-85
lines changed

2 files changed

+7
-85
lines changed

capabilities-api/src/main/java/ai/wanaku/capabilities/sdk/api/discovery/RegistrationManager.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public interface RegistrationManager {
2727
* This method is used to periodically inform the registry that the service is still active
2828
* and operational, preventing its registration from expiring due to inactivity.
2929
*/
30-
void ping();
30+
@Deprecated(forRemoval = true)
31+
default void ping() {}
3132

3233
/**
3334
* Notifies the Wanaku registration system that the last attempted operation (tool call
@@ -37,15 +38,17 @@ public interface RegistrationManager {
3738
* This information can be used for logging, debugging, or alerting purposes
3839
* by the registration system.
3940
*/
40-
void lastAsFail(String reason);
41+
@Deprecated(forRemoval = true)
42+
default void lastAsFail(String reason) {}
4143

4244
/**
4345
* Notifies the Wanaku registration system that the last attempted operation (tool call
4446
* or resource acquisition) from this service was successful.
4547
* This method can be used to update the service's status within the registry,
4648
* indicating its continued health and availability.
4749
*/
48-
void lastAsSuccessful();
50+
@Deprecated(forRemoval = true)
51+
default void lastAsSuccessful() {}
4952

5053
/**
5154
* Adds a callback to be run after some operations have executed

capabilities-discovery/src/main/java/ai/wanaku/capabilities/sdk/discovery/ZeroDepRegistrationManager.java

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import ai.wanaku.capabilities.sdk.api.discovery.RegistrationManager;
1919
import ai.wanaku.capabilities.sdk.api.exceptions.WanakuException;
2020
import ai.wanaku.capabilities.sdk.api.types.WanakuResponse;
21-
import ai.wanaku.capabilities.sdk.api.types.discovery.ServiceState;
2221
import ai.wanaku.capabilities.sdk.api.types.providers.ServiceTarget;
2322
import ai.wanaku.capabilities.sdk.data.files.InstanceDataManager;
2423
import ai.wanaku.capabilities.sdk.data.files.ServiceEntry;
@@ -175,11 +174,7 @@ private int waitAndRetry(String serviceName, Exception e, int currentRetries, in
175174
*/
176175
@Override
177176
public void register() {
178-
if (isRegistered()) {
179-
if (config.isPingEnabled()) {
180-
ping();
181-
}
182-
} else {
177+
if (!isRegistered()) {
183178
tryRegistering();
184179
}
185180
}
@@ -215,82 +210,6 @@ public void deregister() {
215210
}
216211
}
217212

218-
/**
219-
* Sends a ping to the Wanaku Discovery API to keep the service registration alive.
220-
*/
221-
@Override
222-
public void ping() {
223-
if (!config.isPingEnabled()) {
224-
return;
225-
}
226-
227-
if (target != null && target.getId() != null) {
228-
LOG.trace("Pinging router ...");
229-
try {
230-
// Assuming client.ping(target.getId()) exists and returns HttpResponse<String>
231-
final HttpResponse<String> response = client.ping(target.getId());
232-
final int status = response.statusCode();
233-
runCallBack(c -> c.onPing(this, target, status));
234-
} catch (Exception e) {
235-
if (LOG.isDebugEnabled()) {
236-
LOG.warn("Pinging router failed with {}", e.getMessage(), e);
237-
} else {
238-
LOG.warn("Pinging router failed with {}", e.getMessage());
239-
}
240-
}
241-
}
242-
}
243-
244-
/**
245-
* Updates the service's state to 'unhealthy' with a given reason.
246-
*
247-
* @param reason The reason for the service being unhealthy.
248-
*/
249-
@Override
250-
public void lastAsFail(String reason) {
251-
if (target.getId() == null) {
252-
LOG.warn("Trying to update the state of an unknown service {}", target.getServiceName());
253-
return;
254-
}
255-
256-
try {
257-
final HttpResponse<String> response = client.updateState(target.getId(), ServiceState.newUnhealthy(reason));
258-
if (response.statusCode() != 200) {
259-
LOG.error("Could not update the state of an service {} ({})", target.getServiceName(), target.getId());
260-
}
261-
} catch (Exception e) {
262-
if (LOG.isDebugEnabled()) {
263-
LOG.warn("Updating last status failed with {}", e.getMessage(), e);
264-
} else {
265-
LOG.warn("Updating last status failed with {}", e.getMessage());
266-
}
267-
}
268-
}
269-
270-
/**
271-
* Updates the service's state to 'healthy'.
272-
*/
273-
@Override
274-
public void lastAsSuccessful() {
275-
if (target.getId() == null) {
276-
LOG.warn("Trying to update the state of an unknown service {}", target.getServiceName());
277-
return;
278-
}
279-
280-
try {
281-
final HttpResponse<String> response = client.updateState(target.getId(), ServiceState.newHealthy());
282-
if (response.statusCode() != 200) {
283-
LOG.error("Could not update the state of an service {} ({})", target.getServiceName(), target.getId());
284-
}
285-
} catch (Exception e) {
286-
if (LOG.isDebugEnabled()) {
287-
LOG.warn("Updating last status failed with {}", e.getMessage(), e);
288-
} else {
289-
LOG.warn("Updating last status failed with {}", e.getMessage());
290-
}
291-
}
292-
}
293-
294213
/**
295214
* Starts the scheduled registration task, which periodically calls the {@link #register()} method.
296215
* The initial delay and period are configured via {@link RegistrationConfig}.

0 commit comments

Comments
 (0)