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);
}
}
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);
}
}
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;
}
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;
}
Aggregations