Search in sources :

Example 6 with LocationAndInstallationStatus

use of se.light.assembly64.model.LocationAndInstallationStatus in project assembly64fx by freabemania.

the class InstallationService method install.

public void install(LocationAndInstallationStatus location, Artifact entry, boolean updateProgressWindow) throws Exception {
    CancelableTask cancelTask = CancelableTask.of();
    if (isRemoteArtifact(entry)) {
        if (!artifactsService.isInstalled(location, entry)) {
            Analytics.sendEvent("install_item", "artifact_" + entry.getName());
            installFull(location, entry);
        } else if (artifactsService.needsUpdate(location, entry)) {
            Analytics.sendEvent("update_item", "artifact_" + entry.getName());
            installDelta(location, entry);
        }
    } else {
        ProgressControlWrapper.getInstance().setProgressLabel("Installing local folder!!!");
        artifactsService.updateChecksumInPrivateFolder();
        FileUtils.copyDirectory(new File(localDbService.getPrivateDir()), LocalStorageUtil.getSubdirOrFile(LocalStorageUtil.getSubdirOrFile(location.getLocation(), "Misc"), localDbService.getPrivateDirName()));
        artifactsService.updateChecksumInInstallation(location);
    }
    if (updateProgressWindow) {
        updateProgressDialog(cancelTask);
    }
}
Also used : File(java.io.File) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 7 with LocationAndInstallationStatus

use of se.light.assembly64.model.LocationAndInstallationStatus in project assembly64fx by freabemania.

the class InstallationService method installEntry.

private File installEntry(LocationAndInstallationStatus installLocation, Artifact entry, String remotePath, String remoteName, String version, Boolean skipUnpack, Boolean updateProgressBar) throws Exception {
    CancelableTask cancelTask = CancelableTask.of();
    int ctr = 0;
    // to keep track of the progressupdates if something fails
    int progressUpdated = 0;
    if (entry.getType() == ArtifactType.REMOTE) {
        while (ctr < 3 && cancelTask.isRunning()) {
            LOGGER.info("Installing " + entry.getName());
            ProgressMessageBox.setMessage("Fetching " + entry.getName());
            ProgressControlWrapper.getInstance().setProgressLabel("Fetching file " + remoteName);
            File target = new File(pathService.getTmpFolderAsString() + remoteName);
            if (target.exists() && ftpService.registerDownload(remoteName, DOWNLOAD_STATUS.CHECK)) {
                ProgressControlWrapper.getInstance().setProgressLabel("Waiting for other worker to finish downloading " + remoteName);
                ProgressControlWrapper.getInstance().increaseCurrentProgressStep(1);
                while (true) {
                    if (!ftpService.registerDownload(remoteName, DOWNLOAD_STATUS.CHECK)) {
                        LOGGER.info(remoteName + " was downloaded by another thread");
                        break;
                    } else if (cancelTask.isCancelled()) {
                        return null;
                    }
                    Thread.sleep(500);
                }
            } else if (!target.exists()) {
                if (!ftpService.registerDownload(remoteName, DOWNLOAD_STATUS.ADD)) {
                    ftpService.getFile(remotePath, remoteName, target);
                    if (cancelTask.isCancelled()) {
                        return null;
                    }
                } else {
                    ProgressControlWrapper.getInstance().setProgressLabel("Waiting for other worker to finish downloading " + remoteName);
                    ProgressControlWrapper.getInstance().increaseCurrentProgressStep(1);
                    while (true) {
                        if (!ftpService.registerDownload(remoteName, DOWNLOAD_STATUS.CHECK)) {
                            LOGGER.info(remoteName + " was downloaded by another thread");
                            break;
                        } else if (cancelTask.isCancelled()) {
                            return null;
                        }
                        Thread.sleep(1000);
                    }
                }
            } else if (target.exists()) {
                LOGGER.info("Target " + target.getAbsolutePath() + " was already downloaded");
            }
            if (progressUpdated < 2 && updateProgressBar) {
                ProgressControlWrapper.getInstance().increaseProgress();
            }
            progressUpdated++;
            if (cancelTask.isCancelled()) {
                return null;
            }
            if (!skipUnpack) {
                try {
                    ProgressMessageBox.setMessage("Installing file " + entry.getName() + "at " + LocalStorageUtil.getSubdirOrFile(installLocation.getLocation(), entry.getPrefix()));
                    unzipService.extractZip(target, LocalStorageUtil.getSubdirOrFile(installLocation.getLocation(), entry.getPrefix()), entry);
                    // unzipService.extractZip(target, installLocation.getLocation(), entry);
                    ProgressControlWrapper.getInstance().increaseProgress();
                    if (progressUpdated < 2 && updateProgressBar) {
                        ProgressControlWrapper.getInstance().setProgressLabel("Fetched file " + remoteName);
                    }
                    progressUpdated++;
                    if (!cancelTask.isCancelled()) {
                        updateDb(installLocation, entry, version);
                    }
                    ProgressControlWrapper.getInstance().setProgressLabel("Done");
                    return target;
                } catch (Exception e) {
                    LOGGER.error("Something bad", e);
                    Analytics.sendEvent("invalid_zip", entry.getName());
                    FileUtils.forceDelete(target);
                    ctr++;
                }
            } else {
                ProgressControlWrapper.getInstance().setProgressLabel("Done");
                return target;
            }
        }
    }
    throw new IllegalStateException("U1nable to install entry " + remoteName);
}
Also used : File(java.io.File) IOException(java.io.IOException) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 8 with LocationAndInstallationStatus

