Search in sources :

Example 21 with GitPatchManagementServiceImpl

use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl 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 22 with GitPatchManagementServiceImpl

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

the class ProtectedTest method updateBinAdminReferences.

@Test
public void updateBinAdminReferences() throws IOException {
    File binAdmin = new File(git.getRepository().getWorkTree(), "bin/admin");
    FileUtils.copyFile(new File("src/test/resources/files/bin/admin"), binAdmin);
    List<BundleUpdate> bundleUpdates = new LinkedList<>();
    bundleUpdates.add(BundleUpdate.from("mvn:org.apache.karaf.admin/org.apache.karaf.admin.command/2.4.0.redhat-620133").to("mvn:org.apache.karaf.admin/org.apache.karaf.admin.command/2.4.0.redhat-620134"));
    bundleUpdates.add(BundleUpdate.from("mvn:org.apache.felix/org.apache.felix.gogo.runtime/0.12.1").to("mvn:org.apache.felix/org.apache.felix.gogo.runtime/1.12.1"));
    Map<String, String> updates = Utils.collectLocationUpdates(bundleUpdates);
    new GitPatchManagementServiceImpl(context).updateReferences(git, "bin/admin", "system/", updates, false);
    String expected = FileUtils.readFileToString(new File("src/test/resources/files/bin/admin.updated"));
    String changed = FileUtils.readFileToString(binAdmin);
    assertThat(changed, equalTo(expected));
}
Also used : File(java.io.File) BundleUpdate(io.fabric8.patch.management.BundleUpdate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 23 with GitPatchManagementServiceImpl

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

the class ProtectedTest method updateEtcStartupReferences.

@Test
public void updateEtcStartupReferences() throws IOException {
    File etcConfig = new File(git.getRepository().getWorkTree(), "etc/startup.properties");
    FileUtils.copyFile(new File("src/test/resources/files/etc/startup.properties"), etcConfig);
    List<BundleUpdate> bundleUpdates = new LinkedList<>();
    bundleUpdates.add(BundleUpdate.from("mvn:org.ops4j.pax.url/pax-url-wrap/2.4.0/jar/uber").to("mvn:org.ops4j.pax.url/pax-url-wrap/2.4.2/jar/uber"));
    bundleUpdates.add(BundleUpdate.from("file:/opt/karaf/system/org/ops4j/pax/url/pax-url-aether/2.4.0/pax-url-aether-2.4.0.jar").to("file:/opt/karaf/system/org/ops4j/pax/url/pax-url-aether/2.4.2/pax-url-aether-2.4.2.jar"));
    bundleUpdates.add(BundleUpdate.from("mvn:org.apache.felix/org.apache.felix.bundlerepository/2.0.4").to("mvn:org.apache.felix/org.apache.felix.bundlerepository/2.1.4"));
    Map<String, String> updates = Utils.collectLocationUpdates(bundleUpdates);
    new GitPatchManagementServiceImpl(context).updateReferences(git, "etc/startup.properties", "", updates, false);
    String expected = FileUtils.readFileToString(new File("src/test/resources/files/etc/startup.properties.updated"));
    String changed = FileUtils.readFileToString(etcConfig);
    assertThat(changed, equalTo(expected));
}
Also used : File(java.io.File) BundleUpdate(io.fabric8.patch.management.BundleUpdate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 24 with GitPatchManagementServiceImpl

use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl 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 25 with GitPatchManagementServiceImpl

use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl 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)

Aggregations

GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)27 Test (org.junit.Test)25 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)20 File (java.io.File)20 Git (org.eclipse.jgit.api.Git)16 LinkedList (java.util.LinkedList)7 ObjectId (org.eclipse.jgit.lib.ObjectId)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)7 BundleUpdate (io.fabric8.patch.management.BundleUpdate)5 PatchManagement (io.fabric8.patch.management.PatchManagement)5 Map (java.util.Map)5 Bundle (org.osgi.framework.Bundle)5 BundleContext (org.osgi.framework.BundleContext)5 Ref (org.eclipse.jgit.lib.Ref)4 ComponentContext (org.osgi.service.component.ComponentContext)4 Patch (io.fabric8.patch.management.Patch)3 IOException (java.io.IOException)3 Version (org.osgi.framework.Version)3 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)3 FrameworkWiring (org.osgi.framework.wiring.FrameworkWiring)3