Search in sources :

Example 1 with ArtifactRequest

use of ml.comet.experiment.impl.rest.ArtifactRequest in project comet-java-sdk by comet-ml.

the class BaseExperiment method upsertArtifact.

/**
 * Synchronously upsert provided Comet artifact into Comet backend.
 *
 * @param artifact the {@link ArtifactImpl} instance.
 * @return the {@link ArtifactEntry} describing saved artifact.
 * @throws ArtifactException if operation failed.
 */
ArtifactEntry upsertArtifact(@NonNull final Artifact artifact) throws ArtifactException {
    try {
        ArtifactImpl artifactImpl = (ArtifactImpl) artifact;
        ArtifactRequest request = createArtifactUpsertRequest(artifactImpl);
        ArtifactEntry response = validateAndGetExperimentKey().concatMap(experimentKey -> getRestApiClient().upsertArtifact(request, experimentKey)).blockingGet();
        if (StringUtils.isBlank(response.getPreviousVersion())) {
            getLogger().info(getString(ARTIFACT_VERSION_CREATED_WITHOUT_PREVIOUS, artifactImpl.getName(), response.getCurrentVersion()));
        } else {
            getLogger().info(getString(ARTIFACT_VERSION_CREATED_WITH_PREVIOUS, artifactImpl.getName(), response.getCurrentVersion(), response.getPreviousVersion()));
        }
        return response;
    } catch (Throwable e) {
        throw new ArtifactException(getString(FAILED_TO_UPSERT_ARTIFACT, artifact), e);
    }
}
Also used : Connection(ml.comet.experiment.impl.http.Connection) RestApiUtils.createArtifactUpsertRequest(ml.comet.experiment.impl.utils.RestApiUtils.createArtifactUpsertRequest) LoggedExperimentAsset(ml.comet.experiment.asset.LoggedExperimentAsset) EXPERIMENT_LIVE(ml.comet.experiment.impl.resources.LogMessages.EXPERIMENT_LIVE) ArtifactDownloadException(ml.comet.experiment.artifact.ArtifactDownloadException) LoggedArtifactAsset(ml.comet.experiment.artifact.LoggedArtifactAsset) RestApiUtils.createLogEndTimeRequest(ml.comet.experiment.impl.utils.RestApiUtils.createLogEndTimeRequest) StringUtils(org.apache.commons.lang3.StringUtils) ExperimentMetadata(ml.comet.experiment.model.ExperimentMetadata) FAILED_TO_DOWNLOAD_ASSET_FILE_ALREADY_EXISTS(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_DOWNLOAD_ASSET_FILE_ALREADY_EXISTS) SOURCE_CODE(ml.comet.experiment.impl.asset.AssetType.SOURCE_CODE) RestApiUtils.createGraphRequest(ml.comet.experiment.impl.utils.RestApiUtils.createGraphRequest) Duration(java.time.Duration) RestApiUtils.createLogMetricRequest(ml.comet.experiment.impl.utils.RestApiUtils.createLogMetricRequest) Path(java.nio.file.Path) SdkErrorCodes.artifactVersionStateNotClosed(ml.comet.experiment.impl.constants.SdkErrorCodes.artifactVersionStateNotClosed) FAILED_TO_DELETE_TEMPORARY_ASSET_FILE(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_DELETE_TEMPORARY_ASSET_FILE) NonNull(lombok.NonNull) AssetUtils.createAssetFromData(ml.comet.experiment.impl.utils.AssetUtils.createAssetFromData) FAILED_TO_DOWNLOAD_ASSET(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_DOWNLOAD_ASSET) ARTIFACT_NOT_FOUND(ml.comet.experiment.impl.resources.LogMessages.ARTIFACT_NOT_FOUND) FAILED_TO_UPSERT_ARTIFACT(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_UPSERT_ARTIFACT) StandardCharsets(java.nio.charset.StandardCharsets) SdkErrorCodes.noArtifactFound(ml.comet.experiment.impl.constants.SdkErrorCodes.noArtifactFound) SdkErrorCodes.artifactVersionStateNotClosedErrorOccurred(ml.comet.experiment.impl.constants.SdkErrorCodes.artifactVersionStateNotClosedErrorOccurred) ARTIFACT_DOWNLOAD_FILE_OVERWRITTEN(ml.comet.experiment.impl.resources.LogMessages.ARTIFACT_DOWNLOAD_FILE_OVERWRITTEN) FAILED_TO_RESOLVE_ASSET_FILE(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_RESOLVE_ASSET_FILE) Experiment(ml.comet.experiment.Experiment) DownloadArtifactAssetOptions(ml.comet.experiment.impl.asset.DownloadArtifactAssetOptions) Optional.empty(java.util.Optional.empty) Single(io.reactivex.rxjava3.core.Single) FAILED_TO_COMPARE_CONTENT_OF_FILES(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_COMPARE_CONTENT_OF_FILES) ArtifactNotFoundException(ml.comet.experiment.artifact.ArtifactNotFoundException) ArtifactRequest(ml.comet.experiment.impl.rest.ArtifactRequest) ArrayList(java.util.ArrayList) Artifact(ml.comet.experiment.artifact.Artifact) ARTIFACT_VERSION_CREATED_WITHOUT_PREVIOUS(ml.comet.experiment.impl.resources.LogMessages.ARTIFACT_VERSION_CREATED_WITHOUT_PREVIOUS) SystemUtils(ml.comet.experiment.impl.utils.SystemUtils) ALL(ml.comet.experiment.impl.asset.AssetType.ALL) FAILED_REGISTER_EXPERIMENT(ml.comet.experiment.impl.resources.LogMessages.FAILED_REGISTER_EXPERIMENT) GitMetaData(ml.comet.experiment.model.GitMetaData) RestApiResponse(ml.comet.experiment.impl.rest.RestApiResponse) Files(java.nio.file.Files) IOException(java.io.IOException) ExperimentContext(ml.comet.experiment.context.ExperimentContext) File(java.io.File) ARTIFACT_NOT_READY(ml.comet.experiment.impl.resources.LogMessages.ARTIFACT_NOT_READY) ExecutionException(java.util.concurrent.ExecutionException) EXPERIMENT_CREATED(ml.comet.experiment.impl.resources.LogMessages.EXPERIMENT_CREATED) Function(io.reactivex.rxjava3.functions.Function) CometGeneralException(ml.comet.experiment.exception.CometGeneralException) AssetUtils.createAssetFromFile(ml.comet.experiment.impl.utils.AssetUtils.createAssetFromFile) ArtifactVersionAssetResponse(ml.comet.experiment.impl.rest.ArtifactVersionAssetResponse) ExperimentStatusResponse(ml.comet.experiment.impl.rest.ExperimentStatusResponse) ArtifactEntry(ml.comet.experiment.impl.rest.ArtifactEntry) RestApiUtils.createLogParamRequest(ml.comet.experiment.impl.utils.RestApiUtils.createLogParamRequest) RestApiUtils.createLogStartTimeRequest(ml.comet.experiment.impl.utils.RestApiUtils.createLogStartTimeRequest) AssetImpl(ml.comet.experiment.impl.asset.AssetImpl) LoggedArtifact(ml.comet.experiment.artifact.LoggedArtifact) ArtifactException(ml.comet.experiment.artifact.ArtifactException) RestApiUtils.createLogLineRequest(ml.comet.experiment.impl.utils.RestApiUtils.createLogLineRequest) RestApiUtils.createGitMetadataRequest(ml.comet.experiment.impl.utils.RestApiUtils.createGitMetadataRequest) ARTIFACT_VERSION_CREATED_WITH_PREVIOUS(ml.comet.experiment.impl.resources.LogMessages.ARTIFACT_VERSION_CREATED_WITH_PREVIOUS) CreateExperimentRequest(ml.comet.experiment.impl.rest.CreateExperimentRequest) ArtifactAsset(ml.comet.experiment.artifact.ArtifactAsset) LogMessages.getString(ml.comet.experiment.impl.resources.LogMessages.getString) Collection(java.util.Collection) RestApiUtils.createLogHtmlRequest(ml.comet.experiment.impl.utils.RestApiUtils.createLogHtmlRequest) ArtifactVersionDetail(ml.comet.experiment.impl.rest.ArtifactVersionDetail) GET_ARTIFACT_FAILED_UNEXPECTEDLY(ml.comet.experiment.impl.resources.LogMessages.GET_ARTIFACT_FAILED_UNEXPECTEDLY) Value(ml.comet.experiment.model.Value) List(java.util.List) FAILED_TO_CREATE_TEMPORARY_ASSET_DOWNLOAD_FILE(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_CREATE_TEMPORARY_ASSET_DOWNLOAD_FILE) FAILED_TO_READ_DOWNLOADED_FILE_SIZE(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_READ_DOWNLOADED_FILE_SIZE) BiFunction(io.reactivex.rxjava3.functions.BiFunction) Disposable(io.reactivex.rxjava3.disposables.Disposable) Optional(java.util.Optional) GetArtifactOptions(ml.comet.experiment.artifact.GetArtifactOptions) MinMaxResponse(ml.comet.experiment.impl.rest.MinMaxResponse) CreateExperimentResponse(ml.comet.experiment.impl.rest.CreateExperimentResponse) Getter(lombok.Getter) CompletableFuture(java.util.concurrent.CompletableFuture) ArtifactAssetImpl(ml.comet.experiment.impl.asset.ArtifactAssetImpl) ExceptionUtils(ml.comet.experiment.impl.utils.ExceptionUtils) AssetOverwriteStrategy(ml.comet.experiment.artifact.AssetOverwriteStrategy) ARTIFACT_HAS_NO_DETAILS(ml.comet.experiment.impl.resources.LogMessages.ARTIFACT_HAS_NO_DETAILS) RestApiUtils.createTagRequest(ml.comet.experiment.impl.utils.RestApiUtils.createTagRequest) InvalidArtifactStateException(ml.comet.experiment.artifact.InvalidArtifactStateException) REMOTE_ASSET_CANNOT_BE_DOWNLOADED(ml.comet.experiment.impl.resources.LogMessages.REMOTE_ASSET_CANNOT_BE_DOWNLOADED) COMPLETED_DOWNLOAD_ARTIFACT_ASSET(ml.comet.experiment.impl.resources.LogMessages.COMPLETED_DOWNLOAD_ARTIFACT_ASSET) FAILED_TO_UPDATE_ARTIFACT_VERSION_STATE(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_UPDATE_ARTIFACT_VERSION_STATE) ArtifactVersionState(ml.comet.experiment.impl.rest.ArtifactVersionState) RestApiUtils.createLogOtherRequest(ml.comet.experiment.impl.utils.RestApiUtils.createLogOtherRequest) RestApiUtils.createArtifactVersionStateRequest(ml.comet.experiment.impl.utils.RestApiUtils.createArtifactVersionStateRequest) ArtifactDto(ml.comet.experiment.impl.rest.ArtifactDto) CometUtils(ml.comet.experiment.impl.utils.CometUtils) ARTIFACT_ASSETS_FILE_EXISTS_PRESERVING(ml.comet.experiment.impl.resources.LogMessages.ARTIFACT_ASSETS_FILE_EXISTS_PRESERVING) Logger(org.slf4j.Logger) FileUtils(ml.comet.experiment.impl.utils.FileUtils) ConnectionInitializer(ml.comet.experiment.impl.http.ConnectionInitializer) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) CometApiException(ml.comet.experiment.exception.CometApiException) FAILED_TO_READ_LOGGED_ARTIFACT_ASSETS(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_READ_LOGGED_ARTIFACT_ASSETS) FAILED_READ_DATA_FOR_EXPERIMENT(ml.comet.experiment.impl.resources.LogMessages.FAILED_READ_DATA_FOR_EXPERIMENT) ArtifactRequest(ml.comet.experiment.impl.rest.ArtifactRequest) ArtifactEntry(ml.comet.experiment.impl.rest.ArtifactEntry) ArtifactException(ml.comet.experiment.artifact.ArtifactException)

