Skip to content

Commit

Permalink
Check for unsuccessful TspClientResponse
Browse files Browse the repository at this point in the history
Always check if the response is successful and if its model is set.

Signed-off-by: Patrick Tasse <patrick.tasse@ericsson.com>
  • Loading branch information
PatrickTasse committed Jan 6, 2021
1 parent fce638a commit 31fdebf
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 83 deletions.
11 changes: 6 additions & 5 deletions packages/base/src/experiment-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export class ExperimentManager {
async getOpenedExperiments(): Promise<Experiment[]> {
const openedExperiments: Array<Experiment> = [];
// Look on the server for opened experiments
const experimentResponse = await this.fTspClient.fetchExperiments();
if (experimentResponse.isOk()) {
openedExperiments.push(...experimentResponse.getModel());
const experimentsResponse = await this.fTspClient.fetchExperiments();
const experiments = experimentsResponse.getModel();
if (experimentsResponse.isOk() && experiments) {
openedExperiments.push(...experiments);
}
return openedExperiments;
}
Expand Down Expand Up @@ -94,8 +95,8 @@ export class ExperimentManager {
experimentResponse = await tryCreate(this.fTspClient, tryNb);
tryNb++;
}
if (experimentResponse.isOk()) {
const experiment = experimentResponse.getModel();
const experiment = experimentResponse.getModel();
if (experimentResponse.isOk() && experiment) {
this.addExperiment(experiment);
signalManager().emit(Signals.EXPERIMENT_OPENED, {experiment: experiment});
return experiment;
Expand Down
9 changes: 5 additions & 4 deletions packages/base/src/trace-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ export class TraceManager {
const openedTraces: Array<Trace> = [];
// Look on the server for opened trace
const tracesResponse = await this.fTspClient.fetchTraces();
if (tracesResponse.isOk()) {
openedTraces.push(...tracesResponse.getModel());
const traces = tracesResponse.getModel();
if (tracesResponse.isOk() && traces) {
openedTraces.push(...traces);
}
return openedTraces;
}
Expand Down Expand Up @@ -84,8 +85,8 @@ export class TraceManager {
traceResponse = await tryOpen(this.fTspClient, tryNb);
tryNb++;
}
if (traceResponse.isOk()) {
const trace = traceResponse.getModel();
const trace = traceResponse.getModel();
if (traceResponse.isOk() && trace) {
this.addTrace(trace);
signalManager().emit(Signals.TRACE_OPENED, {trace: trace});
return trace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ export abstract class AbstractTreeOutputComponent<P extends AbstractOutputProps,
// TODO Use the output descriptor to find out if the analysis is completed
const xyTreeParameters = QueryHelper.selectionTimeQuery(
QueryHelper.splitRangeIntoEqualParts(this.props.range.getstart(), this.props.range.getEnd(), 1120), []);
let xyTreeResponse = (await tspClient.fetchXYTree(traceUUID, outPutId, xyTreeParameters)).getModel();
while (xyTreeResponse.status === ResponseStatus.RUNNING) {
xyTreeResponse = (await tspClient.fetchXYTree(traceUUID, outPutId, xyTreeParameters)).getModel();
let tspClientResponse = await tspClient.fetchXYTree(traceUUID, outPutId, xyTreeParameters);
let xyTreeResponse = tspClientResponse.getModel();
while (tspClientResponse.isOk() && xyTreeResponse && xyTreeResponse.status === ResponseStatus.RUNNING) {
tspClientResponse = await tspClient.fetchXYTree(traceUUID, outPutId, xyTreeParameters);
xyTreeResponse = tspClientResponse.getModel();
}
if (tspClientResponse.isOk() && xyTreeResponse) {
this.setState({
outputStatus: xyTreeResponse.status
});
}
this.setState({
outputStatus: xyTreeResponse.status
});
}

componentWillUnmount(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ export class StyleProvider {
*/
public async getStyles(forceUpdate?: boolean): Promise<{ [key: string]: OutputElementStyle }> {
if (!this.styles || forceUpdate) {
const styleResponse = await this.tspClient.fetchStyles(this.traceId, this.outputId, QueryHelper.query());
const styleModel = styleResponse.getModel().model;
const styles = styleModel.styles;
this.styles = styles;
return styles;
const tspClientResponse = await this.tspClient.fetchStyles(this.traceId, this.outputId, QueryHelper.query());
const styleResponse = tspClientResponse.getModel();
if (tspClientResponse.isOk() && styleResponse) {
const styleModel = styleResponse.model;
const styles = styleModel.styles;
this.styles = styles;
return styles;
}
this.styles = {};
}
return this.styles;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ export class TspDataProvider {
const end = viewRange.end + this.timeGraphEntries[0].start;
statesParameters = QueryHelper.selectionTimeQuery(QueryHelper.splitRangeIntoEqualParts(Math.trunc(start), Math.trunc(end), resolution), ids);
}
const stateResponse = (await this.client.fetchTimeGraphStates(this.traceUUID,
this.outputId, statesParameters)).getModel();

this.timeGraphRows = stateResponse.model.rows;
this.timeGraphRowsOrdering(ids);
const tspClientResponse = await this.client.fetchTimeGraphStates(this.traceUUID, this.outputId, statesParameters);
const stateResponse = tspClientResponse.getModel();
if (tspClientResponse.isOk() && stateResponse) {
this.timeGraphRows = stateResponse.model.rows;
this.timeGraphRowsOrdering(ids);
} else {
this.timeGraphRows = [];
}

// the start time which is normalized to logical 0 in timeline chart.
const chartStart = this.timeGraphEntries[0].start;
Expand Down
33 changes: 20 additions & 13 deletions packages/react-components/src/components/table-output-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ export class TableOutputComponent extends AbstractOutputComponent<TableOutputPro
const tspClient = this.props.tspClient;
const outPutId = this.props.outputDescriptor.id;

const lineResponse = (await tspClient.fetchTableLines(traceUUID, outPutId, QueryHelper.tableQuery(this.columnIds, fetchIndex, linesToFetch))).getModel();
const tspClientResponse = await tspClient.fetchTableLines(traceUUID, outPutId, QueryHelper.tableQuery(this.columnIds, fetchIndex, linesToFetch));
const lineResponse = tspClientResponse.getModel();
const linesArray = new Array<any>();
if (!tspClientResponse.isOk() || !lineResponse) {
return linesArray;
}
const model = lineResponse.model;
const lines = model.lines;
const linesArray = new Array<any>();
lines.forEach(line => {
const obj: any = {};
const cells = line.cells;
Expand Down Expand Up @@ -127,8 +131,8 @@ export class TableOutputComponent extends AbstractOutputComponent<TableOutputPro
const outPutId = this.props.outputDescriptor.id;

// Fetch columns
const columnsResponse = (await tspClient.fetchTableColumns(traceUUID, outPutId, QueryHelper.timeQuery([0, 1]))).getModel();
const columnEntries = columnsResponse.model;
const tspClientResponse = await tspClient.fetchTableColumns(traceUUID, outPutId, QueryHelper.timeQuery([0, 1]));
const columnsResponse = tspClientResponse.getModel();
const colIds: Array<number> = [];
const columnsArray = new Array<any>();

Expand All @@ -142,16 +146,19 @@ export class TableOutputComponent extends AbstractOutputComponent<TableOutputPro
colIds.push(0);
}

columnEntries.forEach(columnHeader => {
const id = this.showIndexColumn ? ++columnHeader.id : columnHeader.id;
colIds.push(id);
columnsArray.push({
headerName: columnHeader.name,
field: columnHeader.id.toString(),
width: this.props.columnWidth

if (tspClientResponse.isOk() && columnsResponse) {
const columnEntries = columnsResponse.model;
columnEntries.forEach(columnHeader => {
const id = this.showIndexColumn ? ++columnHeader.id : columnHeader.id;
colIds.push(id);
columnsArray.push({
headerName: columnHeader.name,
field: columnHeader.id.toString(),
width: this.props.columnWidth

});
});
});
}

if (!this.showIndexColumn) {
columnsArray[0].cellRenderer = 'loadingRenderer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,39 @@ export class TimegraphOutputComponent extends AbstractTreeOutputComponent<Timegr
async componentDidUpdate(_prevProps: TimegraphOutputProps, _prevState: TimegraphOutputState): Promise<void> {
if (this.state.outputStatus !== ResponseStatus.COMPLETED || !this.state.timegraphTree.length) {
const treeParameters = QueryHelper.timeQuery([0, 1]);
const treeResponse = (await this.props.tspClient.fetchTimeGraphTree(this.props.traceId,
this.props.outputDescriptor.id, treeParameters)).getModel();
const nbEntries = treeResponse.model.entries.length;
this.totalHeight = nbEntries * this.props.style.rowHeight;
this.rowController.totalHeight = this.totalHeight;
const columns: ColumnHeader[] = [];
if (treeResponse.model.headers && treeResponse.model.headers.length > 0) {
treeResponse.model.headers.forEach(header => {
columns.push({title: header.name, sortable: true, tooltip: header.tooltip});
});
} else {
columns.push({title: 'Name', sortable: true});
}
const tspClientResponse = await this.props.tspClient.fetchTimeGraphTree(this.props.traceId,
this.props.outputDescriptor.id, treeParameters);
const treeResponse = tspClientResponse.getModel();
// TODO Style should not be retreive in the "initialization" part or at least async
const styleResponse = (await this.props.tspClient.fetchStyles(this.props.traceId, this.props.outputDescriptor.id, QueryHelper.query())).getModel();
this.setState({
// outputStatus: ResponseStatus.COMPLETED,
timegraphTree: treeResponse.model.entries,
styleModel: styleResponse.model,
columns
});
if (tspClientResponse.isOk() && treeResponse) {
const nbEntries = treeResponse.model.entries.length;
this.totalHeight = nbEntries * this.props.style.rowHeight;
this.rowController.totalHeight = this.totalHeight;
const columns: ColumnHeader[] = [];
if (treeResponse.model.headers && treeResponse.model.headers.length > 0) {
treeResponse.model.headers.forEach(header => {
columns.push({title: header.name, sortable: true, tooltip: header.tooltip});
});
} else {
columns.push({title: 'Name', sortable: true});
}
const tspClientResponse2 = await this.props.tspClient.fetchStyles(this.props.traceId, this.props.outputDescriptor.id, QueryHelper.query());
const styleResponse = tspClientResponse2.getModel();
if (tspClientResponse2.isOk() && styleResponse) {
this.setState({
// outputStatus: ResponseStatus.COMPLETED,
timegraphTree: treeResponse.model.entries,
styleModel: styleResponse.model,
columns
});
} else {
this.setState({
// outputStatus: ResponseStatus.COMPLETED,
timegraphTree: treeResponse.model.entries,
columns
});
}
}
this.chartLayer.updateChart();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,28 @@ export class TraceContextComponent extends React.Component<TraceContextProps, Tr

private async updateTrace() {
if (this.state.traceIndexing) {
let updatedExperiment = (await this.props.tspClient.fetchExperiment(this.props.experiment.UUID)).getModel();
let isIndexing = updatedExperiment.indexingStatus === this.INDEXING_RUNNING_STATUS;
let isIndexing = true;
while (isIndexing) {
updatedExperiment = (await this.props.tspClient.fetchExperiment(this.props.experiment.UUID)).getModel();
isIndexing = updatedExperiment.indexingStatus === this.INDEXING_RUNNING_STATUS;
this.setState({
timeOffset: updatedExperiment.start,
experiment: updatedExperiment,
traceIndexing: isIndexing,
currentRange: new TimeRange(updatedExperiment.start - updatedExperiment.start, updatedExperiment.end - updatedExperiment.start, updatedExperiment.start)
});
const tspClientResponse = await this.props.tspClient.fetchExperiment(this.props.experiment.UUID);
const updatedExperiment = tspClientResponse.getModel();
if (tspClientResponse.isOk() && updatedExperiment) {
isIndexing = updatedExperiment.indexingStatus === this.INDEXING_RUNNING_STATUS;
this.setState({
timeOffset: updatedExperiment.start,
experiment: updatedExperiment,
traceIndexing: isIndexing,
currentRange: new TimeRange(updatedExperiment.start - updatedExperiment.start, updatedExperiment.end - updatedExperiment.start, updatedExperiment.start)
});

// Update status bar
this.props.messageManager.addStatusMessage(this.INDEXING_STATUS_BAR_KEY, {
text: `Indexing ${this.props.experiment.name}: ${this.state.experiment.nbEvents}`,
category: Messages.MessageCategory.SERVER_MESSAGE
});
await this.sleep(500);
// Update status bar
this.props.messageManager.addStatusMessage(this.INDEXING_STATUS_BAR_KEY, {
text: `Indexing ${this.props.experiment.name}: ${this.state.experiment.nbEvents}`,
category: Messages.MessageCategory.SERVER_MESSAGE
});
await this.sleep(500);
} else {
break;
}
}
}
this.props.messageManager.removeStatusMessage(this.INDEXING_STATUS_BAR_KEY);
Expand Down
18 changes: 12 additions & 6 deletions packages/react-components/src/components/xy-output-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,13 @@ export class XYOutputComponent extends AbstractTreeOutputComponent<AbstractOutpu
// TODO Remove cpus parameters at some point. This is very specific to Trace Compass server
const xyTreeParameters = QueryHelper.selectionTimeQuery(
QueryHelper.splitRangeIntoEqualParts(this.props.range.getstart(), this.props.range.getEnd(), 1120), []); // , [], { 'cpus': [] }
const xyTreeResponse = (await this.props.tspClient.fetchXYTree(this.props.traceId, this.props.outputDescriptor.id, xyTreeParameters)).getModel();
const treeModel = xyTreeResponse.model;
if (treeModel) {
this.buildTreeNodes(treeModel);
const tspClientResponse = await this.props.tspClient.fetchXYTree(this.props.traceId, this.props.outputDescriptor.id, xyTreeParameters);
const xyTreeResponse = tspClientResponse.getModel();
if (tspClientResponse.isOk() && xyTreeResponse) {
const treeModel = xyTreeResponse.model;
if (treeModel) {
this.buildTreeNodes(treeModel);
}
}
}

Expand All @@ -241,8 +244,11 @@ export class XYOutputComponent extends AbstractTreeOutputComponent<AbstractOutpu
const xyDataParameters = QueryHelper.selectionTimeQuery(
QueryHelper.splitRangeIntoEqualParts(Math.trunc(start), Math.trunc(end), this.props.style.chartWidth), this.state.checkedSeries);

const xyDataResponse = (await this.props.tspClient.fetchXY(this.props.traceId, this.props.outputDescriptor.id, xyDataParameters)).getModel();
this.buildXYData(xyDataResponse.model.series);
const tspClientResponse = await this.props.tspClient.fetchXY(this.props.traceId, this.props.outputDescriptor.id, xyDataParameters);
const xyDataResponse = tspClientResponse.getModel();
if (tspClientResponse.isOk() && xyDataResponse) {
this.buildXYData(xyDataResponse.model.series);
}
}

private buildXYData(seriesObj: XYSeries[]) {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15664,9 +15664,9 @@ tslint@^5.20.1:
tsutils "^2.29.0"

tsp-typescript-client@next:
version "0.2.0-next.339f1e7"
resolved "https://registry.yarnpkg.com/tsp-typescript-client/-/tsp-typescript-client-0.2.0-next.339f1e7.tgz#de2190af8ff6e1773211d601d53e7755c4a142e6"
integrity sha512-cIPbP+uZpNOQTvRHJHQYdHdCZY7Qq5TJSPkbilN/qGG3LSgjfNQgXoWJfoA2RK/n1l3yOTs3CAN5YYqHtPFUlA==
version "0.2.0-next.2c0c62f"
resolved "https://registry.yarnpkg.com/tsp-typescript-client/-/tsp-typescript-client-0.2.0-next.2c0c62f.tgz#ffbd555e8e9c2a898b295c67bd0491ea14492502"
integrity sha512-wSF51oQPT+LMbpMEAwLP4KzNHkjoUZxFQ2nh7IYoEMkRhsmKS3yYCmRQFJcCe/QYk4Ez8RrWwGYd/HhFJJw1Dw==
dependencies:
node-fetch "^2.5.0"

Expand Down

0 comments on commit 31fdebf

Please sign in to comment.