Search in sources :

Example 86 with Patch

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

the class GitPatchManagementServiceIT method installThreeNonRollupPatches.

@Test
public void installThreeNonRollupPatches() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInSystem();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch5", "target/karaf/patches/source/patch-5.zip", false);
    preparePatchZip("src/test/resources/content/patch6", "target/karaf/patches/source/patch-6.zip", false);
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
    Patch patch1 = service.trackPatch(patchData1);
    PatchData patchData5 = service.fetchPatches(new File("target/karaf/patches/source/patch-5.zip").toURI().toURL()).get(0);
    Patch patch5 = service.trackPatch(patchData5);
    PatchData patchData6 = service.fetchPatches(new File("target/karaf/patches/source/patch-6.zip").toURI().toURL()).get(0);
    Patch patch6 = service.trackPatch(patchData6);
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    List<BundleUpdate> patch1Updates = new LinkedList<>();
    patch1Updates.add(BundleUpdate.from("mvn:io.fabric8/fabric-tranquility/1.2.0").to("mvn:io.fabric8/fabric-tranquility/1.2.3"));
    service.install(tx, patch1, patch1Updates);
    List<BundleUpdate> patch5Updates = new LinkedList<>();
    patch5Updates.add(BundleUpdate.from("mvn:io.fabric8/fabric-zen/1.1.44/war").to("mvn:io.fabric8/fabric-zen/1.2.0/war"));
    service.install(tx, patch5, patch5Updates);
    List<BundleUpdate> patch6Updates = new LinkedList<>();
    patch5Updates.add(BundleUpdate.from("mvn:io.fabric8/fabric-zen/1.2.4/war").to("mvn:io.fabric8/fabric-zen/1.3.0/war"));
    service.install(tx, patch6, patch6Updates);
    service.commitInstallation(tx);
    String binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/admin"));
    assertTrue(binAdmin.contains("system/io/fabric8/fabric-tranquility/1.2.3/fabric-tranquility-1.2.3.jar"));
    String etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"));
    // version from patch-5 should be chosen, because there's 1.1.44->1.2.0
    assertTrue(etcStartupProperties.contains("io/fabric8/fabric-zen/1.2.0/fabric-zen-1.2.0.war=42"));
    assertTrue(etcStartupProperties.contains("io/fabric8/fabric-tranquility/1.2.3/fabric-tranquility-1.2.3.jar=42"));
    String etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"));
    assertTrue(etcOverridesProperties.contains("mvn:io.fabric8/fabric-tranquility/1.2.3\n"));
    assertTrue(etcOverridesProperties.contains("mvn:io.fabric8/fabric-zen/1.2.0/war;range=[1.1,1.2)\n"));
    assertTrue(etcOverridesProperties.contains("mvn:io.fabric8/fabric-zen/1.3.3/war\n"));
    /* rollback time! */
    Patch p5 = service.loadPatch(new PatchDetailsRequest("my-patch-5"));
    service.rollback(p5.getPatchData());
    binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/admin"));
    assertTrue(binAdmin.contains("system/io/fabric8/fabric-tranquility/1.2.3/fabric-tranquility-1.2.3.jar"));
    etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"));
    // rollback wasn't successful
    assertTrue(etcStartupProperties.contains("io/fabric8/fabric-zen/1.2.0/fabric-zen-1.2.0.war=42"));
    assertFalse(etcStartupProperties.contains("io/fabric8/fabric-zen/1.1.44/fabric-zen-1.1.44.war=42"));
    assertTrue(etcStartupProperties.contains("io/fabric8/fabric-tranquility/1.2.3/fabric-tranquility-1.2.3.jar=42"));
    etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"));
    assertTrue(etcOverridesProperties.contains("mvn:io.fabric8/fabric-tranquility/1.2.3\n"));
    assertTrue(etcOverridesProperties.contains("mvn:io.fabric8/fabric-zen/1.2.0/war;range=[1.1,1.2)\n"));
    assertTrue(etcOverridesProperties.contains("mvn:io.fabric8/fabric-zen/1.3.3/war\n"));
    Patch p6 = service.loadPatch(new PatchDetailsRequest("my-patch-6"));
    service.rollback(p6.getPatchData());
    binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/admin"));
    assertTrue(binAdmin.contains("system/io/fabric8/fabric-tranquility/1.2.3/fabric-tranquility-1.2.3.jar"));
    etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"));
    assertTrue(etcStartupProperties.contains("io/fabric8/fabric-zen/1.2.0/fabric-zen-1.2.0.war=42"));
    assertTrue(etcStartupProperties.contains("io/fabric8/fabric-tranquility/1.2.3/fabric-tranquility-1.2.3.jar=42"));
    etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"));
    assertFalse(etcOverridesProperties.contains("mvn:io.fabric8/fabric-zen/1.3.3/war\n"));
    repository.closeRepository(fork, true);
}
Also used : GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 87 with Patch

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

