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);
}
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));
}
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));
}
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);
}
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\""));
}
Aggregations