Search in sources :

Example 1 with GetArtifactOptions

use of ml.comet.experiment.artifact.GetArtifactOptions in project comet-java-sdk by comet-ml.

the class BaseExperiment method getArtifactVersionDetail.

/**
 * Synchronously retrieves all data about a specific Artifact Version.
 *
 * @param options the {@link GetArtifactOptions} defining query options.
 * @return the {@link LoggedArtifact} instance holding all data about a specific Artifact Version.
 * @throws ArtifactNotFoundException     if artifact is not found or no artifact data returned.
 * @throws InvalidArtifactStateException if artifact was not closed or has empty artifact data returned.
 * @throws ArtifactException             if failed to get artifact due to the unexpected error.
 */
LoggedArtifact getArtifactVersionDetail(@NonNull GetArtifactOptions options) throws ArtifactNotFoundException, InvalidArtifactStateException, ArtifactException {
    try {
        ArtifactVersionDetail detail = validateAndGetExperimentKey().concatMap(experimentKey -> getRestApiClient().getArtifactVersionDetail(options, experimentKey)).blockingGet();
        ArtifactDto artifactDto = detail.getArtifact();
        if (artifactDto == null) {
            throw new InvalidArtifactStateException(getString(ARTIFACT_HAS_NO_DETAILS, options));
        }
        return detail.copyToLoggedArtifact(new LoggedArtifactImpl(artifactDto.getArtifactName(), artifactDto.getArtifactType(), this));
    } catch (CometApiException apiException) {
        switch(apiException.getSdkErrorCode()) {
            case noArtifactFound:
                throw new ArtifactNotFoundException(getString(ARTIFACT_NOT_FOUND, options), apiException);
            case artifactVersionStateNotClosed:
            case artifactVersionStateNotClosedErrorOccurred:
                throw new InvalidArtifactStateException(getString(ARTIFACT_NOT_READY, options), apiException);
            default:
                throw new ArtifactException(getString(GET_ARTIFACT_FAILED_UNEXPECTEDLY, options), apiException);
        }
    } catch (Throwable e) {
        throw new ArtifactException(getString(GET_ARTIFACT_FAILED_UNEXPECTEDLY, options), 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) ArtifactDto(ml.comet.experiment.impl.rest.ArtifactDto) InvalidArtifactStateException(ml.comet.experiment.artifact.InvalidArtifactStateException) ArtifactException(ml.comet.experiment.artifact.ArtifactException) ArtifactVersionDetail(ml.comet.experiment.impl.rest.ArtifactVersionDetail) ArtifactNotFoundException(ml.comet.experiment.artifact.ArtifactNotFoundException) CometApiException(ml.comet.experiment.exception.CometApiException)

Aggregations

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 Getter (lombok.Getter)1 NonNull (lombok.NonNull)1