the class GitPatchManagementServiceForStandaloneChildContainersIT method installPPatchAndThenRPatch.

@Test
public void installPPatchAndThenRPatch() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInPatches();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch7", "target/karaf/patches/source/patch-7.zip", false);
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
    Patch patch1 = service.trackPatch(patchData1);
    String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    service.install(tx, patch1, null);
    service.commitInstallation(tx);
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertTrue(repository.containsTag(fork, "patch-my-patch-1-child"));
    // tag from baseline
    assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-620133"));
    // tag from patch (root and child) - not available yet
    assertFalse(repository.containsTag(fork, "baseline-6.2.0.redhat-002"));
    assertFalse(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084"));
    assertFalse(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084-child"));
    repository.closeRepository(fork, true);
    PatchData patchData7 = service.fetchPatches(new File("target/karaf/patches/source/patch-7.zip").toURI().toURL()).get(0);
    Patch patch7 = service.trackPatch(patchData7);
    tx = service.beginInstallation(PatchKind.ROLLUP);
    service.install(tx, patch7, null);
    service.commitInstallation(tx);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertFalse(repository.containsTag(fork, "patch-my-patch-1-child"));
    // there's no such tag - we're not in STANDALONE container
    assertFalse(repository.containsTag(fork, "baseline-6.2.0.redhat-002"));
    assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084"));
    repository.closeRepository(fork, true);
}
Also used : GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) File(java.io.File) Test(org.junit.Test)

Example 88 with Patch

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

the class GitPatchManagementServiceForStandaloneChildContainersIT method rollbackInstalledNonRollupPatch.

@Test
public void rollbackInstalledNonRollupPatch() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInPatches();
    freshKarafStandaloneDistro();
    PatchManagement management = (PatchManagement) pm;
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL());
    Patch patch = management.trackPatch(patches.get(0));
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    ObjectId master1 = fork.getRepository().resolve(GitPatchRepository.ADMIN_HISTORY_BRANCH + "-child");
    String tx = management.beginInstallation(PatchKind.NON_ROLLUP);
    management.install(tx, patch, null);
    management.commitInstallation(tx);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertTrue(repository.containsTag(fork, "patch-my-patch-1-child"));
    repository.closeRepository(fork, true);
    management.rollback(patch.getPatchData());
    repository.closeRepository(fork, true);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    ObjectId master2 = fork.getRepository().resolve(GitPatchRepository.ADMIN_HISTORY_BRANCH + "-child");
    assertThat(master1, not(equalTo(master2)));
    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, "baseline-child-2.4.0.redhat-620133"));
    assertFalse(repository.containsTag(fork, "patch-my-patch-1-child"));
    String binStart = FileUtils.readFileToString(new File(karafHome, "bin/start"));
    assertTrue("bin/start should be at previous version", binStart.contains("echo \"This is user's change\""));
}
Also used : GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) File(java.io.File) Test(org.junit.Test)

Example 89 with Patch

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

the class GitPatchManagementServiceForStandaloneChildContainersIT method installRollupPatch.

