Search in sources :

Example 26 with GitPatchManagementServiceImpl

use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl 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 GitPatchManagementServiceImpl

use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl 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 GitPatchManagementServiceImpl

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

the class GitPatchManagementServiceForStandaloneChildContainersIT method init.

@Before
public void init() throws IOException, GitAPIException {
    super.init(true, true);
    bsl = mock(BundleStartLevel.class);
    when(bundle.adapt(BundleStartLevel.class)).thenReturn(bsl);
    when(systemContext.getDataFile("patches")).thenReturn(new File(karafHome, "data/cache/bundle0/data/patches"));
    // root container's part - initialization of baselines
    freshKarafStandaloneDistro();
    FileUtils.copyFile(new File("src/test/resources/karaf2/system/org/apache/karaf/instance/org.apache.karaf.instance.core/4.2.0.redhat-700001/org.apache.karaf.instance.core-4.2.0.redhat-700001.jar"), new File(karafHome, "system/org/apache/karaf/instance/org.apache.karaf.instance.core/4.2.0.redhat-700001/org.apache.karaf.instance.core-4.2.0.redhat-700001.jar"));
    preparePatchZip("src/test/resources/baselines/baseline3", "target/karaf/system/org/jboss/fuse/fuse-karaf/7.0.0/fuse-karaf-7.0.0-baseline.zip", true);
    pm = new GitPatchManagementServiceImpl(bundleContext);
    pm.start();
    pm.ensurePatchManagementInitialized();
    karafHome = new File("target/karaf");
    karafBase = new File("target/karaf/instances/child");
    super.init(false, false);
    properties.setProperty("karaf.name", "child");
    properties.setProperty("karaf.instances", properties.getProperty("karaf.home") + File.separatorChar + "instances");
}
Also used : BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) File(java.io.File) Before(org.junit.Before)

Example 29 with GitPatchManagementServiceImpl

use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl 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)

Example 30 with GitPatchManagementServiceImpl

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

the class PatchManagementIT method init.

@Before
public void init() throws IOException, GitAPIException {
    super.init(true, true);
    pm = new GitPatchManagementServiceImpl(bundleContext);
    ((GitPatchManagementServiceImpl) pm).start();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch3", "target/karaf/patches/source/patch-3.zip", false);
}
Also used : GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Before(org.junit.Before)

Aggregations

GitPatchManagementServiceImpl (org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl)31 Test (org.junit.Test)25 GitPatchRepository (org.jboss.fuse.patch.management.impl.GitPatchRepository)22 File (java.io.File)18 Git (org.eclipse.jgit.api.Git)18 ObjectId (org.eclipse.jgit.lib.ObjectId)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 Map (java.util.Map)8 Ref (org.eclipse.jgit.lib.Ref)6 RevWalk (org.eclipse.jgit.revwalk.RevWalk)6 IOException (java.io.IOException)5 Patch (org.jboss.fuse.patch.management.Patch)5 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)5 FileReader (java.io.FileReader)4 LinkedList (java.util.LinkedList)4 Properties (java.util.Properties)4 FeaturesProcessing (org.apache.karaf.features.internal.model.processing.FeaturesProcessing)4 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)4 PatchData (org.jboss.fuse.patch.management.PatchData)4 PatchManagement (org.jboss.fuse.patch.management.PatchManagement)4