Search in sources :

Example 1 with HtmlRest

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

the class BaseExperimentAsync method logHtml.

/**
 * Asynchronous version that only logs any received exceptions or failures.
 *
 * @param html       A block of html to be sent to Comet
 * @param override   Whether previous html sent should be deleted.
 *                   If <code>true</code> the old html will be deleted.
 * @param onComplete The optional action to be invoked when this operation asynchronously completes.
 *                   Can be {@code null} if not interested in completion signal.
 */
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
void logHtml(@NonNull String html, boolean override, @NonNull Optional<Action> onComplete) {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("logHtmlAsync {}, override: {}", html, override);
    }
    HtmlRest htmlRequest = createLogHtmlRequest(html, override);
    this.sendAsynchronously(getRestApiClient()::logHtml, htmlRequest, onComplete);
}
Also used : HtmlRest(ml.comet.experiment.impl.rest.HtmlRest)

Example 2 with HtmlRest

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

the class ConnectionUtilsTest method testCreatePostJsonRequest.

@Test
public void testCreatePostJsonRequest() {
    String url = "http://test.com" + ApiEndpoints.ADD_ASSET;
    HtmlRest html = new HtmlRest("<html><body></body></html", false, System.currentTimeMillis());
    String json = JsonUtils.toJson(html);
    Request r = ConnectionUtils.createPostJsonRequest(json, url);
    this.validateRequest(r, url, null, POST, APPLICATION_JSON.toString());
    assertEquals(json.length(), r.getBodyGenerator().createBody().getContentLength(), "wrong body");
}
Also used : Request(org.asynchttpclient.Request) HtmlRest(ml.comet.experiment.impl.rest.HtmlRest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with HtmlRest

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

the class RestApiUtils method createLogHtmlRequest.

/**
 * The factory to create {@link HtmlRest} instance.
 *
 * @param html     the HTML code to be logged.
 * @param override the flag to indicate whether it should override already saved version.
 * @return the initialized {@link HtmlRest} instance.
 */
public static HtmlRest createLogHtmlRequest(@NonNull String html, boolean override) {
    HtmlRest request = new HtmlRest();
    request.setHtml(html);
    request.setOverride(override);
    request.setTimestamp(System.currentTimeMillis());
    return request;
}
Also used : HtmlRest(ml.comet.experiment.impl.rest.HtmlRest)

Aggregations

HtmlRest (ml.comet.experiment.impl.rest.HtmlRest)3 Request (org.asynchttpclient.Request)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1