Search in sources :

Example 1 with State

use of org.apache.felix.fileinstall.plugins.installer.State in project felix by apache.

the class DeploymentInstaller method invalidateAllUnits.

private void invalidateAllUnits(String reason) {
    List<File> affectedFiles = new LinkedList<>();
    List<InstallableUnitEvent> events = new LinkedList<>();
    withLock(this.unitsLock.writeLock(), () -> {
        for (Entry<File, InstallableUnitImpl> entry : this.units.entrySet()) {
            InstallableUnitImpl unit = entry.getValue();
            State currentState = unit.getState();
            if (EnumSet.of(State.RESOLVED, State.ERROR).contains(currentState)) {
                unit.setState(State.REMOVED);
                affectedFiles.add(entry.getKey());
                events.add(new InstallableUnitEvent(currentState, State.REMOVED, unit));
                debug("invalidated %s because: %s%n", entry.getKey(), reason);
            }
        }
    });
    notifyListeners(events);
    // Schedule re-resolution of the affected files.
    for (File file : affectedFiles) {
        putResolveJob(file);
    }
}
Also used : State(org.apache.felix.fileinstall.plugins.installer.State) JarFile(java.util.jar.JarFile) File(java.io.File) LinkedList(java.util.LinkedList) InstallableUnitEvent(org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)

Example 2 with State

use of org.apache.felix.fileinstall.plugins.installer.State in project felix by apache.

the class DeploymentInstaller method installArtifacts.

private List<Bundle> installArtifacts(InstallableUnitImpl unit) {
    Supplier<List<Bundle>> func = () -> {
        State oldState = unit.getState();
        unit.setState(State.INSTALLING);
        notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.INSTALLING, unit)));
        try {
            // Install Bundles
            Collection<Artifact> artifacts = unit.getArtifacts();
            List<String> locations = artifacts.stream().map(Artifact::getLocation).collect(Collectors.toList());
            List<Bundle> installed = this.frameworkInstaller.addLocations(unit, locations);
            // Start bundles
            for (Bundle bundle : installed) {
                if (!isFragment(bundle)) {
                    bundle.start();
                }
            }
            // Mark unit installed
            oldState = unit.getState();
            unit.setState(State.INSTALLED);
            notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.INSTALLED, unit)));
            return installed;
        } catch (BundleException | IOException e) {
            oldState = unit.getState();
            unit.setState(State.ERROR);
            unit.setErrorMessage(e.getMessage());
            if (log != null) {
                log.log(LogService.LOG_ERROR, "Error installing artifact(s)", e);
            }
            notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.ERROR, unit)));
            return Collections.emptyList();
        }
    };
    return withLock(this.unitsLock.writeLock(), func);
}
Also used : State(org.apache.felix.fileinstall.plugins.installer.State) Bundle(org.osgi.framework.Bundle) Collection(java.util.Collection) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Artifact(org.apache.felix.fileinstall.plugins.installer.Artifact) InstallableUnitEvent(org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)

Example 3 with State

use of org.apache.felix.fileinstall.plugins.installer.State in project felix by apache.

the class DeploymentInstaller method uninstallArtifacts.

private List<Bundle> uninstallArtifacts(InstallableUnitImpl unit) {
    List<Bundle> bundles = this.frameworkInstaller.removeSponsor(unit);
    // Mark unit uninstalled
    withLock(this.unitsLock.writeLock(), () -> {
        State oldState = unit.getState();
        if (unit.setState(State.REMOVED)) {
            notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.REMOVED, unit)));
        }
    });
    return bundles;
}
Also used : Bundle(org.osgi.framework.Bundle) State(org.apache.felix.fileinstall.plugins.installer.State) InstallableUnitEvent(org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)

Example 4 with State

use of org.apache.felix.fileinstall.plugins.installer.State in project felix by apache.

the class DeploymentInstaller method unsponsorUnit.

/**
 * Unsponsor the installable unit. Returns a promise which is resolved when the uninstall is completed.
 */
private Promise<List<Bundle>> unsponsorUnit(File file) {
    List<InstallableUnitEvent> events = new LinkedList<>();
    Promise<List<Bundle>> bundles = withLock(this.unitsLock.writeLock(), () -> {
        Promise<List<Bundle>> promise = Promises.resolved(Collections.emptyList());
        InstallableUnitImpl existing = this.units.remove(file);
        if (existing != null) {
            State origState = existing.getState();
            if (origState.equals(State.INSTALLED)) {
                promise = putUninstallJob(existing);
            }
            if (existing.setState(State.REMOVED)) {
                events.add(new InstallableUnitEvent(origState, State.REMOVED, existing));
            }
        }
        return promise;
    });
    notifyListeners(events);
    return bundles;
}
Also used : State(org.apache.felix.fileinstall.plugins.installer.State) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) InstallableUnitEvent(org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)

Example 5 with State

use of org.apache.felix.fileinstall.plugins.installer.State in project felix by apache.

the class DeploymentInstaller method replaceUnit.

private void replaceUnit(File file, State origState, InstallableUnitImpl newUnit) {
    Collection<InstallableUnitEvent> events = new ArrayList<>(2);
    events.add(new InstallableUnitEvent(origState, newUnit.getState(), newUnit));
    events.addAll(withLock(this.unitsLock.writeLock(), () -> {
        InstallableUnitImpl existing = this.units.put(file, newUnit);
        if (existing != null) {
            State oldState = existing.getState();
            if (existing.setState(State.REMOVED)) {
                return Collections.singleton(new InstallableUnitEvent(oldState, State.REMOVED, existing));
            }
        }
        return Collections.emptyList();
    }));
    notifyListeners(events);
}
Also used : State(org.apache.felix.fileinstall.plugins.installer.State) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) InstallableUnitEvent(org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)

Aggregations

State (org.apache.felix.fileinstall.plugins.installer.State)6 InstallableUnitEvent (org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)5 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 List (java.util.List)2 Bundle (org.osgi.framework.Bundle)2 File (java.io.File)1 Collection (java.util.Collection)1 JarFile (java.util.jar.JarFile)1 Artifact (org.apache.felix.fileinstall.plugins.installer.Artifact)1