-
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
Showing
6 changed files
with
133 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 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")); | ||
|
||
} | ||
|
||
} | ||
|
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
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
72 changes: 72 additions & 0 deletions
72
...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,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(); | ||
} | ||
|
||
} |
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
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