mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-26 20:21:33 +01:00
[rest] added systeminfo rest resource (#1608)
Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
parent
3ada0d0148
commit
bcee357829
@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||||
|
*
|
||||||
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-2.0
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*/
|
||||||
|
package org.openhab.core.io.rest.internal.resources;
|
||||||
|
|
||||||
|
import javax.annotation.security.RolesAllowed;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.openhab.core.auth.Role;
|
||||||
|
import org.openhab.core.io.rest.RESTConstants;
|
||||||
|
import org.openhab.core.io.rest.RESTResource;
|
||||||
|
import org.openhab.core.io.rest.internal.resources.beans.SystemInfoBean;
|
||||||
|
import org.osgi.service.component.annotations.Activate;
|
||||||
|
import org.osgi.service.component.annotations.Component;
|
||||||
|
import org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants;
|
||||||
|
import org.osgi.service.jaxrs.whiteboard.propertytypes.JSONRequired;
|
||||||
|
import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsApplicationSelect;
|
||||||
|
import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsName;
|
||||||
|
import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsResource;
|
||||||
|
|
||||||
|
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.security.SecurityRequirement;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class acts as a REST resource for system information.
|
||||||
|
*
|
||||||
|
* @author Kai Kreuzer - Initial contribution
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@JaxrsResource
|
||||||
|
@JaxrsName(SystemInfoResource.PATH_SYSTEMINFO)
|
||||||
|
@JaxrsApplicationSelect("(" + JaxrsWhiteboardConstants.JAX_RS_NAME + "=" + RESTConstants.JAX_RS_NAME + ")")
|
||||||
|
@JSONRequired
|
||||||
|
@Path(SystemInfoResource.PATH_SYSTEMINFO)
|
||||||
|
@RolesAllowed({ Role.ADMIN })
|
||||||
|
@SecurityRequirement(name = "oauth2", scopes = { "admin" })
|
||||||
|
@Tag(name = SystemInfoResource.PATH_SYSTEMINFO)
|
||||||
|
@NonNullByDefault
|
||||||
|
public class SystemInfoResource implements RESTResource {
|
||||||
|
|
||||||
|
/** The URI path to this resource */
|
||||||
|
public static final String PATH_SYSTEMINFO = "systeminfo";
|
||||||
|
|
||||||
|
@Activate
|
||||||
|
public SystemInfoResource() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Operation(summary = "Gets information about the system.", responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SystemInfoBean.class))) })
|
||||||
|
public Response getSystemInfo(@Context UriInfo uriInfo) {
|
||||||
|
|
||||||
|
final SystemInfoBean bean = new SystemInfoBean();
|
||||||
|
return Response.ok(bean).build();
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,7 @@ package org.openhab.core.io.rest.internal.resources.beans;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.core.OpenHAB;
|
import org.openhab.core.OpenHAB;
|
||||||
import org.openhab.core.io.rest.RESTConstants;
|
import org.openhab.core.io.rest.RESTConstants;
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ import org.openhab.core.io.rest.RESTConstants;
|
|||||||
* @author Kai Kreuzer - Initial contribution
|
* @author Kai Kreuzer - Initial contribution
|
||||||
* @author Yannick Schaus - Add runtime info
|
* @author Yannick Schaus - Add runtime info
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class RootBean {
|
public class RootBean {
|
||||||
|
|
||||||
public final String version = RESTConstants.API_VERSION;
|
public final String version = RESTConstants.API_VERSION;
|
||||||
@ -36,8 +38,6 @@ public class RootBean {
|
|||||||
public static class RuntimeInfo {
|
public static class RuntimeInfo {
|
||||||
public final String version = OpenHAB.getVersion();
|
public final String version = OpenHAB.getVersion();
|
||||||
public final String buildString = OpenHAB.buildString();
|
public final String buildString = OpenHAB.buildString();
|
||||||
public final String configFolder = OpenHAB.getConfigFolder();
|
|
||||||
public final String userdataFolder = OpenHAB.getUserDataFolder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Links {
|
public static class Links {
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||||
|
*
|
||||||
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-2.0
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*/
|
||||||
|
package org.openhab.core.io.rest.internal.resources.beans;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.openhab.core.OpenHAB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a java bean that is used to define system information for the REST interface.
|
||||||
|
*
|
||||||
|
* @author Kai Kreuzer - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class SystemInfoBean {
|
||||||
|
|
||||||
|
public final SystemInfo systemInfo = new SystemInfo();
|
||||||
|
|
||||||
|
public static class SystemInfo {
|
||||||
|
public final String configFolder = OpenHAB.getConfigFolder();
|
||||||
|
public final String userdataFolder = OpenHAB.getUserDataFolder();
|
||||||
|
public final String javaVersion = System.getProperty("java.version");
|
||||||
|
public final String osName = System.getProperty("os.name");
|
||||||
|
public final String osVersion = System.getProperty("os.version");
|
||||||
|
public final String osArchitecture = System.getProperty("os.arch");
|
||||||
|
public final int availableProcessors = Runtime.getRuntime().availableProcessors();
|
||||||
|
public final long freeMemory = Runtime.getRuntime().freeMemory();
|
||||||
|
public final long totalMemory = Runtime.getRuntime().totalMemory();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user