Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Implement experiment run name update functionality #4098

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,120 +1,31 @@
package ai.verta.modeldb.experimentRun;

import ai.verta.common.Artifact;
import ai.verta.common.CodeVersion;
import ai.verta.common.KeyValue;
import ai.verta.common.KeyValueQuery;
import ai.verta.common.*;
import ai.verta.common.ModelDBResourceEnum.ModelDBServiceResourceTypes;
import ai.verta.common.OperatorEnum;
import ai.verta.common.Pagination;
import ai.verta.common.ValueTypeEnum;
import ai.verta.modeldb.AddExperimentRunTags;
import ai.verta.modeldb.CloneExperimentRun;
import ai.verta.modeldb.CommitArtifactPart;
import ai.verta.modeldb.CommitMultipartArtifact;
import ai.verta.modeldb.CreateExperimentRun;
import ai.verta.modeldb.DeleteArtifact;
import ai.verta.modeldb.DeleteExperimentRunAttributes;
import ai.verta.modeldb.DeleteExperimentRunTags;
import ai.verta.modeldb.DeleteExperimentRuns;
import ai.verta.modeldb.DeleteHyperparameters;
import ai.verta.modeldb.DeleteMetrics;
import ai.verta.modeldb.DeleteObservations;
import ai.verta.modeldb.ExperimentRun;
import ai.verta.modeldb.*;
import ai.verta.modeldb.ExperimentRun.Builder;
import ai.verta.modeldb.Feature;
import ai.verta.modeldb.FindExperimentRuns;
import ai.verta.modeldb.GetArtifacts;
import ai.verta.modeldb.GetAttributes;
import ai.verta.modeldb.GetCommittedArtifactParts;
import ai.verta.modeldb.GetDatasets;
import ai.verta.modeldb.GetExperimentRunCodeVersion;
import ai.verta.modeldb.GetExperimentRunsByDatasetVersionId;
import ai.verta.modeldb.GetExperimentRunsInExperiment;
import ai.verta.modeldb.GetHyperparameters;
import ai.verta.modeldb.GetMetrics;
import ai.verta.modeldb.GetObservations;
import ai.verta.modeldb.GetTags;
import ai.verta.modeldb.GetUrlForArtifact;
import ai.verta.modeldb.GetVersionedInput;
import ai.verta.modeldb.LogArtifacts;
import ai.verta.modeldb.LogAttributes;
import ai.verta.modeldb.LogDatasets;
import ai.verta.modeldb.LogEnvironment;
import ai.verta.modeldb.LogExperimentRunCodeVersion;
import ai.verta.modeldb.LogHyperparameters;
import ai.verta.modeldb.LogMetrics;
import ai.verta.modeldb.LogObservations;
import ai.verta.modeldb.LogVersionedInput;
import ai.verta.modeldb.ModelDBConstants;
import ai.verta.modeldb.ModelDBMessages;
import ai.verta.modeldb.Observation;
import ai.verta.modeldb.UpdateExperimentRunDescription;
import ai.verta.modeldb.VersioningEntry;
import ai.verta.modeldb.common.CommonUtils;
import ai.verta.modeldb.common.artifactStore.ArtifactStoreDAO;
import ai.verta.modeldb.common.authservice.RoleServiceUtils;
import ai.verta.modeldb.common.authservice.UACApisUtil;
import ai.verta.modeldb.common.connections.UAC;
import ai.verta.modeldb.common.exceptions.AlreadyExistsException;
import ai.verta.modeldb.common.exceptions.InternalErrorException;
import ai.verta.modeldb.common.exceptions.InvalidArgumentException;
import ai.verta.modeldb.common.exceptions.ModelDBException;
import ai.verta.modeldb.common.exceptions.NotFoundException;
import ai.verta.modeldb.common.exceptions.PermissionDeniedException;
import ai.verta.modeldb.common.futures.FutureExecutor;
import ai.verta.modeldb.common.futures.FutureJdbi;
import ai.verta.modeldb.common.futures.FutureUtil;
import ai.verta.modeldb.common.futures.InternalFuture;
import ai.verta.modeldb.common.exceptions.*;
import ai.verta.modeldb.common.futures.*;
import ai.verta.modeldb.common.handlers.TagsHandlerBase;
import ai.verta.modeldb.common.query.QueryFilterContext;
import ai.verta.modeldb.common.subtypes.MapSubtypes;
import ai.verta.modeldb.config.MDBConfig;
import ai.verta.modeldb.entities.ExperimentRunEntity;
import ai.verta.modeldb.experimentRun.subtypes.ArtifactHandler;
import ai.verta.modeldb.experimentRun.subtypes.AttributeHandler;
import ai.verta.modeldb.experimentRun.subtypes.CodeVersionFromBlobHandler;
import ai.verta.modeldb.experimentRun.subtypes.CodeVersionHandler;
import ai.verta.modeldb.experimentRun.subtypes.CreateExperimentRunHandler;
import ai.verta.modeldb.experimentRun.subtypes.DatasetHandler;
import ai.verta.modeldb.experimentRun.subtypes.EnvironmentHandler;
import ai.verta.modeldb.experimentRun.subtypes.FeatureHandler;
import ai.verta.modeldb.experimentRun.subtypes.FilterPrivilegedDatasetsHandler;
import ai.verta.modeldb.experimentRun.subtypes.FilterPrivilegedVersionedInputsHandler;
import ai.verta.modeldb.experimentRun.subtypes.HyperparametersFromConfigHandler;
import ai.verta.modeldb.experimentRun.subtypes.KeyValueBaseHandler;
import ai.verta.modeldb.experimentRun.subtypes.ObservationHandler;
import ai.verta.modeldb.experimentRun.subtypes.PredicatesHandler;
import ai.verta.modeldb.experimentRun.subtypes.SortingHandler;
import ai.verta.modeldb.experimentRun.subtypes.TagsHandler;
import ai.verta.modeldb.experimentRun.subtypes.VersionInputHandler;
import ai.verta.modeldb.experimentRun.subtypes.*;
import ai.verta.modeldb.utils.RdbmsUtils;
import ai.verta.modeldb.versioning.BlobDAO;
import ai.verta.modeldb.versioning.CommitDAO;
import ai.verta.modeldb.versioning.EnvironmentBlob;
import ai.verta.modeldb.versioning.RepositoryDAO;
import ai.verta.uac.Action;
import ai.verta.uac.*;
import ai.verta.uac.Empty;
import ai.verta.uac.IsSelfAllowed;
import ai.verta.uac.ModelDBActionEnum;
import ai.verta.uac.ResourceType;
import ai.verta.uac.Resources;
import ai.verta.uac.ServiceEnum;
import com.google.protobuf.Value;
import com.google.rpc.Code;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -455,6 +366,8 @@ public InternalFuture<List<String>> getTags(GetTags request) {
.thenSupply(() -> tagsHandler.getTags(runId).toInternalFuture(), executor);
}

