Skip to content

Commit

Permalink
server: Fix potential trace UUID mismatch when creating experiment model
Browse files Browse the repository at this point in the history
Don't rely on the order of traces array in experiment and trace UUIDs
stored in ExperimentManagerService to create TSP Experiment model.
Instead use the trace resources to create the TSP Trace model return
in the TSP Experiment Model.

Fixes eclipse-tracecompass-incubator#51

[Fixed] potential trace UUID mismatch when creating experiment model

Signed-off-by: Bernd Hufmann <[email protected]>
  • Loading branch information
bhufmann committed Jul 17, 2024
1 parent 4b14d71 commit cfa1308
Showing 1 changed file with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,17 @@
package org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

/**
* Experiment model for TSP
Expand Down Expand Up @@ -88,11 +82,8 @@ public Experiment(@JsonProperty("name") String name,
* @return the experiment model
*/
public static Experiment from(TmfExperiment experiment, UUID expUUID) {
Iterator<UUID> iter = ExperimentManagerService.getTraceUUIDs(expUUID).iterator();
// Get all the leaf traces from experiment
@NonNull List<@NonNull ITmfTrace> children = new ArrayList<>(TmfTraceManager.getTraceSet(experiment));
Set<Trace> traces = Sets.newLinkedHashSet(Lists.transform(children,
t -> Trace.from(t, iter.next())));
List<UUID> traceUUIDs = ExperimentManagerService.getTraceUUIDs(expUUID);
Set<Trace> traces = new LinkedHashSet<>(Lists.transform(traceUUIDs, uuid -> Trace.from(TraceManagerService.getTraceResource(uuid), uuid)));
return new Experiment(experiment.getName(),
expUUID,
experiment.getNbEvents(),
Expand Down

0 comments on commit cfa1308

Please sign in to comment.