working version with new Kotlin frontend!!!
This commit is contained in:
@@ -110,7 +110,6 @@ public class PackageSynchronizerEJB implements FileSystemSynchronizer {
|
||||
long[] count = new long[]{0};
|
||||
long totalPackages = fileListStreamSupplier.get().count();
|
||||
var parser = new PkgDataParser(em);
|
||||
// List<PkgData> stack = new ArrayList<>();
|
||||
Con<Boolean> persistPackages = (Boolean drain) -> {
|
||||
while (inProgress.size() > maxInProgress || (drain && !inProgress.isEmpty())) {
|
||||
Optional.ofNullable(completionService.poll(1, TimeUnit.SECONDS))
|
||||
@@ -123,16 +122,6 @@ public class PackageSynchronizerEJB implements FileSystemSynchronizer {
|
||||
throw ee.getCause();
|
||||
}
|
||||
persistPackage(em, parser, pkgData, ++count[0], totalPackages);
|
||||
// stack.add(pkgData);
|
||||
// if(stack.size() >= 1000 || drain) {
|
||||
// parser.addNewDependencies(parser.getNewDependencies(stack));
|
||||
// parser.addNewPackagers(parser.getNewPackagers(stack));
|
||||
// parser.addNewPkgBases(parser.getNewPkgBases(stack));
|
||||
// parser.addNewLicenses(parser.getNewLicenses(stack));
|
||||
// while(!stack.isEmpty()) {
|
||||
// persistPackage(em, parser, stack.removeLast(), ++count[0], totalPackages);
|
||||
// }
|
||||
// }
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@@ -204,13 +204,16 @@ public class PacmanServiceEJB implements PacmanServiceLocal {
|
||||
else {
|
||||
try (OutputStream output = Files.newOutputStream(file)) {
|
||||
JWO.copy(input, output, 0x10000);
|
||||
var parser = new PkgDataParser(em);
|
||||
PkgData pkg = PkgDataParser.parseFile(file,
|
||||
CompressionFormatImpl.guess(Paths.get(fileName)));
|
||||
pkg.setFileName(fileName);
|
||||
pkg = parser.hydrateJPA(pkg);
|
||||
getPackage(pkg.getPkgId()).ifPresent((Con<PkgData>) (pkgData -> {
|
||||
em.remove(pkgData);
|
||||
Files.delete(ctx.getRepoFolder().resolve(pkgData.getFileName()));
|
||||
}));
|
||||
|
||||
logger.info("Persisting package {}", pkg.getFileName());
|
||||
em.persist(pkg);
|
||||
Files.move(file, ctx.getRepoFolder().resolve(fileName), StandardCopyOption.ATOMIC_MOVE);
|
||||
|
@@ -45,6 +45,7 @@ import net.woggioni.jpacrepo.api.wire.StringList;
|
||||
import net.woggioni.jpacrepo.config.AppConfig;
|
||||
import net.woggioni.jpacrepo.version.VersionComparator;
|
||||
import net.woggioni.jwo.CollectionUtils;
|
||||
import net.woggioni.jwo.Fun;
|
||||
import net.woggioni.jwo.JWO;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||
@@ -65,6 +66,8 @@ import java.util.NavigableMap;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.Optional;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.ToLongFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.woggioni.jpacrepo.api.security.Roles.WRITER;
|
||||
@@ -140,19 +143,17 @@ public class PacmanWebService {
|
||||
EntityTag etag = new EntityTag(Integer.toString(cachedMap.hashCode()), true);
|
||||
Response.ResponseBuilder builder = request.evaluatePreconditions(etag);
|
||||
if (builder == null) {
|
||||
|
||||
TreeMap<String, TreeMap<String, Map<String, NavigableSet<PkgTuple>>>> result = cachedMap.entrySet().stream().collect(
|
||||
TreeMap<String, TreeMap<String, Map<String, Map<CompressionFormat, PkgTuple>>>> result = cachedMap.entrySet().stream().collect(
|
||||
Collectors.groupingBy((Map.Entry<PkgId, PkgTuple> entry) -> entry.getKey().getArch(),
|
||||
TreeMap::new,
|
||||
Collectors.groupingBy((Map.Entry<PkgId, PkgTuple> entry) -> entry.getKey().getName(),
|
||||
TreeMap::new,
|
||||
Collectors.groupingBy((Map.Entry<PkgId, PkgTuple> entry) -> entry.getKey().getVersion(),
|
||||
() -> new TreeMap<>(VersionComparator.getInstance().reversed()),
|
||||
Collectors.mapping(
|
||||
Map.Entry::getValue,
|
||||
CollectionUtils.toUnmodifiableTreeSet(
|
||||
Comparator.comparing(PkgTuple::getFileName)
|
||||
)
|
||||
CollectionUtils.toMap(
|
||||
TreeMap::new,
|
||||
(Map.Entry<PkgId, PkgTuple> entry) -> entry.getKey().getCompressionFormat(),
|
||||
Map.Entry::getValue
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -305,6 +306,11 @@ public class PacmanWebService {
|
||||
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
public Response downloadTar(@FormParam("pkgs") String formData) {
|
||||
String[] files = URLDecoder.decode(formData, StandardCharsets.UTF_8).split(" ");
|
||||
Fun<java.nio.file.Path, Long> fun = Files::size;
|
||||
long estimatedSize = Arrays.stream(files)
|
||||
.map(ctx::getFile)
|
||||
.mapToLong(fun::apply)
|
||||
.sum();
|
||||
Arrays.stream(files)
|
||||
.filter(fileName -> !Files.exists(ctx.getFile(fileName)))
|
||||
.forEach(fileName -> {
|
||||
@@ -318,11 +324,11 @@ public class PacmanWebService {
|
||||
public void write(OutputStream output) {
|
||||
try(TarArchiveOutputStream taos = new TarArchiveOutputStream(output)) {
|
||||
for (String fname : files) {
|
||||
log.info(fname);
|
||||
java.nio.file.Path file = ctx.getFile(fname);
|
||||
try(InputStream input = Files.newInputStream(file)) {
|
||||
TarArchiveEntry entry = new TarArchiveEntry(fname);
|
||||
entry.setSize(Files.size(file));
|
||||
long fileSize = Files.size(file);
|
||||
entry.setSize(fileSize);
|
||||
taos.putArchiveEntry(entry);
|
||||
JWO.copy(input, taos, buffer);
|
||||
taos.closeArchiveEntry();
|
||||
@@ -334,7 +340,10 @@ public class PacmanWebService {
|
||||
}
|
||||
}
|
||||
};
|
||||
return Response.ok(stream).header("Content-Disposition", "attachment; filename=pkgs.tar").build();
|
||||
return Response.ok(stream)
|
||||
.header("Content-Length", estimatedSize)
|
||||
.header("Content-Disposition", "attachment; filename=pkgs.tar")
|
||||
.build();
|
||||
}
|
||||
|
||||
@GET
|
||||
|
@@ -151,7 +151,7 @@ public class Queries {
|
||||
public static TypedQuery<PkgData> getPackageById(EntityManager em, PkgId pkgId) {
|
||||
var cb = em.getCriteriaBuilder();
|
||||
var cq = cb.createQuery(PkgData.class);
|
||||
var root = cq.from(PkgData_.class_);
|
||||
var root = cq.from(PkgData.class);
|
||||
cq.select(root).where(
|
||||
cb.equal(
|
||||
root.get(PkgData_.pkgId),
|
||||
|
@@ -12,6 +12,9 @@
|
||||
<column name="size" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="installedsize" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="updtimestamp" type="TIMESTAMP WITH TIME ZONE"/>
|
||||
<column name="arch" type="VARCHAR(16)"/>
|
||||
<column name="md5sum" type="BYTEA"/>
|
||||
|
@@ -10,7 +10,7 @@ import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriBuilder;
|
||||
import lombok.SneakyThrows;
|
||||
import net.woggioni.jpacrepo.api.model.PkgData;
|
||||
import net.woggioni.jpacrepo.api.service.PacmanServiceRemote;
|
||||
import net.woggioni.jpacrepo.api.service.FileSystemSynchronizer;
|
||||
import net.woggioni.jpacrepo.impl.model.CompressionFormatImpl;
|
||||
import net.woggioni.jpacrepo.impl.model.PkgDataParser;
|
||||
import net.woggioni.jwo.Con;
|
||||
@@ -137,12 +137,12 @@ public class ClientTest {
|
||||
Context ctx = new InitialContext(prop);
|
||||
traverseJndiNode("/", context);
|
||||
// final PacmanService stateService = (PacmanService) ctx.lookup("/jpacrepo-1.0/remote/PacmanServiceEJB!service.PacmanService");
|
||||
final PacmanServiceRemote service = (PacmanServiceRemote) ctx.lookup(
|
||||
"/jpacrepo/PacmanServiceEJB!net.woggioni.jpacrepo.api.service.PacmanServiceRemote"
|
||||
final FileSystemSynchronizer service = (FileSystemSynchronizer) ctx.lookup(
|
||||
"/jpacrepo/PackageSynchronizerEJB!net.woggioni.jpacrepo.api.service.FileSystemSynchronizer"
|
||||
);
|
||||
// List<PkgData> pkgs = service.searchPackage("google-earth", null, null, 1, 10);
|
||||
// System.out.println(new XStream().toXML(pkgs));
|
||||
service.syncDB();
|
||||
service.syncDb();
|
||||
// service.searchPkgId("jre8-openjdk", null, null, null)
|
||||
// .stream()
|
||||
// .map(service::getPackage)
|
||||
|
Reference in New Issue
Block a user