// TODO: refactor all usages to use updateVersionNumberV2
@Deprecated
private InternalFuture<Void> updateModifiedTimestamp(String runId, Long now) {
return jdbi.useHandle(
handle -> {
Expand All @@ -471,6 +384,24 @@ private InternalFuture<Void> updateModifiedTimestamp(String runId, Long now) {
});
}

private Future<Void> updateModifiedTimestampV2(String runId, Long now) {
return jdbi.run(
handle -> {
try (var findQuery =
handle.createQuery("SELECT date_updated FROM experiment_run WHERE id=:run_id")) {
final var currentDateUpdated = findQuery.bind("run_id", runId).mapTo(Long.class).one();
final var dateUpdated = Math.max(currentDateUpdated, now);
try (var updateQuery =
handle.createUpdate(
"update experiment_run set date_updated=:date_updated where id=:run_id")) {
updateQuery.bind("run_id", runId).bind("date_updated", dateUpdated).execute();
}
}
});
}

// TODO: refactor all usages to use updateVersionNumberV2
@Deprecated
private InternalFuture<Void> updateVersionNumber(String erId) {
return jdbi.useHandle(
handle -> {
Expand All @@ -482,6 +413,17 @@ private InternalFuture<Void> updateVersionNumber(String erId) {
});
}

private Future<Void> updateVersionNumberV2(String erId) {
return jdbi.run(
handle -> {
try (var updateQuery =
handle.createUpdate(
"update experiment_run set version_number=(version_number + 1) where id=:er_id")) {
updateQuery.bind("er_id", erId).execute();
}
});
}

private InternalFuture<Boolean> getEntityPermissionBasedOnResourceTypes(
List<String> entityIds,
ModelDBActionEnum.ModelDBServiceActions action,
Expand Down Expand Up @@ -1519,8 +1461,7 @@ public InternalFuture<VersioningEntry> getVersionedInputs(GetVersionedInput requ
() -> {
// Validate request parameter
if (request.getDatasetVersionId().isEmpty()) {
throw new ModelDBException(
"DatasetVersion Id should not be empty", Code.INVALID_ARGUMENT);
throw new InvalidArgumentException("DatasetVersion Id should not be empty");
}
},
executor);
Expand Down Expand Up @@ -1876,4 +1817,29 @@ public void deleteLogVersionedInputs(Session session, List<Long> repoIds) {
query.executeUpdate();
LOGGER.debug("ExperimentRun versioning deleted successfully");
}

public Future<Void> updateExperimentRunName(UpdateExperimentRunName request) {
final var runId = request.getId();
final var name = request.getName();
final var now = Calendar.getInstance().getTimeInMillis();

return checkPermission(
Collections.singletonList(runId), ModelDBActionEnum.ModelDBServiceActions.UPDATE)
.toFuture()
.thenCompose(
unused ->
jdbi.run(
handle -> {
String updateQueryString =
"UPDATE experiment_run SET name=:name, date_updated=:date_updated WHERE id=:runId";
gustavoteixeirah marked this conversation as resolved.
Show resolved Hide resolved
handle
.createUpdate(updateQueryString)
.bind("name", name)
.bind("date_updated", now)
.bind("runId", runId)
.execute();
}))
.thenCompose(unused -> updateModifiedTimestampV2(runId, now))
.thenCompose(unused -> updateVersionNumberV2(runId));
gustavoteixeirah marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ai.verta.modeldb.common.exceptions.InternalErrorException;
import ai.verta.modeldb.common.exceptions.InvalidArgumentException;
import ai.verta.modeldb.common.exceptions.NotFoundException;
import ai.verta.modeldb.common.futures.Future;
import ai.verta.modeldb.common.futures.FutureExecutor;
import ai.verta.modeldb.common.futures.FutureGrpc;
import ai.verta.modeldb.common.futures.InternalFuture;
Expand Down Expand Up @@ -218,8 +219,16 @@ public void getExperimentRunByName(
public void updateExperimentRunName(
UpdateExperimentRunName request,
StreamObserver<UpdateExperimentRunName.Response> responseObserver) {
responseObserver.onError(
Status.UNIMPLEMENTED.withDescription(ModelDBMessages.UNIMPLEMENTED).asRuntimeException());
try {
final var response =
futureExperimentRunDAO
.updateExperimentRunName(request)
.thenSupply(() -> Future.of(UpdateExperimentRunName.Response.getDefaultInstance()));

FutureGrpc.serverResponse(responseObserver, response);
} catch (Exception e) {
CommonUtils.observeError(responseObserver, e);
}
}

@Override
Expand Down
Loading