Search in sources :

Example 36 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class FabricFeaturesServiceImpl method getFeatures.

private Map<String, Map<String, Feature>> getFeatures(Iterable<Repository> repositories) throws Exception {
    Map<String, Map<String, Feature>> features = new HashMap<String, Map<String, Feature>>();
    for (Repository repo : repositories) {
        try {
            for (Feature f : repo.getFeatures()) {
                if (features.get(f.getName()) == null) {
                    Map<String, Feature> versionMap = new TreeMap<String, Feature>();
                    versionMap.put(f.getVersion(), f);
                    features.put(f.getName(), versionMap);
                } else {
                    features.get(f.getName()).put(f.getVersion(), f);
                }
            }
        } catch (Exception ex) {
            LOGGER.debug("Could not load features from %s.", repo.getURI());
        }
    }
    return features;
}
Also used : Repository(org.apache.karaf.features.Repository) Feature(org.apache.karaf.features.Feature) InvalidComponentException(io.fabric8.api.InvalidComponentException)

Example 37 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class CachingGitDataStoreTest method testDataStore.

@Test
public void testDataStore() throws Exception {
    // dataStore.getDefaultVersion();
    String defaultVersion = null;
    assertEquals("defaultVersion", "1.0", defaultVersion);
    // now lets import some data - using the old non-git file layout...
    String importPath = basedir + "/../fabric8-karaf/src/main/resources/distro/fabric";
    if (useOldImportFormat) {
        assertFolderExists(importPath);
        try {
            dataStore.importFromFileSystem(importPath);
        } catch (Exception e) {
        // Ignore exception about missing url handlers. Not needed for this test anyway.
        }
        assertHasVersion(defaultVersion);
    } else {
        String prefix = importPath + "/fabric";
        String profileImport = prefix + "/configs/versions/1.0/profiles";
        assertFolderExists(profileImport);
        // dataStore.importFromFileSystem(new File(profileImport), "fabric",
        // "1.0", true);
        assertHasVersion(defaultVersion);
    }
    remote.checkout().setName("1.0").call();
    String importedProfile = "example-dozer";
    String profile = importedProfile;
    assertProfileExists(defaultVersion, profile);
    // assertFolderExists("Should have imported an mq/ReadMe.md file!",
    // getLocalGitFile("fabric/profiles/mq/ReadMe.md"));
    String version = "1.1";
    assertCreateVersion("1.0", version);
    assertProfileConfiguration(version, importedProfile, Constants.AGENT_PID, "attribute.parents", "feature-camel");
    assertProfileTextFileConfigurationContains(version, "example-camel-mq", "camel.xml", "http://camel.apache.org/schema/blueprint");
    /*
         * List<String> fileNames = dataStore.getConfigurationFileNames(version,
         * "example-camel-mq"); assertNotNull("Should have some file names",
         * fileNames); assertTrue("Should have some file names",
         * fileNames.size() > 0); assertTrue("Should contain 'came",
         * fileNames.size() > 0);
         * assertCollectionContains("configurationFileNames", fileNames,
         * "camel.xml");
         */
    // lets test the profile attributes
    // dataStore.getProfileAttributes(version, importedProfile);
    Map<String, String> profileAttributes = Collections.emptyMap();
    String parent = profileAttributes.get("parents");
    assertEquals(importedProfile + ".profileAttributes[parent]", "feature-camel", parent);
    System.out.println("Profile attributes: " + profileAttributes);
    String profileAttributeKey = "myKey";
    String expectedProfileAttributeValue = "myValue";
    // dataStore.setProfileAttribute(version, importedProfile, profileAttributeKey, expectedProfileAttributeValue);
    // profileAttributes = dataStore.getProfileAttributes(version, importedProfile);
    System.out.println("Profile attributes: " + profileAttributes);
    assertMapContains("Profile attribute[" + profileAttributeKey + "]", profileAttributes, profileAttributeKey, expectedProfileAttributeValue);
    String hawtioRepoKey = "repository.hawtio";
    // dataStore.getConfiguration(version, "hawtio", Constants.AGENT_PID);
    Map<String, String> hawtioAttrbutes = Collections.emptyMap();
    String currentHawtRepo = hawtioAttrbutes.get(hawtioRepoKey);
    System.out.println("Current repository.hawtio: " + currentHawtRepo);
    // now lets write via the hawtio API
    FabricGitFacade hawtio = new FabricGitFacade();
    hawtio.bindGitDataStoreForTesting(dataStore);
    hawtio.activateForTesting();
    /* String hawtioPropertyFile = "/fabric/profiles/" + dataStore.convertProfileIdToDirectory("hawtio") + "/" + Constants.AGENT_PID + ".properties";
        hawtio.write(version, hawtioPropertyFile, "My commit message", "me", "me@apache.org", "# new file\n" + hawtioRepoKey + " = "
                + "mvn\\:io.hawt/hawtio-karaf/myNewVersion/xml/features" + "\n");
        */
    // dataStore.getConfiguration(version, "hawtio", Constants.AGENT_PID);
    hawtioAttrbutes = Collections.emptyMap();
    String actual = hawtioAttrbutes.get(hawtioRepoKey);
    assertEquals("should have found the updated hawtio repo key", "mvn:io.hawt/hawtio-karaf/myNewVersion/xml/features", actual);
    // lets check that the file configurations recurses into folders
    // Map<String, byte[]> tomcatFileConfigurations = dataStore.getFileConfigurations("1.0", "controller-tomcat");
    // assertHasFileConfiguration(tomcatFileConfigurations, "tomcat/conf/server.xml.mvel");
    /* 
        Collection<String> schemas = dataStore.listFiles("1.0", Arrays.asList("example-dozer"), "schemas");
        assertNotNull(schemas);
        assertContainerEquals("schemas for example-dozer", Arrays.asList("invoice.xsd"), new ArrayList<String>(schemas));
         */
    // check we don't accidentally create a profile
    String profileNotCreated = "shouldNotBeCreated";
    // assertEquals("Should not create profile: " + profileNotCreated, null, dataStore.getProfile(version, profileNotCreated, false));
    assertProfileNotExists(defaultVersion, profileNotCreated);
    // assertFolderNotExists(getLocalGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(profileNotCreated)));
    // now lets create some profiles in this new version
    String newProfile = "myNewProfile";
    // dataStore.createProfile(version, newProfile);
    assertProfileExists(version, newProfile);
    // lazy create a profile
    String anotherNewProfile = "anotherNewProfile";
    // dataStore.getProfile(version, anotherNewProfile, true);
    assertProfileExists(version, anotherNewProfile);
    version = "1.2";
    assertCreateVersion("1.1", version);
    // check this version has the profile too
    assertProfileExists(version, newProfile);
    assertProfileExists(version, profile);
    // now lets delete a profile
    dataStore.deleteProfile(version, newProfile);
    assertProfileNotExists(version, newProfile);
    // lets check the remote repo
    remote.checkout().setName("1.1").call();
    assertProfileExists("1.1", profile);
    assertProfileExists("1.1", newProfile);
    // assertFolderExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(profile)));
    // assertFolderExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(newProfile)));
    remote.checkout().setName("1.2").call();
    assertProfileExists("1.2", profile);
    assertProfileNotExists("1.2", newProfile);
    // assertFolderExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(profile)));
    // assertFolderNotExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(newProfile)));
    remote.checkout().setName("1.0").call();
    // assertFolderExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(profile)));
    // assertFolderNotExists(getRemoteGitFile("fabric/profiles/" +
    // dataStore.convertProfileIdToDirectory(newProfile)));
    // delete version 1.2
    assertHasVersion("1.1");
    assertHasVersion("1.2");
    // dataStore.removeVersion("1.2");
    assertHasVersion("1.1");
    assertHasNotVersion("1.2");
    Collection<String> remoteBranches = RepositoryUtils.getBranches(remote.getRepository());
    System.out.println("Remote branches after delete: " + remoteBranches);
}
Also used : FabricGitFacade(io.fabric8.git.hawtio.FabricGitFacade) IOException(java.io.IOException) Test(org.junit.Test)