Example 2 with ArtifactRequest

use of ml.comet.experiment.impl.rest.ArtifactRequest in project comet-java-sdk by comet-ml.

the class BaseExperiment method updateArtifactVersionState.

/**
 * Synchronously updates the state associated with Comet artifact version.
 *
 * @param artifactVersionId the artifact version identifier.
 * @param state             the state to be associated.
 * @throws ArtifactException is operation failed.
 */
void updateArtifactVersionState(@NonNull String artifactVersionId, @NonNull ArtifactVersionState state) throws ArtifactException {
    try {
        ArtifactRequest request = createArtifactVersionStateRequest(artifactVersionId, state);
        sendSynchronously(getRestApiClient()::updateArtifactState, request);
    } catch (Throwable e) {
        throw new ArtifactException(getString(FAILED_TO_UPDATE_ARTIFACT_VERSION_STATE, artifactVersionId), e);
    }
}
Also used : ArtifactRequest(ml.comet.experiment.impl.rest.ArtifactRequest) ArtifactException(ml.comet.experiment.artifact.ArtifactException)

Example 3 with ArtifactRequest

use of ml.comet.experiment.impl.rest.ArtifactRequest in project comet-java-sdk by comet-ml.

the class RestApiUtils method createArtifactUpsertRequest.

/**
 * The factory to create {@link ArtifactRequest} instance to be used to upsert Comet artifact.
 *
 * @param artifact the {@link ArtifactImpl} instance.
 * @return the initialized {@link ArtifactRequest} instance.
 */
