Skip to content

Commit

Permalink
trace-server: implement IdentifierService
Browse files Browse the repository at this point in the history
Signed-off-by: Vlad Arama <[email protected]>
  • Loading branch information
vladarama committed Apr 3, 2024
1 parent 869a327 commit 76d28a2
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Object, Object> 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"));

}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 76d28a2

Please sign in to comment.