Skip to content

Commit 8bfbd39

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 1a37907 commit 8bfbd39

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public class ImageReportDataProvider implements IReportDataProvider {
118118
.setId(configuration.getId())
119119
.setName(configuration.getName())
120120
.setDescription(configuration.getDescription())
121-
.setProviderType(ProviderType.NONE)
121+
.setProviderType(ProviderType.IMAGE)
122122
.setConfiguration(configuration)
123123
.setCapabilities(new DataProviderCapabilities.Builder().setCanDelete(true).build())
124124
.build();

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: 68 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.IMG;
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,70 @@ private Response getTree(UUID expUUID, String outputId, QueryParameters queryPar
11011105
}
11021106
}
11031107

1108+
/**
1109+
* Query the provider for an image-based data provider
1110+
*
1111+
* @param expUUID
1112+
* desired experiment UUID
1113+
* @param outputId
1114+
* Output ID for the data provider to query
1115+
* @return {@link Response} with the corresponding image
1116+
*/
1117+
@GET
1118+
@Path("/image/{outputId}")
1119+
@Tag(name = IMG)
1120+
@Produces({ MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON })
1121+
@Operation(summary = "API to get an image", responses = {
1122+
@ApiResponse(responseCode = "200", description = "Returns the image file", content = @Content(mediaType = "application/octet-stream")),
1123+
@ApiResponse(responseCode = "400", description = MISSING_PARAMETERS, content = @Content(schema = @Schema(implementation = String.class))),
1124+
@ApiResponse(responseCode = "404", description = PROVIDER_NOT_FOUND, content = @Content(schema = @Schema(implementation = String.class))),
1125+
@ApiResponse(responseCode = "500", description = "Error reading the image file", content = @Content(schema = @Schema(implementation = String.class)))
1126+
})
1127+
public Response getImage(
1128+
@Parameter(description = EXP_UUID) @PathParam("expUUID") UUID expUUID,
1129+
@Parameter(description = OUTPUT_ID) @PathParam("outputId") String outputId) {
1130+
1131+
if (outputId == null) {
1132+
return Response.status(Status.BAD_REQUEST).entity(MISSING_OUTPUTID).build();
1133+
}
1134+
1135+
TmfExperiment experiment = ExperimentManagerService.getExperimentByUUID(expUUID);
1136+
if (experiment == null) {
1137+
return Response.status(Status.NOT_FOUND).entity(NO_SUCH_TRACE).build();
1138+
}
1139+
1140+
IDataProviderDescriptor descriptor = getDescriptor(experiment, outputId);
1141+
if (descriptor == null || descriptor.getType() != ProviderType.IMAGE) {
1142+
return Response.status(Status.NOT_FOUND).entity(NO_SUCH_PROVIDER).build();
1143+
}
1144+
1145+
ITmfConfiguration config = descriptor.getConfiguration();
1146+
if (config == null) {
1147+
return Response.status(Status.NOT_FOUND).entity("No configuration found for this provider").build(); //$NON-NLS-1$
1148+
}
1149+
1150+
String imagePath = (String) config.getParameters().get("path"); //$NON-NLS-1$
1151+
if (imagePath == null) {
1152+
return Response.status(Status.NOT_FOUND).entity("Image path not found in configuration").build(); //$NON-NLS-1$
1153+
}
1154+
1155+
File imageFile = new File(imagePath);
1156+
if (!imageFile.exists() || !imageFile.isFile()) {
1157+
return Response.status(Status.NOT_FOUND).entity("Image file not found").build(); //$NON-NLS-1$
1158+
}
1159+
1160+
try {
1161+
String contentType = Files.probeContentType(imageFile.toPath());
1162+
if (contentType == null) {
1163+
contentType = MediaType.APPLICATION_OCTET_STREAM;
1164+
}
1165+
1166+
return Response.ok(imageFile, contentType).build();
1167+
} catch (IOException e) {
1168+
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
1169+
}
1170+
}
1171+
11041172
/**
11051173
* Query the provider for styles
11061174
*

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
@@ -98,6 +98,7 @@ public final class EndpointConstants {
9898
static final String DT = "Data Tree"; //$NON-NLS-1$
9999
static final String EXP = "Experiments"; //$NON-NLS-1$
100100
static final String IDF = "Identifier"; //$NON-NLS-1$
101+
static final String IMG = "Image"; //$NON-NLS-1$
101102
static final String OCG = "Output Configurations"; //$NON-NLS-1$
102103
static final String STY = "Styles"; //$NON-NLS-1$
103104
static final String TGR = "TimeGraph"; //$NON-NLS-1$

0 commit comments

Comments
 (0)