added old package removing feature and automatic dayly resync
This commit is contained in:
@@ -4,7 +4,7 @@ apply plugin: 'war'
|
|||||||
|
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
version = '1.0'
|
//version = '1.0'
|
||||||
|
|
||||||
logging.captureStandardOutput LogLevel.INFO
|
logging.captureStandardOutput LogLevel.INFO
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ dependencies {
|
|||||||
testCompile 'org.jboss.resteasy:resteasy-jackson-provider:3.0.11.Final'
|
testCompile 'org.jboss.resteasy:resteasy-jackson-provider:3.0.11.Final'
|
||||||
testCompile 'org.jboss.resteasy:resteasy-jaxb-provider:3.0.11.Final'
|
testCompile 'org.jboss.resteasy:resteasy-jaxb-provider:3.0.11.Final'
|
||||||
|
|
||||||
testCompile files('/opt/wildfly/bin/client/jboss-client.jar')
|
testCompile files('lib/jboss-client.jar')
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,13 +11,9 @@ import org.jpacrepo.pacbase.Parser;
|
|||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.ejb.Singleton;
|
import javax.ejb.*;
|
||||||
import javax.ejb.Startup;
|
|
||||||
import javax.ejb.TransactionManagement;
|
|
||||||
import javax.ejb.TransactionManagementType;
|
|
||||||
import javax.enterprise.concurrent.ManagedThreadFactory;
|
import javax.enterprise.concurrent.ManagedThreadFactory;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.naming.InitialContext;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
@@ -55,9 +51,10 @@ public class PacmanServiceEJB implements PacmanService
|
|||||||
|
|
||||||
private Map<String, PkgData> knownPkg;
|
private Map<String, PkgData> knownPkg;
|
||||||
|
|
||||||
@PostConstruct
|
@Schedule(hour = "3", minute = "00")
|
||||||
public void syncDB()
|
public void syncDB()
|
||||||
{
|
{
|
||||||
|
logger.log(Level.INFO, "Starting repository cleanup");
|
||||||
knownPkg = new HashMap<>();
|
knownPkg = new HashMap<>();
|
||||||
//Elimina i pacchetti sul DB che non esistono più nel filesystem
|
//Elimina i pacchetti sul DB che non esistono più nel filesystem
|
||||||
try
|
try
|
||||||
@@ -71,7 +68,7 @@ public class PacmanServiceEJB implements PacmanService
|
|||||||
File file = ctx.getFile(p);
|
File file = ctx.getFile(p);
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
{
|
{
|
||||||
logger.log(Level.INFO, String.format("Removing package %s", file.getName()));
|
logger.log(Level.INFO, String.format("Removing package %s which was not found in filesystem", file.getName()));
|
||||||
em.remove(p);
|
em.remove(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,11 +103,7 @@ public class PacmanServiceEJB implements PacmanService
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
deleteOld();
|
||||||
|
|
||||||
private void parseFile2(Parser p, File file) throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseFile(Parser p, File file) throws Exception
|
private void parseFile(Parser p, File file) throws Exception
|
||||||
@@ -171,6 +164,7 @@ public class PacmanServiceEJB implements PacmanService
|
|||||||
|
|
||||||
em.remove(pkg);
|
em.remove(pkg);
|
||||||
ut.commit();
|
ut.commit();
|
||||||
|
logger.log(Level.INFO,String.format("Package %s has been deleted", filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SyncWorker implements Runnable
|
private class SyncWorker implements Runnable
|
||||||
@@ -220,4 +214,30 @@ public class PacmanServiceEJB implements PacmanService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String deleteQuery = "SELECT p.fileName FROM PkgData p WHERE p.buildDate < :cutoff and p.name.id in \n" +
|
||||||
|
"(SELECT p2.name.id FROM PkgData p2 GROUP BY p2.name.id HAVING count(p2.name.id) > :minVersions\n)";
|
||||||
|
|
||||||
|
private void deleteOld()
|
||||||
|
{
|
||||||
|
TypedQuery<String> query = em.createQuery(deleteQuery, String.class);
|
||||||
|
Calendar cutoff = Calendar.getInstance();
|
||||||
|
cutoff.add(Calendar.YEAR, -2);
|
||||||
|
query.setParameter("cutoff", cutoff.getTime());
|
||||||
|
query.setParameter("minVersions", (long)2);
|
||||||
|
List<String> list = query.getResultList();
|
||||||
|
logger.log(Level.INFO, "Removing obsolete packages");
|
||||||
|
list.forEach((el) -> {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
deletePackage(el);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user