Skip to content

Commit 21c94f9

Browse files
committed
CM-2345: Implemented CometApi.deleteRegistryModel() and related test cases.
1 parent bac421f commit 21c94f9

File tree

7 files changed

+63
-0
lines changed

7 files changed

+63
-0
lines changed

comet-java-client/src/main/java/ml/comet/experiment/CometApi.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,12 @@ void updateRegistryModelVersion(String registryName, String workspace, String ve
157157
String comments, List<String> stages);
158158

159159
void updateRegistryModelVersion(String registryName, String workspace, String version, String comments);
160+
161+
/**
162+
* Deletes registered model with given name.
163+
*
164+
* @param registryName the name of the model.
165+
* @param workspace the name of the model's workspace.
166+
*/
167+
void deleteRegistryModel(String registryName, String workspace);
160168
}

comet-java-client/src/main/java/ml/comet/experiment/impl/CometApiImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import static ml.comet.experiment.impl.resources.LogMessages.DOWNLOADING_REGISTRY_MODEL_TO_FILE;
6868
import static ml.comet.experiment.impl.resources.LogMessages.EXPERIMENT_HAS_NO_MODELS;
6969
import static ml.comet.experiment.impl.resources.LogMessages.EXTRACTED_N_REGISTRY_MODEL_FILES;
70+
import static ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_DELETE_REGISTRY_MODEL;
7071
import static ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_DOWNLOAD_REGISTRY_MODEL;
7172
import static ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_FIND_EXPERIMENT_MODEL_BY_NAME;
7273
import static ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_GET_REGISTRY_MODEL_DETAILS;
@@ -424,6 +425,13 @@ public void updateRegistryModelVersion(String registryName, String workspace, St
424425
this.updateRegistryModelVersion(registryName, workspace, version, null, null);
425426
}
426427

