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 <vlad.arama@ericsson.com>
  • Loading branch information
vladarama authored and MatthewKhouzam committed May 14, 2024
1 parent 2ffaa40 commit f287f0f
Show file tree
Hide file tree
Showing 8 changed files with 411 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 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.internal.trace.server.jersey.rest.core.services.ServerInfoResponseImpl;
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();
ServerInfoResponseImpl responseValues = response.readEntity(ServerInfoResponseImpl.class);

assertNotNull("Server version should not be null", responseValues.getVersion());
assertNotNull("OS should not be null", responseValues.getOs());
assertNotNull("OS Architecture should not be null", responseValues.getOsArch());
assertNotNull("OS Version should not be null", responseValues.getOsVersion());
assertNotNull("CPU count should not be null", responseValues.getCpuCount());
assertNotNull("Max memory should not be null", responseValues.getMaxMemory());
assertNotNull("Product ID should not be null", responseValues.getProductId());

}

}
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
@@ -0,0 +1,76 @@
/**********************************************************************
* 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.model;

import io.swagger.v3.oas.annotations.media.Schema;

/**
* Contributes to the model used for TSP swagger-core annotations.
*
* @author Vlad Arama
*/
@Schema(description = "System Information Response")
public interface ServerInfoResponse {

/**
* @return Version in the format Major.Minor.Micro
*/
@Schema(required = true, description = "Version in the format Major.Minor.Micro")
String getVersion();

/**
* @return Build time or qualifier of the server version, if available
*/
@Schema(description = "Build time or qualifier of the server version, if available")
String getBuildTime();

/**
* @return Operating system name
*/
@Schema(required = true, description = "Operating system name")
String getOs();

/**
* @return Architecture of the operating system
*/
@Schema(description = "Architecture of the operating system")
String getOsArch();

/**
* @return Operating system version
*/
@Schema(description = "Operating system version")
String getOsVersion();

/**
* @return Number of CPUs available
*/
@Schema(description = "Number of CPUs available")
int getCpuCount();

/**
* @return Maximum memory available to the JVM in bytes
*/
@Schema(description = "Maximum memory available to the JVM in bytes")
long getMaxMemory();

/**
* @return Name of the launcher used, if available
*/
@Schema(description = "Name of the launcher used, if available")
String getLauncherName();

/**
* @return Product identifier for the trace server
*/
@Schema(required = true, description = "Product identifier for the trace server")
String getProductId();
}
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,87 @@
/*******************************************************************************
* 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 org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Version;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.ServerInfoResponse;

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.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
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 {
private static final String OS_NAME = "os.name"; //$NON-NLS-1$
private static final String OS_ARCH = "os.arch"; //$NON-NLS-1$
private static final String OS_VERSION = "os.version"; //$NON-NLS-1$
private static final String PRODUCT_ID = "eclipse.product"; //$NON-NLS-1$
private static final String LAUNCHER_NAME = "eclipse.launcher.name"; //$NON-NLS-1$
private static final String QUALIFIER = "qualifier"; //$NON-NLS-1$
private static final String SEPARATOR = "."; //$NON-NLS-1$
private static final String HARD_CODED_VERSION = "0.8.1"; //$NON-NLS-1$

/**
* Getter returning important information about the system, including server
* version, OS, CPU count, memory size, launcher name and product id.
*
* @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", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ServerInfoResponse.class)))
})
public Response getSystemInfo() {
IProduct product = Platform.getProduct();
ServerInfoResponseImpl response = new ServerInfoResponseImpl();

response.setOs(System.getProperty(OS_NAME));
response.setOsArch(System.getProperty(OS_ARCH));
response.setOsVersion(System.getProperty(OS_VERSION));
response.setCpuCount(Runtime.getRuntime().availableProcessors());
response.setMaxMemory(Runtime.getRuntime().maxMemory());
response.setProductId(System.getProperty(PRODUCT_ID));
response.setLauncherName(System.getProperty(LAUNCHER_NAME));

if (product != null) {
Version version = product.getDefiningBundle().getVersion();
response.setVersion(version.getMajor() + SEPARATOR + version.getMicro() + SEPARATOR + version.getMinor());
String qualifier = version.getQualifier();
if (!QUALIFIER.equalsIgnoreCase(qualifier) && qualifier != null) {
response.setBuildTime(qualifier);
}
} else {
response.setVersion(HARD_CODED_VERSION);
}

return Response.ok(response).build();
}

}
Loading

0 comments on commit f287f0f

Please sign in to comment.