Commit a696f7a7 authored by Michael Ritter's avatar Michael Ritter
Browse files

Merge branch '32-rest-additions' into 'develop'

REST access for corrupt collections + files

Closes #32

See merge request !5
parents 92926de3 e3e76d59
...@@ -34,6 +34,11 @@ package edu.umiacs.ace.monitor.core; ...@@ -34,6 +34,11 @@ package edu.umiacs.ace.monitor.core;
import edu.umiacs.ace.monitor.log.LogEnum; import edu.umiacs.ace.monitor.log.LogEnum;
import edu.umiacs.ace.monitor.log.LogEventManager; import edu.umiacs.ace.monitor.log.LogEventManager;
import edu.umiacs.ace.util.PersistUtil; import edu.umiacs.ace.util.PersistUtil;
import org.apache.log4j.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
...@@ -42,10 +47,6 @@ import java.util.List; ...@@ -42,10 +47,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import org.apache.log4j.Logger;
/** /**
* *
...@@ -58,13 +59,13 @@ public class MonitoredItemManager { ...@@ -58,13 +59,13 @@ public class MonitoredItemManager {
MonitoredItemManager.class); MonitoredItemManager.class);
EntityManager em; EntityManager em;
// TODO: This may leak... // TODO: This may leak...
private Set<String> existingParents = new HashSet<String>(); private Set<String> existingParents = new HashSet<>();
public MonitoredItemManager( EntityManager em ) { public MonitoredItemManager( EntityManager em ) {
this.em = em; this.em = em;
} }
public List<MonitoredItem> listItemsBefore( Collection c, Date d ) { public Iterable<MonitoredItem> listItemsBefore( Collection c, Date d ) {
lock.lock(); lock.lock();
try { try {
......
...@@ -31,12 +31,17 @@ ...@@ -31,12 +31,17 @@
package edu.umiacs.ace.monitor.reporting; package edu.umiacs.ace.monitor.reporting;
import edu.umiacs.ace.monitor.log.*;
import edu.umiacs.ace.util.PersistUtil;
import edu.umiacs.ace.monitor.core.Collection; import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.log.LogEnum;
import edu.umiacs.ace.util.PersistUtil;
import edu.umiacs.sql.SQL; import edu.umiacs.sql.SQL;
import edu.umiacs.util.Argument; import edu.umiacs.util.Argument;
import edu.umiacs.util.Strings; import edu.umiacs.util.Strings;
import org.apache.log4j.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.sql.DataSource;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -45,10 +50,6 @@ import java.sql.Timestamp; ...@@ -45,10 +50,6 @@ import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
/** /**
* Log summary generator, this will generate a report summarizing all log entries * Log summary generator, this will generate a report summarizing all log entries
...@@ -168,7 +169,7 @@ public class SummaryGenerator extends ReportItemTypes { ...@@ -168,7 +169,7 @@ public class SummaryGenerator extends ReportItemTypes {
+ "MIN(logevent.ID), logevent.LOGTYPE, count(logevent.LOGTYPE)" + "MIN(logevent.ID), logevent.LOGTYPE, count(logevent.LOGTYPE)"
+ "FROM logevent WHERE logevent.COLLECTION_ID = ? " + "FROM logevent WHERE logevent.COLLECTION_ID = ? "
+ "GROUP BY logevent.LOGTYPE"); + "GROUP BY logevent.LOGTYPE");
ps.setLong(2, collection.getId()); ps.setLong(1, collection.getId());
} }
// create entries for each result, for start date and session id // create entries for each result, for start date and session id
......
package edu.umiacs.ace.rest; package edu.umiacs.ace.rest;
import edu.umiacs.ace.monitor.core.Collection; import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.core.MonitoredItem;
import edu.umiacs.ace.util.PersistUtil; import edu.umiacs.ace.util.PersistUtil;
import org.apache.log4j.Logger;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.Query; import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Get a listing of groups/collections in ACE
*
* Created by shake on 10/22/14. * Created by shake on 10/22/14.
*/ */
@Path("/") @Path("/")
public class ListController { public class ListController {
private static final Logger LOG = Logger.getLogger(ListController.class);
/** /**
* Get a list of all the groups registered in ACE * Get a list of all the groups registered in ACE
...@@ -64,7 +73,7 @@ public class ListController { ...@@ -64,7 +73,7 @@ public class ListController {
// Get all // Get all
Query q = em.createNamedQuery("Collection.listAllCollections"); Query q = em.createNamedQuery("Collection.listAllCollections");
List<Collection> results = q.getResultList(); List<Collection> results = q.getResultList();
List<Collection> groupless = new ArrayList<Collection>(); List<Collection> groupless = new ArrayList<>();
// Filter if the group == null // Filter if the group == null
for (Collection result : results) { for (Collection result : results) {
...@@ -75,4 +84,65 @@ public class ListController { ...@@ -75,4 +84,65 @@ public class ListController {
return groupless; return groupless;
} }
/**
* New API method to get all collections with query parameters
*
* @return
*/
@GET
@Path("collections")
@Produces(MediaType.APPLICATION_JSON)
public List<Collection> getCollections(@QueryParam("group") String group,
@QueryParam("active") Boolean active,
@QueryParam("corrupt") Boolean corrupt) {
EntityManager entityManager = PersistUtil.getEntityManager();
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Collection> cq = cb.createQuery(Collection.class);
Root<Collection> coll = cq.from(Collection.class);
cq.select(coll);
if (active != null && active) {
cq.where(cb.equal(coll.get("state"), 'A'));
}
if (corrupt != null && corrupt) {
cq.where(cb.equal(coll.get("state"), 'E'));
}
return entityManager.createQuery(cq).getResultList();
}
/**
* API for getting items in a collection. We can offer more query parameters (path, last seen, etc),
* but for now just query based on state
*
* @param id The id of the collection
* @param state The state of the monitored items
* @return a list of monitored items for the collection
*/
@GET
@Path("collections/{id}/items")
@Produces(MediaType.APPLICATION_JSON)
public List<MonitoredItemBean> getCollectionItems(@PathParam("id") Long id,
@QueryParam("state") String state) {
EntityManager entityManager = PersistUtil.getEntityManager();
Collection c = entityManager.find(Collection.class, id);
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<MonitoredItemBean> cq = cb.createQuery(MonitoredItemBean.class);
Root<MonitoredItem> mi = cq.from(MonitoredItem.class);
cq.select(cb.construct(MonitoredItemBean.class,
mi.get("id"), mi.get("path"),
mi.get("state"), mi.get("fileDigest"),
mi.get("size"), mi.get("lastSeen"),
mi.get("stateChange"), mi.get("lastVisited")));
cq.where(cb.equal(mi.get("parentCollection"), c));
if (state != null && !state.isEmpty()) {
cq.where(cb.equal(mi.get("state"), state));
}
return entityManager.createQuery(cq).getResultList();
}
} }
package edu.umiacs.ace.rest;
import java.util.Date;
/**
* Bean for displaying certain MonitoredItem properties in our api
*
* Created by shake on 11/14/16.
*/
public class MonitoredItemBean {
private Long id;
private String path;
private String state;
private String fileDigest;
private Long size;
private Date lastSeen;
private Date stateChange;
private Date lastVisited;
public MonitoredItemBean() {
}
public MonitoredItemBean(Long id, String path, char state, String fileDigest, Long size , Date lastSeen, Date stateChange, Date lastVisited) {
this.id = id;
this.path = path;
this.state = String.valueOf(state);
this.fileDigest = fileDigest;
this.size = size;
this.lastSeen = lastSeen;
this.stateChange = stateChange;
this.lastVisited = lastVisited;
}
public Long getId() {
return id;
}
public MonitoredItemBean setId(Long id) {
this.id = id;
return this;
}
public String getPath() {
return path;
}
public MonitoredItemBean setPath(String path) {
this.path = path;
return this;
}
public String getState() {
return state;
}
public MonitoredItemBean setState(String state) {
this.state = state;
return this;
}
public String getFileDigest() {
return fileDigest;
}
public MonitoredItemBean setFileDigest(String fileDigest) {
this.fileDigest = fileDigest;
return this;
}
public Long getSize() {
return size;
}
public MonitoredItemBean setSize(Long size) {
this.size = size;
return this;
}
public Date getLastSeen() {
return lastSeen;
}
public MonitoredItemBean setLastSeen(Date lastSeen) {
this.lastSeen = lastSeen;
return this;
}
public Date getStateChange() {
return stateChange;
}
public MonitoredItemBean setStateChange(Date stateChange) {
this.stateChange = stateChange;
return this;
}
public Date getLastVisited() {
return lastVisited;
}
public MonitoredItemBean setLastVisited(Date lastVisited) {
this.lastVisited = lastVisited;
return this;
}
}
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
*/ */
package edu.umiacs.ace.rest; package edu.umiacs.ace.rest;
import com.sun.istack.logging.Logger;
import edu.umiacs.ace.driver.irods.IrodsSetting; import edu.umiacs.ace.driver.irods.IrodsSetting;
import edu.umiacs.ace.monitor.core.Collection; import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.util.PersistUtil; import edu.umiacs.ace.util.PersistUtil;
import org.apache.log4j.Logger;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction; import javax.persistence.EntityTransaction;
import javax.persistence.NoResultException; import javax.persistence.NoResultException;
......
...@@ -49,6 +49,7 @@ public class KSFuture<V extends Runnable> extends KnownFuture<Submittable<V>> { ...@@ -49,6 +49,7 @@ public class KSFuture<V extends Runnable> extends KnownFuture<Submittable<V>> {
Submittable<V> result = getKnownResult(); Submittable<V> result = getKnownResult();
beforeExecute(result); beforeExecute(result);
super.run(); super.run();
// TODO: Check exception and print if true?
afterExecute(result); afterExecute(result);
} }
......
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
<exclude-unlisted-classes>true</exclude-unlisted-classes> <exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties> <properties>
<!-- <property name="toplink.logging.level" value="FINE"/> --> <!-- <property name="toplink.logging.level" value="FINE"/> -->
<!-- <property name="eclipselink.logging.file" value="/tmp/eclipselink.log"/> -->
<!-- <property name="eclipselink.logging.level" value="FINE"/> -->
<!-- <property name="eclipselink.logging.level.sql" value="FINE"/> -->
<property name="eclipselink.session.customizer" value="edu.umiacs.ace.util.DataSourceSessionCustomizer"/> <property name="eclipselink.session.customizer" value="edu.umiacs.ace.util.DataSourceSessionCustomizer"/>
<!-- <property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql"/> <!-- <property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql"/>
<property name="eclipselink.ddl-generation.output-mode" value="sql-script"/> <property name="eclipselink.ddl-generation.output-mode" value="sql-script"/>
......
...@@ -254,7 +254,7 @@ public final class HashTreeBuilder { ...@@ -254,7 +254,7 @@ public final class HashTreeBuilder {
// Find out how many nodes are going to be in the parent level // Find out how many nodes are going to be in the parent level
int parentNodeCount = size / order; int parentNodeCount = size / order;
List<HashTree.Node> parentLevel = List<HashTree.Node> parentLevel =
new ArrayList<HashTree.Node>(parentNodeCount); new ArrayList<>(parentNodeCount);
// Index for iterating through the nodes in this level // Index for iterating through the nodes in this level
int iterIndex = 0; int iterIndex = 0;
...@@ -290,7 +290,7 @@ public final class HashTreeBuilder { ...@@ -290,7 +290,7 @@ public final class HashTreeBuilder {
// Construct the parent node // Construct the parent node
List<HashTree.Node> childrenNodes = List<HashTree.Node> childrenNodes =
new ArrayList<HashTree.Node>(childrenNodeCount); new ArrayList<>(childrenNodeCount);
HashTree.Node parentNode = new HashTree.Node(); HashTree.Node parentNode = new HashTree.Node();
for ( int i = iterIndex, childIndex = 0; for ( int i = iterIndex, childIndex = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment