Search in sources :

Example 16 with BundleUpdate

use of io.fabric8.patch.management.BundleUpdate in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceIT method installNonRollupPatchWithUberJars.

@Test
public void installNonRollupPatchWithUberJars() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    GitPatchRepository repository = patchManagement("baseline4");
    PatchManagement management = (PatchManagement) pm;
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    // no changes, but commit
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    repository.prepareCommit(fork, "artificial change, not treated as user change (could be a patch)").call();
    repository.push(fork);
    repository.closeRepository(fork, true);
    preparePatchZip("src/test/resources/content/patch8", "target/karaf/patches/source/patch-8.zip", false);
    List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-8.zip").toURI().toURL());
    Patch patch = management.trackPatch(patches.get(0));
    String tx = management.beginInstallation(PatchKind.NON_ROLLUP);
    /*
         * bundle.0 = mvn:io.fabric8/pax-romana/1.0.1
         * bundle.1 = mvn:io.fabric8/pax-hellenica/1.0.1/jar
         * # for these two, bundle.getLocation() will return non-matching location
         * bundle.2 = mvn:io.fabric8/pax-bohemia/1.0.1
         * bundle.3 = mvn:io.fabric8/pax-pomerania/1.0.1/jar
         * # for these two, bundle.getLocation() will return matching location
         * bundle.4 = mvn:io.fabric8/pax-avaria/1.0.1/jar/uber
         * bundle.5 = mvn:io.fabric8/pax-mazovia/1.0.1//uber
         * # for these two, bundle.getLocation() will return non-matching location
         * bundle.6 = mvn:io.fabric8/pax-novgorod/1.0.1/jar/uber
         * bundle.7 = mvn:io.fabric8/pax-castile/1.0.1//uber
         */
    LinkedList<BundleUpdate> bundleUpdatesInThisPatch = new LinkedList<>();
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-romana", "1.0.1", "mvn:io.fabric8/pax-romana/1.0.1", "1.0.0", "mvn:io.fabric8/pax-romana/1.0.0"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-hellenica", "1.0.1", "mvn:io.fabric8/pax-hellenica/1.0.1/jar", "1.0.0", "mvn:io.fabric8/pax-hellenica/1.0.0/jar"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-bohemia", "1.0.1", "mvn:io.fabric8/pax-bohemia/1.0.1", "1.0.0", "mvn:io.fabric8/pax-bohemia/1.0.0/jar"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-pomerania", "1.0.1", "mvn:io.fabric8/pax-pomerania/1.0.1/jar", "1.0.0", "mvn:io.fabric8/pax-pomerania/1.0.0"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-avaria", "1.0.1", "mvn:io.fabric8/pax-avaria/1.0.1/jar/uber", "1.0.0", "mvn:io.fabric8/pax-avaria/1.0.0/jar/uber"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-mazovia", "1.0.1", "mvn:io.fabric8/pax-mazovia/1.0.1//uber", "1.0.0", "mvn:io.fabric8/pax-mazovia/1.0.0//uber"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-novgorod", "1.0.1", "mvn:io.fabric8/pax-novgorod/1.0.1/jar/uber", "1.0.0", "mvn:io.fabric8/pax-novgorod/1.0.0//uber"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-castile", "1.0.1", "mvn:io.fabric8/pax-castile/1.0.1//uber", "1.0.0", "mvn:io.fabric8/pax-castile/1.0.0/jar/uber"));
    management.install(tx, patch, bundleUpdatesInThisPatch);
    @SuppressWarnings("unchecked") Map<String, Git> transactions = (Map<String, Git>) getField(management, "pendingTransactions");
    assertThat(transactions.size(), equalTo(1));
    fork = transactions.values().iterator().next();
    ObjectId since = fork.getRepository().resolve("baseline-6.2.0^{commit}");
    ObjectId to = fork.getRepository().resolve(tx);
    Iterable<RevCommit> commits = fork.log().addRange(since, to).call();
    List<String> commitList = Arrays.asList("[PATCH] Installing patch my-patch-8", "artificial change, not treated as user change (could be a patch)", "[PATCH] Apply user changes");
    int n = 0;
    for (RevCommit c : commits) {
        String msg = c.getShortMessage();
        assertThat(msg, equalTo(commitList.get(n++)));
    }
    assertThat(n, equalTo(commitList.size()));
    assertThat(fork.tagList().call().size(), equalTo(3));
    assertTrue(repository.containsTag(fork, "patch-management"));
    assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
    assertTrue(repository.containsTag(fork, "patch-my-patch-8"));
    Properties startup = new Properties();
    try (FileReader reader = new FileReader(new File(fork.getRepository().getWorkTree(), "etc/startup.properties"))) {
        startup.load(reader);
        assertTrue(startup.containsKey("io/fabric8/pax-romana/1.0.1/pax-romana-1.0.1.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-hellenica/1.0.1/pax-hellenica-1.0.1.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-bohemia/1.0.1/pax-bohemia-1.0.1.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-pomerania/1.0.1/pax-pomerania-1.0.1.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-avaria/1.0.1/pax-avaria-1.0.1-uber.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-mazovia/1.0.1/pax-mazovia-1.0.1-uber.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-novgorod/1.0.1/pax-novgorod-1.0.1-uber.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-castile/1.0.1/pax-castile-1.0.1-uber.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-romana/1.0.0/pax-romana-1.0.0.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-hellenica/1.0.0/pax-hellenica-1.0.0.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-bohemia/1.0.0/pax-bohemia-1.0.0.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-pomerania/1.0.0/pax-pomerania-1.0.0.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-avaria/1.0.0/pax-avaria-1.0.0-uber.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-mazovia/1.0.0/pax-mazovia-1.0.0-uber.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-novgorod/1.0.0/pax-novgorod-1.0.0-uber.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-castile/1.0.0/pax-castile-1.0.0-uber.jar"));
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) Properties(java.util.Properties) LinkedList(java.util.LinkedList) Git(org.eclipse.jgit.api.Git) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) FileReader(java.io.FileReader) File(java.io.File) Map(java.util.Map) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 17 with BundleUpdate

