Skip to content

Commit 20a7685

Browse files
authored
Merge pull request #37 from comet-ml/CM-1582-data-streamer-api
2 parents ac6b9c5 + 3d6e6e3 commit 20a7685

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2529
-1623
lines changed

comet-examples/src/main/java/ml/comet/examples/OnlineExperimentExample.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ private void run() throws IOException {
4040
//this will take configs from /comet-java-sdk/comet-examples/src/main/resources/application.conf
4141
//be sure you have set up apiKey, project, workspace in defaults.conf before you start!
4242

43-
OnlineExperiment experiment = new OnlineExperimentImpl();
44-
experiment.setInterceptStdout();
43+
OnlineExperiment experiment = OnlineExperimentImpl
44+
.builder()
45+
.interceptStdout()
46+
.build();
4547

4648
//you can use a builder or just inject params
4749
//OnlineExperimentImpl.builder();

comet-examples/src/main/java/ml/comet/examples/mnist/MnistExperimentExample.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public final class MnistExperimentExample {
5353
/**
5454
* The experiment entry point.
5555
*
56-
* <p>You need to set three environment variables to run this experiment:
56+
* <p>You should set three environment variables to run this experiment:
5757
* <ul>
58-
* <li>COMET_API_KEY - the API key to access Comet</li>
59-
* <li>COMET_WORKSPACE_NAME - the name of the workspace for your project</li>
60-
* <li>COMET_PROJECT_NAME - the name of the project.</li>
58+
* <li>COMET_API_KEY - the API key to access Comet (MANDATORY)</li>
59+
* <li>COMET_WORKSPACE_NAME - the name of the workspace for your project (OPTIONAL)</li>
60+
* <li>COMET_PROJECT_NAME - the name of the project (OPTIONAL)</li>
6161
* </ul>
6262
*
6363
* <p>Alternatively you can set these values in the <strong>resources/application.conf</strong> file
@@ -73,8 +73,10 @@ public static void main(String[] args) throws Exception {
7373
.parse(args);
7474

7575
// update application.conf or provide environment variables as described in JavaDoc.
76-
OnlineExperiment experiment = OnlineExperimentImpl.builder().build();
77-
experiment.setInterceptStdout();
76+
OnlineExperiment experiment = OnlineExperimentImpl
77+
.builder()
78+
.interceptStdout()
79+
.build();
7880
try {
7981
main.runMnistExperiment(experiment);
8082
} catch (Exception e) {

comet-examples/src/main/resources/application.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The application configuration options.
22
#
33
# Uncomment the following options and provide your own values. Also, you can set all the options through the environment
4-
# variables. Refer to the ml.comet.experiment.config.CometConfig for more details.
4+
# variables. Refer to the ml.comet.experiment.impl.config.CometConfig for more details.
55
comet {
66
# baseUrl = "https://www.comet.ml"
77
# apiKey = "XXXX"

comet-java-client/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<groupId>org.asynchttpclient</groupId>
3535
<artifactId>async-http-client</artifactId>
3636
</dependency>
37+
<dependency>
38+
<groupId>io.reactivex.rxjava3</groupId>
39+
<artifactId>rxjava</artifactId>
40+
<version>3.1.2</version>
41+
</dependency>
3742
<dependency>
3843
<groupId>org.projectlombok</groupId>
3944
<artifactId>lombok</artifactId>
Lines changed: 9 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,24 @@
11
package ml.comet.experiment;
22

33
import lombok.NonNull;
4+
import lombok.experimental.UtilityClass;
45
import ml.comet.experiment.builder.ApiExperimentBuilder;
5-
import ml.comet.experiment.config.CometConfig;
6-
import ml.comet.experiment.http.Connection;
7-
import ml.comet.experiment.http.ConnectionInitializer;
8-
import ml.comet.experiment.utils.CometUtils;
9-
import org.apache.commons.lang3.StringUtils;
10-
import org.slf4j.Logger;
11-
import org.slf4j.LoggerFactory;
12-
13-
import java.io.File;
14-
import java.time.Duration;
15-
import java.util.Optional;
16-
17-
import static ml.comet.experiment.config.CometConfig.COMET_API_KEY;
18-
import static ml.comet.experiment.config.CometConfig.COMET_BASE_URL;
19-
import static ml.comet.experiment.config.CometConfig.COMET_MAX_AUTH_RETRIES;
20-
import static ml.comet.experiment.config.CometConfig.COMET_TIMEOUT_CLEANING_SECONDS;
6+
import ml.comet.experiment.impl.ApiExperimentImpl;
217

228
/**
23-
* <p>Implementation of the {@link Experiment} that allows to read/update existing experiment.</p>
9+
* This is stub to support backward compatibility.
2410
*
25-
* <p>The ApiExperiment should be used to directly read/update data of the
26-
* existing experiment from the Comet server.</p>
11+
* @deprecated It would be replaced in the future with new experiment creation API.
2712
*/
28-
public final class ApiExperiment extends BaseExperiment {
29-
private final String baseUrl;
30-
private final String experimentKey;
31-
private final Duration cleaningTimeout;
32-
private final Connection connection;
33-
private Logger logger = LoggerFactory.getLogger(ApiExperiment.class);
34-
35-
private ApiExperiment(
36-
final String apiKey,
37-
final String anExperimentKey,
38-
final Logger logger,
39-
final String baseUrl,
40-
final int maxAuthRetries,
41-
Duration cleaningTimeout) {
42-
this.experimentKey = anExperimentKey;
43-
this.baseUrl = baseUrl;
44-
this.cleaningTimeout = cleaningTimeout;
45-
if (logger != null) {
46-
this.logger = logger;
47-
}
48-
this.connection = ConnectionInitializer.initConnection(
49-
apiKey, this.baseUrl, maxAuthRetries, this.logger);
50-
51-
CometUtils.printCometSdkVersion();
52-
}
53-
13+
@UtilityClass
14+
public final class ApiExperiment {
5415
/**
55-
* Returns builder to create ApiExperiment instance.
16+
* Returns builder to create {@link Experiment} instance.
5617
*
5718
* @param experimentKey the unique identifier of the existing experiment.
5819
* @return the initialized ApiExperiment instance.
5920
*/
60-
public static ApiExperiment.ApiExperimentBuilderImpl builder(@NonNull final String experimentKey) {
61-
return new ApiExperiment.ApiExperimentBuilderImpl(experimentKey);
62-
}
63-
64-
@Override
65-
protected Connection getConnection() {
66-
return this.connection;
67-
}
68-
69-
@Override
70-
protected Logger getLogger() {
71-
return this.logger;
72-
}
73-
74-
@Override
75-
public String getContext() {
76-
return StringUtils.EMPTY;
77-
}
78-
79-
@Override
80-
public String getWorkspaceName() {
81-
return getMetadata().getWorkspaceName();
82-
}
83-
84-
@Override
85-
public String getProjectName() {
86-
return getMetadata().getProjectName();
87-
}
88-
89-
@Override
90-
public String getExperimentName() {
91-
return getMetadata().getExperimentName();
92-
}
93-
94-
@Override
95-
public void end() {
96-
// invoke end of the superclass for common cleanup routines with given timeout
97-
super.end(this.cleaningTimeout);
98-
}
99-
100-
@Override
101-
public String getExperimentKey() {
102-
return this.experimentKey;
103-
}
104-
105-
@Override
106-
public Optional<String> getExperimentLink() {
107-
if (StringUtils.isEmpty(experimentKey)) {
108-
return Optional.empty();
109-
}
110-
try {
111-
return Optional.of(CometUtils.createExperimentLink(
112-
baseUrl, getWorkspaceName(), getProjectName(), experimentKey));
113-
} catch (Exception ex) {
114-
this.logger.error("failed to build experiment link", ex);
115-
return Optional.empty();
116-
}
117-
}
118-
119-
/**
120-
* The builder to create properly configured ApiExperiment instance.
121-
*/
122-
public static final class ApiExperimentBuilderImpl implements ApiExperimentBuilder {
123-
private final String experimentKey;
124-
private String apiKey;
125-
private Logger logger;
126-
127-
private ApiExperimentBuilderImpl(final String anExperimentKey) {
128-
this.experimentKey = anExperimentKey;
129-
}
130-
131-
@Override
132-
public ApiExperiment.ApiExperimentBuilderImpl withApiKey(@NonNull final String anApiKey) {
133-
this.apiKey = anApiKey;
134-
return this;
135-
}
136-
137-
@Override
138-
public ApiExperiment.ApiExperimentBuilderImpl withLogger(@NonNull final Logger logger) {
139-
this.logger = logger;
140-
return this;
141-
}
142-
143-
@Override
144-
public ApiExperiment.ApiExperimentBuilderImpl withConfigOverride(@NonNull final File overrideConfig) {
145-
CometConfig.applyConfigOverride(overrideConfig);
146-
return this;
147-
}
148-
149-
@Override
150-
public ApiExperiment build() {
151-
if (StringUtils.isEmpty(this.apiKey)) {
152-
this.apiKey = COMET_API_KEY.getString();
153-
}
154-
return new ApiExperiment(
155-
this.apiKey, this.experimentKey, this.logger,
156-
COMET_BASE_URL.getString(),
157-
COMET_MAX_AUTH_RETRIES.getInt(),
158-
COMET_TIMEOUT_CLEANING_SECONDS.getDuration());
159-
}
21+
public static ApiExperimentBuilder builder(@NonNull final String experimentKey) {
22+
return ApiExperimentImpl.builder(experimentKey);
16023
}
16124
}

0 commit comments

Comments
 (0)