@Test
public void installRollupPatch() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInPatches();
    freshKarafStandaloneDistro();
    PatchManagement management = (PatchManagement) pm;
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    repository.prepareCommit(fork, "artificial change, not treated as user change (could be a patch)").call();
    repository.prepareCommit(fork, "artificial change, not treated as user change").call();
    // no changes, but commit
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    FileUtils.write(new File(karafBase, "bin/start"), "echo \"another user change\"\n", true);
    // conflicting change, but commit
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    FileUtils.write(new File(karafBase, "bin/test"), "echo \"another user change\"\n");
    // non-conflicting
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    repository.closeRepository(fork, true);
    preparePatchZip("src/test/resources/content/patch7", "target/karaf/patches/source/patch-7.zip", false);
    List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-7.zip").toURI().toURL());
    Patch patch = management.trackPatch(patches.get(0));
    String tx = management.beginInstallation(PatchKind.ROLLUP);
    management.install(tx, patch, null);
    @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-child-2.4.0.redhat-620133^{commit}");
    ObjectId to = fork.getRepository().resolve(tx);
    Iterable<RevCommit> commits = fork.log().addRange(since, to).call();
    // only one "user change", because we had two conflicts with new baseline - they were resolved
    // by picking what already comes from rollup patch ("ours"):
    /*
         * Problem with applying the change 657f11c4b65bb7893a2b82f888bb9731a6d5f7d0:
         *  - bin/start: BOTH_MODIFIED
         * Choosing "ours" change
         * Problem with applying the change d9272b97582582f4b056f7170130ec91fc21aeac:
         *  - bin/start: BOTH_MODIFIED
         * Choosing "ours" change
         */
    List<String> commitList = Arrays.asList("[PATCH] Apply user changes", "[PATCH] Apply user changes", "[PATCH] Apply user changes", "[PATCH] Rollup patch patch-7 - resetting etc/overrides.properties", "[PATCH/baseline] Installing baseline-child-2.4.0.redhat-621084");
    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(4));
    assertTrue(repository.containsTag(fork, "patch-management"));
    assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
    assertFalse(repository.containsTag(fork, "baseline-6.2.0.redhat-002"));
    assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-620133"));
    assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084"));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) File(java.io.File) Map(java.util.Map) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 90 with Patch

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

the class GitPatchManagementServiceForStandaloneChildContainersIT method rollbackInstalledRollupPatch.

@Test
public void rollbackInstalledRollupPatch() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInPatches();
    freshKarafStandaloneDistro();
    PatchManagement management = (PatchManagement) pm;
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch7", "target/karaf/patches/source/patch-7.zip", false);
    List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL());
    Patch patch1 = management.trackPatch(patches.get(0));
    patches = management.fetchPatches(new File("target/karaf/patches/source/patch-7.zip").toURI().toURL());
    Patch patch7 = management.trackPatch(patches.get(0));
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    ObjectId master1 = fork.getRepository().resolve(GitPatchRepository.ADMIN_HISTORY_BRANCH + "-child");
    String tx = management.beginInstallation(PatchKind.ROLLUP);
    management.install(tx, patch7, null);
    management.commitInstallation(tx);
    // install P patch to check if rolling back rollup patch will remove P patch's tag
    tx = management.beginInstallation(PatchKind.NON_ROLLUP);
    management.install(tx, patch1, null);
    management.commitInstallation(tx);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
    assertTrue(repository.containsTag(fork, "patch-my-patch-1-child"));
    assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-620133"));
    assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084"));
    management.rollback(patch7.getPatchData());
    repository.closeRepository(fork, true);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    ObjectId master2 = fork.getRepository().resolve(GitPatchRepository.ADMIN_HISTORY_BRANCH + "-child");
    assertThat(master1, not(equalTo(master2)));
    assertThat(fork.tagList().call().size(), equalTo(4));
    assertTrue(repository.containsTag(fork, "patch-management"));
    assertFalse("P patch1 should be not visible as installed", repository.containsTag(fork, "patch-my-patch-1-child"));
    assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
    assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-620133"));
    assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084"));
    assertFalse(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084-child"));
    assertFalse("When rolling back rollup patch, newer P patches' tags should be removed", repository.containsTag(fork, "patch-my-patch-1"));
    assertThat(repository.findCurrentBaseline(fork).getTagName(), equalTo("baseline-child-2.4.0.redhat-620133"));
}
Also used : GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)54 Test (org.junit.Test)43 Git (org.eclipse.jgit.api.Git)35 PatchException (io.fabric8.patch.management.PatchException)34 Patch (io.fabric8.patch.management.Patch)30 IOException (java.io.IOException)28 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)27 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)26 HashMap (java.util.HashMap)18 RevCommit (org.eclipse.jgit.revwalk.RevCommit)18 LinkedList (java.util.LinkedList)17 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)17 ObjectId (org.eclipse.jgit.lib.ObjectId)17 Bundle (org.osgi.framework.Bundle)17 Version (org.osgi.framework.Version)15 PatchResult (io.fabric8.patch.management.PatchResult)13 BundleUpdate (io.fabric8.patch.management.BundleUpdate)11 PatchData (io.fabric8.patch.management.PatchData)11 ArrayList (java.util.ArrayList)11