use of io.fabric8.patch.management.BundleUpdate in project fabric8 by jboss-fuse.

the class FabricPatchServiceImpl method install.

@Override
public PatchResult install(final Patch patch, boolean simulation, final String versionId, boolean upload, final String username, final String password, final ProfileUpdateStrategy strategy) throws IOException {
    // we start from the same state as in standalone mode - after successful patch:add
    // we have other things to do in fabric env however:
    // 1. check prerequisites
    // 2. we don't care about current state of framework - it'll be managed by fabric-agent and we don't
    // necessary install a patch for this container we're in
    // 3. we don't do patchManagement.beginInstallation / patchManagement.commitInstallation here
    // this will be done later - after updated fabric-agent is started
    // 4. we don't have to analyze bundles/features/repositories updates - these will be handled simply by
    // updating profiles in specified version
    PatchKind kind = patch.getPatchData().isRollupPatch() ? PatchKind.ROLLUP : PatchKind.NON_ROLLUP;
    if (kind == PatchKind.NON_ROLLUP) {
        throw new UnsupportedOperationException("patch:fabric-install should be used for Rollup patches only");
    }
    String currentContainersVersionId = fabricService.getCurrentContainer().getVersionId();
    if (!simulation && versionId.equals(currentContainersVersionId)) {
        throw new UnsupportedOperationException("Can't install Rollup patch in current version. Please install" + " this patch in new version and then upgrade existing container(s)");
    }
    fabricService.adapt(ProfileService.class).getRequiredVersion(versionId);
    // just a list of new bundle locations - in fabric the updatable version depends on the moment we
    // apply the new version to existing containers.
    List<BundleUpdate> bundleUpdatesInThisPatch = bundleUpdatesInPatch(patch);
    Presentation.displayBundleUpdates(bundleUpdatesInThisPatch, true);
    PatchResult result = new PatchResult(patch.getPatchData(), simulation, System.currentTimeMillis(), bundleUpdatesInThisPatch, null);
    if (!simulation) {
        // update profile definitions stored in Git. We don't update ${karaf.home}/fabric, becuase it is used
        // only once - when importing profiles during fabric:create.
        // when fabric is already available, we have to update (Git) repository information
        GitOperation operation = new GitOperation() {

            @Override
            public Object call(Git git, GitContext context) throws Exception {
                // we can't pass git reference to patch-management
                // because patch-management private-packages git library
                // but we can leverage the write lock we have
                GitHelpers.checkoutBranch(git, versionId);
                // let's get back in history to the point before user changes (profile-edits), but not earlier
                // than last R patch
                String patchBranch = patchManagement.findLatestPatchRevision(git.getRepository().getDirectory(), versionId);
                // now install profiles from patch just like there were no user changes
                patchManagement.installProfiles(git.getRepository().getDirectory(), versionId, patch, strategy);
                // and finally we have to merge user and patch changes to profiles.
                patchManagement.mergeProfileChanges(patch, git.getRepository().getDirectory(), versionId, patchBranch);
                context.commitMessage("Installing rollup patch \"" + patch.getPatchData().getId() + "\"");
                return null;
            }
        };
        gitDataStore.gitOperation(new GitContext().requireCommit().setRequirePush(true), operation, null);
        if (upload) {
            PatchManagement.UploadCallback callback = new PatchManagement.UploadCallback() {

                @Override
                public void doWithUrlConnection(URLConnection connection) throws ProtocolException {
                    if (connection instanceof HttpURLConnection) {
                        ((HttpURLConnection) connection).setRequestMethod("PUT");
                    }
                    if (username != null && password != null) {
                        connection.setRequestProperty("Authorization", "Basic " + Base64Encoder.encode(username + ":" + password));
                    }
                }
            };
            patchManagement.uploadPatchArtifacts(patch.getPatchData(), fabricService.getMavenRepoUploadURI(), callback);
        }
    }
    return result;
}
Also used : PatchKind(io.fabric8.patch.management.PatchKind) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) ProfileService(io.fabric8.api.ProfileService) GitOperation(io.fabric8.git.internal.GitOperation) Git(org.eclipse.jgit.api.Git) HttpURLConnection(java.net.HttpURLConnection) GitContext(io.fabric8.api.GitContext) PatchManagement(io.fabric8.patch.management.PatchManagement) PatchResult(io.fabric8.patch.management.PatchResult) BundleUpdate(io.fabric8.patch.management.BundleUpdate)

