Skip to content
Snippets Groups Projects
Commit f9798322 authored by aboeckle's avatar aboeckle
Browse files

OO-4463 Rest endpoint for sum of revisions size

parent 30a1ae54
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,7 @@ public class MonitoringWebService {
private static final MemoryWebService memoryWebService = new MemoryWebService();
private static final ThreadsWebService threadsWebService = new ThreadsWebService();
private static final OpenOLATStatisticsWebService ooStatsWebService = new OpenOLATStatisticsWebService();
private static final VFSStatsWebService vfsStatsWebService = new VFSStatsWebService();
public MonitoringWebService() {
//make Spring happy
......@@ -86,6 +87,12 @@ public class MonitoringWebService {
return threadsWebService;
}
@Path("revisionsSize")
public VFSStatsWebService getRevisionsSizeWS() {
return vfsStatsWebService;
}
/**
* Return the configuration of the monitoring, which probes are available,
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.restapi.system;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.persistence.DB;
import org.olat.restapi.system.vo.VFSStatsVO;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* <h3>Description:</h3>
*
* Initial Date: 21 juin 2010 <br>
* @author srosse, stephane.rosse@frentix.com, www.frentix.com
*/
public class VFSStatsWebService {
@Autowired
private DB dbInstance;
public VFSStatsWebService() {
CoreSpringFactory.autowireObject(this);
}
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getRevisionSizeXML() {
StringBuilder sb = new StringBuilder(256);
sb.append("select SUM(size) from vfsrevision");
List<Long> revisionsSize = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), Long.class)
.getResultList();
Long size = revisionsSize == null || revisionsSize.isEmpty() ? Long.valueOf(0) : revisionsSize.get(0);
dbInstance.commitAndCloseSession();
VFSStatsVO vo = new VFSStatsVO(size);
return Response.ok(vo).build();
}
}
\ No newline at end of file
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.restapi.system.vo;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* <h3>Description:</h3>
*
*
* Initial Date: 21 juin 2010 <br>
* @author srosse, stephane.rosse@frentix.com, www.frentix.com
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "vfsStatsVO")
public class VFSStatsVO {
@XmlAttribute(name="revisionsSize", required=true)
private long revisionsSize;
public VFSStatsVO() {
//make JAXB happy
}
public VFSStatsVO(long revisionsSize) {
this.revisionsSize = revisionsSize;
}
public long getRevisionsSize() {
return revisionsSize;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("revisionsSize=").append(getRevisionsSize());
return sb.toString();
}
}
......@@ -36,17 +36,18 @@ import org.olat.restapi.system.vo.MemoryStatisticsVO;
import org.olat.restapi.system.vo.MemoryVO;
import org.olat.restapi.system.vo.MonitoringInfosVO;
import org.olat.restapi.system.vo.OpenOLATStatisticsVO;
import org.olat.restapi.system.vo.StatusVO;
import org.olat.restapi.system.vo.ReleaseInfosVO;
import org.olat.restapi.system.vo.RepositoryStatisticsVO;
import org.olat.restapi.system.vo.RuntimeStatisticsVO;
import org.olat.restapi.system.vo.SessionsVO;
import org.olat.restapi.system.vo.StatusVO;
import org.olat.restapi.system.vo.TasksVO;
import org.olat.restapi.system.vo.ThreadStatisticsVO;
import org.olat.restapi.system.vo.ThreadVO;
import org.olat.restapi.system.vo.ThreadVOes;
import org.olat.restapi.system.vo.ThreadsVO;
import org.olat.restapi.system.vo.UserStatisticsVO;
import org.olat.restapi.system.vo.VFSStatsVO;
import org.olat.test.OlatRestTestCase;
/**
......@@ -427,4 +428,17 @@ public class SystemTest extends OlatRestTestCase {
conn.shutdown();
}
@Test
public void testVFSStats() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI systemUri = conn.getContextURI().path("system").path("monitoring").path("revisionsSize").build();
VFSStatsVO revisionsInfos = conn.get(systemUri, VFSStatsVO.class);
assertNotNull(revisionsInfos);
assertNotNull(revisionsInfos.getRevisionsSize());
conn.shutdown();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment