use of ml.comet.experiment.exception.CometGeneralException in project comet-java-sdk by comet-ml.
the class Connection method executeRequestAsync.
/**
* Executes provided request asynchronously.
*
* @param request the request to be executed.
* @param downloadListener the {@link DownloadListener} to collect received bytes.
* @return the {@link ListenableFuture} which can be used to check request status.
*/
ListenableFuture<Response> executeRequestAsync(@NonNull Request request, DownloadListener downloadListener) {
// check that client is not closed
if (this.asyncHttpClient.isClosed()) {
String msg = String.format("failed to execute request %s connection to the server already closed", request);
return new ListenableFuture.CompletedFailure<>("asyncHttpClient already closed", new CometGeneralException(msg));
}
// increment inventory
this.requestsInventory.incrementAndGet();
request.getHeaders().add(COMET_SDK_API_HEADER, apiKey);
String endpoint = request.getUrl();
return this.asyncHttpClient.executeRequest(request, new AsyncCompletionInventoryHandler(this.requestsInventory, this.logger, endpoint, downloadListener));
}
use of ml.comet.experiment.exception.CometGeneralException in project comet-java-sdk by comet-ml.
the class BaseExperiment method registerExperiment.
/**
* Synchronously registers experiment at the Comet server.
*
* @throws CometGeneralException if failed to register experiment.
*/
void registerExperiment() throws CometGeneralException {
if (StringUtils.isNotBlank(this.experimentKey)) {
getLogger().debug("Not registering a new experiment. Using previous experiment key {}", this.experimentKey);
return;
}
// do synchronous call to register experiment
try {
CreateExperimentResponse result = this.restApiClient.registerExperiment(new CreateExperimentRequest(this.workspaceName, this.projectName, this.experimentName)).blockingGet();
if (StringUtils.isBlank(result.getExperimentKey())) {
throw new CometGeneralException(getString(FAILED_REGISTER_EXPERIMENT));
}
this.experimentKey = result.getExperimentKey();
this.experimentLink = result.getLink();
this.workspaceName = result.getWorkspaceName();
this.projectName = result.getProjectName();
if (StringUtils.isBlank(this.experimentName)) {
this.experimentName = result.getName();
}
} catch (CometApiException ex) {
this.getLogger().error(getString(FAILED_REGISTER_EXPERIMENT), ex);
throw new CometGeneralException(getString(FAILED_REGISTER_EXPERIMENT), ex);
}
getLogger().info(getString(EXPERIMENT_CREATED, this.workspaceName, this.projectName, this.experimentName));
getLogger().info(getString(EXPERIMENT_LIVE, this.experimentLink));
}
use of ml.comet.experiment.exception.CometGeneralException in project comet-java-sdk by comet-ml.
the class ExceptionUtilsTest method testUnwrap.
@Test
public void testUnwrap() {
// Test exception without cause
CometGeneralException root = new CometGeneralException("Root cause");
Throwable unwrapped = ExceptionUtils.unwrap(root);
assertEquals(root, unwrapped, "wrong unwrapped exception");
// Test exception with cause
RuntimeException composite = new RuntimeException("Composite exception 1-st level", new RuntimeException("Composite exception 2-nd level", root));
unwrapped = ExceptionUtils.unwrap(composite);
assertEquals(root, unwrapped, "wrong unwrapped exception");
}
use of ml.comet.experiment.exception.CometGeneralException in project comet-java-sdk by comet-ml.
the class OnlineExperimentTest method testCreateExperiment_wrongApiKey.
@Test
@Timeout(60)
public void testCreateExperiment_wrongApiKey() {
String wrongApiKey = "not existing API key";
CometGeneralException ex = assertThrows(CometGeneralException.class, () -> OnlineExperimentImpl.builder().withApiKey(wrongApiKey).build());
assertEquals(getString(FAILED_REGISTER_EXPERIMENT), ex.getMessage());
}
Aggregations