use of se.light.assembly64.model.LocationAndInstallationStatus in project assembly64fx by freabemania.

the class Scheduler method addToQueue.

public void addToQueue(Integer installation, Artifact entry) {
    File location = UserService.getInstance().getLocation(installation).asFile();
    Optional<LocationAndArtifactToInstall> itemPossiblyAlreadyInList = workQueue.stream().filter(item -> item.getArtifact().getName().equals(entry.getName())).findFirst();
    LocationAndInstallationStatus tmp = LocationAndInstallationStatus.builder().location(location).id(installation).build();
    if (itemPossiblyAlreadyInList.isPresent()) {
        LOGGER.info("Adding " + entry.getName() + " " + installation + " to already in queue");
        ProgressControlWrapper.getInstance().addProgressSteps(countNofItems(tmp, entry));
        itemPossiblyAlreadyInList.get().addLocationAndInstallationStatus(tmp);
    } else if (currentlyInstalling.containsKey(entry.getName())) {
        LOGGER.info("Adding " + entry.getName() + " to current worker");
        ProgressControlWrapper.getInstance().addProgressSteps(countNofItems(tmp, entry));
        currentlyInstalling.get(entry.getName()).addLocationAndInstallationStatus(tmp);
    } else {
        Optional<Artifact> first = artifactsService.getArtifactsDb().stream().filter(item -> item.isMarkedForUpdate() || item.isUpdating()).findFirst();
        LocationAndInstallationStatus locationAndInstallation = LocationAndInstallationStatus.builder().location(location).id(installation).build();
        if (!first.isPresent()) {
            ProgressControlWrapper.getInstance().resetThreadIdMapping();
            ProgressControlWrapper.getInstance().setProgressSteps(countNofItems(locationAndInstallation, entry));
        } else {
            ProgressControlWrapper.getInstance().addProgressSteps(countNofItems(locationAndInstallation, entry));
        }
        entry.setMarkedForUpdate(true);
        // Main.resolveFXMain().refreshTree();
        Support.refreshTree();
        workQueue.offer(LocationAndArtifactToInstall.builder().artifact(entry).locationsAndInstallationStatus(LocationAndInstallationStatus.builder().location(location).id(installation).build()).build());
    }
}
Also used : LocationAndArtifactToInstall(se.light.assembly64.model.LocationAndArtifactToInstall) ArtifactDelta(se.light.assembly64.model.ArtifactDelta) LoggerFactory(org.slf4j.LoggerFactory) PoisonPill(se.light.assembly64.model.PoisonPill) HashMap(java.util.HashMap) PathService(se.light.assembly64.service.PathService) ArrayList(java.util.ArrayList) Support.getVersionAsInteger(se.light.assembly64.Support.getVersionAsInteger) ArtifactType(se.light.assembly64.model.ArtifactType) Map(java.util.Map) CancelableTask(se.light.assembly64.model.CancelableTask) Support.getExecutor(se.light.assembly64.Support.getExecutor) Logger(org.slf4j.Logger) BlockingQueue(java.util.concurrent.BlockingQueue) Artifact(se.light.assembly64.model.Artifact) ArtifactsService(se.light.assembly64.service.ArtifactsService) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) File(java.io.File) UserService(se.light.assembly64.service.UserService) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ProgressControlWrapper(se.light.assembly64.fx.ProgressControlWrapper) List(java.util.List) LocationAndArtifactToInstall(se.light.assembly64.model.LocationAndArtifactToInstall) SettingsController(se.light.assembly64.fx.SettingsController) Optional(java.util.Optional) InstallationService(se.light.assembly64.service.InstallationService) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) Optional(java.util.Optional) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) File(java.io.File)

Aggregations

File (java.io.File)6 CancelableTask (se.light.assembly64.model.CancelableTask)6 ArtifactDelta (se.light.assembly64.model.ArtifactDelta)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Support.getTodayDateAsBasicIsoString (se.light.assembly64.Support.getTodayDateAsBasicIsoString)4 Support.getVersionAsInteger (se.light.assembly64.Support.getVersionAsInteger)4 ProgressControlWrapper (se.light.assembly64.fx.ProgressControlWrapper)4 Artifact (se.light.assembly64.model.Artifact)4 ArtifactType (se.light.assembly64.model.ArtifactType)4 LocalDate (java.time.LocalDate)3 DateTimeFormatter (java.time.format.DateTimeFormatter)3 ChronoUnit (java.time.temporal.ChronoUnit)3