-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trace-server: implement
IdentifierService
Signed-off-by: Vlad Arama <[email protected]>
- Loading branch information
1 parent
2ffaa40
commit f287f0f
Showing
8 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...compass/incubator/trace/server/jersey/rest/core/tests/services/IdentifierServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...acecompass/incubator/internal/trace/server/jersey/rest/core/model/ServerInfoResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...ecompass/incubator/internal/trace/server/jersey/rest/core/services/IdentifierService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
Oops, something went wrong.