Example 38 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class ServiceImpl method featureUpdatesInPatch.

/**
 * Returns a list of {@link FeatureUpdate} for single patch, taking into account already discovered updates
 * @param patch
 * @param updatesForFeatureKeys
 * @param kind
 * @return
 */
private List<FeatureUpdate> featureUpdatesInPatch(Patch patch, Map<String, FeatureUpdate> updatesForFeatureKeys, PatchKind kind) throws Exception {
    Set<String> addedRepositoryNames = new HashSet<>();
    HashMap<String, Repository> after = null;
    try {
        List<FeatureUpdate> updatesInThisPatch = new LinkedList<>();
        /*
             * Two pairs of features makes feature names not enough to be a key:
             * <feature name="openjpa" description="Apache OpenJPA 2.2.x persistent engine support" version="2.2.2" resolver="(obr)">
             * <feature name="openjpa" description="Apache OpenJPA 2.3.x persistence engine support" version="2.3.0" resolver="(obr)">
             * and
             * <feature name="activemq-camel" version="5.11.0.redhat-621039" resolver="(obr)" start-level="50">
             * <feature name="activemq-camel" version="1.2.0.redhat-621039" resolver="(obr)">
             */
        // install the new feature repos, tracking the set the were
        // installed before and after
        // (e.g, "karaf-enterprise-2.4.0.redhat-620133" -> Repository)
        Map<String, Repository> before = new HashMap<>(getAvailableFeatureRepositories());
        for (String url : patch.getPatchData().getFeatureFiles()) {
            featuresService.addRepository(new URI(url));
        }
        after = getAvailableFeatureRepositories();
        // track which old repos provide which features to find out if we have new repositories for those features
        // key is name|version (don't expect '|' to be part of name...)
        // assume that [feature-name, feature-version{major,minor,0,0}] is defined only in single repository
        Map<String, String> featuresInOldRepositories = new HashMap<>();
        // key is only name, without version - used when there's single feature in old and in new repositories
        MultiMap<String, String> singleFeaturesInOldRepositories = new MultiMap<>();
        Map<String, Version> actualOldFeatureVersions = new HashMap<>();
        for (Repository existingRepository : before.values()) {
            for (Feature feature : existingRepository.getFeatures()) {
                Version v = Utils.getOsgiVersion(feature.getVersion());
                Version lowestUpdateableVersion = new Version(v.getMajor(), v.getMinor(), 0);
                // assume that we can update feature XXX-2.2.3 to XXX-2.2.142, but not to XXX-2.3.0.alpha-1
                String key = String.format("%s|%s", feature.getName(), lowestUpdateableVersion.toString());
                featuresInOldRepositories.put(key, existingRepository.getURI().toString());
                singleFeaturesInOldRepositories.put(feature.getName(), existingRepository.getURI().toString());
                actualOldFeatureVersions.put(key, v);
            }
        }
        // Use the before and after set to figure out which repos were added.
        addedRepositoryNames = new HashSet<>(after.keySet());
        addedRepositoryNames.removeAll(before.keySet());
        // track the new repositories where we can find old features
        Map<String, String> featuresInNewRepositories = new HashMap<>();
        MultiMap<String, String> singleFeaturesInNewRepositories = new MultiMap<>();
        Map<String, String> actualNewFeatureVersions = new HashMap<>();
        MultiMap<String, String> singleActualNewFeatureVersions = new MultiMap<>();
        // Figure out which old repos were updated:  Do they have feature
        // with the same name as one contained in a repo being added?
        // and do they have update'able version? (just like with bundles)
        Set<String> oldRepositoryNames = new HashSet<String>();
        for (String addedRepositoryName : addedRepositoryNames) {
            Repository added = after.get(addedRepositoryName);
            for (Feature feature : added.getFeatures()) {
                Version v = Utils.getOsgiVersion(feature.getVersion());
                Version lowestUpdateableVersion = new Version(v.getMajor(), v.getMinor(), 0);
                String key = String.format("%s|%s", feature.getName(), lowestUpdateableVersion.toString());
                featuresInNewRepositories.put(key, addedRepositoryName);
                singleFeaturesInNewRepositories.put(feature.getName(), addedRepositoryName);
                actualNewFeatureVersions.put(key, v.toString());
                singleActualNewFeatureVersions.put(feature.getName(), v.toString());
                String oldRepositoryWithUpdateableFeature = featuresInOldRepositories.get(key);
                if (oldRepositoryWithUpdateableFeature == null && singleFeaturesInOldRepositories.get(feature.getName()) != null && singleFeaturesInOldRepositories.get(feature.getName()).size() == 1) {
                    oldRepositoryWithUpdateableFeature = singleFeaturesInOldRepositories.get(feature.getName()).get(0);
                }
                if (oldRepositoryWithUpdateableFeature != null) {
                    // track the old repository to be removed
                    oldRepositoryNames.add(oldRepositoryWithUpdateableFeature);
                }
            }
        }
        // We need to uninstall them. Before we uninstall, track which features were installed.
        for (String oldRepositoryName : oldRepositoryNames) {
            Repository repository = before.get(oldRepositoryName);
            for (Feature feature : repository.getFeatures()) {
                if (featuresService.isInstalled(feature)) {
                    Version v = Utils.getOsgiVersion(feature.getVersion());
                    Version lowestUpdateableVersion = new Version(v.getMajor(), v.getMinor(), 0);
                    String key = String.format("%s|%s", feature.getName(), lowestUpdateableVersion.toString());
                    String newRepositoryName = featuresInNewRepositories.get(key);
                    String newVersion = actualNewFeatureVersions.get(key);
                    if (newRepositoryName == null) {
                        // feature from 1.1.1 to 1.3.0
                        if (singleFeaturesInOldRepositories.get(feature.getName()) != null && singleFeaturesInOldRepositories.get(feature.getName()).size() == 1 && singleFeaturesInNewRepositories.get(feature.getName()) != null && singleFeaturesInNewRepositories.get(feature.getName()).size() == 1) {
                            newRepositoryName = singleFeaturesInNewRepositories.get(feature.getName()).get(0);
                        }
                    }
                    if (newVersion == null) {
                        if (singleActualNewFeatureVersions.get(feature.getName()) != null && singleActualNewFeatureVersions.get(feature.getName()).size() == 1) {
                            newVersion = singleActualNewFeatureVersions.get(feature.getName()).get(0);
                        }
                    }
                    FeatureUpdate featureUpdate = null;
                    if (newVersion != null && newRepositoryName != null) {
                        featureUpdate = new FeatureUpdate(feature.getName(), after.get(oldRepositoryName).getURI().toString(), feature.getVersion(), after.get(newRepositoryName).getURI().toString(), newVersion);
                    } else {
                        // we didn't find an update for installed features among feature repositories from patch
                        // which means we have to preserve both the feature and the repository - this may
                        // be user's feature
                        featureUpdate = new FeatureUpdate(feature.getName(), after.get(oldRepositoryName).getURI().toString(), feature.getVersion(), null, null);
                    }
                    updatesInThisPatch.add(featureUpdate);
                    // Merge result
                    FeatureUpdate oldUpdate = updatesForFeatureKeys.get(key);
                    if (oldUpdate != null) {
                        Version upv = null, newV = null;
                        if (oldUpdate.getNewVersion() != null) {
                            upv = VersionTable.getVersion(oldUpdate.getNewVersion());
                        }
                        if (newVersion != null) {
                            newV = VersionTable.getVersion(newVersion);
                        }
                        if (upv == null && newV == null) {
                        // weird...
                        } else {
                            if (upv == null || (newV != null && upv.compareTo(newV) < 0)) {
                                // other patch contains newer update for the feature
                                updatesForFeatureKeys.put(key, featureUpdate);
                            }
                        }
                    } else {
                        // this is the first update of the bundle
                        updatesForFeatureKeys.put(key, featureUpdate);
                    }
                }
            }
        }
        // now let's see if there are repositories that are NOT updated (either they're not available in patch
        // (like user feature repositories) or simply didn't change (like jclouds 1.8.1 between Fuse 6.2 and 6.2.1)
        Set<String> unchangedRepositoryNames = new HashSet<>(before.keySet());
        unchangedRepositoryNames.removeAll(oldRepositoryNames);
        for (String unchangedRepositoryName : unchangedRepositoryNames) {
            Repository repository = before.get(unchangedRepositoryName);
            boolean hasInstalledFeatures = false;
            for (Feature feature : repository.getFeatures()) {
                if (featuresService.isInstalled(feature)) {
                    FeatureUpdate featureUpdate = new FeatureUpdate(feature.getName(), after.get(unchangedRepositoryName).getURI().toString(), feature.getVersion(), null, null);
                    hasInstalledFeatures = true;
                    // preserve unchanged/user feature - install after restart
                    updatesInThisPatch.add(featureUpdate);
                    // the key doesn't matter
                    updatesForFeatureKeys.put(String.format("%s|%s", feature.getName(), feature.getVersion()), featureUpdate);
                }
            }
            if (!hasInstalledFeatures) {
                // we have to preserve unchanged/user feature repository - even if it had no installed features
                // this featureUpdate means - "restore feature repository only"
                FeatureUpdate featureUpdate = new FeatureUpdate(null, after.get(unchangedRepositoryName).getURI().toString(), null, null, null);
                updatesInThisPatch.add(featureUpdate);
                updatesForFeatureKeys.put(String.format("REPOSITORY_TO_ADD:%s", after.get(unchangedRepositoryName).getURI().toString()), featureUpdate);
            }
        }
        return updatesInThisPatch;
    } catch (Exception e) {
        throw new PatchException(e.getMessage(), e);
    } finally {
        // we'll add new feature repositories again later. here we've added them only to track the updates
        if (after != null) {
            for (String repo : addedRepositoryNames) {
                if (after.get(repo) != null) {
                    featuresService.removeRepository(after.get(repo).getURI(), false);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) URI(java.net.URI) Feature(org.apache.karaf.features.Feature) LinkedList(java.util.LinkedList) URISyntaxException(java.net.URISyntaxException) PatchException(io.fabric8.patch.management.PatchException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) Repository(org.apache.karaf.features.Repository) Version(org.osgi.framework.Version) PatchException(io.fabric8.patch.management.PatchException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FeatureUpdate(io.fabric8.patch.management.FeatureUpdate)

Example 39 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class ServiceImpl method resumePendingPatchTasks.

/**
 * Upon startup (activation), we check if there are any *.patch.pending files. if yes, we're finishing the
 * installation
 */
private void resumePendingPatchTasks() throws IOException {
    File[] pendingPatches = patchDir.listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.exists() && pathname.getName().endsWith(".pending");
        }
    });
    if (pendingPatches == null || pendingPatches.length == 0) {
        return;
    }
    for (File pending : pendingPatches) {
        Pending what = Pending.valueOf(FileUtils.readFileToString(pending));
        String name = pending.getName().replaceFirst("\\.pending$", "");
        if (patchManagement.isStandaloneChild()) {
            if (name.endsWith("." + System.getProperty("karaf.name") + ".patch")) {
                name = name.replaceFirst("\\." + System.getProperty("karaf.name"), "");
            } else {
                continue;
            }
        }
        File patchFile = new File(pending.getParentFile(), name);
        if (!patchFile.isFile()) {
            System.out.println("Ignoring patch result file: " + patchFile.getName());
            continue;
        }
        PatchData patchData = PatchData.load(new FileInputStream(patchFile));
        Patch patch = patchManagement.loadPatch(new PatchDetailsRequest(patchData.getId()));
        System.out.printf("Resume %s of %spatch \"%s\"%n", what == Pending.ROLLUP_INSTALLATION ? "installation" : "rollback", patch.getPatchData().isRollupPatch() ? "rollup " : "", patch.getPatchData().getId());
        PatchResult result = patch.getResult();
        if (patchManagement.isStandaloneChild()) {
            result = result.getChildPatches().get(System.getProperty("karaf.name"));
            if (result == null) {
                System.out.println("Ignoring patch result file: " + patchFile.getName());
                continue;
            }
        }
        // feature time
        Set<String> newRepositories = new LinkedHashSet<>();
        Set<String> features = new LinkedHashSet<>();
        for (FeatureUpdate featureUpdate : result.getFeatureUpdates()) {
            if (featureUpdate.getName() == null && featureUpdate.getPreviousRepository() != null) {
                // feature was not shipped by patch
                newRepositories.add(featureUpdate.getPreviousRepository());
            } else if (featureUpdate.getNewRepository() == null) {
                // feature was not changed by patch
                newRepositories.add(featureUpdate.getPreviousRepository());
                features.add(String.format("%s|%s", featureUpdate.getName(), featureUpdate.getPreviousVersion()));
            } else {
                // feature was shipped by patch
                if (what == Pending.ROLLUP_INSTALLATION) {
                    newRepositories.add(featureUpdate.getNewRepository());
                    features.add(String.format("%s|%s", featureUpdate.getName(), featureUpdate.getNewVersion()));
                } else {
                    newRepositories.add(featureUpdate.getPreviousRepository());
                    features.add(String.format("%s|%s", featureUpdate.getName(), featureUpdate.getPreviousVersion()));
                }
            }
        }
        for (String repo : newRepositories) {
            System.out.println("Restoring feature repository: " + repo);
            try {
                featuresService.addRepository(URI.create(repo));
            } catch (Exception e) {
                System.err.println(e.getMessage());
                e.printStackTrace(System.err);
                System.err.flush();
            }
        }
        for (String f : features) {
            String[] fv = f.split("\\|");
            System.out.printf("Restoring feature %s/%s%n", fv[0], fv[1]);
            try {
                featuresService.installFeature(fv[0], fv[1]);
            } catch (Exception e) {
                System.err.println(e.getMessage());
                e.printStackTrace(System.err);
                System.err.flush();
            }
        }
        for (BundleUpdate update : result.getBundleUpdates()) {
            if (!update.isIndependent()) {
                continue;
            }
            String location = null;
            if (update.getNewVersion() == null) {
                System.out.printf("Restoring bundle %s from %s%n", update.getSymbolicName(), update.getPreviousLocation());
                location = update.getPreviousLocation();
            } else {
                if (what == Pending.ROLLUP_INSTALLATION) {
                    System.out.printf("Updating bundle %s from %s%n", update.getSymbolicName(), update.getNewLocation());
                    location = update.getNewLocation();
                } else {
                    System.out.printf("Downgrading bundle %s from %s%n", update.getSymbolicName(), update.getPreviousLocation());
                    location = update.getPreviousLocation();
                }
            }
            try {
                Bundle b = bundleContext.installBundle(location);
                if (update.getStartLevel() > -1) {
                    b.adapt(BundleStartLevel.class).setStartLevel(update.getStartLevel());
                }
                switch(update.getState()) {
                    // ?
                    case Bundle.UNINSTALLED:
                    case Bundle.INSTALLED:
                    case Bundle.STARTING:
                    case Bundle.STOPPING:
                        break;
                    case Bundle.RESOLVED:
                        // ?bundleContext.getBundle(0L).adapt(org.osgi.framework.wiring.FrameworkWiring.class).resolveBundles(...);
                        break;
                    case Bundle.ACTIVE:
                        b.start();
                        break;
                }
            } catch (BundleException e) {
                System.err.println(" - " + e.getMessage());
                // e.printStackTrace(System.err);
                System.err.flush();
            }
        }
        pending.delete();
        System.out.printf("%spatch \"%s\" %s successfully%n", patch.getPatchData().isRollupPatch() ? "Rollup " : "", patchData.getId(), what == Pending.ROLLUP_INSTALLATION ? "installed" : "rolled back");
        if (what == Pending.ROLLUP_ROLLBACK) {
            List<String> bases = patch.getResult().getKarafBases();
            for (Iterator<String> iterator = bases.iterator(); iterator.hasNext(); ) {
                String s = iterator.next();
                if (s.startsWith(System.getProperty("karaf.name"))) {
                    iterator.remove();
                }
            }
            result.setPending(null);
            patch.getResult().store();
            if (patch.getResult().getKarafBases().size() == 0) {
                File file = new File(patchDir, patchData.getId() + ".patch.result");
                file.delete();
            }
            if (patchManagement.isStandaloneChild()) {
                File file = new File(patchDir, patchData.getId() + "." + System.getProperty("karaf.name") + ".patch.result");
                if (file.isFile()) {
                    file.delete();
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) PatchData(io.fabric8.patch.management.PatchData) Bundle(org.osgi.framework.Bundle) PatchDetailsRequest(io.fabric8.patch.management.PatchDetailsRequest) FileInputStream(java.io.FileInputStream) URISyntaxException(java.net.URISyntaxException) PatchException(io.fabric8.patch.management.PatchException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) PatchResult(io.fabric8.patch.management.PatchResult) BundleException(org.osgi.framework.BundleException) FileFilter(java.io.FileFilter) File(java.io.File) Patch(io.fabric8.patch.management.Patch) Pending(io.fabric8.patch.management.Pending) BundleUpdate(io.fabric8.patch.management.BundleUpdate) FeatureUpdate(io.fabric8.patch.management.FeatureUpdate)

Example 40 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class OSGiPatchHelper method sortFeatureUpdates.

/**
 * Sorts feature updates in the way that features listed in etc/org.apache.karaf.features.cfg:featuresBoot
 * are updated first
 * @param featureUpdatesInThisPatch
 */
public void sortFeatureUpdates(List<FeatureUpdate> featureUpdatesInThisPatch) throws IOException {
    Properties props = new Properties();
    FileInputStream stream = new FileInputStream(new File(karafHome, "etc/org.apache.karaf.features.cfg"));
    props.load(stream);
    IOUtils.closeQuietly(stream);
    String p = props.getProperty("featuresBoot");
    if (p != null) {
        String[] properties = p.split("\\s,\\s");
        Set<String> featuresBoot = new LinkedHashSet<>(Arrays.asList(properties));
        // Set<String> featuresSpecial = new LinkedHashSet<>(Arrays.asList("cxf-specs", "cxf-core", "cxf-jaxrs"));
        Set<String> featuresSpecial = new LinkedHashSet<>(Arrays.asList("fabric-cxf"));
        Map<String, FeatureUpdate> newOrderedUpdates = new HashMap<>();
        List<FeatureUpdate> newOtherUpdates = new LinkedList<>();
        List<FeatureUpdate> newUpdates = new LinkedList<>();
        for (Iterator<FeatureUpdate> iterator = featureUpdatesInThisPatch.iterator(); iterator.hasNext(); ) {
            FeatureUpdate update = iterator.next();
            if (update.getName() != null && (featuresBoot.contains(update.getName()) || featuresSpecial.contains(update.getName()))) {
                newOrderedUpdates.put(update.getName(), update);
            } else {
                newOtherUpdates.add(update);
            }
        }
        for (String fb : featuresBoot) {
            if (newOrderedUpdates.containsKey(fb)) {
                newUpdates.add(newOrderedUpdates.get(fb));
            }
        }
        for (String fs : featuresSpecial) {
            if (newOrderedUpdates.containsKey(fs)) {
                newUpdates.add(newOrderedUpdates.get(fs));
            }
        }
        newUpdates.addAll(newOtherUpdates);
        featureUpdatesInThisPatch.clear();
        featureUpdatesInThisPatch.addAll(newUpdates);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) File(java.io.File) FeatureUpdate(io.fabric8.patch.management.FeatureUpdate)

Aggregations

Test (org.junit.Test)20 HashMap (java.util.HashMap)18 FabricService (io.fabric8.api.FabricService)15 IOException (java.io.IOException)13 Feature (io.fabric8.agent.model.Feature)12 Container (io.fabric8.api.Container)11 Profile (io.fabric8.api.Profile)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 Map (java.util.Map)9 BundleContext (org.osgi.framework.BundleContext)9 HashSet (java.util.HashSet)8 URL (java.net.URL)7 BundleException (org.osgi.framework.BundleException)7 Repository (io.fabric8.agent.model.Repository)6 Version (io.fabric8.api.Version)6 LinkedHashSet (java.util.LinkedHashSet)6 Ignore (org.junit.Ignore)6 BundleInfo (io.fabric8.agent.model.BundleInfo)5 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)5