public static ArtifactRequest createArtifactUpsertRequest(final ArtifactImpl artifact) {
    ArtifactRequest r = new ArtifactRequest();
    r.setArtifactName(artifact.getName());
    r.setArtifactType(artifact.getType());
    if (artifact.getSemanticVersion() != null) {
        r.setVersion(artifact.getSemanticVersion().getValue());
    }
    if (artifact.getAliases() != null && artifact.getAliases().size() > 0) {
        r.setAlias(artifact.getAliases().toArray(new String[0]));
    }
    if (artifact.getVersionTags() != null && artifact.getVersionTags().size() > 0) {
        r.setVersionTags(artifact.getVersionTags().toArray(new String[0]));
    }
    if (artifact.getMetadata() != null) {
        r.setVersionMetadata(JsonUtils.toJson(artifact.getMetadata()));
    }
    return r;
}
Also used : ArtifactRequest(ml.comet.experiment.impl.rest.ArtifactRequest)

Example 4 with ArtifactRequest

use of ml.comet.experiment.impl.rest.ArtifactRequest in project comet-java-sdk by comet-ml.

the class RestApiUtils method createArtifactVersionStateRequest.

/**
 * Creates request to signal the state of the artifact version send operation.
 *
 * @param artifactVersionId the identifier of the artifact version.
 * @param state             the {@link ArtifactVersionState} signaling state of the operation.
 * @return the properly initialized {@link ArtifactRequest} instance.
 */
public static ArtifactRequest createArtifactVersionStateRequest(String artifactVersionId, ArtifactVersionState state) {
    ArtifactRequest r = new ArtifactRequest();
    r.setArtifactVersionId(artifactVersionId);
    r.setState(state);
    return r;
}
Also used : ArtifactRequest(ml.comet.experiment.impl.rest.ArtifactRequest)

Aggregations

ArtifactRequest (ml.comet.experiment.impl.rest.ArtifactRequest)3 ArtifactException (ml.comet.experiment.artifact.ArtifactException)2 Single (io.reactivex.rxjava3.core.Single)1 Disposable (io.reactivex.rxjava3.disposables.Disposable)1 BiFunction (io.reactivex.rxjava3.functions.BiFunction)1 Function (io.reactivex.rxjava3.functions.Function)1 File (java.io.File)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1