428+
@Override
429+
public void deleteRegistryModel(String registryName, String workspace) {
430+
RestApiResponse response = this.restApiClient.deleteRegistryModel(registryName, workspace)
431+
.blockingGet();
432+
this.checkRestApiResponse(response, getString(FAILED_TO_DELETE_REGISTRY_MODEL, registryName, workspace));
433+
}
434+
427435
/**
428436
* Release all resources hold by this instance, such as connection to the Comet server.
429437
*

comet-java-client/src/main/java/ml/comet/experiment/impl/RestApiClient.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import static ml.comet.experiment.impl.constants.ApiEndpoints.ADD_TAG;
7878
import static ml.comet.experiment.impl.constants.ApiEndpoints.CREATE_REGISTRY_MODEL;
7979
import static ml.comet.experiment.impl.constants.ApiEndpoints.CREATE_REGISTRY_MODEL_ITEM;
80+
import static ml.comet.experiment.impl.constants.ApiEndpoints.DELETE_REGISTRY_MODEL;
8081
import static ml.comet.experiment.impl.constants.ApiEndpoints.DOWNLOAD_REGISTRY_MODEL;
8182
import static ml.comet.experiment.impl.constants.ApiEndpoints.EXPERIMENTS;
8283
import static ml.comet.experiment.impl.constants.ApiEndpoints.GET_ARTIFACT_VERSION_DETAIL;
@@ -385,6 +386,13 @@ Single<RestApiResponse> updateRegistryModelVersion(RegistryModelUpdateItemReques
385386
return singleFromAsyncPost(request, UPDATE_REGISTRY_MODEL_VERSION);
386387
}
387388

389+
Single<RestApiResponse> deleteRegistryModel(String modelName, String workspaceName) {
390+
Map<QueryParamName, String> queryParams = new HashMap<>();
391+
queryParams.put(WORKSPACE_NAME, workspaceName);
392+
queryParams.put(MODEL_NAME, modelName);
393+
return singleFromSyncGetWithRetries(DELETE_REGISTRY_MODEL, queryParams);
394+
}
395+
388396
private Single<RestApiResponse> singleFromAsyncDownload(@NonNull OutputStream output,
389397
@NonNull String endpoint,
390398
@NonNull Map<QueryParamName, String> queryParams) {
@@ -492,6 +500,14 @@ private Single<RestApiResponse> singleFromSyncPostWithRetriesEmptyBody(@NonNull
492500
String.format("No response was returned by endpoint: %s", endpoint))));
493501
}
494502

503+
private Single<RestApiResponse> singleFromSyncGetWithRetries(@NonNull String endpoint,
504+
@NonNull Map<QueryParamName, String> params) {
505+
return this.connection.sendGetWithRetries(endpoint, params, true)
506+
.map(body -> Single.just(new RestApiResponse(200, body)))
507+
.orElse(Single.error(new CometApiException(
508+
String.format("No response was returned by endpoint: %s", endpoint))));
509+
}
510+
495511
private <T> Single<T> singleFromSyncGetWithRetries(@NonNull String endpoint,
496512
@NonNull String experimentKey,
497513
@NonNull Class<T> clazz) {

comet-java-client/src/main/java/ml/comet/experiment/impl/constants/ApiEndpoints.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public final class ApiEndpoints {
2828
public static final String UPDATE_REGISTRY_MODEL_NOTES = UPDATE_API_URL + "/registry-model/notes";
2929
public static final String UPDATE_REGISTRY_MODEL = UPDATE_API_URL + "/registry-model/update";
3030
public static final String UPDATE_REGISTRY_MODEL_VERSION = UPDATE_API_URL + "/registry-model/item/update";
31+
public static final String DELETE_REGISTRY_MODEL = UPDATE_API_URL + "/registry-model/delete";
3132

3233
public static final String READ_API_URL = "/api/rest/v2";
3334
public static final String GET_ASSETS_LIST = READ_API_URL + "/experiment/asset/list";

comet-java-client/src/main/java/ml/comet/experiment/impl/resources/LogMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class LogMessages {
9797
public static final String FAILED_TO_UPDATE_REGISTRY_MODEL = "FAILED_TO_UPDATE_REGISTRY_MODEL";
9898
public static final String FAILED_TO_UPDATE_REGISTRY_MODEL_VERSION = "FAILED_TO_UPDATE_REGISTRY_MODEL_VERSION";
9999
public static final String REGISTRY_MODEL_VERSION_NOT_FOUND = "REGISTRY_MODEL_VERSION_NOT_FOUND";
100+
public static final String FAILED_TO_DELETE_REGISTRY_MODEL = "FAILED_TO_DELETE_REGISTRY_MODEL";
100101

101102

102103
/**

comet-java-client/src/main/resources/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ FAILED_TO_UPDATE_REGISTRY_MODEL_NOTES=Failed to update notes of the registry mod
8282
FAILED_TO_UPDATE_REGISTRY_MODEL=Failed to update registry model '%s/%s' with data: '%s'.
8383
FAILED_TO_UPDATE_REGISTRY_MODEL_VERSION=Failed to update registry model's version '%s/%s:%s' with data: '%s'.
8484
REGISTRY_MODEL_VERSION_NOT_FOUND=Version '%s' of the registry model '%s/%s' is not found.
85+
FAILED_TO_DELETE_REGISTRY_MODEL=Failed to delete registry model '%s/%s'.

comet-java-client/src/test/java/ml/comet/experiment/impl/CometApiTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,34 @@ public void testUpdateRegistryModelVersion() {
550550
assertEquals(stages, versionOverview.getStages(), "wrong stages");
551551
}
552552

553+
@Test
554+
public void testDeleteRegistryModel() {
555+
String modelName = String.format("%s-%d", SOME_MODEL_NAME, System.currentTimeMillis());
556+
557+
// register model with defaults
558+
//
559+
registerModelWithDefaults(modelName);
560+
561+
// wait for registry model to be processed by backend
562+
//
563+
Awaitility.await("failed to get registry model")
564+
.pollInterval(1, TimeUnit.SECONDS)
565+
.atMost(60, TimeUnit.SECONDS)
566+
.until(() -> COMET_API.getRegistryModelDetails(modelName,
567+
SHARED_EXPERIMENT.getWorkspaceName()).isPresent());
568+
569+
// try to delete the model
570+
//
571+
COMET_API.deleteRegistryModel(modelName, SHARED_EXPERIMENT.getWorkspaceName());
572+
}
573+
574+
@Test
575+
public void testDeleteRegistryModel_doesnt_exists() {
576+
String modelName = "not existing model";
577+
assertThrows(CometApiException.class, () ->
578+
COMET_API.deleteRegistryModel(modelName, SHARED_EXPERIMENT.getWorkspaceName()));
579+
}
580+
553581
private static String registerModelWithDefaults(String modelName) {
554582
// log model folder
555583
//

0 commit comments

Comments
 (0)