Search in sources :

Example 26 with GitPatchRepository

use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf 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.INSTANCE_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.INSTANCE_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-7.0.0"));
    assertTrue(repository.containsTag(fork, "baseline-child-4.2.0.redhat-700001"));
    assertFalse(repository.containsTag(fork, "patch-my-patch-1-child"));
    String binStart = FileUtils.readFileToString(new File(karafHome, "bin/start"), "UTF-8");
    assertTrue("bin/start should be at previous version", binStart.contains("echo \"This is user's change\""));
}
Also used : GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) File(java.io.File) Test(org.junit.Test)

Example 27 with GitPatchRepository

use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf by jboss-fuse.

the class GitPatchManagementServiceForStandaloneChildContainersIT method installNonRollupPatch.

@Test
public void installNonRollupPatch() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInPatches();
    freshKarafStandaloneDistro();
    PatchManagement management = (PatchManagement) pm;
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    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);
    FileUtils.write(new File(karafBase, "bin/shutdown"), "#!/bin/bash\nexit 42", "UTF-8");
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    repository.closeRepository(fork, true);
    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));
    String tx = management.beginInstallation(PatchKind.NON_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-4.2.0.redhat-700001^{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-1", "[PATCH] Apply user changes", "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(4));
    assertTrue(repository.containsTag(fork, "patch-management"));
    assertTrue(repository.containsTag(fork, "baseline-7.0.0"));
    assertTrue(repository.containsTag(fork, "baseline-child-4.2.0.redhat-700001"));
    assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
    assertTrue(repository.containsTag(fork, "patch-my-patch-1-child"));
    assertThat("The conflict should be resolved in special way", FileUtils.readFileToString(new File(karafHome, "bin/setenv"), "UTF-8"), equalTo("JAVA_MIN_MEM=2G # Minimum memory for the JVM\n"));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) GitPatchManagementServiceImpl(org.jboss.fuse.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 28 with GitPatchRepository

use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf 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.INSTANCE_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-4.2.0.redhat-700001"));
    assertTrue(repository.containsTag(fork, "baseline-child-4.2.0.redhat-700002"));
    management.rollback(patch7.getPatchData());
    repository.closeRepository(fork, true);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    ObjectId master2 = fork.getRepository().resolve(GitPatchRepository.INSTANCE_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-7.0.0"));
    assertTrue(repository.containsTag(fork, "baseline-child-4.2.0.redhat-700001"));
    assertTrue(repository.containsTag(fork, "baseline-child-4.2.0.redhat-700002"));
    assertFalse(repository.containsTag(fork, "baseline-child-4.2.0.redhat-700002-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-4.2.0.redhat-700001"));
}
Also used : GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) File(java.io.File) Test(org.junit.Test)

Aggregations

GitPatchRepository (org.jboss.fuse.patch.management.impl.GitPatchRepository)28 Test (org.junit.Test)25 Git (org.eclipse.jgit.api.Git)24 File (java.io.File)23 GitPatchManagementServiceImpl (org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl)21 ObjectId (org.eclipse.jgit.lib.ObjectId)16 RevCommit (org.eclipse.jgit.revwalk.RevCommit)10 Map (java.util.Map)8 Ref (org.eclipse.jgit.lib.Ref)7 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 IOException (java.io.IOException)4 FeaturesProcessing (org.apache.karaf.features.internal.model.processing.FeaturesProcessing)4 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)4 PatchManagement (org.jboss.fuse.patch.management.PatchManagement)4 Bundle (org.osgi.framework.Bundle)4 BundleContext (org.osgi.framework.BundleContext)4 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)4 ComponentContext (org.osgi.service.component.ComponentContext)4 FileReader (java.io.FileReader)3 LinkedList (java.util.LinkedList)3