Skip to content

Commit

Permalink
Handle conflicting experiments when opening
Browse files Browse the repository at this point in the history
When opening a trace with the same name as another experiment, the experiment
that contains it will have a conflict on the server. The client should
retry posting it with a different name until it succeeds or another
error occurs.

The title of the trace viewer should also be updated to represent the
actual name of the experiment.

Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
  • Loading branch information
tahini committed May 26, 2020
1 parent 21bbb26 commit a13523b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions viewer-prototype/src/browser/trace-viewer/trace-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class TraceViewerWidget extends ReactWidget {
const experiment = await this.experimentManager.openExperiment(this.uri.name, traces);
if (experiment) {
this.openedExperiment = experiment;
this.title.label = 'Trace: ' + experiment.name;
}

this.update();
Expand Down
25 changes: 24 additions & 1 deletion viewer-prototype/src/common/experiment-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Query } from 'tsp-typescript-client/lib/models/query/query';
import { injectable, inject } from 'inversify';
import { OutputDescriptor } from 'tsp-typescript-client/lib/models/output-descriptor';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import { TspClientResponse } from 'tsp-typescript-client/lib/protocol/tsp-client-response';

@injectable()
export class ExperimentManager {
Expand Down Expand Up @@ -87,11 +88,33 @@ export class ExperimentManager {
'traces': traceURIs
}));
const experiment = experimentResponse.getModel()
if (experiment && (experimentResponse.isOk() || experimentResponse.getStatusCode() === 409)) {
if (experiment && experimentResponse.isOk()) {
this.addExperiment(experiment);
this.experimentOpenedEmitter.fire(experiment);
return experiment;
} else if (experiment && experimentResponse.getStatusCode() === 409) {
// Repost with a suffix as long as there are conflicts
let handleConflict = async function(tspClient: TspClient, tryNb: number): Promise<TspClientResponse<Experiment>> {
let suffix = '(' + tryNb + ')';
return await tspClient.createExperiment(new Query({
'name': name + suffix,
'traces': traceURIs
}))
}
let conflictResolutionResponse = experimentResponse;
let i = 1;
while (conflictResolutionResponse.getStatusCode() === 409) {
conflictResolutionResponse = await handleConflict(this.tspClient, i);
i++;
}
const experiment = conflictResolutionResponse.getModel()
if (experiment && conflictResolutionResponse.isOk()) {
this.addExperiment(experiment);
this.experimentOpenedEmitter.fire(experiment);
return experiment;
}
}
// TODO Handle any other experiment open errors
return undefined;
}

Expand Down
3 changes: 2 additions & 1 deletion viewer-prototype/src/common/trace-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ export class TraceManager {
'uri': tracePath
}));
const trace = traceResponse.getModel()
if (trace && (traceResponse.isOk() || traceResponse.getStatusCode() === 409)) {
if (trace && traceResponse.isOk()) {
this.addTrace(trace);
this.traceOpenedEmitter.fire(trace);
return trace;
}
// TODO Handle trace open errors
return undefined;
}

Expand Down

0 comments on commit a13523b

Please sign in to comment.