Example 18 with BundleUpdate

use of io.fabric8.patch.management.BundleUpdate in project fabric8 by jboss-fuse.

the class FabricPatchServiceImpl method bundleUpdatesInPatch.

/**
 * Simpler (than in standalone scenario) method of checking what bundles are updated with currently installed
 * {@link PatchKind#ROLLUP rollup patch}.
 * We only care about core bundles updated - all other bundles are handled by fabric agent.
 * @param patch
 * @return
 */
private List<BundleUpdate> bundleUpdatesInPatch(Patch patch) throws IOException {
    List<BundleUpdate> updatesInThisPatch = new LinkedList<>();
    for (String newLocation : patch.getPatchData().getBundles()) {
        // [symbolicName, version] of the new bundle
        String[] symbolicNameVersion = helper.getBundleIdentity(newLocation);
        if (symbolicNameVersion == null || symbolicNameVersion[0] == null) {
            continue;
        }
        String sn = stripSymbolicName(symbolicNameVersion[0]);
        String vr = symbolicNameVersion[1];
        Version newVersion = VersionTable.getVersion(vr);
        BundleUpdate update = new BundleUpdate(sn, newVersion.toString(), newLocation, null, null);
        update.setIndependent(true);
        updatesInThisPatch.add(update);
    }
    return updatesInThisPatch;
}
Also used : Version(org.osgi.framework.Version) BundleUpdate(io.fabric8.patch.management.BundleUpdate) LinkedList(java.util.LinkedList)

Example 19 with BundleUpdate

use of io.fabric8.patch.management.BundleUpdate in project fabric8 by jboss-fuse.

the class PatchActionSupport method display.

protected void display(PatchResult result) {
    int l1 = "[name]".length(), l2 = "[old]".length(), l3 = "[new]".length();
    for (BundleUpdate update : result.getBundleUpdates()) {
        if (update.getSymbolicName() != null && stripSymbolicName(update.getSymbolicName()).length() > l1) {
            l1 = stripSymbolicName(update.getSymbolicName()).length();
        }
        if (update.getPreviousVersion().length() > l2) {
            l2 = update.getPreviousVersion().length();
        }
        if (update.getNewVersion().length() > l3) {
            l3 = update.getNewVersion().length();
        }
    }
    System.out.println(String.format("%-" + l1 + "s   %-" + l2 + "s   %-" + l3 + "s", "[name]", "[old]", "[new]"));
    java.util.List<BundleUpdate> updates = new ArrayList<>(result.getBundleUpdates());
    Collections.sort(updates, new Comparator<BundleUpdate>() {

        @Override
        public int compare(BundleUpdate o1, BundleUpdate o2) {
            return o1.getSymbolicName().compareTo(o2.getSymbolicName());
        }
    });
    for (BundleUpdate update : updates) {
        System.out.println(String.format("%-" + l1 + "s | %-" + l2 + "s | %-" + l3 + "s", update.getSymbolicName() == null ? "" : stripSymbolicName(update.getSymbolicName()), update.getPreviousVersion(), update.getNewVersion()));
    }
}
Also used : java.util(java.util) BundleUpdate(io.fabric8.patch.management.BundleUpdate)

Aggregations

BundleUpdate (io.fabric8.patch.management.BundleUpdate)16 File (java.io.File)14 LinkedList (java.util.LinkedList)11 Test (org.junit.Test)9 HashMap (java.util.HashMap)7 PatchResult (io.fabric8.patch.management.PatchResult)6 Bundle (org.osgi.framework.Bundle)6 IOException (java.io.IOException)5 Git (org.eclipse.jgit.api.Git)5 Patch (io.fabric8.patch.management.Patch)4 PatchData (io.fabric8.patch.management.PatchData)4 PatchException (io.fabric8.patch.management.PatchException)4 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)4 Map (java.util.Map)4 Properties (java.util.Properties)4 FeatureUpdate (io.fabric8.patch.management.FeatureUpdate)3 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)3 URISyntaxException (java.net.URISyntaxException)3 LinkedHashMap (java.util.LinkedHashMap)3 Artifact (io.fabric8.patch.management.Artifact)2