Skip to content

Commit

Permalink
Close traces after experiment and handle trace deletion rejection
Browse files Browse the repository at this point in the history
Wait for experiment deletion response to be received before attempting
to close its traces.

Handle trace deletion response '409 Conflict' and do not remove it from
the trace manager if the deletion was rejected by the trace server.

Signed-off-by: Patrick Tasse <patrick.tasse@ericsson.com>
  • Loading branch information
PatrickTasse committed Dec 4, 2020
1 parent e7b6819 commit 9838bfb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
18 changes: 17 additions & 1 deletion packages/base/src/experiment-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ import { TspClient } from 'tsp-typescript-client/lib/protocol/tsp-client';
import { Query } from 'tsp-typescript-client/lib/models/query/query';
import { OutputDescriptor } from 'tsp-typescript-client/lib/models/output-descriptor';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import { TraceManager } from './trace-manager';
import { TspClientResponse } from 'tsp-typescript-client/lib/protocol/tsp-client-response';
import { signalManager, Signals } from './signal-manager';

export class ExperimentManager {

private fOpenExperiments: Map<string, Experiment> = new Map();
private fTspClient: TspClient;
private fTraceManager: TraceManager;

constructor(
tspClient: TspClient
tspClient: TspClient,
traceManager: TraceManager
) {
this.fTspClient = tspClient;
this.fTraceManager = traceManager;
signalManager().on(Signals.EXPERIMENT_CLOSED, ({experiment}) => this.onExperimentClosed(experiment));
}

/**
Expand Down Expand Up @@ -133,6 +138,17 @@ export class ExperimentManager {
}
}

private onExperimentClosed(experiment: Experiment) {
/*
* TODO: Do not close traces used by another experiment
*/
// Close each trace
const traces = experiment.traces;
for (let i = 0; i < traces.length; i++) {
this.fTraceManager.closeTrace(traces[i].UUID);
}
}

private addExperiment(experiment: Experiment) {
this.fOpenExperiments.set(experiment.UUID, experiment);
}
Expand Down
10 changes: 6 additions & 4 deletions packages/base/src/trace-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ export class TraceManager {
async closeTrace(traceUUID: string): Promise<void> {
const traceToClose = this.fOpenTraces.get(traceUUID);
if (traceToClose) {
await this.fTspClient.deleteTrace(traceUUID);
const deletedTrace = this.removeTrace(traceUUID);
if (deletedTrace) {
signalManager().emit(Signals.TRACE_CLOSED, {trace: deletedTrace});
const deleteResponse = await this.fTspClient.deleteTrace(traceUUID);
if (deleteResponse.getStatusCode() !== 409) {
const deletedTrace = this.removeTrace(traceUUID);
if (deletedTrace) {
signalManager().emit(Signals.TRACE_CLOSED, {trace: deletedTrace});
}
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions viewer-prototype/src/browser/trace-viewer/trace-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,8 @@ export class TraceViewerWidget extends ReactWidget {

onCloseRequest(msg: Message): void {
if (this.openedExperiment) {

const traces = this.openedExperiment.traces;
// Close experiment
this.experimentManager.closeExperiment(this.openedExperiment.UUID);

/*
TODO:
Decide wheather to delete traces from server as well.
Other experiments might wan to be create with these traces.
*/
// Close each trace
for (let i = 0; i < traces.length; i++) {
this.traceManager.closeTrace(traces[i].UUID);
}
}
this.statusBar.removeElement('time-selection-range');
super.onCloseRequest(msg);
Expand Down
4 changes: 2 additions & 2 deletions viewer-prototype/src/browser/tsp-client-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export class TspClientProvider {
) {
this._tspClient = new TspClient(this.tspUrlProvider.getTraceServerUrl());
this._traceManager = new TraceManager(this._tspClient);
this._experimentManager = new ExperimentManager(this._tspClient);
this._experimentManager = new ExperimentManager(this._tspClient, this._traceManager);
this._listeners = [];
tspUrlProvider.addTraceServerUrlChangedListener(url => {
this._tspClient = new TspClient(url);
this._traceManager = new TraceManager(this._tspClient);
this._experimentManager = new ExperimentManager(this._tspClient);
this._experimentManager = new ExperimentManager(this._tspClient, this._traceManager);
this._listeners.forEach(listener => listener(this._tspClient));
});
}
Expand Down

0 comments on commit 9838bfb

Please sign in to comment.