Skip to content

Commit 367a3c6

Browse files
committed
server: Add get report data provider endpoint
Following the introduction of configurable reports data providers, the trace server can now face a new data provider type for image providers (i.e., "MIME"). This commit introduces the required endpoint for fetching the MIME reports from the trace server based on the given configurable output id. [Added] A new GET endpoint for MIME report data providers Signed-off-by: Kaveh Shahedi <kaveh.shahedi@ericsson.com>
1 parent 2096efe commit 367a3c6

File tree

7 files changed

+136
-5
lines changed

7 files changed

+136
-5
lines changed

callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/analysis/core/reports/IReportDataProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package org.eclipse.tracecompass.incubator.analysis.core.reports;
1212

1313
import org.eclipse.jdt.annotation.NonNull;
14+
import org.eclipse.tracecompass.internal.provisional.tmf.core.dataprovider.ITmfDataProviderConfigurationDataFetcher;
1415
import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration;
1516
import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSourceType;
1617
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;
@@ -25,7 +26,7 @@
2526
*
2627
* @author Kaveh Shahedi
2728
*/
28-
public interface IReportDataProvider {
29+
public interface IReportDataProvider extends ITmfDataProviderConfigurationDataFetcher {
2930

3031
/**
3132
* Type identifier for report providers

callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/analysis/core/reports/ImageReportDataProvider.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.FileOutputStream;
1616
import java.io.IOException;
1717
import java.nio.channels.FileChannel;
18+
import java.nio.file.Files;
1819
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Objects;
@@ -25,6 +26,7 @@
2526
import org.eclipse.core.runtime.Status;
2627
import org.eclipse.jdt.annotation.NonNull;
2728
import org.eclipse.tracecompass.incubator.internal.analysis.core.Activator;
29+
import org.eclipse.tracecompass.internal.provisional.tmf.core.dataprovider.TmfDataProviderConfigurationDataModel;
2830
import org.eclipse.tracecompass.tmf.core.config.ITmfConfigParamDescriptor;
2931
import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration;
3032
import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSourceType;
@@ -36,6 +38,8 @@
3638
import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException;
3739
import org.eclipse.tracecompass.tmf.core.model.DataProviderCapabilities;
3840
import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor;
41+
import org.eclipse.tracecompass.tmf.core.response.ITmfResponse;
42+
import org.eclipse.tracecompass.tmf.core.response.TmfModelResponse;
3943
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
4044

4145
/**
@@ -118,7 +122,7 @@ public class ImageReportDataProvider implements IReportDataProvider {
118122
.setId(configuration.getId())
119123
.setName(configuration.getName())
120124
.setDescription(configuration.getDescription())
121-
.setProviderType(ProviderType.NONE)
125+
.setProviderType(ProviderType.MIME)
122126
.setConfiguration(configuration)
123127
.setCapabilities(new DataProviderCapabilities.Builder().setCanDelete(true).build())
124128
.build();
@@ -251,4 +255,27 @@ public void validateConfiguration(@NonNull ITmfConfiguration configuration) thro
251255

252256
return getDescriptorFromConfig(trace, configuration);
253257
}
258+
259+
@Override
260+
public TmfModelResponse<TmfDataProviderConfigurationDataModel> getData(ITmfTrace trace, ITmfConfiguration configuration) throws Exception {
261+
// Get the image path from the configuration
262+
String imagePath = (String) configuration.getParameters().get(PATH);
263+
if (imagePath == null) {
264+
throw new TmfConfigurationException("Image path not found in configuration"); //$NON-NLS-1$
265+
}
266+
267+
File imageFile = new File(imagePath);
268+
if (!imageFile.exists() || !imageFile.isFile()) {
269+
throw new TmfConfigurationException("Image file not found"); //$NON-NLS-1$
270+
}
271+
272+
String contentType = Files.probeContentType(imageFile.toPath());
273+
if (contentType == null) {
274+
contentType = "application/octet-stream"; //$NON-NLS-1$
275+
}
276+
277+
TmfDataProviderConfigurationDataModel dataModel = new TmfDataProviderConfigurationDataModel(imageFile, contentType, imageFile.getName());
278+
279+
return new TmfModelResponse<>(dataModel, ITmfResponse.Status.COMPLETED, configuration.getName());
280+
}
254281
}

callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/analysis/core/reports/ReportsDataProviderFactory.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@
4848
import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor;
4949
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel;
5050
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataProvider;
51+
import org.eclipse.tracecompass.tmf.core.response.TmfModelResponse;
5152
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
5253
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
5354
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
5455
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
5556
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
5657
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
5758
import org.eclipse.tracecompass.incubator.internal.analysis.core.Activator;
59+
import org.eclipse.tracecompass.internal.provisional.tmf.core.dataprovider.TmfDataProviderConfigurationDataModel;
5860

5961
import com.google.common.collect.HashBasedTable;
6062
import com.google.common.collect.Table;
@@ -726,4 +728,18 @@ public void dispose() {
726728
fTmfConfigurationHierarchy.clear();
727729
}
728730

731+
@Override
732+
public TmfModelResponse<TmfDataProviderConfigurationDataModel> getData(ITmfTrace trace, ITmfConfiguration configuration) throws Exception {
733+
ReportProviderType reportType = getReportType(configuration);
734+
IReportDataProvider provider = ReportsDataProviderRegistry.getProvider(reportType);
735+
if (provider == null) {
736+
throw new TmfConfigurationException("No provider found for report type"); //$NON-NLS-1$
737+
}
738+
739+
if (provider instanceof ReportsDataProviderFactory) {
740+
throw new TmfConfigurationException("Cannot get data from the report factory"); //$NON-NLS-1$
741+
}
742+
743+
return provider.getData(trace, configuration);
744+
}
729745
}

trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/DataProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface DataProvider {
2222
* The provider types.
2323
*/
2424
enum ProviderType {
25-
TABLE, TREE_TIME_XY, TIME_GRAPH, DATA_TREE, NONE
25+
TABLE, TREE_TIME_XY, TIME_GRAPH, DATA_TREE, MIME, NONE
2626
}
2727

2828
/**

trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/DataProviderService.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.EXP_UUID;
3636
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.FILTER_QUERY_PARAMETERS;
3737
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.FILTER_QUERY_PARAMETERS_EX;
38+
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.RPT;
3839
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.INDEX;
3940
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.INDEX_EX;
4041
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.INVALID_PARAMETERS;
@@ -50,7 +51,9 @@
5051
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.MARKER_SET_ID;
5152
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.MISSING_OUTPUTID;
5253
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.MISSING_PARAMETERS;
54+
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.MISSING_SUBTYPE;
5355
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.NO_PROVIDER;
56+
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.NO_SUCH_CONFIGURATION;
5457
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.NO_SUCH_CONFIGURATION_TYPE;
5558
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.NO_SUCH_DERIVED_PROVIDER;
5659
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.NO_SUCH_PROVIDER;
@@ -133,6 +136,8 @@
133136
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.TreeModelWrapper;
134137
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.VirtualTableModelWrapper;
135138
import org.eclipse.tracecompass.internal.analysis.timing.core.event.matching.EventMatchingLatencyAnalysis;
139+
import org.eclipse.tracecompass.internal.provisional.tmf.core.dataprovider.ITmfDataProviderConfigurationDataFetcher;
140+
import org.eclipse.tracecompass.internal.provisional.tmf.core.dataprovider.TmfDataProviderConfigurationDataModel;
136141
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.table.ITmfVirtualTableDataProvider;
137142
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.table.ITmfVirtualTableModel;
138143
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.table.IVirtualTableLine;
@@ -1101,6 +1106,87 @@ private Response getTree(UUID expUUID, String outputId, QueryParameters queryPar
11011106
}
11021107
}
11031108

1109+
/**
1110+
* Query the provider for a MIME report. Based on the given output, this
1111+
* endpoint will return a specific report, which can be an image, a
1112+
* textual data, a HTML, etc.
1113+
*
1114+
* @param expUUID
1115+
* desired experiment UUID
1116+
* @param outputId
1117+
* Output ID for the data provider to query
1118+
* @return {@link Response} with the corresponding report data
1119+
*/
1120+
@GET
1121+
@Path("/report/{outputId}")
1122+
@Tag(name = RPT)
1123+
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN })
1124+
@Operation(summary = "API to get a MIME report", responses = {
1125+
@ApiResponse(responseCode = "200", description = "Returns the report data"),
1126+
@ApiResponse(responseCode = "400", description = MISSING_PARAMETERS, content = @Content(schema = @Schema(implementation = String.class))),
1127+
@ApiResponse(responseCode = "404", description = "Provider not found, missing subtype, or requested resource not found", content = @Content(schema = @Schema(implementation = String.class))),
1128+
@ApiResponse(responseCode = "500", description = "Error retrieving the report data", content = @Content(schema = @Schema(implementation = String.class))),
1129+
})
1130+
public Response getReport(
1131+
@Parameter(description = EXP_UUID) @PathParam("expUUID") UUID expUUID,
1132+
@Parameter(description = OUTPUT_ID) @PathParam("outputId") String outputId) {
1133+
1134+
if (outputId == null) {
1135+
return Response.status(Status.BAD_REQUEST).entity(MISSING_OUTPUTID).build();
1136+
}
1137+
1138+
TmfExperiment experiment = ExperimentManagerService.getExperimentByUUID(expUUID);
1139+
if (experiment == null) {
1140+
return Response.status(Status.NOT_FOUND).entity(NO_SUCH_TRACE).build();
1141+
}
1142+
1143+
IDataProviderDescriptor descriptor = getDescriptor(experiment, outputId);
1144+
if (descriptor == null) {
1145+
return Response.status(Status.NOT_FOUND).entity(NO_SUCH_PROVIDER).build();
1146+
}
1147+
1148+
if (descriptor.getType() != ProviderType.MIME) {
1149+
return Response.status(Status.NOT_FOUND).entity("The requested output is not a MIME report").build(); //$NON-NLS-1$"
1150+
}
1151+
1152+
ITmfConfiguration config = descriptor.getConfiguration();
1153+
if (config == null) {
1154+
return Response.status(Status.NOT_FOUND).entity(NO_SUCH_CONFIGURATION).build();
1155+
}
1156+
1157+
IDataProviderFactory factory = manager.getFactory(REPORTS_FACTORY_ID);
1158+
if (factory == null) {
1159+
return Response.status(Status.NOT_FOUND).entity("Report factory not found").build(); //$NON-NLS-1$"
1160+
}
1161+
1162+
ITmfDataProviderConfigurationDataFetcher dataFetcher = factory.getAdapter(ITmfDataProviderConfigurationDataFetcher.class);
1163+
if (dataFetcher == null) {
1164+
return Response.status(Status.NOT_FOUND).entity("Report data fetcher not found").build(); //$NON-NLS-1$ "
1165+
}
1166+
1167+
try {
1168+
TmfModelResponse<TmfDataProviderConfigurationDataModel> reportResponse = dataFetcher.getData(experiment, config);
1169+
if (reportResponse == null) {
1170+
return Response.status(Status.NOT_FOUND).entity("Report data not found").build(); //$NON-NLS-1$
1171+
}
1172+
1173+
if (reportResponse.getStatus() != ITmfResponse.Status.COMPLETED) {
1174+
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(reportResponse.getStatusMessage()).build();
1175+
}
1176+
1177+
TmfDataProviderConfigurationDataModel responseModel = reportResponse.getModel();
1178+
if (responseModel == null) {
1179+
return Response.status(Status.NOT_FOUND).entity("Report data model not found").build(); //$NON-NLS-1$
1180+
}
1181+
1182+
return Response.ok(responseModel.getContent(), responseModel.getContentType()).build();
1183+
} catch (TmfConfigurationException e) {
1184+
return Response.status(Status.NOT_FOUND).entity(e.getMessage()).build();
1185+
} catch (Exception e) {
1186+
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
1187+
}
1188+
}
1189+
11041190
/**
11051191
* Query the provider for styles
11061192
*

trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/EndpointConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public final class EndpointConstants {
9999
static final String EXP = "Experiments"; //$NON-NLS-1$
100100
static final String IDF = "Identifier"; //$NON-NLS-1$
101101
static final String OCG = "Output Configurations"; //$NON-NLS-1$
102+
static final String RPT = "Report"; //$NON-NLS-1$
102103
static final String STY = "Styles"; //$NON-NLS-1$
103104
static final String TGR = "TimeGraph"; //$NON-NLS-1$
104105
static final String TRA = "Traces"; //$NON-NLS-1$

trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/DataProviderDescriptorSerializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
2424

2525
/**
26-
* {@link StdSerializer} for {@link IDataProviderDescriptor} to avoid building intermediate
27-
* representations.
26+
* {@link StdSerializer} for {@link IDataProviderDescriptor} to avoid building
27+
* intermediate representations.
2828
*
2929
* @author Bernd Hufmann
3030
*/

0 commit comments

Comments
 (0)