Skip to content

Commit e57f3bd

Browse files
committed
server: Add get image 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., "IMAGE"). This commit introduces the required endpoint for fetching the images from the trace server based on the given configurable output id. [Added] A new GET endpoint for image data providers Signed-off-by: Kaveh Shahedi <kaveh.shahedi@ericsson.com>
1 parent 1c44a82 commit e57f3bd

File tree

6 files changed

+99
-4
lines changed

6 files changed

+99
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ public class ImageReportDataProvider implements IReportDataProvider {
118118
.setId(configuration.getId())
119119
.setName(configuration.getName())
120120
.setDescription(configuration.getDescription())
121-
.setProviderType(ProviderType.NONE)
121+
.setProviderType(ProviderType.REPORT)
122+
.setProviderSubType(ProviderType.IMAGE)
122123
.setConfiguration(configuration)
123124
.setCapabilities(new DataProviderCapabilities.Builder().setCanDelete(true).build())
124125
.build();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ private static IDataProviderDescriptor createDescriptor(IDataProviderDescriptor
182182
.setName(descriptor.getName())
183183
.setDescription(descriptor.getDescription())
184184
.setProviderType(descriptor.getType())
185+
.setProviderSubType(descriptor.getSubType())
185186
.setCapabilities(descriptor.getCapabilities())
186187
.setConfiguration(new TmfConfiguration.Builder()
187188
.setId(config.getId())

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: 7 additions & 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, REPORT, IMAGE, NONE
2626
}
2727

2828
/**
@@ -47,6 +47,12 @@ enum ProviderType {
4747
"Providers of type NONE have no data to visualize. Can be used for grouping purposes and/or as data provider configurator.")
4848
ProviderType getType();
4949

50+
/**
51+
* @return The provider sub-type.
52+
*/
53+
@Schema(description = "The provider sub-type. Can be used to group providers of the same type together.")
54+
ProviderType getSubType();
55+
5056
/**
5157
* @return The description.
5258
*/

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: 81 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;
@@ -74,6 +75,9 @@
7475
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.VTB;
7576
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.X_Y;
7677

78+
import java.io.File;
79+
import java.io.IOException;
80+
import java.nio.file.Files;
7781
import java.util.ArrayList;
7882
import java.util.Collection;
7983
import java.util.Collections;
@@ -1101,6 +1105,83 @@ private Response getTree(UUID expUUID, String outputId, QueryParameters queryPar
11011105
}
11021106
}
11031107

1108+
/**
1109+
* Query the provider for a report. Based on the given output, this
1110+
* endpoint will return a specific report, which can be an image, a
1111+
* textual data, a HTML, etc.
1112+
*
1113+
* @param expUUID
1114+
* desired experiment UUID
1115+
* @param outputId
1116+
* Output ID for the data provider to query
1117+
* @return {@link Response} with the corresponding report data
1118+
*/
1119+
@GET
1120+
@Path("/report/{outputId}")
1121+
@Tag(name = RPT)
1122+
@Produces({ MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON })
1123+
@Operation(summary = "API to get an image", responses = {
1124+
@ApiResponse(responseCode = "200", description = "Returns the image file", content = @Content(mediaType = "application/octet-stream")),
1125+
@ApiResponse(responseCode = "400", description = MISSING_PARAMETERS, content = @Content(schema = @Schema(implementation = String.class))),
1126+
@ApiResponse(responseCode = "404", description = PROVIDER_NOT_FOUND, content = @Content(schema = @Schema(implementation = String.class))),
1127+
@ApiResponse(responseCode = "500", description = "Error reading the image file", content = @Content(schema = @Schema(implementation = String.class)))
1128+
})
1129+
public Response getReport(
1130+
@Parameter(description = EXP_UUID) @PathParam("expUUID") UUID expUUID,
1131+
@Parameter(description = OUTPUT_ID) @PathParam("outputId") String outputId) {
1132+
1133+
if (outputId == null) {
1134+
return Response.status(Status.BAD_REQUEST).entity(MISSING_OUTPUTID).build();
1135+
}
1136+
1137+
TmfExperiment experiment = ExperimentManagerService.getExperimentByUUID(expUUID);
1138+
if (experiment == null) {
1139+
return Response.status(Status.NOT_FOUND).entity(NO_SUCH_TRACE).build();
1140+
}
1141+
1142+
IDataProviderDescriptor descriptor = getDescriptor(experiment, outputId);
1143+
if (descriptor == null || descriptor.getType() != ProviderType.REPORT) {
1144+
return Response.status(Status.NOT_FOUND).entity(NO_SUCH_PROVIDER).build();
1145+
}
1146+
1147+
ProviderType reportType = descriptor.getSubType();
1148+
if (reportType == null) {
1149+
return Response.status(Status.NOT_FOUND).entity(NO_SUCH_PROVIDER).build();
1150+
}
1151+
1152+
ITmfConfiguration config = descriptor.getConfiguration();
1153+
if (config == null) {
1154+
return Response.status(Status.NOT_FOUND).entity("No configuration found for this provider").build(); //$NON-NLS-1$
1155+
}
1156+
1157+
switch (reportType) {
1158+
case IMAGE:
1159+
String imagePath = (String) config.getParameters().get("path"); //$NON-NLS-1$
1160+
if (imagePath == null) {
1161+
return Response.status(Status.NOT_FOUND).entity("Image path not found in configuration").build(); //$NON-NLS-1$
1162+
}
1163+
1164+
File imageFile = new File(imagePath);
1165+
if (!imageFile.exists() || !imageFile.isFile()) {
1166+
return Response.status(Status.NOT_FOUND).entity("Image file not found").build(); //$NON-NLS-1$
1167+
}
1168+
1169+
try {
1170+
String contentType = Files.probeContentType(imageFile.toPath());
1171+
if (contentType == null) {
1172+
contentType = MediaType.APPLICATION_OCTET_STREAM;
1173+
}
1174+
1175+
return Response.ok(imageFile, contentType).build();
1176+
} catch (IOException e) {
1177+
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
1178+
}
1179+
//$CASES-OMITTED$
1180+
default:
1181+
return Response.status(Status.NOT_FOUND).entity("Unsupported report type").build(); //$NON-NLS-1$
1182+
}
1183+
}
1184+
11041185
/**
11051186
* Query the provider for styles
11061187
*

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration;
1717
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderCapabilities;
1818
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;
19+
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor.ProviderType;
1920
import org.eclipse.tracecompass.tmf.core.model.DataProviderCapabilities;
2021

2122
import com.fasterxml.jackson.core.JsonGenerator;
2223
import com.fasterxml.jackson.databind.SerializerProvider;
2324
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
2425

2526
/**
26-
* {@link StdSerializer} for {@link IDataProviderDescriptor} to avoid building intermediate
27-
* representations.
27+
* {@link StdSerializer} for {@link IDataProviderDescriptor} to avoid building
28+
* intermediate representations.
2829
*
2930
* @author Bernd Hufmann
3031
*/
@@ -53,6 +54,10 @@ public void serialize(IDataProviderDescriptor value, JsonGenerator gen, Serializ
5354
gen.writeStringField("name", value.getName()); //$NON-NLS-1$
5455
gen.writeStringField("description", value.getDescription()); //$NON-NLS-1$
5556
gen.writeStringField("type", value.getType().name()); //$NON-NLS-1$
57+
ProviderType subType = value.getSubType();
58+
if (subType != null) {
59+
gen.writeStringField("subType", subType.name()); //$NON-NLS-1$
60+
}
5661
ITmfConfiguration config = value.getConfiguration();
5762
if (config != null) {
5863
gen.writeObjectField("configuration", config); //$NON-NLS-1$

0 commit comments

Comments
 (0)