Search in sources :

Example 1 with CometGeneralException

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));
}
Also used : CometGeneralException(ml.comet.experiment.exception.CometGeneralException)

Example 2 with CometGeneralException

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));
}
Also used : CreateExperimentRequest(ml.comet.experiment.impl.rest.CreateExperimentRequest) CreateExperimentResponse(ml.comet.experiment.impl.rest.CreateExperimentResponse) CometGeneralException(ml.comet.experiment.exception.CometGeneralException) CometApiException(ml.comet.experiment.exception.CometApiException)

Example 3 with CometGeneralException

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");
}
Also used : CometGeneralException(ml.comet.experiment.exception.CometGeneralException) Test(org.junit.jupiter.api.Test)

Example 4 with CometGeneralException

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());
}
Also used : LogMessages.getString(ml.comet.experiment.impl.resources.LogMessages.getString) CometGeneralException(ml.comet.experiment.exception.CometGeneralException) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

CometGeneralException (ml.comet.experiment.exception.CometGeneralException)4 Test (org.junit.jupiter.api.Test)2 CometApiException (ml.comet.experiment.exception.CometApiException)1 LogMessages.getString (ml.comet.experiment.impl.resources.LogMessages.getString)1 CreateExperimentRequest (ml.comet.experiment.impl.rest.CreateExperimentRequest)1 CreateExperimentResponse (ml.comet.experiment.impl.rest.CreateExperimentResponse)1 Timeout (org.junit.jupiter.api.Timeout)1