diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/IdentifierServiceTest.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/IdentifierServiceTest.java new file mode 100644 index 000000000..9f4862dcc --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/IdentifierServiceTest.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2024 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.services; + +import static org.junit.Assert.assertNotNull; + +import java.util.Map; + +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.IdentifierService; +import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.utils.RestServerTest; +import org.junit.Test; + +/** + * Test the {@link IdentifierService} + * + * @author Vlad Arama + */ +public class IdentifierServiceTest extends RestServerTest { + + /** + * Test basic operations on the Identifier Service + */ + @Test + public void testIdentifier() { + WebTarget application = getApplicationEndpoint(); + WebTarget identifierEndpoint = application.path("identifier"); + + Response response = identifierEndpoint.request(MediaType.APPLICATION_JSON) + .get(); + Map responseValues = response.readEntity(Map.class); + assertNotNull(responseValues.get("server-version")); + assertNotNull(responseValues.get("os")); + assertNotNull(responseValues.get("cpu-count")); + assertNotNull(responseValues.get("memory")); + assertNotNull(responseValues.get("launcher-name")); + assertNotNull(responseValues.get("product-name")); + + } + +} + diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/webapp/TestWebApplication.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/webapp/TestWebApplication.java index 17e6837d2..0a5e92773 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/webapp/TestWebApplication.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/webapp/TestWebApplication.java @@ -15,6 +15,7 @@ import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.ExperimentManagerService; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.FilterService; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.HealthService; +import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.IdentifierService; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.TraceManagerService; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp.CORSFilter; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp.JacksonObjectMapperProvider; @@ -46,6 +47,7 @@ protected void registerResourcesAndMappers(ResourceConfig rc) { rc.register(TestDataProviderService.class); rc.register(FilterService.class); rc.register(HealthService.class); + rc.register(IdentifierService.class); rc.register(ConfigurationManagerService.class); rc.register(CORSFilter.class); rc.register(JacksonObjectMapperProvider.class); diff --git a/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 b/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 index e14505411..870b93717 100644 --- a/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 +++ b/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 @@ -83,6 +83,7 @@ public final class EndpointConstants { static final String DIA = "Diagnostic"; //$NON-NLS-1$ static final String DT = "Data Tree"; //$NON-NLS-1$ static final String EXP = "Experiments"; //$NON-NLS-1$ + static final String IDF = "Identifier"; //$NON-NLS-1$ static final String STY = "Styles"; //$NON-NLS-1$ static final String TGR = "TimeGraph"; //$NON-NLS-1$ static final String TRA = "Traces"; //$NON-NLS-1$ diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/IdentifierService.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/IdentifierService.java new file mode 100644 index 000000000..a113c46fa --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/IdentifierService.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2024 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services; + +import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.VERSION; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * + * Service to identify important information regarding the trace server and the system it is running on. + * + * @author Vlad Arama + * + */ +@Path("/identifier") +@Tag(name = EndpointConstants.IDF) +public class IdentifierService { + /** + * Getter returning important information about the system, including server version, OS, CPU count, memory size, launcher and product names. + * + * @return A JSON response containing the system's details. + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Operation(summary = "Retrieves system and server information", responses = { + @ApiResponse(responseCode = "200", description = "Successfully retrieved the system and server information") + }) + public Response getSystemInfo() { + int nbCpus = Runtime.getRuntime().availableProcessors(); + long memory = Runtime.getRuntime().totalMemory(); + String os = System.getProperty("os.name"); + String version = VERSION; + String launcherName = System.getProperty("eclipse.launcher.name"); + String executableName = System.getProperty("eclipse.product"); + + if (launcherName == null) { + launcherName = System.getProperty("eclipse.application"); + } + + Map status = new HashMap<>(); + status.put("server-version", version); + status.put("os", os); + status.put("cpu-count", nbCpus); + status.put("memory", memory); + status.put("launcher-name", launcherName); + status.put("product-name", executableName); + + return Response.ok(status).build(); + } + +} diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/TraceServerOpenApiResource.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/TraceServerOpenApiResource.java index 329aa24f6..215e32d98 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/TraceServerOpenApiResource.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/TraceServerOpenApiResource.java @@ -18,6 +18,7 @@ import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.DT; import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.EMAIL; import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.EXP; +import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.IDF; import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.LICENSE; import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.LICENSE_URL; import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.SERVER; @@ -50,6 +51,7 @@ @Tag(name = DIA, description = "Retrieve the server's status."), @Tag(name = DT, description = "Query data tree models (e.g. for statistics)."), @Tag(name = EXP, description = "Manage experiments on your server; an experiment represents a collection of traces, which can produce output models."), + @Tag(name = IDF, description = "Retrieve information about the server and the system it is running on."), @Tag(name = STY, description = "Retrieve styles for different outputs."), @Tag(name = TGR, description = "Query Time Graph models."), @Tag(name = TRA, description = "Manage physical traces on your server."), diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/WebApplication.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/WebApplication.java index f6a82f751..7a901855e 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/WebApplication.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/WebApplication.java @@ -31,6 +31,7 @@ import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.ExperimentManagerService; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.FilterService; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.HealthService; +import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.IdentifierService; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.TraceManagerService; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.TraceServerOpenApiResource; import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; @@ -137,6 +138,7 @@ protected void registerResourcesAndMappers(ResourceConfig rc) { rc.register(DataProviderService.class); rc.register(FilterService.class); rc.register(HealthService.class); + rc.register(IdentifierService.class); rc.register(CORSFilter.class); rc.register(JacksonObjectMapperProvider.class); EncodingFilter.enableFor(rc, GZipEncoder.class);